From patchwork Sat Apr 12 10:57:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 880599 Received: from abb.hmeau.com (abb.hmeau.com [144.6.53.87]) (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 C70FA1A5B91 for ; Sat, 12 Apr 2025 10:57:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.6.53.87 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744455447; cv=none; b=iMTxkV+UiVW/hAoRYJlGz6y/jCWRDpVmBqYG3wa+pFpNv1LSaz6iB3OyZ4IvO3v3y97Cl0uSsQoHHqA9SPWR72Ju+0Uch1zNekmWGIAgzbkfNMwzewRD40quCJlC+vN6zFZbFl7Vz/REe7EAB2ulX5OkrRoyPpULhu0XcmOJugk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744455447; c=relaxed/simple; bh=k6+SjRG37S53lEwB05RhSvAxUeTpw3PzILhb7t5TnnU=; h=Date:Message-Id:In-Reply-To:References:From:Subject:To; b=qUi+aQDyqG4V7LbHdDTHgNoAInWoOa8q7BmbZoZdXFALA1lTlgwlxE/DOyQ3BH06PaoXK28xlRuJIwOW1zyJU51kGjlPFGH6DpPU9zJ2RpAGdAlkuIA4RY1pKWpRyYnPY2pbXvPV/mum2aqRirQavyRDUaArzn0dTh78L7L5Wr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au; spf=pass smtp.mailfrom=gondor.apana.org.au; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b=AjmGFhE3; arc=none smtp.client-ip=144.6.53.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b="AjmGFhE3" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hmeau.com; s=formenos; h=To:Subject:From:References:In-Reply-To:Message-Id:Date:Sender: Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=td/SuIyG8JRnrEC+a5l5TfO7hFYWZKV28xmSGmMz0e8=; b=AjmGFhE3/slgAjYj96OvCVazqV vio1T6hb0fhgpBpeOUJYSQDHxRVd62t4jb6yn32RG6qb1JsxGrZBLgJ/olHSKaJJTr+SgIfTBJrCd YnS3fppQu9IjIYlr+NWH8X7T2jNbeI9P6+fd4h+wAVCnP4aPkRKSX4TnbFuePhATifnILxy8yN3oU 8ufQFBxG/qvmv2XoV64jwxkrn2Gq1xYHRj0wtZVWxdg7fTO7rFswGrqKhf0Y7OhDhksfz7859qsQt ufxsq1i+pFmuorAL3+tyY3ZR397PFlKR0P/IkoAkXtbyhqySWxWOLi4hcTI1/JaOjHcBwHXwO4jls WrpfYLeg==; Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.96 #2 (Debian)) id 1u3YY3-00F5JW-37; Sat, 12 Apr 2025 18:57:21 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Sat, 12 Apr 2025 18:57:19 +0800 Date: Sat, 12 Apr 2025 18:57:19 +0800 Message-Id: <120d42816e45cc1dcd172a50927736010731b29d.1744455146.git.herbert@gondor.apana.org.au> In-Reply-To: References: From: Herbert Xu Subject: [PATCH 1/8] crypto: hash - Add HASH_REQUEST_ON_STACK To: Linux Crypto Mailing List Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Allow any ahash to be used with a stack request, with optional dynamic allocation when async is needed. The intended usage is: HASH_REQUEST_ON_STACK(req, tfm); ... err = crypto_ahash_digest(req); /* The request cannot complete synchronously. */ if (err == -EAGAIN) { /* This will not fail. */ req = HASH_REQUEST_CLONE(req, gfp); /* Redo operation. */ err = crypto_ahash_digest(req); } Signed-off-by: Herbert Xu --- crypto/ahash.c | 106 +++++++++++++++++++++++++++++++-- include/crypto/hash.h | 54 +++++++++++++---- include/crypto/internal/hash.h | 26 +++++++- 3 files changed, 171 insertions(+), 15 deletions(-) diff --git a/crypto/ahash.c b/crypto/ahash.c index 7c9c0931197f..7a74092323b9 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -300,6 +300,8 @@ int crypto_ahash_setkey(struct crypto_ahash *tfm, const u8 *key, int err; err = alg->setkey(tfm, key, keylen); + if (!err && ahash_is_async(tfm)) + err = crypto_ahash_setkey(tfm->fb, key, keylen); if (unlikely(err)) { ahash_set_needkey(tfm, alg); return err; @@ -473,6 +475,8 @@ int crypto_ahash_init(struct ahash_request *req) return crypto_shash_init(prepare_shash_desc(req, tfm)); if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) return -ENOKEY; + if (ahash_req_on_stack(req) && ahash_is_async(tfm)) + return -EAGAIN; return ahash_do_req_chain(req, crypto_ahash_alg(tfm)->init); } EXPORT_SYMBOL_GPL(crypto_ahash_init); @@ -520,6 +524,8 @@ int crypto_ahash_update(struct ahash_request *req) if (likely(tfm->using_shash)) return shash_ahash_update(req, ahash_request_ctx(req)); + if (ahash_req_on_stack(req) && ahash_is_async(tfm)) + return -EAGAIN; return ahash_do_req_chain(req, crypto_ahash_alg(tfm)->update); } EXPORT_SYMBOL_GPL(crypto_ahash_update); @@ -530,6 +536,8 @@ int crypto_ahash_final(struct ahash_request *req) if (likely(tfm->using_shash)) return crypto_shash_final(ahash_request_ctx(req), req->result); + if (ahash_req_on_stack(req) && ahash_is_async(tfm)) + return -EAGAIN; return ahash_do_req_chain(req, crypto_ahash_alg(tfm)->final); } EXPORT_SYMBOL_GPL(crypto_ahash_final); @@ -540,6 +548,8 @@ int crypto_ahash_finup(struct ahash_request *req) if (likely(tfm->using_shash)) return shash_ahash_finup(req, ahash_request_ctx(req)); + if (ahash_req_on_stack(req) && ahash_is_async(tfm)) + return -EAGAIN; if (!crypto_ahash_alg(tfm)->finup || (!crypto_ahash_req_chain(tfm) && ahash_request_isvirt(req))) return ahash_def_finup(req); @@ -611,6 +621,8 @@ int crypto_ahash_digest(struct ahash_request *req) if (likely(tfm->using_shash)) return shash_ahash_digest(req, prepare_shash_desc(req, tfm)); + if (ahash_req_on_stack(req) && ahash_is_async(tfm)) + return -EAGAIN; if (!crypto_ahash_req_chain(tfm) && ahash_request_isvirt(req)) return ahash_def_digest(req); if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) @@ -714,26 +726,63 @@ static void crypto_ahash_exit_tfm(struct crypto_tfm *tfm) struct crypto_ahash *hash = __crypto_ahash_cast(tfm); struct ahash_alg *alg = crypto_ahash_alg(hash); - alg->exit_tfm(hash); + if (alg->exit_tfm) + alg->exit_tfm(hash); + else if (tfm->__crt_alg->cra_exit) + tfm->__crt_alg->cra_exit(tfm); + + if (ahash_is_async(hash)) + crypto_free_ahash(hash->fb); } static int crypto_ahash_init_tfm(struct crypto_tfm *tfm) { struct crypto_ahash *hash = __crypto_ahash_cast(tfm); struct ahash_alg *alg = crypto_ahash_alg(hash); + struct crypto_ahash *fb = NULL; + int err; crypto_ahash_set_statesize(hash, alg->halg.statesize); crypto_ahash_set_reqsize(hash, crypto_tfm_alg_reqsize(tfm)); + hash->fb = hash; + if (tfm->__crt_alg->cra_type == &crypto_shash_type) return crypto_init_ahash_using_shash(tfm); + if (ahash_is_async(hash)) { + fb = crypto_alloc_ahash(crypto_ahash_alg_name(hash), + 0, CRYPTO_ALG_ASYNC); + if (IS_ERR(fb)) + return PTR_ERR(fb); + + hash->fb = fb; + } + ahash_set_needkey(hash, alg); - if (alg->exit_tfm) - tfm->exit = crypto_ahash_exit_tfm; + tfm->exit = crypto_ahash_exit_tfm; - return alg->init_tfm ? alg->init_tfm(hash) : 0; + if (!alg->init_tfm) { + if (!tfm->__crt_alg->cra_init) + return 0; + + err = tfm->__crt_alg->cra_init(tfm); + if (err) + goto out_free_sync_hash; + + return 0; + } + + err = alg->init_tfm(hash); + if (err) + goto out_free_sync_hash; + + return 0; + +out_free_sync_hash: + crypto_free_ahash(fb); + return err; } static unsigned int crypto_ahash_extsize(struct crypto_alg *alg) @@ -970,5 +1019,54 @@ int ahash_register_instance(struct crypto_template *tmpl, } EXPORT_SYMBOL_GPL(ahash_register_instance); +void ahash_request_free(struct ahash_request *req) +{ + if (unlikely(!req)) + return; + + if (!ahash_req_on_stack(req)) { + kfree(req); + return; + } + + ahash_request_zero(req); +} +EXPORT_SYMBOL_GPL(ahash_request_free); + +int crypto_hash_digest(struct crypto_ahash *tfm, const u8 *data, + unsigned int len, u8 *out) +{ + HASH_REQUEST_ON_STACK(req, tfm->fb); + int err; + + ahash_request_set_callback(req, 0, NULL, NULL); + ahash_request_set_virt(req, data, out, len); + err = crypto_ahash_digest(req); + + ahash_request_zero(req); + + return err; +} +EXPORT_SYMBOL_GPL(crypto_hash_digest); + +struct ahash_request *ahash_request_clone(struct ahash_request *req, + size_t total, gfp_t gfp) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct ahash_request *nreq; + + nreq = kmalloc(total, gfp); + if (!nreq) { + ahash_request_set_tfm(req, tfm->fb); + req->base.flags = CRYPTO_TFM_REQ_ON_STACK; + return req; + } + + memcpy(nreq, req, total); + ahash_request_set_tfm(req, tfm); + return req; +} +EXPORT_SYMBOL_GPL(ahash_request_clone); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Asynchronous cryptographic hash type"); diff --git a/include/crypto/hash.h b/include/crypto/hash.h index 87518cf3b2d8..b00ea8407f9c 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h @@ -16,6 +16,9 @@ /* Set this bit for virtual address instead of SG list. */ #define CRYPTO_AHASH_REQ_VIRT 0x00000001 +#define CRYPTO_AHASH_REQ_PRIVATE \ + CRYPTO_AHASH_REQ_VIRT + struct crypto_ahash; /** @@ -167,12 +170,22 @@ struct shash_desc { * containing a 'struct sha3_state'. */ #define HASH_MAX_DESCSIZE (sizeof(struct shash_desc) + 360) +#define MAX_SYNC_HASH_REQSIZE HASH_MAX_DESCSIZE #define SHASH_DESC_ON_STACK(shash, ctx) \ char __##shash##_desc[sizeof(struct shash_desc) + HASH_MAX_DESCSIZE] \ __aligned(__alignof__(struct shash_desc)); \ struct shash_desc *shash = (struct shash_desc *)__##shash##_desc +#define HASH_REQUEST_ON_STACK(name, _tfm) \ + char __##name##_req[sizeof(struct ahash_request) + \ + MAX_SYNC_HASH_REQSIZE] CRYPTO_MINALIGN_ATTR; \ + struct ahash_request *name = \ + ahash_request_on_stack_init(__##name##_req, (_tfm)) + +#define HASH_REQUEST_CLONE(name, gfp) \ + hash_request_clone(name, sizeof(__##name##_req), gfp) + /** * struct shash_alg - synchronous message digest definition * @init: see struct ahash_alg @@ -231,6 +244,7 @@ struct crypto_ahash { bool using_shash; /* Underlying algorithm is shash, not ahash */ unsigned int statesize; unsigned int reqsize; + struct crypto_ahash *fb; struct crypto_tfm base; }; @@ -248,6 +262,11 @@ struct crypto_shash { * CRYPTO_ALG_TYPE_SKCIPHER API applies here as well. */ +static inline bool ahash_req_on_stack(struct ahash_request *req) +{ + return crypto_req_on_stack(&req->base); +} + static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) { return container_of(tfm, struct crypto_ahash, base); @@ -544,7 +563,7 @@ int crypto_ahash_update(struct ahash_request *req); static inline void ahash_request_set_tfm(struct ahash_request *req, struct crypto_ahash *tfm) { - req->base.tfm = crypto_ahash_tfm(tfm); + crypto_request_set_tfm(&req->base, crypto_ahash_tfm(tfm)); } /** @@ -578,9 +597,12 @@ static inline struct ahash_request *ahash_request_alloc_noprof( * ahash_request_free() - zeroize and free the request data structure * @req: request data structure cipher handle to be freed */ -static inline void ahash_request_free(struct ahash_request *req) +void ahash_request_free(struct ahash_request *req); + +static inline void ahash_request_zero(struct ahash_request *req) { - kfree_sensitive(req); + memzero_explicit(req, sizeof(*req) + + crypto_ahash_reqsize(crypto_ahash_reqtfm(req))); } static inline struct ahash_request *ahash_request_cast( @@ -619,13 +641,9 @@ static inline void ahash_request_set_callback(struct ahash_request *req, crypto_completion_t compl, void *data) { - u32 keep = CRYPTO_AHASH_REQ_VIRT; - - req->base.complete = compl; - req->base.data = data; - flags &= ~keep; - req->base.flags &= keep; - req->base.flags |= flags; + flags &= ~CRYPTO_AHASH_REQ_PRIVATE; + flags |= req->base.flags & CRYPTO_AHASH_REQ_PRIVATE; + crypto_request_set_callback(&req->base, flags, compl, data); } /** @@ -870,6 +888,9 @@ int crypto_shash_digest(struct shash_desc *desc, const u8 *data, int crypto_shash_tfm_digest(struct crypto_shash *tfm, const u8 *data, unsigned int len, u8 *out); +int crypto_hash_digest(struct crypto_ahash *tfm, const u8 *data, + unsigned int len, u8 *out); + /** * crypto_shash_export() - extract operational state for message digest * @desc: reference to the operational state handle whose state is exported @@ -980,4 +1001,17 @@ static inline bool ahash_is_async(struct crypto_ahash *tfm) return crypto_tfm_is_async(&tfm->base); } +static inline struct ahash_request *ahash_request_on_stack_init( + char *buf, struct crypto_ahash *tfm) +{ + struct ahash_request *req = (void *)buf; + + ahash_request_set_tfm(req, tfm); + req->base.flags = CRYPTO_TFM_REQ_ON_STACK; + return req; +} + +struct ahash_request *ahash_request_clone(struct ahash_request *req, + size_t total, gfp_t gfp); + #endif /* _CRYPTO_HASH_H */ diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index e2a1fac38610..45c728ac2621 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h @@ -11,6 +11,12 @@ #include #include +#define HASH_FBREQ_ON_STACK(name, req) \ + char __##name##_req[sizeof(struct ahash_request) + \ + MAX_SYNC_HASH_REQSIZE] CRYPTO_MINALIGN_ATTR; \ + struct ahash_request *name = ahash_fbreq_on_stack_init( \ + __##name##_req, (req)) + struct ahash_request; struct ahash_instance { @@ -187,7 +193,7 @@ static inline void ahash_request_complete(struct ahash_request *req, int err) static inline u32 ahash_request_flags(struct ahash_request *req) { - return req->base.flags; + return crypto_request_flags(&req->base) & ~CRYPTO_AHASH_REQ_PRIVATE; } static inline struct crypto_ahash *crypto_spawn_ahash( @@ -257,5 +263,23 @@ static inline bool crypto_ahash_req_chain(struct crypto_ahash *tfm) return crypto_tfm_req_chain(&tfm->base); } +static inline struct ahash_request *ahash_fbreq_on_stack_init( + char *buf, struct ahash_request *old) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(old); + struct ahash_request *req = (void *)buf; + + ahash_request_set_tfm(req, tfm->fb); + req->base.flags = CRYPTO_TFM_REQ_ON_STACK; + ahash_request_set_callback(req, ahash_request_flags(old), NULL, NULL); + req->base.flags &= ~CRYPTO_AHASH_REQ_PRIVATE; + req->base.flags |= old->base.flags & CRYPTO_AHASH_REQ_PRIVATE; + req->src = old->src; + req->result = old->result; + req->nbytes = old->nbytes; + + return req; +} + #endif /* _CRYPTO_INTERNAL_HASH_H */ From patchwork Sat Apr 12 10:57:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 880598 Received: from abb.hmeau.com (abb.hmeau.com [144.6.53.87]) (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 62FAB1D7E42 for ; Sat, 12 Apr 2025 10:57:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.6.53.87 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744455450; cv=none; b=TfL7Qk/I1T6lVVGScdDnWTpHELCjeJKUf53s5wadkVDsc2B2K8iz23UEc5EL7aIvm1SC5ifhGsZkdybWrJC39UbWq/XZVmddLHbrjJjg88jP+naaTfpA8sKPqVJzlcZE/t7owUG4+sRHDMoGFsxLfPXgjcRNqtyHnNoE+Sr1NnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744455450; c=relaxed/simple; bh=x4cgi/eNdYnXU6Azc/fwrlX40v9FIFnQ3nVnZTJ8ARc=; h=Date:Message-Id:In-Reply-To:References:From:Subject:To; b=hoKgTvY9Nr9/4CJ3uN5cizL6rWsB0IsbVE3Jvj5OjFq3QSGCNQkWQSoAQxzXL/2xuRArbMBItmCrbKwEFWv4OI1TZQvD8htRNZHp9CZea/QvzIaoT6ypMrTt6R1hvNtNqgkr87mog9QOVoA+ItAq01KcVFhCU4UVwyyzo1C/+F0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au; spf=pass smtp.mailfrom=gondor.apana.org.au; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b=BBeZf4P3; arc=none smtp.client-ip=144.6.53.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b="BBeZf4P3" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hmeau.com; s=formenos; h=To:Subject:From:References:In-Reply-To:Message-Id:Date:Sender: Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=3taFg7/J8OiJUAP4pU1TZ/aEtAT/FE2f4x/3LCbVOrA=; b=BBeZf4P3MsWOmsrAi0rbAyGRve 2qF5bE38T2BBQf0kMOwX5EQ4Y6HIA8DwJkmeJh1kRoEtNUIZomWtB9/9wo8TTVkuNGWQgyqdI0qwl 92GhEwQuL1xWYOaOZAys9DT3o8B8B1kV3ncwnlioPDDwfaXzlatAInNVUIAW/0NCTv/86V68+Yya0 teq4yOKxicwRnaJhmgsPP8xAaFml13Ao1JVDWuyXjUFul4HE/pzo/5CY6+wMhxu88AArfQjRbFQ2p 2A+na98d0M5L5KUIyqnmyfR1HmSYwIQ/e0LnlWP43Wn25x2aHAkPxr/jFlLvaM6X6IfubBDxzk6vh fk6KkNzw==; Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.96 #2 (Debian)) id 1u3YY8-00F5KF-1u; Sat, 12 Apr 2025 18:57:25 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Sat, 12 Apr 2025 18:57:24 +0800 Date: Sat, 12 Apr 2025 18:57:24 +0800 Message-Id: <46a016a18a0e7440ff74c6f4e8d04cf54baad659.1744455146.git.herbert@gondor.apana.org.au> In-Reply-To: References: From: Herbert Xu Subject: [PATCH 3/8] crypto: arm64/sha512 - Fix header inclusions To: Linux Crypto Mailing List Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Instead of relying on linux/module.h being included through the header file sha512_base.h, include it directly. Signed-off-by: Herbert Xu --- arch/arm64/crypto/sha512-glue.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/arm64/crypto/sha512-glue.c b/arch/arm64/crypto/sha512-glue.c index 62f129dea83d..f789deabefc0 100644 --- a/arch/arm64/crypto/sha512-glue.c +++ b/arch/arm64/crypto/sha512-glue.c @@ -6,11 +6,10 @@ */ #include -#include -#include +#include +#include #include #include -#include MODULE_DESCRIPTION("SHA-384/SHA-512 secure hash for arm64"); MODULE_AUTHOR("Andy Polyakov "); From patchwork Sat Apr 12 10:57:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 880597 Received: from abb.hmeau.com (abb.hmeau.com [144.6.53.87]) (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 2D5A12B9BF for ; Sat, 12 Apr 2025 10:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.6.53.87 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744455455; cv=none; b=ucwU6bp/wC2jnsjs4dMgdRVOAr+sdg3eFLeZDtnGrHq4jBC2eenMDdw0WgKxucJPydnUaUGTZO2ip42aEWhg0DFEYNQ+A5rW8tZL2CH4z+da3U+qzAKAXyg/B1udgMicqufcyfGEbg77iu6oTJ5+wK1cNj6OlCVRojLCpXRMtfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744455455; c=relaxed/simple; bh=DJg/lJavUf/y5rf/ORD0oIq++ok0nPkK57XupUbRY8U=; h=Date:Message-Id:In-Reply-To:References:From:Subject:To; b=WUOZNtazVJ6ml4qN/zuDZSL4WuVkpwhnrQffeCDxjX1BIOIPkrfT93JIb2fVamg75cdeCwdnyGTCVMojSJwl7PQK6XjIzbVwZbI+BaXmj+SC8RvyyHdOwmOucuHk1SwdctA3b1o7CfZvo6e8iDyfb/+FrFbhdJGb7JJX3M0r534= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au; spf=pass smtp.mailfrom=gondor.apana.org.au; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b=gCuVlMAX; arc=none smtp.client-ip=144.6.53.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b="gCuVlMAX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hmeau.com; s=formenos; h=To:Subject:From:References:In-Reply-To:Message-Id:Date:Sender: Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=/cGK8DTQUaWaIVHx6FwOQIaw4QF6GuL4EzD2qR9r6Nc=; b=gCuVlMAXEAmmiRuWpOsBjtJCkA 4xCk44dvAWxWTA7jv4myXZgRkKKiI4cmWCOrxrCPnFYbQlaArLkwV+vygLd1IUznbH0LHCoYNjLcl dg7bt7Wpo5AqQqfDS54rowjqJzOJ8yIMjWQtPTUiMMDjwLvDZoj+OfQPmGIwcMVExdaXpyX1hFAYR FQuV/MCKhWLYT8IocvXt7f+1ahHZUyJ2iNTmmDydZEEvujOCILbJd/kBjYVWCkCmR/q/Qbg9ZCIWx e+ffMB77HTI626h7XOr4kQ4t8vSgZDCM0/fNrBeVIVLyWuBmT0tVALS10AewM6Goles91xMaRrMbc yKUaQdQg==; Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.96 #2 (Debian)) id 1u3YYD-00F5Kb-0f; Sat, 12 Apr 2025 18:57:30 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Sat, 12 Apr 2025 18:57:29 +0800 Date: Sat, 12 Apr 2025 18:57:29 +0800 Message-Id: In-Reply-To: References: From: Herbert Xu Subject: [PATCH 5/8] crypto: lib/sm3 - Move sm3 library into lib/crypto To: Linux Crypto Mailing List Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Move the sm3 library code into lib/crypto. Signed-off-by: Herbert Xu --- arch/arm64/crypto/Kconfig | 4 ++-- arch/riscv/crypto/Kconfig | 2 +- arch/x86/crypto/Kconfig | 2 +- crypto/Kconfig | 5 +---- crypto/Makefile | 1 - lib/crypto/Kconfig | 3 +++ lib/crypto/Makefile | 3 +++ {crypto => lib/crypto}/sm3.c | 0 8 files changed, 11 insertions(+), 9 deletions(-) rename {crypto => lib/crypto}/sm3.c (100%) diff --git a/arch/arm64/crypto/Kconfig b/arch/arm64/crypto/Kconfig index ce655da0fbee..9dd1ae7a68a4 100644 --- a/arch/arm64/crypto/Kconfig +++ b/arch/arm64/crypto/Kconfig @@ -101,7 +101,7 @@ config CRYPTO_SM3_NEON tristate "Hash functions: SM3 (NEON)" depends on KERNEL_MODE_NEON select CRYPTO_HASH - select CRYPTO_SM3 + select CRYPTO_LIB_SM3 help SM3 (ShangMi 3) secure hash function (OSCCA GM/T 0004-2012) @@ -112,7 +112,7 @@ config CRYPTO_SM3_ARM64_CE tristate "Hash functions: SM3 (ARMv8.2 Crypto Extensions)" depends on KERNEL_MODE_NEON select CRYPTO_HASH - select CRYPTO_SM3 + select CRYPTO_LIB_SM3 help SM3 (ShangMi 3) secure hash function (OSCCA GM/T 0004-2012) diff --git a/arch/riscv/crypto/Kconfig b/arch/riscv/crypto/Kconfig index 6392e1e11bc9..27a1f26d41bd 100644 --- a/arch/riscv/crypto/Kconfig +++ b/arch/riscv/crypto/Kconfig @@ -61,7 +61,7 @@ config CRYPTO_SM3_RISCV64 tristate "Hash functions: SM3 (ShangMi 3)" depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO select CRYPTO_HASH - select CRYPTO_SM3 + select CRYPTO_LIB_SM3 help SM3 (ShangMi 3) secure hash function (OSCCA GM/T 0004-2012) diff --git a/arch/x86/crypto/Kconfig b/arch/x86/crypto/Kconfig index 0cec75926380..4e0bd1258751 100644 --- a/arch/x86/crypto/Kconfig +++ b/arch/x86/crypto/Kconfig @@ -455,7 +455,7 @@ config CRYPTO_SM3_AVX_X86_64 tristate "Hash functions: SM3 (AVX)" depends on X86 && 64BIT select CRYPTO_HASH - select CRYPTO_SM3 + select CRYPTO_LIB_SM3 help SM3 secure hash function as defined by OSCCA GM/T 0004-2012 SM3 diff --git a/crypto/Kconfig b/crypto/Kconfig index dbf97c4e7c59..9322e42e562d 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -1012,13 +1012,10 @@ config CRYPTO_SHA3 help SHA-3 secure hash algorithms (FIPS 202, ISO/IEC 10118-3) -config CRYPTO_SM3 - tristate - config CRYPTO_SM3_GENERIC tristate "SM3 (ShangMi 3)" select CRYPTO_HASH - select CRYPTO_SM3 + select CRYPTO_LIB_SM3 help SM3 (ShangMi 3) secure hash function (OSCCA GM/T 0004-2012, ISO/IEC 10118-3) diff --git a/crypto/Makefile b/crypto/Makefile index 98510a2aa0b1..baf5040ca661 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -79,7 +79,6 @@ obj-$(CONFIG_CRYPTO_SHA1) += sha1_generic.o obj-$(CONFIG_CRYPTO_SHA256) += sha256_generic.o obj-$(CONFIG_CRYPTO_SHA512) += sha512_generic.o obj-$(CONFIG_CRYPTO_SHA3) += sha3_generic.o -obj-$(CONFIG_CRYPTO_SM3) += sm3.o obj-$(CONFIG_CRYPTO_SM3_GENERIC) += sm3_generic.o obj-$(CONFIG_CRYPTO_STREEBOG) += streebog_generic.o obj-$(CONFIG_CRYPTO_WP512) += wp512.o diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig index 798972b29b68..2c6ab80e0cdc 100644 --- a/lib/crypto/Kconfig +++ b/lib/crypto/Kconfig @@ -152,4 +152,7 @@ config CRYPTO_LIB_SHA1 config CRYPTO_LIB_SHA256 tristate +config CRYPTO_LIB_SM3 + tristate + endmenu diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 01fac1cd05a1..4dd62bc5bee3 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -60,3 +60,6 @@ endif obj-$(CONFIG_MPILIB) += mpi/ obj-$(CONFIG_CRYPTO_MANAGER_EXTRA_TESTS) += simd.o + +obj-$(CONFIG_CRYPTO_LIB_SM3) += libsm3.o +libsm3-y := sm3.o diff --git a/crypto/sm3.c b/lib/crypto/sm3.c similarity index 100% rename from crypto/sm3.c rename to lib/crypto/sm3.c From patchwork Sat Apr 12 10:57:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 880596 Received: from abb.hmeau.com (abb.hmeau.com [144.6.53.87]) (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 5CA291C862C for ; Sat, 12 Apr 2025 10:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.6.53.87 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744455459; cv=none; b=g0eUZtfSTG5yy/ZEJc9z+J7jCnFdYsPTppzwSIj7bVwz4wLgbqXSdRF1fHpJ4nNcAl29lmjI4za3EIeQgA1ZTiNll36Ro05xkKxtIZCJfbM5a3nukdycL1WzQJph5WW2bqpoSsJxtsmHRmqBo1zRoUGQYRFSSzOswAGnXYNW3fI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744455459; c=relaxed/simple; bh=zkEjWMz+NW4kv4G/+qtW+Hh+xyTZ21IwHiI0f45+3kw=; h=Date:Message-Id:In-Reply-To:References:From:Subject:To; b=O4G94nbXvqjDH4ttk77Qzy0a84cCj0G7QWaqTLqI/2mG4gRnXbXVxpA+b44oFucE9YnqsLzBWsaWJtMAb5T1wdBjswqgr9W+npLjhKHydDBJeiQGYdNYxwS1TdoxNnmC6G1TyAq6gTLC8ryn26tDmOSt3+AIwffWl78mYU3tNEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au; spf=pass smtp.mailfrom=gondor.apana.org.au; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b=ovzAdp7a; arc=none smtp.client-ip=144.6.53.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b="ovzAdp7a" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hmeau.com; s=formenos; h=To:Subject:From:References:In-Reply-To:Message-Id:Date:Sender: Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=6gQDB8Yqfk3SDdiT6guiC6PkLO+DPr//1ficAUoElGc=; b=ovzAdp7aQSgQ2hTjkbl/4zw8Xg Zm/0p+MxuEH15pr+kbYfCIThNaT3nqEA/9Gd1LLzzUeKsJskhoiQriGLywToOPRuwmstnGxOd2Q2I MG2thYp+/ue0c91wodxHuwpaM6myb38t0p6ujDgmjqYM62PIP8MU7JpUj/TvYxcCmRdXVIUInE4vP Kj11R70A2pzJdZ/nX2N5z9d/Md+Ds42RTgp8SK0gUi8/hcF+upO35v8vllAGc6cMIAnXOp6U7HOe+ Gvh2CQ1GehzpncuG8Fsxk2f9vH3658VE73lcxarEkviAV8aBNxifGvS2oMBMjOmKk+A8e6B0mimS4 GdexY/6g==; Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.96 #2 (Debian)) id 1u3YYH-00F5LM-2o; Sat, 12 Apr 2025 18:57:34 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Sat, 12 Apr 2025 18:57:33 +0800 Date: Sat, 12 Apr 2025 18:57:33 +0800 Message-Id: In-Reply-To: References: From: Herbert Xu Subject: [PATCH 7/8] crypto: sm3-base - Use sm3_init To: Linux Crypto Mailing List Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Remove the duplicate init code and simply call sm3_init. Signed-off-by: Herbert Xu --- include/crypto/sm3_base.h | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/include/crypto/sm3_base.h b/include/crypto/sm3_base.h index b33ed39c2bce..835896228e8e 100644 --- a/include/crypto/sm3_base.h +++ b/include/crypto/sm3_base.h @@ -20,18 +20,7 @@ typedef void (sm3_block_fn)(struct sm3_state *sst, u8 const *src, int blocks); static inline int sm3_base_init(struct shash_desc *desc) { - struct sm3_state *sctx = shash_desc_ctx(desc); - - sctx->state[0] = SM3_IVA; - sctx->state[1] = SM3_IVB; - sctx->state[2] = SM3_IVC; - sctx->state[3] = SM3_IVD; - sctx->state[4] = SM3_IVE; - sctx->state[5] = SM3_IVF; - sctx->state[6] = SM3_IVG; - sctx->state[7] = SM3_IVH; - sctx->count = 0; - + sm3_init(shash_desc_ctx(desc)); return 0; }