sha1_lastBlock:
- tst r20
- brne sha1_lastBlock_prolog
cpi r21, 0x02
- brne sha1_lastBlock_prolog
+ brlo sha1_lastBlock_prolog
push r25
push r24
push r23
push r22
+ push r21
+ push r20
rcall sha1_nextBlock
+ pop r20
+ pop r21
pop r22
pop r23
pop r24
pop r25
- clr r21
- clr r22
+ subi r21, 2
+ subi r23, -2
+ rjmp sha1_lastBlock
sha1_lastBlock_prolog:
/* allocate space on stack */
in r30, SPL
adc T4, tmp1
/* T = ROTL(a,5) + e + kt + w[s] */
- /* wo Z-4 gerade auf kt zeigt ... */
+ /* Z-4 is just pointing to kt ... */
movw r28, r26 /* copy X in Y */
adiw r30, 3*4 /* now Z points to the rigth locatin in our jump-vector-table */
lsr r31
inc LoopC
cpi LoopC, 80
brge 1f
- jmp sha1_nextBlock_mainloop
+ rjmp sha1_nextBlock_mainloop
/**************************************/
1:
/* littel patch */
.int 0x8f1bbcdc
.int 0xca62c1d6
sha1_nextBlock_JumpTable:
-jmp sha1_nextBlock_Ch
-jmp sha1_nextBlock_Parity
-jmp sha1_nextBlock_Maj
-jmp sha1_nextBlock_Parity
+rjmp sha1_nextBlock_Ch
+ nop
+rjmp sha1_nextBlock_Parity
+ nop
+rjmp sha1_nextBlock_Maj
+ nop
+rjmp sha1_nextBlock_Parity
/* X and Y still point at a[1] aka b ; return value in tmp1 */
sha1_nextBlock_Ch:
ldd tmp3, Y+7 /* load from d */
and tmp2, tmp3
eor tmp1, tmp2
- /**
- precall
- ldi r24, lo8(ch_str)
- ldi r25, hi8(ch_str)
- call uart_putstr_P
- postcall
- /**/
ret
sha1_nextBlock_Maj:
eor tmp1, tmp2
and tmp3, tmp4
eor tmp1, tmp3
- /**
- precall
- ldi r24, lo8(maj_str)
- ldi r25, hi8(maj_str)
- call uart_putstr_P
- postcall
- /**/
ret
sha1_nextBlock_Parity:
eor tmp1, tmp2
ldd tmp2, Y+7 /* load from d */
eor tmp1, tmp2
-
- /**
- precall
- ldi r24, lo8(parity_str)
- ldi r25, hi8(parity_str)
- call uart_putstr_P
- postcall
- /**/
ret
/*
ch_str: .asciz "\r\nCh"
dec r22
brne sha1_init_vloop
ldi r22, 8
- clr r1 /* this should not be needed */
sha1_init_lloop:
st X+, r1
dec r22
.int 0x98badcfe;
.int 0x10325476;
.int 0xc3d2e1f0;
-/*
-;###########################################################
-.global rotl32
-; === ROTL32 ===
-; function that rotates a 32 bit word to the left
-; param1: the 32-bit word to rotate
-; given in r25,r24,r23,r22 (r25 is most significant)
-; param2: an 8-bit value telling how often to rotate
-; given in r20
-; modifys: r21, r22
-rotl32:
- cpi r20, 8
- brlo bitrotl
- mov r21, r25
- mov r25, r24
- mov r24, r23
- mov r23, r22
- mov r22, r21
- subi r20, 8
- rjmp rotr32
-bitrotl:
- clr r21
- clc
-bitrotl_loop:
- tst r20
- breq fixrotl
- rol r22
- rol r23
- rol r24
- rol r25
- rol r21
- dec r20
- rjmp bitrotl_loop
-fixrotl:
- or r22, r21
- ret
-
-
-;###########################################################
-
-.global rotr32
-; === ROTR32 ===
-; function that rotates a 32 bit word to the right
-; param1: the 32-bit word to rotate
-; given in r25,r24,r23,22 (r25 is most significant)
-; param2: an 8-bit value telling how often to rotate
-; given in r20
-; modifys: r21, r22
-rotr32:
- cpi r20, 8
- brlo bitrotr
- mov r21, r22
- mov r22, r23
- mov r23, r24
- mov r24, r25
- mov r25, r21
- subi r20, 8
- rjmp rotr32
-bitrotr:
- clr r21
- clc
-bitrotr_loop:
- tst r20
- breq fixrotr
- ror r25
- ror r24
- ror r23
- ror r22
- ror r21
- dec r20
- rjmp bitrotr_loop
-fixrotr:
- or r25, r21
- ret
-
-
-;###########################################################
-
-.global change_endian32
-; === change_endian32 ===
-; function that changes the endianess of a 32-bit word
-; param1: the 32-bit word
-; given in r25,r24,r23,22 (r25 is most significant)
-; modifys: r21, r22
-change_endian32:
- movw r20, r22 ; (r22,r23) --> (r20,r21)
- mov r22, r25
- mov r23, r24
- mov r24, r21
- mov r25, r20
- ret
-*/