fix constants

This commit is contained in:
Dmitry Vagner 2022-09-22 09:40:40 -07:00
parent 81675e6eda
commit f45d6593f9
4 changed files with 16 additions and 15 deletions

View File

@ -62,7 +62,7 @@
// stack: value
%endmacro
%macro mload_kernel_code_shift(label)
%macro mload_kernel_code_label(label)
// stack: shift
PUSH $label
ADD
@ -71,6 +71,15 @@
// stack: byte
%endmacro
%macro mload_kernel_code_label_u32(label)
// stack: shift
PUSH $label
ADD
// stack: label + shift
%mload_kernel_code_u32
// stack: byte
%endmacro
// Load a big-endian u32, consisting of 4 bytes (c_3, c_2, c_1, c_0),
// from kernel code.
%macro mload_kernel_code_u32

View File

@ -26,7 +26,7 @@
global compress:
// stack: STATE, virt, retdest
%stack (x) -> (0, 0, 16, 5, 1, x)
%stack (stack) -> (0, 0, 16, 5, 1, stack)
%stack (CONSTS: 5, virt, switch, STATE: 5) -> (STATE, CONSTS, virt, switch, STATE)
// stack: STATE, 0, 0, 16, 5, 1, virt, switch, STATE, virt, retdest
%jump(loop)
@ -123,7 +123,8 @@ update_round_vars:
// stack: rnd, rnd, STATE, F', K , 16, rounds, sides, virt, retdest
SWAP8
POP
%load_K
%mul_const(4)
%mload_kernel_code_label_u32(K_data)
SWAP7
POP
// stack: STATE, F', K', 16, rounds, sides, virt, retdest
@ -182,7 +183,7 @@ pre_rol:
%get_box
// stack: box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
DUP1
%mload_kernel_code_shift(R_data)
%mload_kernel_code_label(R_data)
DUP13
ADD
// stack: virt + r, box, a, b, c, d, e, F, K, boxes, rounds, sides, virt
@ -199,7 +200,7 @@ pre_rol:
PUSH mid_rol
SWAP2
// stack: box, a, mid_rol, b, c, d, e, F, K, boxes, rounds, sides, virt
%mload_kernel_code_shift(S_data)
%mload_kernel_code_label(S_data)
// stack: s, a, mid_rol, b, c, d, e, F, K, boxes, rounds, sides, virt
%jump(rol)
mid_rol:

View File

@ -1,12 +1,3 @@
%macro load_K
// stack: rnd
%mul_const(4)
%add_const(K_data)
// stack: K_data + 4*rnd
%mload_kernel_code_u32
// stack: K
%endmacro
global K_data:
// Left
BYTES 0x00, 0x00, 0x00, 0x00

View File

@ -12,7 +12,7 @@ fn test_ripemd() -> Result<()> {
let kernel = combined_kernel();
let input: Vec<u32> = vec![
26, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
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,
];
let stack_init: Vec<U256> = input.iter().map(|&x| U256::from(x as u32)).rev().collect();