Skip to content

Commit

Permalink
chore: change to chacha based Rng in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Mar 23, 2024
1 parent 1ba7a2c commit 3ccf2dc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ winter-math = { version = "0.8", default-features = false }
winter-utils = { version = "0.8", default-features = false }

[dev-dependencies]
rand_chacha = { version = "0.3", default-features = false }
criterion = { version = "0.5", features = ["html_reports"] }
getrandom = { version = "0.2", features = ["js"] }
hex = { version = "0.4", default-features = false, features = ["alloc"] }
Expand Down
8 changes: 5 additions & 3 deletions src/dsa/rpo_falcon512/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ pub use secret_key::SecretKey;

#[cfg(test)]
mod tests {
use crate::{dsa::rpo_falcon512::SecretKey, rand::RpoRandomCoin, Word, ONE, ZERO};
use crate::{dsa::rpo_falcon512::SecretKey, Word, ONE};
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use winter_math::FieldElement;
use winter_utils::{Deserializable, Serializable};

#[test]
fn test_falcon_verification() {
let seed = [ZERO; 4];
let mut rng = RpoRandomCoin::new(seed);
let seed = [0_u8; 32];
let mut rng = ChaCha20Rng::from_seed(seed);

// generate random keys
let sk = SecretKey::with_rng(&mut rng);
Expand Down
7 changes: 4 additions & 3 deletions src/dsa/rpo_falcon512/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,13 @@ fn are_coefficients_valid(x: &[i16]) -> bool {
#[cfg(test)]
mod tests {
use super::{super::SecretKey, *};
use crate::{rand::RpoRandomCoin, ZERO};
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;

#[test]
fn test_serialization_round_trip() {
let seed = [ZERO; 4];
let mut rng = RpoRandomCoin::new(seed);
let seed = [0_u8; 32];
let mut rng = ChaCha20Rng::from_seed(seed);

let sk = SecretKey::with_rng(&mut rng);
let signature = sk.sign_with_rng(Word::default(), &mut rng);
Expand Down

0 comments on commit 3ccf2dc

Please sign in to comment.