aes-ce-glue.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /*
  2. * aes-ce-glue.c - wrapper code for ARMv8 AES
  3. *
  4. * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <asm/hwcap.h>
  11. #include <asm/neon.h>
  12. #include <asm/hwcap.h>
  13. #include <crypto/aes.h>
  14. #include <crypto/ablk_helper.h>
  15. #include <crypto/algapi.h>
  16. #include <linux/module.h>
  17. #include <crypto/xts.h>
  18. MODULE_DESCRIPTION("AES-ECB/CBC/CTR/XTS using ARMv8 Crypto Extensions");
  19. MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
  20. MODULE_LICENSE("GPL v2");
  21. /* defined in aes-ce-core.S */
  22. asmlinkage u32 ce_aes_sub(u32 input);
  23. asmlinkage void ce_aes_invert(void *dst, void *src);
  24. asmlinkage void ce_aes_ecb_encrypt(u8 out[], u8 const in[], u8 const rk[],
  25. int rounds, int blocks);
  26. asmlinkage void ce_aes_ecb_decrypt(u8 out[], u8 const in[], u8 const rk[],
  27. int rounds, int blocks);
  28. asmlinkage void ce_aes_cbc_encrypt(u8 out[], u8 const in[], u8 const rk[],
  29. int rounds, int blocks, u8 iv[]);
  30. asmlinkage void ce_aes_cbc_decrypt(u8 out[], u8 const in[], u8 const rk[],
  31. int rounds, int blocks, u8 iv[]);
  32. asmlinkage void ce_aes_ctr_encrypt(u8 out[], u8 const in[], u8 const rk[],
  33. int rounds, int blocks, u8 ctr[]);
  34. asmlinkage void ce_aes_xts_encrypt(u8 out[], u8 const in[], u8 const rk1[],
  35. int rounds, int blocks, u8 iv[],
  36. u8 const rk2[], int first);
  37. asmlinkage void ce_aes_xts_decrypt(u8 out[], u8 const in[], u8 const rk1[],
  38. int rounds, int blocks, u8 iv[],
  39. u8 const rk2[], int first);
  40. struct aes_block {
  41. u8 b[AES_BLOCK_SIZE];
  42. };
  43. static int num_rounds(struct crypto_aes_ctx *ctx)
  44. {
  45. /*
  46. * # of rounds specified by AES:
  47. * 128 bit key 10 rounds
  48. * 192 bit key 12 rounds
  49. * 256 bit key 14 rounds
  50. * => n byte key => 6 + (n/4) rounds
  51. */
  52. return 6 + ctx->key_length / 4;
  53. }
  54. static int ce_aes_expandkey(struct crypto_aes_ctx *ctx, const u8 *in_key,
  55. unsigned int key_len)
  56. {
  57. /*
  58. * The AES key schedule round constants
  59. */
  60. static u8 const rcon[] = {
  61. 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36,
  62. };
  63. u32 kwords = key_len / sizeof(u32);
  64. struct aes_block *key_enc, *key_dec;
  65. int i, j;
  66. if (key_len != AES_KEYSIZE_128 &&
  67. key_len != AES_KEYSIZE_192 &&
  68. key_len != AES_KEYSIZE_256)
  69. return -EINVAL;
  70. memcpy(ctx->key_enc, in_key, key_len);
  71. ctx->key_length = key_len;
  72. kernel_neon_begin();
  73. for (i = 0; i < sizeof(rcon); i++) {
  74. u32 *rki = ctx->key_enc + (i * kwords);
  75. u32 *rko = rki + kwords;
  76. #ifndef CONFIG_CPU_BIG_ENDIAN
  77. rko[0] = ror32(ce_aes_sub(rki[kwords - 1]), 8);
  78. rko[0] = rko[0] ^ rki[0] ^ rcon[i];
  79. #else
  80. rko[0] = rol32(ce_aes_sub(rki[kwords - 1]), 8);
  81. rko[0] = rko[0] ^ rki[0] ^ (rcon[i] << 24);
  82. #endif
  83. rko[1] = rko[0] ^ rki[1];
  84. rko[2] = rko[1] ^ rki[2];
  85. rko[3] = rko[2] ^ rki[3];
  86. if (key_len == AES_KEYSIZE_192) {
  87. if (i >= 7)
  88. break;
  89. rko[4] = rko[3] ^ rki[4];
  90. rko[5] = rko[4] ^ rki[5];
  91. } else if (key_len == AES_KEYSIZE_256) {
  92. if (i >= 6)
  93. break;
  94. rko[4] = ce_aes_sub(rko[3]) ^ rki[4];
  95. rko[5] = rko[4] ^ rki[5];
  96. rko[6] = rko[5] ^ rki[6];
  97. rko[7] = rko[6] ^ rki[7];
  98. }
  99. }
  100. /*
  101. * Generate the decryption keys for the Equivalent Inverse Cipher.
  102. * This involves reversing the order of the round keys, and applying
  103. * the Inverse Mix Columns transformation on all but the first and
  104. * the last one.
  105. */
  106. key_enc = (struct aes_block *)ctx->key_enc;
  107. key_dec = (struct aes_block *)ctx->key_dec;
  108. j = num_rounds(ctx);
  109. key_dec[0] = key_enc[j];
  110. for (i = 1, j--; j > 0; i++, j--)
  111. ce_aes_invert(key_dec + i, key_enc + j);
  112. key_dec[i] = key_enc[0];
  113. kernel_neon_end();
  114. return 0;
  115. }
  116. static int ce_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,
  117. unsigned int key_len)
  118. {
  119. struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
  120. int ret;
  121. ret = ce_aes_expandkey(ctx, in_key, key_len);
  122. if (!ret)
  123. return 0;
  124. tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
  125. return -EINVAL;
  126. }
  127. struct crypto_aes_xts_ctx {
  128. struct crypto_aes_ctx key1;
  129. struct crypto_aes_ctx __aligned(8) key2;
  130. };
  131. static int xts_set_key(struct crypto_tfm *tfm, const u8 *in_key,
  132. unsigned int key_len)
  133. {
  134. struct crypto_aes_xts_ctx *ctx = crypto_tfm_ctx(tfm);
  135. int ret;
  136. ret = xts_check_key(tfm, in_key, key_len);
  137. if (ret)
  138. return ret;
  139. ret = ce_aes_expandkey(&ctx->key1, in_key, key_len / 2);
  140. if (!ret)
  141. ret = ce_aes_expandkey(&ctx->key2, &in_key[key_len / 2],
  142. key_len / 2);
  143. if (!ret)
  144. return 0;
  145. tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
  146. return -EINVAL;
  147. }
  148. static int ecb_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  149. struct scatterlist *src, unsigned int nbytes)
  150. {
  151. struct crypto_aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  152. struct blkcipher_walk walk;
  153. unsigned int blocks;
  154. int err;
  155. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  156. blkcipher_walk_init(&walk, dst, src, nbytes);
  157. err = blkcipher_walk_virt(desc, &walk);
  158. kernel_neon_begin();
  159. while ((blocks = (walk.nbytes / AES_BLOCK_SIZE))) {
  160. ce_aes_ecb_encrypt(walk.dst.virt.addr, walk.src.virt.addr,
  161. (u8 *)ctx->key_enc, num_rounds(ctx), blocks);
  162. err = blkcipher_walk_done(desc, &walk,
  163. walk.nbytes % AES_BLOCK_SIZE);
  164. }
  165. kernel_neon_end();
  166. return err;
  167. }
  168. static int ecb_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  169. struct scatterlist *src, unsigned int nbytes)
  170. {
  171. struct crypto_aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  172. struct blkcipher_walk walk;
  173. unsigned int blocks;
  174. int err;
  175. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  176. blkcipher_walk_init(&walk, dst, src, nbytes);
  177. err = blkcipher_walk_virt(desc, &walk);
  178. kernel_neon_begin();
  179. while ((blocks = (walk.nbytes / AES_BLOCK_SIZE))) {
  180. ce_aes_ecb_decrypt(walk.dst.virt.addr, walk.src.virt.addr,
  181. (u8 *)ctx->key_dec, num_rounds(ctx), blocks);
  182. err = blkcipher_walk_done(desc, &walk,
  183. walk.nbytes % AES_BLOCK_SIZE);
  184. }
  185. kernel_neon_end();
  186. return err;
  187. }
  188. static int cbc_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  189. struct scatterlist *src, unsigned int nbytes)
  190. {
  191. struct crypto_aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  192. struct blkcipher_walk walk;
  193. unsigned int blocks;
  194. int err;
  195. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  196. blkcipher_walk_init(&walk, dst, src, nbytes);
  197. err = blkcipher_walk_virt(desc, &walk);
  198. kernel_neon_begin();
  199. while ((blocks = (walk.nbytes / AES_BLOCK_SIZE))) {
  200. ce_aes_cbc_encrypt(walk.dst.virt.addr, walk.src.virt.addr,
  201. (u8 *)ctx->key_enc, num_rounds(ctx), blocks,
  202. walk.iv);
  203. err = blkcipher_walk_done(desc, &walk,
  204. walk.nbytes % AES_BLOCK_SIZE);
  205. }
  206. kernel_neon_end();
  207. return err;
  208. }
  209. static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  210. struct scatterlist *src, unsigned int nbytes)
  211. {
  212. struct crypto_aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  213. struct blkcipher_walk walk;
  214. unsigned int blocks;
  215. int err;
  216. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  217. blkcipher_walk_init(&walk, dst, src, nbytes);
  218. err = blkcipher_walk_virt(desc, &walk);
  219. kernel_neon_begin();
  220. while ((blocks = (walk.nbytes / AES_BLOCK_SIZE))) {
  221. ce_aes_cbc_decrypt(walk.dst.virt.addr, walk.src.virt.addr,
  222. (u8 *)ctx->key_dec, num_rounds(ctx), blocks,
  223. walk.iv);
  224. err = blkcipher_walk_done(desc, &walk,
  225. walk.nbytes % AES_BLOCK_SIZE);
  226. }
  227. kernel_neon_end();
  228. return err;
  229. }
  230. static int ctr_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  231. struct scatterlist *src, unsigned int nbytes)
  232. {
  233. struct crypto_aes_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  234. struct blkcipher_walk walk;
  235. int err, blocks;
  236. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  237. blkcipher_walk_init(&walk, dst, src, nbytes);
  238. err = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE);
  239. kernel_neon_begin();
  240. while ((blocks = (walk.nbytes / AES_BLOCK_SIZE))) {
  241. ce_aes_ctr_encrypt(walk.dst.virt.addr, walk.src.virt.addr,
  242. (u8 *)ctx->key_enc, num_rounds(ctx), blocks,
  243. walk.iv);
  244. nbytes -= blocks * AES_BLOCK_SIZE;
  245. if (nbytes && nbytes == walk.nbytes % AES_BLOCK_SIZE)
  246. break;
  247. err = blkcipher_walk_done(desc, &walk,
  248. walk.nbytes % AES_BLOCK_SIZE);
  249. }
  250. if (walk.nbytes % AES_BLOCK_SIZE) {
  251. u8 *tdst = walk.dst.virt.addr + blocks * AES_BLOCK_SIZE;
  252. u8 *tsrc = walk.src.virt.addr + blocks * AES_BLOCK_SIZE;
  253. u8 __aligned(8) tail[AES_BLOCK_SIZE];
  254. /*
  255. * Minimum alignment is 8 bytes, so if nbytes is <= 8, we need
  256. * to tell aes_ctr_encrypt() to only read half a block.
  257. */
  258. blocks = (nbytes <= 8) ? -1 : 1;
  259. ce_aes_ctr_encrypt(tail, tsrc, (u8 *)ctx->key_enc,
  260. num_rounds(ctx), blocks, walk.iv);
  261. memcpy(tdst, tail, nbytes);
  262. err = blkcipher_walk_done(desc, &walk, 0);
  263. }
  264. kernel_neon_end();
  265. return err;
  266. }
  267. static int xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  268. struct scatterlist *src, unsigned int nbytes)
  269. {
  270. struct crypto_aes_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  271. int err, first, rounds = num_rounds(&ctx->key1);
  272. struct blkcipher_walk walk;
  273. unsigned int blocks;
  274. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  275. blkcipher_walk_init(&walk, dst, src, nbytes);
  276. err = blkcipher_walk_virt(desc, &walk);
  277. kernel_neon_begin();
  278. for (first = 1; (blocks = (walk.nbytes / AES_BLOCK_SIZE)); first = 0) {
  279. ce_aes_xts_encrypt(walk.dst.virt.addr, walk.src.virt.addr,
  280. (u8 *)ctx->key1.key_enc, rounds, blocks,
  281. walk.iv, (u8 *)ctx->key2.key_enc, first);
  282. err = blkcipher_walk_done(desc, &walk,
  283. walk.nbytes % AES_BLOCK_SIZE);
  284. }
  285. kernel_neon_end();
  286. return err;
  287. }
  288. static int xts_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  289. struct scatterlist *src, unsigned int nbytes)
  290. {
  291. struct crypto_aes_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  292. int err, first, rounds = num_rounds(&ctx->key1);
  293. struct blkcipher_walk walk;
  294. unsigned int blocks;
  295. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  296. blkcipher_walk_init(&walk, dst, src, nbytes);
  297. err = blkcipher_walk_virt(desc, &walk);
  298. kernel_neon_begin();
  299. for (first = 1; (blocks = (walk.nbytes / AES_BLOCK_SIZE)); first = 0) {
  300. ce_aes_xts_decrypt(walk.dst.virt.addr, walk.src.virt.addr,
  301. (u8 *)ctx->key1.key_dec, rounds, blocks,
  302. walk.iv, (u8 *)ctx->key2.key_enc, first);
  303. err = blkcipher_walk_done(desc, &walk,
  304. walk.nbytes % AES_BLOCK_SIZE);
  305. }
  306. kernel_neon_end();
  307. return err;
  308. }
  309. static struct crypto_alg aes_algs[] = { {
  310. .cra_name = "__ecb-aes-ce",
  311. .cra_driver_name = "__driver-ecb-aes-ce",
  312. .cra_priority = 0,
  313. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER |
  314. CRYPTO_ALG_INTERNAL,
  315. .cra_blocksize = AES_BLOCK_SIZE,
  316. .cra_ctxsize = sizeof(struct crypto_aes_ctx),
  317. .cra_alignmask = 7,
  318. .cra_type = &crypto_blkcipher_type,
  319. .cra_module = THIS_MODULE,
  320. .cra_blkcipher = {
  321. .min_keysize = AES_MIN_KEY_SIZE,
  322. .max_keysize = AES_MAX_KEY_SIZE,
  323. .ivsize = 0,
  324. .setkey = ce_aes_setkey,
  325. .encrypt = ecb_encrypt,
  326. .decrypt = ecb_decrypt,
  327. },
  328. }, {
  329. .cra_name = "__cbc-aes-ce",
  330. .cra_driver_name = "__driver-cbc-aes-ce",
  331. .cra_priority = 0,
  332. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER |
  333. CRYPTO_ALG_INTERNAL,
  334. .cra_blocksize = AES_BLOCK_SIZE,
  335. .cra_ctxsize = sizeof(struct crypto_aes_ctx),
  336. .cra_alignmask = 7,
  337. .cra_type = &crypto_blkcipher_type,
  338. .cra_module = THIS_MODULE,
  339. .cra_blkcipher = {
  340. .min_keysize = AES_MIN_KEY_SIZE,
  341. .max_keysize = AES_MAX_KEY_SIZE,
  342. .ivsize = AES_BLOCK_SIZE,
  343. .setkey = ce_aes_setkey,
  344. .encrypt = cbc_encrypt,
  345. .decrypt = cbc_decrypt,
  346. },
  347. }, {
  348. .cra_name = "__ctr-aes-ce",
  349. .cra_driver_name = "__driver-ctr-aes-ce",
  350. .cra_priority = 0,
  351. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER |
  352. CRYPTO_ALG_INTERNAL,
  353. .cra_blocksize = 1,
  354. .cra_ctxsize = sizeof(struct crypto_aes_ctx),
  355. .cra_alignmask = 7,
  356. .cra_type = &crypto_blkcipher_type,
  357. .cra_module = THIS_MODULE,
  358. .cra_blkcipher = {
  359. .min_keysize = AES_MIN_KEY_SIZE,
  360. .max_keysize = AES_MAX_KEY_SIZE,
  361. .ivsize = AES_BLOCK_SIZE,
  362. .setkey = ce_aes_setkey,
  363. .encrypt = ctr_encrypt,
  364. .decrypt = ctr_encrypt,
  365. },
  366. }, {
  367. .cra_name = "__xts-aes-ce",
  368. .cra_driver_name = "__driver-xts-aes-ce",
  369. .cra_priority = 0,
  370. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER |
  371. CRYPTO_ALG_INTERNAL,
  372. .cra_blocksize = AES_BLOCK_SIZE,
  373. .cra_ctxsize = sizeof(struct crypto_aes_xts_ctx),
  374. .cra_alignmask = 7,
  375. .cra_type = &crypto_blkcipher_type,
  376. .cra_module = THIS_MODULE,
  377. .cra_blkcipher = {
  378. .min_keysize = 2 * AES_MIN_KEY_SIZE,
  379. .max_keysize = 2 * AES_MAX_KEY_SIZE,
  380. .ivsize = AES_BLOCK_SIZE,
  381. .setkey = xts_set_key,
  382. .encrypt = xts_encrypt,
  383. .decrypt = xts_decrypt,
  384. },
  385. }, {
  386. .cra_name = "ecb(aes)",
  387. .cra_driver_name = "ecb-aes-ce",
  388. .cra_priority = 300,
  389. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
  390. .cra_blocksize = AES_BLOCK_SIZE,
  391. .cra_ctxsize = sizeof(struct async_helper_ctx),
  392. .cra_alignmask = 7,
  393. .cra_type = &crypto_ablkcipher_type,
  394. .cra_module = THIS_MODULE,
  395. .cra_init = ablk_init,
  396. .cra_exit = ablk_exit,
  397. .cra_ablkcipher = {
  398. .min_keysize = AES_MIN_KEY_SIZE,
  399. .max_keysize = AES_MAX_KEY_SIZE,
  400. .ivsize = 0,
  401. .setkey = ablk_set_key,
  402. .encrypt = ablk_encrypt,
  403. .decrypt = ablk_decrypt,
  404. }
  405. }, {
  406. .cra_name = "cbc(aes)",
  407. .cra_driver_name = "cbc-aes-ce",
  408. .cra_priority = 300,
  409. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
  410. .cra_blocksize = AES_BLOCK_SIZE,
  411. .cra_ctxsize = sizeof(struct async_helper_ctx),
  412. .cra_alignmask = 7,
  413. .cra_type = &crypto_ablkcipher_type,
  414. .cra_module = THIS_MODULE,
  415. .cra_init = ablk_init,
  416. .cra_exit = ablk_exit,
  417. .cra_ablkcipher = {
  418. .min_keysize = AES_MIN_KEY_SIZE,
  419. .max_keysize = AES_MAX_KEY_SIZE,
  420. .ivsize = AES_BLOCK_SIZE,
  421. .setkey = ablk_set_key,
  422. .encrypt = ablk_encrypt,
  423. .decrypt = ablk_decrypt,
  424. }
  425. }, {
  426. .cra_name = "ctr(aes)",
  427. .cra_driver_name = "ctr-aes-ce",
  428. .cra_priority = 300,
  429. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
  430. .cra_blocksize = 1,
  431. .cra_ctxsize = sizeof(struct async_helper_ctx),
  432. .cra_alignmask = 7,
  433. .cra_type = &crypto_ablkcipher_type,
  434. .cra_module = THIS_MODULE,
  435. .cra_init = ablk_init,
  436. .cra_exit = ablk_exit,
  437. .cra_ablkcipher = {
  438. .min_keysize = AES_MIN_KEY_SIZE,
  439. .max_keysize = AES_MAX_KEY_SIZE,
  440. .ivsize = AES_BLOCK_SIZE,
  441. .setkey = ablk_set_key,
  442. .encrypt = ablk_encrypt,
  443. .decrypt = ablk_decrypt,
  444. }
  445. }, {
  446. .cra_name = "xts(aes)",
  447. .cra_driver_name = "xts-aes-ce",
  448. .cra_priority = 300,
  449. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
  450. .cra_blocksize = AES_BLOCK_SIZE,
  451. .cra_ctxsize = sizeof(struct async_helper_ctx),
  452. .cra_alignmask = 7,
  453. .cra_type = &crypto_ablkcipher_type,
  454. .cra_module = THIS_MODULE,
  455. .cra_init = ablk_init,
  456. .cra_exit = ablk_exit,
  457. .cra_ablkcipher = {
  458. .min_keysize = 2 * AES_MIN_KEY_SIZE,
  459. .max_keysize = 2 * AES_MAX_KEY_SIZE,
  460. .ivsize = AES_BLOCK_SIZE,
  461. .setkey = ablk_set_key,
  462. .encrypt = ablk_encrypt,
  463. .decrypt = ablk_decrypt,
  464. }
  465. } };
  466. static int __init aes_init(void)
  467. {
  468. if (!(elf_hwcap2 & HWCAP2_AES))
  469. return -ENODEV;
  470. return crypto_register_algs(aes_algs, ARRAY_SIZE(aes_algs));
  471. }
  472. static void __exit aes_exit(void)
  473. {
  474. crypto_unregister_algs(aes_algs, ARRAY_SIZE(aes_algs));
  475. }
  476. module_init(aes_init);
  477. module_exit(aes_exit);