aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/keccak.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/keccak.c')
-rw-r--r--src/crypto/keccak.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/crypto/keccak.c b/src/crypto/keccak.c
index fc6d487c2..de8e2a5b3 100644
--- a/src/crypto/keccak.c
+++ b/src/crypto/keccak.c
@@ -4,9 +4,20 @@
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include "hash-ops.h"
#include "keccak.h"
+static void local_abort(const char *msg)
+{
+ fprintf(stderr, "%s\n", msg);
+#ifdef NDEBUG
+ _exit(1);
+#else
+ abort();
+#endif
+}
+
const uint64_t keccakf_rndc[24] =
{
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
@@ -81,10 +92,10 @@ void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
uint8_t temp[144];
size_t i, rsiz, rsizw;
- if (mdlen <= 0 || mdlen > 200 || sizeof(st) != 200)
+ static_assert(HASH_DATA_AREA <= sizeof(temp), "Bad keccak preconditions");
+ if (mdlen <= 0 || (mdlen > 100 && sizeof(st) != (size_t)mdlen))
{
- fprintf(stderr, "Bad keccak use");
- abort();
+ local_abort("Bad keccak use");
}
rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen;
@@ -99,10 +110,9 @@ void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
}
// last block and padding
- if (inlen >= sizeof(temp) || inlen > rsiz || rsiz - inlen + inlen + 1 >= sizeof(temp) || rsiz == 0 || rsiz - 1 >= sizeof(temp) || rsizw * 8 > sizeof(temp))
+ if (inlen + 1 >= sizeof(temp) || inlen > rsiz || rsiz - inlen + inlen + 1 >= sizeof(temp) || rsiz == 0 || rsiz - 1 >= sizeof(temp) || rsizw * 8 > sizeof(temp))
{
- fprintf(stderr, "Bad keccak use");
- abort();
+ local_abort("Bad keccak use");
}
memcpy(temp, in, inlen);