mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
crypto: zynqmp-sha - Use API partial block handling
Use the Crypto API partial block handling. As this was the last user of the extra fields in struct sha3_state, remove them. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
0d474be267
commit
201e9ec3b6
2 changed files with 22 additions and 54 deletions
|
@ -3,7 +3,6 @@
|
|||
* Xilinx ZynqMP SHA Driver.
|
||||
* Copyright (c) 2022 Xilinx Inc.
|
||||
*/
|
||||
#include <crypto/hash.h>
|
||||
#include <crypto/internal/hash.h>
|
||||
#include <crypto/sha3.h>
|
||||
#include <linux/cacheflush.h>
|
||||
|
@ -37,10 +36,6 @@ struct zynqmp_sha_tfm_ctx {
|
|||
struct crypto_shash *fbk_tfm;
|
||||
};
|
||||
|
||||
struct zynqmp_sha_desc_ctx {
|
||||
struct shash_desc fbk_req;
|
||||
};
|
||||
|
||||
static dma_addr_t update_dma_addr, final_dma_addr;
|
||||
static char *ubuf, *fbuf;
|
||||
|
||||
|
@ -64,7 +59,6 @@ static int zynqmp_sha_init_tfm(struct crypto_shash *hash)
|
|||
return PTR_ERR(fallback_tfm);
|
||||
|
||||
if (crypto_shash_descsize(hash) <
|
||||
sizeof(struct zynqmp_sha_desc_ctx) +
|
||||
crypto_shash_descsize(tfm_ctx->fbk_tfm)) {
|
||||
crypto_free_shash(fallback_tfm);
|
||||
return -EINVAL;
|
||||
|
@ -79,58 +73,41 @@ static void zynqmp_sha_exit_tfm(struct crypto_shash *hash)
|
|||
{
|
||||
struct zynqmp_sha_tfm_ctx *tfm_ctx = crypto_shash_ctx(hash);
|
||||
|
||||
if (tfm_ctx->fbk_tfm) {
|
||||
crypto_free_shash(tfm_ctx->fbk_tfm);
|
||||
tfm_ctx->fbk_tfm = NULL;
|
||||
}
|
||||
|
||||
memzero_explicit(tfm_ctx, sizeof(struct zynqmp_sha_tfm_ctx));
|
||||
}
|
||||
|
||||
static int zynqmp_sha_init(struct shash_desc *desc)
|
||||
{
|
||||
struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc);
|
||||
struct zynqmp_sha_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
|
||||
struct crypto_shash *fbtfm = tctx->fbk_tfm;
|
||||
SHASH_DESC_ON_STACK(fbdesc, fbtfm);
|
||||
|
||||
dctx->fbk_req.tfm = tctx->fbk_tfm;
|
||||
return crypto_shash_init(&dctx->fbk_req);
|
||||
fbdesc->tfm = fbtfm;
|
||||
return crypto_shash_init(fbdesc) ?:
|
||||
crypto_shash_export_core(fbdesc, shash_desc_ctx(desc));
|
||||
}
|
||||
|
||||
static int zynqmp_sha_update(struct shash_desc *desc, const u8 *data, unsigned int length)
|
||||
{
|
||||
struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc);
|
||||
struct zynqmp_sha_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
|
||||
struct crypto_shash *fbtfm = tctx->fbk_tfm;
|
||||
SHASH_DESC_ON_STACK(fbdesc, fbtfm);
|
||||
|
||||
return crypto_shash_update(&dctx->fbk_req, data, length);
|
||||
}
|
||||
|
||||
static int zynqmp_sha_final(struct shash_desc *desc, u8 *out)
|
||||
{
|
||||
struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc);
|
||||
|
||||
return crypto_shash_final(&dctx->fbk_req, out);
|
||||
fbdesc->tfm = fbtfm;
|
||||
return crypto_shash_import_core(fbdesc, shash_desc_ctx(desc)) ?:
|
||||
crypto_shash_update(fbdesc, data, length) ?:
|
||||
crypto_shash_export_core(fbdesc, shash_desc_ctx(desc));
|
||||
}
|
||||
|
||||
static int zynqmp_sha_finup(struct shash_desc *desc, const u8 *data, unsigned int length, u8 *out)
|
||||
{
|
||||
struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc);
|
||||
|
||||
return crypto_shash_finup(&dctx->fbk_req, data, length, out);
|
||||
}
|
||||
|
||||
static int zynqmp_sha_import(struct shash_desc *desc, const void *in)
|
||||
{
|
||||
struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc);
|
||||
struct zynqmp_sha_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
|
||||
struct crypto_shash *fbtfm = tctx->fbk_tfm;
|
||||
SHASH_DESC_ON_STACK(fbdesc, fbtfm);
|
||||
|
||||
dctx->fbk_req.tfm = tctx->fbk_tfm;
|
||||
return crypto_shash_import(&dctx->fbk_req, in);
|
||||
}
|
||||
|
||||
static int zynqmp_sha_export(struct shash_desc *desc, void *out)
|
||||
{
|
||||
struct zynqmp_sha_desc_ctx *dctx = shash_desc_ctx(desc);
|
||||
|
||||
return crypto_shash_export(&dctx->fbk_req, out);
|
||||
fbdesc->tfm = fbtfm;
|
||||
return crypto_shash_import_core(fbdesc, shash_desc_ctx(desc)) ?:
|
||||
crypto_shash_finup(fbdesc, data, length, out);
|
||||
}
|
||||
|
||||
static int __zynqmp_sha_digest(struct shash_desc *desc, const u8 *data,
|
||||
|
@ -179,24 +156,20 @@ static struct zynqmp_sha_drv_ctx sha3_drv_ctx = {
|
|||
.sha3_384 = {
|
||||
.init = zynqmp_sha_init,
|
||||
.update = zynqmp_sha_update,
|
||||
.final = zynqmp_sha_final,
|
||||
.finup = zynqmp_sha_finup,
|
||||
.digest = zynqmp_sha_digest,
|
||||
.export = zynqmp_sha_export,
|
||||
.import = zynqmp_sha_import,
|
||||
.init_tfm = zynqmp_sha_init_tfm,
|
||||
.exit_tfm = zynqmp_sha_exit_tfm,
|
||||
.descsize = sizeof(struct zynqmp_sha_desc_ctx) +
|
||||
sizeof(struct sha3_state),
|
||||
.statesize = sizeof(struct sha3_state),
|
||||
.descsize = sizeof(struct sha3_state),
|
||||
.digestsize = SHA3_384_DIGEST_SIZE,
|
||||
.base = {
|
||||
.cra_name = "sha3-384",
|
||||
.cra_driver_name = "zynqmp-sha3-384",
|
||||
.cra_priority = 300,
|
||||
.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY |
|
||||
CRYPTO_ALG_ALLOCATES_MEMORY |
|
||||
CRYPTO_ALG_NEED_FALLBACK,
|
||||
CRYPTO_ALG_NEED_FALLBACK |
|
||||
CRYPTO_AHASH_ALG_BLOCK_ONLY |
|
||||
CRYPTO_AHASH_ALG_FINUP_MAX,
|
||||
.cra_blocksize = SHA3_384_BLOCK_SIZE,
|
||||
.cra_ctxsize = sizeof(struct zynqmp_sha_tfm_ctx),
|
||||
.cra_module = THIS_MODULE,
|
||||
|
|
|
@ -25,11 +25,6 @@ struct shash_desc;
|
|||
|
||||
struct sha3_state {
|
||||
u64 st[SHA3_STATE_SIZE / 8];
|
||||
unsigned int rsiz;
|
||||
unsigned int rsizw;
|
||||
|
||||
unsigned int partial;
|
||||
u8 buf[SHA3_224_BLOCK_SIZE];
|
||||
};
|
||||
|
||||
int crypto_sha3_init(struct shash_desc *desc);
|
||||
|
|
Loading…
Add table
Reference in a new issue