summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-18 12:20:10 +0100
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-18 13:08:08 +0100
commit61848f89db3c42d6cc67c8498c7e6aabb6202a9b (patch)
treeaaec25c76a32b383e2f6cb8a1505eb55fe1b243a /src/lib
parent645cf66af11ac36b81648f2e1eb3b1f5aeb7b544 (diff)
downloadouroboros-61848f89db3c42d6cc67c8498c7e6aabb6202a9b.tar.gz
ouroboros-61848f89db3c42d6cc67c8498c7e6aabb6202a9b.zip
lib: Fix bug in sha3
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/sha3.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/sha3.c b/src/lib/sha3.c
index b2f9de57..212f645a 100644
--- a/src/lib/sha3.c
+++ b/src/lib/sha3.c
@@ -47,7 +47,8 @@
#include "sha3.h"
-#define IS_ALIGNED_64(p) (0 == (7 & ((const char*) (p) - (const char*) 0)))
+#define IS_ALIGNED_64(p) (0 == (7 & ((const uint8_t *) (p) \
+ - (const uint8_t *) 0)))
#define I64(x) x##LL
#define ROTL64(qword, n) ((qword) << (n) ^ ((qword) >> (64 - (n))))
@@ -307,8 +308,9 @@ void rhash_sha3_final(struct sha3_ctx * ctx,
uint8_t * res)
{
size_t digest_length = 100 - ctx->block_size / 2;
- const size_t block_size = ctx->block_size;
- unsigned int i = 0;
+ size_t digest_words = digest_length / sizeof(uint64_t);
+ const size_t block_size = ctx->block_size;
+ size_t i = 0;
if (!(ctx->rest & SHA3_FINALIZED)) {
/* clear the rest of the data queue */
@@ -325,7 +327,7 @@ void rhash_sha3_final(struct sha3_ctx * ctx,
assert(block_size > digest_length);
if (res != NULL) {
- for (i = 0; i < digest_length; i++)
+ for (i = 0; i < digest_words; i++)
ctx->hash[i] = htole64(ctx->hash[i]);
memcpy(res, ctx->hash, digest_length);