This commit is contained in:
Dmitry Vagner 2022-09-26 07:34:57 -07:00
parent 705b4a432f
commit 4850c338b4
4 changed files with 20 additions and 11 deletions

View File

@ -30,7 +30,7 @@ store_size:
store_padding:
// stack: i (init 63)
%store_zeros(136, store_padding)
%jumpi(store_input_alt)
%jump(store_input_alt)
%jump(ripemd_init)
store_input_alt:

View File

@ -36,8 +36,8 @@ global ripemd_init:
// stack: length
%stack (length) -> ( 0, length, 136, ripemd_1, ripemd_2, process)
// stack: count = 0, length, virt = 136, ripemd_1, ripemd_2, process
%stack (ARGS: 3, LABELS: 3) -> (0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0, ARGS, LABELS)
// stack: 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0, count, length, virt, LABELS
%stack () -> (0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0)
// stack: 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0, count, length, virt, LABELS
%jump(ripemd_update)
ripemd_1:
// stack: STATE, count, length , virt , LABELS

View File

@ -91,19 +91,19 @@ update_1a:
/// cond -= 64
update_2:
// stack: STATE, shift, need, have, count, length, virt, retdest
// stack: STATE, shift, need, have, count, length, virt, retdest
%stack (STATE: 5, shift, need, have, count, length) -> (length, shift, STATE, shift, need, have, count, length)
SUB
%ge_const(64)
// stack: cond, STATE, shift, need, have, count, length, virt, retdest
// stack: cond, STATE, shift, need, have, count, length, virt, retdest
DUP12
DUP8
ADD
// stack: offset, cond, STATE, shift, need, have, count, length, virt, retdest
// stack: offset, cond, STATE, shift, need, have, count, length, virt, retdest
%stack (offset, cond, STATE: 5) -> (cond, STATE, offset, compression_loop)
// stack: cond, STATE, offset, compression_loop, shift, need, have, count, length, virt, retdest
%jumpi(compress)
%stack (STATE:5, offset, compression_loop) -> (STATE, offset)
%stack (STATE: 5, offset, compression_loop) -> (STATE, offset)
%jump(final_update)
compression_loop:
// stack: STATE, offset , cond , shift, need, have, count, length, virt, retdest

View File

@ -13,14 +13,23 @@ fn make_input(word: &str) -> Vec<u8> {
#[test]
fn test_ripemd() -> Result<()> {
let input: Vec<u8> = make_input("");
let expected = U256::from("0x9c1185a5c5e9fc54612808977ee8f548b2258d31");
// let input: Vec<u8> = make_input("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
// let expected = U256::from("0x9b752e45573d4b39f4dbd3323cab82bf63326bfb");
let input: Vec<u8> = make_input("abcdefghijklmnopqrstuvwxyz");
let expected = U256::from("0xf71c27109c692c1b56bbdceb5b9d2865b3708dbc");
let kernel = combined_kernel();
let label = kernel.global_labels["ripemd_alt"];
let stack_input: Vec<U256> = input.iter().map(|&x| U256::from(x as u8)).rev().collect();
let output: U256 = run_with_kernel(&kernel, label, stack_input)?.stack()[0];
assert_eq!(output, expected);
let stack_output: Vec<U256> = run_with_kernel(&kernel, label, stack_input)?.stack().to_vec();
let read_out: Vec<String> = stack_output.iter().map(|x| format!("{:x}", x)).rev().collect();
println!("{:x?}", read_out);
let actual = stack_output[0];
assert_eq!(actual, expected);
Ok(())
}