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.

ecommend using it, unless you are concerned about interoperating with a legacy<br />

application. Otherwise, there is nothing wrong with RSASSA-PKCS1v1.5.<br />

Both schemes should have a similar interface in a cryptographic library supporting<br />

RSA. That is, signing should take the following parameters:<br />

• The signer’s private key.<br />

• The message to be signed. In a low-level API, instead of the actual message, you<br />

will be expected to provide a hash digest of the data you really want to be signing.<br />

High-level APIs will do the message digest operation for you.<br />

• An indication of which message digest algorithm was used in the signing. This<br />

may be assumed for you in a high-level API (in which case it will probably be<br />

SHA1).<br />

RSASSA-PKCS1v1.5 encodes the message digest value into its result to avoid certain<br />

classes of attack. RSASSA-PSS does no such encoding, but it uses a hash function<br />

internally, and that function should generally be the same one used to create the<br />

digest to be signed.<br />

You may or may not need to give an indication of the length of the input message<br />

digest. The value can be deduced easily if the API enforces that the input should be a<br />

message digest value. Similarly, the API may output the signature size, even though it<br />

is a well-known value (the same size as the public RSA modulus—for example, 2,048<br />

bits in 2,048-bit RSA).<br />

OpenSSLsupports RSASSA-PKCS1v1.5 only for digital signatures. It<br />

does support raw encrypting with the private key, which you can use<br />

to implement RSASSA-PSS. However, we don’t generally recommend<br />

this, and you certainly should not use the raw interface (RSA_private_<br />

encrypt( )) for any other purpose whatsoever.<br />

In OpenSSL, we recommend always using the low-level interface to RSA signing,<br />

using the function RSA_sign( ) to perform signatures when you’ve already calculated<br />

the appropriate hash. The signature, defined in openssl/rsa.h, is:<br />

int RSA_sign(int md_type, unsigned char *dgst, unsigned int dlen,<br />

unsigned char *sig, unsigned int *siglen, RSA *r);<br />

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

Signing Data Using an RSA Private Key | 339<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!