win32 port: fix LWIP_RAND() being called without sys_init()

This can happen in tests...
This commit is contained in:
Simon Goldschmidt 2020-02-17 21:28:04 +01:00
parent 04cf6bbe66
commit 9b5a6fe1dc

View File

@ -78,17 +78,6 @@ static DWORD netconn_sem_tls_index;
static HCRYPTPROV hcrypt;
unsigned int
lwip_port_rand(void)
{
u32_t ret;
if (CryptGenRandom(hcrypt, sizeof(ret), (BYTE*)&ret)) {
return ret;
}
LWIP_ASSERT("CryptGenRandom failed", 0);
return 0;
}
static void
sys_win_rand_init(void)
{
@ -105,6 +94,22 @@ sys_win_rand_init(void)
}
}
unsigned int
lwip_port_rand(void)
{
u32_t ret;
if (CryptGenRandom(hcrypt, sizeof(ret), (BYTE*)&ret)) {
return ret;
}
// maybe CryptAcquireContext has not been called...
sys_win_rand_init();
if (CryptGenRandom(hcrypt, sizeof(ret), (BYTE*)&ret)) {
return ret;
}
LWIP_ASSERT("CryptGenRandom failed", 0);
return 0;
}
static void
sys_init_timing(void)
{