From c18e3a5165c30aa0475ae938cc083d4fa7bd167d Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 3 Jul 2011 16:50:17 -0400 Subject: Change Basis.rand to use cryptographically secure generation --- src/c/urweb.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/c/urweb.c b/src/c/urweb.c index b1785cb6..238b27e2 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -3777,8 +3778,13 @@ uw_Basis_unit uw_Basis_debug(uw_context ctx, uw_Basis_string s) { } uw_Basis_int uw_Basis_rand(uw_context ctx) { - uw_Basis_int n = abs(rand()); - return n; + uw_Basis_int ret; + int r = RAND_bytes((unsigned char *)&ret, sizeof ret); + + if (r) + return abs(ret); + else + uw_error(ctx, FATAL, "Random number generation failed"); } void uw_noPostBody(uw_context ctx) { -- cgit v1.2.3