views:

297

answers:

3

Is there a hash function that returns a 16-digit hex value (as MD5 returns 32-digit), or is there a library (for C++) in which I can use MD5 or SHA-1 which returns a 16-digit value

+6  A: 

Since you're willing to live with the much-higher collision rate, you can just truncate the MD5 hash of the data.

Ignacio Vazquez-Abrams
wouldnt this give a higher collision rate than having a hash that returns 16^16 unique strings
Aly
Marginally. It's about 1 in 30.6e12 chance of a collision either way, which is not all that impressive.
Ignacio Vazquez-Abrams
+1  A: 

is there a library (for C++) in which I can use MD5 or SHA-1 which returns a 16-digit value

Lookup the OpenSSL crypto library (free) or RSA BSAFE (paid).

dirkgently
could you provide an example of how to truncate the hash from 32-digits to 16 using the crypto library
Aly
+1  A: 

If you truncate the size of a cryptographic hash function, you will break it - by which I mean you're very likely to damage the properties which make it cryptographically secure. If the cryptographic properties aren't important to you, then you don't need a cryptographic hash at all - you'd be better off with a checksum or non-cryptographic hash.

And whatever you're doing, don't use md5. If you need a cryptographic hash function, md5 isn't a good choice as algorithms exist that create collisions in a reasonable amount of time. If you don't need a cryptographic hash function, then md5 is overkill.

Joe Gauterin