[PATCH] libc++: add NaCl and PNaCl support for std::random_device

JF Bastien jfb at chromium.org
Mon Dec 1 09:18:26 PST 2014


>>! In D6442#17, @mclow.lists wrote:
> Your changes look good; but now I'm wondering if you want to accept both `"/dev/random"` and `"/dev/urandom"` as valid tokens.

I don't want /dev/random because the NaCl interface I'm using doesn't guarantee "very high quality randomness" and doesn't block when such randomness isn't available. User code that expects such randomness should hard-fail (and fall back as makes sense for them), instead of getting lower quality randomness. NaCl has, for example, SSH clients that rely on similar (non-C++) random device interfaces, and knowing that the source of randomness is bad is pretty important to them (not that OpenSSL and friends have a great track record).

> Should the windows implementation also accept only `"/dev/random"` and `"/dev/urandom"` as valid tokens?

I wouldn't offer /dev/random unless the implementation actually meets the expectations of users.

> That would enable us to make the test portable; and help people to write cross-platform code.

I think the lack of platform portability should go back to WG21 LEWG ;-)

Agreed that the test is now ugly... but hey it's correct!

================
Comment at: include/__config:118
@@ +117,3 @@
+  // std::random_device is instead exposed through a NaCl syscall.
+# define _LIBCPP_USING_NACL_RANDOM 1
+#endif // defined(__native_client__)
----------------
mclow.lists wrote:
> I don't think you need to actually set `_LIBCPP_USING_NACL_RANDOM` to a value.
> 
>     #define _LIBCPP_USING_NACL_RANDOM
> 
> is sufficient.
Done.

http://reviews.llvm.org/D6442






More information about the cfe-commits mailing list