Skip to content

Commit

Permalink
Add getrandom feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Christiaan676 committed Sep 19, 2024
1 parent 067bde1 commit 0fd7669
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions x-wing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ homepage = "https://github.com/RustCrypto/KEMs/tree/master/ml-kem"
repository = "https://github.com/RustCrypto/KEMs"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "x-wing", "xwing", "kem", "post-quantum"]
exclude = ["src/test-vectors.json"]


[features]
getrandom = ["rand_core/getrandom"]

[lints.clippy]
pedantic = "warn" # Be pedantic by default
Expand Down
12 changes: 12 additions & 0 deletions x-wing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ pub struct DecapsulationKey {
}

impl DecapsulationKey {
/// Generate a new `DecapsulationKey` using `OsRng`
#[cfg(feature = "getrandom")]
pub fn generate_rng() -> DecapsulationKey {
Self::generate(&mut rand_core::OsRng)
}

/// Generate a new `DecapsulationKey` using the provided RNG
pub fn generate(rng: &mut impl CryptoRngCore) -> DecapsulationKey {
let sk = generate(rng);
Expand Down Expand Up @@ -211,6 +217,12 @@ impl From<&[u8; 1120]> for Ciphertext {
}
}

/// Generate a X-Wing key pair using a the `OsRng`
#[cfg(feature = "getrandom")]
pub fn generate_key_pair_rng() -> (DecapsulationKey, EncapsulationKey) {
generate_key_pair(&mut rand_core::OsRng)
}

/// Generate a X-Wing key pair
pub fn generate_key_pair(rng: &mut impl CryptoRngCore) -> (DecapsulationKey, EncapsulationKey) {
let sk = DecapsulationKey::generate(rng);
Expand Down

0 comments on commit 0fd7669

Please sign in to comment.