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.

When using OpenSSL, decryption can be done with the RSA_private_decrypt( ) function,<br />

defined in openssl/rsa.h and shown below. It will return the length of the<br />

decrypted string, or –1 if an error occurs.<br />

int RSA_private_decrypt(int l, unsigned char *ct, unsigned char *pt, RSA *r, int p);<br />

This function has the following arguments:<br />

l<br />

ct<br />

pt<br />

r<br />

p<br />

Length in bytes of the ciphertext to be decrypted, which must be equal to the<br />

size in bytes of the public modulus. This value can be obtained by passing the<br />

RSA object to RSA_size( ).<br />

Buffer containing the ciphertext to be decrypted.<br />

Buffer into which the plaintext will be written. The size of this buffer must be at<br />

least RSA_size(r) bytes.<br />

RSA object containing the private key to be used to decrypt the ciphertext.<br />

Type of padding that was used when encrypting. The defined constants for padding<br />

types are enumerated in Recipe 7.10.<br />

Some implementations of RSA decryption are susceptible to timing attacks. Basically,<br />

if RSA decryption operations do not happen in a fixed amount of time, such<br />

attacks may be a possibility. A technique called blinding can thwart timing attacks.<br />

The amount of time it takes to decrypt is randomized somewhat by operating on a<br />

random number in the process. To eliminate the possibility of such attacks, you<br />

should always turn blinding on before doing a decryption operation. To thwart<br />

blinding attacks in OpenSSL, you can use the RSA_blinding_on( ) function, which has<br />

the following signature:<br />

int RSA_blinding_on(RSA *r, BN_CTX *x);<br />

This function has the following arguments:<br />

r<br />

x<br />

RSA object for which blinding should be enabled.<br />

BN_CTX object that will be used by the blinding operations as scratch space (see<br />

Recipe 7.4 for a discussion of BN_CTX objects). It may be specified as NULL, in<br />

which case a new one will be allocated and used internally.<br />

See Also<br />

Recipes 7.1, 7.2, 7.4, 7.10<br />

Performing Raw Decryption Using an RSA Private Key | 337<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!