mirror of https://github.com/torvalds/linux.git
crypto: riscv/sha512 - 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
0b4aa3d10f
commit
561aab1104
|
|
@ -14,7 +14,7 @@
|
|||
#include <crypto/internal/hash.h>
|
||||
#include <crypto/internal/simd.h>
|
||||
#include <crypto/sha512_base.h>
|
||||
#include <linux/linkage.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
/*
|
||||
|
|
@ -24,8 +24,8 @@
|
|||
asmlinkage void sha512_transform_zvknhb_zvkb(
|
||||
struct sha512_state *state, const u8 *data, int num_blocks);
|
||||
|
||||
static int riscv64_sha512_update(struct shash_desc *desc, const u8 *data,
|
||||
unsigned int len)
|
||||
static void sha512_block(struct sha512_state *state, const u8 *data,
|
||||
int num_blocks)
|
||||
{
|
||||
/*
|
||||
* Ensure struct sha512_state begins directly with the SHA-512
|
||||
|
|
@ -35,35 +35,24 @@ static int riscv64_sha512_update(struct shash_desc *desc, const u8 *data,
|
|||
|
||||
if (crypto_simd_usable()) {
|
||||
kernel_vector_begin();
|
||||
sha512_base_do_update(desc, data, len,
|
||||
sha512_transform_zvknhb_zvkb);
|
||||
sha512_transform_zvknhb_zvkb(state, data, num_blocks);
|
||||
kernel_vector_end();
|
||||
} else {
|
||||
crypto_sha512_update(desc, data, len);
|
||||
sha512_generic_block_fn(state, data, num_blocks);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int riscv64_sha512_update(struct shash_desc *desc, const u8 *data,
|
||||
unsigned int len)
|
||||
{
|
||||
return sha512_base_do_update_blocks(desc, data, len, sha512_block);
|
||||
}
|
||||
|
||||
static int riscv64_sha512_finup(struct shash_desc *desc, const u8 *data,
|
||||
unsigned int len, u8 *out)
|
||||
{
|
||||
if (crypto_simd_usable()) {
|
||||
kernel_vector_begin();
|
||||
if (len)
|
||||
sha512_base_do_update(desc, data, len,
|
||||
sha512_transform_zvknhb_zvkb);
|
||||
sha512_base_do_finalize(desc, sha512_transform_zvknhb_zvkb);
|
||||
kernel_vector_end();
|
||||
|
||||
return sha512_base_finish(desc, out);
|
||||
}
|
||||
|
||||
return crypto_sha512_finup(desc, data, len, out);
|
||||
}
|
||||
|
||||
static int riscv64_sha512_final(struct shash_desc *desc, u8 *out)
|
||||
{
|
||||
return riscv64_sha512_finup(desc, NULL, 0, out);
|
||||
sha512_base_do_finup(desc, data, len, sha512_block);
|
||||
return sha512_base_finish(desc, out);
|
||||
}
|
||||
|
||||
static int riscv64_sha512_digest(struct shash_desc *desc, const u8 *data,
|
||||
|
|
@ -77,14 +66,15 @@ static struct shash_alg riscv64_sha512_algs[] = {
|
|||
{
|
||||
.init = sha512_base_init,
|
||||
.update = riscv64_sha512_update,
|
||||
.final = riscv64_sha512_final,
|
||||
.finup = riscv64_sha512_finup,
|
||||
.digest = riscv64_sha512_digest,
|
||||
.descsize = sizeof(struct sha512_state),
|
||||
.descsize = SHA512_STATE_SIZE,
|
||||
.digestsize = SHA512_DIGEST_SIZE,
|
||||
.base = {
|
||||
.cra_blocksize = SHA512_BLOCK_SIZE,
|
||||
.cra_priority = 300,
|
||||
.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY |
|
||||
CRYPTO_AHASH_ALG_FINUP_MAX,
|
||||
.cra_name = "sha512",
|
||||
.cra_driver_name = "sha512-riscv64-zvknhb-zvkb",
|
||||
.cra_module = THIS_MODULE,
|
||||
|
|
@ -92,13 +82,14 @@ static struct shash_alg riscv64_sha512_algs[] = {
|
|||
}, {
|
||||
.init = sha384_base_init,
|
||||
.update = riscv64_sha512_update,
|
||||
.final = riscv64_sha512_final,
|
||||
.finup = riscv64_sha512_finup,
|
||||
.descsize = sizeof(struct sha512_state),
|
||||
.descsize = SHA512_STATE_SIZE,
|
||||
.digestsize = SHA384_DIGEST_SIZE,
|
||||
.base = {
|
||||
.cra_blocksize = SHA384_BLOCK_SIZE,
|
||||
.cra_priority = 300,
|
||||
.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY |
|
||||
CRYPTO_AHASH_ALG_FINUP_MAX,
|
||||
.cra_name = "sha384",
|
||||
.cra_driver_name = "sha384-riscv64-zvknhb-zvkb",
|
||||
.cra_module = THIS_MODULE,
|
||||
|
|
|
|||
|
|
@ -145,14 +145,15 @@ sha512_transform(u64 *state, const u8 *input)
|
|||
state[4] += e; state[5] += f; state[6] += g; state[7] += h;
|
||||
}
|
||||
|
||||
static void sha512_generic_block_fn(struct sha512_state *sst, u8 const *src,
|
||||
int blocks)
|
||||
void sha512_generic_block_fn(struct sha512_state *sst, u8 const *src,
|
||||
int blocks)
|
||||
{
|
||||
while (blocks--) {
|
||||
sha512_transform(sst->state, src);
|
||||
src += SHA512_BLOCK_SIZE;
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(sha512_generic_block_fn);
|
||||
|
||||
int crypto_sha512_update(struct shash_desc *desc, const u8 *data,
|
||||
unsigned int len)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@
|
|||
|
||||
#include <crypto/internal/hash.h>
|
||||
#include <crypto/sha2.h>
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/math.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/unaligned.h>
|
||||
|
||||
typedef void (sha512_block_fn)(struct sha512_state *sst, u8 const *src,
|
||||
|
|
@ -175,4 +178,7 @@ static inline int sha512_base_finish(struct shash_desc *desc, u8 *out)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void sha512_generic_block_fn(struct sha512_state *sst, u8 const *src,
|
||||
int blocks);
|
||||
|
||||
#endif /* _CRYPTO_SHA512_BASE_H */
|
||||
|
|
|
|||
Loading…
Reference in New Issue