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.

This function has the following arguments:<br />

md_type<br />

OpenSSL-specific identifier for the hash function. Possible values are NID_sha1,<br />

NID_ripemd, orNID_md5. A fourth value, NID_md5_sha1, can be used to combine<br />

MD5 and SHA1 by hashing with both hash functions and concatenating the<br />

results. These four constants are defined in the header file openssl/objects.h.<br />

dgst<br />

Buffer containing the digest of the data whose signature is to be verified. The<br />

digest should have been generated by the algorithm specified by the md_type<br />

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 containing the signature that is to be verified.<br />

siglen<br />

Number of bytes contained in the signature buffer. The number of bytes should<br />

always be the same size as the public modulus, which can be determined by calling<br />

RSA_size( ) with the RSA object that will be used to verify the signature.<br />

r<br />

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

signer’s public key for verification to be successful.<br />

As we discussed in Recipe 7.12, OpenSSLRSA signatures only support PKCS #1 v1.5<br />

and do not support RSASSA-PSS.<br />

Here’s code that implements verification on an arbitrary message, given a signature<br />

and the public RSA key of the signer:<br />

#include <br />

#include <br />

#include <br />

#include <br />

int spc_verify(unsigned char *msg, unsigned int mlen, unsigned char *sig,<br />

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

unsigned char hash[20];<br />

BN_CTX *c;<br />

int ret;<br />

if (!(c = BN_CTX_new( ))) return 0;<br />

if (!SHA1(msg, mlen, hash) || !RSA_blinding_on(r, c)) {<br />

BN_CTX_free(c);<br />

return 0;<br />

}<br />

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