summaryrefslogtreecommitdiff
path: root/src/lib/sha3.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/sha3.c')
-rw-r--r--src/lib/sha3.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/sha3.c b/src/lib/sha3.c
index b2f9de57..750038f2 100644
--- a/src/lib/sha3.c
+++ b/src/lib/sha3.c
@@ -3,6 +3,9 @@
*
* SHA3 algorithm
*
+ * Dimitri Staessens <[email protected]>
+ * Sander Vrijders <[email protected]>
+ *
* This implementation is adapted and redistributed from the RHASH
* project
*
@@ -47,7 +50,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 +311,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 +330,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);