Commit f77bd0a3 authored by Niels Möller's avatar Niels Möller

Generalize _sha3_pad to take magic value as argument.

parent d4c3e2ee
......@@ -63,7 +63,7 @@ sha3_224_digest(struct sha3_224_ctx *ctx,
size_t length,
uint8_t *digest)
{
_sha3_pad (&ctx->state, SHA3_224_BLOCK_SIZE, ctx->block, ctx->index);
_sha3_pad_hash (&ctx->state, SHA3_224_BLOCK_SIZE, ctx->block, ctx->index);
_nettle_write_le64 (length, digest, ctx->state.a);
sha3_224_init (ctx);
}
......@@ -63,7 +63,7 @@ sha3_256_digest(struct sha3_256_ctx *ctx,
size_t length,
uint8_t *digest)
{
_sha3_pad (&ctx->state, SHA3_256_BLOCK_SIZE, ctx->block, ctx->index);
_sha3_pad_hash (&ctx->state, SHA3_256_BLOCK_SIZE, ctx->block, ctx->index);
_nettle_write_le64 (length, digest, ctx->state.a);
sha3_256_init (ctx);
}
......@@ -63,7 +63,7 @@ sha3_384_digest(struct sha3_384_ctx *ctx,
size_t length,
uint8_t *digest)
{
_sha3_pad (&ctx->state, SHA3_384_BLOCK_SIZE, ctx->block, ctx->index);
_sha3_pad_hash (&ctx->state, SHA3_384_BLOCK_SIZE, ctx->block, ctx->index);
_nettle_write_le64 (length, digest, ctx->state.a);
sha3_384_init (ctx);
}
......@@ -63,7 +63,7 @@ sha3_512_digest(struct sha3_512_ctx *ctx,
size_t length,
uint8_t *digest)
{
_sha3_pad (&ctx->state, SHA3_512_BLOCK_SIZE, ctx->block, ctx->index);
_sha3_pad_hash (&ctx->state, SHA3_512_BLOCK_SIZE, ctx->block, ctx->index);
_nettle_write_le64 (length, digest, ctx->state.a);
sha3_512_init (ctx);
}
......@@ -39,14 +39,21 @@
#define _sha3_update _nettle_sha3_update
#define _sha3_pad _nettle_sha3_pad
#define SHA3_HASH_MAGIC 6
unsigned
_sha3_update (struct sha3_state *state,
unsigned block_size, uint8_t *block,
unsigned pos,
size_t length, const uint8_t *data);
void
_sha3_pad (struct sha3_state *state,
unsigned block_size, uint8_t *block, unsigned pos);
unsigned block_size, uint8_t *block, unsigned pos, uint8_t magic);
#define _sha3_pad_hash(state, block_size, block, pos) \
_sha3_pad (state, block_size, block, pos, SHA3_HASH_MAGIC)
#endif
......@@ -92,10 +92,10 @@ _sha3_update (struct sha3_state *state,
void
_sha3_pad (struct sha3_state *state,
unsigned block_size, uint8_t *block, unsigned pos)
unsigned block_size, uint8_t *block, unsigned pos, uint8_t magic)
{
assert (pos < block_size);
block[pos++] = 6;
block[pos++] = magic;
memset (block + pos, 0, block_size - pos);
block[block_size - 1] |= 0x80;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment