This commit is contained in:
Nicholas Ward 2022-11-29 16:12:58 -08:00
parent 20169a5476
commit 49504dde7d
4 changed files with 17 additions and 35 deletions

View File

@ -162,7 +162,7 @@ compression_loop:
// stack: cur_message_addr, cur_block_byte, ...
DUP2
// stack: cur_block_byte, cur_message_addr, cur_block_byte, ...
%mload_blake_word
%mload_blake_word_from_bytes
// stack: m_i, cur_message_addr, cur_block_byte, ...
DUP2
// stack: cur_message_addr, m_i, cur_message_addr, cur_block_byte, ...
@ -209,7 +209,6 @@ compression_loop:
%mstore_kernel_general
%increment
%endrep
// stack: start + 8, invert_if_last_block, t, retdest
PUSH 0
// stack: 0, start + 8, invert_if_last_block, t, retdest
@ -272,36 +271,20 @@ compression_loop:
// stack: start, retdest
PUSH 0
// stack: round=0, start, retdest
%rep 1
%rep 12
// stack: round, start, retdest
%call_blake_g_function(0, 4, 8, 12, 0, 1)
// %call_blake_g_function(1, 5, 9, 13, 2, 3)
// %call_blake_g_function(2, 6, 10, 14, 4, 5)
// %call_blake_g_function(3, 7, 11, 15, 6, 7)
// %call_blake_g_function(0, 5, 10, 15, 8, 9)
// %call_blake_g_function(1, 6, 11, 12, 10, 11)
// %call_blake_g_function(2, 7, 8, 13, 12, 13)
// %call_blake_g_function(3, 4, 9, 14, 14, 15)
%call_blake_g_function(1, 5, 9, 13, 2, 3)
%call_blake_g_function(2, 6, 10, 14, 4, 5)
%call_blake_g_function(3, 7, 11, 15, 6, 7)
%call_blake_g_function(0, 5, 10, 15, 8, 9)
%call_blake_g_function(1, 6, 11, 12, 10, 11)
%call_blake_g_function(2, 7, 8, 13, 12, 13)
%call_blake_g_function(3, 4, 9, 14, 14, 15)
// stack: round, start, retdest
%increment
// stack: round + 1, start, retdest
%endrep
%blake_internal_state_addr
%add_const(15)
%rep 16
// stack: addr, ...
DUP1
// stack: addr, addr, ...
%mload_kernel_general
// stack: val, addr, ...
SWAP1
// stack: addr, val, ...
%decrement
%endrep
STOP
// stack: 12, start, retdest
POP
POP

View File

@ -103,7 +103,7 @@
// stack: s[y_idx], round, start
%blake_message_addr
ADD
%mload_blake_word
%mload_kernel_general
// stack: m[s[y_idx]], round, start
PUSH $x_idx
DUP3
@ -112,7 +112,7 @@
// stack: s[x_idx], m[s[y_idx]], round, start
%blake_message_addr
ADD
%mload_blake_word
%mload_kernel_general
// stack: m[s[x_idx]], m[s[y_idx]], round, start
%stack (ss: 2, r, s) -> (ss, s, r, s)
// stack: m[s[x_idx]], m[s[y_idx]], start, round, start

View File

@ -1,5 +1,5 @@
// Load a 64-bit word from kernel general memory.
%macro mload_blake_word
%macro mload_blake_word_from_bytes
// stack: offset
DUP1
%mload_kernel_general_u32_LE
@ -7,7 +7,7 @@
SWAP1
// stack: offset, lo
%add_const(4)
%mload_kernel_general_u32
%mload_kernel_general_u32_LE
// stack: hi, lo
%shl_const(32)
// stack: hi << 32, lo

View File

@ -41,7 +41,9 @@ fn make_random_input() -> Vec<u8> {
fn make_custom_input() -> Vec<u8> {
// Hardcode a custom message
vec![
1, 2, 3, 4, 5,
86, 124, 206, 245, 74, 57, 250, 43, 60, 30, 254, 43, 143, 144, 242, 215, 13, 103, 237, 61,
90, 105, 123, 250, 189, 181, 110, 192, 227, 57, 145, 46, 221, 238, 7, 181, 146, 111, 209,
150, 31, 157, 229, 126, 206, 105, 37, 17,
]
}
@ -115,15 +117,12 @@ fn test_hash_512(hash_fn_label: &str, standard_implementation: &dyn Fn(Vec<u8>)
let random_stack = result_random.stack();
let custom_stack = result_custom.stack();
dbg!(custom_stack);
// dbg!(result_custom.get_kernel_general_memory());
// Extract the final output.
let actual_random = combine_u256s(random_stack[0], random_stack[1]);
let actual_custom = combine_u256s(custom_stack[0], custom_stack[1]);
// Check that the result is correct.
// assert_eq!(expected_random, actual_random);
assert_eq!(expected_random, actual_random);
assert_eq!(expected_custom, actual_custom);
Ok(())