Skip to content

Commit c478b19

Browse files
committed
Add feature 32x9, to conditionaly compile the 2 impls
1 parent f1ac246 commit c478b19

File tree

3 files changed

+182
-91
lines changed

3 files changed

+182
-91
lines changed

curves/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ ark-ff = { version = "0.3.0", features = ["parallel", "asm"] }
1717
rand = { version = "0.8.0", default-features = false }
1818
ark-algebra-test-templates = "0.3.0"
1919
ark-std = "0.3.0"
20+
21+
[features]
22+
32x9 = []

curves/src/pasta/fields/fp.rs

Lines changed: 90 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use ark_ff::{biginteger::BigInteger256 as BigInteger, FftParameters, Fp256Parameters, NewFp256};
1+
use ark_ff::{biginteger::BigInteger256 as BigInteger, FftParameters, Fp256Parameters, Fp256};
22

3-
pub type Fp = NewFp256<FpParameters>;
3+
pub type Fp = Fp256<FpParameters>;
44

55
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, PartialOrd, Ord, Hash)]
66
pub struct FpParameters;
@@ -19,49 +19,93 @@ impl FftParameters for FpParameters {
1919
};
2020
}
2121

22-
#[rustfmt::skip]
23-
impl ark_ff::FpParameters for FpParameters {
24-
// 28948022309329048855892746252171976963363056481941560715954676764349967630337
25-
const MODULUS: BigInteger = BigInteger([
26-
0x1, 0x9698768, 0x133e46e6, 0xd31f812, 0x224, 0x0, 0x0, 0x0, 0x400000,
27-
]);
28-
29-
const R: BigInteger = BigInteger([
30-
0x1fffff81, 0x14a5d367, 0x141ad3c0, 0x1435eec5, 0x1ffeefef, 0x1fffffff, 0x1fffffff,
31-
0x1fffffff, 0x3fffff,
32-
]);
33-
34-
const R2: BigInteger = BigInteger([
35-
0x3b6a, 0x19c10910, 0x1a6a0188, 0x12a4fd88, 0x634b36d, 0x178792ba, 0x7797a99, 0x1dce5b8a,
36-
0x3506bd,
37-
]);
38-
39-
// TODO
40-
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
41-
0x0, 0x4b4c3b4, 0x99f2373, 0x698fc09, 0x112, 0x0, 0x0, 0x0, 0x200000,
42-
]);
43-
44-
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
45-
const T: BigInteger = BigInteger([
46-
0x192d30ed, 0xa67c8dc, 0x11a63f02, 0x44, 0x0, 0x0, 0x0, 0x80000, 0x0,
47-
]);
48-
49-
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
50-
0xc969876, 0x533e46e, 0x8d31f81, 0x22, 0x0, 0x0, 0x0, 0x40000, 0x0,
51-
]);
52-
53-
// GENERATOR = 5
54-
const GENERATOR: BigInteger = {
55-
const FIVE: Fp = ark_ff::field_new!(Fp, "5");
56-
FIVE.0
57-
};
58-
59-
const MODULUS_BITS: u32 = 255;
60-
61-
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
62-
63-
const REPR_SHAVE_BITS: u32 = 1;
22+
#[cfg(not(any(target_family = "wasm", feature = "32x9")))]
23+
pub mod native {
24+
use super::*;
25+
26+
impl ark_ff::FpParameters for FpParameters {
27+
// 28948022309329048855892746252171976963363056481941560715954676764349967630337
28+
const MODULUS: BigInteger = BigInteger::new([
29+
0x992d30ed00000001,
30+
0x224698fc094cf91b,
31+
0x0,
32+
0x4000000000000000,
33+
]);
34+
const R: BigInteger = BigInteger::new([
35+
0x34786d38fffffffd,
36+
0x992c350be41914ad,
37+
0xffffffffffffffff,
38+
0x3fffffffffffffff,
39+
]);
40+
const R2: BigInteger = BigInteger::new([
41+
0x8c78ecb30000000f,
42+
0xd7d30dbd8b0de0e7,
43+
0x7797a99bc3c95d18,
44+
0x96d41af7b9cb714,
45+
]);
46+
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
47+
0xcc96987680000000,
48+
0x11234c7e04a67c8d,
49+
0x0,
50+
0x2000000000000000,
51+
]);
52+
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
53+
const T: BigInteger = BigInteger::new([0x94cf91b992d30ed, 0x224698fc, 0x0, 0x40000000]);
54+
const T_MINUS_ONE_DIV_TWO: BigInteger =
55+
BigInteger::new([0x4a67c8dcc969876, 0x11234c7e, 0x0, 0x20000000]);
56+
// GENERATOR = 5
57+
const GENERATOR: BigInteger = BigInteger::new([
58+
0xa1a55e68ffffffed,
59+
0x74c2a54b4f4982f3,
60+
0xfffffffffffffffd,
61+
0x3fffffffffffffff,
62+
]);
63+
const MODULUS_BITS: u32 = 255;
64+
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
65+
const REPR_SHAVE_BITS: u32 = 1;
66+
// -(MODULUS^{-1} mod 2^64) mod 2^64
67+
const INV: u64 = 11037532056220336127;
68+
}
69+
}
6470

