aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-11-15 11:22:56 +0200
committerRiccardo Spagni <ric@spagni.net>2017-11-15 11:22:56 +0200
commit5c2dfe157b48a486eb2b92dcf8789b3b1eb20f60 (patch)
tree2a16fc9e5ee8fcdc8d78d56de747eacdc4ba7469 /src
parentMerge pull request #2634 (diff)
parentkaccak: remove unused return value (diff)
downloadmonero-5c2dfe157b48a486eb2b92dcf8789b3b1eb20f60.tar.xz
Merge pull request #2771
e3e838d0 kaccak: remove unused return value (moneromooo-monero) 4877aca2 keccak: some paranoid "can't happen" checks (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/crypto/keccak.c18
-rw-r--r--src/crypto/keccak.h2
2 files changed, 16 insertions, 4 deletions
diff --git a/src/crypto/keccak.c b/src/crypto/keccak.c
index 090d563a2..fc6d487c2 100644
--- a/src/crypto/keccak.c
+++ b/src/crypto/keccak.c
@@ -2,6 +2,8 @@
// 19-Nov-11 Markku-Juhani O. Saarinen <mjos@iki.fi>
// A baseline Keccak (3rd round) implementation.
+#include <stdio.h>
+#include <stdlib.h>
#include "hash-ops.h"
#include "keccak.h"
@@ -73,12 +75,18 @@ void keccakf(uint64_t st[25], int rounds)
// compute a keccak hash (md) of given byte length from "in"
typedef uint64_t state_t[25];
-int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
+void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
{
state_t st;
uint8_t temp[144];
size_t i, rsiz, rsizw;
+ if (mdlen <= 0 || mdlen > 200 || sizeof(st) != 200)
+ {
+ fprintf(stderr, "Bad keccak use");
+ abort();
+ }
+
rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen;
rsizw = rsiz / 8;
@@ -91,6 +99,12 @@ int 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))
+ {
+ fprintf(stderr, "Bad keccak use");
+ abort();
+ }
+
memcpy(temp, in, inlen);
temp[inlen++] = 1;
memset(temp + inlen, 0, rsiz - inlen);
@@ -102,8 +116,6 @@ int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
keccakf(st, KECCAK_ROUNDS);
memcpy(md, st, mdlen);
-
- return 0;
}
void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md)
diff --git a/src/crypto/keccak.h b/src/crypto/keccak.h
index fbd8e1904..fb9d8bd04 100644
--- a/src/crypto/keccak.h
+++ b/src/crypto/keccak.h
@@ -16,7 +16,7 @@
#endif
// compute a keccak hash (md) of given byte length from "in"
-int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen);
+void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen);
// update the state
void keccakf(uint64_t st[25], int norounds);