SHA512/SHA384 are using the SHA256 update and differs in the transform function.
This adds a pointer to transform function into a SHA context.
ctx->nblocks_high = 0;
ctx->count = 0;
ctx->blocksize = 64;
+ ctx->transform = sha256_transform;
}
void
ctx->nblocks_high = 0;
ctx->count = 0;
ctx->blocksize = 64;
+ ctx->transform = sha256_transform;
}
/* (4.2) same as SHA-1's F1. */
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++;
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;
#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 */
u32 nblocks_high;
int count;
u32 blocksize;
+ sha_transform_fn *transform;
} sha256_context;
typedef sha256_context sha224_context;
return sha256_final(ctx);
}
+static unsigned int sha256_transform(void *ctx, const unsigned char *data, size_t nblks);
+
/**
* HMAC-SHA256, HMAC-SHA224
*/
ctx->bctx.nblocks_high = 0;
ctx->bctx.count = 0;
ctx->bctx.blocksize = 128;
+ ctx->bctx.transform = sha512_transform;
}
void
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)