Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions src/algorithms/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use alloc::vec::Vec;
use crypto_bigint::{BoxedUint, Odd};
use crypto_primes::{
hazmat::{SetBits, SmallPrimesSieveFactory},
is_prime, sieve_and_find,
hazmat::{SetBits, SmallFactorsSieveFactory},
is_prime, sieve_and_find, Flavor,
};
use rand_core::CryptoRng;

Expand Down Expand Up @@ -121,11 +121,13 @@ pub(crate) fn generate_multi_prime_key_with_exp<R: CryptoRng + ?Sized>(
}

fn generate_prime_with_rng<R: CryptoRng + ?Sized>(rng: &mut R, bit_length: u32) -> BoxedUint {
sieve_and_find(
rng,
SmallPrimesSieveFactory::new(bit_length, SetBits::TwoMsb),
|_rng, candidate| is_prime(candidate),
)
let factory = SmallFactorsSieveFactory::new(Flavor::Any, bit_length, SetBits::TwoMsb)
.unwrap_or_else(|err| panic!("Error creating the sieve: {err}"));

sieve_and_find(rng, factory, |_rng, candidate| {
is_prime(Flavor::Any, candidate)
})
.unwrap_or_else(|err| panic!("Error generating random candidates: {}", err))
.expect("will produce a result eventually")
}

Expand Down