Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test a prime with 128 zeroes #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/hazmat/miller_rabin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ mod tests {
use alloc::format;
use core::num::NonZeroU32;

use crypto_bigint::{Integer, Odd, RandomMod, Uint, U1024, U128, U1536, U64};
use crypto_bigint::{Integer, Odd, RandomMod, Uint, U1024, U128, U1536, U256, U64};
use rand_chacha::ChaCha8Rng;
use rand_core::{CryptoRngCore, OsRng, SeedableRng};

Expand Down Expand Up @@ -280,6 +280,15 @@ mod tests {
test_large_primes(primes::PRIMES_1024);
}

// Test to guard against regressions such as https://github.com/RustCrypto/crypto-bigint/pull/685
#[test]
fn zero_padded_input_works() {
// A prime that happens to have 128 starting zeroes.
let hex = "00000000000000000000000000000000E0BD7D7A037746B47ABDDC706525370F";
let num = U256::from_be_hex(hex);
test_large_primes(&[num]);
}

#[cfg(feature = "tests-exhaustive")]
#[test]
fn exhaustive() {
Expand Down
11 changes: 2 additions & 9 deletions src/presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ fn _is_prime_with_rng<T: Integer + RandomMod>(rng: &mut impl CryptoRngCore, num:

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

use super::{
generate_prime, generate_prime_with_rng, generate_safe_prime, generate_safe_prime_with_rng,
Expand Down Expand Up @@ -381,12 +380,6 @@ mod tests {
}
}
}

#[test]
fn generate_prime_into_int_double_size_precision() {
let mut rng = ChaCha8Rng::from_seed(*b"01234567890123456789012345678901");
let _p = generate_safe_prime_with_rng::<U256>(&mut rng, 128, 256);
}
}

#[cfg(test)]
Expand Down
Loading