summaryrefslogtreecommitdiffstats
path: root/crypto/rsa/rsa_ameth.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2006-03-23 19:02:23 +0100
committerDr. Stephen Henson <steve@openssl.org>2006-03-23 19:02:23 +0100
commite42633140e98c7c07a5bc013127e1e6a251995ed (patch)
tree512218e4d8b50fb52630ce69ee534a485e3fbb76 /crypto/rsa/rsa_ameth.c
parentTypo. (diff)
downloadopenssl-e42633140e98c7c07a5bc013127e1e6a251995ed.tar.xz
openssl-e42633140e98c7c07a5bc013127e1e6a251995ed.zip
Add support for legacy PEM format private keys in EVP_PKEY_ASN1_METHOD.
Diffstat (limited to '')
-rw-r--r--crypto/rsa/rsa_ameth.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c
index 0b3a9d057d..905719310c 100644
--- a/crypto/rsa/rsa_ameth.c
+++ b/crypto/rsa/rsa_ameth.c
@@ -101,22 +101,24 @@ static int rsa_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
return 1;
}
-static int rsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
+static int old_rsa_priv_decode(EVP_PKEY *pkey,
+ const unsigned char **pder, int derlen)
{
- const unsigned char *p;
- int pklen;
- RSA *rsa = NULL;
- if (!PKCS8_pkey_get0(NULL, &p, &pklen, NULL, p8))
- return 0;
- if (!(rsa = d2i_RSAPrivateKey (NULL, &p, pklen)))
+ RSA *rsa;
+ if (!(rsa = d2i_RSAPrivateKey (NULL, pder, derlen)))
{
RSAerr(RSA_F_RSA_PRIV_DECODE, ERR_R_RSA_LIB);
return 0;
}
- EVP_PKEY_assign_RSA (pkey, rsa);
+ EVP_PKEY_assign_RSA(pkey, rsa);
return 1;
}
+static int old_rsa_priv_encode(const EVP_PKEY *pkey, unsigned char **pder)
+ {
+ return i2d_RSAPrivateKey(pkey->pkey.rsa, pder);
+ }
+
static int rsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
{
unsigned char *rk = NULL;
@@ -139,6 +141,15 @@ static int rsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
return 1;
}
+static int rsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
+ {
+ const unsigned char *p;
+ int pklen;
+ if (!PKCS8_pkey_get0(NULL, &p, &pklen, NULL, p8))
+ return 0;
+ return old_rsa_priv_decode(pkey, &p, pklen);
+ }
+
static int int_rsa_size(const EVP_PKEY *pkey)
{
return RSA_size(pkey->pkey.rsa);
@@ -256,7 +267,7 @@ const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[] =
EVP_PKEY_RSA,
0,
- "rsa",
+ "RSA",
"OpenSSL RSA method",
rsa_pub_decode,
@@ -274,7 +285,9 @@ const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[] =
0,0,0,0,0,0,
int_rsa_free,
- 0
+ 0,
+ old_rsa_priv_decode,
+ old_rsa_priv_encode
},
{