21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

See Also<br />

Recipes 5.5, 6.3, 6.7, 6.16<br />

6.16 Using a Block Cipher to Build a Full-Strength<br />

Hash Function<br />

<strong>Problem</strong><br />

Given a block cipher, you want to produce a one-way hash function, where finding<br />

collisions should always be as hard as inverting the block cipher.<br />

Solution<br />

Use MDC-2, which is a construction that turns a block cipher into a hash function<br />

using two Matyas-Meyer-Oseas hashes and a bit of postprocessing.<br />

Discussion<br />

Hash functions do not provide security in and of themselves! If you<br />

need to perform message integrity checking, use a MAC instead.<br />

The MDC-2 message digest construction turns an arbitrary block cipher into a oneway<br />

hash function. It’s different from Davies-Meyer and Matyas-Meyer-Oseas in that<br />

the output of the hash function is twice the block length of the cipher. It is also protected<br />

by patent until August 28, 2004.<br />

However, MDC-2 does use two instances of Matyas-Meyer-Oseas as components in<br />

its construction. Matyas-Meyer-Oseas hashes block by block and uses the internal<br />

state as a key used to encrypt each block of input. The resulting ciphertext is XOR’d<br />

with the block of input, and the output of that operation becomes the new internal<br />

state. The output of the hash function is the final internal state (though if the block<br />

size is not equal to the key size, it may need to be expanded, usually by repeating the<br />

value). The initial value of the internal state can be any arbitrary constant. See<br />

Figure 6-2 for a depiction of how one block of the message is treated.<br />

An issue with Matyas-Meyer-Oseas is that the cipher block size can be smaller than<br />

the key size, so you might need to expand the internal state somehow before using it<br />

to encrypt. Simply duplicating part of the key is sufficient. In the code we provide<br />

with this recipe, though, we’ll assume that you want to use AES with 128-bit keys.<br />

Because the block size of AES is also 128 bits, there doesn’t need to be an expansion<br />

operation.<br />

294 | Chapter 6: Hashes and Message Authentication<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!