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 # ====================================================================
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...
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:
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));
38 # The return value is placed in $a0. Following coding rules facilitate
41 # - never ever touch $tp, "thread pointer", former $gp;
42 # - copy return value to $t0, former $v0 [or to $a0 if you're adapting
44 # - on O32 populate $a4-$a7 with 'lw $aN,4*N($sp)' if necessary;
46 # For reference here is register layout for N32/64 MIPS ABIs:
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));
54 $flavour = shift || "o32"; # supported flavours are o32,n32,64,nubi32,nubi64
56 if ($flavour =~ /64|n32/i) {
57 $PTR_ADD="dadd"; # incidentally works even on n32
58 $PTR_SUB="dsub"; # incidentally works even on n32
62 $PTR_SLL="dsll"; # incidentally works even on n32
73 $pf = ($flavour =~ /nubi/i) ? $t0 : $t2;
77 ######################################################################
79 $big_endian=(`echo MIPSEL | $ENV{CC} -E -P -`=~/MIPSEL/)?1:0;
81 for (@ARGV) { $output=$_ if (/^\w[\w\-]*\.\w+$/); }
82 open STDOUT,">$output";
84 if (!defined($big_endian))
85 { $big_endian=(unpack('L',pack('N',1))==1); }
87 while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
88 open STDOUT,">$output";
90 my ($MSB,$LSB)=(0,3); # automatically converted to little-endian
94 #ifdef OPENSSL_FIPSCANISTER
95 # include <openssl/fipssyms.h>
98 #if !defined(__vxworks) || defined(__pic__)
105 my $FRAMESIZE=16*$SZREG;
106 my $SAVED_REGS_MASK = ($flavour =~ /nubi/i) ? 0xc0fff008 : 0xc0ff0000;
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);
113 # instuction ordering is "stolen" from output from MIPSpro assembler
114 # invoked with -mips3 -O3 arguments...
117 .ent _mips_AES_encrypt
126 $PTR_ADD $key0,$key,16
147 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
148 lw $t0,0($i0) # Te1[s1>>16]
150 lw $t1,0($i1) # Te1[s2>>16]
152 lw $t2,0($i2) # Te1[s3>>16]
154 lw $t3,0($i3) # Te1[s0>>16]
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]
163 lwr $t1,2($i1) # Te1[s2>>16]
165 lwr $t2,2($i2) # Te1[s3>>16]
167 lwr $t3,2($i3) # Te1[s0>>16]
178 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
183 # if defined(_MIPSEL)
184 lw $t4,0($i0) # Te1[s1>>16]
186 lw $t5,0($i1) # Te1[s2>>16]
188 lw $t6,0($i2) # Te1[s3>>16]
190 lw $t7,0($i3) # Te1[s0>>16]
201 lw $t8,0($i0) # Te1[s1>>16]
203 lw $t9,0($i1) # Te1[s2>>16]
205 lw $t10,0($i2) # Te1[s3>>16]
207 lw $t11,0($i3) # Te1[s0>>16]
210 lw $t4,0($i0) # Te1[s1>>16]
212 lw $t5,0($i1) # Te1[s2>>16]
214 lw $t6,0($i2) # Te1[s3>>16]
216 lw $t7,0($i3) # Te1[s0>>16]
219 lw $t8,0($i0) # Te1[s1>>16]
221 lw $t9,0($i1) # Te1[s2>>16]
223 lw $t10,0($i2) # Te1[s3>>16]
225 lw $t11,0($i3) # Te1[s0>>16]
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]
253 lwr $t5,1($i1) # Te2[s3>>8]
255 lwr $t6,1($i2) # Te2[s0>>8]
257 lwr $t7,1($i3) # Te2[s1>>8]
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]
274 lwr $t9,0($i1) # Te3[s0]
276 lwr $t10,0($i2) # Te3[s1]
278 lwr $t11,0($i3) # Te3[s2]
291 lw $t4,0($i0) # Te0[s0>>24]
293 lw $t5,0($i1) # Te0[s1>>24]
295 lw $t6,0($i2) # Te0[s2>>24]
297 lw $t7,0($i3) # Te0[s3>>24]
335 lbu $t0,2($i0) # Te4[s1>>16]
337 lbu $t1,2($i1) # Te4[s2>>16]
339 lbu $t2,2($i2) # Te4[s3>>16]
341 lbu $t3,2($i3) # Te4[s0>>16]
352 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
353 # if defined(_MIPSEL)
354 lbu $t4,2($i0) # Te4[s2>>8]
356 lbu $t5,2($i1) # Te4[s3>>8]
358 lbu $t6,2($i2) # Te4[s0>>8]
360 lbu $t7,2($i3) # Te4[s1>>8]
363 lbu $t8,2($i0) # Te4[s0>>24]
365 lbu $t9,2($i1) # Te4[s1>>24]
367 lbu $t10,2($i2) # Te4[s2>>24]
369 lbu $t11,2($i3) # Te4[s3>>24]
381 lbu $t4,2($i0) # Te4[s2>>8]
383 lbu $t5,2($i1) # Te4[s3>>8]
385 lbu $t6,2($i2) # Te4[s0>>8]
387 lbu $t7,2($i3) # Te4[s1>>8]
398 lbu $t8,2($i0) # Te4[s0>>24]
400 lbu $t9,2($i1) # Te4[s1>>24]
402 lbu $t10,2($i2) # Te4[s2>>24]
404 lbu $t11,2($i3) # Te4[s3>>24]
413 lbu $t4,2($i0) # Te4[s3]
415 lbu $t5,2($i1) # Te4[s0]
417 lbu $t6,2($i2) # Te4[s1]
419 lbu $t7,2($i3) # Te4[s2]
435 lbu $t4,2($i0) # Te4[s2>>8]
437 lbu $t5,2($i1) # Te4[s3>>8]
439 lbu $t6,2($i2) # Te4[s0>>8]
441 lbu $t7,2($i3) # Te4[s1>>8]
452 lbu $t8,2($i0) # Te4[s0>>24]
454 lbu $t9,2($i1) # Te4[s1>>24]
456 lbu $t10,2($i2) # Te4[s2>>24]
458 lbu $t11,2($i3) # Te4[s3>>24]
481 lbu $t4,2($i0) # Te4[s3]
483 lbu $t5,2($i1) # Te4[s0]
485 lbu $t6,2($i2) # Te4[s1]
487 lbu $t7,2($i3) # Te4[s2]
519 .end _mips_AES_encrypt
525 .frame $sp,$FRAMESIZE,$ra
526 .mask $SAVED_REGS_MASK,-$SZREG
529 $code.=<<___ if ($flavour =~ /o32/i); # o32 PIC-ification
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)
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)
552 $code.=<<___ if ($flavour !~ /o32/i); # non-o32 PIC-ification
554 .cpsetup $pf,$zero,AES_encrypt
558 la $Tbl,AES_Te # PIC-ified 'load address'
563 lwl $s3,12+$MSB($inp)
567 lwr $s3,12+$LSB($inp)
569 bal _mips_AES_encrypt
574 swr $s3,12+$LSB($out)
578 swl $s3,12+$MSB($out)
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)
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)
601 $PTR_ADD $sp,$FRAMESIZE
607 .ent _mips_AES_decrypt
616 $PTR_ADD $key0,$key,16
637 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
638 lw $t0,0($i0) # Td1[s3>>16]
640 lw $t1,0($i1) # Td1[s0>>16]
642 lw $t2,0($i2) # Td1[s1>>16]
644 lw $t3,0($i3) # Td1[s2>>16]
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]
653 lwr $t1,2($i1) # Td1[s0>>16]
655 lwr $t2,2($i2) # Td1[s1>>16]
657 lwr $t3,2($i3) # Td1[s2>>16]
669 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
674 # if defined(_MIPSEL)
675 lw $t4,0($i0) # Td2[s2>>8]
677 lw $t5,0($i1) # Td2[s3>>8]
679 lw $t6,0($i2) # Td2[s0>>8]
681 lw $t7,0($i3) # Td2[s1>>8]
692 lw $t8,0($i0) # Td3[s1]
694 lw $t9,0($i1) # Td3[s2]
696 lw $t10,0($i2) # Td3[s3]
698 lw $t11,0($i3) # Td3[s0]
701 lw $t4,0($i0) # Td2[s2>>8]
703 lw $t5,0($i1) # Td2[s3>>8]
705 lw $t6,0($i2) # Td2[s0>>8]
707 lw $t7,0($i3) # Td2[s1>>8]
710 lw $t8,0($i0) # Td3[s1]
712 lw $t9,0($i1) # Td3[s2]
714 lw $t10,0($i2) # Td3[s3]
716 lw $t11,0($i3) # Td3[s0]
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]
744 lwr $t5,1($i1) # Td2[s3>>8]
746 lwr $t6,1($i2) # Td2[s0>>8]
748 lwr $t7,1($i3) # Td2[s1>>8]
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]
765 lwr $t9,0($i1) # Td3[s2]
767 lwr $t10,0($i2) # Td3[s3]
769 lwr $t11,0($i3) # Td3[s0]
783 lw $t4,0($i0) # Td0[s0>>24]
785 lw $t5,0($i1) # Td0[s1>>24]
787 lw $t6,0($i2) # Td0[s2>>24]
789 lw $t7,0($i3) # Td0[s3>>24]
816 lw $t4,1024($Tbl) # prefetch Td4
824 lw $t8,1024+128($Tbl)
826 lw $t9,1024+160($Tbl)
828 lw $t10,1024+192($Tbl)
830 lw $t11,1024+224($Tbl)
837 lbu $t0,1024($i0) # Td4[s3>>16]
839 lbu $t1,1024($i1) # Td4[s0>>16]
841 lbu $t2,1024($i2) # Td4[s1>>16]
843 lbu $t3,1024($i3) # Td4[s2>>16]
854 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
855 # if defined(_MIPSEL)
856 lbu $t4,1024($i0) # Td4[s2>>8]
858 lbu $t5,1024($i1) # Td4[s3>>8]
860 lbu $t6,1024($i2) # Td4[s0>>8]
862 lbu $t7,1024($i3) # Td4[s1>>8]
865 lbu $t8,1024($i0) # Td4[s0>>24]
867 lbu $t9,1024($i1) # Td4[s1>>24]
869 lbu $t10,1024($i2) # Td4[s2>>24]
871 lbu $t11,1024($i3) # Td4[s3>>24]
879 lbu $t4,1024($i0) # Td4[s2>>8]
881 lbu $t5,1024($i1) # Td4[s3>>8]
883 lbu $t6,1024($i2) # Td4[s0>>8]
885 lbu $t7,1024($i3) # Td4[s1>>8]
892 lbu $t8,1024($i0) # Td4[s0>>24]
894 lbu $t9,1024($i1) # Td4[s1>>24]
896 lbu $t10,1024($i2) # Td4[s2>>24]
898 lbu $t11,1024($i3) # Td4[s3>>24]
907 lbu $t4,1024($i0) # Td4[s1]
909 lbu $t5,1024($i1) # Td4[s2]
911 lbu $t6,1024($i2) # Td4[s3]
913 lbu $t7,1024($i3) # Td4[s0]
929 lbu $t4,1024($i0) # Td4[s2>>8]
931 lbu $t5,1024($i1) # Td4[s3>>8]
933 lbu $t6,1024($i2) # Td4[s0>>8]
935 lbu $t7,1024($i3) # Td4[s1>>8]
942 lbu $t8,1024($i0) # Td4[s0>>24]
944 lbu $t9,1024($i1) # Td4[s1>>24]
946 lbu $t10,1024($i2) # Td4[s2>>24]
948 lbu $t11,1024($i3) # Td4[s3>>24]
967 lbu $t4,1024($i0) # Td4[s1]
969 lbu $t5,1024($i1) # Td4[s2]
971 lbu $t6,1024($i2) # Td4[s3]
973 lbu $t7,1024($i3) # Td4[s0]
1006 .end _mips_AES_decrypt
1012 .frame $sp,$FRAMESIZE,$ra
1013 .mask $SAVED_REGS_MASK,-$SZREG
1016 $code.=<<___ if ($flavour =~ /o32/i); # o32 PIC-ification
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)
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)
1039 $code.=<<___ if ($flavour !~ /o32/i); # non-o32 PIC-ification
1041 .cpsetup $pf,$zero,AES_decrypt
1045 la $Tbl,AES_Td # PIC-ified 'load address'
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)
1056 bal _mips_AES_decrypt
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)
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)
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)
1088 $PTR_ADD $sp,$FRAMESIZE
1094 my $FRAMESIZE=8*$SZREG;
1095 my $SAVED_REGS_MASK = ($flavour =~ /nubi/i) ? 0xc000f008 : 0xc0000000;
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);
1104 .ent _mips_AES_set_encrypt_key
1105 _mips_AES_set_encrypt_key:
1108 beqz $inp,.Lekey_done
1110 beqz $key,.Lekey_done
1111 $PTR_ADD $rcon,$Tbl,256
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)
1119 lwr $rk0,0+$LSB($inp)
1120 lwr $rk1,4+$LSB($inp)
1121 lwr $rk2,8+$LSB($inp)
1122 lwr $rk3,12+$LSB($inp)
1124 beq $bits,$at,.L128bits
1128 lwl $rk4,16+$MSB($inp) # load 192 bits
1129 lwl $rk5,20+$MSB($inp)
1131 lwr $rk4,16+$LSB($inp)
1132 lwr $rk5,20+$LSB($inp)
1134 beq $bits,$at,.L192bits
1138 lwl $rk6,24+$MSB($inp) # load 256 bits
1139 lwl $rk7,28+$MSB($inp)
1141 lwr $rk6,24+$LSB($inp)
1142 lwr $rk7,28+$LSB($inp)
1144 beq $bits,$at,.L256bits
1307 beqz $cnt,.L256bits_done
1354 .end _mips_AES_set_encrypt_key
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
1363 $code.=<<___ if ($flavour =~ /o32/i); # o32 PIC-ification
1367 $PTR_SUB $sp,$FRAMESIZE
1368 $REG_S $ra,$FRAMESIZE-1*$SZREG($sp)
1369 $REG_S $fp,$FRAMESIZE-2*$SZREG($sp)
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)
1378 $code.=<<___ if ($flavour !~ /o32/i); # non-o32 PIC-ification
1380 .cpsetup $pf,$zero,AES_set_encrypt_key
1384 la $Tbl,AES_Te4 # PIC-ified 'load address'
1386 bal _mips_AES_set_encrypt_key
1390 $REG_L $ra,$FRAMESIZE-1*$SZREG($sp)
1391 $REG_L $fp,$FRAMESIZE-2*$SZREG($sp)
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)
1402 $PTR_ADD $sp,$FRAMESIZE
1403 .end AES_set_encrypt_key
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);
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
1418 $code.=<<___ if ($flavour =~ /o32/i); # o32 PIC-ification
1422 $PTR_SUB $sp,$FRAMESIZE
1423 $REG_S $ra,$FRAMESIZE-1*$SZREG($sp)
1424 $REG_S $fp,$FRAMESIZE-2*$SZREG($sp)
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)
1433 $code.=<<___ if ($flavour !~ /o32/i); # non-o32 PIC-ification
1435 .cpsetup $pf,$zero,AES_set_decrypt_key
1439 la $Tbl,AES_Te4 # PIC-ified 'load address'
1441 bal _mips_AES_set_encrypt_key
1443 bltz $t0,.Ldkey_done
1446 $PTR_ADD $head,$key,0
1447 $PTR_ADD $tail,$key,$at
1468 bne $head,$tail,.Lswap
1470 lw $tp1,16($key) # modulo-scheduled
1471 lui $x80808080,0x8080
1473 or $x80808080,0x8080
1476 lui $x1b1b1b1b,0x1b1b
1477 nor $x7f7f7f7f,$zero,$x80808080
1478 or $x1b1b1b1b,0x1b1b
1481 and $m,$tp1,$x80808080
1482 and $tp2,$tp1,$x7f7f7f7f
1484 addu $tp2,$tp2 # tp2<<1
1489 and $m,$tp2,$x80808080
1490 and $tp4,$tp2,$x7f7f7f7f
1492 addu $tp4,$tp4 # tp4<<1
1497 and $m,$tp4,$x80808080
1498 and $tp8,$tp4,$x7f7f7f7f
1500 addu $tp8,$tp8 # tp8<<1
1510 #if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
1517 lw $tp1,4($key) # modulo-scheduled
1532 lw $tp1,4($key) # modulo-scheduled
1544 $REG_L $ra,$FRAMESIZE-1*$SZREG($sp)
1545 $REG_L $fp,$FRAMESIZE-2*$SZREG($sp)
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)
1556 $PTR_ADD $sp,$FRAMESIZE
1557 .end AES_set_decrypt_key
1561 ######################################################################
1562 # Tables are kept in endian-neutral manner
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
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
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
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
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
1900 foreach (split("\n",$code)) {
1901 s/\`([^\`]*)\`/eval $1/ge;
1903 # made-up _instructions, _xtr, _ins, _ror and _bias, cope
1904 # with byte order dependencies...
1906 s/(_[a-z]+\s+)(\$[0-9]+),([^,]+)(#.*)*$/$1$2,$2,$3/;
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;
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/;
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;
1939 s/(rotr\s+\$[0-9]+,\$[0-9]+),([0-9]+)/sprintf("$1,%d",32-$2)/e if(!$big_endian);