aes.asm 11.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	! Benchmarks on my slow sparcstation:	
	! C code	
	! aes128 (ECB encrypt): 14.36s, 0.696MB/s
	! aes128 (ECB decrypt): 17.19s, 0.582MB/s
	! aes128 (CBC encrypt): 16.08s, 0.622MB/s
	! aes128 ((CBC decrypt)): 18.79s, 0.532MB/s
	! 
	! aes192 (ECB encrypt): 16.85s, 0.593MB/s
	! aes192 (ECB decrypt): 19.64s, 0.509MB/s
	! aes192 (CBC encrypt): 18.43s, 0.543MB/s
	! aes192 ((CBC decrypt)): 20.76s, 0.482MB/s
	! 
	! aes256 (ECB encrypt): 19.12s, 0.523MB/s
	! aes256 (ECB decrypt): 22.57s, 0.443MB/s
	! aes256 (CBC encrypt): 20.92s, 0.478MB/s
	! aes256 ((CBC decrypt)): 23.22s, 0.431MB/s

18
	.file	"aes.asm"
19
20
21
22
	.section	".text"
	.align 4
	.type	key_addition_8to32,#function
	.proc	020
23
24
25
! /* Key addition that also packs every byte in the key to a word rep. */
! static void
! key_addition_8to32(const uint8_t *txt, const uint32_t *keys, uint32_t *out)
26
key_addition_8to32:
27
28
29
30
	! %o0:	txt
	! %o1:	keys
	! %o2:	out
	! i:	%o5
31
	mov	0, %o5
32
33
.Liloop: 
	! val:	%o4
34
	mov	0, %o4
35
	! j:	%o3
36
	mov	0, %o3
37
.Lshiftloop:
38
	ldub	[%o0], %g3
39
	! %g2 = j << 3
40
	sll	%o3, 3, %g2
41
	! %g3 << 0
42
43
44
45
	sll	%g3, %g2, %g3
	add	%o3, 1, %o3
	or	%o4, %g3, %o4
	cmp	%o3, 3
46
	bleu	.Lshiftloop
47
	add	%o0, 1, %o0
48
49
	! val in %o4 now

Niels Möller's avatar
Niels Möller committed
50
	! out[i] = keys[i] ^ val;  i++
51
52
53
54
55
	sll	%o5, 2, %g3
	ld	[%o1+%g3], %g2
	add	%o5, 1, %o5
	xor	%g2, %o4, %g2
	cmp	%o5, 3
56
	bleu	.Liloop
57
	st	%g2, [%o2+%g3]
58

59
60
	retl
	nop
61

62
63
! key_addition32(const uint32_t *txt, const uint32_t *keys, uint32_t *out)

64
65
66
67
68
	.size	key_addition_8to32,.LLfe1-key_addition_8to32
	.align 4
	.type	key_addition32,#function
	.proc	020
key_addition32:
Niels Möller's avatar
Niels Möller committed
69
70
71
72
73
	! Unrolled version
	ld	[%o0], %g2
	ld	[%o1], %g3
	xor	%g2, %g3, %g3
	st	%g3, [%o2]
74

Niels Möller's avatar
Niels Möller committed
75
76
	ld	[%o0+4], %g2
	ld	[%o1+4], %g3
77
	xor	%g2, %g3, %g3
Niels Möller's avatar
Niels Möller committed
78
	st	%g3, [%o2+4]
Niels Möller's avatar
Niels Möller committed
79

Niels Möller's avatar
Niels Möller committed
80
81
82
83
	ld	[%o0+8], %g2
	ld	[%o1+8], %g3
	xor	%g2, %g3, %g3
	st	%g3, [%o2+8]
84

Niels Möller's avatar
Niels Möller committed
85
86
87
88
89
	ld	[%o0+12], %g2
	ld	[%o1+12], %g3
	xor	%g2, %g3, %g3
	retl
	st	%g3, [%o2+12]
90

91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
.LLfe2:
	.size	key_addition32,.LLfe2-key_addition32
	.align 4
	.type	key_addition32to8,#function
	.proc	020
key_addition32to8:
	mov	%o0, %o5
	mov	0, %o4
	sll	%o4, 2, %g2
.LL42:
	ld	[%o1+%g2], %o0
	mov	0, %o3
	ld	[%o5+%g2], %g3
	xor	%g3, %o0, %g3
