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.

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.<br />

dlen<br />

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

16 bytes. For SHA1 and RIPEMD, it should always be 20 bytes. For the MD5<br />

and SHA1 combination, it should always be 36 bytes.<br />

sig<br />

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

siglen<br />

The number of bytes written into the signature buffer will be placed in the integer<br />

pointed to by this argument. The number of bytes will always be the same<br />

size as the public modulus, which can be determined by calling RSA_size( ) with<br />

the RSA object that will be used to generate the signature.<br />

r<br />

RSA object to be used to generate the signature. The RSA object must contain the<br />

private key for signing.<br />

The high-level interface to RSA signatures is certainly no less complex than computing<br />

the digest and calling RSA_sign( ) yourself. The only advantage of it is that you<br />

can minimize the amount of code you need to change if you would additionally like<br />

to support DSA signatures. If you’re interested in this API, see the book Network<br />

Security with OpenSSL for more information.<br />

Here’s an example of signing an arbitrary message using OpenSSL’s RSA_sign( ) function:<br />

#include <br />

#include <br />

#include <br />

int spc_sign(unsigned char *msg, unsigned int mlen, unsigned char *out,<br />

unsigned int *outlen, RSA *r) {<br />

unsigned char hash[20];<br />

if (!SHA1(msg, mlen, hash)) return 0;<br />

return RSA_sign(NID_sha1, hash, 20, out, outlen, r);<br />

}<br />

7.13 Verifying Signed Data Using an RSA Public<br />

Key<br />

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

You have some data, an RSA digital signature of that data, and the public key that<br />

you believe corresponds to the signature. You want to determine whether the signa-<br />

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