65-
// -(MODULUS^{-1} mod 2^64) mod 2^64
66-
const INV: u64 = 0x1fffffff;
71+
#[cfg(any(target_family = "wasm", feature = "32x9"))]
72+
pub mod x32x9 {
73+
use super::*;
74+
75+
#[rustfmt::skip]
76+
impl ark_ff::FpParameters for FpParameters {
77+
// 28948022309329048855892746252171976963363056481941560715954676764349967630337
78+
const MODULUS: BigInteger = BigInteger::new([
79+
0x1, 0x9698768, 0x133e46e6, 0xd31f812, 0x224, 0x0, 0x0, 0x0, 0x400000,
80+
]);
81+
const R: BigInteger = BigInteger::new([
82+
0x1fffff81, 0x14a5d367, 0x141ad3c0, 0x1435eec5, 0x1ffeefef, 0x1fffffff, 0x1fffffff,
83+
0x1fffffff, 0x3fffff,
84+
]);
85+
const R2: BigInteger = BigInteger::new([
86+
0x3b6a, 0x19c10910, 0x1a6a0188, 0x12a4fd88, 0x634b36d, 0x178792ba, 0x7797a99, 0x1dce5b8a,
87+
0x3506bd,
88+
]);
89+
// TODO
90+
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
91+
0x0, 0x4b4c3b4, 0x99f2373, 0x698fc09, 0x112, 0x0, 0x0, 0x0, 0x200000,
92+
]);
93+
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
94+
const T: BigInteger = BigInteger::new([
95+
0x192d30ed, 0xa67c8dc, 0x11a63f02, 0x44, 0x0, 0x0, 0x0, 0x80000, 0x0,
96+
]);
97+
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
98+
0xc969876, 0x533e46e, 0x8d31f81, 0x22, 0x0, 0x0, 0x0, 0x40000, 0x0,
99+
]);
100+
// GENERATOR = 5
101+
const GENERATOR: BigInteger = {
102+
const FIVE: Fp = ark_ff::field_new!(Fp, "5");
103+
FIVE.0
104+
};
105+
const MODULUS_BITS: u32 = 255;
106+
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
107+
const REPR_SHAVE_BITS: u32 = 1;
108+
// -(MODULUS^{-1} mod 2^64) mod 2^64
109+
const INV: u64 = 0x1fffffff;
110+
}
67111
}

curves/src/pasta/fields/fq.rs

Lines changed: 89 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use ark_ff::{biginteger::BigInteger256 as BigInteger, FftParameters, Fp256Parameters, NewFp256};
1+
use ark_ff::{biginteger::BigInteger256 as BigInteger, FftParameters, Fp256Parameters, Fp256};
22

3-
pub type Fq = NewFp256<FqParameters>;
3+
pub type Fq = Fp256<FqParameters>;
44

55

66
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, PartialOrd, Ord, Hash)]
@@ -20,48 +20,92 @@ impl FftParameters for FqParameters {
2020
};
2121
}
2222

