summaryrefslogtreecommitdiffstats
path: root/crypto/algif_skcipher.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-12-18 06:16:57 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2015-12-22 07:40:01 -0500
commit0d96e4bab2855a030077cc695a3563fd7cb0e7d8 (patch)
treed08a3336f3eb851d27f93fe11eb3dfd6cf65b32d /crypto/algif_skcipher.c
parent70d906bc17500edfa9bdd8c8b7e59618c7911613 (diff)
crypto: algif_skcipher - Use new skcipher interface
This patch replaces uses of ablkcipher with the new skcipher interface. Cc: stable@vger.kernel.org Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Tested-by: <smueller@chronox.de>
Diffstat (limited to 'crypto/algif_skcipher.c')
-rw-r--r--crypto/algif_skcipher.c61
1 files changed, 30 insertions, 31 deletions
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index af31a0ee4057..973fe45e0515 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -47,7 +47,7 @@ struct skcipher_ctx {
47 bool merge; 47 bool merge;
48 bool enc; 48 bool enc;
49 49
50 struct ablkcipher_request req; 50 struct skcipher_request req;
51}; 51};
52 52
53struct skcipher_async_rsgl { 53struct skcipher_async_rsgl {
@@ -64,13 +64,13 @@ struct skcipher_async_req {
64}; 64};
65 65
66#define GET_SREQ(areq, ctx) (struct skcipher_async_req *)((char *)areq + \ 66#define GET_SREQ(areq, ctx) (struct skcipher_async_req *)((char *)areq + \
67 crypto_ablkcipher_reqsize(crypto_ablkcipher_reqtfm(&ctx->req))) 67 crypto_skcipher_reqsize(crypto_skcipher_reqtfm(&ctx->req)))
68 68
69#define GET_REQ_SIZE(ctx) \ 69#define GET_REQ_SIZE(ctx) \
70 crypto_ablkcipher_reqsize(crypto_ablkcipher_reqtfm(&ctx->req)) 70 crypto_skcipher_reqsize(crypto_skcipher_reqtfm(&ctx->req))
71 71
72#define GET_IV_SIZE(ctx) \ 72#define GET_IV_SIZE(ctx) \
73 crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(&ctx->req)) 73 crypto_skcipher_ivsize(crypto_skcipher_reqtfm(&ctx->req))
74 74
75#define MAX_SGL_ENTS ((4096 - sizeof(struct skcipher_sg_list)) / \ 75#define MAX_SGL_ENTS ((4096 - sizeof(struct skcipher_sg_list)) / \
76 sizeof(struct scatterlist) - 1) 76 sizeof(struct scatterlist) - 1)
@@ -302,8 +302,8 @@ static int skcipher_sendmsg(struct socket *sock, struct msghdr *msg,
302 struct sock *sk = sock->sk; 302 struct sock *sk = sock->sk;
303 struct alg_sock *ask = alg_sk(sk); 303 struct alg_sock *ask = alg_sk(sk);
304 struct skcipher_ctx *ctx = ask->private; 304 struct skcipher_ctx *ctx = ask->private;
305 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(&ctx->req); 305 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(&ctx->req);
306 unsigned ivsize = crypto_ablkcipher_ivsize(tfm); 306 unsigned ivsize = crypto_skcipher_ivsize(tfm);
307 struct skcipher_sg_list *sgl; 307 struct skcipher_sg_list *sgl;
308 struct af_alg_control con = {}; 308 struct af_alg_control con = {};
309 long copied = 0; 309 long copied = 0;
@@ -507,7 +507,7 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
507 struct skcipher_sg_list *sgl; 507 struct skcipher_sg_list *sgl;
508 struct scatterlist *sg; 508 struct scatterlist *sg;
509 struct skcipher_async_req *sreq; 509 struct skcipher_async_req *sreq;
510 struct ablkcipher_request *req; 510 struct skcipher_request *req;
511 struct skcipher_async_rsgl *last_rsgl = NULL; 511 struct skcipher_async_rsgl *last_rsgl = NULL;
512 unsigned int txbufs = 0, len = 0, tx_nents = skcipher_all_sg_nents(ctx); 512 unsigned int txbufs = 0, len = 0, tx_nents = skcipher_all_sg_nents(ctx);
513 unsigned int reqlen = sizeof(struct skcipher_async_req) + 513 unsigned int reqlen = sizeof(struct skcipher_async_req) +
@@ -531,9 +531,9 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
531 } 531 }
532 sg_init_table(sreq->tsg, tx_nents); 532 sg_init_table(sreq->tsg, tx_nents);
533 memcpy(sreq->iv, ctx->iv, GET_IV_SIZE(ctx)); 533 memcpy(sreq->iv, ctx->iv, GET_IV_SIZE(ctx));
534 ablkcipher_request_set_tfm(req, crypto_ablkcipher_reqtfm(&ctx->req)); 534 skcipher_request_set_tfm(req, crypto_skcipher_reqtfm(&ctx->req));
535 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 535 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
536 skcipher_async_cb, sk); 536 skcipher_async_cb, sk);
537 537
538 while (iov_iter_count(&msg->msg_iter)) { 538 while (iov_iter_count(&msg->msg_iter)) {
539 struct skcipher_async_rsgl *rsgl; 539 struct skcipher_async_rsgl *rsgl;
@@ -608,10 +608,10 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
608 if (mark) 608 if (mark)
609 sg_mark_end(sreq->tsg + txbufs - 1); 609 sg_mark_end(sreq->tsg + txbufs - 1);
610 610
611 ablkcipher_request_set_crypt(req, sreq->tsg, sreq->first_sgl.sgl.sg, 611 skcipher_request_set_crypt(req, sreq->tsg, sreq->first_sgl.sgl.sg,
612 len, sreq->iv); 612 len, sreq->iv);
613 err = ctx->enc ? crypto_ablkcipher_encrypt(req) : 613 err = ctx->enc ? crypto_skcipher_encrypt(req) :
614 crypto_ablkcipher_decrypt(req); 614 crypto_skcipher_decrypt(req);
615 if (err == -EINPROGRESS) { 615 if (err == -EINPROGRESS) {
616 atomic_inc(&ctx->inflight); 616 atomic_inc(&ctx->inflight);
617 err = -EIOCBQUEUED; 617 err = -EIOCBQUEUED;
@@ -632,7 +632,7 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg,
632 struct sock *sk = sock->sk; 632 struct sock *sk = sock->sk;
633 struct alg_sock *ask = alg_sk(sk); 633 struct alg_sock *ask = alg_sk(sk);
634 struct skcipher_ctx *ctx = ask->private; 634 struct skcipher_ctx *ctx = ask->private;
635 unsigned bs = crypto_ablkcipher_blocksize(crypto_ablkcipher_reqtfm( 635 unsigned bs = crypto_skcipher_blocksize(crypto_skcipher_reqtfm(
636 &ctx->req)); 636 &ctx->req));
637 struct skcipher_sg_list *sgl; 637 struct skcipher_sg_list *sgl;
638 struct scatterlist *sg; 638 struct scatterlist *sg;
@@ -669,14 +669,13 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg,
669 if (!used) 669 if (!used)
670 goto free; 670 goto free;
671 671
672 ablkcipher_request_set_crypt(&ctx->req, sg, 672 skcipher_request_set_crypt(&ctx->req, sg, ctx->rsgl.sg, used,
673 ctx->rsgl.sg, used, 673 ctx->iv);
674 ctx->iv);
675 674
676 err = af_alg_wait_for_completion( 675 err = af_alg_wait_for_completion(
677 ctx->enc ? 676 ctx->enc ?
678 crypto_ablkcipher_encrypt(&ctx->req) : 677 crypto_skcipher_encrypt(&ctx->req) :
679 crypto_ablkcipher_decrypt(&ctx->req), 678 crypto_skcipher_decrypt(&ctx->req),
680 &ctx->completion); 679 &ctx->completion);
681 680
682free: 681free:
@@ -751,17 +750,17 @@ static struct proto_ops algif_skcipher_ops = {
751 750
752static void *skcipher_bind(const char *name, u32 type, u32 mask) 751static void *skcipher_bind(const char *name, u32 type, u32 mask)
753{ 752{
754 return crypto_alloc_ablkcipher(name, type, mask); 753 return crypto_alloc_skcipher(name, type, mask);
755} 754}
756 755
757static void skcipher_release(void *private) 756static void skcipher_release(void *private)
758{ 757{
759 crypto_free_ablkcipher(private); 758 crypto_free_skcipher(private);
760} 759}
761 760
762static int skcipher_setkey(void *private, const u8 *key, unsigned int keylen) 761static int skcipher_setkey(void *private, const u8 *key, unsigned int keylen)
763{ 762{
764 return crypto_ablkcipher_setkey(private, key, keylen); 763 return crypto_skcipher_setkey(private, key, keylen);
765} 764}
766 765
767static void skcipher_wait(struct sock *sk) 766static void skcipher_wait(struct sock *sk)
@@ -778,13 +777,13 @@ static void skcipher_sock_destruct(struct sock *sk)
778{ 777{
779 struct alg_sock *ask = alg_sk(sk); 778 struct alg_sock *ask = alg_sk(sk);
780 struct skcipher_ctx *ctx = ask->private; 779 struct skcipher_ctx *ctx = ask->private;
781 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(&ctx->req); 780 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(&ctx->req);
782 781
783 if (atomic_read(&ctx->inflight)) 782 if (atomic_read(&ctx->inflight))
784 skcipher_wait(sk); 783 skcipher_wait(sk);
785 784
786 skcipher_free_sgl(sk); 785 skcipher_free_sgl(sk);
787 sock_kzfree_s(sk, ctx->iv, crypto_ablkcipher_ivsize(tfm)); 786 sock_kzfree_s(sk, ctx->iv, crypto_skcipher_ivsize(tfm));
788 sock_kfree_s(sk, ctx, ctx->len); 787 sock_kfree_s(sk, ctx, ctx->len);
789 af_alg_release_parent(sk); 788 af_alg_release_parent(sk);
790} 789}
@@ -793,20 +792,20 @@ static int skcipher_accept_parent(void *private, struct sock *sk)
793{ 792{
794 struct skcipher_ctx *ctx; 793 struct skcipher_ctx *ctx;
795 struct alg_sock *ask = alg_sk(sk); 794 struct alg_sock *ask = alg_sk(sk);
796 unsigned int len = sizeof(*ctx) + crypto_ablkcipher_reqsize(private); 795 unsigned int len = sizeof(*ctx) + crypto_skcipher_reqsize(private);
797 796
798 ctx = sock_kmalloc(sk, len, GFP_KERNEL); 797 ctx = sock_kmalloc(sk, len, GFP_KERNEL);
799 if (!ctx) 798 if (!ctx)
800 return -ENOMEM; 799 return -ENOMEM;
801 800
802 ctx->iv = sock_kmalloc(sk, crypto_ablkcipher_ivsize(private), 801 ctx->iv = sock_kmalloc(sk, crypto_skcipher_ivsize(private),
803 GFP_KERNEL); 802 GFP_KERNEL);
804 if (!ctx->iv) { 803 if (!ctx->iv) {
805 sock_kfree_s(sk, ctx, len); 804 sock_kfree_s(sk, ctx, len);
806 return -ENOMEM; 805 return -ENOMEM;
807 } 806 }
808 807
809 memset(ctx->iv, 0, crypto_ablkcipher_ivsize(private)); 808 memset(ctx->iv, 0, crypto_skcipher_ivsize(private));
810 809
811 INIT_LIST_HEAD(&ctx->tsgl); 810 INIT_LIST_HEAD(&ctx->tsgl);
812 ctx->len = len; 811 ctx->len = len;
@@ -819,9 +818,9 @@ static int skcipher_accept_parent(void *private, struct sock *sk)
819 818
820 ask->private = ctx; 819 ask->private = ctx;
821 820
822 ablkcipher_request_set_tfm(&ctx->req, private); 821 skcipher_request_set_tfm(&ctx->req, private);
823 ablkcipher_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG, 822 skcipher_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG,
824 af_alg_complete, &ctx->completion); 823 af_alg_complete, &ctx->completion);
825 824
826 sk->sk_destruct = skcipher_sock_destruct; 825 sk->sk_destruct = skcipher_sock_destruct;
827 826