From: Rudolf Polzer Date: Tue, 25 Oct 2011 11:35:16 +0000 (+0200) Subject: turn some buffers into TLS X-Git-Tag: v0.5~20 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a0a5771a9d31aa0a0b4709014e3a6af226f915d8;p=xonotic%2Fd0_blind_id.git turn some buffers into TLS --- diff --git a/d0_bignum-gmp.c b/d0_bignum-gmp.c index d59f735..5353704 100644 --- a/d0_bignum-gmp.c +++ b/d0_bignum-gmp.c @@ -133,7 +133,7 @@ void d0_bignum_SHUTDOWN(void) D0_BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum) { - static unsigned char numbuf[65536]; // FIXME make threadsafe + static __thread unsigned char numbuf[65536]; size_t count = 0; numbuf[0] = mpz_sgn(bignum->z) & 3; if((numbuf[0] & 3) != 0) // nonzero @@ -148,7 +148,7 @@ D0_BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum) d0_bignum_t *d0_iobuf_read_bignum(d0_iobuf_t *buf, d0_bignum_t *bignum) { - static unsigned char numbuf[65536]; // FIXME make threadsafe + static __thread unsigned char numbuf[65536]; size_t count = sizeof(numbuf); if(!d0_iobuf_read_packet(buf, numbuf, &count)) return NULL; diff --git a/d0_bignum-openssl.c b/d0_bignum-openssl.c index 1d92c32..c5b2b65 100644 --- a/d0_bignum-openssl.c +++ b/d0_bignum-openssl.c @@ -79,7 +79,7 @@ void d0_bignum_SHUTDOWN(void) D0_BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum) { - static unsigned char numbuf[65536]; // FIXME make threadsafe + static __thread unsigned char numbuf[65536]; size_t count = 0; numbuf[0] = BN_is_zero(&bignum->z) ? 0 : BN_is_negative(&bignum->z) ? 3 : 1; if((numbuf[0] & 3) != 0) // nonzero @@ -94,7 +94,7 @@ D0_BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum) d0_bignum_t *d0_iobuf_read_bignum(d0_iobuf_t *buf, d0_bignum_t *bignum) { - static unsigned char numbuf[65536]; // FIXME make threadsafe + static __thread unsigned char numbuf[65536]; size_t count = sizeof(numbuf); if(!d0_iobuf_read_packet(buf, numbuf, &count)) return NULL; diff --git a/d0_bignum-tommath.c b/d0_bignum-tommath.c index b3230fd..b2a3913 100644 --- a/d0_bignum-tommath.c +++ b/d0_bignum-tommath.c @@ -123,7 +123,7 @@ void d0_bignum_SHUTDOWN(void) D0_BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum) { - static unsigned char numbuf[65536]; // FIXME make threadsafe + static __thread unsigned char numbuf[65536]; size_t count = 0; numbuf[0] = (mp_iszero(&bignum->z) ? 0 : (bignum->z.sign == MP_ZPOS) ? 1 : 3); if((numbuf[0] & 3) != 0) // nonzero @@ -138,7 +138,7 @@ D0_BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum) d0_bignum_t *d0_iobuf_read_bignum(d0_iobuf_t *buf, d0_bignum_t *bignum) { - static unsigned char numbuf[65536]; // FIXME make threadsafe + static __thread unsigned char numbuf[65536]; size_t count = sizeof(numbuf); if(!d0_iobuf_read_packet(buf, numbuf, &count)) return NULL; @@ -425,7 +425,7 @@ d0_bignum_t *d0_bignum_gcd(d0_bignum_t *r, d0_bignum_t *s, d0_bignum_t *t, const char *d0_bignum_tostring(const d0_bignum_t *x, unsigned int base) { - static char str[65536]; // FIXME make threadsafe + static __thread char str[65536]; mp_toradix_n((mp_int *) &x->z, str, base, sizeof(str)); return str; } diff --git a/d0_blind_id.c b/d0_blind_id.c index fd32cdb..1920cdc 100644 --- a/d0_blind_id.c +++ b/d0_blind_id.c @@ -317,7 +317,7 @@ D0_WARN_UNUSED_RESULT D0_BOOL d0_longhash_destructive(unsigned char *convbuf, si D0_WARN_UNUSED_RESULT D0_BOOL d0_longhash_bignum(const d0_bignum_t *in, unsigned char *outbuf, size_t outbuflen) { - unsigned char convbuf[1024]; + static __thread unsigned char convbuf[1024]; size_t sz; CHECK(d0_bignum_export_unsigned(in, convbuf, sizeof(convbuf)) >= 0); @@ -464,7 +464,7 @@ fail: D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_fingerprint64_public_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; - unsigned char convbuf[2048]; + static __thread unsigned char convbuf[2048]; d0_iobuf_t *conv = NULL; size_t sz, n; @@ -554,7 +554,7 @@ fail: D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_id_request(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; - unsigned char shabuf[2048]; + static __thread unsigned char shabuf[2048]; size_t sz; // temps: temp0 rsa_blind_signature_camouflage^challenge, temp1 (4^s)*rsa_blind_signature_camouflage^challenge @@ -743,7 +743,7 @@ D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_start(d0_ // 1. get random r, send HASH(4^r) { d0_iobuf_t *out = NULL; - unsigned char convbuf[1024]; + static __thread unsigned char convbuf[1024]; d0_iobuf_t *conv = NULL; size_t sz = 0; D0_BOOL failed = 0; @@ -816,7 +816,7 @@ D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_challenge { d0_iobuf_t *in = NULL; d0_iobuf_t *out = NULL; - unsigned char shabuf[2048]; + static __thread unsigned char shabuf[2048]; size_t sz; // temps: temp0 order, temp0 signature check @@ -961,7 +961,7 @@ D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_verify(d0 // (check using H(g^r) which we know) { d0_iobuf_t *in = NULL; - unsigned char convbuf[1024]; + static __thread unsigned char convbuf[1024]; d0_iobuf_t *conv = NULL; size_t sz; @@ -1028,7 +1028,7 @@ fail: D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_generate_missing_signature(d0_blind_id_t *ctx) { size_t sz; - unsigned char shabuf[2048]; + static __thread unsigned char shabuf[2048]; REPLACING(schnorr_H_g_to_s_signature); USING(schnorr_g_to_s); USING(rsa_d); USING(rsa_n); @@ -1054,7 +1054,7 @@ D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_sign_with_private_id_sign_internal(d0_ { d0_iobuf_t *out = NULL; unsigned char *convbuf = NULL; - unsigned char shabuf[2048]; + static __thread unsigned char shabuf[2048]; d0_iobuf_t *conv = NULL; size_t sz = 0; @@ -1128,7 +1128,7 @@ D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_sign_with_private_id_verify_internal(d d0_iobuf_t *in = NULL; d0_iobuf_t *conv = NULL; unsigned char *convbuf = NULL; - unsigned char shabuf[2048]; + static __thread unsigned char shabuf[2048]; size_t sz; if(is_first) @@ -1240,7 +1240,7 @@ D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_sign_with_private_id_verify_detached(d D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_fingerprint64_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; - unsigned char convbuf[1024]; + static __thread unsigned char convbuf[1024]; d0_iobuf_t *conv = NULL; size_t sz, n;