Skip to content

Commit 27e4444

Browse files
committed
ascon-aead: zeroize buffer during decryption on failed tag check
1 parent 843c3f9 commit 27e4444

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

ascon-aead/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 0.4.3 (2025-03-03)
8+
### Fixed
9+
- Zeroize buffer during decryption on failed tag check ([#659])
10+
11+
[#659]: https://github.com/RustCrypto/AEADs/pull/659
12+
713
## 0.4.2 (2023-03-21)
814
### Changed
915
- Drop MSRV back to 1.56 and keep it in sync with `ascon` ([#514])

ascon-aead/src/asconcore.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ impl<'a, P: Parameters> AsconCore<'a, P> {
360360
if bool::from(tag.ct_eq(expected_tag)) {
361361
Ok(())
362362
} else {
363+
ciphertext.fill(0);
363364
Err(Error)
364365
}
365366
}

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)