-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: feltroidprime <[email protected]>
- Loading branch information
1 parent
2986b7b
commit 933784e
Showing
8 changed files
with
195 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::ecip::{ | ||
curve::{get_irreducible_poly, CurveParamsProvider}, | ||
polynomial::{pad_with_zero_coefficients_to_length, Polynomial}, | ||
}; | ||
use lambdaworks_math::field::traits::IsPrimeField; | ||
|
||
// Returns (Q(X), R(X)) such that Π(Pi)(X) = Q(X) * P_irr(X) + R(X), for a given curve and extension degree. | ||
// R(X) is the result of the multiplication in the extension field. | ||
// Q(X) is used for verification. | ||
pub fn nondeterministic_extension_field_mul_divmod<F: IsPrimeField + CurveParamsProvider<F>>( | ||
ext_degree: usize, | ||
ps: Vec<Polynomial<F>>, | ||
) -> (Polynomial<F>, Polynomial<F>) { | ||
let mut z_poly = Polynomial::one(); | ||
for poly in ps { | ||
z_poly = z_poly.mul_with_ref(&poly); | ||
} | ||
|
||
let p_irr = get_irreducible_poly(ext_degree); | ||
|
||
let (z_polyq, mut z_polyr) = z_poly.divmod(&p_irr); | ||
assert!(z_polyr.coefficients.len() <= ext_degree); | ||
|
||
// Extend polynomial with 0 coefficients to match the expected length. | ||
if z_polyr.coefficients.len() < ext_degree { | ||
pad_with_zero_coefficients_to_length(&mut z_polyr, ext_degree); | ||
} | ||
|
||
(z_polyq, z_polyr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use lambdaworks_math::field::element::FieldElement; | ||
use lambdaworks_math::field::traits::IsPrimeField; | ||
use lambdaworks_math::traits::ByteConversion; | ||
use num_bigint::BigUint; | ||
|
||
pub fn parse_field_elements_from_list<F: IsPrimeField>( | ||
coeffs: &[BigUint], | ||
) -> Result<Vec<FieldElement<F>>, String> | ||
where | ||
FieldElement<F>: ByteConversion, | ||
{ | ||
let length = (F::field_bit_size() + 7) / 8; | ||
coeffs | ||
.iter() | ||
.map(|x| { | ||
let bytes = x.to_bytes_be(); | ||
let pad_length = length.saturating_sub(bytes.len()); | ||
let mut padded_bytes = vec![0u8; pad_length]; | ||
padded_bytes.extend(bytes); | ||
FieldElement::from_bytes_be(&padded_bytes) | ||
.map_err(|e| format!("Byte conversion error: {:?}", e)) | ||
}) | ||
.collect() | ||
} |
Oops, something went wrong.