mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-08 23:11:29 +01:00
BigInt fixes corresponding to algebra#372
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use ark_ff::{biginteger::BigInteger384 as BigInteger, fields::*};
|
||||
use ark_ff::{
|
||||
biginteger::{BigInt, BigInteger384 as BigInteger},
|
||||
fields::*,
|
||||
};
|
||||
|
||||
pub type Fq = Fp384<FqParameters>;
|
||||
|
||||
@@ -11,7 +14,7 @@ impl FftParameters for FqParameters {
|
||||
const TWO_ADICITY: u32 = 46u32;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
||||
2022196864061697551u64,
|
||||
17419102863309525423u64,
|
||||
8564289679875062096u64,
|
||||
@@ -23,7 +26,7 @@ impl FftParameters for FqParameters {
|
||||
impl FpParameters for FqParameters {
|
||||
/// MODULUS = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
|
||||
#[rustfmt::skip]
|
||||
const MODULUS: BigInteger = BigInteger([
|
||||
const MODULUS: BigInteger = BigInt::new([
|
||||
0x8508c00000000001,
|
||||
0x170b5d4430000000,
|
||||
0x1ef3622fba094800,
|
||||
@@ -40,7 +43,7 @@ impl FpParameters for FqParameters {
|
||||
|
||||
/// R = 85013442423176922659824578519796707547925331718418265885885478904210582549405549618995257669764901891699128663912
|
||||
#[rustfmt::skip]
|
||||
const R: BigInteger = BigInteger([
|
||||
const R: BigInteger = BigInt::new([
|
||||
202099033278250856u64,
|
||||
5854854902718660529u64,
|
||||
11492539364873682930u64,
|
||||
@@ -50,7 +53,7 @@ impl FpParameters for FqParameters {
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const R2: BigInteger = BigInteger([
|
||||
const R2: BigInteger = BigInt::new([
|
||||
0xb786686c9400cd22,
|
||||
0x329fcaab00431b1,
|
||||
0x22a5f11162d6b46d,
|
||||
@@ -65,7 +68,7 @@ impl FpParameters for FqParameters {
|
||||
/// Encoded in Montgomery form, so the value here is
|
||||
/// (-5 * R) % q = 92261639910053574722182574790803529333160366917737991650341130812388023949653897454961487930322210790384999596794
|
||||
#[rustfmt::skip]
|
||||
const GENERATOR: BigInteger = BigInteger([
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
||||
0xfc0b8000000002fa,
|
||||
0x97d39cf6e000018b,
|
||||
0x2072420fbfa05044,
|
||||
@@ -75,7 +78,7 @@ impl FpParameters for FqParameters {
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0x4284600000000000,
|
||||
0xb85aea218000000,
|
||||
0x8f79b117dd04a400,
|
||||
@@ -90,7 +93,7 @@ impl FpParameters for FqParameters {
|
||||
// T = (MODULUS - 1) // 2^S =
|
||||
// 3675842578061421676390135839012792950148785745837396071634149488243117337281387659330802195819009059
|
||||
#[rustfmt::skip]
|
||||
const T: BigInteger = BigInteger([
|
||||
const T: BigInteger = BigInt::new([
|
||||
0x7510c00000021423,
|
||||
0x88bee82520005c2d,
|
||||
0x67cc03d44e3c7bcd,
|
||||
@@ -102,7 +105,7 @@ impl FpParameters for FqParameters {
|
||||
// (T - 1) // 2 =
|
||||
// 1837921289030710838195067919506396475074392872918698035817074744121558668640693829665401097909504529
|
||||
#[rustfmt::skip]
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0xba88600000010a11,
|
||||
0xc45f741290002e16,
|
||||
0xb3e601ea271e3de6,
|
||||
@@ -115,4 +118,4 @@ impl FpParameters for FqParameters {
|
||||
#[allow(dead_code)]
|
||||
pub const FQ_ONE: Fq = Fq::new(FqParameters::R);
|
||||
#[allow(dead_code)]
|
||||
pub const FQ_ZERO: Fq = Fq::new(BigInteger([0, 0, 0, 0, 0, 0]));
|
||||
pub const FQ_ZERO: Fq = Fq::new(BigInt::new([0, 0, 0, 0, 0, 0]));
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
/// print("Gen: ", into_chunks(g * R % q, 64, 4))
|
||||
/// print("2-adic gen: ", into_chunks(g2 * R % q, 64, 4))
|
||||
/// ```
|
||||
use ark_ff::{biginteger::BigInteger256 as BigInteger, fields::*};
|
||||
|
||||
use ark_ff::{
|
||||
biginteger::{BigInt, BigInteger256 as BigInteger},
|
||||
fields::*,
|
||||
};
|
||||
pub type Fr = Fp256<FrParameters>;
|
||||
|
||||
pub struct FrParameters;
|
||||
@@ -32,7 +34,7 @@ impl FftParameters for FrParameters {
|
||||
const TWO_ADICITY: u32 = 47;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
||||
12646347781564978760u64,
|
||||
6783048705277173164u64,
|
||||
268534165941069093u64,
|
||||
@@ -42,7 +44,7 @@ impl FftParameters for FrParameters {
|
||||
impl FpParameters for FrParameters {
|
||||
/// MODULUS = 8444461749428370424248824938781546531375899335154063827935233455917409239041
|
||||
#[rustfmt::skip]
|
||||
const MODULUS: BigInteger = BigInteger([
|
||||
const MODULUS: BigInteger = BigInt::new([
|
||||
725501752471715841u64,
|
||||
6461107452199829505u64,
|
||||
6968279316240510977u64,
|
||||
@@ -57,7 +59,7 @@ impl FpParameters for FrParameters {
|
||||
|
||||
/// R = 6014086494747379908336260804527802945383293308637734276299549080986809532403
|
||||
#[rustfmt::skip]
|
||||
const R: BigInteger = BigInteger([
|
||||
const R: BigInteger = BigInt::new([
|
||||
9015221291577245683u64,
|
||||
8239323489949974514u64,
|
||||
1646089257421115374u64,
|
||||
@@ -65,7 +67,7 @@ impl FpParameters for FrParameters {
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const R2: BigInteger = BigInteger([
|
||||
const R2: BigInteger = BigInt::new([
|
||||
2726216793283724667u64,
|
||||
14712177743343147295u64,
|
||||
12091039717619697043u64,
|
||||
@@ -79,7 +81,7 @@ impl FpParameters for FrParameters {
|
||||
/// (22 * R) % q =
|
||||
/// 5642976643016801619665363617888466827793962762719196659561577942948671127251
|
||||
#[rustfmt::skip]
|
||||
const GENERATOR: BigInteger = BigInteger([
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
||||
2984901390528151251u64,
|
||||
10561528701063790279u64,
|
||||
5476750214495080041u64,
|
||||
@@ -89,7 +91,7 @@ impl FpParameters for FrParameters {
|
||||
/// (r - 1)/2 =
|
||||
/// 4222230874714185212124412469390773265687949667577031913967616727958704619520
|
||||
#[rustfmt::skip]
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0x8508c00000000000,
|
||||
0xacd53b7f68000000,
|
||||
0x305a268f2e1bd800,
|
||||
@@ -102,7 +104,7 @@ impl FpParameters for FrParameters {
|
||||
/// t = (r - 1) / 2^s =
|
||||
/// 60001509534603559531609739528203892656505753216962260608619555
|
||||
#[rustfmt::skip]
|
||||
const T: BigInteger = BigInteger([
|
||||
const T: BigInteger = BigInt::new([
|
||||
0xedfda00000021423,
|
||||
0x9a3cb86f6002b354,
|
||||
0xcabd34594aacc168,
|
||||
@@ -112,7 +114,7 @@ impl FpParameters for FrParameters {
|
||||
/// (t - 1) / 2 =
|
||||
/// 30000754767301779765804869764101946328252876608481130304309777
|
||||
#[rustfmt::skip]
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0x76fed00000010a11,
|
||||
0x4d1e5c37b00159aa,
|
||||
0x655e9a2ca55660b4,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use ark_ff::{
|
||||
biginteger::{BigInteger, BigInteger384},
|
||||
biginteger::{BigInt, BigInteger, BigInteger384},
|
||||
fields::{
|
||||
fp6_3over2::Fp6Parameters, FftField, FftParameters, Field, Fp2Parameters, FpParameters,
|
||||
PrimeField, SquareRootField,
|
||||
@@ -24,10 +24,7 @@ generate_field_serialization_test!(bls12_377; fq2; fq6; fq12;);
|
||||
|
||||
#[test]
|
||||
fn test_fq_repr_from() {
|
||||
assert_eq!(
|
||||
BigInteger384::from(100),
|
||||
BigInteger384([100, 0, 0, 0, 0, 0])
|
||||
);
|
||||
assert_eq!(BigInt::from(100u64), BigInt::new([100, 0, 0, 0, 0, 0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -44,9 +41,9 @@ fn test_fq_repr_is_odd() {
|
||||
|
||||
#[test]
|
||||
fn test_fq_repr_is_zero() {
|
||||
assert!(BigInteger384::from(0).is_zero());
|
||||
assert!(!BigInteger384::from(1).is_zero());
|
||||
assert!(!BigInteger384([0, 0, 0, 0, 1, 0]).is_zero());
|
||||
assert!(BigInteger384::from(0u64).is_zero());
|
||||
assert!(!BigInteger384::from(1u64).is_zero());
|
||||
assert!(!BigInt::new([0, 0, 0, 0, 1, 0]).is_zero());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user