camellia-aesni-avx2-asm_64.S 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  1. /*
  2. * x86_64/AVX2/AES-NI assembler implementation of Camellia
  3. *
  4. * Copyright © 2013 Jussi Kivilinna <jussi.kivilinna@iki.fi>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. */
  12. #include <linux/linkage.h>
  13. #include <asm/nospec-branch.h>
  14. #define CAMELLIA_TABLE_BYTE_LEN 272
  15. /* struct camellia_ctx: */
  16. #define key_table 0
  17. #define key_length CAMELLIA_TABLE_BYTE_LEN
  18. /* register macros */
  19. #define CTX %rdi
  20. #define RIO %r8
  21. /**********************************************************************
  22. helper macros
  23. **********************************************************************/
  24. #define filter_8bit(x, lo_t, hi_t, mask4bit, tmp0) \
  25. vpand x, mask4bit, tmp0; \
  26. vpandn x, mask4bit, x; \
  27. vpsrld $4, x, x; \
  28. \
  29. vpshufb tmp0, lo_t, tmp0; \
  30. vpshufb x, hi_t, x; \
  31. vpxor tmp0, x, x;
  32. #define ymm0_x xmm0
  33. #define ymm1_x xmm1
  34. #define ymm2_x xmm2
  35. #define ymm3_x xmm3
  36. #define ymm4_x xmm4
  37. #define ymm5_x xmm5
  38. #define ymm6_x xmm6
  39. #define ymm7_x xmm7
  40. #define ymm8_x xmm8
  41. #define ymm9_x xmm9
  42. #define ymm10_x xmm10
  43. #define ymm11_x xmm11
  44. #define ymm12_x xmm12
  45. #define ymm13_x xmm13
  46. #define ymm14_x xmm14
  47. #define ymm15_x xmm15
  48. /**********************************************************************
  49. 32-way camellia
  50. **********************************************************************/
  51. /*
  52. * IN:
  53. * x0..x7: byte-sliced AB state
  54. * mem_cd: register pointer storing CD state
  55. * key: index for key material
  56. * OUT:
  57. * x0..x7: new byte-sliced CD state
  58. */
  59. #define roundsm32(x0, x1, x2, x3, x4, x5, x6, x7, t0, t1, t2, t3, t4, t5, t6, \
  60. t7, mem_cd, key) \
  61. /* \
  62. * S-function with AES subbytes \
  63. */ \
  64. vbroadcasti128 .Linv_shift_row, t4; \
  65. vpbroadcastd .L0f0f0f0f, t7; \
  66. vbroadcasti128 .Lpre_tf_lo_s1, t5; \
  67. vbroadcasti128 .Lpre_tf_hi_s1, t6; \
  68. vbroadcasti128 .Lpre_tf_lo_s4, t2; \
  69. vbroadcasti128 .Lpre_tf_hi_s4, t3; \
  70. \
  71. /* AES inverse shift rows */ \
  72. vpshufb t4, x0, x0; \
  73. vpshufb t4, x7, x7; \
  74. vpshufb t4, x3, x3; \
  75. vpshufb t4, x6, x6; \
  76. vpshufb t4, x2, x2; \
  77. vpshufb t4, x5, x5; \
  78. vpshufb t4, x1, x1; \
  79. vpshufb t4, x4, x4; \
  80. \
  81. /* prefilter sboxes 1, 2 and 3 */ \
  82. /* prefilter sbox 4 */ \
  83. filter_8bit(x0, t5, t6, t7, t4); \
  84. filter_8bit(x7, t5, t6, t7, t4); \
  85. vextracti128 $1, x0, t0##_x; \
  86. vextracti128 $1, x7, t1##_x; \
  87. filter_8bit(x3, t2, t3, t7, t4); \
  88. filter_8bit(x6, t2, t3, t7, t4); \
  89. vextracti128 $1, x3, t3##_x; \
  90. vextracti128 $1, x6, t2##_x; \
  91. filter_8bit(x2, t5, t6, t7, t4); \
  92. filter_8bit(x5, t5, t6, t7, t4); \
  93. filter_8bit(x1, t5, t6, t7, t4); \
  94. filter_8bit(x4, t5, t6, t7, t4); \
  95. \
  96. vpxor t4##_x, t4##_x, t4##_x; \
  97. \
  98. /* AES subbytes + AES shift rows */ \
  99. vextracti128 $1, x2, t6##_x; \
  100. vextracti128 $1, x5, t5##_x; \
  101. vaesenclast t4##_x, x0##_x, x0##_x; \
  102. vaesenclast t4##_x, t0##_x, t0##_x; \
  103. vinserti128 $1, t0##_x, x0, x0; \
  104. vaesenclast t4##_x, x7##_x, x7##_x; \
  105. vaesenclast t4##_x, t1##_x, t1##_x; \
  106. vinserti128 $1, t1##_x, x7, x7; \
  107. vaesenclast t4##_x, x3##_x, x3##_x; \
  108. vaesenclast t4##_x, t3##_x, t3##_x; \
  109. vinserti128 $1, t3##_x, x3, x3; \
  110. vaesenclast t4##_x, x6##_x, x6##_x; \
  111. vaesenclast t4##_x, t2##_x, t2##_x; \
  112. vinserti128 $1, t2##_x, x6, x6; \
  113. vextracti128 $1, x1, t3##_x; \
  114. vextracti128 $1, x4, t2##_x; \
  115. vbroadcasti128 .Lpost_tf_lo_s1, t0; \
  116. vbroadcasti128 .Lpost_tf_hi_s1, t1; \
  117. vaesenclast t4##_x, x2##_x, x2##_x; \
  118. vaesenclast t4##_x, t6##_x, t6##_x; \
  119. vinserti128 $1, t6##_x, x2, x2; \
  120. vaesenclast t4##_x, x5##_x, x5##_x; \
  121. vaesenclast t4##_x, t5##_x, t5##_x; \
  122. vinserti128 $1, t5##_x, x5, x5; \
  123. vaesenclast t4##_x, x1##_x, x1##_x; \
  124. vaesenclast t4##_x, t3##_x, t3##_x; \
  125. vinserti128 $1, t3##_x, x1, x1; \
  126. vaesenclast t4##_x, x4##_x, x4##_x; \
  127. vaesenclast t4##_x, t2##_x, t2##_x; \
  128. vinserti128 $1, t2##_x, x4, x4; \
  129. \
  130. /* postfilter sboxes 1 and 4 */ \
  131. vbroadcasti128 .Lpost_tf_lo_s3, t2; \
  132. vbroadcasti128 .Lpost_tf_hi_s3, t3; \
  133. filter_8bit(x0, t0, t1, t7, t6); \
  134. filter_8bit(x7, t0, t1, t7, t6); \
  135. filter_8bit(x3, t0, t1, t7, t6); \
  136. filter_8bit(x6, t0, t1, t7, t6); \
  137. \
  138. /* postfilter sbox 3 */ \
  139. vbroadcasti128 .Lpost_tf_lo_s2, t4; \
  140. vbroadcasti128 .Lpost_tf_hi_s2, t5; \
  141. filter_8bit(x2, t2, t3, t7, t6); \
  142. filter_8bit(x5, t2, t3, t7, t6); \
  143. \
  144. vpbroadcastq key, t0; /* higher 64-bit duplicate ignored */ \
  145. \
  146. /* postfilter sbox 2 */ \
  147. filter_8bit(x1, t4, t5, t7, t2); \
  148. filter_8bit(x4, t4, t5, t7, t2); \
  149. vpxor t7, t7, t7; \
  150. \
  151. vpsrldq $1, t0, t1; \
  152. vpsrldq $2, t0, t2; \
  153. vpshufb t7, t1, t1; \
  154. vpsrldq $3, t0, t3; \
  155. \
  156. /* P-function */ \
  157. vpxor x5, x0, x0; \
  158. vpxor x6, x1, x1; \
  159. vpxor x7, x2, x2; \
  160. vpxor x4, x3, x3; \
  161. \
  162. vpshufb t7, t2, t2; \
  163. vpsrldq $4, t0, t4; \
  164. vpshufb t7, t3, t3; \
  165. vpsrldq $5, t0, t5; \
  166. vpshufb t7, t4, t4; \
  167. \
  168. vpxor x2, x4, x4; \
  169. vpxor x3, x5, x5; \
  170. vpxor x0, x6, x6; \
  171. vpxor x1, x7, x7; \
  172. \
  173. vpsrldq $6, t0, t6; \
  174. vpshufb t7, t5, t5; \
  175. vpshufb t7, t6, t6; \
  176. \
  177. vpxor x7, x0, x0; \
  178. vpxor x4, x1, x1; \
  179. vpxor x5, x2, x2; \
  180. vpxor x6, x3, x3; \
  181. \
  182. vpxor x3, x4, x4; \
  183. vpxor x0, x5, x5; \
  184. vpxor x1, x6, x6; \
  185. vpxor x2, x7, x7; /* note: high and low parts swapped */ \
  186. \
  187. /* Add key material and result to CD (x becomes new CD) */ \
  188. \
  189. vpxor t6, x1, x1; \
  190. vpxor 5 * 32(mem_cd), x1, x1; \
  191. \
  192. vpsrldq $7, t0, t6; \
  193. vpshufb t7, t0, t0; \
  194. vpshufb t7, t6, t7; \
  195. \
  196. vpxor t7, x0, x0; \
  197. vpxor 4 * 32(mem_cd), x0, x0; \
  198. \
  199. vpxor t5, x2, x2; \
  200. vpxor 6 * 32(mem_cd), x2, x2; \
  201. \
  202. vpxor t4, x3, x3; \
  203. vpxor 7 * 32(mem_cd), x3, x3; \
  204. \
  205. vpxor t3, x4, x4; \
  206. vpxor 0 * 32(mem_cd), x4, x4; \
  207. \
  208. vpxor t2, x5, x5; \
  209. vpxor 1 * 32(mem_cd), x5, x5; \
  210. \
  211. vpxor t1, x6, x6; \
  212. vpxor 2 * 32(mem_cd), x6, x6; \
  213. \
  214. vpxor t0, x7, x7; \
  215. vpxor 3 * 32(mem_cd), x7, x7;
  216. /*
  217. * Size optimization... with inlined roundsm32 binary would be over 5 times
  218. * larger and would only marginally faster.
  219. */
  220. .align 8
  221. roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
  222. roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  223. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
  224. %rcx, (%r9));
  225. ret;
  226. ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
  227. .align 8
  228. roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
  229. roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
  230. %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
  231. %rax, (%r9));
  232. ret;
  233. ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
  234. /*
  235. * IN/OUT:
  236. * x0..x7: byte-sliced AB state preloaded
  237. * mem_ab: byte-sliced AB state in memory
  238. * mem_cb: byte-sliced CD state in memory
  239. */
  240. #define two_roundsm32(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  241. y6, y7, mem_ab, mem_cd, i, dir, store_ab) \
  242. leaq (key_table + (i) * 8)(CTX), %r9; \
  243. call roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd; \
  244. \
  245. vmovdqu x0, 4 * 32(mem_cd); \
  246. vmovdqu x1, 5 * 32(mem_cd); \
  247. vmovdqu x2, 6 * 32(mem_cd); \
  248. vmovdqu x3, 7 * 32(mem_cd); \
  249. vmovdqu x4, 0 * 32(mem_cd); \
  250. vmovdqu x5, 1 * 32(mem_cd); \
  251. vmovdqu x6, 2 * 32(mem_cd); \
  252. vmovdqu x7, 3 * 32(mem_cd); \
  253. \
  254. leaq (key_table + ((i) + (dir)) * 8)(CTX), %r9; \
  255. call roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab; \
  256. \
  257. store_ab(x0, x1, x2, x3, x4, x5, x6, x7, mem_ab);
  258. #define dummy_store(x0, x1, x2, x3, x4, x5, x6, x7, mem_ab) /* do nothing */
  259. #define store_ab_state(x0, x1, x2, x3, x4, x5, x6, x7, mem_ab) \
  260. /* Store new AB state */ \
  261. vmovdqu x4, 4 * 32(mem_ab); \
  262. vmovdqu x5, 5 * 32(mem_ab); \
  263. vmovdqu x6, 6 * 32(mem_ab); \
  264. vmovdqu x7, 7 * 32(mem_ab); \
  265. vmovdqu x0, 0 * 32(mem_ab); \
  266. vmovdqu x1, 1 * 32(mem_ab); \
  267. vmovdqu x2, 2 * 32(mem_ab); \
  268. vmovdqu x3, 3 * 32(mem_ab);
  269. #define enc_rounds32(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  270. y6, y7, mem_ab, mem_cd, i) \
  271. two_roundsm32(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  272. y6, y7, mem_ab, mem_cd, (i) + 2, 1, store_ab_state); \
  273. two_roundsm32(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  274. y6, y7, mem_ab, mem_cd, (i) + 4, 1, store_ab_state); \
  275. two_roundsm32(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  276. y6, y7, mem_ab, mem_cd, (i) + 6, 1, dummy_store);
  277. #define dec_rounds32(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  278. y6, y7, mem_ab, mem_cd, i) \
  279. two_roundsm32(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  280. y6, y7, mem_ab, mem_cd, (i) + 7, -1, store_ab_state); \
  281. two_roundsm32(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  282. y6, y7, mem_ab, mem_cd, (i) + 5, -1, store_ab_state); \
  283. two_roundsm32(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  284. y6, y7, mem_ab, mem_cd, (i) + 3, -1, dummy_store);
  285. /*
  286. * IN:
  287. * v0..3: byte-sliced 32-bit integers
  288. * OUT:
  289. * v0..3: (IN <<< 1)
  290. */
  291. #define rol32_1_32(v0, v1, v2, v3, t0, t1, t2, zero) \
  292. vpcmpgtb v0, zero, t0; \
  293. vpaddb v0, v0, v0; \
  294. vpabsb t0, t0; \
  295. \
  296. vpcmpgtb v1, zero, t1; \
  297. vpaddb v1, v1, v1; \
  298. vpabsb t1, t1; \
  299. \
  300. vpcmpgtb v2, zero, t2; \
  301. vpaddb v2, v2, v2; \
  302. vpabsb t2, t2; \
  303. \
  304. vpor t0, v1, v1; \
  305. \
  306. vpcmpgtb v3, zero, t0; \
  307. vpaddb v3, v3, v3; \
  308. vpabsb t0, t0; \
  309. \
  310. vpor t1, v2, v2; \
  311. vpor t2, v3, v3; \
  312. vpor t0, v0, v0;
  313. /*
  314. * IN:
  315. * r: byte-sliced AB state in memory
  316. * l: byte-sliced CD state in memory
  317. * OUT:
  318. * x0..x7: new byte-sliced CD state
  319. */
  320. #define fls32(l, l0, l1, l2, l3, l4, l5, l6, l7, r, t0, t1, t2, t3, tt0, \
  321. tt1, tt2, tt3, kll, klr, krl, krr) \
  322. /* \
  323. * t0 = kll; \
  324. * t0 &= ll; \
  325. * lr ^= rol32(t0, 1); \
  326. */ \
  327. vpbroadcastd kll, t0; /* only lowest 32-bit used */ \
  328. vpxor tt0, tt0, tt0; \
  329. vpshufb tt0, t0, t3; \
  330. vpsrldq $1, t0, t0; \
  331. vpshufb tt0, t0, t2; \
  332. vpsrldq $1, t0, t0; \
  333. vpshufb tt0, t0, t1; \
  334. vpsrldq $1, t0, t0; \
  335. vpshufb tt0, t0, t0; \
  336. \
  337. vpand l0, t0, t0; \
  338. vpand l1, t1, t1; \
  339. vpand l2, t2, t2; \
  340. vpand l3, t3, t3; \
  341. \
  342. rol32_1_32(t3, t2, t1, t0, tt1, tt2, tt3, tt0); \
  343. \
  344. vpxor l4, t0, l4; \
  345. vpbroadcastd krr, t0; /* only lowest 32-bit used */ \
  346. vmovdqu l4, 4 * 32(l); \
  347. vpxor l5, t1, l5; \
  348. vmovdqu l5, 5 * 32(l); \
  349. vpxor l6, t2, l6; \
  350. vmovdqu l6, 6 * 32(l); \
  351. vpxor l7, t3, l7; \
  352. vmovdqu l7, 7 * 32(l); \
  353. \
  354. /* \
  355. * t2 = krr; \
  356. * t2 |= rr; \
  357. * rl ^= t2; \
  358. */ \
  359. \
  360. vpshufb tt0, t0, t3; \
  361. vpsrldq $1, t0, t0; \
  362. vpshufb tt0, t0, t2; \
  363. vpsrldq $1, t0, t0; \
  364. vpshufb tt0, t0, t1; \
  365. vpsrldq $1, t0, t0; \
  366. vpshufb tt0, t0, t0; \
  367. \
  368. vpor 4 * 32(r), t0, t0; \
  369. vpor 5 * 32(r), t1, t1; \
  370. vpor 6 * 32(r), t2, t2; \
  371. vpor 7 * 32(r), t3, t3; \
  372. \
  373. vpxor 0 * 32(r), t0, t0; \
  374. vpxor 1 * 32(r), t1, t1; \
  375. vpxor 2 * 32(r), t2, t2; \
  376. vpxor 3 * 32(r), t3, t3; \
  377. vmovdqu t0, 0 * 32(r); \
  378. vpbroadcastd krl, t0; /* only lowest 32-bit used */ \
  379. vmovdqu t1, 1 * 32(r); \
  380. vmovdqu t2, 2 * 32(r); \
  381. vmovdqu t3, 3 * 32(r); \
  382. \
  383. /* \
  384. * t2 = krl; \
  385. * t2 &= rl; \
  386. * rr ^= rol32(t2, 1); \
  387. */ \
  388. vpshufb tt0, t0, t3; \
  389. vpsrldq $1, t0, t0; \
  390. vpshufb tt0, t0, t2; \
  391. vpsrldq $1, t0, t0; \
  392. vpshufb tt0, t0, t1; \
  393. vpsrldq $1, t0, t0; \
  394. vpshufb tt0, t0, t0; \
  395. \
  396. vpand 0 * 32(r), t0, t0; \
  397. vpand 1 * 32(r), t1, t1; \
  398. vpand 2 * 32(r), t2, t2; \
  399. vpand 3 * 32(r), t3, t3; \
  400. \
  401. rol32_1_32(t3, t2, t1, t0, tt1, tt2, tt3, tt0); \
  402. \
  403. vpxor 4 * 32(r), t0, t0; \
  404. vpxor 5 * 32(r), t1, t1; \
  405. vpxor 6 * 32(r), t2, t2; \
  406. vpxor 7 * 32(r), t3, t3; \
  407. vmovdqu t0, 4 * 32(r); \
  408. vpbroadcastd klr, t0; /* only lowest 32-bit used */ \
  409. vmovdqu t1, 5 * 32(r); \
  410. vmovdqu t2, 6 * 32(r); \
  411. vmovdqu t3, 7 * 32(r); \
  412. \
  413. /* \
  414. * t0 = klr; \
  415. * t0 |= lr; \
  416. * ll ^= t0; \
  417. */ \
  418. \
  419. vpshufb tt0, t0, t3; \
  420. vpsrldq $1, t0, t0; \
  421. vpshufb tt0, t0, t2; \
  422. vpsrldq $1, t0, t0; \
  423. vpshufb tt0, t0, t1; \
  424. vpsrldq $1, t0, t0; \
  425. vpshufb tt0, t0, t0; \
  426. \
  427. vpor l4, t0, t0; \
  428. vpor l5, t1, t1; \
  429. vpor l6, t2, t2; \
  430. vpor l7, t3, t3; \
  431. \
  432. vpxor l0, t0, l0; \
  433. vmovdqu l0, 0 * 32(l); \
  434. vpxor l1, t1, l1; \
  435. vmovdqu l1, 1 * 32(l); \
  436. vpxor l2, t2, l2; \
  437. vmovdqu l2, 2 * 32(l); \
  438. vpxor l3, t3, l3; \
  439. vmovdqu l3, 3 * 32(l);
  440. #define transpose_4x4(x0, x1, x2, x3, t1, t2) \
  441. vpunpckhdq x1, x0, t2; \
  442. vpunpckldq x1, x0, x0; \
  443. \
  444. vpunpckldq x3, x2, t1; \
  445. vpunpckhdq x3, x2, x2; \
  446. \
  447. vpunpckhqdq t1, x0, x1; \
  448. vpunpcklqdq t1, x0, x0; \
  449. \
  450. vpunpckhqdq x2, t2, x3; \
  451. vpunpcklqdq x2, t2, x2;
  452. #define byteslice_16x16b_fast(a0, b0, c0, d0, a1, b1, c1, d1, a2, b2, c2, d2, \
  453. a3, b3, c3, d3, st0, st1) \
  454. vmovdqu d2, st0; \
  455. vmovdqu d3, st1; \
  456. transpose_4x4(a0, a1, a2, a3, d2, d3); \
  457. transpose_4x4(b0, b1, b2, b3, d2, d3); \
  458. vmovdqu st0, d2; \
  459. vmovdqu st1, d3; \
  460. \
  461. vmovdqu a0, st0; \
  462. vmovdqu a1, st1; \
  463. transpose_4x4(c0, c1, c2, c3, a0, a1); \
  464. transpose_4x4(d0, d1, d2, d3, a0, a1); \
  465. \
  466. vbroadcasti128 .Lshufb_16x16b, a0; \
  467. vmovdqu st1, a1; \
  468. vpshufb a0, a2, a2; \
  469. vpshufb a0, a3, a3; \
  470. vpshufb a0, b0, b0; \
  471. vpshufb a0, b1, b1; \
  472. vpshufb a0, b2, b2; \
  473. vpshufb a0, b3, b3; \
  474. vpshufb a0, a1, a1; \
  475. vpshufb a0, c0, c0; \
  476. vpshufb a0, c1, c1; \
  477. vpshufb a0, c2, c2; \
  478. vpshufb a0, c3, c3; \
  479. vpshufb a0, d0, d0; \
  480. vpshufb a0, d1, d1; \
  481. vpshufb a0, d2, d2; \
  482. vpshufb a0, d3, d3; \
  483. vmovdqu d3, st1; \
  484. vmovdqu st0, d3; \
  485. vpshufb a0, d3, a0; \
  486. vmovdqu d2, st0; \
  487. \
  488. transpose_4x4(a0, b0, c0, d0, d2, d3); \
  489. transpose_4x4(a1, b1, c1, d1, d2, d3); \
  490. vmovdqu st0, d2; \
  491. vmovdqu st1, d3; \
  492. \
  493. vmovdqu b0, st0; \
  494. vmovdqu b1, st1; \
  495. transpose_4x4(a2, b2, c2, d2, b0, b1); \
  496. transpose_4x4(a3, b3, c3, d3, b0, b1); \
  497. vmovdqu st0, b0; \
  498. vmovdqu st1, b1; \
  499. /* does not adjust output bytes inside vectors */
  500. /* load blocks to registers and apply pre-whitening */
  501. #define inpack32_pre(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  502. y6, y7, rio, key) \
  503. vpbroadcastq key, x0; \
  504. vpshufb .Lpack_bswap, x0, x0; \
  505. \
  506. vpxor 0 * 32(rio), x0, y7; \
  507. vpxor 1 * 32(rio), x0, y6; \
  508. vpxor 2 * 32(rio), x0, y5; \
  509. vpxor 3 * 32(rio), x0, y4; \
  510. vpxor 4 * 32(rio), x0, y3; \
  511. vpxor 5 * 32(rio), x0, y2; \
  512. vpxor 6 * 32(rio), x0, y1; \
  513. vpxor 7 * 32(rio), x0, y0; \
  514. vpxor 8 * 32(rio), x0, x7; \
  515. vpxor 9 * 32(rio), x0, x6; \
  516. vpxor 10 * 32(rio), x0, x5; \
  517. vpxor 11 * 32(rio), x0, x4; \
  518. vpxor 12 * 32(rio), x0, x3; \
  519. vpxor 13 * 32(rio), x0, x2; \
  520. vpxor 14 * 32(rio), x0, x1; \
  521. vpxor 15 * 32(rio), x0, x0;
  522. /* byteslice pre-whitened blocks and store to temporary memory */
  523. #define inpack32_post(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  524. y6, y7, mem_ab, mem_cd) \
  525. byteslice_16x16b_fast(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, \
  526. y4, y5, y6, y7, (mem_ab), (mem_cd)); \
  527. \
  528. vmovdqu x0, 0 * 32(mem_ab); \
  529. vmovdqu x1, 1 * 32(mem_ab); \
  530. vmovdqu x2, 2 * 32(mem_ab); \
  531. vmovdqu x3, 3 * 32(mem_ab); \
  532. vmovdqu x4, 4 * 32(mem_ab); \
  533. vmovdqu x5, 5 * 32(mem_ab); \
  534. vmovdqu x6, 6 * 32(mem_ab); \
  535. vmovdqu x7, 7 * 32(mem_ab); \
  536. vmovdqu y0, 0 * 32(mem_cd); \
  537. vmovdqu y1, 1 * 32(mem_cd); \
  538. vmovdqu y2, 2 * 32(mem_cd); \
  539. vmovdqu y3, 3 * 32(mem_cd); \
  540. vmovdqu y4, 4 * 32(mem_cd); \
  541. vmovdqu y5, 5 * 32(mem_cd); \
  542. vmovdqu y6, 6 * 32(mem_cd); \
  543. vmovdqu y7, 7 * 32(mem_cd);
  544. /* de-byteslice, apply post-whitening and store blocks */
  545. #define outunpack32(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, \
  546. y5, y6, y7, key, stack_tmp0, stack_tmp1) \
  547. byteslice_16x16b_fast(y0, y4, x0, x4, y1, y5, x1, x5, y2, y6, x2, x6, \
  548. y3, y7, x3, x7, stack_tmp0, stack_tmp1); \
  549. \
  550. vmovdqu x0, stack_tmp0; \
  551. \
  552. vpbroadcastq key, x0; \
  553. vpshufb .Lpack_bswap, x0, x0; \
  554. \
  555. vpxor x0, y7, y7; \
  556. vpxor x0, y6, y6; \
  557. vpxor x0, y5, y5; \
  558. vpxor x0, y4, y4; \
  559. vpxor x0, y3, y3; \
  560. vpxor x0, y2, y2; \
  561. vpxor x0, y1, y1; \
  562. vpxor x0, y0, y0; \
  563. vpxor x0, x7, x7; \
  564. vpxor x0, x6, x6; \
  565. vpxor x0, x5, x5; \
  566. vpxor x0, x4, x4; \
  567. vpxor x0, x3, x3; \
  568. vpxor x0, x2, x2; \
  569. vpxor x0, x1, x1; \
  570. vpxor stack_tmp0, x0, x0;
  571. #define write_output(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \
  572. y6, y7, rio) \
  573. vmovdqu x0, 0 * 32(rio); \
  574. vmovdqu x1, 1 * 32(rio); \
  575. vmovdqu x2, 2 * 32(rio); \
  576. vmovdqu x3, 3 * 32(rio); \
  577. vmovdqu x4, 4 * 32(rio); \
  578. vmovdqu x5, 5 * 32(rio); \
  579. vmovdqu x6, 6 * 32(rio); \
  580. vmovdqu x7, 7 * 32(rio); \
  581. vmovdqu y0, 8 * 32(rio); \
  582. vmovdqu y1, 9 * 32(rio); \
  583. vmovdqu y2, 10 * 32(rio); \
  584. vmovdqu y3, 11 * 32(rio); \
  585. vmovdqu y4, 12 * 32(rio); \
  586. vmovdqu y5, 13 * 32(rio); \
  587. vmovdqu y6, 14 * 32(rio); \
  588. vmovdqu y7, 15 * 32(rio);
  589. .data
  590. .align 32
  591. #define SHUFB_BYTES(idx) \
  592. 0 + (idx), 4 + (idx), 8 + (idx), 12 + (idx)
  593. .Lshufb_16x16b:
  594. .byte SHUFB_BYTES(0), SHUFB_BYTES(1), SHUFB_BYTES(2), SHUFB_BYTES(3)
  595. .byte SHUFB_BYTES(0), SHUFB_BYTES(1), SHUFB_BYTES(2), SHUFB_BYTES(3)
  596. .Lpack_bswap:
  597. .long 0x00010203, 0x04050607, 0x80808080, 0x80808080
  598. .long 0x00010203, 0x04050607, 0x80808080, 0x80808080
  599. /* For CTR-mode IV byteswap */
  600. .Lbswap128_mask:
  601. .byte 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
  602. /* For XTS mode */
  603. .Lxts_gf128mul_and_shl1_mask_0:
  604. .byte 0x87, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0
  605. .Lxts_gf128mul_and_shl1_mask_1:
  606. .byte 0x0e, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0
  607. /*
  608. * pre-SubByte transform
  609. *
  610. * pre-lookup for sbox1, sbox2, sbox3:
  611. * swap_bitendianness(
  612. * isom_map_camellia_to_aes(
  613. * camellia_f(
  614. * swap_bitendianess(in)
  615. * )
  616. * )
  617. * )
  618. *
  619. * (note: '⊕ 0xc5' inside camellia_f())
  620. */
  621. .Lpre_tf_lo_s1:
  622. .byte 0x45, 0xe8, 0x40, 0xed, 0x2e, 0x83, 0x2b, 0x86
  623. .byte 0x4b, 0xe6, 0x4e, 0xe3, 0x20, 0x8d, 0x25, 0x88
  624. .Lpre_tf_hi_s1:
  625. .byte 0x00, 0x51, 0xf1, 0xa0, 0x8a, 0xdb, 0x7b, 0x2a
  626. .byte 0x09, 0x58, 0xf8, 0xa9, 0x83, 0xd2, 0x72, 0x23
  627. /*
  628. * pre-SubByte transform
  629. *
  630. * pre-lookup for sbox4:
  631. * swap_bitendianness(
  632. * isom_map_camellia_to_aes(
  633. * camellia_f(
  634. * swap_bitendianess(in <<< 1)
  635. * )
  636. * )
  637. * )
  638. *
  639. * (note: '⊕ 0xc5' inside camellia_f())
  640. */
  641. .Lpre_tf_lo_s4:
  642. .byte 0x45, 0x40, 0x2e, 0x2b, 0x4b, 0x4e, 0x20, 0x25
  643. .byte 0x14, 0x11, 0x7f, 0x7a, 0x1a, 0x1f, 0x71, 0x74
  644. .Lpre_tf_hi_s4:
  645. .byte 0x00, 0xf1, 0x8a, 0x7b, 0x09, 0xf8, 0x83, 0x72
  646. .byte 0xad, 0x5c, 0x27, 0xd6, 0xa4, 0x55, 0x2e, 0xdf
  647. /*
  648. * post-SubByte transform
  649. *
  650. * post-lookup for sbox1, sbox4:
  651. * swap_bitendianness(
  652. * camellia_h(
  653. * isom_map_aes_to_camellia(
  654. * swap_bitendianness(
  655. * aes_inverse_affine_transform(in)
  656. * )
  657. * )
  658. * )
  659. * )
  660. *
  661. * (note: '⊕ 0x6e' inside camellia_h())
  662. */
  663. .Lpost_tf_lo_s1:
  664. .byte 0x3c, 0xcc, 0xcf, 0x3f, 0x32, 0xc2, 0xc1, 0x31
  665. .byte 0xdc, 0x2c, 0x2f, 0xdf, 0xd2, 0x22, 0x21, 0xd1
  666. .Lpost_tf_hi_s1:
  667. .byte 0x00, 0xf9, 0x86, 0x7f, 0xd7, 0x2e, 0x51, 0xa8
  668. .byte 0xa4, 0x5d, 0x22, 0xdb, 0x73, 0x8a, 0xf5, 0x0c
  669. /*
  670. * post-SubByte transform
  671. *
  672. * post-lookup for sbox2:
  673. * swap_bitendianness(
  674. * camellia_h(
  675. * isom_map_aes_to_camellia(
  676. * swap_bitendianness(
  677. * aes_inverse_affine_transform(in)
  678. * )
  679. * )
  680. * )
  681. * ) <<< 1
  682. *
  683. * (note: '⊕ 0x6e' inside camellia_h())
  684. */
  685. .Lpost_tf_lo_s2:
  686. .byte 0x78, 0x99, 0x9f, 0x7e, 0x64, 0x85, 0x83, 0x62
  687. .byte 0xb9, 0x58, 0x5e, 0xbf, 0xa5, 0x44, 0x42, 0xa3
  688. .Lpost_tf_hi_s2:
  689. .byte 0x00, 0xf3, 0x0d, 0xfe, 0xaf, 0x5c, 0xa2, 0x51
  690. .byte 0x49, 0xba, 0x44, 0xb7, 0xe6, 0x15, 0xeb, 0x18
  691. /*
  692. * post-SubByte transform
  693. *
  694. * post-lookup for sbox3:
  695. * swap_bitendianness(
  696. * camellia_h(
  697. * isom_map_aes_to_camellia(
  698. * swap_bitendianness(
  699. * aes_inverse_affine_transform(in)
  700. * )
  701. * )
  702. * )
  703. * ) >>> 1
  704. *
  705. * (note: '⊕ 0x6e' inside camellia_h())
  706. */
  707. .Lpost_tf_lo_s3:
  708. .byte 0x1e, 0x66, 0xe7, 0x9f, 0x19, 0x61, 0xe0, 0x98
  709. .byte 0x6e, 0x16, 0x97, 0xef, 0x69, 0x11, 0x90, 0xe8
  710. .Lpost_tf_hi_s3:
  711. .byte 0x00, 0xfc, 0x43, 0xbf, 0xeb, 0x17, 0xa8, 0x54
  712. .byte 0x52, 0xae, 0x11, 0xed, 0xb9, 0x45, 0xfa, 0x06
  713. /* For isolating SubBytes from AESENCLAST, inverse shift row */
  714. .Linv_shift_row:
  715. .byte 0x00, 0x0d, 0x0a, 0x07, 0x04, 0x01, 0x0e, 0x0b
  716. .byte 0x08, 0x05, 0x02, 0x0f, 0x0c, 0x09, 0x06, 0x03
  717. .align 4
  718. /* 4-bit mask */
  719. .L0f0f0f0f:
  720. .long 0x0f0f0f0f
  721. .text
  722. .align 8
  723. __camellia_enc_blk32:
  724. /* input:
  725. * %rdi: ctx, CTX
  726. * %rax: temporary storage, 512 bytes
  727. * %ymm0..%ymm15: 32 plaintext blocks
  728. * output:
  729. * %ymm0..%ymm15: 32 encrypted blocks, order swapped:
  730. * 7, 8, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8
  731. */
  732. leaq 8 * 32(%rax), %rcx;
  733. inpack32_post(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  734. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  735. %ymm15, %rax, %rcx);
  736. enc_rounds32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  737. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  738. %ymm15, %rax, %rcx, 0);
  739. fls32(%rax, %ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  740. %rcx, %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  741. %ymm15,
  742. ((key_table + (8) * 8) + 0)(CTX),
  743. ((key_table + (8) * 8) + 4)(CTX),
  744. ((key_table + (8) * 8) + 8)(CTX),
  745. ((key_table + (8) * 8) + 12)(CTX));
  746. enc_rounds32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  747. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  748. %ymm15, %rax, %rcx, 8);
  749. fls32(%rax, %ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  750. %rcx, %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  751. %ymm15,
  752. ((key_table + (16) * 8) + 0)(CTX),
  753. ((key_table + (16) * 8) + 4)(CTX),
  754. ((key_table + (16) * 8) + 8)(CTX),
  755. ((key_table + (16) * 8) + 12)(CTX));
  756. enc_rounds32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  757. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  758. %ymm15, %rax, %rcx, 16);
  759. movl $24, %r8d;
  760. cmpl $16, key_length(CTX);
  761. jne .Lenc_max32;
  762. .Lenc_done:
  763. /* load CD for output */
  764. vmovdqu 0 * 32(%rcx), %ymm8;
  765. vmovdqu 1 * 32(%rcx), %ymm9;
  766. vmovdqu 2 * 32(%rcx), %ymm10;
  767. vmovdqu 3 * 32(%rcx), %ymm11;
  768. vmovdqu 4 * 32(%rcx), %ymm12;
  769. vmovdqu 5 * 32(%rcx), %ymm13;
  770. vmovdqu 6 * 32(%rcx), %ymm14;
  771. vmovdqu 7 * 32(%rcx), %ymm15;
  772. outunpack32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  773. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  774. %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
  775. ret;
  776. .align 8
  777. .Lenc_max32:
  778. movl $32, %r8d;
  779. fls32(%rax, %ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  780. %rcx, %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  781. %ymm15,
  782. ((key_table + (24) * 8) + 0)(CTX),
  783. ((key_table + (24) * 8) + 4)(CTX),
  784. ((key_table + (24) * 8) + 8)(CTX),
  785. ((key_table + (24) * 8) + 12)(CTX));
  786. enc_rounds32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  787. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  788. %ymm15, %rax, %rcx, 24);
  789. jmp .Lenc_done;
  790. ENDPROC(__camellia_enc_blk32)
  791. .align 8
  792. __camellia_dec_blk32:
  793. /* input:
  794. * %rdi: ctx, CTX
  795. * %rax: temporary storage, 512 bytes
  796. * %r8d: 24 for 16 byte key, 32 for larger
  797. * %ymm0..%ymm15: 16 encrypted blocks
  798. * output:
  799. * %ymm0..%ymm15: 16 plaintext blocks, order swapped:
  800. * 7, 8, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8
  801. */
  802. leaq 8 * 32(%rax), %rcx;
  803. inpack32_post(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  804. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  805. %ymm15, %rax, %rcx);
  806. cmpl $32, %r8d;
  807. je .Ldec_max32;
  808. .Ldec_max24:
  809. dec_rounds32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  810. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  811. %ymm15, %rax, %rcx, 16);
  812. fls32(%rax, %ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  813. %rcx, %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  814. %ymm15,
  815. ((key_table + (16) * 8) + 8)(CTX),
  816. ((key_table + (16) * 8) + 12)(CTX),
  817. ((key_table + (16) * 8) + 0)(CTX),
  818. ((key_table + (16) * 8) + 4)(CTX));
  819. dec_rounds32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  820. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  821. %ymm15, %rax, %rcx, 8);
  822. fls32(%rax, %ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  823. %rcx, %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  824. %ymm15,
  825. ((key_table + (8) * 8) + 8)(CTX),
  826. ((key_table + (8) * 8) + 12)(CTX),
  827. ((key_table + (8) * 8) + 0)(CTX),
  828. ((key_table + (8) * 8) + 4)(CTX));
  829. dec_rounds32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  830. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  831. %ymm15, %rax, %rcx, 0);
  832. /* load CD for output */
  833. vmovdqu 0 * 32(%rcx), %ymm8;
  834. vmovdqu 1 * 32(%rcx), %ymm9;
  835. vmovdqu 2 * 32(%rcx), %ymm10;
  836. vmovdqu 3 * 32(%rcx), %ymm11;
  837. vmovdqu 4 * 32(%rcx), %ymm12;
  838. vmovdqu 5 * 32(%rcx), %ymm13;
  839. vmovdqu 6 * 32(%rcx), %ymm14;
  840. vmovdqu 7 * 32(%rcx), %ymm15;
  841. outunpack32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  842. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  843. %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
  844. ret;
  845. .align 8
  846. .Ldec_max32:
  847. dec_rounds32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  848. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  849. %ymm15, %rax, %rcx, 24);
  850. fls32(%rax, %ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  851. %rcx, %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  852. %ymm15,
  853. ((key_table + (24) * 8) + 8)(CTX),
  854. ((key_table + (24) * 8) + 12)(CTX),
  855. ((key_table + (24) * 8) + 0)(CTX),
  856. ((key_table + (24) * 8) + 4)(CTX));
  857. jmp .Ldec_max24;
  858. ENDPROC(__camellia_dec_blk32)
  859. ENTRY(camellia_ecb_enc_32way)
  860. /* input:
  861. * %rdi: ctx, CTX
  862. * %rsi: dst (32 blocks)
  863. * %rdx: src (32 blocks)
  864. */
  865. vzeroupper;
  866. inpack32_pre(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  867. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  868. %ymm15, %rdx, (key_table)(CTX));
  869. /* now dst can be used as temporary buffer (even in src == dst case) */
  870. movq %rsi, %rax;
  871. call __camellia_enc_blk32;
  872. write_output(%ymm7, %ymm6, %ymm5, %ymm4, %ymm3, %ymm2, %ymm1, %ymm0,
  873. %ymm15, %ymm14, %ymm13, %ymm12, %ymm11, %ymm10, %ymm9,
  874. %ymm8, %rsi);
  875. vzeroupper;
  876. ret;
  877. ENDPROC(camellia_ecb_enc_32way)
  878. ENTRY(camellia_ecb_dec_32way)
  879. /* input:
  880. * %rdi: ctx, CTX
  881. * %rsi: dst (32 blocks)
  882. * %rdx: src (32 blocks)
  883. */
  884. vzeroupper;
  885. cmpl $16, key_length(CTX);
  886. movl $32, %r8d;
  887. movl $24, %eax;
  888. cmovel %eax, %r8d; /* max */
  889. inpack32_pre(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  890. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  891. %ymm15, %rdx, (key_table)(CTX, %r8, 8));
  892. /* now dst can be used as temporary buffer (even in src == dst case) */
  893. movq %rsi, %rax;
  894. call __camellia_dec_blk32;
  895. write_output(%ymm7, %ymm6, %ymm5, %ymm4, %ymm3, %ymm2, %ymm1, %ymm0,
  896. %ymm15, %ymm14, %ymm13, %ymm12, %ymm11, %ymm10, %ymm9,
  897. %ymm8, %rsi);
  898. vzeroupper;
  899. ret;
  900. ENDPROC(camellia_ecb_dec_32way)
  901. ENTRY(camellia_cbc_dec_32way)
  902. /* input:
  903. * %rdi: ctx, CTX
  904. * %rsi: dst (32 blocks)
  905. * %rdx: src (32 blocks)
  906. */
  907. vzeroupper;
  908. cmpl $16, key_length(CTX);
  909. movl $32, %r8d;
  910. movl $24, %eax;
  911. cmovel %eax, %r8d; /* max */
  912. inpack32_pre(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  913. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  914. %ymm15, %rdx, (key_table)(CTX, %r8, 8));
  915. movq %rsp, %r10;
  916. cmpq %rsi, %rdx;
  917. je .Lcbc_dec_use_stack;
  918. /* dst can be used as temporary storage, src is not overwritten. */
  919. movq %rsi, %rax;
  920. jmp .Lcbc_dec_continue;
  921. .Lcbc_dec_use_stack:
  922. /*
  923. * dst still in-use (because dst == src), so use stack for temporary
  924. * storage.
  925. */
  926. subq $(16 * 32), %rsp;
  927. movq %rsp, %rax;
  928. .Lcbc_dec_continue:
  929. call __camellia_dec_blk32;
  930. vmovdqu %ymm7, (%rax);
  931. vpxor %ymm7, %ymm7, %ymm7;
  932. vinserti128 $1, (%rdx), %ymm7, %ymm7;
  933. vpxor (%rax), %ymm7, %ymm7;
  934. movq %r10, %rsp;
  935. vpxor (0 * 32 + 16)(%rdx), %ymm6, %ymm6;
  936. vpxor (1 * 32 + 16)(%rdx), %ymm5, %ymm5;
  937. vpxor (2 * 32 + 16)(%rdx), %ymm4, %ymm4;
  938. vpxor (3 * 32 + 16)(%rdx), %ymm3, %ymm3;
  939. vpxor (4 * 32 + 16)(%rdx), %ymm2, %ymm2;
  940. vpxor (5 * 32 + 16)(%rdx), %ymm1, %ymm1;
  941. vpxor (6 * 32 + 16)(%rdx), %ymm0, %ymm0;
  942. vpxor (7 * 32 + 16)(%rdx), %ymm15, %ymm15;
  943. vpxor (8 * 32 + 16)(%rdx), %ymm14, %ymm14;
  944. vpxor (9 * 32 + 16)(%rdx), %ymm13, %ymm13;
  945. vpxor (10 * 32 + 16)(%rdx), %ymm12, %ymm12;
  946. vpxor (11 * 32 + 16)(%rdx), %ymm11, %ymm11;
  947. vpxor (12 * 32 + 16)(%rdx), %ymm10, %ymm10;
  948. vpxor (13 * 32 + 16)(%rdx), %ymm9, %ymm9;
  949. vpxor (14 * 32 + 16)(%rdx), %ymm8, %ymm8;
  950. write_output(%ymm7, %ymm6, %ymm5, %ymm4, %ymm3, %ymm2, %ymm1, %ymm0,
  951. %ymm15, %ymm14, %ymm13, %ymm12, %ymm11, %ymm10, %ymm9,
  952. %ymm8, %rsi);
  953. vzeroupper;
  954. ret;
  955. ENDPROC(camellia_cbc_dec_32way)
  956. #define inc_le128(x, minus_one, tmp) \
  957. vpcmpeqq minus_one, x, tmp; \
  958. vpsubq minus_one, x, x; \
  959. vpslldq $8, tmp, tmp; \
  960. vpsubq tmp, x, x;
  961. #define add2_le128(x, minus_one, minus_two, tmp1, tmp2) \
  962. vpcmpeqq minus_one, x, tmp1; \
  963. vpcmpeqq minus_two, x, tmp2; \
  964. vpsubq minus_two, x, x; \
  965. vpor tmp2, tmp1, tmp1; \
  966. vpslldq $8, tmp1, tmp1; \
  967. vpsubq tmp1, x, x;
  968. ENTRY(camellia_ctr_32way)
  969. /* input:
  970. * %rdi: ctx, CTX
  971. * %rsi: dst (32 blocks)
  972. * %rdx: src (32 blocks)
  973. * %rcx: iv (little endian, 128bit)
  974. */
  975. vzeroupper;
  976. movq %rsp, %r10;
  977. cmpq %rsi, %rdx;
  978. je .Lctr_use_stack;
  979. /* dst can be used as temporary storage, src is not overwritten. */
  980. movq %rsi, %rax;
  981. jmp .Lctr_continue;
  982. .Lctr_use_stack:
  983. subq $(16 * 32), %rsp;
  984. movq %rsp, %rax;
  985. .Lctr_continue:
  986. vpcmpeqd %ymm15, %ymm15, %ymm15;
  987. vpsrldq $8, %ymm15, %ymm15; /* ab: -1:0 ; cd: -1:0 */
  988. vpaddq %ymm15, %ymm15, %ymm12; /* ab: -2:0 ; cd: -2:0 */
  989. /* load IV and byteswap */
  990. vmovdqu (%rcx), %xmm0;
  991. vmovdqa %xmm0, %xmm1;
  992. inc_le128(%xmm0, %xmm15, %xmm14);
  993. vbroadcasti128 .Lbswap128_mask, %ymm14;
  994. vinserti128 $1, %xmm0, %ymm1, %ymm0;
  995. vpshufb %ymm14, %ymm0, %ymm13;
  996. vmovdqu %ymm13, 15 * 32(%rax);
  997. /* construct IVs */
  998. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13); /* ab:le2 ; cd:le3 */
  999. vpshufb %ymm14, %ymm0, %ymm13;
  1000. vmovdqu %ymm13, 14 * 32(%rax);
  1001. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1002. vpshufb %ymm14, %ymm0, %ymm13;
  1003. vmovdqu %ymm13, 13 * 32(%rax);
  1004. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1005. vpshufb %ymm14, %ymm0, %ymm13;
  1006. vmovdqu %ymm13, 12 * 32(%rax);
  1007. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1008. vpshufb %ymm14, %ymm0, %ymm13;
  1009. vmovdqu %ymm13, 11 * 32(%rax);
  1010. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1011. vpshufb %ymm14, %ymm0, %ymm10;
  1012. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1013. vpshufb %ymm14, %ymm0, %ymm9;
  1014. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1015. vpshufb %ymm14, %ymm0, %ymm8;
  1016. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1017. vpshufb %ymm14, %ymm0, %ymm7;
  1018. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1019. vpshufb %ymm14, %ymm0, %ymm6;
  1020. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1021. vpshufb %ymm14, %ymm0, %ymm5;
  1022. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1023. vpshufb %ymm14, %ymm0, %ymm4;
  1024. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1025. vpshufb %ymm14, %ymm0, %ymm3;
  1026. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1027. vpshufb %ymm14, %ymm0, %ymm2;
  1028. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1029. vpshufb %ymm14, %ymm0, %ymm1;
  1030. add2_le128(%ymm0, %ymm15, %ymm12, %ymm11, %ymm13);
  1031. vextracti128 $1, %ymm0, %xmm13;
  1032. vpshufb %ymm14, %ymm0, %ymm0;
  1033. inc_le128(%xmm13, %xmm15, %xmm14);
  1034. vmovdqu %xmm13, (%rcx);
  1035. /* inpack32_pre: */
  1036. vpbroadcastq (key_table)(CTX), %ymm15;
  1037. vpshufb .Lpack_bswap, %ymm15, %ymm15;
  1038. vpxor %ymm0, %ymm15, %ymm0;
  1039. vpxor %ymm1, %ymm15, %ymm1;
  1040. vpxor %ymm2, %ymm15, %ymm2;
  1041. vpxor %ymm3, %ymm15, %ymm3;
  1042. vpxor %ymm4, %ymm15, %ymm4;
  1043. vpxor %ymm5, %ymm15, %ymm5;
  1044. vpxor %ymm6, %ymm15, %ymm6;
  1045. vpxor %ymm7, %ymm15, %ymm7;
  1046. vpxor %ymm8, %ymm15, %ymm8;
  1047. vpxor %ymm9, %ymm15, %ymm9;
  1048. vpxor %ymm10, %ymm15, %ymm10;
  1049. vpxor 11 * 32(%rax), %ymm15, %ymm11;
  1050. vpxor 12 * 32(%rax), %ymm15, %ymm12;
  1051. vpxor 13 * 32(%rax), %ymm15, %ymm13;
  1052. vpxor 14 * 32(%rax), %ymm15, %ymm14;
  1053. vpxor 15 * 32(%rax), %ymm15, %ymm15;
  1054. call __camellia_enc_blk32;
  1055. movq %r10, %rsp;
  1056. vpxor 0 * 32(%rdx), %ymm7, %ymm7;
  1057. vpxor 1 * 32(%rdx), %ymm6, %ymm6;
  1058. vpxor 2 * 32(%rdx), %ymm5, %ymm5;
  1059. vpxor 3 * 32(%rdx), %ymm4, %ymm4;
  1060. vpxor 4 * 32(%rdx), %ymm3, %ymm3;
  1061. vpxor 5 * 32(%rdx), %ymm2, %ymm2;
  1062. vpxor 6 * 32(%rdx), %ymm1, %ymm1;
  1063. vpxor 7 * 32(%rdx), %ymm0, %ymm0;
  1064. vpxor 8 * 32(%rdx), %ymm15, %ymm15;
  1065. vpxor 9 * 32(%rdx), %ymm14, %ymm14;
  1066. vpxor 10 * 32(%rdx), %ymm13, %ymm13;
  1067. vpxor 11 * 32(%rdx), %ymm12, %ymm12;
  1068. vpxor 12 * 32(%rdx), %ymm11, %ymm11;
  1069. vpxor 13 * 32(%rdx), %ymm10, %ymm10;
  1070. vpxor 14 * 32(%rdx), %ymm9, %ymm9;
  1071. vpxor 15 * 32(%rdx), %ymm8, %ymm8;
  1072. write_output(%ymm7, %ymm6, %ymm5, %ymm4, %ymm3, %ymm2, %ymm1, %ymm0,
  1073. %ymm15, %ymm14, %ymm13, %ymm12, %ymm11, %ymm10, %ymm9,
  1074. %ymm8, %rsi);
  1075. vzeroupper;
  1076. ret;
  1077. ENDPROC(camellia_ctr_32way)
  1078. #define gf128mul_x_ble(iv, mask, tmp) \
  1079. vpsrad $31, iv, tmp; \
  1080. vpaddq iv, iv, iv; \
  1081. vpshufd $0x13, tmp, tmp; \
  1082. vpand mask, tmp, tmp; \
  1083. vpxor tmp, iv, iv;
  1084. #define gf128mul_x2_ble(iv, mask1, mask2, tmp0, tmp1) \
  1085. vpsrad $31, iv, tmp0; \
  1086. vpaddq iv, iv, tmp1; \
  1087. vpsllq $2, iv, iv; \
  1088. vpshufd $0x13, tmp0, tmp0; \
  1089. vpsrad $31, tmp1, tmp1; \
  1090. vpand mask2, tmp0, tmp0; \
  1091. vpshufd $0x13, tmp1, tmp1; \
  1092. vpxor tmp0, iv, iv; \
  1093. vpand mask1, tmp1, tmp1; \
  1094. vpxor tmp1, iv, iv;
  1095. .align 8
  1096. camellia_xts_crypt_32way:
  1097. /* input:
  1098. * %rdi: ctx, CTX
  1099. * %rsi: dst (32 blocks)
  1100. * %rdx: src (32 blocks)
  1101. * %rcx: iv (t ⊕ αⁿ ∈ GF(2¹²⁸))
  1102. * %r8: index for input whitening key
  1103. * %r9: pointer to __camellia_enc_blk32 or __camellia_dec_blk32
  1104. */
  1105. vzeroupper;
  1106. subq $(16 * 32), %rsp;
  1107. movq %rsp, %rax;
  1108. vbroadcasti128 .Lxts_gf128mul_and_shl1_mask_0, %ymm12;
  1109. /* load IV and construct second IV */
  1110. vmovdqu (%rcx), %xmm0;
  1111. vmovdqa %xmm0, %xmm15;
  1112. gf128mul_x_ble(%xmm0, %xmm12, %xmm13);
  1113. vbroadcasti128 .Lxts_gf128mul_and_shl1_mask_1, %ymm13;
  1114. vinserti128 $1, %xmm0, %ymm15, %ymm0;
  1115. vpxor 0 * 32(%rdx), %ymm0, %ymm15;
  1116. vmovdqu %ymm15, 15 * 32(%rax);
  1117. vmovdqu %ymm0, 0 * 32(%rsi);
  1118. /* construct IVs */
  1119. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1120. vpxor 1 * 32(%rdx), %ymm0, %ymm15;
  1121. vmovdqu %ymm15, 14 * 32(%rax);
  1122. vmovdqu %ymm0, 1 * 32(%rsi);
  1123. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1124. vpxor 2 * 32(%rdx), %ymm0, %ymm15;
  1125. vmovdqu %ymm15, 13 * 32(%rax);
  1126. vmovdqu %ymm0, 2 * 32(%rsi);
  1127. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1128. vpxor 3 * 32(%rdx), %ymm0, %ymm15;
  1129. vmovdqu %ymm15, 12 * 32(%rax);
  1130. vmovdqu %ymm0, 3 * 32(%rsi);
  1131. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1132. vpxor 4 * 32(%rdx), %ymm0, %ymm11;
  1133. vmovdqu %ymm0, 4 * 32(%rsi);
  1134. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1135. vpxor 5 * 32(%rdx), %ymm0, %ymm10;
  1136. vmovdqu %ymm0, 5 * 32(%rsi);
  1137. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1138. vpxor 6 * 32(%rdx), %ymm0, %ymm9;
  1139. vmovdqu %ymm0, 6 * 32(%rsi);
  1140. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1141. vpxor 7 * 32(%rdx), %ymm0, %ymm8;
  1142. vmovdqu %ymm0, 7 * 32(%rsi);
  1143. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1144. vpxor 8 * 32(%rdx), %ymm0, %ymm7;
  1145. vmovdqu %ymm0, 8 * 32(%rsi);
  1146. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1147. vpxor 9 * 32(%rdx), %ymm0, %ymm6;
  1148. vmovdqu %ymm0, 9 * 32(%rsi);
  1149. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1150. vpxor 10 * 32(%rdx), %ymm0, %ymm5;
  1151. vmovdqu %ymm0, 10 * 32(%rsi);
  1152. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1153. vpxor 11 * 32(%rdx), %ymm0, %ymm4;
  1154. vmovdqu %ymm0, 11 * 32(%rsi);
  1155. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1156. vpxor 12 * 32(%rdx), %ymm0, %ymm3;
  1157. vmovdqu %ymm0, 12 * 32(%rsi);
  1158. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1159. vpxor 13 * 32(%rdx), %ymm0, %ymm2;
  1160. vmovdqu %ymm0, 13 * 32(%rsi);
  1161. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1162. vpxor 14 * 32(%rdx), %ymm0, %ymm1;
  1163. vmovdqu %ymm0, 14 * 32(%rsi);
  1164. gf128mul_x2_ble(%ymm0, %ymm12, %ymm13, %ymm14, %ymm15);
  1165. vpxor 15 * 32(%rdx), %ymm0, %ymm15;
  1166. vmovdqu %ymm15, 0 * 32(%rax);
  1167. vmovdqu %ymm0, 15 * 32(%rsi);
  1168. vextracti128 $1, %ymm0, %xmm0;
  1169. gf128mul_x_ble(%xmm0, %xmm12, %xmm15);
  1170. vmovdqu %xmm0, (%rcx);
  1171. /* inpack32_pre: */
  1172. vpbroadcastq (key_table)(CTX, %r8, 8), %ymm15;
  1173. vpshufb .Lpack_bswap, %ymm15, %ymm15;
  1174. vpxor 0 * 32(%rax), %ymm15, %ymm0;
  1175. vpxor %ymm1, %ymm15, %ymm1;
  1176. vpxor %ymm2, %ymm15, %ymm2;
  1177. vpxor %ymm3, %ymm15, %ymm3;
  1178. vpxor %ymm4, %ymm15, %ymm4;
  1179. vpxor %ymm5, %ymm15, %ymm5;
  1180. vpxor %ymm6, %ymm15, %ymm6;
  1181. vpxor %ymm7, %ymm15, %ymm7;
  1182. vpxor %ymm8, %ymm15, %ymm8;
  1183. vpxor %ymm9, %ymm15, %ymm9;
  1184. vpxor %ymm10, %ymm15, %ymm10;
  1185. vpxor %ymm11, %ymm15, %ymm11;
  1186. vpxor 12 * 32(%rax), %ymm15, %ymm12;
  1187. vpxor 13 * 32(%rax), %ymm15, %ymm13;
  1188. vpxor 14 * 32(%rax), %ymm15, %ymm14;
  1189. vpxor 15 * 32(%rax), %ymm15, %ymm15;
  1190. CALL_NOSPEC %r9;
  1191. addq $(16 * 32), %rsp;
  1192. vpxor 0 * 32(%rsi), %ymm7, %ymm7;
  1193. vpxor 1 * 32(%rsi), %ymm6, %ymm6;
  1194. vpxor 2 * 32(%rsi), %ymm5, %ymm5;
  1195. vpxor 3 * 32(%rsi), %ymm4, %ymm4;
  1196. vpxor 4 * 32(%rsi), %ymm3, %ymm3;
  1197. vpxor 5 * 32(%rsi), %ymm2, %ymm2;
  1198. vpxor 6 * 32(%rsi), %ymm1, %ymm1;
  1199. vpxor 7 * 32(%rsi), %ymm0, %ymm0;
  1200. vpxor 8 * 32(%rsi), %ymm15, %ymm15;
  1201. vpxor 9 * 32(%rsi), %ymm14, %ymm14;
  1202. vpxor 10 * 32(%rsi), %ymm13, %ymm13;
  1203. vpxor 11 * 32(%rsi), %ymm12, %ymm12;
  1204. vpxor 12 * 32(%rsi), %ymm11, %ymm11;
  1205. vpxor 13 * 32(%rsi), %ymm10, %ymm10;
  1206. vpxor 14 * 32(%rsi), %ymm9, %ymm9;
  1207. vpxor 15 * 32(%rsi), %ymm8, %ymm8;
  1208. write_output(%ymm7, %ymm6, %ymm5, %ymm4, %ymm3, %ymm2, %ymm1, %ymm0,
  1209. %ymm15, %ymm14, %ymm13, %ymm12, %ymm11, %ymm10, %ymm9,
  1210. %ymm8, %rsi);
  1211. vzeroupper;
  1212. ret;
  1213. ENDPROC(camellia_xts_crypt_32way)
  1214. ENTRY(camellia_xts_enc_32way)
  1215. /* input:
  1216. * %rdi: ctx, CTX
  1217. * %rsi: dst (32 blocks)
  1218. * %rdx: src (32 blocks)
  1219. * %rcx: iv (t ⊕ αⁿ ∈ GF(2¹²⁸))
  1220. */
  1221. xorl %r8d, %r8d; /* input whitening key, 0 for enc */
  1222. leaq __camellia_enc_blk32, %r9;
  1223. jmp camellia_xts_crypt_32way;
  1224. ENDPROC(camellia_xts_enc_32way)
  1225. ENTRY(camellia_xts_dec_32way)
  1226. /* input:
  1227. * %rdi: ctx, CTX
  1228. * %rsi: dst (32 blocks)
  1229. * %rdx: src (32 blocks)
  1230. * %rcx: iv (t ⊕ αⁿ ∈ GF(2¹²⁸))
  1231. */
  1232. cmpl $16, key_length(CTX);
  1233. movl $32, %r8d;
  1234. movl $24, %eax;
  1235. cmovel %eax, %r8d; /* input whitening key, last for dec */
  1236. leaq __camellia_dec_blk32, %r9;
  1237. jmp camellia_xts_crypt_32way;
  1238. ENDPROC(camellia_xts_dec_32way)