Use negative non-residue optimization
ValarDragon dojha12@gmail.com
Fri, 05 Feb 2021 11:53:30 -0600
1 files changed,
21 insertions(+),
0 deletions(-)
jump to
M
bls12_377/src/fields/fq2.rs
→
bls12_377/src/fields/fq2.rs
@@ -25,12 +25,33 @@ // NONRESIDUE**(((q^1) - 1) / 2)
field_new!(Fq, "-1"), ]; + // Mul by -5 #[inline(always)] fn mul_fp_by_nonresidue(fe: &Self::Fp) -> Self::Fp { let original = fe; let mut fe = -fe.double(); fe.double_in_place(); fe - original + } + + // x + -5 * y, computed as x - 5*y + #[inline(always)] + fn add_and_mul_fp_by_nonresidue(x: &Self::Fp, y: &Self::Fp) -> Self::Fp { + // c becomes 5 * y + let mut c = y.double(); + c.double_in_place(); + c += y; + *x - c + } + + // x - (-5 * y), computed as x + 5*y + #[inline(always)] + fn sub_and_mul_fp_by_nonresidue(x: &Self::Fp, y: &Self::Fp) -> Self::Fp { + // c becomes 5 * y + let mut c = y.double(); + c.double_in_place(); + c += y; + *x + c } }