aes-x86_64.pl 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805
  1. #!/usr/bin/env perl
  2. #
  3. # ====================================================================
  4. # Written by Andy Polyakov <appro@fy.chalmers.se> 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. # Version 2.1.
  11. #
  12. # aes-*-cbc benchmarks are improved by >70% [compared to gcc 3.3.2 on
  13. # Opteron 240 CPU] plus all the bells-n-whistles from 32-bit version
  14. # [you'll notice a lot of resemblance], such as compressed S-boxes
  15. # in little-endian byte order, prefetch of these tables in CBC mode,
  16. # as well as avoiding L1 cache aliasing between stack frame and key
  17. # schedule and already mentioned tables, compressed Td4...
  18. #
  19. # Performance in number of cycles per processed byte for 128-bit key:
  20. #
  21. # ECB encrypt ECB decrypt CBC large chunk
  22. # AMD64 33 41 13.0
  23. # EM64T 38 59 18.6(*)
  24. # Core 2 30 43 14.5(*)
  25. #
  26. # (*) with hyper-threading off
  27. $flavour = shift;
  28. $output = shift;
  29. if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
  30. $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
  31. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  32. ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
  33. ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
  34. die "can't locate x86_64-xlate.pl";
  35. open STDOUT,"| $^X $xlate $flavour $output";
  36. $verticalspin=1; # unlike 32-bit version $verticalspin performs
  37. # ~15% better on both AMD and Intel cores
  38. $speed_limit=512; # see aes-586.pl for details
  39. $code=".text\n";
  40. $s0="%eax";
  41. $s1="%ebx";
  42. $s2="%ecx";
  43. $s3="%edx";
  44. $acc0="%esi"; $mask80="%rsi";
  45. $acc1="%edi"; $maskfe="%rdi";
  46. $acc2="%ebp"; $mask1b="%rbp";
  47. $inp="%r8";
  48. $out="%r9";
  49. $t0="%r10d";
  50. $t1="%r11d";
  51. $t2="%r12d";
  52. $rnds="%r13d";
  53. $sbox="%r14";
  54. $key="%r15";
  55. sub hi() { my $r=shift; $r =~ s/%[er]([a-d])x/%\1h/; $r; }
  56. sub lo() { my $r=shift; $r =~ s/%[er]([a-d])x/%\1l/;
  57. $r =~ s/%[er]([sd]i)/%\1l/;
  58. $r =~ s/%(r[0-9]+)[d]?/%\1b/; $r; }
  59. sub LO() { my $r=shift; $r =~ s/%r([a-z]+)/%e\1/;
  60. $r =~ s/%r([0-9]+)/%r\1d/; $r; }
  61. sub _data_word()
  62. { my $i;
  63. while(defined($i=shift)) { $code.=sprintf".long\t0x%08x,0x%08x\n",$i,$i; }
  64. }
  65. sub data_word()
  66. { my $i;
  67. my $last=pop(@_);
  68. $code.=".long\t";
  69. while(defined($i=shift)) { $code.=sprintf"0x%08x,",$i; }
  70. $code.=sprintf"0x%08x\n",$last;
  71. }
  72. sub data_byte()
  73. { my $i;
  74. my $last=pop(@_);
  75. $code.=".byte\t";
  76. while(defined($i=shift)) { $code.=sprintf"0x%02x,",$i&0xff; }
  77. $code.=sprintf"0x%02x\n",$last&0xff;
  78. }
  79. sub encvert()
  80. { my $t3="%r8d"; # zaps $inp!
  81. $code.=<<___;
  82. # favor 3-way issue Opteron pipeline...
  83. movzb `&lo("$s0")`,$acc0
  84. movzb `&lo("$s1")`,$acc1
  85. movzb `&lo("$s2")`,$acc2
  86. mov 0($sbox,$acc0,8),$t0
  87. mov 0($sbox,$acc1,8),$t1
  88. mov 0($sbox,$acc2,8),$t2
  89. movzb `&hi("$s1")`,$acc0
  90. movzb `&hi("$s2")`,$acc1
  91. movzb `&lo("$s3")`,$acc2
  92. xor 3($sbox,$acc0,8),$t0
  93. xor 3($sbox,$acc1,8),$t1
  94. mov 0($sbox,$acc2,8),$t3
  95. movzb `&hi("$s3")`,$acc0
  96. shr \$16,$s2
  97. movzb `&hi("$s0")`,$acc2
  98. xor 3($sbox,$acc0,8),$t2
  99. shr \$16,$s3
  100. xor 3($sbox,$acc2,8),$t3
  101. shr \$16,$s1
  102. lea 16($key),$key
  103. shr \$16,$s0
  104. movzb `&lo("$s2")`,$acc0
  105. movzb `&lo("$s3")`,$acc1
  106. movzb `&lo("$s0")`,$acc2
  107. xor 2($sbox,$acc0,8),$t0
  108. xor 2($sbox,$acc1,8),$t1
  109. xor 2($sbox,$acc2,8),$t2
  110. movzb `&hi("$s3")`,$acc0
  111. movzb `&hi("$s0")`,$acc1
  112. movzb `&lo("$s1")`,$acc2
  113. xor 1($sbox,$acc0,8),$t0
  114. xor 1($sbox,$acc1,8),$t1
  115. xor 2($sbox,$acc2,8),$t3
  116. mov 12($key),$s3
  117. movzb `&hi("$s1")`,$acc1
  118. movzb `&hi("$s2")`,$acc2
  119. mov 0($key),$s0
  120. xor 1($sbox,$acc1,8),$t2
  121. xor 1($sbox,$acc2,8),$t3
  122. mov 4($key),$s1
  123. mov 8($key),$s2
  124. xor $t0,$s0
  125. xor $t1,$s1
  126. xor $t2,$s2
  127. xor $t3,$s3
  128. ___
  129. }
  130. sub enclastvert()
  131. { my $t3="%r8d"; # zaps $inp!
  132. $code.=<<___;
  133. movzb `&lo("$s0")`,$acc0
  134. movzb `&lo("$s1")`,$acc1
  135. movzb `&lo("$s2")`,$acc2
  136. movzb 2($sbox,$acc0,8),$t0
  137. movzb 2($sbox,$acc1,8),$t1
  138. movzb 2($sbox,$acc2,8),$t2
  139. movzb `&lo("$s3")`,$acc0
  140. movzb `&hi("$s1")`,$acc1
  141. movzb `&hi("$s2")`,$acc2
  142. movzb 2($sbox,$acc0,8),$t3
  143. mov 0($sbox,$acc1,8),$acc1 #$t0
  144. mov 0($sbox,$acc2,8),$acc2 #$t1
  145. and \$0x0000ff00,$acc1
  146. and \$0x0000ff00,$acc2
  147. xor $acc1,$t0
  148. xor $acc2,$t1
  149. shr \$16,$s2
  150. movzb `&hi("$s3")`,$acc0
  151. movzb `&hi("$s0")`,$acc1
  152. shr \$16,$s3
  153. mov 0($sbox,$acc0,8),$acc0 #$t2
  154. mov 0($sbox,$acc1,8),$acc1 #$t3
  155. and \$0x0000ff00,$acc0
  156. and \$0x0000ff00,$acc1
  157. shr \$16,$s1
  158. xor $acc0,$t2
  159. xor $acc1,$t3
  160. shr \$16,$s0
  161. movzb `&lo("$s2")`,$acc0
  162. movzb `&lo("$s3")`,$acc1
  163. movzb `&lo("$s0")`,$acc2
  164. mov 0($sbox,$acc0,8),$acc0 #$t0
  165. mov 0($sbox,$acc1,8),$acc1 #$t1
  166. mov 0($sbox,$acc2,8),$acc2 #$t2
  167. and \$0x00ff0000,$acc0
  168. and \$0x00ff0000,$acc1
  169. and \$0x00ff0000,$acc2
  170. xor $acc0,$t0
  171. xor $acc1,$t1
  172. xor $acc2,$t2
  173. movzb `&lo("$s1")`,$acc0
  174. movzb `&hi("$s3")`,$acc1
  175. movzb `&hi("$s0")`,$acc2
  176. mov 0($sbox,$acc0,8),$acc0 #$t3
  177. mov 2($sbox,$acc1,8),$acc1 #$t0
  178. mov 2($sbox,$acc2,8),$acc2 #$t1
  179. and \$0x00ff0000,$acc0
  180. and \$0xff000000,$acc1
  181. and \$0xff000000,$acc2
  182. xor $acc0,$t3
  183. xor $acc1,$t0
  184. xor $acc2,$t1
  185. movzb `&hi("$s1")`,$acc0
  186. movzb `&hi("$s2")`,$acc1
  187. mov 16+12($key),$s3
  188. mov 2($sbox,$acc0,8),$acc0 #$t2
  189. mov 2($sbox,$acc1,8),$acc1 #$t3
  190. mov 16+0($key),$s0
  191. and \$0xff000000,$acc0
  192. and \$0xff000000,$acc1
  193. xor $acc0,$t2
  194. xor $acc1,$t3
  195. mov 16+4($key),$s1
  196. mov 16+8($key),$s2
  197. xor $t0,$s0
  198. xor $t1,$s1
  199. xor $t2,$s2
  200. xor $t3,$s3
  201. ___
  202. }
  203. sub encstep()
  204. { my ($i,@s) = @_;
  205. my $tmp0=$acc0;
  206. my $tmp1=$acc1;
  207. my $tmp2=$acc2;
  208. my $out=($t0,$t1,$t2,$s[0])[$i];
  209. if ($i==3) {
  210. $tmp0=$s[1];
  211. $tmp1=$s[2];
  212. $tmp2=$s[3];
  213. }
  214. $code.=" movzb ".&lo($s[0]).",$out\n";
  215. $code.=" mov $s[2],$tmp1\n" if ($i!=3);
  216. $code.=" lea 16($key),$key\n" if ($i==0);
  217. $code.=" movzb ".&hi($s[1]).",$tmp0\n";
  218. $code.=" mov 0($sbox,$out,8),$out\n";
  219. $code.=" shr \$16,$tmp1\n";
  220. $code.=" mov $s[3],$tmp2\n" if ($i!=3);
  221. $code.=" xor 3($sbox,$tmp0,8),$out\n";
  222. $code.=" movzb ".&lo($tmp1).",$tmp1\n";
  223. $code.=" shr \$24,$tmp2\n";
  224. $code.=" xor 4*$i($key),$out\n";
  225. $code.=" xor 2($sbox,$tmp1,8),$out\n";
  226. $code.=" xor 1($sbox,$tmp2,8),$out\n";
  227. $code.=" mov $t0,$s[1]\n" if ($i==3);
  228. $code.=" mov $t1,$s[2]\n" if ($i==3);
  229. $code.=" mov $t2,$s[3]\n" if ($i==3);
  230. $code.="\n";
  231. }
  232. sub enclast()
  233. { my ($i,@s)=@_;
  234. my $tmp0=$acc0;
  235. my $tmp1=$acc1;
  236. my $tmp2=$acc2;
  237. my $out=($t0,$t1,$t2,$s[0])[$i];
  238. if ($i==3) {
  239. $tmp0=$s[1];
  240. $tmp1=$s[2];
  241. $tmp2=$s[3];
  242. }
  243. $code.=" movzb ".&lo($s[0]).",$out\n";
  244. $code.=" mov $s[2],$tmp1\n" if ($i!=3);
  245. $code.=" mov 2($sbox,$out,8),$out\n";
  246. $code.=" shr \$16,$tmp1\n";
  247. $code.=" mov $s[3],$tmp2\n" if ($i!=3);
  248. $code.=" and \$0x000000ff,$out\n";
  249. $code.=" movzb ".&hi($s[1]).",$tmp0\n";
  250. $code.=" movzb ".&lo($tmp1).",$tmp1\n";
  251. $code.=" shr \$24,$tmp2\n";
  252. $code.=" mov 0($sbox,$tmp0,8),$tmp0\n";
  253. $code.=" mov 0($sbox,$tmp1,8),$tmp1\n";
  254. $code.=" mov 2($sbox,$tmp2,8),$tmp2\n";
  255. $code.=" and \$0x0000ff00,$tmp0\n";
  256. $code.=" and \$0x00ff0000,$tmp1\n";
  257. $code.=" and \$0xff000000,$tmp2\n";
  258. $code.=" xor $tmp0,$out\n";
  259. $code.=" mov $t0,$s[1]\n" if ($i==3);
  260. $code.=" xor $tmp1,$out\n";
  261. $code.=" mov $t1,$s[2]\n" if ($i==3);
  262. $code.=" xor $tmp2,$out\n";
  263. $code.=" mov $t2,$s[3]\n" if ($i==3);
  264. $code.="\n";
  265. }
  266. $code.=<<___;
  267. .type _x86_64_AES_encrypt,\@abi-omnipotent
  268. .align 16
  269. _x86_64_AES_encrypt:
  270. xor 0($key),$s0 # xor with key
  271. xor 4($key),$s1
  272. xor 8($key),$s2
  273. xor 12($key),$s3
  274. mov 240($key),$rnds # load key->rounds
  275. sub \$1,$rnds
  276. jmp .Lenc_loop
  277. .align 16
  278. .Lenc_loop:
  279. ___
  280. if ($verticalspin) { &encvert(); }
  281. else { &encstep(0,$s0,$s1,$s2,$s3);
  282. &encstep(1,$s1,$s2,$s3,$s0);
  283. &encstep(2,$s2,$s3,$s0,$s1);
  284. &encstep(3,$s3,$s0,$s1,$s2);
  285. }
  286. $code.=<<___;
  287. sub \$1,$rnds
  288. jnz .Lenc_loop
  289. ___
  290. if ($verticalspin) { &enclastvert(); }
  291. else { &enclast(0,$s0,$s1,$s2,$s3);
  292. &enclast(1,$s1,$s2,$s3,$s0);
  293. &enclast(2,$s2,$s3,$s0,$s1);
  294. &enclast(3,$s3,$s0,$s1,$s2);
  295. $code.=<<___;
  296. xor 16+0($key),$s0 # xor with key
  297. xor 16+4($key),$s1
  298. xor 16+8($key),$s2
  299. xor 16+12($key),$s3
  300. ___
  301. }
  302. $code.=<<___;
  303. .byte 0xf3,0xc3 # rep ret
  304. .size _x86_64_AES_encrypt,.-_x86_64_AES_encrypt
  305. ___
  306. # it's possible to implement this by shifting tN by 8, filling least
  307. # significant byte with byte load and finally bswap-ing at the end,
  308. # but such partial register load kills Core 2...
  309. sub enccompactvert()
  310. { my ($t3,$t4,$t5)=("%r8d","%r9d","%r13d");
  311. $code.=<<___;
  312. movzb `&lo("$s0")`,$t0
  313. movzb `&lo("$s1")`,$t1
  314. movzb `&lo("$s2")`,$t2
  315. movzb ($sbox,$t0,1),$t0
  316. movzb ($sbox,$t1,1),$t1
  317. movzb ($sbox,$t2,1),$t2
  318. movzb `&lo("$s3")`,$t3
  319. movzb `&hi("$s1")`,$acc0
  320. movzb `&hi("$s2")`,$acc1
  321. movzb ($sbox,$t3,1),$t3
  322. movzb ($sbox,$acc0,1),$t4 #$t0
  323. movzb ($sbox,$acc1,1),$t5 #$t1
  324. movzb `&hi("$s3")`,$acc2
  325. movzb `&hi("$s0")`,$acc0
  326. shr \$16,$s2
  327. movzb ($sbox,$acc2,1),$acc2 #$t2
  328. movzb ($sbox,$acc0,1),$acc0 #$t3
  329. shr \$16,$s3
  330. movzb `&lo("$s2")`,$acc1
  331. shl \$8,$t4
  332. shl \$8,$t5
  333. movzb ($sbox,$acc1,1),$acc1 #$t0
  334. xor $t4,$t0
  335. xor $t5,$t1
  336. movzb `&lo("$s3")`,$t4
  337. shr \$16,$s0
  338. shr \$16,$s1
  339. movzb `&lo("$s0")`,$t5
  340. shl \$8,$acc2
  341. shl \$8,$acc0
  342. movzb ($sbox,$t4,1),$t4 #$t1
  343. movzb ($sbox,$t5,1),$t5 #$t2
  344. xor $acc2,$t2
  345. xor $acc0,$t3
  346. movzb `&lo("$s1")`,$acc2
  347. movzb `&hi("$s3")`,$acc0
  348. shl \$16,$acc1
  349. movzb ($sbox,$acc2,1),$acc2 #$t3
  350. movzb ($sbox,$acc0,1),$acc0 #$t0
  351. xor $acc1,$t0
  352. movzb `&hi("$s0")`,$acc1
  353. shr \$8,$s2
  354. shr \$8,$s1
  355. movzb ($sbox,$acc1,1),$acc1 #$t1
  356. movzb ($sbox,$s2,1),$s3 #$t3
  357. movzb ($sbox,$s1,1),$s2 #$t2
  358. shl \$16,$t4
  359. shl \$16,$t5
  360. shl \$16,$acc2
  361. xor $t4,$t1
  362. xor $t5,$t2
  363. xor $acc2,$t3
  364. shl \$24,$acc0
  365. shl \$24,$acc1
  366. shl \$24,$s3
  367. xor $acc0,$t0
  368. shl \$24,$s2
  369. xor $acc1,$t1
  370. mov $t0,$s0
  371. mov $t1,$s1
  372. xor $t2,$s2
  373. xor $t3,$s3
  374. ___
  375. }
  376. sub enctransform_ref()
  377. { my $sn = shift;
  378. my ($acc,$r2,$tmp)=("%r8d","%r9d","%r13d");
  379. $code.=<<___;
  380. mov $sn,$acc
  381. and \$0x80808080,$acc
  382. mov $acc,$tmp
  383. shr \$7,$tmp
  384. lea ($sn,$sn),$r2
  385. sub $tmp,$acc
  386. and \$0xfefefefe,$r2
  387. and \$0x1b1b1b1b,$acc
  388. mov $sn,$tmp
  389. xor $acc,$r2
  390. xor $r2,$sn
  391. rol \$24,$sn
  392. xor $r2,$sn
  393. ror \$16,$tmp
  394. xor $tmp,$sn
  395. ror \$8,$tmp
  396. xor $tmp,$sn
  397. ___
  398. }
  399. # unlike decrypt case it does not pay off to parallelize enctransform
  400. sub enctransform()
  401. { my ($t3,$r20,$r21)=($acc2,"%r8d","%r9d");
  402. $code.=<<___;
  403. mov $s0,$acc0
  404. mov $s1,$acc1
  405. and \$0x80808080,$acc0
  406. and \$0x80808080,$acc1
  407. mov $acc0,$t0
  408. mov $acc1,$t1
  409. shr \$7,$t0
  410. lea ($s0,$s0),$r20
  411. shr \$7,$t1
  412. lea ($s1,$s1),$r21
  413. sub $t0,$acc0
  414. sub $t1,$acc1
  415. and \$0xfefefefe,$r20
  416. and \$0xfefefefe,$r21
  417. and \$0x1b1b1b1b,$acc0
  418. and \$0x1b1b1b1b,$acc1
  419. mov $s0,$t0
  420. mov $s1,$t1
  421. xor $acc0,$r20
  422. xor $acc1,$r21
  423. xor $r20,$s0
  424. xor $r21,$s1
  425. mov $s2,$acc0
  426. mov $s3,$acc1
  427. rol \$24,$s0
  428. rol \$24,$s1
  429. and \$0x80808080,$acc0
  430. and \$0x80808080,$acc1
  431. xor $r20,$s0
  432. xor $r21,$s1
  433. mov $acc0,$t2
  434. mov $acc1,$t3
  435. ror \$16,$t0
  436. ror \$16,$t1
  437. shr \$7,$t2
  438. lea ($s2,$s2),$r20
  439. xor $t0,$s0
  440. xor $t1,$s1
  441. shr \$7,$t3
  442. lea ($s3,$s3),$r21
  443. ror \$8,$t0
  444. ror \$8,$t1
  445. sub $t2,$acc0
  446. sub $t3,$acc1
  447. xor $t0,$s0
  448. xor $t1,$s1
  449. and \$0xfefefefe,$r20
  450. and \$0xfefefefe,$r21
  451. and \$0x1b1b1b1b,$acc0
  452. and \$0x1b1b1b1b,$acc1
  453. mov $s2,$t2
  454. mov $s3,$t3
  455. xor $acc0,$r20
  456. xor $acc1,$r21
  457. xor $r20,$s2
  458. xor $r21,$s3
  459. rol \$24,$s2
  460. rol \$24,$s3
  461. xor $r20,$s2
  462. xor $r21,$s3
  463. mov 0($sbox),$acc0 # prefetch Te4
  464. ror \$16,$t2
  465. ror \$16,$t3
  466. mov 64($sbox),$acc1
  467. xor $t2,$s2
  468. xor $t3,$s3
  469. mov 128($sbox),$r20
  470. ror \$8,$t2
  471. ror \$8,$t3
  472. mov 192($sbox),$r21
  473. xor $t2,$s2
  474. xor $t3,$s3
  475. ___
  476. }
  477. $code.=<<___;
  478. .type _x86_64_AES_encrypt_compact,\@abi-omnipotent
  479. .align 16
  480. _x86_64_AES_encrypt_compact:
  481. lea 128($sbox),$inp # size optimization
  482. mov 0-128($inp),$acc1 # prefetch Te4
  483. mov 32-128($inp),$acc2
  484. mov 64-128($inp),$t0
  485. mov 96-128($inp),$t1
  486. mov 128-128($inp),$acc1
  487. mov 160-128($inp),$acc2
  488. mov 192-128($inp),$t0
  489. mov 224-128($inp),$t1
  490. jmp .Lenc_loop_compact
  491. .align 16
  492. .Lenc_loop_compact:
  493. xor 0($key),$s0 # xor with key
  494. xor 4($key),$s1
  495. xor 8($key),$s2
  496. xor 12($key),$s3
  497. lea 16($key),$key
  498. ___
  499. &enccompactvert();
  500. $code.=<<___;
  501. cmp 16(%rsp),$key
  502. je .Lenc_compact_done
  503. ___
  504. &enctransform();
  505. $code.=<<___;
  506. jmp .Lenc_loop_compact
  507. .align 16
  508. .Lenc_compact_done:
  509. xor 0($key),$s0
  510. xor 4($key),$s1
  511. xor 8($key),$s2
  512. xor 12($key),$s3
  513. .byte 0xf3,0xc3 # rep ret
  514. .size _x86_64_AES_encrypt_compact,.-_x86_64_AES_encrypt_compact
  515. ___
  516. # void AES_encrypt (const void *inp,void *out,const AES_KEY *key);
  517. $code.=<<___;
  518. .globl AES_encrypt
  519. .type AES_encrypt,\@function,3
  520. .align 16
  521. AES_encrypt:
  522. push %rbx
  523. push %rbp
  524. push %r12
  525. push %r13
  526. push %r14
  527. push %r15
  528. # allocate frame "above" key schedule
  529. mov %rsp,%r10
  530. lea -63(%rdx),%rcx # %rdx is key argument
  531. and \$-64,%rsp
  532. sub %rsp,%rcx
  533. neg %rcx
  534. and \$0x3c0,%rcx
  535. sub %rcx,%rsp
  536. sub \$32,%rsp
  537. mov %rsi,16(%rsp) # save out
  538. mov %r10,24(%rsp) # save real stack pointer
  539. .Lenc_prologue:
  540. mov %rdx,$key
  541. mov 240($key),$rnds # load rounds
  542. mov 0(%rdi),$s0 # load input vector
  543. mov 4(%rdi),$s1
  544. mov 8(%rdi),$s2
  545. mov 12(%rdi),$s3
  546. shl \$4,$rnds
  547. lea ($key,$rnds),%rbp
  548. mov $key,(%rsp) # key schedule
  549. mov %rbp,8(%rsp) # end of key schedule
  550. # pick Te4 copy which can't "overlap" with stack frame or key schedule
  551. lea .LAES_Te+2048(%rip),$sbox
  552. lea 768(%rsp),%rbp
  553. sub $sbox,%rbp
  554. and \$0x300,%rbp
  555. lea ($sbox,%rbp),$sbox
  556. call _x86_64_AES_encrypt_compact
  557. mov 16(%rsp),$out # restore out
  558. mov 24(%rsp),%rsi # restore saved stack pointer
  559. mov $s0,0($out) # write output vector
  560. mov $s1,4($out)
  561. mov $s2,8($out)
  562. mov $s3,12($out)
  563. mov (%rsi),%r15
  564. mov 8(%rsi),%r14
  565. mov 16(%rsi),%r13
  566. mov 24(%rsi),%r12
  567. mov 32(%rsi),%rbp
  568. mov 40(%rsi),%rbx
  569. lea 48(%rsi),%rsp
  570. .Lenc_epilogue:
  571. ret
  572. .size AES_encrypt,.-AES_encrypt
  573. ___
  574. #------------------------------------------------------------------#
  575. sub decvert()
  576. { my $t3="%r8d"; # zaps $inp!
  577. $code.=<<___;
  578. # favor 3-way issue Opteron pipeline...
  579. movzb `&lo("$s0")`,$acc0
  580. movzb `&lo("$s1")`,$acc1
  581. movzb `&lo("$s2")`,$acc2
  582. mov 0($sbox,$acc0,8),$t0
  583. mov 0($sbox,$acc1,8),$t1
  584. mov 0($sbox,$acc2,8),$t2
  585. movzb `&hi("$s3")`,$acc0
  586. movzb `&hi("$s0")`,$acc1
  587. movzb `&lo("$s3")`,$acc2
  588. xor 3($sbox,$acc0,8),$t0
  589. xor 3($sbox,$acc1,8),$t1
  590. mov 0($sbox,$acc2,8),$t3
  591. movzb `&hi("$s1")`,$acc0
  592. shr \$16,$s0
  593. movzb `&hi("$s2")`,$acc2
  594. xor 3($sbox,$acc0,8),$t2
  595. shr \$16,$s3
  596. xor 3($sbox,$acc2,8),$t3
  597. shr \$16,$s1
  598. lea 16($key),$key
  599. shr \$16,$s2
  600. movzb `&lo("$s2")`,$acc0
  601. movzb `&lo("$s3")`,$acc1
  602. movzb `&lo("$s0")`,$acc2
  603. xor 2($sbox,$acc0,8),$t0
  604. xor 2($sbox,$acc1,8),$t1
  605. xor 2($sbox,$acc2,8),$t2
  606. movzb `&hi("$s1")`,$acc0
  607. movzb `&hi("$s2")`,$acc1
  608. movzb `&lo("$s1")`,$acc2
  609. xor 1($sbox,$acc0,8),$t0
  610. xor 1($sbox,$acc1,8),$t1
  611. xor 2($sbox,$acc2,8),$t3
  612. movzb `&hi("$s3")`,$acc0
  613. mov 12($key),$s3
  614. movzb `&hi("$s0")`,$acc2
  615. xor 1($sbox,$acc0,8),$t2
  616. mov 0($key),$s0
  617. xor 1($sbox,$acc2,8),$t3
  618. xor $t0,$s0
  619. mov 4($key),$s1
  620. mov 8($key),$s2
  621. xor $t2,$s2
  622. xor $t1,$s1
  623. xor $t3,$s3
  624. ___
  625. }
  626. sub declastvert()
  627. { my $t3="%r8d"; # zaps $inp!
  628. $code.=<<___;
  629. lea 2048($sbox),$sbox # size optimization
  630. movzb `&lo("$s0")`,$acc0
  631. movzb `&lo("$s1")`,$acc1
  632. movzb `&lo("$s2")`,$acc2
  633. movzb ($sbox,$acc0,1),$t0
  634. movzb ($sbox,$acc1,1),$t1
  635. movzb ($sbox,$acc2,1),$t2
  636. movzb `&lo("$s3")`,$acc0
  637. movzb `&hi("$s3")`,$acc1
  638. movzb `&hi("$s0")`,$acc2
  639. movzb ($sbox,$acc0,1),$t3
  640. movzb ($sbox,$acc1,1),$acc1 #$t0
  641. movzb ($sbox,$acc2,1),$acc2 #$t1
  642. shl \$8,$acc1
  643. shl \$8,$acc2
  644. xor $acc1,$t0
  645. xor $acc2,$t1
  646. shr \$16,$s3
  647. movzb `&hi("$s1")`,$acc0
  648. movzb `&hi("$s2")`,$acc1
  649. shr \$16,$s0
  650. movzb ($sbox,$acc0,1),$acc0 #$t2
  651. movzb ($sbox,$acc1,1),$acc1 #$t3
  652. shl \$8,$acc0
  653. shl \$8,$acc1
  654. shr \$16,$s1
  655. xor $acc0,$t2
  656. xor $acc1,$t3
  657. shr \$16,$s2
  658. movzb `&lo("$s2")`,$acc0
  659. movzb `&lo("$s3")`,$acc1
  660. movzb `&lo("$s0")`,$acc2
  661. movzb ($sbox,$acc0,1),$acc0 #$t0
  662. movzb ($sbox,$acc1,1),$acc1 #$t1
  663. movzb ($sbox,$acc2,1),$acc2 #$t2
  664. shl \$16,$acc0
  665. shl \$16,$acc1
  666. shl \$16,$acc2
  667. xor $acc0,$t0
  668. xor $acc1,$t1
  669. xor $acc2,$t2
  670. movzb `&lo("$s1")`,$acc0
  671. movzb `&hi("$s1")`,$acc1
  672. movzb `&hi("$s2")`,$acc2
  673. movzb ($sbox,$acc0,1),$acc0 #$t3
  674. movzb ($sbox,$acc1,1),$acc1 #$t0
  675. movzb ($sbox,$acc2,1),$acc2 #$t1
  676. shl \$16,$acc0
  677. shl \$24,$acc1
  678. shl \$24,$acc2
  679. xor $acc0,$t3
  680. xor $acc1,$t0
  681. xor $acc2,$t1
  682. movzb `&hi("$s3")`,$acc0
  683. movzb `&hi("$s0")`,$acc1
  684. mov 16+12($key),$s3
  685. movzb ($sbox,$acc0,1),$acc0 #$t2
  686. movzb ($sbox,$acc1,1),$acc1 #$t3
  687. mov 16+0($key),$s0
  688. shl \$24,$acc0
  689. shl \$24,$acc1
  690. xor $acc0,$t2
  691. xor $acc1,$t3
  692. mov 16+4($key),$s1
  693. mov 16+8($key),$s2
  694. lea -2048($sbox),$sbox
  695. xor $t0,$s0
  696. xor $t1,$s1
  697. xor $t2,$s2
  698. xor $t3,$s3
  699. ___
  700. }
  701. sub decstep()
  702. { my ($i,@s) = @_;
  703. my $tmp0=$acc0;
  704. my $tmp1=$acc1;
  705. my $tmp2=$acc2;
  706. my $out=($t0,$t1,$t2,$s[0])[$i];
  707. $code.=" mov $s[0],$out\n" if ($i!=3);
  708. $tmp1=$s[2] if ($i==3);
  709. $code.=" mov $s[2],$tmp1\n" if ($i!=3);
  710. $code.=" and \$0xFF,$out\n";
  711. $code.=" mov 0($sbox,$out,8),$out\n";
  712. $code.=" shr \$16,$tmp1\n";
  713. $tmp2=$s[3] if ($i==3);
  714. $code.=" mov $s[3],$tmp2\n" if ($i!=3);
  715. $tmp0=$s[1] if ($i==3);
  716. $code.=" movzb ".&hi($s[1]).",$tmp0\n";
  717. $code.=" and \$0xFF,$tmp1\n";
  718. $code.=" shr \$24,$tmp2\n";
  719. $code.=" xor 3($sbox,$tmp0,8),$out\n";
  720. $code.=" xor 2($sbox,$tmp1,8),$out\n";
  721. $code.=" xor 1($sbox,$tmp2,8),$out\n";
  722. $code.=" mov $t2,$s[1]\n" if ($i==3);
  723. $code.=" mov $t1,$s[2]\n" if ($i==3);
  724. $code.=" mov $t0,$s[3]\n" if ($i==3);
  725. $code.="\n";
  726. }
  727. sub declast()
  728. { my ($i,@s)=@_;
  729. my $tmp0=$acc0;
  730. my $tmp1=$acc1;
  731. my $tmp2=$acc2;
  732. my $out=($t0,$t1,$t2,$s[0])[$i];
  733. $code.=" mov $s[0],$out\n" if ($i!=3);
  734. $tmp1=$s[2] if ($i==3);
  735. $code.=" mov $s[2],$tmp1\n" if ($i!=3);
  736. $code.=" and \$0xFF,$out\n";
  737. $code.=" movzb 2048($sbox,$out,1),$out\n";
  738. $code.=" shr \$16,$tmp1\n";
  739. $tmp2=$s[3] if ($i==3);
  740. $code.=" mov $s[3],$tmp2\n" if ($i!=3);
  741. $tmp0=$s[1] if ($i==3);
  742. $code.=" movzb ".&hi($s[1]).",$tmp0\n";
  743. $code.=" and \$0xFF,$tmp1\n";
  744. $code.=" shr \$24,$tmp2\n";
  745. $code.=" movzb 2048($sbox,$tmp0,1),$tmp0\n";
  746. $code.=" movzb 2048($sbox,$tmp1,1),$tmp1\n";
  747. $code.=" movzb 2048($sbox,$tmp2,1),$tmp2\n";
  748. $code.=" shl \$8,$tmp0\n";
  749. $code.=" shl \$16,$tmp1\n";
  750. $code.=" shl \$24,$tmp2\n";
  751. $code.=" xor $tmp0,$out\n";
  752. $code.=" mov $t2,$s[1]\n" if ($i==3);
  753. $code.=" xor $tmp1,$out\n";
  754. $code.=" mov $t1,$s[2]\n" if ($i==3);
  755. $code.=" xor $tmp2,$out\n";
  756. $code.=" mov $t0,$s[3]\n" if ($i==3);
  757. $code.="\n";
  758. }
  759. $code.=<<___;
  760. .type _x86_64_AES_decrypt,\@abi-omnipotent
  761. .align 16
  762. _x86_64_AES_decrypt:
  763. xor 0($key),$s0 # xor with key
  764. xor 4($key),$s1
  765. xor 8($key),$s2
  766. xor 12($key),$s3
  767. mov 240($key),$rnds # load key->rounds
  768. sub \$1,$rnds
  769. jmp .Ldec_loop
  770. .align 16
  771. .Ldec_loop:
  772. ___
  773. if ($verticalspin) { &decvert(); }
  774. else { &decstep(0,$s0,$s3,$s2,$s1);
  775. &decstep(1,$s1,$s0,$s3,$s2);
  776. &decstep(2,$s2,$s1,$s0,$s3);
  777. &decstep(3,$s3,$s2,$s1,$s0);
  778. $code.=<<___;
  779. lea 16($key),$key
  780. xor 0($key),$s0 # xor with key
  781. xor 4($key),$s1
  782. xor 8($key),$s2
  783. xor 12($key),$s3
  784. ___
  785. }
  786. $code.=<<___;
  787. sub \$1,$rnds
  788. jnz .Ldec_loop
  789. ___
  790. if ($verticalspin) { &declastvert(); }
  791. else { &declast(0,$s0,$s3,$s2,$s1);
  792. &declast(1,$s1,$s0,$s3,$s2);
  793. &declast(2,$s2,$s1,$s0,$s3);
  794. &declast(3,$s3,$s2,$s1,$s0);
  795. $code.=<<___;
  796. xor 16+0($key),$s0 # xor with key
  797. xor 16+4($key),$s1
  798. xor 16+8($key),$s2
  799. xor 16+12($key),$s3
  800. ___
  801. }
  802. $code.=<<___;
  803. .byte 0xf3,0xc3 # rep ret
  804. .size _x86_64_AES_decrypt,.-_x86_64_AES_decrypt
  805. ___
  806. sub deccompactvert()
  807. { my ($t3,$t4,$t5)=("%r8d","%r9d","%r13d");
  808. $code.=<<___;
  809. movzb `&lo("$s0")`,$t0
  810. movzb `&lo("$s1")`,$t1
  811. movzb `&lo("$s2")`,$t2
  812. movzb ($sbox,$t0,1),$t0
  813. movzb ($sbox,$t1,1),$t1
  814. movzb ($sbox,$t2,1),$t2
  815. movzb `&lo("$s3")`,$t3
  816. movzb `&hi("$s3")`,$acc0
  817. movzb `&hi("$s0")`,$acc1
  818. movzb ($sbox,$t3,1),$t3
  819. movzb ($sbox,$acc0,1),$t4 #$t0
  820. movzb ($sbox,$acc1,1),$t5 #$t1
  821. movzb `&hi("$s1")`,$acc2
  822. movzb `&hi("$s2")`,$acc0
  823. shr \$16,$s2
  824. movzb ($sbox,$acc2,1),$acc2 #$t2
  825. movzb ($sbox,$acc0,1),$acc0 #$t3
  826. shr \$16,$s3
  827. movzb `&lo("$s2")`,$acc1
  828. shl \$8,$t4
  829. shl \$8,$t5
  830. movzb ($sbox,$acc1,1),$acc1 #$t0
  831. xor $t4,$t0
  832. xor $t5,$t1
  833. movzb `&lo("$s3")`,$t4
  834. shr \$16,$s0
  835. shr \$16,$s1
  836. movzb `&lo("$s0")`,$t5
  837. shl \$8,$acc2
  838. shl \$8,$acc0
  839. movzb ($sbox,$t4,1),$t4 #$t1
  840. movzb ($sbox,$t5,1),$t5 #$t2
  841. xor $acc2,$t2
  842. xor $acc0,$t3
  843. movzb `&lo("$s1")`,$acc2
  844. movzb `&hi("$s1")`,$acc0
  845. shl \$16,$acc1
  846. movzb ($sbox,$acc2,1),$acc2 #$t3
  847. movzb ($sbox,$acc0,1),$acc0 #$t0
  848. xor $acc1,$t0
  849. movzb `&hi("$s2")`,$acc1
  850. shl \$16,$t4
  851. shl \$16,$t5
  852. movzb ($sbox,$acc1,1),$s1 #$t1
  853. xor $t4,$t1
  854. xor $t5,$t2
  855. movzb `&hi("$s3")`,$acc1
  856. shr \$8,$s0
  857. shl \$16,$acc2
  858. movzb ($sbox,$acc1,1),$s2 #$t2
  859. movzb ($sbox,$s0,1),$s3 #$t3
  860. xor $acc2,$t3
  861. shl \$24,$acc0
  862. shl \$24,$s1
  863. shl \$24,$s2
  864. xor $acc0,$t0
  865. shl \$24,$s3
  866. xor $t1,$s1
  867. mov $t0,$s0
  868. xor $t2,$s2
  869. xor $t3,$s3
  870. ___
  871. }
  872. # parallelized version! input is pair of 64-bit values: %rax=s1.s0
  873. # and %rcx=s3.s2, output is four 32-bit values in %eax=s0, %ebx=s1,
  874. # %ecx=s2 and %edx=s3.
  875. sub dectransform()
  876. { my ($tp10,$tp20,$tp40,$tp80,$acc0)=("%rax","%r8", "%r9", "%r10","%rbx");
  877. my ($tp18,$tp28,$tp48,$tp88,$acc8)=("%rcx","%r11","%r12","%r13","%rdx");
  878. my $prefetch = shift;
  879. $code.=<<___;
  880. mov $tp10,$acc0
  881. mov $tp18,$acc8
  882. and $mask80,$acc0
  883. and $mask80,$acc8
  884. mov $acc0,$tp40
  885. mov $acc8,$tp48
  886. shr \$7,$tp40
  887. lea ($tp10,$tp10),$tp20
  888. shr \$7,$tp48
  889. lea ($tp18,$tp18),$tp28
  890. sub $tp40,$acc0
  891. sub $tp48,$acc8
  892. and $maskfe,$tp20
  893. and $maskfe,$tp28
  894. and $mask1b,$acc0
  895. and $mask1b,$acc8
  896. xor $tp20,$acc0
  897. xor $tp28,$acc8
  898. mov $acc0,$tp20
  899. mov $acc8,$tp28
  900. and $mask80,$acc0
  901. and $mask80,$acc8
  902. mov $acc0,$tp80
  903. mov $acc8,$tp88
  904. shr \$7,$tp80
  905. lea ($tp20,$tp20),$tp40
  906. shr \$7,$tp88
  907. lea ($tp28,$tp28),$tp48
  908. sub $tp80,$acc0
  909. sub $tp88,$acc8
  910. and $maskfe,$tp40
  911. and $maskfe,$tp48
  912. and $mask1b,$acc0
  913. and $mask1b,$acc8
  914. xor $tp40,$acc0
  915. xor $tp48,$acc8
  916. mov $acc0,$tp40
  917. mov $acc8,$tp48
  918. and $mask80,$acc0
  919. and $mask80,$acc8
  920. mov $acc0,$tp80
  921. mov $acc8,$tp88
  922. shr \$7,$tp80
  923. xor $tp10,$tp20 # tp2^=tp1
  924. shr \$7,$tp88
  925. xor $tp18,$tp28 # tp2^=tp1
  926. sub $tp80,$acc0
  927. sub $tp88,$acc8
  928. lea ($tp40,$tp40),$tp80
  929. lea ($tp48,$tp48),$tp88
  930. xor $tp10,$tp40 # tp4^=tp1
  931. xor $tp18,$tp48 # tp4^=tp1
  932. and $maskfe,$tp80
  933. and $maskfe,$tp88
  934. and $mask1b,$acc0
  935. and $mask1b,$acc8
  936. xor $acc0,$tp80
  937. xor $acc8,$tp88
  938. xor $tp80,$tp10 # tp1^=tp8
  939. xor $tp88,$tp18 # tp1^=tp8
  940. xor $tp80,$tp20 # tp2^tp1^=tp8
  941. xor $tp88,$tp28 # tp2^tp1^=tp8
  942. mov $tp10,$acc0
  943. mov $tp18,$acc8
  944. xor $tp80,$tp40 # tp4^tp1^=tp8
  945. xor $tp88,$tp48 # tp4^tp1^=tp8
  946. shr \$32,$acc0
  947. shr \$32,$acc8
  948. xor $tp20,$tp80 # tp8^=tp8^tp2^tp1=tp2^tp1
  949. xor $tp28,$tp88 # tp8^=tp8^tp2^tp1=tp2^tp1
  950. rol \$8,`&LO("$tp10")` # ROTATE(tp1^tp8,8)
  951. rol \$8,`&LO("$tp18")` # ROTATE(tp1^tp8,8)
  952. xor $tp40,$tp80 # tp2^tp1^=tp8^tp4^tp1=tp8^tp4^tp2
  953. xor $tp48,$tp88 # tp2^tp1^=tp8^tp4^tp1=tp8^tp4^tp2
  954. rol \$8,`&LO("$acc0")` # ROTATE(tp1^tp8,8)
  955. rol \$8,`&LO("$acc8")` # ROTATE(tp1^tp8,8)
  956. xor `&LO("$tp80")`,`&LO("$tp10")`
  957. xor `&LO("$tp88")`,`&LO("$tp18")`
  958. shr \$32,$tp80
  959. shr \$32,$tp88
  960. xor `&LO("$tp80")`,`&LO("$acc0")`
  961. xor `&LO("$tp88")`,`&LO("$acc8")`
  962. mov $tp20,$tp80
  963. mov $tp28,$tp88
  964. shr \$32,$tp80
  965. shr \$32,$tp88
  966. rol \$24,`&LO("$tp20")` # ROTATE(tp2^tp1^tp8,24)
  967. rol \$24,`&LO("$tp28")` # ROTATE(tp2^tp1^tp8,24)
  968. rol \$24,`&LO("$tp80")` # ROTATE(tp2^tp1^tp8,24)
  969. rol \$24,`&LO("$tp88")` # ROTATE(tp2^tp1^tp8,24)
  970. xor `&LO("$tp20")`,`&LO("$tp10")`
  971. xor `&LO("$tp28")`,`&LO("$tp18")`
  972. mov $tp40,$tp20
  973. mov $tp48,$tp28
  974. xor `&LO("$tp80")`,`&LO("$acc0")`
  975. xor `&LO("$tp88")`,`&LO("$acc8")`
  976. `"mov 0($sbox),$mask80" if ($prefetch)`
  977. shr \$32,$tp20
  978. shr \$32,$tp28
  979. `"mov 64($sbox),$maskfe" if ($prefetch)`
  980. rol \$16,`&LO("$tp40")` # ROTATE(tp4^tp1^tp8,16)
  981. rol \$16,`&LO("$tp48")` # ROTATE(tp4^tp1^tp8,16)
  982. `"mov 128($sbox),$mask1b" if ($prefetch)`
  983. rol \$16,`&LO("$tp20")` # ROTATE(tp4^tp1^tp8,16)
  984. rol \$16,`&LO("$tp28")` # ROTATE(tp4^tp1^tp8,16)
  985. `"mov 192($sbox),$tp80" if ($prefetch)`
  986. xor `&LO("$tp40")`,`&LO("$tp10")`
  987. xor `&LO("$tp48")`,`&LO("$tp18")`
  988. `"mov 256($sbox),$tp88" if ($prefetch)`
  989. xor `&LO("$tp20")`,`&LO("$acc0")`
  990. xor `&LO("$tp28")`,`&LO("$acc8")`
  991. ___
  992. }
  993. $code.=<<___;
  994. .type _x86_64_AES_decrypt_compact,\@abi-omnipotent
  995. .align 16
  996. _x86_64_AES_decrypt_compact:
  997. lea 128($sbox),$inp # size optimization
  998. mov 0-128($inp),$acc1 # prefetch Td4
  999. mov 32-128($inp),$acc2
  1000. mov 64-128($inp),$t0
  1001. mov 96-128($inp),$t1
  1002. mov 128-128($inp),$acc1
  1003. mov 160-128($inp),$acc2
  1004. mov 192-128($inp),$t0
  1005. mov 224-128($inp),$t1
  1006. jmp .Ldec_loop_compact
  1007. .align 16
  1008. .Ldec_loop_compact:
  1009. xor 0($key),$s0 # xor with key
  1010. xor 4($key),$s1
  1011. xor 8($key),$s2
  1012. xor 12($key),$s3
  1013. lea 16($key),$key
  1014. ___
  1015. &deccompactvert();
  1016. $code.=<<___;
  1017. cmp 16(%rsp),$key
  1018. je .Ldec_compact_done
  1019. mov 256+0($sbox),$mask80
  1020. shl \$32,%rbx
  1021. shl \$32,%rdx
  1022. mov 256+8($sbox),$maskfe
  1023. or %rbx,%rax
  1024. or %rdx,%rcx
  1025. mov 256+16($sbox),$mask1b
  1026. ___
  1027. &dectransform(1);
  1028. $code.=<<___;
  1029. jmp .Ldec_loop_compact
  1030. .align 16
  1031. .Ldec_compact_done:
  1032. xor 0($key),$s0
  1033. xor 4($key),$s1
  1034. xor 8($key),$s2
  1035. xor 12($key),$s3
  1036. .byte 0xf3,0xc3 # rep ret
  1037. .size _x86_64_AES_decrypt_compact,.-_x86_64_AES_decrypt_compact
  1038. ___
  1039. # void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
  1040. $code.=<<___;
  1041. .globl AES_decrypt
  1042. .type AES_decrypt,\@function,3
  1043. .align 16
  1044. AES_decrypt:
  1045. push %rbx
  1046. push %rbp
  1047. push %r12
  1048. push %r13
  1049. push %r14
  1050. push %r15
  1051. # allocate frame "above" key schedule
  1052. mov %rsp,%r10
  1053. lea -63(%rdx),%rcx # %rdx is key argument
  1054. and \$-64,%rsp
  1055. sub %rsp,%rcx
  1056. neg %rcx
  1057. and \$0x3c0,%rcx
  1058. sub %rcx,%rsp
  1059. sub \$32,%rsp
  1060. mov %rsi,16(%rsp) # save out
  1061. mov %r10,24(%rsp) # save real stack pointer
  1062. .Ldec_prologue:
  1063. mov %rdx,$key
  1064. mov 240($key),$rnds # load rounds
  1065. mov 0(%rdi),$s0 # load input vector
  1066. mov 4(%rdi),$s1
  1067. mov 8(%rdi),$s2
  1068. mov 12(%rdi),$s3
  1069. shl \$4,$rnds
  1070. lea ($key,$rnds),%rbp
  1071. mov $key,(%rsp) # key schedule
  1072. mov %rbp,8(%rsp) # end of key schedule
  1073. # pick Td4 copy which can't "overlap" with stack frame or key schedule
  1074. lea .LAES_Td+2048(%rip),$sbox
  1075. lea 768(%rsp),%rbp
  1076. sub $sbox,%rbp
  1077. and \$0x300,%rbp
  1078. lea ($sbox,%rbp),$sbox
  1079. shr \$3,%rbp # recall "magic" constants!
  1080. add %rbp,$sbox
  1081. call _x86_64_AES_decrypt_compact
  1082. mov 16(%rsp),$out # restore out
  1083. mov 24(%rsp),%rsi # restore saved stack pointer
  1084. mov $s0,0($out) # write output vector
  1085. mov $s1,4($out)
  1086. mov $s2,8($out)
  1087. mov $s3,12($out)
  1088. mov (%rsi),%r15
  1089. mov 8(%rsi),%r14
  1090. mov 16(%rsi),%r13
  1091. mov 24(%rsi),%r12
  1092. mov 32(%rsi),%rbp
  1093. mov 40(%rsi),%rbx
  1094. lea 48(%rsi),%rsp
  1095. .Ldec_epilogue:
  1096. ret
  1097. .size AES_decrypt,.-AES_decrypt
  1098. ___
  1099. #------------------------------------------------------------------#
  1100. sub enckey()
  1101. {
  1102. $code.=<<___;
  1103. movz %dl,%esi # rk[i]>>0
  1104. movzb -128(%rbp,%rsi),%ebx
  1105. movz %dh,%esi # rk[i]>>8
  1106. shl \$24,%ebx
  1107. xor %ebx,%eax
  1108. movzb -128(%rbp,%rsi),%ebx
  1109. shr \$16,%edx
  1110. movz %dl,%esi # rk[i]>>16
  1111. xor %ebx,%eax
  1112. movzb -128(%rbp,%rsi),%ebx
  1113. movz %dh,%esi # rk[i]>>24
  1114. shl \$8,%ebx
  1115. xor %ebx,%eax
  1116. movzb -128(%rbp,%rsi),%ebx
  1117. shl \$16,%ebx
  1118. xor %ebx,%eax
  1119. xor 1024-128(%rbp,%rcx,4),%eax # rcon
  1120. ___
  1121. }
  1122. # int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
  1123. # AES_KEY *key)
  1124. $code.=<<___;
  1125. .globl AES_set_encrypt_key
  1126. .type AES_set_encrypt_key,\@function,3
  1127. .align 16
  1128. AES_set_encrypt_key:
  1129. push %rbx
  1130. push %rbp
  1131. push %r12 # redundant, but allows to share
  1132. push %r13 # exception handler...
  1133. push %r14
  1134. push %r15
  1135. sub \$8,%rsp
  1136. .Lenc_key_prologue:
  1137. call _x86_64_AES_set_encrypt_key
  1138. mov 40(%rsp),%rbp
  1139. mov 48(%rsp),%rbx
  1140. add \$56,%rsp
  1141. .Lenc_key_epilogue:
  1142. ret
  1143. .size AES_set_encrypt_key,.-AES_set_encrypt_key
  1144. .type _x86_64_AES_set_encrypt_key,\@abi-omnipotent
  1145. .align 16
  1146. _x86_64_AES_set_encrypt_key:
  1147. mov %esi,%ecx # %ecx=bits
  1148. mov %rdi,%rsi # %rsi=userKey
  1149. mov %rdx,%rdi # %rdi=key
  1150. test \$-1,%rsi
  1151. jz .Lbadpointer
  1152. test \$-1,%rdi
  1153. jz .Lbadpointer
  1154. lea .LAES_Te(%rip),%rbp
  1155. lea 2048+128(%rbp),%rbp
  1156. # prefetch Te4
  1157. mov 0-128(%rbp),%eax
  1158. mov 32-128(%rbp),%ebx
  1159. mov 64-128(%rbp),%r8d
  1160. mov 96-128(%rbp),%edx
  1161. mov 128-128(%rbp),%eax
  1162. mov 160-128(%rbp),%ebx
  1163. mov 192-128(%rbp),%r8d
  1164. mov 224-128(%rbp),%edx
  1165. cmp \$128,%ecx
  1166. je .L10rounds
  1167. cmp \$192,%ecx
  1168. je .L12rounds
  1169. cmp \$256,%ecx
  1170. je .L14rounds
  1171. mov \$-2,%rax # invalid number of bits
  1172. jmp .Lexit
  1173. .L10rounds:
  1174. mov 0(%rsi),%rax # copy first 4 dwords
  1175. mov 8(%rsi),%rdx
  1176. mov %rax,0(%rdi)
  1177. mov %rdx,8(%rdi)
  1178. shr \$32,%rdx
  1179. xor %ecx,%ecx
  1180. jmp .L10shortcut
  1181. .align 4
  1182. .L10loop:
  1183. mov 0(%rdi),%eax # rk[0]
  1184. mov 12(%rdi),%edx # rk[3]
  1185. .L10shortcut:
  1186. ___
  1187. &enckey ();
  1188. $code.=<<___;
  1189. mov %eax,16(%rdi) # rk[4]
  1190. xor 4(%rdi),%eax
  1191. mov %eax,20(%rdi) # rk[5]
  1192. xor 8(%rdi),%eax
  1193. mov %eax,24(%rdi) # rk[6]
  1194. xor 12(%rdi),%eax
  1195. mov %eax,28(%rdi) # rk[7]
  1196. add \$1,%ecx
  1197. lea 16(%rdi),%rdi
  1198. cmp \$10,%ecx
  1199. jl .L10loop
  1200. movl \$10,80(%rdi) # setup number of rounds
  1201. xor %rax,%rax
  1202. jmp .Lexit
  1203. .L12rounds:
  1204. mov 0(%rsi),%rax # copy first 6 dwords
  1205. mov 8(%rsi),%rbx
  1206. mov 16(%rsi),%rdx
  1207. mov %rax,0(%rdi)
  1208. mov %rbx,8(%rdi)
  1209. mov %rdx,16(%rdi)
  1210. shr \$32,%rdx
  1211. xor %ecx,%ecx
  1212. jmp .L12shortcut
  1213. .align 4
  1214. .L12loop:
  1215. mov 0(%rdi),%eax # rk[0]
  1216. mov 20(%rdi),%edx # rk[5]
  1217. .L12shortcut:
  1218. ___
  1219. &enckey ();
  1220. $code.=<<___;
  1221. mov %eax,24(%rdi) # rk[6]
  1222. xor 4(%rdi),%eax
  1223. mov %eax,28(%rdi) # rk[7]
  1224. xor 8(%rdi),%eax
  1225. mov %eax,32(%rdi) # rk[8]
  1226. xor 12(%rdi),%eax
  1227. mov %eax,36(%rdi) # rk[9]
  1228. cmp \$7,%ecx
  1229. je .L12break
  1230. add \$1,%ecx
  1231. xor 16(%rdi),%eax
  1232. mov %eax,40(%rdi) # rk[10]
  1233. xor 20(%rdi),%eax
  1234. mov %eax,44(%rdi) # rk[11]
  1235. lea 24(%rdi),%rdi
  1236. jmp .L12loop
  1237. .L12break:
  1238. movl \$12,72(%rdi) # setup number of rounds
  1239. xor %rax,%rax
  1240. jmp .Lexit
  1241. .L14rounds:
  1242. mov 0(%rsi),%rax # copy first 8 dwords
  1243. mov 8(%rsi),%rbx
  1244. mov 16(%rsi),%rcx
  1245. mov 24(%rsi),%rdx
  1246. mov %rax,0(%rdi)
  1247. mov %rbx,8(%rdi)
  1248. mov %rcx,16(%rdi)
  1249. mov %rdx,24(%rdi)
  1250. shr \$32,%rdx
  1251. xor %ecx,%ecx
  1252. jmp .L14shortcut
  1253. .align 4
  1254. .L14loop:
  1255. mov 0(%rdi),%eax # rk[0]
  1256. mov 28(%rdi),%edx # rk[4]
  1257. .L14shortcut:
  1258. ___
  1259. &enckey ();
  1260. $code.=<<___;
  1261. mov %eax,32(%rdi) # rk[8]
  1262. xor 4(%rdi),%eax
  1263. mov %eax,36(%rdi) # rk[9]
  1264. xor 8(%rdi),%eax
  1265. mov %eax,40(%rdi) # rk[10]
  1266. xor 12(%rdi),%eax
  1267. mov %eax,44(%rdi) # rk[11]
  1268. cmp \$6,%ecx
  1269. je .L14break
  1270. add \$1,%ecx
  1271. mov %eax,%edx
  1272. mov 16(%rdi),%eax # rk[4]
  1273. movz %dl,%esi # rk[11]>>0
  1274. movzb -128(%rbp,%rsi),%ebx
  1275. movz %dh,%esi # rk[11]>>8
  1276. xor %ebx,%eax
  1277. movzb -128(%rbp,%rsi),%ebx
  1278. shr \$16,%edx
  1279. shl \$8,%ebx
  1280. movz %dl,%esi # rk[11]>>16
  1281. xor %ebx,%eax
  1282. movzb -128(%rbp,%rsi),%ebx
  1283. movz %dh,%esi # rk[11]>>24
  1284. shl \$16,%ebx
  1285. xor %ebx,%eax
  1286. movzb -128(%rbp,%rsi),%ebx
  1287. shl \$24,%ebx
  1288. xor %ebx,%eax
  1289. mov %eax,48(%rdi) # rk[12]
  1290. xor 20(%rdi),%eax
  1291. mov %eax,52(%rdi) # rk[13]
  1292. xor 24(%rdi),%eax
  1293. mov %eax,56(%rdi) # rk[14]
  1294. xor 28(%rdi),%eax
  1295. mov %eax,60(%rdi) # rk[15]
  1296. lea 32(%rdi),%rdi
  1297. jmp .L14loop
  1298. .L14break:
  1299. movl \$14,48(%rdi) # setup number of rounds
  1300. xor %rax,%rax
  1301. jmp .Lexit
  1302. .Lbadpointer:
  1303. mov \$-1,%rax
  1304. .Lexit:
  1305. .byte 0xf3,0xc3 # rep ret
  1306. .size _x86_64_AES_set_encrypt_key,.-_x86_64_AES_set_encrypt_key
  1307. ___
  1308. sub deckey_ref()
  1309. { my ($i,$ptr,$te,$td) = @_;
  1310. my ($tp1,$tp2,$tp4,$tp8,$acc)=("%eax","%ebx","%edi","%edx","%r8d");
  1311. $code.=<<___;
  1312. mov $i($ptr),$tp1
  1313. mov $tp1,$acc
  1314. and \$0x80808080,$acc
  1315. mov $acc,$tp4
  1316. shr \$7,$tp4
  1317. lea 0($tp1,$tp1),$tp2
  1318. sub $tp4,$acc
  1319. and \$0xfefefefe,$tp2
  1320. and \$0x1b1b1b1b,$acc
  1321. xor $tp2,$acc
  1322. mov $acc,$tp2
  1323. and \$0x80808080,$acc
  1324. mov $acc,$tp8
  1325. shr \$7,$tp8
  1326. lea 0($tp2,$tp2),$tp4
  1327. sub $tp8,$acc
  1328. and \$0xfefefefe,$tp4
  1329. and \$0x1b1b1b1b,$acc
  1330. xor $tp1,$tp2 # tp2^tp1
  1331. xor $tp4,$acc
  1332. mov $acc,$tp4
  1333. and \$0x80808080,$acc
  1334. mov $acc,$tp8
  1335. shr \$7,$tp8
  1336. sub $tp8,$acc
  1337. lea 0($tp4,$tp4),$tp8
  1338. xor $tp1,$tp4 # tp4^tp1
  1339. and \$0xfefefefe,$tp8
  1340. and \$0x1b1b1b1b,$acc
  1341. xor $acc,$tp8
  1342. xor $tp8,$tp1 # tp1^tp8
  1343. rol \$8,$tp1 # ROTATE(tp1^tp8,8)
  1344. xor $tp8,$tp2 # tp2^tp1^tp8
  1345. xor $tp8,$tp4 # tp4^tp1^tp8
  1346. xor $tp2,$tp8
  1347. xor $tp4,$tp8 # tp8^(tp8^tp4^tp1)^(tp8^tp2^tp1)=tp8^tp4^tp2
  1348. xor $tp8,$tp1
  1349. rol \$24,$tp2 # ROTATE(tp2^tp1^tp8,24)
  1350. xor $tp2,$tp1
  1351. rol \$16,$tp4 # ROTATE(tp4^tp1^tp8,16)
  1352. xor $tp4,$tp1
  1353. mov $tp1,$i($ptr)
  1354. ___
  1355. }
  1356. # int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
  1357. # AES_KEY *key)
  1358. $code.=<<___;
  1359. .globl AES_set_decrypt_key
  1360. .type AES_set_decrypt_key,\@function,3
  1361. .align 16
  1362. AES_set_decrypt_key:
  1363. push %rbx
  1364. push %rbp
  1365. push %r12
  1366. push %r13
  1367. push %r14
  1368. push %r15
  1369. push %rdx # save key schedule
  1370. .Ldec_key_prologue:
  1371. call _x86_64_AES_set_encrypt_key
  1372. mov (%rsp),%r8 # restore key schedule
  1373. cmp \$0,%eax
  1374. jne .Labort
  1375. mov 240(%r8),%r14d # pull number of rounds
  1376. xor %rdi,%rdi
  1377. lea (%rdi,%r14d,4),%rcx
  1378. mov %r8,%rsi
  1379. lea (%r8,%rcx,4),%rdi # pointer to last chunk
  1380. .align 4
  1381. .Linvert:
  1382. mov 0(%rsi),%rax
  1383. mov 8(%rsi),%rbx
  1384. mov 0(%rdi),%rcx
  1385. mov 8(%rdi),%rdx
  1386. mov %rax,0(%rdi)
  1387. mov %rbx,8(%rdi)
  1388. mov %rcx,0(%rsi)
  1389. mov %rdx,8(%rsi)
  1390. lea 16(%rsi),%rsi
  1391. lea -16(%rdi),%rdi
  1392. cmp %rsi,%rdi
  1393. jne .Linvert
  1394. lea .LAES_Te+2048+1024(%rip),%rax # rcon
  1395. mov 40(%rax),$mask80
  1396. mov 48(%rax),$maskfe
  1397. mov 56(%rax),$mask1b
  1398. mov %r8,$key
  1399. sub \$1,%r14d
  1400. .align 4
  1401. .Lpermute:
  1402. lea 16($key),$key
  1403. mov 0($key),%rax
  1404. mov 8($key),%rcx
  1405. ___
  1406. &dectransform ();
  1407. $code.=<<___;
  1408. mov %eax,0($key)
  1409. mov %ebx,4($key)
  1410. mov %ecx,8($key)
  1411. mov %edx,12($key)
  1412. sub \$1,%r14d
  1413. jnz .Lpermute
  1414. xor %rax,%rax
  1415. .Labort:
  1416. mov 8(%rsp),%r15
  1417. mov 16(%rsp),%r14
  1418. mov 24(%rsp),%r13
  1419. mov 32(%rsp),%r12
  1420. mov 40(%rsp),%rbp
  1421. mov 48(%rsp),%rbx
  1422. add \$56,%rsp
  1423. .Ldec_key_epilogue:
  1424. ret
  1425. .size AES_set_decrypt_key,.-AES_set_decrypt_key
  1426. ___
  1427. # void AES_cbc_encrypt (const void char *inp, unsigned char *out,
  1428. # size_t length, const AES_KEY *key,
  1429. # unsigned char *ivp,const int enc);
  1430. {
  1431. # stack frame layout
  1432. # -8(%rsp) return address
  1433. my $keyp="0(%rsp)"; # one to pass as $key
  1434. my $keyend="8(%rsp)"; # &(keyp->rd_key[4*keyp->rounds])
  1435. my $_rsp="16(%rsp)"; # saved %rsp
  1436. my $_inp="24(%rsp)"; # copy of 1st parameter, inp
  1437. my $_out="32(%rsp)"; # copy of 2nd parameter, out
  1438. my $_len="40(%rsp)"; # copy of 3rd parameter, length
  1439. my $_key="48(%rsp)"; # copy of 4th parameter, key
  1440. my $_ivp="56(%rsp)"; # copy of 5th parameter, ivp
  1441. my $ivec="64(%rsp)"; # ivec[16]
  1442. my $aes_key="80(%rsp)"; # copy of aes_key
  1443. my $mark="80+240(%rsp)"; # copy of aes_key->rounds
  1444. $code.=<<___;
  1445. .globl AES_cbc_encrypt
  1446. .type AES_cbc_encrypt,\@function,6
  1447. .align 16
  1448. .extern OPENSSL_ia32cap_P
  1449. AES_cbc_encrypt:
  1450. cmp \$0,%rdx # check length
  1451. je .Lcbc_epilogue
  1452. pushfq
  1453. push %rbx
  1454. push %rbp
  1455. push %r12
  1456. push %r13
  1457. push %r14
  1458. push %r15
  1459. .Lcbc_prologue:
  1460. cld
  1461. mov %r9d,%r9d # clear upper half of enc
  1462. lea .LAES_Te(%rip),$sbox
  1463. cmp \$0,%r9
  1464. jne .Lcbc_picked_te
  1465. lea .LAES_Td(%rip),$sbox
  1466. .Lcbc_picked_te:
  1467. mov OPENSSL_ia32cap_P(%rip),%r10d
  1468. cmp \$$speed_limit,%rdx
  1469. jb .Lcbc_slow_prologue
  1470. test \$15,%rdx
  1471. jnz .Lcbc_slow_prologue
  1472. bt \$28,%r10d
  1473. jc .Lcbc_slow_prologue
  1474. # allocate aligned stack frame...
  1475. lea -88-248(%rsp),$key
  1476. and \$-64,$key
  1477. # ... and make sure it doesn't alias with AES_T[ed] modulo 4096
  1478. mov $sbox,%r10
  1479. lea 2304($sbox),%r11
  1480. mov $key,%r12
  1481. and \$0xFFF,%r10 # s = $sbox&0xfff
  1482. and \$0xFFF,%r11 # e = ($sbox+2048)&0xfff
  1483. and \$0xFFF,%r12 # p = %rsp&0xfff
  1484. cmp %r11,%r12 # if (p=>e) %rsp =- (p-e);
  1485. jb .Lcbc_te_break_out
  1486. sub %r11,%r12
  1487. sub %r12,$key
  1488. jmp .Lcbc_te_ok
  1489. .Lcbc_te_break_out: # else %rsp -= (p-s)&0xfff + framesz
  1490. sub %r10,%r12
  1491. and \$0xFFF,%r12
  1492. add \$320,%r12
  1493. sub %r12,$key
  1494. .align 4
  1495. .Lcbc_te_ok:
  1496. xchg %rsp,$key
  1497. #add \$8,%rsp # reserve for return address!
  1498. mov $key,$_rsp # save %rsp
  1499. .Lcbc_fast_body:
  1500. mov %rdi,$_inp # save copy of inp
  1501. mov %rsi,$_out # save copy of out
  1502. mov %rdx,$_len # save copy of len
  1503. mov %rcx,$_key # save copy of key
  1504. mov %r8,$_ivp # save copy of ivp
  1505. movl \$0,$mark # copy of aes_key->rounds = 0;
  1506. mov %r8,%rbp # rearrange input arguments
  1507. mov %r9,%rbx
  1508. mov %rsi,$out
  1509. mov %rdi,$inp
  1510. mov %rcx,$key
  1511. mov 240($key),%eax # key->rounds
  1512. # do we copy key schedule to stack?
  1513. mov $key,%r10
  1514. sub $sbox,%r10
  1515. and \$0xfff,%r10
  1516. cmp \$2304,%r10
  1517. jb .Lcbc_do_ecopy
  1518. cmp \$4096-248,%r10
  1519. jb .Lcbc_skip_ecopy
  1520. .align 4
  1521. .Lcbc_do_ecopy:
  1522. mov $key,%rsi
  1523. lea $aes_key,%rdi
  1524. lea $aes_key,$key
  1525. mov \$240/8,%ecx
  1526. .long 0x90A548F3 # rep movsq
  1527. mov %eax,(%rdi) # copy aes_key->rounds
  1528. .Lcbc_skip_ecopy:
  1529. mov $key,$keyp # save key pointer
  1530. mov \$18,%ecx
  1531. .align 4
  1532. .Lcbc_prefetch_te:
  1533. mov 0($sbox),%r10
  1534. mov 32($sbox),%r11
  1535. mov 64($sbox),%r12
  1536. mov 96($sbox),%r13
  1537. lea 128($sbox),$sbox
  1538. sub \$1,%ecx
  1539. jnz .Lcbc_prefetch_te
  1540. lea -2304($sbox),$sbox
  1541. cmp \$0,%rbx
  1542. je .LFAST_DECRYPT
  1543. #----------------------------- ENCRYPT -----------------------------#
  1544. mov 0(%rbp),$s0 # load iv
  1545. mov 4(%rbp),$s1
  1546. mov 8(%rbp),$s2
  1547. mov 12(%rbp),$s3
  1548. .align 4
  1549. .Lcbc_fast_enc_loop:
  1550. xor 0($inp),$s0
  1551. xor 4($inp),$s1
  1552. xor 8($inp),$s2
  1553. xor 12($inp),$s3
  1554. mov $keyp,$key # restore key
  1555. mov $inp,$_inp # if ($verticalspin) save inp
  1556. call _x86_64_AES_encrypt
  1557. mov $_inp,$inp # if ($verticalspin) restore inp
  1558. mov $_len,%r10
  1559. mov $s0,0($out)
  1560. mov $s1,4($out)
  1561. mov $s2,8($out)
  1562. mov $s3,12($out)
  1563. lea 16($inp),$inp
  1564. lea 16($out),$out
  1565. sub \$16,%r10
  1566. test \$-16,%r10
  1567. mov %r10,$_len
  1568. jnz .Lcbc_fast_enc_loop
  1569. mov $_ivp,%rbp # restore ivp
  1570. mov $s0,0(%rbp) # save ivec
  1571. mov $s1,4(%rbp)
  1572. mov $s2,8(%rbp)
  1573. mov $s3,12(%rbp)
  1574. jmp .Lcbc_fast_cleanup
  1575. #----------------------------- DECRYPT -----------------------------#
  1576. .align 16
  1577. .LFAST_DECRYPT:
  1578. cmp $inp,$out
  1579. je .Lcbc_fast_dec_in_place
  1580. mov %rbp,$ivec
  1581. .align 4
  1582. .Lcbc_fast_dec_loop:
  1583. mov 0($inp),$s0 # read input
  1584. mov 4($inp),$s1
  1585. mov 8($inp),$s2
  1586. mov 12($inp),$s3
  1587. mov $keyp,$key # restore key
  1588. mov $inp,$_inp # if ($verticalspin) save inp
  1589. call _x86_64_AES_decrypt
  1590. mov $ivec,%rbp # load ivp
  1591. mov $_inp,$inp # if ($verticalspin) restore inp
  1592. mov $_len,%r10 # load len
  1593. xor 0(%rbp),$s0 # xor iv
  1594. xor 4(%rbp),$s1
  1595. xor 8(%rbp),$s2
  1596. xor 12(%rbp),$s3
  1597. mov $inp,%rbp # current input, next iv
  1598. sub \$16,%r10
  1599. mov %r10,$_len # update len
  1600. mov %rbp,$ivec # update ivp
  1601. mov $s0,0($out) # write output
  1602. mov $s1,4($out)
  1603. mov $s2,8($out)
  1604. mov $s3,12($out)
  1605. lea 16($inp),$inp
  1606. lea 16($out),$out
  1607. jnz .Lcbc_fast_dec_loop
  1608. mov $_ivp,%r12 # load user ivp
  1609. mov 0(%rbp),%r10 # load iv
  1610. mov 8(%rbp),%r11
  1611. mov %r10,0(%r12) # copy back to user
  1612. mov %r11,8(%r12)
  1613. jmp .Lcbc_fast_cleanup
  1614. .align 16
  1615. .Lcbc_fast_dec_in_place:
  1616. mov 0(%rbp),%r10 # copy iv to stack
  1617. mov 8(%rbp),%r11
  1618. mov %r10,0+$ivec
  1619. mov %r11,8+$ivec
  1620. .align 4
  1621. .Lcbc_fast_dec_in_place_loop:
  1622. mov 0($inp),$s0 # load input
  1623. mov 4($inp),$s1
  1624. mov 8($inp),$s2
  1625. mov 12($inp),$s3
  1626. mov $keyp,$key # restore key
  1627. mov $inp,$_inp # if ($verticalspin) save inp
  1628. call _x86_64_AES_decrypt
  1629. mov $_inp,$inp # if ($verticalspin) restore inp
  1630. mov $_len,%r10
  1631. xor 0+$ivec,$s0
  1632. xor 4+$ivec,$s1
  1633. xor 8+$ivec,$s2
  1634. xor 12+$ivec,$s3
  1635. mov 0($inp),%r11 # load input
  1636. mov 8($inp),%r12
  1637. sub \$16,%r10
  1638. jz .Lcbc_fast_dec_in_place_done
  1639. mov %r11,0+$ivec # copy input to iv
  1640. mov %r12,8+$ivec
  1641. mov $s0,0($out) # save output [zaps input]
  1642. mov $s1,4($out)
  1643. mov $s2,8($out)
  1644. mov $s3,12($out)
  1645. lea 16($inp),$inp
  1646. lea 16($out),$out
  1647. mov %r10,$_len
  1648. jmp .Lcbc_fast_dec_in_place_loop
  1649. .Lcbc_fast_dec_in_place_done:
  1650. mov $_ivp,%rdi
  1651. mov %r11,0(%rdi) # copy iv back to user
  1652. mov %r12,8(%rdi)
  1653. mov $s0,0($out) # save output [zaps input]
  1654. mov $s1,4($out)
  1655. mov $s2,8($out)
  1656. mov $s3,12($out)
  1657. .align 4
  1658. .Lcbc_fast_cleanup:
  1659. cmpl \$0,$mark # was the key schedule copied?
  1660. lea $aes_key,%rdi
  1661. je .Lcbc_exit
  1662. mov \$240/8,%ecx
  1663. xor %rax,%rax
  1664. .long 0x90AB48F3 # rep stosq
  1665. jmp .Lcbc_exit
  1666. #--------------------------- SLOW ROUTINE ---------------------------#
  1667. .align 16
  1668. .Lcbc_slow_prologue:
  1669. # allocate aligned stack frame...
  1670. lea -88(%rsp),%rbp
  1671. and \$-64,%rbp
  1672. # ... just "above" key schedule
  1673. lea -88-63(%rcx),%r10
  1674. sub %rbp,%r10
  1675. neg %r10
  1676. and \$0x3c0,%r10
  1677. sub %r10,%rbp
  1678. xchg %rsp,%rbp
  1679. #add \$8,%rsp # reserve for return address!
  1680. mov %rbp,$_rsp # save %rsp
  1681. .Lcbc_slow_body:
  1682. #mov %rdi,$_inp # save copy of inp
  1683. #mov %rsi,$_out # save copy of out
  1684. #mov %rdx,$_len # save copy of len
  1685. #mov %rcx,$_key # save copy of key
  1686. mov %r8,$_ivp # save copy of ivp
  1687. mov %r8,%rbp # rearrange input arguments
  1688. mov %r9,%rbx
  1689. mov %rsi,$out
  1690. mov %rdi,$inp
  1691. mov %rcx,$key
  1692. mov %rdx,%r10
  1693. mov 240($key),%eax
  1694. mov $key,$keyp # save key pointer
  1695. shl \$4,%eax
  1696. lea ($key,%rax),%rax
  1697. mov %rax,$keyend
  1698. # pick Te4 copy which can't "overlap" with stack frame or key scdedule
  1699. lea 2048($sbox),$sbox
  1700. lea 768-8(%rsp),%rax
  1701. sub $sbox,%rax
  1702. and \$0x300,%rax
  1703. lea ($sbox,%rax),$sbox
  1704. cmp \$0,%rbx
  1705. je .LSLOW_DECRYPT
  1706. #--------------------------- SLOW ENCRYPT ---------------------------#
  1707. test \$-16,%r10 # check upon length
  1708. mov 0(%rbp),$s0 # load iv
  1709. mov 4(%rbp),$s1
  1710. mov 8(%rbp),$s2
  1711. mov 12(%rbp),$s3
  1712. jz .Lcbc_slow_enc_tail # short input...
  1713. .align 4
  1714. .Lcbc_slow_enc_loop:
  1715. xor 0($inp),$s0
  1716. xor 4($inp),$s1
  1717. xor 8($inp),$s2
  1718. xor 12($inp),$s3
  1719. mov $keyp,$key # restore key
  1720. mov $inp,$_inp # save inp
  1721. mov $out,$_out # save out
  1722. mov %r10,$_len # save len
  1723. call _x86_64_AES_encrypt_compact
  1724. mov $_inp,$inp # restore inp
  1725. mov $_out,$out # restore out
  1726. mov $_len,%r10 # restore len
  1727. mov $s0,0($out)
  1728. mov $s1,4($out)
  1729. mov $s2,8($out)
  1730. mov $s3,12($out)
  1731. lea 16($inp),$inp
  1732. lea 16($out),$out
  1733. sub \$16,%r10
  1734. test \$-16,%r10
  1735. jnz .Lcbc_slow_enc_loop
  1736. test \$15,%r10
  1737. jnz .Lcbc_slow_enc_tail
  1738. mov $_ivp,%rbp # restore ivp
  1739. mov $s0,0(%rbp) # save ivec
  1740. mov $s1,4(%rbp)
  1741. mov $s2,8(%rbp)
  1742. mov $s3,12(%rbp)
  1743. jmp .Lcbc_exit
  1744. .align 4
  1745. .Lcbc_slow_enc_tail:
  1746. mov %rax,%r11
  1747. mov %rcx,%r12
  1748. mov %r10,%rcx
  1749. mov $inp,%rsi
  1750. mov $out,%rdi
  1751. .long 0x9066A4F3 # rep movsb
  1752. mov \$16,%rcx # zero tail
  1753. sub %r10,%rcx
  1754. xor %rax,%rax
  1755. .long 0x9066AAF3 # rep stosb
  1756. mov $out,$inp # this is not a mistake!
  1757. mov \$16,%r10 # len=16
  1758. mov %r11,%rax
  1759. mov %r12,%rcx
  1760. jmp .Lcbc_slow_enc_loop # one more spin...
  1761. #--------------------------- SLOW DECRYPT ---------------------------#
  1762. .align 16
  1763. .LSLOW_DECRYPT:
  1764. shr \$3,%rax
  1765. add %rax,$sbox # recall "magic" constants!
  1766. mov 0(%rbp),%r11 # copy iv to stack
  1767. mov 8(%rbp),%r12
  1768. mov %r11,0+$ivec
  1769. mov %r12,8+$ivec
  1770. .align 4
  1771. .Lcbc_slow_dec_loop:
  1772. mov 0($inp),$s0 # load input
  1773. mov 4($inp),$s1
  1774. mov 8($inp),$s2
  1775. mov 12($inp),$s3
  1776. mov $keyp,$key # restore key
  1777. mov $inp,$_inp # save inp
  1778. mov $out,$_out # save out
  1779. mov %r10,$_len # save len
  1780. call _x86_64_AES_decrypt_compact
  1781. mov $_inp,$inp # restore inp
  1782. mov $_out,$out # restore out
  1783. mov $_len,%r10
  1784. xor 0+$ivec,$s0
  1785. xor 4+$ivec,$s1
  1786. xor 8+$ivec,$s2
  1787. xor 12+$ivec,$s3
  1788. mov 0($inp),%r11 # load input
  1789. mov 8($inp),%r12
  1790. sub \$16,%r10
  1791. jc .Lcbc_slow_dec_partial
  1792. jz .Lcbc_slow_dec_done
  1793. mov %r11,0+$ivec # copy input to iv
  1794. mov %r12,8+$ivec
  1795. mov $s0,0($out) # save output [can zap input]
  1796. mov $s1,4($out)
  1797. mov $s2,8($out)
  1798. mov $s3,12($out)
  1799. lea 16($inp),$inp
  1800. lea 16($out),$out
  1801. jmp .Lcbc_slow_dec_loop
  1802. .Lcbc_slow_dec_done:
  1803. mov $_ivp,%rdi
  1804. mov %r11,0(%rdi) # copy iv back to user
  1805. mov %r12,8(%rdi)
  1806. mov $s0,0($out) # save output [can zap input]
  1807. mov $s1,4($out)
  1808. mov $s2,8($out)
  1809. mov $s3,12($out)
  1810. jmp .Lcbc_exit
  1811. .align 4
  1812. .Lcbc_slow_dec_partial:
  1813. mov $_ivp,%rdi
  1814. mov %r11,0(%rdi) # copy iv back to user
  1815. mov %r12,8(%rdi)
  1816. mov $s0,0+$ivec # save output to stack
  1817. mov $s1,4+$ivec
  1818. mov $s2,8+$ivec
  1819. mov $s3,12+$ivec
  1820. mov $out,%rdi
  1821. lea $ivec,%rsi
  1822. lea 16(%r10),%rcx
  1823. .long 0x9066A4F3 # rep movsb
  1824. jmp .Lcbc_exit
  1825. .align 16
  1826. .Lcbc_exit:
  1827. mov $_rsp,%rsi
  1828. mov (%rsi),%r15
  1829. mov 8(%rsi),%r14
  1830. mov 16(%rsi),%r13
  1831. mov 24(%rsi),%r12
  1832. mov 32(%rsi),%rbp
  1833. mov 40(%rsi),%rbx
  1834. lea 48(%rsi),%rsp
  1835. .Lcbc_popfq:
  1836. popfq
  1837. .Lcbc_epilogue:
  1838. ret
  1839. .size AES_cbc_encrypt,.-AES_cbc_encrypt
  1840. ___
  1841. }
  1842. $code.=<<___;
  1843. .align 64
  1844. .LAES_Te:
  1845. ___
  1846. &_data_word(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6);
  1847. &_data_word(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591);
  1848. &_data_word(0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56);
  1849. &_data_word(0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec);
  1850. &_data_word(0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa);
  1851. &_data_word(0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb);
  1852. &_data_word(0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45);
  1853. &_data_word(0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b);
  1854. &_data_word(0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c);
  1855. &_data_word(0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83);
  1856. &_data_word(0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9);
  1857. &_data_word(0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a);
  1858. &_data_word(0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d);
  1859. &_data_word(0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f);
  1860. &_data_word(0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df);
  1861. &_data_word(0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea);
  1862. &_data_word(0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34);
  1863. &_data_word(0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b);
  1864. &_data_word(0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d);
  1865. &_data_word(0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413);
  1866. &_data_word(0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1);
  1867. &_data_word(0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6);
  1868. &_data_word(0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972);
  1869. &_data_word(0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85);
  1870. &_data_word(0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed);
  1871. &_data_word(0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511);
  1872. &_data_word(0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe);
  1873. &_data_word(0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b);
  1874. &_data_word(0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05);
  1875. &_data_word(0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1);
  1876. &_data_word(0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142);
  1877. &_data_word(0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf);
  1878. &_data_word(0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3);
  1879. &_data_word(0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e);
  1880. &_data_word(0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a);
  1881. &_data_word(0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6);
  1882. &_data_word(0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3);
  1883. &_data_word(0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b);
  1884. &_data_word(0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428);
  1885. &_data_word(0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad);
  1886. &_data_word(0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14);
  1887. &_data_word(0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8);
  1888. &_data_word(0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4);
  1889. &_data_word(0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2);
  1890. &_data_word(0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda);
  1891. &_data_word(0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949);
  1892. &_data_word(0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf);
  1893. &_data_word(0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810);
  1894. &_data_word(0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c);
  1895. &_data_word(0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697);
  1896. &_data_word(0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e);
  1897. &_data_word(0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f);
  1898. &_data_word(0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc);
  1899. &_data_word(0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c);
  1900. &_data_word(0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969);
  1901. &_data_word(0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27);
  1902. &_data_word(0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122);
  1903. &_data_word(0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433);
  1904. &_data_word(0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9);
  1905. &_data_word(0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5);
  1906. &_data_word(0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a);
  1907. &_data_word(0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0);
  1908. &_data_word(0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e);
  1909. &_data_word(0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c);
  1910. #Te4 # four copies of Te4 to choose from to avoid L1 aliasing
  1911. &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
  1912. &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
  1913. &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
  1914. &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
  1915. &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
  1916. &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
  1917. &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
  1918. &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
  1919. &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
  1920. &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
  1921. &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
  1922. &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
  1923. &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
  1924. &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
  1925. &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
  1926. &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
  1927. &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
  1928. &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
  1929. &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
  1930. &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
  1931. &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
  1932. &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
  1933. &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
  1934. &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
  1935. &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
  1936. &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
  1937. &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
  1938. &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
  1939. &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
  1940. &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
  1941. &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
  1942. &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
  1943. &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
  1944. &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
  1945. &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
  1946. &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
  1947. &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
  1948. &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
  1949. &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
  1950. &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
  1951. &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
  1952. &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
  1953. &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
  1954. &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
  1955. &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
  1956. &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
  1957. &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
  1958. &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
  1959. &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
  1960. &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
  1961. &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
  1962. &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
  1963. &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
  1964. &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
  1965. &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
  1966. &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
  1967. &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
  1968. &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
  1969. &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
  1970. &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
  1971. &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
  1972. &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
  1973. &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
  1974. &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
  1975. &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
  1976. &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
  1977. &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
  1978. &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
  1979. &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
  1980. &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
  1981. &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
  1982. &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
  1983. &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
  1984. &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
  1985. &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
  1986. &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
  1987. &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
  1988. &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
  1989. &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
  1990. &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
  1991. &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
  1992. &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
  1993. &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
  1994. &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
  1995. &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
  1996. &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
  1997. &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
  1998. &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
  1999. &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
  2000. &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
  2001. &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
  2002. &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
  2003. &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
  2004. &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
  2005. &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
  2006. &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
  2007. &data_byte(0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5);
  2008. &data_byte(0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76);
  2009. &data_byte(0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0);
  2010. &data_byte(0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0);
  2011. &data_byte(0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc);
  2012. &data_byte(0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15);
  2013. &data_byte(0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a);
  2014. &data_byte(0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75);
  2015. &data_byte(0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0);
  2016. &data_byte(0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84);
  2017. &data_byte(0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b);
  2018. &data_byte(0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf);
  2019. &data_byte(0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85);
  2020. &data_byte(0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8);
  2021. &data_byte(0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5);
  2022. &data_byte(0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2);
  2023. &data_byte(0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17);
  2024. &data_byte(0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73);
  2025. &data_byte(0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88);
  2026. &data_byte(0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb);
  2027. &data_byte(0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c);
  2028. &data_byte(0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79);
  2029. &data_byte(0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9);
  2030. &data_byte(0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08);
  2031. &data_byte(0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6);
  2032. &data_byte(0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a);
  2033. &data_byte(0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e);
  2034. &data_byte(0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e);
  2035. &data_byte(0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94);
  2036. &data_byte(0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf);
  2037. &data_byte(0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68);
  2038. &data_byte(0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16);
  2039. #rcon:
  2040. $code.=<<___;
  2041. .long 0x00000001, 0x00000002, 0x00000004, 0x00000008
  2042. .long 0x00000010, 0x00000020, 0x00000040, 0x00000080
  2043. .long 0x0000001b, 0x00000036, 0x80808080, 0x80808080
  2044. .long 0xfefefefe, 0xfefefefe, 0x1b1b1b1b, 0x1b1b1b1b
  2045. ___
  2046. $code.=<<___;
  2047. .align 64
  2048. .LAES_Td:
  2049. ___
  2050. &_data_word(0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a);
  2051. &_data_word(0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b);
  2052. &_data_word(0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5);
  2053. &_data_word(0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5);
  2054. &_data_word(0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d);
  2055. &_data_word(0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b);
  2056. &_data_word(0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295);
  2057. &_data_word(0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e);
  2058. &_data_word(0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927);
  2059. &_data_word(0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d);
  2060. &_data_word(0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362);
  2061. &_data_word(0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9);
  2062. &_data_word(0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52);
  2063. &_data_word(0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566);
  2064. &_data_word(0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3);
  2065. &_data_word(0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed);
  2066. &_data_word(0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e);
  2067. &_data_word(0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4);
  2068. &_data_word(0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4);
  2069. &_data_word(0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd);
  2070. &_data_word(0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d);
  2071. &_data_word(0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060);
  2072. &_data_word(0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967);
  2073. &_data_word(0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879);
  2074. &_data_word(0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000);
  2075. &_data_word(0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c);
  2076. &_data_word(0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36);
  2077. &_data_word(0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624);
  2078. &_data_word(0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b);
  2079. &_data_word(0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c);
  2080. &_data_word(0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12);
  2081. &_data_word(0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14);
  2082. &_data_word(0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3);
  2083. &_data_word(0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b);
  2084. &_data_word(0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8);
  2085. &_data_word(0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684);
  2086. &_data_word(0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7);
  2087. &_data_word(0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177);
  2088. &_data_word(0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947);
  2089. &_data_word(0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322);
  2090. &_data_word(0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498);
  2091. &_data_word(0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f);
  2092. &_data_word(0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54);
  2093. &_data_word(0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382);
  2094. &_data_word(0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf);
  2095. &_data_word(0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb);
  2096. &_data_word(0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83);
  2097. &_data_word(0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef);
  2098. &_data_word(0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029);
  2099. &_data_word(0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235);
  2100. &_data_word(0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733);
  2101. &_data_word(0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117);
  2102. &_data_word(0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4);
  2103. &_data_word(0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546);
  2104. &_data_word(0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb);
  2105. &_data_word(0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d);
  2106. &_data_word(0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb);
  2107. &_data_word(0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a);
  2108. &_data_word(0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773);
  2109. &_data_word(0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478);
  2110. &_data_word(0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2);
  2111. &_data_word(0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff);
  2112. &_data_word(0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664);
  2113. &_data_word(0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0);
  2114. #Td4: # four copies of Td4 to choose from to avoid L1 aliasing
  2115. &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
  2116. &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
  2117. &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
  2118. &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
  2119. &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
  2120. &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
  2121. &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
  2122. &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
  2123. &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
  2124. &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
  2125. &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
  2126. &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
  2127. &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
  2128. &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
  2129. &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
  2130. &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
  2131. &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
  2132. &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
  2133. &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
  2134. &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
  2135. &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
  2136. &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
  2137. &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
  2138. &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
  2139. &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
  2140. &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
  2141. &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
  2142. &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
  2143. &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
  2144. &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
  2145. &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
  2146. &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
  2147. $code.=<<___;
  2148. .long 0x80808080, 0x80808080, 0xfefefefe, 0xfefefefe
  2149. .long 0x1b1b1b1b, 0x1b1b1b1b, 0, 0
  2150. ___
  2151. &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
  2152. &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
  2153. &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
  2154. &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
  2155. &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
  2156. &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
  2157. &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
  2158. &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
  2159. &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
  2160. &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
  2161. &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
  2162. &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
  2163. &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
  2164. &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
  2165. &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
  2166. &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
  2167. &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
  2168. &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
  2169. &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
  2170. &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
  2171. &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
  2172. &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
  2173. &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
  2174. &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
  2175. &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
  2176. &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
  2177. &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
  2178. &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
  2179. &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
  2180. &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
  2181. &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
  2182. &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
  2183. $code.=<<___;
  2184. .long 0x80808080, 0x80808080, 0xfefefefe, 0xfefefefe
  2185. .long 0x1b1b1b1b, 0x1b1b1b1b, 0, 0
  2186. ___
  2187. &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
  2188. &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
  2189. &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
  2190. &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
  2191. &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
  2192. &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
  2193. &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
  2194. &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
  2195. &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
  2196. &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
  2197. &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
  2198. &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
  2199. &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
  2200. &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
  2201. &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
  2202. &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
  2203. &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
  2204. &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
  2205. &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
  2206. &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
  2207. &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
  2208. &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
  2209. &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
  2210. &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
  2211. &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
  2212. &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
  2213. &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
  2214. &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
  2215. &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
  2216. &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
  2217. &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
  2218. &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
  2219. $code.=<<___;
  2220. .long 0x80808080, 0x80808080, 0xfefefefe, 0xfefefefe
  2221. .long 0x1b1b1b1b, 0x1b1b1b1b, 0, 0
  2222. ___
  2223. &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
  2224. &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
  2225. &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
  2226. &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
  2227. &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
  2228. &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
  2229. &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
  2230. &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
  2231. &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
  2232. &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
  2233. &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
  2234. &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
  2235. &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
  2236. &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
  2237. &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
  2238. &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
  2239. &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
  2240. &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
  2241. &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
  2242. &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
  2243. &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
  2244. &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
  2245. &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
  2246. &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
  2247. &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
  2248. &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
  2249. &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
  2250. &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
  2251. &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
  2252. &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
  2253. &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
  2254. &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
  2255. $code.=<<___;
  2256. .long 0x80808080, 0x80808080, 0xfefefefe, 0xfefefefe
  2257. .long 0x1b1b1b1b, 0x1b1b1b1b, 0, 0
  2258. .asciz "AES for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
  2259. .align 64
  2260. ___
  2261. # EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
  2262. # CONTEXT *context,DISPATCHER_CONTEXT *disp)
  2263. if ($win64) {
  2264. $rec="%rcx";
  2265. $frame="%rdx";
  2266. $context="%r8";
  2267. $disp="%r9";
  2268. $code.=<<___;
  2269. .extern __imp_RtlVirtualUnwind
  2270. .type block_se_handler,\@abi-omnipotent
  2271. .align 16
  2272. block_se_handler:
  2273. push %rsi
  2274. push %rdi
  2275. push %rbx
  2276. push %rbp
  2277. push %r12
  2278. push %r13
  2279. push %r14
  2280. push %r15
  2281. pushfq
  2282. sub \$64,%rsp
  2283. mov 120($context),%rax # pull context->Rax
  2284. mov 248($context),%rbx # pull context->Rip
  2285. mov 8($disp),%rsi # disp->ImageBase
  2286. mov 56($disp),%r11 # disp->HandlerData
  2287. mov 0(%r11),%r10d # HandlerData[0]
  2288. lea (%rsi,%r10),%r10 # prologue label
  2289. cmp %r10,%rbx # context->Rip<prologue label
  2290. jb .Lin_block_prologue
  2291. mov 152($context),%rax # pull context->Rsp
  2292. mov 4(%r11),%r10d # HandlerData[1]
  2293. lea (%rsi,%r10),%r10 # epilogue label
  2294. cmp %r10,%rbx # context->Rip>=epilogue label
  2295. jae .Lin_block_prologue
  2296. mov 24(%rax),%rax # pull saved real stack pointer
  2297. lea 48(%rax),%rax # adjust...
  2298. mov -8(%rax),%rbx
  2299. mov -16(%rax),%rbp
  2300. mov -24(%rax),%r12
  2301. mov -32(%rax),%r13
  2302. mov -40(%rax),%r14
  2303. mov -48(%rax),%r15
  2304. mov %rbx,144($context) # restore context->Rbx
  2305. mov %rbp,160($context) # restore context->Rbp
  2306. mov %r12,216($context) # restore context->R12
  2307. mov %r13,224($context) # restore context->R13
  2308. mov %r14,232($context) # restore context->R14
  2309. mov %r15,240($context) # restore context->R15
  2310. .Lin_block_prologue:
  2311. mov 8(%rax),%rdi
  2312. mov 16(%rax),%rsi
  2313. mov %rax,152($context) # restore context->Rsp
  2314. mov %rsi,168($context) # restore context->Rsi
  2315. mov %rdi,176($context) # restore context->Rdi
  2316. jmp .Lcommon_seh_exit
  2317. .size block_se_handler,.-block_se_handler
  2318. .type key_se_handler,\@abi-omnipotent
  2319. .align 16
  2320. key_se_handler:
  2321. push %rsi
  2322. push %rdi
  2323. push %rbx
  2324. push %rbp
  2325. push %r12
  2326. push %r13
  2327. push %r14
  2328. push %r15
  2329. pushfq
  2330. sub \$64,%rsp
  2331. mov 120($context),%rax # pull context->Rax
  2332. mov 248($context),%rbx # pull context->Rip
  2333. mov 8($disp),%rsi # disp->ImageBase
  2334. mov 56($disp),%r11 # disp->HandlerData
  2335. mov 0(%r11),%r10d # HandlerData[0]
  2336. lea (%rsi,%r10),%r10 # prologue label
  2337. cmp %r10,%rbx # context->Rip<prologue label
  2338. jb .Lin_key_prologue
  2339. mov 152($context),%rax # pull context->Rsp
  2340. mov 4(%r11),%r10d # HandlerData[1]
  2341. lea (%rsi,%r10),%r10 # epilogue label
  2342. cmp %r10,%rbx # context->Rip>=epilogue label
  2343. jae .Lin_key_prologue
  2344. lea 56(%rax),%rax
  2345. mov -8(%rax),%rbx
  2346. mov -16(%rax),%rbp
  2347. mov -24(%rax),%r12
  2348. mov -32(%rax),%r13
  2349. mov -40(%rax),%r14
  2350. mov -48(%rax),%r15
  2351. mov %rbx,144($context) # restore context->Rbx
  2352. mov %rbp,160($context) # restore context->Rbp
  2353. mov %r12,216($context) # restore context->R12
  2354. mov %r13,224($context) # restore context->R13
  2355. mov %r14,232($context) # restore context->R14
  2356. mov %r15,240($context) # restore context->R15
  2357. .Lin_key_prologue:
  2358. mov 8(%rax),%rdi
  2359. mov 16(%rax),%rsi
  2360. mov %rax,152($context) # restore context->Rsp
  2361. mov %rsi,168($context) # restore context->Rsi
  2362. mov %rdi,176($context) # restore context->Rdi
  2363. jmp .Lcommon_seh_exit
  2364. .size key_se_handler,.-key_se_handler
  2365. .type cbc_se_handler,\@abi-omnipotent
  2366. .align 16
  2367. cbc_se_handler:
  2368. push %rsi
  2369. push %rdi
  2370. push %rbx
  2371. push %rbp
  2372. push %r12
  2373. push %r13
  2374. push %r14
  2375. push %r15
  2376. pushfq
  2377. sub \$64,%rsp
  2378. mov 120($context),%rax # pull context->Rax
  2379. mov 248($context),%rbx # pull context->Rip
  2380. lea .Lcbc_prologue(%rip),%r10
  2381. cmp %r10,%rbx # context->Rip<.Lcbc_prologue
  2382. jb .Lin_cbc_prologue
  2383. lea .Lcbc_fast_body(%rip),%r10
  2384. cmp %r10,%rbx # context->Rip<.Lcbc_fast_body
  2385. jb .Lin_cbc_frame_setup
  2386. lea .Lcbc_slow_prologue(%rip),%r10
  2387. cmp %r10,%rbx # context->Rip<.Lcbc_slow_prologue
  2388. jb .Lin_cbc_body
  2389. lea .Lcbc_slow_body(%rip),%r10
  2390. cmp %r10,%rbx # context->Rip<.Lcbc_slow_body
  2391. jb .Lin_cbc_frame_setup
  2392. .Lin_cbc_body:
  2393. mov 152($context),%rax # pull context->Rsp
  2394. lea .Lcbc_epilogue(%rip),%r10
  2395. cmp %r10,%rbx # context->Rip>=.Lcbc_epilogue
  2396. jae .Lin_cbc_prologue
  2397. lea 8(%rax),%rax
  2398. lea .Lcbc_popfq(%rip),%r10
  2399. cmp %r10,%rbx # context->Rip>=.Lcbc_popfq
  2400. jae .Lin_cbc_prologue
  2401. mov `16-8`(%rax),%rax # biased $_rsp
  2402. lea 56(%rax),%rax
  2403. .Lin_cbc_frame_setup:
  2404. mov -16(%rax),%rbx
  2405. mov -24(%rax),%rbp
  2406. mov -32(%rax),%r12
  2407. mov -40(%rax),%r13
  2408. mov -48(%rax),%r14
  2409. mov -56(%rax),%r15
  2410. mov %rbx,144($context) # restore context->Rbx
  2411. mov %rbp,160($context) # restore context->Rbp
  2412. mov %r12,216($context) # restore context->R12
  2413. mov %r13,224($context) # restore context->R13
  2414. mov %r14,232($context) # restore context->R14
  2415. mov %r15,240($context) # restore context->R15
  2416. .Lin_cbc_prologue:
  2417. mov 8(%rax),%rdi
  2418. mov 16(%rax),%rsi
  2419. mov %rax,152($context) # restore context->Rsp
  2420. mov %rsi,168($context) # restore context->Rsi
  2421. mov %rdi,176($context) # restore context->Rdi
  2422. .Lcommon_seh_exit:
  2423. mov 40($disp),%rdi # disp->ContextRecord
  2424. mov $context,%rsi # context
  2425. mov \$`1232/8`,%ecx # sizeof(CONTEXT)
  2426. .long 0xa548f3fc # cld; rep movsq
  2427. mov $disp,%rsi
  2428. xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
  2429. mov 8(%rsi),%rdx # arg2, disp->ImageBase
  2430. mov 0(%rsi),%r8 # arg3, disp->ControlPc
  2431. mov 16(%rsi),%r9 # arg4, disp->FunctionEntry
  2432. mov 40(%rsi),%r10 # disp->ContextRecord
  2433. lea 56(%rsi),%r11 # &disp->HandlerData
  2434. lea 24(%rsi),%r12 # &disp->EstablisherFrame
  2435. mov %r10,32(%rsp) # arg5
  2436. mov %r11,40(%rsp) # arg6
  2437. mov %r12,48(%rsp) # arg7
  2438. mov %rcx,56(%rsp) # arg8, (NULL)
  2439. call *__imp_RtlVirtualUnwind(%rip)
  2440. mov \$1,%eax # ExceptionContinueSearch
  2441. add \$64,%rsp
  2442. popfq
  2443. pop %r15
  2444. pop %r14
  2445. pop %r13
  2446. pop %r12
  2447. pop %rbp
  2448. pop %rbx
  2449. pop %rdi
  2450. pop %rsi
  2451. ret
  2452. .size cbc_se_handler,.-cbc_se_handler
  2453. .section .pdata
  2454. .align 4
  2455. .rva .LSEH_begin_AES_encrypt
  2456. .rva .LSEH_end_AES_encrypt
  2457. .rva .LSEH_info_AES_encrypt
  2458. .rva .LSEH_begin_AES_decrypt
  2459. .rva .LSEH_end_AES_decrypt
  2460. .rva .LSEH_info_AES_decrypt
  2461. .rva .LSEH_begin_AES_set_encrypt_key
  2462. .rva .LSEH_end_AES_set_encrypt_key
  2463. .rva .LSEH_info_AES_set_encrypt_key
  2464. .rva .LSEH_begin_AES_set_decrypt_key
  2465. .rva .LSEH_end_AES_set_decrypt_key
  2466. .rva .LSEH_info_AES_set_decrypt_key
  2467. .rva .LSEH_begin_AES_cbc_encrypt
  2468. .rva .LSEH_end_AES_cbc_encrypt
  2469. .rva .LSEH_info_AES_cbc_encrypt
  2470. .section .xdata
  2471. .align 8
  2472. .LSEH_info_AES_encrypt:
  2473. .byte 9,0,0,0
  2474. .rva block_se_handler
  2475. .rva .Lenc_prologue,.Lenc_epilogue # HandlerData[]
  2476. .LSEH_info_AES_decrypt:
  2477. .byte 9,0,0,0
  2478. .rva block_se_handler
  2479. .rva .Ldec_prologue,.Ldec_epilogue # HandlerData[]
  2480. .LSEH_info_AES_set_encrypt_key:
  2481. .byte 9,0,0,0
  2482. .rva key_se_handler
  2483. .rva .Lenc_key_prologue,.Lenc_key_epilogue # HandlerData[]
  2484. .LSEH_info_AES_set_decrypt_key:
  2485. .byte 9,0,0,0
  2486. .rva key_se_handler
  2487. .rva .Ldec_key_prologue,.Ldec_key_epilogue # HandlerData[]
  2488. .LSEH_info_AES_cbc_encrypt:
  2489. .byte 9,0,0,0
  2490. .rva cbc_se_handler
  2491. ___
  2492. }
  2493. $code =~ s/\`([^\`]*)\`/eval($1)/gem;
  2494. print $code;
  2495. close STDOUT;