Niels Möller's avatar
Niels Möller committed
106
	! FIXME:	Unroll inner loop
107
108
109
110
.LL37:
	sll	%o3, 3, %g2
	srl	%g3, %g2, %g2
	stb	%g2, [%o2]
Niels Möller's avatar
Niels Möller committed
111

112
113
	add	%o3, 1, %o3
	cmp	%o3, 3
Niels Möller's avatar
Niels Möller committed
114

115
116
	bleu	.LL37
	add	%o2, 1, %o2
Niels Möller's avatar
Niels Möller committed
117

118
119
120
121
	add	%o4, 1, %o4
	cmp	%o4, 3
	bleu	.LL42
	sll	%o4, 2, %g2
Niels Möller's avatar
Niels Möller committed
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
	retl
	nop
.LLFE3:
.LLfe3:
	.size	key_addition32to8,.LLfe3-key_addition32to8
	.section	".rodata"
	.align 4
	.type	idx,#object
	.size	idx,64
idx:
	.long	0
	.long	1
	.long	2
	.long	3
	.long	1
	.long	2
	.long	3
	.long	0
	.long	2
	.long	3
	.long	0
	.long	1
	.long	3
	.long	0
	.long	1
	.long	2
	.align 8
.LLC0:
	.asciz	"!(length % 16)"
	.align 8
.LLC1:
Niels Möller's avatar
Niels Möller committed
154
	.asciz	"aes.asm"
155
156
157
158
159
160
161
162
	.align 8
.LLC2:
	.asciz	"aes_encrypt"
	.section	".text"
	.align 4
	.global aes_encrypt
	.type	aes_encrypt,#function
	.proc	020
Niels Möller's avatar
Niels Möller committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

! input parameters
define(ctx,	%i0)
define(length,	%i1)
define(dst,	%i2)
define(src,	%i3)

! locals
define(g_idx, %i5)
	
define(dtbl,	%l1)
define(round,	%l3)
define(txt,	%l5)
define(wtxt,	%l6)

178
179
aes_encrypt:
	save	%sp, -136, %sp
Niels Möller's avatar
Niels Möller committed
180

Niels Möller's avatar
Niels Möller committed
181
	andcc	length, 15, %g0
Niels Möller's avatar
Niels Möller committed
182
	bne	.Lencrypt_fail
Niels Möller's avatar
Niels Möller committed
183
	cmp	length, 0
Niels Möller's avatar
Niels Möller committed
184
	be	.Lencrypt_end
185
	sethi	%hi(idx), %i4
Niels Möller's avatar
Niels Möller committed
186
187
188
	add	%fp, -24, wtxt
	add	%fp, -40, txt
	or	%i4, %lo(idx), g_idx
Niels Möller's avatar
Niels Möller committed
189
.Lencrypt_block:
Niels Möller's avatar
Niels Möller committed
190
191
192
	! key_addition_8to32(src, ctx->keys, wtxt);
	mov	src, %o0
	mov	ctx, %o1
193
	call	key_addition_8to32, 0
Niels Möller's avatar
Niels Möller committed
194
195
196
197
198
199
200
	mov	wtxt, %o2

	! get nrounds
	ld	[ctx+480], %o0
	mov	1, round
	cmp	round, %o0
	bgeu	.Lencrypt_final
201
	sethi	%hi(64512), %o0
Niels Möller's avatar
Niels Möller committed
202

203
	sethi	%hi(_aes_dtbl), %o0
Niels Möller's avatar
Niels Möller committed
204
205
206
207
208
	or	%o0, %lo(_aes_dtbl), dtbl

	mov	txt, %l4
	mov	wtxt, %l0
	! FIXME:	%l7 = idx, seems redundant? 
209
	! or	%i4, %lo(idx), %l7
Niels Möller's avatar
Niels Möller committed
210
211
212
213
	add	ctx, 16, %l2
.Lencrypt_round:
	! j:	%o7
	! 4j:	%g2
214
	mov	0, %o7
Niels Möller's avatar
Niels Möller committed
215
	! %g3 = &idx[3][0]
216
	add	g_idx, 48, %g3
Niels Möller's avatar
Niels Möller committed
217
218
.Lencrypt_inner:
	! %o0 = idx[3][0]
219
	ld	[%g3], %o0
Niels Möller's avatar
Niels Möller committed
220
	! %g2 = 4j
221
	sll	%o7, 2, %g2
