diff --git a/.gitignore b/.gitignore index 2c39f9c..92c58dc 100755 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ evercrypt_provider/target no-std-support-check/target rust_crypto_provider/target traits/target/ +hpke-rs-tests/target .DS_Store /.idea diff --git a/Cargo.toml b/Cargo.toml index d312891..41b83f7 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ std = [] serialization = ["serde", "tls_codec", "tls_codec/serde", "std"] hazmat = [] hpke-test = ["std"] -hpke-test-prng = [] # ⚠️ Enable testing PRNG - DO NOT USE +hpke-test-prng = [] # ⚠️ Enable testing PRNG - DO NOT USE [dev-dependencies] hpke-rs-crypto = { version = "0.2.0", path = "./traits", features = ["std"] } @@ -38,6 +38,7 @@ hpke-rs-rust-crypto = { version = "0.2.0", path = "./rust_crypto_provider", feat rand = { version = "0.8" } pretty_env_logger = "0.5" criterion = { version = "0.5", features = ["html_reports"] } +hpke-rs-tests = { path = "./hpke-rs-tests", version = "*" } [[bench]] name = "bench" diff --git a/hpke-rs-tests/Cargo.toml b/hpke-rs-tests/Cargo.toml new file mode 100644 index 0000000..78be72c --- /dev/null +++ b/hpke-rs-tests/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "hpke-rs-tests" +version = "0.1.0" +authors = ["Cryspen"] +edition = "2021" +license = "MPL-2.0" +readme = "Readme.md" +description = "Tests for crypto providers" +repository = "https://github.com/cryspen/hpke-rs" + +[dependencies] +hpke-rs = { version = "0.2.0", features = [ + "hazmat", + "serialization", + "hpke-test", +], path = "../" } +hpke-rs-crypto = { version = "0.2.0", path = "../traits" } +serde_json = "1.0" +serde = { version = "1.0", features = ["derive"] } +rayon = "1.5" +log = "0.4" +pretty_env_logger = "0.5" + +[features] +prng = ["hpke-rs/hpke-test-prng"] diff --git a/hpke-rs-tests/Readme.md b/hpke-rs-tests/Readme.md new file mode 100644 index 0000000..0774a57 --- /dev/null +++ b/hpke-rs-tests/Readme.md @@ -0,0 +1,24 @@ +# Tests for Crypto Providers + +This crate exposes macros that define crypto provider test functions. + +## Usage + +```rust +struct MyCryptoProvider; + +impl hpke_rs_crypto::CryptoProvider for MyCryptoProvider { + // ... +} + +#[cfg(tests)] +mod tests { + // the tests names are close to the spec and don't follow rust conventions + #![allow(non_snake_case)] + + use super::MyCryptoProvider; + + hpke_rs_tests::test_funs!(MyCryptoProvider); + hpke_rs_tests::kat_fun!(MyCryptoProvider); +} +``` \ No newline at end of file diff --git a/hpke-rs-tests/src/lib.rs b/hpke-rs-tests/src/lib.rs new file mode 100644 index 0000000..63a025c --- /dev/null +++ b/hpke-rs-tests/src/lib.rs @@ -0,0 +1,9 @@ +pub mod test_hpke; +pub mod test_hpke_kat; + +pub use hpke_rs; +pub use hpke_rs_crypto; +pub use serde; +pub use serde_json; + +mod util; diff --git a/tests/test_hpke.rs b/hpke-rs-tests/src/test_hpke.rs similarity index 65% rename from tests/test_hpke.rs rename to hpke-rs-tests/src/test_hpke.rs index 03e8b99..e80b073 100644 --- a/tests/test_hpke.rs +++ b/hpke-rs-tests/src/test_hpke.rs @@ -2,48 +2,104 @@ extern crate hpke_rs as hpke; -use hpke::prelude::*; -use hpke_rs_crypto::{ - types::{AeadAlgorithm, KdfAlgorithm, KemAlgorithm}, - HpkeCrypto, RngCore, -}; -// use hpke_rs_evercrypt::HpkeEvercrypt; -use hpke_rs_rust_crypto::HpkeRustCrypto; -use lazy_static::lazy_static; +use hpke_rs_crypto::RngCore as _; -lazy_static! { - static ref TEST_CASES: Vec<(Mode, KemAlgorithm, KdfAlgorithm, AeadAlgorithm)> = { - let mut tests = Vec::new(); - for mode in 0u8..4 { - let hpke_mode = Mode::try_from(mode).unwrap(); - for aead_mode in 1u16..4 { - let aead_mode = AeadAlgorithm::try_from(aead_mode).unwrap(); - for kdf_mode in 1u16..4 { - let kdf_mode = KdfAlgorithm::try_from(kdf_mode).unwrap(); - for &kem_mode in &[0x10u16, 0x20] { - let kem_mode = KemAlgorithm::try_from(kem_mode).unwrap(); - tests.push((hpke_mode, kem_mode, kdf_mode, aead_mode)); - println!( - "generate_test_case!({}, HpkeMode::{:?}, KemAlgorithm::{:?}, KdfAlgorithm::{:?}, AeadAlgorithm::{:?});", - Hpke::::new(hpke_mode, kem_mode, kdf_mode, aead_mode), - hpke_mode, - kem_mode, - kdf_mode, - aead_mode - ); - } - } +#[macro_export] +macro_rules! test_funs { + ( $provider:ty, [ $($test_names:ident),+ $(,)?]) => { + $( + #[test] + fn $test_names() { + $crate::test_hpke::$test_names::<$provider>() } - } - tests + )+ + }; + ($provider:ty) => { + $crate::test_funs!($provider, [ + base_dhkemp256_hkdfsha256_Aes128Gcm, + base_dhkem25519_hkdfsha256_Aes128Gcm, + base_dhkemp256_hkdfsha384_Aes128Gcm, + base_dhkem25519_hkdfsha384_Aes128Gcm, + base_dhkemp256_hkdfsha512_Aes128Gcm, + base_dhkem25519_hkdfsha512_Aes128Gcm, + base_dhkemp256_hkdfsha256_Aes256Gcm, + base_dhkem25519_hkdfsha256_Aes256Gcm, + base_dhkemp256_hkdfsha384_Aes256Gcm, + base_dhkem25519_hkdfsha384_Aes256Gcm, + base_dhkemp256_hkdfsha512_Aes256Gcm, + base_dhkem25519_hkdfsha512_Aes256Gcm, + base_dhkemp256_hkdfsha256_chacha20poly1305, + base_dhkem25519_hkdfsha256_chacha20poly1305, + base_dhkemp256_hkdfsha384_chacha20poly1305, + base_dhkem25519_hkdfsha384_chacha20poly1305, + base_dhkemp256_hkdfsha512_chacha20poly1305, + base_dhkem25519_hkdfsha512_chacha20poly1305, + psk_dhkemp256_hkdfsha256_Aes128Gcm, + psk_dhkem25519_hkdfsha256_Aes128Gcm, + psk_dhkemp256_hkdfsha384_Aes128Gcm, + psk_dhkem25519_hkdfsha384_Aes128Gcm, + psk_dhkemp256_hkdfsha512_Aes128Gcm, + psk_dhkem25519_hkdfsha512_Aes128Gcm, + psk_dhkemp256_hkdfsha256_Aes256Gcm, + psk_dhkem25519_hkdfsha256_Aes256Gcm, + psk_dhkemp256_hkdfsha384_Aes256Gcm, + psk_dhkem25519_hkdfsha384_Aes256Gcm, + psk_dhkemp256_hkdfsha512_Aes256Gcm, + psk_dhkem25519_hkdfsha512_Aes256Gcm, + psk_dhkemp256_hkdfsha256_chacha20poly1305, + psk_dhkem25519_hkdfsha256_chacha20poly1305, + psk_dhkemp256_hkdfsha384_chacha20poly1305, + psk_dhkem25519_hkdfsha384_chacha20poly1305, + psk_dhkemp256_hkdfsha512_chacha20poly1305, + psk_dhkem25519_hkdfsha512_chacha20poly1305, + auth_dhkemp256_hkdfsha256_Aes128Gcm, + auth_dhkem25519_hkdfsha256_Aes128Gcm, + auth_dhkemp256_hkdfsha384_Aes128Gcm, + auth_dhkem25519_hkdfsha384_Aes128Gcm, + auth_dhkemp256_hkdfsha512_Aes128Gcm, + auth_dhkem25519_hkdfsha512_Aes128Gcm, + auth_dhkemp256_hkdfsha256_Aes256Gcm, + auth_dhkem25519_hkdfsha256_Aes256Gcm, + auth_dhkemp256_hkdfsha384_Aes256Gcm, + auth_dhkem25519_hkdfsha384_Aes256Gcm, + auth_dhkemp256_hkdfsha512_Aes256Gcm, + auth_dhkem25519_hkdfsha512_Aes256Gcm, + auth_dhkemp256_hkdfsha256_chacha20poly1305, + auth_dhkem25519_hkdfsha256_chacha20poly1305, + auth_dhkemp256_hkdfsha384_chacha20poly1305, + auth_dhkem25519_hkdfsha384_chacha20poly1305, + auth_dhkemp256_hkdfsha512_chacha20poly1305, + auth_dhkem25519_hkdfsha512_chacha20poly1305, + authpsk_dhkemp256_hkdfsha256_Aes128Gcm, + authpsk_dhkem25519_hkdfsha256_Aes128Gcm, + authpsk_dhkemp256_hkdfsha384_Aes128Gcm, + authpsk_dhkem25519_hkdfsha384_Aes128Gcm, + authpsk_dhkemp256_hkdfsha512_Aes128Gcm, + authpsk_dhkem25519_hkdfsha512_Aes128Gcm, + authpsk_dhkemp256_hkdfsha256_Aes256Gcm, + authpsk_dhkem25519_hkdfsha256_Aes256Gcm, + authpsk_dhkemp256_hkdfsha384_Aes256Gcm, + authpsk_dhkem25519_hkdfsha384_Aes256Gcm, + authpsk_dhkemp256_hkdfsha512_Aes256Gcm, + authpsk_dhkem25519_hkdfsha512_Aes256Gcm, + authpsk_dhkemp256_hkdfsha256_chacha20poly1305, + authpsk_dhkem25519_hkdfsha256_chacha20poly1305, + authpsk_dhkemp256_hkdfsha384_chacha20poly1305, + authpsk_dhkem25519_hkdfsha384_chacha20poly1305, + authpsk_dhkemp256_hkdfsha512_chacha20poly1305, + authpsk_dhkem25519_hkdfsha512_chacha20poly1305 + ]); }; } macro_rules! generate_test_case { - ($name:ident, $hpke_mode:expr, $kem_mode:expr, $kdf_mode:expr, $aead_mode:expr, $provider:ident) => { - #[test] - fn $name() { - let mut hpke = Hpke::<$provider>::new($hpke_mode, $kem_mode, $kdf_mode, $aead_mode); + ($name:ident, $hpke_mode:expr, $kem_mode:expr, $kdf_mode:expr, $aead_mode:expr) => { + pub fn $name() { + use ::core::option::Option; + use $crate::hpke_rs::prelude::{Hpke, HpkeMode}; + use $crate::hpke_rs_crypto::types::{AeadAlgorithm, KdfAlgorithm, KemAlgorithm}; + + let mut hpke = Hpke::::new($hpke_mode, $kem_mode, $kdf_mode, $aead_mode); println!("Self test {}", hpke); // Self test seal and open with random keys. @@ -54,16 +110,16 @@ macro_rules! generate_test_case { let plain_txt = b"HPKE self test plain text"; let exporter_context = b"HPKE self test exporter context"; let mut psk = [0u8; 32]; - $provider::prng().fill_bytes(&mut psk); + Crypto::prng().fill_bytes(&mut psk); let mut psk_id = [0u8; 32]; - $provider::prng().fill_bytes(&mut psk_id); + Crypto::prng().fill_bytes(&mut psk_id); let (psk, psk_id): (Option<&[u8]>, Option<&[u8]>) = match $hpke_mode { - Mode::Base | Mode::Auth => (None, None), - Mode::Psk | Mode::AuthPsk => (Some(&psk), Some(&psk_id)), + HpkeMode::Base | HpkeMode::Auth => (None, None), + HpkeMode::Psk | HpkeMode::AuthPsk => (Some(&psk), Some(&psk_id)), }; let (sk_s_option, pk_s_option) = match $hpke_mode { - Mode::Auth | Mode::AuthPsk => (Some(&sk_s), Some(&pk_s)), - Mode::Psk | Mode::Base => (None, None), + HpkeMode::Auth | HpkeMode::AuthPsk => (Some(&sk_s), Some(&pk_s)), + HpkeMode::Psk | HpkeMode::Base => (None, None), }; let (enc, ctxt) = hpke .seal(&pk_r, info, aad, plain_txt, psk, psk_id, sk_s_option) @@ -118,590 +174,502 @@ generate_test_case!( HpkeMode::Base, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( base_dhkem25519_hkdfsha256_Aes128Gcm, HpkeMode::Base, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( base_dhkemp256_hkdfsha384_Aes128Gcm, HpkeMode::Base, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( base_dhkem25519_hkdfsha384_Aes128Gcm, HpkeMode::Base, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( base_dhkemp256_hkdfsha512_Aes128Gcm, HpkeMode::Base, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( base_dhkem25519_hkdfsha512_Aes128Gcm, HpkeMode::Base, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( base_dhkemp256_hkdfsha256_Aes256Gcm, HpkeMode::Base, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( base_dhkem25519_hkdfsha256_Aes256Gcm, HpkeMode::Base, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( base_dhkemp256_hkdfsha384_Aes256Gcm, HpkeMode::Base, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( base_dhkem25519_hkdfsha384_Aes256Gcm, HpkeMode::Base, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( base_dhkemp256_hkdfsha512_Aes256Gcm, HpkeMode::Base, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( base_dhkem25519_hkdfsha512_Aes256Gcm, HpkeMode::Base, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( base_dhkemp256_hkdfsha256_chacha20poly1305, HpkeMode::Base, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto -); -// generate_test_case!( -// base_dhkemp256_hkdfsha256_chacha20poly1305_evercrypt, -// HpkeMode::Base, -// KemAlgorithm::DhKemP256, -// KdfAlgorithm::HkdfSha256, -// AeadAlgorithm::ChaCha20Poly1305, -// HpkeEvercrypt -// ); + AeadAlgorithm::ChaCha20Poly1305 +); generate_test_case!( base_dhkem25519_hkdfsha256_chacha20poly1305, HpkeMode::Base, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto -); -// generate_test_case!( -// base_dhkem25519_hkdfsha256_chacha20poly1305_evercrypt, -// HpkeMode::Base, -// KemAlgorithm::DhKem25519, -// KdfAlgorithm::HkdfSha256, -// AeadAlgorithm::ChaCha20Poly1305, -// HpkeEvercrypt -// ); + AeadAlgorithm::ChaCha20Poly1305 +); generate_test_case!( base_dhkemp256_hkdfsha384_chacha20poly1305, HpkeMode::Base, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( base_dhkem25519_hkdfsha384_chacha20poly1305, HpkeMode::Base, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( base_dhkemp256_hkdfsha512_chacha20poly1305, HpkeMode::Base, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( base_dhkem25519_hkdfsha512_chacha20poly1305, HpkeMode::Base, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( psk_dhkemp256_hkdfsha256_Aes128Gcm, HpkeMode::Psk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( psk_dhkem25519_hkdfsha256_Aes128Gcm, HpkeMode::Psk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( psk_dhkemp256_hkdfsha384_Aes128Gcm, HpkeMode::Psk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( psk_dhkem25519_hkdfsha384_Aes128Gcm, HpkeMode::Psk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( psk_dhkemp256_hkdfsha512_Aes128Gcm, HpkeMode::Psk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( psk_dhkem25519_hkdfsha512_Aes128Gcm, HpkeMode::Psk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( psk_dhkemp256_hkdfsha256_Aes256Gcm, HpkeMode::Psk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( psk_dhkem25519_hkdfsha256_Aes256Gcm, HpkeMode::Psk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( psk_dhkemp256_hkdfsha384_Aes256Gcm, HpkeMode::Psk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( psk_dhkem25519_hkdfsha384_Aes256Gcm, HpkeMode::Psk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( psk_dhkemp256_hkdfsha512_Aes256Gcm, HpkeMode::Psk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( psk_dhkem25519_hkdfsha512_Aes256Gcm, HpkeMode::Psk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( psk_dhkemp256_hkdfsha256_chacha20poly1305, HpkeMode::Psk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( psk_dhkem25519_hkdfsha256_chacha20poly1305, HpkeMode::Psk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( psk_dhkemp256_hkdfsha384_chacha20poly1305, HpkeMode::Psk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( psk_dhkem25519_hkdfsha384_chacha20poly1305, HpkeMode::Psk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( psk_dhkemp256_hkdfsha512_chacha20poly1305, HpkeMode::Psk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( psk_dhkem25519_hkdfsha512_chacha20poly1305, HpkeMode::Psk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( auth_dhkemp256_hkdfsha256_Aes128Gcm, HpkeMode::Auth, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( auth_dhkem25519_hkdfsha256_Aes128Gcm, HpkeMode::Auth, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( auth_dhkemp256_hkdfsha384_Aes128Gcm, HpkeMode::Auth, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( auth_dhkem25519_hkdfsha384_Aes128Gcm, HpkeMode::Auth, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( auth_dhkemp256_hkdfsha512_Aes128Gcm, HpkeMode::Auth, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( auth_dhkem25519_hkdfsha512_Aes128Gcm, HpkeMode::Auth, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( auth_dhkemp256_hkdfsha256_Aes256Gcm, HpkeMode::Auth, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( auth_dhkem25519_hkdfsha256_Aes256Gcm, HpkeMode::Auth, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( auth_dhkemp256_hkdfsha384_Aes256Gcm, HpkeMode::Auth, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( auth_dhkem25519_hkdfsha384_Aes256Gcm, HpkeMode::Auth, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( auth_dhkemp256_hkdfsha512_Aes256Gcm, HpkeMode::Auth, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( auth_dhkem25519_hkdfsha512_Aes256Gcm, HpkeMode::Auth, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( auth_dhkemp256_hkdfsha256_chacha20poly1305, HpkeMode::Auth, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( auth_dhkem25519_hkdfsha256_chacha20poly1305, HpkeMode::Auth, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( auth_dhkemp256_hkdfsha384_chacha20poly1305, HpkeMode::Auth, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( auth_dhkem25519_hkdfsha384_chacha20poly1305, HpkeMode::Auth, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( auth_dhkemp256_hkdfsha512_chacha20poly1305, HpkeMode::Auth, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( auth_dhkem25519_hkdfsha512_chacha20poly1305, HpkeMode::Auth, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( authpsk_dhkemp256_hkdfsha256_Aes128Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( authpsk_dhkem25519_hkdfsha256_Aes128Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( authpsk_dhkemp256_hkdfsha384_Aes128Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( authpsk_dhkem25519_hkdfsha384_Aes128Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( authpsk_dhkemp256_hkdfsha512_Aes128Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( authpsk_dhkem25519_hkdfsha512_Aes128Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes128Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes128Gcm ); generate_test_case!( authpsk_dhkemp256_hkdfsha256_Aes256Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( authpsk_dhkem25519_hkdfsha256_Aes256Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( authpsk_dhkemp256_hkdfsha384_Aes256Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( authpsk_dhkem25519_hkdfsha384_Aes256Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( authpsk_dhkemp256_hkdfsha512_Aes256Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( authpsk_dhkem25519_hkdfsha512_Aes256Gcm, HpkeMode::AuthPsk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::Aes256Gcm, - HpkeRustCrypto + AeadAlgorithm::Aes256Gcm ); generate_test_case!( authpsk_dhkemp256_hkdfsha256_chacha20poly1305, HpkeMode::AuthPsk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( authpsk_dhkem25519_hkdfsha256_chacha20poly1305, HpkeMode::AuthPsk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha256, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( authpsk_dhkemp256_hkdfsha384_chacha20poly1305, HpkeMode::AuthPsk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( authpsk_dhkem25519_hkdfsha384_chacha20poly1305, HpkeMode::AuthPsk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha384, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( authpsk_dhkemp256_hkdfsha512_chacha20poly1305, HpkeMode::AuthPsk, KemAlgorithm::DhKemP256, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); generate_test_case!( authpsk_dhkem25519_hkdfsha512_chacha20poly1305, HpkeMode::AuthPsk, KemAlgorithm::DhKem25519, KdfAlgorithm::HkdfSha512, - AeadAlgorithm::ChaCha20Poly1305, - HpkeRustCrypto + AeadAlgorithm::ChaCha20Poly1305 ); diff --git a/tests/test_hpke_kat.rs b/hpke-rs-tests/src/test_hpke_kat.rs similarity index 67% rename from tests/test_hpke_kat.rs rename to hpke-rs-tests/src/test_hpke_kat.rs index 8a736be..4615991 100755 --- a/tests/test_hpke_kat.rs +++ b/hpke-rs-tests/src/test_hpke_kat.rs @@ -1,21 +1,19 @@ -extern crate hpke_rs as hpke; - -// use hpke_rs_evercrypt::HpkeEvercrypt; -use hpke_rs_rust_crypto::HpkeRustCrypto; -use rayon::iter::{IntoParallelIterator, ParallelIterator}; -use serde::{self, Deserialize, Serialize}; use std::convert::TryInto; -use std::fs::File; -use std::io::BufReader; use std::time::Instant; -use hpke::prelude::*; -use hpke::test_util::{hex_to_bytes, hex_to_bytes_option, vec_to_option_slice}; +use rayon::iter::{IntoParallelIterator, ParallelIterator}; +use serde::{Deserialize, Serialize}; + +use hpke_rs::prelude::{Hpke, HpkeMode, HpkePrivateKey, HpkePublicKey}; use hpke_rs_crypto::{types::*, HpkeCrypto}; +use crate::util::{hex_to_bytes, hex_to_bytes_option, vec_to_option_slice}; + +static TEST_JSON: &[u8] = include_bytes!("test_vectors.json"); + #[derive(Serialize, Deserialize, Debug, Clone)] #[allow(non_snake_case)] -struct HpkeTestVector { +pub struct HpkeTestVector { mode: u8, kem_id: u16, kdf_id: u16, @@ -60,15 +58,17 @@ struct ExportsKAT { exported_value: String, } -fn kat(tests: Vec) { +pub fn kat(tests: Vec) { tests.into_par_iter().for_each(|test| { let mode: HpkeMode = test.mode.try_into().unwrap(); let kem_id: KemAlgorithm = test.kem_id.try_into().unwrap(); let kdf_id: KdfAlgorithm = test.kdf_id.try_into().unwrap(); let aead_id: AeadAlgorithm = test.aead_id.try_into().unwrap(); + let ciphersuite_string = format!("{mode}/{kem_id}/{kdf_id}/{aead_id}"); + if Crypto::supports_kem(kem_id).is_err() { - log::trace!( + println!( " > KEM {:?} not implemented yet for {}", kem_id, Crypto::name() @@ -77,7 +77,7 @@ fn kat(tests: Vec) { } if Crypto::supports_aead(aead_id).is_err() { - log::trace!( + println!( " > AEAD {:?} not implemented yet for {}", aead_id, Crypto::name() @@ -86,7 +86,7 @@ fn kat(tests: Vec) { } if Crypto::supports_kdf(kdf_id).is_err() { - log::trace!( + println!( " > KDF {:?} not implemented yet for {}", kdf_id, Crypto::name() @@ -94,12 +94,9 @@ fn kat(tests: Vec) { return; } - log::trace!( + println!( "Testing mode {:?} with ciphersuite {:?}_{:?}_{:?}", - mode, - kem_id, - kdf_id, - aead_id + mode, kem_id, kdf_id, aead_id ); // Init HPKE with the given mode and ciphersuite. @@ -147,7 +144,7 @@ fn kat(tests: Vec) { psk.unwrap_or_default(), psk_id.unwrap_or_default(), ) - .unwrap(); + .unwrap_or_else(|err| panic!("key schedule failed with {ciphersuite_string}: {err}")); // Check setup info // Note that key and nonce are empty for exporter only key derivation. @@ -165,22 +162,28 @@ fn kat(tests: Vec) { assert_eq!(pk_em, my_pk_e); if let (Some(sk_sm), Some(pk_sm)) = (sk_sm, pk_sm) { let (my_sk_s, my_pk_s) = hpke.derive_key_pair(&ikm_s).unwrap().into_keys(); - assert_eq!(sk_sm, &my_sk_s); - assert_eq!(pk_sm, &my_pk_s); + assert_eq!( + sk_sm, &my_sk_s, + "derive key returned different sks for {ciphersuite_string}" + ); + assert_eq!( + pk_sm, &my_pk_s, + "derive key returned different pks for {ciphersuite_string}" + ); } // Setup KAT receiver. let kat_enc = hex_to_bytes(&test.enc); let mut receiver_context_kat = hpke .setup_receiver(&kat_enc, &sk_rm, &info, psk, psk_id, pk_sm) - .unwrap(); + .unwrap_or_else(|err| panic!("setup_receiver failed for {ciphersuite_string}: {err}")); // Setup sender and receiver with KAT randomness. // We first have to inject the randomness (ikmE). - #[cfg(feature = "hpke-test-prng")] + #[cfg(feature = "prng")] { - log::trace!("Testing with known ikmE ..."); + println!("Testing with known ikmE ..."); let mut hpke_sender = Hpke::::new(mode, kem_id, kdf_id, aead_id); // This only works when seeding the PRNG with ikmE. hpke_sender.seed(&ikm_e).expect("Error injecting ikm_e"); @@ -223,7 +226,9 @@ fn kat(tests: Vec) { // Test context API self-test let ctxt_out = sender_context.seal(&aad, &ptxt).unwrap(); - let ptxt_out = receiver_context.open(&aad, &ctxt_out).unwrap(); + let ptxt_out = receiver_context + .open(&aad, &ctxt_out) + .unwrap_or_else(|err| panic!("open failed for {ciphersuite_string}: {err}")); assert_eq!(ptxt_out, ptxt); // Test single-shot API self-test @@ -257,80 +262,78 @@ fn kat(tests: Vec) { }); } -#[test] -fn test_kat() { - let _ = pretty_env_logger::try_init(); - let file = "tests/test_vectors.json"; - let file = match File::open(file) { - Ok(f) => f, - Err(_) => panic!("Couldn't open file {}.", file), - }; - let reader = BufReader::new(file); - let tests: Vec = match serde_json::from_reader(reader) { +pub fn test_kat() { + let mut reader = TEST_JSON; + let tests: Vec = match serde_json::from_reader(&mut reader) { Ok(r) => r, Err(e) => panic!("Error reading file.\n{:?}", e), }; let now = Instant::now(); - kat::(tests.clone()); + kat::(tests.clone()); let time = now.elapsed(); - log::info!("Test vectors with Rust Crypto took: {}s", time.as_secs()); - - // let now = Instant::now(); - // kat::(tests); - // let time = now.elapsed(); - // log::info!("Test vectors with Evercrypt took: {}s", time.as_secs()); + log::info!( + "Test vectors with {} took: {}s", + Crypto::name(), + time.as_secs() + ); } -#[cfg(feature = "serialization")] -#[cfg(feature = "hazmat")] -#[test] -fn test_serialization() { - use hpke::HpkeKeyPair; - - // XXX: Make these individual tests. - for mode in 0u8..4 { - let hpke_mode = HpkeMode::try_from(mode).unwrap(); - for aead_mode in 1u16..4 { - let aead_mode = AeadAlgorithm::try_from(aead_mode).unwrap(); - for kdf_mode in 1u16..4 { - let kdf_mode = KdfAlgorithm::try_from(kdf_mode).unwrap(); - for &kem_mode in &[0x10u16, 0x20] { - let kem_mode = KemAlgorithm::try_from(kem_mode).unwrap(); - - let mut hpke = - Hpke::::new(hpke_mode, kem_mode, kdf_mode, aead_mode); - - // JSON: Public, Private, KeyPair - let key_pair = hpke.generate_key_pair().unwrap(); - - let serialized_key_pair = serde_json::to_string(&key_pair).unwrap(); - let deserialized_key_pair: HpkeKeyPair = - serde_json::from_str(&serialized_key_pair).unwrap(); - - let (sk, pk) = key_pair.into_keys(); - - let serialized_sk = serde_json::to_string(&sk).unwrap(); - let deserialized_sk: HpkePrivateKey = - serde_json::from_str(&serialized_sk).unwrap(); - let serialized_pk = serde_json::to_string(&pk).unwrap(); - let deserialized_pk: HpkePublicKey = - serde_json::from_str(&serialized_pk).unwrap(); - - let (des_sk, des_pk) = deserialized_key_pair.into_keys(); - - assert_eq!(pk, des_pk); - assert_eq!(pk, deserialized_pk); - assert_eq!(sk.as_slice(), des_sk.as_slice()); - assert_eq!(sk.as_slice(), deserialized_sk.as_slice()); +#[macro_export] +macro_rules! kat_fun { + ($provider:ty) => { + #[test] + fn test_kat() { + $crate::test_hpke_kat::test_kat::<$provider>(); + } + + #[test] + fn test_serialization() { + use $crate::hpke_rs::prelude::{ + Hpke, HpkeKeyPair, HpkeMode, HpkePrivateKey, HpkePublicKey, + }; + use $crate::hpke_rs_crypto::types::{AeadAlgorithm, KdfAlgorithm, KemAlgorithm}; + use $crate::serde_json; + + // XXX: Make these individual tests. + for mode in 0u8..4 { + let hpke_mode = HpkeMode::try_from(mode).unwrap(); + for aead_mode in 1u16..4 { + let aead_mode = AeadAlgorithm::try_from(aead_mode).unwrap(); + for kdf_mode in 1u16..4 { + let kdf_mode = KdfAlgorithm::try_from(kdf_mode).unwrap(); + for &kem_mode in &[0x10u16, 0x20] { + let kem_mode = KemAlgorithm::try_from(kem_mode).unwrap(); + + let mut hpke = + Hpke::<$provider>::new(hpke_mode, kem_mode, kdf_mode, aead_mode); + + // JSON: Public, Private, KeyPair + let key_pair = hpke.generate_key_pair().unwrap(); + + let serialized_key_pair = serde_json::to_string(&key_pair).unwrap(); + let deserialized_key_pair: HpkeKeyPair = + serde_json::from_str(&serialized_key_pair).unwrap(); + + let (sk, pk) = key_pair.into_keys(); + + let serialized_sk = serde_json::to_string(&sk).unwrap(); + let deserialized_sk: HpkePrivateKey = + serde_json::from_str(&serialized_sk).unwrap(); + let serialized_pk = serde_json::to_string(&pk).unwrap(); + let deserialized_pk: HpkePublicKey = + serde_json::from_str(&serialized_pk).unwrap(); + + let (des_sk, des_pk) = deserialized_key_pair.into_keys(); + + assert_eq!(pk, des_pk); + assert_eq!(pk, deserialized_pk); + assert_eq!(sk.as_slice(), des_sk.as_slice()); + assert_eq!(sk.as_slice(), deserialized_sk.as_slice()); + } + } } } } - } - - // let mode: Mode = Mode::Base; - // let kem_id: kem::Mode = kem::Mode::DhKemP256; - // let kdf_id: kdf::Mode = kdf::Mode::HkdfSha256; - // let aead_id: aead::Mode = aead::Mode::AesGcm128; - // let hpke = Hpke::new(mode, kem_id, kdf_id, aead_id); + }; } diff --git a/tests/test_vectors.json b/hpke-rs-tests/src/test_vectors.json similarity index 100% rename from tests/test_vectors.json rename to hpke-rs-tests/src/test_vectors.json diff --git a/hpke-rs-tests/src/util.rs b/hpke-rs-tests/src/util.rs new file mode 100644 index 0000000..2c2b998 --- /dev/null +++ b/hpke-rs-tests/src/util.rs @@ -0,0 +1,28 @@ +/// Convert a hex string to a byte vector. +pub fn hex_to_bytes(hex: &str) -> Vec { + assert!(hex.len() % 2 == 0); + let mut bytes = Vec::new(); + for i in 0..(hex.len() / 2) { + bytes.push(u8::from_str_radix(&hex[2 * i..2 * i + 2], 16).unwrap()); + } + bytes +} + +/// Convert a hex string to a byte vector. +/// If the input is `None`, this returns an empty vector. +pub fn hex_to_bytes_option(hex: Option) -> Vec { + match hex { + Some(s) => hex_to_bytes(&s), + None => vec![], + } +} + +/// Convert a byte slice into byte slice option. +/// Returns `Nonce` if the byte slice is empty and `Some(v)` otherwise. +pub fn vec_to_option_slice(v: &[u8]) -> Option<&[u8]> { + if v.is_empty() { + None + } else { + Some(v) + } +} diff --git a/rust_crypto_provider/Cargo.toml b/rust_crypto_provider/Cargo.toml index e46dcb8..7fcd9be 100644 --- a/rust_crypto_provider/Cargo.toml +++ b/rust_crypto_provider/Cargo.toml @@ -31,6 +31,7 @@ rand_chacha = { version = "0.3", default-features = false } [dev-dependencies] criterion = { version = "0.5", features = ["html_reports"] } rand = { version = "0.8" } +hpke-rs-tests = { path = "../hpke-rs-tests/" } [features] deterministic-prng = [ diff --git a/rust_crypto_provider/tests/hpke-rs-tests.rs b/rust_crypto_provider/tests/hpke-rs-tests.rs new file mode 100644 index 0000000..cdcb4b0 --- /dev/null +++ b/rust_crypto_provider/tests/hpke-rs-tests.rs @@ -0,0 +1,6 @@ +#![allow(non_snake_case)] + +use hpke_rs_tests::{kat_fun, test_funs}; + +test_funs!(hpke_rs_rust_crypto::HpkeRustCrypto); +kat_fun!(hpke_rs_rust_crypto::HpkeRustCrypto); diff --git a/tests/hpke.rs b/tests/hpke.rs new file mode 100644 index 0000000..cdcb4b0 --- /dev/null +++ b/tests/hpke.rs @@ -0,0 +1,6 @@ +#![allow(non_snake_case)] + +use hpke_rs_tests::{kat_fun, test_funs}; + +test_funs!(hpke_rs_rust_crypto::HpkeRustCrypto); +kat_fun!(hpke_rs_rust_crypto::HpkeRustCrypto);