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.

BN_CTX *tmp_ctx;<br />

if (!(secret = BN_new( ))) return 0;<br />

if (!(tmp_ctx = BN_CTX_new( ))) {<br />

BN_free(secret);<br />

return 0;<br />

}<br />

if (!BN_mod_exp(secret, received, ctx->private_value, ctx->n, tmp_ctx)) {<br />

BN_CTX_free(tmp_ctx);<br />

BN_free(secret);<br />

return 0;<br />

}<br />

BN_CTX_free(tmp_ctx);<br />

return secret;<br />

}<br />

You can turn the shared secret into a key by converting the BIGNUM object returned by<br />

DH_compute_secret( ) to binary (see Recipe 7.4) and then hashing it with SHA1, as<br />

discussed above.<br />

Traditional Diffie-Hellman is sometimes called ephemeral Diffie-Hellman, because<br />

the algorithm can be seen as generating key pairs for one-time use. There are variants<br />

of Diffie-Hellman that always use the same values for each client. There are<br />

some hidden “gotchas” when doing that, so we don’t particularly recommend it.<br />

However, if you wish to explore it, see RFC 2631 and RFC 2785 for more information.<br />

See Also<br />

• RFC 2631: Diffie-Hellman Key Agreement Method<br />

• RFC 2785: Methods for Avoiding the “Small-Subgroup” Attacks on the Diffie-<br />

Hellman Key Agreement Method for S/MIME<br />

• Recipes 4.11, 7.1, 7.4, 7.5, 7.15, 8.17, 8.18<br />

8.18 Using Diffie-Hellman and DSA Together<br />

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

You want to use Diffie-Hellman for key exchange, and you need some secure way to<br />

authenticate the key agreement to protect against a man-in-the-middle attack.<br />

Solution<br />

Use the station-to-station protocol for two-way authentication. A simple modification<br />

provides one-way authentication. For example, the server may not care to<br />

authenticate the client using public key cryptography.<br />

436 | Chapter 8: Authentication and Key Exchange<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!