| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ec_ameth.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | static int ecdh_cms_decrypt(CMS_RecipientInfo *ri); | - | ||||||||||||||||||
| 6 | static int ecdh_cms_encrypt(CMS_RecipientInfo *ri); | - | ||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | static int eckey_param2type(int *pptype, void **ppval, EC_KEY *ec_key) | - | ||||||||||||||||||
| 10 | { | - | ||||||||||||||||||
| 11 | const EC_GROUP *group; | - | ||||||||||||||||||
| 12 | int nid; | - | ||||||||||||||||||
| 13 | if (ec_key ==
| 0-13092 | ||||||||||||||||||
| 14 | ((void *)0)
| 0-13092 | ||||||||||||||||||
| 15 | || (
| 0-13092 | ||||||||||||||||||
| 16 | ((void *)0)
| 0-13092 | ||||||||||||||||||
| 17 | ) { | - | ||||||||||||||||||
| 18 | ERR_put_error(16,(223),(124),__FILE__,31); | - | ||||||||||||||||||
| 19 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 20 | } | - | ||||||||||||||||||
| 21 | if (EC_GROUP_get_asn1_flag(group)
| 0-13092 | ||||||||||||||||||
| 22 | && (
| 0-13092 | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | { | - | ||||||||||||||||||
| 25 | *ppval = OBJ_nid2obj(nid); | - | ||||||||||||||||||
| 26 | *pptype = 6; | - | ||||||||||||||||||
| 27 | } executed 13092 times by 1 test: else {end of blockExecuted by:
| 13092 | ||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | ASN1_STRING *pstr = | - | ||||||||||||||||||
| 30 | ((void *)0) | - | ||||||||||||||||||
| 31 | ; | - | ||||||||||||||||||
| 32 | pstr = ASN1_STRING_new(); | - | ||||||||||||||||||
| 33 | if (pstr ==
| 0 | ||||||||||||||||||
| 34 | ((void *)0)
| 0 | ||||||||||||||||||
| 35 | ) | - | ||||||||||||||||||
| 36 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 37 | pstr->length = i2d_ECParameters(ec_key, &pstr->data); | - | ||||||||||||||||||
| 38 | if (pstr->length <= 0
| 0 | ||||||||||||||||||
| 39 | ASN1_STRING_free(pstr); | - | ||||||||||||||||||
| 40 | ERR_put_error(16,(223),(16),__FILE__,49); | - | ||||||||||||||||||
| 41 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 42 | } | - | ||||||||||||||||||
| 43 | *ppval = pstr; | - | ||||||||||||||||||
| 44 | *pptype = 16; | - | ||||||||||||||||||
| 45 | } never executed: end of block | 0 | ||||||||||||||||||
| 46 | return executed 13092 times by 1 test: 1;return 1;Executed by:
executed 13092 times by 1 test: return 1;Executed by:
| 13092 | ||||||||||||||||||
| 47 | } | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | static int eckey_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 50 | { | - | ||||||||||||||||||
| 51 | EC_KEY *ec_key = pkey->pkey.ec; | - | ||||||||||||||||||
| 52 | void *pval = | - | ||||||||||||||||||
| 53 | ((void *)0) | - | ||||||||||||||||||
| 54 | ; | - | ||||||||||||||||||
| 55 | int ptype; | - | ||||||||||||||||||
| 56 | unsigned char *penc = | - | ||||||||||||||||||
| 57 | ((void *)0) | - | ||||||||||||||||||
| 58 | , *p; | - | ||||||||||||||||||
| 59 | int penclen; | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | if (!eckey_param2type(&ptype, &pval, ec_key)
| 0-13087 | ||||||||||||||||||
| 62 | ERR_put_error(16,(216),(16),__FILE__,67); | - | ||||||||||||||||||
| 63 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 64 | } | - | ||||||||||||||||||
| 65 | penclen = i2o_ECPublicKey(ec_key, | - | ||||||||||||||||||
| 66 | ((void *)0) | - | ||||||||||||||||||
| 67 | ); | - | ||||||||||||||||||
| 68 | if (penclen <= 0
| 0-13087 | ||||||||||||||||||
| 69 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 70 | penc = CRYPTO_malloc(penclen, __FILE__, 73); | - | ||||||||||||||||||
| 71 | if (penc ==
| 0-13087 | ||||||||||||||||||
| 72 | ((void *)0)
| 0-13087 | ||||||||||||||||||
| 73 | ) | - | ||||||||||||||||||
| 74 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 75 | p = penc; | - | ||||||||||||||||||
| 76 | penclen = i2o_ECPublicKey(ec_key, &p); | - | ||||||||||||||||||
| 77 | if (penclen <= 0
| 0-13087 | ||||||||||||||||||
| 78 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 79 | if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(408),
| 0-13087 | ||||||||||||||||||
| 80 | ptype, pval, penc, penclen)
| 0-13087 | ||||||||||||||||||
| 81 | return executed 13087 times by 1 test: 1;return 1;Executed by:
executed 13087 times by 1 test: return 1;Executed by:
| 13087 | ||||||||||||||||||
| 82 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||
| 83 | if (ptype == 6
| 0 | ||||||||||||||||||
| 84 | ASN1_OBJECT_free(pval); never executed: ASN1_OBJECT_free(pval); | 0 | ||||||||||||||||||
| 85 | else | - | ||||||||||||||||||
| 86 | ASN1_STRING_free(pval); never executed: ASN1_STRING_free(pval); | 0 | ||||||||||||||||||
| 87 | CRYPTO_free(penc, __FILE__, 88); | - | ||||||||||||||||||
| 88 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 89 | } | - | ||||||||||||||||||
| 90 | - | |||||||||||||||||||
| 91 | static EC_KEY *eckey_type2param(int ptype, const void *pval) | - | ||||||||||||||||||
| 92 | { | - | ||||||||||||||||||
| 93 | EC_KEY *eckey = | - | ||||||||||||||||||
| 94 | ((void *)0) | - | ||||||||||||||||||
| 95 | ; | - | ||||||||||||||||||
| 96 | EC_GROUP *group = | - | ||||||||||||||||||
| 97 | ((void *)0) | - | ||||||||||||||||||
| 98 | ; | - | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | if (ptype == 16
| 1917-32187 | ||||||||||||||||||
| 101 | const ASN1_STRING *pstr = pval; | - | ||||||||||||||||||
| 102 | const unsigned char *pm = pstr->data; | - | ||||||||||||||||||
| 103 | int pmlen = pstr->length; | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | if ((
| 109-1808 | ||||||||||||||||||
| 106 | ((void *)0)
| 109-1808 | ||||||||||||||||||
| 107 | , &pm, pmlen)) ==
| 109-1808 | ||||||||||||||||||
| 108 | ((void *)0)
| 109-1808 | ||||||||||||||||||
| 109 | ) { | - | ||||||||||||||||||
| 110 | ERR_put_error(16,(220),(142),__FILE__,103); | - | ||||||||||||||||||
| 111 | goto executed 1808 times by 1 test: ecerr;goto ecerr;Executed by:
executed 1808 times by 1 test: goto ecerr;Executed by:
| 1808 | ||||||||||||||||||
| 112 | } | - | ||||||||||||||||||
| 113 | } executed 109 times by 1 test: else if (ptype == 6end of blockExecuted by:
| 109-31933 | ||||||||||||||||||
| 114 | const ASN1_OBJECT *poid = pval; | - | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | if ((
| 0-31933 | ||||||||||||||||||
| 120 | ((void *)0)
| 0-31933 | ||||||||||||||||||
| 121 | ) { | - | ||||||||||||||||||
| 122 | ERR_put_error(16,(220),((1|64)),__FILE__,113); | - | ||||||||||||||||||
| 123 | goto never executed: ecerr;goto ecerr;never executed: goto ecerr; | 0 | ||||||||||||||||||
| 124 | } | - | ||||||||||||||||||
| 125 | group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(poid)); | - | ||||||||||||||||||
| 126 | if (group ==
| 191-31742 | ||||||||||||||||||
| 127 | ((void *)0)
| 191-31742 | ||||||||||||||||||
| 128 | ) | - | ||||||||||||||||||
| 129 | goto executed 191 times by 1 test: ecerr;goto ecerr;Executed by:
executed 191 times by 1 test: goto ecerr;Executed by:
| 191 | ||||||||||||||||||
| 130 | EC_GROUP_set_asn1_flag(group, 0x001); | - | ||||||||||||||||||
| 131 | if (EC_KEY_set_group(eckey, group) == 0
| 0-31742 | ||||||||||||||||||
| 132 | goto never executed: ecerr;goto ecerr;never executed: goto ecerr; | 0 | ||||||||||||||||||
| 133 | EC_GROUP_free(group); | - | ||||||||||||||||||
| 134 | } executed 31742 times by 1 test: else {end of blockExecuted by:
| 31742 | ||||||||||||||||||
| 135 | ERR_put_error(16,(220),(142),__FILE__,124); | - | ||||||||||||||||||
| 136 | goto executed 254 times by 1 test: ecerr;goto ecerr;Executed by:
executed 254 times by 1 test: goto ecerr;Executed by:
| 254 | ||||||||||||||||||
| 137 | } | - | ||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | return executed 31851 times by 1 test: eckey;return eckey;Executed by:
executed 31851 times by 1 test: return eckey;Executed by:
| 31851 | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | ecerr: | - | ||||||||||||||||||
| 142 | EC_KEY_free(eckey); | - | ||||||||||||||||||
| 143 | EC_GROUP_free(group); | - | ||||||||||||||||||
| 144 | return executed 2253 times by 1 test: return ((void *)0) ;Executed by:
executed 2253 times by 1 test: return ((void *)0) ;Executed by:
| 2253 | ||||||||||||||||||
| 145 | ((void *)0) executed 2253 times by 1 test: return ((void *)0) ;Executed by:
| 2253 | ||||||||||||||||||
| 146 | ; executed 2253 times by 1 test: return ((void *)0) ;Executed by:
| 2253 | ||||||||||||||||||
| 147 | } | - | ||||||||||||||||||
| 148 | - | |||||||||||||||||||
| 149 | static int eckey_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) | - | ||||||||||||||||||
| 150 | { | - | ||||||||||||||||||
| 151 | const unsigned char *p = | - | ||||||||||||||||||
| 152 | ((void *)0) | - | ||||||||||||||||||
| 153 | ; | - | ||||||||||||||||||
| 154 | const void *pval; | - | ||||||||||||||||||
| 155 | int ptype, pklen; | - | ||||||||||||||||||
| 156 | EC_KEY *eckey = | - | ||||||||||||||||||
| 157 | ((void *)0) | - | ||||||||||||||||||
| 158 | ; | - | ||||||||||||||||||
| 159 | X509_ALGOR *palg; | - | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | if (!X509_PUBKEY_get0_param(
| 0-33133 | ||||||||||||||||||
| 162 | ((void *)0)
| 0-33133 | ||||||||||||||||||
| 163 | , &p, &pklen, &palg, pubkey)
| 0-33133 | ||||||||||||||||||
| 164 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 165 | X509_ALGOR_get0( | - | ||||||||||||||||||
| 166 | ((void *)0) | - | ||||||||||||||||||
| 167 | , &ptype, &pval, palg); | - | ||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | eckey = eckey_type2param(ptype, pval); | - | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | if (!eckey
| 2252-30881 | ||||||||||||||||||
| 172 | ERR_put_error(16,(215),(16),__FILE__,151); | - | ||||||||||||||||||
| 173 | return executed 2252 times by 1 test: 0;return 0;Executed by:
executed 2252 times by 1 test: return 0;Executed by:
| 2252 | ||||||||||||||||||
| 174 | } | - | ||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | if (!o2i_ECPublicKey(&eckey, &p, pklen)
| 7011-23870 | ||||||||||||||||||
| 178 | ERR_put_error(16,(215),(142),__FILE__,157); | - | ||||||||||||||||||
| 179 | goto executed 7011 times by 1 test: ecerr;goto ecerr;Executed by:
executed 7011 times by 1 test: goto ecerr;Executed by:
| 7011 | ||||||||||||||||||
| 180 | } | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | EVP_PKEY_assign((pkey),408, (char *)(eckey)); | - | ||||||||||||||||||
| 183 | return executed 23870 times by 1 test: 1;return 1;Executed by:
executed 23870 times by 1 test: return 1;Executed by:
| 23870 | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | ecerr: | - | ||||||||||||||||||
| 186 | EC_KEY_free(eckey); | - | ||||||||||||||||||
| 187 | return executed 7011 times by 1 test: 0;return 0;Executed by:
executed 7011 times by 1 test: return 0;Executed by:
| 7011 | ||||||||||||||||||
| 188 | } | - | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | static int eckey_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b) | - | ||||||||||||||||||
| 191 | { | - | ||||||||||||||||||
| 192 | int r; | - | ||||||||||||||||||
| 193 | const EC_GROUP *group = EC_KEY_get0_group(b->pkey.ec); | - | ||||||||||||||||||
| 194 | const EC_POINT *pa = EC_KEY_get0_public_key(a->pkey.ec), | - | ||||||||||||||||||
| 195 | *pb = EC_KEY_get0_public_key(b->pkey.ec); | - | ||||||||||||||||||
| 196 | if (group ==
| 0-2748 | ||||||||||||||||||
| 197 | ((void *)0)
| 0-2748 | ||||||||||||||||||
| 198 | || pa ==
| 0-2748 | ||||||||||||||||||
| 199 | ((void *)0)
| 0-2748 | ||||||||||||||||||
| 200 | || pb ==
| 0-2748 | ||||||||||||||||||
| 201 | ((void *)0)
| 0-2748 | ||||||||||||||||||
| 202 | ) | - | ||||||||||||||||||
| 203 | return never executed: -2;return -2;never executed: return -2; | 0 | ||||||||||||||||||
| 204 | r = EC_POINT_cmp(group, pa, pb, | - | ||||||||||||||||||
| 205 | ((void *)0) | - | ||||||||||||||||||
| 206 | ); | - | ||||||||||||||||||
| 207 | if (r == 0
| 0-2748 | ||||||||||||||||||
| 208 | return executed 2748 times by 1 test: 1;return 1;Executed by:
executed 2748 times by 1 test: return 1;Executed by:
| 2748 | ||||||||||||||||||
| 209 | if (r == 1
| 0 | ||||||||||||||||||
| 210 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 211 | return never executed: -2;return -2;never executed: return -2; | 0 | ||||||||||||||||||
| 212 | } | - | ||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | static int eckey_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) | - | ||||||||||||||||||
| 215 | { | - | ||||||||||||||||||
| 216 | const unsigned char *p = | - | ||||||||||||||||||
| 217 | ((void *)0) | - | ||||||||||||||||||
| 218 | ; | - | ||||||||||||||||||
| 219 | const void *pval; | - | ||||||||||||||||||
| 220 | int ptype, pklen; | - | ||||||||||||||||||
| 221 | EC_KEY *eckey = | - | ||||||||||||||||||
| 222 | ((void *)0) | - | ||||||||||||||||||
| 223 | ; | - | ||||||||||||||||||
| 224 | const X509_ALGOR *palg; | - | ||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | if (!PKCS8_pkey_get0(
| 0-971 | ||||||||||||||||||
| 227 | ((void *)0)
| 0-971 | ||||||||||||||||||
| 228 | , &p, &pklen, &palg, p8)
| 0-971 | ||||||||||||||||||
| 229 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 230 | X509_ALGOR_get0( | - | ||||||||||||||||||
| 231 | ((void *)0) | - | ||||||||||||||||||
| 232 | , &ptype, &pval, palg); | - | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | eckey = eckey_type2param(ptype, pval); | - | ||||||||||||||||||
| 235 | - | |||||||||||||||||||
| 236 | if (!eckey
| 1-970 | ||||||||||||||||||
| 237 | goto executed 1 time by 1 test: ecliberr;goto ecliberr;Executed by:
executed 1 time by 1 test: goto ecliberr;Executed by:
| 1 | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | if (!d2i_ECPrivateKey(&eckey, &p, pklen)
| 2-968 | ||||||||||||||||||
| 241 | ERR_put_error(16,(213),(142),__FILE__,204); | - | ||||||||||||||||||
| 242 | goto executed 2 times by 1 test: ecerr;goto ecerr;Executed by:
executed 2 times by 1 test: goto ecerr;Executed by:
| 2 | ||||||||||||||||||
| 243 | } | - | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | EVP_PKEY_assign((pkey),408, (char *)(eckey)); | - | ||||||||||||||||||
| 246 | return executed 968 times by 1 test: 1;return 1;Executed by:
executed 968 times by 1 test: return 1;Executed by:
| 968 | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | ecliberr: | - | ||||||||||||||||||
| 249 | ERR_put_error(16,(213),(16),__FILE__,212); | - | ||||||||||||||||||
| 250 | ecerr: code before this statement executed 1 time by 1 test: ecerr:Executed by:
| 1 | ||||||||||||||||||
| 251 | EC_KEY_free(eckey); | - | ||||||||||||||||||
| 252 | return executed 3 times by 1 test: 0;return 0;Executed by:
executed 3 times by 1 test: return 0;Executed by:
| 3 | ||||||||||||||||||
| 253 | } | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | static int eckey_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 256 | { | - | ||||||||||||||||||
| 257 | EC_KEY ec_key = *(pkey->pkey.ec); | - | ||||||||||||||||||
| 258 | unsigned char *ep, *p; | - | ||||||||||||||||||
| 259 | int eplen, ptype; | - | ||||||||||||||||||
| 260 | void *pval; | - | ||||||||||||||||||
| 261 | unsigned int old_flags; | - | ||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | if (!eckey_param2type(&ptype, &pval, &ec_key)
| 0-5 | ||||||||||||||||||
| 264 | ERR_put_error(16,(214),(142),__FILE__,227); | - | ||||||||||||||||||
| 265 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 266 | } | - | ||||||||||||||||||
| 267 | - | |||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | old_flags = EC_KEY_get_enc_flags(&ec_key); | - | ||||||||||||||||||
| 275 | EC_KEY_set_enc_flags(&ec_key, old_flags | 0x001); | - | ||||||||||||||||||
| 276 | - | |||||||||||||||||||
| 277 | eplen = i2d_ECPrivateKey(&ec_key, | - | ||||||||||||||||||
| 278 | ((void *)0) | - | ||||||||||||||||||
| 279 | ); | - | ||||||||||||||||||
| 280 | if (!eplen
| 0-5 | ||||||||||||||||||
| 281 | ERR_put_error(16,(214),(16),__FILE__,242); | - | ||||||||||||||||||
| 282 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 283 | } | - | ||||||||||||||||||
| 284 | ep = CRYPTO_malloc(eplen, __FILE__, 245); | - | ||||||||||||||||||
| 285 | if (ep ==
| 0-5 | ||||||||||||||||||
| 286 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 287 | ) { | - | ||||||||||||||||||
| 288 | ERR_put_error(16,(214),((1|64)),__FILE__,247); | - | ||||||||||||||||||
| 289 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 290 | } | - | ||||||||||||||||||
| 291 | p = ep; | - | ||||||||||||||||||
| 292 | if (!i2d_ECPrivateKey(&ec_key, &p)
| 0-5 | ||||||||||||||||||
| 293 | CRYPTO_free(ep, __FILE__, 252); | - | ||||||||||||||||||
| 294 | ERR_put_error(16,(214),(16),__FILE__,253); | - | ||||||||||||||||||
| 295 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 296 | } | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(408), 0,
| 0-5 | ||||||||||||||||||
| 299 | ptype, pval, ep, eplen)
| 0-5 | ||||||||||||||||||
| 300 | CRYPTO_free(ep, __FILE__, 259); | - | ||||||||||||||||||
| 301 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 302 | } | - | ||||||||||||||||||
| 303 | - | |||||||||||||||||||
| 304 | return executed 5 times by 1 test: 1;return 1;Executed by:
executed 5 times by 1 test: return 1;Executed by:
| 5 | ||||||||||||||||||
| 305 | } | - | ||||||||||||||||||
| 306 | - | |||||||||||||||||||
| 307 | static int int_ec_size(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 308 | { | - | ||||||||||||||||||
| 309 | return executed 482 times by 1 test: ECDSA_size(pkey->pkey.ec);return ECDSA_size(pkey->pkey.ec);Executed by:
executed 482 times by 1 test: return ECDSA_size(pkey->pkey.ec);Executed by:
| 482 | ||||||||||||||||||
| 310 | } | - | ||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | static int ec_bits(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 313 | { | - | ||||||||||||||||||
| 314 | return executed 2374 times by 1 test: EC_GROUP_order_bits(EC_KEY_get0_group(pkey->pkey.ec));return EC_GROUP_order_bits(EC_KEY_get0_group(pkey->pkey.ec));Executed by:
executed 2374 times by 1 test: return EC_GROUP_order_bits(EC_KEY_get0_group(pkey->pkey.ec));Executed by:
| 2374 | ||||||||||||||||||
| 315 | } | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | static int ec_security_bits(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 318 | { | - | ||||||||||||||||||
| 319 | int ecbits = ec_bits(pkey); | - | ||||||||||||||||||
| 320 | if (ecbits >= 512
| 0-2342 | ||||||||||||||||||
| 321 | return never executed: 256;return 256;never executed: return 256; | 0 | ||||||||||||||||||
| 322 | if (ecbits >= 384
| 5-2337 | ||||||||||||||||||
| 323 | return executed 5 times by 1 test: 192;return 192;Executed by:
executed 5 times by 1 test: return 192;Executed by:
| 5 | ||||||||||||||||||
| 324 | if (ecbits >= 256
| 0-2337 | ||||||||||||||||||
| 325 | return executed 2337 times by 1 test: 128;return 128;Executed by:
executed 2337 times by 1 test: return 128;Executed by:
| 2337 | ||||||||||||||||||
| 326 | if (ecbits >= 224
| 0 | ||||||||||||||||||
| 327 | return never executed: 112;return 112;never executed: return 112; | 0 | ||||||||||||||||||
| 328 | if (ecbits >= 160
| 0 | ||||||||||||||||||
| 329 | return never executed: 80;return 80;never executed: return 80; | 0 | ||||||||||||||||||
| 330 | return never executed: ecbits / 2;return ecbits / 2;never executed: return ecbits / 2; | 0 | ||||||||||||||||||
| 331 | } | - | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | static int ec_missing_parameters(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 334 | { | - | ||||||||||||||||||
| 335 | if (pkey->pkey.ec ==
| 150-6645 | ||||||||||||||||||
| 336 | ((void *)0)
| 150-6645 | ||||||||||||||||||
| 337 | || EC_KEY_get0_group(pkey->pkey.ec) ==
| 209-6436 | ||||||||||||||||||
| 338 | ((void *)0)
| 209-6436 | ||||||||||||||||||
| 339 | ) | - | ||||||||||||||||||
| 340 | return executed 359 times by 1 test: 1;return 1;Executed by:
executed 359 times by 1 test: return 1;Executed by:
| 359 | ||||||||||||||||||
| 341 | return executed 6436 times by 1 test: 0;return 0;Executed by:
executed 6436 times by 1 test: return 0;Executed by:
| 6436 | ||||||||||||||||||
| 342 | } | - | ||||||||||||||||||
| 343 | - | |||||||||||||||||||
| 344 | static int ec_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) | - | ||||||||||||||||||
| 345 | { | - | ||||||||||||||||||
| 346 | EC_GROUP *group = EC_GROUP_dup(EC_KEY_get0_group(from->pkey.ec)); | - | ||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | if (group ==
| 0-359 | ||||||||||||||||||
| 349 | ((void *)0)
| 0-359 | ||||||||||||||||||
| 350 | ) | - | ||||||||||||||||||
| 351 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 352 | if (to->pkey.ec ==
| 150-209 | ||||||||||||||||||
| 353 | ((void *)0)
| 150-209 | ||||||||||||||||||
| 354 | ) { | - | ||||||||||||||||||
| 355 | to->pkey.ec = EC_KEY_new(); | - | ||||||||||||||||||
| 356 | if (to->pkey.ec ==
| 0-150 | ||||||||||||||||||
| 357 | ((void *)0)
| 0-150 | ||||||||||||||||||
| 358 | ) | - | ||||||||||||||||||
| 359 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 360 | } executed 150 times by 1 test: end of blockExecuted by:
| 150 | ||||||||||||||||||
| 361 | if (EC_KEY_set_group(to->pkey.ec, group) == 0
| 0-359 | ||||||||||||||||||
| 362 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 363 | EC_GROUP_free(group); | - | ||||||||||||||||||
| 364 | return executed 359 times by 1 test: 1;return 1;Executed by:
executed 359 times by 1 test: return 1;Executed by:
| 359 | ||||||||||||||||||
| 365 | err: | - | ||||||||||||||||||
| 366 | EC_GROUP_free(group); | - | ||||||||||||||||||
| 367 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 368 | } | - | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) | - | ||||||||||||||||||
| 371 | { | - | ||||||||||||||||||
| 372 | const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec), | - | ||||||||||||||||||
| 373 | *group_b = EC_KEY_get0_group(b->pkey.ec); | - | ||||||||||||||||||
| 374 | if (group_a ==
| 0-5991 | ||||||||||||||||||
| 375 | ((void *)0)
| 0-5991 | ||||||||||||||||||
| 376 | || group_b ==
| 0-5991 | ||||||||||||||||||
| 377 | ((void *)0)
| 0-5991 | ||||||||||||||||||
| 378 | ) | - | ||||||||||||||||||
| 379 | return never executed: -2;return -2;never executed: return -2; | 0 | ||||||||||||||||||
| 380 | if (EC_GROUP_cmp(group_a, group_b,
| 0-5991 | ||||||||||||||||||
| 381 | ((void *)0)
| 0-5991 | ||||||||||||||||||
| 382 | )
| 0-5991 | ||||||||||||||||||
| 383 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 384 | else | - | ||||||||||||||||||
| 385 | return executed 5991 times by 1 test: 1;return 1;Executed by:
executed 5991 times by 1 test: return 1;Executed by:
| 5991 | ||||||||||||||||||
| 386 | } | - | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | static void int_ec_free(EVP_PKEY *pkey) | - | ||||||||||||||||||
| 389 | { | - | ||||||||||||||||||
| 390 | EC_KEY_free(pkey->pkey.ec); | - | ||||||||||||||||||
| 391 | } executed 39224 times by 1 test: end of blockExecuted by:
| 39224 | ||||||||||||||||||
| 392 | - | |||||||||||||||||||
| 393 | typedef enum { | - | ||||||||||||||||||
| 394 | EC_KEY_PRINT_PRIVATE, | - | ||||||||||||||||||
| 395 | EC_KEY_PRINT_PUBLIC, | - | ||||||||||||||||||
| 396 | EC_KEY_PRINT_PARAM | - | ||||||||||||||||||
| 397 | } ec_print_t; | - | ||||||||||||||||||
| 398 | - | |||||||||||||||||||
| 399 | static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, ec_print_t ktype) | - | ||||||||||||||||||
| 400 | { | - | ||||||||||||||||||
| 401 | const char *ecstr; | - | ||||||||||||||||||
| 402 | unsigned char *priv = | - | ||||||||||||||||||
| 403 | ((void *)0) | - | ||||||||||||||||||
| 404 | , *pub = | - | ||||||||||||||||||
| 405 | ((void *)0) | - | ||||||||||||||||||
| 406 | ; | - | ||||||||||||||||||
| 407 | size_t privlen = 0, publen = 0; | - | ||||||||||||||||||
| 408 | int ret = 0; | - | ||||||||||||||||||
| 409 | const EC_GROUP *group; | - | ||||||||||||||||||
| 410 | - | |||||||||||||||||||
| 411 | if (x ==
| 0-298 | ||||||||||||||||||
| 412 | ((void *)0)
| 0-298 | ||||||||||||||||||
| 413 | || (
| 0-298 | ||||||||||||||||||
| 414 | ((void *)0)
| 0-298 | ||||||||||||||||||
| 415 | ) { | - | ||||||||||||||||||
| 416 | ERR_put_error(16,(221),((3|64)),__FILE__,351); | - | ||||||||||||||||||
| 417 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 418 | } | - | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | if (ktype != EC_KEY_PRINT_PARAM
| 0-276 | ||||||||||||||||||
| 421 | ((void *)0)
| 0-276 | ||||||||||||||||||
| 422 | ) { | - | ||||||||||||||||||
| 423 | publen = EC_KEY_key2buf(x, EC_KEY_get_conv_form(x), &pub, | - | ||||||||||||||||||
| 424 | ((void *)0) | - | ||||||||||||||||||
| 425 | ); | - | ||||||||||||||||||
| 426 | if (publen == 0
| 2-274 | ||||||||||||||||||
| 427 | goto executed 2 times by 1 test: err;goto err;Executed by:
executed 2 times by 1 test: goto err;Executed by:
| 2 | ||||||||||||||||||
| 428 | } executed 274 times by 1 test: end of blockExecuted by:
| 274 | ||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | if (ktype == EC_KEY_PRINT_PRIVATE
| 0-227 | ||||||||||||||||||
| 431 | ((void *)0)
| 0-227 | ||||||||||||||||||
| 432 | ) { | - | ||||||||||||||||||
| 433 | privlen = EC_KEY_priv2buf(x, &priv); | - | ||||||||||||||||||
| 434 | if (privlen == 0
| 39-188 | ||||||||||||||||||
| 435 | goto executed 39 times by 1 test: err;goto err;Executed by:
executed 39 times by 1 test: goto err;Executed by:
| 39 | ||||||||||||||||||
| 436 | } executed 188 times by 1 test: end of blockExecuted by:
| 188 | ||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | if (ktype == EC_KEY_PRINT_PRIVATE
| 69-188 | ||||||||||||||||||
| 439 | ecstr = "Private-Key"; executed 188 times by 1 test: ecstr = "Private-Key";Executed by:
| 188 | ||||||||||||||||||
| 440 | else if (ktype == EC_KEY_PRINT_PUBLIC
| 22-47 | ||||||||||||||||||
| 441 | ecstr = "Public-Key"; executed 47 times by 1 test: ecstr = "Public-Key";Executed by:
| 47 | ||||||||||||||||||
| 442 | else | - | ||||||||||||||||||
| 443 | ecstr = "ECDSA-Parameters"; executed 22 times by 1 test: ecstr = "ECDSA-Parameters";Executed by:
| 22 | ||||||||||||||||||
| 444 | - | |||||||||||||||||||
| 445 | if (!BIO_indent(bp, off, 128)
| 0-257 | ||||||||||||||||||
| 446 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 447 | if (BIO_printf(bp, "%s: (%d bit)\n", ecstr,
| 0-257 | ||||||||||||||||||
| 448 | EC_GROUP_order_bits(group)) <= 0
| 0-257 | ||||||||||||||||||
| 449 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | if (privlen != 0
| 69-188 | ||||||||||||||||||
| 452 | if (BIO_printf(bp, "%*spriv:\n", off, "") <= 0
| 0-188 | ||||||||||||||||||
| 453 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 454 | if (ASN1_buf_print(bp, priv, privlen, off + 4) == 0
| 0-188 | ||||||||||||||||||
| 455 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 456 | } executed 188 times by 1 test: end of blockExecuted by:
| 188 | ||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | if (publen != 0
| 22-235 | ||||||||||||||||||
| 459 | if (BIO_printf(bp, "%*spub:\n", off, "") <= 0
| 0-235 | ||||||||||||||||||
| 460 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 461 | if (ASN1_buf_print(bp, pub, publen, off + 4) == 0
| 0-235 | ||||||||||||||||||
| 462 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 463 | } executed 235 times by 1 test: end of blockExecuted by:
| 235 | ||||||||||||||||||
| 464 | - | |||||||||||||||||||
| 465 | if (!ECPKParameters_print(bp, group, off)
| 0-257 | ||||||||||||||||||
| 466 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 467 | ret = 1; | - | ||||||||||||||||||
| 468 | err: code before this statement executed 257 times by 1 test: err:Executed by:
| 257 | ||||||||||||||||||
| 469 | if (!ret
| 41-257 | ||||||||||||||||||
| 470 | ERR_put_error(16,(221),(16),__FILE__,399); executed 41 times by 1 test: ERR_put_error(16,(221),(16),__FILE__,399);Executed by:
| 41 | ||||||||||||||||||
| 471 | CRYPTO_clear_free(priv, privlen, __FILE__, 400); | - | ||||||||||||||||||
| 472 | CRYPTO_free(pub, __FILE__, 401); | - | ||||||||||||||||||
| 473 | return executed 298 times by 1 test: ret;return ret;Executed by:
executed 298 times by 1 test: return ret;Executed by:
| 298 | ||||||||||||||||||
| 474 | } | - | ||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | static int eckey_param_decode(EVP_PKEY *pkey, | - | ||||||||||||||||||
| 477 | const unsigned char **pder, int derlen) | - | ||||||||||||||||||
| 478 | { | - | ||||||||||||||||||
| 479 | EC_KEY *eckey; | - | ||||||||||||||||||
| 480 | - | |||||||||||||||||||
| 481 | if ((
| 0-1 | ||||||||||||||||||
| 482 | ((void *)0)
| 0-1 | ||||||||||||||||||
| 483 | , pder, derlen)) ==
| 0-1 | ||||||||||||||||||
| 484 | ((void *)0)
| 0-1 | ||||||||||||||||||
| 485 | ) { | - | ||||||||||||||||||
| 486 | ERR_put_error(16,(212),(16),__FILE__,411); | - | ||||||||||||||||||
| 487 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 488 | } | - | ||||||||||||||||||
| 489 | EVP_PKEY_assign((pkey),408, (char *)(eckey)); | - | ||||||||||||||||||
| 490 | return executed 1 time by 1 test: 1;return 1;Executed by:
executed 1 time by 1 test: return 1;Executed by:
| 1 | ||||||||||||||||||
| 491 | } | - | ||||||||||||||||||
| 492 | - | |||||||||||||||||||
| 493 | static int eckey_param_encode(const EVP_PKEY *pkey, unsigned char **pder) | - | ||||||||||||||||||
| 494 | { | - | ||||||||||||||||||
| 495 | return never executed: i2d_ECParameters(pkey->pkey.ec, pder);return i2d_ECParameters(pkey->pkey.ec, pder);never executed: return i2d_ECParameters(pkey->pkey.ec, pder); | 0 | ||||||||||||||||||
| 496 | } | - | ||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | static int eckey_param_print(BIO *bp, const EVP_PKEY *pkey, int indent, | - | ||||||||||||||||||
| 499 | ASN1_PCTX *ctx) | - | ||||||||||||||||||
| 500 | { | - | ||||||||||||||||||
| 501 | return never executed: do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PARAM);return do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PARAM);never executed: return do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PARAM); | 0 | ||||||||||||||||||
| 502 | } | - | ||||||||||||||||||
| 503 | - | |||||||||||||||||||
| 504 | static int eckey_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent, | - | ||||||||||||||||||
| 505 | ASN1_PCTX *ctx) | - | ||||||||||||||||||
| 506 | { | - | ||||||||||||||||||
| 507 | return executed 49 times by 1 test: do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PUBLIC);return do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PUBLIC);Executed by:
executed 49 times by 1 test: return do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PUBLIC);Executed by:
| 49 | ||||||||||||||||||
| 508 | } | - | ||||||||||||||||||
| 509 | - | |||||||||||||||||||
| 510 | static int eckey_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent, | - | ||||||||||||||||||
| 511 | ASN1_PCTX *ctx) | - | ||||||||||||||||||
| 512 | { | - | ||||||||||||||||||
| 513 | return never executed: do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PRIVATE);return do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PRIVATE);never executed: return do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PRIVATE); | 0 | ||||||||||||||||||
| 514 | } | - | ||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | static int old_ec_priv_decode(EVP_PKEY *pkey, | - | ||||||||||||||||||
| 517 | const unsigned char **pder, int derlen) | - | ||||||||||||||||||
| 518 | { | - | ||||||||||||||||||
| 519 | EC_KEY *ec; | - | ||||||||||||||||||
| 520 | - | |||||||||||||||||||
| 521 | if ((
| 245-1812 | ||||||||||||||||||
| 522 | ((void *)0)
| 245-1812 | ||||||||||||||||||
| 523 | , pder, derlen)) ==
| 245-1812 | ||||||||||||||||||
| 524 | ((void *)0)
| 245-1812 | ||||||||||||||||||
| 525 | ) { | - | ||||||||||||||||||
| 526 | ERR_put_error(16,(222),(142),__FILE__,447); | - | ||||||||||||||||||
| 527 | return executed 245 times by 1 test: 0;return 0;Executed by:
executed 245 times by 1 test: return 0;Executed by:
| 245 | ||||||||||||||||||
| 528 | } | - | ||||||||||||||||||
| 529 | EVP_PKEY_assign((pkey),408, (char *)(ec)); | - | ||||||||||||||||||
| 530 | return executed 1812 times by 1 test: 1;return 1;Executed by:
executed 1812 times by 1 test: return 1;Executed by:
| 1812 | ||||||||||||||||||
| 531 | } | - | ||||||||||||||||||
| 532 | - | |||||||||||||||||||
| 533 | static int old_ec_priv_encode(const EVP_PKEY *pkey, unsigned char **pder) | - | ||||||||||||||||||
| 534 | { | - | ||||||||||||||||||
| 535 | return executed 6 times by 1 test: i2d_ECPrivateKey(pkey->pkey.ec, pder);return i2d_ECPrivateKey(pkey->pkey.ec, pder);Executed by:
executed 6 times by 1 test: return i2d_ECPrivateKey(pkey->pkey.ec, pder);Executed by:
| 6 | ||||||||||||||||||
| 536 | } | - | ||||||||||||||||||
| 537 | - | |||||||||||||||||||
| 538 | static int ec_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2) | - | ||||||||||||||||||
| 539 | { | - | ||||||||||||||||||
| 540 | switch (op) { | - | ||||||||||||||||||
| 541 | case never executed: 0x1:case 0x1:never executed: case 0x1: | 0 | ||||||||||||||||||
| 542 | if (arg1 == 0
| 0 | ||||||||||||||||||
| 543 | int snid, hnid; | - | ||||||||||||||||||
| 544 | X509_ALGOR *alg1, *alg2; | - | ||||||||||||||||||
| 545 | PKCS7_SIGNER_INFO_get0_algs(arg2, | - | ||||||||||||||||||
| 546 | ((void *)0) | - | ||||||||||||||||||
| 547 | , &alg1, &alg2); | - | ||||||||||||||||||
| 548 | if (alg1 ==
| 0 | ||||||||||||||||||
| 549 | ((void *)0)
| 0 | ||||||||||||||||||
| 550 | || alg1->algorithm ==
| 0 | ||||||||||||||||||
| 551 | ((void *)0)
| 0 | ||||||||||||||||||
| 552 | ) | - | ||||||||||||||||||
| 553 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 554 | hnid = OBJ_obj2nid(alg1->algorithm); | - | ||||||||||||||||||
| 555 | if (hnid == 0
| 0 | ||||||||||||||||||
| 556 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 557 | if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey))
| 0 | ||||||||||||||||||
| 558 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 559 | X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), -1, 0); | - | ||||||||||||||||||
| 560 | } never executed: end of block | 0 | ||||||||||||||||||
| 561 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||||||||||||||
| 562 | - | |||||||||||||||||||
| 563 | case never executed: 0x5:case 0x5:never executed: case 0x5: | 0 | ||||||||||||||||||
| 564 | if (arg1 == 0
| 0 | ||||||||||||||||||
| 565 | int snid, hnid; | - | ||||||||||||||||||
| 566 | X509_ALGOR *alg1, *alg2; | - | ||||||||||||||||||
| 567 | CMS_SignerInfo_get0_algs(arg2, | - | ||||||||||||||||||
| 568 | ((void *)0) | - | ||||||||||||||||||
| 569 | , | - | ||||||||||||||||||
| 570 | ((void *)0) | - | ||||||||||||||||||
| 571 | , &alg1, &alg2); | - | ||||||||||||||||||
| 572 | if (alg1 ==
| 0 | ||||||||||||||||||
| 573 | ((void *)0)
| 0 | ||||||||||||||||||
| 574 | || alg1->algorithm ==
| 0 | ||||||||||||||||||
| 575 | ((void *)0)
| 0 | ||||||||||||||||||
| 576 | ) | - | ||||||||||||||||||
| 577 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 578 | hnid = OBJ_obj2nid(alg1->algorithm); | - | ||||||||||||||||||
| 579 | if (hnid == 0
| 0 | ||||||||||||||||||
| 580 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 581 | if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey))
| 0 | ||||||||||||||||||
| 582 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 583 | X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), -1, 0); | - | ||||||||||||||||||
| 584 | } never executed: end of block | 0 | ||||||||||||||||||
| 585 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||||||||||||||
| 586 | - | |||||||||||||||||||
| 587 | case executed 11 times by 1 test: 0x7:case 0x7:Executed by:
executed 11 times by 1 test: case 0x7:Executed by:
| 11 | ||||||||||||||||||
| 588 | if (arg1 == 1
| 5-6 | ||||||||||||||||||
| 589 | return executed 5 times by 1 test: ecdh_cms_decrypt(arg2);return ecdh_cms_decrypt(arg2);Executed by:
executed 5 times by 1 test: return ecdh_cms_decrypt(arg2);Executed by:
| 5 | ||||||||||||||||||
| 590 | else if (arg1 == 0
| 0-6 | ||||||||||||||||||
| 591 | return executed 6 times by 1 test: ecdh_cms_encrypt(arg2);return ecdh_cms_encrypt(arg2);Executed by:
executed 6 times by 1 test: return ecdh_cms_encrypt(arg2);Executed by:
| 6 | ||||||||||||||||||
| 592 | return never executed: -2;return -2;never executed: return -2; | 0 | ||||||||||||||||||
| 593 | - | |||||||||||||||||||
| 594 | case executed 11 times by 1 test: 0x8:case 0x8:Executed by:
executed 11 times by 1 test: case 0x8:Executed by:
| 11 | ||||||||||||||||||
| 595 | *(int *)arg2 = 1; | - | ||||||||||||||||||
| 596 | return executed 11 times by 1 test: 1;return 1;Executed by:
executed 11 times by 1 test: return 1;Executed by:
| 11 | ||||||||||||||||||
| 597 | - | |||||||||||||||||||
| 598 | - | |||||||||||||||||||
| 599 | case executed 1 time by 1 test: 0x3:case 0x3:Executed by:
executed 1 time by 1 test: case 0x3:Executed by:
| 1 | ||||||||||||||||||
| 600 | *(int *)arg2 = 672; | - | ||||||||||||||||||
| 601 | return executed 1 time by 1 test: 2;return 2;Executed by:
executed 1 time by 1 test: return 2;Executed by:
| 1 | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | case executed 403 times by 1 test: 0x9:case 0x9:Executed by:
executed 403 times by 1 test: case 0x9:Executed by:
| 403 | ||||||||||||||||||
| 604 | return executed 403 times by 1 test: EC_KEY_oct2key(EVP_PKEY_get0_EC_KEY(pkey), arg2, arg1, return EC_KEY_oct2key(EVP_PKEY_get0_EC_KEY(pkey), arg2, arg1, ((void *)0) );Executed by:
executed 403 times by 1 test: return EC_KEY_oct2key(EVP_PKEY_get0_EC_KEY(pkey), arg2, arg1, ((void *)0) );Executed by:
| 403 | ||||||||||||||||||
| 605 | ((void *)0) executed 403 times by 1 test: return EC_KEY_oct2key(EVP_PKEY_get0_EC_KEY(pkey), arg2, arg1, ((void *)0) );Executed by:
| 403 | ||||||||||||||||||
| 606 | ); executed 403 times by 1 test: return EC_KEY_oct2key(EVP_PKEY_get0_EC_KEY(pkey), arg2, arg1, ((void *)0) );Executed by:
| 403 | ||||||||||||||||||
| 607 | - | |||||||||||||||||||
| 608 | case executed 891 times by 1 test: 0xa:case 0xa:Executed by:
executed 891 times by 1 test: case 0xa:Executed by:
| 891 | ||||||||||||||||||
| 609 | return executed 891 times by 1 test: EC_KEY_key2buf(EVP_PKEY_get0_EC_KEY(pkey),return EC_KEY_key2buf(EVP_PKEY_get0_EC_KEY(pkey), POINT_CONVERSION_UNCOMPRESSED, arg2, ((void *)0) );Executed by:
executed 891 times by 1 test: return EC_KEY_key2buf(EVP_PKEY_get0_EC_KEY(pkey), POINT_CONVERSION_UNCOMPRESSED, arg2, ((void *)0) );Executed by:
| 891 | ||||||||||||||||||
| 610 | POINT_CONVERSION_UNCOMPRESSED, arg2, executed 891 times by 1 test: return EC_KEY_key2buf(EVP_PKEY_get0_EC_KEY(pkey), POINT_CONVERSION_UNCOMPRESSED, arg2, ((void *)0) );Executed by:
| 891 | ||||||||||||||||||
| 611 | ((void *)0) executed 891 times by 1 test: return EC_KEY_key2buf(EVP_PKEY_get0_EC_KEY(pkey), POINT_CONVERSION_UNCOMPRESSED, arg2, ((void *)0) );Executed by:
| 891 | ||||||||||||||||||
| 612 | ); executed 891 times by 1 test: return EC_KEY_key2buf(EVP_PKEY_get0_EC_KEY(pkey), POINT_CONVERSION_UNCOMPRESSED, arg2, ((void *)0) );Executed by:
| 891 | ||||||||||||||||||
| 613 | - | |||||||||||||||||||
| 614 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||
| 615 | return never executed: -2;return -2;never executed: return -2; | 0 | ||||||||||||||||||
| 616 | - | |||||||||||||||||||
| 617 | } | - | ||||||||||||||||||
| 618 | - | |||||||||||||||||||
| 619 | } | - | ||||||||||||||||||
| 620 | - | |||||||||||||||||||
| 621 | static int ec_pkey_check(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 622 | { | - | ||||||||||||||||||
| 623 | EC_KEY *eckey = pkey->pkey.ec; | - | ||||||||||||||||||
| 624 | - | |||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | if (eckey->priv_key ==
| 1-2 | ||||||||||||||||||
| 627 | ((void *)0)
| 1-2 | ||||||||||||||||||
| 628 | ) { | - | ||||||||||||||||||
| 629 | ERR_put_error(16,(273),(125),__FILE__,530); | - | ||||||||||||||||||
| 630 | return executed 2 times by 1 test: 0;return 0;Executed by:
executed 2 times by 1 test: return 0;Executed by:
| 2 | ||||||||||||||||||
| 631 | } | - | ||||||||||||||||||
| 632 | - | |||||||||||||||||||
| 633 | return executed 1 time by 1 test: EC_KEY_check_key(eckey);return EC_KEY_check_key(eckey);Executed by:
executed 1 time by 1 test: return EC_KEY_check_key(eckey);Executed by:
| 1 | ||||||||||||||||||
| 634 | } | - | ||||||||||||||||||
| 635 | - | |||||||||||||||||||
| 636 | static int ec_pkey_public_check(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 637 | { | - | ||||||||||||||||||
| 638 | EC_KEY *eckey = pkey->pkey.ec; | - | ||||||||||||||||||
| 639 | return executed 3 times by 1 test: EC_KEY_check_key(eckey);return EC_KEY_check_key(eckey);Executed by:
executed 3 times by 1 test: return EC_KEY_check_key(eckey);Executed by:
| 3 | ||||||||||||||||||
| 640 | } | - | ||||||||||||||||||
| 641 | - | |||||||||||||||||||
| 642 | static int ec_pkey_param_check(const EVP_PKEY *pkey) | - | ||||||||||||||||||
| 643 | { | - | ||||||||||||||||||
| 644 | EC_KEY *eckey = pkey->pkey.ec; | - | ||||||||||||||||||
| 645 | - | |||||||||||||||||||
| 646 | - | |||||||||||||||||||
| 647 | if (eckey->group ==
| 0-3 | ||||||||||||||||||
| 648 | ((void *)0)
| 0-3 | ||||||||||||||||||
| 649 | ) { | - | ||||||||||||||||||
| 650 | ERR_put_error(16,(274),(124),__FILE__,559); | - | ||||||||||||||||||
| 651 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 652 | } | - | ||||||||||||||||||
| 653 | - | |||||||||||||||||||
| 654 | return executed 3 times by 1 test: EC_GROUP_check(eckey->group, return EC_GROUP_check(eckey->group, ((void *)0) );Executed by:
executed 3 times by 1 test: return EC_GROUP_check(eckey->group, ((void *)0) );Executed by:
| 3 | ||||||||||||||||||
| 655 | ((void *)0) executed 3 times by 1 test: return EC_GROUP_check(eckey->group, ((void *)0) );Executed by:
| 3 | ||||||||||||||||||
| 656 | ); executed 3 times by 1 test: return EC_GROUP_check(eckey->group, ((void *)0) );Executed by:
| 3 | ||||||||||||||||||
| 657 | } | - | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | const EVP_PKEY_ASN1_METHOD eckey_asn1_meth = { | - | ||||||||||||||||||
| 660 | 408, | - | ||||||||||||||||||
| 661 | 408, | - | ||||||||||||||||||
| 662 | 0, | - | ||||||||||||||||||
| 663 | "EC", | - | ||||||||||||||||||
| 664 | "OpenSSL EC algorithm", | - | ||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | eckey_pub_decode, | - | ||||||||||||||||||
| 667 | eckey_pub_encode, | - | ||||||||||||||||||
| 668 | eckey_pub_cmp, | - | ||||||||||||||||||
| 669 | eckey_pub_print, | - | ||||||||||||||||||
| 670 | - | |||||||||||||||||||
| 671 | eckey_priv_decode, | - | ||||||||||||||||||
| 672 | eckey_priv_encode, | - | ||||||||||||||||||
| 673 | eckey_priv_print, | - | ||||||||||||||||||
| 674 | - | |||||||||||||||||||
| 675 | int_ec_size, | - | ||||||||||||||||||
| 676 | ec_bits, | - | ||||||||||||||||||
| 677 | ec_security_bits, | - | ||||||||||||||||||
| 678 | - | |||||||||||||||||||
| 679 | eckey_param_decode, | - | ||||||||||||||||||
| 680 | eckey_param_encode, | - | ||||||||||||||||||
| 681 | ec_missing_parameters, | - | ||||||||||||||||||
| 682 | ec_copy_parameters, | - | ||||||||||||||||||
| 683 | ec_cmp_parameters, | - | ||||||||||||||||||
| 684 | eckey_param_print, | - | ||||||||||||||||||
| 685 | 0, | - | ||||||||||||||||||
| 686 | - | |||||||||||||||||||
| 687 | int_ec_free, | - | ||||||||||||||||||
| 688 | ec_pkey_ctrl, | - | ||||||||||||||||||
| 689 | old_ec_priv_decode, | - | ||||||||||||||||||
| 690 | old_ec_priv_encode, | - | ||||||||||||||||||
| 691 | - | |||||||||||||||||||
| 692 | 0, 0, 0, | - | ||||||||||||||||||
| 693 | - | |||||||||||||||||||
| 694 | ec_pkey_check, | - | ||||||||||||||||||
| 695 | ec_pkey_public_check, | - | ||||||||||||||||||
| 696 | ec_pkey_param_check | - | ||||||||||||||||||
| 697 | }; | - | ||||||||||||||||||
| 698 | - | |||||||||||||||||||
| 699 | - | |||||||||||||||||||
| 700 | const EVP_PKEY_ASN1_METHOD sm2_asn1_meth = { | - | ||||||||||||||||||
| 701 | 1172, | - | ||||||||||||||||||
| 702 | 408, | - | ||||||||||||||||||
| 703 | 0x1 | - | ||||||||||||||||||
| 704 | }; | - | ||||||||||||||||||
| 705 | - | |||||||||||||||||||
| 706 | - | |||||||||||||||||||
| 707 | int EC_KEY_print(BIO *bp, const EC_KEY *x, int off) | - | ||||||||||||||||||
| 708 | { | - | ||||||||||||||||||
| 709 | int private = EC_KEY_get0_private_key(x) != | - | ||||||||||||||||||
| 710 | ((void *)0) | - | ||||||||||||||||||
| 711 | ; | - | ||||||||||||||||||
| 712 | - | |||||||||||||||||||
| 713 | return executed 227 times by 1 test: do_EC_KEY_print(bp, x, off,return do_EC_KEY_print(bp, x, off, private ? EC_KEY_PRINT_PRIVATE : EC_KEY_PRINT_PUBLIC);Executed by:
executed 227 times by 1 test: return do_EC_KEY_print(bp, x, off, private ? EC_KEY_PRINT_PRIVATE : EC_KEY_PRINT_PUBLIC);Executed by:
| 227 | ||||||||||||||||||
| 714 | private ? EC_KEY_PRINT_PRIVATE : EC_KEY_PRINT_PUBLIC); executed 227 times by 1 test: return do_EC_KEY_print(bp, x, off, private ? EC_KEY_PRINT_PRIVATE : EC_KEY_PRINT_PUBLIC);Executed by:
| 227 | ||||||||||||||||||
| 715 | } | - | ||||||||||||||||||
| 716 | - | |||||||||||||||||||
| 717 | int ECParameters_print(BIO *bp, const EC_KEY *x) | - | ||||||||||||||||||
| 718 | { | - | ||||||||||||||||||
| 719 | return executed 22 times by 1 test: do_EC_KEY_print(bp, x, 4, EC_KEY_PRINT_PARAM);return do_EC_KEY_print(bp, x, 4, EC_KEY_PRINT_PARAM);Executed by:
executed 22 times by 1 test: return do_EC_KEY_print(bp, x, 4, EC_KEY_PRINT_PARAM);Executed by:
| 22 | ||||||||||||||||||
| 720 | } | - | ||||||||||||||||||
| 721 | - | |||||||||||||||||||
| 722 | - | |||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | static int ecdh_cms_set_peerkey(EVP_PKEY_CTX *pctx, | - | ||||||||||||||||||
| 725 | X509_ALGOR *alg, ASN1_BIT_STRING *pubkey) | - | ||||||||||||||||||
| 726 | { | - | ||||||||||||||||||
| 727 | const ASN1_OBJECT *aoid; | - | ||||||||||||||||||
| 728 | int atype; | - | ||||||||||||||||||
| 729 | const void *aval; | - | ||||||||||||||||||
| 730 | int rv = 0; | - | ||||||||||||||||||
| 731 | EVP_PKEY *pkpeer = | - | ||||||||||||||||||
| 732 | ((void *)0) | - | ||||||||||||||||||
| 733 | ; | - | ||||||||||||||||||
| 734 | EC_KEY *ecpeer = | - | ||||||||||||||||||
| 735 | ((void *)0) | - | ||||||||||||||||||
| 736 | ; | - | ||||||||||||||||||
| 737 | const unsigned char *p; | - | ||||||||||||||||||
| 738 | int plen; | - | ||||||||||||||||||
| 739 | X509_ALGOR_get0(&aoid, &atype, &aval, alg); | - | ||||||||||||||||||
| 740 | if (OBJ_obj2nid(aoid) != 408
| 0-5 | ||||||||||||||||||
| 741 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 742 | - | |||||||||||||||||||
| 743 | if (atype == -1
| 0-5 | ||||||||||||||||||
| 744 | const EC_GROUP *grp; | - | ||||||||||||||||||
| 745 | EVP_PKEY *pk; | - | ||||||||||||||||||
| 746 | pk = EVP_PKEY_CTX_get0_pkey(pctx); | - | ||||||||||||||||||
| 747 | if (!pk
| 0-5 | ||||||||||||||||||
| 748 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 749 | grp = EC_KEY_get0_group(pk->pkey.ec); | - | ||||||||||||||||||
| 750 | ecpeer = EC_KEY_new(); | - | ||||||||||||||||||
| 751 | if (ecpeer ==
| 0-5 | ||||||||||||||||||
| 752 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 753 | ) | - | ||||||||||||||||||
| 754 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 755 | if (!EC_KEY_set_group(ecpeer, grp)
| 0-5 | ||||||||||||||||||
| 756 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 757 | } executed 5 times by 1 test: else {end of blockExecuted by:
| 5 | ||||||||||||||||||
| 758 | ecpeer = eckey_type2param(atype, aval); | - | ||||||||||||||||||
| 759 | if (!ecpeer
| 0 | ||||||||||||||||||
| 760 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 761 | } never executed: end of block | 0 | ||||||||||||||||||
| 762 | - | |||||||||||||||||||
| 763 | plen = ASN1_STRING_length(pubkey); | - | ||||||||||||||||||
| 764 | p = ASN1_STRING_get0_data(pubkey); | - | ||||||||||||||||||
| 765 | if (!p
| 0-5 | ||||||||||||||||||
| 766 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 767 | if (!o2i_ECPublicKey(&ecpeer, &p, plen)
| 0-5 | ||||||||||||||||||
| 768 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 769 | pkpeer = EVP_PKEY_new(); | - | ||||||||||||||||||
| 770 | if (pkpeer ==
| 0-5 | ||||||||||||||||||
| 771 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 772 | ) | - | ||||||||||||||||||
| 773 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 774 | EVP_PKEY_set1_EC_KEY(pkpeer, ecpeer); | - | ||||||||||||||||||
| 775 | if (EVP_PKEY_derive_set_peer(pctx, pkpeer) > 0
| 0-5 | ||||||||||||||||||
| 776 | rv = 1; executed 5 times by 1 test: rv = 1;Executed by:
| 5 | ||||||||||||||||||
| 777 | err: code before this statement executed 5 times by 1 test: err:Executed by:
| 5 | ||||||||||||||||||
| 778 | EC_KEY_free(ecpeer); | - | ||||||||||||||||||
| 779 | EVP_PKEY_free(pkpeer); | - | ||||||||||||||||||
| 780 | return executed 5 times by 1 test: rv;return rv;Executed by:
executed 5 times by 1 test: return rv;Executed by:
| 5 | ||||||||||||||||||
| 781 | } | - | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | - | |||||||||||||||||||
| 784 | static int ecdh_cms_set_kdf_param(EVP_PKEY_CTX *pctx, int eckdf_nid) | - | ||||||||||||||||||
| 785 | { | - | ||||||||||||||||||
| 786 | int kdf_nid, kdfmd_nid, cofactor; | - | ||||||||||||||||||
| 787 | const EVP_MD *kdf_md; | - | ||||||||||||||||||
| 788 | if (eckdf_nid == 0
| 0-5 | ||||||||||||||||||
| 789 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 790 | - | |||||||||||||||||||
| 791 | - | |||||||||||||||||||
| 792 | if (!OBJ_find_sigid_algs(eckdf_nid, &kdfmd_nid, &kdf_nid)
| 0-5 | ||||||||||||||||||
| 793 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 794 | - | |||||||||||||||||||
| 795 | if (kdf_nid == 946
| 1-4 | ||||||||||||||||||
| 796 | cofactor = 0; executed 4 times by 1 test: cofactor = 0;Executed by:
| 4 | ||||||||||||||||||
| 797 | else if (kdf_nid == 947
| 0-1 | ||||||||||||||||||
| 798 | cofactor = 1; executed 1 time by 1 test: cofactor = 1;Executed by:
| 1 | ||||||||||||||||||
| 799 | else | - | ||||||||||||||||||
| 800 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 801 | - | |||||||||||||||||||
| 802 | if (EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 3), cofactor,
| 0-5 | ||||||||||||||||||
| 803 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 804 | ) <= 0
| 0-5 | ||||||||||||||||||
| 805 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 806 | - | |||||||||||||||||||
| 807 | if (EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 4), 2,
| 0-5 | ||||||||||||||||||
| 808 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 809 | ) <= 0
| 0-5 | ||||||||||||||||||
| 810 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 811 | - | |||||||||||||||||||
| 812 | kdf_md = EVP_get_digestbyname(OBJ_nid2sn(kdfmd_nid)); | - | ||||||||||||||||||
| 813 | if (!kdf_md
| 0-5 | ||||||||||||||||||
| 814 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 815 | - | |||||||||||||||||||
| 816 | if (EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 5), 0, (void *)(kdf_md)) <= 0
| 0-5 | ||||||||||||||||||
| 817 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 818 | return executed 5 times by 1 test: 1;return 1;Executed by:
executed 5 times by 1 test: return 1;Executed by:
| 5 | ||||||||||||||||||
| 819 | } | - | ||||||||||||||||||
| 820 | - | |||||||||||||||||||
| 821 | static int ecdh_cms_set_shared_info(EVP_PKEY_CTX *pctx, CMS_RecipientInfo *ri) | - | ||||||||||||||||||
| 822 | { | - | ||||||||||||||||||
| 823 | int rv = 0; | - | ||||||||||||||||||
| 824 | - | |||||||||||||||||||
| 825 | X509_ALGOR *alg, *kekalg = | - | ||||||||||||||||||
| 826 | ((void *)0) | - | ||||||||||||||||||
| 827 | ; | - | ||||||||||||||||||
| 828 | ASN1_OCTET_STRING *ukm; | - | ||||||||||||||||||
| 829 | const unsigned char *p; | - | ||||||||||||||||||
| 830 | unsigned char *der = | - | ||||||||||||||||||
| 831 | ((void *)0) | - | ||||||||||||||||||
| 832 | ; | - | ||||||||||||||||||
| 833 | int plen, keylen; | - | ||||||||||||||||||
| 834 | const EVP_CIPHER *kekcipher; | - | ||||||||||||||||||
| 835 | EVP_CIPHER_CTX *kekctx; | - | ||||||||||||||||||
| 836 | - | |||||||||||||||||||
| 837 | if (!CMS_RecipientInfo_kari_get0_alg(ri, &alg, &ukm)
| 0-5 | ||||||||||||||||||
| 838 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 839 | - | |||||||||||||||||||
| 840 | if (!ecdh_cms_set_kdf_param(pctx, OBJ_obj2nid(alg->algorithm))
| 0-5 | ||||||||||||||||||
| 841 | ERR_put_error(16,(239),(148),__FILE__,730); | - | ||||||||||||||||||
| 842 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 843 | } | - | ||||||||||||||||||
| 844 | - | |||||||||||||||||||
| 845 | if (alg->parameter->type != 16
| 0-5 | ||||||||||||||||||
| 846 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 847 | - | |||||||||||||||||||
| 848 | p = alg->parameter->value.sequence->data; | - | ||||||||||||||||||
| 849 | plen = alg->parameter->value.sequence->length; | - | ||||||||||||||||||
| 850 | kekalg = d2i_X509_ALGOR( | - | ||||||||||||||||||
| 851 | ((void *)0) | - | ||||||||||||||||||
| 852 | , &p, plen); | - | ||||||||||||||||||
| 853 | if (!kekalg
| 0-5 | ||||||||||||||||||
| 854 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 855 | kekctx = CMS_RecipientInfo_kari_get0_ctx(ri); | - | ||||||||||||||||||
| 856 | if (!kekctx
| 0-5 | ||||||||||||||||||
| 857 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 858 | kekcipher = EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(kekalg->algorithm))); | - | ||||||||||||||||||
| 859 | if (!kekcipher
| 0-5 | ||||||||||||||||||
| 860 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 861 | if (!EVP_EncryptInit_ex(kekctx, kekcipher,
| 0-5 | ||||||||||||||||||
| 862 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 863 | ,
| 0-5 | ||||||||||||||||||
| 864 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 865 | ,
| 0-5 | ||||||||||||||||||
| 866 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 867 | )
| 0-5 | ||||||||||||||||||
| 868 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 869 | if (EVP_CIPHER_asn1_to_param(kekctx, kekalg->parameter) <= 0
| 0-5 | ||||||||||||||||||
| 870 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 871 | - | |||||||||||||||||||
| 872 | keylen = EVP_CIPHER_CTX_key_length(kekctx); | - | ||||||||||||||||||
| 873 | if (EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 7), keylen,
| 0-5 | ||||||||||||||||||
| 874 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 875 | ) <= 0
| 0-5 | ||||||||||||||||||
| 876 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 877 | - | |||||||||||||||||||
| 878 | plen = CMS_SharedInfo_encode(&der, kekalg, ukm, keylen); | - | ||||||||||||||||||
| 879 | - | |||||||||||||||||||
| 880 | if (!plen
| 0-5 | ||||||||||||||||||
| 881 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 882 | - | |||||||||||||||||||
| 883 | if (EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 9), plen, (void *)(der)) <= 0
| 0-5 | ||||||||||||||||||
| 884 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 885 | der = | - | ||||||||||||||||||
| 886 | ((void *)0) | - | ||||||||||||||||||
| 887 | ; | - | ||||||||||||||||||
| 888 | - | |||||||||||||||||||
| 889 | rv = 1; | - | ||||||||||||||||||
| 890 | err: code before this statement executed 5 times by 1 test: err:Executed by:
| 5 | ||||||||||||||||||
| 891 | X509_ALGOR_free(kekalg); | - | ||||||||||||||||||
| 892 | CRYPTO_free(der, __FILE__, 769); | - | ||||||||||||||||||
| 893 | return executed 5 times by 1 test: rv;return rv;Executed by:
executed 5 times by 1 test: return rv;Executed by:
| 5 | ||||||||||||||||||
| 894 | } | - | ||||||||||||||||||
| 895 | - | |||||||||||||||||||
| 896 | static int ecdh_cms_decrypt(CMS_RecipientInfo *ri) | - | ||||||||||||||||||
| 897 | { | - | ||||||||||||||||||
| 898 | EVP_PKEY_CTX *pctx; | - | ||||||||||||||||||
| 899 | pctx = CMS_RecipientInfo_get0_pkey_ctx(ri); | - | ||||||||||||||||||
| 900 | if (!pctx
| 0-5 | ||||||||||||||||||
| 901 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 902 | - | |||||||||||||||||||
| 903 | if (!EVP_PKEY_CTX_get0_peerkey(pctx)
| 0-5 | ||||||||||||||||||
| 904 | X509_ALGOR *alg; | - | ||||||||||||||||||
| 905 | ASN1_BIT_STRING *pubkey; | - | ||||||||||||||||||
| 906 | if (!CMS_RecipientInfo_kari_get0_orig_id(ri, &alg, &pubkey,
| 0-5 | ||||||||||||||||||
| 907 |
| 0-5 | ||||||||||||||||||
| 908 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 909 | ,
| 0-5 | ||||||||||||||||||
| 910 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 911 | ,
| 0-5 | ||||||||||||||||||
| 912 | ((void *)0)
| 0-5 | ||||||||||||||||||
| 913 | )
| 0-5 | ||||||||||||||||||
| 914 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 915 | if (!alg
| 0-5 | ||||||||||||||||||
| 916 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 917 | if (!ecdh_cms_set_peerkey(pctx, alg, pubkey)
| 0-5 | ||||||||||||||||||
| 918 | ERR_put_error(16,(238),(149),__FILE__,789); | - | ||||||||||||||||||
| 919 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 920 | } | - | ||||||||||||||||||
| 921 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 922 | - | |||||||||||||||||||
| 923 | if (!ecdh_cms_set_shared_info(pctx, ri)
| 0-5 | ||||||||||||||||||
| 924 | ERR_put_error(16,(238),(150),__FILE__,795); | - | ||||||||||||||||||
| 925 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 926 | } | - | ||||||||||||||||||
| 927 | return executed 5 times by 1 test: 1;return 1;Executed by:
executed 5 times by 1 test: return 1;Executed by:
| 5 | ||||||||||||||||||
| 928 | } | - | ||||||||||||||||||
| 929 | - | |||||||||||||||||||
| 930 | static int ecdh_cms_encrypt(CMS_RecipientInfo *ri) | - | ||||||||||||||||||
| 931 | { | - | ||||||||||||||||||
| 932 | EVP_PKEY_CTX *pctx; | - | ||||||||||||||||||
| 933 | EVP_PKEY *pkey; | - | ||||||||||||||||||
| 934 | EVP_CIPHER_CTX *ctx; | - | ||||||||||||||||||
| 935 | int keylen; | - | ||||||||||||||||||
| 936 | X509_ALGOR *talg, *wrap_alg = | - | ||||||||||||||||||
| 937 | ((void *)0) | - | ||||||||||||||||||
| 938 | ; | - | ||||||||||||||||||
| 939 | const ASN1_OBJECT *aoid; | - | ||||||||||||||||||
| 940 | ASN1_BIT_STRING *pubkey; | - | ||||||||||||||||||
| 941 | ASN1_STRING *wrap_str; | - | ||||||||||||||||||
| 942 | ASN1_OCTET_STRING *ukm; | - | ||||||||||||||||||
| 943 | unsigned char *penc = | - | ||||||||||||||||||
| 944 | ((void *)0) | - | ||||||||||||||||||
| 945 | ; | - | ||||||||||||||||||
| 946 | int penclen; | - | ||||||||||||||||||
| 947 | int rv = 0; | - | ||||||||||||||||||
| 948 | int ecdh_nid, kdf_type, kdf_nid, wrap_nid; | - | ||||||||||||||||||
| 949 | const EVP_MD *kdf_md; | - | ||||||||||||||||||
| 950 | pctx = CMS_RecipientInfo_get0_pkey_ctx(ri); | - | ||||||||||||||||||
| 951 | if (!pctx
| 0-6 | ||||||||||||||||||
| 952 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 953 | - | |||||||||||||||||||
| 954 | pkey = EVP_PKEY_CTX_get0_pkey(pctx); | - | ||||||||||||||||||
| 955 | if (!CMS_RecipientInfo_kari_get0_orig_id(ri, &talg, &pubkey,
| 0-6 | ||||||||||||||||||
| 956 |
| 0-6 | ||||||||||||||||||
| 957 | ((void *)0)
| 0-6 | ||||||||||||||||||
| 958 | ,
| 0-6 | ||||||||||||||||||
| 959 | ((void *)0)
| 0-6 | ||||||||||||||||||
| 960 | ,
| 0-6 | ||||||||||||||||||
| 961 | ((void *)0)
| 0-6 | ||||||||||||||||||
| 962 | )
| 0-6 | ||||||||||||||||||
| 963 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 964 | X509_ALGOR_get0(&aoid, | - | ||||||||||||||||||
| 965 | ((void *)0) | - | ||||||||||||||||||
| 966 | , | - | ||||||||||||||||||
| 967 | ((void *)0) | - | ||||||||||||||||||
| 968 | , talg); | - | ||||||||||||||||||
| 969 | - | |||||||||||||||||||
| 970 | if (aoid == OBJ_nid2obj(0)
| 0-6 | ||||||||||||||||||
| 971 | - | |||||||||||||||||||
| 972 | EC_KEY *eckey = pkey->pkey.ec; | - | ||||||||||||||||||
| 973 | - | |||||||||||||||||||
| 974 | unsigned char *p; | - | ||||||||||||||||||
| 975 | - | |||||||||||||||||||
| 976 | penclen = i2o_ECPublicKey(eckey, | - | ||||||||||||||||||
| 977 | ((void *)0) | - | ||||||||||||||||||
| 978 | ); | - | ||||||||||||||||||
| 979 | if (penclen <= 0
| 0-6 | ||||||||||||||||||
| 980 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 981 | penc = CRYPTO_malloc(penclen, __FILE__, 836); | - | ||||||||||||||||||
| 982 | if (penc ==
| 0-6 | ||||||||||||||||||
| 983 | ((void *)0)
| 0-6 | ||||||||||||||||||
| 984 | ) | - | ||||||||||||||||||
| 985 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 986 | p = penc; | - | ||||||||||||||||||
| 987 | penclen = i2o_ECPublicKey(eckey, &p); | - | ||||||||||||||||||
| 988 | if (penclen <= 0
| 0-6 | ||||||||||||||||||
| 989 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 990 | ASN1_STRING_set0(pubkey, penc, penclen); | - | ||||||||||||||||||
| 991 | pubkey->flags &= ~(0x08 | 0x07); | - | ||||||||||||||||||
| 992 | pubkey->flags |= 0x08; | - | ||||||||||||||||||
| 993 | - | |||||||||||||||||||
| 994 | penc = | - | ||||||||||||||||||
| 995 | ((void *)0) | - | ||||||||||||||||||
| 996 | ; | - | ||||||||||||||||||
| 997 | X509_ALGOR_set0(talg, OBJ_nid2obj(408), | - | ||||||||||||||||||
| 998 | -1, | - | ||||||||||||||||||
| 999 | ((void *)0) | - | ||||||||||||||||||
| 1000 | ); | - | ||||||||||||||||||
| 1001 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 1002 | - | |||||||||||||||||||
| 1003 | - | |||||||||||||||||||
| 1004 | kdf_type = EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 4), -2, | - | ||||||||||||||||||
| 1005 | ((void *)0) | - | ||||||||||||||||||
| 1006 | ); | - | ||||||||||||||||||
| 1007 | if (kdf_type <= 0
| 0-6 | ||||||||||||||||||
| 1008 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1009 | if (!EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 6), 0, (void *)(&kdf_md))
| 0-6 | ||||||||||||||||||
| 1010 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1011 | ecdh_nid = EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 3), -2, | - | ||||||||||||||||||
| 1012 | ((void *)0) | - | ||||||||||||||||||
| 1013 | ); | - | ||||||||||||||||||
| 1014 | if (ecdh_nid < 0
| 0-6 | ||||||||||||||||||
| 1015 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1016 | else if (ecdh_nid == 0
| 1-5 | ||||||||||||||||||
| 1017 | ecdh_nid = 946; executed 5 times by 1 test: ecdh_nid = 946;Executed by:
| 5 | ||||||||||||||||||
| 1018 | else if (ecdh_nid == 1
| 0-1 | ||||||||||||||||||
| 1019 | ecdh_nid = 947; executed 1 time by 1 test: ecdh_nid = 947;Executed by:
| 1 | ||||||||||||||||||
| 1020 | - | |||||||||||||||||||
| 1021 | if (kdf_type == 1
| 0-6 | ||||||||||||||||||
| 1022 | kdf_type = 2; | - | ||||||||||||||||||
| 1023 | if (EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 4), kdf_type,
| 0-6 | ||||||||||||||||||
| 1024 | ((void *)0)
| 0-6 | ||||||||||||||||||
| 1025 | ) <= 0
| 0-6 | ||||||||||||||||||
| 1026 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1027 | } executed 6 times by 1 test: elseend of blockExecuted by:
| 6 | ||||||||||||||||||
| 1028 | - | |||||||||||||||||||
| 1029 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1030 | if (kdf_md ==
| 2-4 | ||||||||||||||||||
| 1031 | ((void *)0)
| 2-4 | ||||||||||||||||||
| 1032 | ) { | - | ||||||||||||||||||
| 1033 | - | |||||||||||||||||||
| 1034 | kdf_md = EVP_sha1(); | - | ||||||||||||||||||
| 1035 | if (EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 5), 0, (void *)(kdf_md)) <= 0
| 0-4 | ||||||||||||||||||
| 1036 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1037 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 1038 | - | |||||||||||||||||||
| 1039 | if (!CMS_RecipientInfo_kari_get0_alg(ri, &talg, &ukm)
| 0-6 | ||||||||||||||||||
| 1040 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1041 | - | |||||||||||||||||||
| 1042 | - | |||||||||||||||||||
| 1043 | - | |||||||||||||||||||
| 1044 | if (!OBJ_find_sigid_by_algs(&kdf_nid, EVP_MD_type(kdf_md), ecdh_nid)
| 0-6 | ||||||||||||||||||
| 1045 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1046 | - | |||||||||||||||||||
| 1047 | ctx = CMS_RecipientInfo_kari_get0_ctx(ri); | - | ||||||||||||||||||
| 1048 | wrap_nid = EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(ctx)); | - | ||||||||||||||||||
| 1049 | keylen = EVP_CIPHER_CTX_key_length(ctx); | - | ||||||||||||||||||
| 1050 | - | |||||||||||||||||||
| 1051 | - | |||||||||||||||||||
| 1052 | - | |||||||||||||||||||
| 1053 | wrap_alg = X509_ALGOR_new(); | - | ||||||||||||||||||
| 1054 | if (wrap_alg ==
| 0-6 | ||||||||||||||||||
| 1055 | ((void *)0)
| 0-6 | ||||||||||||||||||
| 1056 | ) | - | ||||||||||||||||||
| 1057 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1058 | wrap_alg->algorithm = OBJ_nid2obj(wrap_nid); | - | ||||||||||||||||||
| 1059 | wrap_alg->parameter = ASN1_TYPE_new(); | - | ||||||||||||||||||
| 1060 | if (wrap_alg->parameter ==
| 0-6 | ||||||||||||||||||
| 1061 | ((void *)0)
| 0-6 | ||||||||||||||||||
| 1062 | ) | - | ||||||||||||||||||
| 1063 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1064 | if (EVP_CIPHER_param_to_asn1(ctx, wrap_alg->parameter) <= 0
| 0-6 | ||||||||||||||||||
| 1065 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1066 | if (ASN1_TYPE_get(wrap_alg->parameter) == 0
| 2-4 | ||||||||||||||||||
| 1067 | ASN1_TYPE_free(wrap_alg->parameter); | - | ||||||||||||||||||
| 1068 | wrap_alg->parameter = | - | ||||||||||||||||||
| 1069 | ((void *)0) | - | ||||||||||||||||||
| 1070 | ; | - | ||||||||||||||||||
| 1071 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1072 | - | |||||||||||||||||||
| 1073 | if (EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 7), keylen,
| 0-6 | ||||||||||||||||||
| 1074 | ((void *)0)
| 0-6 | ||||||||||||||||||
| 1075 | ) <= 0
| 0-6 | ||||||||||||||||||
| 1076 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1077 | - | |||||||||||||||||||
| 1078 | penclen = CMS_SharedInfo_encode(&penc, wrap_alg, ukm, keylen); | - | ||||||||||||||||||
| 1079 | - | |||||||||||||||||||
| 1080 | if (!penclen
| 0-6 | ||||||||||||||||||
| 1081 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1082 | - | |||||||||||||||||||
| 1083 | if (EVP_PKEY_CTX_ctrl(pctx, 408, (1<<10), (0x1000 + 9), penclen, (void *)(penc)) <= 0
| 0-6 | ||||||||||||||||||
| 1084 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1085 | penc = | - | ||||||||||||||||||
| 1086 | ((void *)0) | - | ||||||||||||||||||
| 1087 | ; | - | ||||||||||||||||||
| 1088 | - | |||||||||||||||||||
| 1089 | - | |||||||||||||||||||
| 1090 | - | |||||||||||||||||||
| 1091 | - | |||||||||||||||||||
| 1092 | - | |||||||||||||||||||
| 1093 | penclen = i2d_X509_ALGOR(wrap_alg, &penc); | - | ||||||||||||||||||
| 1094 | if (!penc
| 0-6 | ||||||||||||||||||
| 1095 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1096 | wrap_str = ASN1_STRING_new(); | - | ||||||||||||||||||
| 1097 | if (wrap_str ==
| 0-6 | ||||||||||||||||||
| 1098 | ((void *)0)
| 0-6 | ||||||||||||||||||
| 1099 | ) | - | ||||||||||||||||||
| 1100 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 1101 | ASN1_STRING_set0(wrap_str, penc, penclen); | - | ||||||||||||||||||
| 1102 | penc = | - | ||||||||||||||||||
| 1103 | ((void *)0) | - | ||||||||||||||||||
| 1104 | ; | - | ||||||||||||||||||
| 1105 | X509_ALGOR_set0(talg, OBJ_nid2obj(kdf_nid), 16, wrap_str); | - | ||||||||||||||||||
| 1106 | - | |||||||||||||||||||
| 1107 | rv = 1; | - | ||||||||||||||||||
| 1108 | - | |||||||||||||||||||
| 1109 | err: code before this statement executed 6 times by 1 test: err:Executed by:
| 6 | ||||||||||||||||||
| 1110 | CRYPTO_free(penc, __FILE__, 937); | - | ||||||||||||||||||
| 1111 | X509_ALGOR_free(wrap_alg); | - | ||||||||||||||||||
| 1112 | return executed 6 times by 1 test: rv;return rv;Executed by:
executed 6 times by 1 test: return rv;Executed by:
| 6 | ||||||||||||||||||
| 1113 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |