Generate uniformly random scalar w/ Fr::from_bytes_wide()

Which reduces mod r always.
This commit is contained in:
Deirdre Connolly 2020-07-28 17:31:41 -04:00 committed by Deirdre Connolly
parent 8f15ed8140
commit e22afa3c8f
1 changed files with 3 additions and 2 deletions

View File

@ -30,9 +30,10 @@ pub fn generate_trapdoor<T>(csprng: &mut T) -> jubjub::Fr
where
T: RngCore + CryptoRng,
{
let mut bytes = [0u8; 32];
let mut bytes = [0u8; 64];
csprng.fill_bytes(&mut bytes);
jubjub::Fr::from_bytes(&bytes).unwrap()
// Fr::from_bytes_wide() reduces the input modulo r via Fr::from_u512()
jubjub::Fr::from_bytes_wide(&bytes)
}
/// "...an algebraic hash function with collision resistance (for