-
Notifications
You must be signed in to change notification settings - Fork 2
/
AES_InitSBoxInvSBox_R.S
173 lines (166 loc) · 4.24 KB
/
AES_InitSBoxInvSBox_R.S
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
# #
# AVR-AES-Faster Library #
# (c) 2020 Rados³aw Gancarz <radgan99@gmail.com> #
# #
# This Source Code Form is subject to the terms of the Mozilla Public #
# License, v. 2.0. If a copy of the MPL was not distributed with this #
# file, You can obtain one at http://mozilla.org/MPL/2.0/. #
# #
#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
#include "AVR-AES-Faster-devel.h"
#ifdef AES_BENCHMARK
#include <avr/io.h>
#endif
#============================================================================
#
# AES_InitSBoxInvSBox_R
#
# AES SBox and inverse S-Box all-in-one generator for RAM variant
#
# Input : C_00(=0)
# Output : None
# Modified: SBOXPTR, SBOXPTR, C_09, C_1B, C_63, VAL, INVVAL, BOXVAL, TMP0, TMP1
#
#define C_00 r1
#define C_09 r18
#define C_1B r19
#define C_63 r20
#define VAL r21
#define INVVAL r22
#define BOXVAL r23
#define TMP0 r24
#define TMP1 r25
#define SBOXPTR_L r26
#define SBOXPTR_H r27
#define ISBXPTR_L r30
#define ISBXPTR_H r31
#define SBOXPTR X
#define ISBXPTR Z
.section .text.AES_InitSBoxInvSBox_R,"ax",@progbits
.global AES_InitSBoxInvSBox_R
AES_InitSBoxInvSBox_R:
#ifdef AES_BENCHMARK
lds r30,_SFR_MEM_ADDR(TCNT1L)
sts benchmark_data+0,r30
lds r30,_SFR_MEM_ADDR(TCNT1H)
sts benchmark_data+1,r30
#endif
#ifdef AES_BENCHMARK
lds r30,_SFR_MEM_ADDR(TCNT1L)
sts benchmark_data+2,r30
lds r30,_SFR_MEM_ADDR(TCNT1H)
sts benchmark_data+3,r30
AES_InitSBoxInvSBox_R_start1:
.global AES_InitSBoxInvSBox_R_start1
#endif
#------------- Real function starts here -------------
ldi C_63,0x63
ldi C_1B,0x1b
ldi C_09,0x09
ldi ISBXPTR_H,hi8(AES_InvSBox_R)
ldi SBOXPTR_H,hi8(AES_SBox_R)
clr SBOXPTR_L
mov ISBXPTR_L,C_63
st SBOXPTR,ISBXPTR_L
st ISBXPTR,SBOXPTR_L
ldi VAL,1
ldi INVVAL,1
100:
mov BOXVAL,INVVAL
mov TMP0,BOXVAL
lsl TMP0
adc TMP0,C_00
eor BOXVAL,TMP0
lsl TMP0
adc TMP0,C_00
eor BOXVAL,TMP0
lsl TMP0
adc TMP0,C_00
eor BOXVAL,TMP0
lsl TMP0
adc TMP0,C_00
eor BOXVAL,TMP0
eor BOXVAL,C_63
mov SBOXPTR_L,VAL
st SBOXPTR,BOXVAL
mov ISBXPTR_L,BOXVAL
st ISBXPTR,VAL
mov BOXVAL,VAL
mov TMP0,BOXVAL
lsl TMP0
adc TMP0,C_00
eor BOXVAL,TMP0
lsl TMP0
adc TMP0,C_00
eor BOXVAL,TMP0
lsl TMP0
adc TMP0,C_00
eor BOXVAL,TMP0
lsl TMP0
adc TMP0,C_00
eor BOXVAL,TMP0
eor BOXVAL,C_63
mov SBOXPTR_L,INVVAL
st SBOXPTR,BOXVAL
mov ISBXPTR_L,BOXVAL
st ISBXPTR,INVVAL
mov TMP0,VAL
# xtime2
lsl TMP0
brcc 1f
eor TMP0,C_1B
1:
eor VAL,TMP0
mov TMP0,INVVAL
lsl TMP0
eor INVVAL,TMP0
mov TMP0,INVVAL
lsl TMP0
lsl TMP0
eor INVVAL,TMP0
mov TMP0,INVVAL
swap TMP0
andi TMP0,0xf0
eor INVVAL,TMP0
brpl 1f
eor INVVAL,C_09
1:
cpi VAL,0xfb
brne 100b
#-------------- Real function ends here --------------
#ifdef AES_BENCHMARK
AES_InitSBoxInvSBox_R_end1:
.global AES_InitSBoxInvSBox_R_end1
lds r24,_SFR_MEM_ADDR(TCNT1L)
sts benchmark_data+4,r24
lds r24,_SFR_MEM_ADDR(TCNT1H)
sts benchmark_data+5,r24
#endif
#ifdef AES_BENCHMARK
lds r30,_SFR_MEM_ADDR(TCNT1L)
sts benchmark_data+6,r30
lds r30,_SFR_MEM_ADDR(TCNT1H)
sts benchmark_data+7,r30
#endif
ret
#ifdef AES_BENCHMARK
AES_InitSBoxInvSBox_R_end:
.global AES_InitSBoxInvSBox_R_end
#endif
.size AES_InitSBoxInvSBox_R,.-AES_InitSBoxInvSBox_R
#undef C_00
#undef C_09
#undef C_1B
#undef C_63
#undef VAL
#undef INVVAL
#undef BOXVAL
#undef TMP0
#undef TMP1
#undef SBOXPTR_L
#undef SBOXPTR_H
#undef ISBXPTR_L
#undef ISBXPTR_H
#undef SBOXPTR
#undef ISBXPTR