.struct ctx_a + 8 * 5 * 5
ctx_r:
.struct ctx_r + 2
-ctx_c:
- .struct ctx_c + 2
-ctx_d:
- .struct ctx_d + 1
ctx_bs:
.section .text
*/
; memcpy(a, b, 200)
; X points at b + 32 + 8 = b + 40 = b[1][0] has to point to b[0][0]
- ldi r16, 200
+ ldi r16, 200 / 8
sbiw XL, 5 * 8
movw ZL, XL
subi YL, lo8(5 * 5 * 8)
sbci YH, hi8(5 * 5 * 8)
movw r2, YL
10:
+ .rept 8
ld r22, X+
st Y+, r22
+ .endr
dec r16
brne 10b
ret
.endfunc
+
+ .global keccak224_ctx2hash
+ .func keccak224_ctx2hash
+keccak224_ctx2hash:
+ movw r20, r22
+ ldi r22, lo8(224)
+ ldi r23, hi8(224)
+ rjmp keccak_ctx2hash
+ .endfunc
+
+ .global keccak384_ctx2hash
+ .func keccak384_ctx2hash
+keccak384_ctx2hash:
+ movw r20, r22
+ ldi r22, lo8(384)
+ ldi r23, hi8(384)
+ rjmp keccak_ctx2hash
+ .endfunc
+
+ .global keccak512_ctx2hash
+ .func keccak512_ctx2hash
+keccak512_ctx2hash:
+ movw r20, r22
+ ldi r22, lo8(512)
+ ldi r23, hi8(512)
+ rjmp keccak_ctx2hash
+ .endfunc
+
+ .global keccak256_ctx2hash
+ .func keccak256_ctx2hash
+keccak256_ctx2hash:
+ movw r20, r22
+ ldi r22, lo8(256)
+ ldi r23, hi8(256)
+ .endfunc
+
/*
void keccak_ctx2hash(void* dest, uint16_t length_b, keccak_ctx_t* ctx){
while(length_b>=ctx->r){
push_range 2, 10
movw r4, r20
movw r6, r24
- movw ZL, r24
+ movw ZL, r20
movw r8, r22
subi ZL, lo8(-ctx_r)
- subi ZH, hi8(-ctx_r)
+ sbci ZH, hi8(-ctx_r)
ld r2, Z+
ld r3, Z+
ldd r10, Z+3 ; load blocksize (in bytes)
10:
- cp r8, r2
- cpc r9, r3
- brcc 40f
+ ; length_b = (r9:r8) ; r = (r3:r2) ; (H:L)
+ cp r2, r8
+ cpc r3, r9
+; rjmp 40f
+ brsh 40f
movw XL, r4
movw ZL, r6
mov r24, r10
ret
.endfunc
+
+ .global keccak224_init
+ .func keccak224_init
+keccak224_init:
+ movw XL, r24
+ ldi r24, lo8(1152)
+ ldi r25, hi8(1152)
+ rjmp keccak_init_1
+ .endfunc
+
+ .global keccak384_init
+ .func keccak384_init
+keccak384_init:
+ movw XL, r24
+ ldi r24, lo8( 832)
+ ldi r25, hi8( 832)
+ rjmp keccak_init_1
+ .endfunc
+
+ .global keccak512_init
+ .func keccak512_init
+keccak512_init:
+ movw XL, r24
+ ldi r24, lo8( 576)
+ ldi r25, hi8( 576)
+ rjmp keccak_init_1
+ .endfunc
+
+ .global keccak256_init
+ .func keccak256_init
+keccak256_init:
+ movw r22, r24
+ ldi r24, lo8(1088)
+ ldi r25, hi8(1088)
+ .endfunc
+/*
+void keccak_init(uint16_t r, keccak_ctx_t* ctx){
+ memset(ctx->a, 0x00, 5 * 5 * 8);
+ ctx->r = r;
+ ctx->bs = (uint8_t)(r / 8);
+}
+*/
+ .global keccak_init
+ .func keccak_init
+keccak_init:
+ movw XL, r22
+keccak_init_1:
+ ldi r22, 200
+10:
+ st X+, __zero_reg__
+ dec r22
+ brne 10b
+ st X+, r24
+ st X+, r25
+ lsr r25
+ ror r24
+ lsr r25
+ ror r24
+ lsr r25
+ ror r24
+ st X+, r24
+ ret
+ .endfunc
+