Skip to content

Commit 1bd4230

Browse files
committed
ascon-aead: implement tests with MockBuffer
1 parent 1116109 commit 1bd4230

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

ascon-aead/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ inout = { version = "0.2.0-rc.4", default-features = false }
2323

2424
[dev-dependencies]
2525
hex-literal = "0.4"
26-
aead = { version = "0.6.0-rc.0", features = ["alloc"] }
26+
aead = { version = "0.6.0-rc.0", features = ["alloc", "dev"] }
2727

2828
[features]
2929
default = ["alloc", "os_rng"]

ascon-aead/tests/kats_test.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use ascon_aead::{
55
AsconAead128,
6-
aead::{Aead, AeadInOut, KeyInit, Payload, Tag},
6+
aead::{Aead, AeadInOut, KeyInit, Payload, Tag, dev::MockBuffer},
77
};
88
use hex_literal::hex;
99

@@ -44,6 +44,24 @@ fn run_tv<A: KeyInit + Aead + AeadInOut>(
4444
core.decrypt_inout_detached(nonce, associated_data, buf.as_mut_slice().into(), &bad_tag);
4545
assert!(res.is_err());
4646
assert!(buf.iter().all(|b| *b == 0));
47+
48+
let mut buf = MockBuffer::from(&plaintext[..ciphertext.len() - bad_tag.len()]);
49+
let tag_encryption = core
50+
.encrypt_inout_detached(nonce, associated_data, buf.to_in_out_buf())
51+
.expect("encryption failed");
52+
assert_eq!(
53+
tag_encryption.as_slice(),
54+
&ciphertext[ciphertext.len() - bad_tag.len()..]
55+
);
56+
assert_eq!(
57+
buf.as_ref(),
58+
&ciphertext[..ciphertext.len() - bad_tag.len()]
59+
);
60+
61+
let mut buf = MockBuffer::from(&ciphertext[..ciphertext.len() - bad_tag.len()]);
62+
core.decrypt_inout_detached(nonce, associated_data, buf.to_in_out_buf(), &tag_encryption)
63+
.expect("decryption failed");
64+
assert_eq!(buf.as_ref(), plaintext);
4765
}
4866

4967
#[test]

0 commit comments

Comments
 (0)