Skip to content
This repository was archived by the owner on May 8, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Salsa20/Salsa20.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function stream($out, $m, $mlen ,$n, $k) {
$u = 1;
for ($i = 8;$i < 16;++$i) {
$u += $z[$i];
$z[$i] = $u;
$z[$i] = $u & 0xff;
$u >>= 8;
}

Expand Down
12 changes: 5 additions & 7 deletions Salt.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,19 @@ public static function instance() {
* @return string
*/
public static function randombytes($length = 32) {
$raw = '';
$raw = false;
if (is_readable('/dev/urandom')) {
$fp = true;
if ($fp === true) {
$fp = @fopen('/dev/urandom', 'rb');
}
if ($fp !== true && $fp !== false) {
$fp = @fopen('/dev/urandom', 'rb');
if ($fp !== false) {
$raw = fread($fp, $length);
fclose($fp);
}
} else if (function_exists('mcrypt_create_iv')) {
$raw = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
} else if (function_exists('openssl_random_pseudo_bytes')) {
$raw = openssl_random_pseudo_bytes($length);
}
if (!$raw || strlen($raw) !== $length) {
if ($raw === false || strlen($raw) !== $length) {
throw new SaltException('Unable to generate randombytes');
}
return $raw;
Expand Down