#ifdef USE_ISAAC64
E void FDECL(init_isaac64, (unsigned long));
+E long NDECL(nhrand);
#endif
E int FDECL(rn2, (int));
E int FDECL(rnl, (int));
#define INTEGER_H
#if defined(__STDC__) && __STDC_VERSION__ >= 199101L
-
/* The compiler claims to conform to C99. Use stdint.h */
#include <stdint.h>
-typedef uint8_t uint8;
-typedef int16_t int16;
-typedef uint16_t uint16;
-typedef int32_t int32;
-typedef uint32_t uint32;
-
-#else /* !C99 */
+#define SKIP_STDINT_WORKAROUND
+#else
+# if defined(HAS_STDINT_H)
+/* Some compilers have stdint.h but don't conform to all of C99. */
+#include <stdint.h>
+#define SKIP_STDINT_WORKAROUND
+# endif
+#endif
-/* Provide uint8, int16, uint16, int32 and uint32 */
-typedef unsigned char uint8;
-typedef short int16;
-typedef unsigned short uint16;
+#ifndef SKIP_STDINT_WORKAROUND /* !C99 */
+typedef unsigned char uint8_t;
+typedef short int16_t;
+typedef unsigned short uint16_t;
#if defined(__WATCOMC__) && !defined(__386__)
/* Open Watcom providing a 16 bit build for MS-DOS or OS/2 */
/* int is 16 bits; use long for 32 bits */
-typedef long int32;
-typedef unsigned long uint32;
+typedef long int32_t;
+typedef unsigned long uint32_t;
#else
/* Otherwise, assume either a 32- or 64-bit compiler */
/* long may be 64 bits; use int for 32 bits */
-typedef int int32;
-typedef unsigned int uint32;
+typedef int int32_t;
+typedef unsigned int uint32_t;
#endif
-typedef unsigned long uint32_t;
+typedef long long int64_t;
typedef unsigned long long uint64_t;
#endif /* !C99 */
+/* Provide uint8, int16, uint16, int32, uint32, int64 and uint64 */
+typedef uint8_t uint8;
+typedef int16_t int16;
+typedef uint16_t uint16;
+typedef int32_t int32;
+typedef uint32_t uint32;
+typedef int64_t int64;
+typedef uint64_t uint64;
+
#endif /* INTEGER_H */
/* #define SHELL */ /* nt use of pcsys routines caused a hang */
-#define RANDOM /* have Berkeley random(3) */
+/* #define RANDOM */ /* have Berkeley random(3) */
+#define USE_ISAAC64
+
#define TEXTCOLOR /* Color text */
#define EXEPATH /* Allow .exe location to be used as HACKDIR */
game */
#define SYSCF /* Use a global configuration */
-#define SYSCF_FILE "sysconf" /* Use a file to hold the SYSCF configuration \
- */
+#define SYSCF_FILE "sysconf" /* Use a file to hold the SYSCF configuration */
#define DUMPLOG /* Enable dumplog files */
/*#define DUMPLOG_FILE "nethack-%n-%d.log"*/
#define USER_SOUNDS
/*#define CHANGE_COLOR*/ /* allow palette changes */
-#define SELECTSAVED /* Provide menu of saved games to choose from at start \
- */
+#define SELECTSAVED /* Provide menu of saved games to choose from at start */
+#define SYS_RANDOM_SEED /* Use random seed derived from CNG */
/*
* -----------------------------------------------------------------
* The remaining code shouldn't need modification.
/* suppress a warning in cppregex.cpp */
#pragma warning(disable : 4101) /* unreferenced local variable */
#endif
+#define HAS_STDINT_H /* force include of stdint.h in integer.h */
#endif /* _MSC_VER */
/* The following is needed for prototypes of certain functions */
# define DEV_RANDOM "/dev/random"
# endif
#endif
+#define SYS_RANDOM_SEED
#endif /* UNIXCONF_H */
#endif /* UNIX */
#else
#define Rand() rand()
#endif
+#define SYS_RANDOM_SEED
#ifndef __GNUC__
#ifndef bcopy
boolean fuzzymatch (const char *, const char *,
const char *, boolean)
void setrandom (void)
+ void init_random (void)
+ void reseed_random (void)
time_t getnow (void)
int getyear (void)
char * yymmdd (time_t)
#endif
STATIC_DCL struct tm *NDECL(getlt);
+#ifdef SYS_RANDOM_SEED
+extern unsigned long NDECL(sys_random_seed);
+#endif
+
/* Returns a number suitable as seed for the random number generator. */
static unsigned long
get_random_seed()
{
unsigned long seed = 0;
-#ifdef DEV_RANDOM
- FILE *fptr = NULL;
-
- fptr = fopen(DEV_RANDOM, "r");
- if (fptr) {
- fread(&seed, sizeof(long), 1, fptr);
- }
- fclose(fptr);
+#ifdef SYS_RANDOM_SEED
+ /* Platform-specific seed if one is provided */
+ seed = sys_random_seed();
#else
seed = (unsigned long) getnow(); /* time((TIME_type) 0) */
-
-# if defined(UNIX) || defined(VMS)
- {
- unsigned long pid = (unsigned long) getpid();
-
- /* Quick dirty band-aid to prevent PRNG prediction */
- if (pid) {
- if (!(pid & 3L))
- pid -= 1L;
- seed *= pid;
- }
- }
-# endif
#endif
return seed;
}
{
/* only reseed if we are certain that the seed generation is unguessable
* by the players. */
-#ifdef DEV_RANDOM
+#if defined(SYS_RANDOM_SEED)
init_random();
#endif
}
{
return (isaac64_next_uint64(&rng_state) % x);
}
+
#else
/* "Rand()"s definition is determined by [OS]conf.h */
#if defined(LINT) && defined(UNIX) /* rand() is long... */
}
#endif
+#ifdef SYS_RANDOM_SEED
+unsigned long
+sys_random_seed()
+{
+ unsigned long seed;
+ unsigned long pid = (unsigned long) getpid();
+#ifdef DEV_RANDOM
+ FILE *fptr = NULL;
+
+ fptr = fopen(DEV_RANDOM, "r");
+ if (fptr) {
+ fread(&seed, sizeof(long), 1, fptr);
+ }
+ fclose(fptr);
+#else
+ seed = (unsigned long) getnow(); /* time((TIME_type) 0) */
+ /* Quick dirty band-aid to prevent PRNG prediction */
+ if (pid) {
+ if (!(pid & 3L))
+ pid -= 1L;
+ seed *= pid;
+ }
+#endif
+ return seed;
+}
+#endif /* SYS_RANDOM_SEED */
+
/*unixmain.c*/
You("are in non-scoring explore/discovery mode.");
}
+#ifdef SYS_RANDOM_SEED
+unsigned long
+sys_random_seed()
+{
+ unsigned long seed;
+ unsigned long pid = (unsigned long) getpid();
+
+ seed = (unsigned long) getnow(); /* time((TIME_type) 0) */
+ /* Quick dirty band-aid to prevent PRNG prediction */
+ if (pid) {
+ if (!(pid & 3L))
+ pid -= 1L;
+ seed *= pid;
+ }
+ return seed;
+}
+#endif
+
/*vmsmain.c*/
# PDCurses header (.h) files and PDCURSES_C to the location
# of your PDCurses C files.
#
-#ADD_CURSES=Y
-#PDCURSES_TOP=..\..\pdcurses
+ADD_CURSES=Y
+PDCURSES_TOP=..\..\pdcurses
#
#==============================================================================
# This marks the end of the BUILD DECISIONS section.
# (see pcconf.h). Set to nothing if not used.
#
-RANDOM = $(OBJ)\random.o
+RANDOM = $(OBJ)\isaac64.o
+#RANDOM = $(OBJ)\random.o
#RANDOM =
-
+BCRYPT=
+! IF ("$(RANDOM)"=="$(OBJ)\isaac64.o")
+BCRYPT=bcrypt.lib
+! ENDIF
WINPFLAG= -DTILES -DMSWIN_GRAPHICS -DWIN32CON
# To store all the level files,
@if not exist $(GAMEDIR)\*.* mkdir $(GAMEDIR)
@echo Linking $(@:\=/)
$(link) $(lflagsBuild) $(conlflags) /STACK:2048 /PDB:$(GAMEDIR)\$(@B).PDB /MAP:$(O)$(@B).MAP \
- $(LIBS) $(PDCLIB) $(conlibs) -out:$@ @<<$(@B).lnk
+ $(LIBS) $(PDCLIB) $(conlibs) $(BCRYPT) -out:$@ @<<$(@B).lnk
$(GAMEOBJ)
$(TTYOBJ)
$(O)nttty.o
@if not exist $(GAMEDIR)\*.* mkdir $(GAMEDIR)
@echo Linking $(@:\=/)
$(link) $(lflagsBuild) $(guilflags) /STACK:2048 /PDB:$(GAMEDIR)\$(@B).PDB \
- /MAP:$(O)$(@B).MAP $(LIBS) $(PDCLIB) $(guilibs) $(COMCTRL) -out:$@ @<<$(@B).lnk
+ /MAP:$(O)$(@B).MAP $(LIBS) $(PDCLIB) $(guilibs) $(COMCTRL) $(BCRYPT) -out:$@ @<<$(@B).lnk
$(GAMEOBJ)
$(GUIOBJ)
$(O)tile.o
@$(CC) $(cflagsBuild) -Fo$@ ..\sys\atari\tos.c
$(O)pctty.o: ..\sys\share\pctty.c $(HACK_H)
@$(CC) $(cflagsBuild) -Fo$@ ..\sys\share\pctty.c
+$(O)isaac64.o: ..\src\isaac64.c $(HACK_H) $(INCL)\isaac64.h $(INCL)\integer.h
+ @$(CC) $(cflagsBuild) -Fo$@ ..\src\isaac64.c
$(O)random.o: ..\sys\share\random.c $(HACK_H)
@$(CC) $(cflagsBuild) -Fo$@ ..\sys\share\random.c
$(O)ioctl.o: ..\sys\share\ioctl.c $(HACK_H) $(INCL)\tcap.h
}
return;
}
+
+#ifdef SYS_RANDOM_SEED
+#ifndef STATUS_SUCCESS
+#define STATUS_SUCCESS 0
+#endif
+#ifndef STATUS_NOT_FOUND
+#define STATUS_NOT_FOUND 0xC0000225
+#endif
+#ifndef STATUS_UNSUCCESSFUL
+#define STATUS_UNSUCCESSFUL 0xC0000001
+#endif
+
+#include <bcrypt.h> /* Windows Crypto Next Gen (CNG) */
+
+unsigned long
+sys_random_seed(VOID_ARGS)
+{
+ unsigned long ourseed = 0UL;
+ BCRYPT_ALG_HANDLE hRa = (BCRYPT_ALG_HANDLE) 0;
+ NTSTATUS status = STATUS_UNSUCCESSFUL;
+ boolean Plan_B = TRUE;
+
+ status = BCryptOpenAlgorithmProvider(&hRa, BCRYPT_RNG_ALGORITHM,
+ (LPCWSTR) 0, 0);
+ if (hRa && status == STATUS_SUCCESS) {
+ status = BCryptGenRandom(hRa, (PUCHAR) &ourseed,
+ (ULONG) sizeof ourseed, 0);
+ if (status == STATUS_SUCCESS) {
+ BCryptCloseAlgorithmProvider(hRa,0);
+ Plan_B = FALSE;
+ }
+ }
+
+ if (Plan_B) {
+ time_t datetime = 0;
+ const char *emsg;
+
+ if (status == STATUS_NOT_FOUND)
+ emsg = "BCRYPT_RNG_ALGORITHM not avail, falling back";
+ else
+ emsg = "Other failure than algorithm not avail";
+ paniclog("sys_random_seed", emsg); /* leaves clue, doesn't exit */
+ (void) time(&datetime);
+ ourseed = (unsigned long) datetime;
+ }
+ return ourseed;
+}
+#endif /* SYS_RANDOM_SEED */
+
#endif /* WIN32 */
/*winnt.c*/