[PATCH]std::random_device for win32 (MinGW) ABI implementation
Jonathan Wakely
jwakely@redhat.com
Tue Oct 16 22:23:00 GMT 2018
On 12/10/18 17:45 +0000, sotrdg sotrdg wrote:
>The implementation is on the GitHub.
>
>https://github.com/euloanty/mingw-std-random_device/blob/master/random_device_gcc_withcxx11abi/random.cc
>
>
>This implementation does several changes towards the original random.cc.
>
>
> 1. Type Erasure Abstractions for various random_devices so we can choose any of them to use if necessary.
> 2. Solve security issue of setvbuf(fp,nullptr,_IONBF,0); In order to avoid seeds leaking to other processes after releasing the buffer of std::FILE*.
> 3. For amd64 platform, random_device will prefer using rdseed instruction instead of rdrand instruction
> 4. For Windows, random_device will get seeds from RtlGenRandom and buffer it.
> 5. Legacy support for mt19937.
>Iâve put it on the GitHub for anyone.
Thanks for this, although I'm afraid we can't use it without some
additional steps being taken, see https://gcc.gnu.org/contribute.html#legal
However, as I mentioned at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85494#c4 I've already
been working on an implementation that uses RtlGenRandom. My version
is attached. This implementation allows constructing a
std::random_device with the following tokens (where supported):
"default" - choose the first supported
"rtlgenrandom" - use Windows RtlGenRandom
"rdrand" or "rdrnd" - use RDRAND instruction
"rdseed" - use RDSEED instruction
"/dev/urandom" or "/dev/random" - use specified device file
This should be an ABI compatible change, so that existing MinGW
applications don't need to be recompiled, they just need to use the
new libstdc++-6.dll to get the new implementation (although they won't
get the secure zeroing out of memory without a recompile).
I've only done minimal testing using a mingw-w64 cross-compile and
executing under Wine, but it seems to work well.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 11596 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20181016/94231918/attachment.bin>
More information about the Libstdc++
mailing list