| 745 | #endif |
| 746 | |
| 747 | unsigned long |
| 748 | sys_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 */ |
| 783 | void |