working sha3_256
This commit is contained in:
@@ -1,20 +1,27 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
use ::sha3::{Digest, Sha3_256};
|
||||||
|
|
||||||
pub struct SHA3_256 {
|
pub struct SHA3_256 {
|
||||||
hash: BITS256,
|
hash: BITS256,
|
||||||
|
hasher: Sha3_256,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hasher for SHA3_256 {
|
impl Hasher for SHA3_256 {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
SHA3_256 { hash: [0; 32] }
|
SHA3_256 {
|
||||||
|
hash: [0; 32],
|
||||||
|
hasher: Sha3_256::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn digest(&mut self, bytes: impl AsRef<[u8]>) {
|
fn digest(&mut self, bytes: impl AsRef<[u8]>) {
|
||||||
todo!()
|
self.hasher.update(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete(self) -> HashReturn {
|
fn complete(mut self) -> HashReturn {
|
||||||
todo!()
|
let res = self.hasher.finalize();
|
||||||
|
self.hash.copy_from_slice(&res);
|
||||||
|
HashReturn::SHA3_256(self.hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +31,17 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sha3_256_hash() {
|
fn test_sha3_256_hash() {
|
||||||
todo!();
|
let input = "HelloWorld";
|
||||||
|
let expected_output = "964b398ecd55793d8ca93e01274efe1377a70c8dc358fdca17cb4e94a9ed7777";
|
||||||
|
|
||||||
|
let mut sha3_256 = SHA3_256::new();
|
||||||
|
|
||||||
|
sha3_256.digest(input);
|
||||||
|
|
||||||
|
let result = sha3_256.complete().into_bytes();
|
||||||
|
|
||||||
|
let hash_out = crate::hex_table::u8_array_to_lower_hex_string(&result).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(hash_out, expected_output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user