-
Notifications
You must be signed in to change notification settings - Fork 18
Support random_bytes() as an additional randomness source
#6
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
base: 1.0
Are you sure you want to change the base?
Changes from all commits
19c6561
12b684c
85c9a3f
41cfbb1
27e4a50
e4b358d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,22 +233,24 @@ protected function _normalize($string, array $options = []) { | |
| return $string; | ||
| } | ||
|
|
||
| /** | ||
| * Generates a cryptographically secure sequence of bytes. | ||
| * | ||
| * @param integer $bytes Number of bytes to return. | ||
| * @return string | ||
| */ | ||
| /** | ||
| * Generates a cryptographically secure sequence of bytes. | ||
| * | ||
| * @param integer $bytes Number of bytes to return. | ||
| * @return string | ||
| * @throws Exception | ||
| */ | ||
| protected function _random($bytes) { | ||
| if (is_readable('/dev/urandom')) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you run into openbasedir issues with this line, than your openbasedir configuration needs to be changed as it is too strict. It is safe to generally include |
||
| $stream = fopen('/dev/urandom', 'rb'); | ||
| $result = fread($stream, $bytes); | ||
| //if (is_readable('/dev/urandom')) { | ||
| if ($fh = @fopen('/dev/urandom', 'rb')) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Errors should not be surpressed. |
||
| $stream = fopen('/dev/urandom', 'rb'); | ||
| $result = fread($stream, $bytes); | ||
|
|
||
| fclose($stream); | ||
| return $result; | ||
| } | ||
| if (function_exists('mcrypt_create_iv')) { | ||
| return mcrypt_create_iv($bytes, MCRYPT_DEV_RANDOM); | ||
| fclose($stream); | ||
| return $result; | ||
| } | ||
| if (function_exists('random_bytes')) { | ||
| return random_bytes($bytes); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line will not be reachable unless the mcrypt extension is installed, which is not what you want. How about adding a similar block as a first possible source of randomness in our |
||
| } | ||
| throw new Exception("No source for generating a cryptographically secure seed found."); | ||
| } | ||
|
|
||
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.
Don't change the identation style