rust-random / getrandom

A small cross-platform library for retrieving random data from (operating) system source
Apache License 2.0
264 stars 166 forks source link

Use libc::getrandom on Solaris and update docs. #420

Closed josephlr closed 2 months ago

josephlr commented 2 months ago

https://github.com/rust-random/getrandom/pull/417 used getentropy(2) on Solaris, but after looking at the blog post introducing getrandom() and getentropy(), it seems like we should prefer using getrandom based on this quote:

On Solaris the output of getentropy(2) is entropy and should not be used where randomness is needed, in particular it must not be used where an IV or nonce is needed when calling a cryptographic operation. It is intended only for seeding a user space RBG (Random Bit Generator) system. More specifically the data returned by getentropy(2) has not had the required FIPS 140-2 processing for the DRBG applied to it.

I also updated some of the documentation explaining:

newpavlov commented 2 months ago

Left comment here just before this PR was created.

josephlr commented 2 months ago

Left comment here just before this PR was created.

Sounds good! I'll put Solaris in its own file.

josephlr commented 2 months ago

@newpavlov I moved Solaris stuff to its own file. I also changed the implementation to always set GRND_RANDOM.

Looking over the man pages, I think your comment in https://github.com/rust-random/getrandom/pull/417#issuecomment-2095341300 (noting that all "correct" examples use GRND_RANDOM) is a good point. I don't think it hugely matters one way or another, and if we are doing a special implementation for Solaris, we might as well just mimic what they recommend in their man pages.

Let me know if you want me to change it back to using flags = 0 for consistency with the other uses of getrandom(2).