Skip to content

Commit a24212a

Browse files
committed
Stronger server salt
ZeroBin now generates a much stronger salt. This fixes issue #68 (mentioned in section 2.1 of https://defuse.ca/audits/zerobin.htm)
1 parent 09d39a9 commit a24212a

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

lib/serversalt.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
function generateRandomSalt()
55
{
66
$randomSalt='';
7-
for($i=0;$i<16;$i++) { $randomSalt.=base_convert(mt_rand(),10,16); }
7+
if (function_exists("mcrypt_create_iv"))
8+
{
9+
$randomSalt = bin2hex(mcrypt_create_iv(256, MCRYPT_DEV_URANDOM));
10+
}
11+
else // fallback to mt_rand()
12+
{
13+
for($i=0;$i<16;$i++) { $randomSalt.=base_convert(mt_rand(),10,16); }
14+
}
815
return $randomSalt;
916
}
1017

lib/vizhash_gd_zero.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,7 @@ function generate($text)
7474

7575
return $imagedata;
7676
}
77-
78-
// Generate a large random hexadecimal salt.
79-
private function randomSalt()
80-
{
81-
$randomSalt='';
82-
for($i=0;$i<6;$i++) { $randomSalt.=base_convert(mt_rand(),10,16); }
83-
return $randomSalt;
84-
}
85-
86-
77+
8778
private function getInt() // Returns a single integer from the $VALUES array (0...255)
8879
{
8980
$v= $this->VALUES[$this->VALUES_INDEX];

0 commit comments

Comments
 (0)