Skip to content

Commit 1f38ad8

Browse files
committed
crypto: sha512 - Export struct sha512_state
This patch renames struct sha512_ctx and exports it as struct sha512_state so that other sha512 implementations can use it as the reference structure for exporting their state. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent ac95301 commit 1f38ad8

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎crypto/sha512_generic.c‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
#include <linux/percpu.h>
2222
#include <asm/byteorder.h>
2323

24-
struct sha512_ctx {
25-
u64 state[8];
26-
u32 count[4];
27-
u8 buf[128];
28-
};
29-
3024
static DEFINE_PER_CPU(u64[80], msg_schedule);
3125

3226
static inline u64 Ch(u64 x, u64 y, u64 z)
@@ -141,7 +135,7 @@ sha512_transform(u64 *state, const u8 *input)
141135
static int
142136
sha512_init(struct shash_desc *desc)
143137
{
144-
struct sha512_ctx *sctx = shash_desc_ctx(desc);
138+
struct sha512_state *sctx = shash_desc_ctx(desc);
145139
sctx->state[0] = SHA512_H0;
146140
sctx->state[1] = SHA512_H1;
147141
sctx->state[2] = SHA512_H2;
@@ -158,7 +152,7 @@ sha512_init(struct shash_desc *desc)
158152
static int
159153
sha384_init(struct shash_desc *desc)
160154
{
161-
struct sha512_ctx *sctx = shash_desc_ctx(desc);
155+
struct sha512_state *sctx = shash_desc_ctx(desc);
162156
sctx->state[0] = SHA384_H0;
163157
sctx->state[1] = SHA384_H1;
164158
sctx->state[2] = SHA384_H2;
@@ -175,7 +169,7 @@ sha384_init(struct shash_desc *desc)
175169
static int
176170
sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len)
177171
{
178-
struct sha512_ctx *sctx = shash_desc_ctx(desc);
172+
struct sha512_state *sctx = shash_desc_ctx(desc);
179173

180174
unsigned int i, index, part_len;
181175

@@ -214,7 +208,7 @@ sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len)
214208
static int
215209
sha512_final(struct shash_desc *desc, u8 *hash)
216210
{
217-
struct sha512_ctx *sctx = shash_desc_ctx(desc);
211+
struct sha512_state *sctx = shash_desc_ctx(desc);
218212
static u8 padding[128] = { 0x80, };
219213
__be64 *dst = (__be64 *)hash;
220214
__be32 bits[4];
@@ -240,7 +234,7 @@ sha512_final(struct shash_desc *desc, u8 *hash)
240234
dst[i] = cpu_to_be64(sctx->state[i]);
241235

242236
/* Zeroize sensitive information. */
243-
memset(sctx, 0, sizeof(struct sha512_ctx));
237+
memset(sctx, 0, sizeof(struct sha512_state));
244238

245239
return 0;
246240
}
@@ -262,7 +256,7 @@ static struct shash_alg sha512 = {
262256
.init = sha512_init,
263257
.update = sha512_update,
264258
.final = sha512_final,
265-
.descsize = sizeof(struct sha512_ctx),
259+
.descsize = sizeof(struct sha512_state),
266260
.base = {
267261
.cra_name = "sha512",
268262
.cra_flags = CRYPTO_ALG_TYPE_SHASH,
@@ -276,7 +270,7 @@ static struct shash_alg sha384 = {
276270
.init = sha384_init,
277271
.update = sha512_update,
278272
.final = sha384_final,
279-
.descsize = sizeof(struct sha512_ctx),
273+
.descsize = sizeof(struct sha512_state),
280274
.base = {
281275
.cra_name = "sha384",
282276
.cra_flags = CRYPTO_ALG_TYPE_SHASH,

‎include/crypto/sha.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,10 @@ struct sha256_state {
7676
u8 buf[SHA256_BLOCK_SIZE];
7777
};
7878

79+
struct sha512_state {
80+
u64 state[8];
81+
u32 count[4];
82+
u8 buf[128];
83+
};
84+
7985
#endif

0 commit comments

Comments
 (0)