From 5acf7aba892156506efb199ac7aabb07b629e049 Mon Sep 17 00:00:00 2001 From: Coda Hale Date: Wed, 1 Nov 2023 20:02:40 -0600 Subject: [PATCH] test(aegis_128l): add interop test with aegis crate --- Cargo.lock | 17 +++++++++++++++++ Cargo.toml | 1 + src/aegis_128l.rs | 18 ++++++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 342f9815..5291f63f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,16 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aegis" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4b1b7dc75fb93f21b66a0d071e3f990dd1504df679b94c1f5e2417b57efaf45" +dependencies = [ + "cc", + "softaes", +] + [[package]] name = "aes" version = "0.8.3" @@ -388,6 +398,7 @@ checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" name = "lockstitch" version = "0.16.2" dependencies = [ + "aegis", "aes", "cmov", "expect-test", @@ -571,6 +582,12 @@ dependencies = [ "cc", ] +[[package]] +name = "softaes" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff744c5d37b8ff11721ef14e92d1ec8743b5419d81513b3df22346cbee3d9d3e" + [[package]] name = "strsim" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index 8e835a82..031e63cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ std = [] members = ["benchmarks", "xtask"] [dev-dependencies] +aegis = { version = "0.4.9", features = ["pure-rust"] } expect-test = "1.4.1" hex = "0.4.3" hex-literal = "0.4.1" diff --git a/src/aegis_128l.rs b/src/aegis_128l.rs index 8a8f2d5b..e1ee4e29 100644 --- a/src/aegis_128l.rs +++ b/src/aegis_128l.rs @@ -565,8 +565,8 @@ mod tests { k: [u8; 16], n: [u8; 16], ad in vec(any::(), 0..200), - msg in vec(any::(), 0..200)) { - + msg in vec(any::(), 0..200), + ) { let mut ct = msg.clone(); let tag_e = encrypt(&k, &n, &mut ct, &ad); let tag_d = decrypt(&k, &n, &mut ct, &ad); @@ -574,5 +574,19 @@ mod tests { prop_assert_eq!(msg, ct, "invalid plaintext"); prop_assert_eq!(tag_e, tag_d, "invalid tag"); } + + #[test] + fn interop( + k: [u8; 16], + n: [u8; 16], + ad in vec(any::(), 0..200), + msg in vec(any::(), 0..200), + ) { + let mut ct = msg.clone(); + let tag = encrypt(&k, &n, &mut ct, &ad); + + let aegis = aegis::aegis128l::Aegis128L::<32>::new(&k, &n); + prop_assert_eq!(Ok(msg), aegis.decrypt(&ct, &tag, &ad), "should decrypt successfully"); + } } }