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
8#ifndef _CRYPTO_SHA256_BASE_H8#ifndef _CRYPTO_SHA256_BASE_H
9#define _CRYPTO_SHA256_BASE_H9#define _CRYPTO_SHA256_BASE_H
10 10
11#include <asm/byteorder.h>
12#include <asm/unaligned.h>
11#include <crypto/internal/hash.h>13#include <crypto/internal/hash.h>
12#include <crypto/sha2.h>14#include <crypto/sha2.h>
13#include <linux/crypto.h>
14#include <linux/module.h>
15#include <linux/string.h>15#include <linux/string.h>
16 16#include <linux/types.h>
17#include <asm/unaligned.h>
18 17
19typedef void (sha256_block_fn)(struct sha256_state *sst, u8 const *src,18typedef void (sha256_block_fn)(struct sha256_state *sst, u8 const *src,
20 int blocks);19 int blocks);
@@ -35,12 +34,11 @@ static inline int sha256_base_init(struct shash_desc *desc) · 14 unmodified lines
35 return 0;34 return 0;
36}35}
37 36
38static inline int sha256_base_do_update(struct shash_desc *desc,37static inline int lib_sha256_base_do_update(struct sha256_state *sctx,
39 const u8 *data,38 const u8 *data,
40 unsigned int len,39 unsigned int len,
41 sha256_block_fn *block_fn)40 sha256_block_fn *block_fn)
42{41{
43 struct sha256_state *sctx = shash_desc_ctx(desc);
44 unsigned int partial = sctx->count % SHA256_BLOCK_SIZE;42 unsigned int partial = sctx->count % SHA256_BLOCK_SIZE;
45 43
46 sctx->count += len;44 sctx->count += len;
@@ -73,11 +71,20 @@ static inline int sha256_base_do_update(struct shash_desc *desc, · 26 unmodified lines
73 return 0;71 return 0;
74}72}
75 73
76static inline int sha256_base_do_finalize(struct shash_desc *desc,74static inline int sha256_base_do_update(struct shash_desc *desc,
77 sha256_block_fn *block_fn)75 const u8 *data,
76 unsigned int len,
77 sha256_block_fn *block_fn)
78{78{
79 const int bit_offset = SHA256_BLOCK_SIZE - sizeof(__be64);
80 struct sha256_state *sctx = shash_desc_ctx(desc);79 struct sha256_state *sctx = shash_desc_ctx(desc);
80
81 return lib_sha256_base_do_update(sctx, data, len, block_fn);
82}
83
84static 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);
81 __be64 *bits = (__be64 *)(sctx->buf + bit_offset);88 __be64 *bits = (__be64 *)(sctx->buf + bit_offset);
82 unsigned int partial = sctx->count % SHA256_BLOCK_SIZE;89 unsigned int partial = sctx->count % SHA256_BLOCK_SIZE;
83 90
@@ -96,10 +103,17 @@ static inline int sha256_base_do_finalize(struct shash_desc *desc, · 12 unmodified lines
96 return 0;103 return 0;
97}104}
98 105
99static inline int sha256_base_finish(struct shash_desc *desc, u8 *out)106static inline int sha256_base_do_finalize(struct shash_desc *desc,
107 sha256_block_fn *block_fn)
100{108{
101 unsigned int digest_size = crypto_shash_digestsize(desc->tfm);
102 struct sha256_state *sctx = shash_desc_ctx(desc);109 struct sha256_state *sctx = shash_desc_ctx(desc);
110
111 return lib_sha256_base_do_finalize(sctx, block_fn);
112}
113
114static inline int lib_sha256_base_finish(struct sha256_state *sctx, u8 *out,
115 unsigned int digest_size)
116{
103 __be32 *digest = (__be32 *)out;117 __be32 *digest = (__be32 *)out;
104 int i;118 int i;
105 119
@@ -110,4 +124,12 @@ static inline int sha256_base_finish(struct shash_desc *desc, u8 *out) · 4 unmodified lines
110 return 0;124 return 0;
111}125}
112 126
127static 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
113#endif /* _CRYPTO_SHA256_BASE_H */135#endif /* _CRYPTO_SHA256_BASE_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t