"Hellan,Kim KHE" wrote:
> 
> I'm wrapping some OpenSSL functionality into C++ classes, and I have run
> into a slight problem.
> I need to duplicate an EVP_PKEY. Is that possible?
> There is an X509_dup(), but there is no EVP_PKEY_dup().
> 
> I checked the mailing archives and 2000-02-12 (in OpenSSL-Users), Dr. Henson
> answered the exact same question. At that time his answer was:
> 
> "Hmm no EVP_PKEY_dup() function? Thats an omission which will be fixed.
> Steve."
> 
> Was it ever fixed, or is there a reason why this was dropped?
> 
> If anyone has the code to "manually" duplicate an EVP_PKEY, I'd really
> appreciate if you would share it.
> 

Ooops, I forgot about that.

There are two solutions. If you don't mind the structure being shared
then you can just up its reference count with:

CRYPTO_add(&key->references,1,CRYPTO_LOCK_EVP_PKEY);

Alternatively you do something like...

dupkey = EVP_PKEY_new();

switch(key->type)
{
        case EVP_PKEY_RSA:
        rsa = EVP_PKEY_get1_RSA(key);
        duprsa = RSA_dup(rsa);
        RSA_free(rsa);
        EVP_PKEY_set1_RSA(dupkey, duprsa);
        RSA_free(duprsa);
        break;

        ....
}

and similarly for DSA and DH key types. There'd also be some error
checking.

Steve.
-- 
Dr Stephen N. Henson.   http://www.drh-consultancy.demon.co.uk/
Personal Email: [EMAIL PROTECTED] 
Senior crypto engineer, Celo Communications: http://www.celocom.com/
Core developer of the   OpenSSL project: http://www.openssl.org/
Business Email: [EMAIL PROTECTED] PGP key: via homepage.


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to