cmll-x86_64.pl 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. #! /usr/bin/env perl
  2. # Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (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. # Copyright (c) 2008 Andy Polyakov <appro@openssl.org>
  10. #
  11. # This module may be used under the terms of either the GNU General
  12. # Public License version 2 or later, the GNU Lesser General Public
  13. # License version 2.1 or later, the Mozilla Public License version
  14. # 1.1 or the BSD License. The exact terms of either license are
  15. # distributed along with this module. For further details see
  16. # http://www.openssl.org/~appro/camellia/.
  17. # ====================================================================
  18. # Performance in cycles per processed byte (less is better) in
  19. # 'openssl speed ...' benchmark:
  20. #
  21. # AMD64 Core2 EM64T
  22. # -evp camellia-128-ecb 16.7 21.0 22.7
  23. # + over gcc 3.4.6 +25% +5% 0%
  24. #
  25. # camellia-128-cbc 15.7 20.4 21.1
  26. #
  27. # 128-bit key setup 128 216 205 cycles/key
  28. # + over gcc 3.4.6 +54% +39% +15%
  29. #
  30. # Numbers in "+" rows represent performance improvement over compiler
  31. # generated code. Key setup timings are impressive on AMD and Core2
  32. # thanks to 64-bit operations being covertly deployed. Improvement on
  33. # EM64T, pre-Core2 Intel x86_64 CPU, is not as impressive, because it
  34. # apparently emulates some of 64-bit operations in [32-bit] microcode.
  35. $flavour = shift;
  36. $output = shift;
  37. if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
  38. $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
  39. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  40. ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
  41. ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
  42. die "can't locate x86_64-xlate.pl";
  43. open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
  44. *STDOUT=*OUT;
  45. sub hi() { my $r=shift; $r =~ s/%[er]([a-d])x/%\1h/; $r; }
  46. sub lo() { my $r=shift; $r =~ s/%[er]([a-d])x/%\1l/;
  47. $r =~ s/%[er]([sd]i)/%\1l/;
  48. $r =~ s/%(r[0-9]+)[d]?/%\1b/; $r; }
  49. $t0="%eax";$t1="%ebx";$t2="%ecx";$t3="%edx";
  50. @S=("%r8d","%r9d","%r10d","%r11d");
  51. $i0="%esi";
  52. $i1="%edi";
  53. $Tbl="%rbp"; # size optimization
  54. $inp="%r12";
  55. $out="%r13";
  56. $key="%r14";
  57. $keyend="%r15";
  58. $arg0d=$win64?"%ecx":"%edi";
  59. # const unsigned int Camellia_SBOX[4][256];
  60. # Well, sort of... Camellia_SBOX[0][] is interleaved with [1][],
  61. # and [2][] - with [3][]. This is done to minimize code size.
  62. $SBOX1_1110=0; # Camellia_SBOX[0]
  63. $SBOX4_4404=4; # Camellia_SBOX[1]
  64. $SBOX2_0222=2048; # Camellia_SBOX[2]
  65. $SBOX3_3033=2052; # Camellia_SBOX[3]
  66. sub Camellia_Feistel {
  67. my $i=@_[0];
  68. my $seed=defined(@_[1])?@_[1]:0;
  69. my $scale=$seed<0?-8:8;
  70. my $j=($i&1)*2;
  71. my ($s0,$s1,$s2,$s3)=(@S[($j)%4],@S[($j+1)%4],@S[($j+2)%4],@S[($j+3)%4]);
  72. $code.=<<___;
  73. xor $s0,$t0 # t0^=key[0]
  74. xor $s1,$t1 # t1^=key[1]
  75. movz `&hi("$t0")`,$i0 # (t0>>8)&0xff
  76. movz `&lo("$t1")`,$i1 # (t1>>0)&0xff
  77. mov $SBOX3_3033($Tbl,$i0,8),$t3 # t3=SBOX3_3033[0]
  78. mov $SBOX1_1110($Tbl,$i1,8),$t2 # t2=SBOX1_1110[1]
  79. movz `&lo("$t0")`,$i0 # (t0>>0)&0xff
  80. shr \$16,$t0
  81. movz `&hi("$t1")`,$i1 # (t1>>8)&0xff
  82. xor $SBOX4_4404($Tbl,$i0,8),$t3 # t3^=SBOX4_4404[0]
  83. shr \$16,$t1
  84. xor $SBOX4_4404($Tbl,$i1,8),$t2 # t2^=SBOX4_4404[1]
  85. movz `&hi("$t0")`,$i0 # (t0>>24)&0xff
  86. movz `&lo("$t1")`,$i1 # (t1>>16)&0xff
  87. xor $SBOX1_1110($Tbl,$i0,8),$t3 # t3^=SBOX1_1110[0]
  88. xor $SBOX3_3033($Tbl,$i1,8),$t2 # t2^=SBOX3_3033[1]
  89. movz `&lo("$t0")`,$i0 # (t0>>16)&0xff
  90. movz `&hi("$t1")`,$i1 # (t1>>24)&0xff
  91. xor $SBOX2_0222($Tbl,$i0,8),$t3 # t3^=SBOX2_0222[0]
  92. xor $SBOX2_0222($Tbl,$i1,8),$t2 # t2^=SBOX2_0222[1]
  93. mov `$seed+($i+1)*$scale`($key),$t1 # prefetch key[i+1]
  94. mov `$seed+($i+1)*$scale+4`($key),$t0
  95. xor $t3,$t2 # t2^=t3
  96. ror \$8,$t3 # t3=RightRotate(t3,8)
  97. xor $t2,$s2
  98. xor $t2,$s3
  99. xor $t3,$s3
  100. ___
  101. }
  102. # void Camellia_EncryptBlock_Rounds(
  103. # int grandRounds,
  104. # const Byte plaintext[],
  105. # const KEY_TABLE_TYPE keyTable,
  106. # Byte ciphertext[])
  107. $code=<<___;
  108. .text
  109. # V1.x API
  110. .globl Camellia_EncryptBlock
  111. .type Camellia_EncryptBlock,\@abi-omnipotent
  112. .align 16
  113. Camellia_EncryptBlock:
  114. .cfi_startproc
  115. movl \$128,%eax
  116. subl $arg0d,%eax
  117. movl \$3,$arg0d
  118. adcl \$0,$arg0d # keyBitLength==128?3:4
  119. jmp .Lenc_rounds
  120. .cfi_endproc
  121. .size Camellia_EncryptBlock,.-Camellia_EncryptBlock
  122. # V2
  123. .globl Camellia_EncryptBlock_Rounds
  124. .type Camellia_EncryptBlock_Rounds,\@function,4
  125. .align 16
  126. .Lenc_rounds:
  127. Camellia_EncryptBlock_Rounds:
  128. .cfi_startproc
  129. push %rbx
  130. .cfi_push %rbx
  131. push %rbp
  132. .cfi_push %rbp
  133. push %r13
  134. .cfi_push %r13
  135. push %r14
  136. .cfi_push %r14
  137. push %r15
  138. .cfi_push %r15
  139. .Lenc_prologue:
  140. #mov %rsi,$inp # put away arguments
  141. mov %rcx,$out
  142. mov %rdx,$key
  143. shl \$6,%edi # process grandRounds
  144. lea .LCamellia_SBOX(%rip),$Tbl
  145. lea ($key,%rdi),$keyend
  146. mov 0(%rsi),@S[0] # load plaintext
  147. mov 4(%rsi),@S[1]
  148. mov 8(%rsi),@S[2]
  149. bswap @S[0]
  150. mov 12(%rsi),@S[3]
  151. bswap @S[1]
  152. bswap @S[2]
  153. bswap @S[3]
  154. call _x86_64_Camellia_encrypt
  155. bswap @S[0]
  156. bswap @S[1]
  157. bswap @S[2]
  158. mov @S[0],0($out)
  159. bswap @S[3]
  160. mov @S[1],4($out)
  161. mov @S[2],8($out)
  162. mov @S[3],12($out)
  163. mov 0(%rsp),%r15
  164. .cfi_restore %r15
  165. mov 8(%rsp),%r14
  166. .cfi_restore %r14
  167. mov 16(%rsp),%r13
  168. .cfi_restore %r13
  169. mov 24(%rsp),%rbp
  170. .cfi_restore %rbp
  171. mov 32(%rsp),%rbx
  172. .cfi_restore %rbx
  173. lea 40(%rsp),%rsp
  174. .cfi_adjust_cfa_offset -40
  175. .Lenc_epilogue:
  176. ret
  177. .cfi_endproc
  178. .size Camellia_EncryptBlock_Rounds,.-Camellia_EncryptBlock_Rounds
  179. .type _x86_64_Camellia_encrypt,\@abi-omnipotent
  180. .align 16
  181. _x86_64_Camellia_encrypt:
  182. .cfi_startproc
  183. xor 0($key),@S[1]
  184. xor 4($key),@S[0] # ^=key[0-3]
  185. xor 8($key),@S[3]
  186. xor 12($key),@S[2]
  187. .align 16
  188. .Leloop:
  189. mov 16($key),$t1 # prefetch key[4-5]
  190. mov 20($key),$t0
  191. ___
  192. for ($i=0;$i<6;$i++) { Camellia_Feistel($i,16); }
  193. $code.=<<___;
  194. lea 16*4($key),$key
  195. cmp $keyend,$key
  196. mov 8($key),$t3 # prefetch key[2-3]
  197. mov 12($key),$t2
  198. je .Ledone
  199. and @S[0],$t0
  200. or @S[3],$t3
  201. rol \$1,$t0
  202. xor $t3,@S[2] # s2^=s3|key[3];
  203. xor $t0,@S[1] # s1^=LeftRotate(s0&key[0],1);
  204. and @S[2],$t2
  205. or @S[1],$t1
  206. rol \$1,$t2
  207. xor $t1,@S[0] # s0^=s1|key[1];
  208. xor $t2,@S[3] # s3^=LeftRotate(s2&key[2],1);
  209. jmp .Leloop
  210. .align 16
  211. .Ledone:
  212. xor @S[2],$t0 # SwapHalf
  213. xor @S[3],$t1
  214. xor @S[0],$t2
  215. xor @S[1],$t3
  216. mov $t0,@S[0]
  217. mov $t1,@S[1]
  218. mov $t2,@S[2]
  219. mov $t3,@S[3]
  220. .byte 0xf3,0xc3 # rep ret
  221. .cfi_endproc
  222. .size _x86_64_Camellia_encrypt,.-_x86_64_Camellia_encrypt
  223. # V1.x API
  224. .globl Camellia_DecryptBlock
  225. .type Camellia_DecryptBlock,\@abi-omnipotent
  226. .align 16
  227. Camellia_DecryptBlock:
  228. .cfi_startproc
  229. movl \$128,%eax
  230. subl $arg0d,%eax
  231. movl \$3,$arg0d
  232. adcl \$0,$arg0d # keyBitLength==128?3:4
  233. jmp .Ldec_rounds
  234. .cfi_endproc
  235. .size Camellia_DecryptBlock,.-Camellia_DecryptBlock
  236. # V2
  237. .globl Camellia_DecryptBlock_Rounds
  238. .type Camellia_DecryptBlock_Rounds,\@function,4
  239. .align 16
  240. .Ldec_rounds:
  241. Camellia_DecryptBlock_Rounds:
  242. .cfi_startproc
  243. push %rbx
  244. .cfi_push %rbx
  245. push %rbp
  246. .cfi_push %rbp
  247. push %r13
  248. .cfi_push %r13
  249. push %r14
  250. .cfi_push %r14
  251. push %r15
  252. .cfi_push %r15
  253. .Ldec_prologue:
  254. #mov %rsi,$inp # put away arguments
  255. mov %rcx,$out
  256. mov %rdx,$keyend
  257. shl \$6,%edi # process grandRounds
  258. lea .LCamellia_SBOX(%rip),$Tbl
  259. lea ($keyend,%rdi),$key
  260. mov 0(%rsi),@S[0] # load plaintext
  261. mov 4(%rsi),@S[1]
  262. mov 8(%rsi),@S[2]
  263. bswap @S[0]
  264. mov 12(%rsi),@S[3]
  265. bswap @S[1]
  266. bswap @S[2]
  267. bswap @S[3]
  268. call _x86_64_Camellia_decrypt
  269. bswap @S[0]
  270. bswap @S[1]
  271. bswap @S[2]
  272. mov @S[0],0($out)
  273. bswap @S[3]
  274. mov @S[1],4($out)
  275. mov @S[2],8($out)
  276. mov @S[3],12($out)
  277. mov 0(%rsp),%r15
  278. .cfi_restore %r15
  279. mov 8(%rsp),%r14
  280. .cfi_restore %r14
  281. mov 16(%rsp),%r13
  282. .cfi_restore %r13
  283. mov 24(%rsp),%rbp
  284. .cfi_restore %rbp
  285. mov 32(%rsp),%rbx
  286. .cfi_restore %rbx
  287. lea 40(%rsp),%rsp
  288. .cfi_adjust_cfa_offset -40
  289. .Ldec_epilogue:
  290. ret
  291. .cfi_endproc
  292. .size Camellia_DecryptBlock_Rounds,.-Camellia_DecryptBlock_Rounds
  293. .type _x86_64_Camellia_decrypt,\@abi-omnipotent
  294. .align 16
  295. _x86_64_Camellia_decrypt:
  296. .cfi_startproc
  297. xor 0($key),@S[1]
  298. xor 4($key),@S[0] # ^=key[0-3]
  299. xor 8($key),@S[3]
  300. xor 12($key),@S[2]
  301. .align 16
  302. .Ldloop:
  303. mov -8($key),$t1 # prefetch key[4-5]
  304. mov -4($key),$t0
  305. ___
  306. for ($i=0;$i<6;$i++) { Camellia_Feistel($i,-8); }
  307. $code.=<<___;
  308. lea -16*4($key),$key
  309. cmp $keyend,$key
  310. mov 0($key),$t3 # prefetch key[2-3]
  311. mov 4($key),$t2
  312. je .Lddone
  313. and @S[0],$t0
  314. or @S[3],$t3
  315. rol \$1,$t0
  316. xor $t3,@S[2] # s2^=s3|key[3];
  317. xor $t0,@S[1] # s1^=LeftRotate(s0&key[0],1);
  318. and @S[2],$t2
  319. or @S[1],$t1
  320. rol \$1,$t2
  321. xor $t1,@S[0] # s0^=s1|key[1];
  322. xor $t2,@S[3] # s3^=LeftRotate(s2&key[2],1);
  323. jmp .Ldloop
  324. .align 16
  325. .Lddone:
  326. xor @S[2],$t2
  327. xor @S[3],$t3
  328. xor @S[0],$t0
  329. xor @S[1],$t1
  330. mov $t2,@S[0] # SwapHalf
  331. mov $t3,@S[1]
  332. mov $t0,@S[2]
  333. mov $t1,@S[3]
  334. .byte 0xf3,0xc3 # rep ret
  335. .cfi_endproc
  336. .size _x86_64_Camellia_decrypt,.-_x86_64_Camellia_decrypt
  337. ___
  338. sub _saveround {
  339. my ($rnd,$key,@T)=@_;
  340. my $bias=int(@T[0])?shift(@T):0;
  341. if ($#T==3) {
  342. $code.=<<___;
  343. mov @T[1],`$bias+$rnd*8+0`($key)
  344. mov @T[0],`$bias+$rnd*8+4`($key)
  345. mov @T[3],`$bias+$rnd*8+8`($key)
  346. mov @T[2],`$bias+$rnd*8+12`($key)
  347. ___
  348. } else {
  349. $code.=" mov @T[0],`$bias+$rnd*8+0`($key)\n";
  350. $code.=" mov @T[1],`$bias+$rnd*8+8`($key)\n" if ($#T>=1);
  351. }
  352. }
  353. sub _loadround {
  354. my ($rnd,$key,@T)=@_;
  355. my $bias=int(@T[0])?shift(@T):0;
  356. $code.=" mov `$bias+$rnd*8+0`($key),@T[0]\n";
  357. $code.=" mov `$bias+$rnd*8+8`($key),@T[1]\n" if ($#T>=1);
  358. }
  359. # shld is very slow on Intel EM64T family. Even on AMD it limits
  360. # instruction decode rate [because it's VectorPath] and consequently
  361. # performance...
  362. sub __rotl128 {
  363. my ($i0,$i1,$rot)=@_;
  364. if ($rot) {
  365. $code.=<<___;
  366. mov $i0,%r11
  367. shld \$$rot,$i1,$i0
  368. shld \$$rot,%r11,$i1
  369. ___
  370. }
  371. }
  372. # ... Implementing 128-bit rotate without shld gives 80% better
  373. # performance EM64T, +15% on AMD64 and only ~7% degradation on
  374. # Core2. This is therefore preferred.
  375. sub _rotl128 {
  376. my ($i0,$i1,$rot)=@_;
  377. if ($rot) {
  378. $code.=<<___;
  379. mov $i0,%r11
  380. shl \$$rot,$i0
  381. mov $i1,%r9
  382. shr \$`64-$rot`,%r9
  383. shr \$`64-$rot`,%r11
  384. or %r9,$i0
  385. shl \$$rot,$i1
  386. or %r11,$i1
  387. ___
  388. }
  389. }
  390. { my $step=0;
  391. $code.=<<___;
  392. .globl Camellia_Ekeygen
  393. .type Camellia_Ekeygen,\@function,3
  394. .align 16
  395. Camellia_Ekeygen:
  396. .cfi_startproc
  397. push %rbx
  398. .cfi_push %rbx
  399. push %rbp
  400. .cfi_push %rbp
  401. push %r13
  402. .cfi_push %r13
  403. push %r14
  404. .cfi_push %r14
  405. push %r15
  406. .cfi_push %r15
  407. .Lkey_prologue:
  408. mov %edi,${keyend}d # put away arguments, keyBitLength
  409. mov %rdx,$out # keyTable
  410. mov 0(%rsi),@S[0] # load 0-127 bits
  411. mov 4(%rsi),@S[1]
  412. mov 8(%rsi),@S[2]
  413. mov 12(%rsi),@S[3]
  414. bswap @S[0]
  415. bswap @S[1]
  416. bswap @S[2]
  417. bswap @S[3]
  418. ___
  419. &_saveround (0,$out,@S); # KL<<<0
  420. $code.=<<___;
  421. cmp \$128,$keyend # check keyBitLength
  422. je .L1st128
  423. mov 16(%rsi),@S[0] # load 128-191 bits
  424. mov 20(%rsi),@S[1]
  425. cmp \$192,$keyend
  426. je .L1st192
  427. mov 24(%rsi),@S[2] # load 192-255 bits
  428. mov 28(%rsi),@S[3]
  429. jmp .L1st256
  430. .L1st192:
  431. mov @S[0],@S[2]
  432. mov @S[1],@S[3]
  433. not @S[2]
  434. not @S[3]
  435. .L1st256:
  436. bswap @S[0]
  437. bswap @S[1]
  438. bswap @S[2]
  439. bswap @S[3]
  440. ___
  441. &_saveround (4,$out,@S); # temp storage for KR!
  442. $code.=<<___;
  443. xor 0($out),@S[1] # KR^KL
  444. xor 4($out),@S[0]
  445. xor 8($out),@S[3]
  446. xor 12($out),@S[2]
  447. .L1st128:
  448. lea .LCamellia_SIGMA(%rip),$key
  449. lea .LCamellia_SBOX(%rip),$Tbl
  450. mov 0($key),$t1
  451. mov 4($key),$t0
  452. ___
  453. &Camellia_Feistel($step++);
  454. &Camellia_Feistel($step++);
  455. $code.=<<___;
  456. xor 0($out),@S[1] # ^KL
  457. xor 4($out),@S[0]
  458. xor 8($out),@S[3]
  459. xor 12($out),@S[2]
  460. ___
  461. &Camellia_Feistel($step++);
  462. &Camellia_Feistel($step++);
  463. $code.=<<___;
  464. cmp \$128,$keyend
  465. jne .L2nd256
  466. lea 128($out),$out # size optimization
  467. shl \$32,%r8 # @S[0]||
  468. shl \$32,%r10 # @S[2]||
  469. or %r9,%r8 # ||@S[1]
  470. or %r11,%r10 # ||@S[3]
  471. ___
  472. &_loadround (0,$out,-128,"%rax","%rbx"); # KL
  473. &_saveround (2,$out,-128,"%r8","%r10"); # KA<<<0
  474. &_rotl128 ("%rax","%rbx",15);
  475. &_saveround (4,$out,-128,"%rax","%rbx"); # KL<<<15
  476. &_rotl128 ("%r8","%r10",15);
  477. &_saveround (6,$out,-128,"%r8","%r10"); # KA<<<15
  478. &_rotl128 ("%r8","%r10",15); # 15+15=30
  479. &_saveround (8,$out,-128,"%r8","%r10"); # KA<<<30
  480. &_rotl128 ("%rax","%rbx",30); # 15+30=45
  481. &_saveround (10,$out,-128,"%rax","%rbx"); # KL<<<45
  482. &_rotl128 ("%r8","%r10",15); # 30+15=45
  483. &_saveround (12,$out,-128,"%r8"); # KA<<<45
  484. &_rotl128 ("%rax","%rbx",15); # 45+15=60
  485. &_saveround (13,$out,-128,"%rbx"); # KL<<<60
  486. &_rotl128 ("%r8","%r10",15); # 45+15=60
  487. &_saveround (14,$out,-128,"%r8","%r10"); # KA<<<60
  488. &_rotl128 ("%rax","%rbx",17); # 60+17=77
  489. &_saveround (16,$out,-128,"%rax","%rbx"); # KL<<<77
  490. &_rotl128 ("%rax","%rbx",17); # 77+17=94
  491. &_saveround (18,$out,-128,"%rax","%rbx"); # KL<<<94
  492. &_rotl128 ("%r8","%r10",34); # 60+34=94
  493. &_saveround (20,$out,-128,"%r8","%r10"); # KA<<<94
  494. &_rotl128 ("%rax","%rbx",17); # 94+17=111
  495. &_saveround (22,$out,-128,"%rax","%rbx"); # KL<<<111
  496. &_rotl128 ("%r8","%r10",17); # 94+17=111
  497. &_saveround (24,$out,-128,"%r8","%r10"); # KA<<<111
  498. $code.=<<___;
  499. mov \$3,%eax
  500. jmp .Ldone
  501. .align 16
  502. .L2nd256:
  503. ___
  504. &_saveround (6,$out,@S); # temp storage for KA!
  505. $code.=<<___;
  506. xor `4*8+0`($out),@S[1] # KA^KR
  507. xor `4*8+4`($out),@S[0]
  508. xor `5*8+0`($out),@S[3]
  509. xor `5*8+4`($out),@S[2]
  510. ___
  511. &Camellia_Feistel($step++);
  512. &Camellia_Feistel($step++);
  513. &_loadround (0,$out,"%rax","%rbx"); # KL
  514. &_loadround (4,$out,"%rcx","%rdx"); # KR
  515. &_loadround (6,$out,"%r14","%r15"); # KA
  516. $code.=<<___;
  517. lea 128($out),$out # size optimization
  518. shl \$32,%r8 # @S[0]||
  519. shl \$32,%r10 # @S[2]||
  520. or %r9,%r8 # ||@S[1]
  521. or %r11,%r10 # ||@S[3]
  522. ___
  523. &_saveround (2,$out,-128,"%r8","%r10"); # KB<<<0
  524. &_rotl128 ("%rcx","%rdx",15);
  525. &_saveround (4,$out,-128,"%rcx","%rdx"); # KR<<<15
  526. &_rotl128 ("%r14","%r15",15);
  527. &_saveround (6,$out,-128,"%r14","%r15"); # KA<<<15
  528. &_rotl128 ("%rcx","%rdx",15); # 15+15=30
  529. &_saveround (8,$out,-128,"%rcx","%rdx"); # KR<<<30
  530. &_rotl128 ("%r8","%r10",30);
  531. &_saveround (10,$out,-128,"%r8","%r10"); # KB<<<30
  532. &_rotl128 ("%rax","%rbx",45);
  533. &_saveround (12,$out,-128,"%rax","%rbx"); # KL<<<45
  534. &_rotl128 ("%r14","%r15",30); # 15+30=45
  535. &_saveround (14,$out,-128,"%r14","%r15"); # KA<<<45
  536. &_rotl128 ("%rax","%rbx",15); # 45+15=60
  537. &_saveround (16,$out,-128,"%rax","%rbx"); # KL<<<60
  538. &_rotl128 ("%rcx","%rdx",30); # 30+30=60
  539. &_saveround (18,$out,-128,"%rcx","%rdx"); # KR<<<60
  540. &_rotl128 ("%r8","%r10",30); # 30+30=60
  541. &_saveround (20,$out,-128,"%r8","%r10"); # KB<<<60
  542. &_rotl128 ("%rax","%rbx",17); # 60+17=77
  543. &_saveround (22,$out,-128,"%rax","%rbx"); # KL<<<77
  544. &_rotl128 ("%r14","%r15",32); # 45+32=77
  545. &_saveround (24,$out,-128,"%r14","%r15"); # KA<<<77
  546. &_rotl128 ("%rcx","%rdx",34); # 60+34=94
  547. &_saveround (26,$out,-128,"%rcx","%rdx"); # KR<<<94
  548. &_rotl128 ("%r14","%r15",17); # 77+17=94
  549. &_saveround (28,$out,-128,"%r14","%r15"); # KA<<<77
  550. &_rotl128 ("%rax","%rbx",34); # 77+34=111
  551. &_saveround (30,$out,-128,"%rax","%rbx"); # KL<<<111
  552. &_rotl128 ("%r8","%r10",51); # 60+51=111
  553. &_saveround (32,$out,-128,"%r8","%r10"); # KB<<<111
  554. $code.=<<___;
  555. mov \$4,%eax
  556. .Ldone:
  557. mov 0(%rsp),%r15
  558. .cfi_restore %r15
  559. mov 8(%rsp),%r14
  560. .cfi_restore %r14
  561. mov 16(%rsp),%r13
  562. .cfi_restore %r13
  563. mov 24(%rsp),%rbp
  564. .cfi_restore %rbp
  565. mov 32(%rsp),%rbx
  566. .cfi_restore %rbx
  567. lea 40(%rsp),%rsp
  568. .cfi_adjust_cfa_offset -40
  569. .Lkey_epilogue:
  570. ret
  571. .cfi_endproc
  572. .size Camellia_Ekeygen,.-Camellia_Ekeygen
  573. ___
  574. }
  575. @SBOX=(
  576. 112,130, 44,236,179, 39,192,229,228,133, 87, 53,234, 12,174, 65,
  577. 35,239,107,147, 69, 25,165, 33,237, 14, 79, 78, 29,101,146,189,
  578. 134,184,175,143,124,235, 31,206, 62, 48,220, 95, 94,197, 11, 26,
  579. 166,225, 57,202,213, 71, 93, 61,217, 1, 90,214, 81, 86,108, 77,
  580. 139, 13,154,102,251,204,176, 45,116, 18, 43, 32,240,177,132,153,
  581. 223, 76,203,194, 52,126,118, 5,109,183,169, 49,209, 23, 4,215,
  582. 20, 88, 58, 97,222, 27, 17, 28, 50, 15,156, 22, 83, 24,242, 34,
  583. 254, 68,207,178,195,181,122,145, 36, 8,232,168, 96,252,105, 80,
  584. 170,208,160,125,161,137, 98,151, 84, 91, 30,149,224,255,100,210,
  585. 16,196, 0, 72,163,247,117,219,138, 3,230,218, 9, 63,221,148,
  586. 135, 92,131, 2,205, 74,144, 51,115,103,246,243,157,127,191,226,
  587. 82,155,216, 38,200, 55,198, 59,129,150,111, 75, 19,190, 99, 46,
  588. 233,121,167,140,159,110,188,142, 41,245,249,182, 47,253,180, 89,
  589. 120,152, 6,106,231, 70,113,186,212, 37,171, 66,136,162,141,250,
  590. 114, 7,185, 85,248,238,172, 10, 54, 73, 42,104, 60, 56,241,164,
  591. 64, 40,211,123,187,201, 67,193, 21,227,173,244,119,199,128,158);
  592. sub S1110 { my $i=shift; $i=@SBOX[$i]; $i=$i<<24|$i<<16|$i<<8; sprintf("0x%08x",$i); }
  593. sub S4404 { my $i=shift; $i=($i<<1|$i>>7)&0xff; $i=@SBOX[$i]; $i=$i<<24|$i<<16|$i; sprintf("0x%08x",$i); }
  594. sub S0222 { my $i=shift; $i=@SBOX[$i]; $i=($i<<1|$i>>7)&0xff; $i=$i<<16|$i<<8|$i; sprintf("0x%08x",$i); }
  595. sub S3033 { my $i=shift; $i=@SBOX[$i]; $i=($i>>1|$i<<7)&0xff; $i=$i<<24|$i<<8|$i; sprintf("0x%08x",$i); }
  596. $code.=<<___;
  597. .align 64
  598. .LCamellia_SIGMA:
  599. .long 0x3bcc908b, 0xa09e667f, 0x4caa73b2, 0xb67ae858
  600. .long 0xe94f82be, 0xc6ef372f, 0xf1d36f1c, 0x54ff53a5
  601. .long 0xde682d1d, 0x10e527fa, 0xb3e6c1fd, 0xb05688c2
  602. .long 0, 0, 0, 0
  603. .LCamellia_SBOX:
  604. ___
  605. # tables are interleaved, remember?
  606. sub data_word { $code.=".long\t".join(',',@_)."\n"; }
  607. for ($i=0;$i<256;$i++) { &data_word(&S1110($i),&S4404($i)); }
  608. for ($i=0;$i<256;$i++) { &data_word(&S0222($i),&S3033($i)); }
  609. # void Camellia_cbc_encrypt (const void char *inp, unsigned char *out,
  610. # size_t length, const CAMELLIA_KEY *key,
  611. # unsigned char *ivp,const int enc);
  612. {
  613. $_key="0(%rsp)";
  614. $_end="8(%rsp)"; # inp+len&~15
  615. $_res="16(%rsp)"; # len&15
  616. $ivec="24(%rsp)";
  617. $_ivp="40(%rsp)";
  618. $_rsp="48(%rsp)";
  619. $code.=<<___;
  620. .globl Camellia_cbc_encrypt
  621. .type Camellia_cbc_encrypt,\@function,6
  622. .align 16
  623. Camellia_cbc_encrypt:
  624. .cfi_startproc
  625. cmp \$0,%rdx
  626. je .Lcbc_abort
  627. push %rbx
  628. .cfi_push %rbx
  629. push %rbp
  630. .cfi_push %rbp
  631. push %r12
  632. .cfi_push %r12
  633. push %r13
  634. .cfi_push %r13
  635. push %r14
  636. .cfi_push %r14
  637. push %r15
  638. .cfi_push %r15
  639. .Lcbc_prologue:
  640. mov %rsp,%rbp
  641. .cfi_def_cfa_register %rbp
  642. sub \$64,%rsp
  643. and \$-64,%rsp
  644. # place stack frame just "above mod 1024" the key schedule,
  645. # this ensures that cache associativity suffices
  646. lea -64-63(%rcx),%r10
  647. sub %rsp,%r10
  648. neg %r10
  649. and \$0x3C0,%r10
  650. sub %r10,%rsp
  651. #add \$8,%rsp # 8 is reserved for callee's ra
  652. mov %rdi,$inp # inp argument
  653. mov %rsi,$out # out argument
  654. mov %r8,%rbx # ivp argument
  655. mov %rcx,$key # key argument
  656. mov 272(%rcx),${keyend}d # grandRounds
  657. mov %r8,$_ivp
  658. mov %rbp,$_rsp
  659. .cfi_cfa_expression $_rsp,deref,+56
  660. .Lcbc_body:
  661. lea .LCamellia_SBOX(%rip),$Tbl
  662. mov \$32,%ecx
  663. .align 4
  664. .Lcbc_prefetch_sbox:
  665. mov 0($Tbl),%rax
  666. mov 32($Tbl),%rsi
  667. mov 64($Tbl),%rdi
  668. mov 96($Tbl),%r11
  669. lea 128($Tbl),$Tbl
  670. loop .Lcbc_prefetch_sbox
  671. sub \$4096,$Tbl
  672. shl \$6,$keyend
  673. mov %rdx,%rcx # len argument
  674. lea ($key,$keyend),$keyend
  675. cmp \$0,%r9d # enc argument
  676. je .LCBC_DECRYPT
  677. and \$-16,%rdx
  678. and \$15,%rcx # length residue
  679. lea ($inp,%rdx),%rdx
  680. mov $key,$_key
  681. mov %rdx,$_end
  682. mov %rcx,$_res
  683. cmp $inp,%rdx
  684. mov 0(%rbx),@S[0] # load IV
  685. mov 4(%rbx),@S[1]
  686. mov 8(%rbx),@S[2]
  687. mov 12(%rbx),@S[3]
  688. je .Lcbc_enc_tail
  689. jmp .Lcbc_eloop
  690. .align 16
  691. .Lcbc_eloop:
  692. xor 0($inp),@S[0]
  693. xor 4($inp),@S[1]
  694. xor 8($inp),@S[2]
  695. bswap @S[0]
  696. xor 12($inp),@S[3]
  697. bswap @S[1]
  698. bswap @S[2]
  699. bswap @S[3]
  700. call _x86_64_Camellia_encrypt
  701. mov $_key,$key # "rewind" the key
  702. bswap @S[0]
  703. mov $_end,%rdx
  704. bswap @S[1]
  705. mov $_res,%rcx
  706. bswap @S[2]
  707. mov @S[0],0($out)
  708. bswap @S[3]
  709. mov @S[1],4($out)
  710. mov @S[2],8($out)
  711. lea 16($inp),$inp
  712. mov @S[3],12($out)
  713. cmp %rdx,$inp
  714. lea 16($out),$out
  715. jne .Lcbc_eloop
  716. cmp \$0,%rcx
  717. jne .Lcbc_enc_tail
  718. mov $_ivp,$out
  719. mov @S[0],0($out) # write out IV residue
  720. mov @S[1],4($out)
  721. mov @S[2],8($out)
  722. mov @S[3],12($out)
  723. jmp .Lcbc_done
  724. .align 16
  725. .Lcbc_enc_tail:
  726. xor %rax,%rax
  727. mov %rax,0+$ivec
  728. mov %rax,8+$ivec
  729. mov %rax,$_res
  730. .Lcbc_enc_pushf:
  731. pushfq
  732. cld
  733. mov $inp,%rsi
  734. lea 8+$ivec,%rdi
  735. .long 0x9066A4F3 # rep movsb
  736. popfq
  737. .Lcbc_enc_popf:
  738. lea $ivec,$inp
  739. lea 16+$ivec,%rax
  740. mov %rax,$_end
  741. jmp .Lcbc_eloop # one more time
  742. .align 16
  743. .LCBC_DECRYPT:
  744. xchg $key,$keyend
  745. add \$15,%rdx
  746. and \$15,%rcx # length residue
  747. and \$-16,%rdx
  748. mov $key,$_key
  749. lea ($inp,%rdx),%rdx
  750. mov %rdx,$_end
  751. mov %rcx,$_res
  752. mov (%rbx),%rax # load IV
  753. mov 8(%rbx),%rbx
  754. jmp .Lcbc_dloop
  755. .align 16
  756. .Lcbc_dloop:
  757. mov 0($inp),@S[0]
  758. mov 4($inp),@S[1]
  759. mov 8($inp),@S[2]
  760. bswap @S[0]
  761. mov 12($inp),@S[3]
  762. bswap @S[1]
  763. mov %rax,0+$ivec # save IV to temporary storage
  764. bswap @S[2]
  765. mov %rbx,8+$ivec
  766. bswap @S[3]
  767. call _x86_64_Camellia_decrypt
  768. mov $_key,$key # "rewind" the key
  769. mov $_end,%rdx
  770. mov $_res,%rcx
  771. bswap @S[0]
  772. mov ($inp),%rax # load IV for next iteration
  773. bswap @S[1]
  774. mov 8($inp),%rbx
  775. bswap @S[2]
  776. xor 0+$ivec,@S[0]
  777. bswap @S[3]
  778. xor 4+$ivec,@S[1]
  779. xor 8+$ivec,@S[2]
  780. lea 16($inp),$inp
  781. xor 12+$ivec,@S[3]
  782. cmp %rdx,$inp
  783. je .Lcbc_ddone
  784. mov @S[0],0($out)
  785. mov @S[1],4($out)
  786. mov @S[2],8($out)
  787. mov @S[3],12($out)
  788. lea 16($out),$out
  789. jmp .Lcbc_dloop
  790. .align 16
  791. .Lcbc_ddone:
  792. mov $_ivp,%rdx
  793. cmp \$0,%rcx
  794. jne .Lcbc_dec_tail
  795. mov @S[0],0($out)
  796. mov @S[1],4($out)
  797. mov @S[2],8($out)
  798. mov @S[3],12($out)
  799. mov %rax,(%rdx) # write out IV residue
  800. mov %rbx,8(%rdx)
  801. jmp .Lcbc_done
  802. .align 16
  803. .Lcbc_dec_tail:
  804. mov @S[0],0+$ivec
  805. mov @S[1],4+$ivec
  806. mov @S[2],8+$ivec
  807. mov @S[3],12+$ivec
  808. .Lcbc_dec_pushf:
  809. pushfq
  810. cld
  811. lea 8+$ivec,%rsi
  812. lea ($out),%rdi
  813. .long 0x9066A4F3 # rep movsb
  814. popfq
  815. .Lcbc_dec_popf:
  816. mov %rax,(%rdx) # write out IV residue
  817. mov %rbx,8(%rdx)
  818. jmp .Lcbc_done
  819. .align 16
  820. .Lcbc_done:
  821. mov $_rsp,%rcx
  822. .cfi_def_cfa %rcx,56
  823. mov 0(%rcx),%r15
  824. .cfi_restore %r15
  825. mov 8(%rcx),%r14
  826. .cfi_restore %r14
  827. mov 16(%rcx),%r13
  828. .cfi_restore %r13
  829. mov 24(%rcx),%r12
  830. .cfi_restore %r12
  831. mov 32(%rcx),%rbp
  832. .cfi_restore %rbp
  833. mov 40(%rcx),%rbx
  834. .cfi_restore %rbx
  835. lea 48(%rcx),%rsp
  836. .cfi_def_cfa %rsp,8
  837. .Lcbc_abort:
  838. ret
  839. .cfi_endproc
  840. .size Camellia_cbc_encrypt,.-Camellia_cbc_encrypt
  841. .asciz "Camellia for x86_64 by <appro\@openssl.org>"
  842. ___
  843. }
  844. # EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
  845. # CONTEXT *context,DISPATCHER_CONTEXT *disp)
  846. if ($win64) {
  847. $rec="%rcx";
  848. $frame="%rdx";
  849. $context="%r8";
  850. $disp="%r9";
  851. $code.=<<___;
  852. .extern __imp_RtlVirtualUnwind
  853. .type common_se_handler,\@abi-omnipotent
  854. .align 16
  855. common_se_handler:
  856. push %rsi
  857. push %rdi
  858. push %rbx
  859. push %rbp
  860. push %r12
  861. push %r13
  862. push %r14
  863. push %r15
  864. pushfq
  865. lea -64(%rsp),%rsp
  866. mov 120($context),%rax # pull context->Rax
  867. mov 248($context),%rbx # pull context->Rip
  868. mov 8($disp),%rsi # disp->ImageBase
  869. mov 56($disp),%r11 # disp->HandlerData
  870. mov 0(%r11),%r10d # HandlerData[0]
  871. lea (%rsi,%r10),%r10 # prologue label
  872. cmp %r10,%rbx # context->Rip<prologue label
  873. jb .Lin_prologue
  874. mov 152($context),%rax # pull context->Rsp
  875. mov 4(%r11),%r10d # HandlerData[1]
  876. lea (%rsi,%r10),%r10 # epilogue label
  877. cmp %r10,%rbx # context->Rip>=epilogue label
  878. jae .Lin_prologue
  879. lea 40(%rax),%rax
  880. mov -8(%rax),%rbx
  881. mov -16(%rax),%rbp
  882. mov -24(%rax),%r13
  883. mov -32(%rax),%r14
  884. mov -40(%rax),%r15
  885. mov %rbx,144($context) # restore context->Rbx
  886. mov %rbp,160($context) # restore context->Rbp
  887. mov %r13,224($context) # restore context->R13
  888. mov %r14,232($context) # restore context->R14
  889. mov %r15,240($context) # restore context->R15
  890. .Lin_prologue:
  891. mov 8(%rax),%rdi
  892. mov 16(%rax),%rsi
  893. mov %rax,152($context) # restore context->Rsp
  894. mov %rsi,168($context) # restore context->Rsi
  895. mov %rdi,176($context) # restore context->Rdi
  896. jmp .Lcommon_seh_exit
  897. .size common_se_handler,.-common_se_handler
  898. .type cbc_se_handler,\@abi-omnipotent
  899. .align 16
  900. cbc_se_handler:
  901. push %rsi
  902. push %rdi
  903. push %rbx
  904. push %rbp
  905. push %r12
  906. push %r13
  907. push %r14
  908. push %r15
  909. pushfq
  910. lea -64(%rsp),%rsp
  911. mov 120($context),%rax # pull context->Rax
  912. mov 248($context),%rbx # pull context->Rip
  913. lea .Lcbc_prologue(%rip),%r10
  914. cmp %r10,%rbx # context->Rip<.Lcbc_prologue
  915. jb .Lin_cbc_prologue
  916. lea .Lcbc_body(%rip),%r10
  917. cmp %r10,%rbx # context->Rip<.Lcbc_body
  918. jb .Lin_cbc_frame_setup
  919. mov 152($context),%rax # pull context->Rsp
  920. lea .Lcbc_abort(%rip),%r10
  921. cmp %r10,%rbx # context->Rip>=.Lcbc_abort
  922. jae .Lin_cbc_prologue
  923. # handle pushf/popf in Camellia_cbc_encrypt
  924. lea .Lcbc_enc_pushf(%rip),%r10
  925. cmp %r10,%rbx # context->Rip<=.Lcbc_enc_pushf
  926. jbe .Lin_cbc_no_flag
  927. lea 8(%rax),%rax
  928. lea .Lcbc_enc_popf(%rip),%r10
  929. cmp %r10,%rbx # context->Rip<.Lcbc_enc_popf
  930. jb .Lin_cbc_no_flag
  931. lea -8(%rax),%rax
  932. lea .Lcbc_dec_pushf(%rip),%r10
  933. cmp %r10,%rbx # context->Rip<=.Lcbc_dec_pushf
  934. jbe .Lin_cbc_no_flag
  935. lea 8(%rax),%rax
  936. lea .Lcbc_dec_popf(%rip),%r10
  937. cmp %r10,%rbx # context->Rip<.Lcbc_dec_popf
  938. jb .Lin_cbc_no_flag
  939. lea -8(%rax),%rax
  940. .Lin_cbc_no_flag:
  941. mov 48(%rax),%rax # $_rsp
  942. lea 48(%rax),%rax
  943. .Lin_cbc_frame_setup:
  944. mov -8(%rax),%rbx
  945. mov -16(%rax),%rbp
  946. mov -24(%rax),%r12
  947. mov -32(%rax),%r13
  948. mov -40(%rax),%r14
  949. mov -48(%rax),%r15
  950. mov %rbx,144($context) # restore context->Rbx
  951. mov %rbp,160($context) # restore context->Rbp
  952. mov %r12,216($context) # restore context->R12
  953. mov %r13,224($context) # restore context->R13
  954. mov %r14,232($context) # restore context->R14
  955. mov %r15,240($context) # restore context->R15
  956. .Lin_cbc_prologue:
  957. mov 8(%rax),%rdi
  958. mov 16(%rax),%rsi
  959. mov %rax,152($context) # restore context->Rsp
  960. mov %rsi,168($context) # restore context->Rsi
  961. mov %rdi,176($context) # restore context->Rdi
  962. .align 4
  963. .Lcommon_seh_exit:
  964. mov 40($disp),%rdi # disp->ContextRecord
  965. mov $context,%rsi # context
  966. mov \$`1232/8`,%ecx # sizeof(CONTEXT)
  967. .long 0xa548f3fc # cld; rep movsq
  968. mov $disp,%rsi
  969. xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
  970. mov 8(%rsi),%rdx # arg2, disp->ImageBase
  971. mov 0(%rsi),%r8 # arg3, disp->ControlPc
  972. mov 16(%rsi),%r9 # arg4, disp->FunctionEntry
  973. mov 40(%rsi),%r10 # disp->ContextRecord
  974. lea 56(%rsi),%r11 # &disp->HandlerData
  975. lea 24(%rsi),%r12 # &disp->EstablisherFrame
  976. mov %r10,32(%rsp) # arg5
  977. mov %r11,40(%rsp) # arg6
  978. mov %r12,48(%rsp) # arg7
  979. mov %rcx,56(%rsp) # arg8, (NULL)
  980. call *__imp_RtlVirtualUnwind(%rip)
  981. mov \$1,%eax # ExceptionContinueSearch
  982. lea 64(%rsp),%rsp
  983. popfq
  984. pop %r15
  985. pop %r14
  986. pop %r13
  987. pop %r12
  988. pop %rbp
  989. pop %rbx
  990. pop %rdi
  991. pop %rsi
  992. ret
  993. .size cbc_se_handler,.-cbc_se_handler
  994. .section .pdata
  995. .align 4
  996. .rva .LSEH_begin_Camellia_EncryptBlock_Rounds
  997. .rva .LSEH_end_Camellia_EncryptBlock_Rounds
  998. .rva .LSEH_info_Camellia_EncryptBlock_Rounds
  999. .rva .LSEH_begin_Camellia_DecryptBlock_Rounds
  1000. .rva .LSEH_end_Camellia_DecryptBlock_Rounds
  1001. .rva .LSEH_info_Camellia_DecryptBlock_Rounds
  1002. .rva .LSEH_begin_Camellia_Ekeygen
  1003. .rva .LSEH_end_Camellia_Ekeygen
  1004. .rva .LSEH_info_Camellia_Ekeygen
  1005. .rva .LSEH_begin_Camellia_cbc_encrypt
  1006. .rva .LSEH_end_Camellia_cbc_encrypt
  1007. .rva .LSEH_info_Camellia_cbc_encrypt
  1008. .section .xdata
  1009. .align 8
  1010. .LSEH_info_Camellia_EncryptBlock_Rounds:
  1011. .byte 9,0,0,0
  1012. .rva common_se_handler
  1013. .rva .Lenc_prologue,.Lenc_epilogue # HandlerData[]
  1014. .LSEH_info_Camellia_DecryptBlock_Rounds:
  1015. .byte 9,0,0,0
  1016. .rva common_se_handler
  1017. .rva .Ldec_prologue,.Ldec_epilogue # HandlerData[]
  1018. .LSEH_info_Camellia_Ekeygen:
  1019. .byte 9,0,0,0
  1020. .rva common_se_handler
  1021. .rva .Lkey_prologue,.Lkey_epilogue # HandlerData[]
  1022. .LSEH_info_Camellia_cbc_encrypt:
  1023. .byte 9,0,0,0
  1024. .rva cbc_se_handler
  1025. ___
  1026. }
  1027. $code =~ s/\`([^\`]*)\`/eval $1/gem;
  1028. print $code;
  1029. close STDOUT or die "error closing STDOUT: $!";