Mask rather than divn, closes #50.

This commit is contained in:
Sean Bowe 2017-09-28 13:15:29 -06:00
parent 291fa71914
commit 93e2a132b5
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
2 changed files with 8 additions and 2 deletions

View File

@ -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
}

View File

@ -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
}