summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJ08nY2017-02-19 02:26:27 +0100
committerJ08nY2017-02-19 02:26:53 +0100
commitc1be6dbea0f6e2b8d9cb8c422bc2e1cfb41524da (patch)
treeb97c873a30eebaae611a60c018cd89062953d02e /src
parent697c966ce5cfaac8c5c81ffcd30b80f2b9c0c43e (diff)
downloadecgen-c1be6dbea0f6e2b8d9cb8c422bc2e1cfb41524da.tar.gz
ecgen-c1be6dbea0f6e2b8d9cb8c422bc2e1cfb41524da.tar.zst
ecgen-c1be6dbea0f6e2b8d9cb8c422bc2e1cfb41524da.zip
Always read a whole pari_ulong from dev/urandom
Diffstat (limited to 'src')
-rw-r--r--src/math/random.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/math/random.c b/src/math/random.c
index 94197fe..a1d88ab 100644
--- a/src/math/random.c
+++ b/src/math/random.c
@@ -11,7 +11,11 @@ bool random_init(void) {
// Try urandom first
FILE *rand = fopen("/dev/urandom", "rb");
if (rand) {
- fread(&seed, 1, sizeof(pari_ulong), rand);
+ size_t read = 0;
+ while (read < sizeof(pari_ulong)) {
+ read += fread(&seed + read, 1, sizeof(pari_ulong) - read, rand);
+ }
+
fclose(rand);
}
// Try worse methods later