md5 consistent across platforms/Python versions?

Tim Peters tim.one at comcast.net
Tue Jul 15 11:18:49 EDT 2003


[Gary Robinson]
> I know that hash functions are often platform-dependent for efficiency
> reasons. From what I understand, this includes Python's hash(), which
> I have read is not guaranteed to return the same result across
> platforms or even across Python versions.

Indeed, a Python hash is a (short) Python int, so is a 32-bit value on most
current boxes, but a 64-bit value on most 64-bit boxes.

> Can someone tell me whether an MD5 hash using Python's MD5 library IS
> guaranteed to return the same results for the same input string,
> across platforms and Python versions?

Yes, it's the same, and the same as what you'll get from any other correct
program for computing an MD5 digest from that string.  The same is true of
the longer SHA digests (also available from Python, via the sha module).

> My limited understanding of how MD5 is normally used would seem to
> indicate that this must be the case, but it would be helpful for me
> to have confirmation, since my knowledge in this area is very limited.

It's confirmed, and your knowledge is now closer to unlimited <wink>.






More information about the Python-list mailing list