summaryrefslogtreecommitdiffstats
path: root/crypto/seqiv.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-08-13 05:28:59 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-08-17 04:53:46 -0400
commit659e7f528317d5a97e5100abcaf6e00552c23417 (patch)
tree6d989f700929503cd18555a02212f2ef662f40f7 /crypto/seqiv.c
parent149a39717dcce3b6ba15285c9fc86e4423437e05 (diff)
crypto: seqiv - Use generic geniv init/exit helpers
This patch replaces the seqiv init/exit handlers with the generic geniv helpers. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/seqiv.c')
-rw-r--r--crypto/seqiv.c75
1 files changed, 7 insertions, 68 deletions
diff --git a/crypto/seqiv.c b/crypto/seqiv.c
index 3d8b02b80872..15a749a5cab7 100644
--- a/crypto/seqiv.c
+++ b/crypto/seqiv.c
@@ -15,7 +15,6 @@
15 15
16#include <crypto/internal/geniv.h> 16#include <crypto/internal/geniv.h>
17#include <crypto/internal/skcipher.h> 17#include <crypto/internal/skcipher.h>
18#include <crypto/null.h>
19#include <crypto/rng.h> 18#include <crypto/rng.h>
20#include <crypto/scatterwalk.h> 19#include <crypto/scatterwalk.h>
21#include <linux/err.h> 20#include <linux/err.h>
@@ -31,13 +30,6 @@ struct seqiv_ctx {
31 u8 salt[] __attribute__ ((aligned(__alignof__(u32)))); 30 u8 salt[] __attribute__ ((aligned(__alignof__(u32))));
32}; 31};
33 32
34struct seqiv_aead_ctx {
35 /* aead_geniv_ctx must be first the element */
36 struct aead_geniv_ctx geniv;
37 struct crypto_blkcipher *null;
38 u8 salt[] __attribute__ ((aligned(__alignof__(u32))));
39};
40
41static void seqiv_free(struct crypto_instance *inst); 33static void seqiv_free(struct crypto_instance *inst);
42 34
43static void seqiv_complete2(struct skcipher_givcrypt_request *req, int err) 35static void seqiv_complete2(struct skcipher_givcrypt_request *req, int err)
@@ -155,7 +147,7 @@ static int seqiv_givencrypt(struct skcipher_givcrypt_request *req)
155static int seqiv_aead_encrypt(struct aead_request *req) 147static int seqiv_aead_encrypt(struct aead_request *req)
156{ 148{
157 struct crypto_aead *geniv = crypto_aead_reqtfm(req); 149 struct crypto_aead *geniv = crypto_aead_reqtfm(req);
158 struct seqiv_aead_ctx *ctx = crypto_aead_ctx(geniv); 150 struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv);
159 struct aead_request *subreq = aead_request_ctx(req); 151 struct aead_request *subreq = aead_request_ctx(req);
160 crypto_completion_t compl; 152 crypto_completion_t compl;
161 void *data; 153 void *data;
@@ -166,7 +158,7 @@ static int seqiv_aead_encrypt(struct aead_request *req)
166 if (req->cryptlen < ivsize) 158 if (req->cryptlen < ivsize)
167 return -EINVAL; 159 return -EINVAL;
168 160
169 aead_request_set_tfm(subreq, ctx->geniv.child); 161 aead_request_set_tfm(subreq, ctx->child);
170 162
171 compl = req->base.complete; 163 compl = req->base.complete;
172 data = req->base.data; 164 data = req->base.data;
@@ -213,7 +205,7 @@ static int seqiv_aead_encrypt(struct aead_request *req)
213static int seqiv_aead_decrypt(struct aead_request *req) 205static int seqiv_aead_decrypt(struct aead_request *req)
214{ 206{
215 struct crypto_aead *geniv = crypto_aead_reqtfm(req); 207 struct crypto_aead *geniv = crypto_aead_reqtfm(req);
216 struct seqiv_aead_ctx *ctx = crypto_aead_ctx(geniv); 208 struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv);
217 struct aead_request *subreq = aead_request_ctx(req); 209 struct aead_request *subreq = aead_request_ctx(req);
218 crypto_completion_t compl; 210 crypto_completion_t compl;
219 void *data; 211 void *data;
@@ -222,7 +214,7 @@ static int seqiv_aead_decrypt(struct aead_request *req)
222 if (req->cryptlen < ivsize + crypto_aead_authsize(geniv)) 214 if (req->cryptlen < ivsize + crypto_aead_authsize(geniv))
223 return -EINVAL; 215 return -EINVAL;
224 216
225 aead_request_set_tfm(subreq, ctx->geniv.child); 217 aead_request_set_tfm(subreq, ctx->child);
226 218
227 compl = req->base.complete; 219 compl = req->base.complete;
228 data = req->base.data; 220 data = req->base.data;
@@ -258,59 +250,6 @@ static int seqiv_init(struct crypto_tfm *tfm)
258 return err ?: skcipher_geniv_init(tfm); 250 return err ?: skcipher_geniv_init(tfm);
259} 251}
260 252
261static int seqiv_aead_init_common(struct crypto_aead *geniv,
262 unsigned int reqsize)
263{
264 struct seqiv_aead_ctx *ctx = crypto_aead_ctx(geniv);
265 int err;
266
267 spin_lock_init(&ctx->geniv.lock);
268
269 crypto_aead_set_reqsize(geniv, sizeof(struct aead_request));
270
271 err = crypto_get_default_rng();
272 if (err)
273 goto out;
274
275 err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
276 crypto_aead_ivsize(geniv));
277 crypto_put_default_rng();
278 if (err)
279 goto out;
280
281 ctx->null = crypto_get_default_null_skcipher();
282 err = PTR_ERR(ctx->null);
283 if (IS_ERR(ctx->null))
284 goto out;
285
286 err = aead_geniv_init(crypto_aead_tfm(geniv));
287 if (err)
288 goto drop_null;
289
290 ctx->geniv.child = geniv->child;
291 geniv->child = geniv;
292
293out:
294 return err;
295
296drop_null:
297 crypto_put_default_null_skcipher();
298 goto out;
299}
300
301static int seqiv_aead_init(struct crypto_aead *tfm)
302{
303 return seqiv_aead_init_common(tfm, sizeof(struct aead_request));
304}
305
306static void seqiv_aead_exit(struct crypto_aead *tfm)
307{
308 struct seqiv_aead_ctx *ctx = crypto_aead_ctx(tfm);
309
310 crypto_free_aead(ctx->geniv.child);
311 crypto_put_default_null_skcipher();
312}
313
314static int seqiv_ablkcipher_create(struct crypto_template *tmpl, 253static int seqiv_ablkcipher_create(struct crypto_template *tmpl,
315 struct rtattr **tb) 254 struct rtattr **tb)
316{ 255{
@@ -370,10 +309,10 @@ static int seqiv_aead_create(struct crypto_template *tmpl, struct rtattr **tb)
370 inst->alg.encrypt = seqiv_aead_encrypt; 309 inst->alg.encrypt = seqiv_aead_encrypt;
371 inst->alg.decrypt = seqiv_aead_decrypt; 310 inst->alg.decrypt = seqiv_aead_decrypt;
372 311
373 inst->alg.init = seqiv_aead_init; 312 inst->alg.init = aead_init_geniv;
374 inst->alg.exit = seqiv_aead_exit; 313 inst->alg.exit = aead_exit_geniv;
375 314
376 inst->alg.base.cra_ctxsize = sizeof(struct seqiv_aead_ctx); 315 inst->alg.base.cra_ctxsize = sizeof(struct aead_geniv_ctx);
377 inst->alg.base.cra_ctxsize += inst->alg.ivsize; 316 inst->alg.base.cra_ctxsize += inst->alg.ivsize;
378 317
379 err = aead_register_instance(tmpl, inst); 318 err = aead_register_instance(tmpl, inst);