diff --git a/bls12_381/src/fields/fq2.rs b/bls12_381/src/fields/fq2.rs index 917c136..46fbf41 100644 --- a/bls12_381/src/fields/fq2.rs +++ b/bls12_381/src/fields/fq2.rs @@ -29,6 +29,18 @@ impl Fp2Parameters for Fq2Parameters { fn mul_fp_by_nonresidue(fp: &Self::Fp) -> Self::Fp { -(*fp) } + + // x + -1 * y, computed as x - y + #[inline(always)] + fn add_and_mul_fp_by_nonresidue(x: &Self::Fp, y: &Self::Fp) -> Self::Fp { + *x - y + } + + // x - (-1 * y), computed as x + y + #[inline(always)] + fn sub_and_mul_fp_by_nonresidue(x: &Self::Fp, y: &Self::Fp) -> Self::Fp { + *x + y + } } pub const FQ2_ZERO: Fq2 = field_new!(Fq2, FQ_ZERO, FQ_ZERO); diff --git a/bn254/src/fields/fq2.rs b/bn254/src/fields/fq2.rs index 8231c56..fbde01c 100644 --- a/bn254/src/fields/fq2.rs +++ b/bn254/src/fields/fq2.rs @@ -32,6 +32,18 @@ impl Fp2Parameters for Fq2Parameters { fn mul_fp_by_nonresidue(fe: &Self::Fp) -> Self::Fp { -(*fe) } + + // x + -1 * y, computed as x - y + #[inline(always)] + fn add_and_mul_fp_by_nonresidue(x: &Self::Fp, y: &Self::Fp) -> Self::Fp { + *x - y + } + + // x - (-1 * y), computed as x + y + #[inline(always)] + fn sub_and_mul_fp_by_nonresidue(x: &Self::Fp, y: &Self::Fp) -> Self::Fp { + *x + y + } } pub const FQ2_ZERO: Fq2 = field_new!(Fq2, FQ_ZERO, FQ_ZERO);