diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2015-06-16 01:54:21 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-06-17 03:35:07 -0400 |
commit | 201f28f055917300c3301b19d0e0e674b9cf8cb7 (patch) | |
tree | 40239555d2d3bd173a28568fd1ae3f21f8d25c53 /drivers/crypto | |
parent | 0af8fbca8c7149c6c637291ed167badbb011b544 (diff) |
crypto: nx - Convert GCM to new AEAD interface
This patch converts the nx GCM implementations to the new AEAD
interface. This is compile-tested only.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r-- | drivers/crypto/nx/nx-aes-gcm.c | 107 | ||||
-rw-r--r-- | drivers/crypto/nx/nx.c | 26 | ||||
-rw-r--r-- | drivers/crypto/nx/nx.h | 7 |
3 files changed, 67 insertions, 73 deletions
diff --git a/drivers/crypto/nx/nx-aes-gcm.c b/drivers/crypto/nx/nx-aes-gcm.c index e4e64f688158..08ac6d48688c 100644 --- a/drivers/crypto/nx/nx-aes-gcm.c +++ b/drivers/crypto/nx/nx-aes-gcm.c | |||
@@ -93,14 +93,6 @@ out: | |||
93 | return rc; | 93 | return rc; |
94 | } | 94 | } |
95 | 95 | ||
96 | static int gcm_aes_nx_setauthsize(struct crypto_aead *tfm, | ||
97 | unsigned int authsize) | ||
98 | { | ||
99 | crypto_aead_crt(tfm)->authsize = authsize; | ||
100 | |||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static int gcm4106_aes_nx_setauthsize(struct crypto_aead *tfm, | 96 | static int gcm4106_aes_nx_setauthsize(struct crypto_aead *tfm, |
105 | unsigned int authsize) | 97 | unsigned int authsize) |
106 | { | 98 | { |
@@ -113,8 +105,6 @@ static int gcm4106_aes_nx_setauthsize(struct crypto_aead *tfm, | |||
113 | return -EINVAL; | 105 | return -EINVAL; |
114 | } | 106 | } |
115 | 107 | ||
116 | crypto_aead_crt(tfm)->authsize = authsize; | ||
117 | |||
118 | return 0; | 108 | return 0; |
119 | } | 109 | } |
120 | 110 | ||
@@ -131,7 +121,7 @@ static int nx_gca(struct nx_crypto_ctx *nx_ctx, | |||
131 | unsigned int max_sg_len; | 121 | unsigned int max_sg_len; |
132 | 122 | ||
133 | if (nbytes <= AES_BLOCK_SIZE) { | 123 | if (nbytes <= AES_BLOCK_SIZE) { |
134 | scatterwalk_start(&walk, req->assoc); | 124 | scatterwalk_start(&walk, req->src); |
135 | scatterwalk_copychunks(out, &walk, nbytes, SCATTERWALK_FROM_SG); | 125 | scatterwalk_copychunks(out, &walk, nbytes, SCATTERWALK_FROM_SG); |
136 | scatterwalk_done(&walk, SCATTERWALK_FROM_SG, 0); | 126 | scatterwalk_done(&walk, SCATTERWALK_FROM_SG, 0); |
137 | return 0; | 127 | return 0; |
@@ -156,7 +146,7 @@ static int nx_gca(struct nx_crypto_ctx *nx_ctx, | |||
156 | NX_PAGE_SIZE * (max_sg_len - 1)); | 146 | NX_PAGE_SIZE * (max_sg_len - 1)); |
157 | 147 | ||
158 | nx_sg = nx_walk_and_build(nx_ctx->in_sg, max_sg_len, | 148 | nx_sg = nx_walk_and_build(nx_ctx->in_sg, max_sg_len, |
159 | req->assoc, processed, &to_process); | 149 | req->src, processed, &to_process); |
160 | 150 | ||
161 | if ((to_process + processed) < nbytes) | 151 | if ((to_process + processed) < nbytes) |
162 | NX_CPB_FDM(csbcpb_aead) |= NX_FDM_INTERMEDIATE; | 152 | NX_CPB_FDM(csbcpb_aead) |= NX_FDM_INTERMEDIATE; |
@@ -222,7 +212,7 @@ static int gmac(struct aead_request *req, struct blkcipher_desc *desc) | |||
222 | NX_PAGE_SIZE * (max_sg_len - 1)); | 212 | NX_PAGE_SIZE * (max_sg_len - 1)); |
223 | 213 | ||
224 | nx_sg = nx_walk_and_build(nx_ctx->in_sg, max_sg_len, | 214 | nx_sg = nx_walk_and_build(nx_ctx->in_sg, max_sg_len, |
225 | req->assoc, processed, &to_process); | 215 | req->src, processed, &to_process); |
226 | 216 | ||
227 | if ((to_process + processed) < nbytes) | 217 | if ((to_process + processed) < nbytes) |
228 | NX_CPB_FDM(csbcpb) |= NX_FDM_INTERMEDIATE; | 218 | NX_CPB_FDM(csbcpb) |= NX_FDM_INTERMEDIATE; |
@@ -374,7 +364,8 @@ static int gcm_aes_nx_crypt(struct aead_request *req, int enc) | |||
374 | csbcpb->cpb.aes_gcm.bit_length_data = nbytes * 8; | 364 | csbcpb->cpb.aes_gcm.bit_length_data = nbytes * 8; |
375 | desc.tfm = (struct crypto_blkcipher *) req->base.tfm; | 365 | desc.tfm = (struct crypto_blkcipher *) req->base.tfm; |
376 | rc = nx_build_sg_lists(nx_ctx, &desc, req->dst, | 366 | rc = nx_build_sg_lists(nx_ctx, &desc, req->dst, |
377 | req->src, &to_process, processed, | 367 | req->src, &to_process, |
368 | processed + req->assoclen, | ||
378 | csbcpb->cpb.aes_gcm.iv_or_cnt); | 369 | csbcpb->cpb.aes_gcm.iv_or_cnt); |
379 | 370 | ||
380 | if (rc) | 371 | if (rc) |
@@ -409,17 +400,19 @@ static int gcm_aes_nx_crypt(struct aead_request *req, int enc) | |||
409 | mac: | 400 | mac: |
410 | if (enc) { | 401 | if (enc) { |
411 | /* copy out the auth tag */ | 402 | /* copy out the auth tag */ |
412 | scatterwalk_map_and_copy(csbcpb->cpb.aes_gcm.out_pat_or_mac, | 403 | scatterwalk_map_and_copy( |
413 | req->dst, nbytes, | 404 | csbcpb->cpb.aes_gcm.out_pat_or_mac, |
414 | crypto_aead_authsize(crypto_aead_reqtfm(req)), | 405 | req->dst, req->assoclen + nbytes, |
415 | SCATTERWALK_TO_SG); | 406 | crypto_aead_authsize(crypto_aead_reqtfm(req)), |
407 | SCATTERWALK_TO_SG); | ||
416 | } else { | 408 | } else { |
417 | u8 *itag = nx_ctx->priv.gcm.iauth_tag; | 409 | u8 *itag = nx_ctx->priv.gcm.iauth_tag; |
418 | u8 *otag = csbcpb->cpb.aes_gcm.out_pat_or_mac; | 410 | u8 *otag = csbcpb->cpb.aes_gcm.out_pat_or_mac; |
419 | 411 | ||
420 | scatterwalk_map_and_copy(itag, req->src, nbytes, | 412 | scatterwalk_map_and_copy( |
421 | crypto_aead_authsize(crypto_aead_reqtfm(req)), | 413 | itag, req->src, req->assoclen + nbytes, |
422 | SCATTERWALK_FROM_SG); | 414 | crypto_aead_authsize(crypto_aead_reqtfm(req)), |
415 | SCATTERWALK_FROM_SG); | ||
423 | rc = memcmp(itag, otag, | 416 | rc = memcmp(itag, otag, |
424 | crypto_aead_authsize(crypto_aead_reqtfm(req))) ? | 417 | crypto_aead_authsize(crypto_aead_reqtfm(req))) ? |
425 | -EBADMSG : 0; | 418 | -EBADMSG : 0; |
@@ -478,45 +471,39 @@ static int gcm4106_aes_nx_decrypt(struct aead_request *req) | |||
478 | * during encrypt/decrypt doesn't solve this problem, because it calls | 471 | * during encrypt/decrypt doesn't solve this problem, because it calls |
479 | * blkcipher_walk_done under the covers, which doesn't use walk->blocksize, | 472 | * blkcipher_walk_done under the covers, which doesn't use walk->blocksize, |
480 | * but instead uses this tfm->blocksize. */ | 473 | * but instead uses this tfm->blocksize. */ |
481 | struct crypto_alg nx_gcm_aes_alg = { | 474 | struct aead_alg nx_gcm_aes_alg = { |
482 | .cra_name = "gcm(aes)", | 475 | .base = { |
483 | .cra_driver_name = "gcm-aes-nx", | 476 | .cra_name = "gcm(aes)", |
484 | .cra_priority = 300, | 477 | .cra_driver_name = "gcm-aes-nx", |
485 | .cra_flags = CRYPTO_ALG_TYPE_AEAD, | 478 | .cra_priority = 300, |
486 | .cra_blocksize = 1, | 479 | .cra_blocksize = 1, |
487 | .cra_ctxsize = sizeof(struct nx_crypto_ctx), | 480 | .cra_ctxsize = sizeof(struct nx_crypto_ctx), |
488 | .cra_type = &crypto_aead_type, | 481 | .cra_module = THIS_MODULE, |
489 | .cra_module = THIS_MODULE, | 482 | }, |
490 | .cra_init = nx_crypto_ctx_aes_gcm_init, | 483 | .init = nx_crypto_ctx_aes_gcm_init, |
491 | .cra_exit = nx_crypto_ctx_exit, | 484 | .exit = nx_crypto_ctx_aead_exit, |
492 | .cra_aead = { | 485 | .ivsize = 12, |
493 | .ivsize = AES_BLOCK_SIZE, | 486 | .maxauthsize = AES_BLOCK_SIZE, |
494 | .maxauthsize = AES_BLOCK_SIZE, | 487 | .setkey = gcm_aes_nx_set_key, |
495 | .setkey = gcm_aes_nx_set_key, | 488 | .encrypt = gcm_aes_nx_encrypt, |
496 | .setauthsize = gcm_aes_nx_setauthsize, | 489 | .decrypt = gcm_aes_nx_decrypt, |
497 | .encrypt = gcm_aes_nx_encrypt, | ||
498 | .decrypt = gcm_aes_nx_decrypt, | ||
499 | } | ||
500 | }; | 490 | }; |
501 | 491 | ||
502 | struct crypto_alg nx_gcm4106_aes_alg = { | 492 | struct aead_alg nx_gcm4106_aes_alg = { |
503 | .cra_name = "rfc4106(gcm(aes))", | 493 | .base = { |
504 | .cra_driver_name = "rfc4106-gcm-aes-nx", | 494 | .cra_name = "rfc4106(gcm(aes))", |
505 | .cra_priority = 300, | 495 | .cra_driver_name = "rfc4106-gcm-aes-nx", |
506 | .cra_flags = CRYPTO_ALG_TYPE_AEAD, | 496 | .cra_priority = 300, |
507 | .cra_blocksize = 1, | 497 | .cra_blocksize = 1, |
508 | .cra_ctxsize = sizeof(struct nx_crypto_ctx), | 498 | .cra_ctxsize = sizeof(struct nx_crypto_ctx), |
509 | .cra_type = &crypto_nivaead_type, | 499 | .cra_module = THIS_MODULE, |
510 | .cra_module = THIS_MODULE, | 500 | }, |
511 | .cra_init = nx_crypto_ctx_aes_gcm_init, | 501 | .init = nx_crypto_ctx_aes_gcm_init, |
512 | .cra_exit = nx_crypto_ctx_exit, | 502 | .exit = nx_crypto_ctx_aead_exit, |
513 | .cra_aead = { | 503 | .ivsize = 8, |
514 | .ivsize = 8, | 504 | .maxauthsize = AES_BLOCK_SIZE, |
515 | .maxauthsize = AES_BLOCK_SIZE, | 505 | .setkey = gcm4106_aes_nx_set_key, |
516 | .geniv = "seqiv", | 506 | .setauthsize = gcm4106_aes_nx_setauthsize, |
517 | .setkey = gcm4106_aes_nx_set_key, | 507 | .encrypt = gcm4106_aes_nx_encrypt, |
518 | .setauthsize = gcm4106_aes_nx_setauthsize, | 508 | .decrypt = gcm4106_aes_nx_decrypt, |
519 | .encrypt = gcm4106_aes_nx_encrypt, | ||
520 | .decrypt = gcm4106_aes_nx_decrypt, | ||
521 | } | ||
522 | }; | 509 | }; |
diff --git a/drivers/crypto/nx/nx.c b/drivers/crypto/nx/nx.c index 2e2529ce8d31..847350534cc1 100644 --- a/drivers/crypto/nx/nx.c +++ b/drivers/crypto/nx/nx.c | |||
@@ -19,8 +19,8 @@ | |||
19 | * Author: Kent Yoder <yoder1@us.ibm.com> | 19 | * Author: Kent Yoder <yoder1@us.ibm.com> |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <crypto/internal/aead.h> | ||
22 | #include <crypto/internal/hash.h> | 23 | #include <crypto/internal/hash.h> |
23 | #include <crypto/hash.h> | ||
24 | #include <crypto/aes.h> | 24 | #include <crypto/aes.h> |
25 | #include <crypto/sha.h> | 25 | #include <crypto/sha.h> |
26 | #include <crypto/algapi.h> | 26 | #include <crypto/algapi.h> |
@@ -29,7 +29,6 @@ | |||
29 | #include <linux/moduleparam.h> | 29 | #include <linux/moduleparam.h> |
30 | #include <linux/types.h> | 30 | #include <linux/types.h> |
31 | #include <linux/mm.h> | 31 | #include <linux/mm.h> |
32 | #include <linux/crypto.h> | ||
33 | #include <linux/scatterlist.h> | 32 | #include <linux/scatterlist.h> |
34 | #include <linux/device.h> | 33 | #include <linux/device.h> |
35 | #include <linux/of.h> | 34 | #include <linux/of.h> |
@@ -531,11 +530,11 @@ static int nx_register_algs(void) | |||
531 | if (rc) | 530 | if (rc) |
532 | goto out_unreg_ctr; | 531 | goto out_unreg_ctr; |
533 | 532 | ||
534 | rc = crypto_register_alg(&nx_gcm_aes_alg); | 533 | rc = crypto_register_aead(&nx_gcm_aes_alg); |
535 | if (rc) | 534 | if (rc) |
536 | goto out_unreg_ctr3686; | 535 | goto out_unreg_ctr3686; |
537 | 536 | ||
538 | rc = crypto_register_alg(&nx_gcm4106_aes_alg); | 537 | rc = crypto_register_aead(&nx_gcm4106_aes_alg); |
539 | if (rc) | 538 | if (rc) |
540 | goto out_unreg_gcm; | 539 | goto out_unreg_gcm; |
541 | 540 | ||
@@ -570,9 +569,9 @@ out_unreg_ccm4309: | |||
570 | out_unreg_ccm: | 569 | out_unreg_ccm: |
571 | crypto_unregister_alg(&nx_ccm_aes_alg); | 570 | crypto_unregister_alg(&nx_ccm_aes_alg); |
572 | out_unreg_gcm4106: | 571 | out_unreg_gcm4106: |
573 | crypto_unregister_alg(&nx_gcm4106_aes_alg); | 572 | crypto_unregister_aead(&nx_gcm4106_aes_alg); |
574 | out_unreg_gcm: | 573 | out_unreg_gcm: |
575 | crypto_unregister_alg(&nx_gcm_aes_alg); | 574 | crypto_unregister_aead(&nx_gcm_aes_alg); |
576 | out_unreg_ctr3686: | 575 | out_unreg_ctr3686: |
577 | crypto_unregister_alg(&nx_ctr3686_aes_alg); | 576 | crypto_unregister_alg(&nx_ctr3686_aes_alg); |
578 | out_unreg_ctr: | 577 | out_unreg_ctr: |
@@ -639,9 +638,9 @@ int nx_crypto_ctx_aes_ccm_init(struct crypto_tfm *tfm) | |||
639 | NX_MODE_AES_CCM); | 638 | NX_MODE_AES_CCM); |
640 | } | 639 | } |
641 | 640 | ||
642 | int nx_crypto_ctx_aes_gcm_init(struct crypto_tfm *tfm) | 641 | int nx_crypto_ctx_aes_gcm_init(struct crypto_aead *tfm) |
643 | { | 642 | { |
644 | return nx_crypto_ctx_init(crypto_tfm_ctx(tfm), NX_FC_AES, | 643 | return nx_crypto_ctx_init(crypto_aead_ctx(tfm), NX_FC_AES, |
645 | NX_MODE_AES_GCM); | 644 | NX_MODE_AES_GCM); |
646 | } | 645 | } |
647 | 646 | ||
@@ -693,6 +692,13 @@ void nx_crypto_ctx_exit(struct crypto_tfm *tfm) | |||
693 | nx_ctx->out_sg = NULL; | 692 | nx_ctx->out_sg = NULL; |
694 | } | 693 | } |
695 | 694 | ||
695 | void nx_crypto_ctx_aead_exit(struct crypto_aead *tfm) | ||
696 | { | ||
697 | struct nx_crypto_ctx *nx_ctx = crypto_aead_ctx(tfm); | ||
698 | |||
699 | kzfree(nx_ctx->kmem); | ||
700 | } | ||
701 | |||
696 | static int nx_probe(struct vio_dev *viodev, const struct vio_device_id *id) | 702 | static int nx_probe(struct vio_dev *viodev, const struct vio_device_id *id) |
697 | { | 703 | { |
698 | dev_dbg(&viodev->dev, "driver probed: %s resource id: 0x%x\n", | 704 | dev_dbg(&viodev->dev, "driver probed: %s resource id: 0x%x\n", |
@@ -721,8 +727,8 @@ static int nx_remove(struct vio_dev *viodev) | |||
721 | 727 | ||
722 | crypto_unregister_alg(&nx_ccm_aes_alg); | 728 | crypto_unregister_alg(&nx_ccm_aes_alg); |
723 | crypto_unregister_alg(&nx_ccm4309_aes_alg); | 729 | crypto_unregister_alg(&nx_ccm4309_aes_alg); |
724 | crypto_unregister_alg(&nx_gcm_aes_alg); | 730 | crypto_unregister_aead(&nx_gcm_aes_alg); |
725 | crypto_unregister_alg(&nx_gcm4106_aes_alg); | 731 | crypto_unregister_aead(&nx_gcm4106_aes_alg); |
726 | crypto_unregister_alg(&nx_ctr_aes_alg); | 732 | crypto_unregister_alg(&nx_ctr_aes_alg); |
727 | crypto_unregister_alg(&nx_ctr3686_aes_alg); | 733 | crypto_unregister_alg(&nx_ctr3686_aes_alg); |
728 | crypto_unregister_alg(&nx_cbc_aes_alg); | 734 | crypto_unregister_alg(&nx_cbc_aes_alg); |
diff --git a/drivers/crypto/nx/nx.h b/drivers/crypto/nx/nx.h index 41b87ee03fe2..de3ea8738146 100644 --- a/drivers/crypto/nx/nx.h +++ b/drivers/crypto/nx/nx.h | |||
@@ -143,13 +143,14 @@ struct nx_crypto_ctx { | |||
143 | 143 | ||
144 | /* prototypes */ | 144 | /* prototypes */ |
145 | int nx_crypto_ctx_aes_ccm_init(struct crypto_tfm *tfm); | 145 | int nx_crypto_ctx_aes_ccm_init(struct crypto_tfm *tfm); |
146 | int nx_crypto_ctx_aes_gcm_init(struct crypto_tfm *tfm); | 146 | int nx_crypto_ctx_aes_gcm_init(struct crypto_aead *tfm); |
147 | int nx_crypto_ctx_aes_xcbc_init(struct crypto_tfm *tfm); | 147 | int nx_crypto_ctx_aes_xcbc_init(struct crypto_tfm *tfm); |
148 | int nx_crypto_ctx_aes_ctr_init(struct crypto_tfm *tfm); | 148 | int nx_crypto_ctx_aes_ctr_init(struct crypto_tfm *tfm); |
149 | int nx_crypto_ctx_aes_cbc_init(struct crypto_tfm *tfm); | 149 | int nx_crypto_ctx_aes_cbc_init(struct crypto_tfm *tfm); |
150 | int nx_crypto_ctx_aes_ecb_init(struct crypto_tfm *tfm); | 150 | int nx_crypto_ctx_aes_ecb_init(struct crypto_tfm *tfm); |
151 | int nx_crypto_ctx_sha_init(struct crypto_tfm *tfm); | 151 | int nx_crypto_ctx_sha_init(struct crypto_tfm *tfm); |
152 | void nx_crypto_ctx_exit(struct crypto_tfm *tfm); | 152 | void nx_crypto_ctx_exit(struct crypto_tfm *tfm); |
153 | void nx_crypto_ctx_aead_exit(struct crypto_aead *tfm); | ||
153 | void nx_ctx_init(struct nx_crypto_ctx *nx_ctx, unsigned int function); | 154 | void nx_ctx_init(struct nx_crypto_ctx *nx_ctx, unsigned int function); |
154 | int nx_hcall_sync(struct nx_crypto_ctx *ctx, struct vio_pfo_op *op, | 155 | int nx_hcall_sync(struct nx_crypto_ctx *ctx, struct vio_pfo_op *op, |
155 | u32 may_sleep); | 156 | u32 may_sleep); |
@@ -176,8 +177,8 @@ void nx_debugfs_fini(struct nx_crypto_driver *); | |||
176 | 177 | ||
177 | extern struct crypto_alg nx_cbc_aes_alg; | 178 | extern struct crypto_alg nx_cbc_aes_alg; |
178 | extern struct crypto_alg nx_ecb_aes_alg; | 179 | extern struct crypto_alg nx_ecb_aes_alg; |
179 | extern struct crypto_alg nx_gcm_aes_alg; | 180 | extern struct aead_alg nx_gcm_aes_alg; |
180 | extern struct crypto_alg nx_gcm4106_aes_alg; | 181 | extern struct aead_alg nx_gcm4106_aes_alg; |
181 | extern struct crypto_alg nx_ctr_aes_alg; | 182 | extern struct crypto_alg nx_ctr_aes_alg; |
182 | extern struct crypto_alg nx_ctr3686_aes_alg; | 183 | extern struct crypto_alg nx_ctr3686_aes_alg; |
183 | extern struct crypto_alg nx_ccm_aes_alg; | 184 | extern struct crypto_alg nx_ccm_aes_alg; |