-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsp_keccak.s43
80 lines (58 loc) · 1.48 KB
/
msp_keccak.s43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "msp430.h"
NAME msp_keccak
EXTERN keccakf
PUBLIC keccak_fupdate
RSEG CODE
; State is pointed by R12, input/output by R13. Size is contained in R14.
; If R15 = 0 absorbtion, otherwise squeezing is performed.
keccak_fupdate
PUSHM.W #6,R11
CLR R7
MOV R13,R9
ADD R14,R9 ; Upper bound of input/output
MOV R12,R10
ADD #18,R10 ; Upper bound of public state, R = 18 bytes
ku_outter
MOV R12,R11 ; Reset state counter
ku_inner ; Iterates over state words in R12
TST R15 ; If R15 is set, go to squeeze
JNZ squeeze ; otherwise absorb
; ABSORBTION PHASE
INCD R11
CMP R9,R13
JZ pad ; Check if padding is needed
MOV @R13+,R8
JMP after_pad ; If not just continue
pad
TST R7
JZ first_pad ; If R7 indicates it is the first pad
CLR R8 ; Otherwise it is the middle or last pad, so set to 0
JMP pad_fin ; Check if it is the last pad
first_pad
MOV #0x01,R8
MOV R8,R7
pad_fin
CMP R11,R10 ; Are we at the end of the block?
JNZ after_pad ; If not, just continue and keep R8 at 0
XOR #0x80,R8 ; If yes, XOR 0x80
after_pad
XOR R8,-2(R11) ; XOR into the state word
JMP fin
; SQUEEZING PHASE
squeeze
MOV @R11+,0(R13)
INCD R13
CMP R13,R9
JZ finr ; In case output length is not multiple of R
fin
CMP R10,R11
JNZ ku_inner
PUSHM.W #7,R15 ; No need to store padding registers
CALLA #keccakf
POPM.W #7,R15
CMP R13,R9
JNZ ku_outter ; Process next block
finr
POPM.W #6,R11
RETA
END