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.

For example, here’s a wrapper for the all-in-one SHA1 interface discussed in Recipe 6.6:<br />

#define SPC_SHA1_DGST_LEN (20)<br />

/* Include anything else you need. */<br />

void spc_extended_sha1(unsigned char *message, unsigned long n,unsigned char *md) {<br />

unsigned char tmp[SPC_SHA1_DGST_LEN];<br />

SHA1(message, n, tmp);<br />

SHA1(tmp, sizeof(tmp), md);<br />

}<br />

Note that this solution does not protect against birthday attacks. When using SHA1,<br />

birthday attacks are generally considered totally impractical. However, to be conservative,<br />

you can use a nonce to protect against such attacks, as discussed in Recipe 6.8.<br />

See Also<br />

Recipes 6.6, 6.8<br />

6.8 Using a Nonce to Protect Against Birthday<br />

Attacks<br />

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

You want to harden a hash function against birthday attacks instead of switching to<br />

an algorithm with a longer digest.<br />

Solution<br />

Use a nonce or salt before and after your message (preferably a securely generated<br />

random salt), padding the nonce to the internal block size of the hash function.<br />

Discussion<br />

Hash functions are not secure by themselves—not for a password system,<br />

not for message authentication, not for anything! If you do need a<br />

hash function by itself, be sure to at least protect against length extension<br />

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

In most cases, when using a nonce or salt with a hash function, where the nonce is as<br />

large as the output length of the hash function, you double the effective strength of<br />

the hash function in circumstances where a birthday attack would apply. Even<br />

smaller nonces help improve security.<br />

270 | 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!