aboutsummaryrefslogtreecommitdiffstats
path: root/java-c-jni/SHA3.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-08-21 19:11:27 +0200
committerMattias Andrée <maandree@operamail.com>2014-08-21 19:11:27 +0200
commitea3d1047b01a6c5f9a70f35db063e5001ed5c14b (patch)
tree02778802a7396527c20623d65cd8f083d4074003 /java-c-jni/SHA3.c
parentscrew that, I am not doing vala (diff)
downloadsha3sum-ea3d1047b01a6c5f9a70f35db063e5001ed5c14b.tar.gz
sha3sum-ea3d1047b01a6c5f9a70f35db063e5001ed5c14b.tar.bz2
sha3sum-ea3d1047b01a6c5f9a70f35db063e5001ed5c14b.tar.xz
fix error in partial bit support for c implementations
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--java-c-jni/SHA3.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/java-c-jni/SHA3.c b/java-c-jni/SHA3.c
index 1735099..9422b3c 100644
--- a/java-c-jni/SHA3.c
+++ b/java-c-jni/SHA3.c
@@ -645,21 +645,25 @@ byte* digest(byte* msg, long msglen, long bits, int* suffix, long suffix_len, bo
msglen += bits >> 3;
if ((bits &= 7))
- {
msg[msglen] &= (1 << bits) - 1;
+ if (suffix_len)
+ {
msg = (byte*)realloc(msg, msglen + ((suffix_len + bits + 7) >> 3));
+ if (!bits)
+ msg[msglen] = 0;
for (i = 0; i < suffix_len; i++)
{
- msg[msglen] |= suffix[i] << bits;
+ msg[msglen] |= suffix[i] << bits++;
if (bits == 8)
{
bits = 0;
msglen++;
+ msg[msglen] = 0;
}
}
- if (bits)
- msglen++;
}
+ if (bits)
+ msglen++;
if (mptr + msglen > mlen)
{