Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ascon-aead: zeroize buffer during decryption on failed tag check #659

Merged
merged 6 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .github/workflows/benches.yml

This file was deleted.

4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ascon-aead/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.4.3 (2025-03-03)
### Fixed
- Zeroize buffer during decryption on failed tag check ([#659])

[#659]: https://github.com/RustCrypto/AEADs/pull/659

## 0.4.2 (2023-03-21)
### Changed
- Drop MSRV back to 1.56 and keep it in sync with `ascon` ([#514])
Expand Down
2 changes: 2 additions & 0 deletions ascon-aead/src/asconcore.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2021-2023 Sebastian Ramacher
// SPDX-License-Identifier: Apache-2.0 OR MIT
#![allow(unknown_lints, non_local_definitions)]

use aead::{
consts::{U16, U20},
Expand Down Expand Up @@ -360,6 +361,7 @@ impl<'a, P: Parameters> AsconCore<'a, P> {
if bool::from(tag.ct_eq(expected_tag)) {
Ok(())
} else {
ciphertext.fill(0);
Err(Error)
}
}
Expand Down
12 changes: 10 additions & 2 deletions ascon-aead/tests/kats_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2022 Sebastian Ramacher
// SPDX-License-Identifier: Apache-2.0 OR MIT

use aead::Tag;
use ascon_aead::{
aead::{Aead, AeadInPlace, KeyInit, Payload},
Ascon128, Ascon128a, Ascon80pq, Key, Nonce,
Expand Down Expand Up @@ -41,9 +42,10 @@ impl TestVector {

fn run_tv<A: KeyInit + AeadInPlace>(tv: TestVector) {
let core = A::new(Key::<A>::from_slice(&tv.key));
let nonce = Nonce::<A>::from_slice(&tv.nonce);
asserting(format!("Test Vector {} encryption", tv.count).as_str())
.that(&core.encrypt(
Nonce::<A>::from_slice(&tv.nonce),
nonce,
Payload {
msg: &tv.plaintext,
aad: &tv.associated_data,
Expand All @@ -54,14 +56,20 @@ fn run_tv<A: KeyInit + AeadInPlace>(tv: TestVector) {

asserting(format!("Test Vector {} decryption", tv.count).as_str())
.that(&core.decrypt(
Nonce::<A>::from_slice(&tv.nonce),
nonce,
Payload {
msg: &tv.ciphertext,
aad: &tv.associated_data,
},
))
.is_ok()
.is_equal_to(&tv.plaintext);

let bad_tag = Tag::<A>::default();
let mut buf = tv.ciphertext[..tv.ciphertext.len() - bad_tag.len()].to_vec();
let res = core.decrypt_in_place_detached(nonce, &tv.associated_data, &mut buf, &bad_tag);
assert!(res.is_err());
assert!(buf.iter().all(|b| *b == 0));
}

fn parse_tvs(tvs: &str) -> Vec<TestVector> {
Expand Down
Loading