summaryrefslogtreecommitdiffstats
path: root/crypto/authencesn.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/authencesn.c')
-rw-r--r--crypto/authencesn.c106
1 files changed, 56 insertions, 50 deletions
diff --git a/crypto/authencesn.c b/crypto/authencesn.c
index 0c0468869e25..121010ac9962 100644
--- a/crypto/authencesn.c
+++ b/crypto/authencesn.c
@@ -35,8 +35,8 @@ struct authenc_esn_instance_ctx {
35struct crypto_authenc_esn_ctx { 35struct crypto_authenc_esn_ctx {
36 unsigned int reqoff; 36 unsigned int reqoff;
37 struct crypto_ahash *auth; 37 struct crypto_ahash *auth;
38 struct crypto_ablkcipher *enc; 38 struct crypto_skcipher *enc;
39 struct crypto_blkcipher *null; 39 struct crypto_skcipher *null;
40}; 40};
41 41
42struct authenc_esn_request_ctx { 42struct authenc_esn_request_ctx {
@@ -65,7 +65,7 @@ static int crypto_authenc_esn_setkey(struct crypto_aead *authenc_esn, const u8 *
65{ 65{
66 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); 66 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn);
67 struct crypto_ahash *auth = ctx->auth; 67 struct crypto_ahash *auth = ctx->auth;
68 struct crypto_ablkcipher *enc = ctx->enc; 68 struct crypto_skcipher *enc = ctx->enc;
69 struct crypto_authenc_keys keys; 69 struct crypto_authenc_keys keys;
70 int err = -EINVAL; 70 int err = -EINVAL;
71 71
@@ -82,11 +82,11 @@ static int crypto_authenc_esn_setkey(struct crypto_aead *authenc_esn, const u8 *
82 if (err) 82 if (err)
83 goto out; 83 goto out;
84 84
85 crypto_ablkcipher_clear_flags(enc, CRYPTO_TFM_REQ_MASK); 85 crypto_skcipher_clear_flags(enc, CRYPTO_TFM_REQ_MASK);
86 crypto_ablkcipher_set_flags(enc, crypto_aead_get_flags(authenc_esn) & 86 crypto_skcipher_set_flags(enc, crypto_aead_get_flags(authenc_esn) &
87 CRYPTO_TFM_REQ_MASK); 87 CRYPTO_TFM_REQ_MASK);
88 err = crypto_ablkcipher_setkey(enc, keys.enckey, keys.enckeylen); 88 err = crypto_skcipher_setkey(enc, keys.enckey, keys.enckeylen);
89 crypto_aead_set_flags(authenc_esn, crypto_ablkcipher_get_flags(enc) & 89 crypto_aead_set_flags(authenc_esn, crypto_skcipher_get_flags(enc) &
90 CRYPTO_TFM_RES_MASK); 90 CRYPTO_TFM_RES_MASK);
91 91
92out: 92out:
@@ -182,11 +182,14 @@ static int crypto_authenc_esn_copy(struct aead_request *req, unsigned int len)
182{ 182{
183 struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req); 183 struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req);
184 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); 184 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn);
185 struct blkcipher_desc desc = { 185 SKCIPHER_REQUEST_ON_STACK(skreq, ctx->null);
186 .tfm = ctx->null,
187 };
188 186
189 return crypto_blkcipher_encrypt(&desc, req->dst, req->src, len); 187 skcipher_request_set_tfm(skreq, ctx->null);
188 skcipher_request_set_callback(skreq, aead_request_flags(req),
189 NULL, NULL);
190 skcipher_request_set_crypt(skreq, req->src, req->dst, len, NULL);
191
192 return crypto_skcipher_encrypt(skreq);
190} 193}
191 194
192static int crypto_authenc_esn_encrypt(struct aead_request *req) 195static int crypto_authenc_esn_encrypt(struct aead_request *req)
@@ -194,9 +197,9 @@ static int crypto_authenc_esn_encrypt(struct aead_request *req)
194 struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req); 197 struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req);
195 struct authenc_esn_request_ctx *areq_ctx = aead_request_ctx(req); 198 struct authenc_esn_request_ctx *areq_ctx = aead_request_ctx(req);
196 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); 199 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn);
197 struct ablkcipher_request *abreq = (void *)(areq_ctx->tail 200 struct skcipher_request *skreq = (void *)(areq_ctx->tail +
198 + ctx->reqoff); 201 ctx->reqoff);
199 struct crypto_ablkcipher *enc = ctx->enc; 202 struct crypto_skcipher *enc = ctx->enc;
200 unsigned int assoclen = req->assoclen; 203 unsigned int assoclen = req->assoclen;
201 unsigned int cryptlen = req->cryptlen; 204 unsigned int cryptlen = req->cryptlen;
202 struct scatterlist *src, *dst; 205 struct scatterlist *src, *dst;
@@ -215,12 +218,12 @@ static int crypto_authenc_esn_encrypt(struct aead_request *req)
215 dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, assoclen); 218 dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, assoclen);
216 } 219 }
217 220
218 ablkcipher_request_set_tfm(abreq, enc); 221 skcipher_request_set_tfm(skreq, enc);
219 ablkcipher_request_set_callback(abreq, aead_request_flags(req), 222 skcipher_request_set_callback(skreq, aead_request_flags(req),
220 crypto_authenc_esn_encrypt_done, req); 223 crypto_authenc_esn_encrypt_done, req);
221 ablkcipher_request_set_crypt(abreq, src, dst, cryptlen, req->iv); 224 skcipher_request_set_crypt(skreq, src, dst, cryptlen, req->iv);
222 225
223 err = crypto_ablkcipher_encrypt(abreq); 226 err = crypto_skcipher_encrypt(skreq);
224 if (err) 227 if (err)
225 return err; 228 return err;
226 229
@@ -234,8 +237,8 @@ static int crypto_authenc_esn_decrypt_tail(struct aead_request *req,
234 unsigned int authsize = crypto_aead_authsize(authenc_esn); 237 unsigned int authsize = crypto_aead_authsize(authenc_esn);
235 struct authenc_esn_request_ctx *areq_ctx = aead_request_ctx(req); 238 struct authenc_esn_request_ctx *areq_ctx = aead_request_ctx(req);
236 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); 239 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn);
237 struct ablkcipher_request *abreq = (void *)(areq_ctx->tail 240 struct skcipher_request *skreq = (void *)(areq_ctx->tail +
238 + ctx->reqoff); 241 ctx->reqoff);
239 struct crypto_ahash *auth = ctx->auth; 242 struct crypto_ahash *auth = ctx->auth;
240 u8 *ohash = PTR_ALIGN((u8 *)areq_ctx->tail, 243 u8 *ohash = PTR_ALIGN((u8 *)areq_ctx->tail,
241 crypto_ahash_alignmask(auth) + 1); 244 crypto_ahash_alignmask(auth) + 1);
@@ -256,12 +259,12 @@ static int crypto_authenc_esn_decrypt_tail(struct aead_request *req,
256 sg_init_table(areq_ctx->dst, 2); 259 sg_init_table(areq_ctx->dst, 2);
257 dst = scatterwalk_ffwd(areq_ctx->dst, dst, assoclen); 260 dst = scatterwalk_ffwd(areq_ctx->dst, dst, assoclen);
258 261
259 ablkcipher_request_set_tfm(abreq, ctx->enc); 262 skcipher_request_set_tfm(skreq, ctx->enc);
260 ablkcipher_request_set_callback(abreq, flags, 263 skcipher_request_set_callback(skreq, flags,
261 req->base.complete, req->base.data); 264 req->base.complete, req->base.data);
262 ablkcipher_request_set_crypt(abreq, dst, dst, cryptlen, req->iv); 265 skcipher_request_set_crypt(skreq, dst, dst, cryptlen, req->iv);
263 266
264 return crypto_ablkcipher_decrypt(abreq); 267 return crypto_skcipher_decrypt(skreq);
265} 268}
266 269
267static void authenc_esn_verify_ahash_done(struct crypto_async_request *areq, 270static void authenc_esn_verify_ahash_done(struct crypto_async_request *areq,
@@ -331,20 +334,20 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
331 struct authenc_esn_instance_ctx *ictx = aead_instance_ctx(inst); 334 struct authenc_esn_instance_ctx *ictx = aead_instance_ctx(inst);
332 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm); 335 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm);
333 struct crypto_ahash *auth; 336 struct crypto_ahash *auth;
334 struct crypto_ablkcipher *enc; 337 struct crypto_skcipher *enc;
335 struct crypto_blkcipher *null; 338 struct crypto_skcipher *null;
336 int err; 339 int err;
337 340
338 auth = crypto_spawn_ahash(&ictx->auth); 341 auth = crypto_spawn_ahash(&ictx->auth);
339 if (IS_ERR(auth)) 342 if (IS_ERR(auth))
340 return PTR_ERR(auth); 343 return PTR_ERR(auth);
341 344
342 enc = crypto_spawn_skcipher(&ictx->enc); 345 enc = crypto_spawn_skcipher2(&ictx->enc);
343 err = PTR_ERR(enc); 346 err = PTR_ERR(enc);
344 if (IS_ERR(enc)) 347 if (IS_ERR(enc))
345 goto err_free_ahash; 348 goto err_free_ahash;
346 349
347 null = crypto_get_default_null_skcipher(); 350 null = crypto_get_default_null_skcipher2();
348 err = PTR_ERR(null); 351 err = PTR_ERR(null);
349 if (IS_ERR(null)) 352 if (IS_ERR(null))
350 goto err_free_skcipher; 353 goto err_free_skcipher;
@@ -361,15 +364,15 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
361 sizeof(struct authenc_esn_request_ctx) + 364 sizeof(struct authenc_esn_request_ctx) +
362 ctx->reqoff + 365 ctx->reqoff +
363 max_t(unsigned int, 366 max_t(unsigned int,
364 crypto_ahash_reqsize(auth) + 367 crypto_ahash_reqsize(auth) +
365 sizeof(struct ahash_request), 368 sizeof(struct ahash_request),
366 sizeof(struct skcipher_givcrypt_request) + 369 sizeof(struct skcipher_request) +
367 crypto_ablkcipher_reqsize(enc))); 370 crypto_skcipher_reqsize(enc)));
368 371
369 return 0; 372 return 0;
370 373
371err_free_skcipher: 374err_free_skcipher:
372 crypto_free_ablkcipher(enc); 375 crypto_free_skcipher(enc);
373err_free_ahash: 376err_free_ahash:
374 crypto_free_ahash(auth); 377 crypto_free_ahash(auth);
375 return err; 378 return err;
@@ -380,8 +383,8 @@ static void crypto_authenc_esn_exit_tfm(struct crypto_aead *tfm)
380 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm); 383 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm);
381 384
382 crypto_free_ahash(ctx->auth); 385 crypto_free_ahash(ctx->auth);
383 crypto_free_ablkcipher(ctx->enc); 386 crypto_free_skcipher(ctx->enc);
384 crypto_put_default_null_skcipher(); 387 crypto_put_default_null_skcipher2();
385} 388}
386 389
387static void crypto_authenc_esn_free(struct aead_instance *inst) 390static void crypto_authenc_esn_free(struct aead_instance *inst)
@@ -400,7 +403,7 @@ static int crypto_authenc_esn_create(struct crypto_template *tmpl,
400 struct aead_instance *inst; 403 struct aead_instance *inst;
401 struct hash_alg_common *auth; 404 struct hash_alg_common *auth;
402 struct crypto_alg *auth_base; 405 struct crypto_alg *auth_base;
403 struct crypto_alg *enc; 406 struct skcipher_alg *enc;
404 struct authenc_esn_instance_ctx *ctx; 407 struct authenc_esn_instance_ctx *ctx;
405 const char *enc_name; 408 const char *enc_name;
406 int err; 409 int err;
@@ -413,7 +416,8 @@ static int crypto_authenc_esn_create(struct crypto_template *tmpl,
413 return -EINVAL; 416 return -EINVAL;
414 417
415 auth = ahash_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH, 418 auth = ahash_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH,
416 CRYPTO_ALG_TYPE_AHASH_MASK); 419 CRYPTO_ALG_TYPE_AHASH_MASK |
420 crypto_requires_sync(algt->type, algt->mask));
417 if (IS_ERR(auth)) 421 if (IS_ERR(auth))
418 return PTR_ERR(auth); 422 return PTR_ERR(auth);
419 423
@@ -437,34 +441,36 @@ static int crypto_authenc_esn_create(struct crypto_template *tmpl,
437 goto err_free_inst; 441 goto err_free_inst;
438 442
439 crypto_set_skcipher_spawn(&ctx->enc, aead_crypto_instance(inst)); 443 crypto_set_skcipher_spawn(&ctx->enc, aead_crypto_instance(inst));
440 err = crypto_grab_skcipher(&ctx->enc, enc_name, 0, 444 err = crypto_grab_skcipher2(&ctx->enc, enc_name, 0,
441 crypto_requires_sync(algt->type, 445 crypto_requires_sync(algt->type,
442 algt->mask)); 446 algt->mask));
443 if (err) 447 if (err)
444 goto err_drop_auth; 448 goto err_drop_auth;
445 449
446 enc = crypto_skcipher_spawn_alg(&ctx->enc); 450 enc = crypto_spawn_skcipher_alg(&ctx->enc);
447 451
448 err = -ENAMETOOLONG; 452 err = -ENAMETOOLONG;
449 if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, 453 if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
450 "authencesn(%s,%s)", auth_base->cra_name, 454 "authencesn(%s,%s)", auth_base->cra_name,
451 enc->cra_name) >= CRYPTO_MAX_ALG_NAME) 455 enc->base.cra_name) >= CRYPTO_MAX_ALG_NAME)
452 goto err_drop_enc; 456 goto err_drop_enc;
453 457
454 if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, 458 if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
455 "authencesn(%s,%s)", auth_base->cra_driver_name, 459 "authencesn(%s,%s)", auth_base->cra_driver_name,
456 enc->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) 460 enc->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
457 goto err_drop_enc; 461 goto err_drop_enc;
458 462
459 inst->alg.base.cra_flags = enc->cra_flags & CRYPTO_ALG_ASYNC; 463 inst->alg.base.cra_flags = (auth_base->cra_flags |
460 inst->alg.base.cra_priority = enc->cra_priority * 10 + 464 enc->base.cra_flags) & CRYPTO_ALG_ASYNC;
465 inst->alg.base.cra_priority = enc->base.cra_priority * 10 +
461 auth_base->cra_priority; 466 auth_base->cra_priority;
462 inst->alg.base.cra_blocksize = enc->cra_blocksize; 467 inst->alg.base.cra_blocksize = enc->base.cra_blocksize;
463 inst->alg.base.cra_alignmask = auth_base->cra_alignmask | 468 inst->alg.base.cra_alignmask = auth_base->cra_alignmask |
464 enc->cra_alignmask; 469 enc->base.cra_alignmask;
465 inst->alg.base.cra_ctxsize = sizeof(struct crypto_authenc_esn_ctx); 470 inst->alg.base.cra_ctxsize = sizeof(struct crypto_authenc_esn_ctx);
466 471
467 inst->alg.ivsize = enc->cra_ablkcipher.ivsize; 472 inst->alg.ivsize = crypto_skcipher_alg_ivsize(enc);
473 inst->alg.chunksize = crypto_skcipher_alg_chunksize(enc);
468 inst->alg.maxauthsize = auth->digestsize; 474 inst->alg.maxauthsize = auth->digestsize;
469 475
470 inst->alg.init = crypto_authenc_esn_init_tfm; 476 inst->alg.init = crypto_authenc_esn_init_tfm;