Skip to content

Commit 1a03061

Browse files
add experimental CCM support
1 parent c8911d4 commit 1a03061

File tree

14 files changed

+558
-15
lines changed

14 files changed

+558
-15
lines changed

Cargo.lock

Lines changed: 132 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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ resolver = "1" # Hack to enable the `custom` feature of `getrandom`
1818
# Ensure all dependencies + feats are mapped to crate features for correct usage
1919
# default features often have std breaking no_std and potentially other unwanted
2020
[dependencies]
21+
aes = { version = "0.8.4", default-features = false, optional = true }
2122
aead = { version = "0.5.2", default-features = false, optional = true }
2223
aes-gcm = { version = "0.10.3", default-features = false, features = [
2324
"aes",
2425
], optional = true }
26+
ccm = { version = "0.5.0", optional = true, default-features = false }
2527
chacha20poly1305 = { version = "0.10.1", default-features = false, optional = true }
2628
crypto-common = { version = "0.1.6", default-features = false }
2729
der = { version = "0.7.9", default-features = false, optional = true }
@@ -84,7 +86,7 @@ std = [
8486
"ed25519-dalek?/std",
8587
"pkcs1?/std",
8688
]
87-
alloc = ["webpki?/alloc", "ecdsa?/alloc", "signature?/alloc"]
89+
alloc = ["webpki?/alloc", "ecdsa?/alloc", "signature?/alloc", "ccm?/alloc"]
8890
zeroize = ["ed25519-dalek?/zeroize", "x25519-dalek?/zeroize"]
8991

9092
nist = []
@@ -95,7 +97,7 @@ ed25519 = ["dep:ed25519-dalek"]
9597

9698
verify = ["dep:webpki"]
9799

98-
ecdsa = ["dep:ecdsa", "verify", "signature", "rand"]
100+
ecdsa = ["dep:ecdsa", "verify", "signature", "rand", "der"]
99101
ecdsa-p256 = ["p256", "p256/ecdsa", "ecdsa"]
100102
ecdsa-p384 = ["p384", "p384/ecdsa", "ecdsa"]
101103
ecdsa-p521 = ["p521", "p521/ecdsa", "ecdsa"]
@@ -118,9 +120,10 @@ rsa-pss = ["rsa"]
118120
rsa-full = ["rsa-pkcs1", "rsa-pss"]
119121

120122
aead = ["dep:aead"]
121-
aes-gcm = ["dep:aes-gcm", "aead"]
123+
aes-gcm = ["aes", "dep:aes-gcm", "aead"]
124+
aes-ccm = ["aes", "dep:ccm", "aead"]
122125
chacha20poly1305 = ["dep:chacha20poly1305", "aead"]
123-
aead-full = ["aes-gcm", "chacha20poly1305"]
126+
aead-full = ["aes-gcm", "aes-ccm", "chacha20poly1305"]
124127

125128
# TODO
126129
hash = []
@@ -146,3 +149,4 @@ pkcs8 = [
146149

147150
signature = ["dep:signature"]
148151
rand = ["dep:rand_core", "signature?/rand_core"]
152+
aes = ["dep:aes"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ Note that RustCrypto performance is generally inferior than ring, but in exchang
1717

1818
## Supported Cipher Suites
1919

20+
- TLS_ECDHE_ECDSA_WITH_AES_128_CCM
21+
- TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
2022
- TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
23+
- TLS_ECDHE_ECDSA_WITH_AES_256_CCM
24+
- TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8
2125
- TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
2226
- TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
2327
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
2428
- TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
2529
- TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
30+
- TLS13_AES_128_CCM_SHA256
31+
- TLS13_AES_128_CCM_8_SHA256
2632
- TLS13_AES_128_GCM_SHA256
2733
- TLS13_AES_256_GCM_SHA384
2834
- TLS13_CHACHA20_POLY1305_SHA256

src/aead.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ pub struct Aes128Gcm;
1212
#[cfg(feature = "aes-gcm")]
1313
pub struct Aes256Gcm;
1414

15+
#[cfg(feature = "aes-ccm")]
16+
pub struct Aes128Ccm;
17+
18+
#[cfg(feature = "aes-ccm")]
19+
pub struct Aes256Ccm;
20+
21+
#[cfg(feature = "aes-ccm")]
22+
pub struct Aes128Ccm8;
23+
24+
#[cfg(feature = "aes-ccm")]
25+
pub struct Aes256Ccm8;
26+
1527
pub(crate) struct EncryptBufferAdapter<'a>(pub(crate) &'a mut PrefixedPayload);
1628

1729
impl AsRef<[u8]> for EncryptBufferAdapter<'_> {
@@ -60,3 +72,6 @@ impl Buffer for DecryptBufferAdapter<'_, '_> {
6072
self.0.truncate(len)
6173
}
6274
}
75+
76+
#[cfg(feature = "aes")]
77+
pub mod aes;

src/aead/aes.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#[cfg(feature = "aes-ccm")]
2+
use aes::{Aes128, Aes256};
3+
#[cfg(feature = "aes-ccm")]
4+
use ccm::{
5+
consts::{U12, U16, U8},
6+
Ccm,
7+
};
8+
9+
// The AEAD_AES_128_CCM authenticated encryption algorithm works as
10+
// specified in [CCM], using AES-128 as the block cipher, by providing
11+
// the key, nonce, associated data, and plaintext to that mode of
12+
// operation. The formatting and counter generation function are as
13+
// specified in Appendix A of that reference, and the values of the
14+
// parameters identified in that appendix are as follows:
15+
// the nonce length n is 12,
16+
// the tag length t is 16, and
17+
// the value of q is 3.
18+
#[cfg(feature = "aes-ccm")]
19+
pub type Aes128Ccm = Ccm<Aes128, U16, U12>;
20+
#[cfg(feature = "aes-ccm")]
21+
pub type Aes256Ccm = Ccm<Aes256, U16, U12>;
22+
23+
// The AEAD_AES_128_CCM_8 authenticated encryption algorithm is
24+
// identical to the AEAD_AES_128_CCM algorithm (see Section 5.3 of
25+
// [RFC5116]), except that it uses 8 octets for authentication, instead
26+
// of the full 16 octets used by AEAD_AES_128_CCM.
27+
#[cfg(feature = "aes-ccm")]
28+
pub type Aes128Ccm8 = Ccm<Aes128, U8, U12>;
29+
#[cfg(feature = "aes-ccm")]
30+
pub type Aes256Ccm8 = Ccm<Aes256, U8, U12>;
31+
32+
#[cfg(feature = "aes-gcm")]
33+
pub type Aes128Gcm = aes_gcm::Aes128Gcm;
34+
35+
#[cfg(feature = "aes-gcm")]
36+
pub type Aes256Gcm = aes_gcm::Aes256Gcm;

src/tls12/aead.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ pub mod chacha20;
33

44
#[cfg(feature = "aes-gcm")]
55
pub mod gcm;
6+
7+
#[cfg(feature = "aes-ccm")]
8+
pub mod ccm;

0 commit comments

Comments
 (0)