Skip to content

Commit 17db854

Browse files
committed
crypto: gcm - Use default null skcipher
This patch makes gcm use the default null skcipher instead of allocating a new one for each tfm. Signed-off-by: Herbert Xu <[email protected]>
1 parent 3302346 commit 17db854

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

crypto/gcm.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <crypto/internal/aead.h>
1313
#include <crypto/internal/skcipher.h>
1414
#include <crypto/internal/hash.h>
15+
#include <crypto/null.h>
1516
#include <crypto/scatterwalk.h>
1617
#include <crypto/hash.h>
1718
#include "internal.h"
@@ -39,7 +40,6 @@ struct crypto_rfc4106_ctx {
3940

4041
struct crypto_rfc4543_instance_ctx {
4142
struct crypto_aead_spawn aead;
42-
struct crypto_skcipher_spawn null;
4343
};
4444

4545
struct crypto_rfc4543_ctx {
@@ -1246,7 +1246,7 @@ static int crypto_rfc4543_init_tfm(struct crypto_tfm *tfm)
12461246
if (IS_ERR(aead))
12471247
return PTR_ERR(aead);
12481248

1249-
null = crypto_spawn_blkcipher(&ictx->null.base);
1249+
null = crypto_get_default_null_skcipher();
12501250
err = PTR_ERR(null);
12511251
if (IS_ERR(null))
12521252
goto err_free_aead;
@@ -1273,7 +1273,7 @@ static void crypto_rfc4543_exit_tfm(struct crypto_tfm *tfm)
12731273
struct crypto_rfc4543_ctx *ctx = crypto_tfm_ctx(tfm);
12741274

12751275
crypto_free_aead(ctx->child);
1276-
crypto_free_blkcipher(ctx->null);
1276+
crypto_put_default_null_skcipher();
12771277
}
12781278

12791279
static struct crypto_instance *crypto_rfc4543_alloc(struct rtattr **tb)
@@ -1311,31 +1311,23 @@ static struct crypto_instance *crypto_rfc4543_alloc(struct rtattr **tb)
13111311

13121312
alg = crypto_aead_spawn_alg(spawn);
13131313

1314-
crypto_set_skcipher_spawn(&ctx->null, inst);
1315-
err = crypto_grab_skcipher(&ctx->null, "ecb(cipher_null)", 0,
1316-
CRYPTO_ALG_ASYNC);
1317-
if (err)
1318-
goto out_drop_alg;
1319-
1320-
crypto_skcipher_spawn_alg(&ctx->null);
1321-
13221314
err = -EINVAL;
13231315

13241316
/* We only support 16-byte blocks. */
13251317
if (alg->cra_aead.ivsize != 16)
1326-
goto out_drop_ecbnull;
1318+
goto out_drop_alg;
13271319

13281320
/* Not a stream cipher? */
13291321
if (alg->cra_blocksize != 1)
1330-
goto out_drop_ecbnull;
1322+
goto out_drop_alg;
13311323

13321324
err = -ENAMETOOLONG;
13331325
if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME,
13341326
"rfc4543(%s)", alg->cra_name) >= CRYPTO_MAX_ALG_NAME ||
13351327
snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
13361328
"rfc4543(%s)", alg->cra_driver_name) >=
13371329
CRYPTO_MAX_ALG_NAME)
1338-
goto out_drop_ecbnull;
1330+
goto out_drop_alg;
13391331

13401332
inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD;
13411333
inst->alg.cra_flags |= alg->cra_flags & CRYPTO_ALG_ASYNC;
@@ -1362,8 +1354,6 @@ static struct crypto_instance *crypto_rfc4543_alloc(struct rtattr **tb)
13621354
out:
13631355
return inst;
13641356

1365-
out_drop_ecbnull:
1366-
crypto_drop_skcipher(&ctx->null);
13671357
out_drop_alg:
13681358
crypto_drop_aead(spawn);
13691359
out_free_inst:
@@ -1377,7 +1367,6 @@ static void crypto_rfc4543_free(struct crypto_instance *inst)
13771367
struct crypto_rfc4543_instance_ctx *ctx = crypto_instance_ctx(inst);
13781368

13791369
crypto_drop_aead(&ctx->aead);
1380-
crypto_drop_skcipher(&ctx->null);
13811370

13821371
kfree(inst);
13831372
}

0 commit comments

Comments
 (0)