| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/p_lib.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||||||||
| 2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||||||||
| 3 | * | - | ||||||||||||||||||
| 4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||||||||
| 5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||||||||
| 6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||||||||
| 7 | * https://www.openssl.org/source/license.html | - | ||||||||||||||||||
| 8 | */ | - | ||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | #include <stdio.h> | - | ||||||||||||||||||
| 11 | #include "internal/cryptlib.h" | - | ||||||||||||||||||
| 12 | #include "internal/refcount.h" | - | ||||||||||||||||||
| 13 | #include <openssl/bn.h> | - | ||||||||||||||||||
| 14 | #include <openssl/err.h> | - | ||||||||||||||||||
| 15 | #include <openssl/objects.h> | - | ||||||||||||||||||
| 16 | #include <openssl/evp.h> | - | ||||||||||||||||||
| 17 | #include <openssl/x509.h> | - | ||||||||||||||||||
| 18 | #include <openssl/rsa.h> | - | ||||||||||||||||||
| 19 | #include <openssl/dsa.h> | - | ||||||||||||||||||
| 20 | #include <openssl/dh.h> | - | ||||||||||||||||||
| 21 | #include <openssl/cmac.h> | - | ||||||||||||||||||
| 22 | #include <openssl/engine.h> | - | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | #include "internal/asn1_int.h" | - | ||||||||||||||||||
| 25 | #include "internal/evp_int.h" | - | ||||||||||||||||||
| 26 | - | |||||||||||||||||||
| 27 | static void EVP_PKEY_free_it(EVP_PKEY *x); | - | ||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | int EVP_PKEY_bits(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 30 | { | - | ||||||||||||||||||
| 31 | if (pkey && pkey->ameth && pkey->ameth->pkey_bits)
| 0-457 | ||||||||||||||||||
| 32 | return pkey->ameth->pkey_bits(pkey); executed 457 times by 1 test: return pkey->ameth->pkey_bits(pkey);Executed by:
| 457 | ||||||||||||||||||
| 33 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 34 | } | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | int EVP_PKEY_security_bits(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 37 | { | - | ||||||||||||||||||
| 38 | if (pkey == NULL)
| 0-13278 | ||||||||||||||||||
| 39 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 40 | if (!pkey->ameth || !pkey->ameth->pkey_security_bits)
| 0-13278 | ||||||||||||||||||
| 41 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
| 42 | return pkey->ameth->pkey_security_bits(pkey); executed 13278 times by 1 test: return pkey->ameth->pkey_security_bits(pkey);Executed by:
| 13278 | ||||||||||||||||||
| 43 | } | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | int EVP_PKEY_size(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 46 | { | - | ||||||||||||||||||
| 47 | if (pkey && pkey->ameth && pkey->ameth->pkey_size)
| 0-8850 | ||||||||||||||||||
| 48 | return pkey->ameth->pkey_size(pkey); executed 8850 times by 1 test: return pkey->ameth->pkey_size(pkey);Executed by:
| 8850 | ||||||||||||||||||
| 49 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 50 | } | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) | - | ||||||||||||||||||
| 53 | { | - | ||||||||||||||||||
| 54 | #ifndef OPENSSL_NO_DSA | - | ||||||||||||||||||
| 55 | if (pkey->type == EVP_PKEY_DSA) {
| 0 | ||||||||||||||||||
| 56 | int ret = pkey->save_parameters; | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | if (mode >= 0)
| 0 | ||||||||||||||||||
| 59 | pkey->save_parameters = mode; never executed: pkey->save_parameters = mode; | 0 | ||||||||||||||||||
| 60 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
| 61 | } | - | ||||||||||||||||||
| 62 | #endif | - | ||||||||||||||||||
| 63 | #ifndef OPENSSL_NO_EC | - | ||||||||||||||||||
| 64 | if (pkey->type == EVP_PKEY_EC) {
| 0 | ||||||||||||||||||
| 65 | int ret = pkey->save_parameters; | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | if (mode >= 0)
| 0 | ||||||||||||||||||
| 68 | pkey->save_parameters = mode; never executed: pkey->save_parameters = mode; | 0 | ||||||||||||||||||
| 69 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
| 70 | } | - | ||||||||||||||||||
| 71 | #endif | - | ||||||||||||||||||
| 72 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 73 | } | - | ||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) | - | ||||||||||||||||||
| 76 | { | - | ||||||||||||||||||
| 77 | if (to->type == EVP_PKEY_NONE) {
| 1062-8461 | ||||||||||||||||||
| 78 | if (EVP_PKEY_set_type(to, from->type) == 0)
| 0-1062 | ||||||||||||||||||
| 79 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 80 | } else if (to->type != from->type) { executed 1062 times by 1 test: end of blockExecuted by:
| 0-8461 | ||||||||||||||||||
| 81 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_KEY_TYPES); | - | ||||||||||||||||||
| 82 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 83 | } | - | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | if (EVP_PKEY_missing_parameters(from)) {
| 0-9523 | ||||||||||||||||||
| 86 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_MISSING_PARAMETERS); | - | ||||||||||||||||||
| 87 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 88 | } | - | ||||||||||||||||||
| 89 | - | |||||||||||||||||||
| 90 | if (!EVP_PKEY_missing_parameters(to)) {
| 634-8889 | ||||||||||||||||||
| 91 | if (EVP_PKEY_cmp_parameters(to, from) == 1)
| 3955-4934 | ||||||||||||||||||
| 92 | return 1; executed 4934 times by 1 test: return 1;Executed by:
| 4934 | ||||||||||||||||||
| 93 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_PARAMETERS); | - | ||||||||||||||||||
| 94 | return 0; executed 3955 times by 1 test: return 0;Executed by:
| 3955 | ||||||||||||||||||
| 95 | } | - | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | if (from->ameth && from->ameth->param_copy)
| 0-634 | ||||||||||||||||||
| 98 | return from->ameth->param_copy(to, from); executed 634 times by 1 test: return from->ameth->param_copy(to, from);Executed by:
| 634 | ||||||||||||||||||
| 99 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||
| 100 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 101 | } | - | ||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 104 | { | - | ||||||||||||||||||
| 105 | if (pkey->ameth && pkey->ameth->param_missing)
| 0-30687 | ||||||||||||||||||
| 106 | return pkey->ameth->param_missing(pkey); executed 12121 times by 1 test: return pkey->ameth->param_missing(pkey);Executed by:
| 12121 | ||||||||||||||||||
| 107 | return 0; executed 18566 times by 1 test: return 0;Executed by:
| 18566 | ||||||||||||||||||
| 108 | } | - | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) | - | ||||||||||||||||||
| 111 | { | - | ||||||||||||||||||
| 112 | if (a->type != b->type)
| 0-13256 | ||||||||||||||||||
| 113 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 114 | if (a->ameth && a->ameth->param_cmp)
| 0-13256 | ||||||||||||||||||
| 115 | return a->ameth->param_cmp(a, b); executed 9301 times by 1 test: return a->ameth->param_cmp(a, b);Executed by:
| 9301 | ||||||||||||||||||
| 116 | return -2; executed 3955 times by 1 test: return -2;Executed by:
| 3955 | ||||||||||||||||||
| 117 | } | - | ||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b) | - | ||||||||||||||||||
| 120 | { | - | ||||||||||||||||||
| 121 | if (a->type != b->type)
| 5-9415 | ||||||||||||||||||
| 122 | return -1; executed 5 times by 1 test: return -1;Executed by:
| 5 | ||||||||||||||||||
| 123 | - | |||||||||||||||||||
| 124 | if (a->ameth) {
| 0-9415 | ||||||||||||||||||
| 125 | int ret; | - | ||||||||||||||||||
| 126 | /* Compare parameters if the algorithm has them */ | - | ||||||||||||||||||
| 127 | if (a->ameth->param_cmp) {
| 4536-4879 | ||||||||||||||||||
| 128 | ret = a->ameth->param_cmp(a, b); | - | ||||||||||||||||||
| 129 | if (ret <= 0)
| 0-4879 | ||||||||||||||||||
| 130 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
| 131 | } executed 4879 times by 1 test: end of blockExecuted by:
| 4879 | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | if (a->ameth->pub_cmp)
| 0-9415 | ||||||||||||||||||
| 134 | return a->ameth->pub_cmp(a, b); executed 9415 times by 1 test: return a->ameth->pub_cmp(a, b);Executed by:
| 9415 | ||||||||||||||||||
| 135 | } never executed: end of block | 0 | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
| 138 | } | - | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | EVP_PKEY *EVP_PKEY_new(void) | - | ||||||||||||||||||
| 141 | { | - | ||||||||||||||||||
| 142 | EVP_PKEY *ret = OPENSSL_zalloc(sizeof(*ret)); | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | if (ret == NULL) {
| 0-98797 | ||||||||||||||||||
| 145 | EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
| 146 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 147 | } | - | ||||||||||||||||||
| 148 | ret->type = EVP_PKEY_NONE; | - | ||||||||||||||||||
| 149 | ret->save_type = EVP_PKEY_NONE; | - | ||||||||||||||||||
| 150 | ret->references = 1; | - | ||||||||||||||||||
| 151 | ret->save_parameters = 1; | - | ||||||||||||||||||
| 152 | ret->lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||||||||
| 153 | if (ret->lock == NULL) {
| 0-98797 | ||||||||||||||||||
| 154 | EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
| 155 | OPENSSL_free(ret); | - | ||||||||||||||||||
| 156 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 157 | } | - | ||||||||||||||||||
| 158 | return ret; executed 98797 times by 1 test: return ret;Executed by:
| 98797 | ||||||||||||||||||
| 159 | } | - | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | int EVP_PKEY_up_ref(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 162 | { | - | ||||||||||||||||||
| 163 | int i; | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | if (CRYPTO_UP_REF(&pkey->references, &i, pkey->lock) <= 0)
| 0-249355 | ||||||||||||||||||
| 166 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | REF_PRINT_COUNT("EVP_PKEY", pkey); | - | ||||||||||||||||||
| 169 | REF_ASSERT_ISNT(i < 2); | - | ||||||||||||||||||
| 170 | return ((i > 1) ? 1 : 0); executed 249355 times by 1 test: return ((i > 1) ? 1 : 0);Executed by:
| 0-249355 | ||||||||||||||||||
| 171 | } | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | /* | - | ||||||||||||||||||
| 174 | * Setup a public key ASN1 method and ENGINE from a NID or a string. If pkey | - | ||||||||||||||||||
| 175 | * is NULL just return 1 or 0 if the algorithm exists. | - | ||||||||||||||||||
| 176 | */ | - | ||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, | - | ||||||||||||||||||
| 179 | int len) | - | ||||||||||||||||||
| 180 | { | - | ||||||||||||||||||
| 181 | const EVP_PKEY_ASN1_METHOD *ameth; | - | ||||||||||||||||||
| 182 | ENGINE **eptr = (e == NULL) ? &e : NULL;
| 0-146230 | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | if (pkey) {
| 0-146230 | ||||||||||||||||||
| 185 | if (pkey->pkey.ptr)
| 590-145640 | ||||||||||||||||||
| 186 | EVP_PKEY_free_it(pkey); executed 590 times by 1 test: EVP_PKEY_free_it(pkey);Executed by:
| 590 | ||||||||||||||||||
| 187 | /* | - | ||||||||||||||||||
| 188 | * If key type matches and a method exists then this lookup has | - | ||||||||||||||||||
| 189 | * succeeded once so just indicate success. | - | ||||||||||||||||||
| 190 | */ | - | ||||||||||||||||||
| 191 | if ((type == pkey->save_type) && pkey->ameth)
| 2072-96757 | ||||||||||||||||||
| 192 | return 1; executed 47401 times by 1 test: return 1;Executed by:
| 47401 | ||||||||||||||||||
| 193 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
| 194 | /* If we have ENGINEs release them */ | - | ||||||||||||||||||
| 195 | ENGINE_finish(pkey->engine); | - | ||||||||||||||||||
| 196 | pkey->engine = NULL; | - | ||||||||||||||||||
| 197 | ENGINE_finish(pkey->pmeth_engine); | - | ||||||||||||||||||
| 198 | pkey->pmeth_engine = NULL; | - | ||||||||||||||||||
| 199 | #endif | - | ||||||||||||||||||
| 200 | } executed 98829 times by 1 test: end of blockExecuted by:
| 98829 | ||||||||||||||||||
| 201 | if (str)
| 1-98828 | ||||||||||||||||||
| 202 | ameth = EVP_PKEY_asn1_find_str(eptr, str, len); executed 1 time by 1 test: ameth = EVP_PKEY_asn1_find_str(eptr, str, len);Executed by:
| 1 | ||||||||||||||||||
| 203 | else | - | ||||||||||||||||||
| 204 | ameth = EVP_PKEY_asn1_find(eptr, type); executed 98828 times by 1 test: ameth = EVP_PKEY_asn1_find(eptr, type);Executed by:
| 98828 | ||||||||||||||||||
| 205 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
| 206 | if (pkey == NULL && eptr != NULL)
| 0-98829 | ||||||||||||||||||
| 207 | ENGINE_finish(e); never executed: ENGINE_finish(e); | 0 | ||||||||||||||||||
| 208 | #endif | - | ||||||||||||||||||
| 209 | if (ameth == NULL) {
| 2174-96655 | ||||||||||||||||||
| 210 | EVPerr(EVP_F_PKEY_SET_TYPE, EVP_R_UNSUPPORTED_ALGORITHM); | - | ||||||||||||||||||
| 211 | return 0; executed 2174 times by 1 test: return 0;Executed by:
| 2174 | ||||||||||||||||||
| 212 | } | - | ||||||||||||||||||
| 213 | if (pkey) {
| 0-96655 | ||||||||||||||||||
| 214 | pkey->ameth = ameth; | - | ||||||||||||||||||
| 215 | pkey->engine = e; | - | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | pkey->type = pkey->ameth->pkey_id; | - | ||||||||||||||||||
| 218 | pkey->save_type = type; | - | ||||||||||||||||||
| 219 | } executed 96655 times by 1 test: end of blockExecuted by:
| 96655 | ||||||||||||||||||
| 220 | return 1; executed 96655 times by 1 test: return 1;Executed by:
| 96655 | ||||||||||||||||||
| 221 | } | - | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e, | - | ||||||||||||||||||
| 224 | const unsigned char *priv, | - | ||||||||||||||||||
| 225 | size_t len) | - | ||||||||||||||||||
| 226 | { | - | ||||||||||||||||||
| 227 | EVP_PKEY *ret = EVP_PKEY_new(); | - | ||||||||||||||||||
| 228 | - | |||||||||||||||||||
| 229 | if (ret == NULL
| 0-16541 | ||||||||||||||||||
| 230 | || !pkey_set_type(ret, e, type, NULL, -1)) {
| 0-16541 | ||||||||||||||||||
| 231 | /* EVPerr already called */ | - | ||||||||||||||||||
| 232 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 233 | } | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | if (ret->ameth->set_priv_key == NULL) {
| 0-16541 | ||||||||||||||||||
| 236 | EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PRIVATE_KEY, | - | ||||||||||||||||||
| 237 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | - | ||||||||||||||||||
| 238 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 239 | } | - | ||||||||||||||||||
| 240 | - | |||||||||||||||||||
| 241 | if (!ret->ameth->set_priv_key(ret, priv, len)) {
| 0-16541 | ||||||||||||||||||
| 242 | EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PRIVATE_KEY, EVP_R_KEY_SETUP_FAILED); | - | ||||||||||||||||||
| 243 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 244 | } | - | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | return ret; executed 16541 times by 1 test: return ret;Executed by:
| 16541 | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | err: | - | ||||||||||||||||||
| 249 | EVP_PKEY_free(ret); | - | ||||||||||||||||||
| 250 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 251 | } | - | ||||||||||||||||||
| 252 | - | |||||||||||||||||||
| 253 | EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e, | - | ||||||||||||||||||
| 254 | const unsigned char *pub, | - | ||||||||||||||||||
| 255 | size_t len) | - | ||||||||||||||||||
| 256 | { | - | ||||||||||||||||||
| 257 | EVP_PKEY *ret = EVP_PKEY_new(); | - | ||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | if (ret == NULL
| 0-15 | ||||||||||||||||||
| 260 | || !pkey_set_type(ret, e, type, NULL, -1)) {
| 0-15 | ||||||||||||||||||
| 261 | /* EVPerr already called */ | - | ||||||||||||||||||
| 262 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 263 | } | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | if (ret->ameth->set_pub_key == NULL) {
| 0-15 | ||||||||||||||||||
| 266 | EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PUBLIC_KEY, | - | ||||||||||||||||||
| 267 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | - | ||||||||||||||||||
| 268 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 269 | } | - | ||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | if (!ret->ameth->set_pub_key(ret, pub, len)) {
| 0-15 | ||||||||||||||||||
| 272 | EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PUBLIC_KEY, EVP_R_KEY_SETUP_FAILED); | - | ||||||||||||||||||
| 273 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 274 | } | - | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | return ret; executed 15 times by 1 test: return ret;Executed by:
| 15 | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | err: | - | ||||||||||||||||||
| 279 | EVP_PKEY_free(ret); | - | ||||||||||||||||||
| 280 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 281 | } | - | ||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv, | - | ||||||||||||||||||
| 284 | size_t *len) | - | ||||||||||||||||||
| 285 | { | - | ||||||||||||||||||
| 286 | if (pkey->ameth->get_priv_key == NULL) {
| 0-8 | ||||||||||||||||||
| 287 | EVPerr(EVP_F_EVP_PKEY_GET_RAW_PRIVATE_KEY, | - | ||||||||||||||||||
| 288 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | - | ||||||||||||||||||
| 289 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 290 | } | - | ||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | if (!pkey->ameth->get_priv_key(pkey, priv, len)) {
| 0-8 | ||||||||||||||||||
| 293 | EVPerr(EVP_F_EVP_PKEY_GET_RAW_PRIVATE_KEY, EVP_R_GET_RAW_KEY_FAILED); | - | ||||||||||||||||||
| 294 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 295 | } | - | ||||||||||||||||||
| 296 | - | |||||||||||||||||||
| 297 | return 1; executed 8 times by 1 test: return 1;Executed by:
| 8 | ||||||||||||||||||
| 298 | } | - | ||||||||||||||||||
| 299 | - | |||||||||||||||||||
| 300 | int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub, | - | ||||||||||||||||||
| 301 | size_t *len) | - | ||||||||||||||||||
| 302 | { | - | ||||||||||||||||||
| 303 | if (pkey->ameth->get_pub_key == NULL) {
| 0-8 | ||||||||||||||||||
| 304 | EVPerr(EVP_F_EVP_PKEY_GET_RAW_PUBLIC_KEY, | - | ||||||||||||||||||
| 305 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | - | ||||||||||||||||||
| 306 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 307 | } | - | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | if (!pkey->ameth->get_pub_key(pkey, pub, len)) {
| 0-8 | ||||||||||||||||||
| 310 | EVPerr(EVP_F_EVP_PKEY_GET_RAW_PUBLIC_KEY, EVP_R_GET_RAW_KEY_FAILED); | - | ||||||||||||||||||
| 311 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 312 | } | - | ||||||||||||||||||
| 313 | - | |||||||||||||||||||
| 314 | return 1; executed 8 times by 1 test: return 1;Executed by:
| 8 | ||||||||||||||||||
| 315 | } | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, | - | ||||||||||||||||||
| 318 | size_t len, const EVP_CIPHER *cipher) | - | ||||||||||||||||||
| 319 | { | - | ||||||||||||||||||
| 320 | #ifndef OPENSSL_NO_CMAC | - | ||||||||||||||||||
| 321 | EVP_PKEY *ret = EVP_PKEY_new(); | - | ||||||||||||||||||
| 322 | CMAC_CTX *cmctx = CMAC_CTX_new(); | - | ||||||||||||||||||
| 323 | - | |||||||||||||||||||
| 324 | if (ret == NULL
| 0-4 | ||||||||||||||||||
| 325 | || cmctx == NULL
| 0-4 | ||||||||||||||||||
| 326 | || !pkey_set_type(ret, e, EVP_PKEY_CMAC, NULL, -1)) {
| 0-4 | ||||||||||||||||||
| 327 | /* EVPerr already called */ | - | ||||||||||||||||||
| 328 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 329 | } | - | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | if (!CMAC_Init(cmctx, priv, len, cipher, e)) {
| 0-4 | ||||||||||||||||||
| 332 | EVPerr(EVP_F_EVP_PKEY_NEW_CMAC_KEY, EVP_R_KEY_SETUP_FAILED); | - | ||||||||||||||||||
| 333 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 334 | } | - | ||||||||||||||||||
| 335 | - | |||||||||||||||||||
| 336 | ret->pkey.ptr = cmctx; | - | ||||||||||||||||||
| 337 | return ret; executed 4 times by 1 test: return ret;Executed by:
| 4 | ||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | err: | - | ||||||||||||||||||
| 340 | EVP_PKEY_free(ret); | - | ||||||||||||||||||
| 341 | CMAC_CTX_free(cmctx); | - | ||||||||||||||||||
| 342 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 343 | #else | - | ||||||||||||||||||
| 344 | EVPerr(EVP_F_EVP_PKEY_NEW_CMAC_KEY, | - | ||||||||||||||||||
| 345 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | - | ||||||||||||||||||
| 346 | return NULL; | - | ||||||||||||||||||
| 347 | #endif | - | ||||||||||||||||||
| 348 | } | - | ||||||||||||||||||
| 349 | - | |||||||||||||||||||
| 350 | int EVP_PKEY_set_type(EVP_PKEY *pkey, int type) | - | ||||||||||||||||||
| 351 | { | - | ||||||||||||||||||
| 352 | return pkey_set_type(pkey, NULL, type, NULL, -1); executed 129669 times by 1 test: return pkey_set_type(pkey, ((void *)0) , type, ((void *)0) , -1);Executed by:
| 129669 | ||||||||||||||||||
| 353 | } | - | ||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len) | - | ||||||||||||||||||
| 356 | { | - | ||||||||||||||||||
| 357 | return pkey_set_type(pkey, NULL, EVP_PKEY_NONE, str, len); executed 1 time by 1 test: return pkey_set_type(pkey, ((void *)0) , 0, str, len);Executed by:
| 1 | ||||||||||||||||||
| 358 | } | - | ||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | int EVP_PKEY_set_alias_type(EVP_PKEY *pkey, int type) | - | ||||||||||||||||||
| 361 | { | - | ||||||||||||||||||
| 362 | if (pkey->type == type) {
| 0-3 | ||||||||||||||||||
| 363 | return 1; /* it already is that type */ never executed: return 1; | 0 | ||||||||||||||||||
| 364 | } | - | ||||||||||||||||||
| 365 | - | |||||||||||||||||||
| 366 | /* | - | ||||||||||||||||||
| 367 | * The application is requesting to alias this to a different pkey type, | - | ||||||||||||||||||
| 368 | * but not one that resolves to the base type. | - | ||||||||||||||||||
| 369 | */ | - | ||||||||||||||||||
| 370 | if (EVP_PKEY_type(type) != EVP_PKEY_base_id(pkey)) {
| 0-3 | ||||||||||||||||||
| 371 | EVPerr(EVP_F_EVP_PKEY_SET_ALIAS_TYPE, EVP_R_UNSUPPORTED_ALGORITHM); | - | ||||||||||||||||||
| 372 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 373 | } | - | ||||||||||||||||||
| 374 | - | |||||||||||||||||||
| 375 | pkey->type = type; | - | ||||||||||||||||||
| 376 | return 1; executed 3 times by 1 test: return 1;Executed by:
| 3 | ||||||||||||||||||
| 377 | } | - | ||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
| 380 | int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *e) | - | ||||||||||||||||||
| 381 | { | - | ||||||||||||||||||
| 382 | if (e != NULL) {
| 0-2 | ||||||||||||||||||
| 383 | if (!ENGINE_init(e)) {
| 0-2 | ||||||||||||||||||
| 384 | EVPerr(EVP_F_EVP_PKEY_SET1_ENGINE, ERR_R_ENGINE_LIB); | - | ||||||||||||||||||
| 385 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 386 | } | - | ||||||||||||||||||
| 387 | if (ENGINE_get_pkey_meth(e, pkey->type) == NULL) {
| 1 | ||||||||||||||||||
| 388 | ENGINE_finish(e); | - | ||||||||||||||||||
| 389 | EVPerr(EVP_F_EVP_PKEY_SET1_ENGINE, EVP_R_UNSUPPORTED_ALGORITHM); | - | ||||||||||||||||||
| 390 | return 0; executed 1 time by 1 test: return 0;Executed by:
| 1 | ||||||||||||||||||
| 391 | } | - | ||||||||||||||||||
| 392 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 393 | ENGINE_finish(pkey->pmeth_engine); | - | ||||||||||||||||||
| 394 | pkey->pmeth_engine = e; | - | ||||||||||||||||||
| 395 | return 1; executed 1 time by 1 test: return 1;Executed by:
| 1 | ||||||||||||||||||
| 396 | } | - | ||||||||||||||||||
| 397 | #endif | - | ||||||||||||||||||
| 398 | int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) | - | ||||||||||||||||||
| 399 | { | - | ||||||||||||||||||
| 400 | if (pkey == NULL || !EVP_PKEY_set_type(pkey, type))
| 0-63914 | ||||||||||||||||||
| 401 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 402 | pkey->pkey.ptr = key; | - | ||||||||||||||||||
| 403 | return (key != NULL); executed 63914 times by 1 test: return (key != ((void *)0) );Executed by:
| 63914 | ||||||||||||||||||
| 404 | } | - | ||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | void *EVP_PKEY_get0(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 407 | { | - | ||||||||||||||||||
| 408 | return pkey->pkey.ptr; executed 20553 times by 1 test: return pkey->pkey.ptr;Executed by:
| 20553 | ||||||||||||||||||
| 409 | } | - | ||||||||||||||||||
| 410 | - | |||||||||||||||||||
| 411 | const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len) | - | ||||||||||||||||||
| 412 | { | - | ||||||||||||||||||
| 413 | ASN1_OCTET_STRING *os = NULL; | - | ||||||||||||||||||
| 414 | if (pkey->type != EVP_PKEY_HMAC) {
| 0 | ||||||||||||||||||
| 415 | EVPerr(EVP_F_EVP_PKEY_GET0_HMAC, EVP_R_EXPECTING_AN_HMAC_KEY); | - | ||||||||||||||||||
| 416 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 417 | } | - | ||||||||||||||||||
| 418 | os = EVP_PKEY_get0(pkey); | - | ||||||||||||||||||
| 419 | *len = os->length; | - | ||||||||||||||||||
| 420 | return os->data; never executed: return os->data; | 0 | ||||||||||||||||||
| 421 | } | - | ||||||||||||||||||
| 422 | - | |||||||||||||||||||
| 423 | #ifndef OPENSSL_NO_POLY1305 | - | ||||||||||||||||||
| 424 | const unsigned char *EVP_PKEY_get0_poly1305(const EVP_PKEY *pkey, size_t *len) | - | ||||||||||||||||||
| 425 | { | - | ||||||||||||||||||
| 426 | ASN1_OCTET_STRING *os = NULL; | - | ||||||||||||||||||
| 427 | if (pkey->type != EVP_PKEY_POLY1305) {
| 0 | ||||||||||||||||||
| 428 | EVPerr(EVP_F_EVP_PKEY_GET0_POLY1305, EVP_R_EXPECTING_A_POLY1305_KEY); | - | ||||||||||||||||||
| 429 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 430 | } | - | ||||||||||||||||||
| 431 | os = EVP_PKEY_get0(pkey); | - | ||||||||||||||||||
| 432 | *len = os->length; | - | ||||||||||||||||||
| 433 | return os->data; never executed: return os->data; | 0 | ||||||||||||||||||
| 434 | } | - | ||||||||||||||||||
| 435 | #endif | - | ||||||||||||||||||
| 436 | - | |||||||||||||||||||
| 437 | #ifndef OPENSSL_NO_SIPHASH | - | ||||||||||||||||||
| 438 | const unsigned char *EVP_PKEY_get0_siphash(const EVP_PKEY *pkey, size_t *len) | - | ||||||||||||||||||
| 439 | { | - | ||||||||||||||||||
| 440 | ASN1_OCTET_STRING *os = NULL; | - | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | if (pkey->type != EVP_PKEY_SIPHASH) {
| 0-26 | ||||||||||||||||||
| 443 | EVPerr(EVP_F_EVP_PKEY_GET0_SIPHASH, EVP_R_EXPECTING_A_SIPHASH_KEY); | - | ||||||||||||||||||
| 444 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 445 | } | - | ||||||||||||||||||
| 446 | os = EVP_PKEY_get0(pkey); | - | ||||||||||||||||||
| 447 | *len = os->length; | - | ||||||||||||||||||
| 448 | return os->data; executed 26 times by 1 test: return os->data;Executed by:
| 26 | ||||||||||||||||||
| 449 | } | - | ||||||||||||||||||
| 450 | #endif | - | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | #ifndef OPENSSL_NO_RSA | - | ||||||||||||||||||
| 453 | int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key) | - | ||||||||||||||||||
| 454 | { | - | ||||||||||||||||||
| 455 | int ret = EVP_PKEY_assign_RSA(pkey, key); | - | ||||||||||||||||||
| 456 | if (ret)
| 0-36 | ||||||||||||||||||
| 457 | RSA_up_ref(key); executed 36 times by 1 test: RSA_up_ref(key);Executed by:
| 36 | ||||||||||||||||||
| 458 | return ret; executed 36 times by 1 test: return ret;Executed by:
| 36 | ||||||||||||||||||
| 459 | } | - | ||||||||||||||||||
| 460 | - | |||||||||||||||||||
| 461 | RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 462 | { | - | ||||||||||||||||||
| 463 | if (pkey->type != EVP_PKEY_RSA) {
| 0-4575 | ||||||||||||||||||
| 464 | EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY); | - | ||||||||||||||||||
| 465 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 466 | } | - | ||||||||||||||||||
| 467 | return pkey->pkey.rsa; executed 4575 times by 1 test: return pkey->pkey.rsa;Executed by:
| 4575 | ||||||||||||||||||
| 468 | } | - | ||||||||||||||||||
| 469 | - | |||||||||||||||||||
| 470 | RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 471 | { | - | ||||||||||||||||||
| 472 | RSA *ret = EVP_PKEY_get0_RSA(pkey); | - | ||||||||||||||||||
| 473 | if (ret != NULL)
| 0-33 | ||||||||||||||||||
| 474 | RSA_up_ref(ret); executed 33 times by 1 test: RSA_up_ref(ret);Executed by:
| 33 | ||||||||||||||||||
| 475 | return ret; executed 33 times by 1 test: return ret;Executed by:
| 33 | ||||||||||||||||||
| 476 | } | - | ||||||||||||||||||
| 477 | #endif | - | ||||||||||||||||||
| 478 | - | |||||||||||||||||||
| 479 | #ifndef OPENSSL_NO_DSA | - | ||||||||||||||||||
| 480 | int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) | - | ||||||||||||||||||
| 481 | { | - | ||||||||||||||||||
| 482 | int ret = EVP_PKEY_assign_DSA(pkey, key); | - | ||||||||||||||||||
| 483 | if (ret)
| 0-51 | ||||||||||||||||||
| 484 | DSA_up_ref(key); executed 51 times by 1 test: DSA_up_ref(key);Executed by:
| 51 | ||||||||||||||||||
| 485 | return ret; executed 51 times by 1 test: return ret;Executed by:
| 51 | ||||||||||||||||||
| 486 | } | - | ||||||||||||||||||
| 487 | - | |||||||||||||||||||
| 488 | DSA *EVP_PKEY_get0_DSA(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 489 | { | - | ||||||||||||||||||
| 490 | if (pkey->type != EVP_PKEY_DSA) {
| 0-1827 | ||||||||||||||||||
| 491 | EVPerr(EVP_F_EVP_PKEY_GET0_DSA, EVP_R_EXPECTING_A_DSA_KEY); | - | ||||||||||||||||||
| 492 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 493 | } | - | ||||||||||||||||||
| 494 | return pkey->pkey.dsa; executed 1827 times by 1 test: return pkey->pkey.dsa;Executed by:
| 1827 | ||||||||||||||||||
| 495 | } | - | ||||||||||||||||||
| 496 | - | |||||||||||||||||||
| 497 | DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 498 | { | - | ||||||||||||||||||
| 499 | DSA *ret = EVP_PKEY_get0_DSA(pkey); | - | ||||||||||||||||||
| 500 | if (ret != NULL)
| 0-1819 | ||||||||||||||||||
| 501 | DSA_up_ref(ret); executed 1819 times by 1 test: DSA_up_ref(ret);Executed by:
| 1819 | ||||||||||||||||||
| 502 | return ret; executed 1819 times by 1 test: return ret;Executed by:
| 1819 | ||||||||||||||||||
| 503 | } | - | ||||||||||||||||||
| 504 | #endif | - | ||||||||||||||||||
| 505 | - | |||||||||||||||||||
| 506 | #ifndef OPENSSL_NO_EC | - | ||||||||||||||||||
| 507 | - | |||||||||||||||||||
| 508 | int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) | - | ||||||||||||||||||
| 509 | { | - | ||||||||||||||||||
| 510 | int ret = EVP_PKEY_assign_EC_KEY(pkey, key); | - | ||||||||||||||||||
| 511 | if (ret)
| 0-17 | ||||||||||||||||||
| 512 | EC_KEY_up_ref(key); executed 17 times by 1 test: EC_KEY_up_ref(key);Executed by:
| 17 | ||||||||||||||||||
| 513 | return ret; executed 17 times by 1 test: return ret;Executed by:
| 17 | ||||||||||||||||||
| 514 | } | - | ||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 517 | { | - | ||||||||||||||||||
| 518 | if (pkey->type != EVP_PKEY_EC) {
| 0-7185 | ||||||||||||||||||
| 519 | EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY); | - | ||||||||||||||||||
| 520 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 521 | } | - | ||||||||||||||||||
| 522 | return pkey->pkey.ec; executed 7185 times by 1 test: return pkey->pkey.ec;Executed by:
| 7185 | ||||||||||||||||||
| 523 | } | - | ||||||||||||||||||
| 524 | - | |||||||||||||||||||
| 525 | EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 526 | { | - | ||||||||||||||||||
| 527 | EC_KEY *ret = EVP_PKEY_get0_EC_KEY(pkey); | - | ||||||||||||||||||
| 528 | if (ret != NULL)
| 0-1842 | ||||||||||||||||||
| 529 | EC_KEY_up_ref(ret); executed 1842 times by 1 test: EC_KEY_up_ref(ret);Executed by:
| 1842 | ||||||||||||||||||
| 530 | return ret; executed 1842 times by 1 test: return ret;Executed by:
| 1842 | ||||||||||||||||||
| 531 | } | - | ||||||||||||||||||
| 532 | #endif | - | ||||||||||||||||||
| 533 | - | |||||||||||||||||||
| 534 | #ifndef OPENSSL_NO_DH | - | ||||||||||||||||||
| 535 | - | |||||||||||||||||||
| 536 | int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key) | - | ||||||||||||||||||
| 537 | { | - | ||||||||||||||||||
| 538 | int ret = EVP_PKEY_assign_DH(pkey, key); | - | ||||||||||||||||||
| 539 | if (ret)
| 0-235 | ||||||||||||||||||
| 540 | DH_up_ref(key); executed 235 times by 1 test: DH_up_ref(key);Executed by:
| 235 | ||||||||||||||||||
| 541 | return ret; executed 235 times by 1 test: return ret;Executed by:
| 235 | ||||||||||||||||||
| 542 | } | - | ||||||||||||||||||
| 543 | - | |||||||||||||||||||
| 544 | DH *EVP_PKEY_get0_DH(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 545 | { | - | ||||||||||||||||||
| 546 | if (pkey->type != EVP_PKEY_DH && pkey->type != EVP_PKEY_DHX) {
| 0-274 | ||||||||||||||||||
| 547 | EVPerr(EVP_F_EVP_PKEY_GET0_DH, EVP_R_EXPECTING_A_DH_KEY); | - | ||||||||||||||||||
| 548 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 549 | } | - | ||||||||||||||||||
| 550 | return pkey->pkey.dh; executed 274 times by 1 test: return pkey->pkey.dh;Executed by:
| 274 | ||||||||||||||||||
| 551 | } | - | ||||||||||||||||||
| 552 | - | |||||||||||||||||||
| 553 | DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 554 | { | - | ||||||||||||||||||
| 555 | DH *ret = EVP_PKEY_get0_DH(pkey); | - | ||||||||||||||||||
| 556 | if (ret != NULL)
| 0 | ||||||||||||||||||
| 557 | DH_up_ref(ret); never executed: DH_up_ref(ret); | 0 | ||||||||||||||||||
| 558 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
| 559 | } | - | ||||||||||||||||||
| 560 | #endif | - | ||||||||||||||||||
| 561 | - | |||||||||||||||||||
| 562 | int EVP_PKEY_type(int type) | - | ||||||||||||||||||
| 563 | { | - | ||||||||||||||||||
| 564 | int ret; | - | ||||||||||||||||||
| 565 | const EVP_PKEY_ASN1_METHOD *ameth; | - | ||||||||||||||||||
| 566 | ENGINE *e; | - | ||||||||||||||||||
| 567 | ameth = EVP_PKEY_asn1_find(&e, type); | - | ||||||||||||||||||
| 568 | if (ameth)
| 0-1373 | ||||||||||||||||||
| 569 | ret = ameth->pkey_id; executed 1373 times by 1 test: ret = ameth->pkey_id;Executed by:
| 1373 | ||||||||||||||||||
| 570 | else | - | ||||||||||||||||||
| 571 | ret = NID_undef; never executed: ret = 0; | 0 | ||||||||||||||||||
| 572 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
| 573 | ENGINE_finish(e); | - | ||||||||||||||||||
| 574 | #endif | - | ||||||||||||||||||
| 575 | return ret; executed 1373 times by 1 test: return ret;Executed by:
| 1373 | ||||||||||||||||||
| 576 | } | - | ||||||||||||||||||
| 577 | - | |||||||||||||||||||
| 578 | int EVP_PKEY_id(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 579 | { | - | ||||||||||||||||||
| 580 | return pkey->type; executed 38125 times by 1 test: return pkey->type;Executed by:
| 38125 | ||||||||||||||||||
| 581 | } | - | ||||||||||||||||||
| 582 | - | |||||||||||||||||||
| 583 | int EVP_PKEY_base_id(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 584 | { | - | ||||||||||||||||||
| 585 | return EVP_PKEY_type(pkey->type); executed 4 times by 1 test: return EVP_PKEY_type(pkey->type);Executed by:
| 4 | ||||||||||||||||||
| 586 | } | - | ||||||||||||||||||
| 587 | - | |||||||||||||||||||
| 588 | void EVP_PKEY_free(EVP_PKEY *x) | - | ||||||||||||||||||
| 589 | { | - | ||||||||||||||||||
| 590 | int i; | - | ||||||||||||||||||
| 591 | - | |||||||||||||||||||
| 592 | if (x == NULL)
| 348152-624970 | ||||||||||||||||||
| 593 | return; executed 624970 times by 1 test: return;Executed by:
| 624970 | ||||||||||||||||||
| 594 | - | |||||||||||||||||||
| 595 | CRYPTO_DOWN_REF(&x->references, &i, x->lock); | - | ||||||||||||||||||
| 596 | REF_PRINT_COUNT("EVP_PKEY", x); | - | ||||||||||||||||||
| 597 | if (i > 0)
| 98797-249355 | ||||||||||||||||||
| 598 | return; executed 249355 times by 1 test: return;Executed by:
| 249355 | ||||||||||||||||||
| 599 | REF_ASSERT_ISNT(i < 0); | - | ||||||||||||||||||
| 600 | EVP_PKEY_free_it(x); | - | ||||||||||||||||||
| 601 | CRYPTO_THREAD_lock_free(x->lock); | - | ||||||||||||||||||
| 602 | sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); | - | ||||||||||||||||||
| 603 | OPENSSL_free(x); | - | ||||||||||||||||||
| 604 | } executed 98797 times by 1 test: end of blockExecuted by:
| 98797 | ||||||||||||||||||
| 605 | - | |||||||||||||||||||
| 606 | static void EVP_PKEY_free_it(EVP_PKEY *x) | - | ||||||||||||||||||
| 607 | { | - | ||||||||||||||||||
| 608 | /* internal function; x is never NULL */ | - | ||||||||||||||||||
| 609 | if (x->ameth && x->ameth->pkey_free) {
| 0-97204 | ||||||||||||||||||
| 610 | x->ameth->pkey_free(x); | - | ||||||||||||||||||
| 611 | x->pkey.ptr = NULL; | - | ||||||||||||||||||
| 612 | } executed 97204 times by 1 test: end of blockExecuted by:
| 97204 | ||||||||||||||||||
| 613 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
| 614 | ENGINE_finish(x->engine); | - | ||||||||||||||||||
| 615 | x->engine = NULL; | - | ||||||||||||||||||
| 616 | ENGINE_finish(x->pmeth_engine); | - | ||||||||||||||||||
| 617 | x->pmeth_engine = NULL; | - | ||||||||||||||||||
| 618 | #endif | - | ||||||||||||||||||
| 619 | } executed 99387 times by 1 test: end of blockExecuted by:
| 99387 | ||||||||||||||||||
| 620 | - | |||||||||||||||||||
| 621 | static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent, | - | ||||||||||||||||||
| 622 | const char *kstr) | - | ||||||||||||||||||
| 623 | { | - | ||||||||||||||||||
| 624 | BIO_indent(out, indent, 128); | - | ||||||||||||||||||
| 625 | BIO_printf(out, "%s algorithm \"%s\" unsupported\n", | - | ||||||||||||||||||
| 626 | kstr, OBJ_nid2ln(pkey->type)); | - | ||||||||||||||||||
| 627 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
| 628 | } | - | ||||||||||||||||||
| 629 | - | |||||||||||||||||||
| 630 | int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, | - | ||||||||||||||||||
| 631 | int indent, ASN1_PCTX *pctx) | - | ||||||||||||||||||
| 632 | { | - | ||||||||||||||||||
| 633 | if (pkey->ameth && pkey->ameth->pub_print)
| 0-244 | ||||||||||||||||||
| 634 | return pkey->ameth->pub_print(out, pkey, indent, pctx); executed 244 times by 1 test: return pkey->ameth->pub_print(out, pkey, indent, pctx);Executed by:
| 244 | ||||||||||||||||||
| 635 | - | |||||||||||||||||||
| 636 | return unsup_alg(out, pkey, indent, "Public Key"); never executed: return unsup_alg(out, pkey, indent, "Public Key"); | 0 | ||||||||||||||||||
| 637 | } | - | ||||||||||||||||||
| 638 | - | |||||||||||||||||||
| 639 | int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, | - | ||||||||||||||||||
| 640 | int indent, ASN1_PCTX *pctx) | - | ||||||||||||||||||
| 641 | { | - | ||||||||||||||||||
| 642 | if (pkey->ameth && pkey->ameth->priv_print)
| 0-116 | ||||||||||||||||||
| 643 | return pkey->ameth->priv_print(out, pkey, indent, pctx); executed 116 times by 1 test: return pkey->ameth->priv_print(out, pkey, indent, pctx);Executed by:
| 116 | ||||||||||||||||||
| 644 | - | |||||||||||||||||||
| 645 | return unsup_alg(out, pkey, indent, "Private Key"); never executed: return unsup_alg(out, pkey, indent, "Private Key"); | 0 | ||||||||||||||||||
| 646 | } | - | ||||||||||||||||||
| 647 | - | |||||||||||||||||||
| 648 | int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, | - | ||||||||||||||||||
| 649 | int indent, ASN1_PCTX *pctx) | - | ||||||||||||||||||
| 650 | { | - | ||||||||||||||||||
| 651 | if (pkey->ameth && pkey->ameth->param_print)
| 0-13 | ||||||||||||||||||
| 652 | return pkey->ameth->param_print(out, pkey, indent, pctx); executed 13 times by 1 test: return pkey->ameth->param_print(out, pkey, indent, pctx);Executed by:
| 13 | ||||||||||||||||||
| 653 | return unsup_alg(out, pkey, indent, "Parameters"); never executed: return unsup_alg(out, pkey, indent, "Parameters"); | 0 | ||||||||||||||||||
| 654 | } | - | ||||||||||||||||||
| 655 | - | |||||||||||||||||||
| 656 | static int evp_pkey_asn1_ctrl(EVP_PKEY *pkey, int op, int arg1, void *arg2) | - | ||||||||||||||||||
| 657 | { | - | ||||||||||||||||||
| 658 | if (pkey->ameth == NULL || pkey->ameth->pkey_ctrl == NULL)
| 0-10282 | ||||||||||||||||||
| 659 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
| 660 | return pkey->ameth->pkey_ctrl(pkey, op, arg1, arg2); executed 10282 times by 1 test: return pkey->ameth->pkey_ctrl(pkey, op, arg1, arg2);Executed by:
| 10282 | ||||||||||||||||||
| 661 | } | - | ||||||||||||||||||
| 662 | - | |||||||||||||||||||
| 663 | int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid) | - | ||||||||||||||||||
| 664 | { | - | ||||||||||||||||||
| 665 | return evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID, 0, pnid); executed 104 times by 1 test: return evp_pkey_asn1_ctrl(pkey, 0x3, 0, pnid);Executed by:
| 104 | ||||||||||||||||||
| 666 | } | - | ||||||||||||||||||
| 667 | - | |||||||||||||||||||
| 668 | int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey, | - | ||||||||||||||||||
| 669 | const unsigned char *pt, size_t ptlen) | - | ||||||||||||||||||
| 670 | { | - | ||||||||||||||||||
| 671 | if (ptlen > INT_MAX)
| 0-3528 | ||||||||||||||||||
| 672 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 673 | if (evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_SET1_TLS_ENCPT, ptlen,
| 72-3456 | ||||||||||||||||||
| 674 | (void *)pt) <= 0)
| 72-3456 | ||||||||||||||||||
| 675 | return 0; executed 72 times by 1 test: return 0;Executed by:
| 72 | ||||||||||||||||||
| 676 | return 1; executed 3456 times by 1 test: return 1;Executed by:
| 3456 | ||||||||||||||||||
| 677 | } | - | ||||||||||||||||||
| 678 | - | |||||||||||||||||||
| 679 | size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt) | - | ||||||||||||||||||
| 680 | { | - | ||||||||||||||||||
| 681 | int rv; | - | ||||||||||||||||||
| 682 | rv = evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_GET1_TLS_ENCPT, 0, ppt); | - | ||||||||||||||||||
| 683 | if (rv <= 0)
| 0-6650 | ||||||||||||||||||
| 684 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 685 | return rv; executed 6650 times by 1 test: return rv;Executed by:
| 6650 | ||||||||||||||||||
| 686 | } | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |