MCPcopy Create free account
hub / github.com/NetHack/NetHack / sys_random_seed

Function sys_random_seed

sys/windows/windsys.c:747–780  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

745#endif
746
747unsigned long
748sys_random_seed(void)
749{
750 unsigned long ourseed = 0UL;
751 BCRYPT_ALG_HANDLE hRa = (BCRYPT_ALG_HANDLE) 0;
752 NTSTATUS status = STATUS_UNSUCCESSFUL;
753 boolean Plan_B = TRUE;
754
755 status = BCryptOpenAlgorithmProvider(&hRa, BCRYPT_RNG_ALGORITHM,
756 (LPCWSTR) 0, 0);
757 if (hRa && status == (NTSTATUS) STATUS_SUCCESS) {
758 status = BCryptGenRandom(hRa, (PUCHAR) &ourseed,
759 (ULONG) sizeof ourseed, 0);
760 if (status == (NTSTATUS) STATUS_SUCCESS) {
761 BCryptCloseAlgorithmProvider(hRa,0);
762 has_strong_rngseed = TRUE;
763 Plan_B = FALSE;
764 }
765 }
766
767 if (Plan_B) {
768 time_t datetime = 0;
769 const char *emsg;
770
771 if (status == (NTSTATUS) STATUS_NOT_FOUND)
772 emsg = "BCRYPT_RNG_ALGORITHM not avail, falling back";
773 else
774 emsg = "Other failure than algorithm not avail";
775 paniclog("sys_random_seed", emsg); /* leaves clue, doesn't exit */
776 (void) time(&datetime);
777 ourseed = (unsigned long) datetime;
778 }
779 return ourseed;
780}
781
782/* nt_assert_failed is called when an nhassert's condition is false */
783void

Callers

nothing calls this directly

Calls 2

paniclogFunction · 0.85
timeFunction · 0.85

Tested by

no test coverage detected