Skip to content

Commit 9b4944f

Browse files
committed
Add zeroization test
1 parent 5bd3538 commit 9b4944f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ascon-aead/tests/kats_test.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2022 Sebastian Ramacher
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4+
use aead::Tag;
45
use ascon_aead::{
56
aead::{Aead, AeadInPlace, KeyInit, Payload},
67
Ascon128, Ascon128a, Ascon80pq, Key, Nonce,
@@ -41,9 +42,10 @@ impl TestVector {
4142

4243
fn run_tv<A: KeyInit + AeadInPlace>(tv: TestVector) {
4344
let core = A::new(Key::<A>::from_slice(&tv.key));
45+
let nonce = Nonce::<A>::from_slice(&tv.nonce);
4446
asserting(format!("Test Vector {} encryption", tv.count).as_str())
4547
.that(&core.encrypt(
46-
Nonce::<A>::from_slice(&tv.nonce),
48+
nonce,
4749
Payload {
4850
msg: &tv.plaintext,
4951
aad: &tv.associated_data,
@@ -54,14 +56,20 @@ fn run_tv<A: KeyInit + AeadInPlace>(tv: TestVector) {
5456

5557
asserting(format!("Test Vector {} decryption", tv.count).as_str())
5658
.that(&core.decrypt(
57-
Nonce::<A>::from_slice(&tv.nonce),
59+
nonce,
5860
Payload {
5961
msg: &tv.ciphertext,
6062
aad: &tv.associated_data,
6163
},
6264
))
6365
.is_ok()
6466
.is_equal_to(&tv.plaintext);
67+
68+
let bad_tag = Tag::<A>::default();
69+
let mut buf = tv.ciphertext[..tv.ciphertext.len() - bad_tag.len()].to_vec();
70+
let res = core.decrypt_in_place_detached(nonce, &tv.associated_data, &mut buf, &bad_tag);
71+
assert!(res.is_err());
72+
assert!(buf.iter().all(|b| *b == 0));
6573
}
6674

6775
fn parse_tvs(tvs: &str) -> Vec<TestVector> {

0 commit comments

Comments
 (0)