From 7510f5b16df9493e24f7ec8291c64e521811c53a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 11 Feb 2014 09:25:11 +0100 Subject: add thread support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- c/sha3.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'c/sha3.c') diff --git a/c/sha3.c b/c/sha3.c index 4346a9c..3b0c28e 100644 --- a/c/sha3.c +++ b/c/sha3.c @@ -25,6 +25,14 @@ #define static_inline inline #endif +#ifdef WITH_THREADLOCAL + #define threadlocal __thread + /* This is compiler dependent, if your compiler does + * not support this you need to define __thread yourself. */ +#else + #define threadlocal /* no threading support */ +#endif + #define null 0 #define true 1 #define false 0 @@ -55,74 +63,74 @@ static const llong RC[] = { /** * Keccak-f round temporary */ -static llong B[25]; +static threadlocal llong B[25]; /** * Keccak-f round temporary */ -static llong C[5]; +static threadlocal llong C[5]; /** * The bitrate */ -static long r = 0; +static threadlocal long r = 0; /** * The capacity */ -static long c = 0; +static threadlocal long c = 0; /** * The output size */ -static long n = 0; +static threadlocal long n = 0; /** * The state size */ -static long b = 0; +static threadlocal long b = 0; /** * The word size */ -static long w = 0; +static threadlocal long w = 0; /** * The word mask */ -static llong wmod = 0; +static threadlocal llong wmod = 0; /** * ℓ, the binary logarithm of the word size */ -static long l = 0; +static threadlocal long l = 0; /** * 12 + 2ℓ, the number of rounds */ -static long nr = 0; +static threadlocal long nr = 0; /** * The current state */ -static llong* S = null; +static threadlocal llong* S = null; /** * Left over water to fill the sponge with at next update */ -static byte* M = null; +static threadlocal byte* M = null; /** * Pointer for {@link #M} */ -static long mptr = 0; +static threadlocal long mptr = 0; /** * Size of {@link #M} */ -static long mlen = 0; +static threadlocal long mlen = 0; -- cgit v1.2.3-70-g09d2