diff --git a/belt-mac/tests/data/belt-mac.blb b/belt-mac/tests/data/belt_mac_stb.blb similarity index 64% rename from belt-mac/tests/data/belt-mac.blb rename to belt-mac/tests/data/belt_mac_stb.blb index 7544b30..0593330 100644 Binary files a/belt-mac/tests/data/belt-mac.blb and b/belt-mac/tests/data/belt_mac_stb.blb differ diff --git a/belt-mac/tests/mod.rs b/belt-mac/tests/mod.rs index 3fa317d..45fd9bb 100644 --- a/belt-mac/tests/mod.rs +++ b/belt-mac/tests/mod.rs @@ -1,6 +1,7 @@ -//! Test vectors. +//! Test vectors from STB 34.101.31-2020: +//! -//use belt_mac::BeltMac; +use belt_mac::BeltMac; +use digest::dev::reset_mac_test; -// TODO(tarcieri): update tests to support RustCrypto/traits#1916 -// digest::new_resettable_mac_test!(belt_mac_stb, "belt-mac", BeltMac, "left"); +digest::new_mac_test!(belt_mac_stb, BeltMac, reset_mac_test, trunc_left); diff --git a/cmac/tests/cavp_large.rs b/cmac/tests/cavp_large.rs index 6b0e990..f151bdb 100644 --- a/cmac/tests/cavp_large.rs +++ b/cmac/tests/cavp_large.rs @@ -1,15 +1,15 @@ //! Tests from CAVP (excluding all 64 KiB vectors for AES-128 except the first one): //! +//! +//! Test vectors in this file use 64 KiB of data, so they are excluded from published packages. -// use aes::Aes128; -// use cmac::Cmac; +use aes::Aes128; +use cmac::Cmac; +use digest::dev::reset_mac_test; -// -// Test vectors in this file use 64 KiB of data, so they are excluded from published packages. -// TODO(tarcieri): update tests to support RustCrypto/traits#1916 -// digest::new_resettable_mac_test!( -// cmac_aes128_cavp, -// "cavp_aes128_large", -// Cmac, -// trunc_left -// ); +digest::new_mac_test!( + cmac_aes128_cavp_large, + Cmac, + reset_mac_test, + trunc_left, +); diff --git a/cmac/tests/data/aes192.blb b/cmac/tests/data/aes192.blb deleted file mode 100644 index 09ee9d4..0000000 Binary files a/cmac/tests/data/aes192.blb and /dev/null differ diff --git a/cmac/tests/data/aes256.blb b/cmac/tests/data/aes256.blb deleted file mode 100644 index ec5b834..0000000 Binary files a/cmac/tests/data/aes256.blb and /dev/null differ diff --git a/cmac/tests/data/cavp_aes128.blb b/cmac/tests/data/cmac_aes128_cavp.blb similarity index 98% rename from cmac/tests/data/cavp_aes128.blb rename to cmac/tests/data/cmac_aes128_cavp.blb index 07b511d..2e1c2d8 100644 Binary files a/cmac/tests/data/cavp_aes128.blb and b/cmac/tests/data/cmac_aes128_cavp.blb differ diff --git a/cmac/tests/data/cavp_aes128_large.blb b/cmac/tests/data/cmac_aes128_cavp_large.blb similarity index 99% rename from cmac/tests/data/cavp_aes128_large.blb rename to cmac/tests/data/cmac_aes128_cavp_large.blb index 669606f..78f6d50 100644 Binary files a/cmac/tests/data/cavp_aes128_large.blb and b/cmac/tests/data/cmac_aes128_cavp_large.blb differ diff --git a/cmac/tests/data/aes128.blb b/cmac/tests/data/cmac_aes128_nist.blb similarity index 69% rename from cmac/tests/data/aes128.blb rename to cmac/tests/data/cmac_aes128_nist.blb index ed39d51..f7ed9a7 100644 Binary files a/cmac/tests/data/aes128.blb and b/cmac/tests/data/cmac_aes128_nist.blb differ diff --git a/cmac/tests/data/wycheproof-aes128.blb b/cmac/tests/data/cmac_aes128_wycheproof.blb similarity index 77% rename from cmac/tests/data/wycheproof-aes128.blb rename to cmac/tests/data/cmac_aes128_wycheproof.blb index dfde593..ab09cc5 100644 Binary files a/cmac/tests/data/wycheproof-aes128.blb and b/cmac/tests/data/cmac_aes128_wycheproof.blb differ diff --git a/cmac/tests/data/cavp_aes192.blb b/cmac/tests/data/cmac_aes192_cavp.blb similarity index 97% rename from cmac/tests/data/cavp_aes192.blb rename to cmac/tests/data/cmac_aes192_cavp.blb index 921f68a..de68390 100644 Binary files a/cmac/tests/data/cavp_aes192.blb and b/cmac/tests/data/cmac_aes192_cavp.blb differ diff --git a/cmac/tests/data/cmac_aes192_nist.blb b/cmac/tests/data/cmac_aes192_nist.blb new file mode 100644 index 0000000..a01370c Binary files /dev/null and b/cmac/tests/data/cmac_aes192_nist.blb differ diff --git a/cmac/tests/data/wycheproof-aes192.blb b/cmac/tests/data/cmac_aes192_wycheproof.blb similarity index 86% rename from cmac/tests/data/wycheproof-aes192.blb rename to cmac/tests/data/cmac_aes192_wycheproof.blb index cb21624..e61a5ba 100644 Binary files a/cmac/tests/data/wycheproof-aes192.blb and b/cmac/tests/data/cmac_aes192_wycheproof.blb differ diff --git a/cmac/tests/data/cavp_aes256.blb b/cmac/tests/data/cmac_aes256_cavp.blb similarity index 99% rename from cmac/tests/data/cavp_aes256.blb rename to cmac/tests/data/cmac_aes256_cavp.blb index bd51d82..f7d92c4 100644 Binary files a/cmac/tests/data/cavp_aes256.blb and b/cmac/tests/data/cmac_aes256_cavp.blb differ diff --git a/cmac/tests/data/cmac_aes256_nist.blb b/cmac/tests/data/cmac_aes256_nist.blb new file mode 100644 index 0000000..6c69080 Binary files /dev/null and b/cmac/tests/data/cmac_aes256_nist.blb differ diff --git a/cmac/tests/data/wycheproof-aes256.blb b/cmac/tests/data/cmac_aes256_wycheproof.blb similarity index 75% rename from cmac/tests/data/wycheproof-aes256.blb rename to cmac/tests/data/cmac_aes256_wycheproof.blb index 1502473..4423260 100644 Binary files a/cmac/tests/data/wycheproof-aes256.blb and b/cmac/tests/data/cmac_aes256_wycheproof.blb differ diff --git a/cmac/tests/data/cmac_kuznyechik_gost.blb b/cmac/tests/data/cmac_kuznyechik_gost.blb new file mode 100644 index 0000000..49747f9 Binary files /dev/null and b/cmac/tests/data/cmac_kuznyechik_gost.blb differ diff --git a/cmac/tests/data/cmac_magma_gost.blb b/cmac/tests/data/cmac_magma_gost.blb new file mode 100644 index 0000000..7bdb6ac Binary files /dev/null and b/cmac/tests/data/cmac_magma_gost.blb differ diff --git a/cmac/tests/data/cavp_tdes2.blb b/cmac/tests/data/cmac_tdes2_cavp.blb similarity index 99% rename from cmac/tests/data/cavp_tdes2.blb rename to cmac/tests/data/cmac_tdes2_cavp.blb index df3ecd1..be67ab4 100644 Binary files a/cmac/tests/data/cavp_tdes2.blb and b/cmac/tests/data/cmac_tdes2_cavp.blb differ diff --git a/cmac/tests/data/cavp_tdes3.blb b/cmac/tests/data/cmac_tdes3_cavp.blb similarity index 99% rename from cmac/tests/data/cavp_tdes3.blb rename to cmac/tests/data/cmac_tdes3_cavp.blb index 5f44305..60deaa6 100644 Binary files a/cmac/tests/data/cavp_tdes3.blb and b/cmac/tests/data/cmac_tdes3_cavp.blb differ diff --git a/cmac/tests/data/kuznyechik.blb b/cmac/tests/data/kuznyechik.blb deleted file mode 100644 index 660fba2..0000000 Binary files a/cmac/tests/data/kuznyechik.blb and /dev/null differ diff --git a/cmac/tests/data/magma.blb b/cmac/tests/data/magma.blb deleted file mode 100644 index c787d90..0000000 Binary files a/cmac/tests/data/magma.blb and /dev/null differ diff --git a/cmac/tests/mod.rs b/cmac/tests/mod.rs index bfc9021..11e0e66 100644 --- a/cmac/tests/mod.rs +++ b/cmac/tests/mod.rs @@ -1,37 +1,33 @@ //! Test vectors. -// use aes::{Aes128, Aes192, Aes256}; -// use cmac::Cmac; -// use des::{TdesEde2, TdesEde3}; -// use digest::new_resettable_mac_test; -// use kuznyechik::Kuznyechik; -// use magma::Magma; +use aes::{Aes128, Aes192, Aes256}; +use cmac::Cmac; +use des::{TdesEde2, TdesEde3}; +use digest::{dev::reset_mac_test, new_mac_test}; +use kuznyechik::Kuznyechik; +use magma::Magma; // Tests from NIST SP 800-38B: // https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/ -// TODO(tarcieri): update tests to support RustCrypto/traits#1916 -// new_resettable_mac_test!(cmac_aes128_nist, "aes128", Cmac); -// new_resettable_mac_test!(cmac_aes192_nist, "aes192", Cmac); -// new_resettable_mac_test!(cmac_aes256_nist, "aes256", Cmac); +new_mac_test!(cmac_aes128_nist, Cmac, reset_mac_test); +new_mac_test!(cmac_aes192_nist, Cmac, reset_mac_test); +new_mac_test!(cmac_aes256_nist, Cmac, reset_mac_test); // Tests from CAVP (excluding all 64 KiB vectors for AES-128 except the first one): // https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES -// TODO(tarcieri): update tests to support RustCrypto/traits#1916 -// new_resettable_mac_test!(cmac_aes128_cavp, "cavp_aes128", Cmac, trunc_left); -// new_resettable_mac_test!(cmac_aes192_cavp, "cavp_aes192", Cmac, trunc_left); -// new_resettable_mac_test!(cmac_aes256_cavp, "cavp_aes256", Cmac, trunc_left); -// new_resettable_mac_test!(cmac_tdes2_cavp, "cavp_tdes2", Cmac, trunc_left); -// new_resettable_mac_test!(cmac_tdes3_cavp, "cavp_tdes3", Cmac, trunc_left); +new_mac_test!(cmac_aes128_cavp, Cmac, reset_mac_test, trunc_left); +new_mac_test!(cmac_aes192_cavp, Cmac, reset_mac_test, trunc_left); +new_mac_test!(cmac_aes256_cavp, Cmac, reset_mac_test, trunc_left); +new_mac_test!(cmac_tdes2_cavp, Cmac, reset_mac_test, trunc_left); +new_mac_test!(cmac_tdes3_cavp, Cmac, reset_mac_test, trunc_left); // Tests from Project Wycheproof: // https://github.com/google/wycheproof -// TODO(tarcieri): update tests to support RustCrypto/traits#1916 -// new_resettable_mac_test!(cmac_aes128_wycheproof, "wycheproof-aes128", Cmac); -// new_resettable_mac_test!(cmac_aes192_wycheproof, "wycheproof-aes192", Cmac); -// new_resettable_mac_test!(cmac_aes256_wycheproof, "wycheproof-aes256", Cmac); +new_mac_test!(cmac_aes128_wycheproof, Cmac, reset_mac_test); +new_mac_test!(cmac_aes192_wycheproof, Cmac, reset_mac_test); +new_mac_test!(cmac_aes256_wycheproof, Cmac, reset_mac_test); // Test from GOST R 34.13-2015: // https://tc26.ru/standard/gost/GOST_R_3413-2015.pdf -// TODO(tarcieri): update tests to support RustCrypto/traits#1916 -// new_resettable_mac_test!(cmac_kuznyechik_gost, "kuznyechik", Cmac); -// new_resettable_mac_test!(cmac_magma_gost, "magma", Cmac); +new_mac_test!(cmac_kuznyechik_gost, Cmac, reset_mac_test); +new_mac_test!(cmac_magma_gost, Cmac, reset_mac_test); diff --git a/hmac/tests/data/md5.blb b/hmac/tests/data/hmac_md5_rfc2104.blb similarity index 62% rename from hmac/tests/data/md5.blb rename to hmac/tests/data/hmac_md5_rfc2104.blb index 731a0ae..967b59f 100644 Binary files a/hmac/tests/data/md5.blb and b/hmac/tests/data/hmac_md5_rfc2104.blb differ diff --git a/hmac/tests/data/wycheproof-sha1.blb b/hmac/tests/data/hmac_sha1_wycheproof.blb similarity index 94% rename from hmac/tests/data/wycheproof-sha1.blb rename to hmac/tests/data/hmac_sha1_wycheproof.blb index a4f8f43..133a5cc 100644 Binary files a/hmac/tests/data/wycheproof-sha1.blb and b/hmac/tests/data/hmac_sha1_wycheproof.blb differ diff --git a/hmac/tests/data/sha224.blb b/hmac/tests/data/hmac_sha224_rfc4231.blb similarity index 62% rename from hmac/tests/data/sha224.blb rename to hmac/tests/data/hmac_sha224_rfc4231.blb index dabb20b..1bfa421 100644 Binary files a/hmac/tests/data/sha224.blb and b/hmac/tests/data/hmac_sha224_rfc4231.blb differ diff --git a/hmac/tests/data/sha256.blb b/hmac/tests/data/hmac_sha256_rfc4231.blb similarity index 61% rename from hmac/tests/data/sha256.blb rename to hmac/tests/data/hmac_sha256_rfc4231.blb index 6b5b288..66e1816 100644 Binary files a/hmac/tests/data/sha256.blb and b/hmac/tests/data/hmac_sha256_rfc4231.blb differ diff --git a/hmac/tests/data/wycheproof-sha256.blb b/hmac/tests/data/hmac_sha256_wycheproof.blb similarity index 93% rename from hmac/tests/data/wycheproof-sha256.blb rename to hmac/tests/data/hmac_sha256_wycheproof.blb index 62f1d35..591b8fd 100644 Binary files a/hmac/tests/data/wycheproof-sha256.blb and b/hmac/tests/data/hmac_sha256_wycheproof.blb differ diff --git a/hmac/tests/data/sha384.blb b/hmac/tests/data/hmac_sha384_rfc4231.blb similarity index 66% rename from hmac/tests/data/sha384.blb rename to hmac/tests/data/hmac_sha384_rfc4231.blb index d5cddb3..868b892 100644 Binary files a/hmac/tests/data/sha384.blb and b/hmac/tests/data/hmac_sha384_rfc4231.blb differ diff --git a/hmac/tests/data/wycheproof-sha384.blb b/hmac/tests/data/hmac_sha384_wycheproof.blb similarity index 97% rename from hmac/tests/data/wycheproof-sha384.blb rename to hmac/tests/data/hmac_sha384_wycheproof.blb index 69a7874..1b24e76 100644 Binary files a/hmac/tests/data/wycheproof-sha384.blb and b/hmac/tests/data/hmac_sha384_wycheproof.blb differ diff --git a/hmac/tests/data/sha512.blb b/hmac/tests/data/hmac_sha512_rfc4231.blb similarity index 75% rename from hmac/tests/data/sha512.blb rename to hmac/tests/data/hmac_sha512_rfc4231.blb index b79ae49..c278f9e 100644 Binary files a/hmac/tests/data/sha512.blb and b/hmac/tests/data/hmac_sha512_rfc4231.blb differ diff --git a/hmac/tests/data/wycheproof-sha512.blb b/hmac/tests/data/hmac_sha512_wycheproof.blb similarity index 99% rename from hmac/tests/data/wycheproof-sha512.blb rename to hmac/tests/data/hmac_sha512_wycheproof.blb index e061fd5..f2e3790 100644 Binary files a/hmac/tests/data/wycheproof-sha512.blb and b/hmac/tests/data/hmac_sha512_wycheproof.blb differ diff --git a/hmac/tests/data/streebog256.blb b/hmac/tests/data/hmac_streebog256_gost.blb similarity index 83% rename from hmac/tests/data/streebog256.blb rename to hmac/tests/data/hmac_streebog256_gost.blb index 99d9722..4cec3d5 100644 Binary files a/hmac/tests/data/streebog256.blb and b/hmac/tests/data/hmac_streebog256_gost.blb differ diff --git a/hmac/tests/data/streebog512.blb b/hmac/tests/data/hmac_streebog512_gost.blb similarity index 88% rename from hmac/tests/data/streebog512.blb rename to hmac/tests/data/hmac_streebog512_gost.blb index 8f0f151..ef212f0 100644 Binary files a/hmac/tests/data/streebog512.blb and b/hmac/tests/data/hmac_streebog512_gost.blb differ diff --git a/hmac/tests/mod.rs b/hmac/tests/mod.rs index 58f1b51..d81bc7e 100644 --- a/hmac/tests/mod.rs +++ b/hmac/tests/mod.rs @@ -1,59 +1,82 @@ //! Test vectors. -macro_rules! test { - ($mod_name:ident, $test_name:expr, $hash:ty $(, $t:ident)?) => { - mod $mod_name { - // TODO(tarcieri): update tests to support RustCrypto/traits#1916 - // digest::new_mac_test!(hmac, $test_name, hmac::Hmac<$hash> $(, $t)?); - // digest::new_mac_test!(simple_hmac, $test_name, hmac::SimpleHmac<$hash> $(, $t)?); - // digest::new_resettable_mac_test!( - // hmac_reset, - // $test_name, - // hmac::HmacReset<$hash> - // $(, $t)? - // ); - // digest::new_resettable_mac_test!( - // simple_reset_hmac, - // $test_name, - // hmac::SimpleHmacReset<$hash> - // $(, $t)? - // ); +macro_rules! new_test { + ($name:ident, $digest:ty $(,)?) => { + new_test!($name, $digest, digest::dev::MacTruncSide::None); + }; + ($name:ident, $digest:ty, trunc_left $(,)?) => { + new_test!($name, $digest, digest::dev::MacTruncSide::Left); + }; + ($name:ident, $digest:ty, $trunc:expr $(,)?) => { + #[test] + fn $name() { + use digest::dev::{MacTestVector, mac_test, reset_mac_test}; + + digest::dev::blobby::parse_into_structs!( + include_bytes!(concat!("data/", stringify!($name), ".blb")); + static TEST_VECTORS: &[MacTestVector { key, input, tag }]; + ); + + type Hmac = hmac::Hmac<$digest>; + type HmacReset = hmac::HmacReset<$digest>; + type SimpleHmac = hmac::SimpleHmac<$digest>; + type SimpleHmacReset = hmac::SimpleHmacReset<$digest>; + + for (i, tv) in TEST_VECTORS.iter().enumerate() { + if let Err(reason) = mac_test::(tv, $trunc) { + panic!( + "\n\ + Failed `Hmac` test #{i}\n\ + reason:\t{reason:?}\n\ + test vector:\t{tv:?}\n" + ); + } + if let Err(reason) = reset_mac_test::(tv, $trunc) { + panic!( + "\n\ + Failed `HmacReset` test #{i}\n\ + reason:\t{reason:?}\n\ + test vector:\t{tv:?}\n" + ); + } + if let Err(reason) = mac_test::(tv, $trunc) { + panic!( + "\n\ + Failed `SimpleHmac` test #{i}\n\ + reason:\t{reason:?}\n\ + test vector:\t{tv:?}\n" + ); + } + if let Err(reason) = reset_mac_test::(tv, $trunc) { + panic!( + "\n\ + Failed `SimpleHmacReset` test #{i}\n\ + reason:\t{reason:?}\n\ + test vector:\t{tv:?}\n" + ); + } + } } }; } -// Test vectors from RFC 2104, plus wiki test -test!(md5_rfc2104, "md5", md5::Md5); +// Test vectors from RFC 2104, plus Wikipedia test +new_test!(hmac_md5_rfc2104, md5::Md5); // Test vectors from RFC 4231 -test!(sha224_rfc4231, "sha224", sha2::Sha224); -test!(sha256_rfc4231, "sha256", sha2::Sha256); -test!(sha384_rfc4231, "sha384", sha2::Sha384); -test!(sha512_rfc4231, "sha512", sha2::Sha512); +new_test!(hmac_sha224_rfc4231, sha2::Sha224); +new_test!(hmac_sha256_rfc4231, sha2::Sha256); +new_test!(hmac_sha384_rfc4231, sha2::Sha384); +new_test!(hmac_sha512_rfc4231, sha2::Sha512); // Test vectors from R 50.1.113-2016: // https://tc26.ru/standard/rs/Р%2050.1.113-2016.pdf -test!(treebog256, "streebog256", streebog::Streebog256); -test!(streebog512, "streebog512", streebog::Streebog512); +new_test!(hmac_streebog256_gost, streebog::Streebog256); +new_test!(hmac_streebog512_gost, streebog::Streebog512); // Tests from Project Wycheproof: // https://github.com/google/wycheproof -test!(sha1_wycheproof, "wycheproof-sha1", sha1::Sha1, trunc_left); -test!( - sha256_wycheproof, - "wycheproof-sha256", - sha2::Sha256, - trunc_left -); -test!( - sha384_wycheproof, - "wycheproof-sha384", - sha2::Sha384, - trunc_left -); -test!( - sha512_wycheproof, - "wycheproof-sha512", - sha2::Sha512, - trunc_left -); +new_test!(hmac_sha1_wycheproof, sha1::Sha1, trunc_left); +new_test!(hmac_sha256_wycheproof, sha2::Sha256, trunc_left); +new_test!(hmac_sha384_wycheproof, sha2::Sha384, trunc_left); +new_test!(hmac_sha512_wycheproof, sha2::Sha512, trunc_left); diff --git a/pmac/tests/data/aes128.blb b/pmac/tests/data/pmac_aes128.blb similarity index 98% rename from pmac/tests/data/aes128.blb rename to pmac/tests/data/pmac_aes128.blb index 0c9bc77..dd8dbe1 100644 Binary files a/pmac/tests/data/aes128.blb and b/pmac/tests/data/pmac_aes128.blb differ diff --git a/pmac/tests/data/aes192.blb b/pmac/tests/data/pmac_aes192.blb similarity index 98% rename from pmac/tests/data/aes192.blb rename to pmac/tests/data/pmac_aes192.blb index 5add08d..d72869d 100644 Binary files a/pmac/tests/data/aes192.blb and b/pmac/tests/data/pmac_aes192.blb differ diff --git a/pmac/tests/data/aes256.blb b/pmac/tests/data/pmac_aes256.blb similarity index 98% rename from pmac/tests/data/aes256.blb rename to pmac/tests/data/pmac_aes256.blb index 77a8864..7642050 100644 Binary files a/pmac/tests/data/aes256.blb and b/pmac/tests/data/pmac_aes256.blb differ diff --git a/pmac/tests/mod.rs b/pmac/tests/mod.rs index e2f25c4..4f53f4c 100644 --- a/pmac/tests/mod.rs +++ b/pmac/tests/mod.rs @@ -1,11 +1,9 @@ -//! Test vectors. +//! Test vectors from: -// use aes::{Aes128, Aes192, Aes256}; -// use digest::new_resettable_mac_test; -// use pmac::Pmac; +use aes::{Aes128, Aes192, Aes256}; +use digest::{dev::reset_mac_test, new_mac_test}; +use pmac::Pmac; -// Test vectors from: http://web.cs.ucdavis.edu/~rogaway/ocb/pmac-test.htm -// TODO(tarcieri): update tests to support RustCrypto/traits#1916 -// new_resettable_mac_test!(pmac_aes128, "aes128", Pmac); -// new_resettable_mac_test!(pmac_aes192, "aes192", Pmac); -// new_resettable_mac_test!(pmac_aes256, "aes256", Pmac); +new_mac_test!(pmac_aes128, Pmac, reset_mac_test); +new_mac_test!(pmac_aes192, Pmac, reset_mac_test); +new_mac_test!(pmac_aes256, Pmac, reset_mac_test);