Skip to content

Commit 50e4bdf

Browse files
committed
Add test for AES256 CCM with 12 byte nonce
1 parent 5095d7d commit 50e4bdf

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

openssl/src/symm.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,35 @@ mod tests {
15351535
assert_eq!(pt, hex::encode(out));
15361536
}
15371537

1538+
#[test]
1539+
#[cfg(not(boringssl))]
1540+
fn test_aes256_ccm_12_byte_nonce() {
1541+
// This tests that using an IV with the recommended length of 12 bytes
1542+
// works as expected.
1543+
let cipher = Cipher::aes_256_ccm();
1544+
assert_eq!(cipher.iv_len(), Some(12));
1545+
1546+
let key = Vec::from_hex("7f4af6765cad1d511db07e33aaafd57646ec279db629048aa6770af24849aa0d")
1547+
.unwrap();
1548+
let nonce = Vec::from_hex("dde2a362ce81b2b6913abc30").unwrap();
1549+
assert_eq!(nonce.len(), 12);
1550+
let aad = Vec::from_hex("404f5df97ece7431987bc098cce994fc3c063b519ffa47b0365226a0015ef695")
1551+
.unwrap();
1552+
1553+
let pt = Vec::from_hex("7ebef26bf4ecf6f0ebb2eb860edbf900f27b75b4a6340fdb").unwrap();
1554+
let ct = Vec::from_hex("9dc19f567998982177db86a985eeff5002df9c7812687fc2").unwrap();
1555+
let tag = Vec::from_hex("54f3a6a0ab9c4161e57cc1c4").unwrap();
1556+
1557+
let mut actual_tag = [0; 12];
1558+
let out = encrypt_aead(cipher, &key, Some(&nonce), &aad, &pt, &mut actual_tag).unwrap();
1559+
1560+
assert_eq!(ct, out);
1561+
assert_eq!(tag, actual_tag);
1562+
1563+
let out = decrypt_aead(cipher, &key, Some(&nonce), &aad, &ct, &tag).unwrap();
1564+
assert_eq!(pt, out);
1565+
}
1566+
15381567
#[test]
15391568
#[cfg(not(boringssl))]
15401569
fn test_aes256_ccm_verify_fail() {

0 commit comments

Comments
 (0)