Does size matter when choosing the right algorithm to use the session hash.
I recently read this article and suggested using a jacuzzi to create a hash for the session ID. Whirlpool generates a 128-character hash string, is it too much?
The plan is to keep the session hash in db. Is there any difference between maybe using a 64-character field (sha256), a field with 96 characters (sha384) or 128 characters (jacuzzi)? One of the initial arguments made for whirlwind was speed versus other algorithms, but looking at the speed results, sha384 does not evaluate too poorly.
There is an option to trim the hash to make it less than 128 characters.
I modified the source code snippet to allow a change in the algorithm based on needs.
Update . Some opinion was expressed that the string hashed, so I included the code.
function generateUniqueId($maxLength = null) {
$entropy = '';
if (function_exists('openssl_random_pseudo_bytes')) {
$entropy = openssl_random_pseudo_bytes(64, $strong);
if($strong !== true) {
$entropy = '';
}
}
$entropy .= uniqid(mt_rand(), true);
if (class_exists('COM')) {
try {
$com = new COM('CAPICOM.Utilities.1');
$entropy .= base64_decode($com->GetRandom(64, 0));
} catch (Exception $ex) {
}
}
if (is_readable('/dev/urandom')) {
$h = fopen('/dev/urandom', 'rb');
$entropy .= fread($h, 64);
fclose($h);
}
$hash = hash('whirlpool', $entropy);
if ($maxLength) {
return substr($hash, 0, $maxLength);
}
return $hash;
}
source
share