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.

kinvp<br />

Pointer to a BIGNUM object, which will receive the precomputed kinv value. If the<br />

BIGNUM object is specified as NULL (in other words, a pointer to NULL is specified), a<br />

new BIGNUM object will be automatically allocated. In general, it’s best to let<br />

OpenSSL allocate the BIGNUM object for you.<br />

rp<br />

Pointer to a BIGNUM object, which will receive the precomputed r value. If the<br />

BIGNUM object is specified as NULL (in other words, a pointer to NULL is specified), a<br />

new BIGNUM object will be automatically allocated. In general, it’s best to let<br />

OpenSSL allocate the BIGNUM object for you.<br />

The two values computed by the call to DSA_sign_setup( ) must then be stored in the<br />

DSA object. DSA_sign_setup( ) does not automatically store the precomputed values in<br />

the DSA object so that a large number of precomputed values may be stored up during<br />

idle cycles and used as needed. Ideally, OpenSSLwould provide an API for storing<br />

the precomputed values in a DSA object without having to directly manipulate the<br />

members of the DSA object, but it doesn’t. The BIGNUM object returned as kinvp must<br />

be assigned to the kinv member of the DSA object, and the BIGNUM object returned as<br />

rp must be assigned to the r member of the DSA object. The next time a signature is<br />

generated with the DSA object, the precomputed values will be used and freed so that<br />

they’re not used again.<br />

Whether or not you’ve performed the precomputation step, generating a signature<br />

with OpenSSLis done in a uniform way by calling DSA_sign( ), which maps directly<br />

to the RSA equivalent (see Recipe 7.12):<br />

int DSA_sign(int md_type, const unsigned char *dgst, int dlen, unsigned char *sig,<br />

unsigned int *siglen, DSA *dsa);<br />

This function has the following arguments:<br />

md_type<br />

OpenSSL-specific identifier for the hash function. It is always ignored because<br />

DSA mandates the use of SHA1. For that reason, you should always specify NID_<br />

sha1, which is defined in the header file openssl/objects.h.<br />

dgst<br />

Buffer containing the digest to be signed. The digest should have been generated<br />

by the algorithm specified by the md_type argument, which for DSA must always<br />

be SHA1.<br />

dlen<br />

Length in bytes of the digest buffer. For SHA1, it should always be 20 bytes.<br />

sig<br />

Buffer into which the generated signature will be placed.<br />

350 | Chapter 7: Public Key Cryptography<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!