feat: Add task runner for the sff task
This commit is contained in:
parent
1c9948ac62
commit
6856420ff9
6 changed files with 62 additions and 24 deletions
|
|
@ -9,8 +9,8 @@ use tasks01::{
|
||||||
gfmul::gfmul_task,
|
gfmul::gfmul_task,
|
||||||
pad_oracle::padding_oracle,
|
pad_oracle::padding_oracle,
|
||||||
pfmath::{
|
pfmath::{
|
||||||
gfdiv, gfpoly_add, gfpoly_diff, gfpoly_divmod, gfpoly_gcd, gfpoly_make_monic, gfpoly_mul,
|
gfdiv, gfpoly_add, gfpoly_diff, gfpoly_divmod, gfpoly_factor_sff, gfpoly_gcd,
|
||||||
gfpoly_pow, gfpoly_powmod, gfpoly_sort, gfpoly_sqrt,
|
gfpoly_make_monic, gfpoly_mul, gfpoly_pow, gfpoly_powmod, gfpoly_sort, gfpoly_sqrt,
|
||||||
},
|
},
|
||||||
poly2block::poly2block,
|
poly2block::poly2block,
|
||||||
sea128::sea128,
|
sea128::sea128,
|
||||||
|
|
@ -157,6 +157,12 @@ pub fn task_deploy(testcase: &Testcase) -> Result<Value> {
|
||||||
|
|
||||||
Ok(json)
|
Ok(json)
|
||||||
}
|
}
|
||||||
|
"gfpoly_factor_sff" => {
|
||||||
|
let result = gfpoly_factor_sff(args)?;
|
||||||
|
let json = json!({"factors" : result});
|
||||||
|
|
||||||
|
Ok(json)
|
||||||
|
}
|
||||||
|
|
||||||
_ => Err(anyhow!(
|
_ => Err(anyhow!(
|
||||||
"Fatal. No compatible action found. Json data was {:?}. Arguments were; {:?}",
|
"Fatal. No compatible action found. Json data was {:?}. Arguments were; {:?}",
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use serde_json::Value;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
field::FieldElement,
|
field::FieldElement,
|
||||||
poly::{gcd, Polynomial},
|
poly::{gcd, Polynomial},
|
||||||
|
sff::{sff, Factors},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn gfpoly_add(args: &Value) -> Result<Polynomial> {
|
pub fn gfpoly_add(args: &Value) -> Result<Polynomial> {
|
||||||
|
|
@ -117,6 +118,23 @@ pub fn gfpoly_gcd(args: &Value) -> Result<Polynomial> {
|
||||||
Ok(result)
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -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 {}
|
||||||
|
}
|
||||||
|
|
@ -22,6 +22,10 @@ impl Polynomial {
|
||||||
Self { polynomial }
|
Self { polynomial }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn degree(&self) -> usize {
|
||||||
|
self.polynomial.len()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_c_array(array: &Value) -> Self {
|
pub fn from_c_array(array: &Value) -> Self {
|
||||||
let mut polynomial: Vec<FieldElement> = vec![];
|
let mut polynomial: Vec<FieldElement> = vec![];
|
||||||
let c_array: Vec<String> = array
|
let c_array: Vec<String> = array
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ use crate::utils::{
|
||||||
use super::poly::Polynomial;
|
use super::poly::Polynomial;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct Factors {
|
pub struct Factors {
|
||||||
factor: Vec<String>,
|
pub factor: Vec<String>,
|
||||||
exponent: u32,
|
pub exponent: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sff(mut f: Polynomial) -> Vec<(Polynomial, u32)> {
|
pub fn sff(mut f: Polynomial) -> Vec<(Polynomial, u32)> {
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,26 @@
|
||||||
{
|
{
|
||||||
"testcases": {
|
"testcases": {
|
||||||
"sandbox": {
|
"sandbox": {
|
||||||
"action": "gfpoly_gcd",
|
"action": "gfpoly_factor_sff",
|
||||||
"arguments": {
|
"arguments": {
|
||||||
"A": [
|
"F": [
|
||||||
"DNWpXnnY24XecPa7a8vrEA==",
|
"vL77UwAAAAAAAAAAAAAAAA==",
|
||||||
"I8uYpCbsiPaVvUznuv1IcA==",
|
"mEHchYAAAAAAAAAAAAAAAA==",
|
||||||
"wsbiU432ARWuO93He3vbvA==",
|
"9WJa0MAAAAAAAAAAAAAAAA==",
|
||||||
"zp0g3o8iNz7Y+8oUxw1vJw==",
|
"akHfwWAAAAAAAAAAAAAAAA==",
|
||||||
"J0GekE3uendpN6WUAuJ4AA==",
|
"E12o/QAAAAAAAAAAAAAAAA==",
|
||||||
"wACd0e6u1ii4AAAAAAAAAA==",
|
"vKJ/FgAAAAAAAAAAAAAAAA==",
|
||||||
"ACAAAAAAAAAAAAAAAAAAAA=="
|
"yctWwAAAAAAAAAAAAAAAAA==",
|
||||||
],
|
"c1BXYAAAAAAAAAAAAAAAAA==",
|
||||||
"B": [
|
"o0AtAAAAAAAAAAAAAAAAAA==",
|
||||||
"I20VjJmlSnRSe88gaDiLRQ==",
|
"AbP2AAAAAAAAAAAAAAAAAA==",
|
||||||
"0Cw5HxJm/pfybJoQDf7/4w==",
|
"k2YAAAAAAAAAAAAAAAAAAA==",
|
||||||
"8ByrMMf+vVj5r3YXUNCJ1g==",
|
"vBYAAAAAAAAAAAAAAAAAAA==",
|
||||||
"rEU/f2UZRXqmZ6V7EPKfBA==",
|
"dSAAAAAAAAAAAAAAAAAAAA==",
|
||||||
"LfdALhvCrdhhGZWl9l9DSg==",
|
"69gAAAAAAAAAAAAAAAAAAA==",
|
||||||
"KSUKhN0n6/DZmHPozd1prw==",
|
"VkAAAAAAAAAAAAAAAAAAAA==",
|
||||||
"DQrRkuA9Zx279wAAAAAAAA==",
|
"a4AAAAAAAAAAAAAAAAAAAA==",
|
||||||
"AhCEAAAAAAAAAAAAAAAAAA=="
|
"gAAAAAAAAAAAAAAAAAAAAA=="
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue