* [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher
@ 2025-05-05 19:10 Eric Biggers
2025-05-05 19:10 ` [PATCH 1/8] crypto: algif_aead - " Eric Biggers
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Eric Biggers @ 2025-05-05 19:10 UTC (permalink / raw)
To: linux-crypto
For copying data between two scatterlists, just use memcpy_sglist()
instead of the so-called "null skcipher". This is much simpler.
Eric Biggers (8):
crypto: algif_aead - use memcpy_sglist() instead of null skcipher
crypto: authenc - use memcpy_sglist() instead of null skcipher
crypto: gcm - use memcpy_sglist() instead of null skcipher
crypto: geniv - use memcpy_sglist() instead of null skcipher
crypto: krb5enc - do not select CRYPTO_NULL
crypto: null - remove the default null skcipher
crypto: null - merge CRYPTO_NULL2 into CRYPTO_NULL
crypto: null - use memcpy_sglist()
crypto/Kconfig | 15 +----
crypto/Makefile | 2 +-
crypto/algif_aead.c | 101 ++++++--------------------------
crypto/authenc.c | 32 +---------
crypto/authencesn.c | 38 +-----------
crypto/crypto_null.c | 70 ++--------------------
crypto/echainiv.c | 18 +-----
crypto/gcm.c | 41 ++-----------
crypto/geniv.c | 13 +---
crypto/seqiv.c | 17 +-----
include/crypto/internal/geniv.h | 1 -
include/crypto/null.h | 3 -
12 files changed, 41 insertions(+), 310 deletions(-)
base-commit: 64745a9ca890ed60d78162ec511e1983e1946d73
--
2.49.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/8] crypto: algif_aead - use memcpy_sglist() instead of null skcipher
2025-05-05 19:10 [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Eric Biggers
@ 2025-05-05 19:10 ` Eric Biggers
2025-05-05 19:10 ` [PATCH 2/8] crypto: authenc " Eric Biggers
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-05-05 19:10 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
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>
---
crypto/Kconfig | 1 -
crypto/algif_aead.c | 101 ++++++++------------------------------------
2 files changed, 18 insertions(+), 84 deletions(-)
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 7bfad077f308..551eeeab3a0a 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1390,11 +1390,10 @@ config CRYPTO_USER_API_RNG_CAVP
config CRYPTO_USER_API_AEAD
tristate "AEAD cipher algorithms"
depends on NET
select CRYPTO_AEAD
select CRYPTO_SKCIPHER
- select CRYPTO_NULL
select CRYPTO_USER_API
help
Enable the userspace interface for AEAD cipher algorithms.
See Documentation/crypto/userspace-if.rst and
diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c
index 7d58cbbce4af..79b016a899a1 100644
--- a/crypto/algif_aead.c
+++ b/crypto/algif_aead.c
@@ -25,32 +25,25 @@
#include <crypto/internal/aead.h>
#include <crypto/scatterwalk.h>
#include <crypto/if_alg.h>
#include <crypto/skcipher.h>
-#include <crypto/null.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/net.h>
#include <net/sock.h>
-struct aead_tfm {
- struct crypto_aead *aead;
- struct crypto_sync_skcipher *null_tfm;
-};
-
static inline bool aead_sufficient_data(struct sock *sk)
{
struct alg_sock *ask = alg_sk(sk);
struct sock *psk = ask->parent;
struct alg_sock *pask = alg_sk(psk);
struct af_alg_ctx *ctx = ask->private;
- struct aead_tfm *aeadc = pask->private;
- struct crypto_aead *tfm = aeadc->aead;
+ struct crypto_aead *tfm = pask->private;
unsigned int as = crypto_aead_authsize(tfm);
/*
* The minimum amount of memory needed for an AEAD cipher is
* the AAD and in case of decryption the tag.
@@ -62,42 +55,25 @@ static int aead_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
{
struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk);
struct sock *psk = ask->parent;
struct alg_sock *pask = alg_sk(psk);
- struct aead_tfm *aeadc = pask->private;
- struct crypto_aead *tfm = aeadc->aead;
+ struct crypto_aead *tfm = pask->private;
unsigned int ivsize = crypto_aead_ivsize(tfm);
return af_alg_sendmsg(sock, msg, size, ivsize);
}
-static int crypto_aead_copy_sgl(struct crypto_sync_skcipher *null_tfm,
- struct scatterlist *src,
- struct scatterlist *dst, unsigned int len)
-{
- SYNC_SKCIPHER_REQUEST_ON_STACK(skreq, null_tfm);
-
- skcipher_request_set_sync_tfm(skreq, null_tfm);
- skcipher_request_set_callback(skreq, CRYPTO_TFM_REQ_MAY_SLEEP,
- NULL, NULL);
- skcipher_request_set_crypt(skreq, src, dst, len, NULL);
-
- return crypto_skcipher_encrypt(skreq);
-}
-
static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
size_t ignored, int flags)
{
struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk);
struct sock *psk = ask->parent;
struct alg_sock *pask = alg_sk(psk);
struct af_alg_ctx *ctx = ask->private;
- struct aead_tfm *aeadc = pask->private;
- struct crypto_aead *tfm = aeadc->aead;
- struct crypto_sync_skcipher *null_tfm = aeadc->null_tfm;
+ struct crypto_aead *tfm = pask->private;
unsigned int i, as = crypto_aead_authsize(tfm);
struct af_alg_async_req *areq;
struct af_alg_tsgl *tsgl, *tmp;
struct scatterlist *rsgl_src, *tsgl_src = NULL;
int err = 0;
@@ -221,15 +197,12 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
* | |
* | copy |
* v v
* RX SGL: AAD || PT || Tag
*/
- err = crypto_aead_copy_sgl(null_tfm, tsgl_src,
- areq->first_rsgl.sgl.sgt.sgl,
- processed);
- if (err)
- goto free;
+ memcpy_sglist(areq->first_rsgl.sgl.sgt.sgl, tsgl_src,
+ processed);
af_alg_pull_tsgl(sk, processed, NULL, 0);
} else {
/*
* Decryption operation - To achieve an in-place cipher
* operation, the following SGL structure is used:
@@ -239,16 +212,12 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
* | copy | | Create SGL link.
* v v |
* RX SGL: AAD || CT ----+
*/
- /* Copy AAD || CT to RX SGL buffer for in-place operation. */
- err = crypto_aead_copy_sgl(null_tfm, tsgl_src,
- areq->first_rsgl.sgl.sgt.sgl,
- outlen);
- if (err)
- goto free;
+ /* Copy AAD || CT to RX SGL buffer for in-place operation. */
+ memcpy_sglist(areq->first_rsgl.sgl.sgt.sgl, tsgl_src, outlen);
/* Create TX SGL for tag and chain it to RX SGL. */
areq->tsgl_entries = af_alg_count_tsgl(sk, processed,
processed - as);
if (!areq->tsgl_entries)
@@ -377,11 +346,11 @@ static struct proto_ops algif_aead_ops = {
static int aead_check_key(struct socket *sock)
{
int err = 0;
struct sock *psk;
struct alg_sock *pask;
- struct aead_tfm *tfm;
+ struct crypto_aead *tfm;
struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk);
lock_sock(sk);
if (!atomic_read(&ask->nokey_refcnt))
@@ -391,11 +360,11 @@ static int aead_check_key(struct socket *sock)
pask = alg_sk(ask->parent);
tfm = pask->private;
err = -ENOKEY;
lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
- if (crypto_aead_get_flags(tfm->aead) & CRYPTO_TFM_NEED_KEY)
+ if (crypto_aead_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
goto unlock;
atomic_dec(&pask->nokey_refcnt);
atomic_set(&ask->nokey_refcnt, 0);
@@ -452,68 +421,35 @@ static struct proto_ops algif_aead_ops_nokey = {
.poll = af_alg_poll,
};
static void *aead_bind(const char *name, u32 type, u32 mask)
{
- struct aead_tfm *tfm;
- struct crypto_aead *aead;
- struct crypto_sync_skcipher *null_tfm;
-
- tfm = kzalloc(sizeof(*tfm), GFP_KERNEL);
- if (!tfm)
- return ERR_PTR(-ENOMEM);
-
- aead = crypto_alloc_aead(name, type, mask);
- if (IS_ERR(aead)) {
- kfree(tfm);
- return ERR_CAST(aead);
- }
-
- null_tfm = crypto_get_default_null_skcipher();
- if (IS_ERR(null_tfm)) {
- crypto_free_aead(aead);
- kfree(tfm);
- return ERR_CAST(null_tfm);
- }
-
- tfm->aead = aead;
- tfm->null_tfm = null_tfm;
-
- return tfm;
+ return crypto_alloc_aead(name, type, mask);
}
static void aead_release(void *private)
{
- struct aead_tfm *tfm = private;
-
- crypto_free_aead(tfm->aead);
- crypto_put_default_null_skcipher();
- kfree(tfm);
+ crypto_free_aead(private);
}
static int aead_setauthsize(void *private, unsigned int authsize)
{
- struct aead_tfm *tfm = private;
-
- return crypto_aead_setauthsize(tfm->aead, authsize);
+ return crypto_aead_setauthsize(private, authsize);
}
static int aead_setkey(void *private, const u8 *key, unsigned int keylen)
{
- struct aead_tfm *tfm = private;
-
- return crypto_aead_setkey(tfm->aead, key, keylen);
+ return crypto_aead_setkey(private, key, keylen);
}
static void aead_sock_destruct(struct sock *sk)
{
struct alg_sock *ask = alg_sk(sk);
struct af_alg_ctx *ctx = ask->private;
struct sock *psk = ask->parent;
struct alg_sock *pask = alg_sk(psk);
- struct aead_tfm *aeadc = pask->private;
- struct crypto_aead *tfm = aeadc->aead;
+ struct crypto_aead *tfm = pask->private;
unsigned int ivlen = crypto_aead_ivsize(tfm);
af_alg_pull_tsgl(sk, ctx->used, NULL, 0);
sock_kzfree_s(sk, ctx->iv, ivlen);
sock_kfree_s(sk, ctx, ctx->len);
@@ -522,14 +458,13 @@ static void aead_sock_destruct(struct sock *sk)
static int aead_accept_parent_nokey(void *private, struct sock *sk)
{
struct af_alg_ctx *ctx;
struct alg_sock *ask = alg_sk(sk);
- struct aead_tfm *tfm = private;
- struct crypto_aead *aead = tfm->aead;
+ struct crypto_aead *tfm = private;
unsigned int len = sizeof(*ctx);
- unsigned int ivlen = crypto_aead_ivsize(aead);
+ unsigned int ivlen = crypto_aead_ivsize(tfm);
ctx = sock_kmalloc(sk, len, GFP_KERNEL);
if (!ctx)
return -ENOMEM;
memset(ctx, 0, len);
@@ -552,13 +487,13 @@ static int aead_accept_parent_nokey(void *private, struct sock *sk)
return 0;
}
static int aead_accept_parent(void *private, struct sock *sk)
{
- struct aead_tfm *tfm = private;
+ struct crypto_aead *tfm = private;
- if (crypto_aead_get_flags(tfm->aead) & CRYPTO_TFM_NEED_KEY)
+ if (crypto_aead_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
return -ENOKEY;
return aead_accept_parent_nokey(private, sk);
}
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/8] crypto: authenc - use memcpy_sglist() instead of null skcipher
2025-05-05 19:10 [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Eric Biggers
2025-05-05 19:10 ` [PATCH 1/8] crypto: algif_aead - " Eric Biggers
@ 2025-05-05 19:10 ` Eric Biggers
2025-05-05 19:10 ` [PATCH 3/8] crypto: gcm " Eric Biggers
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-05-05 19:10 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
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>
---
crypto/Kconfig | 1 -
crypto/authenc.c | 32 +-------------------------------
crypto/authencesn.c | 38 +++-----------------------------------
3 files changed, 4 insertions(+), 67 deletions(-)
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 551eeeab3a0a..537602b8e60e 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -226,11 +226,10 @@ config CRYPTO_AUTHENC
tristate "Authenc support"
select CRYPTO_AEAD
select CRYPTO_SKCIPHER
select CRYPTO_MANAGER
select CRYPTO_HASH
- select CRYPTO_NULL
help
Authenc: Combined mode wrapper for IPsec.
This is required for IPSec ESP (XFRM_ESP).
diff --git a/crypto/authenc.c b/crypto/authenc.c
index 9521ae2f112e..a723769c8777 100644
--- a/crypto/authenc.c
+++ b/crypto/authenc.c
@@ -7,11 +7,10 @@
#include <crypto/internal/aead.h>
#include <crypto/internal/hash.h>
#include <crypto/internal/skcipher.h>
#include <crypto/authenc.h>
-#include <crypto/null.h>
#include <crypto/scatterwalk.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -26,11 +25,10 @@ struct authenc_instance_ctx {
};
struct crypto_authenc_ctx {
struct crypto_ahash *auth;
struct crypto_skcipher *enc;
- struct crypto_sync_skcipher *null;
};
struct authenc_request_ctx {
struct scatterlist src[2];
struct scatterlist dst[2];
@@ -168,25 +166,10 @@ static void crypto_authenc_encrypt_done(void *data, int err)
out:
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)
{
struct crypto_aead *authenc = crypto_aead_reqtfm(req);
struct aead_instance *inst = aead_alg_instance(authenc);
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
@@ -201,14 +184,11 @@ static int crypto_authenc_encrypt(struct aead_request *req)
src = scatterwalk_ffwd(areq_ctx->src, req->src, req->assoclen);
dst = src;
if (req->src != req->dst) {
- err = crypto_authenc_copy_assoc(req);
- if (err)
- return err;
-
+ memcpy_sglist(req->dst, req->src, req->assoclen);
dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, req->assoclen);
}
skcipher_request_set_tfm(skreq, enc);
skcipher_request_set_callback(skreq, aead_request_flags(req),
@@ -301,11 +281,10 @@ static int crypto_authenc_init_tfm(struct crypto_aead *tfm)
struct aead_instance *inst = aead_alg_instance(tfm);
struct authenc_instance_ctx *ictx = aead_instance_ctx(inst);
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(tfm);
struct crypto_ahash *auth;
struct crypto_skcipher *enc;
- struct crypto_sync_skcipher *null;
int err;
auth = crypto_spawn_ahash(&ictx->auth);
if (IS_ERR(auth))
return PTR_ERR(auth);
@@ -313,18 +292,12 @@ static int crypto_authenc_init_tfm(struct crypto_aead *tfm)
enc = crypto_spawn_skcipher(&ictx->enc);
err = PTR_ERR(enc);
if (IS_ERR(enc))
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->enc = enc;
- ctx->null = null;
crypto_aead_set_reqsize(
tfm,
sizeof(struct authenc_request_ctx) +
ictx->reqoff +
@@ -334,12 +307,10 @@ static int crypto_authenc_init_tfm(struct crypto_aead *tfm)
sizeof(struct skcipher_request) +
crypto_skcipher_reqsize(enc)));
return 0;
-err_free_skcipher:
- crypto_free_skcipher(enc);
err_free_ahash:
crypto_free_ahash(auth);
return err;
}
@@ -347,11 +318,10 @@ static void crypto_authenc_exit_tfm(struct crypto_aead *tfm)
{
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(tfm);
crypto_free_ahash(ctx->auth);
crypto_free_skcipher(ctx->enc);
- crypto_put_default_null_skcipher();
}
static void crypto_authenc_free(struct aead_instance *inst)
{
struct authenc_instance_ctx *ctx = aead_instance_ctx(inst);
diff --git a/crypto/authencesn.c b/crypto/authencesn.c
index b1c78313cbc1..d1bf0fda3f2e 100644
--- a/crypto/authencesn.c
+++ b/crypto/authencesn.c
@@ -10,11 +10,10 @@
#include <crypto/internal/aead.h>
#include <crypto/internal/hash.h>
#include <crypto/internal/skcipher.h>
#include <crypto/authenc.h>
-#include <crypto/null.h>
#include <crypto/scatterwalk.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -29,11 +28,10 @@ struct authenc_esn_instance_ctx {
struct crypto_authenc_esn_ctx {
unsigned int reqoff;
struct crypto_ahash *auth;
struct crypto_skcipher *enc;
- struct crypto_sync_skcipher *null;
};
struct authenc_esn_request_ctx {
struct scatterlist src[2];
struct scatterlist dst[2];
@@ -156,24 +154,10 @@ static void crypto_authenc_esn_encrypt_done(void *data, int err)
err = crypto_authenc_esn_genicv(areq, 0);
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)
{
struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req);
struct authenc_esn_request_ctx *areq_ctx = aead_request_ctx(req);
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn);
@@ -188,14 +172,11 @@ static int crypto_authenc_esn_encrypt(struct aead_request *req)
sg_init_table(areq_ctx->src, 2);
src = scatterwalk_ffwd(areq_ctx->src, req->src, assoclen);
dst = src;
if (req->src != req->dst) {
- err = crypto_authenc_esn_copy(req, assoclen);
- if (err)
- return err;
-
+ memcpy_sglist(req->dst, req->src, assoclen);
sg_init_table(areq_ctx->dst, 2);
dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, assoclen);
}
skcipher_request_set_tfm(skreq, enc);
@@ -275,15 +256,12 @@ static int crypto_authenc_esn_decrypt(struct aead_request *req)
u32 tmp[2];
int err;
cryptlen -= authsize;
- if (req->src != dst) {
- err = crypto_authenc_esn_copy(req, assoclen + cryptlen);
- if (err)
- return err;
- }
+ if (req->src != dst)
+ memcpy_sglist(dst, req->src, assoclen + cryptlen);
scatterwalk_map_and_copy(ihash, req->src, assoclen + cryptlen,
authsize, 0);
if (!authsize)
@@ -315,11 +293,10 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
struct aead_instance *inst = aead_alg_instance(tfm);
struct authenc_esn_instance_ctx *ictx = aead_instance_ctx(inst);
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm);
struct crypto_ahash *auth;
struct crypto_skcipher *enc;
- struct crypto_sync_skcipher *null;
int err;
auth = crypto_spawn_ahash(&ictx->auth);
if (IS_ERR(auth))
return PTR_ERR(auth);
@@ -327,18 +304,12 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
enc = crypto_spawn_skcipher(&ictx->enc);
err = PTR_ERR(enc);
if (IS_ERR(enc))
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->enc = enc;
- ctx->null = null;
ctx->reqoff = 2 * crypto_ahash_digestsize(auth);
crypto_aead_set_reqsize(
tfm,
@@ -350,12 +321,10 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
sizeof(struct skcipher_request) +
crypto_skcipher_reqsize(enc)));
return 0;
-err_free_skcipher:
- crypto_free_skcipher(enc);
err_free_ahash:
crypto_free_ahash(auth);
return err;
}
@@ -363,11 +332,10 @@ static void crypto_authenc_esn_exit_tfm(struct crypto_aead *tfm)
{
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm);
crypto_free_ahash(ctx->auth);
crypto_free_skcipher(ctx->enc);
- crypto_put_default_null_skcipher();
}
static void crypto_authenc_esn_free(struct aead_instance *inst)
{
struct authenc_esn_instance_ctx *ctx = aead_instance_ctx(inst);
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/8] crypto: gcm - use memcpy_sglist() instead of null skcipher
2025-05-05 19:10 [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Eric Biggers
2025-05-05 19:10 ` [PATCH 1/8] crypto: algif_aead - " Eric Biggers
2025-05-05 19:10 ` [PATCH 2/8] crypto: authenc " Eric Biggers
@ 2025-05-05 19:10 ` Eric Biggers
2025-05-05 19:10 ` [PATCH 4/8] crypto: geniv " Eric Biggers
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-05-05 19:10 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
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>
---
crypto/Kconfig | 1 -
crypto/gcm.c | 41 ++++-------------------------------------
2 files changed, 4 insertions(+), 38 deletions(-)
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 537602b8e60e..231791703594 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -803,11 +803,10 @@ config CRYPTO_CCM
config CRYPTO_GCM
tristate "GCM (Galois/Counter Mode) and GMAC (GCM MAC)"
select CRYPTO_CTR
select CRYPTO_AEAD
select CRYPTO_GHASH
- select CRYPTO_NULL
select CRYPTO_MANAGER
help
GCM (Galois/Counter Mode) authenticated encryption mode and GMAC
(GCM Message Authentication Code) (NIST SP800-38D)
diff --git a/crypto/gcm.c b/crypto/gcm.c
index 54ca9faf0e0c..97716482bed0 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -7,11 +7,10 @@
#include <crypto/gf128mul.h>
#include <crypto/internal/aead.h>
#include <crypto/internal/skcipher.h>
#include <crypto/internal/hash.h>
-#include <crypto/null.h>
#include <crypto/scatterwalk.h>
#include <crypto/gcm.h>
#include <crypto/hash.h>
#include <linux/err.h>
#include <linux/init.h>
@@ -44,11 +43,10 @@ struct crypto_rfc4543_instance_ctx {
struct crypto_aead_spawn aead;
};
struct crypto_rfc4543_ctx {
struct crypto_aead *child;
- struct crypto_sync_skcipher *null;
u8 nonce[4];
};
struct crypto_rfc4543_req_ctx {
struct aead_request subreq;
@@ -77,12 +75,10 @@ struct crypto_gcm_req_priv_ctx {
static struct {
u8 buf[16];
struct scatterlist sg;
} *gcm_zeroes;
-static int crypto_rfc4543_copy_src_to_dst(struct aead_request *req, bool enc);
-
static inline struct crypto_gcm_req_priv_ctx *crypto_gcm_reqctx(
struct aead_request *req)
{
unsigned long align = crypto_aead_alignmask(crypto_aead_reqtfm(req));
@@ -928,16 +924,16 @@ static int crypto_rfc4543_crypt(struct aead_request *req, bool enc)
struct crypto_rfc4543_req_ctx *rctx = aead_request_ctx(req);
struct aead_request *subreq = &rctx->subreq;
unsigned int authsize = crypto_aead_authsize(aead);
u8 *iv = PTR_ALIGN((u8 *)(rctx + 1) + crypto_aead_reqsize(ctx->child),
crypto_aead_alignmask(ctx->child) + 1);
- int err;
if (req->src != req->dst) {
- err = crypto_rfc4543_copy_src_to_dst(req, enc);
- if (err)
- return err;
+ unsigned int nbytes = req->assoclen + req->cryptlen -
+ (enc ? 0 : authsize);
+
+ memcpy_sglist(req->dst, req->src, nbytes);
}
memcpy(iv, ctx->nonce, 4);
memcpy(iv + 4, req->iv, 8);
@@ -950,26 +946,10 @@ static int crypto_rfc4543_crypt(struct aead_request *req, bool enc)
subreq->cryptlen);
return enc ? crypto_aead_encrypt(subreq) : crypto_aead_decrypt(subreq);
}
-static int crypto_rfc4543_copy_src_to_dst(struct aead_request *req, bool enc)
-{
- struct crypto_aead *aead = crypto_aead_reqtfm(req);
- struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(aead);
- unsigned int authsize = crypto_aead_authsize(aead);
- unsigned int nbytes = req->assoclen + req->cryptlen -
- (enc ? 0 : authsize);
- SYNC_SKCIPHER_REQUEST_ON_STACK(nreq, ctx->null);
-
- skcipher_request_set_sync_tfm(nreq, ctx->null);
- skcipher_request_set_callback(nreq, req->base.flags, NULL, NULL);
- skcipher_request_set_crypt(nreq, req->src, req->dst, nbytes, NULL);
-
- return crypto_skcipher_encrypt(nreq);
-}
-
static int crypto_rfc4543_encrypt(struct aead_request *req)
{
return crypto_ipsec_check_assoclen(req->assoclen) ?:
crypto_rfc4543_crypt(req, true);
}
@@ -985,47 +965,34 @@ static int crypto_rfc4543_init_tfm(struct crypto_aead *tfm)
struct aead_instance *inst = aead_alg_instance(tfm);
struct crypto_rfc4543_instance_ctx *ictx = aead_instance_ctx(inst);
struct crypto_aead_spawn *spawn = &ictx->aead;
struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(tfm);
struct crypto_aead *aead;
- struct crypto_sync_skcipher *null;
unsigned long align;
- int err = 0;
aead = crypto_spawn_aead(spawn);
if (IS_ERR(aead))
return PTR_ERR(aead);
- null = crypto_get_default_null_skcipher();
- err = PTR_ERR(null);
- if (IS_ERR(null))
- goto err_free_aead;
-
ctx->child = aead;
- ctx->null = null;
align = crypto_aead_alignmask(aead);
align &= ~(crypto_tfm_ctx_alignment() - 1);
crypto_aead_set_reqsize(
tfm,
sizeof(struct crypto_rfc4543_req_ctx) +
ALIGN(crypto_aead_reqsize(aead), crypto_tfm_ctx_alignment()) +
align + GCM_AES_IV_SIZE);
return 0;
-
-err_free_aead:
- crypto_free_aead(aead);
- return err;
}
static void crypto_rfc4543_exit_tfm(struct crypto_aead *tfm)
{
struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(tfm);
crypto_free_aead(ctx->child);
- crypto_put_default_null_skcipher();
}
static void crypto_rfc4543_free(struct aead_instance *inst)
{
struct crypto_rfc4543_instance_ctx *ctx = aead_instance_ctx(inst);
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/8] crypto: geniv - use memcpy_sglist() instead of null skcipher
2025-05-05 19:10 [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Eric Biggers
` (2 preceding siblings ...)
2025-05-05 19:10 ` [PATCH 3/8] crypto: gcm " Eric Biggers
@ 2025-05-05 19:10 ` Eric Biggers
2025-05-05 19:10 ` [PATCH 5/8] crypto: krb5enc - do not select CRYPTO_NULL Eric Biggers
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-05-05 19:10 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
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>
---
crypto/Kconfig | 1 -
crypto/echainiv.c | 18 +++---------------
crypto/geniv.c | 13 +------------
crypto/seqiv.c | 17 +++--------------
include/crypto/internal/geniv.h | 1 -
5 files changed, 7 insertions(+), 43 deletions(-)
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 231791703594..f0c8cc5e30ae 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -813,11 +813,10 @@ config CRYPTO_GCM
This is required for IPSec ESP (XFRM_ESP).
config CRYPTO_GENIV
tristate
select CRYPTO_AEAD
- select CRYPTO_NULL
select CRYPTO_MANAGER
select CRYPTO_RNG_DEFAULT
config CRYPTO_SEQIV
tristate "Sequence Number IV Generator"
diff --git a/crypto/echainiv.c b/crypto/echainiv.c
index 1913be8dfbba..e0a2d3209938 100644
--- a/crypto/echainiv.c
+++ b/crypto/echainiv.c
@@ -30,33 +30,21 @@ static int echainiv_encrypt(struct aead_request *req)
struct aead_request *subreq = aead_request_ctx(req);
__be64 nseqno;
u64 seqno;
u8 *info;
unsigned int ivsize = crypto_aead_ivsize(geniv);
- int err;
if (req->cryptlen < ivsize)
return -EINVAL;
aead_request_set_tfm(subreq, ctx->child);
info = req->iv;
- if (req->src != req->dst) {
- SYNC_SKCIPHER_REQUEST_ON_STACK(nreq, ctx->sknull);
-
- skcipher_request_set_sync_tfm(nreq, ctx->sknull);
- skcipher_request_set_callback(nreq, req->base.flags,
- NULL, NULL);
- skcipher_request_set_crypt(nreq, req->src, req->dst,
- req->assoclen + req->cryptlen,
- NULL);
-
- err = crypto_skcipher_encrypt(nreq);
- if (err)
- return err;
- }
+ if (req->src != req->dst)
+ memcpy_sglist(req->dst, req->src,
+ req->assoclen + req->cryptlen);
aead_request_set_callback(subreq, req->base.flags,
req->base.complete, req->base.data);
aead_request_set_crypt(subreq, req->dst, req->dst,
req->cryptlen, info);
diff --git a/crypto/geniv.c b/crypto/geniv.c
index bee4621b4f12..42eff6a7387c 100644
--- a/crypto/geniv.c
+++ b/crypto/geniv.c
@@ -7,11 +7,10 @@
* Copyright (c) 2007-2019 Herbert Xu <herbert@gondor.apana.org.au>
*/
#include <crypto/internal/geniv.h>
#include <crypto/internal/rng.h>
-#include <crypto/null.h>
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/rtnetlink.h>
#include <linux/slab.h>
@@ -123,41 +122,31 @@ int aead_init_geniv(struct crypto_aead *aead)
crypto_aead_ivsize(aead));
crypto_put_default_rng();
if (err)
goto out;
- ctx->sknull = crypto_get_default_null_skcipher();
- err = PTR_ERR(ctx->sknull);
- if (IS_ERR(ctx->sknull))
- goto out;
-
child = crypto_spawn_aead(aead_instance_ctx(inst));
err = PTR_ERR(child);
if (IS_ERR(child))
- goto drop_null;
+ goto out;
ctx->child = child;
crypto_aead_set_reqsize(aead, crypto_aead_reqsize(child) +
sizeof(struct aead_request));
err = 0;
out:
return err;
-
-drop_null:
- crypto_put_default_null_skcipher();
- goto out;
}
EXPORT_SYMBOL_GPL(aead_init_geniv);
void aead_exit_geniv(struct crypto_aead *tfm)
{
struct aead_geniv_ctx *ctx = crypto_aead_ctx(tfm);
crypto_free_aead(ctx->child);
- crypto_put_default_null_skcipher();
}
EXPORT_SYMBOL_GPL(aead_exit_geniv);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Shared IV generator code");
diff --git a/crypto/seqiv.c b/crypto/seqiv.c
index a17ef5184398..2bae99e33526 100644
--- a/crypto/seqiv.c
+++ b/crypto/seqiv.c
@@ -62,24 +62,13 @@ static int seqiv_aead_encrypt(struct aead_request *req)
compl = req->base.complete;
data = req->base.data;
info = req->iv;
- if (req->src != req->dst) {
- SYNC_SKCIPHER_REQUEST_ON_STACK(nreq, ctx->sknull);
-
- skcipher_request_set_sync_tfm(nreq, ctx->sknull);
- skcipher_request_set_callback(nreq, req->base.flags,
- NULL, NULL);
- skcipher_request_set_crypt(nreq, req->src, req->dst,
- req->assoclen + req->cryptlen,
- NULL);
-
- err = crypto_skcipher_encrypt(nreq);
- if (err)
- return err;
- }
+ if (req->src != req->dst)
+ memcpy_sglist(req->dst, req->src,
+ req->assoclen + req->cryptlen);
if (unlikely(!IS_ALIGNED((unsigned long)info,
crypto_aead_alignmask(geniv) + 1))) {
info = kmemdup(req->iv, ivsize, req->base.flags &
CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL :
diff --git a/include/crypto/internal/geniv.h b/include/crypto/internal/geniv.h
index 7fd7126f593a..012f5fb22d43 100644
--- a/include/crypto/internal/geniv.h
+++ b/include/crypto/internal/geniv.h
@@ -13,11 +13,10 @@
#include <linux/types.h>
struct aead_geniv_ctx {
spinlock_t lock;
struct crypto_aead *child;
- struct crypto_sync_skcipher *sknull;
u8 salt[] __attribute__ ((aligned(__alignof__(u32))));
};
struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
struct rtattr **tb);
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/8] crypto: krb5enc - do not select CRYPTO_NULL
2025-05-05 19:10 [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Eric Biggers
` (3 preceding siblings ...)
2025-05-05 19:10 ` [PATCH 4/8] crypto: geniv " Eric Biggers
@ 2025-05-05 19:10 ` Eric Biggers
2025-05-05 19:10 ` [PATCH 6/8] crypto: null - remove the default null skcipher Eric Biggers
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-05-05 19:10 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
The krb5enc code does not use any of the so-called "null algorithms", so
it does not need to select CRYPTO_NULL. Presumably this unused
dependency got copied from one of the other kconfig options.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/Kconfig | 1 -
1 file changed, 1 deletion(-)
diff --git a/crypto/Kconfig b/crypto/Kconfig
index f0c8cc5e30ae..cf5a427bb54d 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -237,11 +237,10 @@ config CRYPTO_KRB5ENC
tristate "Kerberos 5 combined hash+cipher support"
select CRYPTO_AEAD
select CRYPTO_SKCIPHER
select CRYPTO_MANAGER
select CRYPTO_HASH
- select CRYPTO_NULL
help
Combined hash and cipher support for Kerberos 5 RFC3961 simplified
profile. This is required for Kerberos 5-style encryption, used by
sunrpc/NFS and rxrpc/AFS.
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/8] crypto: null - remove the default null skcipher
2025-05-05 19:10 [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Eric Biggers
` (4 preceding siblings ...)
2025-05-05 19:10 ` [PATCH 5/8] crypto: krb5enc - do not select CRYPTO_NULL Eric Biggers
@ 2025-05-05 19:10 ` Eric Biggers
2025-05-05 19:10 ` [PATCH 7/8] crypto: null - merge CRYPTO_NULL2 into CRYPTO_NULL Eric Biggers
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-05-05 19:10 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
crypto_get_default_null_skcipher() and
crypto_put_default_null_skcipher() are no longer used, so remove them.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/crypto_null.c | 53 -------------------------------------------
include/crypto/null.h | 3 ---
2 files changed, 56 deletions(-)
diff --git a/crypto/crypto_null.c b/crypto/crypto_null.c
index 5822753b0995..48c71b925f37 100644
--- a/crypto/crypto_null.c
+++ b/crypto/crypto_null.c
@@ -15,17 +15,12 @@
#include <crypto/null.h>
#include <crypto/internal/hash.h>
#include <crypto/internal/skcipher.h>
#include <linux/init.h>
#include <linux/module.h>
-#include <linux/spinlock.h>
#include <linux/string.h>
-static DEFINE_SPINLOCK(crypto_default_null_skcipher_lock);
-static struct crypto_sync_skcipher *crypto_default_null_skcipher;
-static int crypto_default_null_skcipher_refcnt;
-
static int null_init(struct shash_desc *desc)
{
return 0;
}
@@ -127,58 +122,10 @@ static struct crypto_alg cipher_null = {
};
MODULE_ALIAS_CRYPTO("digest_null");
MODULE_ALIAS_CRYPTO("cipher_null");
-struct crypto_sync_skcipher *crypto_get_default_null_skcipher(void)
-{
- struct crypto_sync_skcipher *ntfm = NULL;
- struct crypto_sync_skcipher *tfm;
-
- spin_lock_bh(&crypto_default_null_skcipher_lock);
- tfm = crypto_default_null_skcipher;
-
- if (!tfm) {
- spin_unlock_bh(&crypto_default_null_skcipher_lock);
-
- ntfm = crypto_alloc_sync_skcipher("ecb(cipher_null)", 0, 0);
- if (IS_ERR(ntfm))
- return ntfm;
-
- spin_lock_bh(&crypto_default_null_skcipher_lock);
- tfm = crypto_default_null_skcipher;
- if (!tfm) {
- tfm = ntfm;
- ntfm = NULL;
- crypto_default_null_skcipher = tfm;
- }
- }
-
- crypto_default_null_skcipher_refcnt++;
- spin_unlock_bh(&crypto_default_null_skcipher_lock);
-
- crypto_free_sync_skcipher(ntfm);
-
- return tfm;
-}
-EXPORT_SYMBOL_GPL(crypto_get_default_null_skcipher);
-
-void crypto_put_default_null_skcipher(void)
-{
- struct crypto_sync_skcipher *tfm = NULL;
-
- spin_lock_bh(&crypto_default_null_skcipher_lock);
- if (!--crypto_default_null_skcipher_refcnt) {
- tfm = crypto_default_null_skcipher;
- crypto_default_null_skcipher = NULL;
- }
- spin_unlock_bh(&crypto_default_null_skcipher_lock);
-
- crypto_free_sync_skcipher(tfm);
-}
-EXPORT_SYMBOL_GPL(crypto_put_default_null_skcipher);
-
static int __init crypto_null_mod_init(void)
{
int ret = 0;
ret = crypto_register_alg(&cipher_null);
diff --git a/include/crypto/null.h b/include/crypto/null.h
index 0ef577cc00e3..1c66abf9de3b 100644
--- a/include/crypto/null.h
+++ b/include/crypto/null.h
@@ -7,9 +7,6 @@
#define NULL_KEY_SIZE 0
#define NULL_BLOCK_SIZE 1
#define NULL_DIGEST_SIZE 0
#define NULL_IV_SIZE 0
-struct crypto_sync_skcipher *crypto_get_default_null_skcipher(void);
-void crypto_put_default_null_skcipher(void);
-
#endif
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 7/8] crypto: null - merge CRYPTO_NULL2 into CRYPTO_NULL
2025-05-05 19:10 [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Eric Biggers
` (5 preceding siblings ...)
2025-05-05 19:10 ` [PATCH 6/8] crypto: null - remove the default null skcipher Eric Biggers
@ 2025-05-05 19:10 ` Eric Biggers
2025-05-05 19:10 ` [PATCH 8/8] crypto: null - use memcpy_sglist() Eric Biggers
2025-05-12 5:46 ` [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Herbert Xu
8 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-05-05 19:10 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
There is no reason to have separate CRYPTO_NULL2 and CRYPTO_NULL
options. Just merge them into CRYPTO_NULL.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/Kconfig | 10 +++-------
crypto/Makefile | 2 +-
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/crypto/Kconfig b/crypto/Kconfig
index cf5a427bb54d..7347277bedf3 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -190,20 +190,16 @@ config CRYPTO_MANAGER_EXTRA_TESTS
This is intended for developer use only, as these tests take much
longer to run than the normal self tests.
config CRYPTO_NULL
tristate "Null algorithms"
- select CRYPTO_NULL2
+ select CRYPTO_ALGAPI
+ select CRYPTO_SKCIPHER
+ select CRYPTO_HASH
help
These are 'Null' algorithms, used by IPsec, which do nothing.
-config CRYPTO_NULL2
- tristate
- select CRYPTO_ALGAPI2
- select CRYPTO_SKCIPHER2
- select CRYPTO_HASH2
-
config CRYPTO_PCRYPT
tristate "Parallel crypto engine"
depends on SMP
select PADATA
select CRYPTO_MANAGER
diff --git a/crypto/Makefile b/crypto/Makefile
index 84f6911dc9ba..0f77e093512c 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -69,11 +69,11 @@ cryptomgr-y := algboss.o testmgr.o
obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o
obj-$(CONFIG_CRYPTO_USER) += crypto_user.o
obj-$(CONFIG_CRYPTO_CMAC) += cmac.o
obj-$(CONFIG_CRYPTO_HMAC) += hmac.o
obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o
-obj-$(CONFIG_CRYPTO_NULL2) += crypto_null.o
+obj-$(CONFIG_CRYPTO_NULL) += crypto_null.o
obj-$(CONFIG_CRYPTO_MD4) += md4.o
obj-$(CONFIG_CRYPTO_MD5) += md5.o
obj-$(CONFIG_CRYPTO_RMD160) += rmd160.o
obj-$(CONFIG_CRYPTO_SHA1) += sha1_generic.o
obj-$(CONFIG_CRYPTO_SHA256) += sha256.o
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 8/8] crypto: null - use memcpy_sglist()
2025-05-05 19:10 [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Eric Biggers
` (6 preceding siblings ...)
2025-05-05 19:10 ` [PATCH 7/8] crypto: null - merge CRYPTO_NULL2 into CRYPTO_NULL Eric Biggers
@ 2025-05-05 19:10 ` Eric Biggers
2025-05-12 5:46 ` [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Herbert Xu
8 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-05-05 19:10 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Make null_skcipher_crypt() use memcpy_sglist() instead of the
skcipher_walk API, as this is simpler.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/crypto_null.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/crypto/crypto_null.c b/crypto/crypto_null.c
index 48c71b925f37..34588f39fdfc 100644
--- a/crypto/crypto_null.c
+++ b/crypto/crypto_null.c
@@ -13,10 +13,11 @@
*/
#include <crypto/null.h>
#include <crypto/internal/hash.h>
#include <crypto/internal/skcipher.h>
+#include <crypto/scatterwalk.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/string.h>
static int null_init(struct shash_desc *desc)
@@ -58,23 +59,13 @@ static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
memcpy(dst, src, NULL_BLOCK_SIZE);
}
static int null_skcipher_crypt(struct skcipher_request *req)
{
- struct skcipher_walk walk;
- int err;
-
- err = skcipher_walk_virt(&walk, req, false);
-
- while (walk.nbytes) {
- if (walk.src.virt.addr != walk.dst.virt.addr)
- memcpy(walk.dst.virt.addr, walk.src.virt.addr,
- walk.nbytes);
- err = skcipher_walk_done(&walk, 0);
- }
-
- return err;
+ if (req->src != req->dst)
+ memcpy_sglist(req->dst, req->src, req->cryptlen);
+ return 0;
}
static struct shash_alg digest_null = {
.digestsize = NULL_DIGEST_SIZE,
.setkey = null_hash_setkey,
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher
2025-05-05 19:10 [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Eric Biggers
` (7 preceding siblings ...)
2025-05-05 19:10 ` [PATCH 8/8] crypto: null - use memcpy_sglist() Eric Biggers
@ 2025-05-12 5:46 ` Herbert Xu
8 siblings, 0 replies; 10+ messages in thread
From: Herbert Xu @ 2025-05-12 5:46 UTC (permalink / raw)
To: Eric Biggers; +Cc: linux-crypto
Eric Biggers <ebiggers@kernel.org> wrote:
> For copying data between two scatterlists, just use memcpy_sglist()
> instead of the so-called "null skcipher". This is much simpler.
>
> Eric Biggers (8):
> crypto: algif_aead - use memcpy_sglist() instead of null skcipher
> crypto: authenc - use memcpy_sglist() instead of null skcipher
> crypto: gcm - use memcpy_sglist() instead of null skcipher
> crypto: geniv - use memcpy_sglist() instead of null skcipher
> crypto: krb5enc - do not select CRYPTO_NULL
> crypto: null - remove the default null skcipher
> crypto: null - merge CRYPTO_NULL2 into CRYPTO_NULL
> crypto: null - use memcpy_sglist()
>
> crypto/Kconfig | 15 +----
> crypto/Makefile | 2 +-
> crypto/algif_aead.c | 101 ++++++--------------------------
> crypto/authenc.c | 32 +---------
> crypto/authencesn.c | 38 +-----------
> crypto/crypto_null.c | 70 ++--------------------
> crypto/echainiv.c | 18 +-----
> crypto/gcm.c | 41 ++-----------
> crypto/geniv.c | 13 +---
> crypto/seqiv.c | 17 +-----
> include/crypto/internal/geniv.h | 1 -
> include/crypto/null.h | 3 -
> 12 files changed, 41 insertions(+), 310 deletions(-)
>
>
> base-commit: 64745a9ca890ed60d78162ec511e1983e1946d73
All applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-05-12 5:46 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-05 19:10 [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Eric Biggers
2025-05-05 19:10 ` [PATCH 1/8] crypto: algif_aead - " Eric Biggers
2025-05-05 19:10 ` [PATCH 2/8] crypto: authenc " Eric Biggers
2025-05-05 19:10 ` [PATCH 3/8] crypto: gcm " Eric Biggers
2025-05-05 19:10 ` [PATCH 4/8] crypto: geniv " Eric Biggers
2025-05-05 19:10 ` [PATCH 5/8] crypto: krb5enc - do not select CRYPTO_NULL Eric Biggers
2025-05-05 19:10 ` [PATCH 6/8] crypto: null - remove the default null skcipher Eric Biggers
2025-05-05 19:10 ` [PATCH 7/8] crypto: null - merge CRYPTO_NULL2 into CRYPTO_NULL Eric Biggers
2025-05-05 19:10 ` [PATCH 8/8] crypto: null - use memcpy_sglist() Eric Biggers
2025-05-12 5:46 ` [PATCH 0/8] crypto: use memcpy_sglist() instead of null skcipher Herbert Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.