Page MenuHomePhabricator

[libcxx] random_device, for OpenBSD specify optimal entropy properties
ClosedPublic

Authored by brad on Jan 12 2021, 5:36 PM.

Details

Summary

Submitting upstream from OpenBSD tree:

The random_device is an abstraction to the underlying OS PRNG. In OpenBSD's case, we know it has optimal entropy properties so specify what that is.

Diff Detail

Event Timeline

brad created this revision.Jan 12 2021, 5:36 PM
brad requested review of this revision.Jan 12 2021, 5:36 PM
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptJan 12 2021, 5:36 PM
ldionne requested changes to this revision.Jan 13 2021, 7:21 AM
ldionne added inline comments.
libcxx/src/random.cpp
42

You can include this unconditionally. Please include it alongside "random" and "system_error" above.

181

Couldn't we do a better job and use ioctl on Linuxes? See cppreference: https://en.cppreference.com/w/cpp/numeric/random/random_device/entropy

This revision now requires changes to proceed.Jan 13 2021, 7:21 AM
brad added inline comments.Jan 13 2021, 8:23 AM
libcxx/src/random.cpp
42

You can include this unconditionally. Please include it alongside "random" and "system_error" above.

Ah. The original diff was like that. I figured you would want it guarded like this.

Immediately below them? In the same form? "limits" or as is?

ldionne added inline comments.Jan 13 2021, 8:34 AM
libcxx/src/random.cpp
42

Just #include "limits". It's a header provided by libc++, and compile-times are not really a concern for building the libc++ library, so I prefer to go for simplicity and removing as many #ifdefs as I can.

brad updated this revision to Diff 316415.Jan 13 2021, 8:41 AM

Updated diff after moving header up to the top and removing the OpenBSD guard.

brad updated this revision to Diff 316418.Jan 13 2021, 8:47 AM

Don't care about the removal of that one line.

ldionne requested changes to this revision.Jan 18 2021, 11:03 AM
ldionne added inline comments.
libcxx/src/random.cpp
181

Ping on this question. Is it a possibility to improve our implementation on all Linux platforms instead?

This revision now requires changes to proceed.Jan 18 2021, 11:03 AM

@brad I suggest we abandon this in favour of D94953. Does it solve your problem?

brad added a comment.Jan 19 2021, 7:37 AM

@ldionne I don't understand how a Linux specific diff would help with another operating system. I could update this after D94953 goes in and eliminate the first chunk.

@ldionne I don't understand how a Linux specific diff would help with another operating system. I could update this after D94953 goes in and eliminate the first chunk.

I thought OpenBSD and Linux might behave the same in that regard. It does look like OpenBSD has ioctl, but not RNDGETENTCNT: https://man.openbsd.org/ioctl.2. Can you confirm this?

brad updated this revision to Diff 318359.Jan 21 2021, 4:57 PM

Rebased.

curdeius added inline comments.
libcxx/src/random.cpp
192

Just asking. I guess it cannot happen that the first branch of #if is true in OpenBSD, right?

193

Please use result_type here or changed to unsigned above for consistency.

brad added inline comments.Jan 23 2021, 10:17 PM
libcxx/src/random.cpp
192

Yes, this RNDGETENTCNT ioctl is Linux specific.

193

Ok.

brad updated this revision to Diff 318807.Jan 23 2021, 10:17 PM

Updated.

ldionne accepted this revision.Jan 25 2021, 7:40 AM
This revision is now accepted and ready to land.Jan 25 2021, 7:40 AM