-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmcrypto_parallel_arm64.go
More file actions
242 lines (198 loc) · 6.09 KB
/
Copy patharmcrypto_parallel_arm64.go
File metadata and controls
242 lines (198 loc) · 6.09 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//go:build arm64 && !purego
package aes
// Hardware-accelerated parallel AES round functions using ARM Crypto Extensions
// These reduce Go/Assembly boundary crossings by processing multiple blocks per call
// Standard round variants (key XOR at end)
//go:noescape
func armRound2(blocks *Block2, roundKeys *Key2)
//go:noescape
func armFinalRound2(blocks *Block2, roundKeys *Key2)
//go:noescape
func armInvRound2(blocks *Block2, roundKeys *Key2)
//go:noescape
func armInvFinalRound2(blocks *Block2, roundKeys *Key2)
//go:noescape
func armRound4(blocks *Block4, roundKeys *Key4)
//go:noescape
func armFinalRound4(blocks *Block4, roundKeys *Key4)
//go:noescape
func armInvRound4(blocks *Block4, roundKeys *Key4)
//go:noescape
func armInvFinalRound4(blocks *Block4, roundKeys *Key4)
// KeyFirst variants (key XOR at beginning - native ARM semantics)
//go:noescape
func armRoundKeyFirst2(blocks *Block2, roundKeys *Key2)
//go:noescape
func armFinalRoundKeyFirst2(blocks *Block2, roundKeys *Key2)
//go:noescape
func armRoundKeyFirst4(blocks *Block4, roundKeys *Key4)
//go:noescape
func armFinalRoundKeyFirst4(blocks *Block4, roundKeys *Key4)
// Round2HW performs one AES encryption round on 2 blocks with hardware acceleration if available
func Round2HW(blocks *Block2, roundKeys *Key2) {
if CPU.HasARMCrypto {
armRound2(blocks, roundKeys)
} else {
Round2(blocks, roundKeys)
}
}
// Round4HW performs one AES encryption round on 4 blocks with hardware acceleration if available
func Round4HW(blocks *Block4, roundKeys *Key4) {
if CPU.HasARMCrypto {
armRound4(blocks, roundKeys)
} else {
Round4(blocks, roundKeys)
}
}
// FinalRound2HW performs the final AES encryption round on 2 blocks with hardware acceleration if available
func FinalRound2HW(blocks *Block2, roundKeys *Key2) {
if CPU.HasARMCrypto {
armFinalRound2(blocks, roundKeys)
} else {
FinalRound2(blocks, roundKeys)
}
}
// FinalRound4HW performs the final AES encryption round on 4 blocks with hardware acceleration if available
func FinalRound4HW(blocks *Block4, roundKeys *Key4) {
if CPU.HasARMCrypto {
armFinalRound4(blocks, roundKeys)
} else {
FinalRound4(blocks, roundKeys)
}
}
// InvRound2HW performs one AES decryption round on 2 blocks with hardware acceleration if available
func InvRound2HW(blocks *Block2, roundKeys *Key2) {
if CPU.HasARMCrypto {
armInvRound2(blocks, roundKeys)
} else {
InvRound2(blocks, roundKeys)
}
}
// InvRound4HW performs one AES decryption round on 4 blocks with hardware acceleration if available
func InvRound4HW(blocks *Block4, roundKeys *Key4) {
if CPU.HasARMCrypto {
armInvRound4(blocks, roundKeys)
} else {
InvRound4(blocks, roundKeys)
}
}
// InvFinalRound2HW performs the final AES decryption round on 2 blocks with hardware acceleration if available
func InvFinalRound2HW(blocks *Block2, roundKeys *Key2) {
if CPU.HasARMCrypto {
armInvFinalRound2(blocks, roundKeys)
} else {
InvFinalRound2(blocks, roundKeys)
}
}
// InvFinalRound4HW performs the final AES decryption round on 4 blocks with hardware acceleration if available
func InvFinalRound4HW(blocks *Block4, roundKeys *Key4) {
if CPU.HasARMCrypto {
armInvFinalRound4(blocks, roundKeys)
} else {
InvFinalRound4(blocks, roundKeys)
}
}
// InvMixColumns2HW performs inverse MixColumns on 2 blocks with hardware acceleration if available
func InvMixColumns2HW(blocks *Block2) {
if CPU.HasARMCrypto {
// ARM doesn't have a dedicated parallel InvMixColumns, use individual blocks
b0 := (*Block)(blocks[0:16])
b1 := (*Block)(blocks[16:32])
InvMixColumnsHW(b0)
InvMixColumnsHW(b1)
} else {
b0 := (*Block)(blocks[0:16])
b1 := (*Block)(blocks[16:32])
InvMixColumns(b0)
InvMixColumns(b1)
}
}
// InvMixColumns4HW performs inverse MixColumns on 4 blocks with hardware acceleration if available
func InvMixColumns4HW(blocks *Block4) {
if CPU.HasARMCrypto {
// ARM doesn't have a dedicated parallel InvMixColumns, use individual blocks
b0 := (*Block)(blocks[0:16])
b1 := (*Block)(blocks[16:32])
b2 := (*Block)(blocks[32:48])
b3 := (*Block)(blocks[48:64])
InvMixColumnsHW(b0)
InvMixColumnsHW(b1)
InvMixColumnsHW(b2)
InvMixColumnsHW(b3)
} else {
b0 := (*Block)(blocks[0:16])
b1 := (*Block)(blocks[16:32])
b2 := (*Block)(blocks[32:48])
b3 := (*Block)(blocks[48:64])
InvMixColumns(b0)
InvMixColumns(b1)
InvMixColumns(b2)
InvMixColumns(b3)
}
}
// KeyFirst variants - these are more efficient on ARM since they match native AESE semantics
func RoundKeyFirst2HW(blocks *Block2, roundKeys *Key2) {
if CPU.HasARMCrypto {
armRoundKeyFirst2(blocks, roundKeys)
} else {
RoundKeyFirst2(blocks, roundKeys)
}
}
func RoundKeyFirst4HW(blocks *Block4, roundKeys *Key4) {
if CPU.HasARMCrypto {
armRoundKeyFirst4(blocks, roundKeys)
} else {
RoundKeyFirst4(blocks, roundKeys)
}
}
func FinalRoundKeyFirst2HW(blocks *Block2, roundKeys *Key2) {
if CPU.HasARMCrypto {
armFinalRoundKeyFirst2(blocks, roundKeys)
} else {
FinalRoundKeyFirst2(blocks, roundKeys)
}
}
func FinalRoundKeyFirst4HW(blocks *Block4, roundKeys *Key4) {
if CPU.HasARMCrypto {
armFinalRoundKeyFirst4(blocks, roundKeys)
} else {
FinalRoundKeyFirst4(blocks, roundKeys)
}
}
func InvRoundKeyFirst2HW(blocks *Block2, roundKeys *Key2) {
InvRoundKeyFirst2(blocks, roundKeys)
}
func InvRoundKeyFirst4HW(blocks *Block4, roundKeys *Key4) {
InvRoundKeyFirst4(blocks, roundKeys)
}
func InvFinalRoundKeyFirst2HW(blocks *Block2, roundKeys *Key2) {
InvFinalRoundKeyFirst2(blocks, roundKeys)
}
func InvFinalRoundKeyFirst4HW(blocks *Block4, roundKeys *Key4) {
InvFinalRoundKeyFirst4(blocks, roundKeys)
}
// NoKey variants use software fallback
func RoundNoKey2HW(blocks *Block2) {
RoundNoKey2(blocks)
}
func RoundNoKey4HW(blocks *Block4) {
RoundNoKey4(blocks)
}
func FinalRoundNoKey2HW(blocks *Block2) {
FinalRoundNoKey2(blocks)
}
func FinalRoundNoKey4HW(blocks *Block4) {
FinalRoundNoKey4(blocks)
}
func InvRoundNoKey2HW(blocks *Block2) {
InvRoundNoKey2(blocks)
}
func InvRoundNoKey4HW(blocks *Block4) {
InvRoundNoKey4(blocks)
}
func InvFinalRoundNoKey2HW(blocks *Block2) {
InvFinalRoundNoKey2(blocks)
}
func InvFinalRoundNoKey4HW(blocks *Block4) {
InvFinalRoundNoKey4(blocks)
}