Skip to content

Commit 1e40355

Browse files
Merge pull request #195 from expressvpn/CVPN-1445-enable-mlkem-and-kyber
CVPN-1445 Add ML-KEM groups
2 parents 4ebd1ba + ad3519d commit 1e40355

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

Cargo.lock

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

wolfssl-sys/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ bindgen = "0.70"
1616
autotools = "0.2"
1717
build-target = "0.4.0"
1818

19+
[dev-dependencies]
20+
test-case = "3.0"
21+
1922
[features]
2023
default = ["postquantum"]
2124
debug = []
2225
postquantum = []
26+
kyber_only = ["postquantum"]
2327

2428
[[example]]
2529
name = "connect_pq"

wolfssl-sys/build.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ fn build_wolfssl(wolfssl_src: &Path) -> PathBuf {
145145
}
146146

147147
if cfg!(feature = "postquantum") {
148+
let flags = if cfg!(feature = "kyber_only") {
149+
"all,original"
150+
} else {
151+
"all,original,ml-kem"
152+
};
148153
// Enable Kyber
149-
conf.enable("kyber", Some("all,original"))
154+
conf.enable("kyber", Some(flags))
150155
// SHA3 is needed for using WolfSSL's implementation of Kyber/ML-KEM
151156
.enable("sha3", None);
152157
}

wolfssl-sys/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use bindings::*;
77
#[cfg(test)]
88
mod tests {
99
use std::os::raw::c_int;
10+
use test_case::test_case;
1011

1112
use super::*;
1213
#[test]
@@ -17,9 +18,10 @@ mod tests {
1718
}
1819
}
1920

20-
#[test]
2121
#[cfg(feature = "postquantum")]
22-
fn test_post_quantum_available() {
22+
#[test_case(WOLFSSL_P521_KYBER_LEVEL5)]
23+
#[cfg_attr(not(feature = "kyber_only"), test_case(WOLFSSL_P521_ML_KEM_1024))]
24+
fn test_post_quantum_available(group: std::os::raw::c_uint) {
2325
unsafe {
2426
// Init WolfSSL
2527
let res = wolfSSL_Init();
@@ -34,10 +36,9 @@ mod tests {
3436
// Create new SSL stream
3537
let ssl = wolfSSL_new(context);
3638

37-
// Enable Kyber
38-
let res = wolfSSL_UseKeyShare(ssl, WOLFSSL_P521_KYBER_LEVEL5.try_into().unwrap());
39+
let res = wolfSSL_UseKeyShare(ssl, group.try_into().unwrap());
3940

40-
// Check that Kyber was enabled
41+
// Check that Kyber/ML-KEM was enabled
4142
assert_eq!(res, WOLFSSL_SUCCESS as c_int);
4243
}
4344
}

wolfssl/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ keywords = ["wolfssl", "vpn", "lightway", "post-quantum", "cryptography"]
1212
default = ["postquantum"]
1313
postquantum = ["wolfssl-sys/postquantum"]
1414
debug = ["wolfssl-sys/debug"] # Note that application code must also call wolfssl::enable_debugging(true)
15+
kyber_only = ["wolfssl-sys/kyber_only"]
1516

1617
[lints.rust]
1718
missing_docs = "deny"

wolfssl/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ pub enum CurveGroup {
236236
/// `WOLFSSL_P521_KYBER_LEVEL5`
237237
#[cfg(feature = "postquantum")]
238238
P521KyberLevel5,
239+
240+
/// `WOLFSSL_P256_ML_KEM_512`
241+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
242+
P256MLKEM512,
243+
/// `WOLFSSL_P384_ML_KEM_768`
244+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
245+
P384MLKEM768,
246+
/// `WOLFSSL_P521_ML_KEM_1024`
247+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
248+
P521MLKEM1024,
239249
}
240250

241251
impl CurveGroup {
@@ -250,6 +260,12 @@ impl CurveGroup {
250260
P384KyberLevel3 => wolfssl_sys::WOLFSSL_P384_KYBER_LEVEL3,
251261
#[cfg(feature = "postquantum")]
252262
P521KyberLevel5 => wolfssl_sys::WOLFSSL_P521_KYBER_LEVEL5,
263+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
264+
P256MLKEM512 => wolfssl_sys::WOLFSSL_P256_ML_KEM_512,
265+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
266+
P384MLKEM768 => wolfssl_sys::WOLFSSL_P384_ML_KEM_768,
267+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
268+
P521MLKEM1024 => wolfssl_sys::WOLFSSL_P521_ML_KEM_1024,
253269
}
254270
}
255271
}

0 commit comments

Comments
 (0)