humanmade / Backdrop

Backdrop is a simple library that does one thing: allows you to run one-off tasks in the background.
GNU General Public License v2.0
46 stars 5 forks source link

PHP hash function for sha1 hash #3

Closed mattheu closed 10 years ago

mattheu commented 10 years ago

I know some hashing algorithms can return negative hash values on 32 bit systems (crc32 and md5 I think), and that it is best to use hash( $algo, $data ); instead. Does this apply to SHA1 as well?

https://github.com/humanmade/Backdrop/blob/master/task.php#L73

Could be

return hash( 'sha1', serialize( $this->callback ) . serialize( $this->params ) );

rmccue commented 10 years ago

Shouldn't make a difference; SHA1 (and MD5 for that matter) should be unsigned integers, plus they're returned hex-encoded.

rmccue commented 10 years ago

As noted on the crc32 page:

Returns the crc32 checksum of str as an integer.

sha1 however (with second parameter false, which is the default):

Returns the sha1 hash as a string.