diff options
| author | jsing <> | 2014-05-07 17:42:51 +0000 |
|---|---|---|
| committer | jsing <> | 2014-05-07 17:42:51 +0000 |
| commit | 809e924b0ceda14722deaae701cea2d9ca6d9ff4 (patch) | |
| tree | b341b2cdc0818410f55d0a4662a40677e4899326 /src/lib/libcrypto/evp/p_lib.c | |
| parent | 4dbedfb705d406cb1f725088db285d6642ca988a (diff) | |
| download | openbsd-809e924b0ceda14722deaae701cea2d9ca6d9ff4.tar.gz openbsd-809e924b0ceda14722deaae701cea2d9ca6d9ff4.tar.bz2 openbsd-809e924b0ceda14722deaae701cea2d9ca6d9ff4.zip | |
KNF.
Diffstat (limited to 'src/lib/libcrypto/evp/p_lib.c')
| -rw-r--r-- | src/lib/libcrypto/evp/p_lib.c | 351 |
1 files changed, 186 insertions, 165 deletions
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c index 5f5f5e328d..97d922d1ba 100644 --- a/src/lib/libcrypto/evp/p_lib.c +++ b/src/lib/libcrypto/evp/p_lib.c | |||
| @@ -5,21 +5,21 @@ | |||
| 5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
| 6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
| 7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
| 8 | * | 8 | * |
| 9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
| 10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 15 | * | 15 | * |
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
| 18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
| 19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
| 20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
| 21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
| 22 | * | 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
| 25 | * are met: | 25 | * are met: |
| @@ -34,10 +34,10 @@ | |||
| 34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
| 36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 40 | * | 40 | * |
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -49,7 +49,7 @@ | |||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
| 52 | * | 52 | * |
| 53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
| @@ -82,134 +82,138 @@ | |||
| 82 | 82 | ||
| 83 | static void EVP_PKEY_free_it(EVP_PKEY *x); | 83 | static void EVP_PKEY_free_it(EVP_PKEY *x); |
| 84 | 84 | ||
| 85 | int EVP_PKEY_bits(EVP_PKEY *pkey) | 85 | int |
| 86 | { | 86 | EVP_PKEY_bits(EVP_PKEY *pkey) |
| 87 | { | ||
| 87 | if (pkey && pkey->ameth && pkey->ameth->pkey_bits) | 88 | if (pkey && pkey->ameth && pkey->ameth->pkey_bits) |
| 88 | return pkey->ameth->pkey_bits(pkey); | 89 | return pkey->ameth->pkey_bits(pkey); |
| 89 | return 0; | 90 | return 0; |
| 90 | } | 91 | } |
| 91 | 92 | ||
| 92 | int EVP_PKEY_size(EVP_PKEY *pkey) | 93 | int |
| 93 | { | 94 | EVP_PKEY_size(EVP_PKEY *pkey) |
| 95 | { | ||
| 94 | if (pkey && pkey->ameth && pkey->ameth->pkey_size) | 96 | if (pkey && pkey->ameth && pkey->ameth->pkey_size) |
| 95 | return pkey->ameth->pkey_size(pkey); | 97 | return pkey->ameth->pkey_size(pkey); |
| 96 | return 0; | 98 | return 0; |
| 97 | } | 99 | } |
| 98 | 100 | ||
| 99 | int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) | 101 | int |
| 100 | { | 102 | EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) |
| 103 | { | ||
| 101 | #ifndef OPENSSL_NO_DSA | 104 | #ifndef OPENSSL_NO_DSA |
| 102 | if (pkey->type == EVP_PKEY_DSA) | 105 | if (pkey->type == EVP_PKEY_DSA) { |
| 103 | { | 106 | int ret = pkey->save_parameters; |
| 104 | int ret=pkey->save_parameters; | ||
| 105 | 107 | ||
| 106 | if (mode >= 0) | 108 | if (mode >= 0) |
| 107 | pkey->save_parameters=mode; | 109 | pkey->save_parameters = mode; |
| 108 | return(ret); | 110 | return (ret); |
| 109 | } | 111 | } |
| 110 | #endif | 112 | #endif |
| 111 | #ifndef OPENSSL_NO_EC | 113 | #ifndef OPENSSL_NO_EC |
| 112 | if (pkey->type == EVP_PKEY_EC) | 114 | if (pkey->type == EVP_PKEY_EC) { |
| 113 | { | ||
| 114 | int ret = pkey->save_parameters; | 115 | int ret = pkey->save_parameters; |
| 115 | 116 | ||
| 116 | if (mode >= 0) | 117 | if (mode >= 0) |
| 117 | pkey->save_parameters = mode; | 118 | pkey->save_parameters = mode; |
| 118 | return(ret); | 119 | return (ret); |
| 119 | } | ||
| 120 | #endif | ||
| 121 | return(0); | ||
| 122 | } | 120 | } |
| 121 | #endif | ||
| 122 | return (0); | ||
| 123 | } | ||
| 123 | 124 | ||
| 124 | int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) | 125 | int |
| 125 | { | 126 | EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) |
| 126 | if (to->type != from->type) | 127 | { |
| 127 | { | 128 | if (to->type != from->type) { |
| 128 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES); | 129 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, |
| 130 | EVP_R_DIFFERENT_KEY_TYPES); | ||
| 129 | goto err; | 131 | goto err; |
| 130 | } | 132 | } |
| 131 | 133 | ||
| 132 | if (EVP_PKEY_missing_parameters(from)) | 134 | if (EVP_PKEY_missing_parameters(from)) { |
| 133 | { | 135 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, |
| 134 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS); | 136 | EVP_R_MISSING_PARAMETERS); |
| 135 | goto err; | 137 | goto err; |
| 136 | } | 138 | } |
| 137 | if (from->ameth && from->ameth->param_copy) | 139 | if (from->ameth && from->ameth->param_copy) |
| 138 | return from->ameth->param_copy(to, from); | 140 | return from->ameth->param_copy(to, from); |
| 141 | |||
| 139 | err: | 142 | err: |
| 140 | return 0; | 143 | return 0; |
| 141 | } | 144 | } |
| 142 | 145 | ||
| 143 | int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey) | 146 | int |
| 144 | { | 147 | EVP_PKEY_missing_parameters(const EVP_PKEY *pkey) |
| 148 | { | ||
| 145 | if (pkey->ameth && pkey->ameth->param_missing) | 149 | if (pkey->ameth && pkey->ameth->param_missing) |
| 146 | return pkey->ameth->param_missing(pkey); | 150 | return pkey->ameth->param_missing(pkey); |
| 147 | return 0; | 151 | return 0; |
| 148 | } | 152 | } |
| 149 | 153 | ||
| 150 | int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) | 154 | int |
| 151 | { | 155 | EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) |
| 156 | { | ||
| 152 | if (a->type != b->type) | 157 | if (a->type != b->type) |
| 153 | return -1; | 158 | return -1; |
| 154 | if (a->ameth && a->ameth->param_cmp) | 159 | if (a->ameth && a->ameth->param_cmp) |
| 155 | return a->ameth->param_cmp(a, b); | 160 | return a->ameth->param_cmp(a, b); |
| 156 | return -2; | 161 | return -2; |
| 157 | } | 162 | } |
| 158 | 163 | ||
| 159 | int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b) | 164 | int |
| 160 | { | 165 | EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b) |
| 166 | { | ||
| 161 | if (a->type != b->type) | 167 | if (a->type != b->type) |
| 162 | return -1; | 168 | return -1; |
| 163 | 169 | ||
| 164 | if (a->ameth) | 170 | if (a->ameth) { |
| 165 | { | ||
| 166 | int ret; | 171 | int ret; |
| 167 | /* Compare parameters if the algorithm has them */ | 172 | /* Compare parameters if the algorithm has them */ |
| 168 | if (a->ameth->param_cmp) | 173 | if (a->ameth->param_cmp) { |
| 169 | { | ||
| 170 | ret = a->ameth->param_cmp(a, b); | 174 | ret = a->ameth->param_cmp(a, b); |
| 171 | if (ret <= 0) | 175 | if (ret <= 0) |
| 172 | return ret; | 176 | return ret; |
| 173 | } | 177 | } |
| 174 | 178 | ||
| 175 | if (a->ameth->pub_cmp) | 179 | if (a->ameth->pub_cmp) |
| 176 | return a->ameth->pub_cmp(a, b); | 180 | return a->ameth->pub_cmp(a, b); |
| 177 | } | 181 | } |
| 178 | 182 | ||
| 179 | return -2; | 183 | return -2; |
| 180 | } | 184 | } |
| 181 | 185 | ||
| 182 | EVP_PKEY *EVP_PKEY_new(void) | 186 | EVP_PKEY * |
| 183 | { | 187 | EVP_PKEY_new(void) |
| 188 | { | ||
| 184 | EVP_PKEY *ret; | 189 | EVP_PKEY *ret; |
| 185 | 190 | ||
| 186 | ret=(EVP_PKEY *)malloc(sizeof(EVP_PKEY)); | 191 | ret = (EVP_PKEY *)malloc(sizeof(EVP_PKEY)); |
| 187 | if (ret == NULL) | 192 | if (ret == NULL) { |
| 188 | { | 193 | EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE); |
| 189 | EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE); | 194 | return (NULL); |
| 190 | return(NULL); | ||
| 191 | } | ||
| 192 | ret->type=EVP_PKEY_NONE; | ||
| 193 | ret->save_type=EVP_PKEY_NONE; | ||
| 194 | ret->references=1; | ||
| 195 | ret->ameth=NULL; | ||
| 196 | ret->engine=NULL; | ||
| 197 | ret->pkey.ptr=NULL; | ||
| 198 | ret->attributes=NULL; | ||
| 199 | ret->save_parameters=1; | ||
| 200 | return(ret); | ||
| 201 | } | 195 | } |
| 196 | ret->type = EVP_PKEY_NONE; | ||
| 197 | ret->save_type = EVP_PKEY_NONE; | ||
| 198 | ret->references = 1; | ||
| 199 | ret->ameth = NULL; | ||
| 200 | ret->engine = NULL; | ||
| 201 | ret->pkey.ptr = NULL; | ||
| 202 | ret->attributes = NULL; | ||
| 203 | ret->save_parameters = 1; | ||
| 204 | return (ret); | ||
| 205 | } | ||
| 202 | 206 | ||
| 203 | /* Setup a public key ASN1 method and ENGINE from a NID or a string. | 207 | /* Setup a public key ASN1 method and ENGINE from a NID or a string. |
| 204 | * If pkey is NULL just return 1 or 0 if the algorithm exists. | 208 | * If pkey is NULL just return 1 or 0 if the algorithm exists. |
| 205 | */ | 209 | */ |
| 206 | 210 | ||
| 207 | static int pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len) | 211 | static int |
| 208 | { | 212 | pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len) |
| 213 | { | ||
| 209 | const EVP_PKEY_ASN1_METHOD *ameth; | 214 | const EVP_PKEY_ASN1_METHOD *ameth; |
| 210 | ENGINE *e = NULL; | 215 | ENGINE *e = NULL; |
| 211 | if (pkey) | 216 | if (pkey) { |
| 212 | { | ||
| 213 | if (pkey->pkey.ptr) | 217 | if (pkey->pkey.ptr) |
| 214 | EVP_PKEY_free_it(pkey); | 218 | EVP_PKEY_free_it(pkey); |
| 215 | /* If key type matches and a method exists then this | 219 | /* If key type matches and a method exists then this |
| @@ -219,13 +223,12 @@ static int pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len) | |||
| 219 | return 1; | 223 | return 1; |
| 220 | #ifndef OPENSSL_NO_ENGINE | 224 | #ifndef OPENSSL_NO_ENGINE |
| 221 | /* If we have an ENGINE release it */ | 225 | /* If we have an ENGINE release it */ |
| 222 | if (pkey->engine) | 226 | if (pkey->engine) { |
| 223 | { | ||
| 224 | ENGINE_finish(pkey->engine); | 227 | ENGINE_finish(pkey->engine); |
| 225 | pkey->engine = NULL; | 228 | pkey->engine = NULL; |
| 226 | } | ||
| 227 | #endif | ||
| 228 | } | 229 | } |
| 230 | #endif | ||
| 231 | } | ||
| 229 | if (str) | 232 | if (str) |
| 230 | ameth = EVP_PKEY_asn1_find_str(&e, str, len); | 233 | ameth = EVP_PKEY_asn1_find_str(&e, str, len); |
| 231 | else | 234 | else |
| @@ -234,57 +237,61 @@ static int pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len) | |||
| 234 | if (!pkey && e) | 237 | if (!pkey && e) |
| 235 | ENGINE_finish(e); | 238 | ENGINE_finish(e); |
| 236 | #endif | 239 | #endif |
| 237 | if (!ameth) | 240 | if (!ameth) { |
| 238 | { | ||
| 239 | EVPerr(EVP_F_PKEY_SET_TYPE, EVP_R_UNSUPPORTED_ALGORITHM); | 241 | EVPerr(EVP_F_PKEY_SET_TYPE, EVP_R_UNSUPPORTED_ALGORITHM); |
| 240 | return 0; | 242 | return 0; |
| 241 | } | 243 | } |
| 242 | if (pkey) | 244 | if (pkey) { |
| 243 | { | ||
| 244 | pkey->ameth = ameth; | 245 | pkey->ameth = ameth; |
| 245 | pkey->engine = e; | 246 | pkey->engine = e; |
| 246 | 247 | ||
| 247 | pkey->type = pkey->ameth->pkey_id; | 248 | pkey->type = pkey->ameth->pkey_id; |
| 248 | pkey->save_type=type; | 249 | pkey->save_type = type; |
| 249 | } | ||
| 250 | return 1; | ||
| 251 | } | 250 | } |
| 251 | return 1; | ||
| 252 | } | ||
| 252 | 253 | ||
| 253 | int EVP_PKEY_set_type(EVP_PKEY *pkey, int type) | 254 | int |
| 254 | { | 255 | EVP_PKEY_set_type(EVP_PKEY *pkey, int type) |
| 256 | { | ||
| 255 | return pkey_set_type(pkey, type, NULL, -1); | 257 | return pkey_set_type(pkey, type, NULL, -1); |
| 256 | } | 258 | } |
| 257 | 259 | ||
| 258 | int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len) | 260 | int |
| 259 | { | 261 | EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len) |
| 262 | { | ||
| 260 | return pkey_set_type(pkey, EVP_PKEY_NONE, str, len); | 263 | return pkey_set_type(pkey, EVP_PKEY_NONE, str, len); |
| 261 | } | 264 | } |
| 262 | 265 | ||
| 263 | int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) | 266 | int |
| 264 | { | 267 | EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) |
| 268 | { | ||
| 265 | if (!EVP_PKEY_set_type(pkey, type)) | 269 | if (!EVP_PKEY_set_type(pkey, type)) |
| 266 | return 0; | 270 | return 0; |
| 267 | pkey->pkey.ptr=key; | 271 | pkey->pkey.ptr = key; |
| 268 | return (key != NULL); | 272 | return (key != NULL); |
| 269 | } | 273 | } |
| 270 | 274 | ||
| 271 | void *EVP_PKEY_get0(EVP_PKEY *pkey) | 275 | void * |
| 272 | { | 276 | EVP_PKEY_get0(EVP_PKEY *pkey) |
| 277 | { | ||
| 273 | return pkey->pkey.ptr; | 278 | return pkey->pkey.ptr; |
| 274 | } | 279 | } |
| 275 | 280 | ||
| 276 | #ifndef OPENSSL_NO_RSA | 281 | #ifndef OPENSSL_NO_RSA |
| 277 | int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key) | 282 | int |
| 283 | EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key) | ||
| 278 | { | 284 | { |
| 279 | int ret = EVP_PKEY_assign_RSA(pkey, key); | 285 | int ret = EVP_PKEY_assign_RSA(pkey, key); |
| 280 | if(ret) | 286 | if (ret) |
| 281 | RSA_up_ref(key); | 287 | RSA_up_ref(key); |
| 282 | return ret; | 288 | return ret; |
| 283 | } | 289 | } |
| 284 | 290 | ||
| 285 | RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey) | 291 | RSA * |
| 286 | { | 292 | EVP_PKEY_get1_RSA(EVP_PKEY *pkey) |
| 287 | if(pkey->type != EVP_PKEY_RSA) { | 293 | { |
| 294 | if (pkey->type != EVP_PKEY_RSA) { | ||
| 288 | EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY); | 295 | EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY); |
| 289 | return NULL; | 296 | return NULL; |
| 290 | } | 297 | } |
| @@ -294,17 +301,19 @@ RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey) | |||
| 294 | #endif | 301 | #endif |
| 295 | 302 | ||
| 296 | #ifndef OPENSSL_NO_DSA | 303 | #ifndef OPENSSL_NO_DSA |
| 297 | int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) | 304 | int |
| 305 | EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) | ||
| 298 | { | 306 | { |
| 299 | int ret = EVP_PKEY_assign_DSA(pkey, key); | 307 | int ret = EVP_PKEY_assign_DSA(pkey, key); |
| 300 | if(ret) | 308 | if (ret) |
| 301 | DSA_up_ref(key); | 309 | DSA_up_ref(key); |
| 302 | return ret; | 310 | return ret; |
| 303 | } | 311 | } |
| 304 | 312 | ||
| 305 | DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey) | 313 | DSA * |
| 306 | { | 314 | EVP_PKEY_get1_DSA(EVP_PKEY *pkey) |
| 307 | if(pkey->type != EVP_PKEY_DSA) { | 315 | { |
| 316 | if (pkey->type != EVP_PKEY_DSA) { | ||
| 308 | EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY); | 317 | EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY); |
| 309 | return NULL; | 318 | return NULL; |
| 310 | } | 319 | } |
| @@ -315,18 +324,19 @@ DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey) | |||
| 315 | 324 | ||
| 316 | #ifndef OPENSSL_NO_EC | 325 | #ifndef OPENSSL_NO_EC |
| 317 | 326 | ||
| 318 | int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) | 327 | int |
| 328 | EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) | ||
| 319 | { | 329 | { |
| 320 | int ret = EVP_PKEY_assign_EC_KEY(pkey,key); | 330 | int ret = EVP_PKEY_assign_EC_KEY(pkey, key); |
| 321 | if (ret) | 331 | if (ret) |
| 322 | EC_KEY_up_ref(key); | 332 | EC_KEY_up_ref(key); |
| 323 | return ret; | 333 | return ret; |
| 324 | } | 334 | } |
| 325 | 335 | ||
| 326 | EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey) | 336 | EC_KEY * |
| 337 | EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey) | ||
| 327 | { | 338 | { |
| 328 | if (pkey->type != EVP_PKEY_EC) | 339 | if (pkey->type != EVP_PKEY_EC) { |
| 329 | { | ||
| 330 | EVPerr(EVP_F_EVP_PKEY_GET1_EC_KEY, EVP_R_EXPECTING_A_EC_KEY); | 340 | EVPerr(EVP_F_EVP_PKEY_GET1_EC_KEY, EVP_R_EXPECTING_A_EC_KEY); |
| 331 | return NULL; | 341 | return NULL; |
| 332 | } | 342 | } |
| @@ -338,17 +348,19 @@ EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey) | |||
| 338 | 348 | ||
| 339 | #ifndef OPENSSL_NO_DH | 349 | #ifndef OPENSSL_NO_DH |
| 340 | 350 | ||
| 341 | int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key) | 351 | int |
| 352 | EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key) | ||
| 342 | { | 353 | { |
| 343 | int ret = EVP_PKEY_assign_DH(pkey, key); | 354 | int ret = EVP_PKEY_assign_DH(pkey, key); |
| 344 | if(ret) | 355 | if (ret) |
| 345 | DH_up_ref(key); | 356 | DH_up_ref(key); |
| 346 | return ret; | 357 | return ret; |
| 347 | } | 358 | } |
| 348 | 359 | ||
| 349 | DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey) | 360 | DH * |
| 350 | { | 361 | EVP_PKEY_get1_DH(EVP_PKEY *pkey) |
| 351 | if(pkey->type != EVP_PKEY_DH) { | 362 | { |
| 363 | if (pkey->type != EVP_PKEY_DH) { | ||
| 352 | EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY); | 364 | EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY); |
| 353 | return NULL; | 365 | return NULL; |
| 354 | } | 366 | } |
| @@ -357,8 +369,9 @@ DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey) | |||
| 357 | } | 369 | } |
| 358 | #endif | 370 | #endif |
| 359 | 371 | ||
| 360 | int EVP_PKEY_type(int type) | 372 | int |
| 361 | { | 373 | EVP_PKEY_type(int type) |
| 374 | { | ||
| 362 | int ret; | 375 | int ret; |
| 363 | const EVP_PKEY_ASN1_METHOD *ameth; | 376 | const EVP_PKEY_ASN1_METHOD *ameth; |
| 364 | ENGINE *e; | 377 | ENGINE *e; |
| @@ -372,89 +385,97 @@ int EVP_PKEY_type(int type) | |||
| 372 | ENGINE_finish(e); | 385 | ENGINE_finish(e); |
| 373 | #endif | 386 | #endif |
| 374 | return ret; | 387 | return ret; |
| 375 | } | 388 | } |
| 376 | 389 | ||
| 377 | int EVP_PKEY_id(const EVP_PKEY *pkey) | 390 | int |
| 378 | { | 391 | EVP_PKEY_id(const EVP_PKEY *pkey) |
| 392 | { | ||
| 379 | return pkey->type; | 393 | return pkey->type; |
| 380 | } | 394 | } |
| 381 | 395 | ||
| 382 | int EVP_PKEY_base_id(const EVP_PKEY *pkey) | 396 | int |
| 383 | { | 397 | EVP_PKEY_base_id(const EVP_PKEY *pkey) |
| 398 | { | ||
| 384 | return EVP_PKEY_type(pkey->type); | 399 | return EVP_PKEY_type(pkey->type); |
| 385 | } | 400 | } |
| 386 | 401 | ||
| 387 | void EVP_PKEY_free(EVP_PKEY *x) | 402 | void |
| 388 | { | 403 | EVP_PKEY_free(EVP_PKEY *x) |
| 404 | { | ||
| 389 | int i; | 405 | int i; |
| 390 | 406 | ||
| 391 | if (x == NULL) return; | 407 | if (x == NULL) |
| 408 | return; | ||
| 392 | 409 | ||
| 393 | i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY); | 410 | i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY); |
| 394 | if (i > 0) return; | 411 | if (i > 0) |
| 412 | return; | ||
| 395 | 413 | ||
| 396 | EVP_PKEY_free_it(x); | 414 | EVP_PKEY_free_it(x); |
| 397 | if (x->attributes) | 415 | if (x->attributes) |
| 398 | sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); | 416 | sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); |
| 399 | free(x); | 417 | free(x); |
| 400 | } | 418 | } |
| 401 | 419 | ||
| 402 | static void EVP_PKEY_free_it(EVP_PKEY *x) | 420 | static void |
| 403 | { | 421 | EVP_PKEY_free_it(EVP_PKEY *x) |
| 404 | if (x->ameth && x->ameth->pkey_free) | 422 | { |
| 405 | { | 423 | if (x->ameth && x->ameth->pkey_free) { |
| 406 | x->ameth->pkey_free(x); | 424 | x->ameth->pkey_free(x); |
| 407 | x->pkey.ptr = NULL; | 425 | x->pkey.ptr = NULL; |
| 408 | } | 426 | } |
| 409 | #ifndef OPENSSL_NO_ENGINE | 427 | #ifndef OPENSSL_NO_ENGINE |
| 410 | if (x->engine) | 428 | if (x->engine) { |
| 411 | { | ||
| 412 | ENGINE_finish(x->engine); | 429 | ENGINE_finish(x->engine); |
| 413 | x->engine = NULL; | 430 | x->engine = NULL; |
| 414 | } | ||
| 415 | #endif | ||
| 416 | } | 431 | } |
| 432 | #endif | ||
| 433 | } | ||
| 417 | 434 | ||
| 418 | static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent, | 435 | static int |
| 419 | const char *kstr) | 436 | unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent, const char *kstr) |
| 420 | { | 437 | { |
| 421 | BIO_indent(out, indent, 128); | 438 | BIO_indent(out, indent, 128); |
| 422 | BIO_printf(out, "%s algorithm \"%s\" unsupported\n", | 439 | BIO_printf(out, "%s algorithm \"%s\" unsupported\n", |
| 423 | kstr, OBJ_nid2ln(pkey->type)); | 440 | kstr, OBJ_nid2ln(pkey->type)); |
| 424 | return 1; | 441 | return 1; |
| 425 | } | 442 | } |
| 426 | 443 | ||
| 427 | int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, | 444 | int |
| 428 | int indent, ASN1_PCTX *pctx) | 445 | EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, int indent, |
| 429 | { | 446 | ASN1_PCTX *pctx) |
| 447 | { | ||
| 430 | if (pkey->ameth && pkey->ameth->pub_print) | 448 | if (pkey->ameth && pkey->ameth->pub_print) |
| 431 | return pkey->ameth->pub_print(out, pkey, indent, pctx); | 449 | return pkey->ameth->pub_print(out, pkey, indent, pctx); |
| 432 | 450 | ||
| 433 | return unsup_alg(out, pkey, indent, "Public Key"); | 451 | return unsup_alg(out, pkey, indent, "Public Key"); |
| 434 | } | 452 | } |
| 435 | 453 | ||
| 436 | int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, | 454 | int |
| 437 | int indent, ASN1_PCTX *pctx) | 455 | EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, int indent, |
| 438 | { | 456 | ASN1_PCTX *pctx) |
| 457 | { | ||
| 439 | if (pkey->ameth && pkey->ameth->priv_print) | 458 | if (pkey->ameth && pkey->ameth->priv_print) |
| 440 | return pkey->ameth->priv_print(out, pkey, indent, pctx); | 459 | return pkey->ameth->priv_print(out, pkey, indent, pctx); |
| 441 | 460 | ||
| 442 | return unsup_alg(out, pkey, indent, "Private Key"); | 461 | return unsup_alg(out, pkey, indent, "Private Key"); |
| 443 | } | 462 | } |
| 444 | 463 | ||
| 445 | int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, | 464 | int |
| 446 | int indent, ASN1_PCTX *pctx) | 465 | EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, int indent, |
| 447 | { | 466 | ASN1_PCTX *pctx) |
| 467 | { | ||
| 448 | if (pkey->ameth && pkey->ameth->param_print) | 468 | if (pkey->ameth && pkey->ameth->param_print) |
| 449 | return pkey->ameth->param_print(out, pkey, indent, pctx); | 469 | return pkey->ameth->param_print(out, pkey, indent, pctx); |
| 450 | return unsup_alg(out, pkey, indent, "Parameters"); | 470 | return unsup_alg(out, pkey, indent, "Parameters"); |
| 451 | } | 471 | } |
| 452 | 472 | ||
| 453 | int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid) | 473 | int |
| 454 | { | 474 | EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid) |
| 475 | { | ||
| 455 | if (!pkey->ameth || !pkey->ameth->pkey_ctrl) | 476 | if (!pkey->ameth || !pkey->ameth->pkey_ctrl) |
| 456 | return -2; | 477 | return -2; |
| 457 | return pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID, | 478 | return pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID, |
| 458 | 0, pnid); | 479 | 0, pnid); |
| 459 | } | 480 | } |
| 460 | 481 | ||
