From e1a6ae20a44fe53c6d28b9c1fcca61fc9b9f6978 Mon Sep 17 00:00:00 2001 From: 0xalivecow Date: Sat, 26 Oct 2024 21:43:35 +0200 Subject: [PATCH] feat: set up testing for gfmul task --- .github/workflows/kauma.yaml | 2 +- .gitignore | 1 + Cargo.lock | 4 ++-- src/tasks/mod.rs | 15 +++++++++++++++ src/tasks/tasks01/gfmul.rs | 22 +--------------------- src/test_json/gfmul_test.json | 12 ++++++++++++ src/test_json/kauma_tests.json | 29 ++++++++++++++--------------- 7 files changed, 46 insertions(+), 39 deletions(-) create mode 100644 src/test_json/gfmul_test.json diff --git a/.github/workflows/kauma.yaml b/.github/workflows/kauma.yaml index 73205af..9d1baed 100644 --- a/.github/workflows/kauma.yaml +++ b/.github/workflows/kauma.yaml @@ -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' diff --git a/.gitignore b/.gitignore index 60ffcf3..ffc975e 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Cargo.lock b/Cargo.lock index fa8324c..25c867c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/src/tasks/mod.rs b/src/tasks/mod.rs index d59f199..05d8e85 100644 --- a/src/tasks/mod.rs +++ b/src/tasks/mod.rs @@ -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(()) + } } diff --git a/src/tasks/tasks01/gfmul.rs b/src/tasks/tasks01/gfmul.rs index dac7970..51afa60 100644 --- a/src/tasks/tasks01/gfmul.rs +++ b/src/tasks/tasks01/gfmul.rs @@ -12,34 +12,21 @@ pub const RED_POLY: u128 = 0x87000000_00000000_00000000_00000000; pub fn gfmul(args: &Value) -> Result { 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 { } 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); diff --git a/src/test_json/gfmul_test.json b/src/test_json/gfmul_test.json new file mode 100644 index 0000000..cb156ef --- /dev/null +++ b/src/test_json/gfmul_test.json @@ -0,0 +1,12 @@ +{ + "testcases": { + "b856d760-023d-4b00-bad2-15d2b6da22fe": { + "action": "gfmul", + "arguments": { + "semantic": "xex", + "a": "ARIAAAAAAAAAAAAAAAAAgA==", + "b": "AgAAAAAAAAAAAAAAAAAAAA==" + } + } + } +} diff --git a/src/test_json/kauma_tests.json b/src/test_json/kauma_tests.json index 96df45c..db68d6b 100644 --- a/src/test_json/kauma_tests.json +++ b/src/test_json/kauma_tests.json @@ -29,20 +29,19 @@ } }, "b856d760-023d-4b00-bad2-15d2b6da22fe": { - "action": "sea128", - "arguments": { - "mode": "encrypt", - "key": "istDASeincoolerKEYrofg==", - "input": "yv66vvrO263eyviIiDNEVQ==" - } - }, - "254eaee7-05fd-4e0d-8292-9b658b852245": { - "action": "sea128", - "arguments": { - "mode": "decrypt", - "key": "istDASeincoolerKEYrofg==", - "input": "D5FDo3iVBoBN9gVi9/MSKQ==" - } + "action": "sea128", + "arguments": { + "mode": "encrypt", + "key": "istDASeincoolerKEYrofg==", + "input": "yv66vvrO263eyviIiDNEVQ==" + } + }, + "254eaee7-05fd-4e0d-8292-9b658b852245": { + "action": "sea128", + "arguments": { + "mode": "decrypt", + "key": "istDASeincoolerKEYrofg==", + "input": "D5FDo3iVBoBN9gVi9/MSKQ==" } } - +}