Skip to content

Commit 30ab5ef

Browse files
authored
aes-gcm: support 32-bit and 64-bit tags under hazmat feature (#777)
Add 32-bit and 64-bit tag length support to AES-GCM. (Fix #541) Appendix C of NIST SP800-38D enforces a maxium decryption invocations on a key when using short tag, while this crate currently does not track the number of invocations. The crate users are responsible to follow the NIST enforcement. Therefore, these two newly added tag lengths are gated on the `hazmat` crate feature, and a warning message is added to the document.
1 parent defcb47 commit 30ab5ef

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

aes-gcm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ alloc = ["aead/alloc"]
3838
arrayvec = ["aead/arrayvec"]
3939
bytes = ["aead/bytes"]
4040
getrandom = ["aead/getrandom"]
41+
hazmat = []
4142
rand_core = ["aead/rand_core"]
4243

4344
[package.metadata.docs.rs]

aes-gcm/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub type Tag<TagSize = U16> = Array<u8, TagSize>;
120120
/// Trait implemented for valid tag sizes, i.e.
121121
/// [`U12`][consts::U12], [`U13`][consts::U13], [`U14`][consts::U14],
122122
/// [`U15`][consts::U15] and [`U16`][consts::U16].
123+
/// When the crate feature `hazmat` is enabled, [`U4`][consts::U4] and
124+
/// [`U8`][consts::U8] are also supported.
123125
pub trait TagSize: private::SealedTagSize {}
124126

125127
impl<T: private::SealedTagSize> TagSize for T {}
@@ -130,6 +132,11 @@ mod private {
130132
// Sealed traits stop other crates from implementing any traits that use it.
131133
pub trait SealedTagSize: ArraySize + Unsigned {}
132134

135+
#[cfg(feature = "hazmat")]
136+
impl SealedTagSize for consts::U4 {}
137+
#[cfg(feature = "hazmat")]
138+
impl SealedTagSize for consts::U8 {}
139+
133140
impl SealedTagSize for consts::U12 {}
134141
impl SealedTagSize for consts::U13 {}
135142
impl SealedTagSize for consts::U14 {}
@@ -170,6 +177,14 @@ type Ctr32BE<Aes> = ctr::CtrCore<Aes, ctr::flavors::Ctr32BE>;
170177
/// the default of 128-bits.
171178
///
172179
/// If in doubt, use the built-in [`Aes128Gcm`] and [`Aes256Gcm`] type aliases.
180+
///
181+
/// # ⚠️ WARNING: Hazmat!
182+
///
183+
/// When using short authentication tags, namely 32-bit tags with `typenum::U4` or
184+
/// 64-bit tags with `typenum::U8` (which require the crate feature `hazmat`), it is
185+
/// **RECOMMENDED** that a key not be used for more than the maximum invocations of
186+
/// authenticated decryption specified in Table 1 or Table 2 of NIST SP 800-38D,
187+
/// respectively.
173188
#[derive(Clone)]
174189
pub struct AesGcm<Aes, NonceSize, TagSize = U16>
175190
where

0 commit comments

Comments
 (0)