Also test AES-GCM decrypt and bad decrypt cases.

This commit is contained in:
Adam Ierymenko 2022-12-06 17:54:43 -05:00
parent 263900ae00
commit 57badb6e56

View file

@ -528,9 +528,22 @@ mod tests {
let mut ciphertext = Vec::new();
ciphertext.resize(tv.plaintext.len(), 0);
gcm.crypt(tv.plaintext, ciphertext.as_mut());
let tag = gcm.finish_encrypt();
let mut tag = gcm.finish_encrypt();
assert!(tag.eq(tv.tag));
assert!(ciphertext.as_slice().eq(tv.ciphertext));
let mut gcm = AesGcm::new(tv.key, false);
gcm.init(tv.nonce);
gcm.aad(tv.aad);
let mut ct_copy = ciphertext.clone();
gcm.crypt_in_place(ct_copy.as_mut());
assert!(gcm.finish_decrypt(&tag));
gcm.init(tv.nonce);
gcm.aad(tv.aad);
gcm.crypt_in_place(ciphertext.as_mut());
tag[0] ^= 1;
assert!(!gcm.finish_decrypt(&tag));
}
}