feat: finialise test runner and add testing json
This commit is contained in:
parent
deb4261121
commit
68d9f13a3d
4 changed files with 213 additions and 11 deletions
|
|
@ -11,7 +11,7 @@ use tasks01::{
|
|||
gcm::{gcm_decrypt, gcm_encrypt},
|
||||
gfmul::gfmul_task,
|
||||
pad_oracle::padding_oracle,
|
||||
pfmath::gfpoly_add,
|
||||
pfmath::{gfdiv, gfpoly_add, gfpoly_divmod, gfpoly_mul, gfpoly_pow, gfpoly_powmod},
|
||||
poly2block::poly2block,
|
||||
sea128::sea128,
|
||||
xex::{self, fde_xex},
|
||||
|
|
@ -86,10 +86,42 @@ pub fn task_deploy(testcase: &Testcase) -> Result<Value> {
|
|||
}
|
||||
"gfpoly_add" => {
|
||||
let result = gfpoly_add(args)?;
|
||||
let json = json!({"plaintext" : result.to_c_array()});
|
||||
let json = json!({"S" : result.to_c_array()});
|
||||
|
||||
Ok(json)
|
||||
}
|
||||
"gfpoly_mul" => {
|
||||
let result = gfpoly_mul(args)?;
|
||||
let json = json!({"P" : result.to_c_array()});
|
||||
|
||||
Ok(json)
|
||||
}
|
||||
"gfpoly_pow" => {
|
||||
let result = gfpoly_pow(args)?;
|
||||
let json = json!({"Z" : result.to_c_array()});
|
||||
|
||||
Ok(json)
|
||||
}
|
||||
"gfdiv" => {
|
||||
let result = gfdiv(args)?;
|
||||
let out = BASE64_STANDARD.encode(result);
|
||||
let json = json!({"q" : out});
|
||||
|
||||
Ok(json)
|
||||
}
|
||||
"gfpoly_divmod" => {
|
||||
let result = gfpoly_divmod(args)?;
|
||||
let json = json!({"Q" : result.0.to_c_array(), "R" : result.1.to_c_array()});
|
||||
|
||||
Ok(json)
|
||||
}
|
||||
"gfpoly_powmod" => {
|
||||
let result = gfpoly_powmod(args)?;
|
||||
let json = json!({"Z" : result.to_c_array()});
|
||||
|
||||
Ok(json)
|
||||
}
|
||||
|
||||
_ => Err(anyhow!(
|
||||
"Fatal. No compatible action found. Json data was {:?}. Arguments were; {:?}",
|
||||
testcase,
|
||||
|
|
@ -279,4 +311,22 @@ mod tests {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_task_gcm_gfpoly_add() -> Result<()> {
|
||||
let json = fs::read_to_string("test_json/gcm_decrypt_sea.json").unwrap();
|
||||
let parsed = parse_json(json).unwrap();
|
||||
|
||||
let expected = json!({ "responses" : { "b856d760-023d-4b00-bad2-15d2b6da22fe" : {
|
||||
"plaintext": "RGFzIGlzdCBlaW4gVGVzdA==",
|
||||
"authentic": true,
|
||||
}}});
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_value(task_distrubute(&parsed)?).unwrap(),
|
||||
serde_json::to_value(expected).unwrap()
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use anyhow::Result;
|
|||
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::utils::field::Polynomial;
|
||||
use crate::utils::field::{FieldElement, Polynomial};
|
||||
|
||||
pub fn gfpoly_add(args: &Value) -> Result<Polynomial> {
|
||||
let poly_a = Polynomial::from_c_array(&args["A"].clone());
|
||||
|
|
@ -13,3 +13,57 @@ pub fn gfpoly_add(args: &Value) -> Result<Polynomial> {
|
|||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn gfpoly_mul(args: &Value) -> Result<Polynomial> {
|
||||
let poly_a = Polynomial::from_c_array(&args["A"].clone());
|
||||
|
||||
let poly_b = Polynomial::from_c_array(&args["B"].clone());
|
||||
|
||||
let result = poly_a * poly_b;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn gfpoly_pow(args: &Value) -> Result<Polynomial> {
|
||||
let poly_a = Polynomial::from_c_array(&args["A"].clone());
|
||||
|
||||
let k: u128 = serde_json::from_value(args["k"].clone())?;
|
||||
|
||||
let result = poly_a.pow(k);
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn gfdiv(args: &Value) -> Result<FieldElement> {
|
||||
let f1_text: String = serde_json::from_value(args["a"].clone())?;
|
||||
let f_a = FieldElement::new(BASE64_STANDARD.decode(f1_text)?);
|
||||
|
||||
let f2_text: String = serde_json::from_value(args["b"].clone())?;
|
||||
let f_b = FieldElement::new(BASE64_STANDARD.decode(f2_text)?);
|
||||
|
||||
let result = f_a / f_b;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn gfpoly_divmod(args: &Value) -> Result<(Polynomial, Polynomial)> {
|
||||
let poly_a = Polynomial::from_c_array(&args["A"].clone());
|
||||
|
||||
let poly_b = Polynomial::from_c_array(&args["B"].clone());
|
||||
|
||||
let result = poly_a.div(&poly_b);
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn gfpoly_powmod(args: &Value) -> Result<Polynomial> {
|
||||
let poly_a = Polynomial::from_c_array(&args["A"].clone());
|
||||
|
||||
let poly_m = Polynomial::from_c_array(&args["M"].clone());
|
||||
|
||||
let k: u128 = serde_json::from_value(args["k"].clone())?;
|
||||
|
||||
let result = poly_a.pow_mod(k, poly_m);
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue