Greetings!


I have been searching the OpenSSL headers for a copy function, which 
would take a const pointer to a rsa_st structure and return another 
pointer to a copy of it, but have not found any. My question is why 
isn't there such a function? Are there any "tricks" in the copying 
process of the mentioned struct? I wrote a function which reads:


RSA* RsaKeyCopy (const RSA* CopyKey)
{
     //  Allocate memory
     RSA*    retValue = RSA_new();

     //  The method pointer is copied as a reference, the rest will be 
copied
     //  by value.
     retValue->pad = CopyKey->pad;
        retValue->version = CopyKey->version;
        retValue->meth = CopyKey->meth;
        if (!BN_copy(retValue->n, CopyKey->n))
         return NULL;
        if (!BN_copy(retValue->e, CopyKey->e))
         return NULL;
        if (!BN_copy(retValue->d, CopyKey->d))
         return NULL;
        if (!BN_copy(retValue->p, CopyKey->p))
         return NULL;
        if (!BN_copy(retValue->q, CopyKey->q))
         return NULL;
        if (!BN_copy(retValue->e, CopyKey->e))
         return NULL;
        if (!BN_copy(retValue->dmp1, CopyKey->dmp1))
         return NULL;
        if (!BN_copy(retValue->dmq1, CopyKey->dmq1))
         return NULL;
        if (!BN_copy(retValue->iqmp, CopyKey->iqmp))
         return NULL;
     retValue->references = CopyKey->references;
        retValue->flags = CopyKey->flags;

     retValue->bignum_data = NULL;

     //  These are cache values copied only to avoid possible trouble.
     BN_MONT_CTX_copy(retValue->_method_mod_n, CopyKey->_method_mod_n);
     BN_MONT_CTX_copy(retValue->_method_mod_p, CopyKey->_method_mod_p);
     BN_MONT_CTX_copy(retValue->_method_mod_q, CopyKey->_method_mod_q);

     //  Copy the BN_BLINDING field
     retValue->blinding->init = CopyKey->blinding->init;
        if (!BN_copy(retValue->blinding->A, CopyKey->blinding->A))
         return NULL;
        if (!BN_copy(retValue->blinding->Ai, CopyKey->blinding->Ai))
         return NULL;
        if (!BN_copy(retValue->blinding->mod, CopyKey->blinding->mod))
         return NULL;

     //  The CRYPTO_EX_DATA ex_data includes a stack, which will not be 
copied
     //  here (and let's hope OpenSSL does the trick without it.)

     return retValue;
}


My question is whether this should do a copy of the struct, or if there 
is something (important) missing.

Thanks in advance for the help!

_____________________________________________________________
Federico Sauter                         [EMAIL PROTECTED]
Software Entwicklung                    Tel: +49 89 7465 4778
TESIS Sysware GmbH                      Fax: +49 89 7465 4788
Implerstraße 26 * D-81371 München * Deutschland
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to