mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-10 16:01:32 +01:00
GLV implementation for BLS12_377, BLS12_381 and BN254 (#158)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use crate::{fq::Fq, fr::Fr};
|
||||
use ark_ec::{
|
||||
models::CurveConfig,
|
||||
scalar_mul::glv::GLVConfig,
|
||||
short_weierstrass::{self as sw, SWCurveConfig},
|
||||
};
|
||||
use ark_ff::{AdditiveGroup, Field, MontFp, Zero};
|
||||
use ark_ff::{AdditiveGroup, BigInt, Field, MontFp, PrimeField, Zero};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -41,6 +42,40 @@ impl SWCurveConfig for VestaConfig {
|
||||
}
|
||||
}
|
||||
|
||||
impl GLVConfig for VestaConfig {
|
||||
const ENDO_COEFFS: &'static [Self::BaseField] = &[MontFp!(
|
||||
"26005156700822196841419187675678338661165322343552424574062261873906994770353"
|
||||
)];
|
||||
|
||||
const LAMBDA: Self::ScalarField =
|
||||
MontFp!("20444556541222657078399132219657928148671392403212669005631716460534733845831");
|
||||
|
||||
const SCALAR_DECOMP_COEFFS: [(bool, <Self::ScalarField as PrimeField>::BigInt); 4] = [
|
||||
(false, BigInt!("98231058071100081932162823354453065729")),
|
||||
(true, BigInt!("98231058071186745657228807397848383488")),
|
||||
(false, BigInt!("196462116142286827589391630752301449217")),
|
||||
(false, BigInt!("98231058071100081932162823354453065729")),
|
||||
];
|
||||
|
||||
fn endomorphism(p: &Projective) -> Projective {
|
||||
// Endomorphism of the points on the curve.
|
||||
// endomorphism_p(x,y) = (BETA * x, y)
|
||||
// where BETA is a non-trivial cubic root of unity in Fq.
|
||||
let mut res = (*p).clone();
|
||||
res.x *= Self::ENDO_COEFFS[0];
|
||||
res
|
||||
}
|
||||
|
||||
fn endomorphism_affine(p: &Affine) -> Affine {
|
||||
// Endomorphism of the points on the curve.
|
||||
// endomorphism_p(x,y) = (BETA * x, y)
|
||||
// where BETA is a non-trivial cubic root of unity in Fq.
|
||||
let mut res = (*p).clone();
|
||||
res.x *= Self::ENDO_COEFFS[0];
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
/// G_GENERATOR_X = -1
|
||||
/// Encoded in Montgomery form, so the value here is -R mod p.
|
||||
pub const G_GENERATOR_X: Fq = MontFp!("-1");
|
||||
|
||||
@@ -2,3 +2,4 @@ use crate::Projective;
|
||||
use ark_algebra_test_templates::*;
|
||||
|
||||
test_group!(g1; Projective; sw);
|
||||
test_group!(g1_glv; Projective; glv);
|
||||
|
||||
Reference in New Issue
Block a user