Package: maradns / 2.0.13-1.2

randprime_prng.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Author: Tobias Frost <tobi@frost.de>
Subject: If /dev/urandom is not there, use PRNG number
Forwarded: not-needed
Last-Update: 2015-10-03
--- a/deadwood-3.2.09/src/RandomPrime.c
+++ b/deadwood-3.2.09/src/RandomPrime.c
@@ -76,17 +76,34 @@
         int a = 0;
 
         rand = fopen("/dev/urandom","rb");
-        if(rand == 0) {
-                fatal("Could not open /dev/urandom");
-        }
+        if(rand == 0 ) {
+		char rndtab[256];
+	        uint32_t tmp;
+                initstate(time(NULL),rndtab,255);
+		candidate = random();
+		/* random only guaranteed to get value RAND_MAX, only guaranteed to be >32767,
+		 * so we combine several values and twist them a little.
+		   on Linux RAND_MAX is 2^30-1, so the MSB is always 0... so we work around only taking the lower bits*/
+		candidate ^= (random() << 16);
+		candidate ^= (random() && 0xFFFF);
 
-        for(a = 0; a < 4; a++) {
+		candidate ^= (random() << 16);
+		candidate ^= (random() && 0xFFFF);
+
+		candidate ^= (random() << 16);
+		candidate ^= (random() && 0xFFFF);
+
+		candidate ^= (random() << 16);
+		candidate ^= (random() && 0xFFFF);
+	} else {
+            for(a = 0; a < 4; a++) {
                 get = getc(rand);
                 candidate <<= 8;
                 candidate |= get;
-        }
+            }
 
         fclose(rand);
+	}
 
         candidate &= 0x3fffffff;
         candidate |= 0x40000001;