summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2019-12-25 16:30:50 +0100
committerNiels Möller <nisse@lysator.liu.se>2019-12-25 16:30:50 +0100
commitf77bd0a33c255b4fd6cac4f8be4d1cde8da0980b (patch)
tree55208e3fbd427fe1a517720bbf1cee5262c2caee
parentd4c3e2ee91ddd992ae155b9375e6bc25e98b22f1 (diff)
downloadnettle-f77bd0a33c255b4fd6cac4f8be4d1cde8da0980b.tar.gz
Generalize _sha3_pad to take magic value as argument.
-rw-r--r--sha3-224.c2
-rw-r--r--sha3-256.c2
-rw-r--r--sha3-384.c2
-rw-r--r--sha3-512.c2
-rw-r--r--sha3-internal.h9
-rw-r--r--sha3.c4
6 files changed, 14 insertions, 7 deletions
diff --git a/sha3-224.c b/sha3-224.c
index 853c9503..62ab7af0 100644
--- a/sha3-224.c
+++ b/sha3-224.c
@@ -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);
}
diff --git a/sha3-256.c b/sha3-256.c
index cf3e7b02..c5f133ee 100644
--- a/sha3-256.c
+++ b/sha3-256.c
@@ -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);
}
diff --git a/sha3-384.c b/sha3-384.c
index c0dec517..83fd1eb9 100644
--- a/sha3-384.c
+++ b/sha3-384.c
@@ -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);
}
diff --git a/sha3-512.c b/sha3-512.c
index b477ec1b..fd6a2e35 100644
--- a/sha3-512.c
+++ b/sha3-512.c
@@ -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
diff --git a/sha3.c b/sha3.c
index 4a083be2..43a911f9 100644
--- a/sha3.c
+++ b/sha3.c
@@ -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;