[PATCH 08/10] Switch from using os_random() to using os_get_random(...) in wpa_supplicant_event_michael_mic_failure(...)

Jouni Malinen j at w1.fi
Fri Feb 19 07:49:07 PST 2016


On Sun, Feb 14, 2016 at 07:40:25PM +0000, Nick Lowe wrote:
>  Switch from using os_random() to using
>  os_get_random(...) in wpa_supplicant_event_michael_mic_failure(...) 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.

> diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
> wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,

> -            int sec;
> +            int sec = 60;
> 
> -            if (os_get_random(rval, sizeof(rval)) < 0)
> -                sec = os_random() % 60;
> -            else
> -                sec = WPA_GET_BE32(rval) % 60;
> +            if (os_get_random(sec, sizeof(sec)) >= 0)
> +                sec = sec % 60;

This would increase the old maximum value by one second in the unlikely
error case, but that sounds fine.

> @@ -2637,7 +2634,7 @@ wpa_supplicant_event_michael_mic_failure(struct
>              eloop_register_timeout(
> -                sec, os_random() % 1000000,
> +                sec, 0,
>                  wpa_supplicant_delayed_mic_error_report,

But this would drop the sub-second resolution completely. That does not
sound desirable. Maybe replace sec with msec 0..60000 and use msec /
1000 and msec % 1000 * 1000 as the arguments here?

-- 
Jouni Malinen                                            PGP id EFC895FA



More information about the Hostap mailing list