Co-authored-by: Sun <huachuang20@gmail.com>update-to-latest-arkworks
@ -0,0 +1,28 @@ |
|||||
|
modulus = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177 |
||||
|
|
||||
|
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) |
@ -0,0 +1,28 @@ |
|||||
|
modulus = 8444461749428370424248824938781546531375899335154063827935233455917409239041 |
||||
|
|
||||
|
assert(modulus.is_prime()) |
||||
|
|
||||
|
Fp = GF(modulus) |
||||
|
|
||||
|
generator = Fp(0); |
||||
|
for i in range(0, 30): |
||||
|
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,121 +1,10 @@ |
|||||
use ark_ff::{
|
|
||||
biginteger::{BigInt, BigInteger384 as BigInteger},
|
|
||||
fields::*,
|
|
||||
};
|
|
||||
|
use ark_ff::fields::{Fp384, MontBackend, MontConfig, MontFp};
|
||||
|
|
||||
pub type Fq = Fp384<FqParameters>;
|
|
||||
|
#[derive(MontConfig)]
|
||||
|
#[modulus = "258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177"]
|
||||
|
#[generator = "15"]
|
||||
|
pub struct FqConfig;
|
||||
|
pub type Fq = Fp384<MontBackend<FqConfig, 6>>;
|
||||
|
|
||||
pub struct FqParameters;
|
|
||||
|
|
||||
impl Fp384Parameters for FqParameters {}
|
|
||||
impl FftParameters for FqParameters {
|
|
||||
type BigInt = BigInteger;
|
|
||||
|
|
||||
const TWO_ADICITY: u32 = 46u32;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
|
||||
2022196864061697551u64,
|
|
||||
17419102863309525423u64,
|
|
||||
8564289679875062096u64,
|
|
||||
17152078065055548215u64,
|
|
||||
17966377291017729567u64,
|
|
||||
68610905582439508u64,
|
|
||||
]);
|
|
||||
}
|
|
||||
impl FpParameters for FqParameters {
|
|
||||
/// MODULUS = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS: BigInteger = BigInt::new([
|
|
||||
0x8508c00000000001,
|
|
||||
0x170b5d4430000000,
|
|
||||
0x1ef3622fba094800,
|
|
||||
0x1a22d9f300f5138f,
|
|
||||
0xc63b05c06ca1493b,
|
|
||||
0x1ae3a4617c510ea,
|
|
||||
]);
|
|
||||
|
|
||||
const MODULUS_BITS: u32 = 377;
|
|
||||
|
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
|
||||
|
|
||||
const REPR_SHAVE_BITS: u32 = 7;
|
|
||||
|
|
||||
/// R = 85013442423176922659824578519796707547925331718418265885885478904210582549405549618995257669764901891699128663912
|
|
||||
#[rustfmt::skip]
|
|
||||
const R: BigInteger = BigInt::new([
|
|
||||
202099033278250856u64,
|
|
||||
5854854902718660529u64,
|
|
||||
11492539364873682930u64,
|
|
||||
8885205928937022213u64,
|
|
||||
5545221690922665192u64,
|
|
||||
39800542322357402u64,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R2: BigInteger = BigInt::new([
|
|
||||
0xb786686c9400cd22,
|
|
||||
0x329fcaab00431b1,
|
|
||||
0x22a5f11162d6b46d,
|
|
||||
0xbfdf7d03827dc3ac,
|
|
||||
0x837e92f041790bf9,
|
|
||||
0x6dfccb1e914b88,
|
|
||||
]);
|
|
||||
|
|
||||
const INV: u64 = 9586122913090633727u64;
|
|
||||
|
|
||||
/// GENERATOR = -5
|
|
||||
/// Encoded in Montgomery form, so the value here is
|
|
||||
/// (-5 * R) % q = 92261639910053574722182574790803529333160366917737991650341130812388023949653897454961487930322210790384999596794
|
|
||||
#[rustfmt::skip]
|
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
|
||||
0xfc0b8000000002fa,
|
|
||||
0x97d39cf6e000018b,
|
|
||||
0x2072420fbfa05044,
|
|
||||
0xcbbcbd50d97c3802,
|
|
||||
0xbaf1ec35813f9eb,
|
|
||||
0x9974a2c0945ad2,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0x4284600000000000,
|
|
||||
0xb85aea218000000,
|
|
||||
0x8f79b117dd04a400,
|
|
||||
0x8d116cf9807a89c7,
|
|
||||
0x631d82e03650a49d,
|
|
||||
0xd71d230be28875,
|
|
||||
]);
|
|
||||
|
|
||||
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
|
|
||||
// For T coprime to 2
|
|
||||
|
|
||||
// T = (MODULUS - 1) // 2^S =
|
|
||||
// 3675842578061421676390135839012792950148785745837396071634149488243117337281387659330802195819009059
|
|
||||
#[rustfmt::skip]
|
|
||||
const T: BigInteger = BigInt::new([
|
|
||||
0x7510c00000021423,
|
|
||||
0x88bee82520005c2d,
|
|
||||
0x67cc03d44e3c7bcd,
|
|
||||
0x1701b28524ec688b,
|
|
||||
0xe9185f1443ab18ec,
|
|
||||
0x6b8,
|
|
||||
]);
|
|
||||
|
|
||||
// (T - 1) // 2 =
|
|
||||
// 1837921289030710838195067919506396475074392872918698035817074744121558668640693829665401097909504529
|
|
||||
#[rustfmt::skip]
|
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0xba88600000010a11,
|
|
||||
0xc45f741290002e16,
|
|
||||
0xb3e601ea271e3de6,
|
|
||||
0xb80d94292763445,
|
|
||||
0x748c2f8a21d58c76,
|
|
||||
0x35c,
|
|
||||
]);
|
|
||||
}
|
|
||||
|
|
||||
#[allow(dead_code)]
|
|
||||
pub const FQ_ONE: Fq = Fq::new(FqParameters::R);
|
|
||||
#[allow(dead_code)]
|
|
||||
pub const FQ_ZERO: Fq = Fq::new(BigInt::new([0, 0, 0, 0, 0, 0]));
|
|
||||
|
pub const FQ_ONE: Fq = Fq::new(FqConfig::R);
|
||||
|
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");
|
@ -1,73 +1,73 @@ |
|||||
use super::*;
|
|
||||
use ark_ff::{field_new, fields::*};
|
|
||||
|
use ark_ff::{fields::*, CubicExt, MontFp, QuadExt};
|
||||
|
|
||||
pub type Fq12 = Fp12<Fq12Parameters>;
|
|
||||
|
use crate::*;
|
||||
|
|
||||
|
pub type Fq12 = Fp12<Fq12Config>;
|
||||
|
|
||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||
pub struct Fq12Parameters;
|
|
||||
|
pub struct Fq12Config;
|
||||
|
|
||||
impl Fp12Parameters for Fq12Parameters {
|
|
||||
type Fp6Params = Fq6Parameters;
|
|
||||
|
impl Fp12Config for Fq12Config {
|
||||
|
type Fp6Config = Fq6Config;
|
||||
|
|
||||
const NONRESIDUE: Fq6 = field_new!(Fq6, FQ2_ZERO, FQ2_ONE, FQ2_ZERO);
|
|
||||
|
const NONRESIDUE: Fq6 = CubicExt!(FQ2_ZERO, FQ2_ONE, FQ2_ZERO);
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[
|
const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[
|
||||
// Fp2::NONRESIDUE^(((q^0) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^0) - 1) / 6)
|
||||
field_new!(Fq2, FQ_ONE, FQ_ZERO),
|
|
||||
|
QuadExt!(FQ_ONE, FQ_ZERO),
|
||||
// Fp2::NONRESIDUE^(((q^1) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^1) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "92949345220277864758624960506473182677953048909283248980960104381795901929519566951595905490535835115111760994353"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "92949345220277864758624960506473182677953048909283248980960104381795901929519566951595905490535835115111760994353"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^2) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^2) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^3) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^3) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "216465761340224619389371505802605247630151569547285782856803747159100223055385581585702401816380679166954762214499"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "216465761340224619389371505802605247630151569547285782856803747159100223055385581585702401816380679166954762214499"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^4) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^4) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^5) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^5) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "123516416119946754630746545296132064952198520638002533875843642777304321125866014634106496325844844051843001220146"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "123516416119946754630746545296132064952198520638002533875843642777304321125866014634106496325844844051843001220146"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^6) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^6) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "-1"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "-1"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^7) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^7) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "165715080792691229252027773188420350858440463845631411558924158284924566418821255823372982649037525009328560463824"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "165715080792691229252027773188420350858440463845631411558924158284924566418821255823372982649037525009328560463824"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^8) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^8) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^9) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^9) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "42198664672744474621281227892288285906241943207628877683080515507620245292955241189266486323192680957485559243678"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "42198664672744474621281227892288285906241943207628877683080515507620245292955241189266486323192680957485559243678"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^10) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^10) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^11) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^11) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "135148009893022339379906188398761468584194992116912126664040619889416147222474808140862391813728516072597320238031"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "135148009893022339379906188398761468584194992116912126664040619889416147222474808140862391813728516072597320238031"),
|
||||
FQ_ZERO,
|
FQ_ZERO,
|
||||
),
|
),
|
||||
];
|
];
|
||||
|
@ -0,0 +1,28 @@ |
|||||
|
modulus = 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787 |
||||
|
|
||||
|
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) |
@ -0,0 +1,28 @@ |
|||||
|
modulus = 52435875175126190479447740508185965837690552500527637822603658699938581184513 |
||||
|
|
||||
|
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,115 +1,10 @@ |
|||||
use ark_ff::{
|
|
||||
biginteger::{BigInt, BigInteger384 as BigInteger},
|
|
||||
field_new,
|
|
||||
fields::{FftParameters, Fp384, Fp384Parameters, FpParameters},
|
|
||||
};
|
|
||||
|
use ark_ff::fields::{Fp384, MontBackend, MontConfig, MontFp};
|
||||
|
|
||||
pub type Fq = Fp384<FqParameters>;
|
|
||||
|
#[derive(MontConfig)]
|
||||
|
#[modulus = "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787"]
|
||||
|
#[generator = "2"]
|
||||
|
pub struct FqConfig;
|
||||
|
pub type Fq = Fp384<MontBackend<FqConfig, 6>>;
|
||||
|
|
||||
pub struct FqParameters;
|
|
||||
|
|
||||
impl Fp384Parameters for FqParameters {}
|
|
||||
impl FftParameters for FqParameters {
|
|
||||
type BigInt = BigInteger;
|
|
||||
|
|
||||
const TWO_ADICITY: u32 = 1;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
|
||||
0x43f5fffffffcaaae,
|
|
||||
0x32b7fff2ed47fffd,
|
|
||||
0x7e83a49a2e99d69,
|
|
||||
0xeca8f3318332bb7a,
|
|
||||
0xef148d1ea0f4c069,
|
|
||||
0x40ab3263eff0206,
|
|
||||
]);
|
|
||||
}
|
|
||||
impl FpParameters for FqParameters {
|
|
||||
/// MODULUS = 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS: BigInteger = BigInt::new([
|
|
||||
0xb9feffffffffaaab,
|
|
||||
0x1eabfffeb153ffff,
|
|
||||
0x6730d2a0f6b0f624,
|
|
||||
0x64774b84f38512bf,
|
|
||||
0x4b1ba7b6434bacd7,
|
|
||||
0x1a0111ea397fe69a,
|
|
||||
]);
|
|
||||
|
|
||||
const MODULUS_BITS: u32 = 381;
|
|
||||
|
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
|
||||
|
|
||||
const REPR_SHAVE_BITS: u32 = 3;
|
|
||||
|
|
||||
/// R = 3380320199399472671518931668520476396067793891014375699959770179129436917079669831430077592723774664465579537268733
|
|
||||
#[rustfmt::skip]
|
|
||||
const R: BigInteger = BigInt::new([
|
|
||||
0x760900000002fffd,
|
|
||||
0xebf4000bc40c0002,
|
|
||||
0x5f48985753c758ba,
|
|
||||
0x77ce585370525745,
|
|
||||
0x5c071a97a256ec6d,
|
|
||||
0x15f65ec3fa80e493,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R2: BigInteger = BigInt::new([
|
|
||||
0xf4df1f341c341746,
|
|
||||
0xa76e6a609d104f1,
|
|
||||
0x8de5476c4c95b6d5,
|
|
||||
0x67eb88a9939d83c0,
|
|
||||
0x9a793e85b519952d,
|
|
||||
0x11988fe592cae3aa,
|
|
||||
]);
|
|
||||
|
|
||||
const INV: u64 = 0x89f3fffcfffcfffd;
|
|
||||
|
|
||||
/// GENERATOR = 2
|
|
||||
/// Encoded in Montgomery form, so the value is
|
|
||||
/// 2 * R % q = 2758230843577277949620073511305048635578704962089743514587482222134842183668501798417467556318533664893264801977679
|
|
||||
#[rustfmt::skip]
|
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
|
||||
0x321300000006554f,
|
|
||||
0xb93c0018d6c40005,
|
|
||||
0x57605e0db0ddbb51,
|
|
||||
0x8b256521ed1f9bcb,
|
|
||||
0x6cf28d7901622c03,
|
|
||||
0x11ebab9dbb81e28c,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0xdcff7fffffffd555,
|
|
||||
0xf55ffff58a9ffff,
|
|
||||
0xb39869507b587b12,
|
|
||||
0xb23ba5c279c2895f,
|
|
||||
0x258dd3db21a5d66b,
|
|
||||
0xd0088f51cbff34d,
|
|
||||
]);
|
|
||||
|
|
||||
/// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
|
|
||||
/// For T coprime to 2
|
|
||||
#[rustfmt::skip]
|
|
||||
const T: BigInteger = BigInt::new([
|
|
||||
0xdcff7fffffffd555,
|
|
||||
0xf55ffff58a9ffff,
|
|
||||
0xb39869507b587b12,
|
|
||||
0xb23ba5c279c2895f,
|
|
||||
0x258dd3db21a5d66b,
|
|
||||
0xd0088f51cbff34d,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0xee7fbfffffffeaaa,
|
|
||||
0x7aaffffac54ffff,
|
|
||||
0xd9cc34a83dac3d89,
|
|
||||
0xd91dd2e13ce144af,
|
|
||||
0x92c6e9ed90d2eb35,
|
|
||||
0x680447a8e5ff9a6,
|
|
||||
]);
|
|
||||
}
|
|
||||
|
|
||||
pub const FQ_ONE: Fq = field_new!(Fq, "1");
|
|
||||
pub const FQ_ZERO: Fq = field_new!(Fq, "0");
|
|
||||
|
pub const FQ_ONE: Fq = MontFp!(Fq, "1");
|
||||
|
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");
|
@ -1,76 +1,77 @@ |
|||||
|
use ark_ff::{fields::*, CubicExt, MontFp, QuadExt};
|
||||
|
|
||||
use crate::*;
|
use crate::*;
|
||||
use ark_ff::{field_new, fields::*};
|
|
||||
|
|
||||
pub type Fq12 = Fp12<Fq12Parameters>;
|
|
||||
|
pub type Fq12 = Fp12<Fq12Config>;
|
||||
|
|
||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||
pub struct Fq12Parameters;
|
|
||||
|
pub struct Fq12Config;
|
||||
|
|
||||
impl Fp12Parameters for Fq12Parameters {
|
|
||||
type Fp6Params = Fq6Parameters;
|
|
||||
|
impl Fp12Config for Fq12Config {
|
||||
|
type Fp6Config = Fq6Config;
|
||||
|
|
||||
const NONRESIDUE: Fq6 = field_new!(Fq6, FQ2_ZERO, FQ2_ONE, FQ2_ZERO);
|
|
||||
|
const NONRESIDUE: Fq6 = CubicExt!(FQ2_ZERO, FQ2_ONE, FQ2_ZERO);
|
||||
|
|
||||
const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[
|
const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[
|
||||
// Fp2::NONRESIDUE^(((q^0) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^0) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "1"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "1"),
|
||||
|
MontFp!(Fq, "0"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^1) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^1) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),
|
|
||||
field_new!(Fq, "151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),
|
||||
|
MontFp!(Fq, "151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^2) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^2) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),
|
||||
|
MontFp!(Fq, "0"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^3) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^3) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),
|
|
||||
field_new!(Fq, "1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),
|
||||
|
MontFp!(Fq, "1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^4) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^4) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
|
||||
|
MontFp!(Fq, "0"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^5) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^5) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"),
|
|
||||
field_new!(Fq, "877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"),
|
||||
|
MontFp!(Fq, "877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^6) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^6) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "-1"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "-1"),
|
||||
|
MontFp!(Fq, "0"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^7) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^7) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"),
|
|
||||
field_new!(Fq, "3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"),
|
||||
|
MontFp!(Fq, "3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^8) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^8) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
|
||||
|
MontFp!(Fq, "0"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^9) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^9) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"),
|
|
||||
field_new!(Fq, "2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"),
|
||||
|
MontFp!(Fq, "2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^10) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^10) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),
|
||||
|
MontFp!(Fq, "0"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^11) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^11) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"),
|
|
||||
field_new!(Fq, "3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(Fq, "877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"),
|
||||
|
MontFp!(Fq, "3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"),
|
||||
),
|
),
|
||||
];
|
];
|
||||
}
|
}
|
@ -1,100 +1,7 @@ |
|||||
use ark_ff::{
|
|
||||
biginteger::{BigInt, BigInteger256 as BigInteger},
|
|
||||
fields::{FftParameters, Fp256, Fp256Parameters, FpParameters},
|
|
||||
};
|
|
||||
|
use ark_ff::fields::{Fp256, MontBackend, MontConfig};
|
||||
|
|
||||
pub type Fr = Fp256<FrParameters>;
|
|
||||
|
|
||||
pub struct FrParameters;
|
|
||||
|
|
||||
impl Fp256Parameters for FrParameters {}
|
|
||||
impl FftParameters for FrParameters {
|
|
||||
type BigInt = BigInteger;
|
|
||||
|
|
||||
const TWO_ADICITY: u32 = 32;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
|
||||
0xb9b58d8c5f0e466a,
|
|
||||
0x5b1b4c801819d7ec,
|
|
||||
0xaf53ae352a31e64,
|
|
||||
0x5bf3adda19e9b27b,
|
|
||||
]);
|
|
||||
}
|
|
||||
impl FpParameters for FrParameters {
|
|
||||
/// MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS: BigInteger = BigInt::new([
|
|
||||
0xffffffff00000001,
|
|
||||
0x53bda402fffe5bfe,
|
|
||||
0x3339d80809a1d805,
|
|
||||
0x73eda753299d7d48,
|
|
||||
]);
|
|
||||
|
|
||||
const MODULUS_BITS: u32 = 255;
|
|
||||
|
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
|
||||
|
|
||||
const REPR_SHAVE_BITS: u32 = 1;
|
|
||||
|
|
||||
/// R = 10920338887063814464675503992315976177888879664585288394250266608035967270910
|
|
||||
#[rustfmt::skip]
|
|
||||
const R: BigInteger = BigInt::new([
|
|
||||
0x1fffffffe,
|
|
||||
0x5884b7fa00034802,
|
|
||||
0x998c4fefecbc4ff5,
|
|
||||
0x1824b159acc5056f,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R2: BigInteger = BigInt::new([
|
|
||||
0xc999e990f3f29c6d,
|
|
||||
0x2b6cedcb87925c23,
|
|
||||
0x5d314967254398f,
|
|
||||
0x748d9d99f59ff11,
|
|
||||
]);
|
|
||||
|
|
||||
const INV: u64 = 0xfffffffeffffffff;
|
|
||||
|
|
||||
/// GENERATOR = 7
|
|
||||
/// Encoded in Montgomery form, so the value here is
|
|
||||
/// 7 * R % q = 24006497034320510773280787438025867407531605151569380937148207556313189711857
|
|
||||
#[rustfmt::skip]
|
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
|
||||
0xefffffff1,
|
|
||||
0x17e363d300189c0f,
|
|
||||
0xff9c57876f8457b0,
|
|
||||
0x351332208fc5a8c4,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0x7fffffff80000000,
|
|
||||
0xa9ded2017fff2dff,
|
|
||||
0x199cec0404d0ec02,
|
|
||||
0x39f6d3a994cebea4,
|
|
||||
]);
|
|
||||
|
|
||||
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
|
|
||||
// For T coprime to 2
|
|
||||
|
|
||||
// T = (MODULUS - 1) / 2^S =
|
|
||||
// 12208678567578594777604504606729831043093128246378069236549469339647
|
|
||||
#[rustfmt::skip]
|
|
||||
const T: BigInteger = BigInt::new([
|
|
||||
0xfffe5bfeffffffff,
|
|
||||
0x9a1d80553bda402,
|
|
||||
0x299d7d483339d808,
|
|
||||
0x73eda753,
|
|
||||
]);
|
|
||||
|
|
||||
// (T - 1) / 2 =
|
|
||||
// 6104339283789297388802252303364915521546564123189034618274734669823
|
|
||||
#[rustfmt::skip]
|
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0x7fff2dff7fffffff,
|
|
||||
0x4d0ec02a9ded201,
|
|
||||
0x94cebea4199cec04,
|
|
||||
0x39f6d3a9,
|
|
||||
]);
|
|
||||
}
|
|
||||
|
#[derive(MontConfig)]
|
||||
|
#[modulus = "52435875175126190479447740508185965837690552500527637822603658699938581184513"]
|
||||
|
#[generator = "7"]
|
||||
|
pub struct FrConfig;
|
||||
|
pub type Fr = Fp256<MontBackend<FrConfig, 4>>;
|
@ -0,0 +1,28 @@ |
|||||
|
modulus = 21888242871839275222246405745257275088696311157297823662689037894645226208583 |
||||
|
|
||||
|
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) |
@ -0,0 +1,28 @@ |
|||||
|
modulus = 21888242871839275222246405745257275088548364400416034343698204186575808495617 |
||||
|
|
||||
|
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,18 +1,15 @@ |
|||||
#![allow(unused_imports)]
|
|
||||
use ark_ec::{models::SWModelParameters, AffineCurve, PairingEngine, ProjectiveCurve};
|
|
||||
|
use ark_algebra_test_templates::{
|
||||
|
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
|
||||
|
};
|
||||
|
use ark_ec::{AffineCurve, PairingEngine};
|
||||
use ark_ff::{
|
use ark_ff::{
|
||||
fields::{Field, FpParameters, PrimeField, SquareRootField},
|
|
||||
One, Zero,
|
|
||||
|
fields::{Field, PrimeField},
|
||||
|
One,
|
||||
};
|
};
|
||||
use ark_serialize::CanonicalSerialize;
|
|
||||
use ark_std::{rand::Rng, test_rng};
|
use ark_std::{rand::Rng, test_rng};
|
||||
use core::ops::{AddAssign, MulAssign};
|
|
||||
|
|
||||
use crate::{g1, g2, Bn254, Fq, Fq12, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
|
|
||||
|
use core::ops::MulAssign;
|
||||
|
|
||||
use ark_algebra_test_templates::{
|
|
||||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
|
|
||||
};
|
|
||||
|
use crate::{g1, g2, Bn254, Fq12, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
|
||||
|
|
||||
generate_g1_test!(bn254; curve_tests; sw_tests;);
|
generate_g1_test!(bn254; curve_tests; sw_tests;);
|
||||
generate_g2_test!(bn254; curve_tests; sw_tests;);
|
generate_g2_test!(bn254; curve_tests; sw_tests;);
|
||||
|
@ -1,100 +1,10 @@ |
|||||
use ark_ff::{
|
|
||||
biginteger::{BigInt, BigInteger256 as BigInteger},
|
|
||||
field_new,
|
|
||||
fields::*,
|
|
||||
};
|
|
||||
|
use ark_ff::fields::{Fp256, MontBackend, MontConfig, MontFp};
|
||||
|
|
||||
pub type Fq = Fp256<FqParameters>;
|
|
||||
|
#[derive(MontConfig)]
|
||||
|
#[modulus = "21888242871839275222246405745257275088696311157297823662689037894645226208583"]
|
||||
|
#[generator = "3"]
|
||||
|
pub struct FqConfig;
|
||||
|
pub type Fq = Fp256<MontBackend<FqConfig, 4>>;
|
||||
|
|
||||
pub struct FqParameters;
|
|
||||
|
|
||||
impl Fp256Parameters for FqParameters {}
|
|
||||
impl FftParameters for FqParameters {
|
|
||||
type BigInt = BigInteger;
|
|
||||
|
|
||||
const TWO_ADICITY: u32 = 1;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
|
||||
0x68c3488912edefaa,
|
|
||||
0x8d087f6872aabf4f,
|
|
||||
0x51e1a24709081231,
|
|
||||
0x2259d6b14729c0fa,
|
|
||||
]);
|
|
||||
}
|
|
||||
impl FpParameters for FqParameters {
|
|
||||
/// MODULUS = 21888242871839275222246405745257275088696311157297823662689037894645226208583
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS: BigInteger = BigInt::new([
|
|
||||
0x3c208c16d87cfd47,
|
|
||||
0x97816a916871ca8d,
|
|
||||
0xb85045b68181585d,
|
|
||||
0x30644e72e131a029,
|
|
||||
]);
|
|
||||
|
|
||||
const MODULUS_BITS: u32 = 254;
|
|
||||
|
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
|
||||
|
|
||||
const REPR_SHAVE_BITS: u32 = 2;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R: BigInteger = BigInt::new([
|
|
||||
0xd35d438dc58f0d9d,
|
|
||||
0x0a78eb28f5c70b3d,
|
|
||||
0x666ea36f7879462c,
|
|
||||
0xe0a77c19a07df2f,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R2: BigInteger = BigInt::new([
|
|
||||
0xf32cfc5b538afa89,
|
|
||||
0xb5e71911d44501fb,
|
|
||||
0x47ab1eff0a417ff6,
|
|
||||
0x6d89f71cab8351f,
|
|
||||
]);
|
|
||||
|
|
||||
const INV: u64 = 9786893198990664585u64;
|
|
||||
|
|
||||
// GENERATOR = 3
|
|
||||
#[rustfmt::skip]
|
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
|
||||
0x7a17caa950ad28d7,
|
|
||||
0x1f6ac17ae15521b9,
|
|
||||
0x334bea4e696bd284,
|
|
||||
0x2a1f6744ce179d8e,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0x9e10460b6c3e7ea3,
|
|
||||
0xcbc0b548b438e546,
|
|
||||
0xdc2822db40c0ac2e,
|
|
||||
0x183227397098d014,
|
|
||||
]);
|
|
||||
|
|
||||
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
|
|
||||
|
|
||||
// T = (MODULUS - 1) // 2^S =
|
|
||||
// 10944121435919637611123202872628637544348155578648911831344518947322613104291
|
|
||||
#[rustfmt::skip]
|
|
||||
const T: BigInteger = BigInt::new([
|
|
||||
0x9e10460b6c3e7ea3,
|
|
||||
0xcbc0b548b438e546,
|
|
||||
0xdc2822db40c0ac2e,
|
|
||||
0x183227397098d014,
|
|
||||
]);
|
|
||||
|
|
||||
// (T - 1) // 2 =
|
|
||||
// 5472060717959818805561601436314318772174077789324455915672259473661306552145
|
|
||||
#[rustfmt::skip]
|
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0x4f082305b61f3f51,
|
|
||||
0x65e05aa45a1c72a3,
|
|
||||
0x6e14116da0605617,
|
|
||||
0xc19139cb84c680a,
|
|
||||
]);
|
|
||||
}
|
|
||||
|
|
||||
pub const FQ_ONE: Fq = field_new!(Fq, "1");
|
|
||||
pub const FQ_ZERO: Fq = field_new!(Fq, "0");
|
|
||||
|
pub const FQ_ONE: Fq = MontFp!(Fq, "1");
|
||||
|
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");
|
@ -1,77 +1,119 @@ |
|||||
use super::*;
|
|
||||
use ark_ff::{field_new, fields::*};
|
|
||||
|
use ark_ff::{fields::*, CubicExt, MontFp, QuadExt};
|
||||
|
|
||||
pub type Fq12 = Fp12<Fq12Parameters>;
|
|
||||
|
use crate::*;
|
||||
|
|
||||
|
pub type Fq12 = Fp12<Fq12Config>;
|
||||
|
|
||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||
pub struct Fq12Parameters;
|
|
||||
|
pub struct Fq12Config;
|
||||
|
|
||||
impl Fp12Parameters for Fq12Parameters {
|
|
||||
type Fp6Params = Fq6Parameters;
|
|
||||
|
impl Fp12Config for Fq12Config {
|
||||
|
type Fp6Config = Fq6Config;
|
||||
|
|
||||
const NONRESIDUE: Fq6 = field_new!(Fq6, FQ2_ZERO, FQ2_ONE, FQ2_ZERO);
|
|
||||
|
const NONRESIDUE: Fq6 = CubicExt!(FQ2_ZERO, FQ2_ONE, FQ2_ZERO);
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[
|
const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[
|
||||
// Fp2::NONRESIDUE^(((q^0) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^0) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "1"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
),
|
|
||||
|
QuadExt!(MontFp!(Fq, "1"), MontFp!(Fq, "0"),),
|
||||
// Fp2::NONRESIDUE^(((q^1) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^1) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "8376118865763821496583973867626364092589906065868298776909617916018768340080"),
|
|
||||
field_new!(Fq, "16469823323077808223889137241176536799009286646108169935659301613961712198316"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"8376118865763821496583973867626364092589906065868298776909617916018768340080"
|
||||
|
),
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"16469823323077808223889137241176536799009286646108169935659301613961712198316"
|
||||
|
),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^2) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^2) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556617"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"21888242871839275220042445260109153167277707414472061641714758635765020556617"
|
||||
|
),
|
||||
|
MontFp!(Fq, "0"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^3) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^3) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "11697423496358154304825782922584725312912383441159505038794027105778954184319"),
|
|
||||
field_new!(Fq, "303847389135065887422783454877609941456349188919719272345083954437860409601"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"11697423496358154304825782922584725312912383441159505038794027105778954184319"
|
||||
|
),
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"303847389135065887422783454877609941456349188919719272345083954437860409601"
|
||||
|
),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^4) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^4) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556616"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"21888242871839275220042445260109153167277707414472061641714758635765020556616"
|
||||
|
),
|
||||
|
MontFp!(Fq, "0"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^5) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^5) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "3321304630594332808241809054958361220322477375291206261884409189760185844239"),
|
|
||||
field_new!(Fq, "5722266937896532885780051958958348231143373700109372999374820235121374419868"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"3321304630594332808241809054958361220322477375291206261884409189760185844239"
|
||||
|
),
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"5722266937896532885780051958958348231143373700109372999374820235121374419868"
|
||||
|
),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^6) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^6) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "-1"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
),
|
|
||||
|
QuadExt!(MontFp!(Fq, "-1"), MontFp!(Fq, "0"),),
|
||||
// Fp2::NONRESIDUE^(((q^7) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^7) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "13512124006075453725662431877630910996106405091429524885779419978626457868503"),
|
|
||||
field_new!(Fq, "5418419548761466998357268504080738289687024511189653727029736280683514010267"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"13512124006075453725662431877630910996106405091429524885779419978626457868503"
|
||||
|
),
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"5418419548761466998357268504080738289687024511189653727029736280683514010267"
|
||||
|
),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^8) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^8) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "2203960485148121921418603742825762020974279258880205651966"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"2203960485148121921418603742825762020974279258880205651966"
|
||||
|
),
|
||||
|
MontFp!(Fq, "0"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^9) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^9) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "10190819375481120917420622822672549775783927716138318623895010788866272024264"),
|
|
||||
field_new!(Fq, "21584395482704209334823622290379665147239961968378104390343953940207365798982"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"10190819375481120917420622822672549775783927716138318623895010788866272024264"
|
||||
|
),
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"21584395482704209334823622290379665147239961968378104390343953940207365798982"
|
||||
|
),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^10) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^10) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "2203960485148121921418603742825762020974279258880205651967"),
|
|
||||
field_new!(Fq, "0"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"2203960485148121921418603742825762020974279258880205651967"
|
||||
|
),
|
||||
|
MontFp!(Fq, "0"),
|
||||
),
|
),
|
||||
// Fp2::NONRESIDUE^(((q^11) - 1) / 6)
|
// Fp2::NONRESIDUE^(((q^11) - 1) / 6)
|
||||
field_new!(Fq2,
|
|
||||
field_new!(Fq, "18566938241244942414004596690298913868373833782006617400804628704885040364344"),
|
|
||||
field_new!(Fq, "16165975933942742336466353786298926857552937457188450663314217659523851788715"),
|
|
||||
|
QuadExt!(
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"18566938241244942414004596690298913868373833782006617400804628704885040364344"
|
||||
|
),
|
||||
|
MontFp!(
|
||||
|
Fq,
|
||||
|
"16165975933942742336466353786298926857552937457188450663314217659523851788715"
|
||||
|
),
|
||||
),
|
),
|
||||
];
|
];
|
||||
}
|
}
|
@ -1,103 +1,7 @@ |
|||||
use ark_ff::{
|
|
||||
biginteger::{BigInt, BigInteger256 as BigInteger},
|
|
||||
fields::*,
|
|
||||
};
|
|
||||
|
use ark_ff::fields::{Fp256, MontBackend, MontConfig};
|
||||
|
|
||||
pub type Fr = Fp256<FrParameters>;
|
|
||||
|
|
||||
pub struct FrParameters;
|
|
||||
|
|
||||
impl Fp256Parameters for FrParameters {}
|
|
||||
impl FftParameters for FrParameters {
|
|
||||
type BigInt = BigInteger;
|
|
||||
|
|
||||
const TWO_ADICITY: u32 = 28;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
|
||||
7164790868263648668u64,
|
|
||||
11685701338293206998u64,
|
|
||||
6216421865291908056u64,
|
|
||||
1756667274303109607u64,
|
|
||||
]);
|
|
||||
}
|
|
||||
impl FpParameters for FrParameters {
|
|
||||
/// MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS: BigInteger = BigInt::new([
|
|
||||
4891460686036598785u64,
|
|
||||
2896914383306846353u64,
|
|
||||
13281191951274694749u64,
|
|
||||
3486998266802970665u64,
|
|
||||
]);
|
|
||||
|
|
||||
const MODULUS_BITS: u32 = 254;
|
|
||||
|
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
|
||||
|
|
||||
const REPR_SHAVE_BITS: u32 = 2;
|
|
||||
|
|
||||
/// R = pow(2, 256) % MODULUS
|
|
||||
/// = 6350874878119819312338956282401532410528162663560392320966563075034087161851
|
|
||||
#[rustfmt::skip]
|
|
||||
const R: BigInteger = BigInt::new([
|
|
||||
12436184717236109307u64,
|
|
||||
3962172157175319849u64,
|
|
||||
7381016538464732718u64,
|
|
||||
1011752739694698287u64,
|
|
||||
]);
|
|
||||
|
|
||||
/// R2 = R * R % MODULUS
|
|
||||
/// = 944936681149208446651664254269745548490766851729442924617792859073125903783
|
|
||||
#[rustfmt::skip]
|
|
||||
const R2: BigInteger = BigInt::new([
|
|
||||
1997599621687373223u64,
|
|
||||
6052339484930628067u64,
|
|
||||
10108755138030829701u64,
|
|
||||
150537098327114917u64,
|
|
||||
]);
|
|
||||
|
|
||||
/// INV = (-MODULUS) ^ {-1} % pow(2, 64) = 14042775128853446655
|
|
||||
const INV: u64 = 14042775128853446655u64;
|
|
||||
|
|
||||
/// GENERATOR = 5
|
|
||||
#[rustfmt::skip]
|
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
|
||||
1949230679015292902u64,
|
|
||||
16913946402569752895u64,
|
|
||||
5177146667339417225u64,
|
|
||||
1571765431670520771u64,
|
|
||||
]);
|
|
||||
|
|
||||
/// (MODULUS - 1)/2 =
|
|
||||
/// 10944121435919637611123202872628637544274182200208017171849102093287904247808
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0xa1f0fac9f8000000,
|
|
||||
0x9419f4243cdcb848,
|
|
||||
0xdc2822db40c0ac2e,
|
|
||||
0x183227397098d014,
|
|
||||
]);
|
|
||||
|
|
||||
// T and T_MINUS_ONE_DIV_TWO, where r - 1 = 2^s * t
|
|
||||
|
|
||||
/// T = (MODULUS - 1) / 2^s =
|
|
||||
/// 81540058820840996586704275553141814055101440848469862132140264610111
|
|
||||
#[rustfmt::skip]
|
|
||||
const T: BigInteger = BigInt::new([
|
|
||||
0x9b9709143e1f593f,
|
|
||||
0x181585d2833e8487,
|
|
||||
0x131a029b85045b68,
|
|
||||
0x30644e72e,
|
|
||||
]);
|
|
||||
|
|
||||
/// (T - 1) / 2 =
|
|
||||
/// 40770029410420498293352137776570907027550720424234931066070132305055
|
|
||||
#[rustfmt::skip]
|
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0xcdcb848a1f0fac9f,
|
|
||||
0x0c0ac2e9419f4243,
|
|
||||
0x098d014dc2822db4,
|
|
||||
0x183227397,
|
|
||||
]);
|
|
||||
}
|
|
||||
|
#[derive(MontConfig)]
|
||||
|
#[modulus = "21888242871839275222246405745257275088548364400416034343698204186575808495617"]
|
||||
|
#[generator = "5"]
|
||||
|
pub struct FrConfig;
|
||||
|
pub type Fr = Fp256<MontBackend<FrConfig, 4>>;
|
@ -0,0 +1,28 @@ |
|||||
|
modulus = 6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299 |
||||
|
|
||||
|
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) |
@ -0,0 +1,28 @@ |
|||||
|
modulus = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177 |
||||
|
|
||||
|
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,15 +1,13 @@ |
|||||
|
use ark_algebra_test_templates::{
|
||||
|
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
|
||||
|
};
|
||||
use ark_ec::{AffineCurve, PairingEngine};
|
use ark_ec::{AffineCurve, PairingEngine};
|
||||
use ark_ff::{Field, One, PrimeField};
|
use ark_ff::{Field, One, PrimeField};
|
||||
use ark_std::{rand::Rng, test_rng};
|
use ark_std::{rand::Rng, test_rng};
|
||||
|
use core::ops::MulAssign;
|
||||
|
|
||||
use crate::*;
|
use crate::*;
|
||||
|
|
||||
use ark_algebra_test_templates::{
|
|
||||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
|
|
||||
};
|
|
||||
|
|
||||
use core::ops::MulAssign;
|
|
||||
|
|
||||
generate_g1_test!(bw6_761; curve_tests; sw_tests;);
|
generate_g1_test!(bw6_761; curve_tests; sw_tests;);
|
||||
generate_g2_test!(bw6_761; curve_tests; sw_tests;);
|
generate_g2_test!(bw6_761; curve_tests; sw_tests;);
|
||||
generate_bilinearity_test!(BW6_761, Fq6);
|
generate_bilinearity_test!(BW6_761, Fq6);
|
@ -1,175 +1,10 @@ |
|||||
use ark_ff::{
|
|
||||
biginteger::{BigInt, BigInteger768 as BigInteger},
|
|
||||
field_new,
|
|
||||
fields::{FftParameters, Fp768, Fp768Parameters, FpParameters},
|
|
||||
};
|
|
||||
|
use ark_ff::fields::{Fp768, MontBackend, MontConfig, MontFp};
|
||||
|
|
||||
pub type Fq = Fp768<FqParameters>;
|
|
||||
|
#[derive(MontConfig)]
|
||||
|
#[modulus = "6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299"]
|
||||
|
#[generator = "2"]
|
||||
|
pub struct FqConfig;
|
||||
|
pub type Fq = Fp768<MontBackend<FqConfig, 12>>;
|
||||
|
|
||||
pub struct FqParameters;
|
|
||||
|
|
||||
pub const FQ_ONE: Fq = field_new!(Fq, "1");
|
|
||||
pub const FQ_ZERO: Fq = field_new!(Fq, "0");
|
|
||||
|
|
||||
impl Fp768Parameters for FqParameters {}
|
|
||||
impl FftParameters for FqParameters {
|
|
||||
type BigInt = BigInteger;
|
|
||||
|
|
||||
// The internal representation of this type is six 64-bit unsigned
|
|
||||
// integers in little-endian order. Values are always in
|
|
||||
// Montgomery form; i.e., Scalar(a) = aR mod p, with R=2^768.
|
|
||||
|
|
||||
// (MODULUS - 1) % 2^TWO_ADICITY == 0
|
|
||||
const TWO_ADICITY: u32 = 1;
|
|
||||
|
|
||||
// least_quadratic_nonresidue(MODULUS) in Sage.
|
|
||||
#[rustfmt::skip]
|
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
|
||||
17481284903592032950u64,
|
|
||||
10104133845767975835u64,
|
|
||||
8607375506753517913u64,
|
|
||||
13706168424391191299u64,
|
|
||||
9580010308493592354u64,
|
|
||||
14241333420363995524u64,
|
|
||||
6665632285037357566u64,
|
|
||||
5559902898979457045u64,
|
|
||||
15504799981718861253u64,
|
|
||||
8332096944629367896u64,
|
|
||||
18005297320867222879u64,
|
|
||||
58811391084848524u64,
|
|
||||
]);
|
|
||||
}
|
|
||||
impl FpParameters for FqParameters {
|
|
||||
/// MODULUS = 6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS: BigInteger = BigInt::new([
|
|
||||
0xf49d00000000008b,
|
|
||||
0xe6913e6870000082,
|
|
||||
0x160cf8aeeaf0a437,
|
|
||||
0x98a116c25667a8f8,
|
|
||||
0x71dcd3dc73ebff2e,
|
|
||||
0x8689c8ed12f9fd90,
|
|
||||
0x03cebaff25b42304,
|
|
||||
0x707ba638e584e919,
|
|
||||
0x528275ef8087be41,
|
|
||||
0xb926186a81d14688,
|
|
||||
0xd187c94004faff3e,
|
|
||||
0x122e824fb83ce0a
|
|
||||
]);
|
|
||||
|
|
||||
const MODULUS_BITS: u32 = 761;
|
|
||||
|
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
|
||||
|
|
||||
// gap to 64-bit machine word
|
|
||||
const REPR_SHAVE_BITS: u32 = 7;
|
|
||||
|
|
||||
// 2^768 % MODULUS
|
|
||||
#[rustfmt::skip]
|
|
||||
const R: BigInteger = BigInt::new([
|
|
||||
144959613005956565u64,
|
|
||||
6509995272855063783u64,
|
|
||||
11428286765660613342u64,
|
|
||||
15738672438262922740u64,
|
|
||||
17071399330169272331u64,
|
|
||||
13899911246788437003u64,
|
|
||||
12055474021000362245u64,
|
|
||||
2545351818702954755u64,
|
|
||||
8887388221587179644u64,
|
|
||||
5009280847225881135u64,
|
|
||||
15539704305423854047u64,
|
|
||||
23071597697427581u64,
|
|
||||
]);
|
|
||||
|
|
||||
// R^2
|
|
||||
#[rustfmt::skip]
|
|
||||
const R2: BigInteger = BigInt::new([
|
|
||||
14305184132582319705u64,
|
|
||||
8868935336694416555u64,
|
|
||||
9196887162930508889u64,
|
|
||||
15486798265448570248u64,
|
|
||||
5402985275949444416u64,
|
|
||||
10893197322525159598u64,
|
|
||||
3204916688966998390u64,
|
|
||||
12417238192559061753u64,
|
|
||||
12426306557607898622u64,
|
|
||||
1305582522441154384u64,
|
|
||||
10311846026977660324u64,
|
|
||||
48736111365249031u64,
|
|
||||
]);
|
|
||||
|
|
||||
// (-1/MODULUS) % 2^64
|
|
||||
const INV: u64 = 744663313386281181u64;
|
|
||||
|
|
||||
/// GENERATOR = 2
|
|
||||
// primitive_root(MODULUS)
|
|
||||
#[rustfmt::skip]
|
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
|
||||
289919226011913130u64,
|
|
||||
13019990545710127566u64,
|
|
||||
4409829457611675068u64,
|
|
||||
13030600802816293865u64,
|
|
||||
15696054586628993047u64,
|
|
||||
9353078419867322391u64,
|
|
||||
5664203968291172875u64,
|
|
||||
5090703637405909511u64,
|
|
||||
17774776443174359288u64,
|
|
||||
10018561694451762270u64,
|
|
||||
12632664537138156478u64,
|
|
||||
46143195394855163u64,
|
|
||||
]);
|
|
||||
|
|
||||
// (MODULUS - 1) / 2
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0x7a4e800000000045,
|
|
||||
0xf3489f3438000041,
|
|
||||
0x0b067c577578521b,
|
|
||||
0x4c508b612b33d47c,
|
|
||||
0x38ee69ee39f5ff97,
|
|
||||
0x4344e476897cfec8,
|
|
||||
0x81e75d7f92da1182,
|
|
||||
0xb83dd31c72c2748c,
|
|
||||
0x29413af7c043df20,
|
|
||||
0x5c930c3540e8a344,
|
|
||||
0x68c3e4a0027d7f9f,
|
|
||||
0x9174127dc1e705,
|
|
||||
]);
|
|
||||
|
|
||||
// T =
|
|
||||
// 3445725192157866269698394841137828771239834456268075054756895080104811711121745868043841591644705843820432283876893306725580879560277123879674755849562650799475802549689254425186271815711798397975949850214984556421382456559534149
|
|
||||
// (MODULUS - 1) / 2 ^ TWO_ADICITY
|
|
||||
#[rustfmt::skip]
|
|
||||
const T: BigInteger = BigInt::new([
|
|
||||
0x7a4e800000000045,
|
|
||||
0xf3489f3438000041,
|
|
||||
0x0b067c577578521b,
|
|
||||
0x4c508b612b33d47c,
|
|
||||
0x38ee69ee39f5ff97,
|
|
||||
0x4344e476897cfec8,
|
|
||||
0x81e75d7f92da1182,
|
|
||||
0xb83dd31c72c2748c,
|
|
||||
0x29413af7c043df20,
|
|
||||
0x5c930c3540e8a344,
|
|
||||
0x68c3e4a0027d7f9f,
|
|
||||
0x9174127dc1e705,
|
|
||||
]);
|
|
||||
|
|
||||
// (T - 1)/2 =
|
|
||||
// 1722862596078933134849197420568914385619917228134037527378447540052405855560872934021920795822352921910216141938446653362790439780138561939837377924781325399737901274844627212593135907855899198987974925107492278210691228279767074
|
|
||||
#[rustfmt::skip]
|
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0xbd27400000000022,
|
|
||||
0xf9a44f9a1c000020,
|
|
||||
0x05833e2bbabc290d,
|
|
||||
0xa62845b09599ea3e,
|
|
||||
0x1c7734f71cfaffcb,
|
|
||||
0x21a2723b44be7f64,
|
|
||||
0x40f3aebfc96d08c1,
|
|
||||
0x5c1ee98e39613a46,
|
|
||||
0x14a09d7be021ef90,
|
|
||||
0xae49861aa07451a2,
|
|
||||
0xb461f250013ebfcf,
|
|
||||
0x48ba093ee0f382,
|
|
||||
]);
|
|
||||
}
|
|
||||
|
pub const FQ_ONE: Fq = MontFp!(Fq, "1");
|
||||
|
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");
|
@ -1,27 +1,26 @@ |
|||||
use crate::{Fq, Fq3, Fq3Parameters, FQ_ONE, FQ_ZERO};
|
|
||||
use ark_ff::{
|
use ark_ff::{
|
||||
field_new,
|
|
||||
fields::fp6_2over3::{Fp6, Fp6Parameters},
|
|
||||
|
fields::fp6_2over3::{Fp6, Fp6Config},
|
||||
|
CubicExt, MontFp,
|
||||
};
|
};
|
||||
|
|
||||
pub type Fq6 = Fp6<Fq6Parameters>;
|
|
||||
|
use crate::{Fq, Fq3, Fq3Config, FQ_ONE, FQ_ZERO};
|
||||
|
|
||||
pub struct Fq6Parameters;
|
|
||||
|
pub type Fq6 = Fp6<Fq6Config>;
|
||||
|
|
||||
impl Fp6Parameters for Fq6Parameters {
|
|
||||
type Fp3Params = Fq3Parameters;
|
|
||||
|
pub struct Fq6Config;
|
||||
|
|
||||
|
impl Fp6Config for Fq6Config {
|
||||
|
type Fp3Config = Fq3Config;
|
||||
|
|
||||
/// NONRESIDUE = (0, 1, 0)
|
/// NONRESIDUE = (0, 1, 0)
|
||||
#[rustfmt::skip]
|
|
||||
const NONRESIDUE: Fq3 = field_new!(Fq3, FQ_ZERO, FQ_ONE, FQ_ZERO);
|
|
||||
|
const NONRESIDUE: Fq3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO);
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[
|
const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[
|
||||
field_new!(Fq, "1"),
|
|
||||
field_new!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775649"),
|
|
||||
field_new!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
|
|
||||
field_new!(Fq, "-1"),
|
|
||||
field_new!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"),
|
|
||||
field_new!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292651"),
|
|
||||
|
MontFp!(Fq, "1"),
|
||||
|
MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775649"),
|
||||
|
MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
|
||||
|
MontFp!(Fq, "-1"),
|
||||
|
MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"),
|
||||
|
MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292651"),
|
||||
];
|
];
|
||||
}
|
}
|
@ -1 +1 @@ |
|||||
pub use ark_bls12_377::{Fq as Fr, FqParameters as FrParameters};
|
|
||||
|
pub use ark_bls12_377::{Fq as Fr, FqConfig as FrConfig};
|
@ -1,14 +1,12 @@ |
|||||
|
use ark_algebra_test_templates::{
|
||||
|
fields::*, generate_field_serialization_test, generate_field_test,
|
||||
|
};
|
||||
use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero};
|
use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero};
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
||||
use ark_std::{rand::Rng, test_rng};
|
use ark_std::{rand::Rng, test_rng};
|
||||
|
use core::ops::{AddAssign, MulAssign, SubAssign};
|
||||
|
|
||||
use crate::*;
|
use crate::*;
|
||||
|
|
||||
use ark_algebra_test_templates::{
|
|
||||
fields::*, generate_field_serialization_test, generate_field_test,
|
|
||||
};
|
|
||||
|
|
||||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
|
||||
|
|
||||
generate_field_test!(bw6_761; fq3; fq6;);
|
|
||||
|
generate_field_test!(bw6_761; fq3; fq6; mont(12, 6); );
|
||||
generate_field_serialization_test!(bw6_761;);
|
generate_field_serialization_test!(bw6_761;);
|
@ -0,0 +1,28 @@ |
|||||
|
modulus = 22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825577 |
||||
|
|
||||
|
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) |
@ -0,0 +1,28 @@ |
|||||
|
modulus = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177 |
||||
|
|
||||
|
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,15 +1,13 @@ |
|||||
|
use ark_algebra_test_templates::{
|
||||
|
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
|
||||
|
};
|
||||
use ark_ec::{AffineCurve, PairingEngine};
|
use ark_ec::{AffineCurve, PairingEngine};
|
||||
use ark_ff::{Field, One, PrimeField};
|
use ark_ff::{Field, One, PrimeField};
|
||||
use ark_std::{rand::Rng, test_rng};
|
use ark_std::{rand::Rng, test_rng};
|
||||
|
use core::ops::MulAssign;
|
||||
|
|
||||
use crate::*;
|
use crate::*;
|
||||
|
|
||||
use ark_algebra_test_templates::{
|
|
||||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
|
|
||||
};
|
|
||||
|
|
||||
use core::ops::MulAssign;
|
|
||||
|
|
||||
generate_g1_test!(cp6_782; curve_tests; sw_tests;);
|
generate_g1_test!(cp6_782; curve_tests; sw_tests;);
|
||||
generate_g2_test!(cp6_782; curve_tests; sw_tests;);
|
generate_g2_test!(cp6_782; curve_tests; sw_tests;);
|
||||
generate_bilinearity_test!(CP6_782, Fq6);
|
generate_bilinearity_test!(CP6_782, Fq6);
|
@ -1,169 +1,10 @@ |
|||||
use ark_ff::{
|
|
||||
biginteger::{BigInt, BigInteger832 as BigInteger},
|
|
||||
fields::{FftParameters, Fp832, Fp832Parameters, FpParameters},
|
|
||||
};
|
|
||||
|
use ark_ff::fields::{Fp832, MontBackend, MontConfig, MontFp};
|
||||
|
|
||||
pub type Fq = Fp832<FqParameters>;
|
|
||||
|
#[derive(MontConfig)]
|
||||
|
#[modulus = "22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825577"]
|
||||
|
#[generator = "13"]
|
||||
|
pub struct FqConfig;
|
||||
|
pub type Fq = Fp832<MontBackend<FqConfig, 13>>;
|
||||
|
|
||||
pub struct FqParameters;
|
|
||||
|
|
||||
pub const FQ_ONE: Fq = ark_ff::field_new!(Fq, "1");
|
|
||||
pub const FQ_ZERO: Fq = ark_ff::field_new!(Fq, "0");
|
|
||||
|
|
||||
impl Fp832Parameters for FqParameters {}
|
|
||||
impl FftParameters for FqParameters {
|
|
||||
type BigInt = BigInteger;
|
|
||||
|
|
||||
const TWO_ADICITY: u32 = 3;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
|
||||
18044746167194862600u64,
|
|
||||
63590321303744709u64,
|
|
||||
5009346151370959890u64,
|
|
||||
2859114157767503991u64,
|
|
||||
8301813204852325413u64,
|
|
||||
5629414263664332594u64,
|
|
||||
2637340888701394641u64,
|
|
||||
17433538052687852753u64,
|
|
||||
2230763098934759248u64,
|
|
||||
3785382115983092023u64,
|
|
||||
8895511354022222370u64,
|
|
||||
15792083141709071785u64,
|
|
||||
1328u64,
|
|
||||
]);
|
|
||||
}
|
|
||||
impl FpParameters for FqParameters {
|
|
||||
/// MODULUS = 22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825577
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS: BigInteger = BigInt::new([
|
|
||||
0xdace79b57b942ae9,
|
|
||||
0x545d85c16dfd424a,
|
|
||||
0xee135c065f4d26b7,
|
|
||||
0x9c2f764a12c4024b,
|
|
||||
0x1ad533049cfe6a39,
|
|
||||
0x52a3fb77c79c1320,
|
|
||||
0xab3596c8617c5792,
|
|
||||
0x830c728d80f9d78b,
|
|
||||
0x6a7223ee72023d07,
|
|
||||
0xbc5d176b746af026,
|
|
||||
0xe959283d8f526663,
|
|
||||
0xc4d2263babf8941f,
|
|
||||
0x3848,
|
|
||||
]);
|
|
||||
|
|
||||
const MODULUS_BITS: u32 = 782;
|
|
||||
|
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
|
||||
|
|
||||
const REPR_SHAVE_BITS: u32 = 50;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R: BigInteger = BigInt::new([
|
|
||||
11190988450819017841u64,
|
|
||||
16170411717126802030u64,
|
|
||||
2265463223430229059u64,
|
|
||||
16946880912571045974u64,
|
|
||||
11155248462028513229u64,
|
|
||||
12855672356664541314u64,
|
|
||||
8489376931127408159u64,
|
|
||||
2655797810825538098u64,
|
|
||||
9648483887143916718u64,
|
|
||||
17514963461276738952u64,
|
|
||||
16777089214204267338u64,
|
|
||||
15649035958020076168u64,
|
|
||||
8659u64,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R2: BigInteger = BigInt::new([
|
|
||||
13983406830510863714u64,
|
|
||||
17863856572171232656u64,
|
|
||||
1698388424046564526u64,
|
|
||||
1773634430448388392u64,
|
|
||||
8684647957094413275u64,
|
|
||||
3992637317298078843u64,
|
|
||||
18420879196616862245u64,
|
|
||||
3238482510270583127u64,
|
|
||||
7928200707794018216u64,
|
|
||||
10024831010452223910u64,
|
|
||||
9613847725664942650u64,
|
|
||||
15361265984156787358u64,
|
|
||||
7833u64,
|
|
||||
]);
|
|
||||
|
|
||||
const INV: u64 = 14469047335842394791u64;
|
|
||||
|
|
||||
/// GENERATOR = 13
|
|
||||
#[rustfmt::skip]
|
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
|
||||
16669393626057438558u64,
|
|
||||
1640520694378723217u64,
|
|
||||
1598646156981121135u64,
|
|
||||
12401834967100173388u64,
|
|
||||
2356467520877704673u64,
|
|
||||
14759118825104212161u64,
|
|
||||
5556628239575210651u64,
|
|
||||
5317520392768798654u64,
|
|
||||
16398429955031064995u64,
|
|
||||
3556102264904210145u64,
|
|
||||
8166834915717907988u64,
|
|
||||
11926665585800594452u64,
|
|
||||
11716u64,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0x6d673cdabdca1574,
|
|
||||
0xaa2ec2e0b6fea125,
|
|
||||
0xf709ae032fa6935b,
|
|
||||
0xce17bb2509620125,
|
|
||||
0xd6a99824e7f351c,
|
|
||||
0x2951fdbbe3ce0990,
|
|
||||
0xd59acb6430be2bc9,
|
|
||||
0xc1863946c07cebc5,
|
|
||||
0x353911f739011e83,
|
|
||||
0xde2e8bb5ba357813,
|
|
||||
0xf4ac941ec7a93331,
|
|
||||
0x6269131dd5fc4a0f,
|
|
||||
0x1c24,
|
|
||||
]);
|
|
||||
|
|
||||
// (T - 1)/2 =
|
|
||||
// 1398117143679731058146671387906315933423474966581074036386468539227923378278626533764529938634242576261128410962740119034868607201414583335758422276643816405480145410934911750070786645716409577212967755581539567265673914343284832551598
|
|
||||
#[rustfmt::skip]
|
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0xadace79b57b942ae,
|
|
||||
0x7545d85c16dfd424,
|
|
||||
0xbee135c065f4d26b,
|
|
||||
0x99c2f764a12c4024,
|
|
||||
0x1ad533049cfe6a3,
|
|
||||
0x252a3fb77c79c132,
|
|
||||
0xbab3596c8617c579,
|
|
||||
0x7830c728d80f9d78,
|
|
||||
0x66a7223ee72023d0,
|
|
||||
0x3bc5d176b746af02,
|
|
||||
0xfe959283d8f52666,
|
|
||||
0x8c4d2263babf8941,
|
|
||||
0x384,
|
|
||||
]);
|
|
||||
|
|
||||
// T =
|
|
||||
// 2796234287359462116293342775812631866846949933162148072772937078455846756557253067529059877268485152522256821925480238069737214402829166671516844553287632810960290821869823500141573291432819154425935511163079134531347828686569665103197
|
|
||||
#[rustfmt::skip]
|
|
||||
const T: BigInteger = BigInt::new([
|
|
||||
0x5b59cf36af72855d,
|
|
||||
0xea8bb0b82dbfa849,
|
|
||||
0x7dc26b80cbe9a4d6,
|
|
||||
0x3385eec942588049,
|
|
||||
0x35aa660939fcd47,
|
|
||||
0x4a547f6ef8f38264,
|
|
||||
0x7566b2d90c2f8af2,
|
|
||||
0xf0618e51b01f3af1,
|
|
||||
0xcd4e447dce4047a0,
|
|
||||
0x778ba2ed6e8d5e04,
|
|
||||
0xfd2b2507b1ea4ccc,
|
|
||||
0x189a44c7757f1283,
|
|
||||
0x709,
|
|
||||
]);
|
|
||||
}
|
|
||||
|
pub const FQ_ONE: Fq = MontFp!(Fq, "1");
|
||||
|
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");
|
@ -1,27 +1,26 @@ |
|||||
use crate::{Fq, Fq3, Fq3Parameters, FQ_ONE, FQ_ZERO};
|
|
||||
use ark_ff::{
|
use ark_ff::{
|
||||
field_new,
|
|
||||
fields::fp6_2over3::{Fp6, Fp6Parameters},
|
|
||||
|
fields::fp6_2over3::{Fp6, Fp6Config},
|
||||
|
CubicExt, MontFp,
|
||||
};
|
};
|
||||
|
|
||||
pub type Fq6 = Fp6<Fq6Parameters>;
|
|
||||
|
use crate::{Fq, Fq3, Fq3Config, FQ_ONE, FQ_ZERO};
|
||||
|
|
||||
pub struct Fq6Parameters;
|
|
||||
|
pub type Fq6 = Fp6<Fq6Config>;
|
||||
|
|
||||
impl Fp6Parameters for Fq6Parameters {
|
|
||||
type Fp3Params = Fq3Parameters;
|
|
||||
|
pub struct Fq6Config;
|
||||
|
|
||||
|
impl Fp6Config for Fq6Config {
|
||||
|
type Fp3Config = Fq3Config;
|
||||
|
|
||||
/// NONRESIDUE = (0, 1, 0).
|
/// NONRESIDUE = (0, 1, 0).
|
||||
#[rustfmt::skip]
|
|
||||
const NONRESIDUE: Fq3 = field_new!(Fq3, FQ_ZERO, FQ_ONE, FQ_ZERO);
|
|
||||
|
const NONRESIDUE: Fq3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO);
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[
|
const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[
|
||||
field_new!(Fq, "1"),
|
|
||||
field_new!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756862"),
|
|
||||
field_new!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"),
|
|
||||
field_new!(Fq, "22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825576"),
|
|
||||
field_new!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"),
|
|
||||
field_new!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068716"),
|
|
||||
|
MontFp!(Fq, "1"),
|
||||
|
MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756862"),
|
||||
|
MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"),
|
||||
|
MontFp!(Fq, "22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825576"),
|
||||
|
MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"),
|
||||
|
MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068716"),
|
||||
];
|
];
|
||||
}
|
}
|
@ -1 +1 @@ |
|||||
pub use ark_bls12_377::{Fq as Fr, FqParameters as FrParameters};
|
|
||||
|
pub use ark_bls12_377::{Fq as Fr, FqConfig as FrConfig};
|
@ -1,14 +1,12 @@ |
|||||
|
use ark_algebra_test_templates::{
|
||||
|
fields::*, generate_field_serialization_test, generate_field_test,
|
||||
|
};
|
||||
use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero};
|
use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero};
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
||||
use ark_std::{rand::Rng, test_rng};
|
use ark_std::{rand::Rng, test_rng};
|
||||
|
use core::ops::{AddAssign, MulAssign, SubAssign};
|
||||
|
|
||||
use crate::*;
|
use crate::*;
|
||||
|
|
||||
use ark_algebra_test_templates::{
|
|
||||
fields::*, generate_field_serialization_test, generate_field_test,
|
|
||||
};
|
|
||||
|
|
||||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
|
||||
|
|
||||
generate_field_test!(cp6_782; fq3; fq6;);
|
|
||||
|
generate_field_test!(cp6_782; fq3; fq6; mont(13, 6); );
|
||||
generate_field_serialization_test!(cp6_782;);
|
generate_field_serialization_test!(cp6_782;);
|
@ -0,0 +1,28 @@ |
|||||
|
modulus = 8444461749428370424248824938781546531375899335154063827935233455917409239041 |
||||
|
|
||||
|
assert(modulus.is_prime()) |
||||
|
|
||||
|
Fp = GF(modulus) |
||||
|
|
||||
|
generator = Fp(0); |
||||
|
for i in range(0, 30): |
||||
|
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) |
@ -0,0 +1,28 @@ |
|||||
|
modulus = 2111115437357092606062206234695386632838870926408408195193685246394721360383 |
||||
|
|
||||
|
assert(modulus.is_prime()) |
||||
|
|
||||
|
Fp = GF(modulus) |
||||
|
|
||||
|
generator = Fp(0); |
||||
|
for i in range(0, 30): |
||||
|
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 +1 @@ |
|||||
pub use ark_bls12_377::{Fr as Fq, FrParameters as FqParameters};
|
|
||||
|
pub use ark_bls12_377::{Fr as Fq, FrConfig as FqConfig};
|
@ -1,83 +1,7 @@ |
|||||
use ark_ff::{
|
|
||||
biginteger::{BigInt, BigInteger256 as BigInteger},
|
|
||||
fields::{FftParameters, Fp256, Fp256Parameters, FpParameters},
|
|
||||
};
|
|
||||
|
use ark_ff::fields::{Fp256, MontBackend, MontConfig};
|
||||
|
|
||||
pub type Fr = Fp256<FrParameters>;
|
|
||||
|
|
||||
pub struct FrParameters;
|
|
||||
|
|
||||
impl Fp256Parameters for FrParameters {}
|
|
||||
impl FftParameters for FrParameters {
|
|
||||
type BigInt = BigInteger;
|
|
||||
|
|
||||
const TWO_ADICITY: u32 = 1;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
|
||||
15170730761708361161u64,
|
|
||||
13670723686578117817u64,
|
|
||||
12803492266614043665u64,
|
|
||||
50861023252832611u64,
|
|
||||
]);
|
|
||||
}
|
|
||||
impl FpParameters for FrParameters {
|
|
||||
/// MODULUS = 2111115437357092606062206234695386632838870926408408195193685246394721360383
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS: BigInteger = BigInt::new([
|
|
||||
13356249993388743167u64,
|
|
||||
5950279507993463550u64,
|
|
||||
10965441865914903552u64,
|
|
||||
336320092672043349u64,
|
|
||||
]);
|
|
||||
|
|
||||
const MODULUS_BITS: u32 = 251;
|
|
||||
|
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
|
||||
|
|
||||
const REPR_SHAVE_BITS: u32 = 5;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R: BigInteger = BigInt::new([
|
|
||||
16632263305389933622u64,
|
|
||||
10726299895124897348u64,
|
|
||||
16608693673010411502u64,
|
|
||||
285459069419210737u64,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R2: BigInteger = BigInt::new([
|
|
||||
3987543627614508126u64,
|
|
||||
17742427666091596403u64,
|
|
||||
14557327917022607905u64,
|
|
||||
322810149704226881u64,
|
|
||||
]);
|
|
||||
|
|
||||
const INV: u64 = 9659935179256617473u64;
|
|
||||
|
|
||||
// 70865795004005329077606947863872807680085016823885970091001235374859923341923
|
|
||||
#[rustfmt::skip]
|
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
|
||||
11289572479685143826u64,
|
|
||||
11383637369941080925u64,
|
|
||||
2288212753973340071u64,
|
|
||||
82014976407880291u64,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
6678124996694371583u64,
|
|
||||
2975139753996731775u64,
|
|
||||
14706092969812227584u64,
|
|
||||
168160046336021674u64,
|
|
||||
]);
|
|
||||
|
|
||||
const T: BigInteger = Self::MODULUS_MINUS_ONE_DIV_TWO;
|
|
||||
|
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
0xae56bba6b0cff67f,
|
|
||||
0x14a4e8ebf10f22bf,
|
|
||||
0x660b44d1e5c37b00,
|
|
||||
0x12ab655e9a2ca55,
|
|
||||
]);
|
|
||||
}
|
|
||||
|
#[derive(MontConfig)]
|
||||
|
#[modulus = "2111115437357092606062206234695386632838870926408408195193685246394721360383"]
|
||||
|
#[generator = "5"]
|
||||
|
pub struct FrConfig;
|
||||
|
pub type Fr = Fp256<MontBackend<FrConfig, 4>>;
|
@ -1,24 +1,15 @@ |
|||||
use ark_std::rand::Rng;
|
|
||||
use ark_std::test_rng;
|
|
||||
|
|
||||
use crate::{Fq, Fr};
|
|
||||
|
|
||||
use ark_algebra_test_templates::fields::*;
|
|
||||
|
|
||||
#[test]
|
|
||||
fn test_fr() {
|
|
||||
let mut rng = test_rng();
|
|
||||
let a: Fr = rng.gen();
|
|
||||
let b: Fr = rng.gen();
|
|
||||
field_test(a, b);
|
|
||||
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);
|
|
||||
primefield_test::<Fq>();
|
|
||||
}
|
|
||||
|
use ark_algebra_test_templates::{
|
||||
|
fields::*, generate_field_serialization_test, generate_field_test,
|
||||
|
};
|
||||
|
use ark_ff::{
|
||||
|
fields::{Field, PrimeField, SquareRootField},
|
||||
|
One, UniformRand, Zero,
|
||||
|
};
|
||||
|
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
||||
|
use ark_std::{rand::Rng, test_rng};
|
||||
|
use core::ops::{AddAssign, MulAssign, SubAssign};
|
||||
|
|
||||
|
use crate::{Fq, FqConfig, Fr, FrConfig};
|
||||
|
|
||||
|
generate_field_test!(ed_on_bls12_377; mont(4, 4); );
|
||||
|
generate_field_serialization_test!(ed_on_bls12_377;);
|
@ -0,0 +1,28 @@ |
|||||
|
modulus = 52435875175126190479447740508185965837690552500527637822603658699938581184513 |
||||
|
|
||||
|
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) |
@ -0,0 +1,28 @@ |
|||||
|
modulus = 6554484396890773809930967563523245729705921265872317281365359162392183254199 |
||||
|
|
||||
|
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 +1 @@ |
|||||
pub use ark_bls12_381::{Fr as Fq, FrParameters as FqParameters};
|
|
||||
|
pub use ark_bls12_381::{Fr as Fq, FrConfig as FqConfig};
|
@ -1,81 +1,7 @@ |
|||||
use ark_ff::{
|
|
||||
biginteger::{BigInt, BigInteger256 as BigInteger},
|
|
||||
fields::{FftParameters, Fp256, Fp256Parameters, FpParameters},
|
|
||||
};
|
|
||||
|
use ark_ff::fields::{Fp256, MontBackend, MontConfig};
|
||||
|
|
||||
pub type Fr = Fp256<FrParameters>;
|
|
||||
|
|
||||
pub struct FrParameters;
|
|
||||
|
|
||||
impl Fp256Parameters for FrParameters {}
|
|
||||
impl FftParameters for FrParameters {
|
|
||||
type BigInt = BigInteger;
|
|
||||
|
|
||||
const TWO_ADICITY: u32 = 1;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
|
||||
0xaa9f02ab1d6124de,
|
|
||||
0xb3524a6466112932,
|
|
||||
0x7342261215ac260b,
|
|
||||
0x4d6b87b1da259e2,
|
|
||||
]);
|
|
||||
}
|
|
||||
impl FpParameters for FrParameters {
|
|
||||
/// MODULUS = 6554484396890773809930967563523245729705921265872317281365359162392183254199.
|
|
||||
#[rustfmt::skip]
|
|
||||
const MODULUS: BigInteger = BigInt::new([
|
|
||||
0xd0970e5ed6f72cb7,
|
|
||||
0xa6682093ccc81082,
|
|
||||
0x6673b0101343b00,
|
|
||||
0xe7db4ea6533afa9,
|
|
||||
]);
|
|
||||
|
|
||||
const MODULUS_BITS: u32 = 252;
|
|
||||
|
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
|
||||
|
|
||||
const REPR_SHAVE_BITS: u32 = 4;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R: BigInteger = BigInt::new([
|
|
||||
0x25f80bb3b99607d9,
|
|
||||
0xf315d62f66b6e750,
|
|
||||
0x932514eeeb8814f4,
|
|
||||
0x9a6fc6f479155c6,
|
|
||||
]);
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const R2: BigInteger = BigInt::new([
|
|
||||
0x67719aa495e57731,
|
|
||||
0x51b0cef09ce3fc26,
|
|
||||
0x69dab7fac026e9a5,
|
|
||||
0x4f6547b8d127688,
|
|
||||
]);
|
|
||||
|
|
||||
const INV: u64 = 0x1ba3a358ef788ef9;
|
|
||||
|
|
||||
#[rustfmt::skip]
|
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
|
||||
0x720b1b19d49ea8f1,
|
|
||||
0xbf4aa36101f13a58,
|
|
||||
0x5fa8cc968193ccbb,
|
|
||||
0xe70cbdc7dccf3ac,
|
|
||||
]);
|
|
||||
|
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
7515249040934278747,
|
|
||||
5995434913520945217,
|
|
||||
9454073218019761536,
|
|
||||
522094803716528084,
|
|
||||
]);
|
|
||||
|
|
||||
const T: BigInteger = Self::MODULUS_MINUS_ONE_DIV_TWO;
|
|
||||
|
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
|
||||
12980996557321915181,
|
|
||||
2997717456760472608,
|
|
||||
4727036609009880768,
|
|
||||
261047401858264042,
|
|
||||
]);
|
|
||||
}
|
|
||||
|
#[derive(MontConfig)]
|
||||
|
#[modulus = "6554484396890773809930967563523245729705921265872317281365359162392183254199"]
|
||||
|
#[generator = "6"]
|
||||
|
pub struct FrConfig;
|
||||
|
pub type Fr = Fp256<MontBackend<FrConfig, 4>>;
|
@ -0,0 +1,28 @@ |
|||||
|
modulus = 52435875175126190479447740508185965837690552500527637822603658699938581184513 |
||||
|
|
||||
|
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) |
@ -0,0 +1,28 @@ |
|||||
|
modulus = 13108968793781547619861935127046491459309155893440570251786403306729687672801 |
||||
|
|
||||
|
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) |