mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-08 23:11:29 +01:00
Rename all *Parameters to *Config (#136)
* Rename all `*Parameters` to `*Config` * Tweak
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::*;
|
||||
use ark_ec::{
|
||||
bls12,
|
||||
bls12::Bls12Parameters,
|
||||
bls12::Bls12Config,
|
||||
models::CurveConfig,
|
||||
short_weierstrass::{Affine, SWCurveConfig},
|
||||
AffineRepr, Group,
|
||||
@@ -14,13 +14,13 @@ use crate::util::{
|
||||
read_g1_compressed, read_g1_uncompressed, serialize_fq, EncodingFlags, G1_SERIALIZED_SIZE,
|
||||
};
|
||||
|
||||
pub type G1Affine = bls12::G1Affine<crate::Parameters>;
|
||||
pub type G1Projective = bls12::G1Projective<crate::Parameters>;
|
||||
pub type G1Affine = bls12::G1Affine<crate::Config>;
|
||||
pub type G1Projective = bls12::G1Projective<crate::Config>;
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct Parameters;
|
||||
pub struct Config;
|
||||
|
||||
impl CurveConfig for Parameters {
|
||||
impl CurveConfig for Config {
|
||||
type BaseField = Fq;
|
||||
type ScalarField = Fr;
|
||||
|
||||
@@ -33,7 +33,7 @@ impl CurveConfig for Parameters {
|
||||
MontFp!("52435875175126190458656871551744051925719901746859129887267498875565241663483");
|
||||
}
|
||||
|
||||
impl SWCurveConfig for Parameters {
|
||||
impl SWCurveConfig for Config {
|
||||
/// COEFF_A = 0
|
||||
const COEFF_A: Fq = Fq::ZERO;
|
||||
|
||||
@@ -57,12 +57,12 @@ impl SWCurveConfig for Parameters {
|
||||
// An early-out optimization described in Section 6.
|
||||
// If uP == P but P != point of infinity, then the point is not in the right
|
||||
// subgroup.
|
||||
let x_times_p = p.mul_bigint(crate::Parameters::X);
|
||||
let x_times_p = p.mul_bigint(crate::Config::X);
|
||||
if x_times_p.eq(p) && !p.infinity {
|
||||
return false;
|
||||
}
|
||||
|
||||
let minus_x_squared_times_p = x_times_p.mul_bigint(crate::Parameters::X).neg();
|
||||
let minus_x_squared_times_p = x_times_p.mul_bigint(crate::Config::X).neg();
|
||||
let endomorphism_p = endomorphism(p);
|
||||
minus_x_squared_times_p.eq(&endomorphism_p)
|
||||
}
|
||||
@@ -74,7 +74,7 @@ impl SWCurveConfig for Parameters {
|
||||
//
|
||||
// It is enough to multiply by (1 - x), instead of (x - 1)^2 / 3
|
||||
let h_eff = one_minus_x().into_bigint();
|
||||
Parameters::mul_affine(&p, h_eff.as_ref()).into()
|
||||
Config::mul_affine(&p, h_eff.as_ref()).into()
|
||||
}
|
||||
|
||||
fn deserialize_with_mode<R: ark_serialize::Read>(
|
||||
@@ -139,7 +139,7 @@ impl SWCurveConfig for Parameters {
|
||||
}
|
||||
|
||||
fn one_minus_x() -> Fr {
|
||||
const X: Fr = Fr::from_sign_and_limbs(!crate::Parameters::X_IS_NEGATIVE, crate::Parameters::X);
|
||||
const X: Fr = Fr::from_sign_and_limbs(!crate::Config::X_IS_NEGATIVE, crate::Config::X);
|
||||
Fr::one() - X
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ pub const G1_GENERATOR_Y: Fq = MontFp!("1339506544944476473020471379941921221584
|
||||
/// BETA is a non-trivial cubic root of unity in Fq.
|
||||
pub const BETA: Fq = MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350");
|
||||
|
||||
pub fn endomorphism(p: &Affine<Parameters>) -> Affine<Parameters> {
|
||||
pub fn endomorphism(p: &Affine<Config>) -> Affine<Config> {
|
||||
// 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.
|
||||
@@ -169,7 +169,7 @@ mod test {
|
||||
use super::*;
|
||||
use ark_std::{rand::Rng, UniformRand};
|
||||
|
||||
fn sample_unchecked() -> Affine<g1::Parameters> {
|
||||
fn sample_unchecked() -> Affine<g1::Config> {
|
||||
let mut rng = ark_std::test_rng();
|
||||
loop {
|
||||
let x = Fq::rand(&mut rng);
|
||||
@@ -185,7 +185,7 @@ mod test {
|
||||
fn test_cofactor_clearing() {
|
||||
const SAMPLES: usize = 100;
|
||||
for _ in 0..SAMPLES {
|
||||
let p: Affine<g1::Parameters> = sample_unchecked();
|
||||
let p: Affine<g1::Config> = sample_unchecked();
|
||||
let p = p.clear_cofactor();
|
||||
assert!(p.is_on_curve());
|
||||
assert!(p.is_in_correct_subgroup_assuming_on_curve());
|
||||
|
||||
@@ -2,7 +2,7 @@ use ark_std::ops::Neg;
|
||||
|
||||
use ark_ec::{
|
||||
bls12,
|
||||
bls12::Bls12Parameters,
|
||||
bls12::Bls12Config,
|
||||
models::CurveConfig,
|
||||
short_weierstrass::{Affine, Projective, SWCurveConfig},
|
||||
AffineRepr, CurveGroup, Group,
|
||||
@@ -16,13 +16,13 @@ use crate::{
|
||||
*,
|
||||
};
|
||||
|
||||
pub type G2Affine = bls12::G2Affine<crate::Parameters>;
|
||||
pub type G2Projective = bls12::G2Projective<crate::Parameters>;
|
||||
pub type G2Affine = bls12::G2Affine<crate::Config>;
|
||||
pub type G2Projective = bls12::G2Projective<crate::Config>;
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct Parameters;
|
||||
pub struct Config;
|
||||
|
||||
impl CurveConfig for Parameters {
|
||||
impl CurveConfig for Config {
|
||||
type BaseField = Fq2;
|
||||
type ScalarField = Fr;
|
||||
|
||||
@@ -47,12 +47,12 @@ impl CurveConfig for Parameters {
|
||||
MontFp!("26652489039290660355457965112010883481355318854675681319708643586776743290055");
|
||||
}
|
||||
|
||||
impl SWCurveConfig for Parameters {
|
||||
impl SWCurveConfig for Config {
|
||||
/// COEFF_A = [0, 0]
|
||||
const COEFF_A: Fq2 = Fq2::new(g1::Parameters::COEFF_A, g1::Parameters::COEFF_A);
|
||||
const COEFF_A: Fq2 = Fq2::new(g1::Config::COEFF_A, g1::Config::COEFF_A);
|
||||
|
||||
/// COEFF_B = [4, 4]
|
||||
const COEFF_B: Fq2 = Fq2::new(g1::Parameters::COEFF_B, g1::Parameters::COEFF_B);
|
||||
const COEFF_B: Fq2 = Fq2::new(g1::Config::COEFF_B, g1::Config::COEFF_B);
|
||||
|
||||
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
|
||||
const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y);
|
||||
@@ -67,8 +67,8 @@ impl SWCurveConfig for Parameters {
|
||||
//
|
||||
// Checks that [p]P = [X]P
|
||||
|
||||
let mut x_times_point = point.mul_bigint(crate::Parameters::X);
|
||||
if crate::Parameters::X_IS_NEGATIVE {
|
||||
let mut x_times_point = point.mul_bigint(crate::Config::X);
|
||||
if crate::Config::X_IS_NEGATIVE {
|
||||
x_times_point = -x_times_point;
|
||||
}
|
||||
|
||||
@@ -86,11 +86,11 @@ impl SWCurveConfig for Parameters {
|
||||
// When multiplying, use -c1 instead, and then negate the result. That's much
|
||||
// more efficient, since the scalar -c1 has less limbs and a much lower Hamming
|
||||
// weight.
|
||||
let x: &'static [u64] = crate::Parameters::X;
|
||||
let x: &'static [u64] = crate::Config::X;
|
||||
let p_projective = p.into_group();
|
||||
|
||||
// [x]P
|
||||
let x_p = Parameters::mul_affine(p, &x).neg();
|
||||
let x_p = Config::mul_affine(p, &x).neg();
|
||||
// ψ(P)
|
||||
let psi_p = p_power_endomorphism(&p);
|
||||
// (ψ^2)(2P)
|
||||
@@ -101,7 +101,7 @@ impl SWCurveConfig for Parameters {
|
||||
tmp += &psi_p;
|
||||
|
||||
// tmp2 = [x^2]P + [x]ψ(P)
|
||||
let mut tmp2: Projective<Parameters> = tmp;
|
||||
let mut tmp2: Projective<Config> = tmp;
|
||||
tmp2 = tmp2.mul_bigint(x).neg();
|
||||
|
||||
// add up all the terms
|
||||
@@ -224,7 +224,7 @@ pub const DOUBLE_P_POWER_ENDOMORPHISM: Fq2 = Fq2::new(
|
||||
Fq::ZERO
|
||||
);
|
||||
|
||||
pub fn p_power_endomorphism(p: &Affine<Parameters>) -> Affine<Parameters> {
|
||||
pub fn p_power_endomorphism(p: &Affine<Config>) -> Affine<Config> {
|
||||
// The p-power endomorphism for G2 is defined as follows:
|
||||
// 1. Note that G2 is defined on curve E': y^2 = x^3 + 4(u+1).
|
||||
// To map a point (x, y) in E' to (s, t) in E,
|
||||
@@ -252,7 +252,7 @@ pub fn p_power_endomorphism(p: &Affine<Parameters>) -> Affine<Parameters> {
|
||||
}
|
||||
|
||||
/// For a p-power endomorphism psi(P), compute psi(psi(P))
|
||||
pub fn double_p_power_endomorphism(p: &Projective<Parameters>) -> Projective<Parameters> {
|
||||
pub fn double_p_power_endomorphism(p: &Projective<Config>) -> Projective<Config> {
|
||||
let mut res = *p;
|
||||
|
||||
res.x *= DOUBLE_P_POWER_ENDOMORPHISM;
|
||||
@@ -287,9 +287,9 @@ mod test {
|
||||
let mut rng = ark_std::test_rng();
|
||||
const SAMPLES: usize = 10;
|
||||
for _ in 0..SAMPLES {
|
||||
let p = Affine::<g2::Parameters>::rand(&mut rng);
|
||||
let p = Affine::<g2::Config>::rand(&mut rng);
|
||||
let optimised = p.clear_cofactor().into_group();
|
||||
let naive = g2::Parameters::mul_affine(&p, h_eff);
|
||||
let naive = g2::Config::mul_affine(&p, h_eff);
|
||||
assert_eq!(optimised, naive);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use ark_ec::bls12::{Bls12, Bls12Parameters, TwistType};
|
||||
use ark_ec::bls12::{Bls12, Bls12Config, TwistType};
|
||||
|
||||
use crate::{Fq, Fq12Config, Fq2Config, Fq6Config};
|
||||
|
||||
@@ -14,11 +14,11 @@ pub use self::{
|
||||
g2::{G2Affine, G2Projective},
|
||||
};
|
||||
|
||||
pub type Bls12_381 = Bls12<Parameters>;
|
||||
pub type Bls12_381 = Bls12<Config>;
|
||||
|
||||
pub struct Parameters;
|
||||
pub struct Config;
|
||||
|
||||
impl Bls12Parameters for Parameters {
|
||||
impl Bls12Config for Config {
|
||||
const X: &'static [u64] = &[0xd201000000010000];
|
||||
const X_IS_NEGATIVE: bool = true;
|
||||
const TWIST_TYPE: TwistType = TwistType::M;
|
||||
@@ -26,6 +26,6 @@ impl Bls12Parameters for Parameters {
|
||||
type Fp2Config = Fq2Config;
|
||||
type Fp6Config = Fq6Config;
|
||||
type Fp12Config = Fq12Config;
|
||||
type G1Parameters = self::g1::Parameters;
|
||||
type G2Parameters = self::g2::Parameters;
|
||||
type G1Config = self::g1::Config;
|
||||
type G2Config = self::g2::Config;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ use ark_ec::{short_weierstrass::Affine, AffineRepr};
|
||||
use ark_ff::{BigInteger384, PrimeField};
|
||||
use ark_serialize::SerializationError;
|
||||
|
||||
use crate::{
|
||||
g1::Parameters as G1Parameters, g2::Parameters as G2Parameters, Fq, Fq2, G1Affine, G2Affine,
|
||||
};
|
||||
use crate::{g1::Config as G1Config, g2::Config as G2Config, Fq, Fq2, G1Affine, G2Affine};
|
||||
|
||||
pub const G1_SERIALIZED_SIZE: usize = 48;
|
||||
pub const G2_SERIALIZED_SIZE: usize = 96;
|
||||
@@ -91,7 +89,7 @@ pub(crate) fn read_fq_with_offset(
|
||||
|
||||
pub(crate) fn read_g1_compressed<R: ark_serialize::Read>(
|
||||
mut reader: R,
|
||||
) -> Result<Affine<G1Parameters>, ark_serialize::SerializationError> {
|
||||
) -> Result<Affine<G1Config>, ark_serialize::SerializationError> {
|
||||
let mut bytes = [0u8; G1_SERIALIZED_SIZE];
|
||||
reader
|
||||
.read_exact(&mut bytes)
|
||||
@@ -121,7 +119,7 @@ pub(crate) fn read_g1_compressed<R: ark_serialize::Read>(
|
||||
|
||||
pub(crate) fn read_g1_uncompressed<R: ark_serialize::Read>(
|
||||
mut reader: R,
|
||||
) -> Result<Affine<G1Parameters>, ark_serialize::SerializationError> {
|
||||
) -> Result<Affine<G1Config>, ark_serialize::SerializationError> {
|
||||
let mut bytes = [0u8; 2 * G1_SERIALIZED_SIZE];
|
||||
reader
|
||||
.read_exact(&mut bytes)
|
||||
@@ -151,7 +149,7 @@ pub(crate) fn read_g1_uncompressed<R: ark_serialize::Read>(
|
||||
|
||||
pub(crate) fn read_g2_compressed<R: ark_serialize::Read>(
|
||||
mut reader: R,
|
||||
) -> Result<Affine<G2Parameters>, ark_serialize::SerializationError> {
|
||||
) -> Result<Affine<G2Config>, ark_serialize::SerializationError> {
|
||||
let mut bytes = [0u8; G2_SERIALIZED_SIZE];
|
||||
reader
|
||||
.read_exact(&mut bytes)
|
||||
@@ -183,7 +181,7 @@ pub(crate) fn read_g2_compressed<R: ark_serialize::Read>(
|
||||
|
||||
pub(crate) fn read_g2_uncompressed<R: ark_serialize::Read>(
|
||||
mut reader: R,
|
||||
) -> Result<Affine<G2Parameters>, ark_serialize::SerializationError> {
|
||||
) -> Result<Affine<G2Config>, ark_serialize::SerializationError> {
|
||||
let mut bytes = [0u8; 2 * G2_SERIALIZED_SIZE];
|
||||
reader
|
||||
.read_exact(&mut bytes)
|
||||
|
||||
Reference in New Issue
Block a user