Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement u256 prime field #137

Merged
merged 22 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bf36c09
fix mul_two_256_bit_integers_works_4() test
GianfrancoBazzani Feb 15, 2023
79e317e
Update element.rs
GianfrancoBazzani Feb 15, 2023
b35aea1
Update element.rs
GianfrancoBazzani Feb 15, 2023
1550ca6
Merge branch 'main' of https://github.com/GianfrancoBazzani/lambdaworks
GianfrancoBazzani Feb 15, 2023
e792ed1
get rid of space
GianfrancoBazzani Feb 15, 2023
1e24f98
Merge branch 'lambdaclass:main' into main
GianfrancoBazzani Feb 16, 2023
5d2ff0b
Merge branch 'main' into Fix-and-complete-UnsignedInteger-test-modules
GianfrancoBazzani Feb 17, 2023
65e378f
Merge branch 'lambdaclass:main' into Fix-and-complete-UnsignedInteger…
GianfrancoBazzani Feb 17, 2023
ad6dd9f
Update element.rs
GianfrancoBazzani Feb 18, 2023
faf896f
Merge branch 'lambdaclass:main' into Fix-and-complete-UnsignedInteger…
GianfrancoBazzani Feb 23, 2023
9c0b77c
Merge pull request #1 from GianfrancoBazzani/Fix-and-complete-Unsigne…
GianfrancoBazzani Feb 23, 2023
49b41a5
Merge branch 'lambdaclass:main' into main
GianfrancoBazzani Feb 26, 2023
81e58dd
Merge branch 'main' of https://github.com/GianfrancoBazzani/lambdaworks
GianfrancoBazzani Feb 26, 2023
9425c61
Generalize IsMontgomeryConfiguration and MontgomeryBackendPrimeField
GianfrancoBazzani Feb 27, 2023
e9c24c5
Extended U256 Montgomery backed prime fields test
GianfrancoBazzani Feb 28, 2023
da59dc8
Implemented U256PrimeField
GianfrancoBazzani Mar 2, 2023
d55679b
Merge branch 'lambdaclass:main' into main
GianfrancoBazzani Mar 2, 2023
1a89e25
Merge branch 'main' into Implement-U256PrimeField
GianfrancoBazzani Mar 2, 2023
7205573
Conflicts fixed
GianfrancoBazzani Mar 2, 2023
d4a8969
fmt
GianfrancoBazzani Mar 2, 2023
b795a20
Get rid of unused commented lines
GianfrancoBazzani Mar 2, 2023
70984d3
Update montgomery_backed_prime_fields.rs
GianfrancoBazzani Mar 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions crypto/src/hash/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,22 @@ where
#[cfg(test)]
mod tests {
use lambdaworks_math::{
field::fields::u384_prime_field::{IsMontgomeryConfiguration, MontgomeryBackendPrimeField},
field::fields::montgomery_backed_prime_fields::{
IsMontgomeryConfiguration, U384PrimeField,
},
unsigned_integer::element::U384,
};

use super::*;

#[derive(Clone, Debug)]
pub struct TestFieldConfig;
impl IsMontgomeryConfiguration for TestFieldConfig {
impl IsMontgomeryConfiguration<6> for TestFieldConfig {
const MODULUS: U384 =
U384::from("2000000000000080000000000000000000000000000000000000000000000001");
}

pub type PoseidonTestField = MontgomeryBackendPrimeField<TestFieldConfig>;
pub type PoseidonTestField = U384PrimeField<TestFieldConfig>;
type TestFieldElement = FieldElement<PoseidonTestField>;

pub fn load_test_parameters() -> Result<Parameters<PoseidonTestField>, String> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::field::{
element::FieldElement,
fields::u384_prime_field::{IsMontgomeryConfiguration, MontgomeryBackendPrimeField},
fields::montgomery_backed_prime_fields::{
IsMontgomeryConfiguration, MontgomeryBackendPrimeField,
},
};
use crate::unsigned_integer::element::U384;

Expand All @@ -9,11 +11,11 @@ pub const BLS12377_PRIME_FIELD_ORDER: U384 = U384::from("1ae3a4617c510eac63b05c0
// FPBLS12377
#[derive(Clone, Debug)]
pub struct BLS12377FieldConfig;
impl IsMontgomeryConfiguration for BLS12377FieldConfig {
impl IsMontgomeryConfiguration<6> for BLS12377FieldConfig {
const MODULUS: U384 = BLS12377_PRIME_FIELD_ORDER;
}

pub type BLS12377PrimeField = MontgomeryBackendPrimeField<BLS12377FieldConfig>;
pub type BLS12377PrimeField = MontgomeryBackendPrimeField<BLS12377FieldConfig, 6>;

impl FieldElement<BLS12377PrimeField> {
pub fn new_base(a_hex: &str) -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use crate::field::{
cubic::{CubicExtensionField, HasCubicNonResidue},
quadratic::{HasQuadraticNonResidue, QuadraticExtensionField},
},
fields::u384_prime_field::{IsMontgomeryConfiguration, MontgomeryBackendPrimeField},
fields::montgomery_backed_prime_fields::{
IsMontgomeryConfiguration, MontgomeryBackendPrimeField,
},
};
use crate::unsigned_integer::element::U384;

Expand All @@ -13,11 +15,11 @@ pub const BLS12381_PRIME_FIELD_ORDER: U384 = U384::from("1a0111ea397fe69a4b1ba7b
// FPBLS12381
#[derive(Clone, Debug)]
pub struct BLS12381FieldConfig;
impl IsMontgomeryConfiguration for BLS12381FieldConfig {
impl IsMontgomeryConfiguration<6> for BLS12381FieldConfig {
const MODULUS: U384 = BLS12381_PRIME_FIELD_ORDER;
}

pub type BLS12381PrimeField = MontgomeryBackendPrimeField<BLS12381FieldConfig>;
pub type BLS12381PrimeField = MontgomeryBackendPrimeField<BLS12381FieldConfig, 6>;

#[derive(Debug, Clone)]
pub struct LevelOneResidue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::elliptic_curve::short_weierstrass::point::ShortWeierstrassProjectivePoint;
use crate::elliptic_curve::traits::IsEllipticCurve;
use crate::field::fields::u384_prime_field::{
use crate::field::fields::montgomery_backed_prime_fields::{
IsMontgomeryConfiguration, MontgomeryBackendPrimeField,
};
use crate::unsigned_integer::element::U384;
Expand All @@ -21,11 +21,11 @@ pub const TEST_CURVE_2_MAIN_SUBGROUP_ORDER: U384 = U384::from("40a065fb5a76390de
// FPBLS12381
#[derive(Clone, Debug)]
pub struct TestCurve2MontgomeryConfig;
impl IsMontgomeryConfiguration for TestCurve2MontgomeryConfig {
impl IsMontgomeryConfiguration<6> for TestCurve2MontgomeryConfig {
const MODULUS: U384 = TEST_CURVE_2_PRIME_FIELD_ORDER;
}

type TestCurve2PrimeField = MontgomeryBackendPrimeField<TestCurve2MontgomeryConfig>;
type TestCurve2PrimeField = MontgomeryBackendPrimeField<TestCurve2MontgomeryConfig, 6>;

/// In F59 the element -1 is not a square. We use this property
/// to construct a Quadratic Field Extension out of it by adding
Expand Down
2 changes: 1 addition & 1 deletion math/src/field/fields/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod u384_prime_field;
pub mod montgomery_backed_prime_fields;
/// Implementation of prime fields over 64 bit unsigned integers.
pub mod u64_prime_field;
Loading