Boost logo

Boost :

Subject: Re: [boost] boost::random, header-only, boost::uuids::detail::seed_rng, and UWP development
From: Peter Dimov (lists_at_[hidden])
Date: 2017-09-12 14:35:35


Andrey Semashev wrote:
> On Tue, Sep 12, 2017 at 4:27 PM, degski via Boost <boost_at_[hidden]>
> wrote:
> > On 12 September 2017 at 15:40, James E. King, III via Boost <
> > boost_at_[hidden]> wrote:
> >
> >> The older WinCrypt calls are not available in some Windows platforms
> >> going forward, so this is going to become a problem pretty quickly for
> >> the community.
> >>
> >
> > You worry too much, just call rand_s
> > <https://msdn.microsoft.com/en-us/library/sxtz2fa8.aspx> (the same thing
> > under the hood, but taking care of any WinCrypt BCrypt, whatever
> > issues).
>
> I assume, this is MSVC-specific, i.e. doesn't work with MinGW?

In addition,

"The rand_s function requires that constant _CRT_RAND_S be defined prior to
the inclusion statement for the function to be declared, as in the following
example:

#define _CRT_RAND_S
#include <stdlib.h>
"

which probably means that if <stdlib.h> is included prior to the header that
wants to use rand_s, it will be unavailable.

We could use RtlGenRandom instead, which is what rand_s calls. Not sure if
that works under UWP.

To answer the question in the original post, yes, making random_device
header-only would indeed be useful, as long as we don't include <windows.h>.

There's no need to include the implementation from seed_rng in its entirety
though, it's more complicated than need be because it tries to support the
case in which a device isn't available. Since the construction of
random_device can fail, it can be a lightweight wrapper over /dev/urandom /
CryptGenRandom, without all the SHA business.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk