History

crypto: lib/sha256 - Use generic code from sha256_base

Instead of duplicating the sha256 block processing code, reuse the common code from crypto/sha256_base.h.

Herbert Xu committed 3 years ago

Commit 6c19f3b1 parent 70d391a2 files · +55 −68Browse files

Showing the changes to include/crypto (1 of 2 files). Show all

Unified · Split

include/crypto/sha256_base.h+36−14
@@ -8,13 +8,12 @@ · 7 unmodified lines
88 #ifndef _CRYPTO_SHA256_BASE_H
99 #define _CRYPTO_SHA256_BASE_H
1010
11+#include <asm/byteorder.h>
12+#include <asm/unaligned.h>
1113 #include <crypto/internal/hash.h>
1214 #include <crypto/sha2.h>
13−#include <linux/crypto.h>
14−#include <linux/module.h>
1515 #include <linux/string.h>
16−
17−#include <asm/unaligned.h>
16+#include <linux/types.h>
1817
1918 typedef void (sha256_block_fn)(struct sha256_state *sst, u8 const *src,
2019 int blocks);
@@ -35,12 +34,11 @@ static inline int sha256_base_init(struct shash_desc *desc) · 14 unmodified lines
3534 return 0;
3635 }
3736
38−static inline int sha256_base_do_update(struct shash_desc *desc,
39− const u8 *data,
40− unsigned int len,
41− sha256_block_fn *block_fn)
37+static inline int lib_sha256_base_do_update(struct sha256_state *sctx,
38+ const u8 *data,
39+ unsigned int len,
40+ sha256_block_fn *block_fn)
4241 {
43− struct sha256_state *sctx = shash_desc_ctx(desc);
4442 unsigned int partial = sctx->count % SHA256_BLOCK_SIZE;
4543
4644 sctx->count += len;
@@ -73,11 +71,20 @@ static inline int sha256_base_do_update(struct shash_desc *desc, · 26 unmodified lines
7371 return 0;
7472 }
7573
76−static inline int sha256_base_do_finalize(struct shash_desc *desc,
77− sha256_block_fn *block_fn)
74+static inline int sha256_base_do_update(struct shash_desc *desc,
75+ const u8 *data,
76+ unsigned int len,
77+ sha256_block_fn *block_fn)
7878 {
79− const int bit_offset = SHA256_BLOCK_SIZE - sizeof(__be64);
8079 struct sha256_state *sctx = shash_desc_ctx(desc);
80+
81+ return lib_sha256_base_do_update(sctx, data, len, block_fn);
82+}
83+
84+static inline int lib_sha256_base_do_finalize(struct sha256_state *sctx,
85+ sha256_block_fn *block_fn)
86+{
87+ const int bit_offset = SHA256_BLOCK_SIZE - sizeof(__be64);
8188 __be64 *bits = (__be64 *)(sctx->buf + bit_offset);
8289 unsigned int partial = sctx->count % SHA256_BLOCK_SIZE;
8390
@@ -96,10 +103,17 @@ static inline int sha256_base_do_finalize(struct shash_desc *desc, · 12 unmodified lines
96103 return 0;
97104 }
98105
99−static inline int sha256_base_finish(struct shash_desc *desc, u8 *out)
106+static inline int sha256_base_do_finalize(struct shash_desc *desc,
107+ sha256_block_fn *block_fn)
100108 {
101− unsigned int digest_size = crypto_shash_digestsize(desc->tfm);
102109 struct sha256_state *sctx = shash_desc_ctx(desc);
110+
111+ return lib_sha256_base_do_finalize(sctx, block_fn);
112+}
113+
114+static inline int lib_sha256_base_finish(struct sha256_state *sctx, u8 *out,
115+ unsigned int digest_size)
116+{
103117 __be32 *digest = (__be32 *)out;
104118 int i;
105119
@@ -110,4 +124,12 @@ static inline int sha256_base_finish(struct shash_desc *desc, u8 *out) · 4 unmodified lines
110124 return 0;
111125 }
112126
127+static inline int sha256_base_finish(struct shash_desc *desc, u8 *out)
128+{
129+ unsigned int digest_size = crypto_shash_digestsize(desc->tfm);
130+ struct sha256_state *sctx = shash_desc_ctx(desc);
131+
132+ return lib_sha256_base_finish(sctx, out, digest_size);
133+}
134+
113135 #endif /* _CRYPTO_SHA256_BASE_H */