-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fixes initialization of ISAAC PRNG without explicit seed #4882
Conversation
src/random/isaac.cr
Outdated
|
||
private def random_seeds | ||
result = uninitialized Seeds | ||
SecureRandom.random_bytes(result.to_unsafe.as(UInt8*).to_slice(sizeof(Seeds))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would unsafe_as(StaticArray(UInt8, 32)).to_slice
work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this way it looks cleaner 😄 . Is StaticArray(UInt8, sizeof(Seeds))
ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it complies it's great.
src/random/isaac.cr
Outdated
|
||
private def random_seeds | ||
result = uninitialized Seeds | ||
SecureRandom.random_bytes(result.to_unsafe.as(UInt8*).to_slice(sizeof(Seeds))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it complies it's great.
src/random/isaac.cr
Outdated
|
||
private def random_seeds | ||
result = uninitialized Seeds | ||
SecureRandom.random_bytes(result.unsafe_as(StaticArray(UInt8, sizeof(Seeds))).to_slice) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract result.unsafe_as(StaticArray(UInt8, sizeof(Seeds))).to_slice
to a result_slice
variable. The line's getting quite messy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Why requiring |
I don't understand what is the difference (I thought that |
That definitely is worth a blogpost or similar that describes what the stdlib should look like moving forward. /cc @mverzilli @matiasgarciaisaia @bcardiff |
@konovod a bit more of background (until someone can produce a condensed and concise response here): Cheers |
@luislavena i think i already read them (maybe not thoroughly). But when reading i thought that it was replacing So, if I understand correctly, the difference is that I've updated PR. |
This weird phobia against including The system random situation in crystal is also just crazy. There should be one class in crystal which uses And you know how I feel about All the current mess just serves to confuse people, as this thread continues to prove. |
I have no personal position on that, so I will suggest a RFC for that be reviewed by core and other contributors. Please do, so the RFC can be used as guidance and modifications be introduced to simply current approach. |
adds specs for such initialization
Thank you @konovod! I was about to say you're steadily becoming "Crystal's Random Guy" but realized it didn't sound so positive :P. |
#4789 introduced a problem - there is no spec ensuring that PRNG can be actually created without seed. So "seeding" it added for ISAAC was a piece of code that don't even compiles.
This PR fixes it and adds spec that ensures that initialization at least compiles. I don't know what else can be checked in spec (i think we can compare that
next_u
of two created instances aren't equal, but this means that there will be 1/2^32 chance that they will match and spec fails).