Merge pull request #337 from libtom/fix/prng_pthread
prevent undefined behavior with LTC_PTHREAD (cherry picked from commit 45db2a9d9a8fca00948edb285e06dfb2ea5a4828)
This commit is contained in:
parent
dd868600b3
commit
f4d2b37cf4
@ -549,6 +549,7 @@
|
||||
#define LTC_MUTEX_INIT(x) LTC_ARGCHK(pthread_mutex_init(x, NULL) == 0);
|
||||
#define LTC_MUTEX_LOCK(x) LTC_ARGCHK(pthread_mutex_lock(x) == 0);
|
||||
#define LTC_MUTEX_UNLOCK(x) LTC_ARGCHK(pthread_mutex_unlock(x) == 0);
|
||||
#define LTC_MUTEX_DESTROY(x) LTC_ARGCHK(pthread_mutex_destroy(x) == 0);
|
||||
|
||||
#else
|
||||
|
||||
@ -559,6 +560,7 @@
|
||||
#define LTC_MUTEX_INIT(x)
|
||||
#define LTC_MUTEX_LOCK(x)
|
||||
#define LTC_MUTEX_UNLOCK(x)
|
||||
#define LTC_MUTEX_DESTROY(x)
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -139,6 +139,7 @@ int chacha20_prng_done(prng_state *prng)
|
||||
prng->ready = 0;
|
||||
err = chacha_done(&prng->chacha.s);
|
||||
LTC_MUTEX_UNLOCK(&prng->lock);
|
||||
LTC_MUTEX_DESTROY(&prng->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -318,6 +318,7 @@ LBL_UNLOCK:
|
||||
zeromem(tmp, sizeof(tmp));
|
||||
#endif
|
||||
LTC_MUTEX_UNLOCK(&prng->lock);
|
||||
LTC_MUTEX_DESTROY(&prng->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -142,6 +142,7 @@ int rc4_done(prng_state *prng)
|
||||
prng->ready = 0;
|
||||
err = rc4_stream_done(&prng->rc4.s);
|
||||
LTC_MUTEX_UNLOCK(&prng->lock);
|
||||
LTC_MUTEX_DESTROY(&prng->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -141,6 +141,7 @@ int sober128_done(prng_state *prng)
|
||||
prng->ready = 0;
|
||||
err = sober128_stream_done(&prng->sober128.s);
|
||||
LTC_MUTEX_UNLOCK(&prng->lock);
|
||||
LTC_MUTEX_DESTROY(&prng->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -262,6 +262,7 @@ int yarrow_done(prng_state *prng)
|
||||
err = ctr_done(&prng->yarrow.ctr);
|
||||
|
||||
LTC_MUTEX_UNLOCK(&prng->lock);
|
||||
LTC_MUTEX_DESTROY(&prng->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user