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.

memcpy(signedtext, decrypt, 16);<br />

if (!BN_bn2bin(recip_key->n, signedtext + 16)) goto err;<br />

if (!BN_bn2bin(recip_key->e, signedtext + 16 + RSA_size(recip_key))) goto err;<br />

if (!SHA1(signedtext, stlen, hash)) goto err;<br />

if (!RSA_verify(NID_sha1, hash, 20, decrypt + 16, RSA_size(signers_pub_key),<br />

signers_pub_key)) goto err;<br />

memcpy(secret, decrypt, 16);<br />

result = 1;<br />

err:<br />

RSA_blinding_off(recip_key);<br />

BN_CTX_free(tctx);<br />

free(decrypt);<br />

if (signedtext) free(signedtext);<br />

return result;<br />

}<br />

See Also<br />

Recipes 7.1, 7.16, 7.17<br />

7.15 Using the Digital Signature Algorithm (DSA)<br />

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

You want to perform public key–based digital signatures, and you have a requirement<br />

necessitating the use of DSA.<br />

Solution<br />

Use an existing cryptographic library’s implementation of DSA.<br />

Discussion<br />

DSA and Diffie-Hellman are both based on the same math problem. DSA only provides<br />

digital signatures; it does not do key agreement or general-purpose encryption.<br />

Unlike Diffie-Hellman, the construction is quite a bit more complex. For that reason,<br />

we recommend using an existing implementation. If you must implement it<br />

yourself, obtain the standard available from the NIST web site (http://www.nist.gov).<br />

With DSA, the private key is used to sign arbitrary data. As is traditionally done with<br />

RSA signatures, the data is actually hashed before it’s signed. The DSA standard<br />

mandates the use of SHA1 as the hash function.<br />

Anyone who has the DSA public key corresponding to the key used to sign a piece of<br />

data can validate signatures. DSA signatures are most useful for authentication during<br />

key agreement and for non-repudiation. We discuss how to perform authentica-<br />

Using the Digital Signature Algorithm (DSA) | 347<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!