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.

6.15 Constructing a Hash Function from a Block<br />

Cipher<br />

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

You’re in an environment in which you’d like to use a hash function, but you would<br />

prefer to use one based on a block cipher. This might be because you have only a<br />

block cipher available, or because you would like to minimize security assumptions<br />

in your system.<br />

Solution<br />

There are several good algorithms for doing this. We present one, Davies-Meyer,<br />

where the digest size is the same as the block length of the underlying cipher. With<br />

64-bit block ciphers, Davies-Meyer does not offer sufficient security unless you add a<br />

nonce, in which case it is barely sufficient. Even with AES-128, without a nonce,<br />

Davies-Meyer is somewhat liberal when you consider birthday attacks.<br />

Unfortunately, there is only one well-known scheme worth using for converting a<br />

block cipher into a hash function that outputs twice the block length (MDC-2), and<br />

it is patented at the time of this writing. However, those patent issues will go away<br />

by August 28, 2004. MDC-2 is covered in Recipe 6.16.<br />

Note that such constructs assume that block ciphers resist related-key attacks. See<br />

Recipe 6.3 for a general comparison of such constructs compared to dedicated constructs<br />

like SHA1.<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 Davies-Meyer hash function uses the message to hash as key material for the<br />

block cipher. The input is padded, strengthened, and broken into blocks based on<br />

the key length, each block used as a key to encrypt a single value. Essentially, the<br />

message is broken into a series of keys.<br />

With Davies-Meyer, the first value encrypted is an initialization vector (IV) that is<br />

usually agreed upon in advance. You may treat it as a nonce instead, however, which<br />

we strongly recommend. (The nonce is then as big as the block size of the cipher.)<br />

The result of encryption is XOR’d with the IV, then used as a new IV. This is<br />

repeated until all keys are exhausted, resulting in the hash output. See Figure 6-1 for<br />

a visual description of one pass of Davies-Meyer.<br />

Constructing a Hash Function from a Block Cipher | 291<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!