mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 14:57:56 +00:00
Add sha2-256 hash function (#4218)
* Add sha2-256 hash function Widely used hash function, supported by bitcoin and ethereum * Add runtime io support * add test * add test * Update hashing.rs * Update hashing.rs
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
//! Hashing functions.
|
||||
|
||||
use blake2_rfc;
|
||||
use sha2::{Digest, Sha256};
|
||||
use tiny_keccak::{Hasher, Keccak};
|
||||
use twox_hash;
|
||||
|
||||
@@ -123,7 +124,7 @@ pub fn twox_256(data: &[u8]) -> [u8; 32] {
|
||||
r
|
||||
}
|
||||
|
||||
/// Do a keccak 256 hash and return result.
|
||||
/// Do a keccak 256-bit hash and return result.
|
||||
pub fn keccak_256(data: &[u8]) -> [u8; 32] {
|
||||
let mut keccak = Keccak::v256();
|
||||
keccak.update(data);
|
||||
@@ -131,3 +132,12 @@ pub fn keccak_256(data: &[u8]) -> [u8; 32] {
|
||||
keccak.finalize(&mut output);
|
||||
output
|
||||
}
|
||||
|
||||
/// Do a sha2 256-bit hash and return result.
|
||||
pub fn sha2_256(data: &[u8]) -> [u8; 32] {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.input(data);
|
||||
let mut output = [0u8; 32];
|
||||
output.copy_from_slice(&hasher.result());
|
||||
output
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user