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>
This commit is contained in:
Herbert Xu 2009-07-22 11:48:18 +08:00
parent ac95301f27
commit 1f38ad8389
2 changed files with 13 additions and 13 deletions

View file

@ -21,12 +21,6 @@
#include <linux/percpu.h> #include <linux/percpu.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
struct sha512_ctx {
u64 state[8];
u32 count[4];
u8 buf[128];
};
static DEFINE_PER_CPU(u64[80], msg_schedule); static DEFINE_PER_CPU(u64[80], msg_schedule);
static inline u64 Ch(u64 x, u64 y, u64 z) static inline u64 Ch(u64 x, u64 y, u64 z)
@ -141,7 +135,7 @@ sha512_transform(u64 *state, const u8 *input)
static int static int
sha512_init(struct shash_desc *desc) sha512_init(struct shash_desc *desc)
{ {
struct sha512_ctx *sctx = shash_desc_ctx(desc); struct sha512_state *sctx = shash_desc_ctx(desc);
sctx->state[0] = SHA512_H0; sctx->state[0] = SHA512_H0;
sctx->state[1] = SHA512_H1; sctx->state[1] = SHA512_H1;
sctx->state[2] = SHA512_H2; sctx->state[2] = SHA512_H2;
@ -158,7 +152,7 @@ sha512_init(struct shash_desc *desc)
static int static int
sha384_init(struct shash_desc *desc) sha384_init(struct shash_desc *desc)
{ {
struct sha512_ctx *sctx = shash_desc_ctx(desc); struct sha512_state *sctx = shash_desc_ctx(desc);
sctx->state[0] = SHA384_H0; sctx->state[0] = SHA384_H0;
sctx->state[1] = SHA384_H1; sctx->state[1] = SHA384_H1;
sctx->state[2] = SHA384_H2; sctx->state[2] = SHA384_H2;
@ -175,7 +169,7 @@ sha384_init(struct shash_desc *desc)
static int static int
sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len) sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len)
{ {
struct sha512_ctx *sctx = shash_desc_ctx(desc); struct sha512_state *sctx = shash_desc_ctx(desc);
unsigned int i, index, part_len; unsigned int i, index, part_len;
@ -214,7 +208,7 @@ sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len)
static int static int
sha512_final(struct shash_desc *desc, u8 *hash) sha512_final(struct shash_desc *desc, u8 *hash)
{ {
struct sha512_ctx *sctx = shash_desc_ctx(desc); struct sha512_state *sctx = shash_desc_ctx(desc);
static u8 padding[128] = { 0x80, }; static u8 padding[128] = { 0x80, };
__be64 *dst = (__be64 *)hash; __be64 *dst = (__be64 *)hash;
__be32 bits[4]; __be32 bits[4];
@ -240,7 +234,7 @@ sha512_final(struct shash_desc *desc, u8 *hash)
dst[i] = cpu_to_be64(sctx->state[i]); dst[i] = cpu_to_be64(sctx->state[i]);
/* Zeroize sensitive information. */ /* Zeroize sensitive information. */
memset(sctx, 0, sizeof(struct sha512_ctx)); memset(sctx, 0, sizeof(struct sha512_state));
return 0; return 0;
} }
@ -262,7 +256,7 @@ static struct shash_alg sha512 = {
.init = sha512_init, .init = sha512_init,
.update = sha512_update, .update = sha512_update,
.final = sha512_final, .final = sha512_final,
.descsize = sizeof(struct sha512_ctx), .descsize = sizeof(struct sha512_state),
.base = { .base = {
.cra_name = "sha512", .cra_name = "sha512",
.cra_flags = CRYPTO_ALG_TYPE_SHASH, .cra_flags = CRYPTO_ALG_TYPE_SHASH,
@ -276,7 +270,7 @@ static struct shash_alg sha384 = {
.init = sha384_init, .init = sha384_init,
.update = sha512_update, .update = sha512_update,
.final = sha384_final, .final = sha384_final,
.descsize = sizeof(struct sha512_ctx), .descsize = sizeof(struct sha512_state),
.base = { .base = {
.cra_name = "sha384", .cra_name = "sha384",
.cra_flags = CRYPTO_ALG_TYPE_SHASH, .cra_flags = CRYPTO_ALG_TYPE_SHASH,

View file

@ -76,4 +76,10 @@ struct sha256_state {
u8 buf[SHA256_BLOCK_SIZE]; u8 buf[SHA256_BLOCK_SIZE];
}; };
struct sha512_state {
u64 state[8];
u32 count[4];
u8 buf[128];
};
#endif #endif