Browse Source

Update `MNT4-298`

fq2_neg_nonresidue
Pratyush Mishra 3 years ago
parent
commit
6f7235d939
6 changed files with 29 additions and 151 deletions
  1. +5
    -29
      mnt4_298/src/curves/g1.rs
  2. +9
    -45
      mnt4_298/src/curves/g2.rs
  3. +7
    -16
      mnt4_298/src/curves/mod.rs
  4. +2
    -2
      mnt4_298/src/curves/tests.rs
  5. +3
    -28
      mnt4_298/src/fields/fq2.rs
  6. +3
    -31
      mnt4_298/src/fields/fq4.rs

+ 5
- 29
mnt4_298/src/curves/g1.rs

@ -3,7 +3,7 @@ use ark_ec::{
mnt4, mnt4,
models::{ModelParameters, SWModelParameters}, models::{ModelParameters, SWModelParameters},
}; };
use ark_ff::{biginteger::BigInteger320, field_new};
use ark_ff::{field_new};
pub type G1Affine = mnt4::G1Affine<crate::Parameters>; pub type G1Affine = mnt4::G1Affine<crate::Parameters>;
pub type G1Projective = mnt4::G1Projective<crate::Parameters>; pub type G1Projective = mnt4::G1Projective<crate::Parameters>;
@ -21,24 +21,12 @@ impl SWModelParameters for Parameters {
/// COEFF_A = 2 /// COEFF_A = 2
/// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L116 /// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L116
#[rustfmt::skip] #[rustfmt::skip]
const COEFF_A: Fq = field_new!(Fq, BigInteger320([
3568597988870129848,
15257338106490985450,
10069779447956199041,
5922375556522222383,
3858029504390,
]));
const COEFF_A: Fq = field_new!(Fq, "2");
/// COEFF_B = 423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685 /// COEFF_B = 423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685
/// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L117 /// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L117
#[rustfmt::skip] #[rustfmt::skip]
const COEFF_B: Fq = field_new!(Fq, BigInteger320([
7842808090366692145,
288200302308193399,
4162060950790347941,
5488589108190218591,
1553456013645,
]));
const COEFF_B: Fq = field_new!(Fq, "423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685");
/// COFACTOR = 1 /// COFACTOR = 1
const COFACTOR: &'static [u64] = &[1]; const COFACTOR: &'static [u64] = &[1];
@ -59,21 +47,9 @@ impl SWModelParameters for Parameters {
/// G1_GENERATOR_X /// G1_GENERATOR_X
/// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L137 /// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L137
#[rustfmt::skip] #[rustfmt::skip]
pub const G1_GENERATOR_X: Fq = field_new!(Fq, BigInteger320([
6046301378120906932,
15105298306031900263,
15757949605695610691,
6113949277267426050,
3063081829217,
]));
pub const G1_GENERATOR_X: Fq = field_new!(Fq, "60760244141852568949126569781626075788424196370144486719385562369396875346601926534016838");
/// G1_GENERATOR_Y /// G1_GENERATOR_Y
/// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L138 /// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L138
#[rustfmt::skip] #[rustfmt::skip]
pub const G1_GENERATOR_Y: Fq = field_new!(Fq, BigInteger320([
8798367863963590781,
9770379341721339603,
17697354471293810920,
15252694996423733496,
3845520398052,
]));
pub const G1_GENERATOR_Y: Fq = field_new!(Fq, "363732850702582978263902770815145784459747722357071843971107674179038674942891694705904306");

+ 9
- 45
mnt4_298/src/curves/g2.rs

@ -4,7 +4,7 @@ use ark_ec::{
mnt4::MNT4Parameters, mnt4::MNT4Parameters,
models::{ModelParameters, SWModelParameters}, models::{ModelParameters, SWModelParameters},
}; };
use ark_ff::{biginteger::BigInteger320, field_new};
use ark_ff::field_new;
pub type G2Affine = mnt4::G2Affine<crate::Parameters>; pub type G2Affine = mnt4::G2Affine<crate::Parameters>;
pub type G2Projective = mnt4::G2Projective<crate::Parameters>; pub type G2Projective = mnt4::G2Projective<crate::Parameters>;
@ -40,13 +40,7 @@ impl SWModelParameters for Parameters {
#[rustfmt::skip] #[rustfmt::skip]
const COEFF_B: Fq2 = field_new!(Fq2, const COEFF_B: Fq2 = field_new!(Fq2,
FQ_ZERO, FQ_ZERO,
field_new!(Fq, BigInteger320([
9511110677122940475,
13403516020116973437,
1464701424831086967,
4646785117660390394,
1747881737068,
])),
field_new!(Fq, "67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430"),
); );
/// COFACTOR = /// COFACTOR =
@ -63,13 +57,7 @@ impl SWModelParameters for Parameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665 /// 475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665
#[rustfmt::skip] #[rustfmt::skip]
const COFACTOR_INV: Fr = field_new!(Fr, BigInteger320([
8065818351154103109,
7537800592537321232,
747075088561892445,
6335802185495034136,
1874289794052,
]));
const COFACTOR_INV: Fr = field_new!(Fr, "475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665");
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
@ -87,41 +75,17 @@ const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1
// Generator of G2 // Generator of G2
// These are two Fq elements each because X and Y (and Z) are elements of Fq^2 // These are two Fq elements each because X and Y (and Z) are elements of Fq^2
// X = 438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708, // X = 438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708,
// 37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641,
// 37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641,
// Y = 37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482, // Y = 37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482,
// 424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489,
// 424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489,
#[rustfmt::skip] #[rustfmt::skip]
pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger320([
5356671649366391794,
2684151262065976452,
4683110650642896126,
10421299515941681582,
1618695480960
]));
pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708");
#[rustfmt::skip] #[rustfmt::skip]
pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger320([
133394645290266480,
15395232932057272770,
18271324022738539173,
9095178119640120034,
2303787573609
]));
pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641");
#[rustfmt::skip] #[rustfmt::skip]
pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger320([
16920448081812496532,
15580160192086626100,
3974467672100342742,
8216505962266760277,
2643162835232
]));
pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482");
#[rustfmt::skip] #[rustfmt::skip]
pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger320([
73816197493558356,
8663991890578965996,
11575903875707445958,
17953546933481201011,
2167465829200
]));
pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489");

