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.

With EME-OAEP padding, the message is padded by a random value output from a<br />

cryptographic one-way hash function. There are two parameters for EME-OAEP<br />

padding: the hash function to use and an additional function used internally by the<br />

padding mechanism. The only internal function in widespread use is called MGF1<br />

and is defined in PKCS #1 v2.0 and later. While any cryptographic one-way hash<br />

algorithm can be used with EME-OAEP padding, many implementations are hardwired<br />

to use SHA1. Generally, you should decide which hash algorithm to use based<br />

on the level of security you need overall in your application, assuming that hash<br />

functions give you half their output length in security. That is, if you’re comfortable<br />

with 80 bits of security (which we believe you should be for the foreseeable future),<br />

SHA1 is sufficient. If you’re feeling conservative, use SHA-256, SHA-384, or SHA-<br />

512 instead.<br />

When using EME-OAEP padding, if k is the number of bytes in your public RSA<br />

modulus, and if h is the number of bytes output by the hash function you choose, the<br />

maximum message length you can encrypt is k -(2h + 2) bytes. For example, if<br />

you’re using 2,048-bit RSA and SHA1, then k = 2,048 / 8 and h = 20. Therefore, you<br />

can encrypt up to 214 bytes. With OpenSSL, specifying EME-OAEP padding forces<br />

the use of SHA1.<br />

Do not use PKCS #1 v1.5 public key padding for any purpose other than encrypting<br />

session keys or hash values. This form of padding can encrypt messages up to 11<br />

bytes smaller than the modulus size in bytes. For example, if you’re using 2,048-bit<br />

RSA, you can encrypt 245-byte messages.<br />

With OpenSSL, encryption with RSA can be done using the function RSA_public_<br />

encrypt( ):<br />

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

This function has the following arguments:<br />

l<br />

pt<br />

ct<br />

r<br />

p<br />

Length of the plaintext to be encrypted.<br />

Buffer that contains the plaintext data to be encrypted.<br />

Buffer into which the resulting ciphertext data will be placed. The size of the<br />

buffer must be equal to the size in bytes of the public modulus. This value can be<br />

obtained by passing the RSA object to RSA_size( ).<br />

RSA object containing the public key to be used to encrypt the plaintext data. The<br />

public modulus (n) and the public exponent (e) must be filled in, but everything<br />

else may be absent.<br />

Type of padding to use.<br />

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