aesni-intel_glue.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548
  1. /*
  2. * Support for Intel AES-NI instructions. This file contains glue
  3. * code, the real AES implementation is in intel-aes_asm.S.
  4. *
  5. * Copyright (C) 2008, Intel Corp.
  6. * Author: Huang Ying <ying.huang@intel.com>
  7. *
  8. * Added RFC4106 AES-GCM support for 128-bit keys under the AEAD
  9. * interface for 64-bit kernels.
  10. * Authors: Adrian Hoban <adrian.hoban@intel.com>
  11. * Gabriele Paoloni <gabriele.paoloni@intel.com>
  12. * Tadeusz Struk (tadeusz.struk@intel.com)
  13. * Aidan O'Mahony (aidan.o.mahony@intel.com)
  14. * Copyright (c) 2010, Intel Corporation.
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. */
  21. #include <linux/hardirq.h>
  22. #include <linux/types.h>
  23. #include <linux/module.h>
  24. #include <linux/err.h>
  25. #include <crypto/algapi.h>
  26. #include <crypto/aes.h>
  27. #include <crypto/cryptd.h>
  28. #include <crypto/ctr.h>
  29. #include <crypto/b128ops.h>
  30. #include <crypto/gcm.h>
  31. #include <crypto/xts.h>
  32. #include <asm/cpu_device_id.h>
  33. #include <asm/fpu/api.h>
  34. #include <asm/crypto/aes.h>
  35. #include <crypto/scatterwalk.h>
  36. #include <crypto/internal/aead.h>
  37. #include <crypto/internal/simd.h>
  38. #include <crypto/internal/skcipher.h>
  39. #include <linux/workqueue.h>
  40. #include <linux/spinlock.h>
  41. #ifdef CONFIG_X86_64
  42. #include <asm/crypto/glue_helper.h>
  43. #endif
  44. #define AESNI_ALIGN 16
  45. #define AESNI_ALIGN_ATTR __attribute__ ((__aligned__(AESNI_ALIGN)))
  46. #define AES_BLOCK_MASK (~(AES_BLOCK_SIZE - 1))
  47. #define RFC4106_HASH_SUBKEY_SIZE 16
  48. #define AESNI_ALIGN_EXTRA ((AESNI_ALIGN - 1) & ~(CRYPTO_MINALIGN - 1))
  49. #define CRYPTO_AES_CTX_SIZE (sizeof(struct crypto_aes_ctx) + AESNI_ALIGN_EXTRA)
  50. #define XTS_AES_CTX_SIZE (sizeof(struct aesni_xts_ctx) + AESNI_ALIGN_EXTRA)
  51. /* This data is stored at the end of the crypto_tfm struct.
  52. * It's a type of per "session" data storage location.
  53. * This needs to be 16 byte aligned.
  54. */
  55. struct aesni_rfc4106_gcm_ctx {
  56. u8 hash_subkey[16] AESNI_ALIGN_ATTR;
  57. struct crypto_aes_ctx aes_key_expanded AESNI_ALIGN_ATTR;
  58. u8 nonce[4];
  59. };
  60. struct generic_gcmaes_ctx {
  61. u8 hash_subkey[16] AESNI_ALIGN_ATTR;
  62. struct crypto_aes_ctx aes_key_expanded AESNI_ALIGN_ATTR;
  63. };
  64. struct aesni_xts_ctx {
  65. u8 raw_tweak_ctx[sizeof(struct crypto_aes_ctx)] AESNI_ALIGN_ATTR;
  66. u8 raw_crypt_ctx[sizeof(struct crypto_aes_ctx)] AESNI_ALIGN_ATTR;
  67. };
  68. #define GCM_BLOCK_LEN 16
  69. struct gcm_context_data {
  70. /* init, update and finalize context data */
  71. u8 aad_hash[GCM_BLOCK_LEN];
  72. u64 aad_length;
  73. u64 in_length;
  74. u8 partial_block_enc_key[GCM_BLOCK_LEN];
  75. u8 orig_IV[GCM_BLOCK_LEN];
  76. u8 current_counter[GCM_BLOCK_LEN];
  77. u64 partial_block_len;
  78. u64 unused;
  79. u8 hash_keys[GCM_BLOCK_LEN * 8];
  80. };
  81. asmlinkage int aesni_set_key(struct crypto_aes_ctx *ctx, const u8 *in_key,
  82. unsigned int key_len);
  83. asmlinkage void aesni_enc(struct crypto_aes_ctx *ctx, u8 *out,
  84. const u8 *in);
  85. asmlinkage void aesni_dec(struct crypto_aes_ctx *ctx, u8 *out,
  86. const u8 *in);
  87. asmlinkage void aesni_ecb_enc(struct crypto_aes_ctx *ctx, u8 *out,
  88. const u8 *in, unsigned int len);
  89. asmlinkage void aesni_ecb_dec(struct crypto_aes_ctx *ctx, u8 *out,
  90. const u8 *in, unsigned int len);
  91. asmlinkage void aesni_cbc_enc(struct crypto_aes_ctx *ctx, u8 *out,
  92. const u8 *in, unsigned int len, u8 *iv);
  93. asmlinkage void aesni_cbc_dec(struct crypto_aes_ctx *ctx, u8 *out,
  94. const u8 *in, unsigned int len, u8 *iv);
  95. int crypto_fpu_init(void);
  96. void crypto_fpu_exit(void);
  97. #define AVX_GEN2_OPTSIZE 640
  98. #define AVX_GEN4_OPTSIZE 4096
  99. #ifdef CONFIG_X86_64
  100. static void (*aesni_ctr_enc_tfm)(struct crypto_aes_ctx *ctx, u8 *out,
  101. const u8 *in, unsigned int len, u8 *iv);
  102. asmlinkage void aesni_ctr_enc(struct crypto_aes_ctx *ctx, u8 *out,
  103. const u8 *in, unsigned int len, u8 *iv);
  104. asmlinkage void aesni_xts_crypt8(struct crypto_aes_ctx *ctx, u8 *out,
  105. const u8 *in, bool enc, u8 *iv);
  106. /* asmlinkage void aesni_gcm_enc()
  107. * void *ctx, AES Key schedule. Starts on a 16 byte boundary.
  108. * struct gcm_context_data. May be uninitialized.
  109. * u8 *out, Ciphertext output. Encrypt in-place is allowed.
  110. * const u8 *in, Plaintext input
  111. * unsigned long plaintext_len, Length of data in bytes for encryption.
  112. * u8 *iv, Pre-counter block j0: 12 byte IV concatenated with 0x00000001.
  113. * 16-byte aligned pointer.
  114. * u8 *hash_subkey, the Hash sub key input. Data starts on a 16-byte boundary.
  115. * const u8 *aad, Additional Authentication Data (AAD)
  116. * unsigned long aad_len, Length of AAD in bytes.
  117. * u8 *auth_tag, Authenticated Tag output.
  118. * unsigned long auth_tag_len), Authenticated Tag Length in bytes.
  119. * Valid values are 16 (most likely), 12 or 8.
  120. */
  121. asmlinkage void aesni_gcm_enc(void *ctx,
  122. struct gcm_context_data *gdata, u8 *out,
  123. const u8 *in, unsigned long plaintext_len, u8 *iv,
  124. u8 *hash_subkey, const u8 *aad, unsigned long aad_len,
  125. u8 *auth_tag, unsigned long auth_tag_len);
  126. /* asmlinkage void aesni_gcm_dec()
  127. * void *ctx, AES Key schedule. Starts on a 16 byte boundary.
  128. * struct gcm_context_data. May be uninitialized.
  129. * u8 *out, Plaintext output. Decrypt in-place is allowed.
  130. * const u8 *in, Ciphertext input
  131. * unsigned long ciphertext_len, Length of data in bytes for decryption.
  132. * u8 *iv, Pre-counter block j0: 12 byte IV concatenated with 0x00000001.
  133. * 16-byte aligned pointer.
  134. * u8 *hash_subkey, the Hash sub key input. Data starts on a 16-byte boundary.
  135. * const u8 *aad, Additional Authentication Data (AAD)
  136. * unsigned long aad_len, Length of AAD in bytes. With RFC4106 this is going
  137. * to be 8 or 12 bytes
  138. * u8 *auth_tag, Authenticated Tag output.
  139. * unsigned long auth_tag_len) Authenticated Tag Length in bytes.
  140. * Valid values are 16 (most likely), 12 or 8.
  141. */
  142. asmlinkage void aesni_gcm_dec(void *ctx,
  143. struct gcm_context_data *gdata, u8 *out,
  144. const u8 *in, unsigned long ciphertext_len, u8 *iv,
  145. u8 *hash_subkey, const u8 *aad, unsigned long aad_len,
  146. u8 *auth_tag, unsigned long auth_tag_len);
  147. /* Scatter / Gather routines, with args similar to above */
  148. asmlinkage void aesni_gcm_init(void *ctx,
  149. struct gcm_context_data *gdata,
  150. u8 *iv,
  151. u8 *hash_subkey, const u8 *aad,
  152. unsigned long aad_len);
  153. asmlinkage void aesni_gcm_enc_update(void *ctx,
  154. struct gcm_context_data *gdata, u8 *out,
  155. const u8 *in, unsigned long plaintext_len);
  156. asmlinkage void aesni_gcm_dec_update(void *ctx,
  157. struct gcm_context_data *gdata, u8 *out,
  158. const u8 *in,
  159. unsigned long ciphertext_len);
  160. asmlinkage void aesni_gcm_finalize(void *ctx,
  161. struct gcm_context_data *gdata,
  162. u8 *auth_tag, unsigned long auth_tag_len);
  163. #ifdef CONFIG_AS_AVX
  164. asmlinkage void aes_ctr_enc_128_avx_by8(const u8 *in, u8 *iv,
  165. void *keys, u8 *out, unsigned int num_bytes);
  166. asmlinkage void aes_ctr_enc_192_avx_by8(const u8 *in, u8 *iv,
  167. void *keys, u8 *out, unsigned int num_bytes);
  168. asmlinkage void aes_ctr_enc_256_avx_by8(const u8 *in, u8 *iv,
  169. void *keys, u8 *out, unsigned int num_bytes);
  170. /*
  171. * asmlinkage void aesni_gcm_precomp_avx_gen2()
  172. * gcm_data *my_ctx_data, context data
  173. * u8 *hash_subkey, the Hash sub key input. Data starts on a 16-byte boundary.
  174. */
  175. asmlinkage void aesni_gcm_precomp_avx_gen2(void *my_ctx_data, u8 *hash_subkey);
  176. asmlinkage void aesni_gcm_enc_avx_gen2(void *ctx, u8 *out,
  177. const u8 *in, unsigned long plaintext_len, u8 *iv,
  178. const u8 *aad, unsigned long aad_len,
  179. u8 *auth_tag, unsigned long auth_tag_len);
  180. asmlinkage void aesni_gcm_dec_avx_gen2(void *ctx, u8 *out,
  181. const u8 *in, unsigned long ciphertext_len, u8 *iv,
  182. const u8 *aad, unsigned long aad_len,
  183. u8 *auth_tag, unsigned long auth_tag_len);
  184. static void aesni_gcm_enc_avx(void *ctx,
  185. struct gcm_context_data *data, u8 *out,
  186. const u8 *in, unsigned long plaintext_len, u8 *iv,
  187. u8 *hash_subkey, const u8 *aad, unsigned long aad_len,
  188. u8 *auth_tag, unsigned long auth_tag_len)
  189. {
  190. struct crypto_aes_ctx *aes_ctx = (struct crypto_aes_ctx*)ctx;
  191. if ((plaintext_len < AVX_GEN2_OPTSIZE) || (aes_ctx-> key_length != AES_KEYSIZE_128)){
  192. aesni_gcm_enc(ctx, data, out, in,
  193. plaintext_len, iv, hash_subkey, aad,
  194. aad_len, auth_tag, auth_tag_len);
  195. } else {
  196. aesni_gcm_precomp_avx_gen2(ctx, hash_subkey);
  197. aesni_gcm_enc_avx_gen2(ctx, out, in, plaintext_len, iv, aad,
  198. aad_len, auth_tag, auth_tag_len);
  199. }
  200. }
  201. static void aesni_gcm_dec_avx(void *ctx,
  202. struct gcm_context_data *data, u8 *out,
  203. const u8 *in, unsigned long ciphertext_len, u8 *iv,
  204. u8 *hash_subkey, const u8 *aad, unsigned long aad_len,
  205. u8 *auth_tag, unsigned long auth_tag_len)
  206. {
  207. struct crypto_aes_ctx *aes_ctx = (struct crypto_aes_ctx*)ctx;
  208. if ((ciphertext_len < AVX_GEN2_OPTSIZE) || (aes_ctx-> key_length != AES_KEYSIZE_128)) {
  209. aesni_gcm_dec(ctx, data, out, in,
  210. ciphertext_len, iv, hash_subkey, aad,
  211. aad_len, auth_tag, auth_tag_len);
  212. } else {
  213. aesni_gcm_precomp_avx_gen2(ctx, hash_subkey);
  214. aesni_gcm_dec_avx_gen2(ctx, out, in, ciphertext_len, iv, aad,
  215. aad_len, auth_tag, auth_tag_len);
  216. }
  217. }
  218. #endif
  219. #ifdef CONFIG_AS_AVX2
  220. /*
  221. * asmlinkage void aesni_gcm_precomp_avx_gen4()
  222. * gcm_data *my_ctx_data, context data
  223. * u8 *hash_subkey, the Hash sub key input. Data starts on a 16-byte boundary.
  224. */
  225. asmlinkage void aesni_gcm_precomp_avx_gen4(void *my_ctx_data, u8 *hash_subkey);
  226. asmlinkage void aesni_gcm_enc_avx_gen4(void *ctx, u8 *out,
  227. const u8 *in, unsigned long plaintext_len, u8 *iv,
  228. const u8 *aad, unsigned long aad_len,
  229. u8 *auth_tag, unsigned long auth_tag_len);
  230. asmlinkage void aesni_gcm_dec_avx_gen4(void *ctx, u8 *out,
  231. const u8 *in, unsigned long ciphertext_len, u8 *iv,
  232. const u8 *aad, unsigned long aad_len,
  233. u8 *auth_tag, unsigned long auth_tag_len);
  234. static void aesni_gcm_enc_avx2(void *ctx,
  235. struct gcm_context_data *data, u8 *out,
  236. const u8 *in, unsigned long plaintext_len, u8 *iv,
  237. u8 *hash_subkey, const u8 *aad, unsigned long aad_len,
  238. u8 *auth_tag, unsigned long auth_tag_len)
  239. {
  240. struct crypto_aes_ctx *aes_ctx = (struct crypto_aes_ctx*)ctx;
  241. if ((plaintext_len < AVX_GEN2_OPTSIZE) || (aes_ctx-> key_length != AES_KEYSIZE_128)) {
  242. aesni_gcm_enc(ctx, data, out, in,
  243. plaintext_len, iv, hash_subkey, aad,
  244. aad_len, auth_tag, auth_tag_len);
  245. } else if (plaintext_len < AVX_GEN4_OPTSIZE) {
  246. aesni_gcm_precomp_avx_gen2(ctx, hash_subkey);
  247. aesni_gcm_enc_avx_gen2(ctx, out, in, plaintext_len, iv, aad,
  248. aad_len, auth_tag, auth_tag_len);
  249. } else {
  250. aesni_gcm_precomp_avx_gen4(ctx, hash_subkey);
  251. aesni_gcm_enc_avx_gen4(ctx, out, in, plaintext_len, iv, aad,
  252. aad_len, auth_tag, auth_tag_len);
  253. }
  254. }
  255. static void aesni_gcm_dec_avx2(void *ctx,
  256. struct gcm_context_data *data, u8 *out,
  257. const u8 *in, unsigned long ciphertext_len, u8 *iv,
  258. u8 *hash_subkey, const u8 *aad, unsigned long aad_len,
  259. u8 *auth_tag, unsigned long auth_tag_len)
  260. {
  261. struct crypto_aes_ctx *aes_ctx = (struct crypto_aes_ctx*)ctx;
  262. if ((ciphertext_len < AVX_GEN2_OPTSIZE) || (aes_ctx-> key_length != AES_KEYSIZE_128)) {
  263. aesni_gcm_dec(ctx, data, out, in,
  264. ciphertext_len, iv, hash_subkey,
  265. aad, aad_len, auth_tag, auth_tag_len);
  266. } else if (ciphertext_len < AVX_GEN4_OPTSIZE) {
  267. aesni_gcm_precomp_avx_gen2(ctx, hash_subkey);
  268. aesni_gcm_dec_avx_gen2(ctx, out, in, ciphertext_len, iv, aad,
  269. aad_len, auth_tag, auth_tag_len);
  270. } else {
  271. aesni_gcm_precomp_avx_gen4(ctx, hash_subkey);
  272. aesni_gcm_dec_avx_gen4(ctx, out, in, ciphertext_len, iv, aad,
  273. aad_len, auth_tag, auth_tag_len);
  274. }
  275. }
  276. #endif
  277. static void (*aesni_gcm_enc_tfm)(void *ctx,
  278. struct gcm_context_data *data, u8 *out,
  279. const u8 *in, unsigned long plaintext_len,
  280. u8 *iv, u8 *hash_subkey, const u8 *aad,
  281. unsigned long aad_len, u8 *auth_tag,
  282. unsigned long auth_tag_len);
  283. static void (*aesni_gcm_dec_tfm)(void *ctx,
  284. struct gcm_context_data *data, u8 *out,
  285. const u8 *in, unsigned long ciphertext_len,
  286. u8 *iv, u8 *hash_subkey, const u8 *aad,
  287. unsigned long aad_len, u8 *auth_tag,
  288. unsigned long auth_tag_len);
  289. static inline struct
  290. aesni_rfc4106_gcm_ctx *aesni_rfc4106_gcm_ctx_get(struct crypto_aead *tfm)
  291. {
  292. unsigned long align = AESNI_ALIGN;
  293. if (align <= crypto_tfm_ctx_alignment())
  294. align = 1;
  295. return PTR_ALIGN(crypto_aead_ctx(tfm), align);
  296. }
  297. static inline struct
  298. generic_gcmaes_ctx *generic_gcmaes_ctx_get(struct crypto_aead *tfm)
  299. {
  300. unsigned long align = AESNI_ALIGN;
  301. if (align <= crypto_tfm_ctx_alignment())
  302. align = 1;
  303. return PTR_ALIGN(crypto_aead_ctx(tfm), align);
  304. }
  305. #endif
  306. static inline struct crypto_aes_ctx *aes_ctx(void *raw_ctx)
  307. {
  308. unsigned long addr = (unsigned long)raw_ctx;
  309. unsigned long align = AESNI_ALIGN;
  310. if (align <= crypto_tfm_ctx_alignment())
  311. align = 1;
  312. return (struct crypto_aes_ctx *)ALIGN(addr, align);
  313. }
  314. static int aes_set_key_common(struct crypto_tfm *tfm, void *raw_ctx,
  315. const u8 *in_key, unsigned int key_len)
  316. {
  317. struct crypto_aes_ctx *ctx = aes_ctx(raw_ctx);
  318. u32 *flags = &tfm->crt_flags;
  319. int err;
  320. if (key_len != AES_KEYSIZE_128 && key_len != AES_KEYSIZE_192 &&
  321. key_len != AES_KEYSIZE_256) {
  322. *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
  323. return -EINVAL;
  324. }
  325. if (!irq_fpu_usable())
  326. err = crypto_aes_expand_key(ctx, in_key, key_len);
  327. else {
  328. kernel_fpu_begin();
  329. err = aesni_set_key(ctx, in_key, key_len);
  330. kernel_fpu_end();
  331. }
  332. return err;
  333. }
  334. static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
  335. unsigned int key_len)
  336. {
  337. return aes_set_key_common(tfm, crypto_tfm_ctx(tfm), in_key, key_len);
  338. }
  339. static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  340. {
  341. struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm));
  342. if (!irq_fpu_usable())
  343. crypto_aes_encrypt_x86(ctx, dst, src);
  344. else {
  345. kernel_fpu_begin();
  346. aesni_enc(ctx, dst, src);
  347. kernel_fpu_end();
  348. }
  349. }
  350. static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  351. {
  352. struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm));
  353. if (!irq_fpu_usable())
  354. crypto_aes_decrypt_x86(ctx, dst, src);
  355. else {
  356. kernel_fpu_begin();
  357. aesni_dec(ctx, dst, src);
  358. kernel_fpu_end();
  359. }
  360. }
  361. static void __aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  362. {
  363. struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm));
  364. aesni_enc(ctx, dst, src);
  365. }
  366. static void __aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  367. {
  368. struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm));
  369. aesni_dec(ctx, dst, src);
  370. }
  371. static int aesni_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
  372. unsigned int len)
  373. {
  374. return aes_set_key_common(crypto_skcipher_tfm(tfm),
  375. crypto_skcipher_ctx(tfm), key, len);
  376. }
  377. static int ecb_encrypt(struct skcipher_request *req)
  378. {
  379. struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  380. struct crypto_aes_ctx *ctx = aes_ctx(crypto_skcipher_ctx(tfm));
  381. struct skcipher_walk walk;
  382. unsigned int nbytes;
  383. int err;
  384. err = skcipher_walk_virt(&walk, req, true);
  385. kernel_fpu_begin();
  386. while ((nbytes = walk.nbytes)) {
  387. aesni_ecb_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  388. nbytes & AES_BLOCK_MASK);
  389. nbytes &= AES_BLOCK_SIZE - 1;
  390. err = skcipher_walk_done(&walk, nbytes);
  391. }
  392. kernel_fpu_end();
  393. return err;
  394. }
  395. static int ecb_decrypt(struct skcipher_request *req)
  396. {
  397. struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  398. struct crypto_aes_ctx *ctx = aes_ctx(crypto_skcipher_ctx(tfm));
  399. struct skcipher_walk walk;
  400. unsigned int nbytes;
  401. int err;
  402. err = skcipher_walk_virt(&walk, req, true);
  403. kernel_fpu_begin();
  404. while ((nbytes = walk.nbytes)) {
  405. aesni_ecb_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  406. nbytes & AES_BLOCK_MASK);
  407. nbytes &= AES_BLOCK_SIZE - 1;
  408. err = skcipher_walk_done(&walk, nbytes);
  409. }
  410. kernel_fpu_end();
  411. return err;
  412. }
  413. static int cbc_encrypt(struct skcipher_request *req)
  414. {
  415. struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  416. struct crypto_aes_ctx *ctx = aes_ctx(crypto_skcipher_ctx(tfm));
  417. struct skcipher_walk walk;
  418. unsigned int nbytes;
  419. int err;
  420. err = skcipher_walk_virt(&walk, req, true);
  421. kernel_fpu_begin();
  422. while ((nbytes = walk.nbytes)) {
  423. aesni_cbc_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  424. nbytes & AES_BLOCK_MASK, walk.iv);
  425. nbytes &= AES_BLOCK_SIZE - 1;
  426. err = skcipher_walk_done(&walk, nbytes);
  427. }
  428. kernel_fpu_end();
  429. return err;
  430. }
  431. static int cbc_decrypt(struct skcipher_request *req)
  432. {
  433. struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  434. struct crypto_aes_ctx *ctx = aes_ctx(crypto_skcipher_ctx(tfm));
  435. struct skcipher_walk walk;
  436. unsigned int nbytes;
  437. int err;
  438. err = skcipher_walk_virt(&walk, req, true);
  439. kernel_fpu_begin();
  440. while ((nbytes = walk.nbytes)) {
  441. aesni_cbc_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  442. nbytes & AES_BLOCK_MASK, walk.iv);
  443. nbytes &= AES_BLOCK_SIZE - 1;
  444. err = skcipher_walk_done(&walk, nbytes);
  445. }
  446. kernel_fpu_end();
  447. return err;
  448. }
  449. #ifdef CONFIG_X86_64
  450. static void ctr_crypt_final(struct crypto_aes_ctx *ctx,
  451. struct skcipher_walk *walk)
  452. {
  453. u8 *ctrblk = walk->iv;
  454. u8 keystream[AES_BLOCK_SIZE];
  455. u8 *src = walk->src.virt.addr;
  456. u8 *dst = walk->dst.virt.addr;
  457. unsigned int nbytes = walk->nbytes;
  458. aesni_enc(ctx, keystream, ctrblk);
  459. crypto_xor_cpy(dst, keystream, src, nbytes);
  460. crypto_inc(ctrblk, AES_BLOCK_SIZE);
  461. }
  462. #ifdef CONFIG_AS_AVX
  463. static void aesni_ctr_enc_avx_tfm(struct crypto_aes_ctx *ctx, u8 *out,
  464. const u8 *in, unsigned int len, u8 *iv)
  465. {
  466. /*
  467. * based on key length, override with the by8 version
  468. * of ctr mode encryption/decryption for improved performance
  469. * aes_set_key_common() ensures that key length is one of
  470. * {128,192,256}
  471. */
  472. if (ctx->key_length == AES_KEYSIZE_128)
  473. aes_ctr_enc_128_avx_by8(in, iv, (void *)ctx, out, len);
  474. else if (ctx->key_length == AES_KEYSIZE_192)
  475. aes_ctr_enc_192_avx_by8(in, iv, (void *)ctx, out, len);
  476. else
  477. aes_ctr_enc_256_avx_by8(in, iv, (void *)ctx, out, len);
  478. }
  479. #endif
  480. static int ctr_crypt(struct skcipher_request *req)
  481. {
  482. struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  483. struct crypto_aes_ctx *ctx = aes_ctx(crypto_skcipher_ctx(tfm));
  484. struct skcipher_walk walk;
  485. unsigned int nbytes;
  486. int err;
  487. err = skcipher_walk_virt(&walk, req, true);
  488. kernel_fpu_begin();
  489. while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
  490. aesni_ctr_enc_tfm(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  491. nbytes & AES_BLOCK_MASK, walk.iv);
  492. nbytes &= AES_BLOCK_SIZE - 1;
  493. err = skcipher_walk_done(&walk, nbytes);
  494. }
  495. if (walk.nbytes) {
  496. ctr_crypt_final(ctx, &walk);
  497. err = skcipher_walk_done(&walk, 0);
  498. }
  499. kernel_fpu_end();
  500. return err;
  501. }
  502. static int xts_aesni_setkey(struct crypto_skcipher *tfm, const u8 *key,
  503. unsigned int keylen)
  504. {
  505. struct aesni_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
  506. int err;
  507. err = xts_verify_key(tfm, key, keylen);
  508. if (err)
  509. return err;
  510. keylen /= 2;
  511. /* first half of xts-key is for crypt */
  512. err = aes_set_key_common(crypto_skcipher_tfm(tfm), ctx->raw_crypt_ctx,
  513. key, keylen);
  514. if (err)
  515. return err;
  516. /* second half of xts-key is for tweak */
  517. return aes_set_key_common(crypto_skcipher_tfm(tfm), ctx->raw_tweak_ctx,
  518. key + keylen, keylen);
  519. }
  520. static void aesni_xts_tweak(void *ctx, u8 *out, const u8 *in)
  521. {
  522. aesni_enc(ctx, out, in);
  523. }
  524. static void aesni_xts_enc(void *ctx, u128 *dst, const u128 *src, le128 *iv)
  525. {
  526. glue_xts_crypt_128bit_one(ctx, dst, src, iv, GLUE_FUNC_CAST(aesni_enc));
  527. }
  528. static void aesni_xts_dec(void *ctx, u128 *dst, const u128 *src, le128 *iv)
  529. {
  530. glue_xts_crypt_128bit_one(ctx, dst, src, iv, GLUE_FUNC_CAST(aesni_dec));
  531. }
  532. static void aesni_xts_enc8(void *ctx, u128 *dst, const u128 *src, le128 *iv)
  533. {
  534. aesni_xts_crypt8(ctx, (u8 *)dst, (const u8 *)src, true, (u8 *)iv);
  535. }
  536. static void aesni_xts_dec8(void *ctx, u128 *dst, const u128 *src, le128 *iv)
  537. {
  538. aesni_xts_crypt8(ctx, (u8 *)dst, (const u8 *)src, false, (u8 *)iv);
  539. }
  540. static const struct common_glue_ctx aesni_enc_xts = {
  541. .num_funcs = 2,
  542. .fpu_blocks_limit = 1,
  543. .funcs = { {
  544. .num_blocks = 8,
  545. .fn_u = { .xts = GLUE_XTS_FUNC_CAST(aesni_xts_enc8) }
  546. }, {
  547. .num_blocks = 1,
  548. .fn_u = { .xts = GLUE_XTS_FUNC_CAST(aesni_xts_enc) }
  549. } }
  550. };
  551. static const struct common_glue_ctx aesni_dec_xts = {
  552. .num_funcs = 2,
  553. .fpu_blocks_limit = 1,
  554. .funcs = { {
  555. .num_blocks = 8,
  556. .fn_u = { .xts = GLUE_XTS_FUNC_CAST(aesni_xts_dec8) }
  557. }, {
  558. .num_blocks = 1,
  559. .fn_u = { .xts = GLUE_XTS_FUNC_CAST(aesni_xts_dec) }
  560. } }
  561. };
  562. static int xts_encrypt(struct skcipher_request *req)
  563. {
  564. struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  565. struct aesni_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
  566. return glue_xts_req_128bit(&aesni_enc_xts, req,
  567. XTS_TWEAK_CAST(aesni_xts_tweak),
  568. aes_ctx(ctx->raw_tweak_ctx),
  569. aes_ctx(ctx->raw_crypt_ctx));
  570. }
  571. static int xts_decrypt(struct skcipher_request *req)
  572. {
  573. struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  574. struct aesni_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
  575. return glue_xts_req_128bit(&aesni_dec_xts, req,
  576. XTS_TWEAK_CAST(aesni_xts_tweak),
  577. aes_ctx(ctx->raw_tweak_ctx),
  578. aes_ctx(ctx->raw_crypt_ctx));
  579. }
  580. static int rfc4106_init(struct crypto_aead *aead)
  581. {
  582. struct cryptd_aead *cryptd_tfm;
  583. struct cryptd_aead **ctx = crypto_aead_ctx(aead);
  584. cryptd_tfm = cryptd_alloc_aead("__driver-gcm-aes-aesni",
  585. CRYPTO_ALG_INTERNAL,
  586. CRYPTO_ALG_INTERNAL);
  587. if (IS_ERR(cryptd_tfm))
  588. return PTR_ERR(cryptd_tfm);
  589. *ctx = cryptd_tfm;
  590. crypto_aead_set_reqsize(aead, crypto_aead_reqsize(&cryptd_tfm->base));
  591. return 0;
  592. }
  593. static void rfc4106_exit(struct crypto_aead *aead)
  594. {
  595. struct cryptd_aead **ctx = crypto_aead_ctx(aead);
  596. cryptd_free_aead(*ctx);
  597. }
  598. static int
  599. rfc4106_set_hash_subkey(u8 *hash_subkey, const u8 *key, unsigned int key_len)
  600. {
  601. struct crypto_cipher *tfm;
  602. int ret;
  603. tfm = crypto_alloc_cipher("aes", 0, 0);
  604. if (IS_ERR(tfm))
  605. return PTR_ERR(tfm);
  606. ret = crypto_cipher_setkey(tfm, key, key_len);
  607. if (ret)
  608. goto out_free_cipher;
  609. /* Clear the data in the hash sub key container to zero.*/
  610. /* We want to cipher all zeros to create the hash sub key. */
  611. memset(hash_subkey, 0, RFC4106_HASH_SUBKEY_SIZE);
  612. crypto_cipher_encrypt_one(tfm, hash_subkey, hash_subkey);
  613. out_free_cipher:
  614. crypto_free_cipher(tfm);
  615. return ret;
  616. }
  617. static int common_rfc4106_set_key(struct crypto_aead *aead, const u8 *key,
  618. unsigned int key_len)
  619. {
  620. struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(aead);
  621. if (key_len < 4) {
  622. crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
  623. return -EINVAL;
  624. }
  625. /*Account for 4 byte nonce at the end.*/
  626. key_len -= 4;
  627. memcpy(ctx->nonce, key + key_len, sizeof(ctx->nonce));
  628. return aes_set_key_common(crypto_aead_tfm(aead),
  629. &ctx->aes_key_expanded, key, key_len) ?:
  630. rfc4106_set_hash_subkey(ctx->hash_subkey, key, key_len);
  631. }
  632. static int gcmaes_wrapper_set_key(struct crypto_aead *parent, const u8 *key,
  633. unsigned int key_len)
  634. {
  635. struct cryptd_aead **ctx = crypto_aead_ctx(parent);
  636. struct cryptd_aead *cryptd_tfm = *ctx;
  637. return crypto_aead_setkey(&cryptd_tfm->base, key, key_len);
  638. }
  639. static int common_rfc4106_set_authsize(struct crypto_aead *aead,
  640. unsigned int authsize)
  641. {
  642. switch (authsize) {
  643. case 8:
  644. case 12:
  645. case 16:
  646. break;
  647. default:
  648. return -EINVAL;
  649. }
  650. return 0;
  651. }
  652. /* This is the Integrity Check Value (aka the authentication tag length and can
  653. * be 8, 12 or 16 bytes long. */
  654. static int gcmaes_wrapper_set_authsize(struct crypto_aead *parent,
  655. unsigned int authsize)
  656. {
  657. struct cryptd_aead **ctx = crypto_aead_ctx(parent);
  658. struct cryptd_aead *cryptd_tfm = *ctx;
  659. return crypto_aead_setauthsize(&cryptd_tfm->base, authsize);
  660. }
  661. static int generic_gcmaes_set_authsize(struct crypto_aead *tfm,
  662. unsigned int authsize)
  663. {
  664. switch (authsize) {
  665. case 4:
  666. case 8:
  667. case 12:
  668. case 13:
  669. case 14:
  670. case 15:
  671. case 16:
  672. break;
  673. default:
  674. return -EINVAL;
  675. }
  676. return 0;
  677. }
  678. static int gcmaes_crypt_by_sg(bool enc, struct aead_request *req,
  679. unsigned int assoclen, u8 *hash_subkey,
  680. u8 *iv, void *aes_ctx)
  681. {
  682. struct crypto_aead *tfm = crypto_aead_reqtfm(req);
  683. unsigned long auth_tag_len = crypto_aead_authsize(tfm);
  684. struct gcm_context_data data AESNI_ALIGN_ATTR;
  685. struct scatter_walk dst_sg_walk = {};
  686. unsigned long left = req->cryptlen;
  687. unsigned long len, srclen, dstlen;
  688. struct scatter_walk assoc_sg_walk;
  689. struct scatter_walk src_sg_walk;
  690. struct scatterlist src_start[2];
  691. struct scatterlist dst_start[2];
  692. struct scatterlist *src_sg;
  693. struct scatterlist *dst_sg;
  694. u8 *src, *dst, *assoc;
  695. u8 *assocmem = NULL;
  696. u8 authTag[16];
  697. if (!enc)
  698. left -= auth_tag_len;
  699. /* Linearize assoc, if not already linear */
  700. if (req->src->length >= assoclen && req->src->length &&
  701. (!PageHighMem(sg_page(req->src)) ||
  702. req->src->offset + req->src->length <= PAGE_SIZE)) {
  703. scatterwalk_start(&assoc_sg_walk, req->src);
  704. assoc = scatterwalk_map(&assoc_sg_walk);
  705. } else {
  706. /* assoc can be any length, so must be on heap */
  707. assocmem = kmalloc(assoclen, GFP_ATOMIC);
  708. if (unlikely(!assocmem))
  709. return -ENOMEM;
  710. assoc = assocmem;
  711. scatterwalk_map_and_copy(assoc, req->src, 0, assoclen, 0);
  712. }
  713. if (left) {
  714. src_sg = scatterwalk_ffwd(src_start, req->src, req->assoclen);
  715. scatterwalk_start(&src_sg_walk, src_sg);
  716. if (req->src != req->dst) {
  717. dst_sg = scatterwalk_ffwd(dst_start, req->dst,
  718. req->assoclen);
  719. scatterwalk_start(&dst_sg_walk, dst_sg);
  720. }
  721. }
  722. kernel_fpu_begin();
  723. aesni_gcm_init(aes_ctx, &data, iv,
  724. hash_subkey, assoc, assoclen);
  725. if (req->src != req->dst) {
  726. while (left) {
  727. src = scatterwalk_map(&src_sg_walk);
  728. dst = scatterwalk_map(&dst_sg_walk);
  729. srclen = scatterwalk_clamp(&src_sg_walk, left);
  730. dstlen = scatterwalk_clamp(&dst_sg_walk, left);
  731. len = min(srclen, dstlen);
  732. if (len) {
  733. if (enc)
  734. aesni_gcm_enc_update(aes_ctx, &data,
  735. dst, src, len);
  736. else
  737. aesni_gcm_dec_update(aes_ctx, &data,
  738. dst, src, len);
  739. }
  740. left -= len;
  741. scatterwalk_unmap(src);
  742. scatterwalk_unmap(dst);
  743. scatterwalk_advance(&src_sg_walk, len);
  744. scatterwalk_advance(&dst_sg_walk, len);
  745. scatterwalk_done(&src_sg_walk, 0, left);
  746. scatterwalk_done(&dst_sg_walk, 1, left);
  747. }
  748. } else {
  749. while (left) {
  750. dst = src = scatterwalk_map(&src_sg_walk);
  751. len = scatterwalk_clamp(&src_sg_walk, left);
  752. if (len) {
  753. if (enc)
  754. aesni_gcm_enc_update(aes_ctx, &data,
  755. src, src, len);
  756. else
  757. aesni_gcm_dec_update(aes_ctx, &data,
  758. src, src, len);
  759. }
  760. left -= len;
  761. scatterwalk_unmap(src);
  762. scatterwalk_advance(&src_sg_walk, len);
  763. scatterwalk_done(&src_sg_walk, 1, left);
  764. }
  765. }
  766. aesni_gcm_finalize(aes_ctx, &data, authTag, auth_tag_len);
  767. kernel_fpu_end();
  768. if (!assocmem)
  769. scatterwalk_unmap(assoc);
  770. else
  771. kfree(assocmem);
  772. if (!enc) {
  773. u8 authTagMsg[16];
  774. /* Copy out original authTag */
  775. scatterwalk_map_and_copy(authTagMsg, req->src,
  776. req->assoclen + req->cryptlen -
  777. auth_tag_len,
  778. auth_tag_len, 0);
  779. /* Compare generated tag with passed in tag. */
  780. return crypto_memneq(authTagMsg, authTag, auth_tag_len) ?
  781. -EBADMSG : 0;
  782. }
  783. /* Copy in the authTag */
  784. scatterwalk_map_and_copy(authTag, req->dst,
  785. req->assoclen + req->cryptlen,
  786. auth_tag_len, 1);
  787. return 0;
  788. }
  789. static int gcmaes_encrypt(struct aead_request *req, unsigned int assoclen,
  790. u8 *hash_subkey, u8 *iv, void *aes_ctx)
  791. {
  792. u8 one_entry_in_sg = 0;
  793. u8 *src, *dst, *assoc;
  794. struct crypto_aead *tfm = crypto_aead_reqtfm(req);
  795. unsigned long auth_tag_len = crypto_aead_authsize(tfm);
  796. struct scatter_walk src_sg_walk;
  797. struct scatter_walk dst_sg_walk = {};
  798. struct gcm_context_data data AESNI_ALIGN_ATTR;
  799. if (((struct crypto_aes_ctx *)aes_ctx)->key_length != AES_KEYSIZE_128 ||
  800. aesni_gcm_enc_tfm == aesni_gcm_enc ||
  801. req->cryptlen < AVX_GEN2_OPTSIZE) {
  802. return gcmaes_crypt_by_sg(true, req, assoclen, hash_subkey, iv,
  803. aes_ctx);
  804. }
  805. if (sg_is_last(req->src) &&
  806. (!PageHighMem(sg_page(req->src)) ||
  807. req->src->offset + req->src->length <= PAGE_SIZE) &&
  808. sg_is_last(req->dst) &&
  809. (!PageHighMem(sg_page(req->dst)) ||
  810. req->dst->offset + req->dst->length <= PAGE_SIZE)) {
  811. one_entry_in_sg = 1;
  812. scatterwalk_start(&src_sg_walk, req->src);
  813. assoc = scatterwalk_map(&src_sg_walk);
  814. src = assoc + req->assoclen;
  815. dst = src;
  816. if (unlikely(req->src != req->dst)) {
  817. scatterwalk_start(&dst_sg_walk, req->dst);
  818. dst = scatterwalk_map(&dst_sg_walk) + req->assoclen;
  819. }
  820. } else {
  821. /* Allocate memory for src, dst, assoc */
  822. assoc = kmalloc(req->cryptlen + auth_tag_len + req->assoclen,
  823. GFP_ATOMIC);
  824. if (unlikely(!assoc))
  825. return -ENOMEM;
  826. scatterwalk_map_and_copy(assoc, req->src, 0,
  827. req->assoclen + req->cryptlen, 0);
  828. src = assoc + req->assoclen;
  829. dst = src;
  830. }
  831. kernel_fpu_begin();
  832. aesni_gcm_enc_tfm(aes_ctx, &data, dst, src, req->cryptlen, iv,
  833. hash_subkey, assoc, assoclen,
  834. dst + req->cryptlen, auth_tag_len);
  835. kernel_fpu_end();
  836. /* The authTag (aka the Integrity Check Value) needs to be written
  837. * back to the packet. */
  838. if (one_entry_in_sg) {
  839. if (unlikely(req->src != req->dst)) {
  840. scatterwalk_unmap(dst - req->assoclen);
  841. scatterwalk_advance(&dst_sg_walk, req->dst->length);
  842. scatterwalk_done(&dst_sg_walk, 1, 0);
  843. }
  844. scatterwalk_unmap(assoc);
  845. scatterwalk_advance(&src_sg_walk, req->src->length);
  846. scatterwalk_done(&src_sg_walk, req->src == req->dst, 0);
  847. } else {
  848. scatterwalk_map_and_copy(dst, req->dst, req->assoclen,
  849. req->cryptlen + auth_tag_len, 1);
  850. kfree(assoc);
  851. }
  852. return 0;
  853. }
  854. static int gcmaes_decrypt(struct aead_request *req, unsigned int assoclen,
  855. u8 *hash_subkey, u8 *iv, void *aes_ctx)
  856. {
  857. u8 one_entry_in_sg = 0;
  858. u8 *src, *dst, *assoc;
  859. unsigned long tempCipherLen = 0;
  860. struct crypto_aead *tfm = crypto_aead_reqtfm(req);
  861. unsigned long auth_tag_len = crypto_aead_authsize(tfm);
  862. u8 authTag[16];
  863. struct scatter_walk src_sg_walk;
  864. struct scatter_walk dst_sg_walk = {};
  865. struct gcm_context_data data AESNI_ALIGN_ATTR;
  866. int retval = 0;
  867. if (((struct crypto_aes_ctx *)aes_ctx)->key_length != AES_KEYSIZE_128 ||
  868. aesni_gcm_enc_tfm == aesni_gcm_enc ||
  869. req->cryptlen < AVX_GEN2_OPTSIZE) {
  870. return gcmaes_crypt_by_sg(false, req, assoclen, hash_subkey, iv,
  871. aes_ctx);
  872. }
  873. tempCipherLen = (unsigned long)(req->cryptlen - auth_tag_len);
  874. if (sg_is_last(req->src) &&
  875. (!PageHighMem(sg_page(req->src)) ||
  876. req->src->offset + req->src->length <= PAGE_SIZE) &&
  877. sg_is_last(req->dst) && req->dst->length &&
  878. (!PageHighMem(sg_page(req->dst)) ||
  879. req->dst->offset + req->dst->length <= PAGE_SIZE)) {
  880. one_entry_in_sg = 1;
  881. scatterwalk_start(&src_sg_walk, req->src);
  882. assoc = scatterwalk_map(&src_sg_walk);
  883. src = assoc + req->assoclen;
  884. dst = src;
  885. if (unlikely(req->src != req->dst)) {
  886. scatterwalk_start(&dst_sg_walk, req->dst);
  887. dst = scatterwalk_map(&dst_sg_walk) + req->assoclen;
  888. }
  889. } else {
  890. /* Allocate memory for src, dst, assoc */
  891. assoc = kmalloc(req->cryptlen + req->assoclen, GFP_ATOMIC);
  892. if (!assoc)
  893. return -ENOMEM;
  894. scatterwalk_map_and_copy(assoc, req->src, 0,
  895. req->assoclen + req->cryptlen, 0);
  896. src = assoc + req->assoclen;
  897. dst = src;
  898. }
  899. kernel_fpu_begin();
  900. aesni_gcm_dec_tfm(aes_ctx, &data, dst, src, tempCipherLen, iv,
  901. hash_subkey, assoc, assoclen,
  902. authTag, auth_tag_len);
  903. kernel_fpu_end();
  904. /* Compare generated tag with passed in tag. */
  905. retval = crypto_memneq(src + tempCipherLen, authTag, auth_tag_len) ?
  906. -EBADMSG : 0;
  907. if (one_entry_in_sg) {
  908. if (unlikely(req->src != req->dst)) {
  909. scatterwalk_unmap(dst - req->assoclen);
  910. scatterwalk_advance(&dst_sg_walk, req->dst->length);
  911. scatterwalk_done(&dst_sg_walk, 1, 0);
  912. }
  913. scatterwalk_unmap(assoc);
  914. scatterwalk_advance(&src_sg_walk, req->src->length);
  915. scatterwalk_done(&src_sg_walk, req->src == req->dst, 0);
  916. } else {
  917. scatterwalk_map_and_copy(dst, req->dst, req->assoclen,
  918. tempCipherLen, 1);
  919. kfree(assoc);
  920. }
  921. return retval;
  922. }
  923. static int helper_rfc4106_encrypt(struct aead_request *req)
  924. {
  925. struct crypto_aead *tfm = crypto_aead_reqtfm(req);
  926. struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(tfm);
  927. void *aes_ctx = &(ctx->aes_key_expanded);
  928. u8 iv[16] __attribute__ ((__aligned__(AESNI_ALIGN)));
  929. unsigned int i;
  930. __be32 counter = cpu_to_be32(1);
  931. /* Assuming we are supporting rfc4106 64-bit extended */
  932. /* sequence numbers We need to have the AAD length equal */
  933. /* to 16 or 20 bytes */
  934. if (unlikely(req->assoclen != 16 && req->assoclen != 20))
  935. return -EINVAL;
  936. /* IV below built */
  937. for (i = 0; i < 4; i++)
  938. *(iv+i) = ctx->nonce[i];
  939. for (i = 0; i < 8; i++)
  940. *(iv+4+i) = req->iv[i];
  941. *((__be32 *)(iv+12)) = counter;
  942. return gcmaes_encrypt(req, req->assoclen - 8, ctx->hash_subkey, iv,
  943. aes_ctx);
  944. }
  945. static int helper_rfc4106_decrypt(struct aead_request *req)
  946. {
  947. __be32 counter = cpu_to_be32(1);
  948. struct crypto_aead *tfm = crypto_aead_reqtfm(req);
  949. struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(tfm);
  950. void *aes_ctx = &(ctx->aes_key_expanded);
  951. u8 iv[16] __attribute__ ((__aligned__(AESNI_ALIGN)));
  952. unsigned int i;
  953. if (unlikely(req->assoclen != 16 && req->assoclen != 20))
  954. return -EINVAL;
  955. /* Assuming we are supporting rfc4106 64-bit extended */
  956. /* sequence numbers We need to have the AAD length */
  957. /* equal to 16 or 20 bytes */
  958. /* IV below built */
  959. for (i = 0; i < 4; i++)
  960. *(iv+i) = ctx->nonce[i];
  961. for (i = 0; i < 8; i++)
  962. *(iv+4+i) = req->iv[i];
  963. *((__be32 *)(iv+12)) = counter;
  964. return gcmaes_decrypt(req, req->assoclen - 8, ctx->hash_subkey, iv,
  965. aes_ctx);
  966. }
  967. static int gcmaes_wrapper_encrypt(struct aead_request *req)
  968. {
  969. struct crypto_aead *tfm = crypto_aead_reqtfm(req);
  970. struct cryptd_aead **ctx = crypto_aead_ctx(tfm);
  971. struct cryptd_aead *cryptd_tfm = *ctx;
  972. tfm = &cryptd_tfm->base;
  973. if (irq_fpu_usable() && (!in_atomic() ||
  974. !cryptd_aead_queued(cryptd_tfm)))
  975. tfm = cryptd_aead_child(cryptd_tfm);
  976. aead_request_set_tfm(req, tfm);
  977. return crypto_aead_encrypt(req);
  978. }
  979. static int gcmaes_wrapper_decrypt(struct aead_request *req)
  980. {
  981. struct crypto_aead *tfm = crypto_aead_reqtfm(req);
  982. struct cryptd_aead **ctx = crypto_aead_ctx(tfm);
  983. struct cryptd_aead *cryptd_tfm = *ctx;
  984. tfm = &cryptd_tfm->base;
  985. if (irq_fpu_usable() && (!in_atomic() ||
  986. !cryptd_aead_queued(cryptd_tfm)))
  987. tfm = cryptd_aead_child(cryptd_tfm);
  988. aead_request_set_tfm(req, tfm);
  989. return crypto_aead_decrypt(req);
  990. }
  991. #endif
  992. static struct crypto_alg aesni_algs[] = { {
  993. .cra_name = "aes",
  994. .cra_driver_name = "aes-aesni",
  995. .cra_priority = 300,
  996. .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
  997. .cra_blocksize = AES_BLOCK_SIZE,
  998. .cra_ctxsize = CRYPTO_AES_CTX_SIZE,
  999. .cra_module = THIS_MODULE,
  1000. .cra_u = {
  1001. .cipher = {
  1002. .cia_min_keysize = AES_MIN_KEY_SIZE,
  1003. .cia_max_keysize = AES_MAX_KEY_SIZE,
  1004. .cia_setkey = aes_set_key,
  1005. .cia_encrypt = aes_encrypt,
  1006. .cia_decrypt = aes_decrypt
  1007. }
  1008. }
  1009. }, {
  1010. .cra_name = "__aes",
  1011. .cra_driver_name = "__aes-aesni",
  1012. .cra_priority = 300,
  1013. .cra_flags = CRYPTO_ALG_TYPE_CIPHER | CRYPTO_ALG_INTERNAL,
  1014. .cra_blocksize = AES_BLOCK_SIZE,
  1015. .cra_ctxsize = CRYPTO_AES_CTX_SIZE,
  1016. .cra_module = THIS_MODULE,
  1017. .cra_u = {
  1018. .cipher = {
  1019. .cia_min_keysize = AES_MIN_KEY_SIZE,
  1020. .cia_max_keysize = AES_MAX_KEY_SIZE,
  1021. .cia_setkey = aes_set_key,
  1022. .cia_encrypt = __aes_encrypt,
  1023. .cia_decrypt = __aes_decrypt
  1024. }
  1025. }
  1026. } };
  1027. static struct skcipher_alg aesni_skciphers[] = {
  1028. {
  1029. .base = {
  1030. .cra_name = "__ecb(aes)",
  1031. .cra_driver_name = "__ecb-aes-aesni",
  1032. .cra_priority = 400,
  1033. .cra_flags = CRYPTO_ALG_INTERNAL,
  1034. .cra_blocksize = AES_BLOCK_SIZE,
  1035. .cra_ctxsize = CRYPTO_AES_CTX_SIZE,
  1036. .cra_module = THIS_MODULE,
  1037. },
  1038. .min_keysize = AES_MIN_KEY_SIZE,
  1039. .max_keysize = AES_MAX_KEY_SIZE,
  1040. .setkey = aesni_skcipher_setkey,
  1041. .encrypt = ecb_encrypt,
  1042. .decrypt = ecb_decrypt,
  1043. }, {
  1044. .base = {
  1045. .cra_name = "__cbc(aes)",
  1046. .cra_driver_name = "__cbc-aes-aesni",
  1047. .cra_priority = 400,
  1048. .cra_flags = CRYPTO_ALG_INTERNAL,
  1049. .cra_blocksize = AES_BLOCK_SIZE,
  1050. .cra_ctxsize = CRYPTO_AES_CTX_SIZE,
  1051. .cra_module = THIS_MODULE,
  1052. },
  1053. .min_keysize = AES_MIN_KEY_SIZE,
  1054. .max_keysize = AES_MAX_KEY_SIZE,
  1055. .ivsize = AES_BLOCK_SIZE,
  1056. .setkey = aesni_skcipher_setkey,
  1057. .encrypt = cbc_encrypt,
  1058. .decrypt = cbc_decrypt,
  1059. #ifdef CONFIG_X86_64
  1060. }, {
  1061. .base = {
  1062. .cra_name = "__ctr(aes)",
  1063. .cra_driver_name = "__ctr-aes-aesni",
  1064. .cra_priority = 400,
  1065. .cra_flags = CRYPTO_ALG_INTERNAL,
  1066. .cra_blocksize = 1,
  1067. .cra_ctxsize = CRYPTO_AES_CTX_SIZE,
  1068. .cra_module = THIS_MODULE,
  1069. },
  1070. .min_keysize = AES_MIN_KEY_SIZE,
  1071. .max_keysize = AES_MAX_KEY_SIZE,
  1072. .ivsize = AES_BLOCK_SIZE,
  1073. .chunksize = AES_BLOCK_SIZE,
  1074. .setkey = aesni_skcipher_setkey,
  1075. .encrypt = ctr_crypt,
  1076. .decrypt = ctr_crypt,
  1077. }, {
  1078. .base = {
  1079. .cra_name = "__xts(aes)",
  1080. .cra_driver_name = "__xts-aes-aesni",
  1081. .cra_priority = 401,
  1082. .cra_flags = CRYPTO_ALG_INTERNAL,
  1083. .cra_blocksize = AES_BLOCK_SIZE,
  1084. .cra_ctxsize = XTS_AES_CTX_SIZE,
  1085. .cra_module = THIS_MODULE,
  1086. },
  1087. .min_keysize = 2 * AES_MIN_KEY_SIZE,
  1088. .max_keysize = 2 * AES_MAX_KEY_SIZE,
  1089. .ivsize = AES_BLOCK_SIZE,
  1090. .setkey = xts_aesni_setkey,
  1091. .encrypt = xts_encrypt,
  1092. .decrypt = xts_decrypt,
  1093. #endif
  1094. }
  1095. };
  1096. static
  1097. struct simd_skcipher_alg *aesni_simd_skciphers[ARRAY_SIZE(aesni_skciphers)];
  1098. static struct {
  1099. const char *algname;
  1100. const char *drvname;
  1101. const char *basename;
  1102. struct simd_skcipher_alg *simd;
  1103. } aesni_simd_skciphers2[] = {
  1104. #if (defined(MODULE) && IS_ENABLED(CONFIG_CRYPTO_PCBC)) || \
  1105. IS_BUILTIN(CONFIG_CRYPTO_PCBC)
  1106. {
  1107. .algname = "pcbc(aes)",
  1108. .drvname = "pcbc-aes-aesni",
  1109. .basename = "fpu(pcbc(__aes-aesni))",
  1110. },
  1111. #endif
  1112. };
  1113. #ifdef CONFIG_X86_64
  1114. static int generic_gcmaes_set_key(struct crypto_aead *aead, const u8 *key,
  1115. unsigned int key_len)
  1116. {
  1117. struct generic_gcmaes_ctx *ctx = generic_gcmaes_ctx_get(aead);
  1118. return aes_set_key_common(crypto_aead_tfm(aead),
  1119. &ctx->aes_key_expanded, key, key_len) ?:
  1120. rfc4106_set_hash_subkey(ctx->hash_subkey, key, key_len);
  1121. }
  1122. static int generic_gcmaes_encrypt(struct aead_request *req)
  1123. {
  1124. struct crypto_aead *tfm = crypto_aead_reqtfm(req);
  1125. struct generic_gcmaes_ctx *ctx = generic_gcmaes_ctx_get(tfm);
  1126. void *aes_ctx = &(ctx->aes_key_expanded);
  1127. u8 iv[16] __attribute__ ((__aligned__(AESNI_ALIGN)));
  1128. __be32 counter = cpu_to_be32(1);
  1129. memcpy(iv, req->iv, 12);
  1130. *((__be32 *)(iv+12)) = counter;
  1131. return gcmaes_encrypt(req, req->assoclen, ctx->hash_subkey, iv,
  1132. aes_ctx);
  1133. }
  1134. static int generic_gcmaes_decrypt(struct aead_request *req)
  1135. {
  1136. __be32 counter = cpu_to_be32(1);
  1137. struct crypto_aead *tfm = crypto_aead_reqtfm(req);
  1138. struct generic_gcmaes_ctx *ctx = generic_gcmaes_ctx_get(tfm);
  1139. void *aes_ctx = &(ctx->aes_key_expanded);
  1140. u8 iv[16] __attribute__ ((__aligned__(AESNI_ALIGN)));
  1141. memcpy(iv, req->iv, 12);
  1142. *((__be32 *)(iv+12)) = counter;
  1143. return gcmaes_decrypt(req, req->assoclen, ctx->hash_subkey, iv,
  1144. aes_ctx);
  1145. }
  1146. static int generic_gcmaes_init(struct crypto_aead *aead)
  1147. {
  1148. struct cryptd_aead *cryptd_tfm;
  1149. struct cryptd_aead **ctx = crypto_aead_ctx(aead);
  1150. cryptd_tfm = cryptd_alloc_aead("__driver-generic-gcm-aes-aesni",
  1151. CRYPTO_ALG_INTERNAL,
  1152. CRYPTO_ALG_INTERNAL);
  1153. if (IS_ERR(cryptd_tfm))
  1154. return PTR_ERR(cryptd_tfm);
  1155. *ctx = cryptd_tfm;
  1156. crypto_aead_set_reqsize(aead, crypto_aead_reqsize(&cryptd_tfm->base));
  1157. return 0;
  1158. }
  1159. static void generic_gcmaes_exit(struct crypto_aead *aead)
  1160. {
  1161. struct cryptd_aead **ctx = crypto_aead_ctx(aead);
  1162. cryptd_free_aead(*ctx);
  1163. }
  1164. static struct aead_alg aesni_aead_algs[] = { {
  1165. .setkey = common_rfc4106_set_key,
  1166. .setauthsize = common_rfc4106_set_authsize,
  1167. .encrypt = helper_rfc4106_encrypt,
  1168. .decrypt = helper_rfc4106_decrypt,
  1169. .ivsize = GCM_RFC4106_IV_SIZE,
  1170. .maxauthsize = 16,
  1171. .base = {
  1172. .cra_name = "__gcm-aes-aesni",
  1173. .cra_driver_name = "__driver-gcm-aes-aesni",
  1174. .cra_flags = CRYPTO_ALG_INTERNAL,
  1175. .cra_blocksize = 1,
  1176. .cra_ctxsize = sizeof(struct aesni_rfc4106_gcm_ctx),
  1177. .cra_alignmask = AESNI_ALIGN - 1,
  1178. .cra_module = THIS_MODULE,
  1179. },
  1180. }, {
  1181. .init = rfc4106_init,
  1182. .exit = rfc4106_exit,
  1183. .setkey = gcmaes_wrapper_set_key,
  1184. .setauthsize = gcmaes_wrapper_set_authsize,
  1185. .encrypt = gcmaes_wrapper_encrypt,
  1186. .decrypt = gcmaes_wrapper_decrypt,
  1187. .ivsize = GCM_RFC4106_IV_SIZE,
  1188. .maxauthsize = 16,
  1189. .base = {
  1190. .cra_name = "rfc4106(gcm(aes))",
  1191. .cra_driver_name = "rfc4106-gcm-aesni",
  1192. .cra_priority = 400,
  1193. .cra_flags = CRYPTO_ALG_ASYNC,
  1194. .cra_blocksize = 1,
  1195. .cra_ctxsize = sizeof(struct cryptd_aead *),
  1196. .cra_module = THIS_MODULE,
  1197. },
  1198. }, {
  1199. .setkey = generic_gcmaes_set_key,
  1200. .setauthsize = generic_gcmaes_set_authsize,
  1201. .encrypt = generic_gcmaes_encrypt,
  1202. .decrypt = generic_gcmaes_decrypt,
  1203. .ivsize = GCM_AES_IV_SIZE,
  1204. .maxauthsize = 16,
  1205. .base = {
  1206. .cra_name = "__generic-gcm-aes-aesni",
  1207. .cra_driver_name = "__driver-generic-gcm-aes-aesni",
  1208. .cra_priority = 0,
  1209. .cra_flags = CRYPTO_ALG_INTERNAL,
  1210. .cra_blocksize = 1,
  1211. .cra_ctxsize = sizeof(struct generic_gcmaes_ctx),
  1212. .cra_alignmask = AESNI_ALIGN - 1,
  1213. .cra_module = THIS_MODULE,
  1214. },
  1215. }, {
  1216. .init = generic_gcmaes_init,
  1217. .exit = generic_gcmaes_exit,
  1218. .setkey = gcmaes_wrapper_set_key,
  1219. .setauthsize = gcmaes_wrapper_set_authsize,
  1220. .encrypt = gcmaes_wrapper_encrypt,
  1221. .decrypt = gcmaes_wrapper_decrypt,
  1222. .ivsize = GCM_AES_IV_SIZE,
  1223. .maxauthsize = 16,
  1224. .base = {
  1225. .cra_name = "gcm(aes)",
  1226. .cra_driver_name = "generic-gcm-aesni",
  1227. .cra_priority = 400,
  1228. .cra_flags = CRYPTO_ALG_ASYNC,
  1229. .cra_blocksize = 1,
  1230. .cra_ctxsize = sizeof(struct cryptd_aead *),
  1231. .cra_module = THIS_MODULE,
  1232. },
  1233. } };
  1234. #else
  1235. static struct aead_alg aesni_aead_algs[0];
  1236. #endif
  1237. static const struct x86_cpu_id aesni_cpu_id[] = {
  1238. X86_FEATURE_MATCH(X86_FEATURE_AES),
  1239. {}
  1240. };
  1241. MODULE_DEVICE_TABLE(x86cpu, aesni_cpu_id);
  1242. static void aesni_free_simds(void)
  1243. {
  1244. int i;
  1245. for (i = 0; i < ARRAY_SIZE(aesni_simd_skciphers) &&
  1246. aesni_simd_skciphers[i]; i++)
  1247. simd_skcipher_free(aesni_simd_skciphers[i]);
  1248. for (i = 0; i < ARRAY_SIZE(aesni_simd_skciphers2); i++)
  1249. if (aesni_simd_skciphers2[i].simd)
  1250. simd_skcipher_free(aesni_simd_skciphers2[i].simd);
  1251. }
  1252. static int __init aesni_init(void)
  1253. {
  1254. struct simd_skcipher_alg *simd;
  1255. const char *basename;
  1256. const char *algname;
  1257. const char *drvname;
  1258. int err;
  1259. int i;
  1260. if (!x86_match_cpu(aesni_cpu_id))
  1261. return -ENODEV;
  1262. #ifdef CONFIG_X86_64
  1263. #ifdef CONFIG_AS_AVX2
  1264. if (boot_cpu_has(X86_FEATURE_AVX2)) {
  1265. pr_info("AVX2 version of gcm_enc/dec engaged.\n");
  1266. aesni_gcm_enc_tfm = aesni_gcm_enc_avx2;
  1267. aesni_gcm_dec_tfm = aesni_gcm_dec_avx2;
  1268. } else
  1269. #endif
  1270. #ifdef CONFIG_AS_AVX
  1271. if (boot_cpu_has(X86_FEATURE_AVX)) {
  1272. pr_info("AVX version of gcm_enc/dec engaged.\n");
  1273. aesni_gcm_enc_tfm = aesni_gcm_enc_avx;
  1274. aesni_gcm_dec_tfm = aesni_gcm_dec_avx;
  1275. } else
  1276. #endif
  1277. {
  1278. pr_info("SSE version of gcm_enc/dec engaged.\n");
  1279. aesni_gcm_enc_tfm = aesni_gcm_enc;
  1280. aesni_gcm_dec_tfm = aesni_gcm_dec;
  1281. }
  1282. aesni_ctr_enc_tfm = aesni_ctr_enc;
  1283. #ifdef CONFIG_AS_AVX
  1284. if (boot_cpu_has(X86_FEATURE_AVX)) {
  1285. /* optimize performance of ctr mode encryption transform */
  1286. aesni_ctr_enc_tfm = aesni_ctr_enc_avx_tfm;
  1287. pr_info("AES CTR mode by8 optimization enabled\n");
  1288. }
  1289. #endif
  1290. #endif
  1291. err = crypto_fpu_init();
  1292. if (err)
  1293. return err;
  1294. err = crypto_register_algs(aesni_algs, ARRAY_SIZE(aesni_algs));
  1295. if (err)
  1296. goto fpu_exit;
  1297. err = crypto_register_skciphers(aesni_skciphers,
  1298. ARRAY_SIZE(aesni_skciphers));
  1299. if (err)
  1300. goto unregister_algs;
  1301. err = crypto_register_aeads(aesni_aead_algs,
  1302. ARRAY_SIZE(aesni_aead_algs));
  1303. if (err)
  1304. goto unregister_skciphers;
  1305. for (i = 0; i < ARRAY_SIZE(aesni_skciphers); i++) {
  1306. algname = aesni_skciphers[i].base.cra_name + 2;
  1307. drvname = aesni_skciphers[i].base.cra_driver_name + 2;
  1308. basename = aesni_skciphers[i].base.cra_driver_name;
  1309. simd = simd_skcipher_create_compat(algname, drvname, basename);
  1310. err = PTR_ERR(simd);
  1311. if (IS_ERR(simd))
  1312. goto unregister_simds;
  1313. aesni_simd_skciphers[i] = simd;
  1314. }
  1315. for (i = 0; i < ARRAY_SIZE(aesni_simd_skciphers2); i++) {
  1316. algname = aesni_simd_skciphers2[i].algname;
  1317. drvname = aesni_simd_skciphers2[i].drvname;
  1318. basename = aesni_simd_skciphers2[i].basename;
  1319. simd = simd_skcipher_create_compat(algname, drvname, basename);
  1320. err = PTR_ERR(simd);
  1321. if (IS_ERR(simd))
  1322. continue;
  1323. aesni_simd_skciphers2[i].simd = simd;
  1324. }
  1325. return 0;
  1326. unregister_simds:
  1327. aesni_free_simds();
  1328. crypto_unregister_aeads(aesni_aead_algs, ARRAY_SIZE(aesni_aead_algs));
  1329. unregister_skciphers:
  1330. crypto_unregister_skciphers(aesni_skciphers,
  1331. ARRAY_SIZE(aesni_skciphers));
  1332. unregister_algs:
  1333. crypto_unregister_algs(aesni_algs, ARRAY_SIZE(aesni_algs));
  1334. fpu_exit:
  1335. crypto_fpu_exit();
  1336. return err;
  1337. }
  1338. static void __exit aesni_exit(void)
  1339. {
  1340. aesni_free_simds();
  1341. crypto_unregister_aeads(aesni_aead_algs, ARRAY_SIZE(aesni_aead_algs));
  1342. crypto_unregister_skciphers(aesni_skciphers,
  1343. ARRAY_SIZE(aesni_skciphers));
  1344. crypto_unregister_algs(aesni_algs, ARRAY_SIZE(aesni_algs));
  1345. crypto_fpu_exit();
  1346. }
  1347. late_initcall(aesni_init);
  1348. module_exit(aesni_exit);
  1349. MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm, Intel AES-NI instructions optimized");
  1350. MODULE_LICENSE("GPL");
  1351. MODULE_ALIAS_CRYPTO("aes");