Search code examples
perlencryptionmd5rsachecksum

MD5 Checksum with optional 128/256/512/1024/2048-bit size in Perl


Is it possible to use MD5 to get checksum that would have optional size of 128/256/512/1024/2048-bit?

The Digest::MD5 module allows to use the RSA MD5 Message Digest algorithm that takes as input a message of arbitrary length and produces as output a 128-bit fingerprint.

How can be used MD5 to produce larger fingerprint?


Solution

  • You cannot create a MD5 hash of that size. In general, secure hash functions have been designed for a specific size. They have an internal state of a certain size.

    Of course, you can use MD5 to create a random stream of bytes; just take the previous value and hash again, and keep appending the results. Of course, the total security of the results will be no stronger than the original hash value over the data. After a while the hashes will become weaker, as a little amount of entropy is lost after each hash (this will take pretty long though).

    Currently the best hash function you can use is SHA-512, although it will be slowly replaced by SHA-3 of the identical size (but that has not been standardized at the time of writing). These hash values provide more than enough security, so if you need more data you could simply use a padding method.

    The padding methods that come to mind are:

    • proprietary method to simply add an X number of bytes with known value;
    • the function as used within PBKDF2;
    • the function as used internally for PSS padding (see the public RSA PKCS#1 v2.1 standards).

    As said, it depends on the application which one is the best to use. If you don't know what you are doing (such as it seems), don't use MD5. It's too broken for general use, and it does not have a big enough state or output.