From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 238383750CC; Thu, 30 Apr 2026 06:09:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777529356; cv=none; b=RSWaXcLRf07f1ubzKGWwYMYWRNcUtwGbsu/xSZMIJvrGlgs8C/66vXXYMSRdbZQKGma1OOmaYRYa2VnldYcj0yp95hBY3R4rkIefl5rANbJ0B7unHO9Jnm484f2jDSOX18SAKCHz9uHPCpCp0NLo+Fr069tdgPOADMvssO/4XVc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777529356; c=relaxed/simple; bh=4d5EDyLs11jBmxuUG8dvj234Q2eJ/kWwVW7Mbp/ixqI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h9UtUQ+yhbXGpqlF2titpnZPCRje/UhXA16gmxkIjGRvW3o4migcQMgG9WUAbiLFOcTdD7xEzjf6JSHta/eKUqnAWt37PB/CszHbrogcPxNiLxlNExghruE4N/LaT+m9wpu7SrOS5i5Z0euLXralSwa6yrYDPpCayfs3Xc2cIuI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aaSgms4V; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aaSgms4V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6938C2BCB8; Thu, 30 Apr 2026 06:09:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777529355; bh=4d5EDyLs11jBmxuUG8dvj234Q2eJ/kWwVW7Mbp/ixqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aaSgms4VyC64NrOTgmgpkVHT61kqoPEFxZF5hune/pauq+AWZl7zDSmzb592IMNll cJkpPohx4Jh7ICUn/sHcsoG2Un136a2+1Y5NGalFJztuPvYni1FXqARx79vH/3c/v4 TA7zI8PoD2r6UviKm8Aby3NBb8czxHoyaav7+QOH3sQqa8CM6FD0k+12zID/m/ZGyz SVqUCON1Q+j3O9l0kN0ja/FeEhwfZaNkJ1rhWJPj1sv7lIx0DNMt9p3t/eFSC65TU2 kNILwVt2fvIqrgDNxqfW7wnjBznOEPOasgJsMe4becUAUPjkz8w7aEntox9WqHXiHC 9ElAZ8kYINpzw== From: Eric Biggers To: stable@vger.kernel.org Cc: linux-crypto@vger.kernel.org, Herbert Xu , Eric Biggers , Eric Biggers Subject: [PATCH 6.12 5/8] crypto: authenc - use memcpy_sglist() instead of null skcipher Date: Wed, 29 Apr 2026 23:06:59 -0700 Message-ID: <20260430060702.110091-6-ebiggers@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260430060702.110091-1-ebiggers@kernel.org> References: <20260430060702.110091-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Eric Biggers commit dbc4b1458e931e47198c3165ff5853bc1ad6bd7a upstream. 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 Signed-off-by: Herbert Xu Signed-off-by: Eric Biggers --- 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 c2d0622d99b8..a997e97937e0 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -220,11 +220,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 d04068af9833..f1f7886bb34c 100644 --- a/crypto/authenc.c +++ b/crypto/authenc.c @@ -7,11 +7,10 @@ #include #include #include #include -#include #include #include #include #include #include @@ -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]; @@ -184,25 +182,10 @@ static void crypto_authenc_encrypt_done(void *data, int err) } err = crypto_authenc_genicv(areq, CRYPTO_TFM_REQ_MAY_SLEEP); 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); @@ -217,14 +200,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), @@ -326,11 +306,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); @@ -338,18 +317,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 + @@ -359,12 +332,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; } @@ -372,11 +343,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 e08032e80f18..a5fbb638d9d7 100644 --- a/crypto/authencesn.c +++ b/crypto/authencesn.c @@ -10,11 +10,10 @@ #include #include #include #include -#include #include #include #include #include #include @@ -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); @@ -191,14 +175,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); @@ -281,15 +262,12 @@ static int crypto_authenc_esn_decrypt(struct aead_request *req) if (assoclen < 8) return -EINVAL; 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) @@ -321,11 +299,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); @@ -333,18 +310,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, @@ -356,12 +327,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; } @@ -369,11 +338,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.54.0