hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/crypto/authencesn.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * authencesn.c - AEAD wrapper for IPsec with extended sequence numbers,
34 * derived from authenc.c
....@@ -5,12 +6,6 @@
56 * Copyright (C) 2010 secunet Security Networks AG
67 * Copyright (C) 2010 Steffen Klassert <steffen.klassert@secunet.com>
78 * Copyright (c) 2015 Herbert Xu <herbert@gondor.apana.org.au>
8
- *
9
- * This program is free software; you can redistribute it and/or modify it
10
- * under the terms of the GNU General Public License as published by the Free
11
- * Software Foundation; either version 2 of the License, or (at your option)
12
- * any later version.
13
- *
149 */
1510
1611 #include <crypto/internal/aead.h>
....@@ -36,7 +31,7 @@
3631 unsigned int reqoff;
3732 struct crypto_ahash *auth;
3833 struct crypto_skcipher *enc;
39
- struct crypto_skcipher *null;
34
+ struct crypto_sync_skcipher *null;
4035 };
4136
4237 struct authenc_esn_request_ctx {
....@@ -70,15 +65,12 @@
7065 int err = -EINVAL;
7166
7267 if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
73
- goto badkey;
68
+ goto out;
7469
7570 crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK);
7671 crypto_ahash_set_flags(auth, crypto_aead_get_flags(authenc_esn) &
7772 CRYPTO_TFM_REQ_MASK);
7873 err = crypto_ahash_setkey(auth, keys.authkey, keys.authkeylen);
79
- crypto_aead_set_flags(authenc_esn, crypto_ahash_get_flags(auth) &
80
- CRYPTO_TFM_RES_MASK);
81
-
8274 if (err)
8375 goto out;
8476
....@@ -86,16 +78,9 @@
8678 crypto_skcipher_set_flags(enc, crypto_aead_get_flags(authenc_esn) &
8779 CRYPTO_TFM_REQ_MASK);
8880 err = crypto_skcipher_setkey(enc, keys.enckey, keys.enckeylen);
89
- crypto_aead_set_flags(authenc_esn, crypto_skcipher_get_flags(enc) &
90
- CRYPTO_TFM_RES_MASK);
91
-
9281 out:
9382 memzero_explicit(&keys, sizeof(keys));
9483 return err;
95
-
96
-badkey:
97
- crypto_aead_set_flags(authenc_esn, CRYPTO_TFM_RES_BAD_KEY_LEN);
98
- goto out;
9984 }
10085
10186 static int crypto_authenc_esn_genicv_tail(struct aead_request *req,
....@@ -183,9 +168,9 @@
183168 {
184169 struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req);
185170 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn);
186
- SKCIPHER_REQUEST_ON_STACK(skreq, ctx->null);
171
+ SYNC_SKCIPHER_REQUEST_ON_STACK(skreq, ctx->null);
187172
188
- skcipher_request_set_tfm(skreq, ctx->null);
173
+ skcipher_request_set_sync_tfm(skreq, ctx->null);
189174 skcipher_request_set_callback(skreq, aead_request_flags(req),
190175 NULL, NULL);
191176 skcipher_request_set_crypt(skreq, req->src, req->dst, len, NULL);
....@@ -341,7 +326,7 @@
341326 struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm);
342327 struct crypto_ahash *auth;
343328 struct crypto_skcipher *enc;
344
- struct crypto_skcipher *null;
329
+ struct crypto_sync_skcipher *null;
345330 int err;
346331
347332 auth = crypto_spawn_ahash(&ictx->auth);
....@@ -405,69 +390,47 @@
405390 static int crypto_authenc_esn_create(struct crypto_template *tmpl,
406391 struct rtattr **tb)
407392 {
408
- struct crypto_attr_type *algt;
393
+ u32 mask;
409394 struct aead_instance *inst;
395
+ struct authenc_esn_instance_ctx *ctx;
410396 struct hash_alg_common *auth;
411397 struct crypto_alg *auth_base;
412398 struct skcipher_alg *enc;
413
- struct authenc_esn_instance_ctx *ctx;
414
- const char *enc_name;
415399 int err;
416400
417
- algt = crypto_get_attr_type(tb);
418
- if (IS_ERR(algt))
419
- return PTR_ERR(algt);
420
-
421
- if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
422
- return -EINVAL;
423
-
424
- auth = ahash_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH,
425
- CRYPTO_ALG_TYPE_AHASH_MASK |
426
- crypto_requires_sync(algt->type, algt->mask));
427
- if (IS_ERR(auth))
428
- return PTR_ERR(auth);
429
-
430
- auth_base = &auth->base;
431
-
432
- enc_name = crypto_attr_alg_name(tb[2]);
433
- err = PTR_ERR(enc_name);
434
- if (IS_ERR(enc_name))
435
- goto out_put_auth;
401
+ err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AEAD, &mask);
402
+ if (err)
403
+ return err;
436404
437405 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
438
- err = -ENOMEM;
439406 if (!inst)
440
- goto out_put_auth;
441
-
407
+ return -ENOMEM;
442408 ctx = aead_instance_ctx(inst);
443409
444
- err = crypto_init_ahash_spawn(&ctx->auth, auth,
445
- aead_crypto_instance(inst));
410
+ err = crypto_grab_ahash(&ctx->auth, aead_crypto_instance(inst),
411
+ crypto_attr_alg_name(tb[1]), 0, mask);
446412 if (err)
447413 goto err_free_inst;
414
+ auth = crypto_spawn_ahash_alg(&ctx->auth);
415
+ auth_base = &auth->base;
448416
449
- crypto_set_skcipher_spawn(&ctx->enc, aead_crypto_instance(inst));
450
- err = crypto_grab_skcipher(&ctx->enc, enc_name, 0,
451
- crypto_requires_sync(algt->type,
452
- algt->mask));
417
+ err = crypto_grab_skcipher(&ctx->enc, aead_crypto_instance(inst),
418
+ crypto_attr_alg_name(tb[2]), 0, mask);
453419 if (err)
454
- goto err_drop_auth;
455
-
420
+ goto err_free_inst;
456421 enc = crypto_spawn_skcipher_alg(&ctx->enc);
457422
458423 err = -ENAMETOOLONG;
459424 if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
460425 "authencesn(%s,%s)", auth_base->cra_name,
461426 enc->base.cra_name) >= CRYPTO_MAX_ALG_NAME)
462
- goto err_drop_enc;
427
+ goto err_free_inst;
463428
464429 if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
465430 "authencesn(%s,%s)", auth_base->cra_driver_name,
466431 enc->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
467
- goto err_drop_enc;
432
+ goto err_free_inst;
468433
469
- inst->alg.base.cra_flags = (auth_base->cra_flags |
470
- enc->base.cra_flags) & CRYPTO_ALG_ASYNC;
471434 inst->alg.base.cra_priority = enc->base.cra_priority * 10 +
472435 auth_base->cra_priority;
473436 inst->alg.base.cra_blocksize = enc->base.cra_blocksize;
....@@ -487,24 +450,14 @@
487450 inst->alg.encrypt = crypto_authenc_esn_encrypt;
488451 inst->alg.decrypt = crypto_authenc_esn_decrypt;
489452
490
- inst->free = crypto_authenc_esn_free,
453
+ inst->free = crypto_authenc_esn_free;
491454
492455 err = aead_register_instance(tmpl, inst);
493
- if (err)
494
- goto err_drop_enc;
495
-
496
-out:
497
- crypto_mod_put(auth_base);
498
- return err;
499
-
500
-err_drop_enc:
501
- crypto_drop_skcipher(&ctx->enc);
502
-err_drop_auth:
503
- crypto_drop_ahash(&ctx->auth);
456
+ if (err) {
504457 err_free_inst:
505
- kfree(inst);
506
-out_put_auth:
507
- goto out;
458
+ crypto_authenc_esn_free(inst);
459
+ }
460
+ return err;
508461 }
509462
510463 static struct crypto_template crypto_authenc_esn_tmpl = {
....@@ -523,7 +476,7 @@
523476 crypto_unregister_template(&crypto_authenc_esn_tmpl);
524477 }
525478
526
-module_init(crypto_authenc_esn_module_init);
479
+subsys_initcall(crypto_authenc_esn_module_init);
527480 module_exit(crypto_authenc_esn_module_exit);
528481
529482 MODULE_LICENSE("GPL");