diff --git a/Cargo.lock b/Cargo.lock index cc6ad66..bcee054 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,9 +48,9 @@ dependencies = [ [[package]] name = "blobby" -version = "0.4.0-pre.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a859067dcb257cb2ae028cb821399b55140b76fb8b2a360e052fe109019db43" +checksum = "89af0b093cc13baa4e51e64e65ec2422f7e73aea0e612e5ad3872986671622f1" [[package]] name = "block-buffer" diff --git a/hkdf/Cargo.toml b/hkdf/Cargo.toml index 7037943..2fe4eb7 100644 --- a/hkdf/Cargo.toml +++ b/hkdf/Cargo.toml @@ -16,7 +16,7 @@ rust-version = "1.85" hmac = "0.13.0-rc.3" [dev-dependencies] -blobby = "=0.4.0-pre.0" +blobby = "0.4" hex-literal = "1" sha1 = { version = "0.11.0-rc.3", default-features = false } sha2 = { version = "0.11.0-rc.3", default-features = false } diff --git a/hkdf/tests/data/wycheproof-sha1.blb b/hkdf/tests/data/wycheproof_sha1.blb similarity index 97% rename from hkdf/tests/data/wycheproof-sha1.blb rename to hkdf/tests/data/wycheproof_sha1.blb index cb7dd3c..865cbee 100644 Binary files a/hkdf/tests/data/wycheproof-sha1.blb and b/hkdf/tests/data/wycheproof_sha1.blb differ diff --git a/hkdf/tests/data/wycheproof-sha256.blb b/hkdf/tests/data/wycheproof_sha256.blb similarity index 99% rename from hkdf/tests/data/wycheproof-sha256.blb rename to hkdf/tests/data/wycheproof_sha256.blb index 6213609..a0aff09 100644 Binary files a/hkdf/tests/data/wycheproof-sha256.blb and b/hkdf/tests/data/wycheproof_sha256.blb differ diff --git a/hkdf/tests/data/wycheproof-sha384.blb b/hkdf/tests/data/wycheproof_sha384.blb similarity index 98% rename from hkdf/tests/data/wycheproof-sha384.blb rename to hkdf/tests/data/wycheproof_sha384.blb index 2323055..fde5143 100644 Binary files a/hkdf/tests/data/wycheproof-sha384.blb and b/hkdf/tests/data/wycheproof_sha384.blb differ diff --git a/hkdf/tests/data/wycheproof-sha512.blb b/hkdf/tests/data/wycheproof_sha512.blb similarity index 99% rename from hkdf/tests/data/wycheproof-sha512.blb rename to hkdf/tests/data/wycheproof_sha512.blb index 7a75318..cef5840 100644 Binary files a/hkdf/tests/data/wycheproof-sha512.blb and b/hkdf/tests/data/wycheproof_sha512.blb differ diff --git a/hkdf/tests/wycheproof.rs b/hkdf/tests/wycheproof.rs index 45ede3b..48ed436 100644 --- a/hkdf/tests/wycheproof.rs +++ b/hkdf/tests/wycheproof.rs @@ -1,47 +1,50 @@ -use blobby::Blob4Iterator; use hkdf::{GenericHkdf, HmacImpl}; use hmac::{Hmac, SimpleHmac}; -fn test(data: &[u8]) { - for (i, row) in Blob4Iterator::new(data).unwrap().enumerate() { - let [ikm, salt, info, okm] = row.unwrap(); +#[derive(Copy, Clone, Debug)] +struct TestVector { + ikm: &'static [u8], + salt: &'static [u8], + info: &'static [u8], + okm: &'static [u8], +} - let prk = GenericHkdf::::new(Some(salt), ikm); - let mut got_okm = vec![0; okm.len()]; +fn test(test_vectors: &[TestVector]) { + let mut buf = [0u8; 1 << 14]; + for (i, tv) in test_vectors.iter().enumerate() { + let prk = GenericHkdf::::new(Some(tv.salt), tv.ikm); + let okm_dst = &mut buf[..tv.okm.len()]; let mut err = None; - if prk.expand(info, &mut got_okm).is_err() { + if prk.expand(tv.info, okm_dst).is_err() { err = Some("prk expand"); } - if got_okm != okm { + if okm_dst != tv.okm { err = Some("mismatch in okm"); } if let Some(err_desc) = err { - panic!( - "\n\ - Failed test №{i}: {err_desc}\n\ - ikm:\t{ikm:?}\n\ - salt:\t{salt:?}\n\ - info:\t{info:?}\n\ - okm:\t{okm:?}\n" - ); + panic!("Failed test #{i}: {err_desc}\nTest vector:\t{tv:#?}"); } } } macro_rules! new_test { - ($name:ident, $test_name:expr, $hash:ty) => { + ($name:ident, $hash:ty) => { #[test] fn $name() { - let data = include_bytes!(concat!("data/", $test_name, ".blb")); - test::>(data); - test::>(data); + blobby::parse_into_structs!( + include_bytes!(concat!("data/", stringify!($name), ".blb")); + static TEST_VECTORS: &[TestVector { ikm, salt, info, okm }]; + ); + + test::>(TEST_VECTORS); + test::>(TEST_VECTORS); } }; } -new_test!(wycheproof_sha1, "wycheproof-sha1", sha1::Sha1); -new_test!(wycheproof_sha256, "wycheproof-sha256", sha2::Sha256); -new_test!(wycheproof_sha384, "wycheproof-sha384", sha2::Sha384); -new_test!(wycheproof_sha512, "wycheproof-sha512", sha2::Sha512); +new_test!(wycheproof_sha1, sha1::Sha1); +new_test!(wycheproof_sha256, sha2::Sha256); +new_test!(wycheproof_sha384, sha2::Sha384); +new_test!(wycheproof_sha512, sha2::Sha512);