in aws-lc-rs/src/aead.rs [1024:1072]
fn test_aes_128() {
let key = from_hex("000102030405060708090a0b0c0d0e0f").unwrap();
let og_nonce = from_hex("5bf11a0951f0bfc7ea5c9e58").unwrap();
let plaintext = from_hex("00112233445566778899aabbccddeeff").unwrap();
let unbound_key = UnboundKey::new(&AES_128_GCM, &key).unwrap();
assert_eq!(&AES_128_GCM, unbound_key.algorithm());
assert_eq!(16, AES_128_GCM.tag_len());
assert_eq!(12, AES_128_GCM.nonce_len());
let less_safe_key = LessSafeKey::new(unbound_key);
let nonce: [u8; NONCE_LEN] = og_nonce.as_slice().try_into().unwrap();
let mut in_out = Vec::from(plaintext.as_slice());
#[allow(deprecated)]
less_safe_key
// Test coverage for `seal_in_place`, which calls `seal_in_place_append_tag`.
.seal_in_place(Nonce(FixedLength::from(nonce)), Aad::empty(), &mut in_out)
.unwrap();
let mut in_out_clone = in_out.clone();
let nonce: [u8; NONCE_LEN] = og_nonce.as_slice().try_into().unwrap();
assert!(less_safe_key
.open_in_place(
Nonce(FixedLength::from(nonce)),
Aad::from("test"),
&mut in_out_clone
)
.is_err());
let mut in_out_clone = in_out.clone();
let mut nonce: [u8; NONCE_LEN] = og_nonce.as_slice().try_into().unwrap();
nonce[0] = 0;
assert!(less_safe_key
.open_in_place(
Nonce(FixedLength::from(nonce)),
Aad::empty(),
&mut in_out_clone
)
.is_err());
let nonce: [u8; NONCE_LEN] = og_nonce.as_slice().try_into().unwrap();
less_safe_key
.open_in_place(Nonce(FixedLength::from(nonce)), Aad::empty(), &mut in_out)
.unwrap();
assert_eq!(plaintext, in_out[..plaintext.len()]);
}