rename blake -> blake2b

This commit is contained in:
Nicholas Ward 2022-12-01 21:42:58 -08:00
parent d30a95f7d5
commit 778aec627b
11 changed files with 87 additions and 87 deletions

View File

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

View File

@ -1,21 +1,21 @@
// Load the initial hash value (the IV, but with params XOR'd into the first word). // Load the initial hash value (the IV, but with params XOR'd into the first word).
%macro blake_initial_hash_value %macro blake2b_initial_hash_value
%blake_iv_i(7) %blake2b_iv_i(7)
%blake_iv_i(6) %blake2b_iv_i(6)
%blake_iv_i(5) %blake2b_iv_i(5)
%blake_iv_i(4) %blake2b_iv_i(4)
%blake_iv_i(3) %blake2b_iv_i(3)
%blake_iv_i(2) %blake2b_iv_i(2)
%blake_iv_i(1) %blake2b_iv_i(1)
// stack: IV_1, IV_2, IV_3, IV_4, IV_5, IV_6, IV_7 // stack: IV_1, IV_2, IV_3, IV_4, IV_5, IV_6, IV_7
PUSH 0x01010040 // params: key = 00, digest_size = 64 = 0x40 PUSH 0x01010040 // params: key = 00, digest_size = 64 = 0x40
%blake_iv_i(0) %blake2b_iv_i(0)
XOR XOR
// stack: IV_0 ^ params, IV_1, IV_2, IV_3, IV_4, IV_5, IV_6, IV_7 // stack: IV_0 ^ params, IV_1, IV_2, IV_3, IV_4, IV_5, IV_6, IV_7
%endmacro %endmacro
// Address where the working version of the hash value is stored. // Address where the working version of the hash value is stored.
%macro blake_hash_value_addr %macro blake2b_hash_value_addr
PUSH 0 PUSH 0
// stack: 0 // stack: 0
%mload_kernel_general %mload_kernel_general
@ -26,13 +26,13 @@
%endmacro %endmacro
// Address where the working version of the compression internal state is stored. // Address where the working version of the compression internal state is stored.
%macro blake_internal_state_addr %macro blake2b_internal_state_addr
%blake_hash_value_addr %blake2b_hash_value_addr
%add_const(8) %add_const(8)
%endmacro %endmacro
// Address where the current message block is stored. // Address where the current message block is stored.
%macro blake_message_addr %macro blake2b_message_addr
%blake_internal_state_addr %blake2b_internal_state_addr
%add_const(16) %add_const(16)
%endmacro %endmacro

View File

@ -1,11 +1,11 @@
global blake_compression: global blake2b_compression:
// stack: retdest // stack: retdest
PUSH 0 PUSH 0
// stack: cur_block = 0, retdest // stack: cur_block = 0, retdest
%blake_initial_hash_value %blake2b_initial_hash_value
compression_loop: compression_loop:
// stack: h_0, ..., h_7, cur_block, retdest // stack: h_0, ..., h_7, cur_block, retdest
%blake_hash_value_addr %blake2b_hash_value_addr
// stack: addr, h_0, ..., h_7, cur_block, retdest // stack: addr, h_0, ..., h_7, cur_block, retdest
%rep 8 %rep 8
SWAP1 SWAP1
@ -54,13 +54,13 @@ compression_loop:
%mul_const(128) %mul_const(128)
%add_const(2) %add_const(2)
// stack: cur_block_start_byte, t, cur_block, is_last_block, retdest // stack: cur_block_start_byte, t, cur_block, is_last_block, retdest
%blake_message_addr %blake2b_message_addr
// stack: message_addr, cur_block_start_byte, t, cur_block, is_last_block, retdest // stack: message_addr, cur_block_start_byte, t, cur_block, is_last_block, retdest
%rep 16 %rep 16
// stack: cur_message_addr, cur_block_byte, ... // stack: cur_message_addr, cur_block_byte, ...
DUP2 DUP2
// stack: cur_block_byte, cur_message_addr, cur_block_byte, ... // stack: cur_block_byte, cur_message_addr, cur_block_byte, ...
%mload_blake_word_from_bytes %mload_blake2b_word_from_bytes
// stack: m_i, cur_message_addr, cur_block_byte, ... // stack: m_i, cur_message_addr, cur_block_byte, ...
DUP2 DUP2
// stack: cur_message_addr, m_i, cur_message_addr, cur_block_byte, ... // stack: cur_message_addr, m_i, cur_message_addr, cur_block_byte, ...
@ -85,7 +85,7 @@ compression_loop:
// stack: is_last_block, t, cur_block, retdest // stack: is_last_block, t, cur_block, retdest
%mul_const(0xFFFFFFFFFFFFFFFF) %mul_const(0xFFFFFFFFFFFFFFFF)
// stack: invert_if_last_block, t, cur_block, retdest // stack: invert_if_last_block, t, cur_block, retdest
%blake_hash_value_addr %blake2b_hash_value_addr
%add_const(7) %add_const(7)
%rep 8 %rep 8
// stack: addr, ... // stack: addr, ...
@ -100,7 +100,7 @@ compression_loop:
// stack: addr, h_0, ..., h_7, invert_if_last_block, t, cur_block, retdest // stack: addr, h_0, ..., h_7, invert_if_last_block, t, cur_block, retdest
POP POP
// stack: h_0, ..., h_7, invert_if_last_block, t, cur_block, retdest // stack: h_0, ..., h_7, invert_if_last_block, t, cur_block, retdest
%blake_internal_state_addr %blake2b_internal_state_addr
// stack: start, h_0, ..., h_7, invert_if_last_block, t, cur_block, retdest // stack: start, h_0, ..., h_7, invert_if_last_block, t, cur_block, retdest
// First eight words of compression state: current state h_0, ..., h_7. // First eight words of compression state: current state h_0, ..., h_7.
%rep 8 %rep 8
@ -117,7 +117,7 @@ compression_loop:
DUP2 DUP2
DUP2 DUP2
// stack: i, loc, i, loc,... // stack: i, loc, i, loc,...
%blake_iv %blake2b_iv
// stack: IV_i, loc, i, loc,... // stack: IV_i, loc, i, loc,...
SWAP1 SWAP1
// stack: loc, IV_i, i, loc,... // stack: loc, IV_i, i, loc,...
@ -149,7 +149,7 @@ compression_loop:
// stack: i, loc, val, next_val,... // stack: i, loc, val, next_val,...
%stack (i, loc, val) -> (i, val, loc, i, loc) %stack (i, loc, val) -> (i, val, loc, i, loc)
// stack: i, val, loc, i, loc, next_val,... // stack: i, val, loc, i, loc, next_val,...
%blake_iv %blake2b_iv
// stack: IV_i, val, loc, i, loc, next_val,... // stack: IV_i, val, loc, i, loc, next_val,...
XOR XOR
// stack: val ^ IV_i, loc, i, loc, next_val,... // stack: val ^ IV_i, loc, i, loc, next_val,...
@ -167,20 +167,20 @@ compression_loop:
POP POP
POP POP
// stack: cur_block, retdest // stack: cur_block, retdest
%blake_internal_state_addr %blake2b_internal_state_addr
// stack: start, cur_block, retdest // stack: start, cur_block, retdest
PUSH 0 PUSH 0
// stack: round=0, start, cur_block, retdest // stack: round=0, start, cur_block, retdest
%rep 12 %rep 12
// stack: round, start, cur_block, retdest // stack: round, start, cur_block, retdest
%call_blake_g_function(0, 4, 8, 12, 0, 1) %call_blake2b_g_function(0, 4, 8, 12, 0, 1)
%call_blake_g_function(1, 5, 9, 13, 2, 3) %call_blake2b_g_function(1, 5, 9, 13, 2, 3)
%call_blake_g_function(2, 6, 10, 14, 4, 5) %call_blake2b_g_function(2, 6, 10, 14, 4, 5)
%call_blake_g_function(3, 7, 11, 15, 6, 7) %call_blake2b_g_function(3, 7, 11, 15, 6, 7)
%call_blake_g_function(0, 5, 10, 15, 8, 9) %call_blake2b_g_function(0, 5, 10, 15, 8, 9)
%call_blake_g_function(1, 6, 11, 12, 10, 11) %call_blake2b_g_function(1, 6, 11, 12, 10, 11)
%call_blake_g_function(2, 7, 8, 13, 12, 13) %call_blake2b_g_function(2, 7, 8, 13, 12, 13)
%call_blake_g_function(3, 4, 9, 14, 14, 15) %call_blake2b_g_function(3, 4, 9, 14, 14, 15)
// stack: round, start, cur_block, retdest // stack: round, start, cur_block, retdest
%increment %increment
// stack: round + 1, start, cur_block, retdest // stack: round + 1, start, cur_block, retdest
@ -189,14 +189,14 @@ compression_loop:
POP POP
POP POP
// stack: cur_block, retdest // stack: cur_block, retdest
%blake_generate_new_hash_value(7) %blake2b_generate_new_hash_value(7)
%blake_generate_new_hash_value(6) %blake2b_generate_new_hash_value(6)
%blake_generate_new_hash_value(5) %blake2b_generate_new_hash_value(5)
%blake_generate_new_hash_value(4) %blake2b_generate_new_hash_value(4)
%blake_generate_new_hash_value(3) %blake2b_generate_new_hash_value(3)
%blake_generate_new_hash_value(2) %blake2b_generate_new_hash_value(2)
%blake_generate_new_hash_value(1) %blake2b_generate_new_hash_value(1)
%blake_generate_new_hash_value(0) %blake2b_generate_new_hash_value(0)
// stack: h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block, retdest // stack: h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block, retdest
DUP9 DUP9
// stack: cur_block, h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block, retdest // stack: cur_block, h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block, retdest
@ -218,28 +218,28 @@ compression_end:
PUSH 0 PUSH 0
// stack: dummy=0, h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest // stack: dummy=0, h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest
SWAP1 SWAP1
%invert_bytes_blake_word %invert_bytes_blake2b_word
SWAP1 SWAP1
SWAP2 SWAP2
%invert_bytes_blake_word %invert_bytes_blake2b_word
SWAP2 SWAP2
SWAP3 SWAP3
%invert_bytes_blake_word %invert_bytes_blake2b_word
SWAP3 SWAP3
SWAP4 SWAP4
%invert_bytes_blake_word %invert_bytes_blake2b_word
SWAP4 SWAP4
SWAP5 SWAP5
%invert_bytes_blake_word %invert_bytes_blake2b_word
SWAP5 SWAP5
SWAP6 SWAP6
%invert_bytes_blake_word %invert_bytes_blake2b_word
SWAP6 SWAP6
SWAP7 SWAP7
%invert_bytes_blake_word %invert_bytes_blake2b_word
SWAP7 SWAP7
SWAP8 SWAP8
%invert_bytes_blake_word %invert_bytes_blake2b_word
SWAP8 SWAP8
POP POP
%shl_const(64) %shl_const(64)

