Skip to content

Commit

Permalink
Add tests for BoxedUint
Browse files Browse the repository at this point in the history
  • Loading branch information
xuganyu96 authored and fjarri committed Dec 29, 2023
1 parent 84aa62b commit 64965d0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn _is_prime_with_rng<T: Integer + RandomMod>(rng: &mut impl CryptoRngCore, num:

#[cfg(test)]
mod tests {
use crypto_bigint::{CheckedAdd, Uint, Word, U128, U64};
use crypto_bigint::{BoxedUint, CheckedAdd, Uint, Word, U128, U64};
use num_prime::nt_funcs::is_prime64;
use rand_core::OsRng;

Expand Down Expand Up @@ -279,6 +279,15 @@ mod tests {
}
}

#[test]
fn prime_generation_boxed() {
for bit_length in (28..=128).step_by(10) {
let p: BoxedUint = generate_prime(bit_length, 128);
assert!(p.bits_vartime() == bit_length);
assert!(is_prime(&p));
}
}

#[test]
fn safe_prime_generation() {
for bit_length in (28..=128).step_by(10) {
Expand All @@ -288,6 +297,15 @@ mod tests {
}
}

#[test]
fn safe_prime_generation_boxed() {
for bit_length in (28..=128).step_by(10) {
let p: BoxedUint = generate_safe_prime(bit_length, 128);
assert!(p.bits_vartime() == bit_length);
assert!(is_safe_prime(&p));
}
}

#[test]
fn corner_cases_is_prime() {
for num in 0u64..30 {
Expand Down

0 comments on commit 64965d0

Please sign in to comment.