Skip to content

Commit f9ef87e

Browse files
Implement u256 prime field (#137)
* fix mul_two_256_bit_integers_works_4() test Test mul_two_256_bit_integers_works_4() fixed after the bug in the * operator patched * Update element.rs * Update element.rs * get rid of space * Update element.rs * Generalize IsMontgomeryConfiguration and MontgomeryBackendPrimeField Solves #126 * Extended U256 Montgomery backed prime fields test * Implemented U256PrimeField solves #95 * Conflicts fixed * fmt * Get rid of unused commented lines * Update montgomery_backed_prime_fields.rs
1 parent 3c681a3 commit f9ef87e

File tree

8 files changed

+797
-587
lines changed

8 files changed

+797
-587
lines changed

crypto/src/hash/poseidon/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,22 @@ where
147147
#[cfg(test)]
148148
mod tests {
149149
use lambdaworks_math::{
150-
field::fields::u384_prime_field::{IsMontgomeryConfiguration, MontgomeryBackendPrimeField},
150+
field::fields::montgomery_backed_prime_fields::{
151+
IsMontgomeryConfiguration, U384PrimeField,
152+
},
151153
unsigned_integer::element::U384,
152154
};
153155

154156
use super::*;
155157

156158
#[derive(Clone, Debug)]
157159
pub struct TestFieldConfig;
158-
impl IsMontgomeryConfiguration for TestFieldConfig {
160+
impl IsMontgomeryConfiguration<6> for TestFieldConfig {
159161
const MODULUS: U384 =
160162
U384::from("2000000000000080000000000000000000000000000000000000000000000001");
161163
}
162164

163-
pub type PoseidonTestField = MontgomeryBackendPrimeField<TestFieldConfig>;
165+
pub type PoseidonTestField = U384PrimeField<TestFieldConfig>;
164166
type TestFieldElement = FieldElement<PoseidonTestField>;
165167

166168
pub fn load_test_parameters() -> Result<Parameters<PoseidonTestField>, String> {

math/src/elliptic_curve/short_weierstrass/curves/bls12_377/field_extension.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::field::{
22
element::FieldElement,
3-
fields::u384_prime_field::{IsMontgomeryConfiguration, MontgomeryBackendPrimeField},
3+
fields::montgomery_backed_prime_fields::{
4+
IsMontgomeryConfiguration, MontgomeryBackendPrimeField,
5+
},
46
};
57
use crate::unsigned_integer::element::U384;
68

@@ -9,11 +11,11 @@ pub const BLS12377_PRIME_FIELD_ORDER: U384 = U384::from("1ae3a4617c510eac63b05c0
911
// FPBLS12377
1012
#[derive(Clone, Debug)]
1113
pub struct BLS12377FieldConfig;
12-
impl IsMontgomeryConfiguration for BLS12377FieldConfig {
14+
impl IsMontgomeryConfiguration<6> for BLS12377FieldConfig {
1315
const MODULUS: U384 = BLS12377_PRIME_FIELD_ORDER;
1416
}
1517

16-
pub type BLS12377PrimeField = MontgomeryBackendPrimeField<BLS12377FieldConfig>;
18+
pub type BLS12377PrimeField = MontgomeryBackendPrimeField<BLS12377FieldConfig, 6>;
1719

1820
impl FieldElement<BLS12377PrimeField> {
1921
pub fn new_base(a_hex: &str) -> Self {

math/src/elliptic_curve/short_weierstrass/curves/bls12_381/field_extension.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::field::{
44
cubic::{CubicExtensionField, HasCubicNonResidue},
55
quadratic::{HasQuadraticNonResidue, QuadraticExtensionField},
66
},
7-
fields::u384_prime_field::{IsMontgomeryConfiguration, MontgomeryBackendPrimeField},
7+
fields::montgomery_backed_prime_fields::{
8+
IsMontgomeryConfiguration, MontgomeryBackendPrimeField,
9+
},
810
};
911
use crate::unsigned_integer::element::U384;
1012

@@ -13,11 +15,11 @@ pub const BLS12381_PRIME_FIELD_ORDER: U384 = U384::from("1a0111ea397fe69a4b1ba7b
1315
// FPBLS12381
1416
#[derive(Clone, Debug)]
1517
pub struct BLS12381FieldConfig;
16-
impl IsMontgomeryConfiguration for BLS12381FieldConfig {
18+
impl IsMontgomeryConfiguration<6> for BLS12381FieldConfig {
1719
const MODULUS: U384 = BLS12381_PRIME_FIELD_ORDER;
1820
}
1921

20-
pub type BLS12381PrimeField = MontgomeryBackendPrimeField<BLS12381FieldConfig>;
22+
pub type BLS12381PrimeField = MontgomeryBackendPrimeField<BLS12381FieldConfig, 6>;
2123

2224
#[derive(Debug, Clone)]
2325
pub struct LevelOneResidue;

math/src/elliptic_curve/short_weierstrass/curves/test_curve_2.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::elliptic_curve::short_weierstrass::point::ShortWeierstrassProjectivePoint;
22
use crate::elliptic_curve::traits::IsEllipticCurve;
3-
use crate::field::fields::u384_prime_field::{
3+
use crate::field::fields::montgomery_backed_prime_fields::{
44
IsMontgomeryConfiguration, MontgomeryBackendPrimeField,
55
};
66
use crate::unsigned_integer::element::U384;
@@ -21,11 +21,11 @@ pub const TEST_CURVE_2_MAIN_SUBGROUP_ORDER: U384 = U384::from("40a065fb5a76390de
2121
// FPBLS12381
2222
#[derive(Clone, Debug)]
2323
pub struct TestCurve2MontgomeryConfig;
24-
impl IsMontgomeryConfiguration for TestCurve2MontgomeryConfig {
24+
impl IsMontgomeryConfiguration<6> for TestCurve2MontgomeryConfig {
2525
const MODULUS: U384 = TEST_CURVE_2_PRIME_FIELD_ORDER;
2626
}
2727

28-
type TestCurve2PrimeField = MontgomeryBackendPrimeField<TestCurve2MontgomeryConfig>;
28+
type TestCurve2PrimeField = MontgomeryBackendPrimeField<TestCurve2MontgomeryConfig, 6>;
2929

3030
/// In F59 the element -1 is not a square. We use this property
3131
/// to construct a Quadratic Field Extension out of it by adding

math/src/field/fields/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pub mod u384_prime_field;
1+
pub mod montgomery_backed_prime_fields;
22
/// Implementation of prime fields over 64 bit unsigned integers.
33
pub mod u64_prime_field;

0 commit comments

Comments
 (0)