Created
November 16, 2019 16:14
-
-
Save rdp/c9c20e1fcc3a52b860e73101ca917d61 to your computer and use it in GitHub Desktop.
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
diff --git a/src/crystal/system/random.cr b/src/crystal/system/random.cr | |
index e03cc6ca6..745d0300d 100644 | |
--- a/src/crystal/system/random.cr | |
+++ b/src/crystal/system/random.cr | |
@@ -11,7 +11,7 @@ module Crystal::System::Random | |
end | |
{% if flag?(:linux) %} | |
- require "./unix/getrandom" | |
+ require "./unix/urandom" | |
{% elsif flag?(:openbsd) %} | |
require "./unix/arc4random" | |
{% elsif flag?(:unix) %} | |
diff --git a/src/crystal/system/unix/urandom.cr b/src/crystal/system/unix/urandom.cr | |
index f2998b772..be9eeba30 100644 | |
--- a/src/crystal/system/unix/urandom.cr | |
+++ b/src/crystal/system/unix/urandom.cr | |
@@ -1,4 +1,5 @@ | |
-{% skip_file unless flag?(:unix) && !flag?(:openbsd) && !flag?(:linux) %} | |
+{% skip_file unless flag?(:unix) && !flag?(:openbsd) %} | |
+require "openssl" | |
module Crystal::System::Random | |
@@initialized = false | |
@@ -19,7 +20,11 @@ module Crystal::System::Random | |
init unless @@initialized | |
if urandom = @@urandom | |
- urandom.read_fully(buf) | |
+# urandom.read_fully(buf) | |
+ out = LibCrypto.rand_bytes(buf, buf.size) | |
+ if out != 1 | |
+ raise "ossl failed" | |
+ end | |
else | |
raise "Failed to access secure source to generate random bytes!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment