#[cfg(any(feature = "arkworks-algebra", feature = "zkcrypto-group"))]
mod traits;
#[cfg(feature = "arkworks-algebra")]
pub mod arkworks_algebra;
#[cfg(feature = "zkcrypto-group")]
pub mod zkcrypto_group;
pub(super) const fn bytes_uniform_modp(modulus_bits: u32) -> usize {
(modulus_bits as usize + 128) / 8
}
#[cfg(feature = "arkworks-algebra")]
pub(super) fn random_bits_in_random_modp<const N: usize>(b: ark_ff::BigInt<N>) -> usize {
use ark_ff::{BigInt, BigInteger};
for n in (0..=b.num_bits()).rev() {
let r_bits = &b.to_bits_le()[..n as usize];
let r = BigInt::<N>::from_bits_le(r_bits);
let log2_a_minus_r = r_bits.iter().rev().skip_while(|&&bit| bit).count() as u32;
if b.num_bits() + n - 1 - r.num_bits() - log2_a_minus_r >= 128 {
return n as usize;
}
}
0
}
#[cfg(feature = "arkworks-algebra")]
pub(super) fn random_bytes_in_random_modp<const N: usize>(modulus: ark_ff::BigInt<N>) -> usize {
random_bits_in_random_modp(modulus) / 8
}
pub(super) const fn bytes_modp(modulus_bits: u32) -> usize {
(modulus_bits as usize).div_ceil(8)
}
#[cfg(all(test, feature = "arkworks-algebra", feature = "zkcrypto-group"))]
mod tests;