View File

@ -1,4 +1,4 @@
%macro blake_g_function %macro blake2b_g_function
// Function to mix two input words, x and y, into the four words indexed by a, b, c, d (which // Function to mix two input words, x and y, into the four words indexed by a, b, c, d (which
// are in the range 0..16) in the internal state. // are in the range 0..16) in the internal state.
// The internal state is stored in memory starting at the address start. // The internal state is stored in memory starting at the address start.
@ -94,23 +94,23 @@
%mstore_kernel_general %mstore_kernel_general
%endmacro %endmacro
%macro call_blake_g_function(a, b, c, d, x_idx, y_idx) %macro call_blake2b_g_function(a, b, c, d, x_idx, y_idx)
// stack: round, start // stack: round, start
PUSH $y_idx PUSH $y_idx
DUP2 DUP2
// stack: round, y_idx, round, start // stack: round, y_idx, round, start
%blake_permutation %blake2b_permutation
// stack: s[y_idx], round, start // stack: s[y_idx], round, start
%blake_message_addr %blake2b_message_addr
ADD ADD
%mload_kernel_general %mload_kernel_general
// stack: m[s[y_idx]], round, start // stack: m[s[y_idx]], round, start
PUSH $x_idx PUSH $x_idx
DUP3 DUP3
// stack: round, 2, m[s[y_idx]], round, start // stack: round, 2, m[s[y_idx]], round, start
%blake_permutation %blake2b_permutation
// stack: s[x_idx], m[s[y_idx]], round, start // stack: s[x_idx], m[s[y_idx]], round, start
%blake_message_addr %blake2b_message_addr
ADD ADD
%mload_kernel_general %mload_kernel_general
// stack: m[s[x_idx]], m[s[y_idx]], round, start // stack: m[s[x_idx]], m[s[y_idx]], round, start
@ -121,6 +121,6 @@
PUSH $b PUSH $b
PUSH $a PUSH $a
// stack: a, b, c, d, m[s[x_idx]], m[s[y_idx]], start, round, start // stack: a, b, c, d, m[s[x_idx]], m[s[y_idx]], start, round, start
%blake_g_function %blake2b_g_function
// stack: round, start // stack: round, start
%endmacro %endmacro

View File

