feat: set up testing for gfmul task
This commit is contained in:
parent
6ef05f6018
commit
e1a6ae20a4
7 changed files with 46 additions and 39 deletions
|
|
@ -119,4 +119,19 @@ mod tests {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_task_gfmul_full() -> Result<()> {
|
||||
let json = fs::read_to_string("src/test_json/gfmul_test.json").unwrap();
|
||||
let parsed = parse_json(json).unwrap();
|
||||
|
||||
let expected = json!({ "responses": { "b856d760-023d-4b00-bad2-15d2b6da22fe": {"product": "hSQAAAAAAAAAAAAAAAAAAA=="}}});
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_value(task_distrubute(&parsed)?).unwrap(),
|
||||
serde_json::to_value(expected).unwrap()
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,34 +12,21 @@ pub const RED_POLY: u128 = 0x87000000_00000000_00000000_00000000;
|
|||
|
||||
pub fn gfmul(args: &Value) -> Result<String> {
|
||||
eprintln!("{args}");
|
||||
// Generate reduction polynomial
|
||||
|
||||
let mut red_poly_bytes: ByteArray = ByteArray(RED_POLY.to_be_bytes().to_vec());
|
||||
eprintln!("Before push {:01X?}", red_poly_bytes);
|
||||
red_poly_bytes.0.push(0x01);
|
||||
//red_poly_bytes.0.reverse();
|
||||
eprintln!("After push {:01X?}", red_poly_bytes);
|
||||
//let red_poly_num = ; //coefficient_to_binary(reduction_polynomial_coeffs);
|
||||
//eprintln!("{:?}", serde_json::from_value(args["a"].clone())?);
|
||||
|
||||
let poly1_text: String = serde_json::from_value(args["a"].clone())?;
|
||||
let mut poly1: ByteArray = ByteArray(BASE64_STANDARD.decode(poly1_text)?);
|
||||
poly1.0.push(0x00);
|
||||
//poly1.0.reverse();
|
||||
|
||||
let poly2_text: String = serde_json::from_value(args["b"].clone())?;
|
||||
let mut poly2: ByteArray = ByteArray(BASE64_STANDARD.decode(poly2_text)?);
|
||||
poly2.0.push(0x00);
|
||||
//poly2.0.reverse();
|
||||
|
||||
eprintln!("poly1 is: {:01X?}", poly1);
|
||||
eprintln!("poly2 is: {:01X?}", poly2);
|
||||
|
||||
/* Begin of magic algorithm
|
||||
* poly1 = a = X = V ???
|
||||
* poly2 = b
|
||||
* result = Z
|
||||
*/
|
||||
|
||||
let mut result: ByteArray = ByteArray(vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
|
||||
if poly2.LSB_is_one() {
|
||||
|
|
@ -75,14 +62,7 @@ pub fn gfmul(args: &Value) -> Result<String> {
|
|||
}
|
||||
poly2.right_shift();
|
||||
}
|
||||
//result.xor_byte_arrays(&red_poly_bytes);
|
||||
//result.xor_byte_arrays(&red_poly_bytes);
|
||||
eprintln!("Result after last red {:01X?}", &result.0);
|
||||
|
||||
eprintln!(
|
||||
"Should be: {:01X?}",
|
||||
ByteArray(BASE64_STANDARD.decode("hSQAAAAAAAAAAAAAAAAAAA==")?)
|
||||
);
|
||||
result.0.remove(16);
|
||||
let mut bytes: [u8; 16] = [0u8; 16];
|
||||
bytes.copy_from_slice(&result.0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue