feat: Add ddf algorithm

This commit is contained in:
Alivecow 2024-11-26 13:19:07 +01:00
parent 6856420ff9
commit 341b22e184
5 changed files with 193 additions and 13 deletions

View file

@ -9,8 +9,9 @@ use tasks01::{
gfmul::gfmul_task,
pad_oracle::padding_oracle,
pfmath::{
gfdiv, gfpoly_add, gfpoly_diff, gfpoly_divmod, gfpoly_factor_sff, gfpoly_gcd,
gfpoly_make_monic, gfpoly_mul, gfpoly_pow, gfpoly_powmod, gfpoly_sort, gfpoly_sqrt,
gfdiv, gfpoly_add, gfpoly_diff, gfpoly_divmod, gfpoly_factor_ddf, gfpoly_factor_sff,
gfpoly_gcd, gfpoly_make_monic, gfpoly_mul, gfpoly_pow, gfpoly_powmod, gfpoly_sort,
gfpoly_sqrt,
},
poly2block::poly2block,
sea128::sea128,
@ -163,6 +164,12 @@ pub fn task_deploy(testcase: &Testcase) -> Result<Value> {
Ok(json)
}
"gfpoly_factor_ddf" => {
let result = gfpoly_factor_ddf(args)?;
let json = json!({"factors" : result});
Ok(json)
}
_ => Err(anyhow!(
"Fatal. No compatible action found. Json data was {:?}. Arguments were; {:?}",

View file

@ -1,11 +1,18 @@
use std::usize;
use anyhow::Result;
use base64::{prelude::BASE64_STANDARD, Engine};
use serde_json::Value;
use crate::utils::{
field::FieldElement,
poly::{gcd, Polynomial},
sff::{sff, Factors},
use crate::{
tasks,
utils::{
self,
dff::ddf,
field::FieldElement,
poly::{gcd, Polynomial},
sff::{sff, Factors},
},
};
pub fn gfpoly_add(args: &Value) -> Result<Polynomial> {
@ -135,6 +142,23 @@ pub fn gfpoly_factor_sff(arsg: &Value) -> Result<Vec<(Factors)>> {
Ok(result)
}
pub fn gfpoly_factor_ddf(arsg: &Value) -> Result<Vec<(utils::dff::Factors)>> {
let poly_f = Polynomial::from_c_array(&arsg["F"].clone());
let mut factors = ddf(poly_f);
factors.sort();
let mut result: Vec<utils::dff::Factors> = vec![];
for (factor, degree) in factors {
result.push(utils::dff::Factors {
factor: factor.to_c_array(),
degree: degree as u32,
});
}
Ok(result)
}
#[cfg(test)]
mod tests {
use super::*;