[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Using arc4random() for luai_makeseed()?
- From: Vitaly Magerya <vmagerya@...>
- Date: Fri, 25 Dec 2015 17:08:29 +0200
On 2015-12-25 17:02, Daurnimator wrote:
>> The second question is: would you approve if FreeBSD package of
>> Lua was to patch 'luai_makeseed' into 'arc4random()'? I'm asking
>> this because I've been using such a patch locally for a while,
>> but FreeBSD Lua maintainers would like your approval before
>> adding it to the ports collection.
>>
>> [1] http://lua-users.org/lists/lua-l/2012-01/msg00658.html
>>
>
> It would seem reasonable to me for the lua 'freebsd' Makefile target
> to pass something like this in SYSCFLAGS:
>
> -D'luai_makeseed()=cast(unsigned int, arc4random())'
Yeah, that was my first attempt as well, but it turns out that
'arc4random' is not visible in 'src/lstate.c'; the actual patch I'm
using is this:
--- src/lstate.c.orig 2014-11-02 21:33:33.000000000 +0200
+++ src/lstate.c 2015-04-16 14:22:07.000000000 +0300
@@ -43,8 +43,12 @@
/*
** a macro to help the creation of a unique random seed when a state is
** created; the seed is used to randomize hashes.
*/
+#define __BSD_VISIBLE 1
+#include <stdlib.h>
+#define luai_makeseed() cast(unsigned int, arc4random())
+
#if !defined(luai_makeseed)
#include <time.h>
#define luai_makeseed() cast(unsigned int, time(NULL))
#endif