fix: add fix for powmod spcial case k=0

This commit is contained in:
Alivecow 2024-11-21 17:20:29 +01:00
parent b63dc86c7e
commit 81fe06941d

View file

@ -85,13 +85,12 @@ impl Polynomial {
} }
if exponent == 0 { if exponent == 0 {
let inter = Polynomial::new(vec![FieldElement::new( let result = Polynomial::new(vec![FieldElement::new(
polynomial_2_block(vec![0], "gcm").unwrap(), polynomial_2_block(vec![0], "gcm").unwrap(),
)]); )]);
let result = inter.div(&modulus);
eprintln!("Returned value is: {:02X?}", result); eprintln!("Returned value is: {:02X?}", result);
return result.1; return result;
} }
//eprintln!("Initial result: {:?}", result); //eprintln!("Initial result: {:?}", result);
@ -1175,6 +1174,20 @@ mod tests {
); );
} }
#[test]
fn test_field_poly_powmod_k0_special() {
let json1 = json!(["NeverGonnaGiveYouUpAAA=="]);
let json2 = json!(["NeverGonnaGiveYouUpAAA=="]);
let element1: Polynomial = Polynomial::from_c_array(&json1);
let modulus: Polynomial = Polynomial::from_c_array(&json2);
let result = element1.pow_mod(0, modulus);
eprintln!("Result is: {:02X?}", result);
assert_eq!(result.to_c_array(), vec!["gAAAAAAAAAAAAAAAAAAAAA=="]);
}
#[test] #[test]
fn test_field_poly_powmod_kn_eqdeg() { fn test_field_poly_powmod_kn_eqdeg() {
let json1 = json!([ let json1 = json!([