2
0

aes-x86_64.pl 75 KB

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