-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAES_InitInvBox_N.S
120 lines (113 loc) · 3.12 KB
/
AES_InitInvBox_N.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
#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
# #
# 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_InitInvBox_N
#
# AES GF(256) inverse multiplicative generator for Nano variant
#
# Input : C_00(=0)
# Output : None
# Modified: IBOXPTR, C_09, C_1B, INVVAL, TMP0, TMP1
#
#define C_00 r1
#define C_09 r18
#define C_1B r19
#define INVVAL r20
#define TMP0 r21
#define TMP1 r22
#define IBOXPTR_L r26
#define IBOXPTR_H r27
#define IBOXPTR X
.section .text.AES_InitInvBox_N,"ax",@progbits
.global AES_InitInvBox_N
AES_InitInvBox_N:
#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_InitInvBox_N_start1:
.global AES_InitInvBox_N_start1
#endif
#------------- Real function starts here -------------
ldi C_1B,0x1b
ldi C_09,0x09
ldi IBOXPTR_H,hi8(AES_InvBox_N)
clr IBOXPTR_L
st IBOXPTR,C_00
ldi IBOXPTR_L,1
ldi INVVAL,1
100:
st IBOXPTR,INVVAL
mov TMP0,IBOXPTR_L
# xtime2
lsl TMP0
brcc 1f
eor TMP0,C_1B
1:
eor IBOXPTR_L,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 IBOXPTR_L,1
brne 100b
#-------------- Real function ends here --------------
#ifdef AES_BENCHMARK
AES_InitInvBox_N_end1:
.global AES_InitInvBox_N_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_InitInvBox_N_end:
.global AES_InitInvBox_N_end
#endif
.size AES_InitInvBox_N,.-AES_InitInvBox_N
#undef C_00
#undef C_09
#undef C_1B
#undef INVVAL
#undef TMP0
#undef TMP1
#undef IBOXPTR_L
#undef IBOXPTR_H
#undef IBOXPTR