diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2015-05-21 03:11:11 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-05-21 23:25:55 -0400 |
commit | 17db8546997023ba5c931c1f250bb23bf8d0b958 (patch) | |
tree | 737804b7258b744c70350e7b24bd2f496a7ba523 /crypto/gcm.c | |
parent | 330234638e16b7b95e8e5e6be719a61a93f074b8 (diff) |
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 <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/gcm.c')
-rw-r--r-- | crypto/gcm.c | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/crypto/gcm.c b/crypto/gcm.c index b56200eff029..fc2b55eaf1ed 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <crypto/internal/aead.h> | 12 | #include <crypto/internal/aead.h> |
13 | #include <crypto/internal/skcipher.h> | 13 | #include <crypto/internal/skcipher.h> |
14 | #include <crypto/internal/hash.h> | 14 | #include <crypto/internal/hash.h> |
15 | #include <crypto/null.h> | ||
15 | #include <crypto/scatterwalk.h> | 16 | #include <crypto/scatterwalk.h> |
16 | #include <crypto/hash.h> | 17 | #include <crypto/hash.h> |
17 | #include "internal.h" | 18 | #include "internal.h" |
@@ -39,7 +40,6 @@ struct crypto_rfc4106_ctx { | |||
39 | 40 | ||
40 | struct crypto_rfc4543_instance_ctx { | 41 | struct crypto_rfc4543_instance_ctx { |
41 | struct crypto_aead_spawn aead; | 42 | struct crypto_aead_spawn aead; |
42 | struct crypto_skcipher_spawn null; | ||
43 | }; | 43 | }; |
44 | 44 | ||
45 | struct crypto_rfc4543_ctx { | 45 | struct crypto_rfc4543_ctx { |
@@ -1246,7 +1246,7 @@ static int crypto_rfc4543_init_tfm(struct crypto_tfm *tfm) | |||
1246 | if (IS_ERR(aead)) | 1246 | if (IS_ERR(aead)) |
1247 | return PTR_ERR(aead); | 1247 | return PTR_ERR(aead); |
1248 | 1248 | ||
1249 | null = crypto_spawn_blkcipher(&ictx->null.base); | 1249 | null = crypto_get_default_null_skcipher(); |
1250 | err = PTR_ERR(null); | 1250 | err = PTR_ERR(null); |
1251 | if (IS_ERR(null)) | 1251 | if (IS_ERR(null)) |
1252 | goto err_free_aead; | 1252 | goto err_free_aead; |
@@ -1273,7 +1273,7 @@ static void crypto_rfc4543_exit_tfm(struct crypto_tfm *tfm) | |||
1273 | struct crypto_rfc4543_ctx *ctx = crypto_tfm_ctx(tfm); | 1273 | struct crypto_rfc4543_ctx *ctx = crypto_tfm_ctx(tfm); |
1274 | 1274 | ||
1275 | crypto_free_aead(ctx->child); | 1275 | crypto_free_aead(ctx->child); |
1276 | crypto_free_blkcipher(ctx->null); | 1276 | crypto_put_default_null_skcipher(); |
1277 | } | 1277 | } |
1278 | 1278 | ||
1279 | static struct crypto_instance *crypto_rfc4543_alloc(struct rtattr **tb) | 1279 | static struct crypto_instance *crypto_rfc4543_alloc(struct rtattr **tb) |
@@ -1311,23 +1311,15 @@ static struct crypto_instance *crypto_rfc4543_alloc(struct rtattr **tb) | |||
1311 | 1311 | ||
1312 | alg = crypto_aead_spawn_alg(spawn); | 1312 | alg = crypto_aead_spawn_alg(spawn); |
1313 | 1313 | ||
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 | |||
1322 | err = -EINVAL; | 1314 | err = -EINVAL; |
1323 | 1315 | ||
1324 | /* We only support 16-byte blocks. */ | 1316 | /* We only support 16-byte blocks. */ |
1325 | if (alg->cra_aead.ivsize != 16) | 1317 | if (alg->cra_aead.ivsize != 16) |
1326 | goto out_drop_ecbnull; | 1318 | goto out_drop_alg; |
1327 | 1319 | ||
1328 | /* Not a stream cipher? */ | 1320 | /* Not a stream cipher? */ |
1329 | if (alg->cra_blocksize != 1) | 1321 | if (alg->cra_blocksize != 1) |
1330 | goto out_drop_ecbnull; | 1322 | goto out_drop_alg; |
1331 | 1323 | ||
1332 | err = -ENAMETOOLONG; | 1324 | err = -ENAMETOOLONG; |
1333 | if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, | 1325 | if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, |
@@ -1335,7 +1327,7 @@ static struct crypto_instance *crypto_rfc4543_alloc(struct rtattr **tb) | |||
1335 | snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, | 1327 | snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
1336 | "rfc4543(%s)", alg->cra_driver_name) >= | 1328 | "rfc4543(%s)", alg->cra_driver_name) >= |
1337 | CRYPTO_MAX_ALG_NAME) | 1329 | CRYPTO_MAX_ALG_NAME) |
1338 | goto out_drop_ecbnull; | 1330 | goto out_drop_alg; |
1339 | 1331 | ||
1340 | inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD; | 1332 | inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD; |
1341 | inst->alg.cra_flags |= alg->cra_flags & CRYPTO_ALG_ASYNC; | 1333 | inst->alg.cra_flags |= alg->cra_flags & CRYPTO_ALG_ASYNC; |
@@ -1362,8 +1354,6 @@ static struct crypto_instance *crypto_rfc4543_alloc(struct rtattr **tb) | |||
1362 | out: | 1354 | out: |
1363 | return inst; | 1355 | return inst; |
1364 | 1356 | ||
1365 | out_drop_ecbnull: | ||
1366 | crypto_drop_skcipher(&ctx->null); | ||
1367 | out_drop_alg: | 1357 | out_drop_alg: |
1368 | crypto_drop_aead(spawn); | 1358 | crypto_drop_aead(spawn); |
1369 | out_free_inst: | 1359 | out_free_inst: |
@@ -1377,7 +1367,6 @@ static void crypto_rfc4543_free(struct crypto_instance *inst) | |||
1377 | struct crypto_rfc4543_instance_ctx *ctx = crypto_instance_ctx(inst); | 1367 | struct crypto_rfc4543_instance_ctx *ctx = crypto_instance_ctx(inst); |
1378 | 1368 | ||
1379 | crypto_drop_aead(&ctx->aead); | 1369 | crypto_drop_aead(&ctx->aead); |
1380 | crypto_drop_skcipher(&ctx->null); | ||
1381 | 1370 | ||
1382 | kfree(inst); | 1371 | kfree(inst); |
1383 | } | 1372 | } |