mirror of
https://github.com/torvalds/linux.git
synced 2025-08-15 14:11:42 +02:00
crypto: authenc - use memcpy_sglist() instead of null skcipher
For copying data between two scatterlists, just use memcpy_sglist() instead of the so-called "null skcipher". This is much simpler. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
f2804d0eee
commit
dbc4b1458e
3 changed files with 4 additions and 67 deletions
|
@ -228,7 +228,6 @@ config CRYPTO_AUTHENC
|
||||||
select CRYPTO_SKCIPHER
|
select CRYPTO_SKCIPHER
|
||||||
select CRYPTO_MANAGER
|
select CRYPTO_MANAGER
|
||||||
select CRYPTO_HASH
|
select CRYPTO_HASH
|
||||||
select CRYPTO_NULL
|
|
||||||
help
|
help
|
||||||
Authenc: Combined mode wrapper for IPsec.
|
Authenc: Combined mode wrapper for IPsec.
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <crypto/internal/hash.h>
|
#include <crypto/internal/hash.h>
|
||||||
#include <crypto/internal/skcipher.h>
|
#include <crypto/internal/skcipher.h>
|
||||||
#include <crypto/authenc.h>
|
#include <crypto/authenc.h>
|
||||||
#include <crypto/null.h>
|
|
||||||
#include <crypto/scatterwalk.h>
|
#include <crypto/scatterwalk.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
|
@ -28,7 +27,6 @@ struct authenc_instance_ctx {
|
||||||
struct crypto_authenc_ctx {
|
struct crypto_authenc_ctx {
|
||||||
struct crypto_ahash *auth;
|
struct crypto_ahash *auth;
|
||||||
struct crypto_skcipher *enc;
|
struct crypto_skcipher *enc;
|
||||||
struct crypto_sync_skcipher *null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct authenc_request_ctx {
|
struct authenc_request_ctx {
|
||||||
|
@ -170,21 +168,6 @@ out:
|
||||||
authenc_request_complete(areq, err);
|
authenc_request_complete(areq, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int crypto_authenc_copy_assoc(struct aead_request *req)
|
|
||||||
{
|
|
||||||
struct crypto_aead *authenc = crypto_aead_reqtfm(req);
|
|
||||||
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
|
|
||||||
SYNC_SKCIPHER_REQUEST_ON_STACK(skreq, ctx->null);
|
|
||||||
|
|
||||||
skcipher_request_set_sync_tfm(skreq, ctx->null);
|
|
||||||
skcipher_request_set_callback(skreq, aead_request_flags(req),
|
|
||||||
NULL, NULL);
|
|
||||||
skcipher_request_set_crypt(skreq, req->src, req->dst, req->assoclen,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
return crypto_skcipher_encrypt(skreq);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int crypto_authenc_encrypt(struct aead_request *req)
|
static int crypto_authenc_encrypt(struct aead_request *req)
|
||||||
{
|
{
|
||||||
struct crypto_aead *authenc = crypto_aead_reqtfm(req);
|
struct crypto_aead *authenc = crypto_aead_reqtfm(req);
|
||||||
|
@ -203,10 +186,7 @@ static int crypto_authenc_encrypt(struct aead_request *req)
|
||||||
dst = src;
|
dst = src;
|
||||||
|
|
||||||
if (req->src != req->dst) {
|
if (req->src != req->dst) {
|
||||||
err = crypto_authenc_copy_assoc(req);
|
memcpy_sglist(req->dst, req->src, req->assoclen);
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, req->assoclen);
|
dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, req->assoclen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +283,6 @@ static int crypto_authenc_init_tfm(struct crypto_aead *tfm)
|
||||||
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(tfm);
|
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(tfm);
|
||||||
struct crypto_ahash *auth;
|
struct crypto_ahash *auth;
|
||||||
struct crypto_skcipher *enc;
|
struct crypto_skcipher *enc;
|
||||||
struct crypto_sync_skcipher *null;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
auth = crypto_spawn_ahash(&ictx->auth);
|
auth = crypto_spawn_ahash(&ictx->auth);
|
||||||
|
@ -315,14 +294,8 @@ static int crypto_authenc_init_tfm(struct crypto_aead *tfm)
|
||||||
if (IS_ERR(enc))
|
if (IS_ERR(enc))
|
||||||
goto err_free_ahash;
|
goto err_free_ahash;
|
||||||
|
|
||||||
null = crypto_get_default_null_skcipher();
|
|
||||||
err = PTR_ERR(null);
|
|
||||||
if (IS_ERR(null))
|
|
||||||
goto err_free_skcipher;
|
|
||||||
|
|
||||||
ctx->auth = auth;
|
ctx->auth = auth;
|
||||||
ctx->enc = enc;
|
ctx->enc = enc;
|
||||||
ctx->null = null;
|
|
||||||
|
|
||||||
crypto_aead_set_reqsize(
|
crypto_aead_set_reqsize(
|
||||||
tfm,
|
tfm,
|
||||||
|
@ -336,8 +309,6 @@ static int crypto_authenc_init_tfm(struct crypto_aead *tfm)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_free_skcipher:
|
|
||||||
crypto_free_skcipher(enc);
|
|
||||||
err_free_ahash:
|
err_free_ahash:
|
||||||
crypto_free_ahash(auth);
|
crypto_free_ahash(auth);
|
||||||
return err;
|
return err;
|
||||||
|
@ -349,7 +320,6 @@ static void crypto_authenc_exit_tfm(struct crypto_aead *tfm)
|
||||||
|
|
||||||
crypto_free_ahash(ctx->auth);
|
crypto_free_ahash(ctx->auth);
|
||||||
crypto_free_skcipher(ctx->enc);
|
crypto_free_skcipher(ctx->enc);
|
||||||
crypto_put_default_null_skcipher();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void crypto_authenc_free(struct aead_instance *inst)
|
static void crypto_authenc_free(struct aead_instance *inst)
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include <crypto/internal/hash.h>
|
#include <crypto/internal/hash.h>
|
||||||
#include <crypto/internal/skcipher.h>
|
#include <crypto/internal/skcipher.h>
|
||||||
#include <crypto/authenc.h>
|
#include <crypto/authenc.h>
|
||||||
#include <crypto/null.h>
|
|
||||||
#include <crypto/scatterwalk.h>
|
#include <crypto/scatterwalk.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
|
@ -31,7 +30,6 @@ struct crypto_authenc_esn_ctx {
|
||||||
unsigned int reqoff;
|
unsigned int reqoff;
|
||||||
struct crypto_ahash *auth;
|
struct crypto_ahash *auth;
|
||||||
struct crypto_skcipher *enc;
|
struct crypto_skcipher *enc;
|
||||||
struct crypto_sync_skcipher *null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct authenc_esn_request_ctx {
|
struct authenc_esn_request_ctx {
|
||||||
|
@ -158,20 +156,6 @@ static void crypto_authenc_esn_encrypt_done(void *data, int err)
|
||||||
authenc_esn_request_complete(areq, err);
|
authenc_esn_request_complete(areq, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int crypto_authenc_esn_copy(struct aead_request *req, unsigned int len)
|
|
||||||
{
|
|
||||||
struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req);
|
|
||||||
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn);
|
|
||||||
SYNC_SKCIPHER_REQUEST_ON_STACK(skreq, ctx->null);
|
|
||||||
|
|
||||||
skcipher_request_set_sync_tfm(skreq, ctx->null);
|
|
||||||
skcipher_request_set_callback(skreq, aead_request_flags(req),
|
|
||||||
NULL, NULL);
|
|
||||||
skcipher_request_set_crypt(skreq, req->src, req->dst, len, NULL);
|
|
||||||
|
|
||||||
return crypto_skcipher_encrypt(skreq);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int crypto_authenc_esn_encrypt(struct aead_request *req)
|
static int crypto_authenc_esn_encrypt(struct aead_request *req)
|
||||||
{
|
{
|
||||||
struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req);
|
struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req);
|
||||||
|
@ -190,10 +174,7 @@ static int crypto_authenc_esn_encrypt(struct aead_request *req)
|
||||||
dst = src;
|
dst = src;
|
||||||
|
|
||||||
if (req->src != req->dst) {
|
if (req->src != req->dst) {
|
||||||
err = crypto_authenc_esn_copy(req, assoclen);
|
memcpy_sglist(req->dst, req->src, assoclen);
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
sg_init_table(areq_ctx->dst, 2);
|
sg_init_table(areq_ctx->dst, 2);
|
||||||
dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, assoclen);
|
dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, assoclen);
|
||||||
}
|
}
|
||||||
|
@ -277,11 +258,8 @@ static int crypto_authenc_esn_decrypt(struct aead_request *req)
|
||||||
|
|
||||||
cryptlen -= authsize;
|
cryptlen -= authsize;
|
||||||
|
|
||||||
if (req->src != dst) {
|
if (req->src != dst)
|
||||||
err = crypto_authenc_esn_copy(req, assoclen + cryptlen);
|
memcpy_sglist(dst, req->src, assoclen + cryptlen);
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
scatterwalk_map_and_copy(ihash, req->src, assoclen + cryptlen,
|
scatterwalk_map_and_copy(ihash, req->src, assoclen + cryptlen,
|
||||||
authsize, 0);
|
authsize, 0);
|
||||||
|
@ -317,7 +295,6 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
|
||||||
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm);
|
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm);
|
||||||
struct crypto_ahash *auth;
|
struct crypto_ahash *auth;
|
||||||
struct crypto_skcipher *enc;
|
struct crypto_skcipher *enc;
|
||||||
struct crypto_sync_skcipher *null;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
auth = crypto_spawn_ahash(&ictx->auth);
|
auth = crypto_spawn_ahash(&ictx->auth);
|
||||||
|
@ -329,14 +306,8 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
|
||||||
if (IS_ERR(enc))
|
if (IS_ERR(enc))
|
||||||
goto err_free_ahash;
|
goto err_free_ahash;
|
||||||
|
|
||||||
null = crypto_get_default_null_skcipher();
|
|
||||||
err = PTR_ERR(null);
|
|
||||||
if (IS_ERR(null))
|
|
||||||
goto err_free_skcipher;
|
|
||||||
|
|
||||||
ctx->auth = auth;
|
ctx->auth = auth;
|
||||||
ctx->enc = enc;
|
ctx->enc = enc;
|
||||||
ctx->null = null;
|
|
||||||
|
|
||||||
ctx->reqoff = 2 * crypto_ahash_digestsize(auth);
|
ctx->reqoff = 2 * crypto_ahash_digestsize(auth);
|
||||||
|
|
||||||
|
@ -352,8 +323,6 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_free_skcipher:
|
|
||||||
crypto_free_skcipher(enc);
|
|
||||||
err_free_ahash:
|
err_free_ahash:
|
||||||
crypto_free_ahash(auth);
|
crypto_free_ahash(auth);
|
||||||
return err;
|
return err;
|
||||||
|
@ -365,7 +334,6 @@ static void crypto_authenc_esn_exit_tfm(struct crypto_aead *tfm)
|
||||||
|
|
||||||
crypto_free_ahash(ctx->auth);
|
crypto_free_ahash(ctx->auth);
|
||||||
crypto_free_skcipher(ctx->enc);
|
crypto_free_skcipher(ctx->enc);
|
||||||
crypto_put_default_null_skcipher();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void crypto_authenc_esn_free(struct aead_instance *inst)
|
static void crypto_authenc_esn_free(struct aead_instance *inst)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue