* [PATCH] crypto: sun8i-ss - use crypto_shash_tfm_digest() in sun8i_ss_hashkey()
@ 2023-10-29 4:56 Eric Biggers
2023-11-17 11:21 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2023-10-29 4:56 UTC (permalink / raw)
To: linux-crypto; +Cc: linux-sunxi, Corentin Labbe
From: Eric Biggers <ebiggers@google.com>
Simplify sun8i_ss_hashkey() by using crypto_shash_tfm_digest() instead
of an alloc+init+update+final sequence. This should also improve
performance.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
.../crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 25 +++----------------
1 file changed, 4 insertions(+), 21 deletions(-)
diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
index d70b105dcfa1..753f67a36dc5 100644
--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
+++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
@@ -23,47 +23,30 @@
#include <linux/pm_runtime.h>
#include <linux/scatterlist.h>
#include <linux/slab.h>
#include <linux/string.h>
#include "sun8i-ss.h"
static int sun8i_ss_hashkey(struct sun8i_ss_hash_tfm_ctx *tfmctx, const u8 *key,
unsigned int keylen)
{
struct crypto_shash *xtfm;
- struct shash_desc *sdesc;
- size_t len;
- int ret = 0;
+ int ret;
xtfm = crypto_alloc_shash("sha1", 0, CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(xtfm))
return PTR_ERR(xtfm);
- len = sizeof(*sdesc) + crypto_shash_descsize(xtfm);
- sdesc = kmalloc(len, GFP_KERNEL);
- if (!sdesc) {
- ret = -ENOMEM;
- goto err_hashkey_sdesc;
- }
- sdesc->tfm = xtfm;
-
- ret = crypto_shash_init(sdesc);
- if (ret) {
- dev_err(tfmctx->ss->dev, "shash init error ret=%d\n", ret);
- goto err_hashkey;
- }
- ret = crypto_shash_finup(sdesc, key, keylen, tfmctx->key);
+ ret = crypto_shash_tfm_digest(xtfm, key, keylen, tfmctx->key);
if (ret)
- dev_err(tfmctx->ss->dev, "shash finup error\n");
-err_hashkey:
- kfree(sdesc);
-err_hashkey_sdesc:
+ dev_err(tfmctx->ss->dev, "shash digest error ret=%d\n", ret);
+
crypto_free_shash(xtfm);
return ret;
}
int sun8i_ss_hmac_setkey(struct crypto_ahash *ahash, const u8 *key,
unsigned int keylen)
{
struct sun8i_ss_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(ahash);
int digestsize, i;
int bs = crypto_ahash_blocksize(ahash);
base-commit: 2af9b20dbb39f6ebf9b9b6c090271594627d818e
--
2.42.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] crypto: sun8i-ss - use crypto_shash_tfm_digest() in sun8i_ss_hashkey()
2023-10-29 4:56 [PATCH] crypto: sun8i-ss - use crypto_shash_tfm_digest() in sun8i_ss_hashkey() Eric Biggers
@ 2023-11-17 11:21 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2023-11-17 11:21 UTC (permalink / raw)
To: Eric Biggers; +Cc: linux-crypto, linux-sunxi, clabbe.montjoie
Eric Biggers <ebiggers@kernel.org> wrote:
> From: Eric Biggers <ebiggers@google.com>
>
> Simplify sun8i_ss_hashkey() by using crypto_shash_tfm_digest() instead
> of an alloc+init+update+final sequence. This should also improve
> performance.
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> .../crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 25 +++----------------
> 1 file changed, 4 insertions(+), 21 deletions(-)
Patch 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] 2+ messages in thread
end of thread, other threads:[~2023-11-17 11:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-29 4:56 [PATCH] crypto: sun8i-ss - use crypto_shash_tfm_digest() in sun8i_ss_hashkey() Eric Biggers
2023-11-17 11:21 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox