nx-aes-ccm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /**
  2. * AES CCM routines supporting the Power 7+ Nest Accelerators driver
  3. *
  4. * Copyright (C) 2012 International Business Machines Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 only.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *
  19. * Author: Kent Yoder <yoder1@us.ibm.com>
  20. */
  21. #include <crypto/internal/aead.h>
  22. #include <crypto/aes.h>
  23. #include <crypto/algapi.h>
  24. #include <crypto/scatterwalk.h>
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <linux/crypto.h>
  28. #include <asm/vio.h>
  29. #include "nx_csbcpb.h"
  30. #include "nx.h"
  31. static int ccm_aes_nx_set_key(struct crypto_aead *tfm,
  32. const u8 *in_key,
  33. unsigned int key_len)
  34. {
  35. struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&tfm->base);
  36. struct nx_csbcpb *csbcpb = nx_ctx->csbcpb;
  37. struct nx_csbcpb *csbcpb_aead = nx_ctx->csbcpb_aead;
  38. nx_ctx_init(nx_ctx, HCOP_FC_AES);
  39. switch (key_len) {
  40. case AES_KEYSIZE_128:
  41. NX_CPB_SET_KEY_SIZE(csbcpb, NX_KS_AES_128);
  42. NX_CPB_SET_KEY_SIZE(csbcpb_aead, NX_KS_AES_128);
  43. nx_ctx->ap = &nx_ctx->props[NX_PROPS_AES_128];
  44. break;
  45. default:
  46. return -EINVAL;
  47. }
  48. csbcpb->cpb.hdr.mode = NX_MODE_AES_CCM;
  49. memcpy(csbcpb->cpb.aes_ccm.key, in_key, key_len);
  50. csbcpb_aead->cpb.hdr.mode = NX_MODE_AES_CCA;
  51. memcpy(csbcpb_aead->cpb.aes_cca.key, in_key, key_len);
  52. return 0;
  53. }
  54. static int ccm4309_aes_nx_set_key(struct crypto_aead *tfm,
  55. const u8 *in_key,
  56. unsigned int key_len)
  57. {
  58. struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&tfm->base);
  59. if (key_len < 3)
  60. return -EINVAL;
  61. key_len -= 3;
  62. memcpy(nx_ctx->priv.ccm.nonce, in_key + key_len, 3);
  63. return ccm_aes_nx_set_key(tfm, in_key, key_len);
  64. }
  65. static int ccm_aes_nx_setauthsize(struct crypto_aead *tfm,
  66. unsigned int authsize)
  67. {
  68. switch (authsize) {
  69. case 4:
  70. case 6:
  71. case 8:
  72. case 10:
  73. case 12:
  74. case 14:
  75. case 16:
  76. break;
  77. default:
  78. return -EINVAL;
  79. }
  80. crypto_aead_crt(tfm)->authsize = authsize;
  81. return 0;
  82. }
  83. static int ccm4309_aes_nx_setauthsize(struct crypto_aead *tfm,
  84. unsigned int authsize)
  85. {
  86. switch (authsize) {
  87. case 8:
  88. case 12:
  89. case 16:
  90. break;
  91. default:
  92. return -EINVAL;
  93. }
  94. crypto_aead_crt(tfm)->authsize = authsize;
  95. return 0;
  96. }
  97. /* taken from crypto/ccm.c */
  98. static int set_msg_len(u8 *block, unsigned int msglen, int csize)
  99. {
  100. __be32 data;
  101. memset(block, 0, csize);
  102. block += csize;
  103. if (csize >= 4)
  104. csize = 4;
  105. else if (msglen > (unsigned int)(1 << (8 * csize)))
  106. return -EOVERFLOW;
  107. data = cpu_to_be32(msglen);
  108. memcpy(block - csize, (u8 *)&data + 4 - csize, csize);
  109. return 0;
  110. }
  111. /* taken from crypto/ccm.c */
  112. static inline int crypto_ccm_check_iv(const u8 *iv)
  113. {
  114. /* 2 <= L <= 8, so 1 <= L' <= 7. */
  115. if (1 > iv[0] || iv[0] > 7)
  116. return -EINVAL;
  117. return 0;
  118. }
  119. /* based on code from crypto/ccm.c */
  120. static int generate_b0(u8 *iv, unsigned int assoclen, unsigned int authsize,
  121. unsigned int cryptlen, u8 *b0)
  122. {
  123. unsigned int l, lp, m = authsize;
  124. int rc;
  125. memcpy(b0, iv, 16);
  126. lp = b0[0];
  127. l = lp + 1;
  128. /* set m, bits 3-5 */
  129. *b0 |= (8 * ((m - 2) / 2));
  130. /* set adata, bit 6, if associated data is used */
  131. if (assoclen)
  132. *b0 |= 64;
  133. rc = set_msg_len(b0 + 16 - l, cryptlen, l);
  134. return rc;
  135. }
  136. static int generate_pat(u8 *iv,
  137. struct aead_request *req,
  138. struct nx_crypto_ctx *nx_ctx,
  139. unsigned int authsize,
  140. unsigned int nbytes,
  141. u8 *out)
  142. {
  143. struct nx_sg *nx_insg = nx_ctx->in_sg;
  144. struct nx_sg *nx_outsg = nx_ctx->out_sg;
  145. unsigned int iauth_len = 0;
  146. u8 tmp[16], *b1 = NULL, *b0 = NULL, *result = NULL;
  147. int rc;
  148. unsigned int max_sg_len;
  149. /* zero the ctr value */
  150. memset(iv + 15 - iv[0], 0, iv[0] + 1);
  151. /* page 78 of nx_wb.pdf has,
  152. * Note: RFC3610 allows the AAD data to be up to 2^64 -1 bytes
  153. * in length. If a full message is used, the AES CCA implementation
  154. * restricts the maximum AAD length to 2^32 -1 bytes.
  155. * If partial messages are used, the implementation supports
  156. * 2^64 -1 bytes maximum AAD length.
  157. *
  158. * However, in the cryptoapi's aead_request structure,
  159. * assoclen is an unsigned int, thus it cannot hold a length
  160. * value greater than 2^32 - 1.
  161. * Thus the AAD is further constrained by this and is never
  162. * greater than 2^32.
  163. */
  164. if (!req->assoclen) {
  165. b0 = nx_ctx->csbcpb->cpb.aes_ccm.in_pat_or_b0;
  166. } else if (req->assoclen <= 14) {
  167. /* if associated data is 14 bytes or less, we do 1 GCM
  168. * operation on 2 AES blocks, B0 (stored in the csbcpb) and B1,
  169. * which is fed in through the source buffers here */
  170. b0 = nx_ctx->csbcpb->cpb.aes_ccm.in_pat_or_b0;
  171. b1 = nx_ctx->priv.ccm.iauth_tag;
  172. iauth_len = req->assoclen;
  173. } else if (req->assoclen <= 65280) {
  174. /* if associated data is less than (2^16 - 2^8), we construct
  175. * B1 differently and feed in the associated data to a CCA
  176. * operation */
  177. b0 = nx_ctx->csbcpb_aead->cpb.aes_cca.b0;
  178. b1 = nx_ctx->csbcpb_aead->cpb.aes_cca.b1;
  179. iauth_len = 14;
  180. } else {
  181. b0 = nx_ctx->csbcpb_aead->cpb.aes_cca.b0;
  182. b1 = nx_ctx->csbcpb_aead->cpb.aes_cca.b1;
  183. iauth_len = 10;
  184. }
  185. /* generate B0 */
  186. rc = generate_b0(iv, req->assoclen, authsize, nbytes, b0);
  187. if (rc)
  188. return rc;
  189. /* generate B1:
  190. * add control info for associated data
  191. * RFC 3610 and NIST Special Publication 800-38C
  192. */
  193. if (b1) {
  194. memset(b1, 0, 16);
  195. if (req->assoclen <= 65280) {
  196. *(u16 *)b1 = (u16)req->assoclen;
  197. scatterwalk_map_and_copy(b1 + 2, req->assoc, 0,
  198. iauth_len, SCATTERWALK_FROM_SG);
  199. } else {
  200. *(u16 *)b1 = (u16)(0xfffe);
  201. *(u32 *)&b1[2] = (u32)req->assoclen;
  202. scatterwalk_map_and_copy(b1 + 6, req->assoc, 0,
  203. iauth_len, SCATTERWALK_FROM_SG);
  204. }
  205. }
  206. /* now copy any remaining AAD to scatterlist and call nx... */
  207. if (!req->assoclen) {
  208. return rc;
  209. } else if (req->assoclen <= 14) {
  210. unsigned int len = 16;
  211. nx_insg = nx_build_sg_list(nx_insg, b1, &len, nx_ctx->ap->sglen);
  212. if (len != 16)
  213. return -EINVAL;
  214. nx_outsg = nx_build_sg_list(nx_outsg, tmp, &len,
  215. nx_ctx->ap->sglen);
  216. if (len != 16)
  217. return -EINVAL;
  218. /* inlen should be negative, indicating to phyp that its a
  219. * pointer to an sg list */
  220. nx_ctx->op.inlen = (nx_ctx->in_sg - nx_insg) *
  221. sizeof(struct nx_sg);
  222. nx_ctx->op.outlen = (nx_ctx->out_sg - nx_outsg) *
  223. sizeof(struct nx_sg);
  224. NX_CPB_FDM(nx_ctx->csbcpb) |= NX_FDM_ENDE_ENCRYPT;
  225. NX_CPB_FDM(nx_ctx->csbcpb) |= NX_FDM_INTERMEDIATE;
  226. result = nx_ctx->csbcpb->cpb.aes_ccm.out_pat_or_mac;
  227. rc = nx_hcall_sync(nx_ctx, &nx_ctx->op,
  228. req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP);
  229. if (rc)
  230. return rc;
  231. atomic_inc(&(nx_ctx->stats->aes_ops));
  232. atomic64_add(req->assoclen, &(nx_ctx->stats->aes_bytes));
  233. } else {
  234. unsigned int processed = 0, to_process;
  235. processed += iauth_len;
  236. /* page_limit: number of sg entries that fit on one page */
  237. max_sg_len = min_t(u64, nx_ctx->ap->sglen,
  238. nx_driver.of.max_sg_len/sizeof(struct nx_sg));
  239. max_sg_len = min_t(u64, max_sg_len,
  240. nx_ctx->ap->databytelen/NX_PAGE_SIZE);
  241. do {
  242. to_process = min_t(u32, req->assoclen - processed,
  243. nx_ctx->ap->databytelen);
  244. nx_insg = nx_walk_and_build(nx_ctx->in_sg,
  245. nx_ctx->ap->sglen,
  246. req->assoc, processed,
  247. &to_process);
  248. if ((to_process + processed) < req->assoclen) {
  249. NX_CPB_FDM(nx_ctx->csbcpb_aead) |=
  250. NX_FDM_INTERMEDIATE;
  251. } else {
  252. NX_CPB_FDM(nx_ctx->csbcpb_aead) &=
  253. ~NX_FDM_INTERMEDIATE;
  254. }
  255. nx_ctx->op_aead.inlen = (nx_ctx->in_sg - nx_insg) *
  256. sizeof(struct nx_sg);
  257. result = nx_ctx->csbcpb_aead->cpb.aes_cca.out_pat_or_b0;
  258. rc = nx_hcall_sync(nx_ctx, &nx_ctx->op_aead,
  259. req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP);
  260. if (rc)
  261. return rc;
  262. memcpy(nx_ctx->csbcpb_aead->cpb.aes_cca.b0,
  263. nx_ctx->csbcpb_aead->cpb.aes_cca.out_pat_or_b0,
  264. AES_BLOCK_SIZE);
  265. NX_CPB_FDM(nx_ctx->csbcpb_aead) |= NX_FDM_CONTINUATION;
  266. atomic_inc(&(nx_ctx->stats->aes_ops));
  267. atomic64_add(req->assoclen,
  268. &(nx_ctx->stats->aes_bytes));
  269. processed += to_process;
  270. } while (processed < req->assoclen);
  271. result = nx_ctx->csbcpb_aead->cpb.aes_cca.out_pat_or_b0;
  272. }
  273. memcpy(out, result, AES_BLOCK_SIZE);
  274. return rc;
  275. }
  276. static int ccm_nx_decrypt(struct aead_request *req,
  277. struct blkcipher_desc *desc)
  278. {
  279. struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm);
  280. struct nx_csbcpb *csbcpb = nx_ctx->csbcpb;
  281. unsigned int nbytes = req->cryptlen;
  282. unsigned int authsize = crypto_aead_authsize(crypto_aead_reqtfm(req));
  283. struct nx_ccm_priv *priv = &nx_ctx->priv.ccm;
  284. unsigned long irq_flags;
  285. unsigned int processed = 0, to_process;
  286. int rc = -1;
  287. spin_lock_irqsave(&nx_ctx->lock, irq_flags);
  288. nbytes -= authsize;
  289. /* copy out the auth tag to compare with later */
  290. scatterwalk_map_and_copy(priv->oauth_tag,
  291. req->src, nbytes, authsize,
  292. SCATTERWALK_FROM_SG);
  293. rc = generate_pat(desc->info, req, nx_ctx, authsize, nbytes,
  294. csbcpb->cpb.aes_ccm.in_pat_or_b0);
  295. if (rc)
  296. goto out;
  297. do {
  298. /* to_process: the AES_BLOCK_SIZE data chunk to process in this
  299. * update. This value is bound by sg list limits.
  300. */
  301. to_process = nbytes - processed;
  302. if ((to_process + processed) < nbytes)
  303. NX_CPB_FDM(csbcpb) |= NX_FDM_INTERMEDIATE;
  304. else
  305. NX_CPB_FDM(csbcpb) &= ~NX_FDM_INTERMEDIATE;
  306. NX_CPB_FDM(nx_ctx->csbcpb) &= ~NX_FDM_ENDE_ENCRYPT;
  307. rc = nx_build_sg_lists(nx_ctx, desc, req->dst, req->src,
  308. &to_process, processed,
  309. csbcpb->cpb.aes_ccm.iv_or_ctr);
  310. if (rc)
  311. goto out;
  312. rc = nx_hcall_sync(nx_ctx, &nx_ctx->op,
  313. req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP);
  314. if (rc)
  315. goto out;
  316. /* for partial completion, copy following for next
  317. * entry into loop...
  318. */
  319. memcpy(desc->info, csbcpb->cpb.aes_ccm.out_ctr, AES_BLOCK_SIZE);
  320. memcpy(csbcpb->cpb.aes_ccm.in_pat_or_b0,
  321. csbcpb->cpb.aes_ccm.out_pat_or_mac, AES_BLOCK_SIZE);
  322. memcpy(csbcpb->cpb.aes_ccm.in_s0,
  323. csbcpb->cpb.aes_ccm.out_s0, AES_BLOCK_SIZE);
  324. NX_CPB_FDM(csbcpb) |= NX_FDM_CONTINUATION;
  325. /* update stats */
  326. atomic_inc(&(nx_ctx->stats->aes_ops));
  327. atomic64_add(csbcpb->csb.processed_byte_count,
  328. &(nx_ctx->stats->aes_bytes));
  329. processed += to_process;
  330. } while (processed < nbytes);
  331. rc = memcmp(csbcpb->cpb.aes_ccm.out_pat_or_mac, priv->oauth_tag,
  332. authsize) ? -EBADMSG : 0;
  333. out:
  334. spin_unlock_irqrestore(&nx_ctx->lock, irq_flags);
  335. return rc;
  336. }
  337. static int ccm_nx_encrypt(struct aead_request *req,
  338. struct blkcipher_desc *desc)
  339. {
  340. struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm);
  341. struct nx_csbcpb *csbcpb = nx_ctx->csbcpb;
  342. unsigned int nbytes = req->cryptlen;
  343. unsigned int authsize = crypto_aead_authsize(crypto_aead_reqtfm(req));
  344. unsigned long irq_flags;
  345. unsigned int processed = 0, to_process;
  346. int rc = -1;
  347. spin_lock_irqsave(&nx_ctx->lock, irq_flags);
  348. rc = generate_pat(desc->info, req, nx_ctx, authsize, nbytes,
  349. csbcpb->cpb.aes_ccm.in_pat_or_b0);
  350. if (rc)
  351. goto out;
  352. do {
  353. /* to process: the AES_BLOCK_SIZE data chunk to process in this
  354. * update. This value is bound by sg list limits.
  355. */
  356. to_process = nbytes - processed;
  357. if ((to_process + processed) < nbytes)
  358. NX_CPB_FDM(csbcpb) |= NX_FDM_INTERMEDIATE;
  359. else
  360. NX_CPB_FDM(csbcpb) &= ~NX_FDM_INTERMEDIATE;
  361. NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT;
  362. rc = nx_build_sg_lists(nx_ctx, desc, req->dst, req->src,
  363. &to_process, processed,
  364. csbcpb->cpb.aes_ccm.iv_or_ctr);
  365. if (rc)
  366. goto out;
  367. rc = nx_hcall_sync(nx_ctx, &nx_ctx->op,
  368. req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP);
  369. if (rc)
  370. goto out;
  371. /* for partial completion, copy following for next
  372. * entry into loop...
  373. */
  374. memcpy(desc->info, csbcpb->cpb.aes_ccm.out_ctr, AES_BLOCK_SIZE);
  375. memcpy(csbcpb->cpb.aes_ccm.in_pat_or_b0,
  376. csbcpb->cpb.aes_ccm.out_pat_or_mac, AES_BLOCK_SIZE);
  377. memcpy(csbcpb->cpb.aes_ccm.in_s0,
  378. csbcpb->cpb.aes_ccm.out_s0, AES_BLOCK_SIZE);
  379. NX_CPB_FDM(csbcpb) |= NX_FDM_CONTINUATION;
  380. /* update stats */
  381. atomic_inc(&(nx_ctx->stats->aes_ops));
  382. atomic64_add(csbcpb->csb.processed_byte_count,
  383. &(nx_ctx->stats->aes_bytes));
  384. processed += to_process;
  385. } while (processed < nbytes);
  386. /* copy out the auth tag */
  387. scatterwalk_map_and_copy(csbcpb->cpb.aes_ccm.out_pat_or_mac,
  388. req->dst, nbytes, authsize,
  389. SCATTERWALK_TO_SG);
  390. out:
  391. spin_unlock_irqrestore(&nx_ctx->lock, irq_flags);
  392. return rc;
  393. }
  394. static int ccm4309_aes_nx_encrypt(struct aead_request *req)
  395. {
  396. struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm);
  397. struct blkcipher_desc desc;
  398. u8 *iv = nx_ctx->priv.ccm.iv;
  399. iv[0] = 3;
  400. memcpy(iv + 1, nx_ctx->priv.ccm.nonce, 3);
  401. memcpy(iv + 4, req->iv, 8);
  402. desc.info = iv;
  403. desc.tfm = (struct crypto_blkcipher *)req->base.tfm;
  404. return ccm_nx_encrypt(req, &desc);
  405. }
  406. static int ccm_aes_nx_encrypt(struct aead_request *req)
  407. {
  408. struct blkcipher_desc desc;
  409. int rc;
  410. desc.info = req->iv;
  411. desc.tfm = (struct crypto_blkcipher *)req->base.tfm;
  412. rc = crypto_ccm_check_iv(desc.info);
  413. if (rc)
  414. return rc;
  415. return ccm_nx_encrypt(req, &desc);
  416. }
  417. static int ccm4309_aes_nx_decrypt(struct aead_request *req)
  418. {
  419. struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm);
  420. struct blkcipher_desc desc;
  421. u8 *iv = nx_ctx->priv.ccm.iv;
  422. iv[0] = 3;
  423. memcpy(iv + 1, nx_ctx->priv.ccm.nonce, 3);
  424. memcpy(iv + 4, req->iv, 8);
  425. desc.info = iv;
  426. desc.tfm = (struct crypto_blkcipher *)req->base.tfm;
  427. return ccm_nx_decrypt(req, &desc);
  428. }
  429. static int ccm_aes_nx_decrypt(struct aead_request *req)
  430. {
  431. struct blkcipher_desc desc;
  432. int rc;
  433. desc.info = req->iv;
  434. desc.tfm = (struct crypto_blkcipher *)req->base.tfm;
  435. rc = crypto_ccm_check_iv(desc.info);
  436. if (rc)
  437. return rc;
  438. return ccm_nx_decrypt(req, &desc);
  439. }
  440. /* tell the block cipher walk routines that this is a stream cipher by
  441. * setting cra_blocksize to 1. Even using blkcipher_walk_virt_block
  442. * during encrypt/decrypt doesn't solve this problem, because it calls
  443. * blkcipher_walk_done under the covers, which doesn't use walk->blocksize,
  444. * but instead uses this tfm->blocksize. */
  445. struct crypto_alg nx_ccm_aes_alg = {
  446. .cra_name = "ccm(aes)",
  447. .cra_driver_name = "ccm-aes-nx",
  448. .cra_priority = 300,
  449. .cra_flags = CRYPTO_ALG_TYPE_AEAD |
  450. CRYPTO_ALG_NEED_FALLBACK,
  451. .cra_blocksize = 1,
  452. .cra_ctxsize = sizeof(struct nx_crypto_ctx),
  453. .cra_type = &crypto_aead_type,
  454. .cra_module = THIS_MODULE,
  455. .cra_init = nx_crypto_ctx_aes_ccm_init,
  456. .cra_exit = nx_crypto_ctx_exit,
  457. .cra_aead = {
  458. .ivsize = AES_BLOCK_SIZE,
  459. .maxauthsize = AES_BLOCK_SIZE,
  460. .setkey = ccm_aes_nx_set_key,
  461. .setauthsize = ccm_aes_nx_setauthsize,
  462. .encrypt = ccm_aes_nx_encrypt,
  463. .decrypt = ccm_aes_nx_decrypt,
  464. }
  465. };
  466. struct crypto_alg nx_ccm4309_aes_alg = {
  467. .cra_name = "rfc4309(ccm(aes))",
  468. .cra_driver_name = "rfc4309-ccm-aes-nx",
  469. .cra_priority = 300,
  470. .cra_flags = CRYPTO_ALG_TYPE_AEAD |
  471. CRYPTO_ALG_NEED_FALLBACK,
  472. .cra_blocksize = 1,
  473. .cra_ctxsize = sizeof(struct nx_crypto_ctx),
  474. .cra_type = &crypto_nivaead_type,
  475. .cra_module = THIS_MODULE,
  476. .cra_init = nx_crypto_ctx_aes_ccm_init,
  477. .cra_exit = nx_crypto_ctx_exit,
  478. .cra_aead = {
  479. .ivsize = 8,
  480. .maxauthsize = AES_BLOCK_SIZE,
  481. .setkey = ccm4309_aes_nx_set_key,
  482. .setauthsize = ccm4309_aes_nx_setauthsize,
  483. .encrypt = ccm4309_aes_nx_encrypt,
  484. .decrypt = ccm4309_aes_nx_decrypt,
  485. .geniv = "seqiv",
  486. }
  487. };