[m-rev.] for post-commit review: add an arc4random() based system RNG implementation

Julien Fischer jfischer at opturion.com
Tue Feb 2 16:00:14 AEDT 2021



On Tue, 2 Feb 2021, Peter Wang wrote:

> On Tue, 02 Feb 2021 00:51:58 +1100 Julien Fischer <jfischer at opturion.com> wrote:
>>
>> I assume no-one wants to run Mercury on old (circa 2014) versions of
>> NetBSD or OpenBSD.  The macOS stuff is a little ugly, but it will have
>> to be that way until we drop support for 10.{9,10,11}.
>>
>> ------------------------------------------
>>
>> Add an arc4random() based system RNG implementation.
>>
>> library/random.system_rng.m:
>>      As above.
>>
>>      Use the arc4random() based implementation on FreeBSD >= 12.0
>>      and macOS >= 10.12, falling back to the urandom approach on earlier
>>      versions.
>>
>>      Always use the arc4random() approach on NetBSD and OpenBSD,
>>      both of which have used ChaCha20 in their implementation
>>      of arc4random() since 2014.
>
>> @@ -142,6 +152,23 @@
>>
>>   #if defined(__linux__) || defined(MR_SOLARIS) || defined(_AIX)
>>       #define ML_SYSRAND_IMPL_URANDOM
>> +#elif defined(__OpenBSD__) || defined(__NetBSD__)
>> +    #define ML_SYSRAND_IMPL_ARC4RANDOM
>> +#elif __FreeBSD__ >= 12
>> +    // arc4random() on FreeBSD used RC4 until version 12.
>> +    #define ML_SYSRAND_IMPL_ARC4RANDOM
>> +#elif defined(__FreeBSD__)
>> +    #define ML_SYSRAND_IMPL_URANDOM
>> +#elif defined(MR_MAC_OSX)
>> +   // arc4random() on macOS used RC4 until version 10.12.
>> +   // XXX this will be unnecessary when we stop supporting versions
>> +   // of macOS before 10.12.
>> +   #if defined(MAC_OS_X_VERSION_10_12) && \
>> +        MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
>> +      #define ML_SYSRAND_IMPL_ARC4RANDOM
>
> You might want to escape the backslash there.

Done.  (I would note that based on quick grep of the library that
backslash escaping in C foreign code is fairly inconsistent -- we
should fix that.)

> Otherwise it looks fine.

Thanks for that.

Julien.


More information about the reviews mailing list