crypto: sha256_base - Remove partial block helpers
authorHerbert Xu <herbert@gondor.apana.org.au>
Fri, 18 Apr 2025 03:00:08 +0000 (11:00 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 23 Apr 2025 07:52:46 +0000 (15:52 +0800)
Now that all sha256_base users have been converted to use the API
partial block handling, remove the partial block helpers.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/x86/crypto/sha256_ssse3_glue.c
include/crypto/sha256_base.h
lib/crypto/sha256.c

index 367ce4830fa4567b1997233500e7b0345613ff95..a5d3be00550b818fc5aee30c943734e531fc2e24 100644 (file)
@@ -51,7 +51,7 @@ MODULE_DEVICE_TABLE(x86cpu, module_cpu_ids);
 
 static int _sha256_update(struct shash_desc *desc, const u8 *data,
                          unsigned int len,
-                         crypto_sha256_block_fn *sha256_xform)
+                         sha256_block_fn *sha256_xform)
 {
        int remain;
 
@@ -69,7 +69,7 @@ static int _sha256_update(struct shash_desc *desc, const u8 *data,
 }
 
 static int sha256_finup(struct shash_desc *desc, const u8 *data,
-             unsigned int len, u8 *out, crypto_sha256_block_fn *sha256_xform)
+             unsigned int len, u8 *out, sha256_block_fn *sha256_xform)
 {
        kernel_fpu_begin();
        sha256_base_do_finup(desc, data, len, sha256_xform);
index b9d3583b625639c02f7cc928a23e19c16883a01f..08cd5e41d4fdb5ebd60c2d8ad9e10b5a2f218c7f 100644 (file)
 #include <linux/types.h>
 #include <linux/unaligned.h>
 
-typedef void (sha256_block_fn)(struct sha256_state *sst, u8 const *src,
+typedef void (sha256_block_fn)(struct crypto_sha256_state *sst, u8 const *src,
                               int blocks);
-typedef void (crypto_sha256_block_fn)(struct crypto_sha256_state *sst,
-                                     u8 const *src, int blocks);
 
 static inline int sha224_base_init(struct shash_desc *desc)
 {
@@ -42,6 +40,7 @@ static inline int lib_sha256_base_do_update(struct sha256_state *sctx,
                                            sha256_block_fn *block_fn)
 {
        unsigned int partial = sctx->count % SHA256_BLOCK_SIZE;
+       struct crypto_sha256_state *state = (void *)sctx;
 
        sctx->count += len;
 
@@ -55,14 +54,14 @@ static inline int lib_sha256_base_do_update(struct sha256_state *sctx,
                        data += p;
                        len -= p;
 
-                       block_fn(sctx, sctx->buf, 1);
+                       block_fn(state, sctx->buf, 1);
                }
 
                blocks = len / SHA256_BLOCK_SIZE;
                len %= SHA256_BLOCK_SIZE;
 
                if (blocks) {
-                       block_fn(sctx, data, blocks);
+                       block_fn(state, data, blocks);
                        data += blocks * SHA256_BLOCK_SIZE;
                }
                partial = 0;
@@ -73,19 +72,9 @@ static inline int lib_sha256_base_do_update(struct sha256_state *sctx,
        return 0;
 }
 
-static inline int sha256_base_do_update(struct shash_desc *desc,
-                                       const u8 *data,
-                                       unsigned int len,
-                                       sha256_block_fn *block_fn)
-{
-       struct sha256_state *sctx = shash_desc_ctx(desc);
-
-       return lib_sha256_base_do_update(sctx, data, len, block_fn);
-}
-
 static inline int lib_sha256_base_do_update_blocks(
        struct crypto_sha256_state *sctx, const u8 *data, unsigned int len,
-       crypto_sha256_block_fn *block_fn)
+       sha256_block_fn *block_fn)
 {
        unsigned int remain = len - round_down(len, SHA256_BLOCK_SIZE);
 
@@ -96,7 +85,7 @@ static inline int lib_sha256_base_do_update_blocks(
 
 static inline int sha256_base_do_update_blocks(
        struct shash_desc *desc, const u8 *data, unsigned int len,
-       crypto_sha256_block_fn *block_fn)
+       sha256_block_fn *block_fn)
 {
        return lib_sha256_base_do_update_blocks(shash_desc_ctx(desc), data,
                                                len, block_fn);
@@ -104,7 +93,7 @@ static inline int sha256_base_do_update_blocks(
 
 static inline int lib_sha256_base_do_finup(struct crypto_sha256_state *sctx,
                                           const u8 *src, unsigned int len,
-                                          crypto_sha256_block_fn *block_fn)
+                                          sha256_block_fn *block_fn)
 {
        unsigned int bit_offset = SHA256_BLOCK_SIZE / 8 - 1;
        union {
@@ -126,7 +115,7 @@ static inline int lib_sha256_base_do_finup(struct crypto_sha256_state *sctx,
 
 static inline int sha256_base_do_finup(struct shash_desc *desc,
                                       const u8 *src, unsigned int len,
-                                      crypto_sha256_block_fn *block_fn)
+                                      sha256_block_fn *block_fn)
 {
        struct crypto_sha256_state *sctx = shash_desc_ctx(desc);
 
@@ -144,23 +133,11 @@ static inline int sha256_base_do_finup(struct shash_desc *desc,
 static inline int lib_sha256_base_do_finalize(struct sha256_state *sctx,
                                              sha256_block_fn *block_fn)
 {
-       const int bit_offset = SHA256_BLOCK_SIZE - sizeof(__be64);
-       __be64 *bits = (__be64 *)(sctx->buf + bit_offset);
        unsigned int partial = sctx->count % SHA256_BLOCK_SIZE;
+       struct crypto_sha256_state *state = (void *)sctx;
 
-       sctx->buf[partial++] = 0x80;
-       if (partial > bit_offset) {
-               memset(sctx->buf + partial, 0x0, SHA256_BLOCK_SIZE - partial);
-               partial = 0;
-
-               block_fn(sctx, sctx->buf, 1);
-       }
-
-       memset(sctx->buf + partial, 0x0, bit_offset - partial);
-       *bits = cpu_to_be64(sctx->count << 3);
-       block_fn(sctx, sctx->buf, 1);
-
-       return 0;
+       sctx->count -= partial;
+       return lib_sha256_base_do_finup(state, sctx->buf, partial, block_fn);
 }
 
 static inline int sha256_base_do_finalize(struct shash_desc *desc,
@@ -182,12 +159,11 @@ static inline int __sha256_base_finish(u32 state[SHA256_DIGEST_SIZE / 4],
        return 0;
 }
 
-static inline int lib_sha256_base_finish(struct sha256_state *sctx, u8 *out,
-                                        unsigned int digest_size)
+static inline void lib_sha256_base_finish(struct sha256_state *sctx, u8 *out,
+                                         unsigned int digest_size)
 {
        __sha256_base_finish(sctx->state, out, digest_size);
        memzero_explicit(sctx, sizeof(*sctx));
-       return 0;
 }
 
 static inline int sha256_base_finish(struct shash_desc *desc, u8 *out)
index 39ead0222937679c8747ce5919bf25129968cb1d..a89bab377de1a4c4878bdf739d0bc7ddbfd3a431 100644 (file)
@@ -132,22 +132,15 @@ void sha256_transform_blocks(struct crypto_sha256_state *sst,
 }
 EXPORT_SYMBOL_GPL(sha256_transform_blocks);
 
-static void lib_sha256_transform_blocks(struct sha256_state *sctx,
-                                       const u8 *input, int blocks)
-{
-       sha256_transform_blocks((struct crypto_sha256_state *)sctx, input,
-                               blocks);
-}
-
 void sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
 {
-       lib_sha256_base_do_update(sctx, data, len, lib_sha256_transform_blocks);
+       lib_sha256_base_do_update(sctx, data, len, sha256_transform_blocks);
 }
 EXPORT_SYMBOL(sha256_update);
 
 static void __sha256_final(struct sha256_state *sctx, u8 *out, int digest_size)
 {
-       lib_sha256_base_do_finalize(sctx, lib_sha256_transform_blocks);
+       lib_sha256_base_do_finalize(sctx, sha256_transform_blocks);
        lib_sha256_base_finish(sctx, out, digest_size);
 }