Only read 32 bytes from /dev/urandom for a seed. #15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem is you're using the standard I/O functions to read this Unix device; that is not a good idea.
The stdio read functions are buffered so the
fread()
call will always read a full block from the input. For files and terminals this isn't a problem; the former will just read the data the latter will just return whatever's available.The problem with
/dev/urandom
is that a full block of data will be available so a whole block will be read, however, this over a hundred times as much randomness as we actually need. This takes quite a while to generate as the kernel tries very hard to give good results. As the extra data is never used this doesn't actually deplete the theoretical entropy that the kernel has, but it doesn't know that. So this can cause problems too, especially if other applications use the blocking version of the device or you have a daemon that hunts for more randomness.The Unix functions
open()
,read()
andclose()
will treat the device nicely.