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.

BIGNUM *dP, *dQ, *qInv;<br />

} RSA_PRIVATE;<br />

void spc_keypair_from_primes(BIGNUM *p, BIGNUM *q, unsigned long e,<br />

RSA_PUBKEY *pubkey, RSA_PRIVATE *privkey)<br />

{<br />

BN_CTX *x = BN_CTX_new( );<br />

BIGNUM p_minus_1, q_minus_1, one, tmp, bn_e;<br />

pubkey->n = privkey->n = BN_new( );<br />

privkey->d = BN_new( );<br />

pubkey->e = e;<br />

privkey->p = p;<br />

privkey->q = q;<br />

BN_mul(pubkey->n, p, q, x);<br />

BN_init(&p_minus_1);<br />

BN_init(&q_minus_1);<br />

BN_init(&one);<br />

BN_init(&tmp);<br />

BN_init(&bn_e);<br />

BN_set_word(&bn_e, e);<br />

BN_one(&one);<br />

BN_sub(&p_minus_1, p, &one);<br />

BN_sub(&q_minus_1, q, &one);<br />

BN_mul(&tmp, &p_minus_1, &q_minus_1, x);<br />

BN_mod_inverse(privkey->d, &bn_e, &tmp, x);<br />

/* Compute extra values. */<br />

privkey->dP = BN_new( );<br />

privkey->dQ = BN_new( );<br />

privkey->qInv = BN_new( );<br />

BN_mod(privkey->dP, privkey->d, &p_minus_1, x);<br />

BN_mod(privkey->dQ, privkey->d, &q_minus_1, x);<br />

BN_mod_inverse(privkey->qInv, q, p, x);<br />

}<br />

See Also<br />

Recipes 7.1, 7.2, 7.5<br />

7.7 Disentangling the Public and Private Keys<br />

in OpenSSL<br />

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

You are using OpenSSLand have a filled RSA object. You wish to remove the private<br />

parts of the key, leaving only the public key, so that you can serialize the data structure<br />

and send it off to a party who should not have the private information.<br />

Disentangling the Public and Private Keys in OpenSSL | 329<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!