Skip to content

Commit

Permalink
Enable arc4random(3) on all supported BSDs and macOS/Darwin (#12608)
Browse files Browse the repository at this point in the history
Co-authored-by: Jamie Gaskins <[email protected]>
  • Loading branch information
dmgk and jgaskins authored Nov 16, 2022
1 parent d447f58 commit 3973f44
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/crystal/system/random.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end
require "./wasi/random"
{% elsif flag?(:linux) %}
require "./unix/getrandom"
{% elsif flag?(:openbsd) || flag?(:netbsd) %}
{% elsif flag?(:bsd) || flag?(:darwin) %}
require "./unix/arc4random"
{% elsif flag?(:unix) %}
require "./unix/urandom"
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/unix/arc4random.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% skip_file unless flag?(:openbsd) || flag?(:netbsd) %}
{% skip_file unless flag?(:bsd) || flag?(:darwin) %}

require "c/stdlib"

Expand Down
3 changes: 3 additions & 0 deletions src/lib_c/aarch64-darwin/c/stdlib.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ lib LibC
rem : Int
end

fun arc4random : UInt32
fun arc4random_buf(x0 : Void*, x1 : SizeT) : Void
fun arc4random_uniform(x0 : UInt32T) : UInt32T
fun atof(x0 : Char*) : Double
fun div(x0 : Int, x1 : Int) : DivT
fun exit(x0 : Int) : NoReturn
Expand Down
3 changes: 3 additions & 0 deletions src/lib_c/x86_64-darwin/c/stdlib.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ lib LibC
rem : Int
end

fun arc4random : UInt32
fun arc4random_buf(x0 : Void*, x1 : SizeT) : Void
fun arc4random_uniform(x0 : UInt32T) : UInt32T
fun atof(x0 : Char*) : Double
fun div(x0 : Int, x1 : Int) : DivT
fun exit(x0 : Int) : NoReturn
Expand Down
3 changes: 3 additions & 0 deletions src/lib_c/x86_64-dragonfly/c/stdlib.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ lib LibC
rem : Int
end

fun arc4random : UInt32
fun arc4random_buf(x0 : Void*, x1 : SizeT) : Void
fun arc4random_uniform(x0 : UInt32T) : UInt32T
fun atof(x0 : Char*) : Double
fun div(x0 : Int, x1 : Int) : DivT
fun exit(x0 : Int) : NoReturn
Expand Down
3 changes: 3 additions & 0 deletions src/lib_c/x86_64-freebsd/c/stdlib.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ lib LibC
rem : Int
end

fun arc4random : UInt32
fun arc4random_buf(x0 : Void*, x1 : SizeT) : Void
fun arc4random_uniform(x0 : UInt32T) : UInt32T
fun atof(x0 : Char*) : Double
fun div(x0 : Int, x1 : Int) : DivT
fun exit(x0 : Int) : NoReturn
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/x86_64-netbsd/c/stdlib.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lib LibC

fun arc4random : UInt32
fun arc4random_buf(x0 : Void*, x1 : SizeT) : Void
fun arc4random_uniform(x0 : UInt32T) : UInt32T
fun atof(x0 : Char*) : Double
fun div(x0 : Int, x1 : Int) : DivT
fun exit(x0 : Int) : NoReturn
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/x86_64-openbsd/c/stdlib.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lib LibC

fun arc4random : UInt32
fun arc4random_buf(x0 : Void*, x1 : SizeT) : Void
fun arc4random_uniform(x0 : UInt32T) : UInt32T
fun atof(x0 : Char*) : Double
fun div(x0 : Int, x1 : Int) : DivT
fun exit(x0 : Int) : NoReturn
Expand Down
2 changes: 1 addition & 1 deletion src/random/secure.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require "crystal/system/random"
# [1, 5, 6].shuffle(Random::Secure) # => [6, 1, 5]
# ```
#
# On OpenBSD, it uses [`arc4random`](https://man.openbsd.org/arc4random),
# On BSD-based systems and macOS/Darwin, it uses [`arc4random`](https://man.openbsd.org/arc4random),
# on Linux [`getrandom`](http://man7.org/linux/man-pages/man2/getrandom.2.html) (if the kernel supports it),
# on Windows [`RtlGenRandom`](https://docs.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom),
# and falls back to reading from `/dev/urandom` on UNIX systems.
Expand Down

0 comments on commit 3973f44

Please sign in to comment.