Dev merge gfmul and XEX tasks #3
4 changed files with 23 additions and 43 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -6,7 +6,7 @@ vendor/
|
||||||
|
|
||||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
# 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
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
# Cargo.lock
|
Cargo.lock
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ use crate::utils::{
|
||||||
pub const RED_POLY: u128 = 0x87000000_00000000_00000000_00000000;
|
pub const RED_POLY: u128 = 0x87000000_00000000_00000000_00000000;
|
||||||
|
|
||||||
pub fn gfmul(args: &Value) -> Result<String> {
|
pub fn gfmul(args: &Value) -> Result<String> {
|
||||||
eprintln!("{args}");
|
|
||||||
|
|
||||||
let mut red_poly_bytes: ByteArray = ByteArray(RED_POLY.to_be_bytes().to_vec());
|
let mut red_poly_bytes: ByteArray = ByteArray(RED_POLY.to_be_bytes().to_vec());
|
||||||
red_poly_bytes.0.push(0x01);
|
red_poly_bytes.0.push(0x01);
|
||||||
|
|
||||||
|
|
@ -24,9 +22,6 @@ pub fn gfmul(args: &Value) -> Result<String> {
|
||||||
let mut poly2: ByteArray = ByteArray(BASE64_STANDARD.decode(poly2_text)?);
|
let mut poly2: ByteArray = ByteArray(BASE64_STANDARD.decode(poly2_text)?);
|
||||||
poly2.0.push(0x00);
|
poly2.0.push(0x00);
|
||||||
|
|
||||||
eprintln!("poly1 is: {:01X?}", poly1);
|
|
||||||
eprintln!("poly2 is: {:01X?}", poly2);
|
|
||||||
|
|
||||||
let mut result: ByteArray = ByteArray(vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
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() {
|
if poly2.LSB_is_one() {
|
||||||
|
|
@ -40,25 +35,10 @@ pub fn gfmul(args: &Value) -> Result<String> {
|
||||||
if poly2.LSB_is_one() {
|
if poly2.LSB_is_one() {
|
||||||
poly1.left_shift();
|
poly1.left_shift();
|
||||||
poly1.xor_byte_arrays(&red_poly_bytes);
|
poly1.xor_byte_arrays(&red_poly_bytes);
|
||||||
eprintln!("Poly1 after reduction: {:01X?}", poly1);
|
|
||||||
result.xor_byte_arrays(&poly1);
|
result.xor_byte_arrays(&poly1);
|
||||||
eprintln!(
|
|
||||||
"LSB was one; \n
|
|
||||||
poly1 is {:01X?}; \n
|
|
||||||
poly2 is {:01X?}; \n
|
|
||||||
result is: {:01X?}",
|
|
||||||
poly1.0, poly2.0, result.0
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
poly1.left_shift();
|
poly1.left_shift();
|
||||||
poly1.xor_byte_arrays(&red_poly_bytes);
|
poly1.xor_byte_arrays(&red_poly_bytes);
|
||||||
eprintln!(
|
|
||||||
"LSB was 0; \n
|
|
||||||
poly1 is {:01X?}; \n
|
|
||||||
poly2 is {:01X?}; \n
|
|
||||||
result is: {:01X?}",
|
|
||||||
poly1.0, poly2.0, result.0
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
poly2.right_shift();
|
poly2.right_shift();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,5 @@
|
||||||
{
|
{
|
||||||
"testcases": {
|
"testcases": {
|
||||||
"b856d760-023d-4b00-bad2-15d2b6da22fe": {
|
|
||||||
"action": "block2poly",
|
|
||||||
"arguments": {
|
|
||||||
"semantic": "xex",
|
|
||||||
"block": "ARIAAAAAAAAAAAAAAAAAgA=="
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"254eaee7-05fd-4e0d-8292-9b658a852245": {
|
|
||||||
"action": "poly2block",
|
|
||||||
"arguments": {
|
|
||||||
"semantic": "xex",
|
|
||||||
"coefficients": [
|
|
||||||
12,
|
|
||||||
127,
|
|
||||||
9,
|
|
||||||
0
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"254eaee7-05fd-4e0d-8292-9b658a852245": {
|
"254eaee7-05fd-4e0d-8292-9b658a852245": {
|
||||||
"action": "gfmul",
|
"action": "gfmul",
|
||||||
"arguments": {
|
"arguments": {
|
||||||
|
|
@ -28,7 +8,7 @@
|
||||||
"b": "AgAAAAAAAAAAAAAAAAAAAA=="
|
"b": "AgAAAAAAAAAAAAAAAAAAAA=="
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"b856d760-023d-4b00-bad2-15d2b6da22fe": {
|
"b8f6d760-023d-4b00-bad2-15d2b6da22fe": {
|
||||||
"action": "sea128",
|
"action": "sea128",
|
||||||
"arguments": {
|
"arguments": {
|
||||||
"mode": "encrypt",
|
"mode": "encrypt",
|
||||||
|
|
@ -43,5 +23,26 @@
|
||||||
"key": "istDASeincoolerKEYrofg==",
|
"key": "istDASeincoolerKEYrofg==",
|
||||||
"input": "D5FDo3iVBoBN9gVi9/MSKQ=="
|
"input": "D5FDo3iVBoBN9gVi9/MSKQ=="
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"b856d760-023d-4b00-bad2-15d2b6da22fe": {
|
||||||
|
"action": "block2poly",
|
||||||
|
"arguments": {
|
||||||
|
"semantic": "xex",
|
||||||
|
"block": "ARIAAAAAAAAAAAAAAAAAgA=="
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"254eafe7-05fd-4e0d-8292-9b658a852245": {
|
||||||
|
"action": "poly2block",
|
||||||
|
"arguments": {
|
||||||
|
"semantic": "xex",
|
||||||
|
"coefficients": [
|
||||||
|
12,
|
||||||
|
127,
|
||||||
|
9,
|
||||||
|
0
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ pub fn get_coefficients(num: u128) -> Vec<u8> {
|
||||||
for shift in 0..128 {
|
for shift in 0..128 {
|
||||||
//println!("{:?}", ((num >> shift) & 1));
|
//println!("{:?}", ((num >> shift) & 1));
|
||||||
if ((num >> shift) & 1) == 1 {
|
if ((num >> shift) & 1) == 1 {
|
||||||
dbg!("Shift success");
|
|
||||||
powers.push(shift);
|
powers.push(shift);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue