cmll-x86_64.pl 27 KB

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