summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-18 12:10:05 +0000
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-18 12:10:05 +0000
commitee47a0c6478ab4e6478ad3b7fe5a35eb5775decb (patch)
tree7bcc999a668eed4247e9e9d203b84aec5338a15b /src
parent787fb78ff2fc54c36b37ecdf9b9c094800b9ef4c (diff)
parent61848f89db3c42d6cc67c8498c7e6aabb6202a9b (diff)
downloadouroboros-ee47a0c6478ab4e6478ad3b7fe5a35eb5775decb.tar.gz
ouroboros-ee47a0c6478ab4e6478ad3b7fe5a35eb5775decb.zip
Merged in dstaesse/ouroboros/be-sha3 (pull request #380)
lib: Fix bug in sha3
Diffstat (limited to 'src')
-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);