some system-specific adjustments for RNG routines

move some system-specific seed-related stuff from hacklib.c to
a system-specific source file and #define SYS_RANDOM_SEED to
utilize it during build.

Windows changes for random seed generation using
crypto next gen (CNG) api routines.

Corresponding vms changes due to disentangling of VMS and
unix when the unix seed bits got moved (untested).
This commit is contained in:
nhmall
2019-01-13 20:54:11 -05:00
committed by Patric Mueller
parent f9433b2a87
commit 6c114640f5
11 changed files with 161 additions and 58 deletions

View File

@@ -765,4 +765,31 @@ error:
}
#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*/