Skip to content

Commit 1ed2a27

Browse files
add x448 support
1 parent a7d55e3 commit 1ed2a27

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ aes = { version = "0.8.4", default-features = false, optional = true }
2424
aes-gcm = { version = "0.10.3", default-features = false, optional = true }
2525
ccm = { version = "0.5.0", default-features = false, optional = true }
2626
chacha20poly1305 = { version = "0.10.1", default-features = false, optional = true }
27+
crrl = { version = "0.9.0", default-features = false, optional = true }
2728
crypto-common = { version = "0.1.6", default-features = false }
2829
der = { version = "0.7.9", default-features = false, optional = true }
2930
digest = { version = "0.10.7", default-features = false }
@@ -124,12 +125,13 @@ eddsa-ed25519 = ["eddsa", "ed25519"]
124125
eddsa-full = ["eddsa-ed25519"]
125126

126127
kx = ["rand", "elliptic-curve"]
128+
kx-x448 = ["kx", "x448"]
127129
kx-x25519 = ["kx", "dep:x25519-dalek"]
128130
kx-nist = ["sec1"]
129131
kx-p256 = ["kx", "p256", "kx-nist", "p256/ecdh"]
130132
kx-p384 = ["kx", "p384", "kx-nist", "p384/ecdh"]
131133
kx-p521 = ["kx", "p521", "kx-nist", "p521/ecdh"]
132-
kx-full = ["kx-x25519", "kx-p256", "kx-p384", "kx-p521"]
134+
kx-full = ["kx-x448", "kx-x25519", "kx-p256", "kx-p384", "kx-p521"]
133135

134136
rsa = ["dep:rsa", "rsa/sha2", "pkcs1"]
135137
rsa-pkcs1 = ["rsa", "pkcs1"]
@@ -222,4 +224,5 @@ chacha20poly1305 = ["dep:chacha20poly1305"]
222224
elliptic-curve = ["dep:elliptic-curve"]
223225
gcm = []
224226
rand = ["dep:rand_core", "signature?/rand_core"]
225-
signature = ["dep:signature"]
227+
signature = ["dep:signature"]
228+
x448 = ["dep:crrl", "crrl/x448"]

src/kx.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use rustls::crypto::SupportedKxGroup;
22

33
pub const ALL_KX_GROUPS: &[&dyn SupportedKxGroup] = &[
4+
#[cfg(feature = "kx-x448")]
5+
&x448::X448,
46
#[cfg(feature = "kx-x25519")]
57
&x25519::X25519,
68
#[cfg(feature = "kx-p256")]
@@ -16,3 +18,6 @@ pub mod nist;
1618

1719
#[cfg(feature = "kx-x25519")]
1820
pub mod x25519;
21+
22+
#[cfg(feature = "kx-x448")]
23+
pub mod x448;

src/kx/x448.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#[cfg(feature = "alloc")]
2+
use alloc::boxed::Box;
3+
4+
use crrl::x448::{x448, x448_base};
5+
use crypto::{SharedSecret, SupportedKxGroup};
6+
use rand_core::RngCore;
7+
use rustls::crypto::{self, ActiveKeyExchange};
8+
9+
#[derive(Debug)]
10+
pub struct X448;
11+
12+
impl crypto::SupportedKxGroup for X448 {
13+
fn name(&self) -> rustls::NamedGroup {
14+
rustls::NamedGroup::X448
15+
}
16+
17+
fn start(&self) -> Result<Box<dyn ActiveKeyExchange>, rustls::Error> {
18+
let priv_key = {
19+
let mut bytes = [0u8; 56];
20+
rand_core::OsRng.fill_bytes(&mut bytes);
21+
bytes
22+
};
23+
let pub_key = x448_base(&priv_key);
24+
Ok(Box::new(X448KeyExchange { priv_key, pub_key }))
25+
}
26+
}
27+
28+
pub struct X448KeyExchange {
29+
priv_key: [u8; 56],
30+
pub_key: [u8; 56],
31+
}
32+
33+
impl ActiveKeyExchange for X448KeyExchange {
34+
fn complete(self: Box<X448KeyExchange>, peer: &[u8]) -> Result<SharedSecret, rustls::Error> {
35+
let peer_public: [u8; 56] = peer
36+
.try_into()
37+
.map_err(|_| rustls::Error::from(rustls::PeerMisbehaved::InvalidKeyShare))?;
38+
Ok(x448(&peer_public, &self.priv_key).as_ref().into())
39+
}
40+
41+
fn pub_key(&self) -> &[u8] {
42+
self.pub_key.as_slice()
43+
}
44+
45+
fn group(&self) -> rustls::NamedGroup {
46+
X448.name()
47+
}
48+
}

validation/local_ping_pong_openssl/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ mod test {
128128
vs_openssl_as_client(group_list, OpenSslCipherSuites::default());
129129
}
130130
#[test]
131-
#[should_panic] // no support
132131
fn vs_openssl_as_client_group_x448() {
133132
let mut group_list = OpenSslGroupsList::all_false();
134133
group_list.X448 = true;

0 commit comments

Comments
 (0)