internal/radix51: make Generate produce random light-reduced elements

This commit is contained in:
Filippo Valsorda 2019-04-03 12:50:50 -04:00 committed by George Tankersley
parent 5382f6dbc9
commit d4456f99c1
1 changed files with 8 additions and 9 deletions

View File

@ -21,17 +21,16 @@ import (
var quickCheckConfig = &quick.Config{MaxCountScale: 1 << 10}
func generateFieldElement(rand *mathrand.Rand) FieldElement {
// Generation strategy: generate random limb values bounded by
// 2**(51+b), where b is a parameter controlling the bit-excess.
// Generation strategy: generate random limb values of [52, 51, 51, 51, 51]
// bits, like the ones returned by lightReduce.
// TODO: randomly decide to set the limbs to "weird" values.
b := uint64(0) // TODO: set this higher once we know the bounds.
mask := (uint64(1) << (51 + b)) - 1
const maskLow52Bits = (1 << 52) - 1
return FieldElement{
rand.Uint64() & mask,
rand.Uint64() & mask,
rand.Uint64() & mask,
rand.Uint64() & mask,
rand.Uint64() & mask,
rand.Uint64() & maskLow52Bits,
rand.Uint64() & maskLow51Bits,
rand.Uint64() & maskLow51Bits,
rand.Uint64() & maskLow51Bits,
rand.Uint64() & maskLow51Bits,
}
}