Skip to content

Commit 57d6cd9

Browse files
committed
CVPN-1445 Add ML-KEM group
Add relevant tests and different ML-KEM groups to be used in the Lightway. The config flags can be found here: #192
1 parent 7a1e3d1 commit 57d6cd9

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ 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 = []

wolfssl-sys/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn build_wolfssl(wolfssl_src: &Path) -> PathBuf {
146146

147147
if cfg!(feature = "postquantum") {
148148
// Enable Kyber
149-
conf.enable("kyber", Some("all,original"))
149+
conf.enable("kyber", Some("all,original,ml-kem"))
150150
// SHA3 is needed for using WolfSSL's implementation of Kyber/ML-KEM
151151
.enable("sha3", None);
152152
}

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+
#[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/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(feature = "postquantum")]
242+
P256MLKEM512,
243+
/// `WOLFSSL_P384_ML_KEM_768`
244+
#[cfg(feature = "postquantum")]
245+
P384MLKEM768,
246+
/// `WOLFSSL_P521_ML_KEM_1024`
247+
#[cfg(feature = "postquantum")]
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(feature = "postquantum")]
264+
P256MLKEM512 => wolfssl_sys::WOLFSSL_P256_ML_KEM_512,
265+
#[cfg(feature = "postquantum")]
266+
P384MLKEM768 => wolfssl_sys::WOLFSSL_P384_ML_KEM_768,
267+
#[cfg(feature = "postquantum")]
268+
P521MLKEM1024 => wolfssl_sys::WOLFSSL_P521_ML_KEM_1024,
253269
}
254270
}
255271
}

0 commit comments

Comments
 (0)