note 96715 deleted from function.hash by danbrown
| From: | danbrown@php.net | Date: | Fri, 12 Mar 2010 13:30:30 +0000 |
| Subject: | note 96715 deleted from function.hash by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166965@lists.php.net to get a copy of this message | ||
Note Submitter: Robin Leffmann
----
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