1use crypto_bigint::Odd;
2use crypto_primitives::crypto_bigint_uint::Uint;
3use std::fmt::Debug;
4
5pub trait PrimalityTest<R>: Debug + Clone {
6 fn is_probably_prime(candidate: &R) -> bool;
7}
8
9#[derive(Debug, Clone, Copy)]
10pub struct MillerRabin {}
11
12impl<const LIMBS: usize> PrimalityTest<Uint<LIMBS>> for MillerRabin {
13 fn is_probably_prime(candidate: &Uint<LIMBS>) -> bool {
14 let Some(odd) = Odd::new(*candidate.inner()).into_option() else {
15 return false;
16 };
17 let test = crypto_primes::hazmat::MillerRabin::new(odd);
18 test.test_base_two().is_probably_prime()
19 }
20}