]> granicus.if.org Git - nethack/commitdiff
detect rng seed strength at runtime based on algorithm not compile time based on...
authornhmall <nhmall@nethack.org>
Fri, 18 Jan 2019 23:42:42 +0000 (18:42 -0500)
committerPatric Mueller <bhaak@gmx.net>
Mon, 28 Jan 2019 09:32:57 +0000 (10:32 +0100)
include/decl.h
src/decl.c
src/hacklib.c
sys/unix/unixmain.c
sys/winnt/winnt.c

index 66bfd74c18f14e60e0615863786134849ed66bec..eb3c904c490be4683ce3d024b2773b843392d655 100644 (file)
@@ -220,6 +220,7 @@ E NEARDATA boolean mrg_to_wielded;
 E NEARDATA boolean defer_see_monsters;
 
 E NEARDATA boolean in_steed_dismounting;
+E NEARDATA boolean has_strong_rngseed;
 
 E const int shield_static[];
 
index 3e9fb82cc23cb5f94f02a72d0f3c858e3837d49d..2849418e6ec99e028f7cffb7a92bb2d448c0827b 100644 (file)
@@ -120,6 +120,7 @@ NEARDATA boolean mrg_to_wielded = FALSE;
 /* weapon picked is merged with wielded one */
 
 NEARDATA boolean in_steed_dismounting = FALSE;
+NEARDATA boolean has_strong_rngseed = FALSE;
 
 NEARDATA coord bhitpos = DUMMY;
 NEARDATA coord doors[DOORMAX] = { DUMMY };
index 56e301ed20f10d1ee04bcff2b9bfc0309d7397f5..60f492b37a0e0a8fcb92669430dc6b9036b2bfb6 100644 (file)
@@ -899,8 +899,10 @@ init_random()
 void
 reseed_random()
 {
-    /* reseed */
-    init_random();
+   /* only reseed if we are certain that the seed generation is unguessable
+    * by the players. */
+    if (has_strong_rngseed)
+        init_random();
 }
 
 time_t
index 6b3cf5aeabe78f3cafa535ea9591ab85d7a0349d..0a1f469a7a46d4a042a7b4ded3f2af0c8df21d30 100644 (file)
@@ -776,6 +776,7 @@ sys_random_seed()
     fptr = fopen(DEV_RANDOM, "r");
     if (fptr) {
         fread(&seed, sizeof(long), 1, fptr);
+        has_strong_rngseed = TRUE;
     }
     fclose(fptr);
 #else
index 1a1fa710ebb93bb4686d5b498c3de74606f291f9..fc75071d84b35747c4662e494833f4622097bd2b 100644 (file)
@@ -708,6 +708,7 @@ sys_random_seed(VOID_ARGS)
                                  (ULONG) sizeof ourseed, 0);
         if (status == STATUS_SUCCESS) {
             BCryptCloseAlgorithmProvider(hRa,0);
+            has_strong_rngseed = TRUE;
             Plan_B = FALSE;
         }
     }