summaryrefslogtreecommitdiffstats
path: root/crypto/gcm.c
diff options
context:
space:
mode:
authorGilad Ben-Yossef <gilad@benyossef.com>2017-10-18 03:00:42 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2017-11-03 10:11:19 -0400
commit76c6739477fa9e16a75633d1f57c62a8a57388ad (patch)
tree6a23f5362e0bf48fb9c625f9fcc27dfb4aa1a70a /crypto/gcm.c
parent85a2dea4bdbfa7565818ca094d08e838cf62da77 (diff)
crypto: gcm - move to generic async completion
gcm is starting an async. crypto op and waiting for it complete. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/gcm.c')
-rw-r--r--crypto/gcm.c32
1 files changed, 6 insertions, 26 deletions
diff --git a/crypto/gcm.c b/crypto/gcm.c
index 80cf6cfe082b..8589681fb9f6 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -17,7 +17,6 @@
17#include <crypto/gcm.h> 17#include <crypto/gcm.h>
18#include <crypto/hash.h> 18#include <crypto/hash.h>
19#include "internal.h" 19#include "internal.h"
20#include <linux/completion.h>
21#include <linux/err.h> 20#include <linux/err.h>
22#include <linux/init.h> 21#include <linux/init.h>
23#include <linux/kernel.h> 22#include <linux/kernel.h>
@@ -79,11 +78,6 @@ struct crypto_gcm_req_priv_ctx {
79 } u; 78 } u;
80}; 79};
81 80
82struct crypto_gcm_setkey_result {
83 int err;
84 struct completion completion;
85};
86
87static struct { 81static struct {
88 u8 buf[16]; 82 u8 buf[16];
89 struct scatterlist sg; 83 struct scatterlist sg;
@@ -99,17 +93,6 @@ static inline struct crypto_gcm_req_priv_ctx *crypto_gcm_reqctx(
99 return (void *)PTR_ALIGN((u8 *)aead_request_ctx(req), align + 1); 93 return (void *)PTR_ALIGN((u8 *)aead_request_ctx(req), align + 1);
100} 94}
101 95
102static void crypto_gcm_setkey_done(struct crypto_async_request *req, int err)
103{
104 struct crypto_gcm_setkey_result *result = req->data;
105
106 if (err == -EINPROGRESS)
107 return;
108
109 result->err = err;
110 complete(&result->completion);
111}
112
113static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key, 96static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key,
114 unsigned int keylen) 97 unsigned int keylen)
115{ 98{
@@ -120,7 +103,7 @@ static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key,
120 be128 hash; 103 be128 hash;
121 u8 iv[16]; 104 u8 iv[16];
122 105
123 struct crypto_gcm_setkey_result result; 106 struct crypto_wait wait;
124 107
125 struct scatterlist sg[1]; 108 struct scatterlist sg[1];
126 struct skcipher_request req; 109 struct skcipher_request req;
@@ -141,21 +124,18 @@ static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key,
141 if (!data) 124 if (!data)
142 return -ENOMEM; 125 return -ENOMEM;
143 126
144 init_completion(&data->result.completion); 127 crypto_init_wait(&data->wait);
145 sg_init_one(data->sg, &data->hash, sizeof(data->hash)); 128 sg_init_one(data->sg, &data->hash, sizeof(data->hash));
146 skcipher_request_set_tfm(&data->req, ctr); 129 skcipher_request_set_tfm(&data->req, ctr);
147 skcipher_request_set_callback(&data->req, CRYPTO_TFM_REQ_MAY_SLEEP | 130 skcipher_request_set_callback(&data->req, CRYPTO_TFM_REQ_MAY_SLEEP |
148 CRYPTO_TFM_REQ_MAY_BACKLOG, 131 CRYPTO_TFM_REQ_MAY_BACKLOG,
149 crypto_gcm_setkey_done, 132 crypto_req_done,
150 &data->result); 133 &data->wait);
151 skcipher_request_set_crypt(&data->req, data->sg, data->sg, 134 skcipher_request_set_crypt(&data->req, data->sg, data->sg,
152 sizeof(data->hash), data->iv); 135 sizeof(data->hash), data->iv);
153 136
154 err = crypto_skcipher_encrypt(&data->req); 137 err = crypto_wait_req(crypto_skcipher_encrypt(&data->req),
155 if (err == -EINPROGRESS || err == -EBUSY) { 138 &data->wait);
156 wait_for_completion(&data->result.completion);
157 err = data->result.err;
158 }
159 139
160 if (err) 140 if (err)
161 goto out; 141 goto out;