Instead of duplicating the sha256 block processing code, reuse the common code from crypto/sha256_base.h.
Showing the changes to include/crypto (1 of 2 files). Show all
Unified · Split
| @@ -8,13 +8,12 @@ · 7 unmodified lines | ||
| 8 | 8 | #ifndef _CRYPTO_SHA256_BASE_H |
| 9 | 9 | #define _CRYPTO_SHA256_BASE_H |
| 10 | 10 | |
| 11 | +#include <asm/byteorder.h> | |
| 12 | +#include <asm/unaligned.h> | |
| 11 | 13 | #include <crypto/internal/hash.h> |
| 12 | 14 | #include <crypto/sha2.h> |
| 13 | −#include <linux/crypto.h> | |
| 14 | −#include <linux/module.h> | |
| 15 | 15 | #include <linux/string.h> |
| 16 | − | |
| 17 | −#include <asm/unaligned.h> | |
| 16 | +#include <linux/types.h> | |
| 18 | 17 | |
| 19 | 18 | typedef void (sha256_block_fn)(struct sha256_state *sst, u8 const *src, |
| 20 | 19 | int blocks); |
| @@ -35,12 +34,11 @@ static inline int sha256_base_init(struct shash_desc *desc) · 14 unmodified lines | ||
| 35 | 34 | return 0; |
| 36 | 35 | } |
| 37 | 36 | |
| 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) | |
| 42 | 41 | { |
| 43 | − struct sha256_state *sctx = shash_desc_ctx(desc); | |
| 44 | 42 | unsigned int partial = sctx->count % SHA256_BLOCK_SIZE; |
| 45 | 43 | |
| 46 | 44 | sctx->count += len; |
| @@ -73,11 +71,20 @@ static inline int sha256_base_do_update(struct shash_desc *desc, · 26 unmodified lines | ||
| 73 | 71 | return 0; |
| 74 | 72 | } |
| 75 | 73 | |
| 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) | |
| 78 | 78 | { |
| 79 | − const int bit_offset = SHA256_BLOCK_SIZE - sizeof(__be64); | |
| 80 | 79 | 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); | |
| 81 | 88 | __be64 *bits = (__be64 *)(sctx->buf + bit_offset); |
| 82 | 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 | 103 | return 0; |
| 97 | 104 | } |
| 98 | 105 | |
| 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) | |
| 100 | 108 | { |
| 101 | − unsigned int digest_size = crypto_shash_digestsize(desc->tfm); | |
| 102 | 109 | 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 | +{ | |
| 103 | 117 | __be32 *digest = (__be32 *)out; |
| 104 | 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 | 124 | return 0; |
| 111 | 125 | } |
| 112 | 126 | |
| 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 | + | |
| 113 | 135 | #endif /* _CRYPTO_SHA256_BASE_H */ |