Why not just copy the key?

EVP_PKEY *cp_key (EVP_PKEY *pkey) {

 /* error handling omittet */
   EVP_PKEY *pnew;
   int key_type;

   pnew = EVP_PKEY_new();
   switch(pkey->type) {
      case EVP_PKEY_RSA:
           DSA *dsa = EVP_PKEY_get1_DSA(pkey);
           EVP_PKEY_set1_DSA(pnew, dsa);
           break;
      case EVP_PKEY_DSA:
           RSA *rsa = EVP_PKEY_get1_RSA(pkey);
           EVP_PKEY_set1_RSA(pnew, rsa);
           break;
      case EVP_PKEY_DH:
           DH *dh = EVP_PKEY_get1_DH(pkey);
           EVP_PKEY_set1_DH(pnew, dh);
           break;
      case EVP_PKEY_EC:
           EC_KEY *ec = EVP_PKEY_get1_EC(pkey);
           EVP_PKEY_set1_EC(pnew, ec);
           break;

     default:
          fprintf(stderr, "unknown key type %.\n", pkey->type);
  }

  return pnew;
}

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

Reply via email to