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.

Some people like to use a fixed modulus shared across all users. We<br />

don’t recommend that approach, but if you insist on using it, be sure<br />

to read RFCs 2631 and 2785.<br />

Diffie-Hellman requires another parameter g, the “generator,” which is a value that<br />

we’ll be exponentiating. For ease of computation, use either 2 or 5. * Note that not<br />

every {prime, generator} pair will work, and you will need to test the generator to<br />

make sure that it has the mathematical properties that Diffie-Hellman requires.<br />

OpenSSLexpects that 2 or 5 will be used as a generator. To select a prime for the<br />

modulus, you can use the function DH_generate_parameters( ), which has the following<br />

signature:<br />

DH *DH_generate_parameters(int prime_len, int g,<br />

void (*callback)(int, int, void *), void *cb_arg);<br />

This function has the following arguments:<br />

prime_len<br />

Size in bits of the prime number for the modulus (n) to be generated.<br />

g<br />

Generator you want to use. It should be either 2 or 5.<br />

callback<br />

Pointer to a callback function that is passed directly to BN_generate_prime( ), as<br />

discussed in Recipe 7.4. It may be specified as NULL, in which case no progress<br />

will be reported.<br />

cb_arg<br />

Application-specific argument that is passed directly to the callback function, if<br />

one is specified.<br />

The result will be a new DH object containing the generated modulus (n) and generator<br />

(g) parameters. When you’re done with the DH object, free it with the function DH_<br />

free( ).<br />

Once parameters are generated, you need to check to make sure the prime and the<br />

generator will work together properly. In OpenSSL, you can do this with DH_check( ):<br />

int *DH_check(DH *ctx, int *err);<br />

This function has the following arguments:<br />

ctx<br />

Pointer to the Diffie-Hellman context object to check.<br />

* It’s possible (but not recommended) to use a nonprime value for n, in which case you need to compute a<br />

suitable value for g. See the Applied Cryptography for an algorithm.<br />

Using Basic Diffie-Hellman Key Agreement | 433<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!