[PATCH] Implement non-trivial std::random_device::entropy (PR libstdc++/67578)

Jonathan Wakely jwakely@redhat.com
Mon May 22 13:01:00 GMT 2017


On 18/05/17 19:27 +0800, Xi Ruoyao wrote:
>This patch use ioctl to get entropy of std::random_device using
>/dev/random and /dev/urandom.

This is a nice addition, thanks.

N.B. I couldn't apply your patch, several lines had U+00A0 (i.e.
NO-BREAK SPACE) characters where normal spaces should be. I don't know
if this is something your mail client did, but maybe attaching the
patch as a multipart message rather than including it inline in the
body will prevent it in future.

>diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
>index 3e6e70b..39ad330 100644
>--- a/libstdc++-v3/config/abi/pre/gnu.ver
>+++ b/libstdc++-v3/config/abi/pre/gnu.ver
>@@ -1963,6 +1963,9 @@ GLIBCXX_3.4.23 {
>     _ZNSt13__future_base13_State_baseV211_Make_ready6_M_setEv;
> #endif
> 
>+    # std::random_device::_M_getentropy() const
>+    _ZNKSt13random_device13_M_getentropyEv;
>+
> } GLIBCXX_3.4.22;

The 3.4.23 version is now "closed" because it was used for the GCC 7.1
release, and so we can't add new symbols to it. That means we need to
bump the library version and create a new GLIBCXX_3.4.24 version node.
The required steps are documented in doc/xml/manual/build_hacking.xml
(and done by the attached patch which I'm testing).

>@@ -161,6 +169,34 @@ namespace std _GLIBCXX_VISIBILITY(default)
>     return _M_mt();
>   }
> 
>+  double
>+  random_device::_M_getentropy() const noexcept
>+  {
>+#if defined _GLIBCXX_HAVE_SYS_IOCTL_H && \
>+    defined _GLIBCXX_HAVE_LINUX_RANDOM_H

Is RNDGETENTCNT guaranteed to be defined by all versions of
<linux/random.h>?

Would it be better to check for it explicitly? i.e.

#if defined _GLIBCXX_HAVE_SYS_IOCTL_H && defined RNDGETENTCNT


It would also be nice to have a test for this functionality, but since
the available entropy might be zero sometimes we can't guarantee that
a test for a non-zero value will always pass.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 5948 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20170522/b4a66518/attachment.bin>


More information about the Libstdc++ mailing list