Skip to content

Commit 4d428fe

Browse files
committed
use merged Aead trait
1 parent 1bd4230 commit 4d428fe

File tree

21 files changed

+61
-135
lines changed

21 files changed

+61
-135
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ resolver = "2"
1818
aead-stream = { path = "./aead-stream" }
1919
aes-gcm = { path = "./aes-gcm" }
2020

21-
aead = { git = "https://github.com/baloo/traits.git", branch = "baloo/aead/bicephalbuffer" }
22-
crypto-common = { git = "https://github.com/baloo/traits.git", branch = "baloo/aead/bicephalbuffer" }
21+
aead = { git = "https://github.com/baloo/traits.git", branch = "baloo/aead/mockbuffer-merge" }
22+
crypto-common = { git = "https://github.com/baloo/traits.git", branch = "baloo/aead/mockbuffer-merge" }
2323

2424
chacha20 = { git = "https://github.com/RustCrypto/stream-ciphers.git" }
2525

aead-stream/src/lib.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
extern crate alloc;
77

88
use aead::{
9-
AeadCore, AeadInPlace, Buffer, Error, Result,
9+
Aead, AeadCore, Buffer, Error, Result,
1010
array::{
1111
Array, ArraySize,
1212
typenum::{U4, U5, Unsigned},
@@ -32,7 +32,7 @@ pub type NonceSize<A, S> =
3232
/// Create a new STREAM from the provided AEAD.
3333
pub trait NewStream<A>: StreamPrimitive<A>
3434
where
35-
A: AeadInPlace,
35+
A: Aead,
3636
A::NonceSize: Sub<Self::NonceOverhead>,
3737
NonceSize<A, Self>: ArraySize,
3838
{
@@ -57,7 +57,7 @@ where
5757
/// Deliberately immutable and stateless to permit parallel operation.
5858
pub trait StreamPrimitive<A>
5959
where
60-
A: AeadInPlace,
60+
A: Aead,
6161
A::NonceSize: Sub<Self::NonceOverhead>,
6262
NonceSize<A, Self>: ArraySize,
6363
{
@@ -165,7 +165,7 @@ macro_rules! impl_stream_object {
165165
#[derive(Debug)]
166166
pub struct $name<A, S>
167167
where
168-
A: AeadInPlace,
168+
A: Aead,
169169
S: StreamPrimitive<A>,
170170
A::NonceSize: Sub<<S as StreamPrimitive<A>>::NonceOverhead>,
171171
NonceSize<A, S>: ArraySize,
@@ -179,7 +179,7 @@ macro_rules! impl_stream_object {
179179

180180
impl<A, S> $name<A, S>
181181
where
182-
A: AeadInPlace,
182+
A: Aead,
183183
S: StreamPrimitive<A>,
184184
A::NonceSize: Sub<<S as StreamPrimitive<A>>::NonceOverhead>,
185185
NonceSize<A, S>: ArraySize,
@@ -344,7 +344,7 @@ pub type DecryptorLE31<A> = Decryptor<A, StreamLE31<A>>;
344344
#[derive(Debug)]
345345
pub struct StreamBE32<A>
346346
where
347-
A: AeadInPlace,
347+
A: Aead,
348348
A::NonceSize: Sub<U5>,
349349
<<A as AeadCore>::NonceSize as Sub<U5>>::Output: ArraySize,
350350
{
@@ -357,7 +357,7 @@ where
357357

358358
impl<A> NewStream<A> for StreamBE32<A>
359359
where
360-
A: AeadInPlace,
360+
A: Aead,
361361
A::NonceSize: Sub<U5>,
362362
<<A as AeadCore>::NonceSize as Sub<U5>>::Output: ArraySize,
363363
{
@@ -371,7 +371,7 @@ where
371371

372372
impl<A> StreamPrimitive<A> for StreamBE32<A>
373373
where
374-
A: AeadInPlace,
374+
A: Aead,
375375
A::NonceSize: Sub<U5>,
376376
<<A as AeadCore>::NonceSize as Sub<U5>>::Output: ArraySize,
377377
{
@@ -405,7 +405,7 @@ where
405405

406406
impl<A> StreamBE32<A>
407407
where
408-
A: AeadInPlace,
408+
A: Aead,
409409
A::NonceSize: Sub<U5>,
410410
<<A as AeadCore>::NonceSize as Sub<U5>>::Output: ArraySize,
411411
{
@@ -434,7 +434,7 @@ where
434434
#[derive(Debug)]
435435
pub struct StreamLE31<A>
436436
where
437-
A: AeadInPlace,
437+
A: Aead,
438438
A::NonceSize: Sub<U4>,
439439
<<A as AeadCore>::NonceSize as Sub<U4>>::Output: ArraySize,
440440
{
@@ -447,7 +447,7 @@ where
447447

448448
impl<A> NewStream<A> for StreamLE31<A>
449449
where
450-
A: AeadInPlace,
450+
A: Aead,
451451
A::NonceSize: Sub<U4>,
452452
<<A as AeadCore>::NonceSize as Sub<U4>>::Output: ArraySize,
453453
{
@@ -461,7 +461,7 @@ where
461461

462462
impl<A> StreamPrimitive<A> for StreamLE31<A>
463463
where
464-
A: AeadInPlace,
464+
A: Aead,
465465
A::NonceSize: Sub<U4>,
466466
<<A as AeadCore>::NonceSize as Sub<U4>>::Output: ArraySize,
467467
{
@@ -495,7 +495,7 @@ where
495495

496496
impl<A> StreamLE31<A>
497497
where
498-
A: AeadInPlace,
498+
A: Aead,
499499
A::NonceSize: Sub<U4>,
500500
<<A as AeadCore>::NonceSize as Sub<U4>>::Output: ArraySize,
501501
{

aes-gcm-siv/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ categories = ["cryptography", "no-std"]
1717
rust-version = "1.85"
1818

1919
[dependencies]
20-
aead = { version = "0.6.0-rc.0", default-features = false, features = ["inout"] }
20+
aead = { version = "0.6.0-rc.0", default-features = false }
2121
aes = { version = "=0.9.0-pre.3", optional = true }
2222
cipher = "=0.5.0-pre.8"
2323
ctr = "0.10.0-pre.2"

aes-gcm-siv/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
//! This crate has an optional `alloc` feature which can be disabled in e.g.
3535
//! microcontroller environments that don't have a heap.
3636
//!
37-
//! The [`AeadInPlace::encrypt_in_place`] and [`AeadInPlace::decrypt_in_place`]
37+
//! The [`Aead::encrypt_in_place`] and [`Aead::decrypt_in_place`]
3838
//! methods accept any type that impls the [`aead::Buffer`] trait which
3939
//! contains the plaintext for encryption or ciphertext for decryption.
4040
//!
@@ -48,7 +48,7 @@
4848
#![cfg_attr(not(all(feature = "os_rng", feature = "heapless")), doc = "```ignore")]
4949
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
5050
//! use aes_gcm_siv::{
51-
//! aead::{AeadInPlace, KeyInit, rand_core::OsRng, heapless::Vec},
51+
//! aead::{Aead, KeyInit, rand_core::OsRng, heapless::Vec},
5252
//! Aes256GcmSiv, Nonce, // Or `Aes128GcmSiv`
5353
//! };
5454
//!
@@ -83,7 +83,7 @@ pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser};
8383
#[cfg(feature = "aes")]
8484
pub use aes;
8585

86-
use aead::{PostfixTagged, inout::InOutBuf};
86+
use aead::{TagPosition, inout::InOutBuf};
8787
use cipher::{
8888
BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore,
8989
array::Array,
@@ -161,10 +161,9 @@ where
161161
{
162162
type NonceSize = U12;
163163
type TagSize = U16;
164+
const TAG_POSITION: TagPosition = TagPosition::Postfix;
164165
}
165166

166-
impl<Aes> PostfixTagged for AesGcmSiv<Aes> {}
167-
168167
impl<Aes> AeadInOut for AesGcmSiv<Aes>
169168
where
170169
Aes: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt + KeyInit,

aes-gcm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ categories = ["cryptography", "no-std"]
1717
rust-version = "1.85"
1818

1919
[dependencies]
20-
aead = { version = "0.6.0-rc.0", default-features = false, features = ["inout"] }
20+
aead = { version = "0.6.0-rc.0", default-features = false }
2121
aes = { version = "=0.9.0-pre.3", optional = true }
2222
cipher = "=0.5.0-pre.8"
2323
ctr = "0.10.0-pre.2"

aes-gcm/src/lib.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
//! This crate has an optional `alloc` feature which can be disabled in e.g.
5555
//! microcontroller environments that don't have a heap.
5656
//!
57-
//! The [`AeadInPlace::encrypt_in_place`] and [`AeadInPlace::decrypt_in_place`]
57+
//! The [`Aead::encrypt_in_place`] and [`Aead::decrypt_in_place`]
5858
//! methods accept any type that impls the [`aead::Buffer`] trait which
5959
//! contains the plaintext for encryption or ciphertext for decryption.
6060
//!
@@ -68,7 +68,7 @@
6868
#![cfg_attr(not(all(feature = "os_rng", feature = "heapless")), doc = "```ignore")]
6969
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
7070
//! use aes_gcm::{
71-
//! aead::{AeadCore, AeadInPlace, KeyInit, rand_core::OsRng, heapless::Vec},
71+
//! aead::{AeadCore, Aead, KeyInit, rand_core::OsRng, heapless::Vec},
7272
//! Aes256Gcm, Nonce, // Or `Aes128Gcm`
7373
//! };
7474
//!
@@ -103,7 +103,7 @@ pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser};
103103
#[cfg(feature = "aes")]
104104
pub use aes;
105105

106-
use aead::{PostfixTagged, inout::InOutBuf};
106+
use aead::{TagPosition, inout::InOutBuf};
107107

108108
use cipher::{
109109
BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore,
@@ -253,11 +253,7 @@ where
253253
{
254254
type NonceSize = NonceSize;
255255
type TagSize = TagSize;
256-
}
257-
258-
impl<Aes, NonceSize, TagSize> PostfixTagged for AesGcm<Aes, NonceSize, TagSize> where
259-
TagSize: self::TagSize
260-
{
256+
const TAG_POSITION: TagPosition = TagPosition::Postfix;
261257
}
262258

263259
impl<Aes, NonceSize, TagSize> AeadInOut for AesGcm<Aes, NonceSize, TagSize>

aes-siv/src/lib.rs

+5-37
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
//! This crate has an optional `alloc` feature which can be disabled in e.g.
3535
//! microcontroller environments that don't have a heap.
3636
//!
37-
//! The [`AeadInPlace::encrypt_in_place`] and [`AeadInPlace::decrypt_in_place`]
37+
//! The [`Aead::encrypt_in_place`] and [`Aead::decrypt_in_place`]
3838
//! methods accept any type that impls the [`aead::Buffer`] trait which
3939
//! contains the plaintext for encryption or ciphertext for decryption.
4040
//!
@@ -48,7 +48,7 @@
4848
#![cfg_attr(not(all(feature = "os_rng", feature = "heapless")), doc = "```ignore")]
4949
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
5050
//! use aes_siv::{
51-
//! aead::{AeadCore, AeadInPlace, KeyInit, rand_core::OsRng, heapless::Vec},
51+
//! aead::{AeadCore, Aead, KeyInit, rand_core::OsRng, heapless::Vec},
5252
//! Aes256SivAead, Nonce, // Or `Aes128SivAead`
5353
//! };
5454
//!
@@ -83,11 +83,11 @@ extern crate alloc;
8383

8484
pub mod siv;
8585

86-
pub use aead::{self, AeadCore, AeadInOut, AeadInPlace, Error, Key, KeyInit, KeySizeUser};
86+
pub use aead::{self, Aead, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser};
8787

8888
use crate::siv::Siv;
8989
use aead::{
90-
Buffer,
90+
TagPosition,
9191
array::Array,
9292
consts::{U1, U16, U32, U64},
9393
inout::InOutBuf,
@@ -205,39 +205,7 @@ where
205205
// https://tools.ietf.org/html/rfc5297#section-6
206206
type NonceSize = NonceSize;
207207
type TagSize = U16;
208-
}
209-
210-
impl<C, M, NonceSize> AeadInPlace for SivAead<C, M, NonceSize>
211-
where
212-
Self: KeySizeUser,
213-
Siv<C, M>: KeyInit + KeySizeUser<KeySize = <Self as KeySizeUser>::KeySize>,
214-
C: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt + KeyInit + KeySizeUser,
215-
M: Mac<OutputSize = U16> + FixedOutputReset + KeyInit,
216-
<C as KeySizeUser>::KeySize: Add,
217-
NonceSize: ArraySize + IsGreaterOrEqual<U1>,
218-
{
219-
fn encrypt_in_place(
220-
&self,
221-
nonce: &Array<u8, Self::NonceSize>,
222-
associated_data: &[u8],
223-
buffer: &mut dyn Buffer,
224-
) -> Result<(), Error> {
225-
// "SIV performs nonce-based authenticated encryption when a component of
226-
// the associated data is a nonce. For purposes of interoperability the
227-
// final component -- i.e., the string immediately preceding the
228-
// plaintext in the vector input to S2V -- is used for the nonce."
229-
// https://tools.ietf.org/html/rfc5297#section-3
230-
Siv::<C, M>::new(&self.key).encrypt_in_place([associated_data, nonce.as_slice()], buffer)
231-
}
232-
233-
fn decrypt_in_place(
234-
&self,
235-
nonce: &Array<u8, Self::NonceSize>,
236-
associated_data: &[u8],
237-
buffer: &mut dyn Buffer,
238-
) -> Result<(), Error> {
239-
Siv::<C, M>::new(&self.key).decrypt_in_place([associated_data, nonce.as_slice()], buffer)
240-
}
208+
const TAG_POSITION: TagPosition = TagPosition::Prefix;
241209
}
242210

243211
impl<C, M, NonceSize> AeadInOut for SivAead<C, M, NonceSize>

ascon-aead/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ categories = ["cryptography", "no-std"]
1515
rust-version = "1.85"
1616

1717
[dependencies]
18-
aead = { version = "0.6.0-rc.0", default-features = false, features = ["inout"] }
18+
aead = { version = "0.6.0-rc.0", default-features = false }
1919
subtle = { version = "2", default-features = false }
2020
zeroize = { version = "1.6", optional = true, default-features = false, features = ["derive"] }
2121
ascon = "0.4"

ascon-aead/src/lib.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
//! This crate has an optional `alloc` feature which can be disabled in e.g.
6060
//! microcontroller environments that don't have a heap.
6161
//!
62-
//! The [`AeadInPlace::encrypt_in_place`] and [`AeadInPlace::decrypt_in_place`]
62+
//! The [`Aead::encrypt_in_place`] and [`Aead::decrypt_in_place`]
6363
//! methods accept any type that impls the [`aead::Buffer`] trait which
6464
//! contains the plaintext for encryption or ciphertext for decryption.
6565
//!
@@ -72,7 +72,7 @@
7272
//! ```
7373
//! # #[cfg(feature = "heapless")] {
7474
//! use ascon_aead::{AsconAead128, Key, Nonce};
75-
//! use ascon_aead::aead::{AeadInPlace, KeyInit};
75+
//! use ascon_aead::aead::{Aead, KeyInit};
7676
//! use ascon_aead::aead::heapless::Vec;
7777
//!
7878
//! let key = Key::<AsconAead128>::from_slice(b"very secret key.");
@@ -105,9 +105,7 @@
105105
pub use zeroize;
106106

107107
pub use aead::{self, Error, Key, Nonce, Tag};
108-
use aead::{
109-
AeadCore, AeadInOut, KeyInit, KeySizeUser, PostfixTagged, consts::U16, inout::InOutBuf,
110-
};
108+
use aead::{AeadCore, AeadInOut, KeyInit, KeySizeUser, TagPosition, consts::U16, inout::InOutBuf};
111109

112110
mod asconcore;
113111

@@ -137,10 +135,9 @@ impl<P: Parameters> KeyInit for Ascon<P> {
137135
impl<P: Parameters> AeadCore for Ascon<P> {
138136
type NonceSize = U16;
139137
type TagSize = U16;
138+
const TAG_POSITION: TagPosition = TagPosition::Postfix;
140139
}
141140

142-
impl<P: Parameters> PostfixTagged for Ascon<P> {}
143-
144141
impl<P: Parameters> AeadInOut for Ascon<P> {
145142
fn encrypt_inout_detached(
146143
&self,
@@ -200,10 +197,9 @@ impl KeyInit for AsconAead128 {
200197
impl AeadCore for AsconAead128 {
201198
type NonceSize = U16;
202199
type TagSize = U16;
200+
const TAG_POSITION: TagPosition = TagPosition::Postfix;
203201
}
204202

205-
impl PostfixTagged for AsconAead128 {}
206-
207203
impl AeadInOut for AsconAead128 {
208204
#[inline(always)]
209205
fn encrypt_inout_detached(

ccm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ keywords = ["encryption", "aead"]
1414
rust-version = "1.85"
1515

1616
[dependencies]
17-
aead = { version = "0.6.0-rc.0", default-features = false, features = ["inout"] }
17+
aead = { version = "0.6.0-rc.0", default-features = false }
1818
cipher = { version = "=0.5.0-pre.8", default-features = false }
1919
ctr = { version = "0.10.0-pre.2", default-features = false }
2020
subtle = { version = "2", default-features = false }

0 commit comments

Comments
 (0)