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)34 (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 S-table values in hex are:
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:
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:
The hash of the zero-length string is:
Rogier and Chauvaud presented in 19955 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.6
In 2004, MD2 was shown to be vulnerable to a preimage attack with time complexity equivalent to 2104 applications of the compression function.7 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.8
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.9
In 2009, security updates were issued disabling MD2 in OpenSSL, GnuTLS, and Network Security Services.10
Kaliski, Burt (April 1992). The MD2 Message-Digest Algorithm. IETF. p. 3. doi:10.17487/RFC1319. RFC 1319. Retrieved 22 November 2014. /wiki/Burt_Kaliski ↩
RFC 6149, MD2 to Historic Status /wiki/RFC_(identifier) ↩
"How is the MD2 hash function S-table constructed from Pi?". Cryptography Stack Exchange. Stack Exchange. 2 August 2014. Retrieved 23 May 2021. https://crypto.stackexchange.com/a/18444 ↩
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. S2CID 21613457. /wiki/Doi_(identifier) ↩
Muller, Frédéric (2004). The MD2 Hash Function is Not One-Way (PDF). ASIACRYPT 2004. pp. 214–229. doi:10.1007/978-3-540-30539-2_16. Retrieved 26 April 2021 – via International Association for Cryptologic Research. https://www.iacr.org/conferences/asiacrypt2004/data/Asiacrypt2004/05%20Hash%20Functions/03_Frederic%20Muller.pdf ↩
Thomsen, Søren S. (2008). "An Improved Preimage Attack on MD2" (PDF). {{cite journal}}: Cite journal requires |journal= (help) http://eprint.iacr.org/2008/089.pdf ↩
Knudsen, Lars R.; Mathiassen, John Erik; Muller, Frédéric; Thomsen, Søren S. (2009). "Cryptanalysis of MD2". Journal of Cryptology. 23: 72–90. doi:10.1007/s00145-009-9054-1. S2CID 2443076. https://doi.org/10.1007%2Fs00145-009-9054-1 ↩
CVE-2009-2409 /wiki/CVE_(identifier) ↩