Niels Möller's avatar
Niels Möller committed
222
	! %o1 = idx[2][0]
223
	ld	[%g3-16], %o1
Niels Möller's avatar
Niels Möller committed
224
	! %o2 = 4 idx[3][0]
225
	sll	%o0, 2, %o0
Niels Möller's avatar
Niels Möller committed
226
	! %o3 = wtxt[idx[3][0]], byte => bits 24-31
227
228
	ldub	[%l0+%o0], %o3
	sll	%o1, 2, %o1
Niels Möller's avatar
Niels Möller committed
229
	! %o4 = wtxt[idx[2][0]], half-word???
230
231
	lduh	[%l0+%o1], %o4
	sll	%o3, 2, %o3
Niels Möller's avatar
Niels Möller committed
232
	! %o0 = idx[1][0]
233
	ld	[%g3-32], %o0
Niels Möller's avatar
Niels Möller committed
234
	! %o4 = (wtxt[idx[2][0]] >> 16) & 0xff => bits 16-23
235
	and	%o4, 255, %o4
Niels Möller's avatar
Niels Möller committed
236
237
238
	! %o2 = dtbl[wtxt[idx[3][0]] >> 24]
	ld	[dtbl+%o3], %o2
	! %o0 = 4 idx[1][0]
239
	sll	%o0, 2, %o0
Niels Möller's avatar
Niels Möller committed
240
	! %o3 = dtbl[wtxt[idx[3][0]] >> 24] >> 24
241
	srl	%o2, 24, %o3
Niels Möller's avatar
Niels Möller committed
242
	! %o4 = 4 ((wtxt[idx[2][0]] >> 16) & 0xff)
243
	sll	%o4, 2, %o4
Niels Möller's avatar
Niels Möller committed
244
	! %o0 = &wtxt[idx[1][0]]
245
	add	%l0, %o0, %o0
Niels Möller's avatar
Niels Möller committed
246
247
248
	! %o1 = dtbl[(wtxt[idx[2][0]] >> 16) & 0xff]
	ld	[dtbl+%o4], %o1
	! %o2 = dtbl[wtxt[idx[3][0]] >> 24] << 8
249
	sll	%o2, 8, %o2
Niels Möller's avatar
Niels Möller committed
250
	! %o5 = (wtxt[idx[1][0]] >> 8) & 0xff
251
	ldub	[%o0+2], %o5
Niels Möller's avatar
Niels Möller committed
252
	! %o2 = ROL(dtbl[wtxt[idx[3][0]] >> 24])
253
	or	%o2, %o3, %o2
Niels Möller's avatar
Niels Möller committed
254
255
	! %o1 = dtbl[(wtxt[idx[2][0]] >> 16) & 0xff] 
	!       ^ ROL(dtbl[wtxt[idx[3][0]] >> 24])  = XX1
256
	xor	%o1, %o2, %o1
Niels Möller's avatar
Niels Möller committed
257
	! %o3 = XX1 >> 24
258
	srl	%o1, 24, %o3
Niels Möller's avatar
Niels Möller committed
259
	! %o5 = 4 ((wtxt[idx[1][0]] >> 8) & 0xff)
260
	sll	%o5, 2, %o5
Niels Möller's avatar
Niels Möller committed
261
	! %o2 = wtxt[j]
262
	ld	[%l0+%g2], %o2
Niels Möller's avatar
Niels Möller committed
263
	! %o1 = XX1 << 8
264
	sll	%o1, 8, %o1
Niels Möller's avatar
Niels Möller committed
265
266
267
	! %o0 = dtbl[(wtxt[idx[1][0]] >> 8) & 0xff]
	ld	[dtbl+%o5], %o0
	! %o1 = ROL(XX1)
268
	or	%o1, %o3, %o1
Niels Möller's avatar
Niels Möller committed
269
	! %o0 = dtbl[(wtxt[idx[1][0]] >> 8) & 0xff] ^ ROL(XX1) = XX2
270
	xor	%o0, %o1, %o0
Niels Möller's avatar
Niels Möller committed
271
	! %o2 = wtxt[j] & 0xff
272
	and	%o2, 255, %o2
Niels Möller's avatar
Niels Möller committed
273
	! %03 = XX2 >> 24
274
	srl	%o0, 24, %o3
Niels Möller's avatar
Niels Möller committed
275
	! %o2 = 4 (wtxt[j] & 0xff)
276
	sll	%o2, 2, %o2
