Wednesday, 18 June 2008

Cryptographic Checksums

Cryptographic checksums are simply hash functions which have been deemed "secure" according to certain criteria. In association with public key algorithms they are used to produce digital signatures. Here is a canonical program utilising the MD5 checksum in PyCrypto:

from Crypto.Hash import MD5
m =MD5.new()
m.update("MD5 is strengthened MD4")
print "checksum: " + m.digest()

Read the RFC written by Ron Rivest. A quick guide to cryptographic hash functions is on Columbia University's website.

SHA is a secure hash function designed for use with the Digital Signature Standard (check out the DSS official specification). It's easy to use in PyCrypto and produces slightly longer digests (160 bits instead of the standard 128 bits of MD2..MD5). Here's the sample code:

from Crypto.Hash import SHA
m =SHA.new()
m.update("SHA is more resistant to brute force attacks than MD5")
print "checksum: " + m.digest()

No comments: