mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 23:03:08 +00:00
outer function
This commit is contained in:
parent
fa69f2a7fb
commit
ffbb6fc617
@ -2,7 +2,7 @@
|
||||
/// Note that state takes up 5 stack slots
|
||||
|
||||
|
||||
/// def hash(state, _block):
|
||||
/// def compression(state, _block):
|
||||
///
|
||||
/// stateL = state
|
||||
/// stateL = loop(stateL)
|
||||
@ -24,7 +24,7 @@
|
||||
/// where si, li, ri, oi, BL, RD respectively denote
|
||||
/// state[i], stateL[i], stateR[i], output[i], block, retdest
|
||||
|
||||
global hash:
|
||||
global compression:
|
||||
// stack: *state, block, retdest
|
||||
PUSH switch
|
||||
DUP7
|
||||
@ -42,7 +42,7 @@ global hash:
|
||||
// stack: *state, 0, 0, 16, 5, 1, block, switch, *state, block, retdest
|
||||
%jump(loop)
|
||||
switch:
|
||||
// stack: *stateL, *state, block, retdest
|
||||
// stack: *stateL, *state, block, retdest
|
||||
PUSH mix
|
||||
DUP12
|
||||
PUSH 0
|
||||
@ -50,7 +50,7 @@ switch:
|
||||
PUSH 16
|
||||
PUSH 0
|
||||
PUSH 0
|
||||
// stack: 0, 0, 16, 5, 0, block, mix, *stateL, *state, block, retdest
|
||||
// stack: 0, 0, 16, 5, 0, block, mix, *stateL, *state, block, retdest
|
||||
DUP17
|
||||
DUP17
|
||||
DUP17
|
||||
@ -177,10 +177,10 @@ round:
|
||||
///
|
||||
/// box = get_box(sides, rounds, boxes)
|
||||
/// a += F(b, c, d)
|
||||
/// r = load_r(box)
|
||||
/// r = load_byte(r)(box)
|
||||
/// x = load_block(r)
|
||||
/// a += x + K
|
||||
/// s = load_s(box)
|
||||
/// s = load_byte(s)(box)
|
||||
/// a = rol(s, a)
|
||||
/// a += e
|
||||
/// c = rol(10, c)
|
||||
@ -198,15 +198,15 @@ box:
|
||||
// stack: F, b, c, d, pre_rol, a, b, c, d, e, F, K, boxes, rounds, sides, block
|
||||
JUMP
|
||||
pre_rol:
|
||||
// stack: F(b, c, d), a, b, c, d, e, F, K, boxes, rounds, sides, block
|
||||
// stack: F(b, c, d), a, b, c, d, e, F, K, boxes, rounds, sides, block
|
||||
ADD
|
||||
// stack: a, b, c, d, e, F, K, boxes, rounds, sides, block
|
||||
// stack: a, b, c, d, e, F, K, boxes, rounds, sides, block
|
||||
%get_box
|
||||
// stack: box, a, b, c, d, e, F, K, boxes, rounds, sides, block
|
||||
DUP12
|
||||
DUP2
|
||||
// stack: box, a, b, c, d, e, F, K, boxes, rounds, sides, block
|
||||
DUP1
|
||||
%load_byte(R_data)
|
||||
// stack: r, block, box, a, b, c, d, e, F, K, boxes, rounds, sides, block
|
||||
DUP13
|
||||
// stack: block, r, box, a, b, c, d, e, F, K, boxes, rounds, sides, block
|
||||
%load_block
|
||||
// stack: x, box, a, b, c, d, e, F, K, boxes, rounds, sides, block
|
||||
SWAP1
|
||||
@ -273,9 +273,3 @@ post_rol:
|
||||
SUB
|
||||
// stack: 176 - boxes - 16*rounds - 80*sides, *7_args, boxes, rounds, sides
|
||||
%endmacro
|
||||
|
||||
|
||||
%macro load_block
|
||||
// stack: r, block
|
||||
%mload_kernel(@SEGMENT_KERNEL_GENERAL)
|
||||
%endmacro
|
||||
@ -1,43 +1,71 @@
|
||||
global ripemd:
|
||||
JUMPDEST
|
||||
// stack: retdest
|
||||
PUSH 0xC3D2E1F0
|
||||
PUSH 0x10325476
|
||||
PUSH 0x98BADCFE
|
||||
PUSH 0xEFCDAB89
|
||||
PUSH 0x67452301
|
||||
// stack: 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0, retdest
|
||||
/// Variables beginning with _ are in memory and not on the stack
|
||||
/// ripemd_update will receive and return the stack in the form:
|
||||
/// stack: *state, count, length, offset
|
||||
/// where offset is the virtual address of its final positional argument
|
||||
///
|
||||
/// def ripemd160(_input):
|
||||
/// state, count, _buffer = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0], 0, [0]*64
|
||||
/// state, count, _buffer = ripemd_update(state, count, _buffer, len(_input), _input)
|
||||
/// _padding = [0x80]+[0]*63
|
||||
/// _size = get_size(count)
|
||||
/// state, count, _buffer = ripemd_update(state, count, _buffer, padlength(count), _padding)
|
||||
/// state, count, _buffer = ripemd_update(state, count, _buffer, 8, _size)
|
||||
/// return process(state)
|
||||
|
||||
global ripemd:
|
||||
// stack: ADDR, length
|
||||
%store_buffer // store _buffer at location 0
|
||||
%store_input // store _input at location 64
|
||||
// stack: length
|
||||
%stack (length) -> ( 0, length, 64, ripemd_1, ripemd_2, process)
|
||||
// stack: count = 0, length, offset = 64, ripemd_1, ripemd_2, process
|
||||
%stack (c, l, o, l1, l2, l3) -> (0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0, c, l, o, l1, l2, l3)
|
||||
// stack: 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0, count, length, offset, *labels
|
||||
%jump(ripemd_update)
|
||||
ripemd_1:
|
||||
// stack: *state, count, length, offset, *labels
|
||||
DUP6
|
||||
DUP1
|
||||
// stack: count, count, *state, count, length, offset, *labels
|
||||
%store_padding // store _padding at location 64
|
||||
%store_size // store _size at location 128 [note: consumes count]
|
||||
%padlength
|
||||
// stack: padlength, *state, count, length, offset, *labels
|
||||
SWAP7
|
||||
POP
|
||||
// stack: *state, count, length, offset, *labels
|
||||
%jump(ripemd_update)
|
||||
ripemd_2:
|
||||
// stack: *state, count, length, offset, *labels
|
||||
%stack (a, b, c, d, e, count, length, offset) -> (a, b, c, d, e, count, 8, 128)
|
||||
// stack: *state, count, length, offset, *labels
|
||||
%jump(ripemd_update)
|
||||
process:
|
||||
JUMPDEST
|
||||
// stack: a , b, c, d, e, count, retdest
|
||||
// stack: a , b, c, d, e, count, length, offset
|
||||
%flip_bytes_u32
|
||||
// stack: a', b, c, d, e, count, retdest
|
||||
// stack: a', b, c, d, e, *vars
|
||||
SWAP1
|
||||
%flip_bytes_32
|
||||
%shl_const(32)
|
||||
OR
|
||||
// stack: b' a', c, d, e, count, retdest
|
||||
// stack: b' a', c, d, e, *vars
|
||||
SWAP1
|
||||
%flip_bytes_32
|
||||
%shl_const(64)
|
||||
OR
|
||||
// stack: c' b' a', d, e, count, retdest
|
||||
// stack: c' b' a', d, e, *vars
|
||||
SWAP1
|
||||
%flip_bytes_32
|
||||
%shl_const(96)
|
||||
OR
|
||||
// stack: d' c' b' a', e, count, retdest
|
||||
// stack: d' c' b' a', e, *vars
|
||||
SWAP1
|
||||
%flip_bytes_32
|
||||
%shl_const(96)
|
||||
OR
|
||||
// stack: e' d' c' b' a', count, retdest
|
||||
SWAP2
|
||||
SWAP1
|
||||
POP
|
||||
// stack: retdest, e'd'c'b'a'
|
||||
JUMP
|
||||
// stack: e' d' c' b' a', *vars
|
||||
%stack (result, x, y, z) -> result
|
||||
// stack: result
|
||||
|
||||
|
||||
/// def padlength(count):
|
||||
@ -60,4 +88,4 @@ process:
|
||||
// stack: 64*(x < 9) , x
|
||||
ADD
|
||||
// stack: 64*(x < 9) + x
|
||||
%endmacro
|
||||
%endmacro
|
||||
|
||||
0
evm/src/cpu/kernel/asm/ripemd/storage_macros.asm
Normal file
0
evm/src/cpu/kernel/asm/ripemd/storage_macros.asm
Normal file
0
evm/src/cpu/kernel/asm/ripemd/update.asm
Normal file
0
evm/src/cpu/kernel/asm/ripemd/update.asm
Normal file
Loading…
x
Reference in New Issue
Block a user