note 96715 added to function.hash
| From: | RobinLeffmann at osu1 dot php dot net | Date: | Fri, 12 Mar 2010 13:25:05 +0000 |
| Subject: | note 96715 added to function.hash | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166964@lists.php.net to get a copy of this message | ||
A while back when helping out on a project relying on message digests for verifying the integrity of
staggering amounts of data, I bumped into some interesting differences in how the various ciphers
perform on different architectures. For the intended deployment platform, I was able to increase
both security, performance and message quality, all at the same time.
Don't assume that a cipher will always be computationally more demanding just because it's
more complex, or because its message size is larger than that of another cipher:
<?php
$rep = 20;
$num = 250;
$size = 32 * 1024;
$ciphers = array( 'sha256', 'sha512', 'whirlpool' );
// create 250 random messages, each 32kb in size
for( $i = 0; $i < $num; $i++ )
{
$c = 0; $tmp = null;
while( $c++ < $size / 16 )
$tmp .= md5( mt_rand(), true );
@$data[] = $tmp;
}
// digest 5000 times
foreach( $ciphers as $cipher )
{
$r = $rep;
$then = microtime( true );
while( $r-- )
{
for( $i = 0; $i < $num; $i++ )
$tmp = hash( $cipher, $data[$i], true );
}
echo "$cipher: " . ( microtime(true) - $then ) . PHP_EOL;
}
?>
On an AMD Athlon 64, running in 1ghz:
sha256: 7.2770738601685 <--
sha512: 17.481907844543 <--
whirlpool: 30.047662973404
After moving the platform to a 45nm Intel Core 2, clocked down to also run in 1ghz (with no dual
core action going on); same OS setup; same PHP setup; no recompiling:
sha256: 4.328763961792 <--
sha512: 2.7524480819702 <-- !
whirlpool: 8.7933950424194
----
Server IP: 194.236.124.41
Probable Submitter: 83.227.160.33
----
Manual Page -- http://www.php.net/manual/en/function.hash.php
Edit -- https://master.php.net/note/edit/96715
Del: integrated -- https://master.php.net/note/delete/96715/integrated
Del: useless -- https://master.php.net/note/delete/96715/useless
Del: bad code -- https://master.php.net/note/delete/96715/bad+code
Del: spam -- https://master.php.net/note/delete/96715/spam
Del: non-english -- https://master.php.net/note/delete/96715/non-english
Del: in docs -- https://master.php.net/note/delete/96715/in+docs
Del: other reasons-- https://master.php.net/note/delete/96715
Reject -- https://master.php.net/note/reject/96715
Search -- https://master.php.net/manage/user-notes.php