summaryrefslogtreecommitdiff
path: root/lib/crypto
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-12-02 01:08:19 -0800
committerOri Bernstein <ori@eigenstate.org>2016-12-02 01:08:19 -0800
commit97602e57fcd2bba52c50454f15cf07a97adf7342 (patch)
treed1f47ad490291d889989cdd5f684a035d588a615 /lib/crypto
parent9f26b5a77063d222e3c62cfdcc77f221991b5c4a (diff)
downloadmc-97602e57fcd2bba52c50454f15cf07a97adf7342.tar.gz
Add mutexes.
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/rand.myr4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/crypto/rand.myr b/lib/crypto/rand.myr
index 34e8ec9..6ce596b 100644
--- a/lib/crypto/rand.myr
+++ b/lib/crypto/rand.myr
@@ -1,4 +1,5 @@
use std
+use thread
use "entropy"
use "sha256"
@@ -20,6 +21,7 @@ var rem : std.size /* size remaining in buffer */
var cnt : std.size /* count we've read since last stirring of entropy */
var ctx : chacha20ctx /* the generator */
var pid : std.pid /* for rekeying on fork and exec */
+var mtx : thread.mutex /* there can be only one */
generic rand = {lo, hi
var span, lim, val, max
@@ -49,6 +51,7 @@ generic randnum = {
const randbytes = {dst
var n, off, rdlen
+ thread.mtxlock(&mtx)
/* costly? */
if pid != std.getpid()
stir()
@@ -70,6 +73,7 @@ const randbytes = {dst
rekey([][:])
;;
;;
+ thread.mtxunlock(&mtx)
}
const stir = {