feat: Add task runner for the sff task

This commit is contained in:
Alivecow 2024-11-25 14:19:41 +01:00
parent 1c9948ac62
commit 6856420ff9
6 changed files with 62 additions and 24 deletions

View file

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

View file

@ -5,6 +5,7 @@ use serde_json::Value;
use crate::utils::{
field::FieldElement,
poly::{gcd, Polynomial},
sff::{sff, Factors},
};
pub fn gfpoly_add(args: &Value) -> Result<Polynomial> {
@ -117,6 +118,23 @@ pub fn gfpoly_gcd(args: &Value) -> Result<Polynomial> {
Ok(result)
}
pub fn gfpoly_factor_sff(arsg: &Value) -> Result<Vec<(Factors)>> {
let poly_f = Polynomial::from_c_array(&arsg["F"].clone());
let mut factors = sff(poly_f);
factors.sort();
let mut result: Vec<Factors> = vec![];
for (factor, exponent) in factors {
result.push(Factors {
factor: factor.to_c_array(),
exponent,
});
}
Ok(result)
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -0,0 +1,10 @@
use super::poly::Polynomial;
pub fn dff(f: Polynomial) {
let q = 2u128.pow(128);
let z: Vec<(Polynomial, u32)> = vec![];
let d = 1;
let f_start = f.clone();
while f_start.degree() >= 2 * d {}
}

View file

@ -22,6 +22,10 @@ impl Polynomial {
Self { polynomial }
}
pub fn degree(&self) -> usize {
self.polynomial.len()
}
pub fn from_c_array(array: &Value) -> Self {
let mut polynomial: Vec<FieldElement> = vec![];
let c_array: Vec<String> = array

View file

@ -8,9 +8,9 @@ use crate::utils::{
use super::poly::Polynomial;
#[derive(Debug, Serialize, Deserialize)]
struct Factors {
factor: Vec<String>,
exponent: u32,
pub struct Factors {
pub factor: Vec<String>,
pub exponent: u32,
}
pub fn sff(mut f: Polynomial) -> Vec<(Polynomial, u32)> {