diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/d2i_pr.c')
-rw-r--r-- | src/lib/libcrypto/asn1/d2i_pr.c | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c index b9eaa9629b..2e7d96af90 100644 --- a/src/lib/libcrypto/asn1/d2i_pr.c +++ b/src/lib/libcrypto/asn1/d2i_pr.c | |||
@@ -58,16 +58,19 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "bn.h" | 61 | #include <openssl/bn.h> |
62 | #include "evp.h" | 62 | #include <openssl/evp.h> |
63 | #include "objects.h" | 63 | #include <openssl/objects.h> |
64 | #include "x509.h" | 64 | #include <openssl/asn1.h> |
65 | #ifndef OPENSSL_NO_RSA | ||
66 | #include <openssl/rsa.h> | ||
67 | #endif | ||
68 | #ifndef OPENSSL_NO_DSA | ||
69 | #include <openssl/dsa.h> | ||
70 | #endif | ||
65 | 71 | ||
66 | EVP_PKEY *d2i_PrivateKey(type,a,pp,length) | 72 | EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp, |
67 | int type; | 73 | long length) |
68 | EVP_PKEY **a; | ||
69 | unsigned char **pp; | ||
70 | long length; | ||
71 | { | 74 | { |
72 | EVP_PKEY *ret; | 75 | EVP_PKEY *ret; |
73 | 76 | ||
@@ -85,18 +88,20 @@ long length; | |||
85 | ret->type=EVP_PKEY_type(type); | 88 | ret->type=EVP_PKEY_type(type); |
86 | switch (ret->type) | 89 | switch (ret->type) |
87 | { | 90 | { |
88 | #ifndef NO_RSA | 91 | #ifndef OPENSSL_NO_RSA |
89 | case EVP_PKEY_RSA: | 92 | case EVP_PKEY_RSA: |
90 | if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL,pp,length)) == NULL) | 93 | if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL, |
94 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | ||
91 | { | 95 | { |
92 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | 96 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); |
93 | goto err; | 97 | goto err; |
94 | } | 98 | } |
95 | break; | 99 | break; |
96 | #endif | 100 | #endif |
97 | #ifndef NO_DSA | 101 | #ifndef OPENSSL_NO_DSA |
98 | case EVP_PKEY_DSA: | 102 | case EVP_PKEY_DSA: |
99 | if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL,pp,length)) == NULL) | 103 | if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL, |
104 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | ||
100 | { | 105 | { |
101 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | 106 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); |
102 | goto err; | 107 | goto err; |
@@ -106,7 +111,7 @@ long length; | |||
106 | default: | 111 | default: |
107 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | 112 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); |
108 | goto err; | 113 | goto err; |
109 | break; | 114 | /* break; */ |
110 | } | 115 | } |
111 | if (a != NULL) (*a)=ret; | 116 | if (a != NULL) (*a)=ret; |
112 | return(ret); | 117 | return(ret); |
@@ -115,3 +120,26 @@ err: | |||
115 | return(NULL); | 120 | return(NULL); |
116 | } | 121 | } |
117 | 122 | ||
123 | /* This works like d2i_PrivateKey() except it automatically works out the type */ | ||
124 | |||
125 | EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp, | ||
126 | long length) | ||
127 | { | ||
128 | STACK_OF(ASN1_TYPE) *inkey; | ||
129 | unsigned char *p; | ||
130 | int keytype; | ||
131 | p = *pp; | ||
132 | /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): | ||
133 | * by analyzing it we can determine the passed structure: this | ||
134 | * assumes the input is surrounded by an ASN1 SEQUENCE. | ||
135 | */ | ||
136 | inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE, | ||
137 | ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); | ||
138 | /* Since we only need to discern "traditional format" RSA and DSA | ||
139 | * keys we can just count the elements. | ||
140 | */ | ||
141 | if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA; | ||
142 | else keytype = EVP_PKEY_RSA; | ||
143 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | ||
144 | return d2i_PrivateKey(keytype, a, pp, length); | ||
145 | } | ||