-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use arc4random_buf to fill random bytes on OpenBSD
- Loading branch information
1 parent
0538f66
commit 0c6135b
Showing
3 changed files
with
13 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "c/stdlib" | ||
|
||
module Crystal::System::Random | ||
# Fills *buffer* with random bytes using arc4random. | ||
# | ||
# NOTE: only secure on OpenBSD and CloudABI | ||
def self.random_bytes(buffer : Bytes) : Nil | ||
LibC.arc4random_buf(buffer.to_unsafe.as(Void*), buffer.size) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters