diff options
author | Niels Möller <nisse@lysator.liu.se> | 2019-12-25 16:30:50 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2019-12-25 16:30:50 +0100 |
commit | f77bd0a33c255b4fd6cac4f8be4d1cde8da0980b (patch) | |
tree | 55208e3fbd427fe1a517720bbf1cee5262c2caee | |
parent | d4c3e2ee91ddd992ae155b9375e6bc25e98b22f1 (diff) | |
download | nettle-f77bd0a33c255b4fd6cac4f8be4d1cde8da0980b.tar.gz |
Generalize _sha3_pad to take magic value as argument.
-rw-r--r-- | sha3-224.c | 2 | ||||
-rw-r--r-- | sha3-256.c | 2 | ||||
-rw-r--r-- | sha3-384.c | 2 | ||||
-rw-r--r-- | sha3-512.c | 2 | ||||
-rw-r--r-- | sha3-internal.h | 9 | ||||
-rw-r--r-- | sha3.c | 4 |
6 files changed, 14 insertions, 7 deletions
@@ -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); } diff --git a/sha3-internal.h b/sha3-internal.h index 172a9273..2a19b24f 100644 --- a/sha3-internal.h +++ b/sha3-internal.h @@ -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; |