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.

Solution<br />

Remove all elements of the structure except for n and e.<br />

Discussion<br />

OpenSSLlumps the private key and the public key into a single RSA structure. They<br />

do this because the information in the public key is useful to anyone with the private<br />

key. If an entity needs only the public key, you’re supposed to clear out the rest of<br />

the data.<br />

#include <br />

void remove_private_key(RSA *r) {<br />

r->d = r->p = r->q = r->dmp1 = r->dmq1 = r->iqmp = 0;<br />

}<br />

Be sure to deallocate the BIGNUM objects if you’re erasing the last reference to them.<br />

Any party that has the private key should also hold on to the public key.<br />

7.8 Converting Binary Strings to Integers for<br />

Use with RSA<br />

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

You need to encode a string as a number for use with the RSA encryption algorithm.<br />

Solution<br />

Use the standard PKCS #1 method for converting a nonnegative integer to a string of<br />

a specified length. PKCS #1 is the RSA Security standard for encryption with the<br />

RSA encryption algorithm. *<br />

Discussion<br />

The PKCS #1 method for representing binary strings as integers is simple. You simply<br />

treat the binary representation of the string directly as the binary representation<br />

of the number, where the string is considered a list of bytes from most significant to<br />

least significant (big-endian notation).<br />

For example, if you have the binary string “Test”, you would have a number represented<br />

as a list of ASCII values. In decimal, these values are:<br />

84, 101, 115, 116<br />

* For the PKCS #1 specification, see http://www.rsasecurity.com/rsalabs/pkcs/pkcs-1/.<br />

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