21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

To ensure the best security, we strongly recommend that you follow these steps:<br />

1. Select a nonce using a well-seeded cryptographic random number generator (see<br />

Chapter 11). If you’re going to have multiple messages to process, select a random<br />

portion that is common to all messages (at least 64 bits) and use a counter<br />

for the rest. (The counter should be big enough to handle any possible number<br />

of messages. Here we also recommend dedicating at least 64 bits.)<br />

2. Determine the internal block length of the hash function (discussed later in this<br />

section).<br />

3. Pad the nonce to the internal block length by adding as many zero-bytes as necessary.<br />

4. Add the padded nonce to both the beginning and the end of the message.<br />

5. Hash, creating a value V.<br />

6. Hash V to get the final output. This final step protects against length-extension<br />

attacks, as discussed in Recipe 6.7.<br />

One thing that you need to be sure to avoid is a situation in which the attacker can<br />

control the nonce value. A nonce works well only if it cannot be reused. If an<br />

attacker can control the nonce, he can generally guarantee it gets reused, in which<br />

case problems like the birthday attack still apply.<br />

In cases where having a nonce that the attacker can’t control isn’t appropriate, you<br />

can probably live with birthday attacks if you’re using SHA1 or better. To protect<br />

against other attacks without using a nonce, see Recipe 6.7.<br />

All hash functions have a compression function as an element. The size to which that<br />

function compresses is the internal block size of the function, and it is usually larger<br />

than the actual digest value. For hash functions based on block ciphers, the internal<br />

block size is the output length of the hash function (and the compression function is<br />

usually built around XOR’ing multiple pieces of block-sized data). Table 6-4 lists the<br />

internal block sizes of common message digest functions not based on block ciphers.<br />

Table 6-4. Internal block sizes of common message digest functions<br />

Algorithm Digest size Internal block size<br />

MD2 128 bits 16 bytes (128 bits)<br />

MD4 128 bits 64 bytes (512 bits)<br />

MD5 128 bits 64 bytes (512 bits)<br />

RIPEMD-160 160 bits 64 bytes (512 bits)<br />

SHA1 160 bits 64 bytes (512 bits)<br />

SHA-256 256 bits 64 bytes (512 bits)<br />

SHA-384 384 bits 128 bytes (1,024 bits)<br />

SHA-512 512 bits 128 bytes (1,024 bits)<br />

Using a Nonce to Protect Against Birthday Attacks | 271<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!