diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/d2i_pr.c')
-rw-r--r-- | src/lib/libcrypto/asn1/d2i_pr.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c index f3d1aa6240..c92b8325d8 100644 --- a/src/lib/libcrypto/asn1/d2i_pr.c +++ b/src/lib/libcrypto/asn1/d2i_pr.c | |||
@@ -112,3 +112,26 @@ err: | |||
112 | return(NULL); | 112 | return(NULL); |
113 | } | 113 | } |
114 | 114 | ||
115 | /* This works like d2i_PrivateKey() except it automatically works out the type */ | ||
116 | |||
117 | EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp, | ||
118 | long length) | ||
119 | { | ||
120 | STACK_OF(ASN1_TYPE) *inkey; | ||
121 | unsigned char *p; | ||
122 | int keytype; | ||
123 | p = *pp; | ||
124 | /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): | ||
125 | * by analyzing it we can determine the passed structure: this | ||
126 | * assumes the input is surrounded by an ASN1 SEQUENCE. | ||
127 | */ | ||
128 | inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE, | ||
129 | ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); | ||
130 | /* Since we only need to discern "traditional format" RSA and DSA | ||
131 | * keys we can just count the elements. | ||
132 | */ | ||
133 | if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA; | ||
134 | else keytype = EVP_PKEY_RSA; | ||
135 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | ||
136 | return d2i_PrivateKey(keytype, a, pp, length); | ||
137 | } | ||