あなたはない本当にこのように、あなただけの参照カウントをインクリメントすることができ、キーを複製する必要がある場合:
CRYPTO_add(&your_evp_pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
そうでない場合、何に似て(ほぼ同じ)のアプローチを> @ X-Istenceは以下の言うように、からRe: How to duplicate an EVP_PKEY:
int pkey_rsa_dup(EVP_PKEY *dst_pkey, EVP_PKEY *src_key) {
// Validate underlying key type - Only allow a RSA key
if (src_key->type != EVP_PKEY_RSA)
return -1;
RSA *rsa = EVP_PKEY_get1_RSA(src_key); // Get the underlying RSA key
RSA *dup_rsa = RSAPrivateKey_dup(rsa); // Duplicate the RSA key
RSA_free(rsa); // Decrement reference count
EVP_PKEY_set1_RSA(dst_pkey, dup_rsa); // Set the underlying RSA key in dst_pkey
// EVP_PKEY_set1_RSA also adjusts the other members in dst_pkey
return 0;
}
参考:以下のだろう提案このリファレンススレッドで提案されている方法は、OpenSSLには存在しません(少なくともこのアップデートの日付まで)。
RSA_dupはOpenSSLソースコードのどこにも存在しません。具体的には、同じ電子メールスレッドでは、同じポスターによるフォローアップには次のように書かれています。http://www.mail-archive.com/[email protected]/msg17617.html –
'dst_pkey'のリーク – Orient
@Orientあなたが正しい。ありがとう!私は 'dst_pkey'に対して偽/不要な割り当てをしていました。渡された引数は、事前に割り当てられたpkeyを参照する必要があります。 i2d/d2i法の場合は+1 – jweyrich