# MDC-2

In cryptography, MDC-2 (Modification Detection Code 2, sometimes called Meyer-Schilling) is a cryptographic hash function. MDC-2 is a hash function based on a block cipher with a proof of security in the ideal-cipher model.[1] The length of the output hash depends on the underlying block cipher used.

## Algorithm

For a given message ${\displaystyle M}$ to hash and a given block cipher encryption function ${\displaystyle E}$, the MDC-2 algorithm proceeds as follows. Let ${\displaystyle n}$ be the block length, ${\displaystyle A_{1},B_{1}}$ two different constants of size ${\displaystyle n}$. If ${\displaystyle M=M_{1}||..||M_{m}}$ where each ${\displaystyle M_{i}}$ has size ${\displaystyle n}$, then the hash ${\displaystyle V_{m}||W_{m}}$ of the message is given by:

• for ${\displaystyle i=1}$ to ${\displaystyle m}$:
• ${\displaystyle V_{i}=M_{i}\oplus E(M_{i},A_{i})}$
• ${\displaystyle W_{i}=M_{i}\oplus E(M_{i},B_{i})}$
• ${\displaystyle V_{i}^{L}||V_{i}^{R}=V_{i}}$
• ${\displaystyle W_{i}^{L}||W_{i}^{R}=W_{i}}$
• ${\displaystyle A_{i+1}=V_{i}^{R}||W_{i}^{L}}$
• ${\displaystyle B_{i+1}=W_{i}^{R}||V_{i}^{L}}$
• return ${\displaystyle A_{m+1}||B_{m+1}}$

## MDC-2DES hashes

When MDC-2 uses the DES block cipher, the 128-bit (16-byte) MDC-2 hashes are typically represented as 32-digit hexadecimal numbers. The following demonstrates a 43-byte ASCII input and the corresponding MDC-2 hash:

``` MDC2("The quick brown fox jumps over the lazy dog")
= 000ed54e093d61679aefbeae05bfe33a
```

Even a small change in the message will (with probability) result in a completely different hash, e.g. changing d to c:

``` MDC2("The quick brown fox jumps over the lazy cog")
= 775f59f8e51aec29c57ac6ab850d58e8
```

The hash of the zero-length string is:

``` MDC2("")
= 52525252525252522525252525252525
```

## Patent issues

MDC-2 was covered by U.S. Patent 4,908,861, issued on March 13, 1990 but filed by IBM on August 28, 1987.
For this reason, support for MDC-2 has been disabled in OpenSSL on most Linux distributions and is not implemented by many other cryptographic libraries.

But the maximum lifespan of 20 years from filing date means that the U.S. Patent 4,908,861 could not have lasted beyond August 28, 2007 ; in fact it has expired in 2002,[2] because IBM has not paid the renewal fee. The same goes for the Canadian patent. There is no patent for Europe. This means that MDC-2 can be freely used.