summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2025-04-18 10:59:48 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2025-04-23 15:52:45 +0800
commit9adeea13ed7f5218028cdc5b11df53e69c39a60f (patch)
tree4c0f3ca48ffde97260979daa850dd43f8bf4a7be
parente6c5597badf2998980639fb83e60696d0f2ce0dd (diff)
crypto: sha256-generic - Use API partial block handling
Use the Crypto API partial block handling. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/sha256_generic.c44
-rw-r--r--include/crypto/sha2.h6
2 files changed, 18 insertions, 32 deletions
diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
index b00521f1a6d4..05084e5bbaec 100644
--- a/crypto/sha256_generic.c
+++ b/crypto/sha256_generic.c
@@ -8,14 +8,10 @@
* SHA224 Support Copyright 2007 Intel Corporation <jonathan.lynch@intel.com>
*/
#include <crypto/internal/hash.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/mm.h>
-#include <linux/types.h>
#include <crypto/sha2.h>
#include <crypto/sha256_base.h>
-#include <asm/byteorder.h>
-#include <linux/unaligned.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
const u8 sha224_zero_message_hash[SHA224_DIGEST_SIZE] = {
0xd1, 0x4a, 0x02, 0x8c, 0x2a, 0x3a, 0x2b, 0xc9, 0x47,
@@ -33,42 +29,37 @@ const u8 sha256_zero_message_hash[SHA256_DIGEST_SIZE] = {
};
EXPORT_SYMBOL_GPL(sha256_zero_message_hash);
-int crypto_sha256_update(struct shash_desc *desc, const u8 *data,
- unsigned int len)
+static void sha256_block(struct crypto_sha256_state *sctx, const u8 *input,
+ int blocks)
{
- sha256_update(shash_desc_ctx(desc), data, len);
- return 0;
+ sha256_transform_blocks(sctx, input, blocks);
}
-EXPORT_SYMBOL(crypto_sha256_update);
-static int crypto_sha256_final(struct shash_desc *desc, u8 *out)
+static int crypto_sha256_update(struct shash_desc *desc, const u8 *data,
+ unsigned int len)
{
- if (crypto_shash_digestsize(desc->tfm) == SHA224_DIGEST_SIZE)
- sha224_final(shash_desc_ctx(desc), out);
- else
- sha256_final(shash_desc_ctx(desc), out);
- return 0;
+ return sha256_base_do_update_blocks(desc, data, len, sha256_block);
}
-int crypto_sha256_finup(struct shash_desc *desc, const u8 *data,
- unsigned int len, u8 *hash)
+static int crypto_sha256_finup(struct shash_desc *desc, const u8 *data,
+ unsigned int len, u8 *hash)
{
- sha256_update(shash_desc_ctx(desc), data, len);
- return crypto_sha256_final(desc, hash);
+ sha256_base_do_finup(desc, data, len, sha256_block);
+ return sha256_base_finish(desc, hash);
}
-EXPORT_SYMBOL(crypto_sha256_finup);
static struct shash_alg sha256_algs[2] = { {
.digestsize = SHA256_DIGEST_SIZE,
.init = sha256_base_init,
.update = crypto_sha256_update,
- .final = crypto_sha256_final,
.finup = crypto_sha256_finup,
- .descsize = sizeof(struct sha256_state),
+ .descsize = sizeof(struct crypto_sha256_state),
.base = {
.cra_name = "sha256",
.cra_driver_name= "sha256-generic",
.cra_priority = 100,
+ .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY |
+ CRYPTO_AHASH_ALG_FINUP_MAX,
.cra_blocksize = SHA256_BLOCK_SIZE,
.cra_module = THIS_MODULE,
}
@@ -76,13 +67,14 @@ static struct shash_alg sha256_algs[2] = { {
.digestsize = SHA224_DIGEST_SIZE,
.init = sha224_base_init,
.update = crypto_sha256_update,
- .final = crypto_sha256_final,
.finup = crypto_sha256_finup,
- .descsize = sizeof(struct sha256_state),
+ .descsize = sizeof(struct crypto_sha256_state),
.base = {
.cra_name = "sha224",
.cra_driver_name= "sha224-generic",
.cra_priority = 100,
+ .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY |
+ CRYPTO_AHASH_ALG_FINUP_MAX,
.cra_blocksize = SHA224_BLOCK_SIZE,
.cra_module = THIS_MODULE,
}
diff --git a/include/crypto/sha2.h b/include/crypto/sha2.h
index d9b1b9932393..a913bad5dd3b 100644
--- a/include/crypto/sha2.h
+++ b/include/crypto/sha2.h
@@ -83,12 +83,6 @@ struct sha512_state {
struct shash_desc;
-extern int crypto_sha256_update(struct shash_desc *desc, const u8 *data,
- unsigned int len);
-
-extern int crypto_sha256_finup(struct shash_desc *desc, const u8 *data,
- unsigned int len, u8 *hash);
-
extern int crypto_sha512_update(struct shash_desc *desc, const u8 *data,
unsigned int len);