mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 16:23:12 +00:00
rename blake -> blake2b
This commit is contained in:
parent
d30a95f7d5
commit
778aec627b
@ -39,15 +39,15 @@ 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/addresses.asm"),
|
||||
include_str!("asm/hash/blake/compression.asm"),
|
||||
include_str!("asm/hash/blake/g_functions.asm"),
|
||||
include_str!("asm/hash/blake/hash.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/blake/util.asm"),
|
||||
include_str!("asm/hash/blake2b/addresses.asm"),
|
||||
include_str!("asm/hash/blake2b/compression.asm"),
|
||||
include_str!("asm/hash/blake2b/g_functions.asm"),
|
||||
include_str!("asm/hash/blake2b/hash.asm"),
|
||||
include_str!("asm/hash/blake2b/iv.asm"),
|
||||
include_str!("asm/hash/blake2b/ops.asm"),
|
||||
include_str!("asm/hash/blake2b/permutations.asm"),
|
||||
include_str!("asm/hash/blake2b/store.asm"),
|
||||
include_str!("asm/hash/blake2b/util.asm"),
|
||||
include_str!("asm/hash/ripemd/box.asm"),
|
||||
include_str!("asm/hash/ripemd/compression.asm"),
|
||||
include_str!("asm/hash/ripemd/constants.asm"),
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
// Load the initial hash value (the IV, but with params XOR'd into the first word).
|
||||
%macro blake_initial_hash_value
|
||||
%blake_iv_i(7)
|
||||
%blake_iv_i(6)
|
||||
%blake_iv_i(5)
|
||||
%blake_iv_i(4)
|
||||
%blake_iv_i(3)
|
||||
%blake_iv_i(2)
|
||||
%blake_iv_i(1)
|
||||
%macro blake2b_initial_hash_value
|
||||
%blake2b_iv_i(7)
|
||||
%blake2b_iv_i(6)
|
||||
%blake2b_iv_i(5)
|
||||
%blake2b_iv_i(4)
|
||||
%blake2b_iv_i(3)
|
||||
%blake2b_iv_i(2)
|
||||
%blake2b_iv_i(1)
|
||||
// stack: IV_1, IV_2, IV_3, IV_4, IV_5, IV_6, IV_7
|
||||
PUSH 0x01010040 // params: key = 00, digest_size = 64 = 0x40
|
||||
%blake_iv_i(0)
|
||||
%blake2b_iv_i(0)
|
||||
XOR
|
||||
// stack: IV_0 ^ params, IV_1, IV_2, IV_3, IV_4, IV_5, IV_6, IV_7
|
||||
%endmacro
|
||||
|
||||
// Address where the working version of the hash value is stored.
|
||||
%macro blake_hash_value_addr
|
||||
%macro blake2b_hash_value_addr
|
||||
PUSH 0
|
||||
// stack: 0
|
||||
%mload_kernel_general
|
||||
@ -26,13 +26,13 @@
|
||||
%endmacro
|
||||
|
||||
// Address where the working version of the compression internal state is stored.
|
||||
%macro blake_internal_state_addr
|
||||
%blake_hash_value_addr
|
||||
%macro blake2b_internal_state_addr
|
||||
%blake2b_hash_value_addr
|
||||
%add_const(8)
|
||||
%endmacro
|
||||
|
||||
// Address where the current message block is stored.
|
||||
%macro blake_message_addr
|
||||
%blake_internal_state_addr
|
||||
%macro blake2b_message_addr
|
||||
%blake2b_internal_state_addr
|
||||
%add_const(16)
|
||||
%endmacro
|
||||
@ -1,11 +1,11 @@
|
||||
global blake_compression:
|
||||
global blake2b_compression:
|
||||
// stack: retdest
|
||||
PUSH 0
|
||||
// stack: cur_block = 0, retdest
|
||||
%blake_initial_hash_value
|
||||
%blake2b_initial_hash_value
|
||||
compression_loop:
|
||||
// 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
|
||||
%rep 8
|
||||
SWAP1
|
||||
@ -54,13 +54,13 @@ compression_loop:
|
||||
%mul_const(128)
|
||||
%add_const(2)
|
||||
// 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
|
||||
%rep 16
|
||||
// stack: cur_message_addr, cur_block_byte, ...
|
||||
DUP2
|
||||
// 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, ...
|
||||
DUP2
|
||||
// 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
|
||||
%mul_const(0xFFFFFFFFFFFFFFFF)
|
||||
// stack: invert_if_last_block, t, cur_block, retdest
|
||||
%blake_hash_value_addr
|
||||
%blake2b_hash_value_addr
|
||||
%add_const(7)
|
||||
%rep 8
|
||||
// stack: addr, ...
|
||||
@ -100,7 +100,7 @@ compression_loop:
|
||||
// stack: addr, h_0, ..., h_7, invert_if_last_block, t, cur_block, retdest
|
||||
POP
|
||||
// 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
|
||||
// First eight words of compression state: current state h_0, ..., h_7.
|
||||
%rep 8
|
||||
@ -117,7 +117,7 @@ compression_loop:
|
||||
DUP2
|
||||
DUP2
|
||||
// stack: i, loc, i, loc,...
|
||||
%blake_iv
|
||||
%blake2b_iv
|
||||
// stack: IV_i, loc, i, loc,...
|
||||
SWAP1
|
||||
// stack: loc, IV_i, i, loc,...
|
||||
@ -149,7 +149,7 @@ compression_loop:
|
||||
// stack: i, loc, val, next_val,...
|
||||
%stack (i, loc, val) -> (i, val, loc, i, loc)
|
||||
// stack: i, val, loc, i, loc, next_val,...
|
||||
%blake_iv
|
||||
%blake2b_iv
|
||||
// stack: IV_i, val, loc, i, loc, next_val,...
|
||||
XOR
|
||||
// stack: val ^ IV_i, loc, i, loc, next_val,...
|
||||
@ -167,20 +167,20 @@ compression_loop:
|
||||
POP
|
||||
POP
|
||||
// stack: cur_block, retdest
|
||||
%blake_internal_state_addr
|
||||
%blake2b_internal_state_addr
|
||||
// stack: start, cur_block, retdest
|
||||
PUSH 0
|
||||
// stack: round=0, start, cur_block, retdest
|
||||
%rep 12
|
||||
// stack: round, start, cur_block, 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_blake2b_g_function(0, 4, 8, 12, 0, 1)
|
||||
%call_blake2b_g_function(1, 5, 9, 13, 2, 3)
|
||||
%call_blake2b_g_function(2, 6, 10, 14, 4, 5)
|
||||
%call_blake2b_g_function(3, 7, 11, 15, 6, 7)
|
||||
%call_blake2b_g_function(0, 5, 10, 15, 8, 9)
|
||||
%call_blake2b_g_function(1, 6, 11, 12, 10, 11)
|
||||
%call_blake2b_g_function(2, 7, 8, 13, 12, 13)
|
||||
%call_blake2b_g_function(3, 4, 9, 14, 14, 15)
|
||||
// stack: round, start, cur_block, retdest
|
||||
%increment
|
||||
// stack: round + 1, start, cur_block, retdest
|
||||
@ -189,14 +189,14 @@ compression_loop:
|
||||
POP
|
||||
POP
|
||||
// stack: cur_block, retdest
|
||||
%blake_generate_new_hash_value(7)
|
||||
%blake_generate_new_hash_value(6)
|
||||
%blake_generate_new_hash_value(5)
|
||||
%blake_generate_new_hash_value(4)
|
||||
%blake_generate_new_hash_value(3)
|
||||
%blake_generate_new_hash_value(2)
|
||||
%blake_generate_new_hash_value(1)
|
||||
%blake_generate_new_hash_value(0)
|
||||
%blake2b_generate_new_hash_value(7)
|
||||
%blake2b_generate_new_hash_value(6)
|
||||
%blake2b_generate_new_hash_value(5)
|
||||
%blake2b_generate_new_hash_value(4)
|
||||
%blake2b_generate_new_hash_value(3)
|
||||
%blake2b_generate_new_hash_value(2)
|
||||
%blake2b_generate_new_hash_value(1)
|
||||
%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
|
||||
DUP9
|
||||
// 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
|
||||
// stack: dummy=0, h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest
|
||||
SWAP1
|
||||
%invert_bytes_blake_word
|
||||
%invert_bytes_blake2b_word
|
||||
SWAP1
|
||||
SWAP2
|
||||
%invert_bytes_blake_word
|
||||
%invert_bytes_blake2b_word
|
||||
SWAP2
|
||||
SWAP3
|
||||
%invert_bytes_blake_word
|
||||
%invert_bytes_blake2b_word
|
||||
SWAP3
|
||||
SWAP4
|
||||
%invert_bytes_blake_word
|
||||
%invert_bytes_blake2b_word
|
||||
SWAP4
|
||||
SWAP5
|
||||
%invert_bytes_blake_word
|
||||
%invert_bytes_blake2b_word
|
||||
SWAP5
|
||||
SWAP6
|
||||
%invert_bytes_blake_word
|
||||
%invert_bytes_blake2b_word
|
||||
SWAP6
|
||||
SWAP7
|
||||
%invert_bytes_blake_word
|
||||
%invert_bytes_blake2b_word
|
||||
SWAP7
|
||||
SWAP8
|
||||
%invert_bytes_blake_word
|
||||
%invert_bytes_blake2b_word
|
||||
SWAP8
|
||||
POP
|
||||
%shl_const(64)
|
||||
@ -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
|
||||
// are in the range 0..16) in the internal state.
|
||||
// The internal state is stored in memory starting at the address start.
|
||||
@ -94,23 +94,23 @@
|
||||
%mstore_kernel_general
|
||||
%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
|
||||
PUSH $y_idx
|
||||
DUP2
|
||||
// stack: round, y_idx, round, start
|
||||
%blake_permutation
|
||||
%blake2b_permutation
|
||||
// stack: s[y_idx], round, start
|
||||
%blake_message_addr
|
||||
%blake2b_message_addr
|
||||
ADD
|
||||
%mload_kernel_general
|
||||
// stack: m[s[y_idx]], round, start
|
||||
PUSH $x_idx
|
||||
DUP3
|
||||
// stack: round, 2, m[s[y_idx]], round, start
|
||||
%blake_permutation
|
||||
%blake2b_permutation
|
||||
// stack: s[x_idx], m[s[y_idx]], round, start
|
||||
%blake_message_addr
|
||||
%blake2b_message_addr
|
||||
ADD
|
||||
%mload_kernel_general
|
||||
// stack: m[s[x_idx]], m[s[y_idx]], round, start
|
||||
@ -121,6 +121,6 @@
|
||||
PUSH $b
|
||||
PUSH $a
|
||||
// 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
|
||||
%endmacro
|
||||
@ -1,13 +1,13 @@
|
||||
%macro blake_generate_new_hash_value(i)
|
||||
%blake_hash_value_addr
|
||||
%macro blake2b_generate_new_hash_value(i)
|
||||
%blake2b_hash_value_addr
|
||||
%add_const($i)
|
||||
%mload_kernel_general
|
||||
// stack: h_i, ...
|
||||
%blake_internal_state_addr
|
||||
%blake2b_internal_state_addr
|
||||
%add_const($i)
|
||||
%mload_kernel_general
|
||||
// stack: v_i, h_i, ...
|
||||
%blake_internal_state_addr
|
||||
%blake2b_internal_state_addr
|
||||
%add_const($i)
|
||||
%add_const(8)
|
||||
%mload_kernel_general
|
||||
@ -1,4 +1,4 @@
|
||||
global blake_iv_const:
|
||||
global blake2b_iv_const:
|
||||
// IV constants (big-endian)
|
||||
|
||||
// IV_0
|
||||
@ -33,19 +33,19 @@ global blake_iv_const:
|
||||
BYTES 91, 224, 205, 25
|
||||
BYTES 19, 126, 33, 121
|
||||
|
||||
%macro blake_iv
|
||||
%macro blake2b_iv
|
||||
// stack: i, ...
|
||||
PUSH blake_iv_const
|
||||
// stack: blake_iv_const, i, ...
|
||||
PUSH blake2b_iv_const
|
||||
// stack: blake2b_iv_const, i, ...
|
||||
SWAP1
|
||||
// stack: i, blake_iv_const, ...
|
||||
// stack: i, blake2b_iv_const, ...
|
||||
%mul_const(8)
|
||||
ADD
|
||||
// stack: blake_iv_const + 2 * i, ...
|
||||
// stack: blake2b_iv_const + 2 * i, ...
|
||||
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)
|
||||
// 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
|
||||
SWAP1
|
||||
%mload_kernel_code_u32
|
||||
@ -56,7 +56,7 @@ global blake_iv_const:
|
||||
// stack: IV_i, ...
|
||||
%endmacro
|
||||
|
||||
%macro blake_iv_i(i)
|
||||
%macro blake2b_iv_i(i)
|
||||
PUSH $i
|
||||
%blake_iv
|
||||
%blake2b_iv
|
||||
%endmacro
|
||||
@ -178,7 +178,7 @@ global permutation_9_constants:
|
||||
BYTES 13
|
||||
BYTES 0
|
||||
|
||||
%macro blake_permutation
|
||||
%macro blake2b_permutation
|
||||
// stack: round, i
|
||||
PUSH permutation_0_constants
|
||||
// stack: permutation_0_constants, round, i
|
||||
@ -1,7 +1,7 @@
|
||||
global blake:
|
||||
%jump(blake_store)
|
||||
global blake2b:
|
||||
%jump(blake2b_store)
|
||||
|
||||
global blake_store:
|
||||
global blake2b_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
|
||||
@ -42,4 +42,4 @@ store_end:
|
||||
// stack: addr, counter, retdest
|
||||
%pop2
|
||||
// stack: retdest
|
||||
%jump(blake_compression)
|
||||
%jump(blake2b_compression)
|
||||
@ -1,5 +1,5 @@
|
||||
// Load a 64-bit word from kernel general memory.
|
||||
%macro mload_blake_word_from_bytes
|
||||
%macro mload_blake2b_word_from_bytes
|
||||
// stack: offset
|
||||
DUP1
|
||||
%mload_kernel_general_u32_LE
|
||||
@ -25,7 +25,7 @@
|
||||
%endmacro
|
||||
|
||||
// Invert the order of the eight bytes in a Blake word.
|
||||
%macro invert_bytes_blake_word
|
||||
%macro invert_bytes_blake2b_word
|
||||
// stack: word
|
||||
DUP1
|
||||
// stack: word, word
|
||||
@ -144,6 +144,6 @@ fn test_ripemd() -> Result<()> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blake() -> Result<()> {
|
||||
test_hash_512("blake", &blake2b)
|
||||
fn test_blake2b() -> Result<()> {
|
||||
test_hash_512("blake2b", &blake2b)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user