mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-11-01 20:07:02 +00:00
Migrate ff to rand_core 0.3 (used by rand 0.5)
This commit is contained in:
@@ -136,13 +136,6 @@ fn prime_field_repr_impl(repr: &syn::Ident, limbs: usize) -> proc_macro2::TokenS
|
||||
}
|
||||
}
|
||||
|
||||
impl ::rand::Rand for #repr {
|
||||
#[inline(always)]
|
||||
fn rand<R: ::rand::Rng>(rng: &mut R) -> Self {
|
||||
#repr(rng.gen())
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Display for #repr {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
try!(write!(f, "0x"));
|
||||
@@ -839,22 +832,6 @@ fn prime_field_impl(
|
||||
}
|
||||
}
|
||||
|
||||
impl ::rand::Rand for #name {
|
||||
/// Computes a uniformly random element using rejection sampling.
|
||||
fn rand<R: ::rand::Rng>(rng: &mut R) -> Self {
|
||||
loop {
|
||||
let mut tmp = #name(#repr::rand(rng));
|
||||
|
||||
// Mask away the unused bits at the beginning.
|
||||
tmp.0.as_mut()[#top_limb_index] &= 0xffffffffffffffff >> REPR_SHAVE_BITS;
|
||||
|
||||
if tmp.is_valid() {
|
||||
return tmp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<#name> for #repr {
|
||||
fn from(e: #name) -> #repr {
|
||||
e.into_repr()
|
||||
@@ -904,6 +881,26 @@ fn prime_field_impl(
|
||||
}
|
||||
|
||||
impl ::ff::Field for #name {
|
||||
/// Computes a uniformly random element using rejection sampling.
|
||||
fn random<R: ::rand_core::RngCore>(rng: &mut R) -> Self {
|
||||
loop {
|
||||
let mut tmp = {
|
||||
let mut repr = [0u64; #limbs];
|
||||
for i in 0..#limbs {
|
||||
repr[i] = rng.next_u64();
|
||||
}
|
||||
#name(#repr(repr))
|
||||
};
|
||||
|
||||
// Mask away the unused bits at the beginning.
|
||||
tmp.0.as_mut()[#top_limb_index] &= 0xffffffffffffffff >> REPR_SHAVE_BITS;
|
||||
|
||||
if tmp.is_valid() {
|
||||
return tmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn zero() -> Self {
|
||||
#name(#repr::from(0))
|
||||
|
||||
Reference in New Issue
Block a user