From 1a381cb7603f0ed3570facbad9fdf685d262a48c Mon Sep 17 00:00:00 2001 From: Tobias Junghans Date: Wed, 7 Nov 2018 12:48:29 +0100 Subject: [PATCH] common: d3des: use per-thread key register When encrypting/decrypting from different threads this can race due to the global key register. --- common/d3des.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/d3des.c b/common/d3des.c index db999a5..12ccf62 100644 --- a/common/d3des.c +++ b/common/d3des.c @@ -28,12 +28,20 @@ #include "d3des.h" +#if defined(__GNUC__) +#define TLS __thread +#elif defined(_MSC_VER) +#define TLS __declspec(thread) +#else +#define TLS +#endif + static void scrunch(unsigned char *, unsigned long *); static void unscrun(unsigned long *, unsigned char *); static void desfunc(unsigned long *, unsigned long *); static void cookey(unsigned long *); -static unsigned long KnL[32] = { 0L }; +static TLS unsigned long KnL[32] = { 0L }; /* static unsigned long KnR[32] = { 0L }; static unsigned long Kn3[32] = { 0L };