compression test works!

This commit is contained in:
Dmitry Vagner 2022-09-23 00:15:44 -07:00
parent 4a5ddfda0a
commit bbeac10bff
5 changed files with 40 additions and 9 deletions

View File

@ -110,6 +110,36 @@
// stack: (((((c_3 << 8) | c_2) << 8) | c_1) << 8) | c_0
%endmacro
// Load LE u32 at given label from 4 bytes (a, b, c, d)
%macro mload_kernel_code_u32_LE(label)
// stack: offset
PUSH $label
ADD
// stack: offset
DUP1
%mload_kernel_code
// stack: a , offset
DUP2
%add_const(1)
%mload_kernel_code
%shl_const(8)
OR
// stack: a | (b << 8) , offset
DUP2
%add_const(2)
%mload_kernel_code
%shl_const(16)
OR
// stack: a | (b << 8) | (c << 16), offset
SWAP1
%add_const(3)
%mload_kernel_code
%shl_const(24)
OR
// stack: a | (b << 8) | (c << 16) | (d << 24)
%endmacro
// Store a single byte to kernel code.
%macro mstore_kernel_code
// stack: offset, value

View File

@ -1,7 +1,5 @@
/// _block is stored in memory and its address virt remains on the stack
/// Note that STATE takes up 5 stack slots
/// def compress(state, _block):
///
/// stateL = state
@ -25,7 +23,7 @@
/// state[i], stateL[i], stateR[i], output[i], virt, retdest
global compress:
// stack: STATE, virt, retdest
// stack: STATE, virt, retdest
PUSH switch
DUP7
PUSH 1
@ -204,12 +202,12 @@ pre_rol:
// stack: a, b, c, d, e, F, K, boxes, rounds, sides, virt
%get_box
// stack: box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
DUP1
DUP12
DUP2
%mload_kernel_code_label(R_data)
DUP13
ADD
// stack: virt + r, box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
%mload_kernel_code_label_u32(Input_Block) // %load_u32_from_block
// stack: virt + r, box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
%mload_kernel_code_u32_LE(Input_Block) // %load_u32_from_block
// stack: x, box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
SWAP1
SWAP2

View File

@ -136,4 +136,5 @@ global Input_Block:
BYTES 0x00, 0x00, 0x00, 0x00
BYTES 0x00, 0x00, 0x00, 0x00
BYTES 0xd0, 0x00, 0x00, 0x00
BYTES 0x00, 0x00, 0x00, 0x00
BYTES 0x00, 0x00, 0x00, 0x00

View File

@ -155,6 +155,7 @@ store_input:
// stack: a | (b << 8) | (c << 16) | (d << 24)
%endmacro
// set offset i to offset j in SEGMENT_RIPEMD
%macro mupdate_ripemd
// stack: j, i

View File

@ -12,6 +12,7 @@ fn test_ripemd() -> Result<()> {
println!("{:#?}", expected);
let input: Vec<u32> = vec![0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0, 0, 0xdeadbeef];
// let input: Vec<u32> = vec![
// 0x1a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
// 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
@ -20,7 +21,7 @@ fn test_ripemd() -> Result<()> {
let kernel = combined_kernel();
let stack_input: Vec<U256> = input.iter().map(|&x| U256::from(x as u32)).rev().collect();
let stack_output = run_with_kernel(&kernel, kernel.global_labels["compress"], stack_input)?;
let actual: Vec<String> = stack_output.stack().iter().map(|&x| format!("{:X}", x)).collect();
let actual: Vec<String> = stack_output.stack().iter().map(|&x| format!("{:X}", x)).rev().collect();
println!("{:#?}", actual);
assert_eq!(expected, actual);