From patchwork Mon May 5 19:10:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 887622 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 1F1A04A1D for ; Mon, 5 May 2025 19:11:36 +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=1746472297; cv=none; b=t1cHWi1re1zFYs7e3x30c40OC6vw+3iHGswRf3Ygxq5Q6jAYGivcBSthda6e9BbFao4S1PaskC9AjuDQyfT0u/GpWRqkwMkY/COH78+oPraOCb/FcggsnqzUTrjga92t2CUUvnbXSKtIWKQnHCqVOtSkbNPoMd9UROolNqL0kMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746472297; c=relaxed/simple; bh=W9GlfLupJ8un/8a0mB6DKsmxe5aVS/5mqb75tv8VGI8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ructC4uxDYrW3YWYIyledHYxUhirfllPMgaXPHXnK6jWyE/h1Ki2HjwsjUFcTDGhwbYRPDbJGe5gjHjzgBUWj9x6U3Yn7QzjrxutCP+Jm5AAfrWMlRDyjwcylTlw7CCjg+wNN+vR2Q9xE6dCJmeyQIo79/42FPkCZqHvvzxMbHw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LD62nloZ; 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="LD62nloZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C3FCC4CEEE for ; Mon, 5 May 2025 19:11:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746472296; bh=W9GlfLupJ8un/8a0mB6DKsmxe5aVS/5mqb75tv8VGI8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LD62nloZTuOi3cJ4GmNB+ylbY7aH+Pzg8iUPlpvWElGO8ewPtYB/FU0XddK/kv0JD Wq7Z06Ys1j/cI7+Q+hFOqUlgmCNbG+c3mtE7gdV5sSSi5r8N8nAcBLzW33MJizObfp 33Jv+yk3/CIb/2sYG9Vple/l55oKZzNEOnyRNuYOWyW+Mpvd7xQ2ztMegsqreFQG+A LY/99YM8/O6I7ci/Sobs3wvGyxnJvnqNr4jFWnPKsdJl/n6lUcidCOj+pqJgFGOVaY 9y3o4dlUhgMEvvlkojQyCb1hTwWT5DNAEJMqVk/3x1BdejNwsHkneDlcmt3/IsmjSx VdM0w+D4KjJPw== From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH 1/8] crypto: algif_aead - use memcpy_sglist() instead of null skcipher Date: Mon, 5 May 2025 12:10:38 -0700 Message-ID: <20250505191045.763835-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250505191045.763835-1-ebiggers@kernel.org> References: <20250505191045.763835-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Eric Biggers 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 --- 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 #include #include #include -#include #include #include #include #include #include #include #include -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); } From patchwork Mon May 5 19:10:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 887621 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 6BFCF26F44E for ; Mon, 5 May 2025 19:11:37 +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=1746472297; cv=none; b=lldPEDIo4XR1ZdDnGbWBX3SZvXss0jHckTowPqeU9rjX9QVxlkNiL0bMNmJ2ueQcsBCPuoGqlXbN1k+3QjXoAjMj4takS9Jm8pMJet5Lc9mQDUINwnkpNwCsbP9nGfL4MYke7rhH0M8C6o4TLput0dEWn5+btrtCaP+l2N493/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746472297; c=relaxed/simple; bh=1B6sDRX1WskvsadgsOPI+1LsNAsBz/m9k3PHvJzF4wc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iczndbc4a+Iogg/424AUhEI47Sm0KBwmypUKcV8qz5JZTX7UeHtfieb4cVHJMuCx76RrITxM0e8BmxRN2dNtOe/KBcmYqpYOQsPE1c8pEvttJRnS4Zm+Bt+SadR2t3hQlOfyP/1VVUVuIQux+b80CGhFTR+LL/R1s/0xHb/VhZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I3Zl2DMB; 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="I3Zl2DMB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9B62C4CEEF for ; Mon, 5 May 2025 19:11:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746472297; bh=1B6sDRX1WskvsadgsOPI+1LsNAsBz/m9k3PHvJzF4wc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=I3Zl2DMBZxLLPU2bfVPHr0M8eIXEG/9gPOSGepC930PH5JOlCOMKd2XWpl8bDk5Xc /lpuadMnTepqiP5l68X9IZzvt+YZcEO1cQWFglHUL6hYMUo5MGXxQqTlYkAQnuo2Qc lI14QUFoGlm758UJldY6c6sgrrJXTpZFug6ZVH5NUP+EIanmfYRfyXzBuIk7jg0ST9 DPknC3u0Nk7hP7NqZfFSnlctANPoJuEeUFt9kjGpu4hXstkCF0m9AU0eeobEfuceOD ww2OC5tiJ9bGzI1aeUVQ3xmy4I7baA/R6xSKBByx9octoW7ibB0Ay13BuppnmLDl46 k1A1yq6zfkhrg== From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH 3/8] crypto: gcm - use memcpy_sglist() instead of null skcipher Date: Mon, 5 May 2025 12:10:40 -0700 Message-ID: <20250505191045.763835-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250505191045.763835-1-ebiggers@kernel.org> References: <20250505191045.763835-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Eric Biggers 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 --- 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 #include #include #include -#include #include #include #include #include #include @@ -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); From patchwork Mon May 5 19:10:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 887620 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 A995926C3A5 for ; Mon, 5 May 2025 19:11:37 +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=1746472297; cv=none; b=nN/uRFf/PmV8E222D8MlEMeDSMSvfKLwAKlRSGJmnwS5oPitGdc0V6FKGuIaTysraGZ1NDwukzeuLw/cexq7LrjGhGOA+XTWyauiLxEpIlkFOQD1x0f2xUUTn7UT4Z1lB0Yh+Uh0bu30MXQ5CXanw6CnoWRWhDGgp/FmFBfSTGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746472297; c=relaxed/simple; bh=NqOPML6jSJcXyXyFGmWequwI2EaJipm7zIcb3OtbBak=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DCXim+pTIatK9GKXLNZ3wf9BRA8a14OJ0OCNNPfhwHHtgu2LVTouH+fLB2oMDIG2NwaKvnh2TnP2Iakzc6VhhQOnwXpHbK+b5evhhtKGhaGeVLsRF4QrFXnQAd03cMoRByGEREugnrOvPe/jGzUKV0xYCePy44Q8lu65ciy5CuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BS6KdRc6; 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="BS6KdRc6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81499C4CEE9 for ; Mon, 5 May 2025 19:11:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746472297; bh=NqOPML6jSJcXyXyFGmWequwI2EaJipm7zIcb3OtbBak=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BS6KdRc6Irl1b80HgT+hC8xEyfOg21xMb8Ce4/gReHG74Pty7RjziWb2BRKhanE+r wALlS2M/PExGGsI7SLSPBnQ65vYZPNGKyJaMpIxPJ286ci4xSBvtMBHxMqHJMt4vC5 ver+zP8LOeOk8tgH1AdFhmoaMGTGrX0lHYofS3GG/N1ZnAgSOjMjH+xKn8vxvQUXFe iTDIyi/mq17LMvebU/rkGRBAy6HSMPNzgz0v/sejm/mVV7ba4pQJejYxmkRU7vNgp5 LKFZF717+sZfk3Btb0OLoCquqoltD/nO9GJnFqsOb42e446Ko016ni7nTqXiOu3np5 c8P0Nx9L/rjJA== From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH 6/8] crypto: null - remove the default null skcipher Date: Mon, 5 May 2025 12:10:43 -0700 Message-ID: <20250505191045.763835-7-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250505191045.763835-1-ebiggers@kernel.org> References: <20250505191045.763835-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Eric Biggers crypto_get_default_null_skcipher() and crypto_put_default_null_skcipher() are no longer used, so remove them. Signed-off-by: Eric Biggers --- 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 #include #include #include #include -#include #include -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 From patchwork Mon May 5 19:10:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 887619 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 D856626FA60 for ; Mon, 5 May 2025 19:11:37 +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=1746472297; cv=none; b=DKSidntmvXp9ZE8oRTUNzwtTQK2ZqYXgMXVy4QjdTi/i1ZQMeB2cqb90Pn4OZKtn2d2sEGLo4VIlWVQsU8eOQA+iOmgAgiDbG4bnLbKoboJ+Rk455cxbmVgJBTYI1DOZMFE+/uG+hpmAVti5SpzV3KTjO7Fi2MR6cgSGzaef6Ho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746472297; c=relaxed/simple; bh=Ef9zmYIZe+4TF2b7Q1Lz2u+fhl0U7p7qqpocEBgQQ8o=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T5mEbXSIaqpbMMDtLM4fH9Fk00qzaENUmidusWrEm86zpuGJiSoHXf5OxxCawS7pF/ZP5bfSMbySb117blmXHi5wFXgVoM+/vsfZsN26+YZiw+LK5Pa9oE/wjv+D19q0p88Uq9mYQQ3jeFlGz8VT942EqIcELRQz4u6K5gNvvvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gGD8xjHt; 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="gGD8xjHt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0147C4CEF1 for ; Mon, 5 May 2025 19:11:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746472297; bh=Ef9zmYIZe+4TF2b7Q1Lz2u+fhl0U7p7qqpocEBgQQ8o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gGD8xjHtUOzw6oCsX571V23i6FYfVsPtQlvX2cIuwl3/jB3N8v0ZLygqqjLA2Zlt2 R7gjhIV2hvrpnqFuIbUh3MX2tw4bUhSSSd2GRv61bZ6QJl/V3B2W9K4w5AYme0dgTF CrwUzwt4LYqVqGU3OdKPjjpOmILAj/ybqnn0BR0uGZGnkOV1UAkp7XaA0ZAvDjHTKm vcQnKShukJqeviQ4kBKbQisrNqF7vjC2rqquag9M21+0Xuu+KdxgcTMBSAcKlIkck6 YCA43zHoolXWPLXqflsz9WPzLmcdjHVCwKGfwVauPKxYdIQWiPkxtwOuwMYUstEDrw LiVTdIIum2GBA== From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH 7/8] crypto: null - merge CRYPTO_NULL2 into CRYPTO_NULL Date: Mon, 5 May 2025 12:10:44 -0700 Message-ID: <20250505191045.763835-8-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250505191045.763835-1-ebiggers@kernel.org> References: <20250505191045.763835-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Eric Biggers There is no reason to have separate CRYPTO_NULL2 and CRYPTO_NULL options. Just merge them into CRYPTO_NULL. Signed-off-by: Eric Biggers --- 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