+ 7
- 16
mnt4_298/src/curves/mod.rs

@ -1,7 +1,7 @@
use ark_ec::models::mnt4::{MNT4Parameters, MNT4}; use ark_ec::models::mnt4::{MNT4Parameters, MNT4};
use ark_ff::{biginteger::BigInteger320, field_new, fields::FpParameters, Fp2};
use ark_ff::{biginteger::BigInteger320, field_new, Fp2};
use crate::{Fq, Fq2, Fq2Parameters, Fq4Parameters, FqParameters, Fr, FrParameters};
use crate::{Fq, Fq2, Fq2Parameters, Fq4Parameters, Fr};
pub mod g1; pub mod g1;
pub mod g2; pub mod g2;
@ -47,17 +47,8 @@ impl MNT4Parameters for Parameters {
} }
// 34 // 34
pub const G1_COEFF_A_NON_RESIDUE: Fq = field_new!(
Fq,
BigInteger320([
9379015694948865065,
3933863906897692531,
7183785805598089445,
17382890709766103498,
3934325337380,
])
);
pub const FQ_ZERO: Fq = field_new!(Fq, BigInteger320([0, 0, 0, 0, 0]));
pub const FQ_ONE: Fq = field_new!(Fq, FqParameters::R);
pub const FR_ZERO: Fr = field_new!(Fr, BigInteger320([0, 0, 0, 0, 0]));
pub const FR_ONE: Fr = field_new!(Fr, FrParameters::R);
pub const G1_COEFF_A_NON_RESIDUE: Fq = field_new!(Fq, "34");
pub const FQ_ZERO: Fq = field_new!(Fq, "0");
pub const FQ_ONE: Fq = field_new!(Fq, "1");
pub const FR_ZERO: Fr = field_new!(Fr, "0");
pub const FR_ONE: Fr = field_new!(Fr, "1");

+ 2
- 2
mnt4_298/src/curves/tests.rs

