Skip to content

Commit

Permalink
test(aegis_128l): add wycheproof tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codahale committed Dec 8, 2023
1 parent eee3791 commit de97de7
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ expect-test = "1.4.1"
hex = "0.4.3"
hex-literal = "0.4.1"
rand = "0.8.5"
wycheproof = "0.5.1"

[package.metadata.docs.rs]
all-features = true
Expand Down
25 changes: 25 additions & 0 deletions src/aegis_128l.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ mod tests {

use expect_test::expect;
use hex_literal::hex;
use wycheproof::aead::{TestName, TestSet};
use wycheproof::TestResult;

fn encrypt(key: &[u8; 16], nonce: &[u8; 16], mc: &mut [u8], ad: &[u8]) -> ([u8; 16], [u8; 32]) {
let mut state = Aegis128L::new(key, nonce);
Expand Down Expand Up @@ -547,4 +549,27 @@ mod tests {
},
);
}

#[test]
fn wycheproof() {
let set = TestSet::load(TestName::Aegis128L).expect("should have AEGIS-128L test vectors");
for group in set.test_groups {
for test in group.tests {
let mut ct = test.pt.to_vec();
let (short_tag, _long_tag) = encrypt(
&test.key.as_ref().try_into().expect("should be 16 bytes"),
&test.nonce.as_ref().try_into().expect("should be 16 bytes"),
&mut ct,
&test.aad,
);

if test.result == TestResult::Valid {
assert_eq!(test.ct.as_ref(), &ct);
assert_eq!(test.tag.as_ref(), &short_tag);
} else {
assert_ne!(test.tag.as_ref(), &short_tag);
}
}
}
}
}

0 comments on commit de97de7

Please sign in to comment.