-
Notifications
You must be signed in to change notification settings - Fork 8k
Tweak CSPRNG error conditions & add exceptions #1398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I question the validity of 2. A properly implemented Fisher-Yates will not require generating random numbers with min=max. If you need this case, it implies that you're doing an additional superfluous iteration. |
Have you seen how most PHP devs write code? Demanding proper On Jul 13, 2015 6:00 PM, "Nikita Popov" notifications@github.com wrote:
|
|
I don't understand your analogy. If you get an exception due to an off-by-one error in your shuffling implementation, you will be forced to improve your implementation. Why do you consider that stricter input validation should result in broken crypto-system implementations? |
|
I'm saying random_int() should behave like mt_rand() so we can encourage http://3v4l.org/WsfED
|
|
That's an argument I can buy ;) |
|
FYI: These changes have also been discussed on the internals mailing list. |
|
Closing this since #1397 now has all the newly-agreed upon logic. |
This PR is part 2 of #1397 and this discussion. It tweaks the behavior of
random_bytes()andrandom_int()in the following ways:random_bytes()will throw anExceptioniflength < 1instead of issuing anE_WARNINGand returningfalse.random_int()now allows formin&maxto be the same value for cases that need it (i.e. when picking the last card in a shuffling algorithm)random_int()will throw anExceptionifmin > maxinstead of issuing anE_WARNINGand returningfalse.There was some discussion of throwing the exceptions as an
InvalidArgumentException, but the consensus seems to be "keep it general" for BC friendliness.CC: @weltling, @KalleZ, @lt