Forum Moderators: coopster

Message Too Old, No Replies

crc32 vs md5

         

Code Sentinel

4:44 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



Which is more processor intensive? are there advantages of one over the other?

bcolflesh

4:54 pm on Sep 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From:

[thecodeproject.com...]

"The CRC32 algorithm can easily be brute forced in minutes. For security applications use MD5, SHA1, SHA256, SHA384, or SHA512..."

Code Sentinel

5:01 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



it won't be used for anything security related, I just need it to generate a unique value.

being on a shared server I try to use functions with lower cpu impact.

I'm just not sure how to go about benchmarking something like this so was wondering if either crc32 or md5 had any advantage over the other in terms of processing speed, cpu usage, uniqueness, and accuracy.

This value will be generated on every page request.

mincklerstraat

5:04 pm on Sep 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



iirc crc32 is more lightweight

drbrain

5:06 pm on Sep 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How unique do you need it to be? If you need to ensure that no two documents in your system have the same hash, use MD5 or SHA1. If you don't care about hash collisions, use CRC32. MD5 is pretty fast since it is implemented as a library. My six-year-old computer can compute an MD5 hash of a 420M file in a few seconds.

Code Sentinel

5:12 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



uniqueness is good, it's used for caching.. I just started wondering lately since I didn't even know of crc32 until recently. Everything I read about generating a hash value in php for security or otherwise uses md5 or SHA1.

if md5 is that fast then I suppose it's the better choice for uniqueness.

mincklerstraat

11:42 pm on Sep 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool, another caching script! What kind, what do you use it for? Functionality? (E-tags? other interesting headers for friendly third-party caching?)

If you have zillions of pages you could run into a hash conflict - I don't know the numbers, but I'd imagine the chances of such a conflict would be minimal if you just have a few thousand pages.

drbrain

7:43 pm on Sep 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For MD5 the likelihood of finding a collision by accident is nearly impossible. You'll be constantly calculating checksums of random content for lifetimes. With CRC32's algorithm you're likely to find a collision by accident within a few weeks.