From: Kamlesh Gurudasani <kamlesh@ti.com>
To: T Pratham <t-pratham@ti.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
T Pratham <t-pratham@ti.com>
Cc: <linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
Praneeth Bajjuri <praneeth@ti.com>,
"Manorit Chawdhry" <m-chawdhry@ti.com>
Subject: Re: [PATCH RFC 2/2] crypto: ti: Add support for MD5 in DTHE V2 Hashing Engine driver
Date: Thu, 20 Feb 2025 00:17:57 +0530 [thread overview]
Message-ID: <87o6yx6aaq.fsf@kamlesh.mail-host-address-is-not-set> (raw)
In-Reply-To: <20250218104943.2304730-3-t-pratham@ti.com>
T Pratham <t-pratham@ti.com> writes:
> Add support for MD5 algorithm of the hashing engine of DTHE V2 crypto
> accelerator driver.
>
> Signed-off-by: T Pratham <t-pratham@ti.com>
> ---
> drivers/crypto/ti/Kconfig | 1 +
> drivers/crypto/ti/dthev2.c | 56 ++++++++++++++++++++++++++++++++++++++
> 2 files changed, 57 insertions(+)
>
> diff --git a/drivers/crypto/ti/Kconfig b/drivers/crypto/ti/Kconfig
> index 39d9d8cb6b78..ab4da73dffc4 100644
> --- a/drivers/crypto/ti/Kconfig
> +++ b/drivers/crypto/ti/Kconfig
> @@ -6,6 +6,7 @@ config CRYPTO_DEV_TI_DTHE_V2
> select CRYPTO_SKCIPHER
> select CRYPTO_SHA256
> select CRYPTO_SHA512
> + select CRYPTO_MD5
> help
> This enables support for the TI DTHE V2 hw crypto accelerator
> which can be found on TI K3 SOCs. Selecting this enables use
> diff --git a/drivers/crypto/ti/dthev2.c b/drivers/crypto/ti/dthev2.c
> index d5ed0f4621f5..ff2d5ef47c2a 100644
> --- a/drivers/crypto/ti/dthev2.c
> +++ b/drivers/crypto/ti/dthev2.c
> @@ -25,6 +25,7 @@
> #include <crypto/internal/aead.h>
> #include <crypto/internal/hash.h>
> #include <crypto/internal/skcipher.h>
> +#include <crypto/md5.h>
> #include <crypto/sha2.h>
>
> #include <linux/delay.h>
> @@ -363,6 +364,25 @@ static int dthe_sha224_cra_init(struct crypto_tfm *tfm)
> return 0;
> }
>
> +static int dthe_md5_cra_init(struct crypto_tfm *tfm)
> +{
> + struct dthe_tfm_ctx *ctx = crypto_tfm_ctx(tfm);
> + struct dthe_data *dev_data = dthe_get_dev(ctx);
> +
> + if (!dev_data)
> + return -ENODEV;
> +
> + ctx->ctx_info.hash_ctx = kzalloc(sizeof(*ctx->ctx_info.hash_ctx), GFP_KERNEL);
> + if (!ctx->ctx_info.hash_ctx)
> + return -ENOMEM;
> +
> + ctx->ctx_info.hash_ctx->mode = DTHE_HASH_MD5;
> + ctx->ctx_info.hash_ctx->block_size = MD5_BLOCK_WORDS * 4;
Assign a meaningful macro
> + ctx->ctx_info.hash_ctx->digest_size = MD5_DIGEST_SIZE;
> + ctx->ctx_info.hash_ctx->phash_size = MD5_DIGEST_SIZE;
> + return 0;
> +}
> +
> static void dthe_hash_cra_exit(struct crypto_tfm *tfm)
> {
> struct dthe_tfm_ctx *ctx = crypto_tfm_ctx(tfm);
> @@ -602,6 +622,8 @@ static int dthe_hash_update(struct ahash_request *req)
> memcpy(sctx->phash, sha256_zero_message_hash, sctx->digest_size);
> else if (sctx->mode == DTHE_HASH_SHA224)
> memcpy(sctx->phash, sha224_zero_message_hash, sctx->digest_size);
> + else if (sctx->mode == DTHE_HASH_MD5)
> + memcpy(sctx->phash, md5_zero_message_hash, sctx->digest_size);
> }
>
> return 0;
> @@ -736,6 +758,8 @@ static int dthe_hash_final(struct ahash_request *req)
> memcpy(req->result, sha256_zero_message_hash, sctx->digest_size);
> else if (sctx->mode == DTHE_HASH_SHA224)
> memcpy(req->result, sha224_zero_message_hash, sctx->digest_size);
> + else if (sctx->mode == DTHE_HASH_MD5)
> + memcpy(req->result, md5_zero_message_hash, sctx->digest_size);
> }
>
> memcpy(req->result, sctx->phash, sctx->digest_size);
> @@ -774,6 +798,8 @@ static int dthe_hash_finup(struct ahash_request *req)
> memcpy(req->result, sha256_zero_message_hash, sctx->digest_size);
> else if (sctx->mode == DTHE_HASH_SHA224)
> memcpy(req->result, sha224_zero_message_hash, sctx->digest_size);
> + else if (sctx->mode == DTHE_HASH_MD5)
> + memcpy(req->result, md5_zero_message_hash, sctx->digest_size);
> }
> return 0;
> }
> @@ -870,6 +896,8 @@ static int dthe_hash_digest(struct ahash_request *req)
> memcpy(req->result, sha256_zero_message_hash, sctx->digest_size);
> else if (sctx->mode == DTHE_HASH_SHA224)
> memcpy(req->result, sha224_zero_message_hash, sctx->digest_size);
> + else if (sctx->mode == DTHE_HASH_MD5)
> + memcpy(req->result, md5_zero_message_hash,
> sctx->digest_size);
Better to use Switch as it will give more readability and
mainitainability. As number of cases are 5 with this patch, both will
probably give same performance.
Kamlesh
> return 0;
> }
>
> @@ -1366,6 +1394,34 @@ static struct ahash_alg hash_algs[] = {
> }
> }
> },
> + {
> + .init = dthe_hash_init,
> + .update = dthe_hash_update,
> + .final = dthe_hash_final,
> + .finup = dthe_hash_finup,
> + .digest = dthe_hash_digest,
> + .export = dthe_hash_export,
> + .import = dthe_hash_import,
> + .halg = {
> + .digestsize = MD5_DIGEST_SIZE,
> + .statesize = sizeof(struct dthe_hash_ctx),
> + .base = {
> + .cra_name = "md5",
> + .cra_driver_name = "md5-dthe_v2",
> + .cra_priority = 400,
> + .cra_flags = CRYPTO_ALG_TYPE_AHASH |
> + CRYPTO_ALG_ASYNC |
> + CRYPTO_ALG_OPTIONAL_KEY |
> + CRYPTO_ALG_KERN_DRIVER_ONLY |
> + CRYPTO_ALG_ALLOCATES_MEMORY,
> + .cra_blocksize = MD5_BLOCK_WORDS * 4,
> + .cra_ctxsize = sizeof(struct dthe_tfm_ctx),
> + .cra_module = THIS_MODULE,
> + .cra_init = dthe_md5_cra_init,
> + .cra_exit = dthe_hash_cra_exit,
> + }
> + }
> + },
> };
>
> static struct skcipher_alg cipher_algs[] = {
> --
> 2.34.1
next prev parent reply other threads:[~2025-02-19 18:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-18 10:49 [PATCH RFC 0/2] Add support for hashing algorithms in TI DTHE V2 T Pratham
2025-02-18 10:49 ` [PATCH RFC 1/2] crypto: ti: Add support for SHA224/256/384/512 in DTHE V2 driver T Pratham
2025-02-19 18:36 ` Kamlesh Gurudasani
2025-03-02 8:09 ` Herbert Xu
2025-04-02 13:31 ` T Pratham
2025-04-02 13:54 ` Herbert Xu
2025-04-02 14:12 ` T Pratham
2025-04-02 14:16 ` Herbert Xu
2025-04-03 8:28 ` T Pratham
2025-04-03 8:35 ` Herbert Xu
2025-04-04 10:15 ` T Pratham
2025-04-04 10:23 ` Herbert Xu
2025-04-04 12:40 ` T Pratham
2025-04-05 1:33 ` Herbert Xu
2025-04-05 1:36 ` Herbert Xu
2025-02-18 10:49 ` [PATCH RFC 2/2] crypto: ti: Add support for MD5 in DTHE V2 Hashing Engine driver T Pratham
2025-02-19 18:47 ` Kamlesh Gurudasani [this message]
2025-04-02 13:50 ` Herbert Xu
2025-04-02 14:21 ` T Pratham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o6yx6aaq.fsf@kamlesh.mail-host-address-is-not-set \
--to=kamlesh@ti.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m-chawdhry@ti.com \
--cc=praneeth@ti.com \
--cc=t-pratham@ti.com \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®