a00193fa455d89a71721a0363859da11bcd2955c
[openssl.git] / crypto / aes / asm / aes-mips.pl
1 #!/usr/bin/env perl
2
3 # ====================================================================
4 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
5 # project. The module is, however, dual licensed under OpenSSL and
6 # CRYPTOGAMS licenses depending on where you obtain it. For further
7 # details see http://www.openssl.org/~appro/cryptogams/.
8 # ====================================================================
9
10 # AES for MIPS
11
12 # October 2010
13 #
14 # Code uses 1K[+256B] S-box and on single-issue core [such as R5000]
15 # spends ~68 cycles per byte processed with 128-bit key. This is ~16%
16 # faster than gcc-generated code, which is not very impressive. But
17 # recall that compressed S-box requires extra processing, namely
18 # additional rotations. Rotations are implemented with lwl/lwr pairs,
19 # which is normally used for loading unaligned data. Another cool
20 # thing about this module is its endian neutrality, which means that
21 # it processes data without ever changing byte order...
22
23 # September 2012
24 #
25 # Add MIPS32R2 code.
26
27 ######################################################################
28 # There is a number of MIPS ABI in use, O32 and N32/64 are most
29 # widely used. Then there is a new contender: NUBI. It appears that if
30 # one picks the latter, it's possible to arrange code in ABI neutral
31 # manner. Therefore let's stick to NUBI register layout:
32 #
33 ($zero,$at,$t0,$t1,$t2)=map("\$$_",(0..2,24,25));
34 ($a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7)=map("\$$_",(4..11));
35 ($s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9,$s10,$s11)=map("\$$_",(12..23));
36 ($gp,$tp,$sp,$fp,$ra)=map("\$$_",(3,28..31));
37 #
38 # The return value is placed in $a0. Following coding rules facilitate
39 # interoperability:
40 #
41 # - never ever touch $tp, "thread pointer", former $gp;
42 # - copy return value to $t0, former $v0 [or to $a0 if you're adapting
43 #   old code];
44 # - on O32 populate $a4-$a7 with 'lw $aN,4*N($sp)' if necessary;
45 #
46 # For reference here is register layout for N32/64 MIPS ABIs:
47 #
48 # ($zero,$at,$v0,$v1)=map("\$$_",(0..3));
49 # ($a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7)=map("\$$_",(4..11));
50 # ($t0,$t1,$t2,$t3,$t8,$t9)=map("\$$_",(12..15,24,25));
51 # ($s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7)=map("\$$_",(16..23));
52 # ($gp,$sp,$fp,$ra)=map("\$$_",(28..31));
53 #
54 $flavour = shift || "o32"; # supported flavours are o32,n32,64,nubi32,nubi64
55
56 if ($flavour =~ /64|n32/i) {
57         $PTR_ADD="dadd";        # incidentally works even on n32
58         $PTR_SUB="dsub";        # incidentally works even on n32
59         $PTR_INS="dins";
60         $REG_S="sd";
61         $REG_L="ld";
62         $PTR_SLL="dsll";        # incidentally works even on n32
63         $SZREG=8;
64 } else {
65         $PTR_ADD="add";
66         $PTR_SUB="sub";
67         $PTR_INS="ins";
68         $REG_S="sw";
69         $REG_L="lw";
70         $PTR_SLL="sll";
71         $SZREG=4;
72 }
73 $pf = ($flavour =~ /nubi/i) ? $t0 : $t2;
74 #
75 # <appro@openssl.org>
76 #
77 ######################################################################
78
79 $big_endian=(`echo MIPSEL | $ENV{CC} -E -P -`=~/MIPSEL/)?1:0;
80
81 for (@ARGV) {   $output=$_ if (/^\w[\w\-]*\.\w+$/);     }
82 open STDOUT,">$output";
83
84 if (!defined($big_endian))
85 {    $big_endian=(unpack('L',pack('N',1))==1);   }
86
87 while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
88 open STDOUT,">$output";
89
90 my ($MSB,$LSB)=(0,3);   # automatically converted to little-endian
91
92 $code.=<<___;
93 .text
94 #ifdef OPENSSL_FIPSCANISTER
95 # include <openssl/fipssyms.h>
96 #endif
97
98 #if !defined(__vxworks) || defined(__pic__)
99 .option pic2
100 #endif
101 .set    noat
102 ___
103 \f
104 {{{
105 my $FRAMESIZE=16*$SZREG;
106 my $SAVED_REGS_MASK = ($flavour =~ /nubi/i) ? 0xc0fff008 : 0xc0ff0000;
107
108 my ($inp,$out,$key,$Tbl,$s0,$s1,$s2,$s3)=($a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7);
109 my ($i0,$i1,$i2,$i3)=($at,$t0,$t1,$t2);
110 my ($t0,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11) = map("\$$_",(12..23));
111 my ($key0,$cnt)=($gp,$fp);
112
113 # instuction ordering is "stolen" from output from MIPSpro assembler
114 # invoked with -mips3 -O3 arguments...
115 $code.=<<___;
116 .align  5
117 .ent    _mips_AES_encrypt
118 _mips_AES_encrypt:
119         .frame  $sp,0,$ra
120         .set    reorder
121         lw      $t0,0($key)
122         lw      $t1,4($key)
123         lw      $t2,8($key)
124         lw      $t3,12($key)
125         lw      $cnt,240($key)
126         $PTR_ADD $key0,$key,16
127
128         xor     $s0,$t0
129         xor     $s1,$t1
130         xor     $s2,$t2
131         xor     $s3,$t3
132
133         sub     $cnt,1
134         _xtr    $i0,$s1,16-2
135 .Loop_enc:
136         _xtr    $i1,$s2,16-2
137         _xtr    $i2,$s3,16-2
138         _xtr    $i3,$s0,16-2
139         and     $i0,0x3fc
140         and     $i1,0x3fc
141         and     $i2,0x3fc
142         and     $i3,0x3fc
143         $PTR_ADD $i0,$Tbl
144         $PTR_ADD $i1,$Tbl
145         $PTR_ADD $i2,$Tbl
146         $PTR_ADD $i3,$Tbl
147 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
148         lw      $t0,0($i0)              # Te1[s1>>16]
149         _xtr    $i0,$s2,8-2
150         lw      $t1,0($i1)              # Te1[s2>>16]
151         _xtr    $i1,$s3,8-2
152         lw      $t2,0($i2)              # Te1[s3>>16]
153         _xtr    $i2,$s0,8-2
154         lw      $t3,0($i3)              # Te1[s0>>16]
155         _xtr    $i3,$s1,8-2
156 #else
157         lwl     $t0,3($i0)              # Te1[s1>>16]
158         lwl     $t1,3($i1)              # Te1[s2>>16]
159         lwl     $t2,3($i2)              # Te1[s3>>16]
160         lwl     $t3,3($i3)              # Te1[s0>>16]
161         lwr     $t0,2($i0)              # Te1[s1>>16]
162         _xtr    $i0,$s2,8-2
163         lwr     $t1,2($i1)              # Te1[s2>>16]
164         _xtr    $i1,$s3,8-2
165         lwr     $t2,2($i2)              # Te1[s3>>16]
166         _xtr    $i2,$s0,8-2
167         lwr     $t3,2($i3)              # Te1[s0>>16]
168         _xtr    $i3,$s1,8-2
169 #endif
170         and     $i0,0x3fc
171         and     $i1,0x3fc
172         and     $i2,0x3fc
173         and     $i3,0x3fc
174         $PTR_ADD $i0,$Tbl
175         $PTR_ADD $i1,$Tbl
176         $PTR_ADD $i2,$Tbl
177         $PTR_ADD $i3,$Tbl
178 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
179         rotr    $t0,$t0,8
180         rotr    $t1,$t1,8
181         rotr    $t2,$t2,8
182         rotr    $t3,$t3,8
183 # if defined(_MIPSEL)
184         lw      $t4,0($i0)              # Te1[s1>>16]
185         _xtr    $i0,$s3,0-2
186         lw      $t5,0($i1)              # Te1[s2>>16]
187         _xtr    $i1,$s0,0-2
188         lw      $t6,0($i2)              # Te1[s3>>16]
189         _xtr    $i2,$s1,0-2
190         lw      $t7,0($i3)              # Te1[s0>>16]
191         _xtr    $i3,$s2,0-2
192
193         and     $i0,0x3fc
194         and     $i1,0x3fc
195         and     $i2,0x3fc
196         and     $i3,0x3fc
197         $PTR_ADD $i0,$Tbl
198         $PTR_ADD $i1,$Tbl
199         $PTR_ADD $i2,$Tbl
200         $PTR_ADD $i3,$Tbl
201         lw      $t8,0($i0)              # Te1[s1>>16]
202         $PTR_INS $i0,$s0,2,8
203         lw      $t9,0($i1)              # Te1[s2>>16]
204         $PTR_INS $i1,$s1,2,8
205         lw      $t10,0($i2)             # Te1[s3>>16]
206         $PTR_INS $i2,$s2,2,8
207         lw      $t11,0($i3)             # Te1[s0>>16]
208         $PTR_INS $i3,$s3,2,8
209 # else
210         lw      $t4,0($i0)              # Te1[s1>>16]
211         $PTR_INS $i0,$s3,2,8
212         lw      $t5,0($i1)              # Te1[s2>>16]
213         $PTR_INS $i1,$s0,2,8
214         lw      $t6,0($i2)              # Te1[s3>>16]
215         $PTR_INS $i2,$s1,2,8
216         lw      $t7,0($i3)              # Te1[s0>>16]
217         $PTR_INS $i3,$s2,2,8
218
219         lw      $t8,0($i0)              # Te1[s1>>16]
220         _xtr    $i0,$s0,24-2
221         lw      $t9,0($i1)              # Te1[s2>>16]
222         _xtr    $i1,$s1,24-2
223         lw      $t10,0($i2)             # Te1[s3>>16]
224         _xtr    $i2,$s2,24-2
225         lw      $t11,0($i3)             # Te1[s0>>16]
226         _xtr    $i3,$s3,24-2
227
228         and     $i0,0x3fc
229         and     $i1,0x3fc
230         and     $i2,0x3fc
231         and     $i3,0x3fc
232         $PTR_ADD $i0,$Tbl
233         $PTR_ADD $i1,$Tbl
234         $PTR_ADD $i2,$Tbl
235         $PTR_ADD $i3,$Tbl
236 # endif
237         rotr    $t4,$t4,16
238         rotr    $t5,$t5,16
239         rotr    $t6,$t6,16
240         rotr    $t7,$t7,16
241
242         rotr    $t8,$t8,24
243         rotr    $t9,$t9,24
244         rotr    $t10,$t10,24
245         rotr    $t11,$t11,24
246 #else
247         lwl     $t4,2($i0)              # Te2[s2>>8]
248         lwl     $t5,2($i1)              # Te2[s3>>8]
249         lwl     $t6,2($i2)              # Te2[s0>>8]
250         lwl     $t7,2($i3)              # Te2[s1>>8]
251         lwr     $t4,1($i0)              # Te2[s2>>8]
252         _xtr    $i0,$s3,0-2
253         lwr     $t5,1($i1)              # Te2[s3>>8]
254         _xtr    $i1,$s0,0-2
255         lwr     $t6,1($i2)              # Te2[s0>>8]
256         _xtr    $i2,$s1,0-2
257         lwr     $t7,1($i3)              # Te2[s1>>8]
258         _xtr    $i3,$s2,0-2
259
260         and     $i0,0x3fc
261         and     $i1,0x3fc
262         and     $i2,0x3fc
263         and     $i3,0x3fc
264         $PTR_ADD $i0,$Tbl
265         $PTR_ADD $i1,$Tbl
266         $PTR_ADD $i2,$Tbl
267         $PTR_ADD $i3,$Tbl
268         lwl     $t8,1($i0)              # Te3[s3]
269         lwl     $t9,1($i1)              # Te3[s0]
270         lwl     $t10,1($i2)             # Te3[s1]
271         lwl     $t11,1($i3)             # Te3[s2]
272         lwr     $t8,0($i0)              # Te3[s3]
273         _xtr    $i0,$s0,24-2
274         lwr     $t9,0($i1)              # Te3[s0]
275         _xtr    $i1,$s1,24-2
276         lwr     $t10,0($i2)             # Te3[s1]
277         _xtr    $i2,$s2,24-2
278         lwr     $t11,0($i3)             # Te3[s2]
279         _xtr    $i3,$s3,24-2
280
281         and     $i0,0x3fc
282         and     $i1,0x3fc
283         and     $i2,0x3fc
284         and     $i3,0x3fc
285         $PTR_ADD $i0,$Tbl
286         $PTR_ADD $i1,$Tbl
287         $PTR_ADD $i2,$Tbl
288         $PTR_ADD $i3,$Tbl
289 #endif
290         xor     $t0,$t4
291         lw      $t4,0($i0)              # Te0[s0>>24]
292         xor     $t1,$t5
293         lw      $t5,0($i1)              # Te0[s1>>24]
294         xor     $t2,$t6
295         lw      $t6,0($i2)              # Te0[s2>>24]
296         xor     $t3,$t7
297         lw      $t7,0($i3)              # Te0[s3>>24]
298
299         xor     $t0,$t8
300         lw      $s0,0($key0)
301         xor     $t1,$t9
302         lw      $s1,4($key0)
303         xor     $t2,$t10
304         lw      $s2,8($key0)
305         xor     $t3,$t11
306         lw      $s3,12($key0)
307
308         xor     $t0,$t4
309         xor     $t1,$t5
310         xor     $t2,$t6
311         xor     $t3,$t7
312
313         sub     $cnt,1
314         $PTR_ADD $key0,16
315         xor     $s0,$t0
316         xor     $s1,$t1
317         xor     $s2,$t2
318         xor     $s3,$t3
319         .set    noreorder
320         bnez    $cnt,.Loop_enc
321         _xtr    $i0,$s1,16-2
322
323         .set    reorder
324         _xtr    $i1,$s2,16-2
325         _xtr    $i2,$s3,16-2
326         _xtr    $i3,$s0,16-2
327         and     $i0,0x3fc
328         and     $i1,0x3fc
329         and     $i2,0x3fc
330         and     $i3,0x3fc
331         $PTR_ADD $i0,$Tbl
332         $PTR_ADD $i1,$Tbl
333         $PTR_ADD $i2,$Tbl
334         $PTR_ADD $i3,$Tbl
335         lbu     $t0,2($i0)              # Te4[s1>>16]
336         _xtr    $i0,$s2,8-2
337         lbu     $t1,2($i1)              # Te4[s2>>16]
338         _xtr    $i1,$s3,8-2
339         lbu     $t2,2($i2)              # Te4[s3>>16]
340         _xtr    $i2,$s0,8-2
341         lbu     $t3,2($i3)              # Te4[s0>>16]
342         _xtr    $i3,$s1,8-2
343
344         and     $i0,0x3fc
345         and     $i1,0x3fc
346         and     $i2,0x3fc
347         and     $i3,0x3fc
348         $PTR_ADD $i0,$Tbl
349         $PTR_ADD $i1,$Tbl
350         $PTR_ADD $i2,$Tbl
351         $PTR_ADD $i3,$Tbl
352 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
353 # if defined(_MIPSEL)
354         lbu     $t4,2($i0)              # Te4[s2>>8]
355         $PTR_INS $i0,$s0,2,8
356         lbu     $t5,2($i1)              # Te4[s3>>8]
357         $PTR_INS $i1,$s1,2,8
358         lbu     $t6,2($i2)              # Te4[s0>>8]
359         $PTR_INS $i2,$s2,2,8
360         lbu     $t7,2($i3)              # Te4[s1>>8]
361         $PTR_INS $i3,$s3,2,8
362
363         lbu     $t8,2($i0)              # Te4[s0>>24]
364         _xtr    $i0,$s3,0-2
365         lbu     $t9,2($i1)              # Te4[s1>>24]
366         _xtr    $i1,$s0,0-2
367         lbu     $t10,2($i2)             # Te4[s2>>24]
368         _xtr    $i2,$s1,0-2
369         lbu     $t11,2($i3)             # Te4[s3>>24]
370         _xtr    $i3,$s2,0-2
371
372         and     $i0,0x3fc
373         and     $i1,0x3fc
374         and     $i2,0x3fc
375         and     $i3,0x3fc
376         $PTR_ADD $i0,$Tbl
377         $PTR_ADD $i1,$Tbl
378         $PTR_ADD $i2,$Tbl
379         $PTR_ADD $i3,$Tbl
380 # else
381         lbu     $t4,2($i0)              # Te4[s2>>8]
382         _xtr    $i0,$s0,24-2
383         lbu     $t5,2($i1)              # Te4[s3>>8]
384         _xtr    $i1,$s1,24-2
385         lbu     $t6,2($i2)              # Te4[s0>>8]
386         _xtr    $i2,$s2,24-2
387         lbu     $t7,2($i3)              # Te4[s1>>8]
388         _xtr    $i3,$s3,24-2
389
390         and     $i0,0x3fc
391         and     $i1,0x3fc
392         and     $i2,0x3fc
393         and     $i3,0x3fc
394         $PTR_ADD $i0,$Tbl
395         $PTR_ADD $i1,$Tbl
396         $PTR_ADD $i2,$Tbl
397         $PTR_ADD $i3,$Tbl
398         lbu     $t8,2($i0)              # Te4[s0>>24]
399         $PTR_INS $i0,$s3,2,8
400         lbu     $t9,2($i1)              # Te4[s1>>24]
401         $PTR_INS $i1,$s0,2,8
402         lbu     $t10,2($i2)             # Te4[s2>>24]
403         $PTR_INS $i2,$s1,2,8
404         lbu     $t11,2($i3)             # Te4[s3>>24]
405         $PTR_INS $i3,$s2,2,8
406 # endif
407         _ins    $t0,16
408         _ins    $t1,16
409         _ins    $t2,16
410         _ins    $t3,16
411
412         _ins2   $t0,$t4,8
413         lbu     $t4,2($i0)              # Te4[s3]
414         _ins2   $t1,$t5,8
415         lbu     $t5,2($i1)              # Te4[s0]
416         _ins2   $t2,$t6,8
417         lbu     $t6,2($i2)              # Te4[s1]
418         _ins2   $t3,$t7,8
419         lbu     $t7,2($i3)              # Te4[s2]
420
421         _ins2   $t0,$t8,24
422         lw      $s0,0($key0)
423         _ins2   $t1,$t9,24
424         lw      $s1,4($key0)
425         _ins2   $t2,$t10,24
426         lw      $s2,8($key0)
427         _ins2   $t3,$t11,24
428         lw      $s3,12($key0)
429
430         _ins2   $t0,$t4,0
431         _ins2   $t1,$t5,0
432         _ins2   $t2,$t6,0
433         _ins2   $t3,$t7,0
434 #else
435         lbu     $t4,2($i0)              # Te4[s2>>8]
436         _xtr    $i0,$s0,24-2
437         lbu     $t5,2($i1)              # Te4[s3>>8]
438         _xtr    $i1,$s1,24-2
439         lbu     $t6,2($i2)              # Te4[s0>>8]
440         _xtr    $i2,$s2,24-2
441         lbu     $t7,2($i3)              # Te4[s1>>8]
442         _xtr    $i3,$s3,24-2
443
444         and     $i0,0x3fc
445         and     $i1,0x3fc
446         and     $i2,0x3fc
447         and     $i3,0x3fc
448         $PTR_ADD $i0,$Tbl
449         $PTR_ADD $i1,$Tbl
450         $PTR_ADD $i2,$Tbl
451         $PTR_ADD $i3,$Tbl
452         lbu     $t8,2($i0)              # Te4[s0>>24]
453         _xtr    $i0,$s3,0-2
454         lbu     $t9,2($i1)              # Te4[s1>>24]
455         _xtr    $i1,$s0,0-2
456         lbu     $t10,2($i2)             # Te4[s2>>24]
457         _xtr    $i2,$s1,0-2
458         lbu     $t11,2($i3)             # Te4[s3>>24]
459         _xtr    $i3,$s2,0-2
460
461         and     $i0,0x3fc
462         and     $i1,0x3fc
463         and     $i2,0x3fc
464         and     $i3,0x3fc
465         $PTR_ADD $i0,$Tbl
466         $PTR_ADD $i1,$Tbl
467         $PTR_ADD $i2,$Tbl
468         $PTR_ADD $i3,$Tbl
469
470         _ins    $t0,16
471         _ins    $t1,16
472         _ins    $t2,16
473         _ins    $t3,16
474
475         _ins    $t4,8
476         _ins    $t5,8
477         _ins    $t6,8
478         _ins    $t7,8
479
480         xor     $t0,$t4
481         lbu     $t4,2($i0)              # Te4[s3]
482         xor     $t1,$t5
483         lbu     $t5,2($i1)              # Te4[s0]
484         xor     $t2,$t6
485         lbu     $t6,2($i2)              # Te4[s1]
486         xor     $t3,$t7
487         lbu     $t7,2($i3)              # Te4[s2]
488
489         _ins    $t8,24
490         lw      $s0,0($key0)
491         _ins    $t9,24
492         lw      $s1,4($key0)
493         _ins    $t10,24
494         lw      $s2,8($key0)
495         _ins    $t11,24
496         lw      $s3,12($key0)
497
498         xor     $t0,$t8
499         xor     $t1,$t9
500         xor     $t2,$t10
501         xor     $t3,$t11
502
503         _ins    $t4,0
504         _ins    $t5,0
505         _ins    $t6,0
506         _ins    $t7,0
507
508         xor     $t0,$t4
509         xor     $t1,$t5
510         xor     $t2,$t6
511         xor     $t3,$t7
512 #endif
513         xor     $s0,$t0
514         xor     $s1,$t1
515         xor     $s2,$t2
516         xor     $s3,$t3
517
518         jr      $ra
519 .end    _mips_AES_encrypt
520
521 .align  5
522 .globl  AES_encrypt
523 .ent    AES_encrypt
524 AES_encrypt:
525         .frame  $sp,$FRAMESIZE,$ra
526         .mask   $SAVED_REGS_MASK,-$SZREG
527         .set    noreorder
528 ___
529 $code.=<<___ if ($flavour =~ /o32/i);   # o32 PIC-ification
530         .cpload $pf
531 ___
532 $code.=<<___;
533         $PTR_SUB $sp,$FRAMESIZE
534         $REG_S  $ra,$FRAMESIZE-1*$SZREG($sp)
535         $REG_S  $fp,$FRAMESIZE-2*$SZREG($sp)
536         $REG_S  $s11,$FRAMESIZE-3*$SZREG($sp)
537         $REG_S  $s10,$FRAMESIZE-4*$SZREG($sp)
538         $REG_S  $s9,$FRAMESIZE-5*$SZREG($sp)
539         $REG_S  $s8,$FRAMESIZE-6*$SZREG($sp)
540         $REG_S  $s7,$FRAMESIZE-7*$SZREG($sp)
541         $REG_S  $s6,$FRAMESIZE-8*$SZREG($sp)
542         $REG_S  $s5,$FRAMESIZE-9*$SZREG($sp)
543         $REG_S  $s4,$FRAMESIZE-10*$SZREG($sp)
544 ___
545 $code.=<<___ if ($flavour =~ /nubi/i);  # optimize non-nubi prologue
546         $REG_S  \$15,$FRAMESIZE-11*$SZREG($sp)
547         $REG_S  \$14,$FRAMESIZE-12*$SZREG($sp)
548         $REG_S  \$13,$FRAMESIZE-13*$SZREG($sp)
549         $REG_S  \$12,$FRAMESIZE-14*$SZREG($sp)
550         $REG_S  $gp,$FRAMESIZE-15*$SZREG($sp)
551 ___
552 $code.=<<___ if ($flavour !~ /o32/i);   # non-o32 PIC-ification
553         .cplocal        $Tbl
554         .cpsetup        $pf,$zero,AES_encrypt
555 ___
556 $code.=<<___;
557         .set    reorder
558         la      $Tbl,AES_Te             # PIC-ified 'load address'
559
560         lwl     $s0,0+$MSB($inp)
561         lwl     $s1,4+$MSB($inp)
562         lwl     $s2,8+$MSB($inp)
563         lwl     $s3,12+$MSB($inp)
564         lwr     $s0,0+$LSB($inp)
565         lwr     $s1,4+$LSB($inp)
566         lwr     $s2,8+$LSB($inp)
567         lwr     $s3,12+$LSB($inp)
568
569         bal     _mips_AES_encrypt
570
571         swr     $s0,0+$LSB($out)
572         swr     $s1,4+$LSB($out)
573         swr     $s2,8+$LSB($out)
574         swr     $s3,12+$LSB($out)
575         swl     $s0,0+$MSB($out)
576         swl     $s1,4+$MSB($out)
577         swl     $s2,8+$MSB($out)
578         swl     $s3,12+$MSB($out)
579
580         .set    noreorder
581         $REG_L  $ra,$FRAMESIZE-1*$SZREG($sp)
582         $REG_L  $fp,$FRAMESIZE-2*$SZREG($sp)
583         $REG_L  $s11,$FRAMESIZE-3*$SZREG($sp)
584         $REG_L  $s10,$FRAMESIZE-4*$SZREG($sp)
585         $REG_L  $s9,$FRAMESIZE-5*$SZREG($sp)
586         $REG_L  $s8,$FRAMESIZE-6*$SZREG($sp)
587         $REG_L  $s7,$FRAMESIZE-7*$SZREG($sp)
588         $REG_L  $s6,$FRAMESIZE-8*$SZREG($sp)
589         $REG_L  $s5,$FRAMESIZE-9*$SZREG($sp)
590         $REG_L  $s4,$FRAMESIZE-10*$SZREG($sp)
591 ___
592 $code.=<<___ if ($flavour =~ /nubi/i);
593         $REG_L  \$15,$FRAMESIZE-11*$SZREG($sp)
594         $REG_L  \$14,$FRAMESIZE-12*$SZREG($sp)
595         $REG_L  \$13,$FRAMESIZE-13*$SZREG($sp)
596         $REG_L  \$12,$FRAMESIZE-14*$SZREG($sp)
597         $REG_L  $gp,$FRAMESIZE-15*$SZREG($sp)
598 ___
599 $code.=<<___;
600         jr      $ra
601         $PTR_ADD $sp,$FRAMESIZE
602 .end    AES_encrypt
603 ___
604 \f
605 $code.=<<___;
606 .align  5
607 .ent    _mips_AES_decrypt
608 _mips_AES_decrypt:
609         .frame  $sp,0,$ra
610         .set    reorder
611         lw      $t0,0($key)
612         lw      $t1,4($key)
613         lw      $t2,8($key)
614         lw      $t3,12($key)
615         lw      $cnt,240($key)
616         $PTR_ADD $key0,$key,16
617
618         xor     $s0,$t0
619         xor     $s1,$t1
620         xor     $s2,$t2
621         xor     $s3,$t3
622
623         sub     $cnt,1
624         _xtr    $i0,$s3,16-2
625 .Loop_dec:
626         _xtr    $i1,$s0,16-2
627         _xtr    $i2,$s1,16-2
628         _xtr    $i3,$s2,16-2
629         and     $i0,0x3fc
630         and     $i1,0x3fc
631         and     $i2,0x3fc
632         and     $i3,0x3fc
633         $PTR_ADD $i0,$Tbl
634         $PTR_ADD $i1,$Tbl
635         $PTR_ADD $i2,$Tbl
636         $PTR_ADD $i3,$Tbl
637 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
638         lw      $t0,0($i0)              # Td1[s3>>16]
639         _xtr    $i0,$s2,8-2
640         lw      $t1,0($i1)              # Td1[s0>>16]
641         _xtr    $i1,$s3,8-2
642         lw      $t2,0($i2)              # Td1[s1>>16]
643         _xtr    $i2,$s0,8-2
644         lw      $t3,0($i3)              # Td1[s2>>16]
645         _xtr    $i3,$s1,8-2
646 #else
647         lwl     $t0,3($i0)              # Td1[s3>>16]
648         lwl     $t1,3($i1)              # Td1[s0>>16]
649         lwl     $t2,3($i2)              # Td1[s1>>16]
650         lwl     $t3,3($i3)              # Td1[s2>>16]
651         lwr     $t0,2($i0)              # Td1[s3>>16]
652         _xtr    $i0,$s2,8-2
653         lwr     $t1,2($i1)              # Td1[s0>>16]
654         _xtr    $i1,$s3,8-2
655         lwr     $t2,2($i2)              # Td1[s1>>16]
656         _xtr    $i2,$s0,8-2
657         lwr     $t3,2($i3)              # Td1[s2>>16]
658         _xtr    $i3,$s1,8-2
659 #endif
660
661         and     $i0,0x3fc
662         and     $i1,0x3fc
663         and     $i2,0x3fc
664         and     $i3,0x3fc
665         $PTR_ADD $i0,$Tbl
666         $PTR_ADD $i1,$Tbl
667         $PTR_ADD $i2,$Tbl
668         $PTR_ADD $i3,$Tbl
669 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
670         rotr    $t0,$t0,8
671         rotr    $t1,$t1,8
672         rotr    $t2,$t2,8
673         rotr    $t3,$t3,8
674 # if defined(_MIPSEL)
675         lw      $t4,0($i0)              # Td2[s2>>8]
676         _xtr    $i0,$s1,0-2
677         lw      $t5,0($i1)              # Td2[s3>>8]
678         _xtr    $i1,$s2,0-2
679         lw      $t6,0($i2)              # Td2[s0>>8]
680         _xtr    $i2,$s3,0-2
681         lw      $t7,0($i3)              # Td2[s1>>8]
682         _xtr    $i3,$s0,0-2
683
684         and     $i0,0x3fc
685         and     $i1,0x3fc
686         and     $i2,0x3fc
687         and     $i3,0x3fc
688         $PTR_ADD $i0,$Tbl
689         $PTR_ADD $i1,$Tbl
690         $PTR_ADD $i2,$Tbl
691         $PTR_ADD $i3,$Tbl
692         lw      $t8,0($i0)              # Td3[s1]
693         $PTR_INS $i0,$s0,2,8
694         lw      $t9,0($i1)              # Td3[s2]
695         $PTR_INS $i1,$s1,2,8
696         lw      $t10,0($i2)             # Td3[s3]
697         $PTR_INS $i2,$s2,2,8
698         lw      $t11,0($i3)             # Td3[s0]
699         $PTR_INS $i3,$s3,2,8
700 #else
701         lw      $t4,0($i0)              # Td2[s2>>8]
702         $PTR_INS $i0,$s1,2,8
703         lw      $t5,0($i1)              # Td2[s3>>8]
704         $PTR_INS $i1,$s2,2,8
705         lw      $t6,0($i2)              # Td2[s0>>8]
706         $PTR_INS $i2,$s3,2,8
707         lw      $t7,0($i3)              # Td2[s1>>8]
708         $PTR_INS $i3,$s0,2,8
709
710         lw      $t8,0($i0)              # Td3[s1]
711         _xtr    $i0,$s0,24-2
712         lw      $t9,0($i1)              # Td3[s2]
713         _xtr    $i1,$s1,24-2
714         lw      $t10,0($i2)             # Td3[s3]
715         _xtr    $i2,$s2,24-2
716         lw      $t11,0($i3)             # Td3[s0]
717         _xtr    $i3,$s3,24-2
718
719         and     $i0,0x3fc
720         and     $i1,0x3fc
721         and     $i2,0x3fc
722         and     $i3,0x3fc
723         $PTR_ADD $i0,$Tbl
724         $PTR_ADD $i1,$Tbl
725         $PTR_ADD $i2,$Tbl
726         $PTR_ADD $i3,$Tbl
727 #endif
728         rotr    $t4,$t4,16
729         rotr    $t5,$t5,16
730         rotr    $t6,$t6,16
731         rotr    $t7,$t7,16
732
733         rotr    $t8,$t8,24
734         rotr    $t9,$t9,24
735         rotr    $t10,$t10,24
736         rotr    $t11,$t11,24
737 #else
738         lwl     $t4,2($i0)              # Td2[s2>>8]
739         lwl     $t5,2($i1)              # Td2[s3>>8]
740         lwl     $t6,2($i2)              # Td2[s0>>8]
741         lwl     $t7,2($i3)              # Td2[s1>>8]
742         lwr     $t4,1($i0)              # Td2[s2>>8]
743         _xtr    $i0,$s1,0-2
744         lwr     $t5,1($i1)              # Td2[s3>>8]
745         _xtr    $i1,$s2,0-2
746         lwr     $t6,1($i2)              # Td2[s0>>8]
747         _xtr    $i2,$s3,0-2
748         lwr     $t7,1($i3)              # Td2[s1>>8]
749         _xtr    $i3,$s0,0-2
750
751         and     $i0,0x3fc
752         and     $i1,0x3fc
753         and     $i2,0x3fc
754         and     $i3,0x3fc
755         $PTR_ADD $i0,$Tbl
756         $PTR_ADD $i1,$Tbl
757         $PTR_ADD $i2,$Tbl
758         $PTR_ADD $i3,$Tbl
759         lwl     $t8,1($i0)              # Td3[s1]
760         lwl     $t9,1($i1)              # Td3[s2]
761         lwl     $t10,1($i2)             # Td3[s3]
762         lwl     $t11,1($i3)             # Td3[s0]
763         lwr     $t8,0($i0)              # Td3[s1]
764         _xtr    $i0,$s0,24-2
765         lwr     $t9,0($i1)              # Td3[s2]
766         _xtr    $i1,$s1,24-2
767         lwr     $t10,0($i2)             # Td3[s3]
768         _xtr    $i2,$s2,24-2
769         lwr     $t11,0($i3)             # Td3[s0]
770         _xtr    $i3,$s3,24-2
771
772         and     $i0,0x3fc
773         and     $i1,0x3fc
774         and     $i2,0x3fc
775         and     $i3,0x3fc
776         $PTR_ADD $i0,$Tbl
777         $PTR_ADD $i1,$Tbl
778         $PTR_ADD $i2,$Tbl
779         $PTR_ADD $i3,$Tbl
780 #endif
781
782         xor     $t0,$t4
783         lw      $t4,0($i0)              # Td0[s0>>24]
784         xor     $t1,$t5
785         lw      $t5,0($i1)              # Td0[s1>>24]
786         xor     $t2,$t6
787         lw      $t6,0($i2)              # Td0[s2>>24]
788         xor     $t3,$t7
789         lw      $t7,0($i3)              # Td0[s3>>24]
790
791         xor     $t0,$t8
792         lw      $s0,0($key0)
793         xor     $t1,$t9
794         lw      $s1,4($key0)
795         xor     $t2,$t10
796         lw      $s2,8($key0)
797         xor     $t3,$t11
798         lw      $s3,12($key0)
799
800         xor     $t0,$t4
801         xor     $t1,$t5
802         xor     $t2,$t6
803         xor     $t3,$t7
804
805         sub     $cnt,1
806         $PTR_ADD $key0,16
807         xor     $s0,$t0
808         xor     $s1,$t1
809         xor     $s2,$t2
810         xor     $s3,$t3
811         .set    noreorder
812         bnez    $cnt,.Loop_dec
813         _xtr    $i0,$s3,16-2
814
815         .set    reorder
816         lw      $t4,1024($Tbl)          # prefetch Td4
817         _xtr    $i0,$s3,16
818         lw      $t5,1024+32($Tbl)
819         _xtr    $i1,$s0,16
820         lw      $t6,1024+64($Tbl)
821         _xtr    $i2,$s1,16
822         lw      $t7,1024+96($Tbl)
823         _xtr    $i3,$s2,16
824         lw      $t8,1024+128($Tbl)
825         and     $i0,0xff
826         lw      $t9,1024+160($Tbl)
827         and     $i1,0xff
828         lw      $t10,1024+192($Tbl)
829         and     $i2,0xff
830         lw      $t11,1024+224($Tbl)
831         and     $i3,0xff
832
833         $PTR_ADD $i0,$Tbl
834         $PTR_ADD $i1,$Tbl
835         $PTR_ADD $i2,$Tbl
836         $PTR_ADD $i3,$Tbl
837         lbu     $t0,1024($i0)           # Td4[s3>>16]
838         _xtr    $i0,$s2,8
839         lbu     $t1,1024($i1)           # Td4[s0>>16]
840         _xtr    $i1,$s3,8
841         lbu     $t2,1024($i2)           # Td4[s1>>16]
842         _xtr    $i2,$s0,8
843         lbu     $t3,1024($i3)           # Td4[s2>>16]
844         _xtr    $i3,$s1,8
845
846         and     $i0,0xff
847         and     $i1,0xff
848         and     $i2,0xff
849         and     $i3,0xff
850         $PTR_ADD $i0,$Tbl
851         $PTR_ADD $i1,$Tbl
852         $PTR_ADD $i2,$Tbl
853         $PTR_ADD $i3,$Tbl
854 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
855 # if defined(_MIPSEL)
856         lbu     $t4,1024($i0)           # Td4[s2>>8]
857         $PTR_INS $i0,$s0,0,8
858         lbu     $t5,1024($i1)           # Td4[s3>>8]
859         $PTR_INS $i1,$s1,0,8
860         lbu     $t6,1024($i2)           # Td4[s0>>8]
861         $PTR_INS $i2,$s2,0,8
862         lbu     $t7,1024($i3)           # Td4[s1>>8]
863         $PTR_INS $i3,$s3,0,8
864
865         lbu     $t8,1024($i0)           # Td4[s0>>24]
866         _xtr    $i0,$s1,0
867         lbu     $t9,1024($i1)           # Td4[s1>>24]
868         _xtr    $i1,$s2,0
869         lbu     $t10,1024($i2)          # Td4[s2>>24]
870         _xtr    $i2,$s3,0
871         lbu     $t11,1024($i3)          # Td4[s3>>24]
872         _xtr    $i3,$s0,0
873
874         $PTR_ADD $i0,$Tbl
875         $PTR_ADD $i1,$Tbl
876         $PTR_ADD $i2,$Tbl
877         $PTR_ADD $i3,$Tbl
878 # else
879         lbu     $t4,1024($i0)           # Td4[s2>>8]
880         _xtr    $i0,$s0,24
881         lbu     $t5,1024($i1)           # Td4[s3>>8]
882         _xtr    $i1,$s1,24
883         lbu     $t6,1024($i2)           # Td4[s0>>8]
884         _xtr    $i2,$s2,24
885         lbu     $t7,1024($i3)           # Td4[s1>>8]
886         _xtr    $i3,$s3,24
887
888         $PTR_ADD $i0,$Tbl
889         $PTR_ADD $i1,$Tbl
890         $PTR_ADD $i2,$Tbl
891         $PTR_ADD $i3,$Tbl
892         lbu     $t8,1024($i0)           # Td4[s0>>24]
893         $PTR_INS $i0,$s1,0,8
894         lbu     $t9,1024($i1)           # Td4[s1>>24]
895         $PTR_INS $i1,$s2,0,8
896         lbu     $t10,1024($i2)          # Td4[s2>>24]
897         $PTR_INS $i2,$s3,0,8
898         lbu     $t11,1024($i3)          # Td4[s3>>24]
899         $PTR_INS $i3,$s0,0,8
900 # endif
901         _ins    $t0,16
902         _ins    $t1,16
903         _ins    $t2,16
904         _ins    $t3,16
905
906         _ins2   $t0,$t4,8
907         lbu     $t4,1024($i0)           # Td4[s1]
908         _ins2   $t1,$t5,8
909         lbu     $t5,1024($i1)           # Td4[s2]
910         _ins2   $t2,$t6,8
911         lbu     $t6,1024($i2)           # Td4[s3]
912         _ins2   $t3,$t7,8
913         lbu     $t7,1024($i3)           # Td4[s0]
914
915         _ins2   $t0,$t8,24
916         lw      $s0,0($key0)
917         _ins2   $t1,$t9,24
918         lw      $s1,4($key0)
919         _ins2   $t2,$t10,24
920         lw      $s2,8($key0)
921         _ins2   $t3,$t11,24
922         lw      $s3,12($key0)
923
924         _ins2   $t0,$t4,0
925         _ins2   $t1,$t5,0
926         _ins2   $t2,$t6,0
927         _ins2   $t3,$t7,0
928 #else
929         lbu     $t4,1024($i0)           # Td4[s2>>8]
930         _xtr    $i0,$s0,24
931         lbu     $t5,1024($i1)           # Td4[s3>>8]
932         _xtr    $i1,$s1,24
933         lbu     $t6,1024($i2)           # Td4[s0>>8]
934         _xtr    $i2,$s2,24
935         lbu     $t7,1024($i3)           # Td4[s1>>8]
936         _xtr    $i3,$s3,24
937
938         $PTR_ADD $i0,$Tbl
939         $PTR_ADD $i1,$Tbl
940         $PTR_ADD $i2,$Tbl
941         $PTR_ADD $i3,$Tbl
942         lbu     $t8,1024($i0)           # Td4[s0>>24]
943         _xtr    $i0,$s1,0
944         lbu     $t9,1024($i1)           # Td4[s1>>24]
945         _xtr    $i1,$s2,0
946         lbu     $t10,1024($i2)          # Td4[s2>>24]
947         _xtr    $i2,$s3,0
948         lbu     $t11,1024($i3)          # Td4[s3>>24]
949         _xtr    $i3,$s0,0
950
951         $PTR_ADD $i0,$Tbl
952         $PTR_ADD $i1,$Tbl
953         $PTR_ADD $i2,$Tbl
954         $PTR_ADD $i3,$Tbl
955
956         _ins    $t0,16
957         _ins    $t1,16
958         _ins    $t2,16
959         _ins    $t3,16
960
961         _ins    $t4,8
962         _ins    $t5,8
963         _ins    $t6,8
964         _ins    $t7,8
965
966         xor     $t0,$t4
967         lbu     $t4,1024($i0)           # Td4[s1]
968         xor     $t1,$t5
969         lbu     $t5,1024($i1)           # Td4[s2]
970         xor     $t2,$t6
971         lbu     $t6,1024($i2)           # Td4[s3]
972         xor     $t3,$t7
973         lbu     $t7,1024($i3)           # Td4[s0]
974
975         _ins    $t8,24
976         lw      $s0,0($key0)
977         _ins    $t9,24
978         lw      $s1,4($key0)
979         _ins    $t10,24
980         lw      $s2,8($key0)
981         _ins    $t11,24
982         lw      $s3,12($key0)
983
984         xor     $t0,$t8
985         xor     $t1,$t9
986         xor     $t2,$t10
987         xor     $t3,$t11
988
989         _ins    $t4,0
990         _ins    $t5,0
991         _ins    $t6,0
992         _ins    $t7,0
993
994         xor     $t0,$t4
995         xor     $t1,$t5
996         xor     $t2,$t6
997         xor     $t3,$t7
998 #endif
999
1000         xor     $s0,$t0
1001         xor     $s1,$t1
1002         xor     $s2,$t2
1003         xor     $s3,$t3
1004
1005         jr      $ra
1006 .end    _mips_AES_decrypt
1007
1008 .align  5
1009 .globl  AES_decrypt
1010 .ent    AES_decrypt
1011 AES_decrypt:
1012         .frame  $sp,$FRAMESIZE,$ra
1013         .mask   $SAVED_REGS_MASK,-$SZREG
1014         .set    noreorder
1015 ___
1016 $code.=<<___ if ($flavour =~ /o32/i);   # o32 PIC-ification
1017         .cpload $pf
1018 ___
1019 $code.=<<___;
1020         $PTR_SUB $sp,$FRAMESIZE
1021         $REG_S  $ra,$FRAMESIZE-1*$SZREG($sp)
1022         $REG_S  $fp,$FRAMESIZE-2*$SZREG($sp)
1023         $REG_S  $s11,$FRAMESIZE-3*$SZREG($sp)
1024         $REG_S  $s10,$FRAMESIZE-4*$SZREG($sp)
1025         $REG_S  $s9,$FRAMESIZE-5*$SZREG($sp)
1026         $REG_S  $s8,$FRAMESIZE-6*$SZREG($sp)
1027         $REG_S  $s7,$FRAMESIZE-7*$SZREG($sp)
1028         $REG_S  $s6,$FRAMESIZE-8*$SZREG($sp)
1029         $REG_S  $s5,$FRAMESIZE-9*$SZREG($sp)
1030         $REG_S  $s4,$FRAMESIZE-10*$SZREG($sp)
1031 ___
1032 $code.=<<___ if ($flavour =~ /nubi/i);  # optimize non-nubi prologue
1033         $REG_S  \$15,$FRAMESIZE-11*$SZREG($sp)
1034         $REG_S  \$14,$FRAMESIZE-12*$SZREG($sp)
1035         $REG_S  \$13,$FRAMESIZE-13*$SZREG($sp)
1036         $REG_S  \$12,$FRAMESIZE-14*$SZREG($sp)
1037         $REG_S  $gp,$FRAMESIZE-15*$SZREG($sp)
1038 ___
1039 $code.=<<___ if ($flavour !~ /o32/i);   # non-o32 PIC-ification
1040         .cplocal        $Tbl
1041         .cpsetup        $pf,$zero,AES_decrypt
1042 ___
1043 $code.=<<___;
1044         .set    reorder
1045         la      $Tbl,AES_Td             # PIC-ified 'load address'
1046
1047         lwl     $s0,0+$MSB($inp)
1048         lwl     $s1,4+$MSB($inp)
1049         lwl     $s2,8+$MSB($inp)
1050         lwl     $s3,12+$MSB($inp)
1051         lwr     $s0,0+$LSB($inp)
1052         lwr     $s1,4+$LSB($inp)
1053         lwr     $s2,8+$LSB($inp)
1054         lwr     $s3,12+$LSB($inp)
1055
1056         bal     _mips_AES_decrypt
1057
1058         swr     $s0,0+$LSB($out)
1059         swr     $s1,4+$LSB($out)
1060         swr     $s2,8+$LSB($out)
1061         swr     $s3,12+$LSB($out)
1062         swl     $s0,0+$MSB($out)
1063         swl     $s1,4+$MSB($out)
1064         swl     $s2,8+$MSB($out)
1065         swl     $s3,12+$MSB($out)
1066
1067         .set    noreorder
1068         $REG_L  $ra,$FRAMESIZE-1*$SZREG($sp)
1069         $REG_L  $fp,$FRAMESIZE-2*$SZREG($sp)
1070         $REG_L  $s11,$FRAMESIZE-3*$SZREG($sp)
1071         $REG_L  $s10,$FRAMESIZE-4*$SZREG($sp)
1072         $REG_L  $s9,$FRAMESIZE-5*$SZREG($sp)
1073         $REG_L  $s8,$FRAMESIZE-6*$SZREG($sp)
1074         $REG_L  $s7,$FRAMESIZE-7*$SZREG($sp)
1075         $REG_L  $s6,$FRAMESIZE-8*$SZREG($sp)
1076         $REG_L  $s5,$FRAMESIZE-9*$SZREG($sp)
1077         $REG_L  $s4,$FRAMESIZE-10*$SZREG($sp)
1078 ___
1079 $code.=<<___ if ($flavour =~ /nubi/i);
1080         $REG_L  \$15,$FRAMESIZE-11*$SZREG($sp)
1081         $REG_L  \$14,$FRAMESIZE-12*$SZREG($sp)
1082         $REG_L  \$13,$FRAMESIZE-13*$SZREG($sp)
1083         $REG_L  \$12,$FRAMESIZE-14*$SZREG($sp)
1084         $REG_L  $gp,$FRAMESIZE-15*$SZREG($sp)
1085 ___
1086 $code.=<<___;
1087         jr      $ra
1088         $PTR_ADD $sp,$FRAMESIZE
1089 .end    AES_decrypt
1090 ___
1091 }}}
1092 \f
1093 {{{
1094 my $FRAMESIZE=8*$SZREG;
1095 my $SAVED_REGS_MASK = ($flavour =~ /nubi/i) ? 0xc000f008 : 0xc0000000;
1096
1097 my ($inp,$bits,$key,$Tbl)=($a0,$a1,$a2,$a3);
1098 my ($rk0,$rk1,$rk2,$rk3,$rk4,$rk5,$rk6,$rk7)=($a4,$a5,$a6,$a7,$s0,$s1,$s2,$s3);
1099 my ($i0,$i1,$i2,$i3)=($at,$t0,$t1,$t2);
1100 my ($rcon,$cnt)=($gp,$fp);
1101
1102 $code.=<<___;
1103 .align  5
1104 .ent    _mips_AES_set_encrypt_key
1105 _mips_AES_set_encrypt_key:
1106         .frame  $sp,0,$ra
1107         .set    noreorder
1108         beqz    $inp,.Lekey_done
1109         li      $t0,-1
1110         beqz    $key,.Lekey_done
1111         $PTR_ADD $rcon,$Tbl,256
1112
1113         .set    reorder
1114         lwl     $rk0,0+$MSB($inp)       # load 128 bits
1115         lwl     $rk1,4+$MSB($inp)
1116         lwl     $rk2,8+$MSB($inp)
1117         lwl     $rk3,12+$MSB($inp)
1118         li      $at,128
1119         lwr     $rk0,0+$LSB($inp)
1120         lwr     $rk1,4+$LSB($inp)
1121         lwr     $rk2,8+$LSB($inp)
1122         lwr     $rk3,12+$LSB($inp)
1123         .set    noreorder
1124         beq     $bits,$at,.L128bits
1125         li      $cnt,10
1126
1127         .set    reorder
1128         lwl     $rk4,16+$MSB($inp)      # load 192 bits
1129         lwl     $rk5,20+$MSB($inp)
1130         li      $at,192
1131         lwr     $rk4,16+$LSB($inp)
1132         lwr     $rk5,20+$LSB($inp)
1133         .set    noreorder
1134         beq     $bits,$at,.L192bits
1135         li      $cnt,8
1136
1137         .set    reorder
1138         lwl     $rk6,24+$MSB($inp)      # load 256 bits
1139         lwl     $rk7,28+$MSB($inp)
1140         li      $at,256
1141         lwr     $rk6,24+$LSB($inp)
1142         lwr     $rk7,28+$LSB($inp)
1143         .set    noreorder
1144         beq     $bits,$at,.L256bits
1145         li      $cnt,7
1146
1147         b       .Lekey_done
1148         li      $t0,-2
1149
1150 .align  4
1151 .L128bits:
1152         .set    reorder
1153         srl     $i0,$rk3,16
1154         srl     $i1,$rk3,8
1155         and     $i0,0xff
1156         and     $i1,0xff
1157         and     $i2,$rk3,0xff
1158         srl     $i3,$rk3,24
1159         $PTR_ADD $i0,$Tbl
1160         $PTR_ADD $i1,$Tbl
1161         $PTR_ADD $i2,$Tbl
1162         $PTR_ADD $i3,$Tbl
1163         lbu     $i0,0($i0)
1164         lbu     $i1,0($i1)
1165         lbu     $i2,0($i2)
1166         lbu     $i3,0($i3)
1167
1168         sw      $rk0,0($key)
1169         sw      $rk1,4($key)
1170         sw      $rk2,8($key)
1171         sw      $rk3,12($key)
1172         sub     $cnt,1
1173         $PTR_ADD $key,16
1174
1175         _bias   $i0,24
1176         _bias   $i1,16
1177         _bias   $i2,8
1178         _bias   $i3,0
1179
1180         xor     $rk0,$i0
1181         lw      $i0,0($rcon)
1182         xor     $rk0,$i1
1183         xor     $rk0,$i2
1184         xor     $rk0,$i3
1185         xor     $rk0,$i0
1186
1187         xor     $rk1,$rk0
1188         xor     $rk2,$rk1
1189         xor     $rk3,$rk2
1190
1191         .set    noreorder
1192         bnez    $cnt,.L128bits
1193         $PTR_ADD $rcon,4
1194
1195         sw      $rk0,0($key)
1196         sw      $rk1,4($key)
1197         sw      $rk2,8($key)
1198         li      $cnt,10
1199         sw      $rk3,12($key)
1200         li      $t0,0
1201         sw      $cnt,80($key)
1202         b       .Lekey_done
1203         $PTR_SUB $key,10*16
1204
1205 .align  4
1206 .L192bits:
1207         .set    reorder
1208         srl     $i0,$rk5,16
1209         srl     $i1,$rk5,8
1210         and     $i0,0xff
1211         and     $i1,0xff
1212         and     $i2,$rk5,0xff
1213         srl     $i3,$rk5,24
1214         $PTR_ADD $i0,$Tbl
1215         $PTR_ADD $i1,$Tbl
1216         $PTR_ADD $i2,$Tbl
1217         $PTR_ADD $i3,$Tbl
1218         lbu     $i0,0($i0)
1219         lbu     $i1,0($i1)
1220         lbu     $i2,0($i2)
1221         lbu     $i3,0($i3)
1222
1223         sw      $rk0,0($key)
1224         sw      $rk1,4($key)
1225         sw      $rk2,8($key)
1226         sw      $rk3,12($key)
1227         sw      $rk4,16($key)
1228         sw      $rk5,20($key)
1229         sub     $cnt,1
1230         $PTR_ADD $key,24
1231
1232         _bias   $i0,24
1233         _bias   $i1,16
1234         _bias   $i2,8
1235         _bias   $i3,0
1236
1237         xor     $rk0,$i0
1238         lw      $i0,0($rcon)
1239         xor     $rk0,$i1
1240         xor     $rk0,$i2
1241         xor     $rk0,$i3
1242         xor     $rk0,$i0
1243
1244         xor     $rk1,$rk0
1245         xor     $rk2,$rk1
1246         xor     $rk3,$rk2
1247         xor     $rk4,$rk3
1248         xor     $rk5,$rk4
1249
1250         .set    noreorder
1251         bnez    $cnt,.L192bits
1252         $PTR_ADD $rcon,4
1253
1254         sw      $rk0,0($key)
1255         sw      $rk1,4($key)
1256         sw      $rk2,8($key)
1257         li      $cnt,12
1258         sw      $rk3,12($key)
1259         li      $t0,0
1260         sw      $cnt,48($key)
1261         b       .Lekey_done
1262         $PTR_SUB $key,12*16
1263
1264 .align  4
1265 .L256bits:
1266         .set    reorder
1267         srl     $i0,$rk7,16
1268         srl     $i1,$rk7,8
1269         and     $i0,0xff
1270         and     $i1,0xff
1271         and     $i2,$rk7,0xff
1272         srl     $i3,$rk7,24
1273         $PTR_ADD $i0,$Tbl
1274         $PTR_ADD $i1,$Tbl
1275         $PTR_ADD $i2,$Tbl
1276         $PTR_ADD $i3,$Tbl
1277         lbu     $i0,0($i0)
1278         lbu     $i1,0($i1)
1279         lbu     $i2,0($i2)
1280         lbu     $i3,0($i3)
1281
1282         sw      $rk0,0($key)
1283         sw      $rk1,4($key)
1284         sw      $rk2,8($key)
1285         sw      $rk3,12($key)
1286         sw      $rk4,16($key)
1287         sw      $rk5,20($key)
1288         sw      $rk6,24($key)
1289         sw      $rk7,28($key)
1290         sub     $cnt,1
1291
1292         _bias   $i0,24
1293         _bias   $i1,16
1294         _bias   $i2,8
1295         _bias   $i3,0
1296
1297         xor     $rk0,$i0
1298         lw      $i0,0($rcon)
1299         xor     $rk0,$i1
1300         xor     $rk0,$i2
1301         xor     $rk0,$i3
1302         xor     $rk0,$i0
1303
1304         xor     $rk1,$rk0
1305         xor     $rk2,$rk1
1306         xor     $rk3,$rk2
1307         beqz    $cnt,.L256bits_done
1308
1309         srl     $i0,$rk3,24
1310         srl     $i1,$rk3,16
1311         srl     $i2,$rk3,8
1312         and     $i3,$rk3,0xff
1313         and     $i1,0xff
1314         and     $i2,0xff
1315         $PTR_ADD $i0,$Tbl
1316         $PTR_ADD $i1,$Tbl
1317         $PTR_ADD $i2,$Tbl
1318         $PTR_ADD $i3,$Tbl
1319         lbu     $i0,0($i0)
1320         lbu     $i1,0($i1)
1321         lbu     $i2,0($i2)
1322         lbu     $i3,0($i3)
1323         sll     $i0,24
1324         sll     $i1,16
1325         sll     $i2,8
1326
1327         xor     $rk4,$i0
1328         xor     $rk4,$i1
1329         xor     $rk4,$i2
1330         xor     $rk4,$i3
1331
1332         xor     $rk5,$rk4
1333         xor     $rk6,$rk5
1334         xor     $rk7,$rk6
1335
1336         $PTR_ADD $key,32
1337         .set    noreorder
1338         b       .L256bits
1339         $PTR_ADD $rcon,4
1340
1341 .L256bits_done:
1342         sw      $rk0,32($key)
1343         sw      $rk1,36($key)
1344         sw      $rk2,40($key)
1345         li      $cnt,14
1346         sw      $rk3,44($key)
1347         li      $t0,0
1348         sw      $cnt,48($key)
1349         $PTR_SUB $key,12*16
1350
1351 .Lekey_done:
1352         jr      $ra
1353         nop
1354 .end    _mips_AES_set_encrypt_key
1355
1356 .globl  AES_set_encrypt_key
1357 .ent    AES_set_encrypt_key
1358 AES_set_encrypt_key:
1359         .frame  $sp,$FRAMESIZE,$ra
1360         .mask   $SAVED_REGS_MASK,-$SZREG
1361         .set    noreorder
1362 ___
1363 $code.=<<___ if ($flavour =~ /o32/i);   # o32 PIC-ification
1364         .cpload $pf
1365 ___
1366 $code.=<<___;
1367         $PTR_SUB $sp,$FRAMESIZE
1368         $REG_S  $ra,$FRAMESIZE-1*$SZREG($sp)
1369         $REG_S  $fp,$FRAMESIZE-2*$SZREG($sp)
1370 ___
1371 $code.=<<___ if ($flavour =~ /nubi/i);  # optimize non-nubi prologue
1372         $REG_S  $s3,$FRAMESIZE-3*$SZREG($sp)
1373         $REG_S  $s2,$FRAMESIZE-4*$SZREG($sp)
1374         $REG_S  $s1,$FRAMESIZE-5*$SZREG($sp)
1375         $REG_S  $s0,$FRAMESIZE-6*$SZREG($sp)
1376         $REG_S  $gp,$FRAMESIZE-7*$SZREG($sp)
1377 ___
1378 $code.=<<___ if ($flavour !~ /o32/i);   # non-o32 PIC-ification
1379         .cplocal        $Tbl
1380         .cpsetup        $pf,$zero,AES_set_encrypt_key
1381 ___
1382 $code.=<<___;
1383         .set    reorder
1384         la      $Tbl,AES_Te4            # PIC-ified 'load address'
1385
1386         bal     _mips_AES_set_encrypt_key
1387
1388         .set    noreorder
1389         move    $a0,$t0
1390         $REG_L  $ra,$FRAMESIZE-1*$SZREG($sp)
1391         $REG_L  $fp,$FRAMESIZE-2*$SZREG($sp)
1392 ___
1393 $code.=<<___ if ($flavour =~ /nubi/i);
1394         $REG_L  $s3,$FRAMESIZE-11*$SZREG($sp)
1395         $REG_L  $s2,$FRAMESIZE-12*$SZREG($sp)
1396         $REG_L  $s1,$FRAMESIZE-13*$SZREG($sp)
1397         $REG_L  $s0,$FRAMESIZE-14*$SZREG($sp)
1398         $REG_L  $gp,$FRAMESIZE-15*$SZREG($sp)
1399 ___
1400 $code.=<<___;
1401         jr      $ra
1402         $PTR_ADD $sp,$FRAMESIZE
1403 .end    AES_set_encrypt_key
1404 ___
1405 \f
1406 my ($head,$tail)=($inp,$bits);
1407 my ($tp1,$tp2,$tp4,$tp8,$tp9,$tpb,$tpd,$tpe)=($a4,$a5,$a6,$a7,$s0,$s1,$s2,$s3);
1408 my ($m,$x80808080,$x7f7f7f7f,$x1b1b1b1b)=($at,$t0,$t1,$t2);
1409 $code.=<<___;
1410 .align  5
1411 .globl  AES_set_decrypt_key
1412 .ent    AES_set_decrypt_key
1413 AES_set_decrypt_key:
1414         .frame  $sp,$FRAMESIZE,$ra
1415         .mask   $SAVED_REGS_MASK,-$SZREG
1416         .set    noreorder
1417 ___
1418 $code.=<<___ if ($flavour =~ /o32/i);   # o32 PIC-ification
1419         .cpload $pf
1420 ___
1421 $code.=<<___;
1422         $PTR_SUB $sp,$FRAMESIZE
1423         $REG_S  $ra,$FRAMESIZE-1*$SZREG($sp)
1424         $REG_S  $fp,$FRAMESIZE-2*$SZREG($sp)
1425 ___
1426 $code.=<<___ if ($flavour =~ /nubi/i);  # optimize non-nubi prologue
1427         $REG_S  $s3,$FRAMESIZE-3*$SZREG($sp)
1428         $REG_S  $s2,$FRAMESIZE-4*$SZREG($sp)
1429         $REG_S  $s1,$FRAMESIZE-5*$SZREG($sp)
1430         $REG_S  $s0,$FRAMESIZE-6*$SZREG($sp)
1431         $REG_S  $gp,$FRAMESIZE-7*$SZREG($sp)
1432 ___
1433 $code.=<<___ if ($flavour !~ /o32/i);   # non-o32 PIC-ification
1434         .cplocal        $Tbl
1435         .cpsetup        $pf,$zero,AES_set_decrypt_key
1436 ___
1437 $code.=<<___;
1438         .set    reorder
1439         la      $Tbl,AES_Te4            # PIC-ified 'load address'
1440
1441         bal     _mips_AES_set_encrypt_key
1442
1443         bltz    $t0,.Ldkey_done
1444
1445         sll     $at,$cnt,4
1446         $PTR_ADD $head,$key,0
1447         $PTR_ADD $tail,$key,$at
1448 .align  4
1449 .Lswap:
1450         lw      $rk0,0($head)
1451         lw      $rk1,4($head)
1452         lw      $rk2,8($head)
1453         lw      $rk3,12($head)
1454         lw      $rk4,0($tail)
1455         lw      $rk5,4($tail)
1456         lw      $rk6,8($tail)
1457         lw      $rk7,12($tail)
1458         sw      $rk0,0($tail)
1459         sw      $rk1,4($tail)
1460         sw      $rk2,8($tail)
1461         sw      $rk3,12($tail)
1462         $PTR_ADD $head,16
1463         $PTR_SUB $tail,16
1464         sw      $rk4,-16($head)
1465         sw      $rk5,-12($head)
1466         sw      $rk6,-8($head)
1467         sw      $rk7,-4($head)
1468         bne     $head,$tail,.Lswap
1469
1470         lw      $tp1,16($key)           # modulo-scheduled
1471         lui     $x80808080,0x8080
1472         sub     $cnt,1
1473         or      $x80808080,0x8080
1474         sll     $cnt,2
1475         $PTR_ADD $key,16
1476         lui     $x1b1b1b1b,0x1b1b
1477         nor     $x7f7f7f7f,$zero,$x80808080
1478         or      $x1b1b1b1b,0x1b1b
1479 .align  4
1480 .Lmix:
1481         and     $m,$tp1,$x80808080
1482         and     $tp2,$tp1,$x7f7f7f7f
1483         srl     $tp4,$m,7
1484         addu    $tp2,$tp2               # tp2<<1
1485         subu    $m,$tp4
1486         and     $m,$x1b1b1b1b
1487         xor     $tp2,$m
1488
1489         and     $m,$tp2,$x80808080
1490         and     $tp4,$tp2,$x7f7f7f7f
1491         srl     $tp8,$m,7
1492         addu    $tp4,$tp4               # tp4<<1
1493         subu    $m,$tp8
1494         and     $m,$x1b1b1b1b
1495         xor     $tp4,$m
1496
1497         and     $m,$tp4,$x80808080
1498         and     $tp8,$tp4,$x7f7f7f7f
1499         srl     $tp9,$m,7
1500         addu    $tp8,$tp8               # tp8<<1
1501         subu    $m,$tp9
1502         and     $m,$x1b1b1b1b
1503         xor     $tp8,$m
1504
1505         xor     $tp9,$tp8,$tp1
1506         xor     $tpe,$tp8,$tp4
1507         xor     $tpb,$tp9,$tp2
1508         xor     $tpd,$tp9,$tp4
1509
1510 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
1511         rotr    $tp1,$tpd,16
1512          xor    $tpe,$tp2
1513         rotr    $tp2,$tp9,8
1514         xor     $tpe,$tp1
1515         rotr    $tp4,$tpb,24
1516         xor     $tpe,$tp2
1517         lw      $tp1,4($key)            # modulo-scheduled
1518         xor     $tpe,$tp4
1519 #else
1520         _ror    $tp1,$tpd,16
1521          xor    $tpe,$tp2
1522         _ror    $tp2,$tpd,-16
1523         xor     $tpe,$tp1
1524         _ror    $tp1,$tp9,8
1525         xor     $tpe,$tp2
1526         _ror    $tp2,$tp9,-24
1527         xor     $tpe,$tp1
1528         _ror    $tp1,$tpb,24
1529         xor     $tpe,$tp2
1530         _ror    $tp2,$tpb,-8
1531         xor     $tpe,$tp1
1532         lw      $tp1,4($key)            # modulo-scheduled
1533         xor     $tpe,$tp2
1534 #endif
1535         sub     $cnt,1
1536         sw      $tpe,0($key)
1537         $PTR_ADD $key,4
1538         bnez    $cnt,.Lmix
1539
1540         li      $t0,0
1541 .Ldkey_done:
1542         .set    noreorder
1543         move    $a0,$t0
1544         $REG_L  $ra,$FRAMESIZE-1*$SZREG($sp)
1545         $REG_L  $fp,$FRAMESIZE-2*$SZREG($sp)
1546 ___
1547 $code.=<<___ if ($flavour =~ /nubi/i);
1548         $REG_L  $s3,$FRAMESIZE-11*$SZREG($sp)
1549         $REG_L  $s2,$FRAMESIZE-12*$SZREG($sp)
1550         $REG_L  $s1,$FRAMESIZE-13*$SZREG($sp)
1551         $REG_L  $s0,$FRAMESIZE-14*$SZREG($sp)
1552         $REG_L  $gp,$FRAMESIZE-15*$SZREG($sp)
1553 ___
1554 $code.=<<___;
1555         jr      $ra
1556         $PTR_ADD $sp,$FRAMESIZE
1557 .end    AES_set_decrypt_key
1558 ___
1559 }}}
1560
1561 ######################################################################
1562 # Tables are kept in endian-neutral manner
1563 $code.=<<___;
1564 .rdata
1565 .align  10
1566 AES_Te:
1567 .byte   0xc6,0x63,0x63,0xa5,    0xf8,0x7c,0x7c,0x84     # Te0
1568 .byte   0xee,0x77,0x77,0x99,    0xf6,0x7b,0x7b,0x8d
1569 .byte   0xff,0xf2,0xf2,0x0d,    0xd6,0x6b,0x6b,0xbd
1570 .byte   0xde,0x6f,0x6f,0xb1,    0x91,0xc5,0xc5,0x54
1571 .byte   0x60,0x30,0x30,0x50,    0x02,0x01,0x01,0x03
1572 .byte   0xce,0x67,0x67,0xa9,    0x56,0x2b,0x2b,0x7d
1573 .byte   0xe7,0xfe,0xfe,0x19,    0xb5,0xd7,0xd7,0x62
1574 .byte   0x4d,0xab,0xab,0xe6,    0xec,0x76,0x76,0x9a
1575 .byte   0x8f,0xca,0xca,0x45,    0x1f,0x82,0x82,0x9d
1576 .byte   0x89,0xc9,0xc9,0x40,    0xfa,0x7d,0x7d,0x87
1577 .byte   0xef,0xfa,0xfa,0x15,    0xb2,0x59,0x59,0xeb
1578 .byte   0x8e,0x47,0x47,0xc9,    0xfb,0xf0,0xf0,0x0b
1579 .byte   0x41,0xad,0xad,0xec,    0xb3,0xd4,0xd4,0x67
1580 .byte   0x5f,0xa2,0xa2,0xfd,    0x45,0xaf,0xaf,0xea
1581 .byte   0x23,0x9c,0x9c,0xbf,    0x53,0xa4,0xa4,0xf7
1582 .byte   0xe4,0x72,0x72,0x96,    0x9b,0xc0,0xc0,0x5b
1583 .byte   0x75,0xb7,0xb7,0xc2,    0xe1,0xfd,0xfd,0x1c
1584 .byte   0x3d,0x93,0x93,0xae,    0x4c,0x26,0x26,0x6a
1585 .byte   0x6c,0x36,0x36,0x5a,    0x7e,0x3f,0x3f,0x41
1586 .byte   0xf5,0xf7,0xf7,0x02,    0x83,0xcc,0xcc,0x4f
1587 .byte   0x68,0x34,0x34,0x5c,    0x51,0xa5,0xa5,0xf4
1588 .byte   0xd1,0xe5,0xe5,0x34,    0xf9,0xf1,0xf1,0x08
1589 .byte   0xe2,0x71,0x71,0x93,    0xab,0xd8,0xd8,0x73
1590 .byte   0x62,0x31,0x31,0x53,    0x2a,0x15,0x15,0x3f
1591 .byte   0x08,0x04,0x04,0x0c,    0x95,0xc7,0xc7,0x52
1592 .byte   0x46,0x23,0x23,0x65,    0x9d,0xc3,0xc3,0x5e
1593 .byte   0x30,0x18,0x18,0x28,    0x37,0x96,0x96,0xa1
1594 .byte   0x0a,0x05,0x05,0x0f,    0x2f,0x9a,0x9a,0xb5
1595 .byte   0x0e,0x07,0x07,0x09,    0x24,0x12,0x12,0x36
1596 .byte   0x1b,0x80,0x80,0x9b,    0xdf,0xe2,0xe2,0x3d
1597 .byte   0xcd,0xeb,0xeb,0x26,    0x4e,0x27,0x27,0x69
1598 .byte   0x7f,0xb2,0xb2,0xcd,    0xea,0x75,0x75,0x9f
1599 .byte   0x12,0x09,0x09,0x1b,    0x1d,0x83,0x83,0x9e
1600 .byte   0x58,0x2c,0x2c,0x74,    0x34,0x1a,0x1a,0x2e
1601 .byte   0x36,0x1b,0x1b,0x2d,    0xdc,0x6e,0x6e,0xb2
1602 .byte   0xb4,0x5a,0x5a,0xee,    0x5b,0xa0,0xa0,0xfb
1603 .byte   0xa4,0x52,0x52,0xf6,    0x76,0x3b,0x3b,0x4d
1604 .byte   0xb7,0xd6,0xd6,0x61,    0x7d,0xb3,0xb3,0xce
1605 .byte   0x52,0x29,0x29,0x7b,    0xdd,0xe3,0xe3,0x3e
1606 .byte   0x5e,0x2f,0x2f,0x71,    0x13,0x84,0x84,0x97
1607 .byte   0xa6,0x53,0x53,0xf5,    0xb9,0xd1,0xd1,0x68
1608 .byte   0x00,0x00,0x00,0x00,    0xc1,0xed,0xed,0x2c
1609 .byte   0x40,0x20,0x20,0x60,    0xe3,0xfc,0xfc,0x1f
1610 .byte   0x79,0xb1,0xb1,0xc8,    0xb6,0x5b,0x5b,0xed
1611 .byte   0xd4,0x6a,0x6a,0xbe,    0x8d,0xcb,0xcb,0x46
1612 .byte   0x67,0xbe,0xbe,0xd9,    0x72,0x39,0x39,0x4b
1613 .byte   0x94,0x4a,0x4a,0xde,    0x98,0x4c,0x4c,0xd4
1614 .byte   0xb0,0x58,0x58,0xe8,    0x85,0xcf,0xcf,0x4a
1615 .byte   0xbb,0xd0,0xd0,0x6b,    0xc5,0xef,0xef,0x2a
1616 .byte   0x4f,0xaa,0xaa,0xe5,    0xed,0xfb,0xfb,0x16
1617 .byte   0x86,0x43,0x43,0xc5,    0x9a,0x4d,0x4d,0xd7
1618 .byte   0x66,0x33,0x33,0x55,    0x11,0x85,0x85,0x94
1619 .byte   0x8a,0x45,0x45,0xcf,    0xe9,0xf9,0xf9,0x10
1620 .byte   0x04,0x02,0x02,0x06,    0xfe,0x7f,0x7f,0x81
1621 .byte   0xa0,0x50,0x50,0xf0,    0x78,0x3c,0x3c,0x44
1622 .byte   0x25,0x9f,0x9f,0xba,    0x4b,0xa8,0xa8,0xe3
1623 .byte   0xa2,0x51,0x51,0xf3,    0x5d,0xa3,0xa3,0xfe
1624 .byte   0x80,0x40,0x40,0xc0,    0x05,0x8f,0x8f,0x8a
1625 .byte   0x3f,0x92,0x92,0xad,    0x21,0x9d,0x9d,0xbc
1626 .byte   0x70,0x38,0x38,0x48,    0xf1,0xf5,0xf5,0x04
1627 .byte   0x63,0xbc,0xbc,0xdf,    0x77,0xb6,0xb6,0xc1
1628 .byte   0xaf,0xda,0xda,0x75,    0x42,0x21,0x21,0x63
1629 .byte   0x20,0x10,0x10,0x30,    0xe5,0xff,0xff,0x1a
1630 .byte   0xfd,0xf3,0xf3,0x0e,    0xbf,0xd2,0xd2,0x6d
1631 .byte   0x81,0xcd,0xcd,0x4c,    0x18,0x0c,0x0c,0x14
1632 .byte   0x26,0x13,0x13,0x35,    0xc3,0xec,0xec,0x2f
1633 .byte   0xbe,0x5f,0x5f,0xe1,    0x35,0x97,0x97,0xa2
1634 .byte   0x88,0x44,0x44,0xcc,    0x2e,0x17,0x17,0x39
1635 .byte   0x93,0xc4,0xc4,0x57,    0x55,0xa7,0xa7,0xf2
1636 .byte   0xfc,0x7e,0x7e,0x82,    0x7a,0x3d,0x3d,0x47
1637 .byte   0xc8,0x64,0x64,0xac,    0xba,0x5d,0x5d,0xe7
1638 .byte   0x32,0x19,0x19,0x2b,    0xe6,0x73,0x73,0x95
1639 .byte   0xc0,0x60,0x60,0xa0,    0x19,0x81,0x81,0x98
1640 .byte   0x9e,0x4f,0x4f,0xd1,    0xa3,0xdc,0xdc,0x7f
1641 .byte   0x44,0x22,0x22,0x66,    0x54,0x2a,0x2a,0x7e
1642 .byte   0x3b,0x90,0x90,0xab,    0x0b,0x88,0x88,0x83
1643 .byte   0x8c,0x46,0x46,0xca,    0xc7,0xee,0xee,0x29
1644 .byte   0x6b,0xb8,0xb8,0xd3,    0x28,0x14,0x14,0x3c
1645 .byte   0xa7,0xde,0xde,0x79,    0xbc,0x5e,0x5e,0xe2
1646 .byte   0x16,0x0b,0x0b,0x1d,    0xad,0xdb,0xdb,0x76
1647 .byte   0xdb,0xe0,0xe0,0x3b,    0x64,0x32,0x32,0x56
1648 .byte   0x74,0x3a,0x3a,0x4e,    0x14,0x0a,0x0a,0x1e
1649 .byte   0x92,0x49,0x49,0xdb,    0x0c,0x06,0x06,0x0a
1650 .byte   0x48,0x24,0x24,0x6c,    0xb8,0x5c,0x5c,0xe4
1651 .byte   0x9f,0xc2,0xc2,0x5d,    0xbd,0xd3,0xd3,0x6e
1652 .byte   0x43,0xac,0xac,0xef,    0xc4,0x62,0x62,0xa6
1653 .byte   0x39,0x91,0x91,0xa8,    0x31,0x95,0x95,0xa4
1654 .byte   0xd3,0xe4,0xe4,0x37,    0xf2,0x79,0x79,0x8b
1655 .byte   0xd5,0xe7,0xe7,0x32,    0x8b,0xc8,0xc8,0x43
1656 .byte   0x6e,0x37,0x37,0x59,    0xda,0x6d,0x6d,0xb7
1657 .byte   0x01,0x8d,0x8d,0x8c,    0xb1,0xd5,0xd5,0x64
1658 .byte   0x9c,0x4e,0x4e,0xd2,    0x49,0xa9,0xa9,0xe0
1659 .byte   0xd8,0x6c,0x6c,0xb4,    0xac,0x56,0x56,0xfa
1660 .byte   0xf3,0xf4,0xf4,0x07,    0xcf,0xea,0xea,0x25
1661 .byte   0xca,0x65,0x65,0xaf,    0xf4,0x7a,0x7a,0x8e
1662 .byte   0x47,0xae,0xae,0xe9,    0x10,0x08,0x08,0x18
1663 .byte   0x6f,0xba,0xba,0xd5,    0xf0,0x78,0x78,0x88
1664 .byte   0x4a,0x25,0x25,0x6f,    0x5c,0x2e,0x2e,0x72
1665 .byte   0x38,0x1c,0x1c,0x24,    0x57,0xa6,0xa6,0xf1
1666 .byte   0x73,0xb4,0xb4,0xc7,    0x97,0xc6,0xc6,0x51
1667 .byte   0xcb,0xe8,0xe8,0x23,    0xa1,0xdd,0xdd,0x7c
1668 .byte   0xe8,0x74,0x74,0x9c,    0x3e,0x1f,0x1f,0x21
1669 .byte   0x96,0x4b,0x4b,0xdd,    0x61,0xbd,0xbd,0xdc
1670 .byte   0x0d,0x8b,0x8b,0x86,    0x0f,0x8a,0x8a,0x85
1671 .byte   0xe0,0x70,0x70,0x90,    0x7c,0x3e,0x3e,0x42
1672 .byte   0x71,0xb5,0xb5,0xc4,    0xcc,0x66,0x66,0xaa
1673 .byte   0x90,0x48,0x48,0xd8,    0x06,0x03,0x03,0x05
1674 .byte   0xf7,0xf6,0xf6,0x01,    0x1c,0x0e,0x0e,0x12
1675 .byte   0xc2,0x61,0x61,0xa3,    0x6a,0x35,0x35,0x5f
1676 .byte   0xae,0x57,0x57,0xf9,    0x69,0xb9,0xb9,0xd0
1677 .byte   0x17,0x86,0x86,0x91,    0x99,0xc1,0xc1,0x58
1678 .byte   0x3a,0x1d,0x1d,0x27,    0x27,0x9e,0x9e,0xb9
1679 .byte   0xd9,0xe1,0xe1,0x38,    0xeb,0xf8,0xf8,0x13
1680 .byte   0x2b,0x98,0x98,0xb3,    0x22,0x11,0x11,0x33
1681 .byte   0xd2,0x69,0x69,0xbb,    0xa9,0xd9,0xd9,0x70
1682 .byte   0x07,0x8e,0x8e,0x89,    0x33,0x94,0x94,0xa7
1683 .byte   0x2d,0x9b,0x9b,0xb6,    0x3c,0x1e,0x1e,0x22
1684 .byte   0x15,0x87,0x87,0x92,    0xc9,0xe9,0xe9,0x20
1685 .byte   0x87,0xce,0xce,0x49,    0xaa,0x55,0x55,0xff
1686 .byte   0x50,0x28,0x28,0x78,    0xa5,0xdf,0xdf,0x7a
1687 .byte   0x03,0x8c,0x8c,0x8f,    0x59,0xa1,0xa1,0xf8
1688 .byte   0x09,0x89,0x89,0x80,    0x1a,0x0d,0x0d,0x17
1689 .byte   0x65,0xbf,0xbf,0xda,    0xd7,0xe6,0xe6,0x31
1690 .byte   0x84,0x42,0x42,0xc6,    0xd0,0x68,0x68,0xb8
1691 .byte   0x82,0x41,0x41,0xc3,    0x29,0x99,0x99,0xb0
1692 .byte   0x5a,0x2d,0x2d,0x77,    0x1e,0x0f,0x0f,0x11
1693 .byte   0x7b,0xb0,0xb0,0xcb,    0xa8,0x54,0x54,0xfc
1694 .byte   0x6d,0xbb,0xbb,0xd6,    0x2c,0x16,0x16,0x3a
1695
1696 AES_Td:
1697 .byte   0x51,0xf4,0xa7,0x50,    0x7e,0x41,0x65,0x53     # Td0
1698 .byte   0x1a,0x17,0xa4,0xc3,    0x3a,0x27,0x5e,0x96
1699 .byte   0x3b,0xab,0x6b,0xcb,    0x1f,0x9d,0x45,0xf1
1700 .byte   0xac,0xfa,0x58,0xab,    0x4b,0xe3,0x03,0x93
1701 .byte   0x20,0x30,0xfa,0x55,    0xad,0x76,0x6d,0xf6
1702 .byte   0x88,0xcc,0x76,0x91,    0xf5,0x02,0x4c,0x25
1703 .byte   0x4f,0xe5,0xd7,0xfc,    0xc5,0x2a,0xcb,0xd7
1704 .byte   0x26,0x35,0x44,0x80,    0xb5,0x62,0xa3,0x8f
1705 .byte   0xde,0xb1,0x5a,0x49,    0x25,0xba,0x1b,0x67
1706 .byte   0x45,0xea,0x0e,0x98,    0x5d,0xfe,0xc0,0xe1
1707 .byte   0xc3,0x2f,0x75,0x02,    0x81,0x4c,0xf0,0x12
1708 .byte   0x8d,0x46,0x97,0xa3,    0x6b,0xd3,0xf9,0xc6
1709 .byte   0x03,0x8f,0x5f,0xe7,    0x15,0x92,0x9c,0x95
1710 .byte   0xbf,0x6d,0x7a,0xeb,    0x95,0x52,0x59,0xda
1711 .byte   0xd4,0xbe,0x83,0x2d,    0x58,0x74,0x21,0xd3
1712 .byte   0x49,0xe0,0x69,0x29,    0x8e,0xc9,0xc8,0x44
1713 .byte   0x75,0xc2,0x89,0x6a,    0xf4,0x8e,0x79,0x78
1714 .byte   0x99,0x58,0x3e,0x6b,    0x27,0xb9,0x71,0xdd
1715 .byte   0xbe,0xe1,0x4f,0xb6,    0xf0,0x88,0xad,0x17
1716 .byte   0xc9,0x20,0xac,0x66,    0x7d,0xce,0x3a,0xb4
1717 .byte   0x63,0xdf,0x4a,0x18,    0xe5,0x1a,0x31,0x82
1718 .byte   0x97,0x51,0x33,0x60,    0x62,0x53,0x7f,0x45
1719 .byte   0xb1,0x64,0x77,0xe0,    0xbb,0x6b,0xae,0x84
1720 .byte   0xfe,0x81,0xa0,0x1c,    0xf9,0x08,0x2b,0x94
1721 .byte   0x70,0x48,0x68,0x58,    0x8f,0x45,0xfd,0x19
1722 .byte   0x94,0xde,0x6c,0x87,    0x52,0x7b,0xf8,0xb7
1723 .byte   0xab,0x73,0xd3,0x23,    0x72,0x4b,0x02,0xe2
1724 .byte   0xe3,0x1f,0x8f,0x57,    0x66,0x55,0xab,0x2a
1725 .byte   0xb2,0xeb,0x28,0x07,    0x2f,0xb5,0xc2,0x03
1726 .byte   0x86,0xc5,0x7b,0x9a,    0xd3,0x37,0x08,0xa5
1727 .byte   0x30,0x28,0x87,0xf2,    0x23,0xbf,0xa5,0xb2
1728 .byte   0x02,0x03,0x6a,0xba,    0xed,0x16,0x82,0x5c
1729 .byte   0x8a,0xcf,0x1c,0x2b,    0xa7,0x79,0xb4,0x92
1730 .byte   0xf3,0x07,0xf2,0xf0,    0x4e,0x69,0xe2,0xa1
1731 .byte   0x65,0xda,0xf4,0xcd,    0x06,0x05,0xbe,0xd5
1732 .byte   0xd1,0x34,0x62,0x1f,    0xc4,0xa6,0xfe,0x8a
1733 .byte   0x34,0x2e,0x53,0x9d,    0xa2,0xf3,0x55,0xa0
1734 .byte   0x05,0x8a,0xe1,0x32,    0xa4,0xf6,0xeb,0x75
1735 .byte   0x0b,0x83,0xec,0x39,    0x40,0x60,0xef,0xaa
1736 .byte   0x5e,0x71,0x9f,0x06,    0xbd,0x6e,0x10,0x51
1737 .byte   0x3e,0x21,0x8a,0xf9,    0x96,0xdd,0x06,0x3d
1738 .byte   0xdd,0x3e,0x05,0xae,    0x4d,0xe6,0xbd,0x46
1739 .byte   0x91,0x54,0x8d,0xb5,    0x71,0xc4,0x5d,0x05
1740 .byte   0x04,0x06,0xd4,0x6f,    0x60,0x50,0x15,0xff
1741 .byte   0x19,0x98,0xfb,0x24,    0xd6,0xbd,0xe9,0x97
1742 .byte   0x89,0x40,0x43,0xcc,    0x67,0xd9,0x9e,0x77
1743 .byte   0xb0,0xe8,0x42,0xbd,    0x07,0x89,0x8b,0x88
1744 .byte   0xe7,0x19,0x5b,0x38,    0x79,0xc8,0xee,0xdb
1745 .byte   0xa1,0x7c,0x0a,0x47,    0x7c,0x42,0x0f,0xe9
1746 .byte   0xf8,0x84,0x1e,0xc9,    0x00,0x00,0x00,0x00
1747 .byte   0x09,0x80,0x86,0x83,    0x32,0x2b,0xed,0x48
1748 .byte   0x1e,0x11,0x70,0xac,    0x6c,0x5a,0x72,0x4e
1749 .byte   0xfd,0x0e,0xff,0xfb,    0x0f,0x85,0x38,0x56
1750 .byte   0x3d,0xae,0xd5,0x1e,    0x36,0x2d,0x39,0x27
1751 .byte   0x0a,0x0f,0xd9,0x64,    0x68,0x5c,0xa6,0x21
1752 .byte   0x9b,0x5b,0x54,0xd1,    0x24,0x36,0x2e,0x3a
1753 .byte   0x0c,0x0a,0x67,0xb1,    0x93,0x57,0xe7,0x0f
1754 .byte   0xb4,0xee,0x96,0xd2,    0x1b,0x9b,0x91,0x9e
1755 .byte   0x80,0xc0,0xc5,0x4f,    0x61,0xdc,0x20,0xa2
1756 .byte   0x5a,0x77,0x4b,0x69,    0x1c,0x12,0x1a,0x16
1757 .byte   0xe2,0x93,0xba,0x0a,    0xc0,0xa0,0x2a,0xe5
1758 .byte   0x3c,0x22,0xe0,0x43,    0x12,0x1b,0x17,0x1d
1759 .byte   0x0e,0x09,0x0d,0x0b,    0xf2,0x8b,0xc7,0xad
1760 .byte   0x2d,0xb6,0xa8,0xb9,    0x14,0x1e,0xa9,0xc8
1761 .byte   0x57,0xf1,0x19,0x85,    0xaf,0x75,0x07,0x4c
1762 .byte   0xee,0x99,0xdd,0xbb,    0xa3,0x7f,0x60,0xfd
1763 .byte   0xf7,0x01,0x26,0x9f,    0x5c,0x72,0xf5,0xbc
1764 .byte   0x44,0x66,0x3b,0xc5,    0x5b,0xfb,0x7e,0x34
1765 .byte   0x8b,0x43,0x29,0x76,    0xcb,0x23,0xc6,0xdc
1766 .byte   0xb6,0xed,0xfc,0x68,    0xb8,0xe4,0xf1,0x63
1767 .byte   0xd7,0x31,0xdc,0xca,    0x42,0x63,0x85,0x10
1768 .byte   0x13,0x97,0x22,0x40,    0x84,0xc6,0x11,0x20
1769 .byte   0x85,0x4a,0x24,0x7d,    0xd2,0xbb,0x3d,0xf8
1770 .byte   0xae,0xf9,0x32,0x11,    0xc7,0x29,0xa1,0x6d
1771 .byte   0x1d,0x9e,0x2f,0x4b,    0xdc,0xb2,0x30,0xf3
1772 .byte   0x0d,0x86,0x52,0xec,    0x77,0xc1,0xe3,0xd0
1773 .byte   0x2b,0xb3,0x16,0x6c,    0xa9,0x70,0xb9,0x99
1774 .byte   0x11,0x94,0x48,0xfa,    0x47,0xe9,0x64,0x22
1775 .byte   0xa8,0xfc,0x8c,0xc4,    0xa0,0xf0,0x3f,0x1a
1776 .byte   0x56,0x7d,0x2c,0xd8,    0x22,0x33,0x90,0xef
1777 .byte   0x87,0x49,0x4e,0xc7,    0xd9,0x38,0xd1,0xc1
1778 .byte   0x8c,0xca,0xa2,0xfe,    0x98,0xd4,0x0b,0x36
1779 .byte   0xa6,0xf5,0x81,0xcf,    0xa5,0x7a,0xde,0x28
1780 .byte   0xda,0xb7,0x8e,0x26,    0x3f,0xad,0xbf,0xa4
1781 .byte   0x2c,0x3a,0x9d,0xe4,    0x50,0x78,0x92,0x0d
1782 .byte   0x6a,0x5f,0xcc,0x9b,    0x54,0x7e,0x46,0x62
1783 .byte   0xf6,0x8d,0x13,0xc2,    0x90,0xd8,0xb8,0xe8
1784 .byte   0x2e,0x39,0xf7,0x5e,    0x82,0xc3,0xaf,0xf5
1785 .byte   0x9f,0x5d,0x80,0xbe,    0x69,0xd0,0x93,0x7c
1786 .byte   0x6f,0xd5,0x2d,0xa9,    0xcf,0x25,0x12,0xb3
1787 .byte   0xc8,0xac,0x99,0x3b,    0x10,0x18,0x7d,0xa7
1788 .byte   0xe8,0x9c,0x63,0x6e,    0xdb,0x3b,0xbb,0x7b
1789 .byte   0xcd,0x26,0x78,0x09,    0x6e,0x59,0x18,0xf4
1790 .byte   0xec,0x9a,0xb7,0x01,    0x83,0x4f,0x9a,0xa8
1791 .byte   0xe6,0x95,0x6e,0x65,    0xaa,0xff,0xe6,0x7e
1792 .byte   0x21,0xbc,0xcf,0x08,    0xef,0x15,0xe8,0xe6
1793 .byte   0xba,0xe7,0x9b,0xd9,    0x4a,0x6f,0x36,0xce
1794 .byte   0xea,0x9f,0x09,0xd4,    0x29,0xb0,0x7c,0xd6
1795 .byte   0x31,0xa4,0xb2,0xaf,    0x2a,0x3f,0x23,0x31
1796 .byte   0xc6,0xa5,0x94,0x30,    0x35,0xa2,0x66,0xc0
1797 .byte   0x74,0x4e,0xbc,0x37,    0xfc,0x82,0xca,0xa6
1798 .byte   0xe0,0x90,0xd0,0xb0,    0x33,0xa7,0xd8,0x15
1799 .byte   0xf1,0x04,0x98,0x4a,    0x41,0xec,0xda,0xf7
1800 .byte   0x7f,0xcd,0x50,0x0e,    0x17,0x91,0xf6,0x2f
1801 .byte   0x76,0x4d,0xd6,0x8d,    0x43,0xef,0xb0,0x4d
1802 .byte   0xcc,0xaa,0x4d,0x54,    0xe4,0x96,0x04,0xdf
1803 .byte   0x9e,0xd1,0xb5,0xe3,    0x4c,0x6a,0x88,0x1b
1804 .byte   0xc1,0x2c,0x1f,0xb8,    0x46,0x65,0x51,0x7f
1805 .byte   0x9d,0x5e,0xea,0x04,    0x01,0x8c,0x35,0x5d
1806 .byte   0xfa,0x87,0x74,0x73,    0xfb,0x0b,0x41,0x2e
1807 .byte   0xb3,0x67,0x1d,0x5a,    0x92,0xdb,0xd2,0x52
1808 .byte   0xe9,0x10,0x56,0x33,    0x6d,0xd6,0x47,0x13
1809 .byte   0x9a,0xd7,0x61,0x8c,    0x37,0xa1,0x0c,0x7a
1810 .byte   0x59,0xf8,0x14,0x8e,    0xeb,0x13,0x3c,0x89
1811 .byte   0xce,0xa9,0x27,0xee,    0xb7,0x61,0xc9,0x35
1812 .byte   0xe1,0x1c,0xe5,0xed,    0x7a,0x47,0xb1,0x3c
1813 .byte   0x9c,0xd2,0xdf,0x59,    0x55,0xf2,0x73,0x3f
1814 .byte   0x18,0x14,0xce,0x79,    0x73,0xc7,0x37,0xbf
1815 .byte   0x53,0xf7,0xcd,0xea,    0x5f,0xfd,0xaa,0x5b
1816 .byte   0xdf,0x3d,0x6f,0x14,    0x78,0x44,0xdb,0x86
1817 .byte   0xca,0xaf,0xf3,0x81,    0xb9,0x68,0xc4,0x3e
1818 .byte   0x38,0x24,0x34,0x2c,    0xc2,0xa3,0x40,0x5f
1819 .byte   0x16,0x1d,0xc3,0x72,    0xbc,0xe2,0x25,0x0c
1820 .byte   0x28,0x3c,0x49,0x8b,    0xff,0x0d,0x95,0x41
1821 .byte   0x39,0xa8,0x01,0x71,    0x08,0x0c,0xb3,0xde
1822 .byte   0xd8,0xb4,0xe4,0x9c,    0x64,0x56,0xc1,0x90
1823 .byte   0x7b,0xcb,0x84,0x61,    0xd5,0x32,0xb6,0x70
1824 .byte   0x48,0x6c,0x5c,0x74,    0xd0,0xb8,0x57,0x42
1825
1826 .byte   0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38  # Td4
1827 .byte   0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb
1828 .byte   0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87
1829 .byte   0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb
1830 .byte   0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d
1831 .byte   0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e
1832 .byte   0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2
1833 .byte   0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25
1834 .byte   0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16
1835 .byte   0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92
1836 .byte   0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda
1837 .byte   0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84
1838 .byte   0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a
1839 .byte   0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06
1840 .byte   0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02
1841 .byte   0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b
1842 .byte   0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea
1843 .byte   0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73
1844 .byte   0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85
1845 .byte   0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e
1846 .byte   0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89
1847 .byte   0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b
1848 .byte   0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20
1849 .byte   0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4
1850 .byte   0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31
1851 .byte   0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f
1852 .byte   0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d
1853 .byte   0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef
1854 .byte   0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0
1855 .byte   0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61
1856 .byte   0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26
1857 .byte   0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
1858
1859 AES_Te4:
1860 .byte   0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5  # Te4
1861 .byte   0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76
1862 .byte   0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0
1863 .byte   0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0
1864 .byte   0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc
1865 .byte   0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15
1866 .byte   0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a
1867 .byte   0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75
1868 .byte   0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0
1869 .byte   0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84
1870 .byte   0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b
1871 .byte   0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf
1872 .byte   0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85
1873 .byte   0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8
1874 .byte   0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5
1875 .byte   0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2
1876 .byte   0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17
1877 .byte   0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73
1878 .byte   0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88
1879 .byte   0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb
1880 .byte   0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c
1881 .byte   0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79
1882 .byte   0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9
1883 .byte   0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08
1884 .byte   0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6
1885 .byte   0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a
1886 .byte   0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e
1887 .byte   0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e
1888 .byte   0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94
1889 .byte   0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf
1890 .byte   0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68
1891 .byte   0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
1892
1893 .byte   0x01,0x00,0x00,0x00,    0x02,0x00,0x00,0x00     # rcon
1894 .byte   0x04,0x00,0x00,0x00,    0x08,0x00,0x00,0x00
1895 .byte   0x10,0x00,0x00,0x00,    0x20,0x00,0x00,0x00
1896 .byte   0x40,0x00,0x00,0x00,    0x80,0x00,0x00,0x00
1897 .byte   0x1B,0x00,0x00,0x00,    0x36,0x00,0x00,0x00
1898 ___
1899 \f
1900 foreach (split("\n",$code)) {
1901         s/\`([^\`]*)\`/eval $1/ge;
1902
1903         # made-up _instructions, _xtr, _ins, _ror and _bias, cope
1904         # with byte order dependencies...
1905         if (/^\s+_/) {
1906             s/(_[a-z]+\s+)(\$[0-9]+),([^,]+)(#.*)*$/$1$2,$2,$3/;
1907
1908             s/_xtr\s+(\$[0-9]+),(\$[0-9]+),([0-9]+(\-2)*)/
1909                 sprintf("srl\t$1,$2,%d",$big_endian ?   eval($3)
1910                                         :               eval("24-$3"))/e or
1911             s/_ins\s+(\$[0-9]+),(\$[0-9]+),([0-9]+)/
1912                 sprintf("sll\t$1,$2,%d",$big_endian ?   eval($3)
1913                                         :               eval("24-$3"))/e or
1914             s/_ins2\s+(\$[0-9]+),(\$[0-9]+),([0-9]+)/
1915                 sprintf("ins\t$1,$2,%d,8",$big_endian ? eval($3)
1916                                         :               eval("24-$3"))/e or
1917             s/_ror\s+(\$[0-9]+),(\$[0-9]+),(\-?[0-9]+)/
1918                 sprintf("srl\t$1,$2,%d",$big_endian ?   eval($3)
1919                                         :               eval("$3*-1"))/e or
1920             s/_bias\s+(\$[0-9]+),(\$[0-9]+),([0-9]+)/
1921                 sprintf("sll\t$1,$2,%d",$big_endian ?   eval($3)
1922                                         :               eval("($3-16)&31"))/e;
1923
1924             s/srl\s+(\$[0-9]+),(\$[0-9]+),\-([0-9]+)/
1925                 sprintf("sll\t$1,$2,$3")/e                              or
1926             s/srl\s+(\$[0-9]+),(\$[0-9]+),0/
1927                 sprintf("and\t$1,$2,0xff")/e                            or
1928             s/(sll\s+\$[0-9]+,\$[0-9]+,0)/#$1/;
1929         }
1930
1931         # convert lwl/lwr and swr/swl to little-endian order
1932         if (!$big_endian && /^\s+[sl]w[lr]\s+/) {
1933             s/([sl]wl.*)([0-9]+)\((\$[0-9]+)\)/
1934                 sprintf("$1%d($3)",eval("$2-$2%4+($2%4-1)&3"))/e        or
1935             s/([sl]wr.*)([0-9]+)\((\$[0-9]+)\)/
1936                 sprintf("$1%d($3)",eval("$2-$2%4+($2%4+1)&3"))/e;
1937         }
1938
1939         s/(rotr\s+\$[0-9]+,\$[0-9]+),([0-9]+)/sprintf("$1,%d",32-$2)/e if(!$big_endian);
1940
1941         print $_,"\n";
1942 }
1943
1944 close STDOUT;