KeyInit for Ascon {
impl AeadCore for Ascon {
type NonceSize = U16;
type TagSize = U16;
- const TAG_POSITION: TagPosition = TagPosition::Postfix;
-}
-impl AeadInOut for Ascon {
fn encrypt_inout_detached(
&self,
nonce: &Nonce,
@@ -158,6 +106,10 @@ impl AeadInOut for Ascon {
}
}
+impl AeadTagPosition for Ascon {
+ const TAG_POSITION: TagPosition = TagPosition::Postfix;
+}
+
/// Ascon-AEAD128
pub struct AsconAead128(Ascon);
/// Key for Ascon-AEAD128
@@ -180,10 +132,7 @@ impl KeyInit for AsconAead128 {
impl AeadCore for AsconAead128 {
type NonceSize = U16;
type TagSize = U16;
- const TAG_POSITION: TagPosition = TagPosition::Postfix;
-}
-impl AeadInOut for AsconAead128 {
#[inline(always)]
fn encrypt_inout_detached(
&self,
@@ -207,3 +156,7 @@ impl AeadInOut for AsconAead128 {
.decrypt_inout_detached(nonce, associated_data, buffer, tag)
}
}
+
+impl AeadTagPosition for AsconAead128 {
+ const TAG_POSITION: TagPosition = TagPosition::Postfix;
+}
diff --git a/belt-dwp/Cargo.toml b/belt-dwp/Cargo.toml
index aac33d13..c1ec05c5 100644
--- a/belt-dwp/Cargo.toml
+++ b/belt-dwp/Cargo.toml
@@ -25,9 +25,7 @@ hex-literal = "1"
[features]
default = ["alloc", "getrandom"]
alloc = ["aead/alloc"]
-arrayvec = ["aead/arrayvec"]
-bytes = ["aead/bytes"]
-getrandom = ["aead/getrandom"]
+getrandom = ["aead/getrandom", "rand_core"]
rand_core = ["aead/rand_core"]
reduced-round = []
zeroize = ["dep:zeroize", "belt-ctr/zeroize"]
diff --git a/belt-dwp/benches/mod.rs b/belt-dwp/benches/mod.rs
index 745b2eec..673e106e 100644
--- a/belt-dwp/benches/mod.rs
+++ b/belt-dwp/benches/mod.rs
@@ -2,7 +2,7 @@
extern crate test;
use aead::{
- AeadInOut, KeyInit,
+ AeadCore, KeyInit,
array::Array,
consts::{U16, U32},
};
diff --git a/belt-dwp/src/lib.rs b/belt-dwp/src/lib.rs
index da94cf70..59d689ff 100644
--- a/belt-dwp/src/lib.rs
+++ b/belt-dwp/src/lib.rs
@@ -27,54 +27,8 @@
//! assert_eq!(&plaintext, b"plaintext message");
//! # Ok(()) }
//! ```
-//!
-//! ## In-place Usage (eliminates `alloc` requirement)
-//!
-//! This crate has an optional `alloc` feature which can be disabled in e.g.
-//! microcontroller environments that don't have a heap.
-//!
-//! The [`AeadInOut::encrypt_in_place`] and [`AeadInOut::decrypt_in_place`]
-//! methods accept any type that impls the [`aead::Buffer`] trait which
-//! contains the plaintext for encryption or ciphertext for decryption.
-//!
-//! Enabling the `arrayvec` feature of this crate will provide an impl of
-//! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as
-//! [`aead::arrayvec::ArrayVec`]).
-//!
-//! It can then be passed as the `buffer` parameter to the in-place encrypt
-//! and decrypt methods:
-//!
-#![cfg_attr(all(feature = "getrandom", feature = "arrayvec"), doc = "```")]
-#![cfg_attr(
- not(all(feature = "getrandom", feature = "arrayvec")),
- doc = "```ignore"
-)]
-//! # fn main() -> Result<(), Box> {
-//! use belt_dwp::{
-//! aead::{AeadInOut, Generate, Key, KeyInit, arrayvec::ArrayVec},
-//! BeltDwp, Nonce
-//! };
-//!
-//! let key = Key::::generate();
-//! let cipher = BeltDwp::new(&key);
-//! let nonce = Nonce::generate(); // 128-bits; MUST be unique per message
-//!
-//! let mut buffer: ArrayVec = ArrayVec::new(); // Note: buffer needs 16-bytes overhead for auth tag
-//! buffer.try_extend_from_slice(b"plaintext message").unwrap();
-//!
-//! // Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
-//! cipher.encrypt_in_place(&nonce, b"", &mut buffer)?;
-//!
-//! // `buffer` now contains the message ciphertext
-//! assert_ne!(buffer.as_ref(), b"plaintext message");
-//!
-//! // Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
-//! cipher.decrypt_in_place(&nonce, b"", &mut buffer)?;
-//! assert_eq!(buffer.as_ref(), b"plaintext message");
-//! # Ok(()) }
-//! ```
-pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser, Tag};
+pub use aead::{self, AeadCore, AeadTagPosition, Error, Key, KeyInit, KeySizeUser, Tag};
pub use belt_block::BeltBlock;
use aead::array::ArraySize;
@@ -137,11 +91,14 @@ where
}
}
-impl AeadInOut for Dwp
+impl AeadCore for Dwp
where
C: BlockCipherEncrypt + BlockSizeUser,
TagSize: ArraySize + NonZero + IsLessOrEqual,
{
+ type NonceSize = C::BlockSize;
+ type TagSize = TagSize;
+
fn encrypt_inout_detached(
&self,
nonce: &Nonce,
@@ -242,13 +199,11 @@ where
}
}
-impl AeadCore for Dwp
+impl AeadTagPosition for Dwp
where
C: BlockCipherEncrypt + BlockSizeUser,
TagSize: ArraySize + NonZero + IsLessOrEqual,
{
- type NonceSize = C::BlockSize;
- type TagSize = TagSize;
const TAG_POSITION: TagPosition = TagPosition::Postfix;
}
diff --git a/belt-dwp/tests/belt.rs b/belt-dwp/tests/belt.rs
index 84c03c71..00d50958 100644
--- a/belt-dwp/tests/belt.rs
+++ b/belt-dwp/tests/belt.rs
@@ -1,4 +1,4 @@
-use aead::AeadInOut;
+use aead::AeadCore;
use belt_dwp::{BeltDwp, KeyInit};
use hex_literal::hex;
diff --git a/ccm/Cargo.toml b/ccm/Cargo.toml
index c39c902c..762bffec 100644
--- a/ccm/Cargo.toml
+++ b/ccm/Cargo.toml
@@ -27,7 +27,5 @@ hex-literal = "1"
[features]
default = ["alloc", "getrandom"]
alloc = ["aead/alloc"]
-arrayvec = ["aead/arrayvec"]
-bytes = ["aead/bytes"]
-getrandom = ["aead/getrandom"]
+getrandom = ["aead/getrandom", "rand_core"]
rand_core = ["aead/rand_core"]
diff --git a/ccm/src/lib.rs b/ccm/src/lib.rs
index 550f86dd..acb2d910 100644
--- a/ccm/src/lib.rs
+++ b/ccm/src/lib.rs
@@ -37,61 +37,8 @@
//! # Ok(())
//! # }
//! ```
-//!
-//! ## In-place Usage (eliminates `alloc` requirement)
-//!
-//! This crate has an optional `alloc` feature which can be disabled in e.g.
-//! microcontroller environments that don't have a heap.
-//!
-//! The [`AeadInOut::encrypt_in_place`] and [`AeadInOut::decrypt_in_place`]
-//! methods accept any type that impls the [`aead::Buffer`] trait which
-//! contains the plaintext for encryption or ciphertext for decryption.
-//!
-//! Enabling the `arrayvec` feature of this crate will provide an impl of
-//! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as
-//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will
-//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the
-//! [`aead`] crate as [`aead::bytes::BytesMut`]).
-//!
-//! It can then be passed as the `buffer` parameter to the in-place encrypt
-//! and decrypt methods:
-//!
-#![cfg_attr(all(feature = "getrandom", feature = "arrayvec"), doc = "```")]
-#![cfg_attr(
- not(all(feature = "getrandom", feature = "arrayvec")),
- doc = "```ignore"
-)]
-//! # fn main() -> Result<(), Box> {
-//! use aes::Aes256;
-//! use ccm::{
-//! aead::{AeadCore, AeadInOut, Generate, Key, KeyInit, Nonce, arrayvec::ArrayVec},
-//! consts::{U10, U13},
-//! Ccm,
-//! };
-//!
-//! // AES-256-CCM type with tag and nonce size equal to 10 and 13 bytes respectively
-//! pub type Aes256Ccm = Ccm;
-//!
-//! let key = Key::::generate();
-//! let cipher = Aes256Ccm::new(&key);
-//!
-//! let nonce = Nonce::::generate(); // MUST be unique per message
-//! let mut buffer: ArrayVec = ArrayVec::new(); // Note: buffer needs 16-bytes overhead for auth tag
-//! buffer.try_extend_from_slice(b"plaintext message").unwrap();
-//!
-//! // Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
-//! cipher.encrypt_in_place(&nonce, b"", &mut buffer)?;
-//!
-//! // `buffer` now contains the message ciphertext
-//! assert_ne!(buffer.as_ref(), b"plaintext message");
-//!
-//! // Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
-//! cipher.decrypt_in_place(&nonce, b"", &mut buffer)?;
-//! assert_eq!(buffer.as_ref(), b"plaintext message");
-//! # Ok(())
-//! # }
-pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser, consts};
+pub use aead::{self, AeadCore, AeadTagPosition, Error, Key, KeyInit, KeySizeUser, consts};
use aead::{
TagPosition,
@@ -261,15 +208,7 @@ where
{
type NonceSize = N;
type TagSize = M;
- const TAG_POSITION: TagPosition = TagPosition::Postfix;
-}
-impl AeadInOut for Ccm
-where
- C: BlockSizeUser + BlockCipherEncrypt,
- M: ArraySize + TagSize,
- N: ArraySize + NonceSize,
-{
fn encrypt_inout_detached(
&self,
nonce: &Nonce,
@@ -335,6 +274,15 @@ where
}
}
+impl AeadTagPosition for Ccm
+where
+ C: BlockSizeUser + BlockCipherEncrypt,
+ M: ArraySize + TagSize,
+ N: ArraySize + NonceSize,
+{
+ const TAG_POSITION: TagPosition = TagPosition::Postfix;
+}
+
struct CbcMac<'a, C: BlockCipherEncrypt> {
cipher: &'a C,
state: Block,
diff --git a/ccm/tests/mod.rs b/ccm/tests/mod.rs
index 3288f8b8..12a584e7 100644
--- a/ccm/tests/mod.rs
+++ b/ccm/tests/mod.rs
@@ -1,6 +1,6 @@
#![cfg(feature = "alloc")]
-use aead::{Aead, AeadInOut, KeyInit, Payload, array::Array};
+use aead::{Aead, AeadCore, KeyInit, Payload, array::Array};
use aes::{Aes128, Aes192, Aes256};
use ccm::{
Ccm,
diff --git a/chacha20poly1305/Cargo.toml b/chacha20poly1305/Cargo.toml
index 56e529fe..9e6798ae 100644
--- a/chacha20poly1305/Cargo.toml
+++ b/chacha20poly1305/Cargo.toml
@@ -32,9 +32,7 @@ aead = { version = "0.6.0-rc.10", features = ["dev"], default-features = false }
[features]
default = ["alloc", "getrandom"]
alloc = ["aead/alloc"]
-arrayvec = ["aead/arrayvec"]
-bytes = ["aead/bytes"]
-getrandom = ["aead/getrandom"]
+getrandom = ["aead/getrandom", "rand_core"]
rand_core = ["aead/rand_core"]
reduced-round = []
zeroize = ["dep:zeroize", "chacha20/zeroize"]
diff --git a/chacha20poly1305/src/lib.rs b/chacha20poly1305/src/lib.rs
index aa565216..6974216c 100644
--- a/chacha20poly1305/src/lib.rs
+++ b/chacha20poly1305/src/lib.rs
@@ -45,57 +45,6 @@
//! # }
//! ```
//!
-//! ## In-place Usage (eliminates `alloc` requirement)
-//!
-//! This crate has an optional `alloc` feature which can be disabled in e.g.
-//! microcontroller environments that don't have a heap.
-//!
-//! The [`AeadInOut::encrypt_in_place`] and [`AeadInOut::decrypt_in_place`]
-//! methods accept any type that impls the [`aead::Buffer`] trait which
-//! contains the plaintext for encryption or ciphertext for decryption.
-//!
-//! Enabling the `arrayvec` feature of this crate will provide an impl of
-//! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as
-//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will
-//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the
-//! [`aead`] crate as [`aead::bytes::BytesMut`]).
-//!
-//! It can then be passed as the `buffer` parameter to the in-place encrypt
-//! and decrypt methods:
-//!
-#![cfg_attr(all(feature = "getrandom", feature = "arrayvec"), doc = "```")]
-#![cfg_attr(
- not(all(feature = "getrandom", feature = "arrayvec")),
- doc = "```ignore"
-)]
-//! # fn main() -> Result<(), Box> {
-//! // NOTE: requires the `arrayvec` and `getrandom` features are enabled
-//!
-//! use chacha20poly1305::{
-//! aead::{AeadCore, AeadInOut, Generate, Key, KeyInit, arrayvec::ArrayVec},
-//! ChaCha20Poly1305, Nonce,
-//! };
-//!
-//! let key = Key::::generate();
-//! let cipher = ChaCha20Poly1305::new(&key);
-//!
-//! let nonce = Nonce::generate(); // MUST be unique per message
-//! let mut buffer: ArrayVec = ArrayVec::new(); // Note: buffer needs 16-bytes overhead for auth tag
-//! buffer.try_extend_from_slice(b"plaintext message").unwrap();
-//!
-//! // Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
-//! cipher.encrypt_in_place(&nonce, b"", &mut buffer)?;
-//!
-//! // `buffer` now contains the message ciphertext
-//! assert_ne!(buffer.as_ref(), b"plaintext message");
-//!
-//! // Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
-//! cipher.decrypt_in_place(&nonce, b"", &mut buffer)?;
-//! assert_eq!(buffer.as_ref(), b"plaintext message");
-//! # Ok(())
-//! # }
-//! ```
-//!
//! ## [`XChaCha20Poly1305`]
//!
//! ChaCha20Poly1305 variant with an extended 192-bit (24-byte) nonce.
@@ -147,7 +96,7 @@
mod cipher;
-pub use aead::{self, AeadCore, AeadInOut, Error, KeyInit, KeySizeUser, consts};
+pub use aead::{self, AeadCore, AeadTagPosition, Error, KeyInit, KeySizeUser, consts};
use self::cipher::Cipher;
use ::cipher::{KeyIvInit, StreamCipher, StreamCipherSeek};
@@ -250,18 +199,12 @@ where
impl AeadCore for ChaChaPoly1305
where
+ C: KeyIvInit + StreamCipher + StreamCipherSeek,
N: ArraySize,
{
type NonceSize = N;
type TagSize = U16;
- const TAG_POSITION: TagPosition = TagPosition::Postfix;
-}
-impl AeadInOut for ChaChaPoly1305
-where
- C: KeyIvInit + StreamCipher + StreamCipherSeek,
- N: ArraySize,
-{
fn encrypt_inout_detached(
&self,
nonce: &aead::Nonce,
@@ -282,6 +225,14 @@ where
}
}
+impl AeadTagPosition for ChaChaPoly1305
+where
+ C: KeyIvInit + StreamCipher + StreamCipherSeek,
+ N: ArraySize,
+{
+ const TAG_POSITION: TagPosition = TagPosition::Postfix;
+}
+
impl Clone for ChaChaPoly1305
where
N: ArraySize,
diff --git a/deoxys/Cargo.toml b/deoxys/Cargo.toml
index 38d81a0a..c765b10d 100644
--- a/deoxys/Cargo.toml
+++ b/deoxys/Cargo.toml
@@ -30,9 +30,7 @@ hex-literal = "1"
[features]
default = ["alloc", "getrandom"]
alloc = ["aead/alloc"]
-arrayvec = ["aead/arrayvec"]
-bytes = ["aead/bytes"]
-getrandom = ["aead/getrandom"]
+getrandom = ["aead/getrandom", "rand_core"]
rand_core = ["aead/rand_core"]
[package.metadata.docs.rs]
diff --git a/deoxys/src/lib.rs b/deoxys/src/lib.rs
index 7f01484b..05a7402b 100644
--- a/deoxys/src/lib.rs
+++ b/deoxys/src/lib.rs
@@ -67,59 +67,6 @@
//! # Ok(())
//! # }
//! ```
-//!
-//! ## In-place Usage (eliminates `alloc` requirement)
-//!
-//! This crate has an optional `alloc` feature which can be disabled in e.g.
-//! microcontroller environments that don't have a heap.
-//!
-//! The [`AeadInOut::encrypt_in_place`] and [`AeadInOut::decrypt_in_place`]
-//! methods accept any type that impls the [`aead::Buffer`] trait which
-//! contains the plaintext for encryption or ciphertext for decryption.
-//!
-//! Enabling the `arrayvec` feature of this crate will provide an impl of
-//! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as
-//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will
-//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the
-//! [`aead`] crate as [`aead::bytes::BytesMut`]).
-//!
-//! It can then be passed as the `buffer` parameter to the in-place encrypt
-//! and decrypt methods:
-//!
-#![cfg_attr(all(feature = "getrandom", feature = "arrayvec"), doc = "```")]
-#![cfg_attr(
- not(all(feature = "getrandom", feature = "arrayvec")),
- doc = "```ignore"
-)]
-//! # fn main() -> Result<(), Box> {
-//! // NOTE: requires the `arrayvec` and `getrandom` features are enabled
-//!
-//! use deoxys::{
-//! aead::{AeadCore, AeadInOut, Generate, Key, KeyInit, arrayvec::ArrayVec},
-//! DeoxysII256, // Can be `DeoxysI128`, `DeoxysI256`, `DeoxysII128` of `DeoxysII256`
-//! Nonce
-//! };
-//!
-//! let key = Key::::generate();
-//! let cipher = DeoxysII256::new(&key);
-//!
-//! let nonce = Nonce::generate(); // MUST be unique per message
-//!
-//! let mut buffer: ArrayVec = ArrayVec::new(); // Buffer needs 16-bytes overhead for tag
-//! buffer.try_extend_from_slice(b"plaintext message").unwrap();
-//!
-//! // Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
-//! cipher.encrypt_in_place(&nonce, b"", &mut buffer)?;
-//!
-//! // `buffer` now contains the message ciphertext
-//! assert_ne!(buffer.as_ref(), b"plaintext message");
-//!
-//! // Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
-//! cipher.decrypt_in_place(&nonce, b"", &mut buffer)?;
-//! assert_eq!(buffer.as_ref(), b"plaintext message");
-//! # Ok(())
-//! # }
-//! ```
/// Deoxys-BC implementations.
mod deoxys_bc;
@@ -127,7 +74,7 @@ mod deoxys_bc;
/// Operation modes for Deoxys.
mod modes;
-pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser, consts};
+pub use aead::{self, AeadCore, AeadTagPosition, Error, Key, KeyInit, KeySizeUser, consts};
use aead::{
TagPosition,
@@ -279,14 +226,6 @@ where
{
type NonceSize = M::NonceSize;
type TagSize = U16;
- const TAG_POSITION: TagPosition = TagPosition::Postfix;
-}
-
-impl AeadInOut for Deoxys
-where
- M: DeoxysMode,
- B: DeoxysBcType,
-{
fn encrypt_inout_detached(
&self,
nonce: &Nonce,
@@ -312,6 +251,14 @@ where
}
}
+impl AeadTagPosition for Deoxys
+where
+ M: DeoxysMode,
+ B: DeoxysBcType,
+{
+ const TAG_POSITION: TagPosition = TagPosition::Postfix;
+}
+
impl Drop for Deoxys
where
M: DeoxysMode,
diff --git a/eax/Cargo.toml b/eax/Cargo.toml
index d2542bc1..dc85bb86 100644
--- a/eax/Cargo.toml
+++ b/eax/Cargo.toml
@@ -33,9 +33,7 @@ aes = "0.9"
[features]
default = ["alloc"]
alloc = ["aead/alloc"]
-arrayvec = ["aead/arrayvec"]
-bytes = ["aead/bytes"]
-getrandom = ["aead/getrandom"]
+getrandom = ["aead/getrandom", "rand_core"]
rand_core = ["aead/rand_core"]
[package.metadata.docs.rs]
diff --git a/eax/src/lib.rs b/eax/src/lib.rs
index d2e6c7f0..5545c6dc 100644
--- a/eax/src/lib.rs
+++ b/eax/src/lib.rs
@@ -33,64 +33,6 @@
//! # }
//! ```
//!
-//! ## In-place Usage (eliminates `alloc` requirement)
-//!
-//! This crate has an optional `alloc` feature which can be disabled in e.g.
-//! microcontroller environments that don't have a heap.
-//!
-//! The [`AeadInOut::encrypt_in_place`] and [`AeadInOut::decrypt_in_place`]
-//! methods accept any type that impls the [`aead::Buffer`] trait which
-//! contains the plaintext for encryption or ciphertext for decryption.
-//!
-//! Enabling the `arrayvec` feature of this crate will provide an impl of
-//! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as
-//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will
-//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the
-//! [`aead`] crate as [`aead::bytes::BytesMut`]).
-//!
-//! It can then be passed as the `buffer` parameter to the in-place encrypt
-//! and decrypt methods:
-//!
-#![cfg_attr(all(feature = "getrandom", feature = "arrayvec"), doc = "```")]
-#![cfg_attr(
- not(all(feature = "getrandom", feature = "arrayvec")),
- doc = "```ignore"
-)]
-//! # fn main() -> Result<(), Box> {
-//! // NOTE: requires the `arrayvec` and `getrandom` features are enabled
-//!
-//! use aes::Aes256;
-//! use eax::{
-//! aead::{
-//! arrayvec::ArrayVec,
-//! AeadCore, AeadInOut, Generate, Key, KeyInit,
-//! },
-//! Eax, Nonce
-//! };
-//!
-//! pub type Aes256Eax = Eax;
-//!
-//! let key = Key::::generate();
-//! let cipher = Aes256Eax::new(&key);
-//!
-//! let nonce = Nonce::generate(); // 128-bits; MUST be unique per message
-//!
-//! let mut buffer: ArrayVec = ArrayVec::new();
-//! buffer.try_extend_from_slice(b"plaintext message").unwrap();
-//!
-//! // Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
-//! cipher.encrypt_in_place(&nonce, b"", &mut buffer).expect("encryption failure!");
-//!
-//! // `buffer` now contains the message ciphertext
-//! assert_ne!(buffer.as_ref(), b"plaintext message");
-//!
-//! // Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
-//! cipher.decrypt_in_place(&nonce, b"", &mut buffer).expect("decryption failure!");
-//! assert_eq!(buffer.as_ref(), b"plaintext message");
-//! # Ok(())
-//! # }
-//! ```
-//!
//! ## Custom Tag Length
//!
//! The tag for eax is usually 16 bytes long but it can be shortened if needed.
@@ -128,7 +70,7 @@
//! # }
//! ```
-pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser};
+pub use aead::{self, AeadCore, AeadTagPosition, Error, Key, KeyInit, KeySizeUser};
pub use cipher;
use aead::{TagPosition, inout::InOutBuf};
@@ -210,14 +152,7 @@ where
{
type NonceSize = Cipher::BlockSize;
type TagSize = M;
- const TAG_POSITION: TagPosition = TagPosition::Postfix;
-}
-impl AeadInOut for Eax
-where
- Cipher: BlockSizeUser + BlockCipherEncrypt + Clone + KeyInit,
- M: TagSize,
-{
fn encrypt_inout_detached(
&self,
nonce: &Nonce,
@@ -289,6 +224,14 @@ where
}
}
+impl AeadTagPosition for Eax
+where
+ Cipher: BlockSizeUser + BlockCipherEncrypt + Clone + KeyInit,
+ M: TagSize,
+{
+ const TAG_POSITION: TagPosition = TagPosition::Postfix;
+}
+
impl Eax
where
Cipher: BlockSizeUser + BlockCipherEncrypt + Clone + KeyInit,
diff --git a/mgm/Cargo.toml b/mgm/Cargo.toml
index 8084ca06..2d8b3329 100644
--- a/mgm/Cargo.toml
+++ b/mgm/Cargo.toml
@@ -34,8 +34,6 @@ hex-literal = "1"
default = ["alloc", "getrandom"]
std = ["aead/std", "alloc"]
alloc = ["aead/alloc"]
-arrayvec = ["aead/arrayvec"]
-bytes = ["aead/bytes"]
getrandom = ["aead/getrandom", "rand_core"]
rand_core = ["aead/rand_core"]
stream = ["aead/stream"]
diff --git a/ocb3/Cargo.toml b/ocb3/Cargo.toml
index e8e749e7..53eb7750 100644
--- a/ocb3/Cargo.toml
+++ b/ocb3/Cargo.toml
@@ -21,7 +21,6 @@ cipher = "0.5"
ctr = "0.10"
dbl = "0.5"
subtle = { version = "2", default-features = false }
-aead-stream = { version = "0.6.0-rc.3", optional = true, default-features = false }
zeroize = { version = "1", optional = true, default-features = false }
[dev-dependencies]
@@ -31,10 +30,8 @@ hex-literal = "1"
[features]
default = ["alloc", "getrandom"]
-alloc = ["aead/alloc", "aead-stream?/alloc"]
-arrayvec = ["aead/arrayvec"]
-bytes = ["aead/bytes"]
-getrandom = ["aead/getrandom"]
+alloc = ["aead/alloc"]
+getrandom = ["aead/getrandom", "rand_core"]
rand_core = ["aead/rand_core"]
[package.metadata.docs.rs]
diff --git a/ocb3/src/lib.rs b/ocb3/src/lib.rs
index b17338db..cf62365b 100644
--- a/ocb3/src/lib.rs
+++ b/ocb3/src/lib.rs
@@ -14,12 +14,12 @@ pub mod consts {
}
pub use aead::{
- self, AeadCore, AeadInOut, Error, KeyInit, KeySizeUser,
+ self, AeadCore, Error, KeyInit, KeySizeUser,
array::{Array, AsArrayRef, AssocArraySize},
};
use aead::{
- TagPosition,
+ AeadTagPosition, TagPosition,
array::ArraySize,
inout::{InOut, InOutBuf},
};
@@ -157,17 +157,6 @@ where
}
}
-impl AeadCore
- for Ocb3
-where
- NonceSize: sealed::NonceSizes,
- TagSize: sealed::TagSizes,
-{
- type NonceSize = NonceSize;
- type TagSize = TagSize;
- const TAG_POSITION: TagPosition = TagPosition::Postfix;
-}
-
impl From
for Ocb3
where
@@ -189,13 +178,17 @@ where
}
}
-impl AeadInOut
+impl AeadCore
for Ocb3
where
Cipher: BlockSizeUser + BlockCipherEncrypt + BlockCipherDecrypt,
NonceSize: sealed::NonceSizes,
TagSize: sealed::TagSizes,
{
+ type NonceSize = NonceSize;
+ type TagSize = TagSize;
+
+ #[allow(clippy::explicit_counter_loop)]
fn encrypt_inout_detached(
&self,
nonce: &Nonce,
@@ -271,6 +264,16 @@ where
}
}
+impl AeadTagPosition
+ for Ocb3
+where
+ Cipher: BlockSizeUser + BlockCipherEncrypt + BlockCipherDecrypt,
+ NonceSize: sealed::NonceSizes,
+ TagSize: sealed::TagSizes,
+{
+ const TAG_POSITION: TagPosition = TagPosition::Postfix;
+}
+
impl
Ocb3
where
@@ -279,6 +282,7 @@ where
TagSize: sealed::TagSizes,
{
/// Decrypts in place and returns expected tag.
+ #[allow(clippy::explicit_counter_loop)]
pub(crate) fn decrypt_inout_return_tag(
&self,
nonce: &Nonce,
diff --git a/ocb3/tests/kats.rs b/ocb3/tests/kats.rs
index 1b4355d2..7737d625 100644
--- a/ocb3/tests/kats.rs
+++ b/ocb3/tests/kats.rs
@@ -1,7 +1,7 @@
#![allow(non_snake_case)]
use aead::{
- AeadInOut, KeyInit,
+ AeadCore, KeyInit,
consts::{U8, U12},
};
use aes::{Aes128, Aes192, Aes256};
diff --git a/ocb3/tests/len_check.rs b/ocb3/tests/len_check.rs
index a1bb20da..62b517ab 100644
--- a/ocb3/tests/len_check.rs
+++ b/ocb3/tests/len_check.rs
@@ -1,5 +1,5 @@
use aead::{
- AeadInOut, KeyInit,
+ AeadCore, KeyInit,
consts::{U12, U16},
};
use aes::Aes128;
diff --git a/xaes-256-gcm/Cargo.toml b/xaes-256-gcm/Cargo.toml
index 8fe9155b..b9235447 100644
--- a/xaes-256-gcm/Cargo.toml
+++ b/xaes-256-gcm/Cargo.toml
@@ -20,7 +20,6 @@ aead = { version = "0.6.0-rc.10", default-features = false }
aes = "0.9"
aes-gcm = { version = "0.11.0-rc.3", default-features = false, features = ["aes"] }
cipher = "0.5"
-aead-stream = { version = "0.6.0-rc.2", optional = true, default-features = false }
[dev-dependencies]
aead = { version = "0.6.0-rc.10", features = ["dev"], default-features = false }
@@ -28,9 +27,8 @@ hex-literal = "1"
[features]
default = ["alloc", "getrandom"]
-alloc = ["aead/alloc", "aead-stream?/alloc", "aes-gcm/alloc"]
-arrayvec = ["aead/arrayvec", "aes-gcm/arrayvec"]
-getrandom = ["aes-gcm/getrandom"]
+alloc = ["aead/alloc", "aes-gcm/alloc"]
+getrandom = ["aes-gcm/getrandom", "rand_core"]
rand_core = ["aead/rand_core", "aes-gcm/rand_core"]
[package.metadata.docs.rs]
diff --git a/xaes-256-gcm/src/lib.rs b/xaes-256-gcm/src/lib.rs
index ecd1e7f2..11231652 100644
--- a/xaes-256-gcm/src/lib.rs
+++ b/xaes-256-gcm/src/lib.rs
@@ -39,7 +39,8 @@ pub use aes_gcm;
use core::ops::{Div, Mul};
use aead::{
- AeadCore, AeadInOut, Error, KeyInit, KeySizeUser, TagPosition, array::Array, inout::InOutBuf,
+ AeadCore, AeadTagPosition, Error, KeyInit, KeySizeUser, TagPosition, array::Array,
+ inout::InOutBuf,
};
use aes::Aes256;
use aes_gcm::Aes256Gcm;
@@ -76,12 +77,6 @@ pub const A_MAX: u64 = 1 << 36;
/// Maximum length of ciphertext.
pub const C_MAX: u64 = (1 << 36) + 16;
-impl AeadCore for Xaes256Gcm {
- type NonceSize = NonceSize;
- type TagSize = TagSize;
- const TAG_POSITION: TagPosition = TagPosition::Postfix;
-}
-
impl KeySizeUser for Xaes256Gcm {
type KeySize = KeySize;
}
@@ -110,7 +105,10 @@ impl KeyInit for Xaes256Gcm {
}
}
-impl AeadInOut for Xaes256Gcm {
+impl AeadCore for Xaes256Gcm {
+ type NonceSize = NonceSize;
+ type TagSize = TagSize;
+
fn encrypt_inout_detached(
&self,
nonce: &Nonce,
@@ -143,6 +141,10 @@ impl AeadInOut for Xaes256Gcm {
}
}
+impl AeadTagPosition for Xaes256Gcm {
+ const TAG_POSITION: TagPosition = TagPosition::Postfix;
+}
+
impl Xaes256Gcm {
// Implements steps 3 - 5 of the spec.
fn derive_key(&self, n1: &Nonce<>::Output>) -> Key {
diff --git a/xaes-256-gcm/tests/xaes256gcm.rs b/xaes-256-gcm/tests/xaes256gcm.rs
index 62b85d7e..eda8a24c 100644
--- a/xaes-256-gcm/tests/xaes256gcm.rs
+++ b/xaes-256-gcm/tests/xaes256gcm.rs
@@ -1,11 +1,6 @@
//! XAES-256-GCM test vectors
-#[macro_use]
-#[path = "../../aes-gcm/tests/common/mod.rs"]
-mod common;
-
-use aes_gcm::aead::{Aead, AeadInOut, KeyInit, Payload, array::Array};
-use common::TestVector;
+use aes_gcm::aead::{Aead, AeadCore, KeyInit, Payload, array::Array};
use hex_literal::hex;
use xaes_256_gcm::Xaes256Gcm;
@@ -31,4 +26,105 @@ const TEST_VECTORS: &[TestVector<[u8; 32], [u8; 24]>] = &[
},
];
+/// Test vectors
+#[derive(Debug)]
+pub struct TestVector {
+ pub key: &'static K,
+ pub nonce: &'static N,
+ pub aad: &'static [u8],
+ pub plaintext: &'static [u8],
+ pub ciphertext: &'static [u8],
+ pub tag: &'static [u8; 16],
+}
+
+#[macro_export]
+macro_rules! tests {
+ ($aead:ty, $vectors:expr) => {
+ #[test]
+ fn encrypt() {
+ for vector in $vectors {
+ let key = Array(*vector.key);
+ let nonce = Array(*vector.nonce);
+ let payload = Payload {
+ msg: vector.plaintext,
+ aad: vector.aad,
+ };
+
+ let cipher = <$aead>::new(&key);
+ let ciphertext = cipher.encrypt(&nonce, payload).unwrap();
+ let (ct, tag) = ciphertext.split_at(ciphertext.len() - 16);
+ assert_eq!(
+ vector.ciphertext, ct,
+ "ciphertext mismatch (expected != actual)"
+ );
+ assert_eq!(vector.tag, tag, "tag mismatch (expected != actual)");
+ }
+ }
+
+ #[test]
+ fn decrypt() {
+ for vector in $vectors {
+ let key = Array(*vector.key);
+ let nonce = Array(*vector.nonce);
+ let mut ciphertext = Vec::from(vector.ciphertext);
+ ciphertext.extend_from_slice(vector.tag);
+
+ let payload = Payload {
+ msg: &ciphertext,
+ aad: vector.aad,
+ };
+
+ let cipher = <$aead>::new(&key);
+ let plaintext = cipher.decrypt(&nonce, payload).unwrap();
+
+ assert_eq!(vector.plaintext, plaintext.as_slice(), "plaintext mismatch");
+ }
+ }
+
+ #[test]
+ fn decrypt_modified() {
+ let vector = &$vectors[0];
+ let key = Array(*vector.key);
+ let nonce = Array(*vector.nonce);
+
+ let mut ciphertext = Vec::from(vector.ciphertext);
+ ciphertext.extend_from_slice(vector.tag);
+
+ // Tweak the first byte
+ ciphertext[0] ^= 0xaa;
+
+ let payload = Payload {
+ msg: &ciphertext,
+ aad: vector.aad,
+ };
+
+ let cipher = <$aead>::new(&key);
+ assert!(cipher.decrypt(&nonce, payload).is_err());
+ }
+
+ #[test]
+ fn decrypt_in_place_detached_modified() {
+ let vector = &$vectors.iter().last().unwrap();
+ let key = Array(*vector.key);
+ let nonce = Array(*vector.nonce);
+
+ let mut buffer = Vec::from(vector.ciphertext);
+ assert!(!buffer.is_empty());
+
+ // Tweak the first byte
+ let mut tag = Array(*vector.tag);
+ tag[0] ^= 0xaa;
+
+ let cipher = <$aead>::new(&key);
+ assert!(
+ cipher
+ .decrypt_inout_detached(&nonce, &[], buffer.as_mut_slice().into(), &tag)
+ .is_err()
+ );
+
+ assert_eq!(vector.ciphertext, buffer);
+ }
+ };
+}
+
tests!(Xaes256Gcm, TEST_VECTORS);