Address @ebfull's review comments.

Co-authored-by: Sean Bowe <sean@electriccoin.co>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood 2021-01-13 00:12:12 +00:00
parent af9834d68c
commit c5e48fdd06
4 changed files with 24 additions and 12 deletions

View file

@ -160,10 +160,10 @@ impl<F: FieldExt> SqrtHasher<F> {
pub struct SqrtTables<F: FieldExt> {
hasher: SqrtHasher<F>,
inv: Vec<u8>,
g0: [F; 256],
g1: [F; 256],
g2: [F; 256],
g3: [F; 129],
g0: Box<[F; 256]>,
g1: Box<[F; 256]>,
g2: Box<[F; 256]>,
g3: Box<[F; 129]>,
}
impl<F: FieldExt> SqrtTables<F> {
@ -202,10 +202,10 @@ impl<F: FieldExt> SqrtTables<F> {
SqrtTables::<F> {
hasher,
inv,
g0: gtab[0][..].try_into().unwrap(),
g1: gtab[1][..].try_into().unwrap(),
g2: gtab[2][..].try_into().unwrap(),
g3: gtab[3][0..129].try_into().unwrap(),
g0: Box::new(gtab[0][..].try_into().unwrap()),
g1: Box::new(gtab[1][..].try_into().unwrap()),
g2: Box::new(gtab[2][..].try_into().unwrap()),
g3: Box::new(gtab[3][0..129].try_into().unwrap()),
}
}

View file

@ -796,7 +796,6 @@ impl FieldExt for Fp {
let rr = sqr(rq, 7) * r111;
let rs = sqr(rr, 3) * r11;
let rt = rs.square();
//assert!(rt == ff::Field::pow_vartime(&self, &Fp::T_MINUS1_OVER2));
rt
}
}
@ -837,6 +836,13 @@ fn test_sqrt() {
assert!(v == Fp::TWO_INV || (-v) == Fp::TWO_INV);
}
#[test]
fn test_pow_by_t_minus1_over2() {
// NB: TWO_INV is standing in as a "random" field element
let v = (Fp::TWO_INV).pow_by_t_minus1_over2();
assert!(v == ff::Field::pow_vartime(&Fp::TWO_INV, &Fp::T_MINUS1_OVER2));
}
#[test]
fn test_sqrt_ratio_and_alt() {
// (true, sqrt(num/div)), if num and div are nonzero and num/div is a square in the field

View file

@ -796,7 +796,6 @@ impl FieldExt for Fq {
let sr = sqr(sq, 5) * s1011;
let ss = sqr(sr, 3) * self;
let st = sqr(ss, 4);
//assert!(st == ff::Field::pow_vartime(&self, &Fq::T_MINUS1_OVER2));
st
}
}
@ -837,6 +836,13 @@ fn test_sqrt() {
assert!(v == Fq::TWO_INV || (-v) == Fq::TWO_INV);
}
#[test]
fn test_pow_by_t_minus1_over2() {
// NB: TWO_INV is standing in as a "random" field element
let v = (Fq::TWO_INV).pow_by_t_minus1_over2();
assert!(v == ff::Field::pow_vartime(&Fq::TWO_INV, &Fq::T_MINUS1_OVER2));
}
#[test]
fn test_sqrt_ratio_and_alt() {
// (true, sqrt(num/div)), if num and div are nonzero and num/div is a square in the field

View file

@ -38,8 +38,8 @@ impl<C: CurveAffine> Params<C> {
// This is usually a limitation on the curve, but we also want 32-bit
// architectures to be supported.
assert!(k < 32);
// No goofy hardware please.
assert!(core::mem::size_of::<usize>() >= 4);
// In src/arithmetic/fields.rs we ensure that usize is at least 32 bits.
let n: u64 = 1 << k;