camellia_glue.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953
  1. /*
  2. * Glue Code for assembler optimized version of Camellia
  3. *
  4. * Copyright (c) 2012 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
  5. *
  6. * Camellia parts based on code by:
  7. * Copyright (C) 2006 NTT (Nippon Telegraph and Telephone Corporation)
  8. * CBC & ECB parts based on code (crypto/cbc.c,ecb.c) by:
  9. * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
  10. * CTR part based on code (crypto/ctr.c) by:
  11. * (C) Copyright IBM Corp. 2007 - Joy Latten <latten@us.ibm.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  26. * USA
  27. *
  28. */
  29. #include <asm/processor.h>
  30. #include <asm/unaligned.h>
  31. #include <linux/crypto.h>
  32. #include <linux/init.h>
  33. #include <linux/module.h>
  34. #include <linux/types.h>
  35. #include <crypto/algapi.h>
  36. #include <crypto/b128ops.h>
  37. #include <crypto/lrw.h>
  38. #include <crypto/xts.h>
  39. #define CAMELLIA_MIN_KEY_SIZE 16
  40. #define CAMELLIA_MAX_KEY_SIZE 32
  41. #define CAMELLIA_BLOCK_SIZE 16
  42. #define CAMELLIA_TABLE_BYTE_LEN 272
  43. struct camellia_ctx {
  44. u64 key_table[CAMELLIA_TABLE_BYTE_LEN / sizeof(u64)];
  45. u32 key_length;
  46. };
  47. /* regular block cipher functions */
  48. asmlinkage void __camellia_enc_blk(struct camellia_ctx *ctx, u8 *dst,
  49. const u8 *src, bool xor);
  50. asmlinkage void camellia_dec_blk(struct camellia_ctx *ctx, u8 *dst,
  51. const u8 *src);
  52. /* 2-way parallel cipher functions */
  53. asmlinkage void __camellia_enc_blk_2way(struct camellia_ctx *ctx, u8 *dst,
  54. const u8 *src, bool xor);
  55. asmlinkage void camellia_dec_blk_2way(struct camellia_ctx *ctx, u8 *dst,
  56. const u8 *src);
  57. static inline void camellia_enc_blk(struct camellia_ctx *ctx, u8 *dst,
  58. const u8 *src)
  59. {
  60. __camellia_enc_blk(ctx, dst, src, false);
  61. }
  62. static inline void camellia_enc_blk_xor(struct camellia_ctx *ctx, u8 *dst,
  63. const u8 *src)
  64. {
  65. __camellia_enc_blk(ctx, dst, src, true);
  66. }
  67. static inline void camellia_enc_blk_2way(struct camellia_ctx *ctx, u8 *dst,
  68. const u8 *src)
  69. {
  70. __camellia_enc_blk_2way(ctx, dst, src, false);
  71. }
  72. static inline void camellia_enc_blk_xor_2way(struct camellia_ctx *ctx, u8 *dst,
  73. const u8 *src)
  74. {
  75. __camellia_enc_blk_2way(ctx, dst, src, true);
  76. }
  77. static void camellia_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  78. {
  79. camellia_enc_blk(crypto_tfm_ctx(tfm), dst, src);
  80. }
  81. static void camellia_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  82. {
  83. camellia_dec_blk(crypto_tfm_ctx(tfm), dst, src);
  84. }
  85. /* camellia sboxes */
  86. const u64 camellia_sp10011110[256] = {
  87. 0x7000007070707000, 0x8200008282828200, 0x2c00002c2c2c2c00,
  88. 0xec0000ecececec00, 0xb30000b3b3b3b300, 0x2700002727272700,
  89. 0xc00000c0c0c0c000, 0xe50000e5e5e5e500, 0xe40000e4e4e4e400,
  90. 0x8500008585858500, 0x5700005757575700, 0x3500003535353500,
  91. 0xea0000eaeaeaea00, 0x0c00000c0c0c0c00, 0xae0000aeaeaeae00,
  92. 0x4100004141414100, 0x2300002323232300, 0xef0000efefefef00,
  93. 0x6b00006b6b6b6b00, 0x9300009393939300, 0x4500004545454500,
  94. 0x1900001919191900, 0xa50000a5a5a5a500, 0x2100002121212100,
  95. 0xed0000edededed00, 0x0e00000e0e0e0e00, 0x4f00004f4f4f4f00,
  96. 0x4e00004e4e4e4e00, 0x1d00001d1d1d1d00, 0x6500006565656500,
  97. 0x9200009292929200, 0xbd0000bdbdbdbd00, 0x8600008686868600,
  98. 0xb80000b8b8b8b800, 0xaf0000afafafaf00, 0x8f00008f8f8f8f00,
  99. 0x7c00007c7c7c7c00, 0xeb0000ebebebeb00, 0x1f00001f1f1f1f00,
  100. 0xce0000cececece00, 0x3e00003e3e3e3e00, 0x3000003030303000,
  101. 0xdc0000dcdcdcdc00, 0x5f00005f5f5f5f00, 0x5e00005e5e5e5e00,
  102. 0xc50000c5c5c5c500, 0x0b00000b0b0b0b00, 0x1a00001a1a1a1a00,
  103. 0xa60000a6a6a6a600, 0xe10000e1e1e1e100, 0x3900003939393900,
  104. 0xca0000cacacaca00, 0xd50000d5d5d5d500, 0x4700004747474700,
  105. 0x5d00005d5d5d5d00, 0x3d00003d3d3d3d00, 0xd90000d9d9d9d900,
  106. 0x0100000101010100, 0x5a00005a5a5a5a00, 0xd60000d6d6d6d600,
  107. 0x5100005151515100, 0x5600005656565600, 0x6c00006c6c6c6c00,
  108. 0x4d00004d4d4d4d00, 0x8b00008b8b8b8b00, 0x0d00000d0d0d0d00,
  109. 0x9a00009a9a9a9a00, 0x6600006666666600, 0xfb0000fbfbfbfb00,
  110. 0xcc0000cccccccc00, 0xb00000b0b0b0b000, 0x2d00002d2d2d2d00,
  111. 0x7400007474747400, 0x1200001212121200, 0x2b00002b2b2b2b00,
  112. 0x2000002020202000, 0xf00000f0f0f0f000, 0xb10000b1b1b1b100,
  113. 0x8400008484848400, 0x9900009999999900, 0xdf0000dfdfdfdf00,
  114. 0x4c00004c4c4c4c00, 0xcb0000cbcbcbcb00, 0xc20000c2c2c2c200,
  115. 0x3400003434343400, 0x7e00007e7e7e7e00, 0x7600007676767600,
  116. 0x0500000505050500, 0x6d00006d6d6d6d00, 0xb70000b7b7b7b700,
  117. 0xa90000a9a9a9a900, 0x3100003131313100, 0xd10000d1d1d1d100,
  118. 0x1700001717171700, 0x0400000404040400, 0xd70000d7d7d7d700,
  119. 0x1400001414141400, 0x5800005858585800, 0x3a00003a3a3a3a00,
  120. 0x6100006161616100, 0xde0000dededede00, 0x1b00001b1b1b1b00,
  121. 0x1100001111111100, 0x1c00001c1c1c1c00, 0x3200003232323200,
  122. 0x0f00000f0f0f0f00, 0x9c00009c9c9c9c00, 0x1600001616161600,
  123. 0x5300005353535300, 0x1800001818181800, 0xf20000f2f2f2f200,
  124. 0x2200002222222200, 0xfe0000fefefefe00, 0x4400004444444400,
  125. 0xcf0000cfcfcfcf00, 0xb20000b2b2b2b200, 0xc30000c3c3c3c300,
  126. 0xb50000b5b5b5b500, 0x7a00007a7a7a7a00, 0x9100009191919100,
  127. 0x2400002424242400, 0x0800000808080800, 0xe80000e8e8e8e800,
  128. 0xa80000a8a8a8a800, 0x6000006060606000, 0xfc0000fcfcfcfc00,
  129. 0x6900006969696900, 0x5000005050505000, 0xaa0000aaaaaaaa00,
  130. 0xd00000d0d0d0d000, 0xa00000a0a0a0a000, 0x7d00007d7d7d7d00,
  131. 0xa10000a1a1a1a100, 0x8900008989898900, 0x6200006262626200,
  132. 0x9700009797979700, 0x5400005454545400, 0x5b00005b5b5b5b00,
  133. 0x1e00001e1e1e1e00, 0x9500009595959500, 0xe00000e0e0e0e000,
  134. 0xff0000ffffffff00, 0x6400006464646400, 0xd20000d2d2d2d200,
  135. 0x1000001010101000, 0xc40000c4c4c4c400, 0x0000000000000000,
  136. 0x4800004848484800, 0xa30000a3a3a3a300, 0xf70000f7f7f7f700,
  137. 0x7500007575757500, 0xdb0000dbdbdbdb00, 0x8a00008a8a8a8a00,
  138. 0x0300000303030300, 0xe60000e6e6e6e600, 0xda0000dadadada00,
  139. 0x0900000909090900, 0x3f00003f3f3f3f00, 0xdd0000dddddddd00,
  140. 0x9400009494949400, 0x8700008787878700, 0x5c00005c5c5c5c00,
  141. 0x8300008383838300, 0x0200000202020200, 0xcd0000cdcdcdcd00,
  142. 0x4a00004a4a4a4a00, 0x9000009090909000, 0x3300003333333300,
  143. 0x7300007373737300, 0x6700006767676700, 0xf60000f6f6f6f600,
  144. 0xf30000f3f3f3f300, 0x9d00009d9d9d9d00, 0x7f00007f7f7f7f00,
  145. 0xbf0000bfbfbfbf00, 0xe20000e2e2e2e200, 0x5200005252525200,
  146. 0x9b00009b9b9b9b00, 0xd80000d8d8d8d800, 0x2600002626262600,
  147. 0xc80000c8c8c8c800, 0x3700003737373700, 0xc60000c6c6c6c600,
  148. 0x3b00003b3b3b3b00, 0x8100008181818100, 0x9600009696969600,
  149. 0x6f00006f6f6f6f00, 0x4b00004b4b4b4b00, 0x1300001313131300,
  150. 0xbe0000bebebebe00, 0x6300006363636300, 0x2e00002e2e2e2e00,
  151. 0xe90000e9e9e9e900, 0x7900007979797900, 0xa70000a7a7a7a700,
  152. 0x8c00008c8c8c8c00, 0x9f00009f9f9f9f00, 0x6e00006e6e6e6e00,
  153. 0xbc0000bcbcbcbc00, 0x8e00008e8e8e8e00, 0x2900002929292900,
  154. 0xf50000f5f5f5f500, 0xf90000f9f9f9f900, 0xb60000b6b6b6b600,
  155. 0x2f00002f2f2f2f00, 0xfd0000fdfdfdfd00, 0xb40000b4b4b4b400,
  156. 0x5900005959595900, 0x7800007878787800, 0x9800009898989800,
  157. 0x0600000606060600, 0x6a00006a6a6a6a00, 0xe70000e7e7e7e700,
  158. 0x4600004646464600, 0x7100007171717100, 0xba0000babababa00,
  159. 0xd40000d4d4d4d400, 0x2500002525252500, 0xab0000abababab00,
  160. 0x4200004242424200, 0x8800008888888800, 0xa20000a2a2a2a200,
  161. 0x8d00008d8d8d8d00, 0xfa0000fafafafa00, 0x7200007272727200,
  162. 0x0700000707070700, 0xb90000b9b9b9b900, 0x5500005555555500,
  163. 0xf80000f8f8f8f800, 0xee0000eeeeeeee00, 0xac0000acacacac00,
  164. 0x0a00000a0a0a0a00, 0x3600003636363600, 0x4900004949494900,
  165. 0x2a00002a2a2a2a00, 0x6800006868686800, 0x3c00003c3c3c3c00,
  166. 0x3800003838383800, 0xf10000f1f1f1f100, 0xa40000a4a4a4a400,
  167. 0x4000004040404000, 0x2800002828282800, 0xd30000d3d3d3d300,
  168. 0x7b00007b7b7b7b00, 0xbb0000bbbbbbbb00, 0xc90000c9c9c9c900,
  169. 0x4300004343434300, 0xc10000c1c1c1c100, 0x1500001515151500,
  170. 0xe30000e3e3e3e300, 0xad0000adadadad00, 0xf40000f4f4f4f400,
  171. 0x7700007777777700, 0xc70000c7c7c7c700, 0x8000008080808000,
  172. 0x9e00009e9e9e9e00,
  173. };
  174. const u64 camellia_sp22000222[256] = {
  175. 0xe0e0000000e0e0e0, 0x0505000000050505, 0x5858000000585858,
  176. 0xd9d9000000d9d9d9, 0x6767000000676767, 0x4e4e0000004e4e4e,
  177. 0x8181000000818181, 0xcbcb000000cbcbcb, 0xc9c9000000c9c9c9,
  178. 0x0b0b0000000b0b0b, 0xaeae000000aeaeae, 0x6a6a0000006a6a6a,
  179. 0xd5d5000000d5d5d5, 0x1818000000181818, 0x5d5d0000005d5d5d,
  180. 0x8282000000828282, 0x4646000000464646, 0xdfdf000000dfdfdf,
  181. 0xd6d6000000d6d6d6, 0x2727000000272727, 0x8a8a0000008a8a8a,
  182. 0x3232000000323232, 0x4b4b0000004b4b4b, 0x4242000000424242,
  183. 0xdbdb000000dbdbdb, 0x1c1c0000001c1c1c, 0x9e9e0000009e9e9e,
  184. 0x9c9c0000009c9c9c, 0x3a3a0000003a3a3a, 0xcaca000000cacaca,
  185. 0x2525000000252525, 0x7b7b0000007b7b7b, 0x0d0d0000000d0d0d,
  186. 0x7171000000717171, 0x5f5f0000005f5f5f, 0x1f1f0000001f1f1f,
  187. 0xf8f8000000f8f8f8, 0xd7d7000000d7d7d7, 0x3e3e0000003e3e3e,
  188. 0x9d9d0000009d9d9d, 0x7c7c0000007c7c7c, 0x6060000000606060,
  189. 0xb9b9000000b9b9b9, 0xbebe000000bebebe, 0xbcbc000000bcbcbc,
  190. 0x8b8b0000008b8b8b, 0x1616000000161616, 0x3434000000343434,
  191. 0x4d4d0000004d4d4d, 0xc3c3000000c3c3c3, 0x7272000000727272,
  192. 0x9595000000959595, 0xabab000000ababab, 0x8e8e0000008e8e8e,
  193. 0xbaba000000bababa, 0x7a7a0000007a7a7a, 0xb3b3000000b3b3b3,
  194. 0x0202000000020202, 0xb4b4000000b4b4b4, 0xadad000000adadad,
  195. 0xa2a2000000a2a2a2, 0xacac000000acacac, 0xd8d8000000d8d8d8,
  196. 0x9a9a0000009a9a9a, 0x1717000000171717, 0x1a1a0000001a1a1a,
  197. 0x3535000000353535, 0xcccc000000cccccc, 0xf7f7000000f7f7f7,
  198. 0x9999000000999999, 0x6161000000616161, 0x5a5a0000005a5a5a,
  199. 0xe8e8000000e8e8e8, 0x2424000000242424, 0x5656000000565656,
  200. 0x4040000000404040, 0xe1e1000000e1e1e1, 0x6363000000636363,
  201. 0x0909000000090909, 0x3333000000333333, 0xbfbf000000bfbfbf,
  202. 0x9898000000989898, 0x9797000000979797, 0x8585000000858585,
  203. 0x6868000000686868, 0xfcfc000000fcfcfc, 0xecec000000ececec,
  204. 0x0a0a0000000a0a0a, 0xdada000000dadada, 0x6f6f0000006f6f6f,
  205. 0x5353000000535353, 0x6262000000626262, 0xa3a3000000a3a3a3,
  206. 0x2e2e0000002e2e2e, 0x0808000000080808, 0xafaf000000afafaf,
  207. 0x2828000000282828, 0xb0b0000000b0b0b0, 0x7474000000747474,
  208. 0xc2c2000000c2c2c2, 0xbdbd000000bdbdbd, 0x3636000000363636,
  209. 0x2222000000222222, 0x3838000000383838, 0x6464000000646464,
  210. 0x1e1e0000001e1e1e, 0x3939000000393939, 0x2c2c0000002c2c2c,
  211. 0xa6a6000000a6a6a6, 0x3030000000303030, 0xe5e5000000e5e5e5,
  212. 0x4444000000444444, 0xfdfd000000fdfdfd, 0x8888000000888888,
  213. 0x9f9f0000009f9f9f, 0x6565000000656565, 0x8787000000878787,
  214. 0x6b6b0000006b6b6b, 0xf4f4000000f4f4f4, 0x2323000000232323,
  215. 0x4848000000484848, 0x1010000000101010, 0xd1d1000000d1d1d1,
  216. 0x5151000000515151, 0xc0c0000000c0c0c0, 0xf9f9000000f9f9f9,
  217. 0xd2d2000000d2d2d2, 0xa0a0000000a0a0a0, 0x5555000000555555,
  218. 0xa1a1000000a1a1a1, 0x4141000000414141, 0xfafa000000fafafa,
  219. 0x4343000000434343, 0x1313000000131313, 0xc4c4000000c4c4c4,
  220. 0x2f2f0000002f2f2f, 0xa8a8000000a8a8a8, 0xb6b6000000b6b6b6,
  221. 0x3c3c0000003c3c3c, 0x2b2b0000002b2b2b, 0xc1c1000000c1c1c1,
  222. 0xffff000000ffffff, 0xc8c8000000c8c8c8, 0xa5a5000000a5a5a5,
  223. 0x2020000000202020, 0x8989000000898989, 0x0000000000000000,
  224. 0x9090000000909090, 0x4747000000474747, 0xefef000000efefef,
  225. 0xeaea000000eaeaea, 0xb7b7000000b7b7b7, 0x1515000000151515,
  226. 0x0606000000060606, 0xcdcd000000cdcdcd, 0xb5b5000000b5b5b5,
  227. 0x1212000000121212, 0x7e7e0000007e7e7e, 0xbbbb000000bbbbbb,
  228. 0x2929000000292929, 0x0f0f0000000f0f0f, 0xb8b8000000b8b8b8,
  229. 0x0707000000070707, 0x0404000000040404, 0x9b9b0000009b9b9b,
  230. 0x9494000000949494, 0x2121000000212121, 0x6666000000666666,
  231. 0xe6e6000000e6e6e6, 0xcece000000cecece, 0xeded000000ededed,
  232. 0xe7e7000000e7e7e7, 0x3b3b0000003b3b3b, 0xfefe000000fefefe,
  233. 0x7f7f0000007f7f7f, 0xc5c5000000c5c5c5, 0xa4a4000000a4a4a4,
  234. 0x3737000000373737, 0xb1b1000000b1b1b1, 0x4c4c0000004c4c4c,
  235. 0x9191000000919191, 0x6e6e0000006e6e6e, 0x8d8d0000008d8d8d,
  236. 0x7676000000767676, 0x0303000000030303, 0x2d2d0000002d2d2d,
  237. 0xdede000000dedede, 0x9696000000969696, 0x2626000000262626,
  238. 0x7d7d0000007d7d7d, 0xc6c6000000c6c6c6, 0x5c5c0000005c5c5c,
  239. 0xd3d3000000d3d3d3, 0xf2f2000000f2f2f2, 0x4f4f0000004f4f4f,
  240. 0x1919000000191919, 0x3f3f0000003f3f3f, 0xdcdc000000dcdcdc,
  241. 0x7979000000797979, 0x1d1d0000001d1d1d, 0x5252000000525252,
  242. 0xebeb000000ebebeb, 0xf3f3000000f3f3f3, 0x6d6d0000006d6d6d,
  243. 0x5e5e0000005e5e5e, 0xfbfb000000fbfbfb, 0x6969000000696969,
  244. 0xb2b2000000b2b2b2, 0xf0f0000000f0f0f0, 0x3131000000313131,
  245. 0x0c0c0000000c0c0c, 0xd4d4000000d4d4d4, 0xcfcf000000cfcfcf,
  246. 0x8c8c0000008c8c8c, 0xe2e2000000e2e2e2, 0x7575000000757575,
  247. 0xa9a9000000a9a9a9, 0x4a4a0000004a4a4a, 0x5757000000575757,
  248. 0x8484000000848484, 0x1111000000111111, 0x4545000000454545,
  249. 0x1b1b0000001b1b1b, 0xf5f5000000f5f5f5, 0xe4e4000000e4e4e4,
  250. 0x0e0e0000000e0e0e, 0x7373000000737373, 0xaaaa000000aaaaaa,
  251. 0xf1f1000000f1f1f1, 0xdddd000000dddddd, 0x5959000000595959,
  252. 0x1414000000141414, 0x6c6c0000006c6c6c, 0x9292000000929292,
  253. 0x5454000000545454, 0xd0d0000000d0d0d0, 0x7878000000787878,
  254. 0x7070000000707070, 0xe3e3000000e3e3e3, 0x4949000000494949,
  255. 0x8080000000808080, 0x5050000000505050, 0xa7a7000000a7a7a7,
  256. 0xf6f6000000f6f6f6, 0x7777000000777777, 0x9393000000939393,
  257. 0x8686000000868686, 0x8383000000838383, 0x2a2a0000002a2a2a,
  258. 0xc7c7000000c7c7c7, 0x5b5b0000005b5b5b, 0xe9e9000000e9e9e9,
  259. 0xeeee000000eeeeee, 0x8f8f0000008f8f8f, 0x0101000000010101,
  260. 0x3d3d0000003d3d3d,
  261. };
  262. const u64 camellia_sp03303033[256] = {
  263. 0x0038380038003838, 0x0041410041004141, 0x0016160016001616,
  264. 0x0076760076007676, 0x00d9d900d900d9d9, 0x0093930093009393,
  265. 0x0060600060006060, 0x00f2f200f200f2f2, 0x0072720072007272,
  266. 0x00c2c200c200c2c2, 0x00abab00ab00abab, 0x009a9a009a009a9a,
  267. 0x0075750075007575, 0x0006060006000606, 0x0057570057005757,
  268. 0x00a0a000a000a0a0, 0x0091910091009191, 0x00f7f700f700f7f7,
  269. 0x00b5b500b500b5b5, 0x00c9c900c900c9c9, 0x00a2a200a200a2a2,
  270. 0x008c8c008c008c8c, 0x00d2d200d200d2d2, 0x0090900090009090,
  271. 0x00f6f600f600f6f6, 0x0007070007000707, 0x00a7a700a700a7a7,
  272. 0x0027270027002727, 0x008e8e008e008e8e, 0x00b2b200b200b2b2,
  273. 0x0049490049004949, 0x00dede00de00dede, 0x0043430043004343,
  274. 0x005c5c005c005c5c, 0x00d7d700d700d7d7, 0x00c7c700c700c7c7,
  275. 0x003e3e003e003e3e, 0x00f5f500f500f5f5, 0x008f8f008f008f8f,
  276. 0x0067670067006767, 0x001f1f001f001f1f, 0x0018180018001818,
  277. 0x006e6e006e006e6e, 0x00afaf00af00afaf, 0x002f2f002f002f2f,
  278. 0x00e2e200e200e2e2, 0x0085850085008585, 0x000d0d000d000d0d,
  279. 0x0053530053005353, 0x00f0f000f000f0f0, 0x009c9c009c009c9c,
  280. 0x0065650065006565, 0x00eaea00ea00eaea, 0x00a3a300a300a3a3,
  281. 0x00aeae00ae00aeae, 0x009e9e009e009e9e, 0x00ecec00ec00ecec,
  282. 0x0080800080008080, 0x002d2d002d002d2d, 0x006b6b006b006b6b,
  283. 0x00a8a800a800a8a8, 0x002b2b002b002b2b, 0x0036360036003636,
  284. 0x00a6a600a600a6a6, 0x00c5c500c500c5c5, 0x0086860086008686,
  285. 0x004d4d004d004d4d, 0x0033330033003333, 0x00fdfd00fd00fdfd,
  286. 0x0066660066006666, 0x0058580058005858, 0x0096960096009696,
  287. 0x003a3a003a003a3a, 0x0009090009000909, 0x0095950095009595,
  288. 0x0010100010001010, 0x0078780078007878, 0x00d8d800d800d8d8,
  289. 0x0042420042004242, 0x00cccc00cc00cccc, 0x00efef00ef00efef,
  290. 0x0026260026002626, 0x00e5e500e500e5e5, 0x0061610061006161,
  291. 0x001a1a001a001a1a, 0x003f3f003f003f3f, 0x003b3b003b003b3b,
  292. 0x0082820082008282, 0x00b6b600b600b6b6, 0x00dbdb00db00dbdb,
  293. 0x00d4d400d400d4d4, 0x0098980098009898, 0x00e8e800e800e8e8,
  294. 0x008b8b008b008b8b, 0x0002020002000202, 0x00ebeb00eb00ebeb,
  295. 0x000a0a000a000a0a, 0x002c2c002c002c2c, 0x001d1d001d001d1d,
  296. 0x00b0b000b000b0b0, 0x006f6f006f006f6f, 0x008d8d008d008d8d,
  297. 0x0088880088008888, 0x000e0e000e000e0e, 0x0019190019001919,
  298. 0x0087870087008787, 0x004e4e004e004e4e, 0x000b0b000b000b0b,
  299. 0x00a9a900a900a9a9, 0x000c0c000c000c0c, 0x0079790079007979,
  300. 0x0011110011001111, 0x007f7f007f007f7f, 0x0022220022002222,
  301. 0x00e7e700e700e7e7, 0x0059590059005959, 0x00e1e100e100e1e1,
  302. 0x00dada00da00dada, 0x003d3d003d003d3d, 0x00c8c800c800c8c8,
  303. 0x0012120012001212, 0x0004040004000404, 0x0074740074007474,
  304. 0x0054540054005454, 0x0030300030003030, 0x007e7e007e007e7e,
  305. 0x00b4b400b400b4b4, 0x0028280028002828, 0x0055550055005555,
  306. 0x0068680068006868, 0x0050500050005050, 0x00bebe00be00bebe,
  307. 0x00d0d000d000d0d0, 0x00c4c400c400c4c4, 0x0031310031003131,
  308. 0x00cbcb00cb00cbcb, 0x002a2a002a002a2a, 0x00adad00ad00adad,
  309. 0x000f0f000f000f0f, 0x00caca00ca00caca, 0x0070700070007070,
  310. 0x00ffff00ff00ffff, 0x0032320032003232, 0x0069690069006969,
  311. 0x0008080008000808, 0x0062620062006262, 0x0000000000000000,
  312. 0x0024240024002424, 0x00d1d100d100d1d1, 0x00fbfb00fb00fbfb,
  313. 0x00baba00ba00baba, 0x00eded00ed00eded, 0x0045450045004545,
  314. 0x0081810081008181, 0x0073730073007373, 0x006d6d006d006d6d,
  315. 0x0084840084008484, 0x009f9f009f009f9f, 0x00eeee00ee00eeee,
  316. 0x004a4a004a004a4a, 0x00c3c300c300c3c3, 0x002e2e002e002e2e,
  317. 0x00c1c100c100c1c1, 0x0001010001000101, 0x00e6e600e600e6e6,
  318. 0x0025250025002525, 0x0048480048004848, 0x0099990099009999,
  319. 0x00b9b900b900b9b9, 0x00b3b300b300b3b3, 0x007b7b007b007b7b,
  320. 0x00f9f900f900f9f9, 0x00cece00ce00cece, 0x00bfbf00bf00bfbf,
  321. 0x00dfdf00df00dfdf, 0x0071710071007171, 0x0029290029002929,
  322. 0x00cdcd00cd00cdcd, 0x006c6c006c006c6c, 0x0013130013001313,
  323. 0x0064640064006464, 0x009b9b009b009b9b, 0x0063630063006363,
  324. 0x009d9d009d009d9d, 0x00c0c000c000c0c0, 0x004b4b004b004b4b,
  325. 0x00b7b700b700b7b7, 0x00a5a500a500a5a5, 0x0089890089008989,
  326. 0x005f5f005f005f5f, 0x00b1b100b100b1b1, 0x0017170017001717,
  327. 0x00f4f400f400f4f4, 0x00bcbc00bc00bcbc, 0x00d3d300d300d3d3,
  328. 0x0046460046004646, 0x00cfcf00cf00cfcf, 0x0037370037003737,
  329. 0x005e5e005e005e5e, 0x0047470047004747, 0x0094940094009494,
  330. 0x00fafa00fa00fafa, 0x00fcfc00fc00fcfc, 0x005b5b005b005b5b,
  331. 0x0097970097009797, 0x00fefe00fe00fefe, 0x005a5a005a005a5a,
  332. 0x00acac00ac00acac, 0x003c3c003c003c3c, 0x004c4c004c004c4c,
  333. 0x0003030003000303, 0x0035350035003535, 0x00f3f300f300f3f3,
  334. 0x0023230023002323, 0x00b8b800b800b8b8, 0x005d5d005d005d5d,
  335. 0x006a6a006a006a6a, 0x0092920092009292, 0x00d5d500d500d5d5,
  336. 0x0021210021002121, 0x0044440044004444, 0x0051510051005151,
  337. 0x00c6c600c600c6c6, 0x007d7d007d007d7d, 0x0039390039003939,
  338. 0x0083830083008383, 0x00dcdc00dc00dcdc, 0x00aaaa00aa00aaaa,
  339. 0x007c7c007c007c7c, 0x0077770077007777, 0x0056560056005656,
  340. 0x0005050005000505, 0x001b1b001b001b1b, 0x00a4a400a400a4a4,
  341. 0x0015150015001515, 0x0034340034003434, 0x001e1e001e001e1e,
  342. 0x001c1c001c001c1c, 0x00f8f800f800f8f8, 0x0052520052005252,
  343. 0x0020200020002020, 0x0014140014001414, 0x00e9e900e900e9e9,
  344. 0x00bdbd00bd00bdbd, 0x00dddd00dd00dddd, 0x00e4e400e400e4e4,
  345. 0x00a1a100a100a1a1, 0x00e0e000e000e0e0, 0x008a8a008a008a8a,
  346. 0x00f1f100f100f1f1, 0x00d6d600d600d6d6, 0x007a7a007a007a7a,
  347. 0x00bbbb00bb00bbbb, 0x00e3e300e300e3e3, 0x0040400040004040,
  348. 0x004f4f004f004f4f,
  349. };
  350. const u64 camellia_sp00444404[256] = {
  351. 0x0000707070700070, 0x00002c2c2c2c002c, 0x0000b3b3b3b300b3,
  352. 0x0000c0c0c0c000c0, 0x0000e4e4e4e400e4, 0x0000575757570057,
  353. 0x0000eaeaeaea00ea, 0x0000aeaeaeae00ae, 0x0000232323230023,
  354. 0x00006b6b6b6b006b, 0x0000454545450045, 0x0000a5a5a5a500a5,
  355. 0x0000edededed00ed, 0x00004f4f4f4f004f, 0x00001d1d1d1d001d,
  356. 0x0000929292920092, 0x0000868686860086, 0x0000afafafaf00af,
  357. 0x00007c7c7c7c007c, 0x00001f1f1f1f001f, 0x00003e3e3e3e003e,
  358. 0x0000dcdcdcdc00dc, 0x00005e5e5e5e005e, 0x00000b0b0b0b000b,
  359. 0x0000a6a6a6a600a6, 0x0000393939390039, 0x0000d5d5d5d500d5,
  360. 0x00005d5d5d5d005d, 0x0000d9d9d9d900d9, 0x00005a5a5a5a005a,
  361. 0x0000515151510051, 0x00006c6c6c6c006c, 0x00008b8b8b8b008b,
  362. 0x00009a9a9a9a009a, 0x0000fbfbfbfb00fb, 0x0000b0b0b0b000b0,
  363. 0x0000747474740074, 0x00002b2b2b2b002b, 0x0000f0f0f0f000f0,
  364. 0x0000848484840084, 0x0000dfdfdfdf00df, 0x0000cbcbcbcb00cb,
  365. 0x0000343434340034, 0x0000767676760076, 0x00006d6d6d6d006d,
  366. 0x0000a9a9a9a900a9, 0x0000d1d1d1d100d1, 0x0000040404040004,
  367. 0x0000141414140014, 0x00003a3a3a3a003a, 0x0000dededede00de,
  368. 0x0000111111110011, 0x0000323232320032, 0x00009c9c9c9c009c,
  369. 0x0000535353530053, 0x0000f2f2f2f200f2, 0x0000fefefefe00fe,
  370. 0x0000cfcfcfcf00cf, 0x0000c3c3c3c300c3, 0x00007a7a7a7a007a,
  371. 0x0000242424240024, 0x0000e8e8e8e800e8, 0x0000606060600060,
  372. 0x0000696969690069, 0x0000aaaaaaaa00aa, 0x0000a0a0a0a000a0,
  373. 0x0000a1a1a1a100a1, 0x0000626262620062, 0x0000545454540054,
  374. 0x00001e1e1e1e001e, 0x0000e0e0e0e000e0, 0x0000646464640064,
  375. 0x0000101010100010, 0x0000000000000000, 0x0000a3a3a3a300a3,
  376. 0x0000757575750075, 0x00008a8a8a8a008a, 0x0000e6e6e6e600e6,
  377. 0x0000090909090009, 0x0000dddddddd00dd, 0x0000878787870087,
  378. 0x0000838383830083, 0x0000cdcdcdcd00cd, 0x0000909090900090,
  379. 0x0000737373730073, 0x0000f6f6f6f600f6, 0x00009d9d9d9d009d,
  380. 0x0000bfbfbfbf00bf, 0x0000525252520052, 0x0000d8d8d8d800d8,
  381. 0x0000c8c8c8c800c8, 0x0000c6c6c6c600c6, 0x0000818181810081,
  382. 0x00006f6f6f6f006f, 0x0000131313130013, 0x0000636363630063,
  383. 0x0000e9e9e9e900e9, 0x0000a7a7a7a700a7, 0x00009f9f9f9f009f,
  384. 0x0000bcbcbcbc00bc, 0x0000292929290029, 0x0000f9f9f9f900f9,
  385. 0x00002f2f2f2f002f, 0x0000b4b4b4b400b4, 0x0000787878780078,
  386. 0x0000060606060006, 0x0000e7e7e7e700e7, 0x0000717171710071,
  387. 0x0000d4d4d4d400d4, 0x0000abababab00ab, 0x0000888888880088,
  388. 0x00008d8d8d8d008d, 0x0000727272720072, 0x0000b9b9b9b900b9,
  389. 0x0000f8f8f8f800f8, 0x0000acacacac00ac, 0x0000363636360036,
  390. 0x00002a2a2a2a002a, 0x00003c3c3c3c003c, 0x0000f1f1f1f100f1,
  391. 0x0000404040400040, 0x0000d3d3d3d300d3, 0x0000bbbbbbbb00bb,
  392. 0x0000434343430043, 0x0000151515150015, 0x0000adadadad00ad,
  393. 0x0000777777770077, 0x0000808080800080, 0x0000828282820082,
  394. 0x0000ecececec00ec, 0x0000272727270027, 0x0000e5e5e5e500e5,
  395. 0x0000858585850085, 0x0000353535350035, 0x00000c0c0c0c000c,
  396. 0x0000414141410041, 0x0000efefefef00ef, 0x0000939393930093,
  397. 0x0000191919190019, 0x0000212121210021, 0x00000e0e0e0e000e,
  398. 0x00004e4e4e4e004e, 0x0000656565650065, 0x0000bdbdbdbd00bd,
  399. 0x0000b8b8b8b800b8, 0x00008f8f8f8f008f, 0x0000ebebebeb00eb,
  400. 0x0000cececece00ce, 0x0000303030300030, 0x00005f5f5f5f005f,
  401. 0x0000c5c5c5c500c5, 0x00001a1a1a1a001a, 0x0000e1e1e1e100e1,
  402. 0x0000cacacaca00ca, 0x0000474747470047, 0x00003d3d3d3d003d,
  403. 0x0000010101010001, 0x0000d6d6d6d600d6, 0x0000565656560056,
  404. 0x00004d4d4d4d004d, 0x00000d0d0d0d000d, 0x0000666666660066,
  405. 0x0000cccccccc00cc, 0x00002d2d2d2d002d, 0x0000121212120012,
  406. 0x0000202020200020, 0x0000b1b1b1b100b1, 0x0000999999990099,
  407. 0x00004c4c4c4c004c, 0x0000c2c2c2c200c2, 0x00007e7e7e7e007e,
  408. 0x0000050505050005, 0x0000b7b7b7b700b7, 0x0000313131310031,
  409. 0x0000171717170017, 0x0000d7d7d7d700d7, 0x0000585858580058,
  410. 0x0000616161610061, 0x00001b1b1b1b001b, 0x00001c1c1c1c001c,
  411. 0x00000f0f0f0f000f, 0x0000161616160016, 0x0000181818180018,
  412. 0x0000222222220022, 0x0000444444440044, 0x0000b2b2b2b200b2,
  413. 0x0000b5b5b5b500b5, 0x0000919191910091, 0x0000080808080008,
  414. 0x0000a8a8a8a800a8, 0x0000fcfcfcfc00fc, 0x0000505050500050,
  415. 0x0000d0d0d0d000d0, 0x00007d7d7d7d007d, 0x0000898989890089,
  416. 0x0000979797970097, 0x00005b5b5b5b005b, 0x0000959595950095,
  417. 0x0000ffffffff00ff, 0x0000d2d2d2d200d2, 0x0000c4c4c4c400c4,
  418. 0x0000484848480048, 0x0000f7f7f7f700f7, 0x0000dbdbdbdb00db,
  419. 0x0000030303030003, 0x0000dadadada00da, 0x00003f3f3f3f003f,
  420. 0x0000949494940094, 0x00005c5c5c5c005c, 0x0000020202020002,
  421. 0x00004a4a4a4a004a, 0x0000333333330033, 0x0000676767670067,
  422. 0x0000f3f3f3f300f3, 0x00007f7f7f7f007f, 0x0000e2e2e2e200e2,
  423. 0x00009b9b9b9b009b, 0x0000262626260026, 0x0000373737370037,
  424. 0x00003b3b3b3b003b, 0x0000969696960096, 0x00004b4b4b4b004b,
  425. 0x0000bebebebe00be, 0x00002e2e2e2e002e, 0x0000797979790079,
  426. 0x00008c8c8c8c008c, 0x00006e6e6e6e006e, 0x00008e8e8e8e008e,
  427. 0x0000f5f5f5f500f5, 0x0000b6b6b6b600b6, 0x0000fdfdfdfd00fd,
  428. 0x0000595959590059, 0x0000989898980098, 0x00006a6a6a6a006a,
  429. 0x0000464646460046, 0x0000babababa00ba, 0x0000252525250025,
  430. 0x0000424242420042, 0x0000a2a2a2a200a2, 0x0000fafafafa00fa,
  431. 0x0000070707070007, 0x0000555555550055, 0x0000eeeeeeee00ee,
  432. 0x00000a0a0a0a000a, 0x0000494949490049, 0x0000686868680068,
  433. 0x0000383838380038, 0x0000a4a4a4a400a4, 0x0000282828280028,
  434. 0x00007b7b7b7b007b, 0x0000c9c9c9c900c9, 0x0000c1c1c1c100c1,
  435. 0x0000e3e3e3e300e3, 0x0000f4f4f4f400f4, 0x0000c7c7c7c700c7,
  436. 0x00009e9e9e9e009e,
  437. };
  438. const u64 camellia_sp02220222[256] = {
  439. 0x00e0e0e000e0e0e0, 0x0005050500050505, 0x0058585800585858,
  440. 0x00d9d9d900d9d9d9, 0x0067676700676767, 0x004e4e4e004e4e4e,
  441. 0x0081818100818181, 0x00cbcbcb00cbcbcb, 0x00c9c9c900c9c9c9,
  442. 0x000b0b0b000b0b0b, 0x00aeaeae00aeaeae, 0x006a6a6a006a6a6a,
  443. 0x00d5d5d500d5d5d5, 0x0018181800181818, 0x005d5d5d005d5d5d,
  444. 0x0082828200828282, 0x0046464600464646, 0x00dfdfdf00dfdfdf,
  445. 0x00d6d6d600d6d6d6, 0x0027272700272727, 0x008a8a8a008a8a8a,
  446. 0x0032323200323232, 0x004b4b4b004b4b4b, 0x0042424200424242,
  447. 0x00dbdbdb00dbdbdb, 0x001c1c1c001c1c1c, 0x009e9e9e009e9e9e,
  448. 0x009c9c9c009c9c9c, 0x003a3a3a003a3a3a, 0x00cacaca00cacaca,
  449. 0x0025252500252525, 0x007b7b7b007b7b7b, 0x000d0d0d000d0d0d,
  450. 0x0071717100717171, 0x005f5f5f005f5f5f, 0x001f1f1f001f1f1f,
  451. 0x00f8f8f800f8f8f8, 0x00d7d7d700d7d7d7, 0x003e3e3e003e3e3e,
  452. 0x009d9d9d009d9d9d, 0x007c7c7c007c7c7c, 0x0060606000606060,
  453. 0x00b9b9b900b9b9b9, 0x00bebebe00bebebe, 0x00bcbcbc00bcbcbc,
  454. 0x008b8b8b008b8b8b, 0x0016161600161616, 0x0034343400343434,
  455. 0x004d4d4d004d4d4d, 0x00c3c3c300c3c3c3, 0x0072727200727272,
  456. 0x0095959500959595, 0x00ababab00ababab, 0x008e8e8e008e8e8e,
  457. 0x00bababa00bababa, 0x007a7a7a007a7a7a, 0x00b3b3b300b3b3b3,
  458. 0x0002020200020202, 0x00b4b4b400b4b4b4, 0x00adadad00adadad,
  459. 0x00a2a2a200a2a2a2, 0x00acacac00acacac, 0x00d8d8d800d8d8d8,
  460. 0x009a9a9a009a9a9a, 0x0017171700171717, 0x001a1a1a001a1a1a,
  461. 0x0035353500353535, 0x00cccccc00cccccc, 0x00f7f7f700f7f7f7,
  462. 0x0099999900999999, 0x0061616100616161, 0x005a5a5a005a5a5a,
  463. 0x00e8e8e800e8e8e8, 0x0024242400242424, 0x0056565600565656,
  464. 0x0040404000404040, 0x00e1e1e100e1e1e1, 0x0063636300636363,
  465. 0x0009090900090909, 0x0033333300333333, 0x00bfbfbf00bfbfbf,
  466. 0x0098989800989898, 0x0097979700979797, 0x0085858500858585,
  467. 0x0068686800686868, 0x00fcfcfc00fcfcfc, 0x00ececec00ececec,
  468. 0x000a0a0a000a0a0a, 0x00dadada00dadada, 0x006f6f6f006f6f6f,
  469. 0x0053535300535353, 0x0062626200626262, 0x00a3a3a300a3a3a3,
  470. 0x002e2e2e002e2e2e, 0x0008080800080808, 0x00afafaf00afafaf,
  471. 0x0028282800282828, 0x00b0b0b000b0b0b0, 0x0074747400747474,
  472. 0x00c2c2c200c2c2c2, 0x00bdbdbd00bdbdbd, 0x0036363600363636,
  473. 0x0022222200222222, 0x0038383800383838, 0x0064646400646464,
  474. 0x001e1e1e001e1e1e, 0x0039393900393939, 0x002c2c2c002c2c2c,
  475. 0x00a6a6a600a6a6a6, 0x0030303000303030, 0x00e5e5e500e5e5e5,
  476. 0x0044444400444444, 0x00fdfdfd00fdfdfd, 0x0088888800888888,
  477. 0x009f9f9f009f9f9f, 0x0065656500656565, 0x0087878700878787,
  478. 0x006b6b6b006b6b6b, 0x00f4f4f400f4f4f4, 0x0023232300232323,
  479. 0x0048484800484848, 0x0010101000101010, 0x00d1d1d100d1d1d1,
  480. 0x0051515100515151, 0x00c0c0c000c0c0c0, 0x00f9f9f900f9f9f9,
  481. 0x00d2d2d200d2d2d2, 0x00a0a0a000a0a0a0, 0x0055555500555555,
  482. 0x00a1a1a100a1a1a1, 0x0041414100414141, 0x00fafafa00fafafa,
  483. 0x0043434300434343, 0x0013131300131313, 0x00c4c4c400c4c4c4,
  484. 0x002f2f2f002f2f2f, 0x00a8a8a800a8a8a8, 0x00b6b6b600b6b6b6,
  485. 0x003c3c3c003c3c3c, 0x002b2b2b002b2b2b, 0x00c1c1c100c1c1c1,
  486. 0x00ffffff00ffffff, 0x00c8c8c800c8c8c8, 0x00a5a5a500a5a5a5,
  487. 0x0020202000202020, 0x0089898900898989, 0x0000000000000000,
  488. 0x0090909000909090, 0x0047474700474747, 0x00efefef00efefef,
  489. 0x00eaeaea00eaeaea, 0x00b7b7b700b7b7b7, 0x0015151500151515,
  490. 0x0006060600060606, 0x00cdcdcd00cdcdcd, 0x00b5b5b500b5b5b5,
  491. 0x0012121200121212, 0x007e7e7e007e7e7e, 0x00bbbbbb00bbbbbb,
  492. 0x0029292900292929, 0x000f0f0f000f0f0f, 0x00b8b8b800b8b8b8,
  493. 0x0007070700070707, 0x0004040400040404, 0x009b9b9b009b9b9b,
  494. 0x0094949400949494, 0x0021212100212121, 0x0066666600666666,
  495. 0x00e6e6e600e6e6e6, 0x00cecece00cecece, 0x00ededed00ededed,
  496. 0x00e7e7e700e7e7e7, 0x003b3b3b003b3b3b, 0x00fefefe00fefefe,
  497. 0x007f7f7f007f7f7f, 0x00c5c5c500c5c5c5, 0x00a4a4a400a4a4a4,
  498. 0x0037373700373737, 0x00b1b1b100b1b1b1, 0x004c4c4c004c4c4c,
  499. 0x0091919100919191, 0x006e6e6e006e6e6e, 0x008d8d8d008d8d8d,
  500. 0x0076767600767676, 0x0003030300030303, 0x002d2d2d002d2d2d,
  501. 0x00dedede00dedede, 0x0096969600969696, 0x0026262600262626,
  502. 0x007d7d7d007d7d7d, 0x00c6c6c600c6c6c6, 0x005c5c5c005c5c5c,
  503. 0x00d3d3d300d3d3d3, 0x00f2f2f200f2f2f2, 0x004f4f4f004f4f4f,
  504. 0x0019191900191919, 0x003f3f3f003f3f3f, 0x00dcdcdc00dcdcdc,
  505. 0x0079797900797979, 0x001d1d1d001d1d1d, 0x0052525200525252,
  506. 0x00ebebeb00ebebeb, 0x00f3f3f300f3f3f3, 0x006d6d6d006d6d6d,
  507. 0x005e5e5e005e5e5e, 0x00fbfbfb00fbfbfb, 0x0069696900696969,
  508. 0x00b2b2b200b2b2b2, 0x00f0f0f000f0f0f0, 0x0031313100313131,
  509. 0x000c0c0c000c0c0c, 0x00d4d4d400d4d4d4, 0x00cfcfcf00cfcfcf,
  510. 0x008c8c8c008c8c8c, 0x00e2e2e200e2e2e2, 0x0075757500757575,
  511. 0x00a9a9a900a9a9a9, 0x004a4a4a004a4a4a, 0x0057575700575757,
  512. 0x0084848400848484, 0x0011111100111111, 0x0045454500454545,
  513. 0x001b1b1b001b1b1b, 0x00f5f5f500f5f5f5, 0x00e4e4e400e4e4e4,
  514. 0x000e0e0e000e0e0e, 0x0073737300737373, 0x00aaaaaa00aaaaaa,
  515. 0x00f1f1f100f1f1f1, 0x00dddddd00dddddd, 0x0059595900595959,
  516. 0x0014141400141414, 0x006c6c6c006c6c6c, 0x0092929200929292,
  517. 0x0054545400545454, 0x00d0d0d000d0d0d0, 0x0078787800787878,
  518. 0x0070707000707070, 0x00e3e3e300e3e3e3, 0x0049494900494949,
  519. 0x0080808000808080, 0x0050505000505050, 0x00a7a7a700a7a7a7,
  520. 0x00f6f6f600f6f6f6, 0x0077777700777777, 0x0093939300939393,
  521. 0x0086868600868686, 0x0083838300838383, 0x002a2a2a002a2a2a,
  522. 0x00c7c7c700c7c7c7, 0x005b5b5b005b5b5b, 0x00e9e9e900e9e9e9,
  523. 0x00eeeeee00eeeeee, 0x008f8f8f008f8f8f, 0x0001010100010101,
  524. 0x003d3d3d003d3d3d,
  525. };
  526. const u64 camellia_sp30333033[256] = {
  527. 0x3800383838003838, 0x4100414141004141, 0x1600161616001616,
  528. 0x7600767676007676, 0xd900d9d9d900d9d9, 0x9300939393009393,
  529. 0x6000606060006060, 0xf200f2f2f200f2f2, 0x7200727272007272,
  530. 0xc200c2c2c200c2c2, 0xab00ababab00abab, 0x9a009a9a9a009a9a,
  531. 0x7500757575007575, 0x0600060606000606, 0x5700575757005757,
  532. 0xa000a0a0a000a0a0, 0x9100919191009191, 0xf700f7f7f700f7f7,
  533. 0xb500b5b5b500b5b5, 0xc900c9c9c900c9c9, 0xa200a2a2a200a2a2,
  534. 0x8c008c8c8c008c8c, 0xd200d2d2d200d2d2, 0x9000909090009090,
  535. 0xf600f6f6f600f6f6, 0x0700070707000707, 0xa700a7a7a700a7a7,
  536. 0x2700272727002727, 0x8e008e8e8e008e8e, 0xb200b2b2b200b2b2,
  537. 0x4900494949004949, 0xde00dedede00dede, 0x4300434343004343,
  538. 0x5c005c5c5c005c5c, 0xd700d7d7d700d7d7, 0xc700c7c7c700c7c7,
  539. 0x3e003e3e3e003e3e, 0xf500f5f5f500f5f5, 0x8f008f8f8f008f8f,
  540. 0x6700676767006767, 0x1f001f1f1f001f1f, 0x1800181818001818,
  541. 0x6e006e6e6e006e6e, 0xaf00afafaf00afaf, 0x2f002f2f2f002f2f,
  542. 0xe200e2e2e200e2e2, 0x8500858585008585, 0x0d000d0d0d000d0d,
  543. 0x5300535353005353, 0xf000f0f0f000f0f0, 0x9c009c9c9c009c9c,
  544. 0x6500656565006565, 0xea00eaeaea00eaea, 0xa300a3a3a300a3a3,
  545. 0xae00aeaeae00aeae, 0x9e009e9e9e009e9e, 0xec00ececec00ecec,
  546. 0x8000808080008080, 0x2d002d2d2d002d2d, 0x6b006b6b6b006b6b,
  547. 0xa800a8a8a800a8a8, 0x2b002b2b2b002b2b, 0x3600363636003636,
  548. 0xa600a6a6a600a6a6, 0xc500c5c5c500c5c5, 0x8600868686008686,
  549. 0x4d004d4d4d004d4d, 0x3300333333003333, 0xfd00fdfdfd00fdfd,
  550. 0x6600666666006666, 0x5800585858005858, 0x9600969696009696,
  551. 0x3a003a3a3a003a3a, 0x0900090909000909, 0x9500959595009595,
  552. 0x1000101010001010, 0x7800787878007878, 0xd800d8d8d800d8d8,
  553. 0x4200424242004242, 0xcc00cccccc00cccc, 0xef00efefef00efef,
  554. 0x2600262626002626, 0xe500e5e5e500e5e5, 0x6100616161006161,
  555. 0x1a001a1a1a001a1a, 0x3f003f3f3f003f3f, 0x3b003b3b3b003b3b,
  556. 0x8200828282008282, 0xb600b6b6b600b6b6, 0xdb00dbdbdb00dbdb,
  557. 0xd400d4d4d400d4d4, 0x9800989898009898, 0xe800e8e8e800e8e8,
  558. 0x8b008b8b8b008b8b, 0x0200020202000202, 0xeb00ebebeb00ebeb,
  559. 0x0a000a0a0a000a0a, 0x2c002c2c2c002c2c, 0x1d001d1d1d001d1d,
  560. 0xb000b0b0b000b0b0, 0x6f006f6f6f006f6f, 0x8d008d8d8d008d8d,
  561. 0x8800888888008888, 0x0e000e0e0e000e0e, 0x1900191919001919,
  562. 0x8700878787008787, 0x4e004e4e4e004e4e, 0x0b000b0b0b000b0b,
  563. 0xa900a9a9a900a9a9, 0x0c000c0c0c000c0c, 0x7900797979007979,
  564. 0x1100111111001111, 0x7f007f7f7f007f7f, 0x2200222222002222,
  565. 0xe700e7e7e700e7e7, 0x5900595959005959, 0xe100e1e1e100e1e1,
  566. 0xda00dadada00dada, 0x3d003d3d3d003d3d, 0xc800c8c8c800c8c8,
  567. 0x1200121212001212, 0x0400040404000404, 0x7400747474007474,
  568. 0x5400545454005454, 0x3000303030003030, 0x7e007e7e7e007e7e,
  569. 0xb400b4b4b400b4b4, 0x2800282828002828, 0x5500555555005555,
  570. 0x6800686868006868, 0x5000505050005050, 0xbe00bebebe00bebe,
  571. 0xd000d0d0d000d0d0, 0xc400c4c4c400c4c4, 0x3100313131003131,
  572. 0xcb00cbcbcb00cbcb, 0x2a002a2a2a002a2a, 0xad00adadad00adad,
  573. 0x0f000f0f0f000f0f, 0xca00cacaca00caca, 0x7000707070007070,
  574. 0xff00ffffff00ffff, 0x3200323232003232, 0x6900696969006969,
  575. 0x0800080808000808, 0x6200626262006262, 0x0000000000000000,
  576. 0x2400242424002424, 0xd100d1d1d100d1d1, 0xfb00fbfbfb00fbfb,
  577. 0xba00bababa00baba, 0xed00ededed00eded, 0x4500454545004545,
  578. 0x8100818181008181, 0x7300737373007373, 0x6d006d6d6d006d6d,
  579. 0x8400848484008484, 0x9f009f9f9f009f9f, 0xee00eeeeee00eeee,
  580. 0x4a004a4a4a004a4a, 0xc300c3c3c300c3c3, 0x2e002e2e2e002e2e,
  581. 0xc100c1c1c100c1c1, 0x0100010101000101, 0xe600e6e6e600e6e6,
  582. 0x2500252525002525, 0x4800484848004848, 0x9900999999009999,
  583. 0xb900b9b9b900b9b9, 0xb300b3b3b300b3b3, 0x7b007b7b7b007b7b,
  584. 0xf900f9f9f900f9f9, 0xce00cecece00cece, 0xbf00bfbfbf00bfbf,
  585. 0xdf00dfdfdf00dfdf, 0x7100717171007171, 0x2900292929002929,
  586. 0xcd00cdcdcd00cdcd, 0x6c006c6c6c006c6c, 0x1300131313001313,
  587. 0x6400646464006464, 0x9b009b9b9b009b9b, 0x6300636363006363,
  588. 0x9d009d9d9d009d9d, 0xc000c0c0c000c0c0, 0x4b004b4b4b004b4b,
  589. 0xb700b7b7b700b7b7, 0xa500a5a5a500a5a5, 0x8900898989008989,
  590. 0x5f005f5f5f005f5f, 0xb100b1b1b100b1b1, 0x1700171717001717,
  591. 0xf400f4f4f400f4f4, 0xbc00bcbcbc00bcbc, 0xd300d3d3d300d3d3,
  592. 0x4600464646004646, 0xcf00cfcfcf00cfcf, 0x3700373737003737,
  593. 0x5e005e5e5e005e5e, 0x4700474747004747, 0x9400949494009494,
  594. 0xfa00fafafa00fafa, 0xfc00fcfcfc00fcfc, 0x5b005b5b5b005b5b,
  595. 0x9700979797009797, 0xfe00fefefe00fefe, 0x5a005a5a5a005a5a,
  596. 0xac00acacac00acac, 0x3c003c3c3c003c3c, 0x4c004c4c4c004c4c,
  597. 0x0300030303000303, 0x3500353535003535, 0xf300f3f3f300f3f3,
  598. 0x2300232323002323, 0xb800b8b8b800b8b8, 0x5d005d5d5d005d5d,
  599. 0x6a006a6a6a006a6a, 0x9200929292009292, 0xd500d5d5d500d5d5,
  600. 0x2100212121002121, 0x4400444444004444, 0x5100515151005151,
  601. 0xc600c6c6c600c6c6, 0x7d007d7d7d007d7d, 0x3900393939003939,
  602. 0x8300838383008383, 0xdc00dcdcdc00dcdc, 0xaa00aaaaaa00aaaa,
  603. 0x7c007c7c7c007c7c, 0x7700777777007777, 0x5600565656005656,
  604. 0x0500050505000505, 0x1b001b1b1b001b1b, 0xa400a4a4a400a4a4,
  605. 0x1500151515001515, 0x3400343434003434, 0x1e001e1e1e001e1e,
  606. 0x1c001c1c1c001c1c, 0xf800f8f8f800f8f8, 0x5200525252005252,
  607. 0x2000202020002020, 0x1400141414001414, 0xe900e9e9e900e9e9,
  608. 0xbd00bdbdbd00bdbd, 0xdd00dddddd00dddd, 0xe400e4e4e400e4e4,
  609. 0xa100a1a1a100a1a1, 0xe000e0e0e000e0e0, 0x8a008a8a8a008a8a,
  610. 0xf100f1f1f100f1f1, 0xd600d6d6d600d6d6, 0x7a007a7a7a007a7a,
  611. 0xbb00bbbbbb00bbbb, 0xe300e3e3e300e3e3, 0x4000404040004040,
  612. 0x4f004f4f4f004f4f,
  613. };
  614. const u64 camellia_sp44044404[256] = {
  615. 0x7070007070700070, 0x2c2c002c2c2c002c, 0xb3b300b3b3b300b3,
  616. 0xc0c000c0c0c000c0, 0xe4e400e4e4e400e4, 0x5757005757570057,
  617. 0xeaea00eaeaea00ea, 0xaeae00aeaeae00ae, 0x2323002323230023,
  618. 0x6b6b006b6b6b006b, 0x4545004545450045, 0xa5a500a5a5a500a5,
  619. 0xeded00ededed00ed, 0x4f4f004f4f4f004f, 0x1d1d001d1d1d001d,
  620. 0x9292009292920092, 0x8686008686860086, 0xafaf00afafaf00af,
  621. 0x7c7c007c7c7c007c, 0x1f1f001f1f1f001f, 0x3e3e003e3e3e003e,
  622. 0xdcdc00dcdcdc00dc, 0x5e5e005e5e5e005e, 0x0b0b000b0b0b000b,
  623. 0xa6a600a6a6a600a6, 0x3939003939390039, 0xd5d500d5d5d500d5,
  624. 0x5d5d005d5d5d005d, 0xd9d900d9d9d900d9, 0x5a5a005a5a5a005a,
  625. 0x5151005151510051, 0x6c6c006c6c6c006c, 0x8b8b008b8b8b008b,
  626. 0x9a9a009a9a9a009a, 0xfbfb00fbfbfb00fb, 0xb0b000b0b0b000b0,
  627. 0x7474007474740074, 0x2b2b002b2b2b002b, 0xf0f000f0f0f000f0,
  628. 0x8484008484840084, 0xdfdf00dfdfdf00df, 0xcbcb00cbcbcb00cb,
  629. 0x3434003434340034, 0x7676007676760076, 0x6d6d006d6d6d006d,
  630. 0xa9a900a9a9a900a9, 0xd1d100d1d1d100d1, 0x0404000404040004,
  631. 0x1414001414140014, 0x3a3a003a3a3a003a, 0xdede00dedede00de,
  632. 0x1111001111110011, 0x3232003232320032, 0x9c9c009c9c9c009c,
  633. 0x5353005353530053, 0xf2f200f2f2f200f2, 0xfefe00fefefe00fe,
  634. 0xcfcf00cfcfcf00cf, 0xc3c300c3c3c300c3, 0x7a7a007a7a7a007a,
  635. 0x2424002424240024, 0xe8e800e8e8e800e8, 0x6060006060600060,
  636. 0x6969006969690069, 0xaaaa00aaaaaa00aa, 0xa0a000a0a0a000a0,
  637. 0xa1a100a1a1a100a1, 0x6262006262620062, 0x5454005454540054,
  638. 0x1e1e001e1e1e001e, 0xe0e000e0e0e000e0, 0x6464006464640064,
  639. 0x1010001010100010, 0x0000000000000000, 0xa3a300a3a3a300a3,
  640. 0x7575007575750075, 0x8a8a008a8a8a008a, 0xe6e600e6e6e600e6,
  641. 0x0909000909090009, 0xdddd00dddddd00dd, 0x8787008787870087,
  642. 0x8383008383830083, 0xcdcd00cdcdcd00cd, 0x9090009090900090,
  643. 0x7373007373730073, 0xf6f600f6f6f600f6, 0x9d9d009d9d9d009d,
  644. 0xbfbf00bfbfbf00bf, 0x5252005252520052, 0xd8d800d8d8d800d8,
  645. 0xc8c800c8c8c800c8, 0xc6c600c6c6c600c6, 0x8181008181810081,
  646. 0x6f6f006f6f6f006f, 0x1313001313130013, 0x6363006363630063,
  647. 0xe9e900e9e9e900e9, 0xa7a700a7a7a700a7, 0x9f9f009f9f9f009f,
  648. 0xbcbc00bcbcbc00bc, 0x2929002929290029, 0xf9f900f9f9f900f9,
  649. 0x2f2f002f2f2f002f, 0xb4b400b4b4b400b4, 0x7878007878780078,
  650. 0x0606000606060006, 0xe7e700e7e7e700e7, 0x7171007171710071,
  651. 0xd4d400d4d4d400d4, 0xabab00ababab00ab, 0x8888008888880088,
  652. 0x8d8d008d8d8d008d, 0x7272007272720072, 0xb9b900b9b9b900b9,
  653. 0xf8f800f8f8f800f8, 0xacac00acacac00ac, 0x3636003636360036,
  654. 0x2a2a002a2a2a002a, 0x3c3c003c3c3c003c, 0xf1f100f1f1f100f1,
  655. 0x4040004040400040, 0xd3d300d3d3d300d3, 0xbbbb00bbbbbb00bb,
  656. 0x4343004343430043, 0x1515001515150015, 0xadad00adadad00ad,
  657. 0x7777007777770077, 0x8080008080800080, 0x8282008282820082,
  658. 0xecec00ececec00ec, 0x2727002727270027, 0xe5e500e5e5e500e5,
  659. 0x8585008585850085, 0x3535003535350035, 0x0c0c000c0c0c000c,
  660. 0x4141004141410041, 0xefef00efefef00ef, 0x9393009393930093,
  661. 0x1919001919190019, 0x2121002121210021, 0x0e0e000e0e0e000e,
  662. 0x4e4e004e4e4e004e, 0x6565006565650065, 0xbdbd00bdbdbd00bd,
  663. 0xb8b800b8b8b800b8, 0x8f8f008f8f8f008f, 0xebeb00ebebeb00eb,
  664. 0xcece00cecece00ce, 0x3030003030300030, 0x5f5f005f5f5f005f,
  665. 0xc5c500c5c5c500c5, 0x1a1a001a1a1a001a, 0xe1e100e1e1e100e1,
  666. 0xcaca00cacaca00ca, 0x4747004747470047, 0x3d3d003d3d3d003d,
  667. 0x0101000101010001, 0xd6d600d6d6d600d6, 0x5656005656560056,
  668. 0x4d4d004d4d4d004d, 0x0d0d000d0d0d000d, 0x6666006666660066,
  669. 0xcccc00cccccc00cc, 0x2d2d002d2d2d002d, 0x1212001212120012,
  670. 0x2020002020200020, 0xb1b100b1b1b100b1, 0x9999009999990099,
  671. 0x4c4c004c4c4c004c, 0xc2c200c2c2c200c2, 0x7e7e007e7e7e007e,
  672. 0x0505000505050005, 0xb7b700b7b7b700b7, 0x3131003131310031,
  673. 0x1717001717170017, 0xd7d700d7d7d700d7, 0x5858005858580058,
  674. 0x6161006161610061, 0x1b1b001b1b1b001b, 0x1c1c001c1c1c001c,
  675. 0x0f0f000f0f0f000f, 0x1616001616160016, 0x1818001818180018,
  676. 0x2222002222220022, 0x4444004444440044, 0xb2b200b2b2b200b2,
  677. 0xb5b500b5b5b500b5, 0x9191009191910091, 0x0808000808080008,
  678. 0xa8a800a8a8a800a8, 0xfcfc00fcfcfc00fc, 0x5050005050500050,
  679. 0xd0d000d0d0d000d0, 0x7d7d007d7d7d007d, 0x8989008989890089,
  680. 0x9797009797970097, 0x5b5b005b5b5b005b, 0x9595009595950095,
  681. 0xffff00ffffff00ff, 0xd2d200d2d2d200d2, 0xc4c400c4c4c400c4,
  682. 0x4848004848480048, 0xf7f700f7f7f700f7, 0xdbdb00dbdbdb00db,
  683. 0x0303000303030003, 0xdada00dadada00da, 0x3f3f003f3f3f003f,
  684. 0x9494009494940094, 0x5c5c005c5c5c005c, 0x0202000202020002,
  685. 0x4a4a004a4a4a004a, 0x3333003333330033, 0x6767006767670067,
  686. 0xf3f300f3f3f300f3, 0x7f7f007f7f7f007f, 0xe2e200e2e2e200e2,
  687. 0x9b9b009b9b9b009b, 0x2626002626260026, 0x3737003737370037,
  688. 0x3b3b003b3b3b003b, 0x9696009696960096, 0x4b4b004b4b4b004b,
  689. 0xbebe00bebebe00be, 0x2e2e002e2e2e002e, 0x7979007979790079,
  690. 0x8c8c008c8c8c008c, 0x6e6e006e6e6e006e, 0x8e8e008e8e8e008e,
  691. 0xf5f500f5f5f500f5, 0xb6b600b6b6b600b6, 0xfdfd00fdfdfd00fd,
  692. 0x5959005959590059, 0x9898009898980098, 0x6a6a006a6a6a006a,
  693. 0x4646004646460046, 0xbaba00bababa00ba, 0x2525002525250025,
  694. 0x4242004242420042, 0xa2a200a2a2a200a2, 0xfafa00fafafa00fa,
  695. 0x0707000707070007, 0x5555005555550055, 0xeeee00eeeeee00ee,
  696. 0x0a0a000a0a0a000a, 0x4949004949490049, 0x6868006868680068,
  697. 0x3838003838380038, 0xa4a400a4a4a400a4, 0x2828002828280028,
  698. 0x7b7b007b7b7b007b, 0xc9c900c9c9c900c9, 0xc1c100c1c1c100c1,
  699. 0xe3e300e3e3e300e3, 0xf4f400f4f4f400f4, 0xc7c700c7c7c700c7,
  700. 0x9e9e009e9e9e009e,
  701. };
  702. const u64 camellia_sp11101110[256] = {
  703. 0x7070700070707000, 0x8282820082828200, 0x2c2c2c002c2c2c00,
  704. 0xececec00ececec00, 0xb3b3b300b3b3b300, 0x2727270027272700,
  705. 0xc0c0c000c0c0c000, 0xe5e5e500e5e5e500, 0xe4e4e400e4e4e400,
  706. 0x8585850085858500, 0x5757570057575700, 0x3535350035353500,
  707. 0xeaeaea00eaeaea00, 0x0c0c0c000c0c0c00, 0xaeaeae00aeaeae00,
  708. 0x4141410041414100, 0x2323230023232300, 0xefefef00efefef00,
  709. 0x6b6b6b006b6b6b00, 0x9393930093939300, 0x4545450045454500,
  710. 0x1919190019191900, 0xa5a5a500a5a5a500, 0x2121210021212100,
  711. 0xededed00ededed00, 0x0e0e0e000e0e0e00, 0x4f4f4f004f4f4f00,
  712. 0x4e4e4e004e4e4e00, 0x1d1d1d001d1d1d00, 0x6565650065656500,
  713. 0x9292920092929200, 0xbdbdbd00bdbdbd00, 0x8686860086868600,
  714. 0xb8b8b800b8b8b800, 0xafafaf00afafaf00, 0x8f8f8f008f8f8f00,
  715. 0x7c7c7c007c7c7c00, 0xebebeb00ebebeb00, 0x1f1f1f001f1f1f00,
  716. 0xcecece00cecece00, 0x3e3e3e003e3e3e00, 0x3030300030303000,
  717. 0xdcdcdc00dcdcdc00, 0x5f5f5f005f5f5f00, 0x5e5e5e005e5e5e00,
  718. 0xc5c5c500c5c5c500, 0x0b0b0b000b0b0b00, 0x1a1a1a001a1a1a00,
  719. 0xa6a6a600a6a6a600, 0xe1e1e100e1e1e100, 0x3939390039393900,
  720. 0xcacaca00cacaca00, 0xd5d5d500d5d5d500, 0x4747470047474700,
  721. 0x5d5d5d005d5d5d00, 0x3d3d3d003d3d3d00, 0xd9d9d900d9d9d900,
  722. 0x0101010001010100, 0x5a5a5a005a5a5a00, 0xd6d6d600d6d6d600,
  723. 0x5151510051515100, 0x5656560056565600, 0x6c6c6c006c6c6c00,
  724. 0x4d4d4d004d4d4d00, 0x8b8b8b008b8b8b00, 0x0d0d0d000d0d0d00,
  725. 0x9a9a9a009a9a9a00, 0x6666660066666600, 0xfbfbfb00fbfbfb00,
  726. 0xcccccc00cccccc00, 0xb0b0b000b0b0b000, 0x2d2d2d002d2d2d00,
  727. 0x7474740074747400, 0x1212120012121200, 0x2b2b2b002b2b2b00,
  728. 0x2020200020202000, 0xf0f0f000f0f0f000, 0xb1b1b100b1b1b100,
  729. 0x8484840084848400, 0x9999990099999900, 0xdfdfdf00dfdfdf00,
  730. 0x4c4c4c004c4c4c00, 0xcbcbcb00cbcbcb00, 0xc2c2c200c2c2c200,
  731. 0x3434340034343400, 0x7e7e7e007e7e7e00, 0x7676760076767600,
  732. 0x0505050005050500, 0x6d6d6d006d6d6d00, 0xb7b7b700b7b7b700,
  733. 0xa9a9a900a9a9a900, 0x3131310031313100, 0xd1d1d100d1d1d100,
  734. 0x1717170017171700, 0x0404040004040400, 0xd7d7d700d7d7d700,
  735. 0x1414140014141400, 0x5858580058585800, 0x3a3a3a003a3a3a00,
  736. 0x6161610061616100, 0xdedede00dedede00, 0x1b1b1b001b1b1b00,
  737. 0x1111110011111100, 0x1c1c1c001c1c1c00, 0x3232320032323200,
  738. 0x0f0f0f000f0f0f00, 0x9c9c9c009c9c9c00, 0x1616160016161600,
  739. 0x5353530053535300, 0x1818180018181800, 0xf2f2f200f2f2f200,
  740. 0x2222220022222200, 0xfefefe00fefefe00, 0x4444440044444400,
  741. 0xcfcfcf00cfcfcf00, 0xb2b2b200b2b2b200, 0xc3c3c300c3c3c300,
  742. 0xb5b5b500b5b5b500, 0x7a7a7a007a7a7a00, 0x9191910091919100,
  743. 0x2424240024242400, 0x0808080008080800, 0xe8e8e800e8e8e800,
  744. 0xa8a8a800a8a8a800, 0x6060600060606000, 0xfcfcfc00fcfcfc00,
  745. 0x6969690069696900, 0x5050500050505000, 0xaaaaaa00aaaaaa00,
  746. 0xd0d0d000d0d0d000, 0xa0a0a000a0a0a000, 0x7d7d7d007d7d7d00,
  747. 0xa1a1a100a1a1a100, 0x8989890089898900, 0x6262620062626200,
  748. 0x9797970097979700, 0x5454540054545400, 0x5b5b5b005b5b5b00,
  749. 0x1e1e1e001e1e1e00, 0x9595950095959500, 0xe0e0e000e0e0e000,
  750. 0xffffff00ffffff00, 0x6464640064646400, 0xd2d2d200d2d2d200,
  751. 0x1010100010101000, 0xc4c4c400c4c4c400, 0x0000000000000000,
  752. 0x4848480048484800, 0xa3a3a300a3a3a300, 0xf7f7f700f7f7f700,
  753. 0x7575750075757500, 0xdbdbdb00dbdbdb00, 0x8a8a8a008a8a8a00,
  754. 0x0303030003030300, 0xe6e6e600e6e6e600, 0xdadada00dadada00,
  755. 0x0909090009090900, 0x3f3f3f003f3f3f00, 0xdddddd00dddddd00,
  756. 0x9494940094949400, 0x8787870087878700, 0x5c5c5c005c5c5c00,
  757. 0x8383830083838300, 0x0202020002020200, 0xcdcdcd00cdcdcd00,
  758. 0x4a4a4a004a4a4a00, 0x9090900090909000, 0x3333330033333300,
  759. 0x7373730073737300, 0x6767670067676700, 0xf6f6f600f6f6f600,
  760. 0xf3f3f300f3f3f300, 0x9d9d9d009d9d9d00, 0x7f7f7f007f7f7f00,
  761. 0xbfbfbf00bfbfbf00, 0xe2e2e200e2e2e200, 0x5252520052525200,
  762. 0x9b9b9b009b9b9b00, 0xd8d8d800d8d8d800, 0x2626260026262600,
  763. 0xc8c8c800c8c8c800, 0x3737370037373700, 0xc6c6c600c6c6c600,
  764. 0x3b3b3b003b3b3b00, 0x8181810081818100, 0x9696960096969600,
  765. 0x6f6f6f006f6f6f00, 0x4b4b4b004b4b4b00, 0x1313130013131300,
  766. 0xbebebe00bebebe00, 0x6363630063636300, 0x2e2e2e002e2e2e00,
  767. 0xe9e9e900e9e9e900, 0x7979790079797900, 0xa7a7a700a7a7a700,
  768. 0x8c8c8c008c8c8c00, 0x9f9f9f009f9f9f00, 0x6e6e6e006e6e6e00,
  769. 0xbcbcbc00bcbcbc00, 0x8e8e8e008e8e8e00, 0x2929290029292900,
  770. 0xf5f5f500f5f5f500, 0xf9f9f900f9f9f900, 0xb6b6b600b6b6b600,
  771. 0x2f2f2f002f2f2f00, 0xfdfdfd00fdfdfd00, 0xb4b4b400b4b4b400,
  772. 0x5959590059595900, 0x7878780078787800, 0x9898980098989800,
  773. 0x0606060006060600, 0x6a6a6a006a6a6a00, 0xe7e7e700e7e7e700,
  774. 0x4646460046464600, 0x7171710071717100, 0xbababa00bababa00,
  775. 0xd4d4d400d4d4d400, 0x2525250025252500, 0xababab00ababab00,
  776. 0x4242420042424200, 0x8888880088888800, 0xa2a2a200a2a2a200,
  777. 0x8d8d8d008d8d8d00, 0xfafafa00fafafa00, 0x7272720072727200,
  778. 0x0707070007070700, 0xb9b9b900b9b9b900, 0x5555550055555500,
  779. 0xf8f8f800f8f8f800, 0xeeeeee00eeeeee00, 0xacacac00acacac00,
  780. 0x0a0a0a000a0a0a00, 0x3636360036363600, 0x4949490049494900,
  781. 0x2a2a2a002a2a2a00, 0x6868680068686800, 0x3c3c3c003c3c3c00,
  782. 0x3838380038383800, 0xf1f1f100f1f1f100, 0xa4a4a400a4a4a400,
  783. 0x4040400040404000, 0x2828280028282800, 0xd3d3d300d3d3d300,
  784. 0x7b7b7b007b7b7b00, 0xbbbbbb00bbbbbb00, 0xc9c9c900c9c9c900,
  785. 0x4343430043434300, 0xc1c1c100c1c1c100, 0x1515150015151500,
  786. 0xe3e3e300e3e3e300, 0xadadad00adadad00, 0xf4f4f400f4f4f400,
  787. 0x7777770077777700, 0xc7c7c700c7c7c700, 0x8080800080808000,
  788. 0x9e9e9e009e9e9e00,
  789. };
  790. /* key constants */
  791. #define CAMELLIA_SIGMA1L (0xA09E667FL)
  792. #define CAMELLIA_SIGMA1R (0x3BCC908BL)
  793. #define CAMELLIA_SIGMA2L (0xB67AE858L)
  794. #define CAMELLIA_SIGMA2R (0x4CAA73B2L)
  795. #define CAMELLIA_SIGMA3L (0xC6EF372FL)
  796. #define CAMELLIA_SIGMA3R (0xE94F82BEL)
  797. #define CAMELLIA_SIGMA4L (0x54FF53A5L)
  798. #define CAMELLIA_SIGMA4R (0xF1D36F1CL)
  799. #define CAMELLIA_SIGMA5L (0x10E527FAL)
  800. #define CAMELLIA_SIGMA5R (0xDE682D1DL)
  801. #define CAMELLIA_SIGMA6L (0xB05688C2L)
  802. #define CAMELLIA_SIGMA6R (0xB3E6C1FDL)
  803. /* macros */
  804. #define ROLDQ(l, r, bits) ({ \
  805. u64 t = l; \
  806. l = (l << bits) | (r >> (64 - bits)); \
  807. r = (r << bits) | (t >> (64 - bits)); \
  808. })
  809. #define CAMELLIA_F(x, kl, kr, y) ({ \
  810. u64 ii = x ^ (((u64)kl << 32) | kr); \
  811. y = camellia_sp11101110[(uint8_t)ii]; \
  812. y ^= camellia_sp44044404[(uint8_t)(ii >> 8)]; \
  813. ii >>= 16; \
  814. y ^= camellia_sp30333033[(uint8_t)ii]; \
  815. y ^= camellia_sp02220222[(uint8_t)(ii >> 8)]; \
  816. ii >>= 16; \
  817. y ^= camellia_sp00444404[(uint8_t)ii]; \
  818. y ^= camellia_sp03303033[(uint8_t)(ii >> 8)]; \
  819. ii >>= 16; \
  820. y ^= camellia_sp22000222[(uint8_t)ii]; \
  821. y ^= camellia_sp10011110[(uint8_t)(ii >> 8)]; \
  822. y = ror64(y, 32); \
  823. })
  824. #define SET_SUBKEY_LR(INDEX, sRL) (subkey[(INDEX)] = ror64((sRL), 32))
  825. static void camellia_setup_tail(u64 *subkey, u64 *subRL, int max)
  826. {
  827. u64 kw4, tt;
  828. u32 dw, tl, tr;
  829. /* absorb kw2 to other subkeys */
  830. /* round 2 */
  831. subRL[3] ^= subRL[1];
  832. /* round 4 */
  833. subRL[5] ^= subRL[1];
  834. /* round 6 */
  835. subRL[7] ^= subRL[1];
  836. subRL[1] ^= (subRL[1] & ~subRL[9]) << 32;
  837. /* modified for FLinv(kl2) */
  838. dw = (subRL[1] & subRL[9]) >> 32,
  839. subRL[1] ^= rol32(dw, 1);
  840. /* round 8 */
  841. subRL[11] ^= subRL[1];
  842. /* round 10 */
  843. subRL[13] ^= subRL[1];
  844. /* round 12 */
  845. subRL[15] ^= subRL[1];
  846. subRL[1] ^= (subRL[1] & ~subRL[17]) << 32;
  847. /* modified for FLinv(kl4) */
  848. dw = (subRL[1] & subRL[17]) >> 32,
  849. subRL[1] ^= rol32(dw, 1);
  850. /* round 14 */
  851. subRL[19] ^= subRL[1];
  852. /* round 16 */
  853. subRL[21] ^= subRL[1];
  854. /* round 18 */
  855. subRL[23] ^= subRL[1];
  856. if (max == 24) {
  857. /* kw3 */
  858. subRL[24] ^= subRL[1];
  859. /* absorb kw4 to other subkeys */
  860. kw4 = subRL[25];
  861. } else {
  862. subRL[1] ^= (subRL[1] & ~subRL[25]) << 32;
  863. /* modified for FLinv(kl6) */
  864. dw = (subRL[1] & subRL[25]) >> 32,
  865. subRL[1] ^= rol32(dw, 1);
  866. /* round 20 */
  867. subRL[27] ^= subRL[1];
  868. /* round 22 */
  869. subRL[29] ^= subRL[1];
  870. /* round 24 */
  871. subRL[31] ^= subRL[1];
  872. /* kw3 */
  873. subRL[32] ^= subRL[1];
  874. /* absorb kw4 to other subkeys */
  875. kw4 = subRL[33];
  876. /* round 23 */
  877. subRL[30] ^= kw4;
  878. /* round 21 */
  879. subRL[28] ^= kw4;
  880. /* round 19 */
  881. subRL[26] ^= kw4;
  882. kw4 ^= (kw4 & ~subRL[24]) << 32;
  883. /* modified for FL(kl5) */
  884. dw = (kw4 & subRL[24]) >> 32,
  885. kw4 ^= rol32(dw, 1);
  886. }
  887. /* round 17 */
  888. subRL[22] ^= kw4;
  889. /* round 15 */
  890. subRL[20] ^= kw4;
  891. /* round 13 */
  892. subRL[18] ^= kw4;
  893. kw4 ^= (kw4 & ~subRL[16]) << 32;
  894. /* modified for FL(kl3) */
  895. dw = (kw4 & subRL[16]) >> 32,
  896. kw4 ^= rol32(dw, 1);
  897. /* round 11 */
  898. subRL[14] ^= kw4;
  899. /* round 9 */
  900. subRL[12] ^= kw4;
  901. /* round 7 */
  902. subRL[10] ^= kw4;
  903. kw4 ^= (kw4 & ~subRL[8]) << 32;
  904. /* modified for FL(kl1) */
  905. dw = (kw4 & subRL[8]) >> 32,
  906. kw4 ^= rol32(dw, 1);
  907. /* round 5 */
  908. subRL[6] ^= kw4;
  909. /* round 3 */
  910. subRL[4] ^= kw4;
  911. /* round 1 */
  912. subRL[2] ^= kw4;
  913. /* kw1 */
  914. subRL[0] ^= kw4;
  915. /* key XOR is end of F-function */
  916. SET_SUBKEY_LR(0, subRL[0] ^ subRL[2]); /* kw1 */
  917. SET_SUBKEY_LR(2, subRL[3]); /* round 1 */
  918. SET_SUBKEY_LR(3, subRL[2] ^ subRL[4]); /* round 2 */
  919. SET_SUBKEY_LR(4, subRL[3] ^ subRL[5]); /* round 3 */
  920. SET_SUBKEY_LR(5, subRL[4] ^ subRL[6]); /* round 4 */
  921. SET_SUBKEY_LR(6, subRL[5] ^ subRL[7]); /* round 5 */
  922. tl = (subRL[10] >> 32) ^ (subRL[10] & ~subRL[8]);
  923. dw = tl & (subRL[8] >> 32), /* FL(kl1) */
  924. tr = subRL[10] ^ rol32(dw, 1);
  925. tt = (tr | ((u64)tl << 32));
  926. SET_SUBKEY_LR(7, subRL[6] ^ tt); /* round 6 */
  927. SET_SUBKEY_LR(8, subRL[8]); /* FL(kl1) */
  928. SET_SUBKEY_LR(9, subRL[9]); /* FLinv(kl2) */
  929. tl = (subRL[7] >> 32) ^ (subRL[7] & ~subRL[9]);
  930. dw = tl & (subRL[9] >> 32), /* FLinv(kl2) */
  931. tr = subRL[7] ^ rol32(dw, 1);
  932. tt = (tr | ((u64)tl << 32));
  933. SET_SUBKEY_LR(10, subRL[11] ^ tt); /* round 7 */
  934. SET_SUBKEY_LR(11, subRL[10] ^ subRL[12]); /* round 8 */
  935. SET_SUBKEY_LR(12, subRL[11] ^ subRL[13]); /* round 9 */
  936. SET_SUBKEY_LR(13, subRL[12] ^ subRL[14]); /* round 10 */
  937. SET_SUBKEY_LR(14, subRL[13] ^ subRL[15]); /* round 11 */
  938. tl = (subRL[18] >> 32) ^ (subRL[18] & ~subRL[16]);
  939. dw = tl & (subRL[16] >> 32), /* FL(kl3) */
  940. tr = subRL[18] ^ rol32(dw, 1);
  941. tt = (tr | ((u64)tl << 32));
  942. SET_SUBKEY_LR(15, subRL[14] ^ tt); /* round 12 */
  943. SET_SUBKEY_LR(16, subRL[16]); /* FL(kl3) */
  944. SET_SUBKEY_LR(17, subRL[17]); /* FLinv(kl4) */
  945. tl = (subRL[15] >> 32) ^ (subRL[15] & ~subRL[17]);
  946. dw = tl & (subRL[17] >> 32), /* FLinv(kl4) */
  947. tr = subRL[15] ^ rol32(dw, 1);
  948. tt = (tr | ((u64)tl << 32));
  949. SET_SUBKEY_LR(18, subRL[19] ^ tt); /* round 13 */
  950. SET_SUBKEY_LR(19, subRL[18] ^ subRL[20]); /* round 14 */
  951. SET_SUBKEY_LR(20, subRL[19] ^ subRL[21]); /* round 15 */
  952. SET_SUBKEY_LR(21, subRL[20] ^ subRL[22]); /* round 16 */
  953. SET_SUBKEY_LR(22, subRL[21] ^ subRL[23]); /* round 17 */
  954. if (max == 24) {
  955. SET_SUBKEY_LR(23, subRL[22]); /* round 18 */
  956. SET_SUBKEY_LR(24, subRL[24] ^ subRL[23]); /* kw3 */
  957. } else {
  958. tl = (subRL[26] >> 32) ^ (subRL[26] & ~subRL[24]);
  959. dw = tl & (subRL[24] >> 32), /* FL(kl5) */
  960. tr = subRL[26] ^ rol32(dw, 1);
  961. tt = (tr | ((u64)tl << 32));
  962. SET_SUBKEY_LR(23, subRL[22] ^ tt); /* round 18 */
  963. SET_SUBKEY_LR(24, subRL[24]); /* FL(kl5) */
  964. SET_SUBKEY_LR(25, subRL[25]); /* FLinv(kl6) */
  965. tl = (subRL[23] >> 32) ^ (subRL[23] & ~subRL[25]);
  966. dw = tl & (subRL[25] >> 32), /* FLinv(kl6) */
  967. tr = subRL[23] ^ rol32(dw, 1);
  968. tt = (tr | ((u64)tl << 32));
  969. SET_SUBKEY_LR(26, subRL[27] ^ tt); /* round 19 */
  970. SET_SUBKEY_LR(27, subRL[26] ^ subRL[28]); /* round 20 */
  971. SET_SUBKEY_LR(28, subRL[27] ^ subRL[29]); /* round 21 */
  972. SET_SUBKEY_LR(29, subRL[28] ^ subRL[30]); /* round 22 */
  973. SET_SUBKEY_LR(30, subRL[29] ^ subRL[31]); /* round 23 */
  974. SET_SUBKEY_LR(31, subRL[30]); /* round 24 */
  975. SET_SUBKEY_LR(32, subRL[32] ^ subRL[31]); /* kw3 */
  976. }
  977. }
  978. static void camellia_setup128(const unsigned char *key, u64 *subkey)
  979. {
  980. u64 kl, kr, ww;
  981. u64 subRL[26];
  982. /**
  983. * k == kl || kr (|| is concatenation)
  984. */
  985. kl = get_unaligned_be64(key);
  986. kr = get_unaligned_be64(key + 8);
  987. /* generate KL dependent subkeys */
  988. /* kw1 */
  989. subRL[0] = kl;
  990. /* kw2 */
  991. subRL[1] = kr;
  992. /* rotation left shift 15bit */
  993. ROLDQ(kl, kr, 15);
  994. /* k3 */
  995. subRL[4] = kl;
  996. /* k4 */
  997. subRL[5] = kr;
  998. /* rotation left shift 15+30bit */
  999. ROLDQ(kl, kr, 30);
  1000. /* k7 */
  1001. subRL[10] = kl;
  1002. /* k8 */
  1003. subRL[11] = kr;
  1004. /* rotation left shift 15+30+15bit */
  1005. ROLDQ(kl, kr, 15);
  1006. /* k10 */
  1007. subRL[13] = kr;
  1008. /* rotation left shift 15+30+15+17 bit */
  1009. ROLDQ(kl, kr, 17);
  1010. /* kl3 */
  1011. subRL[16] = kl;
  1012. /* kl4 */
  1013. subRL[17] = kr;
  1014. /* rotation left shift 15+30+15+17+17 bit */
  1015. ROLDQ(kl, kr, 17);
  1016. /* k13 */
  1017. subRL[18] = kl;
  1018. /* k14 */
  1019. subRL[19] = kr;
  1020. /* rotation left shift 15+30+15+17+17+17 bit */
  1021. ROLDQ(kl, kr, 17);
  1022. /* k17 */
  1023. subRL[22] = kl;
  1024. /* k18 */
  1025. subRL[23] = kr;
  1026. /* generate KA */
  1027. kl = subRL[0];
  1028. kr = subRL[1];
  1029. CAMELLIA_F(kl, CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R, ww);
  1030. kr ^= ww;
  1031. CAMELLIA_F(kr, CAMELLIA_SIGMA2L, CAMELLIA_SIGMA2R, kl);
  1032. /* current status == (kll, klr, w0, w1) */
  1033. CAMELLIA_F(kl, CAMELLIA_SIGMA3L, CAMELLIA_SIGMA3R, kr);
  1034. kr ^= ww;
  1035. CAMELLIA_F(kr, CAMELLIA_SIGMA4L, CAMELLIA_SIGMA4R, ww);
  1036. kl ^= ww;
  1037. /* generate KA dependent subkeys */
  1038. /* k1, k2 */
  1039. subRL[2] = kl;
  1040. subRL[3] = kr;
  1041. ROLDQ(kl, kr, 15);
  1042. /* k5,k6 */
  1043. subRL[6] = kl;
  1044. subRL[7] = kr;
  1045. ROLDQ(kl, kr, 15);
  1046. /* kl1, kl2 */
  1047. subRL[8] = kl;
  1048. subRL[9] = kr;
  1049. ROLDQ(kl, kr, 15);
  1050. /* k9 */
  1051. subRL[12] = kl;
  1052. ROLDQ(kl, kr, 15);
  1053. /* k11, k12 */
  1054. subRL[14] = kl;
  1055. subRL[15] = kr;
  1056. ROLDQ(kl, kr, 34);
  1057. /* k15, k16 */
  1058. subRL[20] = kl;
  1059. subRL[21] = kr;
  1060. ROLDQ(kl, kr, 17);
  1061. /* kw3, kw4 */
  1062. subRL[24] = kl;
  1063. subRL[25] = kr;
  1064. camellia_setup_tail(subkey, subRL, 24);
  1065. }
  1066. static void camellia_setup256(const unsigned char *key, u64 *subkey)
  1067. {
  1068. u64 kl, kr; /* left half of key */
  1069. u64 krl, krr; /* right half of key */
  1070. u64 ww; /* temporary variables */
  1071. u64 subRL[34];
  1072. /**
  1073. * key = (kl || kr || krl || krr) (|| is concatenation)
  1074. */
  1075. kl = get_unaligned_be64(key);
  1076. kr = get_unaligned_be64(key + 8);
  1077. krl = get_unaligned_be64(key + 16);
  1078. krr = get_unaligned_be64(key + 24);
  1079. /* generate KL dependent subkeys */
  1080. /* kw1 */
  1081. subRL[0] = kl;
  1082. /* kw2 */
  1083. subRL[1] = kr;
  1084. ROLDQ(kl, kr, 45);
  1085. /* k9 */
  1086. subRL[12] = kl;
  1087. /* k10 */
  1088. subRL[13] = kr;
  1089. ROLDQ(kl, kr, 15);
  1090. /* kl3 */
  1091. subRL[16] = kl;
  1092. /* kl4 */
  1093. subRL[17] = kr;
  1094. ROLDQ(kl, kr, 17);
  1095. /* k17 */
  1096. subRL[22] = kl;
  1097. /* k18 */
  1098. subRL[23] = kr;
  1099. ROLDQ(kl, kr, 34);
  1100. /* k23 */
  1101. subRL[30] = kl;
  1102. /* k24 */
  1103. subRL[31] = kr;
  1104. /* generate KR dependent subkeys */
  1105. ROLDQ(krl, krr, 15);
  1106. /* k3 */
  1107. subRL[4] = krl;
  1108. /* k4 */
  1109. subRL[5] = krr;
  1110. ROLDQ(krl, krr, 15);
  1111. /* kl1 */
  1112. subRL[8] = krl;
  1113. /* kl2 */
  1114. subRL[9] = krr;
  1115. ROLDQ(krl, krr, 30);
  1116. /* k13 */
  1117. subRL[18] = krl;
  1118. /* k14 */
  1119. subRL[19] = krr;
  1120. ROLDQ(krl, krr, 34);
  1121. /* k19 */
  1122. subRL[26] = krl;
  1123. /* k20 */
  1124. subRL[27] = krr;
  1125. ROLDQ(krl, krr, 34);
  1126. /* generate KA */
  1127. kl = subRL[0] ^ krl;
  1128. kr = subRL[1] ^ krr;
  1129. CAMELLIA_F(kl, CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R, ww);
  1130. kr ^= ww;
  1131. CAMELLIA_F(kr, CAMELLIA_SIGMA2L, CAMELLIA_SIGMA2R, kl);
  1132. kl ^= krl;
  1133. CAMELLIA_F(kl, CAMELLIA_SIGMA3L, CAMELLIA_SIGMA3R, kr);
  1134. kr ^= ww ^ krr;
  1135. CAMELLIA_F(kr, CAMELLIA_SIGMA4L, CAMELLIA_SIGMA4R, ww);
  1136. kl ^= ww;
  1137. /* generate KB */
  1138. krl ^= kl;
  1139. krr ^= kr;
  1140. CAMELLIA_F(krl, CAMELLIA_SIGMA5L, CAMELLIA_SIGMA5R, ww);
  1141. krr ^= ww;
  1142. CAMELLIA_F(krr, CAMELLIA_SIGMA6L, CAMELLIA_SIGMA6R, ww);
  1143. krl ^= ww;
  1144. /* generate KA dependent subkeys */
  1145. ROLDQ(kl, kr, 15);
  1146. /* k5 */
  1147. subRL[6] = kl;
  1148. /* k6 */
  1149. subRL[7] = kr;
  1150. ROLDQ(kl, kr, 30);
  1151. /* k11 */
  1152. subRL[14] = kl;
  1153. /* k12 */
  1154. subRL[15] = kr;
  1155. /* rotation left shift 32bit */
  1156. ROLDQ(kl, kr, 32);
  1157. /* kl5 */
  1158. subRL[24] = kl;
  1159. /* kl6 */
  1160. subRL[25] = kr;
  1161. /* rotation left shift 17 from k11,k12 -> k21,k22 */
  1162. ROLDQ(kl, kr, 17);
  1163. /* k21 */
  1164. subRL[28] = kl;
  1165. /* k22 */
  1166. subRL[29] = kr;
  1167. /* generate KB dependent subkeys */
  1168. /* k1 */
  1169. subRL[2] = krl;
  1170. /* k2 */
  1171. subRL[3] = krr;
  1172. ROLDQ(krl, krr, 30);
  1173. /* k7 */
  1174. subRL[10] = krl;
  1175. /* k8 */
  1176. subRL[11] = krr;
  1177. ROLDQ(krl, krr, 30);
  1178. /* k15 */
  1179. subRL[20] = krl;
  1180. /* k16 */
  1181. subRL[21] = krr;
  1182. ROLDQ(krl, krr, 51);
  1183. /* kw3 */
  1184. subRL[32] = krl;
  1185. /* kw4 */
  1186. subRL[33] = krr;
  1187. camellia_setup_tail(subkey, subRL, 32);
  1188. }
  1189. static void camellia_setup192(const unsigned char *key, u64 *subkey)
  1190. {
  1191. unsigned char kk[32];
  1192. u64 krl, krr;
  1193. memcpy(kk, key, 24);
  1194. memcpy((unsigned char *)&krl, key+16, 8);
  1195. krr = ~krl;
  1196. memcpy(kk+24, (unsigned char *)&krr, 8);
  1197. camellia_setup256(kk, subkey);
  1198. }
  1199. static int __camellia_setkey(struct camellia_ctx *cctx,
  1200. const unsigned char *key,
  1201. unsigned int key_len, u32 *flags)
  1202. {
  1203. if (key_len != 16 && key_len != 24 && key_len != 32) {
  1204. *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
  1205. return -EINVAL;
  1206. }
  1207. cctx->key_length = key_len;
  1208. switch (key_len) {
  1209. case 16:
  1210. camellia_setup128(key, cctx->key_table);
  1211. break;
  1212. case 24:
  1213. camellia_setup192(key, cctx->key_table);
  1214. break;
  1215. case 32:
  1216. camellia_setup256(key, cctx->key_table);
  1217. break;
  1218. }
  1219. return 0;
  1220. }
  1221. static int camellia_setkey(struct crypto_tfm *tfm, const u8 *in_key,
  1222. unsigned int key_len)
  1223. {
  1224. return __camellia_setkey(crypto_tfm_ctx(tfm), in_key, key_len,
  1225. &tfm->crt_flags);
  1226. }
  1227. static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk,
  1228. void (*fn)(struct camellia_ctx *, u8 *, const u8 *),
  1229. void (*fn_2way)(struct camellia_ctx *, u8 *, const u8 *))
  1230. {
  1231. struct camellia_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1232. unsigned int bsize = CAMELLIA_BLOCK_SIZE;
  1233. unsigned int nbytes;
  1234. int err;
  1235. err = blkcipher_walk_virt(desc, walk);
  1236. while ((nbytes = walk->nbytes)) {
  1237. u8 *wsrc = walk->src.virt.addr;
  1238. u8 *wdst = walk->dst.virt.addr;
  1239. /* Process two block batch */
  1240. if (nbytes >= bsize * 2) {
  1241. do {
  1242. fn_2way(ctx, wdst, wsrc);
  1243. wsrc += bsize * 2;
  1244. wdst += bsize * 2;
  1245. nbytes -= bsize * 2;
  1246. } while (nbytes >= bsize * 2);
  1247. if (nbytes < bsize)
  1248. goto done;
  1249. }
  1250. /* Handle leftovers */
  1251. do {
  1252. fn(ctx, wdst, wsrc);
  1253. wsrc += bsize;
  1254. wdst += bsize;
  1255. nbytes -= bsize;
  1256. } while (nbytes >= bsize);
  1257. done:
  1258. err = blkcipher_walk_done(desc, walk, nbytes);
  1259. }
  1260. return err;
  1261. }
  1262. static int ecb_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1263. struct scatterlist *src, unsigned int nbytes)
  1264. {
  1265. struct blkcipher_walk walk;
  1266. blkcipher_walk_init(&walk, dst, src, nbytes);
  1267. return ecb_crypt(desc, &walk, camellia_enc_blk, camellia_enc_blk_2way);
  1268. }
  1269. static int ecb_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1270. struct scatterlist *src, unsigned int nbytes)
  1271. {
  1272. struct blkcipher_walk walk;
  1273. blkcipher_walk_init(&walk, dst, src, nbytes);
  1274. return ecb_crypt(desc, &walk, camellia_dec_blk, camellia_dec_blk_2way);
  1275. }
  1276. static unsigned int __cbc_encrypt(struct blkcipher_desc *desc,
  1277. struct blkcipher_walk *walk)
  1278. {
  1279. struct camellia_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1280. unsigned int bsize = CAMELLIA_BLOCK_SIZE;
  1281. unsigned int nbytes = walk->nbytes;
  1282. u128 *src = (u128 *)walk->src.virt.addr;
  1283. u128 *dst = (u128 *)walk->dst.virt.addr;
  1284. u128 *iv = (u128 *)walk->iv;
  1285. do {
  1286. u128_xor(dst, src, iv);
  1287. camellia_enc_blk(ctx, (u8 *)dst, (u8 *)dst);
  1288. iv = dst;
  1289. src += 1;
  1290. dst += 1;
  1291. nbytes -= bsize;
  1292. } while (nbytes >= bsize);
  1293. u128_xor((u128 *)walk->iv, (u128 *)walk->iv, iv);
  1294. return nbytes;
  1295. }
  1296. static int cbc_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1297. struct scatterlist *src, unsigned int nbytes)
  1298. {
  1299. struct blkcipher_walk walk;
  1300. int err;
  1301. blkcipher_walk_init(&walk, dst, src, nbytes);
  1302. err = blkcipher_walk_virt(desc, &walk);
  1303. while ((nbytes = walk.nbytes)) {
  1304. nbytes = __cbc_encrypt(desc, &walk);
  1305. err = blkcipher_walk_done(desc, &walk, nbytes);
  1306. }
  1307. return err;
  1308. }
  1309. static unsigned int __cbc_decrypt(struct blkcipher_desc *desc,
  1310. struct blkcipher_walk *walk)
  1311. {
  1312. struct camellia_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1313. unsigned int bsize = CAMELLIA_BLOCK_SIZE;
  1314. unsigned int nbytes = walk->nbytes;
  1315. u128 *src = (u128 *)walk->src.virt.addr;
  1316. u128 *dst = (u128 *)walk->dst.virt.addr;
  1317. u128 ivs[2 - 1];
  1318. u128 last_iv;
  1319. /* Start of the last block. */
  1320. src += nbytes / bsize - 1;
  1321. dst += nbytes / bsize - 1;
  1322. last_iv = *src;
  1323. /* Process two block batch */
  1324. if (nbytes >= bsize * 2) {
  1325. do {
  1326. nbytes -= bsize * (2 - 1);
  1327. src -= 2 - 1;
  1328. dst -= 2 - 1;
  1329. ivs[0] = src[0];
  1330. camellia_dec_blk_2way(ctx, (u8 *)dst, (u8 *)src);
  1331. u128_xor(dst + 1, dst + 1, ivs + 0);
  1332. nbytes -= bsize;
  1333. if (nbytes < bsize)
  1334. goto done;
  1335. u128_xor(dst, dst, src - 1);
  1336. src -= 1;
  1337. dst -= 1;
  1338. } while (nbytes >= bsize * 2);
  1339. if (nbytes < bsize)
  1340. goto done;
  1341. }
  1342. /* Handle leftovers */
  1343. for (;;) {
  1344. camellia_dec_blk(ctx, (u8 *)dst, (u8 *)src);
  1345. nbytes -= bsize;
  1346. if (nbytes < bsize)
  1347. break;
  1348. u128_xor(dst, dst, src - 1);
  1349. src -= 1;
  1350. dst -= 1;
  1351. }
  1352. done:
  1353. u128_xor(dst, dst, (u128 *)walk->iv);
  1354. *(u128 *)walk->iv = last_iv;
  1355. return nbytes;
  1356. }
  1357. static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1358. struct scatterlist *src, unsigned int nbytes)
  1359. {
  1360. struct blkcipher_walk walk;
  1361. int err;
  1362. blkcipher_walk_init(&walk, dst, src, nbytes);
  1363. err = blkcipher_walk_virt(desc, &walk);
  1364. while ((nbytes = walk.nbytes)) {
  1365. nbytes = __cbc_decrypt(desc, &walk);
  1366. err = blkcipher_walk_done(desc, &walk, nbytes);
  1367. }
  1368. return err;
  1369. }
  1370. static inline void u128_to_be128(be128 *dst, const u128 *src)
  1371. {
  1372. dst->a = cpu_to_be64(src->a);
  1373. dst->b = cpu_to_be64(src->b);
  1374. }
  1375. static inline void be128_to_u128(u128 *dst, const be128 *src)
  1376. {
  1377. dst->a = be64_to_cpu(src->a);
  1378. dst->b = be64_to_cpu(src->b);
  1379. }
  1380. static inline void u128_inc(u128 *i)
  1381. {
  1382. i->b++;
  1383. if (!i->b)
  1384. i->a++;
  1385. }
  1386. static void ctr_crypt_final(struct blkcipher_desc *desc,
  1387. struct blkcipher_walk *walk)
  1388. {
  1389. struct camellia_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1390. u8 keystream[CAMELLIA_BLOCK_SIZE];
  1391. u8 *src = walk->src.virt.addr;
  1392. u8 *dst = walk->dst.virt.addr;
  1393. unsigned int nbytes = walk->nbytes;
  1394. u128 ctrblk;
  1395. memcpy(keystream, src, nbytes);
  1396. camellia_enc_blk_xor(ctx, keystream, walk->iv);
  1397. memcpy(dst, keystream, nbytes);
  1398. be128_to_u128(&ctrblk, (be128 *)walk->iv);
  1399. u128_inc(&ctrblk);
  1400. u128_to_be128((be128 *)walk->iv, &ctrblk);
  1401. }
  1402. static unsigned int __ctr_crypt(struct blkcipher_desc *desc,
  1403. struct blkcipher_walk *walk)
  1404. {
  1405. struct camellia_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1406. unsigned int bsize = CAMELLIA_BLOCK_SIZE;
  1407. unsigned int nbytes = walk->nbytes;
  1408. u128 *src = (u128 *)walk->src.virt.addr;
  1409. u128 *dst = (u128 *)walk->dst.virt.addr;
  1410. u128 ctrblk;
  1411. be128 ctrblocks[2];
  1412. be128_to_u128(&ctrblk, (be128 *)walk->iv);
  1413. /* Process two block batch */
  1414. if (nbytes >= bsize * 2) {
  1415. do {
  1416. if (dst != src) {
  1417. dst[0] = src[0];
  1418. dst[1] = src[1];
  1419. }
  1420. /* create ctrblks for parallel encrypt */
  1421. u128_to_be128(&ctrblocks[0], &ctrblk);
  1422. u128_inc(&ctrblk);
  1423. u128_to_be128(&ctrblocks[1], &ctrblk);
  1424. u128_inc(&ctrblk);
  1425. camellia_enc_blk_xor_2way(ctx, (u8 *)dst,
  1426. (u8 *)ctrblocks);
  1427. src += 2;
  1428. dst += 2;
  1429. nbytes -= bsize * 2;
  1430. } while (nbytes >= bsize * 2);
  1431. if (nbytes < bsize)
  1432. goto done;
  1433. }
  1434. /* Handle leftovers */
  1435. do {
  1436. if (dst != src)
  1437. *dst = *src;
  1438. u128_to_be128(&ctrblocks[0], &ctrblk);
  1439. u128_inc(&ctrblk);
  1440. camellia_enc_blk_xor(ctx, (u8 *)dst, (u8 *)ctrblocks);
  1441. src += 1;
  1442. dst += 1;
  1443. nbytes -= bsize;
  1444. } while (nbytes >= bsize);
  1445. done:
  1446. u128_to_be128((be128 *)walk->iv, &ctrblk);
  1447. return nbytes;
  1448. }
  1449. static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1450. struct scatterlist *src, unsigned int nbytes)
  1451. {
  1452. struct blkcipher_walk walk;
  1453. int err;
  1454. blkcipher_walk_init(&walk, dst, src, nbytes);
  1455. err = blkcipher_walk_virt_block(desc, &walk, CAMELLIA_BLOCK_SIZE);
  1456. while ((nbytes = walk.nbytes) >= CAMELLIA_BLOCK_SIZE) {
  1457. nbytes = __ctr_crypt(desc, &walk);
  1458. err = blkcipher_walk_done(desc, &walk, nbytes);
  1459. }
  1460. if (walk.nbytes) {
  1461. ctr_crypt_final(desc, &walk);
  1462. err = blkcipher_walk_done(desc, &walk, 0);
  1463. }
  1464. return err;
  1465. }
  1466. static void encrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes)
  1467. {
  1468. const unsigned int bsize = CAMELLIA_BLOCK_SIZE;
  1469. struct camellia_ctx *ctx = priv;
  1470. int i;
  1471. while (nbytes >= 2 * bsize) {
  1472. camellia_enc_blk_2way(ctx, srcdst, srcdst);
  1473. srcdst += bsize * 2;
  1474. nbytes -= bsize * 2;
  1475. }
  1476. for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
  1477. camellia_enc_blk(ctx, srcdst, srcdst);
  1478. }
  1479. static void decrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes)
  1480. {
  1481. const unsigned int bsize = CAMELLIA_BLOCK_SIZE;
  1482. struct camellia_ctx *ctx = priv;
  1483. int i;
  1484. while (nbytes >= 2 * bsize) {
  1485. camellia_dec_blk_2way(ctx, srcdst, srcdst);
  1486. srcdst += bsize * 2;
  1487. nbytes -= bsize * 2;
  1488. }
  1489. for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
  1490. camellia_dec_blk(ctx, srcdst, srcdst);
  1491. }
  1492. struct camellia_lrw_ctx {
  1493. struct lrw_table_ctx lrw_table;
  1494. struct camellia_ctx camellia_ctx;
  1495. };
  1496. static int lrw_camellia_setkey(struct crypto_tfm *tfm, const u8 *key,
  1497. unsigned int keylen)
  1498. {
  1499. struct camellia_lrw_ctx *ctx = crypto_tfm_ctx(tfm);
  1500. int err;
  1501. err = __camellia_setkey(&ctx->camellia_ctx, key,
  1502. keylen - CAMELLIA_BLOCK_SIZE,
  1503. &tfm->crt_flags);
  1504. if (err)
  1505. return err;
  1506. return lrw_init_table(&ctx->lrw_table,
  1507. key + keylen - CAMELLIA_BLOCK_SIZE);
  1508. }
  1509. static int lrw_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1510. struct scatterlist *src, unsigned int nbytes)
  1511. {
  1512. struct camellia_lrw_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1513. be128 buf[2 * 4];
  1514. struct lrw_crypt_req req = {
  1515. .tbuf = buf,
  1516. .tbuflen = sizeof(buf),
  1517. .table_ctx = &ctx->lrw_table,
  1518. .crypt_ctx = &ctx->camellia_ctx,
  1519. .crypt_fn = encrypt_callback,
  1520. };
  1521. return lrw_crypt(desc, dst, src, nbytes, &req);
  1522. }
  1523. static int lrw_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1524. struct scatterlist *src, unsigned int nbytes)
  1525. {
  1526. struct camellia_lrw_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1527. be128 buf[2 * 4];
  1528. struct lrw_crypt_req req = {
  1529. .tbuf = buf,
  1530. .tbuflen = sizeof(buf),
  1531. .table_ctx = &ctx->lrw_table,
  1532. .crypt_ctx = &ctx->camellia_ctx,
  1533. .crypt_fn = decrypt_callback,
  1534. };
  1535. return lrw_crypt(desc, dst, src, nbytes, &req);
  1536. }
  1537. static void lrw_exit_tfm(struct crypto_tfm *tfm)
  1538. {
  1539. struct camellia_lrw_ctx *ctx = crypto_tfm_ctx(tfm);
  1540. lrw_free_table(&ctx->lrw_table);
  1541. }
  1542. struct camellia_xts_ctx {
  1543. struct camellia_ctx tweak_ctx;
  1544. struct camellia_ctx crypt_ctx;
  1545. };
  1546. static int xts_camellia_setkey(struct crypto_tfm *tfm, const u8 *key,
  1547. unsigned int keylen)
  1548. {
  1549. struct camellia_xts_ctx *ctx = crypto_tfm_ctx(tfm);
  1550. u32 *flags = &tfm->crt_flags;
  1551. int err;
  1552. /* key consists of keys of equal size concatenated, therefore
  1553. * the length must be even
  1554. */
  1555. if (keylen % 2) {
  1556. *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
  1557. return -EINVAL;
  1558. }
  1559. /* first half of xts-key is for crypt */
  1560. err = __camellia_setkey(&ctx->crypt_ctx, key, keylen / 2, flags);
  1561. if (err)
  1562. return err;
  1563. /* second half of xts-key is for tweak */
  1564. return __camellia_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2,
  1565. flags);
  1566. }
  1567. static int xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1568. struct scatterlist *src, unsigned int nbytes)
  1569. {
  1570. struct camellia_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1571. be128 buf[2 * 4];
  1572. struct xts_crypt_req req = {
  1573. .tbuf = buf,
  1574. .tbuflen = sizeof(buf),
  1575. .tweak_ctx = &ctx->tweak_ctx,
  1576. .tweak_fn = XTS_TWEAK_CAST(camellia_enc_blk),
  1577. .crypt_ctx = &ctx->crypt_ctx,
  1578. .crypt_fn = encrypt_callback,
  1579. };
  1580. return xts_crypt(desc, dst, src, nbytes, &req);
  1581. }
  1582. static int xts_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1583. struct scatterlist *src, unsigned int nbytes)
  1584. {
  1585. struct camellia_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1586. be128 buf[2 * 4];
  1587. struct xts_crypt_req req = {
  1588. .tbuf = buf,
  1589. .tbuflen = sizeof(buf),
  1590. .tweak_ctx = &ctx->tweak_ctx,
  1591. .tweak_fn = XTS_TWEAK_CAST(camellia_enc_blk),
  1592. .crypt_ctx = &ctx->crypt_ctx,
  1593. .crypt_fn = decrypt_callback,
  1594. };
  1595. return xts_crypt(desc, dst, src, nbytes, &req);
  1596. }
  1597. static struct crypto_alg camellia_algs[6] = { {
  1598. .cra_name = "camellia",
  1599. .cra_driver_name = "camellia-asm",
  1600. .cra_priority = 200,
  1601. .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
  1602. .cra_blocksize = CAMELLIA_BLOCK_SIZE,
  1603. .cra_ctxsize = sizeof(struct camellia_ctx),
  1604. .cra_alignmask = 0,
  1605. .cra_module = THIS_MODULE,
  1606. .cra_list = LIST_HEAD_INIT(camellia_algs[0].cra_list),
  1607. .cra_u = {
  1608. .cipher = {
  1609. .cia_min_keysize = CAMELLIA_MIN_KEY_SIZE,
  1610. .cia_max_keysize = CAMELLIA_MAX_KEY_SIZE,
  1611. .cia_setkey = camellia_setkey,
  1612. .cia_encrypt = camellia_encrypt,
  1613. .cia_decrypt = camellia_decrypt
  1614. }
  1615. }
  1616. }, {
  1617. .cra_name = "ecb(camellia)",
  1618. .cra_driver_name = "ecb-camellia-asm",
  1619. .cra_priority = 300,
  1620. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  1621. .cra_blocksize = CAMELLIA_BLOCK_SIZE,
  1622. .cra_ctxsize = sizeof(struct camellia_ctx),
  1623. .cra_alignmask = 0,
  1624. .cra_type = &crypto_blkcipher_type,
  1625. .cra_module = THIS_MODULE,
  1626. .cra_list = LIST_HEAD_INIT(camellia_algs[1].cra_list),
  1627. .cra_u = {
  1628. .blkcipher = {
  1629. .min_keysize = CAMELLIA_MIN_KEY_SIZE,
  1630. .max_keysize = CAMELLIA_MAX_KEY_SIZE,
  1631. .setkey = camellia_setkey,
  1632. .encrypt = ecb_encrypt,
  1633. .decrypt = ecb_decrypt,
  1634. },
  1635. },
  1636. }, {
  1637. .cra_name = "cbc(camellia)",
  1638. .cra_driver_name = "cbc-camellia-asm",
  1639. .cra_priority = 300,
  1640. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  1641. .cra_blocksize = CAMELLIA_BLOCK_SIZE,
  1642. .cra_ctxsize = sizeof(struct camellia_ctx),
  1643. .cra_alignmask = 0,
  1644. .cra_type = &crypto_blkcipher_type,
  1645. .cra_module = THIS_MODULE,
  1646. .cra_list = LIST_HEAD_INIT(camellia_algs[2].cra_list),
  1647. .cra_u = {
  1648. .blkcipher = {
  1649. .min_keysize = CAMELLIA_MIN_KEY_SIZE,
  1650. .max_keysize = CAMELLIA_MAX_KEY_SIZE,
  1651. .ivsize = CAMELLIA_BLOCK_SIZE,
  1652. .setkey = camellia_setkey,
  1653. .encrypt = cbc_encrypt,
  1654. .decrypt = cbc_decrypt,
  1655. },
  1656. },
  1657. }, {
  1658. .cra_name = "ctr(camellia)",
  1659. .cra_driver_name = "ctr-camellia-asm",
  1660. .cra_priority = 300,
  1661. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  1662. .cra_blocksize = 1,
  1663. .cra_ctxsize = sizeof(struct camellia_ctx),
  1664. .cra_alignmask = 0,
  1665. .cra_type = &crypto_blkcipher_type,
  1666. .cra_module = THIS_MODULE,
  1667. .cra_list = LIST_HEAD_INIT(camellia_algs[3].cra_list),
  1668. .cra_u = {
  1669. .blkcipher = {
  1670. .min_keysize = CAMELLIA_MIN_KEY_SIZE,
  1671. .max_keysize = CAMELLIA_MAX_KEY_SIZE,
  1672. .ivsize = CAMELLIA_BLOCK_SIZE,
  1673. .setkey = camellia_setkey,
  1674. .encrypt = ctr_crypt,
  1675. .decrypt = ctr_crypt,
  1676. },
  1677. },
  1678. }, {
  1679. .cra_name = "lrw(camellia)",
  1680. .cra_driver_name = "lrw-camellia-asm",
  1681. .cra_priority = 300,
  1682. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  1683. .cra_blocksize = CAMELLIA_BLOCK_SIZE,
  1684. .cra_ctxsize = sizeof(struct camellia_lrw_ctx),
  1685. .cra_alignmask = 0,
  1686. .cra_type = &crypto_blkcipher_type,
  1687. .cra_module = THIS_MODULE,
  1688. .cra_list = LIST_HEAD_INIT(camellia_algs[4].cra_list),
  1689. .cra_exit = lrw_exit_tfm,
  1690. .cra_u = {
  1691. .blkcipher = {
  1692. .min_keysize = CAMELLIA_MIN_KEY_SIZE +
  1693. CAMELLIA_BLOCK_SIZE,
  1694. .max_keysize = CAMELLIA_MAX_KEY_SIZE +
  1695. CAMELLIA_BLOCK_SIZE,
  1696. .ivsize = CAMELLIA_BLOCK_SIZE,
  1697. .setkey = lrw_camellia_setkey,
  1698. .encrypt = lrw_encrypt,
  1699. .decrypt = lrw_decrypt,
  1700. },
  1701. },
  1702. }, {
  1703. .cra_name = "xts(camellia)",
  1704. .cra_driver_name = "xts-camellia-asm",
  1705. .cra_priority = 300,
  1706. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  1707. .cra_blocksize = CAMELLIA_BLOCK_SIZE,
  1708. .cra_ctxsize = sizeof(struct camellia_xts_ctx),
  1709. .cra_alignmask = 0,
  1710. .cra_type = &crypto_blkcipher_type,
  1711. .cra_module = THIS_MODULE,
  1712. .cra_list = LIST_HEAD_INIT(camellia_algs[5].cra_list),
  1713. .cra_u = {
  1714. .blkcipher = {
  1715. .min_keysize = CAMELLIA_MIN_KEY_SIZE * 2,
  1716. .max_keysize = CAMELLIA_MAX_KEY_SIZE * 2,
  1717. .ivsize = CAMELLIA_BLOCK_SIZE,
  1718. .setkey = xts_camellia_setkey,
  1719. .encrypt = xts_encrypt,
  1720. .decrypt = xts_decrypt,
  1721. },
  1722. },
  1723. } };
  1724. static bool is_blacklisted_cpu(void)
  1725. {
  1726. if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
  1727. return false;
  1728. if (boot_cpu_data.x86 == 0x0f) {
  1729. /*
  1730. * On Pentium 4, camellia-asm is slower than original assembler
  1731. * implementation because excessive uses of 64bit rotate and
  1732. * left-shifts (which are really slow on P4) needed to store and
  1733. * handle 128bit block in two 64bit registers.
  1734. */
  1735. return true;
  1736. }
  1737. return false;
  1738. }
  1739. static int force;
  1740. module_param(force, int, 0);
  1741. MODULE_PARM_DESC(force, "Force module load, ignore CPU blacklist");
  1742. static int __init init(void)
  1743. {
  1744. if (!force && is_blacklisted_cpu()) {
  1745. printk(KERN_INFO
  1746. "camellia-x86_64: performance on this CPU "
  1747. "would be suboptimal: disabling "
  1748. "camellia-x86_64.\n");
  1749. return -ENODEV;
  1750. }
  1751. return crypto_register_algs(camellia_algs, ARRAY_SIZE(camellia_algs));
  1752. }
  1753. static void __exit fini(void)
  1754. {
  1755. crypto_unregister_algs(camellia_algs, ARRAY_SIZE(camellia_algs));
  1756. }
  1757. module_init(init);
  1758. module_exit(fini);
  1759. MODULE_LICENSE("GPL");
  1760. MODULE_DESCRIPTION("Camellia Cipher Algorithm, asm optimized");
  1761. MODULE_ALIAS("camellia");
  1762. MODULE_ALIAS("camellia-asm");