-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Remove DefaultCsprng #6731
Remove DefaultCsprng #6731
Conversation
lib/std/rand.zig
Outdated
pub const DefaultPrng = Xoroshiro128; | ||
|
||
/// Cryptographically secure random numbers. | ||
pub const DefaultCsprng = Gimli; |
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.
I would keep this here and switch it over when the new one arrives.
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.
The interface may be different, though.
} | ||
|
||
fn fill(r: *Random, buf: []u8) void { | ||
std.crypto.randomBytes(buf) catch @panic("System random number generator not available"); |
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.
Hmm, this makes me think std.crypto.randomBytes
is badly location; perhaps should have its implementation moved here.
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.
Having it in std.crypto
also makes sense. Maybe we can reexport it.
I'm on board for some sweeping breaking changes to reorganize this, but let's leave this until we have the new thing, so that users have a clear upgrade path. |
Sounds reasonable! The removal of |
pub fn init() OsRandom { | ||
return OsRandom{ | ||
.random = Random{ .fillFn = fill }, | ||
}; | ||
} |
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.
proposal: delete this function, and follow this pattern:
Lines 88 to 98 in 1e13e8e
pub const page_allocator = if (std.Target.current.isWasm()) | |
&wasm_page_allocator_state | |
else if (std.Target.current.os.tag == .freestanding) | |
root.os.heap.page_allocator | |
else | |
&page_allocator_state; | |
var page_allocator_state = Allocator{ | |
.allocFn = PageAllocator.alloc, | |
.resizeFn = PageAllocator.resize, | |
}; |
Combined with moving it to std.crypto, usage would look like this:
std.crypto.os_random.bytes(buf);
Which I think would be enough to justify deleting std.crypto.randomBytes
. This would be a good time to plan what the namespace of the #6704 API would be. Perhaps std.crypto.random
meaning that we could tell users to upgrade from std.crypto.randomBytes
to std.crypto.random.bytes
which is a pretty satisfying upgrade, especially considering that bytes
could then be replaced with any of the other Random interface functions, and it gains the benefits of the thread-local CSPRNG infrastructure.
Reserve the name for the forthcoming global CSPRNG instead.
Not a lot of changes required since we don't use this type.
Add some comments by the way, as well as a
Rand
interface togetRandom()
.