@ -57,8 +57,8 @@ fn test_bilinearity() {
let b: G2Projective = rng.gen(); let b: G2Projective = rng.gen();
let s: Fr = rng.gen(); let s: Fr = rng.gen();
let sa = a.mul(s);
let sb = b.mul(s);
let sa = a.mul(s.into_repr());
let sb = b.mul(s.into_repr());
let ans1 = MNT4_298::pairing(sa, b); let ans1 = MNT4_298::pairing(sa, b);
let ans2 = MNT4_298::pairing(a, sb); let ans2 = MNT4_298::pairing(a, sb);

+ 3
- 28
mnt4_298/src/fields/fq2.rs

@ -1,6 +1,5 @@
use crate::{Fq, FQ_ONE}; use crate::{Fq, FQ_ONE};
use ark_ff::{ use ark_ff::{
biginteger::BigInteger320 as BigInteger,
field_new, field_new,
fields::fp2::{Fp2, Fp2Parameters}, fields::fp2::{Fp2, Fp2Parameters},
}; };
@ -15,28 +14,13 @@ impl Fp2Parameters for Fq2Parameters {
/// The quadratic non-residue (17) used to construct the extension is /// The quadratic non-residue (17) used to construct the extension is
/// the same as that used in [`libff`](https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L102). /// the same as that used in [`libff`](https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L102).
#[rustfmt::skip] #[rustfmt::skip]
const NONRESIDUE: Fq = field_new!(Fq, BigInteger([
2709730703260633621,
13556085429182073539,
10903316137158576359,
5319113788683590444,
4022235209932,
]));
const NONRESIDUE: Fq = field_new!(Fq, "17");
/// The quadratic non-residue in F<sub>p</sub><sup>2</sup> that is used /// The quadratic non-residue in F<sub>p</sub><sup>2</sup> that is used
/// in the computation of square roots is (8, 1), the same as that in /// in the computation of square roots is (8, 1), the same as that in
/// [`libff`](https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L103) /// [`libff`](https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L103)
const QUADRATIC_NONRESIDUE: (Self::Fp, Self::Fp) = ( const QUADRATIC_NONRESIDUE: (Self::Fp, Self::Fp) = (
field_new!(
Fq,
BigInteger([
7706310747053761245,
9941175645274129776,
14857322459377157960,
7030003475866554129,
3101682770110
])
),
field_new!(Fq, "8"),
FQ_ONE, FQ_ONE,
); );
@ -44,15 +28,6 @@ impl Fp2Parameters for Fq2Parameters {
/// `[1, 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080]` /// `[1, 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080]`
const FROBENIUS_COEFF_FP2_C1: &'static [Self::Fp] = &[ const FROBENIUS_COEFF_FP2_C1: &'static [Self::Fp] = &[
FQ_ONE, FQ_ONE,
field_new!(
Fq,
BigInteger([
12702890790846888869,
6326265861366186013,
364584707886187945,
8740893163049517815,
2181130330288
])
),
field_new!(Fq, "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"),
]; ];
} }

+ 3
- 31
mnt4_298/src/fields/fq4.rs

@ -1,6 +1,5 @@
use crate::{Fq, Fq2, Fq2Parameters, FQ_ONE, FQ_ZERO}; use crate::{Fq, Fq2, Fq2Parameters, FQ_ONE, FQ_ZERO};
use ark_ff::{ use ark_ff::{
biginteger::BigInteger320 as BigInteger,
field_new, field_new,
fields::fp4::{Fp4, Fp4Parameters}, fields::fp4::{Fp4, Fp4Parameters},
}; };
@ -22,35 +21,8 @@ impl Fp4Parameters for Fq4Parameters {
#[rustfmt::skip] #[rustfmt::skip]
const FROBENIUS_COEFF_FP4_C1: &'static [Fq] = &[ const FROBENIUS_COEFF_FP4_C1: &'static [Fq] = &[
FQ_ONE, FQ_ONE,
field_new!(
Fq,
BigInteger([
16439849825752526567,
14772594681319164557,
16175669228740845684,
4590896976404796446,
3810243174413
])
),
field_new!(
Fq,
BigInteger([
12702890790846888869,
6326265861366186013,
364584707886187945,
8740893163049517815,
2181130330288
])
),
field_new!(
Fq,
BigInteger([
16494084033238978842,
8405712270147289988,
16893921313687769205,
7111183964905832559,
299901908070
])
),
field_new!(Fq, "7684163245453501615621351552473337069301082060976805004625011694147890954040864167002308"),
field_new!(Fq, "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"),
field_new!(Fq, "468238122923807824137727898100575114475823797181717920390930116882062371863914936316755773"),
]; ];
} }

Loading…
Cancel
Save