Dev merge gfmul and XEX tasks #3
7 changed files with 46 additions and 39 deletions
2
.github/workflows/kauma.yaml
vendored
2
.github/workflows/kauma.yaml
vendored
|
|
@ -66,4 +66,4 @@ jobs:
|
|||
docker tag ghcr.io/johndoe31415/labwork-docker:master labwork
|
||||
- name: Run labwork container
|
||||
run: |
|
||||
docker run -v $PWD:/dut/ labwork /bin/bash -c '/dut/build && /dut/kauma ./test_json/kauma_tests.json'
|
||||
docker run -v $PWD:/dut/ labwork /bin/bash -c '/dut/build && /dut/kauma ./src/test_json/kauma_tests.json'
|
||||
|
|
|
|||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,6 +2,7 @@
|
|||
# will have compiled files and executables
|
||||
# debug/
|
||||
target/
|
||||
vendor/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
|
|
|
|||
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -4,9 +4,9 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.90"
|
||||
version = "1.0.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95"
|
||||
checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
12
src/test_json/gfmul_test.json
Normal file
12
src/test_json/gfmul_test.json
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"testcases": {
|
||||
"b856d760-023d-4b00-bad2-15d2b6da22fe": {
|
||||
"action": "gfmul",
|
||||
"arguments": {
|
||||
"semantic": "xex",
|
||||
"a": "ARIAAAAAAAAAAAAAAAAAgA==",
|
||||
"b": "AgAAAAAAAAAAAAAAAAAAAA=="
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -44,5 +44,4 @@
|
|||
"input": "D5FDo3iVBoBN9gVi9/MSKQ=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue