Initial commit

This commit is contained in:
Pratyush Mishra
2020-10-11 19:50:41 -07:00
commit 43ca2132fd
209 changed files with 18825 additions and 0 deletions

104
mnt6_753/src/curves/g1.rs Normal file
View File

@@ -0,0 +1,104 @@
use ark_ec::{
mnt6,
models::{ModelParameters, SWModelParameters},
};
use ark_ff::{biginteger::BigInteger768, field_new};
use crate::{Fq, Fr, FR_ONE};
pub type G1Affine = mnt6::G1Affine<crate::Parameters>;
pub type G1Projective = mnt6::G1Projective<crate::Parameters>;
pub type G1Prepared = mnt6::G1Prepared<crate::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 = 11
#[rustfmt::skip]
const COEFF_A: Fq = field_new!(Fq, BigInteger768([
5145524327033718740,
14149824967095184544,
5159730833497260295,
3902941467692815387,
15830098551216085679,
8665641533746801158,
17502192300007146323,
14483698255198590748,
546300946688995976,
4331975528992054828,
5311428878520309260,
495362057711802,
]));
/// COEFF_B = 0x7DA285E70863C79D56446237CE2E1468D14AE9BB64B2BB01B10E60A5D5DFE0A25714B7985993F62F03B22A9A3C737A1A1E0FCF2C43D7BF847957C34CCA1E3585F9A80A95F401867C4E80F4747FDE5ABA7505BA6FCF2485540B13DFC8468A
#[rustfmt::skip]
const COEFF_B: Fq = field_new!(Fq, BigInteger768([
8828711393625909642,
12722539140758597443,
2303826860244282256,
8063890988281098391,
6269149169423748670,
3425772737529456013,
1457017085322601211,
5177155908178255133,
18057960053344868113,
10481469207136524576,
17888199912367160320,
290288558853910,
]));
/// COFACTOR = 1
const COFACTOR: &'static [u64] = &[1];
/// COFACTOR^(-1) mod r =
/// 1
#[rustfmt::skip]
const COFACTOR_INV: Fr = FR_ONE;
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
(G1_GENERATOR_X, G1_GENERATOR_Y);
}
// Generator of G1
// X = 3458420969484235708806261200128850544017070333833944116801482064540723268149235477762870414664917360605949659630933184751526227993647030875167687492714052872195770088225183259051403087906158701786758441889742618916006546636728,
// Y = 27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569,
/// G1_GENERATOR_X =
#[rustfmt::skip]
pub const G1_GENERATOR_X: Fq = field_new!(Fq, BigInteger768([
16404456614462158210,
16873534995404346316,
29580875041164893,
12740551787746921884,
16087583716780115490,
15096170813200936110,
930080103225705610,
660122182606823185,
5211213138865083410,
15466479635231681544,
11783401481713071326,
20214808394592
]));
/// G1_GENERATOR_Y =
#[rustfmt::skip]
pub const G1_GENERATOR_Y: Fq = field_new!(Fq, BigInteger768([
11636140615878154554,
15149343852908177063,
14426639389651280896,
12711360703798958610,
3787948290527586979,
7628180411662927078,
17195203689728925717,
6800476327444280291,
2228796880865780105,
15627033749683396124,
13783535191786892346,
61400438920476
]));

262
mnt6_753/src/curves/g2.rs Normal file
View File

@@ -0,0 +1,262 @@
use ark_ec::{
mnt6,
mnt6::MNT6Parameters,
models::{ModelParameters, SWModelParameters},
};
use ark_ff::{biginteger::BigInteger768, field_new};
use crate::{g1, Fq, Fq3, Fr, FQ_ZERO};
pub type G2Affine = mnt6::G2Affine<crate::Parameters>;
pub type G2Projective = mnt6::G2Projective<crate::Parameters>;
pub type G2Prepared = mnt6::G2Prepared<crate::Parameters>;
#[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters;
impl ModelParameters for Parameters {
type BaseField = Fq3;
type ScalarField = Fr;
}
/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A
#[rustfmt::skip]
pub const MUL_BY_A_C0: Fq = field_new!(Fq, BigInteger768([
10895242587870565906,
6757387713923212228,
12683949709867392876,
1229095484098138811,
18111217745394181988,
3648021353977015866,
7900332254549424237,
5988529219097278134,
11544487525720487778,
7317517692149492894,
9905728181042915773,
470678396104534
]));
/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
#[rustfmt::skip]
pub const MUL_BY_A_C1: Fq = field_new!(Fq, BigInteger768([
10895242587870565906,
6757387713923212228,
12683949709867392876,
1229095484098138811,
18111217745394181988,
3648021353977015866,
7900332254549424237,
5988529219097278134,
11544487525720487778,
7317517692149492894,
9905728181042915773,
470678396104534
]));
/// MUL_BY_A_C2 = COEFF_A
pub const MUL_BY_A_C2: Fq = g1::Parameters::COEFF_A;
impl SWModelParameters for Parameters {
const COEFF_A: Fq3 = crate::Parameters::TWIST_COEFF_A;
// B coefficient of MNT6-753 G2 =
// ```
// mnt6753_twist_coeff_b = mnt6753_Fq3(mnt6753_G1::coeff_b * mnt6753_Fq3::non_residue,
// mnt6753_Fq::zero(), mnt6753_Fq::zero());
// non_residue = mnt6753_Fq3::non_residue = mnt6753_Fq("11");
// = (G1_B_COEFF * NON_RESIDUE, ZERO, ZERO);
// =
// (2189526091197672465268098090392210500740714959757583916377481826443393499947557697773546040576162515434508768057245887856591913752342600919117433675080691499697020523783784738694360040853591723916201150207746019687604267190251,
// 0, 0)
// ```
#[rustfmt::skip]
const COEFF_B: Fq3 = field_new!(
Fq3,
field_new!(Fq, BigInteger768([
3284231658830416104,
13720030246451177991,
6276939417009443243,
8340612253649729185,
4863511590806861670,
15883218135158530927,
4865336109262680856,
16600307443495218926,
10112528487499131659,
17308657107605697754,
5326857497786417651,
206191604157846
])),
FQ_ZERO,
FQ_ZERO,
);
/// COFACTOR =
/// 1755483545388786116744270475466687259186947712032004459714210070280389500116987496124098574823389466285978151140155508638765729019174599527183600372094760023144398285325863550664578643924584541949466179502227232245309952839189635010671372908411609248348904807785904229403747495114436660255866932060472369629692502198423138429922875792635236729929780298333055698257230963645509826963717287902205842627121011526048163097042046361575549171961352924692480000
#[rustfmt::skip]
const COFACTOR: &'static [u64] = &[
17839255819456086016,
500623104730997740,
2110252009236161768,
1500878543414750896,
12839751506594314239,
8978537329634833065,
13830010955957826199,
7626514311663165506,
14876243211944528805,
2316601947950921451,
2601177562497904269,
18300670698693155036,
17321427554953155530,
12586270719596716948,
807965545138267130,
13086323046094411844,
16597411233431396880,
5578519820383338987,
16478065054289650824,
12110148809888520863,
5901144846689643164,
3407195776166256068,
14663852814447346059,
13435169368,
];
/// COFACTOR^(-1) mod r =
/// 6983081827986492233724035798540106188028451653325658178630583820170892135428517795509815627298389820236345161981341515817589065927929152555581161598204976128690232061758269440757592419606754539638220064054062394397574161203200
#[rustfmt::skip]
const COFACTOR_INV: Fr = field_new!(Fr, BigInteger768([
9418103049026957703,
3464743017686961509,
7872172759259099794,
17514322419398292337,
1496353716802911167,
16961719271566193274,
15426671498718617736,
9230857178223113223,
11731938389074297274,
16450973680014766981,
431917267220694852,
94637508603012
]));
/// 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(elt: &Fq3) -> Fq3 {
field_new!(
Fq3,
MUL_BY_A_C0 * &elt.c1,
MUL_BY_A_C1 * &elt.c2,
MUL_BY_A_C2 * &elt.c0,
)
}
}
const G2_GENERATOR_X: Fq3 =
field_new!(Fq3, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2);
const G2_GENERATOR_Y: Fq3 =
field_new!(Fq3, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2);
// Generator of G2
// These are three Fq elements each because X and Y (and Z) are elements of Fq^3
// X = 27250797394340459586637772414334383652934225310678303542554641987990991970766156209996739240400887081904395745019996048910447071686918567661896491214767494514394154061111870331668445455228882471000120574964265209669155206168252,
// 35762481056967998715733586393399457882827322353696313323665483142561285210083843314423554450886956650265947502285422529615273790981238406393402603210224104850580302463396274854098657541573494421834514772635884262388058080180368,
// 36955296703808958167583270646821654948157955258947892285629161090141878438357164213613114995903637211606408001037026832604054121847388692538440756596264746452765613740820430501353237866984394057660379098674983614861254438847846,
// Y = 2540920530670785421282147216459500299597350984927286541981768941513322907384197363939300669100157141915897390694710534916701460991329498878429407641200901974650893207493883271892985923686300670742888673128384350189165542294615,
// 7768974215205248225654340523113146529854477025417883273460270519532499370133542215655437897583245920162220909271982265882784840026754554720358946490360213245668334549692889019612343620295335698052097726325099648573158597797497,
// 21014872727619291834131369222699267167761185012487859171850226473555446863681002782100371394603357586906967186931035615146288030444598977758226767063525819170917389755555854704165900869058188909090444447822088242504281789869689,
#[rustfmt::skip]
pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger768([
12772807549130126376,
2873211972983293592,
15999100872160401842,
5277158980096688998,
12258756012310206056,
11885883517271414939,
6373672746025419911,
13662747456330091710,
11960680427306056040,
15150766304321120168,
9480712498131729809,
413066879180657
]));
#[rustfmt::skip]
pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger768([
10478274013728260378,
15392361149861123784,
17610084573134912261,
14474130264887792371,
16754378329454263996,
3186303078832273968,
7143189323629797683,
897486443141339765,
3675579496642106405,
4429391539758461550,
18414257413872084180,
331209511183940
]));
#[rustfmt::skip]
pub const G2_GENERATOR_X_C2: Fq = field_new!(Fq, BigInteger768([
5133712986240959624,
10763134357204872827,
8672341403101541980,
18084133226637702602,
4689040548070804594,
7352115990101270007,
14358820512747653623,
10167201669589504005,
3117673189936726036,
9407838052466059644,
7246385421116647671,
464288782946273
]));
#[rustfmt::skip]
pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger768([
710862246533630948,
9314168172257972041,
4722111556929662508,
4408676313209842703,
10491088158750500898,
13211840969745661306,
13985341743807087374,
7111198859398088665,
158194789363472891,
7682183069894584797,
9510326135325230913,
338826428359581
]));
#[rustfmt::skip]
pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger768([
10889422482835557076,
6073207585023077555,
16059368148547235058,
14871121891082823821,
15156344465408677175,
12695157488434086405,
7840105431702704631,
4763759818130023465,
12295696339556388640,
352741974984397506,
10581333776569094279,
204002329498100
]));
#[rustfmt::skip]
pub const G2_GENERATOR_Y_C2: Fq = field_new!(Fq, BigInteger768([
11263496889641203707,
16306762242042931049,
8275973312257833978,
12034012818098316014,
5392903691498465561,
4572635011530974247,
696221667645211601,
11098678912660456319,
5477755854538915619,
11442390115310629698,
10262065045802790037,
17901561410539
]));

