mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-11 08:21:33 +01:00
Initial commit
This commit is contained in:
113
bw6_761/src/curves/g1.rs
Normal file
113
bw6_761/src/curves/g1.rs
Normal file
@@ -0,0 +1,113 @@
|
||||
use crate::{Fq, Fr};
|
||||
use ark_ec::{
|
||||
models::{ModelParameters, SWModelParameters},
|
||||
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
|
||||
};
|
||||
use ark_ff::{
|
||||
biginteger::{BigInteger384, BigInteger768},
|
||||
field_new,
|
||||
};
|
||||
|
||||
pub type G1Affine = GroupAffine<Parameters>;
|
||||
pub type G1Projective = GroupProjective<Parameters>;
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct Parameters;
|
||||
|
||||
impl ModelParameters for Parameters {
|
||||
type BaseField = Fq;
|
||||
type ScalarField = Fr;
|
||||
}
|
||||
|
||||
impl SWModelParameters for Parameters {
|
||||
/// COEFF_A = 0
|
||||
#[rustfmt::skip]
|
||||
|
||||
const COEFF_A: Fq = field_new!(Fq, BigInteger768([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
|
||||
/// COEFF_B = -1
|
||||
#[rustfmt::skip]
|
||||
const COEFF_B: Fq = field_new!(Fq, BigInteger768([
|
||||
0xf29a000000007ab6,
|
||||
0x8c391832e000739b,
|
||||
0x77738a6b6870f959,
|
||||
0xbe36179047832b03,
|
||||
0x84f3089e56574722,
|
||||
0xc5a3614ac0b1d984,
|
||||
0x5c81153f4906e9fe,
|
||||
0x4d28be3a9f55c815,
|
||||
0xd72c1d6f77d5f5c5,
|
||||
0x73a18e069ac04458,
|
||||
0xf9dfaa846595555f,
|
||||
0xd0f0a60a5be58c,
|
||||
]));
|
||||
|
||||
/// COFACTOR =
|
||||
/// 26642435879335816683987677701488073867751118270052650655942102502312977592501693353047140953112195348280268661194876
|
||||
#[rustfmt::skip]
|
||||
const COFACTOR: &'static [u64] = &[
|
||||
0x3de580000000007c,
|
||||
0x832ba4061000003b,
|
||||
0xc61c554757551c0c,
|
||||
0xc856a0853c9db94c,
|
||||
0x2c77d5ac34cb12ef,
|
||||
0xad1972339049ce76,
|
||||
];
|
||||
|
||||
/// COFACTOR^(-1) mod r =
|
||||
/// 91141326767669940707819291241958318717982251277713150053234367522357946997763584490607453720072232540829942217804
|
||||
#[rustfmt::skip]
|
||||
const COFACTOR_INV: Fr = field_new!(Fr, BigInteger384([
|
||||
489703175600125849,
|
||||
3883341943836920852,
|
||||
1678256062427438196,
|
||||
5848789333018172718,
|
||||
7127967896440782320,
|
||||
71512347676739162,
|
||||
]));
|
||||
|
||||
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
|
||||
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
|
||||
(G1_GENERATOR_X, G1_GENERATOR_Y);
|
||||
#[inline(always)]
|
||||
fn mul_by_a(_elem: &Self::BaseField) -> Self::BaseField {
|
||||
use ark_ff::Zero;
|
||||
Self::BaseField::zero()
|
||||
}
|
||||
}
|
||||
|
||||
/// G1_GENERATOR_X =
|
||||
/// 6238772257594679368032145693622812838779005809760824733138787810501188623461307351759238099287535516224314149266511977132140828635950940021790489507611754366317801811090811367945064510304504157188661901055903167026722666149426237
|
||||
#[rustfmt::skip]
|
||||
pub const G1_GENERATOR_X: Fq = field_new!(Fq, BigInteger768([
|
||||
0xd6e42d7614c2d770,
|
||||
0x4bb886eddbc3fc21,
|
||||
0x64648b044098b4d2,
|
||||
0x1a585c895a422985,
|
||||
0xf1a9ac17cf8685c9,
|
||||
0x352785830727aea5,
|
||||
0xddf8cb12306266fe,
|
||||
0x6913b4bfbc9e949a,
|
||||
0x3a4b78d67ba5f6ab,
|
||||
0x0f481c06a8d02a04,
|
||||
0x91d4e7365c43edac,
|
||||
0xf4d17cd48beca5,
|
||||
]));
|
||||
|
||||
/// G1_GENERATOR_Y =
|
||||
/// 2101735126520897423911504562215834951148127555913367997162789335052900271653517958562461315794228241561913734371411178226936527683203879553093934185950470971848972085321797958124416462268292467002957525517188485984766314758624099
|
||||
#[rustfmt::skip]
|
||||
pub const G1_GENERATOR_Y: Fq = field_new!(Fq, BigInteger768([
|
||||
0x97e805c4bd16411f,
|
||||
0x870d844e1ee6dd08,
|
||||
0x1eba7a37cb9eab4d,
|
||||
0xd544c4df10b9889a,
|
||||
0x8fe37f21a33897be,
|
||||
0xe9bf99a43a0885d2,
|
||||
0xd7ee0c9e273de139,
|
||||
0xaa6a9ec7a38dd791,
|
||||
0x8f95d3fcf765da8e,
|
||||
0x42326e7db7357c99,
|
||||
0xe217e407e218695f,
|
||||
0x9d1eb23b7cf684,
|
||||
]));
|
||||
113
bw6_761/src/curves/g2.rs
Normal file
113
bw6_761/src/curves/g2.rs
Normal file
@@ -0,0 +1,113 @@
|
||||
use crate::{Fq, Fr};
|
||||
use ark_ec::{
|
||||
models::{ModelParameters, SWModelParameters},
|
||||
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
|
||||
};
|
||||
use ark_ff::{
|
||||
biginteger::{BigInteger384, BigInteger768},
|
||||
field_new,
|
||||
};
|
||||
|
||||
pub type G2Affine = GroupAffine<Parameters>;
|
||||
pub type G2Projective = GroupProjective<Parameters>;
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct Parameters;
|
||||
|
||||
impl ModelParameters for Parameters {
|
||||
type BaseField = Fq;
|
||||
type ScalarField = Fr;
|
||||
}
|
||||
|
||||
impl SWModelParameters for Parameters {
|
||||
/// COEFF_A = 0
|
||||
#[rustfmt::skip]
|
||||
|
||||
const COEFF_A: Fq = field_new!(Fq, BigInteger768([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
|
||||
/// COEFF_B = 4
|
||||
#[rustfmt::skip]
|
||||
const COEFF_B: Fq = field_new!(Fq, BigInteger768([
|
||||
0x136efffffffe16c9,
|
||||
0x82cf5a6dcffe3319,
|
||||
0x6458c05f1f0e0741,
|
||||
0xd10ae605e52a4eda,
|
||||
0x41ca591c0266e100,
|
||||
0x7d0fd59c3626929f,
|
||||
0x9967dc004d00c112,
|
||||
0x1ccff9c033379af5,
|
||||
0x9ad6ec10a23f63af,
|
||||
0x5cec11251a72c235,
|
||||
0x8d18b1ae789ba83e,
|
||||
10403402007434220,
|
||||
]));
|
||||
|
||||
/// COFACTOR =
|
||||
/// 26642435879335816683987677701488073867751118270052650655942102502312977592501693353047140953112195348280268661194869
|
||||
#[rustfmt::skip]
|
||||
const COFACTOR: &'static [u64] = &[
|
||||
0x3de5800000000075,
|
||||
0x832ba4061000003b,
|
||||
0xc61c554757551c0c,
|
||||
0xc856a0853c9db94c,
|
||||
0x2c77d5ac34cb12ef,
|
||||
0xad1972339049ce76,
|
||||
];
|
||||
|
||||
/// COFACTOR^(-1) mod r =
|
||||
/// 214911522365886453591244899095480747723790054550866810551297776298664428889000553861210287833206024638187939842124
|
||||
#[rustfmt::skip]
|
||||
const COFACTOR_INV: Fr = field_new!(Fr, BigInteger384([
|
||||
14378295991815829998,
|
||||
14586153992421458638,
|
||||
9788477762582722914,
|
||||
12654821707953664524,
|
||||
15185631607604703397,
|
||||
26723985783783076,
|
||||
]));
|
||||
|
||||
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
|
||||
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
|
||||
(G2_GENERATOR_X, G2_GENERATOR_Y);
|
||||
#[inline(always)]
|
||||
fn mul_by_a(_elem: &Self::BaseField) -> Self::BaseField {
|
||||
use ark_ff::Zero;
|
||||
Self::BaseField::zero()
|
||||
}
|
||||
}
|
||||
|
||||
/// G2_GENERATOR_X =
|
||||
/// 6445332910596979336035888152774071626898886139774101364933948236926875073754470830732273879639675437155036544153105017729592600560631678554299562762294743927912429096636156401171909259073181112518725201388196280039960074422214428
|
||||
#[rustfmt::skip]
|
||||
pub const G2_GENERATOR_X: Fq = field_new!(Fq, BigInteger768([
|
||||
0x3d902a84cd9f4f78,
|
||||
0x864e451b8a9c05dd,
|
||||
0xc2b3c0d6646c5673,
|
||||
0x17a7682def1ecb9d,
|
||||
0xbe31a1e0fb768fe3,
|
||||
0x4df125e09b92d1a6,
|
||||
0x0943fce635b02ee9,
|
||||
0xffc8e7ad0605e780,
|
||||
0x8165c00a39341e95,
|
||||
0x8ccc2ae90a0f094f,
|
||||
0x73a8b8cc0ad09e0c,
|
||||
0x11027e203edd9f4,
|
||||
]));
|
||||
|
||||
/// G2_GENERATOR_Y =
|
||||
/// 562923658089539719386922163444547387757586534741080263946953401595155211934630598999300396317104182598044793758153214972605680357108252243146746187917218885078195819486220416605630144001533548163105316661692978285266378674355041
|
||||
#[rustfmt::skip]
|
||||
pub const G2_GENERATOR_Y: Fq = field_new!(Fq, BigInteger768([
|
||||
0x9a159be4e773f67c,
|
||||
0x6b957244aa8f4e6b,
|
||||
0xa27b70c9c945a38c,
|
||||
0xacb6a09fda11d0ab,
|
||||
0x3abbdaa9bb6b1291,
|
||||
0xdbdf642af5694c36,
|
||||
0xb6360bb9560b369f,
|
||||
0xac0bd1e822b8d6da,
|
||||
0xfa355d17afe6945f,
|
||||
0x8d6a0fc1fbcad35e,
|
||||
0x72a63c7874409840,
|
||||
0x114976e5b0db280,
|
||||
]));
|
||||
61
bw6_761/src/curves/mod.rs
Normal file
61
bw6_761/src/curves/mod.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use crate::*;
|
||||
use ark_ec::{
|
||||
bw6,
|
||||
bw6::{BW6Parameters, TwistType, BW6},
|
||||
};
|
||||
use ark_ff::biginteger::BigInteger768 as BigInteger;
|
||||
|
||||
pub mod g1;
|
||||
pub mod g2;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct Parameters;
|
||||
|
||||
impl BW6Parameters for Parameters {
|
||||
const X: BigInteger = BigInteger([
|
||||
0x8508c00000000001,
|
||||
0x0,
|
||||
0x0,
|
||||
0x0,
|
||||
0x0,
|
||||
0x0,
|
||||
0x0,
|
||||
0x0,
|
||||
0x0,
|
||||
0x0,
|
||||
0x0,
|
||||
0x0,
|
||||
]);
|
||||
/// `x` is positive.
|
||||
const X_IS_NEGATIVE: bool = false;
|
||||
// X+1
|
||||
const ATE_LOOP_COUNT_1: &'static [u64] = &[0x8508c00000000002];
|
||||
const ATE_LOOP_COUNT_1_IS_NEGATIVE: bool = false;
|
||||
// X^3-X^2-X
|
||||
const ATE_LOOP_COUNT_2: &'static [i8] = &[
|
||||
-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
|
||||
0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, -1, 0, 0,
|
||||
1, 0, 0, 0, -1, 0, 0, -1, 0, 1, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, -1, 0, 1, 0, 1, 0, 0, 0, 1,
|
||||
0, -1, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 1,
|
||||
];
|
||||
const ATE_LOOP_COUNT_2_IS_NEGATIVE: bool = false;
|
||||
const TWIST_TYPE: TwistType = TwistType::M;
|
||||
type Fp = Fq;
|
||||
type Fp3Params = Fq3Parameters;
|
||||
type Fp6Params = Fq6Parameters;
|
||||
type G1Parameters = g1::Parameters;
|
||||
type G2Parameters = g2::Parameters;
|
||||
}
|
||||
|
||||
pub type BW6_761 = BW6<Parameters>;
|
||||
|
||||
pub type G1Affine = bw6::G1Affine<Parameters>;
|
||||
pub type G1Projective = bw6::G1Projective<Parameters>;
|
||||
pub type G2Affine = bw6::G2Affine<Parameters>;
|
||||
pub type G2Projective = bw6::G2Projective<Parameters>;
|
||||
77
bw6_761/src/curves/tests.rs
Normal file
77
bw6_761/src/curves/tests.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
|
||||
use ark_ff::{test_rng, Field, One, PrimeField};
|
||||
use rand::Rng;
|
||||
|
||||
use crate::*;
|
||||
|
||||
use ark_curve_tests::{curves::*, groups::*};
|
||||
|
||||
#[test]
|
||||
fn test_g1_projective_curve() {
|
||||
curve_tests::<G1Projective>();
|
||||
|
||||
sw_tests::<g1::Parameters>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_g1_projective_group() {
|
||||
let mut rng = test_rng();
|
||||
let a: G1Projective = rng.gen();
|
||||
let b: G1Projective = rng.gen();
|
||||
group_test(a, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_g1_generator() {
|
||||
let generator = G1Affine::prime_subgroup_generator();
|
||||
assert!(generator.is_on_curve());
|
||||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_g2_projective_curve() {
|
||||
curve_tests::<G2Projective>();
|
||||
|
||||
sw_tests::<g2::Parameters>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_g2_projective_group() {
|
||||
let mut rng = test_rng();
|
||||
let a: G2Projective = rng.gen();
|
||||
let b: G2Projective = rng.gen();
|
||||
group_test(a, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_g2_generator() {
|
||||
let generator = G2Affine::prime_subgroup_generator();
|
||||
assert!(generator.is_on_curve());
|
||||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bilinearity() {
|
||||
let mut rng = test_rng();
|
||||
let a: G1Projective = rng.gen();
|
||||
let b: G2Projective = rng.gen();
|
||||
let s: Fr = rng.gen();
|
||||
|
||||
let sa = a.mul(s);
|
||||
let sb = b.mul(s);
|
||||
|
||||
let ans1 = BW6_761::pairing(sa, b);
|
||||
let ans2 = BW6_761::pairing(a, sb);
|
||||
let ans3 = BW6_761::pairing(a, b).pow(s.into_repr());
|
||||
|
||||
assert_eq!(ans1, ans2);
|
||||
assert_eq!(ans2, ans3);
|
||||
|
||||
assert_ne!(ans1, Fq6::one());
|
||||
assert_ne!(ans2, Fq6::one());
|
||||
assert_ne!(ans3, Fq6::one());
|
||||
|
||||
assert_eq!(ans1.pow(Fr::characteristic()), Fq6::one());
|
||||
assert_eq!(ans2.pow(Fr::characteristic()), Fq6::one());
|
||||
assert_eq!(ans3.pow(Fr::characteristic()), Fq6::one());
|
||||
}
|
||||
Reference in New Issue
Block a user