summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/d2i_pr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/d2i_pr.c')
-rw-r--r--src/lib/libcrypto/asn1/d2i_pr.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c
index 2e7d96af90..207ccda5ac 100644
--- a/src/lib/libcrypto/asn1/d2i_pr.c
+++ b/src/lib/libcrypto/asn1/d2i_pr.c
@@ -68,8 +68,11 @@
68#ifndef OPENSSL_NO_DSA 68#ifndef OPENSSL_NO_DSA
69#include <openssl/dsa.h> 69#include <openssl/dsa.h>
70#endif 70#endif
71#ifndef OPENSSL_NO_EC
72#include <openssl/ec.h>
73#endif
71 74
72EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp, 75EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
73 long length) 76 long length)
74 { 77 {
75 EVP_PKEY *ret; 78 EVP_PKEY *ret;
@@ -108,6 +111,16 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp,
108 } 111 }
109 break; 112 break;
110#endif 113#endif
114#ifndef OPENSSL_NO_EC
115 case EVP_PKEY_EC:
116 if ((ret->pkey.ec = d2i_ECPrivateKey(NULL,
117 (const unsigned char **)pp, length)) == NULL)
118 {
119 ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_ASN1_LIB);
120 goto err;
121 }
122 break;
123#endif
111 default: 124 default:
112 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); 125 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
113 goto err; 126 goto err;
@@ -122,11 +135,11 @@ err:
122 135
123/* This works like d2i_PrivateKey() except it automatically works out the type */ 136/* This works like d2i_PrivateKey() except it automatically works out the type */
124 137
125EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp, 138EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
126 long length) 139 long length)
127{ 140{
128 STACK_OF(ASN1_TYPE) *inkey; 141 STACK_OF(ASN1_TYPE) *inkey;
129 unsigned char *p; 142 const unsigned char *p;
130 int keytype; 143 int keytype;
131 p = *pp; 144 p = *pp;
132 /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): 145 /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE):
@@ -138,7 +151,10 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
138 /* Since we only need to discern "traditional format" RSA and DSA 151 /* Since we only need to discern "traditional format" RSA and DSA
139 * keys we can just count the elements. 152 * keys we can just count the elements.
140 */ 153 */
141 if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA; 154 if(sk_ASN1_TYPE_num(inkey) == 6)
155 keytype = EVP_PKEY_DSA;
156 else if (sk_ASN1_TYPE_num(inkey) == 4)
157 keytype = EVP_PKEY_EC;
142 else keytype = EVP_PKEY_RSA; 158 else keytype = EVP_PKEY_RSA;
143 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); 159 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
144 return d2i_PrivateKey(keytype, a, pp, length); 160 return d2i_PrivateKey(keytype, a, pp, length);