Blake progress

This commit is contained in:
Nicholas Ward 2022-11-07 16:26:49 -08:00
parent 0c919443f9
commit 6e782a1a1e
4 changed files with 124 additions and 0 deletions

View File

@ -39,6 +39,13 @@ pub(crate) fn combined_kernel() -> Kernel {
include_str!("asm/fields/fp6_mul.asm"),
include_str!("asm/fields/fp12_mul.asm"),
include_str!("asm/halt.asm"),
// include_str!("asm/hash/blake/compression.asm"),
// include_str!("asm/hash/blake/g_functions.asm"),
// include_str!("asm/hash/blake/initial_state.asm"),
// include_str!("asm/hash/blake/iv.asm"),
// include_str!("asm/hash/blake/ops.asm"),
// include_str!("asm/hash/blake/permutations.asm"),
// include_str!("asm/hash/blake/store.asm"),
include_str!("asm/hash/ripemd/box.asm"),
include_str!("asm/hash/ripemd/compression.asm"),
include_str!("asm/hash/ripemd/constants.asm"),

View File

@ -0,0 +1,16 @@
global blake_initial_state:
// stack: retdest
%blake_iv(7)
%blake_iv(6)
%blake_iv(5)
%blake_iv(4)
%blake_iv(3)
%blake_iv(2)
%blake_iv(1)
// stack: IV_1, IV_2, IV_3, IV_4, IV_5, IV_6, IV_7, retdest
PUSH 0x01010040 // params: key = 00, digest_size = 64 = 0x40
%blake_iv(0)
XOR
// stack: IV_0 ^ params, IV_1, IV_2, IV_3, IV_4, IV_5, IV_6, IV_7, retdest
%stack () -> (0, 0)
// stack: c_0 = 0, c_1 = 0, h_0, h_1, h_2, h_3, h_4, h_5, h_6, h_7, retdest

View File

@ -0,0 +1,62 @@
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
// stack: i, ...
PUSH blake_iv_const
// stack: blake_iv_const, i, ...
SWAP1
// 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
%macro blake_iv_i(i)
PUSH $i
%blake_iv
%endmacro

View File

@ -0,0 +1,39 @@
global blake:
%jump(blake_store)
global blake_store:
// stack: num_bytes, x[0], x[1], ..., x[num_bytes - 1], retdest
DUP1
// stack: num_bytes, num_bytes, x[0], x[1], ..., x[num_bytes - 1], retdest
%add_const(127)
%div_const(128)
// stack: num_blocks = ceil(num_bytes / 128), num_bytes, x[0], x[1], ..., x[num_bytes - 1], retdest
PUSH 0
// stack: addr=0, num_blocks, num_bytes, x[0], x[1], ..., x[num_bytes - 1], retdest
%mstore_kernel_general
// stack: num_bytes, x[0], x[1], ..., x[num_bytes - 1], retdest
PUSH 1
// stack: addr=1, counter=num_bytes, x[0], x[1], x[2], ... , x[num_bytes-1], retdest
store_loop:
// stack: addr, counter, x[num_bytes-counter], ... , x[num_bytes-1], retdest
DUP2
// stack: counter, addr, counter, x[num_bytes-counter], ... , x[num_bytes-1], retdest
ISZERO
%jumpi(store_end)
// stack: addr, counter, x[num_bytes-counter], ... , x[num_bytes-1], retdest
%stack (addr, counter, val) -> (addr, val, counter, addr)
// stack: addr, x[num_bytes-counter], counter, addr, ... , x[num_bytes-1], retdest
%mstore_kernel_general
// stack: counter, addr, ... , x[num_bytes-1], retdest
%decrement
// stack: counter-1, addr, ... , x[num_bytes-1], retdest
SWAP1
// stack: addr, counter-1, ... , x[num_bytes-1], retdest
%increment
// stack: addr+1, counter-1, ... , x[num_bytes-1], retdest
%jump(store_loop)
store_end:
// stack: addr, counter, retdest
%pop2
// stack: retdest
%jump(blake_pad)