[PATCH 07/10] Switch from using os_random() to using os_get_random(...) in advertisement_state_machine_start(...)

Nick Lowe nick.lowe at lugatech.com
Sun Feb 14 11:39:32 PST 2016


 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 at lugatech.com>
---
 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0007-Switch-from-using-os_random-to-using-os_get_random-..patch
Type: text/x-patch
Size: 1914 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/hostap/attachments/20160214/b3ae5bfe/attachment.bin>


More information about the Hostap mailing list