Add documentation of perfect hash parameters.

This commit is contained in:
Daira Hopwood 2021-01-17 02:24:09 +00:00 committed by GitHub
parent adc3c9c2ea
commit c7a12ee178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 0 deletions

View File

@ -151,6 +151,10 @@ struct SqrtHasher<F: FieldExt> {
impl<F: FieldExt> SqrtHasher<F> {
/// Returns a perfect hash of x for use with SqrtTables::inv.
fn hash(&self, x: &F) -> usize {
// This is just the simplest constant-time perfect hash construction that could
// possibly work. The 32 low-order bits are unique within the 2^S order subgroup,
// then the xor acts as "salt" to injectively randomize the output when taken modulo
// `hash_mod`. Since the table is small, we do not need anything more complicated.
((x.get_lower_32() ^ self.hash_xor) as usize) % self.hash_mod
}
}

View File

@ -600,6 +600,7 @@ impl ff::PrimeField for Fp {
}
lazy_static! {
// The perfect hash parameters are found by `squareroottab.sage` in zcash/pasta.
static ref FP_TABLES: SqrtTables<Fp> = SqrtTables::new(0x11BE, 1098);
}

View File

@ -600,6 +600,7 @@ impl ff::PrimeField for Fq {
}
lazy_static! {
// The perfect hash parameters are found by `squareroottab.sage` in zcash/pasta.
static ref FQ_TABLES: SqrtTables<Fq> = SqrtTables::new(0x116A9E, 1206);
}