@ -1,13 +1,13 @@
%macro blake_generate_new_hash_value(i) %macro blake2b_generate_new_hash_value(i)
%blake_hash_value_addr %blake2b_hash_value_addr
%add_const($i) %add_const($i)
%mload_kernel_general %mload_kernel_general
// stack: h_i, ... // stack: h_i, ...
%blake_internal_state_addr %blake2b_internal_state_addr
%add_const($i) %add_const($i)
%mload_kernel_general %mload_kernel_general
// stack: v_i, h_i, ... // stack: v_i, h_i, ...
%blake_internal_state_addr %blake2b_internal_state_addr
%add_const($i) %add_const($i)
%add_const(8) %add_const(8)
%mload_kernel_general %mload_kernel_general

View File

@ -1,4 +1,4 @@
global blake_iv_const: global blake2b_iv_const:
// IV constants (big-endian) // IV constants (big-endian)
// IV_0 // IV_0
@ -33,19 +33,19 @@ global blake_iv_const:
BYTES 91, 224, 205, 25 BYTES 91, 224, 205, 25
BYTES 19, 126, 33, 121 BYTES 19, 126, 33, 121
%macro blake_iv %macro blake2b_iv
// stack: i, ... // stack: i, ...
PUSH blake_iv_const PUSH blake2b_iv_const
// stack: blake_iv_const, i, ... // stack: blake2b_iv_const, i, ...
SWAP1 SWAP1
// stack: i, blake_iv_const, ... // stack: i, blake2b_iv_const, ...
%mul_const(8) %mul_const(8)
ADD ADD
// stack: blake_iv_const + 2 * i, ... // stack: blake2b_iv_const + 2 * i, ...
DUP1 DUP1
// stack: blake_iv_const + 2 * i, blake_iv_const + 2 * i, ... // stack: blake2b_iv_const + 2 * i, blake2b_iv_const + 2 * i, ...
%add_const(4) %add_const(4)
// stack: blake_iv_const + 2 * i + 1, blake_iv_const + 2 * i, ... // stack: blake2b_iv_const + 2 * i + 1, blake2b_iv_const + 2 * i, ...
%mload_kernel_code_u32 %mload_kernel_code_u32
SWAP1 SWAP1
%mload_kernel_code_u32 %mload_kernel_code_u32
@ -56,7 +56,7 @@ global blake_iv_const:
// stack: IV_i, ... // stack: IV_i, ...
%endmacro %endmacro
%macro blake_iv_i(i) %macro blake2b_iv_i(i)
PUSH $i PUSH $i
%blake_iv %blake2b_iv
%endmacro %endmacro

View File

@ -178,7 +178,7 @@ global permutation_9_constants:
BYTES 13 BYTES 13
BYTES 0 BYTES 0
%macro blake_permutation %macro blake2b_permutation
// stack: round, i // stack: round, i
PUSH permutation_0_constants PUSH permutation_0_constants
// stack: permutation_0_constants, round, i // stack: permutation_0_constants, round, i

View File

@ -1,7 +1,7 @@
global blake: global blake2b:
%jump(blake_store) %jump(blake2b_store)
global blake_store: global blake2b_store:
// stack: num_bytes, x[0], x[1], ..., x[num_bytes - 1], retdest // stack: num_bytes, x[0], x[1], ..., x[num_bytes - 1], retdest
DUP1 DUP1
// stack: num_bytes, num_bytes, x[0], x[1], ..., x[num_bytes - 1], retdest // stack: num_bytes, num_bytes, x[0], x[1], ..., x[num_bytes - 1], retdest
@ -42,4 +42,4 @@ store_end:
// stack: addr, counter, retdest // stack: addr, counter, retdest
%pop2 %pop2
// stack: retdest // stack: retdest
%jump(blake_compression) %jump(blake2b_compression)

View File

@ -1,5 +1,5 @@
// Load a 64-bit word from kernel general memory. // Load a 64-bit word from kernel general memory.
%macro mload_blake_word_from_bytes %macro mload_blake2b_word_from_bytes
// stack: offset // stack: offset
DUP1 DUP1
%mload_kernel_general_u32_LE %mload_kernel_general_u32_LE
@ -25,7 +25,7 @@
%endmacro %endmacro
// Invert the order of the eight bytes in a Blake word. // Invert the order of the eight bytes in a Blake word.
%macro invert_bytes_blake_word %macro invert_bytes_blake2b_word
// stack: word // stack: word
DUP1 DUP1
// stack: word, word // stack: word, word

View File

@ -144,6 +144,6 @@ fn test_ripemd() -> Result<()> {
} }
#[test] #[test]
fn test_blake() -> Result<()> { fn test_blake2b() -> Result<()> {
test_hash_512("blake", &blake2b) test_hash_512("blake2b", &blake2b)
} }