Skip to content

Commit 29c904f

Browse files
committed
Limit DNDK-GCM to 24-byte nonces
1 parent 4a269c2 commit 29c904f

File tree

3 files changed

+2
-78
lines changed

3 files changed

+2
-78
lines changed

dndk-gcm/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ Pure Rust implementation of DNDK-GCM (Double Nonce Derive Key AES-GCM) with
44
key commitment disabled (KC_Choice = 0) as specified in
55
`draft-gueron-cfrg-dndkgcm`.
66

7-
This crate provides two fixed-nonce variants:
8-
9-
- `DndkGcm24`: 24-byte nonce (recommended in the draft).
10-
- `DndkGcm12`: 12-byte nonce (AES-GCM compatible length).
7+
This crate provides a fixed 24-byte nonce variant: `DndkGcm24`.
118

129
## Usage
1310

dndk-gcm/src/lib.rs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,11 @@ pub struct DndkGcm24 {
5050
aes: Aes256,
5151
}
5252

53-
/// DNDK-GCM with a 12-byte nonce (KC_Choice = 0).
54-
#[derive(Clone)]
55-
pub struct DndkGcm12 {
56-
aes: Aes256,
57-
}
58-
5953
type KeySize = <Aes256Gcm as KeySizeUser>::KeySize;
6054

6155
/// DNDK-GCM nonce (24 bytes).
6256
pub type Nonce24 = aes_gcm::Nonce<cipher::consts::U24>;
6357

64-
/// DNDK-GCM nonce (12 bytes).
65-
pub type Nonce12 = aes_gcm::Nonce<U12>;
66-
6758
/// DNDK-GCM key.
6859
pub type Key<B = Aes256> = aes_gcm::Key<B>;
6960

@@ -85,32 +76,16 @@ impl AeadCore for DndkGcm24 {
8576
const TAG_POSITION: TagPosition = TagPosition::Postfix;
8677
}
8778

88-
impl AeadCore for DndkGcm12 {
89-
type NonceSize = U12;
90-
type TagSize = <Aes256Gcm as AeadCore>::TagSize;
91-
const TAG_POSITION: TagPosition = TagPosition::Postfix;
92-
}
93-
9479
impl KeySizeUser for DndkGcm24 {
9580
type KeySize = KeySize;
9681
}
9782

98-
impl KeySizeUser for DndkGcm12 {
99-
type KeySize = KeySize;
100-
}
101-
10283
impl KeyInit for DndkGcm24 {
10384
fn new(key: &Key) -> Self {
10485
Self { aes: Aes256::new(key) }
10586
}
10687
}
10788

108-
impl KeyInit for DndkGcm12 {
109-
fn new(key: &Key) -> Self {
110-
Self { aes: Aes256::new(key) }
111-
}
112-
}
113-
11489
impl AeadInOut for DndkGcm24 {
11590
fn encrypt_inout_detached(
11691
&self,
@@ -142,37 +117,6 @@ impl AeadInOut for DndkGcm24 {
142117
}
143118
}
144119

145-
impl AeadInOut for DndkGcm12 {
146-
fn encrypt_inout_detached(
147-
&self,
148-
nonce: &Nonce12,
149-
associated_data: &[u8],
150-
buffer: InOutBuf<'_, '_, u8>,
151-
) -> Result<Tag, Error> {
152-
if buffer.len() as u64 > P_MAX || associated_data.len() as u64 > A_MAX {
153-
return Err(Error);
154-
}
155-
156-
let (gcm_iv, key) = derive_key_and_iv::<12>(&self.aes, nonce.as_slice());
157-
Aes256Gcm::new(&key).encrypt_inout_detached(&gcm_iv, associated_data, buffer)
158-
}
159-
160-
fn decrypt_inout_detached(
161-
&self,
162-
nonce: &Nonce12,
163-
associated_data: &[u8],
164-
buffer: InOutBuf<'_, '_, u8>,
165-
tag: &Tag,
166-
) -> Result<(), Error> {
167-
if buffer.len() as u64 > C_MAX || associated_data.len() as u64 > A_MAX {
168-
return Err(Error);
169-
}
170-
171-
let (gcm_iv, key) = derive_key_and_iv::<12>(&self.aes, nonce.as_slice());
172-
Aes256Gcm::new(&key).decrypt_inout_detached(&gcm_iv, associated_data, buffer, tag)
173-
}
174-
}
175-
176120
type Block = Array<u8, <Aes256 as BlockSizeUser>::BlockSize>;
177121

178122
type GcmIv = aes_gcm::Nonce<U12>;

dndk-gcm/tests/dndkgcm.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod common;
66

77
use aes_gcm::aead::{Aead, AeadInOut, KeyInit, Payload, array::Array};
88
use common::TestVector;
9-
use dndk_gcm::{DndkGcm12, DndkGcm24};
9+
use dndk_gcm::DndkGcm24;
1010
use hex_literal::hex;
1111

1212
/// DNDK-GCM test vectors (draft-gueron-cfrg-dndkgcm-03, Appendix A)
@@ -21,21 +21,4 @@ const TEST_VECTORS_24: &[TestVector<[u8; 32], [u8; 24]>] = &[
2121
},
2222
];
2323

24-
/// DNDK-GCM test vectors (draft-gueron-cfrg-dndkgcm-03, Appendix A)
25-
const TEST_VECTORS_12: &[TestVector<[u8; 32], [u8; 12]>] = &[
26-
TestVector {
27-
key: &hex!("0100000000000000000000000000000000000000000000000000000000000000"),
28-
nonce: &hex!("000102030405060708090a0b"),
29-
plaintext: &hex!("11000001"),
30-
aad: &hex!("0100000011"),
31-
ciphertext: &hex!("b95cf258"),
32-
tag: &hex!("39e74511d997eaafd0f567d13758305b"),
33-
},
34-
];
35-
3624
tests!(DndkGcm24, TEST_VECTORS_24);
37-
38-
mod dndk_gcm12 {
39-
use super::*;
40-
tests!(DndkGcm12, TEST_VECTORS_12);
41-
}

0 commit comments

Comments
 (0)