mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 08:13:11 +00:00
restored blake2b_g_function and call_blake2b_g_function macros
This commit is contained in:
parent
0f55956ade
commit
fda2e19054
@ -1,89 +1,89 @@
|
|||||||
blake2b_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.
|
||||||
// stack: a, b, c, d, x, y, start, retdest
|
// stack: a, b, c, d, x, y, start
|
||||||
%stack (indices: 4) -> (indices, indices)
|
%stack (indices: 4) -> (indices, indices)
|
||||||
// stack: a, b, c, d, a, b, c, d, x, y, start, retdest
|
// stack: a, b, c, d, a, b, c, d, x, y, start
|
||||||
DUP11
|
DUP11
|
||||||
// stack: start, a, b, c, d, a, b, c, d, x, y, start, retdest
|
// stack: start, a, b, c, d, a, b, c, d, x, y, start
|
||||||
%stack (start, a, b, c, d) -> (d, start, c, start, b, start, a, start)
|
%stack (start, a, b, c, d) -> (d, start, c, start, b, start, a, start)
|
||||||
// stack: d, start, c, start, b, start, a, start, a, b, c, d, x, y, start, retdest
|
// stack: d, start, c, start, b, start, a, start, a, b, c, d, x, y, start
|
||||||
ADD
|
ADD
|
||||||
%mload_kernel_general
|
%mload_kernel_general
|
||||||
// stack: v[d], c, start, b, start, a, start, a, b, c, d, x, y, start, retdest
|
// stack: v[d], c, start, b, start, a, start, a, b, c, d, x, y, start
|
||||||
%stack (vd, remaining: 6) -> (remaining, vd)
|
%stack (vd, remaining: 6) -> (remaining, vd)
|
||||||
// stack: c, start, b, start, a, start, v[d], a, b, c, d, x, y, start, retdest
|
// stack: c, start, b, start, a, start, v[d], a, b, c, d, x, y, start
|
||||||
ADD
|
ADD
|
||||||
%mload_kernel_general
|
%mload_kernel_general
|
||||||
%stack (vc, remaining: 4) -> (remaining, vc)
|
%stack (vc, remaining: 4) -> (remaining, vc)
|
||||||
// stack: b, start, a, start, v[c], v[d], a, b, c, d, x, y, start, retdest
|
// stack: b, start, a, start, v[c], v[d], a, b, c, d, x, y, start
|
||||||
ADD
|
ADD
|
||||||
%mload_kernel_general
|
%mload_kernel_general
|
||||||
// stack: v[b], a, start, v[c], v[d], a, b, c, d, x, y, start, retdest
|
// stack: v[b], a, start, v[c], v[d], a, b, c, d, x, y, start
|
||||||
%stack (vb, remaining: 2) -> (remaining, vb)
|
%stack (vb, remaining: 2) -> (remaining, vb)
|
||||||
// stack: a, start, v[b], v[c], v[d], a, b, c, d, x, y, start, retdest
|
// stack: a, start, v[b], v[c], v[d], a, b, c, d, x, y, start
|
||||||
ADD
|
ADD
|
||||||
%mload_kernel_general
|
%mload_kernel_general
|
||||||
// stack: v[a], v[b], v[c], v[d], a, b, c, d, x, y, start, retdest
|
// stack: v[a], v[b], v[c], v[d], a, b, c, d, x, y, start
|
||||||
DUP2
|
DUP2
|
||||||
// stack: v[b], v[a], v[b], v[c], v[d], a, b, c, d, x, y, start, retdest
|
// stack: v[b], v[a], v[b], v[c], v[d], a, b, c, d, x, y, start
|
||||||
DUP10
|
DUP10
|
||||||
// stack: x, v[b], v[a], v[b], v[c], v[d], a, b, c, d, x, y, start, retdest
|
// stack: x, v[b], v[a], v[b], v[c], v[d], a, b, c, d, x, y, start
|
||||||
ADD
|
ADD
|
||||||
ADD
|
ADD
|
||||||
%as_u64
|
%as_u64
|
||||||
// stack: v[a]' = (v[a] + v[b] + x) % 2^64, v[b], v[c], v[d], a, b, c, d, x, y, start, retdest
|
// stack: v[a]' = (v[a] + v[b] + x) % 2^64, v[b], v[c], v[d], a, b, c, d, x, y, start
|
||||||
%stack (a, b, c, d) -> (a, d, a, b, c, d)
|
%stack (a, b, c, d) -> (a, d, a, b, c, d)
|
||||||
// stack: v[a]', v[d], v[a]', v[b], v[c], v[d], a, b, c, d, x, y, start, retdest
|
// stack: v[a]', v[d], v[a]', v[b], v[c], v[d], a, b, c, d, x, y, start
|
||||||
XOR
|
XOR
|
||||||
%rotr_64(32)
|
%rotr_64(32)
|
||||||
// stack: v[d]' = (v[d] ^ v[a]') >>> 32, v[a]', v[b], v[c], v[d], a, b, c, d, x, y, start, retdest
|
// stack: v[d]' = (v[d] ^ v[a]') >>> 32, v[a]', v[b], v[c], v[d], a, b, c, d, x, y, start
|
||||||
%stack (top: 4, vd) -> (top)
|
%stack (top: 4, vd) -> (top)
|
||||||
// stack: v[d]', v[a]', v[b], v[c], a, b, c, d, x, y, start, retdest
|
// stack: v[d]', v[a]', v[b], v[c], a, b, c, d, x, y, start
|
||||||
%stack (d, a, b, c) -> (c, d, a, b, d)
|
%stack (d, a, b, c) -> (c, d, a, b, d)
|
||||||
// stack: v[c], v[d]', v[a]', v[b], v[d]', a, b, c, d, x, y, start, retdest
|
// stack: v[c], v[d]', v[a]', v[b], v[d]', a, b, c, d, x, y, start
|
||||||
ADD
|
ADD
|
||||||
%as_u64
|
%as_u64
|
||||||
// stack: v[c]' = (v[c] + v[d]') % 2^64, v[a]', v[b], v[d]', a, b, c, d, x, y, start, retdest
|
// stack: v[c]' = (v[c] + v[d]') % 2^64, v[a]', v[b], v[d]', a, b, c, d, x, y, start
|
||||||
%stack (c, a, b, d) -> (b, c, a, c, d)
|
%stack (c, a, b, d) -> (b, c, a, c, d)
|
||||||
// stack: v[b], v[c]', v[a]', v[c]', v[d]', a, b, c, d, x, y, start, retdest
|
// stack: v[b], v[c]', v[a]', v[c]', v[d]', a, b, c, d, x, y, start
|
||||||
XOR
|
XOR
|
||||||
%rotr_64(24)
|
%rotr_64(24)
|
||||||
// stack: v[b]' = (v[b] ^ v[c]') >>> 24, v[a]', v[c]', v[d]', a, b, c, d, x, y, start, retdest
|
// stack: v[b]' = (v[b] ^ v[c]') >>> 24, v[a]', v[c]', v[d]', a, b, c, d, x, y, start
|
||||||
SWAP1
|
SWAP1
|
||||||
// stack: v[a]', v[b]', v[c]', v[d]', a, b, c, d, x, y, start, retdest
|
// stack: v[a]', v[b]', v[c]', v[d]', a, b, c, d, x, y, start
|
||||||
DUP2
|
DUP2
|
||||||
// stack: v[b]', v[a]', v[b]', v[c]', v[d]', a, b, c, d, x, y, start, retdest
|
// stack: v[b]', v[a]', v[b]', v[c]', v[d]', a, b, c, d, x, y, start
|
||||||
DUP11
|
DUP11
|
||||||
// stack: y, v[b]', v[a]', v[b]', v[c]', v[d]', a, b, c, d, x, y, start, retdest
|
// stack: y, v[b]', v[a]', v[b]', v[c]', v[d]', a, b, c, d, x, y, start
|
||||||
ADD
|
ADD
|
||||||
ADD
|
ADD
|
||||||
%as_u64
|
%as_u64
|
||||||
// stack: v[a]'' = (v[a]' + v[b]' + y) % 2^64, v[b]', v[c]', v[d]', a, b, c, d, x, y, start, retdest
|
// stack: v[a]'' = (v[a]' + v[b]' + y) % 2^64, v[b]', v[c]', v[d]', a, b, c, d, x, y, start
|
||||||
SWAP3
|
SWAP3
|
||||||
// stack: v[d]', v[b]', v[c]', v[a]'', a, b, c, d, x, y, start, retdest
|
// stack: v[d]', v[b]', v[c]', v[a]'', a, b, c, d, x, y, start
|
||||||
DUP4
|
DUP4
|
||||||
// stack: v[a]'', v[d]', v[b]', v[c]', v[a]'', a, b, c, d, x, y, start, retdest
|
// stack: v[a]'', v[d]', v[b]', v[c]', v[a]'', a, b, c, d, x, y, start
|
||||||
XOR
|
XOR
|
||||||
%rotr_64(16)
|
%rotr_64(16)
|
||||||
// stack: v[d]'' = (v[a]'' ^ v[d]') >>> 8, v[b]', v[c]', v[a]'', a, b, c, d, x, y, start, retdest
|
// stack: v[d]'' = (v[a]'' ^ v[d]') >>> 8, v[b]', v[c]', v[a]'', a, b, c, d, x, y, start
|
||||||
SWAP2
|
SWAP2
|
||||||
// stack: v[c]', v[b]', v[d]'', v[a]'', a, b, c, d, x, y, start, retdest
|
// stack: v[c]', v[b]', v[d]'', v[a]'', a, b, c, d, x, y, start
|
||||||
DUP3
|
DUP3
|
||||||
// stack: v[d]'', v[c]', v[b]', v[d]'', v[a]'', a, b, c, d, x, y, start, retdest
|
// stack: v[d]'', v[c]', v[b]', v[d]'', v[a]'', a, b, c, d, x, y, start
|
||||||
ADD
|
ADD
|
||||||
%as_u64
|
%as_u64
|
||||||
// stack: v[c]'' = (v[c]' + v[d]'') % 2^64, v[b]', v[d]'', v[a]'', a, b, c, d, x, y, start, retdest
|
// stack: v[c]'' = (v[c]' + v[d]'') % 2^64, v[b]', v[d]'', v[a]'', a, b, c, d, x, y, start
|
||||||
DUP1
|
DUP1
|
||||||
// stack: v[c]'', v[c]'', v[b]', v[d]'', v[a]'', a, b, c, d, x, y, start, retdest
|
// stack: v[c]'', v[c]'', v[b]', v[d]'', v[a]'', a, b, c, d, x, y, start
|
||||||
SWAP2
|
SWAP2
|
||||||
// stack: v[b]', v[c]'', v[c]'', v[d]'', v[a]'', a, b, c, d, x, y, start, retdest
|
// stack: v[b]', v[c]'', v[c]'', v[d]'', v[a]'', a, b, c, d, x, y, start
|
||||||
XOR
|
XOR
|
||||||
%rotr_64(63)
|
%rotr_64(63)
|
||||||
// stack: v[b]'' = (v[b]' ^ v[c]'') >>> 7, v[c]'', v[d]'', v[a]'', a, b, c, d, x, y, start, retdest
|
// stack: v[b]'' = (v[b]' ^ v[c]'') >>> 7, v[c]'', v[d]'', v[a]'', a, b, c, d, x, y, start
|
||||||
%stack (vb, vc, vd, va, a, b, c, d, x, y, start) -> (start, a, va, start, b, vb, start, c, vc, start, d, vd)
|
%stack (vb, vc, vd, va, a, b, c, d, x, y, start) -> (start, a, va, start, b, vb, start, c, vc, start, d, vd)
|
||||||
// stack: start, a, v[a]'', start, b, v[b]'', start, c, v[c]'', start, d, v[d]'', retdest
|
// stack: start, a, v[a]'', start, b, v[b]'', start, c, v[c]'', start, d, v[d]''
|
||||||
ADD
|
ADD
|
||||||
%mstore_kernel_general
|
%mstore_kernel_general
|
||||||
ADD
|
ADD
|
||||||
@ -92,100 +92,53 @@ blake2b_g_function:
|
|||||||
%mstore_kernel_general
|
%mstore_kernel_general
|
||||||
ADD
|
ADD
|
||||||
%mstore_kernel_general
|
%mstore_kernel_general
|
||||||
// stack: retdest
|
%endmacro
|
||||||
JUMP
|
|
||||||
|
|
||||||
call_blake2b_g_function:
|
%macro call_blake2b_g_function(a, b, c, d, x_idx, y_idx)
|
||||||
// stack: a, b, c, d, x_idx, y_idx, round, start, retdest
|
// stack: round, start
|
||||||
DUP6
|
PUSH $y_idx
|
||||||
// stack: y_idx, a, b, c, d, x_idx, y_idx, round, start, retdest
|
DUP2
|
||||||
DUP8
|
// stack: round, y_idx, round, start
|
||||||
// stack: round, y_idx, a, b, c, d, x_idx, y_idx, round, start, retdest
|
|
||||||
%blake2b_permutation
|
%blake2b_permutation
|
||||||
// stack: s[y_idx], a, b, c, d, x_idx, y_idx, round, start, retdest
|
// stack: s[y_idx], round, start
|
||||||
%blake2b_message_addr
|
%blake2b_message_addr
|
||||||
ADD
|
ADD
|
||||||
%mload_kernel_general
|
%mload_kernel_general
|
||||||
// stack: m[s[y_idx]], a, b, c, d, x_idx, y_idx, round, start, retdest
|
// stack: m[s[y_idx]], round, start
|
||||||
DUP6
|
PUSH $x_idx
|
||||||
// stack: x_idx, m[s[y_idx]], a, b, c, d, x_idx, y_idx, round, start, retdest
|
DUP3
|
||||||
DUP9
|
// stack: round, 2, m[s[y_idx]], round, start
|
||||||
// stack: round, x_idx, m[s[y_idx]], a, b, c, d, x_idx, y_idx, round, start, retdest
|
|
||||||
%blake2b_permutation
|
%blake2b_permutation
|
||||||
// stack: s[x_idx], m[s[y_idx]], a, b, c, d, x_idx, y_idx, round, start, retdest
|
// stack: s[x_idx], m[s[y_idx]], round, start
|
||||||
%blake2b_message_addr
|
%blake2b_message_addr
|
||||||
ADD
|
ADD
|
||||||
%mload_kernel_general
|
%mload_kernel_general
|
||||||
// stack: m[s[x_idx]], m[s[y_idx]], a, b, c, d, x_idx, y_idx, round, start, retdest
|
// stack: m[s[x_idx]], m[s[y_idx]], round, start
|
||||||
%stack (mm: 2, abcd: 4, xy: 2, r, s) -> (abcd, mm, s)
|
%stack (ss: 2, r, s) -> (ss, s, r, s)
|
||||||
// stack: a, b, c, d, m[s[x_idx]], m[s[y_idx]], start, retdest
|
// stack: m[s[x_idx]], m[s[y_idx]], start, round, start
|
||||||
%jump(blake2b_g_function)
|
PUSH $d
|
||||||
|
PUSH $c
|
||||||
|
PUSH $b
|
||||||
|
PUSH $a
|
||||||
|
// stack: a, b, c, d, m[s[x_idx]], m[s[y_idx]], start, round, start
|
||||||
|
%blake2b_g_function
|
||||||
|
// stack: round, start
|
||||||
|
%endmacro
|
||||||
|
|
||||||
global run_g_function_round:
|
run_g_function_round:
|
||||||
// stack: round, start, retdest
|
// stack: round, start, retdest
|
||||||
PUSH g_function_return_1
|
%call_blake2b_g_function(0, 4, 8, 12, 0, 1)
|
||||||
// stack: g_function_return_1, round, start, retdest
|
%call_blake2b_g_function(1, 5, 9, 13, 2, 3)
|
||||||
%stack (ret, r, s) -> (0, 4, 8, 12, 0, 1, r, s, ret, r, s)
|
%call_blake2b_g_function(2, 6, 10, 14, 4, 5)
|
||||||
// stack: a=0, b=4, c=8, d=12, x_idx=0, y_idx=1, round, start, g_function_return_1, round, start, retdest
|
%call_blake2b_g_function(3, 7, 11, 15, 6, 7)
|
||||||
%jump(call_blake2b_g_function)
|
%call_blake2b_g_function(0, 5, 10, 15, 8, 9)
|
||||||
g_function_return_1:
|
%call_blake2b_g_function(1, 6, 11, 12, 10, 11)
|
||||||
// stack: round, start, retdest
|
%call_blake2b_g_function(2, 7, 8, 13, 12, 13)
|
||||||
PUSH g_function_return_2
|
%call_blake2b_g_function(3, 4, 9, 14, 14, 15)
|
||||||
// stack: g_function_return_2, round, start, retdest
|
%stack (r, s, ret) -> (ret, r, s)
|
||||||
%stack (ret, r, s) -> (1, 5, 9, 13, 2, 3, r, s, ret, r, s)
|
|
||||||
// stack: a=1, b=5, c=9, d=13, x_idx=2, y_idx=3, round, start, g_function_return_2, round, start, retdest
|
|
||||||
%jump(call_blake2b_g_function)
|
|
||||||
g_function_return_2:
|
|
||||||
// stack: round, start, retdest
|
|
||||||
PUSH g_function_return_3
|
|
||||||
// stack: g_function_return_3, round, start, retdest
|
|
||||||
%stack (ret, r, s) -> (2, 6, 10, 14, 4, 5, r, s, ret, r, s)
|
|
||||||
// stack: a=2, b=6, c=10, d=14, x_idx=4, y_idx=5, round, start, g_function_return_3, round, start, retdest
|
|
||||||
%jump(call_blake2b_g_function)
|
|
||||||
g_function_return_3:
|
|
||||||
// stack: round, start, retdest
|
|
||||||
PUSH g_function_return_4
|
|
||||||
// stack: g_function_return_4, round, start, retdest
|
|
||||||
%stack (ret, r, s) -> (3, 7, 11, 15, 6, 7, r, s, ret, r, s)
|
|
||||||
// stack: a=3, b=7, c=11, d=15, x_idx=6, y_idx=7, round, start, g_function_return_4, round, start, retdest
|
|
||||||
%jump(call_blake2b_g_function)
|
|
||||||
g_function_return_4:
|
|
||||||
// stack: round, start, retdest
|
|
||||||
PUSH g_function_return_5
|
|
||||||
// stack: g_function_return_5, round, start, retdest
|
|
||||||
%stack (ret, r, s) -> (0, 5, 10, 15, 8, 9, r, s, ret, r, s)
|
|
||||||
// stack: a=0, b=5, c=10, d=15, x_idx=8, y_idx=9, round, start, g_function_return_5, round, start, retdest
|
|
||||||
%jump(call_blake2b_g_function)
|
|
||||||
g_function_return_5:
|
|
||||||
// stack: round, start, retdest
|
|
||||||
PUSH g_function_return_6
|
|
||||||
// stack: g_function_return_6, round, start, retdest
|
|
||||||
%stack (ret, r, s) -> (1, 6, 11, 12, 10, 11, r, s, ret, r, s)
|
|
||||||
// stack: a=1, b=6, c=11, d=12, x_idx=10, y_idx=11, round, start, g_function_return_6, round, start, retdest
|
|
||||||
%jump(call_blake2b_g_function)
|
|
||||||
g_function_return_6:
|
|
||||||
// stack: round, start, retdest
|
|
||||||
PUSH g_function_return_7
|
|
||||||
// stack: g_function_return_7, round, start, retdest
|
|
||||||
%stack (ret, r, s) -> (2, 7, 8, 13, 12, 13, r, s, ret, r, s)
|
|
||||||
// stack: a=2, b=7, c=8, d=13, x_idx=12, y_idx=13, round, start, g_function_return_7, round, start, retdest
|
|
||||||
%jump(call_blake2b_g_function)
|
|
||||||
g_function_return_7:
|
|
||||||
// stack: round, start, retdest
|
|
||||||
PUSH g_function_return_8
|
|
||||||
// stack: g_function_return_8, round, start, retdest
|
|
||||||
%stack (ret, r, s) -> (3, 4, 9, 14, 14, 15, r, s, ret, r, s)
|
|
||||||
// stack: a=3, b=4, c=9, d=14, x_idx=14, y_idx=15, round, start, g_function_return_8, round, start, retdest
|
|
||||||
%jump(call_blake2b_g_function)
|
|
||||||
g_function_return_8:
|
|
||||||
// stack: round, start, retdest
|
|
||||||
SWAP1
|
|
||||||
// stack: start, round, retdest
|
|
||||||
SWAP2
|
|
||||||
// stack: retdest, round, start
|
// stack: retdest, round, start
|
||||||
JUMP
|
JUMP
|
||||||
|
|
||||||
|
|
||||||
global run_12_rounds_g_function:
|
global run_12_rounds_g_function:
|
||||||
// stack: start, retdest
|
// stack: start, retdest
|
||||||
PUSH 0
|
PUSH 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user