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.

err<br />

Pointer to an integer to which is written an indication of any error that occurs.<br />

This function returns 1 even if the parameters are bad. The 0 return value indicates<br />

that the generator is not 2 or 5, as OpenSSLis not capable of checking parameter sets<br />

that include other generators. Any error is always passed through the err parameter.<br />

The errors are as follows:<br />

H_CHECK_P_NOT_SAFE_PRIME<br />

DH_NOT_SUITABLE_GENERATOR<br />

DH_UNABLE_TO_CHECK_GENERATOR<br />

The first two errors can occur at the same time, in which case the value pointed to by<br />

err will be the logical OR of both constants.<br />

Once both sides have the same parameters, they can send each other a message;<br />

each then computes the shared secret. If the client initiates the connection, the client<br />

chooses a random value x, where x is less than n. The client computes A = gx mod n,<br />

then sends A to the server. The server chooses a random value y, where y is less than<br />

n. The server computes B = gy mod n, then sends B to the client.<br />

The server calculates the shared secret by computing k =A y mod n. The client calculates<br />

the same secret by computing B x mod n.<br />

Generating the message to send with OpenSSLis done with a call to the function DH_<br />

generate_key( ):<br />

int DH_generate_key(DH *ctx);<br />

The function returns 1 on success. The value to send to the other party is stored in<br />

ctx->pub_key.<br />

Once one side receives the public value from the other, it can generate the shared<br />

secret with the function DH_compute_key( ):<br />

int DH_compute_key(unsigned char *secret, BIGNUM *pub_value, DH *dh);<br />

This function has the following arguments:<br />

secret<br />

Buffer into which the resulting secret will be written, which must be large<br />

enough to hold the secret. The size of the secret can be determined with a call to<br />

DH_size(dh).<br />

pub_value<br />

Public value received from the other party.<br />

dh<br />

DH object containing the parameters and public key.<br />

Once both sides have agreed on a secret, it generally needs to be turned into some<br />

sort of fixed-size key, or a set of fixed-size keys. A reasonable way is to represent the<br />

secret in binary and cryptographically hash the binary value, truncating if necessary.<br />

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