This commit is contained in:
Nicholas Ward 2022-11-07 14:30:14 -08:00
parent 9a5db4b8d2
commit b40338ff2e
4 changed files with 62 additions and 60 deletions

View File

@ -2,6 +2,10 @@
PUSH 0
%endmacro
%macro blake_compression_message_addr
PUSH 16
%endmacro
global blake_compression:
// stack: h_0, ..., h_7, t_0, t_1, f_0, f_1, m_0, ..., m_15
%blake_compression_internal_state_addr
@ -16,6 +20,58 @@ global blake_compression:
PUSH 0
// stack: 0, start + 8, t_0, t_1, f_0, f_1, m_0, ..., m_15
%rep 4
// stack: i, loc, ...
DUP2
DUP2
// stack: i, loc, i, loc,...
%blake_iv
// stack: IV_i, loc, i, loc,...
SWAP1
// stack: loc, IV_i, i, loc,...
%mstore_kernel_general
// stack: i, loc,...
%increment
SWAP1
%increment
SWAP1
// stack: i + 1, loc + 1,...
%endrep
%rep 4
// stack: i, loc, val, next_val, next_val,...
%stack (i, loc, val) -> (i, val, loc, i, loc)
// stack: i, val, loc, i, loc, next_val,...
%blake_iv
// stack: IV_i, val, loc, i, loc, next_val,...
XOR
// stack: val ^ IV_i, loc, i, loc, next_val,...
SWAP1
// stack: loc, val ^ IV_i, i, loc, next_val,...
%mstore_kernel_general
// stack: i, loc, next_val,...
%increment
SWAP1
%increment
SWAP1
// stack: i + 1, loc + 1, next_val,...
%endrep
// stack: 8, loc + 16, m_0, ..., m_15
POP
POP
// stack: m_0, ..., m_15
%blake_compression_message_addr
// stack: addr, m_0, ..., m_15
%rep 16
%endrep
PUSH 0
// stack: round=0, m_0, ..., m_15
compression_loop:
// stack: round, m_0, ..., m_15
PUSH 0
DUP2
// stack: round, 0, round, m_0, ..., m_15
%blake_permutation
// stack: s[0], round, m_0, ..., m_15

View File

@ -1,56 +0,0 @@
global blake_iv_const:
// IV constants (big-endian)
// IV_0
BYTES 106, 9, 230, 103
BYTES 243, 188, 201, 8
// IV_1
BYTES 187, 103, 174, 133
BYTES 132, 202, 167, 59
// IV_2
BYTES 60, 110, 243, 114
BYTES 254, 148, 248, 43
// IV_3
BYTES 165, 79, 245, 58
BYTES 95, 29, 54, 241
// IV_4
BYTES 81, 14, 82, 127
BYTES 173, 230, 130, 209
// IV_5
BYTES 155, 5, 104, 140
BYTES 43, 62, 108, 31
// IV_6
BYTES 31, 131, 217, 171
BYTES 251, 65, 189, 107
// IV_7
BYTES 91, 224, 205, 25
BYTES 19, 126, 33, 121
%macro blake_iv(i)
PUSH blake_iv_const
// stack: blake_iv_const
PUSH $i
// stack: i, blake_iv_const
%mul_const(2)
ADD
// stack: blake_iv_const + 2 * i
DUP1
// stack: blake_iv_const + 2 * i, blake_iv_const + 2 * i
%increment
// stack: blake_iv_const + 2 * i, blake_iv_const + 2 * i
%mload_kernel_code
SWAP1
%increment
// stack: IV_i[32:], IV_i[:32]
%shl_const(32)
// stack: IV_i[32:] << 32, IV_i[:32]
ADD
// stack: IV_i
%endmacro

View File

@ -22,4 +22,4 @@
%as_u64
// stack: (value << (64 - rot)) % (1 << 64), value >> rot
ADD
%endmacro
%endmacro

View File

@ -160,13 +160,15 @@ permutation_9_constants:
BYTES 13
BYTES 0
%macro blake_permutation(round, i)
%macro blake_permutation
// stack: round, i
PUSH permutation_1_constants
PUSH $round
// stack: permutation_1_constants, round, i
SWAP1
// stack: round, permutation_1_constants, i
%mod_const(10)
%mul_const(16)
ADD
%add_const($i)
%mload_kernel_code
%endmacro