Niels Möller's avatar
Niels Möller committed
277
278
279
	! %o1 = dtbl[wtxt[j] & 0xff]
	ld	[dtbl+%o2], %o1
	! %o0 = XX2 << 8
280
	sll	%o0, 8, %o0
Niels Möller's avatar
Niels Möller committed
281
	! %o0 = ROL(XX2)
282
	or	%o0, %o3, %o0
Niels Möller's avatar
Niels Möller committed
283
	! %o1 = dtbl[wtxt[j] & 0xff] ^ ROL(XX2 = XX3
284
	xor	%o1, %o0, %o1
Niels Möller's avatar
Niels Möller committed
285
	! j++
286
	add	%o7, 1, %o7
Niels Möller's avatar
Niels Möller committed
287
	! txt[j] (old j) = XX3 
288
	st	%o1, [%l4+%g2]
Niels Möller's avatar
Niels Möller committed
289
	! j <= 3?
290
	cmp	%o7, 3
Niels Möller's avatar
Niels Möller committed
291
292
	bleu	.Lencrypt_inner
	! %g3 = &idx[3][j]
293
	add	%g3, 4, %g3
Niels Möller's avatar
Niels Möller committed
294
295

	! key_addition32(txt, ctx + 16, wtxt)
296
	mov	%l2, %o1
Niels Möller's avatar
Niels Möller committed
297
	mov	txt, %o0
298
	call	key_addition32, 0
Niels Möller's avatar
Niels Möller committed
299
300
301
302
303
304
305
306
307
308
	mov	wtxt, %o2

	! %o0 = nrounds
	! FIXME:	Keep in some register?
	ld	[ctx+480], %o0
	add	round, 1, round
	cmp	round, %o0
	! round < nrounds?
	blu	.Lencrypt_round
	! %l2 = ctx->keys + r*4 
309
	add	%l2, 16, %l2
Niels Möller's avatar
Niels Möller committed
310
	
311
	sethi	%hi(64512), %o0
Niels Möller's avatar
Niels Möller committed
312
313
.Lencrypt_final:
	! %l3 = 0xff00 ???
314
	or	%o0, 768, %l3
Niels Möller's avatar
Niels Möller committed
315
	! %o7 = j = 0
316
	mov	0, %o7
Niels Möller's avatar
Niels Möller committed
317
318
319
	! %g3 = wtxt
	mov	wtxt, %g3
	! %l2 = 0xff0000
320
	sethi	%hi(16711680), %l2
Niels Möller's avatar
Niels Möller committed
321
	! %l1 = 0xff000000
322
	sethi	%hi(-16777216), %l1
Niels Möller's avatar
Niels Möller committed
323
324
325
326
	! %l0 = txt 
	mov	txt, %l0
	! %g2 = &idx[3][0]
	add	g_idx, 48, %g2
327
.LL63:
Niels Möller's avatar
Niels Möller committed
328
	! %o0 = idx[1][0]
329
	ld	[%g2-32], %o0
Niels Möller's avatar
Niels Möller committed
330
	! %o5 = 4 j
331
	sll	%o7, 2, %o5
Niels Möller's avatar
Niels Möller committed
332
	! %o2 = idx[2][0]
333
	ld	[%g2-16], %o2
Niels Möller's avatar
Niels Möller committed
334
	! %o0 = 4(idx[1][0])
335
	sll	%o0, 2, %o0
Niels Möller's avatar
Niels Möller committed
336
	! %o3 = wtxt[idx[1][0]]
337
	ld	[%g3+%o0], %o3
Niels Möller's avatar
Niels Möller committed
338
	! %o2 = 4 idx[2][0]
339
	sll	%o2, 2, %o2
Niels Möller's avatar
Niels Möller committed
340
	! %o4 = idx[3][0]
341
	ld	[%g2], %o4
Niels Möller's avatar
Niels Möller committed
342
	! %o3 = wtxt[idx[1][0]] & 0xff00 
343
	and	%o3, %l3, %o3
Niels Möller's avatar
Niels Möller committed
344
	! %o1 = wtxt[idx[2][0]]
345
	ld	[%g3+%o2], %o1
Niels Möller's avatar
Niels Möller committed
346
	! %o4 = 4 idx[3][0]
347
	sll	%o4, 2, %o4
Niels Möller's avatar
Niels Möller committed
348
	! %o0 = wtxt[idx[1][0]]
349
	ld	[%g3+%o5], %o0
Niels Möller's avatar
Niels Möller committed
350
	! %o1 = wtxt[idx[2][0]] & 0xff0000
351
	and	%o1, %l2, %o1
Niels Möller's avatar
Niels Möller committed
352
	! %o2 = wtxt[idx[3][0]]
353
	ld	[%g3+%o4], %o2
Niels Möller's avatar
Niels Möller committed
354
	! %o0 = wtxt[idx[1][0]] & 0xff
355
	and	%o0, 255, %o0
Niels Möller's avatar
Niels Möller committed
356
357
358
359

	! % o0 = wtxt[idx[1][0]] & 0xff
	!        | wtxt[idx[1][0]] & 0xff00
	!        | wtxt[idx[2][0]] & 0xff0000
360
361
	or	%o0, %o3, %o0
	or	%o0, %o1, %o0
Niels Möller's avatar
Niels Möller committed
362
	! %o2 = wtxt[idx[3][0]] & 0xff000000
363
364
	and	%o2, %l1, %o2
	or	%o0, %o2, %o0
Niels Möller's avatar
Niels Möller committed
365
	! j++
366
	add	%o7, 1, %o7
Niels Möller's avatar
Niels Möller committed
367
	! txt[j] = ... | ... | ... | ... (old j)
368
	st	%o0, [%l0+%o5]
Niels Möller's avatar
Niels Möller committed
369
	! j <= 3?
370
371
	cmp	%o7, 3
	bleu	.LL63
Niels Möller's avatar
Niels Möller committed
372
	! %g2 = &idx[3][j]
373
	add	%g2, 4, %g2
Niels Möller's avatar
Niels Möller committed
374
	
375
376
	sethi	%hi(_aes_sbox), %o0
	or	%o0, %lo(_aes_sbox), %g3
Niels Möller's avatar
Niels Möller committed
377
378
	
	! %o7 = j = 0
379
	mov	0, %o7
Niels Möller's avatar
Niels Möller committed
380
	! %g2 = txt
381
	mov	%l5, %g2
Niels Möller's avatar
Niels Möller committed
382
383
.Lencrypt_sbox:
	! %o5 = 4 j
384
	sll	%o7, 2, %o5
Niels Möller's avatar
Niels Möller committed
385
	! %o3 = txt[j]
386
	ld	[%g2+%o5], %o3
Niels Möller's avatar
Niels Möller committed
387
	! j++
388
	add	%o7, 1, %o7
Niels Möller's avatar
Niels Möller committed
389
	! %o0 = (txt[j] >> 8) & 0xff (old j) 
390
391
	srl	%o3, 8, %o0
	and	%o0, 255, %o0
Niels Möller's avatar
Niels Möller committed
392
	! %o4 = sbox[(txt[j] >> 8) & 0xff]
393
	ldub	[%g3+%o0], %o4
Niels Möller's avatar
Niels Möller committed
394
	! %o2 = (txt[j] >> 16) (old j)
395
	srl	%o3, 16, %o2
Niels Möller's avatar
Niels Möller committed
396
	! %o0 = txt[j] & 0xff
397
	and	%o3, 255, %o0
Niels Möller's avatar
Niels Möller committed
398
	! %o1 = sbox[txt[j] & 0xff]
399
	ldub	[%g3+%o0], %o1
Niels Möller's avatar
Niels Möller committed
400
	! %o2 = (txt[j] >> 16) & 0xff (old j)
401
	and	%o2, 255, %o2
Niels Möller's avatar
Niels Möller committed
402
	! %o0 = sbox[(txt[j] >> 16) & 0xff]
403
	ldub	[%g3+%o2], %o0
Niels Möller's avatar
Niels Möller committed
404
	! %o3 = txt[j] >> 24
405
	srl	%o3, 24, %o3
Niels Möller's avatar
Niels Möller committed
406
	! %o4 = sbox[txt[j] & 0xff] << 8
407
	sll	%o4, 8, %o4
Niels Möller's avatar
Niels Möller committed
408
	! %o2 = sbox[txt[j] >> 24]
409
	ldub	[%g3+%o3], %o2
Niels Möller's avatar
Niels Möller committed
410
411
	! %o1 = sbox[txt[j] & 0xff] 
	!	| sbox[(txt[j] >> 8) & 0xff] << 8
412
	or	%o1, %o4, %o1
Niels Möller's avatar
Niels Möller committed
413
	!	| sbox[(txt[j] >> 16) & 0xff] << 16
414
415
	sll	%o0, 16, %o0
	or	%o1, %o0, %o1
Niels Möller's avatar
Niels Möller committed
416
	!	| sbox[txt[j] >> 24] << 24
417
418
	sll	%o2, 24, %o2
	or	%o1, %o2, %o1
Niels Möller's avatar
Niels Möller committed
419
	! j < 3 
420
	cmp	%o7, 3
Niels Möller's avatar
Niels Möller committed
421
422
	bleu	.Lencrypt_sbox
	! txt[j] = ... | ... | ... | ...
423
	st	%o1, [%g2+%o5]
Niels Möller's avatar
Niels Möller committed
424
425
426
427

	! key_addition32to8(txt, ctx + nrounds * 4, dst,
	ld	[ctx+480], %o1
	mov	dst, %o2
428
	sll	%o1, 4, %o1
Niels Möller's avatar
Niels Möller committed
429
	add	ctx, %o1, %o1
430
431
	call	key_addition32to8, 0
	mov	%l5, %o0
Niels Möller's avatar
Niels Möller committed
432
433
434

	add	src, 16, src
	addcc	length, -16, length
Niels Möller's avatar
Niels Möller committed
435
	bne	.Lencrypt_block
Niels Möller's avatar
Niels Möller committed
436
	add	dst, 16, dst
Niels Möller's avatar
Niels Möller committed
437
438
	b,a	.Lencrypt_end
.Lencrypt_fail:
439
440
441
442
443
444
445
446
	sethi	%hi(.LLC0), %o0
	sethi	%hi(.LLC1), %o1
	sethi	%hi(.LLC2), %o3
	or	%o0, %lo(.LLC0), %o0
	or	%o1, %lo(.LLC1), %o1
	or	%o3, %lo(.LLC2), %o3
	call	__assert_fail, 0
	mov	92, %o2
Niels Möller's avatar
Niels Möller committed
447
.Lencrypt_end:
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
.LLBE5:
	ret
	restore
.LLFE4:
.LLfe4:
	.size	aes_encrypt,.LLfe4-aes_encrypt
	.section	".rodata"
	.align 4
	.type	iidx,#object
	.size	iidx,64
iidx:
	.long	0
	.long	1
	.long	2
	.long	3
	.long	3
	.long	0
	.long	1
	.long	2
	.long	2
	.long	3
	.long	0
	.long	1
	.long	1
	.long	2
	.long	3
	.long	0
	.align 8
.LLC3:
	.asciz	"aes_decrypt"
	.section	".text"
	.align 4
	.global aes_decrypt
	.type	aes_decrypt,#function
	.proc	020
aes_decrypt:
.LLFB5:
	!#PROLOGUE# 0
	save	%sp, -136, %sp
.LLCFI1:
	!#PROLOGUE# 1
.LLBB6:
	andcc	%i1, 15, %g0
	bne	.LL111
	cmp	%i1, 0
	be	.LL106
	sethi	%hi(iidx), %i4
	add	%fp, -24, %l6
	add	%fp, -40, %l5
	add	%i0, 240, %i5
.LL84:
	ld	[%i0+480], %o1
	mov	%i3, %o0
	sll	%o1, 4, %o1
	add	%i0, %o1, %o1
	add	%o1, 240, %o1
	call	key_addition_8to32, 0
	mov	%l6, %o2
	ld	[%i0+480], %o0
	addcc	%o0, -1, %l2
	be	.LL107
	sll	%l2, 4, %o1
	add	%o1, %i0, %o1
	sethi	%hi(_aes_itbl), %o0
	or	%o0, %lo(_aes_itbl), %l1
	add	%o1, 240, %l3
	mov	%l5, %l4
	mov	%l6, %l0
	or	%i4, %lo(iidx), %l7
.LL88:
	mov	0, %o7
	add	%l7, 48, %g3
.LL92:
	ld	[%g3], %o0
	sll	%o7, 2, %g2
	ld	[%g3-16], %o1
	sll	%o0, 2, %o0
	ldub	[%l0+%o0], %o3
	sll	%o1, 2, %o1
	lduh	[%l0+%o1], %o4
	sll	%o3, 2, %o3
	ld	[%g3-32], %o0
	and	%o4, 255, %o4
	ld	[%l1+%o3], %o2
	sll	%o0, 2, %o0
	srl	%o2, 24, %o3
	sll	%o4, 2, %o4
	add	%l0, %o0, %o0
	ld	[%l1+%o4], %o1
	sll	%o2, 8, %o2
	ldub	[%o0+2], %o5
	or	%o2, %o3, %o2
	xor	%o1, %o2, %o1
	srl	%o1, 24, %o3
	sll	%o5, 2, %o5
	ld	[%l0+%g2], %o2
	sll	%o1, 8, %o1
	ld	[%l1+%o5], %o0
	or	%o1, %o3, %o1
	xor	%o0, %o1, %o0
	and	%o2, 255, %o2
	srl	%o0, 24, %o3
	sll	%o2, 2, %o2
	ld	[%l1+%o2], %o1
	sll	%o0, 8, %o0
	or	%o0, %o3, %o0
	xor	%o1, %o0, %o1
	add	%o7, 1, %o7
	st	%o1, [%l4+%g2]
	cmp	%o7, 3
	bleu	.LL92
	add	%g3, 4, %g3
	mov	%l3, %o1
	mov	%l5, %o0
	call	key_addition32, 0
	mov	%l6, %o2
	addcc	%l2, -1, %l2
	bne	.LL88
	add	%l3, -16, %l3
.LL107:
	sethi	%hi(64512), %o0
	or	%o0, 768, %l3
	sethi	%hi(iidx), %o0
	or	%o0, %lo(iidx), %o0
	mov	0, %o7
	mov	%l6, %g3
	sethi	%hi(16711680), %l2
	sethi	%hi(-16777216), %l1
	mov	%l5, %l0
	add	%o0, 48, %g2
.LL98:
	ld	[%g2-32], %o0
	sll	%o7, 2, %o5
	ld	[%g2-16], %o2
	sll	%o0, 2, %o0
	ld	[%g3+%o0], %o3
	sll	%o2, 2, %o2
	ld	[%g2], %o4
	and	%o3, %l3, %o3
	ld	[%g3+%o2], %o1
	sll	%o4, 2, %o4
	ld	[%g3+%o5], %o0
	and	%o1, %l2, %o1
	ld	[%g3+%o4], %o2
	and	%o0, 255, %o0
	or	%o0, %o3, %o0
	or	%o0, %o1, %o0
	and	%o2, %l1, %o2
	or	%o0, %o2, %o0
	add	%o7, 1, %o7
	st	%o0, [%l0+%o5]
	cmp	%o7, 3
	bleu	.LL98
	add	%g2, 4, %g2
	sethi	%hi(_aes_isbox), %o0
	or	%o0, %lo(_aes_isbox), %g3
	mov	0, %o7
	mov	%l5, %g2
.LL103:
	sll	%o7, 2, %o5
	ld	[%g2+%o5], %o3
	add	%o7, 1, %o7
	srl	%o3, 8, %o0
	and	%o0, 255, %o0
	ldub	[%g3+%o0], %o4
	srl	%o3, 16, %o2
	and	%o3, 255, %o0
	ldub	[%g3+%o0], %o1
	and	%o2, 255, %o2
	ldub	[%g3+%o2], %o0
	srl	%o3, 24, %o3
	sll	%o4, 8, %o4
	ldub	[%g3+%o3], %o2
	or	%o1, %o4, %o1
	sll	%o0, 16, %o0
	or	%o1, %o0, %o1
	sll	%o2, 24, %o2
	or	%o1, %o2, %o1
	cmp	%o7, 3
	bleu	.LL103
	st	%o1, [%g2+%o5]
	mov	%i2, %o2
	mov	%l5, %o0
	call	key_addition32to8, 0
	mov	%i5, %o1
	add	%i3, 16, %i3
	addcc	%i1, -16, %i1
	bne	.LL84
	add	%i2, 16, %i2
	b,a	.LL106
.LL111:
	sethi	%hi(.LLC0), %o0
	sethi	%hi(.LLC1), %o1
	sethi	%hi(.LLC3), %o3
	or	%o0, %lo(.LLC0), %o0
	or	%o1, %lo(.LLC1), %o1
	or	%o3, %lo(.LLC3), %o3
	call	__assert_fail, 0
	mov	142, %o2
.LL106:
.LLBE6:
	ret
	restore
.LLFE5:
.LLfe5:
	.size	aes_decrypt,.LLfe5-aes_decrypt