Skip to content

Commit 708e976

Browse files
committed
use merged Aead trait
1 parent 1bd4230 commit 708e976

File tree

30 files changed

+113
-224
lines changed

30 files changed

+113
-224
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
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

Lines changed: 22 additions & 22 deletions
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, Buffer, Error, Result,
1010
array::{
1111
Array, ArraySize,
1212
typenum::{U4, U5, Unsigned},
@@ -27,12 +27,12 @@ pub type Nonce<A, S> = Array<u8, NonceSize<A, S>>;
2727
/// Size of a nonce as used by a STREAM construction, sans the overhead of
2828
/// the STREAM protocol itself.
2929
pub type NonceSize<A, S> =
30-
<<A as AeadCore>::NonceSize as Sub<<S as StreamPrimitive<A>>::NonceOverhead>>::Output;
30+
<<A as Aead>::NonceSize as Sub<<S as StreamPrimitive<A>>::NonceOverhead>>::Output;
3131

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,9 +344,9 @@ 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>,
349-
<<A as AeadCore>::NonceSize as Sub<U5>>::Output: ArraySize,
349+
<<A as Aead>::NonceSize as Sub<U5>>::Output: ArraySize,
350350
{
351351
/// Underlying AEAD cipher
352352
aead: A,
@@ -357,9 +357,9 @@ where
357357

358358
impl<A> NewStream<A> for StreamBE32<A>
359359
where
360-
A: AeadInPlace,
360+
A: Aead,
361361
A::NonceSize: Sub<U5>,
362-
<<A as AeadCore>::NonceSize as Sub<U5>>::Output: ArraySize,
362+
<<A as Aead>::NonceSize as Sub<U5>>::Output: ArraySize,
363363
{
364364
fn from_aead(aead: A, nonce: &Nonce<A, Self>) -> Self {
365365
Self {
@@ -371,9 +371,9 @@ where
371371

372372
impl<A> StreamPrimitive<A> for StreamBE32<A>
373373
where
374-
A: AeadInPlace,
374+
A: Aead,
375375
A::NonceSize: Sub<U5>,
376-
<<A as AeadCore>::NonceSize as Sub<U5>>::Output: ArraySize,
376+
<<A as Aead>::NonceSize as Sub<U5>>::Output: ArraySize,
377377
{
378378
type NonceOverhead = U5;
379379
type Counter = u32;
@@ -405,9 +405,9 @@ where
405405

406406
impl<A> StreamBE32<A>
407407
where
408-
A: AeadInPlace,
408+
A: Aead,
409409
A::NonceSize: Sub<U5>,
410-
<<A as AeadCore>::NonceSize as Sub<U5>>::Output: ArraySize,
410+
<<A as Aead>::NonceSize as Sub<U5>>::Output: ArraySize,
411411
{
412412
/// Compute the full AEAD nonce including the STREAM counter and last
413413
/// block flag.
@@ -434,9 +434,9 @@ where
434434
#[derive(Debug)]
435435
pub struct StreamLE31<A>
436436
where
437-
A: AeadInPlace,
437+
A: Aead,
438438
A::NonceSize: Sub<U4>,
439-
<<A as AeadCore>::NonceSize as Sub<U4>>::Output: ArraySize,
439+
<<A as Aead>::NonceSize as Sub<U4>>::Output: ArraySize,
440440
{
441441
/// Underlying AEAD cipher
442442
aead: A,
@@ -447,9 +447,9 @@ where
447447

448448
impl<A> NewStream<A> for StreamLE31<A>
449449
where
450-
A: AeadInPlace,
450+
A: Aead,
451451
A::NonceSize: Sub<U4>,
452-
<<A as AeadCore>::NonceSize as Sub<U4>>::Output: ArraySize,
452+
<<A as Aead>::NonceSize as Sub<U4>>::Output: ArraySize,
453453
{
454454
fn from_aead(aead: A, nonce: &Nonce<A, Self>) -> Self {
455455
Self {
@@ -461,9 +461,9 @@ where
461461

462462
impl<A> StreamPrimitive<A> for StreamLE31<A>
463463
where
464-
A: AeadInPlace,
464+
A: Aead,
465465
A::NonceSize: Sub<U4>,
466-
<<A as AeadCore>::NonceSize as Sub<U4>>::Output: ArraySize,
466+
<<A as Aead>::NonceSize as Sub<U4>>::Output: ArraySize,
467467
{
468468
type NonceOverhead = U4;
469469
type Counter = u32;
@@ -495,9 +495,9 @@ where
495495

496496
impl<A> StreamLE31<A>
497497
where
498-
A: AeadInPlace,
498+
A: Aead,
499499
A::NonceSize: Sub<U4>,
500-
<<A as AeadCore>::NonceSize as Sub<U4>>::Output: ArraySize,
500+
<<A as Aead>::NonceSize as Sub<U4>>::Output: ArraySize,
501501
{
502502
/// Compute the full AEAD nonce including the STREAM counter and last
503503
/// block flag.

aes-gcm-siv/Cargo.toml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![cfg_attr(not(feature = "os_rng"), doc = "```ignore")]
1616
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
1717
//! use aes_gcm_siv::{
18-
//! aead::{Aead, AeadCore, KeyInit, rand_core::OsRng},
18+
//! aead::{Aead, KeyInit, rand_core::OsRng},
1919
//! Aes256GcmSiv, Nonce // Or `Aes128GcmSiv`
2020
//! };
2121
//!
@@ -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
//!
@@ -78,12 +78,12 @@
7878
//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the
7979
//! [`aead`] crate as [`aead::bytes::BytesMut`]).
8080
81-
pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser};
81+
pub use aead::{self, Aead, Error, Key, KeyInit, KeySizeUser};
8282

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,
@@ -155,20 +155,14 @@ where
155155
}
156156
}
157157

158-
impl<Aes> AeadCore for AesGcmSiv<Aes>
158+
impl<Aes> Aead for AesGcmSiv<Aes>
159159
where
160160
Aes: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt + KeyInit,
161161
{
162162
type NonceSize = U12;
163163
type TagSize = U16;
164-
}
165-
166-
impl<Aes> PostfixTagged for AesGcmSiv<Aes> {}
164+
const TAG_POSITION: TagPosition = TagPosition::Postfix;
167165

168-
impl<Aes> AeadInOut for AesGcmSiv<Aes>
169-
where
170-
Aes: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt + KeyInit,
171-
{
172166
fn encrypt_inout_detached(
173167
&self,
174168
nonce: &Nonce,

aes-gcm/Cargo.toml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![cfg_attr(all(feature = "os_rng", feature = "heapless"), doc = "```")]
1616
#![cfg_attr(not(all(feature = "os_rng", feature = "heapless")), doc = "```ignore")]
1717
//! use aes_gcm::{
18-
//! aead::{Aead, AeadCore, KeyInit, rand_core::OsRng},
18+
//! aead::{Aead, KeyInit, rand_core::OsRng},
1919
//! Aes256Gcm, Nonce, Key // Or `Aes128Gcm`
2020
//! };
2121
//!
@@ -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::{Aead, KeyInit, rand_core::OsRng, heapless::Vec},
7272
//! Aes256Gcm, Nonce, // Or `Aes128Gcm`
7373
//! };
7474
//!
@@ -98,12 +98,12 @@
9898
//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the
9999
//! [`aead`] crate as [`aead::bytes::BytesMut`]).
100100
101-
pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser};
101+
pub use aead::{self, Aead, Error, Key, KeyInit, KeySizeUser};
102102

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,
@@ -246,26 +246,16 @@ where
246246
}
247247
}
248248

249-
impl<Aes, NonceSize, TagSize> AeadCore for AesGcm<Aes, NonceSize, TagSize>
249+
impl<Aes, NonceSize, TagSize> Aead for AesGcm<Aes, NonceSize, TagSize>
250250
where
251+
Aes: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt,
251252
NonceSize: ArraySize,
252253
TagSize: self::TagSize,
253254
{
254255
type NonceSize = NonceSize;
255256
type TagSize = TagSize;
256-
}
257-
258-
impl<Aes, NonceSize, TagSize> PostfixTagged for AesGcm<Aes, NonceSize, TagSize> where
259-
TagSize: self::TagSize
260-
{
261-
}
257+
const TAG_POSITION: TagPosition = TagPosition::Postfix;
262258

263-
impl<Aes, NonceSize, TagSize> AeadInOut for AesGcm<Aes, NonceSize, TagSize>
264-
where
265-
Aes: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt,
266-
NonceSize: ArraySize,
267-
TagSize: self::TagSize,
268-
{
269259
fn encrypt_inout_detached(
270260
&self,
271261
nonce: &Nonce<NonceSize>,

aes-gcm/tests/aes128gcm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod common;
77

88
use self::common::TestVector;
99
use aes_gcm::Aes128Gcm;
10-
use aes_gcm::aead::{Aead, AeadInOut, KeyInit, Payload, array::Array};
10+
use aes_gcm::aead::{Aead, KeyInit, Payload, array::Array};
1111
use hex_literal::hex;
1212

1313
/// NIST CAVS vectors

aes-gcm/tests/aes256gcm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod common;
77

88
use self::common::TestVector;
99
use aes_gcm::Aes256Gcm;
10-
use aes_gcm::aead::{Aead, AeadInOut, KeyInit, Payload, array::Array};
10+
use aes_gcm::aead::{Aead, KeyInit, Payload, array::Array};
1111
use hex_literal::hex;
1212

1313
/// NIST CAVS vectors

0 commit comments

Comments
 (0)