mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-02-02 14:20:01 +00:00
SHA512: Fixing bug in SHA512 & SHA384
SHA512/SHA384 are using the SHA256 update and differs in the transform function. This adds a pointer to transform function into a SHA context.
This commit is contained in:
parent
5a12cc27f7
commit
d16b33f556
@ -33,6 +33,7 @@ sha256_init(sha256_context *ctx)
|
||||
ctx->nblocks_high = 0;
|
||||
ctx->count = 0;
|
||||
ctx->blocksize = 64;
|
||||
ctx->transform = sha256_transform;
|
||||
}
|
||||
|
||||
void
|
||||
@ -51,6 +52,7 @@ sha224_init(sha224_context *ctx)
|
||||
ctx->nblocks_high = 0;
|
||||
ctx->count = 0;
|
||||
ctx->blocksize = 64;
|
||||
ctx->transform = sha256_transform;
|
||||
}
|
||||
|
||||
/* (4.2) same as SHA-1's F1. */
|
||||
@ -244,7 +246,7 @@ sha256_update(sha256_context *ctx, const byte *in_buf, size_t in_len)
|
||||
|
||||
if (ctx->count == blocksize) /* Flush the buffer. */
|
||||
{
|
||||
sha256_transform(ctx, ctx->buf, 1);
|
||||
ctx->transform(ctx, ctx->buf, 1);
|
||||
ctx->count = 0;
|
||||
if (!++ctx->nblocks)
|
||||
ctx->nblocks_high++;
|
||||
@ -264,7 +266,7 @@ sha256_update(sha256_context *ctx, const byte *in_buf, size_t in_len)
|
||||
if (in_len >= blocksize)
|
||||
{
|
||||
inblocks = in_len / blocksize;
|
||||
sha256_transform(ctx, in_buf, inblocks);
|
||||
ctx->transform(ctx, in_buf, inblocks);
|
||||
ctx->count = 0;
|
||||
ctx->nblocks_high += (ctx->nblocks + inblocks < inblocks);
|
||||
ctx->nblocks += inblocks;
|
||||
|
@ -22,6 +22,8 @@
|
||||
#define SHA256_HEX_SIZE 65
|
||||
#define SHA256_BLOCK_SIZE 64
|
||||
|
||||
typedef unsigned int sha_transform_fn (void *c, const unsigned char *blks, size_t nblks);
|
||||
|
||||
typedef struct {
|
||||
u32 h0,h1,h2,h3,h4,h5,h6,h7;
|
||||
byte buf[128]; /* 128 is for SHA384 and SHA512 support, otherwise for SHA224 and SHA256 is 64 enough */
|
||||
@ -29,6 +31,7 @@ typedef struct {
|
||||
u32 nblocks_high;
|
||||
int count;
|
||||
u32 blocksize;
|
||||
sha_transform_fn *transform;
|
||||
} sha256_context;
|
||||
typedef sha256_context sha224_context;
|
||||
|
||||
@ -47,6 +50,8 @@ byte* sha224_final(sha224_context *ctx)
|
||||
return sha256_final(ctx);
|
||||
}
|
||||
|
||||
static unsigned int sha256_transform(void *ctx, const unsigned char *data, size_t nblks);
|
||||
|
||||
/**
|
||||
* HMAC-SHA256, HMAC-SHA224
|
||||
*/
|
||||
|
@ -39,6 +39,7 @@ sha512_init(sha512_context *ctx)
|
||||
ctx->bctx.nblocks_high = 0;
|
||||
ctx->bctx.count = 0;
|
||||
ctx->bctx.blocksize = 128;
|
||||
ctx->bctx.transform = sha512_transform;
|
||||
}
|
||||
|
||||
void
|
||||
@ -59,6 +60,7 @@ sha384_init(sha384_context *ctx)
|
||||
ctx->bctx.nblocks_high = 0;
|
||||
ctx->bctx.count = 0;
|
||||
ctx->bctx.blocksize = 128;
|
||||
ctx->bctx.transform = sha512_transform;
|
||||
}
|
||||
|
||||
void sha512_update(sha512_context *ctx, const byte *in_buf, size_t in_len)
|
||||
|
Loading…
x
Reference in New Issue
Block a user