Skip to content

Commit a67875e

Browse files
authored
feat: update to liboqs 0.13.0 (#281)
* Bump versions Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca> * Expose OQS_randombytes in oqs-sys Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca> * Expose keypair_derand KEM API Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca> * Switch example in README to standards Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca> * Add UOV Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca> * Update submodule to 0.13.0 Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca> * chore: update CHANGELOG for release Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca> --------- Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca>
1 parent 8dbac0c commit a67875e

File tree

10 files changed

+116
-9
lines changed

10 files changed

+116
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## v0.11.0 (2025-05-01)
2+
3+
- Sync with liboqs 0.13.0.
4+
- New algorithms: UOV (NIST Additional Signatures Round 2).
5+
- Updated algorithms: CROSS (Additional Signatures Round 2), MAYO (Additional Signatures Round 2).
6+
- New API for derandomized key generation with a seed.
7+
18
## v0.10.1 (2025-01-29)
29

310
- Add a `vendored-openssl` feature. (#275)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ tests.
110110
- `mayo`
111111
- `ml_dsa`
112112
- `sphincs`: SPHINCS<sup>+</sup>
113+
- `uov`
113114

114115
## Running
115116

@@ -119,8 +120,8 @@ tests.
119120
///
120121
use oqs::*;
121122
fn main() -> Result<()> {
122-
let sigalg = sig::Sig::new(sig::Algorithm::Dilithium2)?;
123-
let kemalg = kem::Kem::new(kem::Algorithm::Kyber512)?;
123+
let sigalg = sig::Sig::new(sig::Algorithm::MlDsa44)?;
124+
let kemalg = kem::Kem::new(kem::Algorithm::MlKem512)?;
124125
// A's long-term secrets
125126
let (a_sig_pk, a_sig_sk) = sigalg.keypair()?;
126127
// B's long-term secrets

oqs-sys/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "oqs-sys"
3-
version = "0.10.1+liboqs-0.12.0"
3+
version = "0.11.0+liboqs-0.13.0"
44
authors = ["Thom Wiggers <thom@thomwiggers.nl>"]
55
edition = "2021"
66
links = "oqs"
@@ -41,13 +41,14 @@ kyber = []
4141
ml_kem = []
4242
ntruprime = []
4343
# algorithms: Signature schemes
44-
sigs = ["cross", "dilithium", "falcon", "mayo", "ml_dsa", "sphincs"]
44+
sigs = ["cross", "dilithium", "falcon", "mayo", "ml_dsa", "sphincs", "uov"]
4545
cross = []
4646
dilithium = []
4747
falcon = []
4848
mayo = []
4949
ml_dsa = []
5050
sphincs = []
51+
uov = []
5152

5253
[package.metadata.docs.rs]
5354
features = ["docs"]

oqs-sys/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This crate provides the unsafe `ffi` bindings to [liboqs][].
2525
* `mayo`
2626
* `ml_dsa`
2727
* `sphincs`: SPHINCS+
28+
* `uov`
2829

2930
[oqs]: https://openquantumsafe.org
3031
[liboqs]: https://github.com/Open-Quantum-Safe/liboqs

oqs-sys/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ fn build_from_source() -> PathBuf {
8181
algorithm_feature!("SIG", "mayo");
8282
algorithm_feature!("SIG", "ml_dsa");
8383
algorithm_feature!("SIG", "sphincs");
84+
algorithm_feature!("SIG", "uov");
8485

8586
if cfg!(windows) {
8687
// Select the latest available Windows SDK
@@ -207,7 +208,7 @@ fn main() {
207208
};
208209

209210
gen_bindings("common", "OQS_.*", "");
210-
gen_bindings("rand", "OQS_(randombytes|RAND)_.*", "");
211+
gen_bindings("rand", "OQS_(randombytes|RAND).*", "");
211212
gen_bindings("kem", "OQS_KEM.*", "");
212213
gen_bindings("sig", "OQS_SIG.*", "OQS_SIG_STFL.*");
213214

oqs-sys/liboqs

Submodule liboqs updated 3005 files

oqs/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "oqs"
3-
version = "0.10.1"
3+
version = "0.11.0"
44
authors = ["Thom Wiggers <thom@thomwiggers.nl>"]
55
edition = "2021"
66
description = "A Rusty interface to Open-Quantum-Safe's liboqs"
@@ -16,7 +16,7 @@ serde = { version = "1.0", optional = true, default-features = false, features =
1616

1717
[dependencies.oqs-sys]
1818
path = "../oqs-sys"
19-
version = "0.10.1"
19+
version = "0.11.0"
2020
default-features = false
2121

2222
[features]
@@ -36,10 +36,11 @@ kyber = ["oqs-sys/kyber"]
3636
ml_kem = ["oqs-sys/ml_kem"]
3737
ntruprime = ["oqs-sys/ntruprime"]
3838
# algorithms: Signature schemes
39-
sigs = ["oqs-sys/sigs", "cross", "dilithium", "falcon", "mayo", "ml_dsa", "sphincs"]
39+
sigs = ["oqs-sys/sigs", "cross", "dilithium", "falcon", "mayo", "ml_dsa", "sphincs", "uov"]
4040
cross = ["oqs-sys/cross"]
4141
dilithium = ["oqs-sys/dilithium"]
4242
falcon = ["oqs-sys/falcon"]
4343
mayo = ["oqs-sys/mayo"]
4444
ml_dsa = ["oqs-sys/ml_dsa"]
4545
sphincs = ["oqs-sys/sphincs"]
46+
uov = ["oqs-sys/uov"]

oqs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ For the ``ffi`` interface bindings, see ``oqs-sys``.
3030
* `mayo`
3131
* `ml_dsa`
3232
* `sphincs`: SPHINCS+
33+
* `uov`

oqs/src/kem.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ newtype_buffer!(PublicKey, PublicKeyRef);
2222
newtype_buffer!(SecretKey, SecretKeyRef);
2323
newtype_buffer!(Ciphertext, CiphertextRef);
2424
newtype_buffer!(SharedSecret, SharedSecretRef);
25+
newtype_buffer!(KeypairSeed, KeypairSeedRef);
2526

2627
macro_rules! implement_kems {
2728
{ $(($feat: literal) $kem: ident: $oqs_id: ident),* $(,)? } => (
@@ -69,6 +70,36 @@ macro_rules! implement_kems {
6970
Ok(())
7071
}
7172

73+
#[test]
74+
#[cfg(feature = $feat)]
75+
fn test_encaps_decaps_derand() -> Result<()> {
76+
use crate::ffi::rand::OQS_randombytes;
77+
crate::init();
78+
79+
let alg = Algorithm::$kem;
80+
let kem = Kem::new(alg)?;
81+
let mut seed = KeypairSeed {
82+
bytes: Vec::with_capacity(kem.length_keypair_seed()),
83+
};
84+
unsafe {
85+
// On some systems, getentropy fails if given a zero-length array
86+
if (kem.length_keypair_seed() > 0) {
87+
OQS_randombytes(seed.bytes.as_mut_ptr(), kem.length_keypair_seed());
88+
}
89+
seed.bytes.set_len(kem.length_keypair_seed());
90+
}
91+
let result = kem.keypair_derand(&seed);
92+
// expect Error::Error for KEMs with this API disabled
93+
if (kem.length_keypair_seed() == 0) {
94+
return result.map_or_else(|e| { match e { Error::Error => Ok(()), _ => Err(Error::Error) } }, |_| Err(Error::Error));
95+
}
96+
let (pk, sk) = result?;
97+
let (ct, ss1) = kem.encapsulate(&pk)?;
98+
let ss2 = kem.decapsulate(&sk, &ct)?;
99+
assert_eq!(ss1, ss2, "shared secret not equal!");
100+
Ok(())
101+
}
102+
72103
#[test]
73104
fn test_enabled() {
74105
crate::init();
@@ -270,6 +301,12 @@ impl Kem {
270301
kem.length_shared_secret
271302
}
272303

304+
/// Get the length of a keypair seed
305+
pub fn length_keypair_seed(&self) -> usize {
306+
let kem = unsafe { self.kem.as_ref() };
307+
kem.length_keypair_seed
308+
}
309+
273310
/// Obtain a secret key objects from bytes
274311
///
275312
/// Returns None if the secret key is not the correct length.
@@ -314,6 +351,17 @@ impl Kem {
314351
}
315352
}
316353

354+
/// Obtain a keypair seed from bytes
355+
///
356+
/// Returns None if the shared secret is not the correct length.
357+
pub fn keypair_seed_from_bytes<'a>(&self, buf: &'a [u8]) -> Option<KeypairSeedRef<'a>> {
358+
if self.length_keypair_seed() != buf.len() {
359+
None
360+
} else {
361+
Some(KeypairSeedRef::new(buf))
362+
}
363+
}
364+
317365
/// Generate a new keypair
318366
pub fn keypair(&self) -> Result<(PublicKey, SecretKey)> {
319367
let kem = unsafe { self.kem.as_ref() };
@@ -335,6 +383,40 @@ impl Kem {
335383
Ok((pk, sk))
336384
}
337385

386+
/// Generate a new keypair from a seed
387+
pub fn keypair_derand<'a, S: Into<KeypairSeedRef<'a>>>(
388+
&self,
389+
seed: S,
390+
) -> Result<(PublicKey, SecretKey)> {
391+
let seed = seed.into();
392+
if seed.bytes.len() != self.length_keypair_seed() {
393+
return Err(Error::InvalidLength);
394+
}
395+
let kem = unsafe { self.kem.as_ref() };
396+
let func = kem.keypair_derand.unwrap();
397+
let mut pk = PublicKey {
398+
bytes: Vec::with_capacity(kem.length_public_key),
399+
};
400+
let mut sk = SecretKey {
401+
bytes: Vec::with_capacity(kem.length_secret_key),
402+
};
403+
let status = unsafe {
404+
func(
405+
pk.bytes.as_mut_ptr(),
406+
sk.bytes.as_mut_ptr(),
407+
seed.bytes.as_ptr(),
408+
)
409+
};
410+
status_to_result(status)?;
411+
// update the lengths of the vecs
412+
// this is safe to do, as we have initialised them now.
413+
unsafe {
414+
pk.bytes.set_len(kem.length_public_key);
415+
sk.bytes.set_len(kem.length_secret_key);
416+
}
417+
Ok((pk, sk))
418+
}
419+
338420
/// Encapsulate to the provided public key
339421
pub fn encapsulate<'a, P: Into<PublicKeyRef<'a>>>(
340422
&self,

oqs/src/sig.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ implement_sigs! {
205205
("sphincs") SphincsShake192sSimple: OQS_SIG_alg_sphincs_shake_192s_simple,
206206
("sphincs") SphincsShake256fSimple: OQS_SIG_alg_sphincs_shake_256f_simple,
207207
("sphincs") SphincsShake256sSimple: OQS_SIG_alg_sphincs_shake_256s_simple,
208+
("uov") UovOvIs: OQS_SIG_alg_uov_ov_Is,
209+
("uov") UovOvIp: OQS_SIG_alg_uov_ov_Ip,
210+
("uov") UovOvIII: OQS_SIG_alg_uov_ov_III,
211+
("uov") UovOvV: OQS_SIG_alg_uov_ov_V,
212+
("uov") UovOvIsPkc: OQS_SIG_alg_uov_ov_Is_pkc,
213+
("uov") UovOvIpPkc: OQS_SIG_alg_uov_ov_Ip_pkc,
214+
("uov") UovOvIIIPkc: OQS_SIG_alg_uov_ov_III_pkc,
215+
("uov") UovOvVPkc: OQS_SIG_alg_uov_ov_V_pkc,
216+
("uov") UovOvIsPkcSkc: OQS_SIG_alg_uov_ov_Is_pkc_skc,
217+
("uov") UovOvIpPkcSkc: OQS_SIG_alg_uov_ov_Ip_pkc_skc,
218+
("uov") UovOvIIIPkcSkc: OQS_SIG_alg_uov_ov_III_pkc_skc,
219+
("uov") UovOvVPkcSkc: OQS_SIG_alg_uov_ov_V_pkc_skc,
208220
}
209221

210222
impl Algorithm {

0 commit comments

Comments
 (0)