Federico,
You can either encode and decode CopyKey (i.e., call i2d followed by d2i) or increment the rsa_st's references element using CRYPTO_add. For example: CRYPTO_add (&CopyKey->references, 1, CRYPTO_LOCK_RSA); See crypto/threads/mttest.c for setting up mutexes for a multithreaded application. Frank ---------------------------------------- Message History ---------------------------------------- From: Federico Sauter <[EMAIL PROTECTED]>@openssl.org on 06/04/2002 04:17 PM ZE2 Please respond to [EMAIL PROTECTED] DELEGATED - Sent by: [EMAIL PROTECTED] To: [EMAIL PROTECTED] cc: Subject: rsa_st copy function 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] -- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List [EMAIL PROTECTED] Automated List Manager [EMAIL PROTECTED]