mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-27 22:23:48 +01:00
Upgrade to work with latest ark-ff (#95)
Co-authored-by: Sun <huachuang20@gmail.com>
This commit is contained in:
@@ -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;);
|
||||
|
||||
Reference in New Issue
Block a user