mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-27 15:36:48 +00:00
crypto: riscv/sm3 - Use API partial block handling
Use the Crypto API partial block handling. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
045f17b444
commit
1523eaed0a
@ -13,8 +13,9 @@
|
||||
#include <asm/vector.h>
|
||||
#include <crypto/internal/hash.h>
|
||||
#include <crypto/internal/simd.h>
|
||||
#include <crypto/sm3.h>
|
||||
#include <crypto/sm3_base.h>
|
||||
#include <linux/linkage.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
/*
|
||||
@ -24,8 +25,8 @@
|
||||
asmlinkage void sm3_transform_zvksh_zvkb(
|
||||
struct sm3_state *state, const u8 *data, int num_blocks);
|
||||
|
||||
static int riscv64_sm3_update(struct shash_desc *desc, const u8 *data,
|
||||
unsigned int len)
|
||||
static void sm3_block(struct sm3_state *state, const u8 *data,
|
||||
int num_blocks)
|
||||
{
|
||||
/*
|
||||
* Ensure struct sm3_state begins directly with the SM3
|
||||
@ -35,52 +36,36 @@ static int riscv64_sm3_update(struct shash_desc *desc, const u8 *data,
|
||||
|
||||
if (crypto_simd_usable()) {
|
||||
kernel_vector_begin();
|
||||
sm3_base_do_update(desc, data, len, sm3_transform_zvksh_zvkb);
|
||||
sm3_transform_zvksh_zvkb(state, data, num_blocks);
|
||||
kernel_vector_end();
|
||||
} else {
|
||||
sm3_update(shash_desc_ctx(desc), data, len);
|
||||
sm3_block_generic(state, data, num_blocks);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int riscv64_sm3_update(struct shash_desc *desc, const u8 *data,
|
||||
unsigned int len)
|
||||
{
|
||||
return sm3_base_do_update_blocks(desc, data, len, sm3_block);
|
||||
}
|
||||
|
||||
static int riscv64_sm3_finup(struct shash_desc *desc, const u8 *data,
|
||||
unsigned int len, u8 *out)
|
||||
{
|
||||
struct sm3_state *ctx;
|
||||
|
||||
if (crypto_simd_usable()) {
|
||||
kernel_vector_begin();
|
||||
if (len)
|
||||
sm3_base_do_update(desc, data, len,
|
||||
sm3_transform_zvksh_zvkb);
|
||||
sm3_base_do_finalize(desc, sm3_transform_zvksh_zvkb);
|
||||
kernel_vector_end();
|
||||
|
||||
return sm3_base_finish(desc, out);
|
||||
}
|
||||
|
||||
ctx = shash_desc_ctx(desc);
|
||||
if (len)
|
||||
sm3_update(ctx, data, len);
|
||||
sm3_final(ctx, out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int riscv64_sm3_final(struct shash_desc *desc, u8 *out)
|
||||
{
|
||||
return riscv64_sm3_finup(desc, NULL, 0, out);
|
||||
sm3_base_do_finup(desc, data, len, sm3_block);
|
||||
return sm3_base_finish(desc, out);
|
||||
}
|
||||
|
||||
static struct shash_alg riscv64_sm3_alg = {
|
||||
.init = sm3_base_init,
|
||||
.update = riscv64_sm3_update,
|
||||
.final = riscv64_sm3_final,
|
||||
.finup = riscv64_sm3_finup,
|
||||
.descsize = sizeof(struct sm3_state),
|
||||
.descsize = SM3_STATE_SIZE,
|
||||
.digestsize = SM3_DIGEST_SIZE,
|
||||
.base = {
|
||||
.cra_blocksize = SM3_BLOCK_SIZE,
|
||||
.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY |
|
||||
CRYPTO_AHASH_ALG_FINUP_MAX,
|
||||
.cra_priority = 300,
|
||||
.cra_name = "sm3",
|
||||
.cra_driver_name = "sm3-riscv64-zvksh-zvkb",
|
||||
|
Loading…
Reference in New Issue
Block a user