Skip to content

Commit fe2150c

Browse files
author
Steve Fan
committed
upgrade to latest rustcrypto crates
1 parent 34b4347 commit fe2150c

File tree

33 files changed

+1264
-1151
lines changed

33 files changed

+1264
-1151
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,62 @@ readme = "README.md"
1111
repository = "https://github.com/RustCrypto/rustls-rustcrypto"
1212
categories = ["cryptography", "no-std"]
1313
keywords = ["rustls", "tls"]
14-
edition = "2021"
15-
rust-version = "1.75"
14+
edition = "2024"
15+
rust-version = "1.85"
1616
resolver = "2"
1717

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]
2121
# Cryptographic dependencies
22-
aead = { version = "0.5.2", default-features = false, optional = true }
23-
aes = { version = "0.8.4", default-features = false, optional = true }
24-
aes-gcm = { version = "0.10.3", default-features = false, optional = true }
25-
ccm = { version = "0.5.0", default-features = false, optional = true }
26-
chacha20poly1305 = { version = "0.10.1", default-features = false, optional = true }
27-
crrl = { git = "https://github.com/stevefan1999-personal/crrl", version = "0.9.0", default-features = false, optional = true }
28-
crypto-common = { version = "0.1.6", default-features = false }
29-
der = { version = "0.7.10", default-features = false, optional = true }
30-
digest = { version = "0.10.7", default-features = false }
31-
ecdsa = { version = "0.16.9", default-features = false, optional = true }
32-
ed25519-dalek = { version = "2", default-features = false, optional = true }
33-
elliptic-curve = { version = "0.13.8", default-features = false, optional = true }
34-
hmac = { version = "0.12.1", default-features = false }
35-
p256 = { version = "0.13.2", default-features = false, optional = true }
36-
p384 = { version = "0.13.1", default-features = false, optional = true }
37-
p521 = { version = "0.13.3", default-features = false, optional = true }
38-
pkcs1 = { version = "0.7.5", default-features = false, optional = true }
39-
pkcs8 = { version = "0.10.2", default-features = false, optional = true }
40-
rsa = { version = "0.9.8", default-features = false, optional = true }
41-
sec1 = { version = "0.7.3", default-features = false, optional = true }
42-
sha2 = { version = "0.10.9", default-features = false }
43-
signature = { version = "2.2.0", default-features = false, optional = true }
22+
aead = { version = "0.6.0-rc.2", default-features = false, optional = true }
23+
aes = { version = "0.9.0-rc.1", default-features = false, optional = true }
24+
aes-gcm = { version = "0.11.0-rc.1", default-features = false, optional = true }
25+
ccm = { version = "0.6.0-pre", default-features = false, optional = true, git = "https://github.com/RustCrypto/AEADs/" }
26+
chacha20poly1305 = { version = "0.11.0-rc.1", default-features = false, optional = true }
27+
cipher = "0.5.0-rc.1"
28+
# crrl = { git = "https://github.com/stevefan1999-personal/crrl", version = "0.9.0", default-features = false, optional = true }
29+
crypto-common = { version = "0.2.0-rc.4", default-features = false }
30+
der = { version = "0.8.0-rc.8", default-features = false, optional = true }
31+
digest = { version = "0.11.0-rc.1", default-features = false }
32+
ecdsa = { version = "0.17.0-rc.6", default-features = false, optional = true }
33+
ed25519-dalek = { version = "3.0.0-pre.1", default-features = false, optional = true }
34+
elliptic-curve = { version = "0.14.0-rc.13", default-features = false, optional = true }
35+
hmac = { version = "0.13.0-rc.1", default-features = false }
36+
p256 = { version = "0.14.0-pre.10", default-features = false, optional = true }
37+
p384 = { version = "0.14.0-pre.10", default-features = false, optional = true }
38+
p521 = { version = "0.14.0-pre.10", default-features = false, optional = true }
39+
pkcs1 = { version = "0.8.0-rc.3", default-features = false, optional = true }
40+
pkcs8 = { version = "0.11.0-rc.6", default-features = false, optional = true }
41+
rsa = { version = "0.10.0-rc.6", default-features = false, optional = true }
42+
sec1 = { version = "0.8.0-rc.9", default-features = false, optional = true }
43+
sha2 = { version = "0.11.0-rc.2", default-features = false }
44+
signature = { version = "3.0.0-rc.3", default-features = false, optional = true }
4445
typenum = { version = "1.18.0", features = ["no_std", "const-generics"] }
45-
x25519-dalek = { version = "2", default-features = false, optional = true }
46+
x25519-dalek = { version = "3.0.0-pre.1", default-features = false, optional = true }
47+
x448 = { version = "0.14.0-pre.0", default-features = false, optional = true }
4648

4749
# External groups
48-
getrandom = { version = "0.2", default-features = false, features = ["custom"] }
49-
paste = { version = "1.0.15", default-features = false }
50+
const-default = { version = "1.0.0", features = ["derive"] }
51+
getrandom = { version = "0.3", default-features = false }
5052
pki-types = { package = "rustls-pki-types", version = "1.12.0", default-features = false }
51-
rand_core = { version = "0.6.4", default-features = false, features = [
52-
"getrandom",
53+
preinterpret = "0.2.0"
54+
rand_core = { version = "0.9.3", default-features = false, features = [
55+
"os_rng"
5356
], optional = true }
54-
rustls = { version = "0.23.27", default-features = false }
55-
webpki = { package = "rustls-webpki", version = "0.102.8", default-features = false, optional = true }
57+
rustls = { version = "0.23.31", default-features = false }
58+
webpki = { package = "rustls-webpki", version = "0.103.4", default-features = false, optional = true }
59+
paste = "1.0.15"
5660

57-
[target.'cfg(target_arch = "wasm32")'.dependencies]
58-
getrandom = { version = "0.2", features = ["wasm-bindgen"] }
5961

6062
[dev-dependencies]
6163
bytes = { version = "1.10.1", default-features = false }
62-
itertools = { version = "0.13.0", default-features = false }
63-
rsa = { version = "0.9.8", default-features = false, features = ["sha2"] }
64-
rustls = { version = "0.23.27", default-features = false, features = ["std"] }
65-
sha2 = { version = "0.10.9", default-features = false }
66-
spki = { version = "0.7.3", default-features = false, features = ["alloc"] }
64+
itertools = { version = "0.14.0", default-features = false }
65+
rsa = { version = "0.10.0-rc.6", default-features = false, features = ["sha2"] }
66+
rustls = { version = "0.23.31", default-features = false, features = ["std"] }
67+
spki = { version = "0.8.0-rc.4", default-features = false, features = ["alloc"] }
6768
x509-cert = { version = "0.2.5", default-features = false, features = [
68-
"builder",
69+
"builder", "hazmat"
6970
] }
7071

7172
[features]
@@ -104,13 +105,13 @@ zeroize = [
104105
subtle = ["digest/subtle", "pkcs8?/subtle", "sec1?/subtle"]
105106
fast = [
106107
"ed25519-dalek?/fast",
107-
"rsa?/u64_digit",
108+
# "rsa?/u64_digit",
108109
"x25519-dalek?/precomputed-tables",
109110
]
110111

111112
nist = []
112-
p256 = ["dep:p256", "nist"]
113-
p384 = ["dep:p384", "nist"]
113+
p256 = ["dep:p256", "nist", "p256/pkcs8"]
114+
p384 = ["dep:p384", "nist", "p384/pkcs8"]
114115
p521 = ["dep:p521", "nist"]
115116
ed25519 = ["dep:ed25519-dalek"]
116117

@@ -203,10 +204,10 @@ hash-sha512 = ["hash"]
203204
hash-full = ["hash-sha224", "hash-sha256", "hash-sha384", "hash-sha512"]
204205

205206
# Formats
206-
der = ["dep:der"]
207-
sec1 = ["dep:sec1", "elliptic-curve?/sec1", "sec1/pkcs8"]
207+
der = ["dep:der", "sec1?/der"]
208+
sec1 = ["dep:sec1", "elliptic-curve?/sec1"]
208209
pem = ["elliptic-curve?/pem", "ecdsa?/pem"]
209-
pkcs1 = ["dep:pkcs1"]
210+
pkcs1 = ["dep:pkcs1", "rsa?/encoding"]
210211
pkcs8 = [
211212
"dep:pkcs8",
212213
"ecdsa?/pkcs8",
@@ -215,7 +216,6 @@ pkcs8 = [
215216
"p256?/pkcs8",
216217
"p384?/pkcs8",
217218
"p521?/pkcs8",
218-
"sec1?/pkcs8",
219219
]
220220

221221
aes = ["dep:aes"]
@@ -225,6 +225,6 @@ ccm = ["dep:ccm"]
225225
chacha20poly1305 = ["dep:chacha20poly1305"]
226226
elliptic-curve = ["dep:elliptic-curve"]
227227
gcm = []
228-
rand = ["dep:rand_core", "signature?/rand_core"]
228+
rand = ["dep:rand_core", "signature?/rand_core", "x25519-dalek?/os_rng"]
229229
signature = ["dep:signature"]
230-
x448 = ["dep:crrl", "crrl/x448"]
230+
x448 = ["dep:x448"]

src/aead.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
use aead::Buffer;
22
use rustls::crypto::cipher::{BorrowedPayload, PrefixedPayload};
33

4-
#[cfg(feature = "chacha20poly1305")]
5-
pub const CHACHAPOLY1305_OVERHEAD: usize = 16;
6-
7-
#[cfg(feature = "chacha20poly1305")]
8-
pub struct ChaCha20Poly1305;
9-
104
#[cfg(feature = "gcm")]
115
pub mod gcm;
126

137
#[cfg(feature = "ccm")]
148
pub mod ccm;
159

10+
#[macro_use]
11+
pub(crate) mod common;
1612
pub(crate) struct EncryptBufferAdapter<'a>(pub(crate) &'a mut PrefixedPayload);
1713

1814
impl AsRef<[u8]> for EncryptBufferAdapter<'_> {

src/aead/aes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use aes::{Aes128, Aes256};
1+
use ::aes::{Aes128, Aes256};
22

33
#[cfg(feature = "gcm")]
44
use aes_gcm::AesGcm;
55

66
#[cfg(feature = "ccm")]
77
use {
88
ccm::Ccm,
9-
typenum::{U16, U8},
9+
typenum::{U8, U16},
1010
};
1111

1212
#[cfg(any(feature = "gcm", feature = "ccm"))]

src/aead/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/hash.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
use alloc::boxed::Box;
33

44
use digest::{Digest, OutputSizeUser};
5-
use paste::paste;
5+
use preinterpret::preinterpret;
66
use rustls::crypto::{self, hash};
77

88
macro_rules! impl_hash {
99
($name:ident, $ty:ty, $algo:ty) => {
10-
paste! {
10+
preinterpret! {
11+
[!set! #hash_name = [!ident! Hash_ $name]]
12+
[!set! #hash_content_name = [!ident! HashContent_ $name]]
13+
1114
#[allow(non_camel_case_types)]
12-
pub struct [<Hash_ $name>];
15+
pub struct #hash_name;
1316

14-
impl hash::Hash for [<Hash_ $name>] {
17+
impl hash::Hash for #hash_name {
1518
fn start(&self) -> Box<dyn hash::Context> {
16-
Box::new([<HashContent_ $name>]($ty::new()))
19+
Box::new(#hash_content_name($ty::new()))
1720
}
1821

1922
fn hash(&self, data: &[u8]) -> hash::Output {
@@ -30,15 +33,15 @@ macro_rules! impl_hash {
3033
}
3134

3235
#[allow(non_camel_case_types)]
33-
pub struct [<HashContent_ $name>]($ty);
36+
pub struct #hash_content_name($ty);
3437

35-
impl hash::Context for [<HashContent_ $name>] {
38+
impl hash::Context for #hash_content_name {
3639
fn fork_finish(&self) -> hash::Output {
3740
hash::Output::new(&self.0.clone().finalize()[..])
3841
}
3942

4043
fn fork(&self) -> Box<dyn hash::Context> {
41-
Box::new([<HashContent_ $name>](self.0.clone()))
44+
Box::new(#hash_content_name(self.0.clone()))
4245
}
4346

4447
fn finish(self: Box<Self>) -> hash::Output {
@@ -50,7 +53,7 @@ macro_rules! impl_hash {
5053
}
5154
}
5255

53-
pub const $name: &dyn crypto::hash::Hash = &[<Hash_ $name>];
56+
pub const $name: &dyn crypto::hash::Hash = &#hash_name;
5457
}
5558
};
5659
}

src/hmac.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
#[cfg(feature = "alloc")]
22
use alloc::boxed::Box;
33

4+
use crypto_common::KeyInit;
45
use crypto_common::OutputSizeUser;
5-
use paste::paste;
6+
use preinterpret::preinterpret;
67
use rustls::crypto::hmac::{Hmac, Key, Tag};
78

89
macro_rules! impl_hmac {
910
(
1011
$name: ident,
1112
$ty: ty
1213
) => {
13-
paste! {
14+
preinterpret! {
15+
[!set! #hmac_type_name = [!ident! Hmac_ $name]]
16+
[!set! #hmac_key_type_name = [!ident! HmacKey_ $name]]
17+
1418
#[allow(non_camel_case_types)]
15-
pub struct [<Hmac_ $name>];
19+
pub struct #hmac_type_name;
1620

17-
impl Hmac for [<Hmac_ $name>] {
21+
impl Hmac for #hmac_type_name {
1822
fn with_key(&self, key: &[u8]) -> Box<dyn Key> {
19-
use ::hmac::Mac;
20-
Box::new([<HmacKey_ $name>](
23+
Box::new(#hmac_key_type_name(
2124
::hmac::Hmac::<$ty>::new_from_slice(key).unwrap(),
2225
))
2326
}
@@ -28,9 +31,9 @@ macro_rules! impl_hmac {
2831
}
2932

3033
#[allow(non_camel_case_types)]
31-
pub struct [<HmacKey_ $name>](::hmac::Hmac<$ty>);
34+
pub struct #hmac_key_type_name(::hmac::Hmac<$ty>);
3235

33-
impl Key for [<HmacKey_ $name>] {
36+
impl Key for #hmac_key_type_name {
3437
fn sign_concat(&self, first: &[u8], middle: &[&[u8]], last: &[u8]) -> Tag {
3538
use ::hmac::Mac;
3639
let mut ctx = self.0.clone();
@@ -46,7 +49,7 @@ macro_rules! impl_hmac {
4649
$ty::output_size()
4750
}
4851
}
49-
pub const $name: &dyn Hmac = &[<Hmac_ $name>];
52+
pub const $name: &dyn Hmac = &#hmac_type_name;
5053
}
5154
};
5255
}

src/kx/nist.rs

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ use alloc::boxed::Box;
55
use crypto::{SharedSecret, SupportedKxGroup};
66

77
#[cfg(feature = "kx-nist")]
8-
use paste::paste;
8+
use preinterpret::preinterpret;
99

1010
#[cfg(feature = "kx-nist")]
1111
use rustls::crypto;
1212

1313
#[cfg(feature = "kx-nist")]
1414
macro_rules! impl_kx {
1515
($name:ident, $kx_name:ty, $secret:ty, $public_key:ty) => {
16-
paste! {
16+
preinterpret! {
17+
[!set! #key_exchange = [!ident! $name KeyExchange]]
18+
1719
#[derive(Debug)]
1820
#[allow(non_camel_case_types)]
1921
pub struct $name;
@@ -24,24 +26,24 @@ macro_rules! impl_kx {
2426
}
2527

2628
fn start(&self) -> Result<Box<dyn crypto::ActiveKeyExchange>, rustls::Error> {
27-
let priv_key = $secret::random(&mut rand_core::OsRng);
29+
let priv_key = $secret::try_from_rng(&mut rand_core::OsRng).unwrap();
2830
let pub_key: $public_key = (&priv_key).into();
29-
Ok(Box::new([<$name KeyExchange>] {
31+
Ok(Box::new(#key_exchange {
3032
priv_key,
3133
pub_key: pub_key.to_sec1_bytes(),
3234
}))
3335
}
3436
}
3537

3638
#[allow(non_camel_case_types)]
37-
pub struct [<$name KeyExchange>] {
39+
pub struct #key_exchange {
3840
priv_key: $secret,
3941
pub_key: Box<[u8]>,
4042
}
4143

42-
impl crypto::ActiveKeyExchange for [<$name KeyExchange>] {
44+
impl crypto::ActiveKeyExchange for #key_exchange {
4345
fn complete(
44-
self: Box<[<$name KeyExchange>]>,
46+
self: Box<#key_exchange>,
4547
peer: &[u8],
4648
) -> Result<SharedSecret, rustls::Error> {
4749
let their_pub = $public_key::from_sec1_bytes(peer)
@@ -72,5 +74,46 @@ impl_kx! {SecP256R1, rustls::NamedGroup::secp256r1, ::p256::ecdh::EphemeralSecre
7274
#[cfg(feature = "kx-p384")]
7375
impl_kx! {SecP384R1, rustls::NamedGroup::secp384r1, ::p384::ecdh::EphemeralSecret, ::p384::PublicKey}
7476

75-
#[cfg(feature = "kx-p521")]
76-
impl_kx! {SecP521R1, rustls::NamedGroup::secp521r1, ::p521::ecdh::EphemeralSecret, ::p521::PublicKey}
77+
#[derive(Debug)]
78+
#[allow(non_camel_case_types)]
79+
pub struct SecP521R1;
80+
81+
impl crypto::SupportedKxGroup for SecP521R1 {
82+
fn name(&self) -> rustls::NamedGroup {
83+
rustls::NamedGroup::secp521r1
84+
}
85+
fn start(&self) -> Result<Box<dyn crypto::ActiveKeyExchange>, rustls::Error> {
86+
let priv_key = ::p521::ecdh::EphemeralSecret::try_from_rng(&mut rand_core::OsRng).unwrap();
87+
let pub_key: ::p521::PublicKey = (&priv_key).into();
88+
Ok(Box::new(SecP521R1KeyExchange {
89+
priv_key,
90+
pub_key: pub_key.to_sec1_bytes(),
91+
}))
92+
}
93+
}
94+
#[allow(non_camel_case_types)]
95+
pub struct SecP521R1KeyExchange {
96+
priv_key: ::p521::ecdh::EphemeralSecret,
97+
pub_key: Box<[u8]>,
98+
}
99+
impl crypto::ActiveKeyExchange for SecP521R1KeyExchange {
100+
fn complete(
101+
self: Box<SecP521R1KeyExchange>,
102+
peer: &[u8],
103+
) -> Result<SharedSecret, rustls::Error> {
104+
let their_pub = ::p521::PublicKey::from_sec1_bytes(peer)
105+
.map_err(|_| rustls::Error::from(rustls::PeerMisbehaved::InvalidKeyShare))?;
106+
Ok(self
107+
.priv_key
108+
.diffie_hellman(&their_pub)
109+
.raw_secret_bytes()
110+
.as_slice()
111+
.into())
112+
}
113+
fn pub_key(&self) -> &[u8] {
114+
&self.pub_key
115+
}
116+
fn group(&self) -> rustls::NamedGroup {
117+
SecP521R1.name()
118+
}
119+
}

0 commit comments

Comments
 (0)