Switch from using os_random() to using os_get_random(...) in advertisement_state_machine_start(...) The intention is to facilitate the future removal of os_random(). os_random() uses a low quality PRNG which we should avoid using outright unless there is a compelling performance justification to do so. Signed-off-by: Nick Lowe <nick.lowe@xxxxxxxxxxxx> --- src/wps/wps_upnp_ssdp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wps/wps_upnp_ssdp.c b/src/wps/wps_upnp_ssdp.c index 968fc03..2b6da2b 100644 --- a/src/wps/wps_upnp_ssdp.c +++ b/src/wps/wps_upnp_ssdp.c @@ -354,7 +354,10 @@ int advertisement_state_machine_start(struct upnp_wps_device_sm *sm) /* (other fields not used here) */ /* First timeout should be random interval < 100 msec */ - next_timeout_msec = (100 * (os_random() & 0xFF)) >> 8; + if (os_get_random((u8 *) &next_timeout_msec, + sizeof(next_timeout_msec)) < 0) + return -1; + next_timeout_msec = (100 * (next_timeout_msec & 0xFF)) >> 8; return eloop_register_timeout(0, next_timeout_msec, advertisement_state_machine_handler, NULL, sm); @@ -475,7 +478,10 @@ static void msearchreply_state_machine_start(struct upnp_wps_device_sm *sm, a->state = 0; os_memcpy(&a->client, client, sizeof(*client)); /* Wait time depending on MX value */ - next_timeout_msec = (1000 * mx * (os_random() & 0xFF)) >> 8; + if (os_get_random((u8 *) &next_timeout_msec, + sizeof(next_timeout_msec)) < 0) + goto fail; + next_timeout_msec = (1000 * mx * (next_timeout_msec & 0xFF)) >> 8; next_timeout_sec = next_timeout_msec / 1000; next_timeout_msec = next_timeout_msec % 1000; if (eloop_register_timeout(next_timeout_sec, next_timeout_msec, -- 2.5.0
From c7b0be9c893827e9a0e4b842047effb8de02e85e Mon Sep 17 00:00:00 2001 From: Nick Lowe <nick.lowe@xxxxxxxxxxxx> Date: Tue, 9 Feb 2016 16:16:21 +0000 Subject: [PATCH 07/10] Switch from using os_random() to using os_get_random(...) in advertisement_state_machine_start(...) The intention is to facilitate the future removal of os_random(). os_random() uses a low quality PRNG which we should avoid using outright unless there is a compelling performance justification to do so. Signed-off-by: Nick Lowe <nick.lowe@xxxxxxxxxxxx> --- src/wps/wps_upnp_ssdp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wps/wps_upnp_ssdp.c b/src/wps/wps_upnp_ssdp.c index 968fc03..2b6da2b 100644 --- a/src/wps/wps_upnp_ssdp.c +++ b/src/wps/wps_upnp_ssdp.c @@ -354,7 +354,10 @@ int advertisement_state_machine_start(struct upnp_wps_device_sm *sm) /* (other fields not used here) */ /* First timeout should be random interval < 100 msec */ - next_timeout_msec = (100 * (os_random() & 0xFF)) >> 8; + if (os_get_random((u8 *) &next_timeout_msec, + sizeof(next_timeout_msec)) < 0) + return -1; + next_timeout_msec = (100 * (next_timeout_msec & 0xFF)) >> 8; return eloop_register_timeout(0, next_timeout_msec, advertisement_state_machine_handler, NULL, sm); @@ -475,7 +478,10 @@ static void msearchreply_state_machine_start(struct upnp_wps_device_sm *sm, a->state = 0; os_memcpy(&a->client, client, sizeof(*client)); /* Wait time depending on MX value */ - next_timeout_msec = (1000 * mx * (os_random() & 0xFF)) >> 8; + if (os_get_random((u8 *) &next_timeout_msec, + sizeof(next_timeout_msec)) < 0) + goto fail; + next_timeout_msec = (1000 * mx * (next_timeout_msec & 0xFF)) >> 8; next_timeout_sec = next_timeout_msec / 1000; next_timeout_msec = next_timeout_msec % 1000; if (eloop_register_timeout(next_timeout_sec, next_timeout_msec, -- 2.5.0
_______________________________________________ Hostap mailing list Hostap@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/hostap