Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keks committed Jan 16, 2025
1 parent 15ea680 commit 8a88614
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion blake2/src/impl_hacl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,12 @@ impl<const OUT_LEN: usize> Blake2s<0, OUT_LEN> {

#[cfg(test)]
mod test {
use crate::{Blake2s, Blake2sBuilder};

use super::{Blake2b, Blake2bBuilder};

#[test]
fn test_hash() {
fn test_blake2b() {
let mut got_hash = [0; 32];
let mut hasher: Blake2b<0, 32> = Blake2bBuilder::new().unwrap().build();
hasher.update(b"this is a test").unwrap();
Expand All @@ -336,6 +338,14 @@ mod test {

assert_eq!(&got_hash, expected_hash);

let mut got_hash = [0; 32];
let mut hasher: Blake2b<4, 32> = Blake2bBuilder::new().unwrap().with_key(b"test").build();
hasher.update(b"this is a test").unwrap();
hasher.finalize(&mut got_hash);
let expected_hash = b"\x2a\xbb\x86\x16\xc6\x99\xe5\x1d\xa3\x65\xca\xb7\xad\xe0\x53\x92\xaf\xa2\xc3\xc6\x13\x08\x7f\x84\xb0\xd1\x6e\x5a\x4f\xab\xa7\xb8";

assert_eq!(&got_hash, expected_hash);

let mut got_hash = [0; 64];
let mut hasher: Blake2b<0, 64> = Blake2bBuilder::new().unwrap().build();
hasher.update(b"this is a test").unwrap();
Expand All @@ -344,4 +354,23 @@ mod test {

assert_eq!(&got_hash, expected_hash);
}

#[test]
fn test_blake2s() {
let mut got_hash = [0; 32];

let mut hasher: Blake2s<0, 32> = Blake2sBuilder::new().unwrap().build();
hasher.update(b"this is a test").unwrap();
hasher.finalize(&mut got_hash);
let expected_hash = b"\xf2\x01\x46\xc0\x54\xf9\xdd\x6b\x67\x64\xb6\xc0\x93\x57\xf7\xcd\x75\x51\xdf\xbc\xba\x54\x59\x72\xa4\xc8\x16\x6d\xf8\xaf\xde\x60";

assert_eq!(&got_hash, expected_hash);

let mut hasher: Blake2s<4, 32> = Blake2sBuilder::new().unwrap().with_key(b"test").build();
hasher.update(b"this is a test").unwrap();
hasher.finalize(&mut got_hash);
let expected_hash = b"\x98\xfb\xfa\x89\xb3\xee\x07\x51\x9e\xe6\x2c\x18\xfe\x9d\x85\xdc\xf0\x83\x7b\x12\xae\x4d\xe7\x29\xf0\x7b\x55\xa9\x1a\x94\x80\xe8";

assert_eq!(&got_hash, expected_hash);
}
}

0 comments on commit 8a88614

Please sign in to comment.