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,14 +3,15 @@ use ark_ec::{
|
||||
bls12::Bls12Config,
|
||||
hashing::curve_maps::wb::{IsogenyMap, WBConfig},
|
||||
models::{
|
||||
short_weierstrass::{Affine as SWAffine, SWCurveConfig},
|
||||
short_weierstrass::{Affine as SWAffine, Projective as SWProjective, SWCurveConfig},
|
||||
twisted_edwards::{
|
||||
Affine as TEAffine, MontCurveConfig, Projective as TEProjective, TECurveConfig,
|
||||
},
|
||||
},
|
||||
scalar_mul::glv::GLVConfig,
|
||||
CurveConfig,
|
||||
};
|
||||
use ark_ff::{AdditiveGroup, Field, MontFp, PrimeField, Zero};
|
||||
use ark_ff::{AdditiveGroup, BigInt, Field, MontFp, PrimeField, Zero};
|
||||
use ark_std::{ops::Neg, One};
|
||||
|
||||
use super::g1_swu_iso::{SwuIsoConfig, ISOGENY_MAP_TO_G1};
|
||||
@@ -49,6 +50,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 clear_cofactor(p: &G1SWAffine) -> G1SWAffine {
|
||||
// Using the effective cofactor.
|
||||
@@ -59,6 +66,34 @@ impl SWCurveConfig for Config {
|
||||
}
|
||||
}
|
||||
|
||||
impl GLVConfig for Config {
|
||||
const ENDO_COEFFS: &'static[Self::BaseField] = &[
|
||||
MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231")
|
||||
];
|
||||
|
||||
const LAMBDA: Self::ScalarField =
|
||||
MontFp!("8444461749428370424248824938781546531284005582649182570233710176290576793600");
|
||||
|
||||
const SCALAR_DECOMP_COEFFS: [(bool, <Self::ScalarField as PrimeField>::BigInt); 4] = [
|
||||
(true, BigInt!("91893752504881257701523279626832445441")),
|
||||
(true, BigInt!("1")),
|
||||
(false, BigInt!("1")),
|
||||
(true, BigInt!("91893752504881257701523279626832445440")),
|
||||
];
|
||||
|
||||
fn endomorphism(p: &SWProjective<Self>) -> SWProjective<Self> {
|
||||
let mut res = (*p).clone();
|
||||
res.x *= Self::ENDO_COEFFS[0];
|
||||
res
|
||||
}
|
||||
|
||||
fn endomorphism_affine(p: &SWAffine<Self>) -> SWAffine<Self> {
|
||||
let mut res = (*p).clone();
|
||||
res.x *= Self::ENDO_COEFFS[0];
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
fn x_minus_one() -> Fr {
|
||||
const X: Fr = Fr::from_sign_and_limbs(!crate::Config::X_IS_NEGATIVE, crate::Config::X);
|
||||
X - Fr::one()
|
||||
|
||||
@@ -2,12 +2,12 @@ use ark_ec::{
|
||||
bls12,
|
||||
bls12::Bls12Config,
|
||||
hashing::curve_maps::wb::{IsogenyMap, WBConfig},
|
||||
models::CurveConfig,
|
||||
scalar_mul::glv::GLVConfig,
|
||||
short_weierstrass::{Affine, Projective, SWCurveConfig},
|
||||
AffineRepr, CurveGroup, PrimeGroup,
|
||||
AffineRepr, CurveConfig, CurveGroup, PrimeGroup,
|
||||
};
|
||||
|
||||
use ark_ff::{AdditiveGroup, Field, MontFp, Zero};
|
||||
use ark_ff::{AdditiveGroup, BigInt, Field, MontFp, PrimeField, Zero};
|
||||
use ark_std::ops::Neg;
|
||||
|
||||
use crate::*;
|
||||
@@ -98,6 +98,36 @@ impl SWCurveConfig for Config {
|
||||
}
|
||||
}
|
||||
|
||||
impl GLVConfig for Config {
|
||||
const ENDO_COEFFS: &'static[Self::BaseField] = &[
|
||||
Fq2::new(
|
||||
MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
|
||||
Fq::ZERO
|
||||
)
|
||||
];
|
||||
|
||||
const LAMBDA: Self::ScalarField = MontFp!("91893752504881257701523279626832445440");
|
||||
|
||||
const SCALAR_DECOMP_COEFFS: [(bool, <Self::ScalarField as PrimeField>::BigInt); 4] = [
|
||||
(false, BigInt!("91893752504881257701523279626832445440")),
|
||||
(true, BigInt!("1")),
|
||||
(false, BigInt!("1")),
|
||||
(false, BigInt!("91893752504881257701523279626832445441")),
|
||||
];
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ test_group!(g1; G1Projective; sw);
|
||||
test_group!(g2; G2Projective; sw);
|
||||
test_group!(pairing_output; ark_ec::pairing::PairingOutput<Bls12_377>; msm);
|
||||
test_pairing!(pairing; crate::Bls12_377);
|
||||
test_group!(g1_glv; G1Projective; glv);
|
||||
test_group!(g2_glv; G2Projective; glv);
|
||||
test_h2c!(g1_h2c; "./src/curves/tests"; "BLS12377G1"; crate::g1::Config; crate::Fq; crate::Fq; 1);
|
||||
test_h2c!(g2_hc2; "./src/curves/tests"; "BLS12377G2"; crate::g2::Config; crate::Fq2; crate::Fq; 2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user