diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-02-11 09:40:46 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-02-11 09:40:46 +0100 |
commit | 443d2a176017cba5ec3c38f0e0ebc8d0aa458c74 (patch) | |
tree | 99ec5a0651dd2014a90b1cb30202bf36592e46f1 | |
parent | add thread support (diff) | |
download | sha3sum-443d2a176017cba5ec3c38f0e0ebc8d0aa458c74.tar.gz sha3sum-443d2a176017cba5ec3c38f0e0ebc8d0aa458c74.tar.bz2 sha3sum-443d2a176017cba5ec3c38f0e0ebc8d0aa458c74.tar.xz |
c version: make with WITH_WIPE=yes to wipe the state and message buffer before freeing
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | c/sha3.c | 43 |
2 files changed, 48 insertions, 1 deletions
@@ -20,12 +20,16 @@ JAVADIRS=-s "java" -d "bin/java" -cp "java" JAVAFLAGS=-Xlint $(JAVA_OPTIMISE) JAVA_FLAGS=$(JAVADIRS) $(JAVAFLAGS) +WITH_WIPE=yes CFLAGS=-W{all,extra} -pedantic $(C_OPTIMISE) -fPIC ifeq ($(WITH_C99),yes) CFLAGS+=-std=c99 -DWITH_C99 endif ifeq ($(WITH_THREADLOCAL),yes) - CFLAGS+=-DWITH_THREADLOCAL + CFLAGS+=-DWITH_THREADLOCAL -DWITH_WIPE +endif +ifeq ($(WITH_WIPE),yes) + CFLAGS+=-DWITH_WIPE endif SOFLAGS=-W{all,extra} -pedantic $(C_OPTIMISE) -shared CPPFLAGS= @@ -552,13 +552,24 @@ extern void sha3_initialise(long bitrate, long capacity, long output) */ extern void sha3_dispose() { + #ifdef WITH_WIPE + long i; + #endif if (S != null) { + #ifdef WITH_WIPE + for (i = 0; i < 25; i++) + *(S + i) = 0; + #endif free(S); S = null; } if (M != null) { + #ifdef WITH_WIPE + for (i = 0; i < mlen; i++) + *(M + i) = 0; + #endif free(M); M = null; } @@ -580,7 +591,17 @@ extern void sha3_update(byte* restrict msg, long msglen) long nnn; if (mptr + msglen > mlen) + #ifdef WITH_WIPE M = (byte*)realloc(M, mlen = (mlen + msglen) << 1); + #else + { + long mlen_ = mlen; + char* M_ = (byte*)malloc(mlen = (mlen + msglen) << 1); + sha3_arraycopy(M, 0, M_, 0, mlen_); + free(M); + M = M_; + } + #endif sha3_arraycopy(msg, 0, M, mptr, msglen); len = mptr += msglen; len -= len % ((r * b) >> 3); @@ -620,6 +641,10 @@ extern void sha3_update(byte* restrict msg, long msglen) len -= rr; } + #ifdef WITH_WIPE + for (i = 0; i < nnn; i++) + *(_msg + i) = 0; + #endif free(_msg); } @@ -648,10 +673,24 @@ extern byte* sha3_digest(byte* restrict msg, long msglen, boolean withReturn) else { if (mptr + msglen > mlen) + #ifdef WITH_WIPE M = (byte*)realloc(M, mlen += msglen); + #else + { + long mlen_ = mlen; + char* M_ = (byte*)malloc(mlen += msglen); + sha3_arraycopy(M, 0, M_, 0, mlen_); + free(M); + M = M_; + } + #endif sha3_arraycopy(msg, 0, M, mptr, msglen); message = sha3_pad10star1(M, mptr + msglen, r, &len); } + #ifdef WITH_WIPE + for (i = 0; i < mlen; i++) + *(M + i) = 0; + #endif free(M); M = null; rc = (byte*)malloc(((n + 7) >> 3) * sizeof(byte)); @@ -688,6 +727,10 @@ extern byte* sha3_digest(byte* restrict msg, long msglen, boolean withReturn) len -= rr; } + #ifdef WITH_WIPE + for (i = 0; i < nnn; i++) + *(_msg + i) = 0; + #endif free(_msg); /* Squeezing phase */ |