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:
@@ -3,10 +3,11 @@ use ark_ec::{
|
||||
bls12::Bls12Config,
|
||||
hashing::curve_maps::wb::{IsogenyMap, WBConfig},
|
||||
models::CurveConfig,
|
||||
scalar_mul::glv::GLVConfig,
|
||||
short_weierstrass::{Affine, SWCurveConfig},
|
||||
AffineRepr, PrimeGroup,
|
||||
};
|
||||
use ark_ff::{AdditiveGroup, MontFp, PrimeField, Zero};
|
||||
use ark_ff::{AdditiveGroup, BigInt, MontFp, PrimeField, Zero};
|
||||
use ark_serialize::{Compress, SerializationError};
|
||||
use ark_std::{ops::Neg, One};
|
||||
|
||||
@@ -52,6 +53,12 @@ impl SWCurveConfig for Config {
|
||||
Self::BaseField::zero()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mul_projective(p: &G1Projective, scalar: &[u64]) -> G1Projective {
|
||||
let s = Self::ScalarField::from_sign_and_limbs(true, scalar);
|
||||
GLVConfig::glv_mul_projective(*p, s)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_in_correct_subgroup_assuming_on_curve(p: &G1Affine) -> bool {
|
||||
// Algorithm from Section 6 of https://eprint.iacr.org/2021/1130.
|
||||
@@ -142,6 +149,34 @@ impl SWCurveConfig for Config {
|
||||
}
|
||||
}
|
||||
|
||||
impl GLVConfig for Config {
|
||||
const ENDO_COEFFS: &'static[Self::BaseField] = &[
|
||||
MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350")
|
||||
];
|
||||
|
||||
const LAMBDA: Self::ScalarField =
|
||||
MontFp!("52435875175126190479447740508185965837461563690374988244538805122978187051009");
|
||||
|
||||
const SCALAR_DECOMP_COEFFS: [(bool, <Self::ScalarField as PrimeField>::BigInt); 4] = [
|
||||
(true, BigInt!("228988810152649578064853576960394133504")),
|
||||
(true, BigInt!("1")),
|
||||
(false, BigInt!("1")),
|
||||
(true, BigInt!("228988810152649578064853576960394133503")),
|
||||
];
|
||||
|
||||
fn endomorphism(p: &G1Projective) -> G1Projective {
|
||||
let mut res = (*p).clone();
|
||||
res.x *= Self::ENDO_COEFFS[0];
|
||||
res
|
||||
}
|
||||
|
||||
fn endomorphism_affine(p: &Affine<Self>) -> Affine<Self> {
|
||||
let mut res = (*p).clone();
|
||||
res.x *= Self::ENDO_COEFFS[0];
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
fn one_minus_x() -> Fr {
|
||||
const X: Fr = Fr::from_sign_and_limbs(!crate::Config::X_IS_NEGATIVE, crate::Config::X);
|
||||
Fr::one() - X
|
||||
|
||||
@@ -5,10 +5,11 @@ use ark_ec::{
|
||||
bls12::Bls12Config,
|
||||
hashing::curve_maps::wb::{IsogenyMap, WBConfig},
|
||||
models::CurveConfig,
|
||||
scalar_mul::glv::GLVConfig,
|
||||
short_weierstrass::{Affine, Projective, SWCurveConfig},
|
||||
AffineRepr, CurveGroup, PrimeGroup,
|
||||
};
|
||||
use ark_ff::{AdditiveGroup, Field, MontFp, Zero};
|
||||
use ark_ff::{AdditiveGroup, BigInt, Field, MontFp, PrimeField, Zero};
|
||||
use ark_serialize::{Compress, SerializationError};
|
||||
|
||||
use super::{
|
||||
@@ -185,6 +186,36 @@ impl SWCurveConfig for Config {
|
||||
}
|
||||
}
|
||||
|
||||
impl GLVConfig for Config {
|
||||
const ENDO_COEFFS: &'static[Self::BaseField] = &[
|
||||
Fq2::new(
|
||||
MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
|
||||
Fq::ZERO
|
||||
)
|
||||
];
|
||||
|
||||
const LAMBDA: Self::ScalarField = MontFp!("228988810152649578064853576960394133503");
|
||||
|
||||
const SCALAR_DECOMP_COEFFS: [(bool, <Self::ScalarField as PrimeField>::BigInt); 4] = [
|
||||
(false, BigInt!("228988810152649578064853576960394133503")),
|
||||
(true, BigInt!("1")),
|
||||
(false, BigInt!("1")),
|
||||
(false, BigInt!("228988810152649578064853576960394133504")),
|
||||
];
|
||||
|
||||
fn endomorphism(p: &Projective<Self>) -> Projective<Self> {
|
||||
let mut res = (*p).clone();
|
||||
res.x *= Self::ENDO_COEFFS[0];
|
||||
res
|
||||
}
|
||||
|
||||
fn endomorphism_affine(p: &Affine<Self>) -> Affine<Self> {
|
||||
let mut res = (*p).clone();
|
||||
res.x *= Self::ENDO_COEFFS[0];
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
pub const G2_GENERATOR_X: Fq2 = Fq2::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
|
||||
pub const G2_GENERATOR_Y: Fq2 = Fq2::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ use crate::{Bls12_381, Fq, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projecti
|
||||
|
||||
test_group!(g1; G1Projective; sw);
|
||||
test_group!(g2; G2Projective; sw);
|
||||
test_group!(g1_glv; G1Projective; glv);
|
||||
test_group!(g2_glv; G2Projective; glv);
|
||||
test_group!(pairing_output; ark_ec::pairing::PairingOutput<Bls12_381>; msm);
|
||||
test_pairing!(pairing; crate::Bls12_381);
|
||||
test_h2c!(g1_h2c; "./src/curves/tests"; "BLS12381G1"; crate::g1::Config; crate::Fq; crate::Fq; 1);
|
||||
|
||||
Reference in New Issue
Block a user