23-
#[rustfmt::skip]
24-
impl ark_ff::FpParameters for FqParameters {
25-
// 28948022309329048855892746252171976963363056481941560715954676764349967630337
26-
const MODULUS: BigInteger = BigInteger([
27-
0x1, 0x2375908, 0x52a3763, 0xd31f813, 0x224, 0x0, 0x0, 0x0, 0x400000,
28-
]);
29-
30-
const R: BigInteger = BigInteger([
31-
0x1fffff81, 0x68ad507, 0x100e85da, 0x1435ee7e, 0x1ffeefef, 0x1fffffff, 0x1fffffff,
32-
0x1fffffff, 0x3fffff,
33-
]);
34-
35-
const R2: BigInteger = BigInteger([
36-
0x3b6a, 0x2b1b550, 0x1027888a, 0x1ea4ed96, 0x418ad7a, 0x999eb, 0x17fae231,
37-
0x1e67ed54, 0x3506bd,
38-
]);
39-
40-
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
41-
0x0, 0x111bac84, 0x12951bb1, 0x698fc09, 0x112, 0x0, 0x0, 0x0, 0x200000,
42-
]);
43-
44-
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
45-
const T: BigInteger = BigInteger([
46-
0xc46eb21, 0xca546ec, 0x11a63f02, 0x44, 0x0, 0x0, 0x0, 0x80000, 0x0,
47-
]);
48-
49-
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
50-
0x6237590, 0x652a376, 0x8d31f81, 0x22, 0x0, 0x0, 0x0, 0x40000, 0x0,
51-
]);
52-
53-
// GENERATOR = 5
54-
const GENERATOR: BigInteger = {
55-
const FIVE: Fq = ark_ff::field_new!(Fq, "5");
56-
FIVE.0
57-
};
58-
59-
const MODULUS_BITS: u32 = 255;
60-
61-
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
62-
63-
const REPR_SHAVE_BITS: u32 = 1;
23+
#[cfg(not(any(target_family = "wasm", feature = "32x9")))]
24+
pub mod native {
25+
use super::*;
26+
27+
impl ark_ff::FpParameters for FqParameters {
28+
// 28948022309329048855892746252171976963363056481941647379679742748393362948097
29+
const MODULUS: BigInteger = BigInteger::new([
30+
0x8c46eb2100000001,
31+
0x224698fc0994a8dd,
32+
0x0,
33+
0x4000000000000000,
34+
]);
35+
const R: BigInteger = BigInteger::new([
36+
0x5b2b3e9cfffffffd,
37+
0x992c350be3420567,
38+
0xffffffffffffffff,
39+
0x3fffffffffffffff,
40+
]);
41+
const R2: BigInteger = BigInteger::new([
42+
0xfc9678ff0000000f,
43+
0x67bb433d891a16e3,
44+
0x7fae231004ccf590,
45+
0x96d41af7ccfdaa9,
46+
]);
47+
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
48+
0xc623759080000000,
49+
0x11234c7e04ca546e,
50+
0x0,
51+
0x2000000000000000,
52+
]);
53+
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
54+
const T: BigInteger = BigInteger::new([0x994a8dd8c46eb21, 0x224698fc, 0x0, 0x40000000]);
55+
const T_MINUS_ONE_DIV_TWO: BigInteger =
56+
BigInteger::new([0x4ca546ec6237590, 0x11234c7e, 0x0, 0x20000000]);
57+
// GENERATOR = 5
58+
const GENERATOR: BigInteger = BigInteger::new([
59+
0x96bc8c8cffffffed,
60+
0x74c2a54b49f7778e,
61+
0xfffffffffffffffd,
62+
0x3fffffffffffffff,
63+
]);
64+
const MODULUS_BITS: u32 = 255;
65+
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
66+
const REPR_SHAVE_BITS: u32 = 1;
67+
// -(MODULUS^{-1} mod 2^64) mod 2^64
68+
const INV: u64 = 10108024940646105087;
69+
}
70+
}
6471

65-
// -(MODULUS^{-1} mod 2^64) mod 2^64
66-
const INV: u64 = 0x1fffffff;
72+
#[cfg(any(target_family = "wasm", feature = "32x9"))]
73+
pub mod x32x9 {
74+
use super::*;
75+
76+
#[rustfmt::skip]
77+
impl ark_ff::FpParameters for FqParameters {
78+
// 28948022309329048855892746252171976963363056481941560715954676764349967630337
79+
const MODULUS: BigInteger = BigInteger::new([
80+
0x1, 0x2375908, 0x52a3763, 0xd31f813, 0x224, 0x0, 0x0, 0x0, 0x400000,
81+
]);
82+
const R: BigInteger = BigInteger::new([
83+
0x1fffff81, 0x68ad507, 0x100e85da, 0x1435ee7e, 0x1ffeefef, 0x1fffffff, 0x1fffffff,
84+
0x1fffffff, 0x3fffff,
85+
]);
86+
const R2: BigInteger = BigInteger::new([
87+
0x3b6a, 0x2b1b550, 0x1027888a, 0x1ea4ed96, 0x418ad7a, 0x999eb, 0x17fae231,
88+
0x1e67ed54, 0x3506bd,
89+
]);
90+
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
91+
0x0, 0x111bac84, 0x12951bb1, 0x698fc09, 0x112, 0x0, 0x0, 0x0, 0x200000,
92+
]);
93+
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
94+
const T: BigInteger = BigInteger::new([
95+
0xc46eb21, 0xca546ec, 0x11a63f02, 0x44, 0x0, 0x0, 0x0, 0x80000, 0x0,
96+
]);
97+
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
98+
0x6237590, 0x652a376, 0x8d31f81, 0x22, 0x0, 0x0, 0x0, 0x40000, 0x0,
99+
]);
100+
// GENERATOR = 5
101+
const GENERATOR: BigInteger = {
102+
const FIVE: Fq = ark_ff::field_new!(Fq, "5");
103+
FIVE.0
104+
};
105+
const MODULUS_BITS: u32 = 255;
106+
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
107+
const REPR_SHAVE_BITS: u32 = 1;
108+
// -(MODULUS^{-1} mod 2^64) mod 2^64
109+
const INV: u64 = 0x1fffffff;
110+
}
67111
}

0 commit comments

Comments
 (0)