View File

@@ -0,0 +1,77 @@
use ark_ff::{biginteger::BigInteger768, field_new, fields::FpParameters, Fp3};
use ark_ec::models::{
mnt6::{MNT6Parameters, MNT6},
SWModelParameters,
};
use crate::{Fq, Fq3, Fq3Parameters, Fq6Parameters, FqParameters, Fr, FrParameters};
pub mod g1;
pub mod g2;
#[cfg(test)]
mod tests;
pub use self::{
g1::{G1Affine, G1Prepared, G1Projective},
g2::{G2Affine, G2Prepared, G2Projective},
};
pub type MNT6_753 = MNT6<Parameters>;
pub struct Parameters;
impl MNT6Parameters for Parameters {
const TWIST: Fp3<Self::Fp3Params> = field_new!(Fq3, FQ_ZERO, FQ_ONE, FQ_ZERO);
// A coefficient of MNT6-753 G2 =
// ```
// mnt6753_twist_coeff_a = mnt6753_Fq3(mnt6753_Fq::zero(), mnt6753_Fq::zero(),
// mnt6753_G1::coeff_a);
// = (ZERO, ZERO, A_COEFF);
// ```
#[rustfmt::skip]
const TWIST_COEFF_A: Fp3<Self::Fp3Params> = field_new!(Fq3,
FQ_ZERO,
FQ_ZERO,
g1::Parameters::COEFF_A,
);
// https://github.com/o1-labs/snarky/blob/9c21ab2bb23874604640740d646a932e813432c3/snarkette/mnt6753.ml
const ATE_LOOP_COUNT: &'static [u64] = &[
8824542903220142080,
7711082599397206192,
8303354903384568230,
5874150271971943936,
9717849827920685054,
95829799234282493,
];
const ATE_IS_LOOP_COUNT_NEG: bool = false;
const FINAL_EXPONENT_LAST_CHUNK_1: BigInteger768 =
BigInteger768([0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]);
const FINAL_EXPONENT_LAST_CHUNK_W0_IS_NEG: bool = false;
const FINAL_EXPONENT_LAST_CHUNK_ABS_OF_W0: BigInteger768 = BigInteger768([
8824542903220142080,
7711082599397206192,
8303354903384568230,
5874150271971943936,
9717849827920685054,
95829799234282493,
0,
0,
0,
0,
0,
0,
]);
type Fp = Fq;
type Fr = Fr;
type Fp3Params = Fq3Parameters;
type Fp6Params = Fq6Parameters;
type G1Parameters = self::g1::Parameters;
type G2Parameters = self::g2::Parameters;
}
pub const FQ_ZERO: Fq = field_new!(Fq, BigInteger768([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
pub const FQ_ONE: Fq = field_new!(Fq, FqParameters::R);
pub const FR_ZERO: Fr = field_new!(Fr, BigInteger768([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
pub const FR_ONE: Fr = field_new!(Fr, FrParameters::R);

View File

@@ -0,0 +1,90 @@
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
use ark_ff::{test_rng, Field, One, PrimeField, UniformRand};
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 = MNT6_753::pairing(sa, b);
let ans2 = MNT6_753::pairing(a, sb);
let ans3 = MNT6_753::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());
}
#[test]
fn test_product_of_pairings() {
let rng = &mut test_rng();
let a = G1Projective::rand(rng).into_affine();
let b = G2Projective::rand(rng).into_affine();
let c = G1Projective::rand(rng).into_affine();
let d = G2Projective::rand(rng).into_affine();
let ans1 = MNT6_753::pairing(a, b) * &MNT6_753::pairing(c, d);
let ans2 = MNT6_753::product_of_pairings(&[(a.into(), b.into()), (c.into(), d.into())]);
assert_eq!(ans1, ans2);
}

View File

@@ -0,0 +1 @@
pub use ark_mnt4_753::{Fr as Fq, FrParameters as FqParameters};

137
mnt6_753/src/fields/fq3.rs Normal file
View File

@@ -0,0 +1,137 @@
use crate::{fq::Fq, FQ_ONE};
use ark_ff::{
biginteger::BigInteger768 as BigInteger,
field_new,
fields::fp3::{Fp3, Fp3Parameters},
};
pub type Fq3 = Fp3<Fq3Parameters>;
pub struct Fq3Parameters;
impl Fp3Parameters for Fq3Parameters {
type Fp = Fq;
#[rustfmt::skip]
const NONRESIDUE: Fq = field_new!(Fq, BigInteger([
5145524327033718740,
14149824967095184544,
5159730833497260295,
3902941467692815387,
15830098551216085679,
8665641533746801158,
17502192300007146323,
14483698255198590748,
546300946688995976,
4331975528992054828,
5311428878520309260,
495362057711802,
]));
const TWO_ADICITY: u32 = 30;
#[rustfmt::skip]
const T_MINUS_ONE_DIV_TWO: &'static [u64] = &[
15439605736802142541,
18190868848461853149,
6220121510046940818,
10310485528612680366,
5032137869959796540,
3943048799800510054,
1971151279016362045,
6096644900171872841,
12908407994230849218,
4163225373804228290,
10382959950522770522,
9008828410264446883,
18411821899404157689,
12386199240837247984,
13370099281150720481,
11909278545073807560,
5964354403900302648,
15347506722065009035,
7045354120681109597,
14294096902719509929,
6180325033003959541,
14381489272445870003,
18159920240207503954,
17487026929061632528,
12314108197538755669,
12116872703077811769,
3401400733784294722,
13905351619889935522,
10972472942574358218,
6104159581753028261,
4690139121547787552,
4880965491878697414,
1926648890365125214,
13532564555356297305,
3114545746551080,
0,
];
#[rustfmt::skip]
const QUADRATIC_NONRESIDUE_TO_T: (Fq, Fq, Fq) = (
field_new!(Fq, BigInteger([
2456656400918202012,
7503386575313625620,
1014314685003569848,
10473903647598823719,
15893393002146336511,
8418203974290622500,
9017296731996077946,
2923126592994124774,
9368756030960215800,
17344552888362241070,
10938255746876359306,
107029542386399,
])),
field_new!(Fq, BigInteger([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])),
field_new!(Fq, BigInteger([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])),
);
// Coefficients for the Frobenius automorphism.
// c1[0] = 1,
// c1[1] = 24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132
// c1[2] = 17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868,
#[rustfmt::skip]
const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[
FQ_ONE,
field_new!(Fq, BigInteger([
7739145380395648640,
1403348385939055902,
11220424057264707228,
4567962295300549271,
5929583493640677751,
17618207486530478833,
16600462137977359741,
16551719371247820635,
12057922785354578416,
13022559182829558162,
13308285686168533250,
313705269181021,
])),
field_new!(Fq, BigInteger([
12973180669431253567,
17038664486452692616,
11034024317238370177,
7712681843988565810,
4725787734130647531,
2175028350442404679,
9323639551697167751,
14465264105466053583,
8569442212929419360,
17553812953652473294,
13991744086792172309,
48577617831792,
])),
];
// c2 = {c1[0], c1[2], c1[1]}
#[rustfmt::skip]
const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[
FQ_ONE,
Self::FROBENIUS_COEFF_FP3_C1[2],
Self::FROBENIUS_COEFF_FP3_C1[1],
];
}

View File

@@ -0,0 +1,99 @@
use crate::{Fq, Fq3, Fq3Parameters, FQ_ONE, FQ_ZERO};
use ark_ff::{
biginteger::BigInteger768 as BigInteger,
field_new,
fields::fp6_2over3::{Fp6, Fp6Parameters},
};
pub type Fq6 = Fp6<Fq6Parameters>;
pub struct Fq6Parameters;
impl Fp6Parameters for Fq6Parameters {
type Fp3Params = Fq3Parameters;
#[rustfmt::skip]
const NONRESIDUE: Fq3 = field_new!(Fq3, FQ_ZERO, FQ_ONE, FQ_ZERO);
// Coefficients for the Frobenius automorphism.
// c1[0] = 1,
// c1[1] = 24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052133
// c1[2] = 24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132
// c1[3] = 41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888458477323173057491593855069696241854796396165721416325350064441470418137846398469611935719059908164220784476160000
// c1[4] = 17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868
// c1[5] = 17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107869
#[rustfmt::skip]
const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[
FQ_ONE,
field_new!(Fq, BigInteger([
2665418275744511426,
7073776242814464967,
4441331072847607829,
5681016258918493042,
18254896527151449163,
10681724016023285331,
1760041123371930134,
4557299868084578750,
16702481779049799698,
14149724469588165150,
5617650120443517591,
449252806040736,
])),
field_new!(Fq, BigInteger([
7739145380395648640,
1403348385939055902,
11220424057264707228,
4567962295300549271,
5929583493640677751,
17618207486530478833,
16600462137977359741,
16551719371247820635,
12057922785354578416,
13022559182829558162,
13308285686168533250,
313705269181021,
])),
field_new!(Fq, BigInteger([
2265581976117350591,
18442012872391748519,
3807704300793525789,
12280644139289115082,
10655371227771325282,
1346491763263331896,
7477357615964975877,
12570239403004322603,
2180620924574446161,
12129628062772479841,
8853285699251153944,
362282887012814,
])),
field_new!(Fq, BigInteger([
12973180669431253567,
17038664486452692616,
11034024317238370177,
7712681843988565810,
4725787734130647531,
2175028350442404679,
9323639551697167751,
14465264105466053583,
8569442212929419360,
17553812953652473294,
13991744086792172309,
48577617831792,
])),
field_new!(Fq, BigInteger([
7899453564780116353,
4262348269618550065,
4254931332821270779,
8825735807606509581,
17051100767641418943,
13685288953644762793,
12929962610801289759,
2470844602302811697,
13214001206624640642,
234234166701528666,
6301108521067156651,
184125154691507,
])),
];
}

View File

@@ -0,0 +1 @@
pub use ark_mnt4_753::{Fq as Fr, FqParameters as FrParameters};

View File

@@ -0,0 +1,14 @@
pub mod fr;
pub use self::fr::*;
pub mod fq;
pub use self::fq::*;
pub mod fq3;
pub use self::fq3::*;
pub mod fq6;
pub use self::fq6::*;
#[cfg(all(feature = "mnt6_753", test))]
mod tests;

View File

@@ -0,0 +1,52 @@
use ark_ff::{
fields::{models::fp6_2over3::*, quadratic_extension::QuadExtParameters},
test_rng, Field,
};
use rand::Rng;
use crate::*;
use ark_curve_tests::fields::*;
#[test]
fn test_fr() {
let mut rng = test_rng();
let a: Fr = rng.gen();
let b: Fr = rng.gen();
field_test(a, b);
sqrt_field_test(a);
primefield_test::<Fr>();
}
#[test]
fn test_fq() {
let mut rng = test_rng();
let a: Fq = rng.gen();
let b: Fq = rng.gen();
field_test(a, b);
sqrt_field_test(a);
primefield_test::<Fq>();
}
#[test]
fn test_fq3() {
let mut rng = test_rng();
let a: Fq3 = rng.gen();
let b: Fq3 = rng.gen();
field_test(a, b);
sqrt_field_test(a);
frobenius_test::<Fq3, _>(Fq::characteristic(), 13);
assert_eq!(
a * Fq6Parameters::NONRESIDUE,
<Fp6ParamsWrapper<Fq6Parameters>>::mul_base_field_by_nonresidue(&a)
);
}
#[test]
fn test_fq6() {
let mut rng = test_rng();
let a: Fq6 = rng.gen();
let b: Fq6 = rng.gen();
field_test(a, b);
frobenius_test::<Fq6, _>(Fq::characteristic(), 13);
}

34
mnt6_753/src/lib.rs Normal file
View File

@@ -0,0 +1,34 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(
warnings,
unused,
future_incompatible,
nonstandard_style,
rust_2018_idioms
)]
#![forbid(unsafe_code)]
//! This library implements the MNT6_753 curve generated in
//! [[BCTV14]](https://eprint.iacr.org/2014/595). The name denotes that it is a
//! Miyaji--Nakabayashi--Takano curve of embedding degree 6, defined over a 753-bit (prime) field.
//! The main feature of this curve is that its scalar field and base field respectively equal the
//! base field and scalar field of MNT4_753.
//!
//! Curve information:
//! * Base field: q = 0x01C4C62D92C41110229022EEE2CDADB7F997505B8FAFED5EB7E8F96C97D87307FDB925E8A0ED8D99D124D9A15AF79DB26C5C28C859A99B3EEBCA9429212636B9DFF97634993AA4D6C381BC3F0057974EA099170FA13A4FD90776E240000001
//! * Scalar field: r = 0x01C4C62D92C41110229022EEE2CDADB7F997505B8FAFED5EB7E8F96C97D87307FDB925E8A0ED8D99D124D9A15AF79DB117E776F218059DB80F0DA5CB537E38685ACCE9767254A4638810719AC425F0E39D54522CDD119F5E9063DE245E8001
//! * valuation(q - 1, 2) = 30
//! * valuation(r - 1, 2) = 15
//! * G1 curve equation: y^2 = x^3 + ax + b, where
//! * a = 11
//! * b = 0x7DA285E70863C79D56446237CE2E1468D14AE9BB64B2BB01B10E60A5D5DFE0A25714B7985993F62F03B22A9A3C737A1A1E0FCF2C43D7BF847957C34CCA1E3585F9A80A95F401867C4E80F4747FDE5ABA7505BA6FCF2485540B13DFC8468A
//! * G2 curve equation: y^2 = x^3 + Ax + B, where
//! * A = Fq3(0, 0, a)
//! * B = Fq3(b * NON_RESIDUE, 0, 0)
//! * NON_RESIDUE = 11 is the cubic non-residue used to construct the extension field Fq3
mod curves;
mod fields;
pub use curves::*;
pub use fields::*;