mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-09 15:31:34 +01:00
Upgrade to work with latest ark-ff (#95)
Co-authored-by: Sun <huachuang20@gmail.com>
This commit is contained in:
28
mnt4_298/scripts/base_field.sage
Normal file
28
mnt4_298/scripts/base_field.sage
Normal file
@@ -0,0 +1,28 @@
|
||||
modulus = 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758081
|
||||
|
||||
assert(modulus.is_prime())
|
||||
|
||||
Fp = GF(modulus)
|
||||
|
||||
generator = Fp(0);
|
||||
for i in range(0, 20):
|
||||
i = Fp(i);
|
||||
neg_i = Fp(-i)
|
||||
if not(i.is_primitive_root() or neg_i.is_primitive_root()):
|
||||
continue
|
||||
elif i.is_primitive_root():
|
||||
assert(i.is_primitive_root());
|
||||
print("Generator: %d" % i)
|
||||
generator = i
|
||||
break
|
||||
else:
|
||||
assert(neg_i.is_primitive_root());
|
||||
print("Generator: %d" % neg_i)
|
||||
generator = neg_i
|
||||
break
|
||||
|
||||
|
||||
two_adicity = valuation(modulus - 1, 2);
|
||||
trace = (modulus - 1) / 2**two_adicity;
|
||||
two_adic_root_of_unity = generator^trace
|
||||
print("2-adic Root of Unity: %d " % two_adic_root_of_unity)
|
||||
28
mnt4_298/scripts/scalar_field.sage
Normal file
28
mnt4_298/scripts/scalar_field.sage
Normal file
@@ -0,0 +1,28 @@
|
||||
modulus = 475922286169261325753349249653048451545124878552823515553267735739164647307408490559963137
|
||||
|
||||
assert(modulus.is_prime())
|
||||
|
||||
Fp = GF(modulus)
|
||||
|
||||
generator = Fp(0);
|
||||
for i in range(0, 20):
|
||||
i = Fp(i);
|
||||
neg_i = Fp(-i)
|
||||
if not(i.is_primitive_root() or neg_i.is_primitive_root()):
|
||||
continue
|
||||
elif i.is_primitive_root():
|
||||
assert(i.is_primitive_root());
|
||||
print("Generator: %d" % i)
|
||||
generator = i
|
||||
break
|
||||
else:
|
||||
assert(neg_i.is_primitive_root());
|
||||
print("Generator: %d" % neg_i)
|
||||
generator = neg_i
|
||||
break
|
||||
|
||||
|
||||
two_adicity = valuation(modulus - 1, 2);
|
||||
trace = (modulus - 1) / 2**two_adicity;
|
||||
two_adic_root_of_unity = generator^trace
|
||||
print("2-adic Root of Unity: %d " % two_adic_root_of_unity)
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::Parameters;
|
||||
use ark_r1cs_std::groups::mnt4;
|
||||
|
||||
use crate::Parameters;
|
||||
|
||||
/// An element of G1 in the MNT4-298 bilinear group.
|
||||
pub type G1Var = mnt4::G1Var<Parameters>;
|
||||
/// An element of G2 in the MNT4-298 bilinear group.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use crate::{Fq, Fq2Parameters, Fq4Parameters};
|
||||
|
||||
use ark_r1cs_std::fields::{fp::FpVar, fp2::Fp2Var, fp4::Fp4Var};
|
||||
|
||||
use crate::{Fq, Fq2Config, Fq4Config};
|
||||
|
||||
/// A variable that is the R1CS equivalent of `crate::Fq`.
|
||||
pub type FqVar = FpVar<Fq>;
|
||||
/// A variable that is the R1CS equivalent of `crate::Fq2`.
|
||||
pub type Fq2Var = Fp2Var<Fq2Parameters>;
|
||||
pub type Fq2Var = Fp2Var<Fq2Config>;
|
||||
/// A variable that is the R1CS equivalent of `crate::Fq4`.
|
||||
pub type Fq4Var = Fp4Var<Fq4Parameters>;
|
||||
pub type Fq4Var = Fp4Var<Fq4Config>;
|
||||
|
||||
#[test]
|
||||
fn mnt4_298_field_gadgets_test() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::Parameters;
|
||||
|
||||
/// Specifies the constraints for computing a pairing in the MNT4-298 bilinear group.
|
||||
/// Specifies the constraints for computing a pairing in the MNT4-298 bilinear
|
||||
/// group.
|
||||
pub type PairingVar = ark_r1cs_std::pairing::mnt4::PairingVar<Parameters>;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::{Fq, Fr, FR_ONE};
|
||||
use ark_ec::{
|
||||
mnt4,
|
||||
models::{ModelParameters, SWModelParameters},
|
||||
};
|
||||
use ark_ff::field_new;
|
||||
use ark_ff::MontFp;
|
||||
|
||||
use crate::{Fq, Fr, FR_ONE};
|
||||
|
||||
pub type G1Affine = mnt4::G1Affine<crate::Parameters>;
|
||||
pub type G1Projective = mnt4::G1Projective<crate::Parameters>;
|
||||
@@ -21,20 +22,17 @@ impl ModelParameters for Parameters {
|
||||
|
||||
/// COFACTOR^(-1) mod r =
|
||||
/// 1
|
||||
#[rustfmt::skip]
|
||||
const COFACTOR_INV: Fr = FR_ONE;
|
||||
}
|
||||
|
||||
impl SWModelParameters for Parameters {
|
||||
/// COEFF_A = 2
|
||||
/// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L116>
|
||||
#[rustfmt::skip]
|
||||
const COEFF_A: Fq = field_new!(Fq, "2");
|
||||
const COEFF_A: Fq = MontFp!(Fq, "2");
|
||||
|
||||
/// COEFF_B = 423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685
|
||||
/// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L117>
|
||||
#[rustfmt::skip]
|
||||
const COEFF_B: Fq = field_new!(Fq, "423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685");
|
||||
const COEFF_B: Fq = MontFp!(Fq, "423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685");
|
||||
|
||||
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
|
||||
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
|
||||
@@ -46,10 +44,14 @@ impl SWModelParameters for Parameters {
|
||||
// Y = 363732850702582978263902770815145784459747722357071843971107674179038674942891694705904306,
|
||||
/// G1_GENERATOR_X
|
||||
/// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L137>
|
||||
#[rustfmt::skip]
|
||||
pub const G1_GENERATOR_X: Fq = field_new!(Fq, "60760244141852568949126569781626075788424196370144486719385562369396875346601926534016838");
|
||||
pub const G1_GENERATOR_X: Fq = MontFp!(
|
||||
Fq,
|
||||
"60760244141852568949126569781626075788424196370144486719385562369396875346601926534016838"
|
||||
);
|
||||
|
||||
/// G1_GENERATOR_Y
|
||||
/// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L138>
|
||||
#[rustfmt::skip]
|
||||
pub const G1_GENERATOR_Y: Fq = field_new!(Fq, "363732850702582978263902770815145784459747722357071843971107674179038674942891694705904306");
|
||||
pub const G1_GENERATOR_Y: Fq = MontFp!(
|
||||
Fq,
|
||||
"363732850702582978263902770815145784459747722357071843971107674179038674942891694705904306"
|
||||
);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use crate::{Fq, Fq2, Fr, FQ_ZERO, G1_COEFF_A_NON_RESIDUE};
|
||||
use ark_ec::{
|
||||
mnt4,
|
||||
mnt4::MNT4Parameters,
|
||||
models::{ModelParameters, SWModelParameters},
|
||||
};
|
||||
use ark_ff::field_new;
|
||||
use ark_ff::{MontFp, QuadExt};
|
||||
|
||||
use crate::{Fq, Fq2, Fr, FQ_ZERO, G1_COEFF_A_NON_RESIDUE};
|
||||
|
||||
pub type G2Affine = mnt4::G2Affine<crate::Parameters>;
|
||||
pub type G2Projective = mnt4::G2Projective<crate::Parameters>;
|
||||
@@ -30,16 +31,13 @@ impl ModelParameters for Parameters {
|
||||
|
||||
/// COFACTOR^(-1) mod r =
|
||||
/// 475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665
|
||||
#[rustfmt::skip]
|
||||
const COFACTOR_INV: Fr = field_new!(Fr, "475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665");
|
||||
const COFACTOR_INV: Fr = MontFp!(Fr, "475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665");
|
||||
}
|
||||
|
||||
/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A
|
||||
#[rustfmt::skip]
|
||||
pub const MUL_BY_A_C0: Fq = G1_COEFF_A_NON_RESIDUE;
|
||||
|
||||
/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
|
||||
#[rustfmt::skip]
|
||||
pub const MUL_BY_A_C1: Fq = G1_COEFF_A_NON_RESIDUE;
|
||||
|
||||
impl SWModelParameters for Parameters {
|
||||
@@ -53,10 +51,9 @@ impl SWModelParameters for Parameters {
|
||||
// =
|
||||
// (0, 67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430)
|
||||
// ```
|
||||
#[rustfmt::skip]
|
||||
const COEFF_B: Fq2 = field_new!(Fq2,
|
||||
const COEFF_B: Fq2 = QuadExt!(
|
||||
FQ_ZERO,
|
||||
field_new!(Fq, "67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430"),
|
||||
MontFp!(Fq, "67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430"),
|
||||
);
|
||||
|
||||
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
|
||||
@@ -65,12 +62,12 @@ impl SWModelParameters for Parameters {
|
||||
|
||||
#[inline(always)]
|
||||
fn mul_by_a(elt: &Fq2) -> Fq2 {
|
||||
field_new!(Fq2, MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1,)
|
||||
QuadExt!(MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1,)
|
||||
}
|
||||
}
|
||||
|
||||
const G2_GENERATOR_X: Fq2 = field_new!(Fq2, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
|
||||
const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
|
||||
const G2_GENERATOR_X: Fq2 = QuadExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
|
||||
const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
|
||||
|
||||
// Generator of G2
|
||||
// These are two Fq elements each because X and Y (and Z) are elements of Fq^2
|
||||
@@ -78,14 +75,22 @@ const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1
|
||||
// 37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641,
|
||||
// Y = 37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482,
|
||||
// 424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489,
|
||||
#[rustfmt::skip]
|
||||
pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708");
|
||||
pub const G2_GENERATOR_X_C0: Fq = MontFp!(
|
||||
Fq,
|
||||
"438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708"
|
||||
);
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641");
|
||||
pub const G2_GENERATOR_X_C1: Fq = MontFp!(
|
||||
Fq,
|
||||
"37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641"
|
||||
);
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482");
|
||||
pub const G2_GENERATOR_Y_C0: Fq = MontFp!(
|
||||
Fq,
|
||||
"37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482"
|
||||
);
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489");
|
||||
pub const G2_GENERATOR_Y_C1: Fq = MontFp!(
|
||||
Fq,
|
||||
"424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489"
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use ark_ec::models::mnt4::{MNT4Parameters, MNT4};
|
||||
use ark_ff::{biginteger::BigInteger320, field_new, BigInt, Fp2};
|
||||
use ark_ff::{biginteger::BigInteger320, BigInt, Fp2, MontFp, QuadExt};
|
||||
|
||||
use crate::{Fq, Fq2, Fq2Parameters, Fq4Parameters, Fr};
|
||||
use crate::{Fq, Fq2Config, Fq4Config, Fr};
|
||||
|
||||
pub mod g1;
|
||||
pub mod g2;
|
||||
@@ -19,18 +19,14 @@ pub type MNT4_298 = MNT4<Parameters>;
|
||||
pub struct Parameters;
|
||||
|
||||
impl MNT4Parameters for Parameters {
|
||||
const TWIST: Fp2<Self::Fp2Params> = field_new!(Fq2, FQ_ZERO, FQ_ONE);
|
||||
const TWIST: Fp2<Self::Fp2Config> = QuadExt!(FQ_ZERO, FQ_ONE);
|
||||
// A coefficient of MNT4-298 G2 =
|
||||
// ```
|
||||
// mnt4298_twist_coeff_a = mnt4298_Fq2(mnt4298_G1::coeff_a * non_residue, mnt6298_Fq::zero());
|
||||
// = (A_COEFF * NONRESIDUE, ZERO)
|
||||
// = (34, ZERO)
|
||||
// ```
|
||||
#[rustfmt::skip]
|
||||
const TWIST_COEFF_A: Fp2<Self::Fp2Params> = field_new!(Fq2,
|
||||
G1_COEFF_A_NON_RESIDUE,
|
||||
FQ_ZERO,
|
||||
);
|
||||
const TWIST_COEFF_A: Fp2<Self::Fp2Config> = QuadExt!(G1_COEFF_A_NON_RESIDUE, FQ_ZERO);
|
||||
|
||||
const ATE_LOOP_COUNT: &'static [u64] = &[993502997770534912, 5071219579242586943, 2027349];
|
||||
const ATE_IS_LOOP_COUNT_NEG: bool = false;
|
||||
@@ -40,15 +36,15 @@ impl MNT4Parameters for Parameters {
|
||||
BigInt::new([993502997770534913, 5071219579242586943, 2027349, 0, 0]);
|
||||
type Fp = Fq;
|
||||
type Fr = Fr;
|
||||
type Fp2Params = Fq2Parameters;
|
||||
type Fp4Params = Fq4Parameters;
|
||||
type Fp2Config = Fq2Config;
|
||||
type Fp4Config = Fq4Config;
|
||||
type G1Parameters = self::g1::Parameters;
|
||||
type G2Parameters = self::g2::Parameters;
|
||||
}
|
||||
|
||||
// 34
|
||||
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");
|
||||
pub const G1_COEFF_A_NON_RESIDUE: Fq = MontFp!(Fq, "34");
|
||||
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");
|
||||
pub const FQ_ONE: Fq = MontFp!(Fq, "1");
|
||||
pub const FR_ZERO: Fr = MontFp!(Fr, "0");
|
||||
pub const FR_ONE: Fr = MontFp!(Fr, "1");
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
|
||||
use ark_ff::{Field, One, PrimeField, UniformRand};
|
||||
use ark_std::{rand::Rng, test_rng};
|
||||
|
||||
use crate::*;
|
||||
|
||||
use ark_algebra_test_templates::{
|
||||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test,
|
||||
generate_product_of_pairings_test, groups::*, msm::*,
|
||||
};
|
||||
|
||||
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
|
||||
use ark_ff::{Field, One, PrimeField, UniformRand};
|
||||
use ark_std::{rand::Rng, test_rng};
|
||||
use core::ops::MulAssign;
|
||||
|
||||
use crate::*;
|
||||
|
||||
generate_g1_test!(mnt4_298; curve_tests; sw_tests;);
|
||||
generate_g2_test!(mnt4_298; curve_tests; sw_tests;);
|
||||
generate_bilinearity_test!(MNT4_298, Fq4);
|
||||
|
||||
@@ -1,115 +1,9 @@
|
||||
use ark_ff::{
|
||||
biginteger::{BigInt, BigInteger320 as BigInteger},
|
||||
fields::{FftParameters, Fp320, Fp320Parameters, FpParameters},
|
||||
};
|
||||
use ark_ff::fields::{Fp320, MontBackend, MontConfig};
|
||||
|
||||
pub type Fq = Fp320<FqParameters>;
|
||||
|
||||
pub struct FqParameters;
|
||||
|
||||
impl Fp320Parameters for FqParameters {}
|
||||
impl FftParameters for FqParameters {
|
||||
type BigInt = BigInteger;
|
||||
|
||||
const TWO_ADICITY: u32 = 17;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
||||
9821480371597472441u64,
|
||||
9468346035609379175u64,
|
||||
9963748368231707135u64,
|
||||
14865337659602750405u64,
|
||||
3984815592673u64,
|
||||
]);
|
||||
|
||||
const SMALL_SUBGROUP_BASE: Option<u32> = Some(7);
|
||||
const SMALL_SUBGROUP_BASE_ADICITY: Option<u32> = Some(2);
|
||||
|
||||
/// LARGE_SUBGROUP_ROOT_OF_UNITY = x * g
|
||||
/// where x = (n - 1) / 2^17 / 7^2
|
||||
/// and represent this value in the Montgomery residue form.
|
||||
/// I.e., write
|
||||
/// 381811485921190977554243339163030148371175054922689353173385941180422489253833691237722982
|
||||
/// * R
|
||||
/// = 260534023778902228073198316993669317435810479439368306496187170459125001342456918103569322
|
||||
const LARGE_SUBGROUP_ROOT_OF_UNITY: Option<BigInteger> = Some(BigInt::new([
|
||||
7711798843682337706u64,
|
||||
16456007754393011187u64,
|
||||
7470854640069402569u64,
|
||||
10767969225751706229u64,
|
||||
2250015743691u64,
|
||||
]));
|
||||
}
|
||||
impl FpParameters for FqParameters {
|
||||
/// MODULUS = 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758081
|
||||
#[rustfmt::skip]
|
||||
const MODULUS: BigInteger = BigInt::new([
|
||||
14487189785281953793u64,
|
||||
4731562877756902930u64,
|
||||
14622846468719063274u64,
|
||||
11702080941310629006u64,
|
||||
4110145082483u64,
|
||||
]);
|
||||
|
||||
const MODULUS_BITS: u32 = 298;
|
||||
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
||||
|
||||
const REPR_SHAVE_BITS: u32 = 22;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const R: BigInteger = BigInt::new([
|
||||
1784298994435064924u64,
|
||||
16852041090100268533u64,
|
||||
14258261760832875328u64,
|
||||
2961187778261111191u64,
|
||||
1929014752195u64,
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const R2: BigInteger = BigInt::new([
|
||||
28619103704175136u64,
|
||||
11702218449377544339u64,
|
||||
7403203599591297249u64,
|
||||
2248105543421449339u64,
|
||||
2357678148148u64,
|
||||
]);
|
||||
|
||||
const INV: u64 = 12714121028002250751u64;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
||||
2709730703260633621u64,
|
||||
13556085429182073539u64,
|
||||
10903316137158576359u64,
|
||||
5319113788683590444u64,
|
||||
4022235209932u64,
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const T: BigInteger = BigInt::new([
|
||||
0x70964866b2d38b3,
|
||||
0x987520d4f1af2890,
|
||||
0x2a47657764b1ae89,
|
||||
0x6a39d133124ed3d8,
|
||||
0x1de7bde,
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0x384b24335969c59,
|
||||
0xcc3a906a78d79448,
|
||||
0x1523b2bbb258d744,
|
||||
0x351ce899892769ec,
|
||||
0xef3def,
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0x64866b2d38b30000,
|
||||
0x20d4f1af28900709,
|
||||
0x657764b1ae899875,
|
||||
0xd133124ed3d82a47,
|
||||
0x1de7bde6a39,
|
||||
]);
|
||||
}
|
||||
#[derive(MontConfig)]
|
||||
#[modulus = "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758081"]
|
||||
#[generator = "17"]
|
||||
#[small_subgroup_base = "7"]
|
||||
#[small_subgroup_power = "2"]
|
||||
pub struct FqConfig;
|
||||
pub type Fq = Fp320<MontBackend<FqConfig, 5>>;
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
use crate::{Fq, FQ_ONE};
|
||||
use ark_ff::{
|
||||
field_new,
|
||||
fields::fp2::{Fp2, Fp2Parameters},
|
||||
fields::fp2::{Fp2, Fp2Config},
|
||||
MontFp, QuadExt,
|
||||
};
|
||||
|
||||
pub type Fq2 = Fp2<Fq2Parameters>;
|
||||
use crate::{Fq, FQ_ONE};
|
||||
|
||||
pub struct Fq2Parameters;
|
||||
pub type Fq2 = Fp2<Fq2Config>;
|
||||
|
||||
impl Fp2Parameters for Fq2Parameters {
|
||||
pub struct Fq2Config;
|
||||
|
||||
impl Fp2Config for Fq2Config {
|
||||
type Fp = Fq;
|
||||
|
||||
/// 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).
|
||||
#[rustfmt::skip]
|
||||
const NONRESIDUE: Fq = field_new!(Fq, "17");
|
||||
const NONRESIDUE: Fq = MontFp!(Fq, "17");
|
||||
|
||||
/// 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
|
||||
/// [`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) = (field_new!(Fq, "8"), FQ_ONE);
|
||||
const QUADRATIC_NONRESIDUE: Fq2 = QuadExt!(MontFp!(Fq, "8"), FQ_ONE);
|
||||
|
||||
/// Precomputed coefficients:
|
||||
/// `[1, 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080]`
|
||||
const FROBENIUS_COEFF_FP2_C1: &'static [Self::Fp] = &[
|
||||
FQ_ONE,
|
||||
field_new!(Fq, "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"),
|
||||
MontFp!(Fq, "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
use crate::{Fq, Fq2, Fq2Parameters, FQ_ONE, FQ_ZERO};
|
||||
use ark_ff::{
|
||||
field_new,
|
||||
fields::fp4::{Fp4, Fp4Parameters},
|
||||
fields::fp4::{Fp4, Fp4Config},
|
||||
MontFp, QuadExt,
|
||||
};
|
||||
|
||||
pub type Fq4 = Fp4<Fq4Parameters>;
|
||||
use crate::{Fq, Fq2, Fq2Config, FQ_ONE, FQ_ZERO};
|
||||
|
||||
pub struct Fq4Parameters;
|
||||
pub type Fq4 = Fp4<Fq4Config>;
|
||||
|
||||
impl Fp4Parameters for Fq4Parameters {
|
||||
type Fp2Params = Fq2Parameters;
|
||||
pub struct Fq4Config;
|
||||
|
||||
const NONRESIDUE: Fq2 = field_new!(Fq2, FQ_ZERO, FQ_ONE);
|
||||
impl Fp4Config for Fq4Config {
|
||||
type Fp2Config = Fq2Config;
|
||||
|
||||
const NONRESIDUE: Fq2 = QuadExt!(FQ_ZERO, FQ_ONE);
|
||||
|
||||
// Coefficients for the Frobenius automorphism.
|
||||
// c1[0] = 1,
|
||||
@@ -19,12 +20,12 @@ impl Fp4Parameters for Fq4Parameters {
|
||||
// c1[2] = 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080
|
||||
// c1[3] = 468238122923807824137727898100575114475823797181717920390930116882062371863914936316755773
|
||||
//
|
||||
// These are calculated as `FROBENIUS_COEFF_FP4_C1[i] = Fp2Params::NONRESIDUE^((q^i - 1) / 4)`.
|
||||
#[rustfmt::skip]
|
||||
// These are calculated as
|
||||
// `FROBENIUS_COEFF_FP4_C1[i] = Fp2Config::NONRESIDUE^((q^i - 1) / 4)`.
|
||||
const FROBENIUS_COEFF_FP4_C1: &'static [Fq] = &[
|
||||
FQ_ONE,
|
||||
field_new!(Fq, "7684163245453501615621351552473337069301082060976805004625011694147890954040864167002308"),
|
||||
field_new!(Fq, "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"),
|
||||
field_new!(Fq, "468238122923807824137727898100575114475823797181717920390930116882062371863914936316755773"),
|
||||
MontFp!(Fq, "7684163245453501615621351552473337069301082060976805004625011694147890954040864167002308"),
|
||||
MontFp!(Fq, "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"),
|
||||
MontFp!(Fq, "468238122923807824137727898100575114475823797181717920390930116882062371863914936316755773"),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,99 +1,7 @@
|
||||
use ark_ff::{
|
||||
biginteger::{BigInt, BigInteger320 as BigInteger},
|
||||
fields::{FftParameters, Fp320, Fp320Parameters, FpParameters},
|
||||
};
|
||||
use ark_ff::fields::{Fp320, MontBackend, MontConfig};
|
||||
|
||||
pub type Fr = Fp320<FrParameters>;
|
||||
|
||||
pub struct FrParameters;
|
||||
|
||||
impl Fp320Parameters for FrParameters {}
|
||||
impl FftParameters for FrParameters {
|
||||
type BigInt = BigInteger;
|
||||
|
||||
const TWO_ADICITY: u32 = 34;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
||||
0x818b361df1af7be4,
|
||||
0x2ae2750d46a53957,
|
||||
0x5784a8fe792c5f8a,
|
||||
0xf9bd39c0cdcf1bb6,
|
||||
0x6a24a0f8a8,
|
||||
]);
|
||||
}
|
||||
impl FpParameters for FrParameters {
|
||||
/// MODULUS = 475922286169261325753349249653048451545124878552823515553267735739164647307408490559963137
|
||||
#[rustfmt::skip]
|
||||
const MODULUS: BigInteger = BigInt::new([
|
||||
0xbb4334a400000001,
|
||||
0xfb494c07925d6ad3,
|
||||
0xcaeec9635cf44194,
|
||||
0xa266249da7b0548e,
|
||||
0x3bcf7bcd473,
|
||||
]);
|
||||
|
||||
const MODULUS_BITS: u32 = 298;
|
||||
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
||||
|
||||
const REPR_SHAVE_BITS: u32 = 22;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const R: BigInteger = BigInt::new([
|
||||
0xc3177aefffbb845c,
|
||||
0x9b80c702f9961788,
|
||||
0xc5df8dcdac70a85a,
|
||||
0x29184098647b5197,
|
||||
0x1c1223d33c3,
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const R2: BigInteger = BigInt::new([
|
||||
0x465a743c68e0596b,
|
||||
0x34f9102adb68371,
|
||||
0x4bbd6dcf1e3a8386,
|
||||
0x2ff00dced8e4b6d,
|
||||
0x149bb44a342,
|
||||
]);
|
||||
|
||||
const INV: u64 = 0xbb4334a3ffffffff;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
||||
0xb1ddfacffd532b94,
|
||||
0x25e295ff76674008,
|
||||
0x8f00647b48958d36,
|
||||
0x1159f37d4e0fddb2,
|
||||
0x2977770b3d1,
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0xdda19a5200000000,
|
||||
0x7da4a603c92eb569,
|
||||
0x657764b1ae7a20ca,
|
||||
0xd133124ed3d82a47,
|
||||
0x1de7bde6a39,
|
||||
]);
|
||||
|
||||
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
|
||||
|
||||
#[rustfmt::skip]
|
||||
const T: BigInteger = BigInt::new([
|
||||
0xe4975ab4eed0cd29,
|
||||
0xd73d10653ed25301,
|
||||
0x69ec1523b2bbb258,
|
||||
0x3def351ce8998927,
|
||||
0xef,
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0xf24bad5a77686694,
|
||||
0x6b9e88329f692980,
|
||||
0xb4f60a91d95dd92c,
|
||||
0x9ef79a8e744cc493,
|
||||
0x77,
|
||||
]);
|
||||
}
|
||||
#[derive(MontConfig)]
|
||||
#[modulus = "475922286169261325753349249653048451545124878552823515553267735739164647307408490559963137"]
|
||||
#[generator = "10"]
|
||||
pub struct FrConfig;
|
||||
pub type Fr = Fp320<MontBackend<FrConfig, 5>>;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
use ark_ff::{Field, One, SquareRootField, UniformRand, Zero};
|
||||
use ark_std::test_rng;
|
||||
|
||||
use crate::*;
|
||||
use ark_algebra_test_templates::{fields::*, generate_field_test};
|
||||
|
||||
use ark_algebra_test_templates::{
|
||||
fields::*, generate_field_serialization_test, generate_field_test,
|
||||
};
|
||||
use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero};
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
||||
use ark_std::{rand::Rng, test_rng};
|
||||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
||||
|
||||
generate_field_test!(mnt4_298; fq2; fq4;);
|
||||
use crate::*;
|
||||
|
||||
generate_field_test!(mnt4_298; fq2; fq4; mont(5, 5); );
|
||||
generate_field_serialization_test!(mnt4_298;);
|
||||
|
||||
@@ -10,14 +10,17 @@
|
||||
|
||||
//! This library implements the MNT4_298 curve generated by
|
||||
//! [\[BCTV14\]](https://eprint.iacr.org/2014/595). The name denotes that it is a
|
||||
//! Miyaji--Nakabayashi--Takano curve of embedding degree 4, defined over a 298-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 MNT6_298.
|
||||
//! Miyaji--Nakabayashi--Takano curve of embedding degree 4, defined over a
|
||||
//! 298-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
|
||||
//! MNT6_298.
|
||||
//!
|
||||
//!
|
||||
//! Curve information:
|
||||
//! * Base field: q = 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758081
|
||||
//! * Scalar field: r = 475922286169261325753349249653048451545124878552823515553267735739164647307408490559963137
|
||||
//! * Base field: q =
|
||||
//! 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758081
|
||||
//! * Scalar field: r =
|
||||
//! 475922286169261325753349249653048451545124878552823515553267735739164647307408490559963137
|
||||
//! * valuation(q - 1, 2) = 17
|
||||
//! * valuation(r - 1, 2) = 34
|
||||
//! * G1 curve equation: y^2 = x^3 + ax + b, where
|
||||
@@ -26,7 +29,8 @@
|
||||
//! * G2 curve equation: y^2 = x^3 + Ax + B, where
|
||||
//! * A = Fq2 = (a * NON_RESIDUE, 0)
|
||||
//! * B = Fq2(0, b * NON_RESIDUE)
|
||||
//! * NON_RESIDUE = 17 is the quadratic non-residue used for constructing the extension field Fq2
|
||||
//! * NON_RESIDUE = 17 is the quadratic non-residue used for constructing the
|
||||
//! extension field Fq2
|
||||
|
||||
#[cfg(feature = "curve")]
|
||||
mod curves;
|
||||
|
||||
Reference in New Issue
Block a user