Even though MD2 is not yet fully compromised, the IETF retired MD2 to "historic" status in 2011, citing "signs of weakness". It is deprecated in favor of SHA-256 and other strong hashing algorithms.[4]
The 128-bit hash value of any message is formed by padding it to a multiple of the block length (128 bits or 16 bytes) and adding a 16-byte checksum to it. For the actual calculation, a 48-byte auxiliary block and a 256-byte S-table are used. The constants were generated by shuffling the integers 0 through 255 using a variant of Durstenfeld's algorithm with a pseudorandom number generator based on decimal digits of π (pi)[3][5] (see nothing up my sleeve number). The algorithm runs through a loop where it permutes each byte in the auxiliary block 18 times for every 16 input bytes processed. Once all of the blocks of the (lengthened) message have been processed, the first partial block of the auxiliary block becomes the hash value of the message.
The 128-bit (16-byte) MD2 hashes (also termed message digests) are typically represented as 32-digit hexadecimal numbers. The following demonstrates a 43-byte ASCII input and the corresponding MD2 hash:
MD2("The quick brown fox jumps over the lazy dog") =
03d85a0d629d2c442e987525319fc471
As the result of the avalanche effect in MD2, even a small change in the input message will (with overwhelming probability) result in a completely different hash. For example, changing the letter d to c in the message results in:
MD2("The quick brown fox jumps over the lazy cog") =
6b890c9292668cdbbfda00a4ebf31f05
The hash of the zero-length string is:
MD2("") =
8350e5a3e24c153df2275c9f80692773
Security
Rogier and Chauvaud presented in 1995[6] collisions of MD2's compression function, although they were unable to extend the attack to the full MD2. The described collisions was published in 1997.[7]
In 2004, MD2 was shown to be vulnerable to a preimage attack with time complexity equivalent to 2104 applications of the compression function.[8] The author concludes, "MD2 can no longer be considered a secure one-way hash function".
In 2008, MD2 has further improvements on a preimage attack with time complexity of 273 compression function evaluations and memory requirements of 273 message blocks.[9]
In 2009, MD2 was shown to be vulnerable to a collision attack with time complexity of 263.3 compression function evaluations and memory requirements of 252 hash values. This is slightly better than the birthday attack which is expected to take 265.5 compression function evaluations.[10]
^RSA Laboratories. "What are MD2, MD4, and MD5?". Public-Key Cryptography Standards (PKCS): PKCS #7: Cryptographic Message Syntax Standard. RSA Laboratories. Archived from the original on 16 January 2017.
^Rogier, N.; Chauvaud, Pascal (18–19 May 1995). The Compression Function of MD2 is not Collision Free. Selected Areas in Cryptography (SAC) 1995, Ottawa, Canada (workshop record).
^Rogier, N.; Chauvaud, Pascal (1997). "MD2 is not Secure without the Checksum Byte". Designs, Codes and Cryptography. 12 (3): 245–251. doi:10.1023/A:1008220711840. S2CID21613457.