Merge pull request #15 from 0xalivecow/dev

fix: Add further handling to leading zero blocks in add and powmod
This commit is contained in:
An0nymous 2024-11-16 15:01:18 +01:00 committed by GitHub
commit c5d3db27f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -81,7 +81,7 @@ impl Polynomial {
if exponent == 0 {
Polynomial::new(vec![FieldElement::new(
polynomial_2_block(vec![1], "gcm").unwrap(),
polynomial_2_block(vec![0], "gcm").unwrap(),
)])
.div(&modulus)
.1;
@ -102,6 +102,23 @@ impl Polynomial {
//eprintln!("After mod: {:?}", self);
exponent >>= 1;
}
while !result.polynomial.is_empty()
&& result
.polynomial
.last()
.unwrap()
.as_ref()
.iter()
.all(|&x| x == 0)
{
result.polynomial.pop();
}
if result.is_empty() {
result = Polynomial::new(vec![FieldElement::new(vec![0; 16])]);
}
result
}
@ -246,10 +263,13 @@ impl Add for Polynomial {
}
}
for i in (0..polynomial.len() - 1).rev() {
if polynomial[i].is_zero() {
while !polynomial.is_empty() && polynomial.last().unwrap().as_ref().iter().all(|&x| x == 0)
{
polynomial.pop();
}
if polynomial.is_empty() {
return Polynomial::new(vec![FieldElement::new(vec![0; 16])]);
}
Polynomial::new(polynomial)