Browse Source

Mask rather than divn, closes #50.

master
Sean Bowe 7 years ago
parent
commit
93e2a132b5
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
  1. 5
      src/bls12_381/fq.rs
  2. 5
      src/bls12_381/fr.rs

5
src/bls12_381/fq.rs

@ -415,7 +415,10 @@ impl ::rand::Rand for Fq {
fn rand<R: ::rand::Rng>(rng: &mut R) -> Self {
loop {
let mut tmp = Fq(FqRepr::rand(rng));
tmp.0.divn(REPR_SHAVE_BITS);
// Mask away the unused bits at the beginning.
tmp.0.as_mut()[5] &= 0xffffffffffffffff >> REPR_SHAVE_BITS;
if tmp.is_valid() {
return tmp
}

5
src/bls12_381/fr.rs

@ -237,7 +237,10 @@ impl ::rand::Rand for Fr {
fn rand<R: ::rand::Rng>(rng: &mut R) -> Self {
loop {
let mut tmp = Fr(FrRepr::rand(rng));
tmp.0.divn(REPR_SHAVE_BITS);
// Mask away the unused bits at the beginning.
tmp.0.as_mut()[3] &= 0xffffffffffffffff >> REPR_SHAVE_BITS;
if tmp.is_valid() {
return tmp
}

Loading…
Cancel
Save