Skip to content

Commit ad3519d

Browse files
committed
CVPN-1445 Add feature to build wolfssl with kyber only
Added a new feature "kyber_only" to build with kyber only so that a kyber client can be built without any of the ML-KEM flags and thus preventing a kyber client to use ML-KEM after negotiation.
1 parent 57d6cd9 commit ad3519d

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

wolfssl-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ test-case = "3.0"
2323
default = ["postquantum"]
2424
debug = []
2525
postquantum = []
26+
kyber_only = ["postquantum"]
2627

2728
[[example]]
2829
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,ml-kem"))
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod tests {
2020

2121
#[cfg(feature = "postquantum")]
2222
#[test_case(WOLFSSL_P521_KYBER_LEVEL5)]
23-
#[test_case(WOLFSSL_P521_ML_KEM_1024)]
23+
#[cfg_attr(not(feature = "kyber_only"), test_case(WOLFSSL_P521_ML_KEM_1024))]
2424
fn test_post_quantum_available(group: std::os::raw::c_uint) {
2525
unsafe {
2626
// Init WolfSSL

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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ pub enum CurveGroup {
238238
P521KyberLevel5,
239239

240240
/// `WOLFSSL_P256_ML_KEM_512`
241-
#[cfg(feature = "postquantum")]
241+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
242242
P256MLKEM512,
243243
/// `WOLFSSL_P384_ML_KEM_768`
244-
#[cfg(feature = "postquantum")]
244+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
245245
P384MLKEM768,
246246
/// `WOLFSSL_P521_ML_KEM_1024`
247-
#[cfg(feature = "postquantum")]
247+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
248248
P521MLKEM1024,
249249
}
250250

@@ -260,11 +260,11 @@ impl CurveGroup {
260260
P384KyberLevel3 => wolfssl_sys::WOLFSSL_P384_KYBER_LEVEL3,
261261
#[cfg(feature = "postquantum")]
262262
P521KyberLevel5 => wolfssl_sys::WOLFSSL_P521_KYBER_LEVEL5,
263-
#[cfg(feature = "postquantum")]
263+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
264264
P256MLKEM512 => wolfssl_sys::WOLFSSL_P256_ML_KEM_512,
265-
#[cfg(feature = "postquantum")]
265+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
266266
P384MLKEM768 => wolfssl_sys::WOLFSSL_P384_ML_KEM_768,
267-
#[cfg(feature = "postquantum")]
267+
#[cfg(all(feature = "postquantum", not(feature = "kyber_only")))]
268268
P521MLKEM1024 => wolfssl_sys::WOLFSSL_P521_ML_KEM_1024,
269269
}
270270
}

0 commit comments

Comments
 (0)