2
0

aes-x86_64.pl 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595
  1. #!/usr/bin/env perl
  2. #
  3. # ====================================================================
  4. # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
  5. # project. Rights for redistribution and usage in source and binary
  6. # forms are granted according to the OpenSSL license.
  7. # ====================================================================
  8. #
  9. # Version 1.1.
  10. #
  11. # aes-*-cbc benchmarks are improved by >70% [compared to gcc 3.3.2 on
  12. # Opteron 240 CPU] plus all the bells-n-whistles from 32-bit version
  13. # [you'll notice a lot of resemblance], such as compressed S-boxes
  14. # in little-endian byte order, prefetch of these tables in CBC mode,
  15. # as well as avoiding L1 cache aliasing between stack frame and key
  16. # schedule and already mentioned tables.
  17. #
  18. # Performance in number of cycles per processed byte for 128-bit key:
  19. #
  20. # ECB CBC encrypt
  21. # AMD64 13.7 13.0(*)
  22. # EM64T 20.2 18.6(*)
  23. #
  24. # (*) CBC benchmarks are better than ECB thanks to custom ABI used
  25. # by the private block encryption function.
  26. $verticalspin=1; # unlike 32-bit version $verticalspin performs
  27. # ~15% better on both AMD and Intel cores
  28. $output=shift;
  29. open STDOUT,"| $^X ../perlasm/x86_64-xlate.pl $output";
  30. $code=".text\n";
  31. $s0="%eax";
  32. $s1="%ebx";
  33. $s2="%ecx";
  34. $s3="%edx";
  35. $acc0="%esi";
  36. $acc1="%edi";
  37. $acc2="%ebp";
  38. $inp="%r8";
  39. $out="%r9";
  40. $t0="%r10d";
  41. $t1="%r11d";
  42. $t2="%r12d";
  43. $rnds="%r13d";
  44. $sbox="%r14";
  45. $key="%r15";
  46. sub hi() { my $r=shift; $r =~ s/%[er]([a-d])x/%\1h/; $r; }
  47. sub lo() { my $r=shift; $r =~ s/%[er]([a-d])x/%\1l/;
  48. $r =~ s/%[er]([sd]i)/%\1l/;
  49. $r =~ s/%(r[0-9]+)[d]?/%\1b/; $r; }
  50. sub _data_word()
  51. { my $i;
  52. while(defined($i=shift)) { $code.=sprintf".long\t0x%08x,0x%08x\n",$i,$i; }
  53. }
  54. sub data_word()
  55. { my $i;
  56. my $last=pop(@_);
  57. $code.=".long\t";
  58. while(defined($i=shift)) { $code.=sprintf"0x%08x,",$i; }
  59. $code.=sprintf"0x%08x\n",$last;
  60. }
  61. sub encvert()
  62. { my $t3="%r8d"; # zaps $inp!
  63. $code.=<<___;
  64. # favor 3-way issue Opteron pipeline...
  65. movzb `&lo("$s0")`,$acc0
  66. movzb `&lo("$s1")`,$acc1
  67. movzb `&lo("$s2")`,$acc2
  68. mov 0($sbox,$acc0,8),$t0
  69. mov 0($sbox,$acc1,8),$t1
  70. mov 0($sbox,$acc2,8),$t2
  71. movzb `&hi("$s1")`,$acc0
  72. movzb `&hi("$s2")`,$acc1
  73. movzb `&lo("$s3")`,$acc2
  74. xor 3($sbox,$acc0,8),$t0
  75. xor 3($sbox,$acc1,8),$t1
  76. mov 0($sbox,$acc2,8),$t3
  77. movzb `&hi("$s3")`,$acc0
  78. shr \$16,$s2
  79. movzb `&hi("$s0")`,$acc2
  80. xor 3($sbox,$acc0,8),$t2
  81. shr \$16,$s3
  82. xor 3($sbox,$acc2,8),$t3
  83. shr \$16,$s1
  84. lea 16($key),$key
  85. shr \$16,$s0
  86. movzb `&lo("$s2")`,$acc0
  87. movzb `&lo("$s3")`,$acc1
  88. movzb `&lo("$s0")`,$acc2
  89. xor 2($sbox,$acc0,8),$t0
  90. xor 2($sbox,$acc1,8),$t1
  91. xor 2($sbox,$acc2,8),$t2
  92. movzb `&hi("$s3")`,$acc0
  93. movzb `&hi("$s0")`,$acc1
  94. movzb `&lo("$s1")`,$acc2
  95. xor 1($sbox,$acc0,8),$t0
  96. xor 1($sbox,$acc1,8),$t1
  97. xor 2($sbox,$acc2,8),$t3
  98. mov 12($key),$s3
  99. movzb `&hi("$s1")`,$acc1
  100. movzb `&hi("$s2")`,$acc2
  101. mov 0($key),$s0
  102. xor 1($sbox,$acc1,8),$t2
  103. xor 1($sbox,$acc2,8),$t3
  104. mov 4($key),$s1
  105. mov 8($key),$s2
  106. xor $t0,$s0
  107. xor $t1,$s1
  108. xor $t2,$s2
  109. xor $t3,$s3
  110. ___
  111. }
  112. sub enclastvert()
  113. { my $t3="%r8d"; # zaps $inp!
  114. $code.=<<___;
  115. movzb `&lo("$s0")`,$acc0
  116. movzb `&lo("$s1")`,$acc1
  117. movzb `&lo("$s2")`,$acc2
  118. mov 2($sbox,$acc0,8),$t0
  119. mov 2($sbox,$acc1,8),$t1
  120. mov 2($sbox,$acc2,8),$t2
  121. and \$0x000000ff,$t0
  122. and \$0x000000ff,$t1
  123. and \$0x000000ff,$t2
  124. movzb `&lo("$s3")`,$acc0
  125. movzb `&hi("$s1")`,$acc1
  126. movzb `&hi("$s2")`,$acc2
  127. mov 2($sbox,$acc0,8),$t3
  128. mov 0($sbox,$acc1,8),$acc1 #$t0
  129. mov 0($sbox,$acc2,8),$acc2 #$t1
  130. and \$0x000000ff,$t3
  131. and \$0x0000ff00,$acc1
  132. and \$0x0000ff00,$acc2
  133. xor $acc1,$t0
  134. xor $acc2,$t1
  135. shr \$16,$s2
  136. movzb `&hi("$s3")`,$acc0
  137. movzb `&hi("$s0")`,$acc1
  138. shr \$16,$s3
  139. mov 0($sbox,$acc0,8),$acc0 #$t2
  140. mov 0($sbox,$acc1,8),$acc1 #$t3
  141. and \$0x0000ff00,$acc0
  142. and \$0x0000ff00,$acc1
  143. shr \$16,$s1
  144. xor $acc0,$t2
  145. xor $acc1,$t3
  146. shr \$16,$s0
  147. movzb `&lo("$s2")`,$acc0
  148. movzb `&lo("$s3")`,$acc1
  149. movzb `&lo("$s0")`,$acc2
  150. mov 0($sbox,$acc0,8),$acc0 #$t0
  151. mov 0($sbox,$acc1,8),$acc1 #$t1
  152. mov 0($sbox,$acc2,8),$acc2 #$t2
  153. and \$0x00ff0000,$acc0
  154. and \$0x00ff0000,$acc1
  155. and \$0x00ff0000,$acc2
  156. xor $acc0,$t0
  157. xor $acc1,$t1
  158. xor $acc2,$t2
  159. movzb `&lo("$s1")`,$acc0
  160. movzb `&hi("$s3")`,$acc1
  161. movzb `&hi("$s0")`,$acc2
  162. mov 0($sbox,$acc0,8),$acc0 #$t3
  163. mov 2($sbox,$acc1,8),$acc1 #$t0
  164. mov 2($sbox,$acc2,8),$acc2 #$t1
  165. and \$0x00ff0000,$acc0
  166. and \$0xff000000,$acc1
  167. and \$0xff000000,$acc2
  168. xor $acc0,$t3
  169. xor $acc1,$t0
  170. xor $acc2,$t1
  171. movzb `&hi("$s1")`,$acc0
  172. movzb `&hi("$s2")`,$acc1
  173. mov 16+12($key),$s3
  174. mov 2($sbox,$acc0,8),$acc0 #$t2
  175. mov 2($sbox,$acc1,8),$acc1 #$t3
  176. mov 16+0($key),$s0
  177. and \$0xff000000,$acc0
  178. and \$0xff000000,$acc1
  179. xor $acc0,$t2
  180. xor $acc1,$t3
  181. mov 16+4($key),$s1
  182. mov 16+8($key),$s2
  183. xor $t0,$s0
  184. xor $t1,$s1
  185. xor $t2,$s2
  186. xor $t3,$s3
  187. ___
  188. }
  189. sub encstep()
  190. { my ($i,@s) = @_;
  191. my $tmp0=$acc0;
  192. my $tmp1=$acc1;
  193. my $tmp2=$acc2;
  194. my $out=($t0,$t1,$t2,$s[0])[$i];
  195. if ($i==3) {
  196. $tmp0=$s[1];
  197. $tmp1=$s[2];
  198. $tmp2=$s[3];
  199. }
  200. $code.=" movzb ".&lo($s[0]).",$out\n";
  201. $code.=" mov $s[2],$tmp1\n" if ($i!=3);
  202. $code.=" lea 16($key),$key\n" if ($i==0);
  203. $code.=" movzb ".&hi($s[1]).",$tmp0\n";
  204. $code.=" mov 0($sbox,$out,8),$out\n";
  205. $code.=" shr \$16,$tmp1\n";
  206. $code.=" mov $s[3],$tmp2\n" if ($i!=3);
  207. $code.=" xor 3($sbox,$tmp0,8),$out\n";
  208. $code.=" movzb ".&lo($tmp1).",$tmp1\n";
  209. $code.=" shr \$24,$tmp2\n";
  210. $code.=" xor 4*$i($key),$out\n";
  211. $code.=" xor 2($sbox,$tmp1,8),$out\n";
  212. $code.=" xor 1($sbox,$tmp2,8),$out\n";
  213. $code.=" mov $t0,$s[1]\n" if ($i==3);
  214. $code.=" mov $t1,$s[2]\n" if ($i==3);
  215. $code.=" mov $t2,$s[3]\n" if ($i==3);
  216. $code.="\n";
  217. }
  218. sub enclast()
  219. { my ($i,@s)=@_;
  220. my $tmp0=$acc0;
  221. my $tmp1=$acc1;
  222. my $tmp2=$acc2;
  223. my $out=($t0,$t1,$t2,$s[0])[$i];
  224. if ($i==3) {
  225. $tmp0=$s[1];
  226. $tmp1=$s[2];
  227. $tmp2=$s[3];
  228. }
  229. $code.=" movzb ".&lo($s[0]).",$out\n";
  230. $code.=" mov $s[2],$tmp1\n" if ($i!=3);
  231. $code.=" mov 2($sbox,$out,8),$out\n";
  232. $code.=" shr \$16,$tmp1\n";
  233. $code.=" mov $s[3],$tmp2\n" if ($i!=3);
  234. $code.=" and \$0x000000ff,$out\n";
  235. $code.=" movzb ".&hi($s[1]).",$tmp0\n";
  236. $code.=" movzb ".&lo($tmp1).",$tmp1\n";
  237. $code.=" shr \$24,$tmp2\n";
  238. $code.=" mov 0($sbox,$tmp0,8),$tmp0\n";
  239. $code.=" mov 0($sbox,$tmp1,8),$tmp1\n";
  240. $code.=" mov 2($sbox,$tmp2,8),$tmp2\n";
  241. $code.=" and \$0x0000ff00,$tmp0\n";
  242. $code.=" and \$0x00ff0000,$tmp1\n";
  243. $code.=" and \$0xff000000,$tmp2\n";
  244. $code.=" xor $tmp0,$out\n";
  245. $code.=" mov $t0,$s[1]\n" if ($i==3);
  246. $code.=" xor $tmp1,$out\n";
  247. $code.=" mov $t1,$s[2]\n" if ($i==3);
  248. $code.=" xor $tmp2,$out\n";
  249. $code.=" mov $t2,$s[3]\n" if ($i==3);
  250. $code.="\n";
  251. }
  252. $code.=<<___;
  253. .type _x86_64_AES_encrypt,\@abi-omnipotent
  254. .align 16
  255. _x86_64_AES_encrypt:
  256. xor 0($key),$s0 # xor with key
  257. xor 4($key),$s1
  258. xor 8($key),$s2
  259. xor 12($key),$s3
  260. mov 240($key),$rnds # load key->rounds
  261. sub \$1,$rnds
  262. jmp .Lenc_loop
  263. .align 16
  264. .Lenc_loop:
  265. ___
  266. if ($verticalspin) { &encvert(); }
  267. else { &encstep(0,$s0,$s1,$s2,$s3);
  268. &encstep(1,$s1,$s2,$s3,$s0);
  269. &encstep(2,$s2,$s3,$s0,$s1);
  270. &encstep(3,$s3,$s0,$s1,$s2);
  271. }
  272. $code.=<<___;
  273. sub \$1,$rnds
  274. jnz .Lenc_loop
  275. ___
  276. if ($verticalspin) { &enclastvert(); }
  277. else { &enclast(0,$s0,$s1,$s2,$s3);
  278. &enclast(1,$s1,$s2,$s3,$s0);
  279. &enclast(2,$s2,$s3,$s0,$s1);
  280. &enclast(3,$s3,$s0,$s1,$s2);
  281. $code.=<<___;
  282. xor 16+0($key),$s0 # xor with key
  283. xor 16+4($key),$s1
  284. xor 16+8($key),$s2
  285. xor 16+12($key),$s3
  286. ___
  287. }
  288. $code.=<<___;
  289. .byte 0xf3,0xc3 # rep ret
  290. .size _x86_64_AES_encrypt,.-_x86_64_AES_encrypt
  291. ___
  292. # void AES_encrypt (const void *inp,void *out,const AES_KEY *key);
  293. $code.=<<___;
  294. .globl AES_encrypt
  295. .type AES_encrypt,\@function,3
  296. .align 16
  297. AES_encrypt:
  298. push %rbx
  299. push %rbp
  300. push %r12
  301. push %r13
  302. push %r14
  303. push %r15
  304. mov %rdx,$key
  305. mov %rdi,$inp
  306. mov %rsi,$out
  307. .picmeup $sbox
  308. lea AES_Te-.($sbox),$sbox
  309. mov 0($inp),$s0
  310. mov 4($inp),$s1
  311. mov 8($inp),$s2
  312. mov 12($inp),$s3
  313. call _x86_64_AES_encrypt
  314. mov $s0,0($out)
  315. mov $s1,4($out)
  316. mov $s2,8($out)
  317. mov $s3,12($out)
  318. pop %r15
  319. pop %r14
  320. pop %r13
  321. pop %r12
  322. pop %rbp
  323. pop %rbx
  324. ret
  325. .size AES_encrypt,.-AES_encrypt
  326. ___
  327. #------------------------------------------------------------------#
  328. sub decvert()
  329. { my $t3="%r8d"; # zaps $inp!
  330. $code.=<<___;
  331. # favor 3-way issue Opteron pipeline...
  332. movzb `&lo("$s0")`,$acc0
  333. movzb `&lo("$s1")`,$acc1
  334. movzb `&lo("$s2")`,$acc2
  335. mov 0($sbox,$acc0,8),$t0
  336. mov 0($sbox,$acc1,8),$t1
  337. mov 0($sbox,$acc2,8),$t2
  338. movzb `&hi("$s3")`,$acc0
  339. movzb `&hi("$s0")`,$acc1
  340. movzb `&lo("$s3")`,$acc2
  341. xor 3($sbox,$acc0,8),$t0
  342. xor 3($sbox,$acc1,8),$t1
  343. mov 0($sbox,$acc2,8),$t3
  344. movzb `&hi("$s1")`,$acc0
  345. shr \$16,$s0
  346. movzb `&hi("$s2")`,$acc2
  347. xor 3($sbox,$acc0,8),$t2
  348. shr \$16,$s3
  349. xor 3($sbox,$acc2,8),$t3
  350. shr \$16,$s1
  351. lea 16($key),$key
  352. shr \$16,$s2
  353. movzb `&lo("$s2")`,$acc0
  354. movzb `&lo("$s3")`,$acc1
  355. movzb `&lo("$s0")`,$acc2
  356. xor 2($sbox,$acc0,8),$t0
  357. xor 2($sbox,$acc1,8),$t1
  358. xor 2($sbox,$acc2,8),$t2
  359. movzb `&hi("$s1")`,$acc0
  360. movzb `&hi("$s2")`,$acc1
  361. movzb `&lo("$s1")`,$acc2
  362. xor 1($sbox,$acc0,8),$t0
  363. xor 1($sbox,$acc1,8),$t1
  364. xor 2($sbox,$acc2,8),$t3
  365. movzb `&hi("$s3")`,$acc0
  366. mov 12($key),$s3
  367. movzb `&hi("$s0")`,$acc2
  368. xor 1($sbox,$acc0,8),$t2
  369. mov 0($key),$s0
  370. xor 1($sbox,$acc2,8),$t3
  371. xor $t0,$s0
  372. mov 4($key),$s1
  373. mov 8($key),$s2
  374. xor $t2,$s2
  375. xor $t1,$s1
  376. xor $t3,$s3
  377. ___
  378. }
  379. sub declastvert()
  380. { my $t3="%r8d"; # zaps $inp!
  381. $code.=<<___;
  382. movzb `&lo("$s0")`,$acc0
  383. movzb `&lo("$s1")`,$acc1
  384. movzb `&lo("$s2")`,$acc2
  385. mov 2048($sbox,$acc0,4),$t0
  386. mov 2048($sbox,$acc1,4),$t1
  387. mov 2048($sbox,$acc2,4),$t2
  388. and \$0x000000ff,$t0
  389. and \$0x000000ff,$t1
  390. and \$0x000000ff,$t2
  391. movzb `&lo("$s3")`,$acc0
  392. movzb `&hi("$s3")`,$acc1
  393. movzb `&hi("$s0")`,$acc2
  394. mov 2048($sbox,$acc0,4),$t3
  395. mov 2048($sbox,$acc1,4),$acc1 #$t0
  396. mov 2048($sbox,$acc2,4),$acc2 #$t1
  397. and \$0x000000ff,$t3
  398. and \$0x0000ff00,$acc1
  399. and \$0x0000ff00,$acc2
  400. xor $acc1,$t0
  401. xor $acc2,$t1
  402. shr \$16,$s3
  403. movzb `&hi("$s1")`,$acc0
  404. movzb `&hi("$s2")`,$acc1
  405. shr \$16,$s0
  406. mov 2048($sbox,$acc0,4),$acc0 #$t2
  407. mov 2048($sbox,$acc1,4),$acc1 #$t3
  408. and \$0x0000ff00,$acc0
  409. and \$0x0000ff00,$acc1
  410. shr \$16,$s1
  411. xor $acc0,$t2
  412. xor $acc1,$t3
  413. shr \$16,$s2
  414. movzb `&lo("$s2")`,$acc0
  415. movzb `&lo("$s3")`,$acc1
  416. movzb `&lo("$s0")`,$acc2
  417. mov 2048($sbox,$acc0,4),$acc0 #$t0
  418. mov 2048($sbox,$acc1,4),$acc1 #$t1
  419. mov 2048($sbox,$acc2,4),$acc2 #$t2
  420. and \$0x00ff0000,$acc0
  421. and \$0x00ff0000,$acc1
  422. and \$0x00ff0000,$acc2
  423. xor $acc0,$t0
  424. xor $acc1,$t1
  425. xor $acc2,$t2
  426. movzb `&lo("$s1")`,$acc0
  427. movzb `&hi("$s1")`,$acc1
  428. movzb `&hi("$s2")`,$acc2
  429. mov 2048($sbox,$acc0,4),$acc0 #$t3
  430. mov 2048($sbox,$acc1,4),$acc1 #$t0
  431. mov 2048($sbox,$acc2,4),$acc2 #$t1
  432. and \$0x00ff0000,$acc0
  433. and \$0xff000000,$acc1
  434. and \$0xff000000,$acc2
  435. xor $acc0,$t3
  436. xor $acc1,$t0
  437. xor $acc2,$t1
  438. movzb `&hi("$s3")`,$acc0
  439. movzb `&hi("$s0")`,$acc1
  440. mov 16+12($key),$s3
  441. mov 2048($sbox,$acc0,4),$acc0 #$t2
  442. mov 2048($sbox,$acc1,4),$acc1 #$t3
  443. mov 16+0($key),$s0
  444. and \$0xff000000,$acc0
  445. and \$0xff000000,$acc1
  446. xor $acc0,$t2
  447. xor $acc1,$t3
  448. mov 16+4($key),$s1
  449. mov 16+8($key),$s2
  450. xor $t0,$s0
  451. xor $t1,$s1
  452. xor $t2,$s2
  453. xor $t3,$s3
  454. ___
  455. }
  456. sub decstep()
  457. { my ($i,@s) = @_;
  458. my $tmp0=$acc0;
  459. my $tmp1=$acc1;
  460. my $tmp2=$acc2;
  461. my $out=($t0,$t1,$t2,$s[0])[$i];
  462. $code.=" mov $s[0],$out\n" if ($i!=3);
  463. $tmp1=$s[2] if ($i==3);
  464. $code.=" mov $s[2],$tmp1\n" if ($i!=3);
  465. $code.=" and \$0xFF,$out\n";
  466. $code.=" mov 0($sbox,$out,8),$out\n";
  467. $code.=" shr \$16,$tmp1\n";
  468. $tmp2=$s[3] if ($i==3);
  469. $code.=" mov $s[3],$tmp2\n" if ($i!=3);
  470. $tmp0=$s[1] if ($i==3);
  471. $code.=" movzb ".&hi($s[1]).",$tmp0\n";
  472. $code.=" and \$0xFF,$tmp1\n";
  473. $code.=" shr \$24,$tmp2\n";
  474. $code.=" xor 3($sbox,$tmp0,8),$out\n";
  475. $code.=" xor 2($sbox,$tmp1,8),$out\n";
  476. $code.=" xor 1($sbox,$tmp2,8),$out\n";
  477. $code.=" mov $t2,$s[1]\n" if ($i==3);
  478. $code.=" mov $t1,$s[2]\n" if ($i==3);
  479. $code.=" mov $t0,$s[3]\n" if ($i==3);
  480. $code.="\n";
  481. }
  482. sub declast()
  483. { my ($i,@s)=@_;
  484. my $tmp0=$acc0;
  485. my $tmp1=$acc1;
  486. my $tmp2=$acc2;
  487. my $out=($t0,$t1,$t2,$s[0])[$i];
  488. $code.=" mov $s[0],$out\n" if ($i!=3);
  489. $tmp1=$s[2] if ($i==3);
  490. $code.=" mov $s[2],$tmp1\n" if ($i!=3);
  491. $code.=" and \$0xFF,$out\n";
  492. $code.=" mov 2048($sbox,$out,4),$out\n";
  493. $code.=" shr \$16,$tmp1\n";
  494. $tmp2=$s[3] if ($i==3);
  495. $code.=" mov $s[3],$tmp2\n" if ($i!=3);
  496. $code.=" and \$0x000000ff,$out\n";
  497. $tmp0=$s[1] if ($i==3);
  498. $code.=" movzb ".&hi($s[1]).",$tmp0\n";
  499. $code.=" and \$0xFF,$tmp1\n";
  500. $code.=" shr \$24,$tmp2\n";
  501. $code.=" mov 2048($sbox,$tmp0,4),$tmp0\n";
  502. $code.=" mov 2048($sbox,$tmp1,4),$tmp1\n";
  503. $code.=" mov 2048($sbox,$tmp2,4),$tmp2\n";
  504. $code.=" and \$0x0000ff00,$tmp0\n";
  505. $code.=" and \$0x00ff0000,$tmp1\n";
  506. $code.=" and \$0xff000000,$tmp2\n";
  507. $code.=" xor $tmp0,$out\n";
  508. $code.=" mov $t2,$s[1]\n" if ($i==3);
  509. $code.=" xor $tmp1,$out\n";
  510. $code.=" mov $t1,$s[2]\n" if ($i==3);
  511. $code.=" xor $tmp2,$out\n";
  512. $code.=" mov $t0,$s[3]\n" if ($i==3);
  513. $code.="\n";
  514. }
  515. $code.=<<___;
  516. .type _x86_64_AES_decrypt,\@abi-omnipotent
  517. .align 16
  518. _x86_64_AES_decrypt:
  519. xor 0($key),$s0 # xor with key
  520. xor 4($key),$s1
  521. xor 8($key),$s2
  522. xor 12($key),$s3
  523. mov 240($key),$rnds # load key->rounds
  524. sub \$1,$rnds
  525. jmp .Ldec_loop
  526. .align 16
  527. .Ldec_loop:
  528. ___
  529. if ($verticalspin) { &decvert(); }
  530. else { &decstep(0,$s0,$s3,$s2,$s1);
  531. &decstep(1,$s1,$s0,$s3,$s2);
  532. &decstep(2,$s2,$s1,$s0,$s3);
  533. &decstep(3,$s3,$s2,$s1,$s0);
  534. $code.=<<___;
  535. lea 16($key),$key
  536. xor 0($key),$s0 # xor with key
  537. xor 4($key),$s1
  538. xor 8($key),$s2
  539. xor 12($key),$s3
  540. ___
  541. }
  542. $code.=<<___;
  543. sub \$1,$rnds
  544. jnz .Ldec_loop
  545. ___
  546. if ($verticalspin) { &declastvert(); }
  547. else { &declast(0,$s0,$s3,$s2,$s1);
  548. &declast(1,$s1,$s0,$s3,$s2);
  549. &declast(2,$s2,$s1,$s0,$s3);
  550. &declast(3,$s3,$s2,$s1,$s0);
  551. $code.=<<___;
  552. xor 16+0($key),$s0 # xor with key
  553. xor 4($key),$s1
  554. xor 8($key),$s2
  555. xor 12($key),$s3
  556. ___
  557. }
  558. $code.=<<___;
  559. .byte 0xf3,0xc3 # rep ret
  560. .size _x86_64_AES_decrypt,.-_x86_64_AES_decrypt
  561. ___
  562. # void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
  563. $code.=<<___;
  564. .globl AES_decrypt
  565. .type AES_decrypt,\@function,3
  566. .align 16
  567. AES_decrypt:
  568. push %rbx
  569. push %rbp
  570. push %r12
  571. push %r13
  572. push %r14
  573. push %r15
  574. mov %rdx,$key
  575. mov %rdi,$inp
  576. mov %rsi,$out
  577. .picmeup $sbox
  578. lea AES_Td-.($sbox),$sbox
  579. mov 0($inp),$s0
  580. mov 4($inp),$s1
  581. mov 8($inp),$s2
  582. mov 12($inp),$s3
  583. call _x86_64_AES_decrypt
  584. mov $s0,0($out)
  585. mov $s1,4($out)
  586. mov $s2,8($out)
  587. mov $s3,12($out)
  588. pop %r15
  589. pop %r14
  590. pop %r13
  591. pop %r12
  592. pop %rbp
  593. pop %rbx
  594. ret
  595. .size AES_decrypt,.-AES_decrypt
  596. ___
  597. #------------------------------------------------------------------#
  598. sub enckey()
  599. {
  600. $code.=<<___;
  601. movz %dl,%esi # rk[i]>>0
  602. mov 2(%rbp,%rsi,8),%ebx
  603. movz %dh,%esi # rk[i]>>8
  604. and \$0xFF000000,%ebx
  605. xor %ebx,%eax
  606. mov 2(%rbp,%rsi,8),%ebx
  607. shr \$16,%edx
  608. and \$0x000000FF,%ebx
  609. movz %dl,%esi # rk[i]>>16
  610. xor %ebx,%eax
  611. mov 0(%rbp,%rsi,8),%ebx
  612. movz %dh,%esi # rk[i]>>24
  613. and \$0x0000FF00,%ebx
  614. xor %ebx,%eax
  615. mov 0(%rbp,%rsi,8),%ebx
  616. and \$0x00FF0000,%ebx
  617. xor %ebx,%eax
  618. xor 2048(%rbp,%rcx,4),%eax # rcon
  619. ___
  620. }
  621. # int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
  622. # AES_KEY *key)
  623. $code.=<<___;
  624. .globl AES_set_encrypt_key
  625. .type AES_set_encrypt_key,\@function,3
  626. .align 16
  627. AES_set_encrypt_key:
  628. push %rbx
  629. push %rbp
  630. mov %esi,%ecx # %ecx=bits
  631. mov %rdi,%rsi # %rsi=userKey
  632. mov %rdx,%rdi # %rdi=key
  633. test \$-1,%rsi
  634. jz .Lbadpointer
  635. test \$-1,%rdi
  636. jz .Lbadpointer
  637. .picmeup %rbp
  638. lea AES_Te-.(%rbp),%rbp
  639. cmp \$128,%ecx
  640. je .L10rounds
  641. cmp \$192,%ecx
  642. je .L12rounds
  643. cmp \$256,%ecx
  644. je .L14rounds
  645. mov \$-2,%rax # invalid number of bits
  646. jmp .Lexit
  647. .L10rounds:
  648. mov 0(%rsi),%eax # copy first 4 dwords
  649. mov 4(%rsi),%ebx
  650. mov 8(%rsi),%ecx
  651. mov 12(%rsi),%edx
  652. mov %eax,0(%rdi)
  653. mov %ebx,4(%rdi)
  654. mov %ecx,8(%rdi)
  655. mov %edx,12(%rdi)
  656. xor %ecx,%ecx
  657. jmp .L10shortcut
  658. .align 4
  659. .L10loop:
  660. mov 0(%rdi),%eax # rk[0]
  661. mov 12(%rdi),%edx # rk[3]
  662. .L10shortcut:
  663. ___
  664. &enckey ();
  665. $code.=<<___;
  666. mov %eax,16(%rdi) # rk[4]
  667. xor 4(%rdi),%eax
  668. mov %eax,20(%rdi) # rk[5]
  669. xor 8(%rdi),%eax
  670. mov %eax,24(%rdi) # rk[6]
  671. xor 12(%rdi),%eax
  672. mov %eax,28(%rdi) # rk[7]
  673. add \$1,%ecx
  674. lea 16(%rdi),%rdi
  675. cmp \$10,%ecx
  676. jl .L10loop
  677. movl \$10,80(%rdi) # setup number of rounds
  678. xor %rax,%rax
  679. jmp .Lexit
  680. .L12rounds:
  681. mov 0(%rsi),%eax # copy first 6 dwords
  682. mov 4(%rsi),%ebx
  683. mov 8(%rsi),%ecx
  684. mov 12(%rsi),%edx
  685. mov %eax,0(%rdi)
  686. mov %ebx,4(%rdi)
  687. mov %ecx,8(%rdi)
  688. mov %edx,12(%rdi)
  689. mov 16(%rsi),%ecx
  690. mov 20(%rsi),%edx
  691. mov %ecx,16(%rdi)
  692. mov %edx,20(%rdi)
  693. xor %ecx,%ecx
  694. jmp .L12shortcut
  695. .align 4
  696. .L12loop:
  697. mov 0(%rdi),%eax # rk[0]
  698. mov 20(%rdi),%edx # rk[5]
  699. .L12shortcut:
  700. ___
  701. &enckey ();
  702. $code.=<<___;
  703. mov %eax,24(%rdi) # rk[6]
  704. xor 4(%rdi),%eax
  705. mov %eax,28(%rdi) # rk[7]
  706. xor 8(%rdi),%eax
  707. mov %eax,32(%rdi) # rk[8]
  708. xor 12(%rdi),%eax
  709. mov %eax,36(%rdi) # rk[9]
  710. cmp \$7,%ecx
  711. je .L12break
  712. add \$1,%ecx
  713. xor 16(%rdi),%eax
  714. mov %eax,40(%rdi) # rk[10]
  715. xor 20(%rdi),%eax
  716. mov %eax,44(%rdi) # rk[11]
  717. lea 24(%rdi),%rdi
  718. jmp .L12loop
  719. .L12break:
  720. movl \$12,72(%rdi) # setup number of rounds
  721. xor %rax,%rax
  722. jmp .Lexit
  723. .L14rounds:
  724. mov 0(%rsi),%eax # copy first 8 dwords
  725. mov 4(%rsi),%ebx
  726. mov 8(%rsi),%ecx
  727. mov 12(%rsi),%edx
  728. mov %eax,0(%rdi)
  729. mov %ebx,4(%rdi)
  730. mov %ecx,8(%rdi)
  731. mov %edx,12(%rdi)
  732. mov 16(%rsi),%eax
  733. mov 20(%rsi),%ebx
  734. mov 24(%rsi),%ecx
  735. mov 28(%rsi),%edx
  736. mov %eax,16(%rdi)
  737. mov %ebx,20(%rdi)
  738. mov %ecx,24(%rdi)
  739. mov %edx,28(%rdi)
  740. xor %ecx,%ecx
  741. jmp .L14shortcut
  742. .align 4
  743. .L14loop:
  744. mov 28(%rdi),%edx # rk[4]
  745. .L14shortcut:
  746. mov 0(%rdi),%eax # rk[0]
  747. ___
  748. &enckey ();
  749. $code.=<<___;
  750. mov %eax,32(%rdi) # rk[8]
  751. xor 4(%rdi),%eax
  752. mov %eax,36(%rdi) # rk[9]
  753. xor 8(%rdi),%eax
  754. mov %eax,40(%rdi) # rk[10]
  755. xor 12(%rdi),%eax
  756. mov %eax,44(%rdi) # rk[11]
  757. cmp \$6,%ecx
  758. je .L14break
  759. add \$1,%ecx
  760. mov %eax,%edx
  761. mov 16(%rdi),%eax # rk[4]
  762. movz %dl,%esi # rk[11]>>0
  763. mov 2(%rbp,%rsi,8),%ebx
  764. movz %dh,%esi # rk[11]>>8
  765. and \$0x000000FF,%ebx
  766. xor %ebx,%eax
  767. mov 0(%rbp,%rsi,8),%ebx
  768. shr \$16,%edx
  769. and \$0x0000FF00,%ebx
  770. movz %dl,%esi # rk[11]>>16
  771. xor %ebx,%eax
  772. mov 0(%rbp,%rsi,8),%ebx
  773. movz %dh,%esi # rk[11]>>24
  774. and \$0x00FF0000,%ebx
  775. xor %ebx,%eax
  776. mov 2(%rbp,%rsi,8),%ebx
  777. and \$0xFF000000,%ebx
  778. xor %ebx,%eax
  779. mov %eax,48(%rdi) # rk[12]
  780. xor 20(%rdi),%eax
  781. mov %eax,52(%rdi) # rk[13]
  782. xor 24(%rdi),%eax
  783. mov %eax,56(%rdi) # rk[14]
  784. xor 28(%rdi),%eax
  785. mov %eax,60(%rdi) # rk[15]
  786. lea 32(%rdi),%rdi
  787. jmp .L14loop
  788. .L14break:
  789. movl \$14,48(%rdi) # setup number of rounds
  790. xor %rax,%rax
  791. jmp .Lexit
  792. .Lbadpointer:
  793. mov \$-1,%rax
  794. .Lexit:
  795. pop %rbp
  796. pop %rbx
  797. ret
  798. .size AES_set_encrypt_key,.-AES_set_encrypt_key
  799. ___
  800. sub deckey()
  801. { my ($i,$ptr,$te,$td) = @_;
  802. $code.=<<___;
  803. mov $i($ptr),%eax
  804. mov %eax,%edx
  805. movz %ah,%ebx
  806. shr \$16,%edx
  807. and \$0xFF,%eax
  808. movzb 2($te,%rax,8),%rax
  809. movzb 2($te,%rbx,8),%rbx
  810. mov 0($td,%rax,8),%eax
  811. xor 3($td,%rbx,8),%eax
  812. movzb %dh,%ebx
  813. and \$0xFF,%edx
  814. movzb 2($te,%rdx,8),%rdx
  815. movzb 2($te,%rbx,8),%rbx
  816. xor 2($td,%rdx,8),%eax
  817. xor 1($td,%rbx,8),%eax
  818. mov %eax,$i($ptr)
  819. ___
  820. }
  821. # int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
  822. # AES_KEY *key)
  823. $code.=<<___;
  824. .globl AES_set_decrypt_key
  825. .type AES_set_decrypt_key,\@function,3
  826. .align 16
  827. AES_set_decrypt_key:
  828. push %rdx
  829. call AES_set_encrypt_key
  830. cmp \$0,%eax
  831. je .Lproceed
  832. lea 24(%rsp),%rsp
  833. ret
  834. .Lproceed:
  835. mov (%rsp),%r8 # restore key schedule
  836. mov %rbx,(%rsp)
  837. mov 240(%r8),%ecx # pull number of rounds
  838. xor %rdi,%rdi
  839. lea (%rdi,%rcx,4),%rcx
  840. mov %r8,%rsi
  841. lea (%r8,%rcx,4),%rdi # pointer to last chunk
  842. .align 4
  843. .Linvert:
  844. mov 0(%rsi),%rax
  845. mov 8(%rsi),%rbx
  846. mov 0(%rdi),%rcx
  847. mov 8(%rdi),%rdx
  848. mov %rax,0(%rdi)
  849. mov %rbx,8(%rdi)
  850. mov %rcx,0(%rsi)
  851. mov %rdx,8(%rsi)
  852. lea 16(%rsi),%rsi
  853. lea -16(%rdi),%rdi
  854. cmp %rsi,%rdi
  855. jne .Linvert
  856. .picmeup %r9
  857. lea AES_Td-.(%r9),%rdi
  858. lea AES_Te-AES_Td(%rdi),%r9
  859. mov %r8,%rsi
  860. mov 240(%r8),%ecx # pull number of rounds
  861. sub \$1,%ecx
  862. .align 4
  863. .Lpermute:
  864. lea 16(%rsi),%rsi
  865. ___
  866. &deckey (0,"%rsi","%r9","%rdi");
  867. &deckey (4,"%rsi","%r9","%rdi");
  868. &deckey (8,"%rsi","%r9","%rdi");
  869. &deckey (12,"%rsi","%r9","%rdi");
  870. $code.=<<___;
  871. sub \$1,%ecx
  872. jnz .Lpermute
  873. xor %rax,%rax
  874. pop %rbx
  875. ret
  876. .size AES_set_decrypt_key,.-AES_set_decrypt_key
  877. ___
  878. # void AES_cbc_encrypt (const void char *inp, unsigned char *out,
  879. # size_t length, const AES_KEY *key,
  880. # unsigned char *ivp,const int enc);
  881. {
  882. # stack frame layout
  883. # -8(%rsp) return address
  884. my $_rsp="0(%rsp)"; # saved %rsp
  885. my $_len="8(%rsp)"; # copy of 3rd parameter, length
  886. my $_key="16(%rsp)"; # copy of 4th parameter, key
  887. my $_ivp="24(%rsp)"; # copy of 5th parameter, ivp
  888. my $keyp="32(%rsp)"; # one to pass as $key
  889. my $ivec="40(%rsp)"; # ivec[16]
  890. my $aes_key="56(%rsp)"; # copy of aes_key
  891. my $mark="56+240(%rsp)"; # copy of aes_key->rounds
  892. $code.=<<___;
  893. .globl AES_cbc_encrypt
  894. .type AES_cbc_encrypt,\@function,6
  895. .align 16
  896. AES_cbc_encrypt:
  897. cmp \$0,%rdx # check length
  898. je .Lcbc_just_ret
  899. push %rbx
  900. push %rbp
  901. push %r12
  902. push %r13
  903. push %r14
  904. push %r15
  905. pushfq
  906. cld
  907. .picmeup $sbox
  908. .Lcbc_pic_point:
  909. cmp \$0,%r9
  910. je .LDECRYPT
  911. lea AES_Te-.Lcbc_pic_point($sbox),$sbox
  912. # allocate aligned stack frame...
  913. lea -64-248(%rsp),$key
  914. and \$-64,$key
  915. # ... and make it doesn't alias with AES_Te modulo 4096
  916. mov $sbox,%r10
  917. lea 2048($sbox),%r11
  918. mov $key,%r12
  919. and \$0xFFF,%r10 # s = $sbox&0xfff
  920. and \$0xFFF,%r11 # e = ($sbox+2048)&0xfff
  921. and \$0xFFF,%r12 # p = %rsp&0xfff
  922. cmp %r11,%r12 # if (p=>e) %rsp =- (p-e);
  923. jb .Lcbc_te_break_out
  924. sub %r11,%r12
  925. sub %r12,$key
  926. jmp .Lcbc_te_ok
  927. .Lcbc_te_break_out: # else %rsp -= (p-s)&0xfff + framesz
  928. sub %r10,%r12
  929. and \$0xFFF,%r12
  930. add \$320,%r12
  931. sub %r12,$key
  932. .align 4
  933. .Lcbc_te_ok:
  934. xchg %rsp,$key
  935. add \$8,%rsp # reserve for return address!
  936. mov $key,$_rsp # save %rsp
  937. mov %rdx,$_len # save copy of len
  938. mov %rcx,$_key # save copy of key
  939. mov %r8,$_ivp # save copy of ivp
  940. movl \$0,$mark # copy of aes_key->rounds = 0;
  941. mov %r8,%rbp # rearrange input arguments
  942. mov %rsi,$out
  943. mov %rdi,$inp
  944. mov %rcx,$key
  945. # do we copy key schedule to stack?
  946. mov $key,%r10
  947. sub $sbox,%r10
  948. and \$0xfff,%r10
  949. cmp \$2048,%r10
  950. jb .Lcbc_do_ecopy
  951. cmp \$4096-248,%r10
  952. jb .Lcbc_skip_ecopy
  953. .align 4
  954. .Lcbc_do_ecopy:
  955. mov $key,%rsi
  956. lea $aes_key,%rdi
  957. lea $aes_key,$key
  958. mov \$240/8,%ecx
  959. .long 0x90A548F3 # rep movsq
  960. mov (%rsi),%eax # copy aes_key->rounds
  961. mov %eax,(%rdi)
  962. .Lcbc_skip_ecopy:
  963. mov $key,$keyp # save key pointer
  964. mov \$16,%ecx
  965. .align 4
  966. .Lcbc_prefetch_te:
  967. mov 0($sbox),%r10
  968. mov 32($sbox),%r11
  969. mov 64($sbox),%r12
  970. mov 96($sbox),%r13
  971. lea 128($sbox),$sbox
  972. sub \$1,%ecx
  973. jnz .Lcbc_prefetch_te
  974. sub \$2048,$sbox
  975. test \$-16,%rdx # check upon length
  976. mov %rdx,%r10
  977. mov 0(%rbp),$s0 # load iv
  978. mov 4(%rbp),$s1
  979. mov 8(%rbp),$s2
  980. mov 12(%rbp),$s3
  981. jz .Lcbc_enc_tail # short input...
  982. .align 4
  983. .Lcbc_enc_loop:
  984. xor 0($inp),$s0
  985. xor 4($inp),$s1
  986. xor 8($inp),$s2
  987. xor 12($inp),$s3
  988. mov $inp,$ivec # if ($verticalspin) save inp
  989. mov $keyp,$key # restore key
  990. call _x86_64_AES_encrypt
  991. mov $ivec,$inp # if ($verticalspin) restore inp
  992. mov $s0,0($out)
  993. mov $s1,4($out)
  994. mov $s2,8($out)
  995. mov $s3,12($out)
  996. mov $_len,%r10
  997. lea 16($inp),$inp
  998. lea 16($out),$out
  999. sub \$16,%r10
  1000. test \$-16,%r10
  1001. mov %r10,$_len
  1002. jnz .Lcbc_enc_loop
  1003. test \$15,%r10
  1004. jnz .Lcbc_enc_tail
  1005. mov $_ivp,%rbp # restore ivp
  1006. mov $s0,0(%rbp) # save ivec
  1007. mov $s1,4(%rbp)
  1008. mov $s2,8(%rbp)
  1009. mov $s3,12(%rbp)
  1010. .align 4
  1011. .Lcbc_cleanup:
  1012. cmpl \$0,$mark # was the key schedule copied?
  1013. lea $aes_key,%rdi
  1014. mov $_rsp,%rsp
  1015. je .Lcbc_exit
  1016. mov \$240/8,%ecx
  1017. xor %rax,%rax
  1018. .long 0x90AB48F3 # rep stosq
  1019. .Lcbc_exit:
  1020. popfq
  1021. pop %r15
  1022. pop %r14
  1023. pop %r13
  1024. pop %r12
  1025. pop %rbp
  1026. pop %rbx
  1027. .Lcbc_just_ret:
  1028. ret
  1029. .align 4
  1030. .Lcbc_enc_tail:
  1031. cmp $inp,$out
  1032. je .Lcbc_enc_in_place
  1033. mov %r10,%rcx
  1034. mov $inp,%rsi
  1035. mov $out,%rdi
  1036. .long 0xF689A4F3 # rep movsb
  1037. .Lcbc_enc_in_place:
  1038. mov \$16,%rcx # zero tail
  1039. sub %r10,%rcx
  1040. xor %rax,%rax
  1041. .long 0xF689AAF3 # rep stosb
  1042. mov $out,$inp # this is not a mistake!
  1043. movq \$16,$_len # len=16
  1044. jmp .Lcbc_enc_loop # one more spin...
  1045. #----------------------------- DECRYPT -----------------------------#
  1046. .align 16
  1047. .LDECRYPT:
  1048. lea AES_Td-.Lcbc_pic_point($sbox),$sbox
  1049. # allocate aligned stack frame...
  1050. lea -64-248(%rsp),$key
  1051. and \$-64,$key
  1052. # ... and make it doesn't alias with AES_Td modulo 4096
  1053. mov $sbox,%r10
  1054. lea 3072($sbox),%r11
  1055. mov $key,%r12
  1056. and \$0xFFF,%r10 # s = $sbox&0xfff
  1057. and \$0xFFF,%r11 # e = ($sbox+2048)&0xfff
  1058. and \$0xFFF,%r12 # p = %rsp&0xfff
  1059. cmp %r11,%r12 # if (p=>e) %rsp =- (p-e);
  1060. jb .Lcbc_td_break_out
  1061. sub %r11,%r12
  1062. sub %r12,$key
  1063. jmp .Lcbc_td_ok
  1064. .Lcbc_td_break_out: # else %rsp -= (p-s)&0xfff + framesz
  1065. sub %r10,%r12
  1066. and \$0xFFF,%r12
  1067. add \$320,%r12
  1068. sub %r12,$key
  1069. .align 4
  1070. .Lcbc_td_ok:
  1071. xchg %rsp,$key
  1072. add \$8,%rsp # reserve for return address!
  1073. mov $key,$_rsp # save %rsp
  1074. mov %rdx,$_len # save copy of len
  1075. mov %rcx,$_key # save copy of key
  1076. mov %r8,$_ivp # save copy of ivp
  1077. movl \$0,$mark # copy of aes_key->rounds = 0;
  1078. mov %r8,%rbp # rearrange input arguments
  1079. mov %rsi,$out
  1080. mov %rdi,$inp
  1081. mov %rcx,$key
  1082. # do we copy key schedule to stack?
  1083. mov $key,%r10
  1084. sub $sbox,%r10
  1085. and \$0xfff,%r10
  1086. cmp \$3072,%r10
  1087. jb .Lcbc_do_dcopy
  1088. cmp \$4096-248,%r10
  1089. jb .Lcbc_skip_dcopy
  1090. .align 4
  1091. .Lcbc_do_dcopy:
  1092. mov $key,%rsi
  1093. lea $aes_key,%rdi
  1094. lea $aes_key,$key
  1095. mov \$240/8,%ecx
  1096. .long 0x90A548F3 # rep movsq
  1097. mov (%rsi),%eax # copy aes_key->rounds
  1098. mov %eax,(%rdi)
  1099. .Lcbc_skip_dcopy:
  1100. mov $key,$keyp # save key pointer
  1101. mov \$24,%ecx
  1102. .align 4
  1103. .Lcbc_prefetch_td:
  1104. mov 0($sbox),%r10
  1105. mov 32($sbox),%r11
  1106. mov 64($sbox),%r12
  1107. mov 96($sbox),%r13
  1108. lea 128($sbox),$sbox
  1109. sub \$1,%ecx
  1110. jnz .Lcbc_prefetch_td
  1111. sub \$3072,$sbox
  1112. cmp $inp,$out
  1113. je .Lcbc_dec_in_place
  1114. mov %rbp,$ivec
  1115. .align 4
  1116. .Lcbc_dec_loop:
  1117. mov 0($inp),$s0 # read input
  1118. mov 4($inp),$s1
  1119. mov 8($inp),$s2
  1120. mov 12($inp),$s3
  1121. mov $inp,8+$ivec # if ($verticalspin) save inp
  1122. mov $keyp,$key # restore key
  1123. call _x86_64_AES_decrypt
  1124. mov $ivec,%rbp # load ivp
  1125. mov 8+$ivec,$inp # if ($verticalspin) restore inp
  1126. xor 0(%rbp),$s0 # xor iv
  1127. xor 4(%rbp),$s1
  1128. xor 8(%rbp),$s2
  1129. xor 12(%rbp),$s3
  1130. mov $inp,%rbp # current input, next iv
  1131. mov $_len,%r10 # load len
  1132. sub \$16,%r10
  1133. jc .Lcbc_dec_partial
  1134. mov %r10,$_len # update len
  1135. mov %rbp,$ivec # update ivp
  1136. mov $s0,0($out) # write output
  1137. mov $s1,4($out)
  1138. mov $s2,8($out)
  1139. mov $s3,12($out)
  1140. lea 16($inp),$inp
  1141. lea 16($out),$out
  1142. jnz .Lcbc_dec_loop
  1143. .Lcbc_dec_end:
  1144. mov $_ivp,%r12 # load user ivp
  1145. mov 0(%rbp),%r10 # load iv
  1146. mov 8(%rbp),%r11
  1147. mov %r10,0(%r12) # copy back to user
  1148. mov %r11,8(%r12)
  1149. jmp .Lcbc_cleanup
  1150. .align 4
  1151. .Lcbc_dec_partial:
  1152. mov $s0,0+$ivec # dump output to stack
  1153. mov $s1,4+$ivec
  1154. mov $s2,8+$ivec
  1155. mov $s3,12+$ivec
  1156. mov $out,%rdi
  1157. lea $ivec,%rsi
  1158. mov \$16,%rcx
  1159. add %r10,%rcx # number of bytes to copy
  1160. .long 0xF689A4F3 # rep movsb
  1161. jmp .Lcbc_dec_end
  1162. .align 16
  1163. .Lcbc_dec_in_place:
  1164. mov 0($inp),$s0 # load input
  1165. mov 4($inp),$s1
  1166. mov 8($inp),$s2
  1167. mov 12($inp),$s3
  1168. mov $inp,$ivec # if ($verticalspin) save inp
  1169. mov $keyp,$key
  1170. call _x86_64_AES_decrypt
  1171. mov $ivec,$inp # if ($verticalspin) restore inp
  1172. mov $_ivp,%rbp
  1173. xor 0(%rbp),$s0
  1174. xor 4(%rbp),$s1
  1175. xor 8(%rbp),$s2
  1176. xor 12(%rbp),$s3
  1177. mov 0($inp),%r10 # copy input to iv
  1178. mov 8($inp),%r11
  1179. mov %r10,0(%rbp)
  1180. mov %r11,8(%rbp)
  1181. mov $s0,0($out) # save output [zaps input]
  1182. mov $s1,4($out)
  1183. mov $s2,8($out)
  1184. mov $s3,12($out)
  1185. mov $_len,%rcx
  1186. lea 16($inp),$inp
  1187. lea 16($out),$out
  1188. sub \$16,%rcx
  1189. jc .Lcbc_dec_in_place_partial
  1190. mov %rcx,$_len
  1191. jnz .Lcbc_dec_in_place
  1192. jmp .Lcbc_cleanup
  1193. .align 4
  1194. .Lcbc_dec_in_place_partial:
  1195. # one can argue if this is actually required
  1196. lea ($out,%rcx),%rdi
  1197. lea (%rbp,%rcx),%rsi
  1198. neg %rcx
  1199. .long 0xF689A4F3 # rep movsb # restore tail
  1200. jmp .Lcbc_cleanup
  1201. .size AES_cbc_encrypt,.-AES_cbc_encrypt
  1202. ___
  1203. }
  1204. $code.=<<___;
  1205. .globl AES_Te
  1206. .align 64
  1207. AES_Te:
  1208. ___
  1209. &_data_word(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6);
  1210. &_data_word(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591);
  1211. &_data_word(0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56);
  1212. &_data_word(0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec);
  1213. &_data_word(0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa);
  1214. &_data_word(0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb);
  1215. &_data_word(0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45);
  1216. &_data_word(0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b);
  1217. &_data_word(0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c);
  1218. &_data_word(0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83);
  1219. &_data_word(0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9);
  1220. &_data_word(0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a);
  1221. &_data_word(0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d);
  1222. &_data_word(0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f);
  1223. &_data_word(0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df);
  1224. &_data_word(0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea);
  1225. &_data_word(0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34);
  1226. &_data_word(0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b);
  1227. &_data_word(0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d);
  1228. &_data_word(0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413);
  1229. &_data_word(0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1);
  1230. &_data_word(0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6);
  1231. &_data_word(0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972);
  1232. &_data_word(0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85);
  1233. &_data_word(0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed);
  1234. &_data_word(0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511);
  1235. &_data_word(0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe);
  1236. &_data_word(0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b);
  1237. &_data_word(0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05);
  1238. &_data_word(0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1);
  1239. &_data_word(0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142);
  1240. &_data_word(0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf);
  1241. &_data_word(0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3);
  1242. &_data_word(0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e);
  1243. &_data_word(0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a);
  1244. &_data_word(0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6);
  1245. &_data_word(0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3);
  1246. &_data_word(0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b);
  1247. &_data_word(0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428);
  1248. &_data_word(0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad);
  1249. &_data_word(0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14);
  1250. &_data_word(0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8);
  1251. &_data_word(0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4);
  1252. &_data_word(0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2);
  1253. &_data_word(0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda);
  1254. &_data_word(0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949);
  1255. &_data_word(0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf);
  1256. &_data_word(0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810);
  1257. &_data_word(0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c);
  1258. &_data_word(0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697);
  1259. &_data_word(0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e);
  1260. &_data_word(0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f);
  1261. &_data_word(0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc);
  1262. &_data_word(0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c);
  1263. &_data_word(0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969);
  1264. &_data_word(0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27);
  1265. &_data_word(0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122);
  1266. &_data_word(0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433);
  1267. &_data_word(0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9);
  1268. &_data_word(0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5);
  1269. &_data_word(0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a);
  1270. &_data_word(0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0);
  1271. &_data_word(0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e);
  1272. &_data_word(0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c);
  1273. #rcon:
  1274. $code.=<<___;
  1275. .long 0x00000001, 0x00000002, 0x00000004, 0x00000008
  1276. .long 0x00000010, 0x00000020, 0x00000040, 0x00000080
  1277. .long 0x0000001b, 0x00000036, 0, 0, 0, 0, 0, 0
  1278. ___
  1279. $code.=<<___;
  1280. .globl AES_Td
  1281. .align 64
  1282. AES_Td:
  1283. ___
  1284. &_data_word(0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a);
  1285. &_data_word(0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b);
  1286. &_data_word(0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5);
  1287. &_data_word(0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5);
  1288. &_data_word(0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d);
  1289. &_data_word(0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b);
  1290. &_data_word(0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295);
  1291. &_data_word(0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e);
  1292. &_data_word(0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927);
  1293. &_data_word(0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d);
  1294. &_data_word(0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362);
  1295. &_data_word(0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9);
  1296. &_data_word(0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52);
  1297. &_data_word(0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566);
  1298. &_data_word(0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3);
  1299. &_data_word(0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed);
  1300. &_data_word(0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e);
  1301. &_data_word(0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4);
  1302. &_data_word(0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4);
  1303. &_data_word(0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd);
  1304. &_data_word(0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d);
  1305. &_data_word(0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060);
  1306. &_data_word(0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967);
  1307. &_data_word(0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879);
  1308. &_data_word(0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000);
  1309. &_data_word(0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c);
  1310. &_data_word(0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36);
  1311. &_data_word(0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624);
  1312. &_data_word(0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b);
  1313. &_data_word(0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c);
  1314. &_data_word(0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12);
  1315. &_data_word(0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14);
  1316. &_data_word(0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3);
  1317. &_data_word(0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b);
  1318. &_data_word(0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8);
  1319. &_data_word(0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684);
  1320. &_data_word(0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7);
  1321. &_data_word(0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177);
  1322. &_data_word(0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947);
  1323. &_data_word(0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322);
  1324. &_data_word(0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498);
  1325. &_data_word(0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f);
  1326. &_data_word(0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54);
  1327. &_data_word(0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382);
  1328. &_data_word(0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf);
  1329. &_data_word(0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb);
  1330. &_data_word(0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83);
  1331. &_data_word(0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef);
  1332. &_data_word(0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029);
  1333. &_data_word(0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235);
  1334. &_data_word(0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733);
  1335. &_data_word(0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117);
  1336. &_data_word(0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4);
  1337. &_data_word(0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546);
  1338. &_data_word(0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb);
  1339. &_data_word(0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d);
  1340. &_data_word(0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb);
  1341. &_data_word(0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a);
  1342. &_data_word(0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773);
  1343. &_data_word(0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478);
  1344. &_data_word(0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2);
  1345. &_data_word(0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff);
  1346. &_data_word(0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664);
  1347. &_data_word(0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0);
  1348. #Td4:
  1349. &data_word(0x52525252, 0x09090909, 0x6a6a6a6a, 0xd5d5d5d5);
  1350. &data_word(0x30303030, 0x36363636, 0xa5a5a5a5, 0x38383838);
  1351. &data_word(0xbfbfbfbf, 0x40404040, 0xa3a3a3a3, 0x9e9e9e9e);
  1352. &data_word(0x81818181, 0xf3f3f3f3, 0xd7d7d7d7, 0xfbfbfbfb);
  1353. &data_word(0x7c7c7c7c, 0xe3e3e3e3, 0x39393939, 0x82828282);
  1354. &data_word(0x9b9b9b9b, 0x2f2f2f2f, 0xffffffff, 0x87878787);
  1355. &data_word(0x34343434, 0x8e8e8e8e, 0x43434343, 0x44444444);
  1356. &data_word(0xc4c4c4c4, 0xdededede, 0xe9e9e9e9, 0xcbcbcbcb);
  1357. &data_word(0x54545454, 0x7b7b7b7b, 0x94949494, 0x32323232);
  1358. &data_word(0xa6a6a6a6, 0xc2c2c2c2, 0x23232323, 0x3d3d3d3d);
  1359. &data_word(0xeeeeeeee, 0x4c4c4c4c, 0x95959595, 0x0b0b0b0b);
  1360. &data_word(0x42424242, 0xfafafafa, 0xc3c3c3c3, 0x4e4e4e4e);
  1361. &data_word(0x08080808, 0x2e2e2e2e, 0xa1a1a1a1, 0x66666666);
  1362. &data_word(0x28282828, 0xd9d9d9d9, 0x24242424, 0xb2b2b2b2);
  1363. &data_word(0x76767676, 0x5b5b5b5b, 0xa2a2a2a2, 0x49494949);
  1364. &data_word(0x6d6d6d6d, 0x8b8b8b8b, 0xd1d1d1d1, 0x25252525);
  1365. &data_word(0x72727272, 0xf8f8f8f8, 0xf6f6f6f6, 0x64646464);
  1366. &data_word(0x86868686, 0x68686868, 0x98989898, 0x16161616);
  1367. &data_word(0xd4d4d4d4, 0xa4a4a4a4, 0x5c5c5c5c, 0xcccccccc);
  1368. &data_word(0x5d5d5d5d, 0x65656565, 0xb6b6b6b6, 0x92929292);
  1369. &data_word(0x6c6c6c6c, 0x70707070, 0x48484848, 0x50505050);
  1370. &data_word(0xfdfdfdfd, 0xedededed, 0xb9b9b9b9, 0xdadadada);
  1371. &data_word(0x5e5e5e5e, 0x15151515, 0x46464646, 0x57575757);
  1372. &data_word(0xa7a7a7a7, 0x8d8d8d8d, 0x9d9d9d9d, 0x84848484);
  1373. &data_word(0x90909090, 0xd8d8d8d8, 0xabababab, 0x00000000);
  1374. &data_word(0x8c8c8c8c, 0xbcbcbcbc, 0xd3d3d3d3, 0x0a0a0a0a);
  1375. &data_word(0xf7f7f7f7, 0xe4e4e4e4, 0x58585858, 0x05050505);
  1376. &data_word(0xb8b8b8b8, 0xb3b3b3b3, 0x45454545, 0x06060606);
  1377. &data_word(0xd0d0d0d0, 0x2c2c2c2c, 0x1e1e1e1e, 0x8f8f8f8f);
  1378. &data_word(0xcacacaca, 0x3f3f3f3f, 0x0f0f0f0f, 0x02020202);
  1379. &data_word(0xc1c1c1c1, 0xafafafaf, 0xbdbdbdbd, 0x03030303);
  1380. &data_word(0x01010101, 0x13131313, 0x8a8a8a8a, 0x6b6b6b6b);
  1381. &data_word(0x3a3a3a3a, 0x91919191, 0x11111111, 0x41414141);
  1382. &data_word(0x4f4f4f4f, 0x67676767, 0xdcdcdcdc, 0xeaeaeaea);
  1383. &data_word(0x97979797, 0xf2f2f2f2, 0xcfcfcfcf, 0xcececece);
  1384. &data_word(0xf0f0f0f0, 0xb4b4b4b4, 0xe6e6e6e6, 0x73737373);
  1385. &data_word(0x96969696, 0xacacacac, 0x74747474, 0x22222222);
  1386. &data_word(0xe7e7e7e7, 0xadadadad, 0x35353535, 0x85858585);
  1387. &data_word(0xe2e2e2e2, 0xf9f9f9f9, 0x37373737, 0xe8e8e8e8);
  1388. &data_word(0x1c1c1c1c, 0x75757575, 0xdfdfdfdf, 0x6e6e6e6e);
  1389. &data_word(0x47474747, 0xf1f1f1f1, 0x1a1a1a1a, 0x71717171);
  1390. &data_word(0x1d1d1d1d, 0x29292929, 0xc5c5c5c5, 0x89898989);
  1391. &data_word(0x6f6f6f6f, 0xb7b7b7b7, 0x62626262, 0x0e0e0e0e);
  1392. &data_word(0xaaaaaaaa, 0x18181818, 0xbebebebe, 0x1b1b1b1b);
  1393. &data_word(0xfcfcfcfc, 0x56565656, 0x3e3e3e3e, 0x4b4b4b4b);
  1394. &data_word(0xc6c6c6c6, 0xd2d2d2d2, 0x79797979, 0x20202020);
  1395. &data_word(0x9a9a9a9a, 0xdbdbdbdb, 0xc0c0c0c0, 0xfefefefe);
  1396. &data_word(0x78787878, 0xcdcdcdcd, 0x5a5a5a5a, 0xf4f4f4f4);
  1397. &data_word(0x1f1f1f1f, 0xdddddddd, 0xa8a8a8a8, 0x33333333);
  1398. &data_word(0x88888888, 0x07070707, 0xc7c7c7c7, 0x31313131);
  1399. &data_word(0xb1b1b1b1, 0x12121212, 0x10101010, 0x59595959);
  1400. &data_word(0x27272727, 0x80808080, 0xecececec, 0x5f5f5f5f);
  1401. &data_word(0x60606060, 0x51515151, 0x7f7f7f7f, 0xa9a9a9a9);
  1402. &data_word(0x19191919, 0xb5b5b5b5, 0x4a4a4a4a, 0x0d0d0d0d);
  1403. &data_word(0x2d2d2d2d, 0xe5e5e5e5, 0x7a7a7a7a, 0x9f9f9f9f);
  1404. &data_word(0x93939393, 0xc9c9c9c9, 0x9c9c9c9c, 0xefefefef);
  1405. &data_word(0xa0a0a0a0, 0xe0e0e0e0, 0x3b3b3b3b, 0x4d4d4d4d);
  1406. &data_word(0xaeaeaeae, 0x2a2a2a2a, 0xf5f5f5f5, 0xb0b0b0b0);
  1407. &data_word(0xc8c8c8c8, 0xebebebeb, 0xbbbbbbbb, 0x3c3c3c3c);
  1408. &data_word(0x83838383, 0x53535353, 0x99999999, 0x61616161);
  1409. &data_word(0x17171717, 0x2b2b2b2b, 0x04040404, 0x7e7e7e7e);
  1410. &data_word(0xbabababa, 0x77777777, 0xd6d6d6d6, 0x26262626);
  1411. &data_word(0xe1e1e1e1, 0x69696969, 0x14141414, 0x63636363);
  1412. &data_word(0x55555555, 0x21212121, 0x0c0c0c0c, 0x7d7d7d7d);
  1413. $code =~ s/\`([^\`]*)\`/eval($1)/gem;
  1414. print $code;
  1415. close STDOUT;