Skip to content

Commit

Permalink
x-wing: use rand::rngs::OsRng in code example (#98)
Browse files Browse the repository at this point in the history
This is the most conservative choice for a random number generator for
keygen, which is a thin wrapper for the `getrandom` crate, which gets
randomness directly from the OS.

Also removes superfluous newlines in the example, and makes the imported
traits explicit so the code example is complete.
  • Loading branch information
tarcieri authored Jan 21, 2025
1 parent 9231075 commit de49bf1
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions x-wing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
//! decapsulation key. X-Wing-KEM is a general-purpose hybrid post-quantum KEM, combining x25519 and ML-KEM-768.
//!
//! ```
//! # use rand;
//! # use kem::{Decapsulate, Encapsulate};
//! let mut rng = rand::thread_rng();
//!
//! let (sk, pk) = x_wing::generate_key_pair(&mut rng);
//!
//! let (ct, ss_sender) = pk.encapsulate(&mut rng).unwrap();
//! use kem::{Decapsulate, Encapsulate};
//!
//! let mut rng = &mut rand::rngs::OsRng;
//! let (sk, pk) = x_wing::generate_key_pair(rng);
//! let (ct, ss_sender) = pk.encapsulate(rng).unwrap();
//! let ss_receiver = sk.decapsulate(&ct).unwrap();
//!
//! assert_eq!(ss_sender, ss_receiver);
//! ```
Expand Down

0 comments on commit de49bf1

Please sign in to comment.