Add: Option for SHA512/256
@@ -29,6 +29,7 @@ pub enum ShaVariantOption {
SHA256,
SHA384,
SHA512,
+ SHA512Trunc256,
}
impl ShaVariantOption {
@@ -38,6 +39,7 @@ impl ShaVariantOption {
ShaVariantOption::SHA256 => 32,
ShaVariantOption::SHA384 => 48,
ShaVariantOption::SHA512 => 64,
+ ShaVariantOption::SHA512Trunc256 => 32,
}
}
@@ -47,6 +49,7 @@ impl ShaVariantOption {
ShaVariantOption::SHA256 => 64,
ShaVariantOption::SHA384 => 128,
ShaVariantOption::SHA512 => 128,
+ ShaVariantOption::SHA512Trunc256 => 128,
}
}
@@ -67,7 +70,12 @@ impl ShaVariantOption {
let mut hash = sha2::Sha512::default();
hash.input(data);
hash.result().to_vec()
- }
+ },
+ ShaVariantOption::SHA512Trunc256 => {
+ let mut hash = sha2::Sha512Trunc256::default();
+ hash.input(data);
+ hash.result().to_vec()
+ },
}
}
}
@@ -116,4 +124,15 @@ mod test {
assert_eq!(expected_md, actual_md);
}
+
+ #[test]
+ fn shavs_512_trunc_256() {
+ let msg = decode("63d8cfd72768c44920d7b015460489ad578c063be19053889cb809").unwrap();
+ let expected_md = decode(
+ "876e59c8a64faf9d665f7cde5d42fbb331ba818ddcd284491ac51ed50e1613be",
+ ).unwrap();
+ let actual_md = ShaVariantOption::SHA512Trunc256.hash(&msg);
+
+ assert_eq!(expected_md, actual_md);
+ }
}
