mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-09 07:21:30 +01:00
Optimizations to field and curve arithmetic
This commit is contained in:
@@ -21,7 +21,7 @@ impl Fp2Config for Fq2Config {
|
||||
];
|
||||
|
||||
#[inline(always)]
|
||||
fn mul_fp_by_nonresidue(fe: &Self::Fp) -> Self::Fp {
|
||||
-(*fe)
|
||||
fn mul_fp_by_nonresidue_in_place(fe: &mut Self::Fp) -> &mut Self::Fp {
|
||||
fe.neg_in_place()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,12 +90,16 @@ impl Fp6Config for Fq6Config {
|
||||
];
|
||||
|
||||
#[inline(always)]
|
||||
fn mul_fp2_by_nonresidue(fe: &Fq2) -> Fq2 {
|
||||
fn mul_fp2_by_nonresidue_in_place(fe: &mut Fq2) -> &mut Fq2 {
|
||||
// (c0+u*c1)*(9+u) = (9*c0-c1)+u*(9*c1+c0)
|
||||
let mut f = *fe;
|
||||
f.double_in_place().double_in_place().double_in_place();
|
||||
let c0 = f.c0 + fe.c0 + Fq2Config::mul_fp_by_nonresidue(&fe.c1);
|
||||
let mut c0 = fe.c1;
|
||||
Fq2Config::mul_fp_by_nonresidue_in_place(&mut c0);
|
||||
c0 += &f.c0;
|
||||
c0 += &fe.c0;
|
||||
let c1 = f.c1 + fe.c1 + fe.c0;
|
||||
Fq2::new(c0, c1)
|
||||
*fe = Fq2::new(c0, c1);
|
||||
fe
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ fn test_fq2_legendre() {
|
||||
// i^2 = -1
|
||||
let mut m1 = -Fq2::one();
|
||||
assert_eq!(QuadraticResidue, m1.legendre());
|
||||
m1 = Fq6Config::mul_fp2_by_nonresidue(&m1);
|
||||
Fq6Config::mul_fp2_by_nonresidue_in_place(&mut m1);
|
||||
assert_eq!(QuadraticNonResidue, m1.legendre());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user