| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ec_asn1.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||||||||||||||
| 2 | * Copyright 2002-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 <string.h> | - | ||||||||||||||||||||||||
| 11 | #include "ec_lcl.h" | - | ||||||||||||||||||||||||
| 12 | #include <openssl/err.h> | - | ||||||||||||||||||||||||
| 13 | #include <openssl/asn1t.h> | - | ||||||||||||||||||||||||
| 14 | #include <openssl/objects.h> | - | ||||||||||||||||||||||||
| 15 | #include "internal/nelem.h" | - | ||||||||||||||||||||||||
| 16 | - | |||||||||||||||||||||||||
| 17 | int EC_GROUP_get_basis_type(const EC_GROUP *group) | - | ||||||||||||||||||||||||
| 18 | { | - | ||||||||||||||||||||||||
| 19 | int i; | - | ||||||||||||||||||||||||
| 20 | - | |||||||||||||||||||||||||
| 21 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
| 0 | ||||||||||||||||||||||||
| 22 | NID_X9_62_characteristic_two_field)
| 0 | ||||||||||||||||||||||||
| 23 | /* everything else is currently not supported */ | - | ||||||||||||||||||||||||
| 24 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 25 | - | |||||||||||||||||||||||||
| 26 | /* Find the last non-zero element of group->poly[] */ | - | ||||||||||||||||||||||||
| 27 | for (i = 0; | - | ||||||||||||||||||||||||
| 28 | i < (int)OSSL_NELEM(group->poly) && group->poly[i] != 0;
| 0 | ||||||||||||||||||||||||
| 29 | i++) | - | ||||||||||||||||||||||||
| 30 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 31 | - | |||||||||||||||||||||||||
| 32 | if (i == 4)
| 0 | ||||||||||||||||||||||||
| 33 | return NID_X9_62_ppBasis; never executed: return 683; | 0 | ||||||||||||||||||||||||
| 34 | else if (i == 2)
| 0 | ||||||||||||||||||||||||
| 35 | return NID_X9_62_tpBasis; never executed: return 682; | 0 | ||||||||||||||||||||||||
| 36 | else | - | ||||||||||||||||||||||||
| 37 | /* everything else is currently not supported */ | - | ||||||||||||||||||||||||
| 38 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 39 | } | - | ||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||
| 41 | #ifndef OPENSSL_NO_EC2M | - | ||||||||||||||||||||||||
| 42 | int EC_GROUP_get_trinomial_basis(const EC_GROUP *group, unsigned int *k) | - | ||||||||||||||||||||||||
| 43 | { | - | ||||||||||||||||||||||||
| 44 | if (group == NULL)
| 0 | ||||||||||||||||||||||||
| 45 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||
| 47 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
| 0 | ||||||||||||||||||||||||
| 48 | NID_X9_62_characteristic_two_field
| 0 | ||||||||||||||||||||||||
| 49 | || !((group->poly[0] != 0) && (group->poly[1] != 0)
| 0 | ||||||||||||||||||||||||
| 50 | && (group->poly[2] == 0))) {
| 0 | ||||||||||||||||||||||||
| 51 | ECerr(EC_F_EC_GROUP_GET_TRINOMIAL_BASIS, | - | ||||||||||||||||||||||||
| 52 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
| 53 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 54 | } | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | if (k)
| 0 | ||||||||||||||||||||||||
| 57 | *k = group->poly[1]; never executed: *k = group->poly[1]; | 0 | ||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||
| 59 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
| 60 | } | - | ||||||||||||||||||||||||
| 61 | - | |||||||||||||||||||||||||
| 62 | int EC_GROUP_get_pentanomial_basis(const EC_GROUP *group, unsigned int *k1, | - | ||||||||||||||||||||||||
| 63 | unsigned int *k2, unsigned int *k3) | - | ||||||||||||||||||||||||
| 64 | { | - | ||||||||||||||||||||||||
| 65 | if (group == NULL)
| 0 | ||||||||||||||||||||||||
| 66 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 67 | - | |||||||||||||||||||||||||
| 68 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
| 0 | ||||||||||||||||||||||||
| 69 | NID_X9_62_characteristic_two_field
| 0 | ||||||||||||||||||||||||
| 70 | || !((group->poly[0] != 0) && (group->poly[1] != 0)
| 0 | ||||||||||||||||||||||||
| 71 | && (group->poly[2] != 0) && (group->poly[3] != 0)
| 0 | ||||||||||||||||||||||||
| 72 | && (group->poly[4] == 0))) {
| 0 | ||||||||||||||||||||||||
| 73 | ECerr(EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS, | - | ||||||||||||||||||||||||
| 74 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
| 75 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 76 | } | - | ||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | if (k1)
| 0 | ||||||||||||||||||||||||
| 79 | *k1 = group->poly[3]; never executed: *k1 = group->poly[3]; | 0 | ||||||||||||||||||||||||
| 80 | if (k2)
| 0 | ||||||||||||||||||||||||
| 81 | *k2 = group->poly[2]; never executed: *k2 = group->poly[2]; | 0 | ||||||||||||||||||||||||
| 82 | if (k3)
| 0 | ||||||||||||||||||||||||
| 83 | *k3 = group->poly[1]; never executed: *k3 = group->poly[1]; | 0 | ||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||
| 85 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
| 86 | } | - | ||||||||||||||||||||||||
| 87 | #endif | - | ||||||||||||||||||||||||
| 88 | - | |||||||||||||||||||||||||
| 89 | /* some structures needed for the asn1 encoding */ | - | ||||||||||||||||||||||||
| 90 | typedef struct x9_62_pentanomial_st { | - | ||||||||||||||||||||||||
| 91 | int32_t k1; | - | ||||||||||||||||||||||||
| 92 | int32_t k2; | - | ||||||||||||||||||||||||
| 93 | int32_t k3; | - | ||||||||||||||||||||||||
| 94 | } X9_62_PENTANOMIAL; | - | ||||||||||||||||||||||||
| 95 | - | |||||||||||||||||||||||||
| 96 | typedef struct x9_62_characteristic_two_st { | - | ||||||||||||||||||||||||
| 97 | int32_t m; | - | ||||||||||||||||||||||||
| 98 | ASN1_OBJECT *type; | - | ||||||||||||||||||||||||
| 99 | union { | - | ||||||||||||||||||||||||
| 100 | char *ptr; | - | ||||||||||||||||||||||||
| 101 | /* NID_X9_62_onBasis */ | - | ||||||||||||||||||||||||
| 102 | ASN1_NULL *onBasis; | - | ||||||||||||||||||||||||
| 103 | /* NID_X9_62_tpBasis */ | - | ||||||||||||||||||||||||
| 104 | ASN1_INTEGER *tpBasis; | - | ||||||||||||||||||||||||
| 105 | /* NID_X9_62_ppBasis */ | - | ||||||||||||||||||||||||
| 106 | X9_62_PENTANOMIAL *ppBasis; | - | ||||||||||||||||||||||||
| 107 | /* anything else */ | - | ||||||||||||||||||||||||
| 108 | ASN1_TYPE *other; | - | ||||||||||||||||||||||||
| 109 | } p; | - | ||||||||||||||||||||||||
| 110 | } X9_62_CHARACTERISTIC_TWO; | - | ||||||||||||||||||||||||
| 111 | - | |||||||||||||||||||||||||
| 112 | typedef struct x9_62_fieldid_st { | - | ||||||||||||||||||||||||
| 113 | ASN1_OBJECT *fieldType; | - | ||||||||||||||||||||||||
| 114 | union { | - | ||||||||||||||||||||||||
| 115 | char *ptr; | - | ||||||||||||||||||||||||
| 116 | /* NID_X9_62_prime_field */ | - | ||||||||||||||||||||||||
| 117 | ASN1_INTEGER *prime; | - | ||||||||||||||||||||||||
| 118 | /* NID_X9_62_characteristic_two_field */ | - | ||||||||||||||||||||||||
| 119 | X9_62_CHARACTERISTIC_TWO *char_two; | - | ||||||||||||||||||||||||
| 120 | /* anything else */ | - | ||||||||||||||||||||||||
| 121 | ASN1_TYPE *other; | - | ||||||||||||||||||||||||
| 122 | } p; | - | ||||||||||||||||||||||||
| 123 | } X9_62_FIELDID; | - | ||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||
| 125 | typedef struct x9_62_curve_st { | - | ||||||||||||||||||||||||
| 126 | ASN1_OCTET_STRING *a; | - | ||||||||||||||||||||||||
| 127 | ASN1_OCTET_STRING *b; | - | ||||||||||||||||||||||||
| 128 | ASN1_BIT_STRING *seed; | - | ||||||||||||||||||||||||
| 129 | } X9_62_CURVE; | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | struct ec_parameters_st { | - | ||||||||||||||||||||||||
| 132 | int32_t version; | - | ||||||||||||||||||||||||
| 133 | X9_62_FIELDID *fieldID; | - | ||||||||||||||||||||||||
| 134 | X9_62_CURVE *curve; | - | ||||||||||||||||||||||||
| 135 | ASN1_OCTET_STRING *base; | - | ||||||||||||||||||||||||
| 136 | ASN1_INTEGER *order; | - | ||||||||||||||||||||||||
| 137 | ASN1_INTEGER *cofactor; | - | ||||||||||||||||||||||||
| 138 | } /* ECPARAMETERS */ ; | - | ||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||
| 140 | struct ecpk_parameters_st { | - | ||||||||||||||||||||||||
| 141 | int type; | - | ||||||||||||||||||||||||
| 142 | union { | - | ||||||||||||||||||||||||
| 143 | ASN1_OBJECT *named_curve; | - | ||||||||||||||||||||||||
| 144 | ECPARAMETERS *parameters; | - | ||||||||||||||||||||||||
| 145 | ASN1_NULL *implicitlyCA; | - | ||||||||||||||||||||||||
| 146 | } value; | - | ||||||||||||||||||||||||
| 147 | } /* ECPKPARAMETERS */ ; | - | ||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||
| 149 | /* SEC1 ECPrivateKey */ | - | ||||||||||||||||||||||||
| 150 | typedef struct ec_privatekey_st { | - | ||||||||||||||||||||||||
| 151 | int32_t version; | - | ||||||||||||||||||||||||
| 152 | ASN1_OCTET_STRING *privateKey; | - | ||||||||||||||||||||||||
| 153 | ECPKPARAMETERS *parameters; | - | ||||||||||||||||||||||||
| 154 | ASN1_BIT_STRING *publicKey; | - | ||||||||||||||||||||||||
| 155 | } EC_PRIVATEKEY; | - | ||||||||||||||||||||||||
| 156 | - | |||||||||||||||||||||||||
| 157 | /* the OpenSSL ASN.1 definitions */ | - | ||||||||||||||||||||||||
| 158 | ASN1_SEQUENCE(X9_62_PENTANOMIAL) = { | - | ||||||||||||||||||||||||
| 159 | ASN1_EMBED(X9_62_PENTANOMIAL, k1, INT32), | - | ||||||||||||||||||||||||
| 160 | ASN1_EMBED(X9_62_PENTANOMIAL, k2, INT32), | - | ||||||||||||||||||||||||
| 161 | ASN1_EMBED(X9_62_PENTANOMIAL, k3, INT32) | - | ||||||||||||||||||||||||
| 162 | } static_ASN1_SEQUENCE_END(X9_62_PENTANOMIAL) | - | ||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | DECLARE_ASN1_ALLOC_FUNCTIONS(X9_62_PENTANOMIAL) | - | ||||||||||||||||||||||||
| 165 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS(X9_62_PENTANOMIAL) never executed: end of blocknever executed: return (X9_62_PENTANOMIAL *)ASN1_item_new((&(X9_62_PENTANOMIAL_it))); | 0 | ||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||
| 167 | ASN1_ADB_TEMPLATE(char_two_def) = ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, p.other, ASN1_ANY); | - | ||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | ASN1_ADB(X9_62_CHARACTERISTIC_TWO) = { | - | ||||||||||||||||||||||||
| 170 | ADB_ENTRY(NID_X9_62_onBasis, ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, p.onBasis, ASN1_NULL)), | - | ||||||||||||||||||||||||
| 171 | ADB_ENTRY(NID_X9_62_tpBasis, ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, p.tpBasis, ASN1_INTEGER)), | - | ||||||||||||||||||||||||
| 172 | ADB_ENTRY(NID_X9_62_ppBasis, ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, p.ppBasis, X9_62_PENTANOMIAL)) | - | ||||||||||||||||||||||||
| 173 | } ASN1_ADB_END(X9_62_CHARACTERISTIC_TWO, 0, type, 0, &char_two_def_tt, NULL); | - | ||||||||||||||||||||||||
| 174 | - | |||||||||||||||||||||||||
| 175 | ASN1_SEQUENCE(X9_62_CHARACTERISTIC_TWO) = { | - | ||||||||||||||||||||||||
| 176 | ASN1_EMBED(X9_62_CHARACTERISTIC_TWO, m, INT32), | - | ||||||||||||||||||||||||
| 177 | ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, type, ASN1_OBJECT), | - | ||||||||||||||||||||||||
| 178 | ASN1_ADB_OBJECT(X9_62_CHARACTERISTIC_TWO) | - | ||||||||||||||||||||||||
| 179 | } static_ASN1_SEQUENCE_END(X9_62_CHARACTERISTIC_TWO) | - | ||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||
| 181 | DECLARE_ASN1_ALLOC_FUNCTIONS(X9_62_CHARACTERISTIC_TWO) | - | ||||||||||||||||||||||||
| 182 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS(X9_62_CHARACTERISTIC_TWO) never executed: end of blocknever executed: return (X9_62_CHARACTERISTIC_TWO *)ASN1_item_new((&(X9_62_CHARACTERISTIC_TWO_it))); | 0 | ||||||||||||||||||||||||
| 183 | - | |||||||||||||||||||||||||
| 184 | ASN1_ADB_TEMPLATE(fieldID_def) = ASN1_SIMPLE(X9_62_FIELDID, p.other, ASN1_ANY); | - | ||||||||||||||||||||||||
| 185 | - | |||||||||||||||||||||||||
| 186 | ASN1_ADB(X9_62_FIELDID) = { | - | ||||||||||||||||||||||||
| 187 | ADB_ENTRY(NID_X9_62_prime_field, ASN1_SIMPLE(X9_62_FIELDID, p.prime, ASN1_INTEGER)), | - | ||||||||||||||||||||||||
| 188 | ADB_ENTRY(NID_X9_62_characteristic_two_field, ASN1_SIMPLE(X9_62_FIELDID, p.char_two, X9_62_CHARACTERISTIC_TWO)) | - | ||||||||||||||||||||||||
| 189 | } ASN1_ADB_END(X9_62_FIELDID, 0, fieldType, 0, &fieldID_def_tt, NULL); | - | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | ASN1_SEQUENCE(X9_62_FIELDID) = { | - | ||||||||||||||||||||||||
| 192 | ASN1_SIMPLE(X9_62_FIELDID, fieldType, ASN1_OBJECT), | - | ||||||||||||||||||||||||
| 193 | ASN1_ADB_OBJECT(X9_62_FIELDID) | - | ||||||||||||||||||||||||
| 194 | } static_ASN1_SEQUENCE_END(X9_62_FIELDID) | - | ||||||||||||||||||||||||
| 195 | - | |||||||||||||||||||||||||
| 196 | ASN1_SEQUENCE(X9_62_CURVE) = { | - | ||||||||||||||||||||||||
| 197 | ASN1_SIMPLE(X9_62_CURVE, a, ASN1_OCTET_STRING), | - | ||||||||||||||||||||||||
| 198 | ASN1_SIMPLE(X9_62_CURVE, b, ASN1_OCTET_STRING), | - | ||||||||||||||||||||||||
| 199 | ASN1_OPT(X9_62_CURVE, seed, ASN1_BIT_STRING) | - | ||||||||||||||||||||||||
| 200 | } static_ASN1_SEQUENCE_END(X9_62_CURVE) | - | ||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||
| 202 | ASN1_SEQUENCE(ECPARAMETERS) = { | - | ||||||||||||||||||||||||
| 203 | ASN1_EMBED(ECPARAMETERS, version, INT32), | - | ||||||||||||||||||||||||
| 204 | ASN1_SIMPLE(ECPARAMETERS, fieldID, X9_62_FIELDID), | - | ||||||||||||||||||||||||
| 205 | ASN1_SIMPLE(ECPARAMETERS, curve, X9_62_CURVE), | - | ||||||||||||||||||||||||
| 206 | ASN1_SIMPLE(ECPARAMETERS, base, ASN1_OCTET_STRING), | - | ||||||||||||||||||||||||
| 207 | ASN1_SIMPLE(ECPARAMETERS, order, ASN1_INTEGER), | - | ||||||||||||||||||||||||
| 208 | ASN1_OPT(ECPARAMETERS, cofactor, ASN1_INTEGER) | - | ||||||||||||||||||||||||
| 209 | } ASN1_SEQUENCE_END(ECPARAMETERS) | - | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS) | - | ||||||||||||||||||||||||
| 212 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS) executed 1 time by 1 test: end of blockExecuted by:
executed 47 times by 1 test: return (ECPARAMETERS *)ASN1_item_new((&(ECPARAMETERS_it)));Executed by:
| 1-47 | ||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | ASN1_CHOICE(ECPKPARAMETERS) = { | - | ||||||||||||||||||||||||
| 215 | ASN1_SIMPLE(ECPKPARAMETERS, value.named_curve, ASN1_OBJECT), | - | ||||||||||||||||||||||||
| 216 | ASN1_SIMPLE(ECPKPARAMETERS, value.parameters, ECPARAMETERS), | - | ||||||||||||||||||||||||
| 217 | ASN1_SIMPLE(ECPKPARAMETERS, value.implicitlyCA, ASN1_NULL) | - | ||||||||||||||||||||||||
| 218 | } ASN1_CHOICE_END(ECPKPARAMETERS) | - | ||||||||||||||||||||||||
| 219 | - | |||||||||||||||||||||||||
| 220 | DECLARE_ASN1_FUNCTIONS_const(ECPKPARAMETERS) | - | ||||||||||||||||||||||||
| 221 | DECLARE_ASN1_ENCODE_FUNCTIONS_const(ECPKPARAMETERS, ECPKPARAMETERS) | - | ||||||||||||||||||||||||
| 222 | IMPLEMENT_ASN1_FUNCTIONS_const(ECPKPARAMETERS) executed 8747 times by 1 test: end of blockExecuted by:
executed 8699 times by 1 test: return (ECPKPARAMETERS *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(ECPKPARAMETERS_it)));Executed by:
executed 48 times by 1 test: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(ECPKPARAMETERS_it)));Executed by:
executed 254 times by 1 test: return (ECPKPARAMETERS *)ASN1_item_new((&(ECPKPARAMETERS_it)));Executed by:
| 48-8747 | ||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||
| 224 | ASN1_SEQUENCE(EC_PRIVATEKEY) = { | - | ||||||||||||||||||||||||
| 225 | ASN1_EMBED(EC_PRIVATEKEY, version, INT32), | - | ||||||||||||||||||||||||
| 226 | ASN1_SIMPLE(EC_PRIVATEKEY, privateKey, ASN1_OCTET_STRING), | - | ||||||||||||||||||||||||
| 227 | ASN1_EXP_OPT(EC_PRIVATEKEY, parameters, ECPKPARAMETERS, 0), | - | ||||||||||||||||||||||||
| 228 | ASN1_EXP_OPT(EC_PRIVATEKEY, publicKey, ASN1_BIT_STRING, 1) | - | ||||||||||||||||||||||||
| 229 | } static_ASN1_SEQUENCE_END(EC_PRIVATEKEY) | - | ||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||
| 231 | DECLARE_ASN1_FUNCTIONS_const(EC_PRIVATEKEY) | - | ||||||||||||||||||||||||
| 232 | DECLARE_ASN1_ENCODE_FUNCTIONS_const(EC_PRIVATEKEY, EC_PRIVATEKEY) | - | ||||||||||||||||||||||||
| 233 | IMPLEMENT_ASN1_FUNCTIONS_const(EC_PRIVATEKEY) executed 3315 times by 1 test: end of blockExecuted by:
executed 6352 times by 1 test: return (EC_PRIVATEKEY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(EC_PRIVATEKEY_it)));Executed by:
executed 216 times by 1 test: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(EC_PRIVATEKEY_it)));Executed by:
executed 255 times by 1 test: return (EC_PRIVATEKEY *)ASN1_item_new((&(EC_PRIVATEKEY_it)));Executed by:
| 216-6352 | ||||||||||||||||||||||||
| 234 | - | |||||||||||||||||||||||||
| 235 | /* some declarations of internal function */ | - | ||||||||||||||||||||||||
| 236 | - | |||||||||||||||||||||||||
| 237 | /* ec_asn1_group2field() sets the values in a X9_62_FIELDID object */ | - | ||||||||||||||||||||||||
| 238 | static int ec_asn1_group2fieldid(const EC_GROUP *, X9_62_FIELDID *); | - | ||||||||||||||||||||||||
| 239 | /* ec_asn1_group2curve() sets the values in a X9_62_CURVE object */ | - | ||||||||||||||||||||||||
| 240 | static int ec_asn1_group2curve(const EC_GROUP *, X9_62_CURVE *); | - | ||||||||||||||||||||||||
| 241 | - | |||||||||||||||||||||||||
| 242 | /* the function definitions */ | - | ||||||||||||||||||||||||
| 243 | - | |||||||||||||||||||||||||
| 244 | static int ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field) | - | ||||||||||||||||||||||||
| 245 | { | - | ||||||||||||||||||||||||
| 246 | int ok = 0, nid; | - | ||||||||||||||||||||||||
| 247 | BIGNUM *tmp = NULL; | - | ||||||||||||||||||||||||
| 248 | - | |||||||||||||||||||||||||
| 249 | if (group == NULL || field == NULL)
| 0-47 | ||||||||||||||||||||||||
| 250 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||
| 252 | /* clear the old values (if necessary) */ | - | ||||||||||||||||||||||||
| 253 | ASN1_OBJECT_free(field->fieldType); | - | ||||||||||||||||||||||||
| 254 | ASN1_TYPE_free(field->p.other); | - | ||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||
| 256 | nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group)); | - | ||||||||||||||||||||||||
| 257 | /* set OID for the field */ | - | ||||||||||||||||||||||||
| 258 | if ((field->fieldType = OBJ_nid2obj(nid)) == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 259 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_OBJ_LIB); | - | ||||||||||||||||||||||||
| 260 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 261 | } | - | ||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||
| 263 | if (nid == NID_X9_62_prime_field) {
| 0-47 | ||||||||||||||||||||||||
| 264 | if ((tmp = BN_new()) == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 265 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 266 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 267 | } | - | ||||||||||||||||||||||||
| 268 | /* the parameters are specified by the prime number p */ | - | ||||||||||||||||||||||||
| 269 | if (!EC_GROUP_get_curve(group, tmp, NULL, NULL, NULL)) {
| 0-47 | ||||||||||||||||||||||||
| 270 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 271 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 272 | } | - | ||||||||||||||||||||||||
| 273 | /* set the prime number */ | - | ||||||||||||||||||||||||
| 274 | field->p.prime = BN_to_ASN1_INTEGER(tmp, NULL); | - | ||||||||||||||||||||||||
| 275 | if (field->p.prime == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 276 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_ASN1_LIB); | - | ||||||||||||||||||||||||
| 277 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 278 | } | - | ||||||||||||||||||||||||
| 279 | } else if (nid == NID_X9_62_characteristic_two_field) executed 47 times by 1 test: end of blockExecuted by:
| 0-47 | ||||||||||||||||||||||||
| 280 | #ifdef OPENSSL_NO_EC2M | - | ||||||||||||||||||||||||
| 281 | { | - | ||||||||||||||||||||||||
| 282 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, EC_R_GF2M_NOT_SUPPORTED); | - | ||||||||||||||||||||||||
| 283 | goto err; | - | ||||||||||||||||||||||||
| 284 | } | - | ||||||||||||||||||||||||
| 285 | #else | - | ||||||||||||||||||||||||
| 286 | { | - | ||||||||||||||||||||||||
| 287 | int field_type; | - | ||||||||||||||||||||||||
| 288 | X9_62_CHARACTERISTIC_TWO *char_two; | - | ||||||||||||||||||||||||
| 289 | - | |||||||||||||||||||||||||
| 290 | field->p.char_two = X9_62_CHARACTERISTIC_TWO_new(); | - | ||||||||||||||||||||||||
| 291 | char_two = field->p.char_two; | - | ||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | if (char_two == NULL) {
| 0 | ||||||||||||||||||||||||
| 294 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 295 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 296 | } | - | ||||||||||||||||||||||||
| 297 | - | |||||||||||||||||||||||||
| 298 | char_two->m = (long)EC_GROUP_get_degree(group); | - | ||||||||||||||||||||||||
| 299 | - | |||||||||||||||||||||||||
| 300 | field_type = EC_GROUP_get_basis_type(group); | - | ||||||||||||||||||||||||
| 301 | - | |||||||||||||||||||||||||
| 302 | if (field_type == 0) {
| 0 | ||||||||||||||||||||||||
| 303 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 304 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 305 | } | - | ||||||||||||||||||||||||
| 306 | /* set base type OID */ | - | ||||||||||||||||||||||||
| 307 | if ((char_two->type = OBJ_nid2obj(field_type)) == NULL) {
| 0 | ||||||||||||||||||||||||
| 308 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_OBJ_LIB); | - | ||||||||||||||||||||||||
| 309 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 310 | } | - | ||||||||||||||||||||||||
| 311 | - | |||||||||||||||||||||||||
| 312 | if (field_type == NID_X9_62_tpBasis) {
| 0 | ||||||||||||||||||||||||
| 313 | unsigned int k; | - | ||||||||||||||||||||||||
| 314 | - | |||||||||||||||||||||||||
| 315 | if (!EC_GROUP_get_trinomial_basis(group, &k))
| 0 | ||||||||||||||||||||||||
| 316 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||
| 318 | char_two->p.tpBasis = ASN1_INTEGER_new(); | - | ||||||||||||||||||||||||
| 319 | if (char_two->p.tpBasis == NULL) {
| 0 | ||||||||||||||||||||||||
| 320 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 321 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 322 | } | - | ||||||||||||||||||||||||
| 323 | if (!ASN1_INTEGER_set(char_two->p.tpBasis, (long)k)) {
| 0 | ||||||||||||||||||||||||
| 324 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_ASN1_LIB); | - | ||||||||||||||||||||||||
| 325 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 326 | } | - | ||||||||||||||||||||||||
| 327 | } else if (field_type == NID_X9_62_ppBasis) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 328 | unsigned int k1, k2, k3; | - | ||||||||||||||||||||||||
| 329 | - | |||||||||||||||||||||||||
| 330 | if (!EC_GROUP_get_pentanomial_basis(group, &k1, &k2, &k3))
| 0 | ||||||||||||||||||||||||
| 331 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||
| 333 | char_two->p.ppBasis = X9_62_PENTANOMIAL_new(); | - | ||||||||||||||||||||||||
| 334 | if (char_two->p.ppBasis == NULL) {
| 0 | ||||||||||||||||||||||||
| 335 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 336 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 337 | } | - | ||||||||||||||||||||||||
| 338 | - | |||||||||||||||||||||||||
| 339 | /* set k? values */ | - | ||||||||||||||||||||||||
| 340 | char_two->p.ppBasis->k1 = (long)k1; | - | ||||||||||||||||||||||||
| 341 | char_two->p.ppBasis->k2 = (long)k2; | - | ||||||||||||||||||||||||
| 342 | char_two->p.ppBasis->k3 = (long)k3; | - | ||||||||||||||||||||||||
| 343 | } else { /* field_type == NID_X9_62_onBasis */ never executed: end of block | 0 | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | /* for ONB the parameters are (asn1) NULL */ | - | ||||||||||||||||||||||||
| 346 | char_two->p.onBasis = ASN1_NULL_new(); | - | ||||||||||||||||||||||||
| 347 | if (char_two->p.onBasis == NULL) {
| 0 | ||||||||||||||||||||||||
| 348 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 349 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 350 | } | - | ||||||||||||||||||||||||
| 351 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 352 | } | - | ||||||||||||||||||||||||
| 353 | #endif | - | ||||||||||||||||||||||||
| 354 | else { | - | ||||||||||||||||||||||||
| 355 | ECerr(EC_F_EC_ASN1_GROUP2FIELDID, EC_R_UNSUPPORTED_FIELD); | - | ||||||||||||||||||||||||
| 356 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 357 | } | - | ||||||||||||||||||||||||
| 358 | - | |||||||||||||||||||||||||
| 359 | ok = 1; | - | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | err: code before this statement executed 47 times by 1 test: err:Executed by:
| 47 | ||||||||||||||||||||||||
| 362 | BN_free(tmp); | - | ||||||||||||||||||||||||
| 363 | return ok; executed 47 times by 1 test: return ok;Executed by:
| 47 | ||||||||||||||||||||||||
| 364 | } | - | ||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||
| 366 | static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve) | - | ||||||||||||||||||||||||
| 367 | { | - | ||||||||||||||||||||||||
| 368 | int ok = 0; | - | ||||||||||||||||||||||||
| 369 | BIGNUM *tmp_1 = NULL, *tmp_2 = NULL; | - | ||||||||||||||||||||||||
| 370 | unsigned char *a_buf = NULL, *b_buf = NULL; | - | ||||||||||||||||||||||||
| 371 | size_t len; | - | ||||||||||||||||||||||||
| 372 | - | |||||||||||||||||||||||||
| 373 | if (!group || !curve || !curve->a || !curve->b)
| 0-47 | ||||||||||||||||||||||||
| 374 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||
| 376 | if ((tmp_1 = BN_new()) == NULL || (tmp_2 = BN_new()) == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 377 | ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 378 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 379 | } | - | ||||||||||||||||||||||||
| 380 | - | |||||||||||||||||||||||||
| 381 | /* get a and b */ | - | ||||||||||||||||||||||||
| 382 | if (!EC_GROUP_get_curve(group, NULL, tmp_1, tmp_2, NULL)) {
| 0-47 | ||||||||||||||||||||||||
| 383 | ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 384 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 385 | } | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | /* | - | ||||||||||||||||||||||||
| 388 | * Per SEC 1, the curve coefficients must be padded up to size. See C.2's | - | ||||||||||||||||||||||||
| 389 | * definition of Curve, C.1's definition of FieldElement, and 2.3.5's | - | ||||||||||||||||||||||||
| 390 | * definition of how to encode the field elements. | - | ||||||||||||||||||||||||
| 391 | */ | - | ||||||||||||||||||||||||
| 392 | len = ((size_t)EC_GROUP_get_degree(group) + 7) / 8; | - | ||||||||||||||||||||||||
| 393 | if ((a_buf = OPENSSL_malloc(len)) == NULL
| 0-47 | ||||||||||||||||||||||||
| 394 | || (b_buf = OPENSSL_malloc(len)) == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 395 | ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 396 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 397 | } | - | ||||||||||||||||||||||||
| 398 | if (BN_bn2binpad(tmp_1, a_buf, len) < 0
| 0-47 | ||||||||||||||||||||||||
| 399 | || BN_bn2binpad(tmp_2, b_buf, len) < 0) {
| 0-47 | ||||||||||||||||||||||||
| 400 | ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_BN_LIB); | - | ||||||||||||||||||||||||
| 401 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 402 | } | - | ||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||
| 404 | /* set a and b */ | - | ||||||||||||||||||||||||
| 405 | if (!ASN1_OCTET_STRING_set(curve->a, a_buf, len)
| 0-47 | ||||||||||||||||||||||||
| 406 | || !ASN1_OCTET_STRING_set(curve->b, b_buf, len)) {
| 0-47 | ||||||||||||||||||||||||
| 407 | ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_ASN1_LIB); | - | ||||||||||||||||||||||||
| 408 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 409 | } | - | ||||||||||||||||||||||||
| 410 | - | |||||||||||||||||||||||||
| 411 | /* set the seed (optional) */ | - | ||||||||||||||||||||||||
| 412 | if (group->seed) {
| 19-28 | ||||||||||||||||||||||||
| 413 | if (!curve->seed)
| 0-19 | ||||||||||||||||||||||||
| 414 | if ((curve->seed = ASN1_BIT_STRING_new()) == NULL) {
| 0-19 | ||||||||||||||||||||||||
| 415 | ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 416 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 417 | } | - | ||||||||||||||||||||||||
| 418 | curve->seed->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); | - | ||||||||||||||||||||||||
| 419 | curve->seed->flags |= ASN1_STRING_FLAG_BITS_LEFT; | - | ||||||||||||||||||||||||
| 420 | if (!ASN1_BIT_STRING_set(curve->seed, group->seed,
| 0-19 | ||||||||||||||||||||||||
| 421 | (int)group->seed_len)) {
| 0-19 | ||||||||||||||||||||||||
| 422 | ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_ASN1_LIB); | - | ||||||||||||||||||||||||
| 423 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 424 | } | - | ||||||||||||||||||||||||
| 425 | } else { executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||||||||||||||
| 426 | ASN1_BIT_STRING_free(curve->seed); | - | ||||||||||||||||||||||||
| 427 | curve->seed = NULL; | - | ||||||||||||||||||||||||
| 428 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 429 | - | |||||||||||||||||||||||||
| 430 | ok = 1; | - | ||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||
| 432 | err: code before this statement executed 47 times by 1 test: err:Executed by:
| 47 | ||||||||||||||||||||||||
| 433 | OPENSSL_free(a_buf); | - | ||||||||||||||||||||||||
| 434 | OPENSSL_free(b_buf); | - | ||||||||||||||||||||||||
| 435 | BN_free(tmp_1); | - | ||||||||||||||||||||||||
| 436 | BN_free(tmp_2); | - | ||||||||||||||||||||||||
| 437 | return ok; executed 47 times by 1 test: return ok;Executed by:
| 47 | ||||||||||||||||||||||||
| 438 | } | - | ||||||||||||||||||||||||
| 439 | - | |||||||||||||||||||||||||
| 440 | ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, | - | ||||||||||||||||||||||||
| 441 | ECPARAMETERS *params) | - | ||||||||||||||||||||||||
| 442 | { | - | ||||||||||||||||||||||||
| 443 | size_t len = 0; | - | ||||||||||||||||||||||||
| 444 | ECPARAMETERS *ret = NULL; | - | ||||||||||||||||||||||||
| 445 | const BIGNUM *tmp; | - | ||||||||||||||||||||||||
| 446 | unsigned char *buffer = NULL; | - | ||||||||||||||||||||||||
| 447 | const EC_POINT *point = NULL; | - | ||||||||||||||||||||||||
| 448 | point_conversion_form_t form; | - | ||||||||||||||||||||||||
| 449 | - | |||||||||||||||||||||||||
| 450 | if (params == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 451 | if ((ret = ECPARAMETERS_new()) == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 452 | ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 453 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 454 | } | - | ||||||||||||||||||||||||
| 455 | } else executed 47 times by 1 test: end of blockExecuted by:
| 47 | ||||||||||||||||||||||||
| 456 | ret = params; never executed: ret = params; | 0 | ||||||||||||||||||||||||
| 457 | - | |||||||||||||||||||||||||
| 458 | /* set the version (always one) */ | - | ||||||||||||||||||||||||
| 459 | ret->version = (long)0x1; | - | ||||||||||||||||||||||||
| 460 | - | |||||||||||||||||||||||||
| 461 | /* set the fieldID */ | - | ||||||||||||||||||||||||
| 462 | if (!ec_asn1_group2fieldid(group, ret->fieldID)) {
| 0-47 | ||||||||||||||||||||||||
| 463 | ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 464 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 465 | } | - | ||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | /* set the curve */ | - | ||||||||||||||||||||||||
| 468 | if (!ec_asn1_group2curve(group, ret->curve)) {
| 0-47 | ||||||||||||||||||||||||
| 469 | ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 470 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 471 | } | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | /* set the base point */ | - | ||||||||||||||||||||||||
| 474 | if ((point = EC_GROUP_get0_generator(group)) == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 475 | ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, EC_R_UNDEFINED_GENERATOR); | - | ||||||||||||||||||||||||
| 476 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 477 | } | - | ||||||||||||||||||||||||
| 478 | - | |||||||||||||||||||||||||
| 479 | form = EC_GROUP_get_point_conversion_form(group); | - | ||||||||||||||||||||||||
| 480 | - | |||||||||||||||||||||||||
| 481 | len = EC_POINT_point2buf(group, point, form, &buffer, NULL); | - | ||||||||||||||||||||||||
| 482 | if (len == 0) {
| 0-47 | ||||||||||||||||||||||||
| 483 | ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 484 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 485 | } | - | ||||||||||||||||||||||||
| 486 | if (ret->base == NULL && (ret->base = ASN1_OCTET_STRING_new()) == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 487 | OPENSSL_free(buffer); | - | ||||||||||||||||||||||||
| 488 | ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 489 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 490 | } | - | ||||||||||||||||||||||||
| 491 | ASN1_STRING_set0(ret->base, buffer, len); | - | ||||||||||||||||||||||||
| 492 | - | |||||||||||||||||||||||||
| 493 | /* set the order */ | - | ||||||||||||||||||||||||
| 494 | tmp = EC_GROUP_get0_order(group); | - | ||||||||||||||||||||||||
| 495 | if (tmp == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 496 | ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 497 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 498 | } | - | ||||||||||||||||||||||||
| 499 | ret->order = BN_to_ASN1_INTEGER(tmp, ret->order); | - | ||||||||||||||||||||||||
| 500 | if (ret->order == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 501 | ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_ASN1_LIB); | - | ||||||||||||||||||||||||
| 502 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 503 | } | - | ||||||||||||||||||||||||
| 504 | - | |||||||||||||||||||||||||
| 505 | /* set the cofactor (optional) */ | - | ||||||||||||||||||||||||
| 506 | tmp = EC_GROUP_get0_cofactor(group); | - | ||||||||||||||||||||||||
| 507 | if (tmp != NULL) {
| 0-47 | ||||||||||||||||||||||||
| 508 | ret->cofactor = BN_to_ASN1_INTEGER(tmp, ret->cofactor); | - | ||||||||||||||||||||||||
| 509 | if (ret->cofactor == NULL) {
| 0-47 | ||||||||||||||||||||||||
| 510 | ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_ASN1_LIB); | - | ||||||||||||||||||||||||
| 511 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 512 | } | - | ||||||||||||||||||||||||
| 513 | } executed 47 times by 1 test: end of blockExecuted by:
| 47 | ||||||||||||||||||||||||
| 514 | - | |||||||||||||||||||||||||
| 515 | return ret; executed 47 times by 1 test: return ret;Executed by:
| 47 | ||||||||||||||||||||||||
| 516 | - | |||||||||||||||||||||||||
| 517 | err: | - | ||||||||||||||||||||||||
| 518 | if (params == NULL)
| 0 | ||||||||||||||||||||||||
| 519 | ECPARAMETERS_free(ret); never executed: ECPARAMETERS_free(ret); | 0 | ||||||||||||||||||||||||
| 520 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 521 | } | - | ||||||||||||||||||||||||
| 522 | - | |||||||||||||||||||||||||
| 523 | ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group, | - | ||||||||||||||||||||||||
| 524 | ECPKPARAMETERS *params) | - | ||||||||||||||||||||||||
| 525 | { | - | ||||||||||||||||||||||||
| 526 | int ok = 1, tmp; | - | ||||||||||||||||||||||||
| 527 | ECPKPARAMETERS *ret = params; | - | ||||||||||||||||||||||||
| 528 | - | |||||||||||||||||||||||||
| 529 | if (ret == NULL) {
| 0-254 | ||||||||||||||||||||||||
| 530 | if ((ret = ECPKPARAMETERS_new()) == NULL) {
| 0-254 | ||||||||||||||||||||||||
| 531 | ECerr(EC_F_EC_GROUP_GET_ECPKPARAMETERS, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 532 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 533 | } | - | ||||||||||||||||||||||||
| 534 | } else { executed 254 times by 1 test: end of blockExecuted by:
| 254 | ||||||||||||||||||||||||
| 535 | if (ret->type == 0)
| 0 | ||||||||||||||||||||||||
| 536 | ASN1_OBJECT_free(ret->value.named_curve); never executed: ASN1_OBJECT_free(ret->value.named_curve); | 0 | ||||||||||||||||||||||||
| 537 | else if (ret->type == 1 && ret->value.parameters)
| 0 | ||||||||||||||||||||||||
| 538 | ECPARAMETERS_free(ret->value.parameters); never executed: ECPARAMETERS_free(ret->value.parameters); | 0 | ||||||||||||||||||||||||
| 539 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 540 | - | |||||||||||||||||||||||||
| 541 | if (EC_GROUP_get_asn1_flag(group)) {
| 46-208 | ||||||||||||||||||||||||
| 542 | /* | - | ||||||||||||||||||||||||
| 543 | * use the asn1 OID to describe the elliptic curve parameters | - | ||||||||||||||||||||||||
| 544 | */ | - | ||||||||||||||||||||||||
| 545 | tmp = EC_GROUP_get_curve_name(group); | - | ||||||||||||||||||||||||
| 546 | if (tmp) {
| 0-208 | ||||||||||||||||||||||||
| 547 | ret->type = 0; | - | ||||||||||||||||||||||||
| 548 | if ((ret->value.named_curve = OBJ_nid2obj(tmp)) == NULL)
| 0-208 | ||||||||||||||||||||||||
| 549 | ok = 0; never executed: ok = 0; | 0 | ||||||||||||||||||||||||
| 550 | } else executed 208 times by 1 test: end of blockExecuted by:
| 208 | ||||||||||||||||||||||||
| 551 | /* we don't know the nid => ERROR */ | - | ||||||||||||||||||||||||
| 552 | ok = 0; never executed: ok = 0; | 0 | ||||||||||||||||||||||||
| 553 | } else { | - | ||||||||||||||||||||||||
| 554 | /* use the ECPARAMETERS structure */ | - | ||||||||||||||||||||||||
| 555 | ret->type = 1; | - | ||||||||||||||||||||||||
| 556 | if ((ret->value.parameters =
| 0-46 | ||||||||||||||||||||||||
| 557 | EC_GROUP_get_ecparameters(group, NULL)) == NULL)
| 0-46 | ||||||||||||||||||||||||
| 558 | ok = 0; never executed: ok = 0; | 0 | ||||||||||||||||||||||||
| 559 | } executed 46 times by 1 test: end of blockExecuted by:
| 46 | ||||||||||||||||||||||||
| 560 | - | |||||||||||||||||||||||||
| 561 | if (!ok) {
| 0-254 | ||||||||||||||||||||||||
| 562 | ECPKPARAMETERS_free(ret); | - | ||||||||||||||||||||||||
| 563 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 564 | } | - | ||||||||||||||||||||||||
| 565 | return ret; executed 254 times by 1 test: return ret;Executed by:
| 254 | ||||||||||||||||||||||||
| 566 | } | - | ||||||||||||||||||||||||
| 567 | - | |||||||||||||||||||||||||
| 568 | EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params) | - | ||||||||||||||||||||||||
| 569 | { | - | ||||||||||||||||||||||||
| 570 | int ok = 0, tmp; | - | ||||||||||||||||||||||||
| 571 | EC_GROUP *ret = NULL; | - | ||||||||||||||||||||||||
| 572 | BIGNUM *p = NULL, *a = NULL, *b = NULL; | - | ||||||||||||||||||||||||
| 573 | EC_POINT *point = NULL; | - | ||||||||||||||||||||||||
| 574 | long field_bits; | - | ||||||||||||||||||||||||
| 575 | - | |||||||||||||||||||||||||
| 576 | if (!params->fieldID || !params->fieldID->fieldType ||
| 0-1046 | ||||||||||||||||||||||||
| 577 | !params->fieldID->p.ptr) {
| 0-1046 | ||||||||||||||||||||||||
| 578 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR); | - | ||||||||||||||||||||||||
| 579 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 580 | } | - | ||||||||||||||||||||||||
| 581 | - | |||||||||||||||||||||||||
| 582 | /* | - | ||||||||||||||||||||||||
| 583 | * Now extract the curve parameters a and b. Note that, although SEC 1 | - | ||||||||||||||||||||||||
| 584 | * specifies the length of their encodings, historical versions of OpenSSL | - | ||||||||||||||||||||||||
| 585 | * encoded them incorrectly, so we must accept any length for backwards | - | ||||||||||||||||||||||||
| 586 | * compatibility. | - | ||||||||||||||||||||||||
| 587 | */ | - | ||||||||||||||||||||||||
| 588 | if (!params->curve || !params->curve->a ||
| 0-1046 | ||||||||||||||||||||||||
| 589 | !params->curve->a->data || !params->curve->b ||
| 0-1046 | ||||||||||||||||||||||||
| 590 | !params->curve->b->data) {
| 0-1046 | ||||||||||||||||||||||||
| 591 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR); | - | ||||||||||||||||||||||||
| 592 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 593 | } | - | ||||||||||||||||||||||||
| 594 | a = BN_bin2bn(params->curve->a->data, params->curve->a->length, NULL); | - | ||||||||||||||||||||||||
| 595 | if (a == NULL) {
| 0-1046 | ||||||||||||||||||||||||
| 596 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_BN_LIB); | - | ||||||||||||||||||||||||
| 597 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 598 | } | - | ||||||||||||||||||||||||
| 599 | b = BN_bin2bn(params->curve->b->data, params->curve->b->length, NULL); | - | ||||||||||||||||||||||||
| 600 | if (b == NULL) {
| 0-1046 | ||||||||||||||||||||||||
| 601 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_BN_LIB); | - | ||||||||||||||||||||||||
| 602 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 603 | } | - | ||||||||||||||||||||||||
| 604 | - | |||||||||||||||||||||||||
| 605 | /* get the field parameters */ | - | ||||||||||||||||||||||||
| 606 | tmp = OBJ_obj2nid(params->fieldID->fieldType); | - | ||||||||||||||||||||||||
| 607 | if (tmp == NID_X9_62_characteristic_two_field)
| 41-1005 | ||||||||||||||||||||||||
| 608 | #ifdef OPENSSL_NO_EC2M | - | ||||||||||||||||||||||||
| 609 | { | - | ||||||||||||||||||||||||
| 610 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_GF2M_NOT_SUPPORTED); | - | ||||||||||||||||||||||||
| 611 | goto err; | - | ||||||||||||||||||||||||
| 612 | } | - | ||||||||||||||||||||||||
| 613 | #else | - | ||||||||||||||||||||||||
| 614 | { | - | ||||||||||||||||||||||||
| 615 | X9_62_CHARACTERISTIC_TWO *char_two; | - | ||||||||||||||||||||||||
| 616 | - | |||||||||||||||||||||||||
| 617 | char_two = params->fieldID->p.char_two; | - | ||||||||||||||||||||||||
| 618 | - | |||||||||||||||||||||||||
| 619 | field_bits = char_two->m; | - | ||||||||||||||||||||||||
| 620 | if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {
| 0-41 | ||||||||||||||||||||||||
| 621 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_FIELD_TOO_LARGE); | - | ||||||||||||||||||||||||
| 622 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 623 | } | - | ||||||||||||||||||||||||
| 624 | - | |||||||||||||||||||||||||
| 625 | if ((p = BN_new()) == NULL) {
| 0-41 | ||||||||||||||||||||||||
| 626 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 627 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 628 | } | - | ||||||||||||||||||||||||
| 629 | - | |||||||||||||||||||||||||
| 630 | /* get the base type */ | - | ||||||||||||||||||||||||
| 631 | tmp = OBJ_obj2nid(char_two->type); | - | ||||||||||||||||||||||||
| 632 | - | |||||||||||||||||||||||||
| 633 | if (tmp == NID_X9_62_tpBasis) {
| 20-21 | ||||||||||||||||||||||||
| 634 | long tmp_long; | - | ||||||||||||||||||||||||
| 635 | - | |||||||||||||||||||||||||
| 636 | if (!char_two->p.tpBasis) {
| 0-21 | ||||||||||||||||||||||||
| 637 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR); | - | ||||||||||||||||||||||||
| 638 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 639 | } | - | ||||||||||||||||||||||||
| 640 | - | |||||||||||||||||||||||||
| 641 | tmp_long = ASN1_INTEGER_get(char_two->p.tpBasis); | - | ||||||||||||||||||||||||
| 642 | - | |||||||||||||||||||||||||
| 643 | if (!(char_two->m > tmp_long && tmp_long > 0)) {
| 0-21 | ||||||||||||||||||||||||
| 644 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, | - | ||||||||||||||||||||||||
| 645 | EC_R_INVALID_TRINOMIAL_BASIS); | - | ||||||||||||||||||||||||
| 646 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 647 | } | - | ||||||||||||||||||||||||
| 648 | - | |||||||||||||||||||||||||
| 649 | /* create the polynomial */ | - | ||||||||||||||||||||||||
| 650 | if (!BN_set_bit(p, (int)char_two->m))
| 0-21 | ||||||||||||||||||||||||
| 651 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 652 | if (!BN_set_bit(p, (int)tmp_long))
| 0-21 | ||||||||||||||||||||||||
| 653 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 654 | if (!BN_set_bit(p, 0))
| 0-21 | ||||||||||||||||||||||||
| 655 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 656 | } else if (tmp == NID_X9_62_ppBasis) { executed 21 times by 1 test: end of blockExecuted by:
| 0-21 | ||||||||||||||||||||||||
| 657 | X9_62_PENTANOMIAL *penta; | - | ||||||||||||||||||||||||
| 658 | - | |||||||||||||||||||||||||
| 659 | penta = char_two->p.ppBasis; | - | ||||||||||||||||||||||||
| 660 | if (!penta) {
| 0-20 | ||||||||||||||||||||||||
| 661 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR); | - | ||||||||||||||||||||||||
| 662 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 663 | } | - | ||||||||||||||||||||||||
| 664 | - | |||||||||||||||||||||||||
| 665 | if (! | - | ||||||||||||||||||||||||
| 666 | (char_two->m > penta->k3 && penta->k3 > penta->k2
| 0-20 | ||||||||||||||||||||||||
| 667 | && penta->k2 > penta->k1 && penta->k1 > 0)) {
| 0-20 | ||||||||||||||||||||||||
| 668 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, | - | ||||||||||||||||||||||||
| 669 | EC_R_INVALID_PENTANOMIAL_BASIS); | - | ||||||||||||||||||||||||
| 670 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 671 | } | - | ||||||||||||||||||||||||
| 672 | - | |||||||||||||||||||||||||
| 673 | /* create the polynomial */ | - | ||||||||||||||||||||||||
| 674 | if (!BN_set_bit(p, (int)char_two->m))
| 0-20 | ||||||||||||||||||||||||
| 675 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 676 | if (!BN_set_bit(p, (int)penta->k1))
| 0-20 | ||||||||||||||||||||||||
| 677 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 678 | if (!BN_set_bit(p, (int)penta->k2))
| 0-20 | ||||||||||||||||||||||||
| 679 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 680 | if (!BN_set_bit(p, (int)penta->k3))
| 0-20 | ||||||||||||||||||||||||
| 681 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 682 | if (!BN_set_bit(p, 0))
| 0-20 | ||||||||||||||||||||||||
| 683 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 684 | } else if (tmp == NID_X9_62_onBasis) { executed 20 times by 1 test: end of blockExecuted by:
| 0-20 | ||||||||||||||||||||||||
| 685 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_NOT_IMPLEMENTED); | - | ||||||||||||||||||||||||
| 686 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 687 | } else { /* error */ | - | ||||||||||||||||||||||||
| 688 | - | |||||||||||||||||||||||||
| 689 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR); | - | ||||||||||||||||||||||||
| 690 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 691 | } | - | ||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||
| 693 | /* create the EC_GROUP structure */ | - | ||||||||||||||||||||||||
| 694 | ret = EC_GROUP_new_curve_GF2m(p, a, b, NULL); | - | ||||||||||||||||||||||||
| 695 | } executed 41 times by 1 test: end of blockExecuted by:
| 41 | ||||||||||||||||||||||||
| 696 | #endif | - | ||||||||||||||||||||||||
| 697 | else if (tmp == NID_X9_62_prime_field) {
| 37-968 | ||||||||||||||||||||||||
| 698 | /* we have a curve over a prime field */ | - | ||||||||||||||||||||||||
| 699 | /* extract the prime number */ | - | ||||||||||||||||||||||||
| 700 | if (!params->fieldID->p.prime) {
| 0-968 | ||||||||||||||||||||||||
| 701 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR); | - | ||||||||||||||||||||||||
| 702 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 703 | } | - | ||||||||||||||||||||||||
| 704 | p = ASN1_INTEGER_to_BN(params->fieldID->p.prime, NULL); | - | ||||||||||||||||||||||||
| 705 | if (p == NULL) {
| 0-968 | ||||||||||||||||||||||||
| 706 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_ASN1_LIB); | - | ||||||||||||||||||||||||
| 707 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 708 | } | - | ||||||||||||||||||||||||
| 709 | - | |||||||||||||||||||||||||
| 710 | if (BN_is_negative(p) || BN_is_zero(p)) {
| 0-899 | ||||||||||||||||||||||||
| 711 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_INVALID_FIELD); | - | ||||||||||||||||||||||||
| 712 | goto err; executed 69 times by 1 test: goto err;Executed by:
| 69 | ||||||||||||||||||||||||
| 713 | } | - | ||||||||||||||||||||||||
| 714 | - | |||||||||||||||||||||||||
| 715 | field_bits = BN_num_bits(p); | - | ||||||||||||||||||||||||
| 716 | if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {
| 0-899 | ||||||||||||||||||||||||
| 717 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_FIELD_TOO_LARGE); | - | ||||||||||||||||||||||||
| 718 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 719 | } | - | ||||||||||||||||||||||||
| 720 | - | |||||||||||||||||||||||||
| 721 | /* create the EC_GROUP structure */ | - | ||||||||||||||||||||||||
| 722 | ret = EC_GROUP_new_curve_GFp(p, a, b, NULL); | - | ||||||||||||||||||||||||
| 723 | } else { executed 899 times by 1 test: end of blockExecuted by:
| 899 | ||||||||||||||||||||||||
| 724 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_INVALID_FIELD); | - | ||||||||||||||||||||||||
| 725 | goto err; executed 37 times by 1 test: goto err;Executed by:
| 37 | ||||||||||||||||||||||||
| 726 | } | - | ||||||||||||||||||||||||
| 727 | - | |||||||||||||||||||||||||
| 728 | if (ret == NULL) {
| 422-518 | ||||||||||||||||||||||||
| 729 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 730 | goto err; executed 422 times by 1 test: goto err;Executed by:
| 422 | ||||||||||||||||||||||||
| 731 | } | - | ||||||||||||||||||||||||
| 732 | - | |||||||||||||||||||||||||
| 733 | /* extract seed (optional) */ | - | ||||||||||||||||||||||||
| 734 | if (params->curve->seed != NULL) {
| 93-425 | ||||||||||||||||||||||||
| 735 | OPENSSL_free(ret->seed); | - | ||||||||||||||||||||||||
| 736 | if ((ret->seed = OPENSSL_malloc(params->curve->seed->length)) == NULL) {
| 6-419 | ||||||||||||||||||||||||
| 737 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 738 | goto err; executed 6 times by 1 test: goto err;Executed by:
| 6 | ||||||||||||||||||||||||
| 739 | } | - | ||||||||||||||||||||||||
| 740 | memcpy(ret->seed, params->curve->seed->data, | - | ||||||||||||||||||||||||
| 741 | params->curve->seed->length); | - | ||||||||||||||||||||||||
| 742 | ret->seed_len = params->curve->seed->length; | - | ||||||||||||||||||||||||
| 743 | } executed 419 times by 1 test: end of blockExecuted by:
| 419 | ||||||||||||||||||||||||
| 744 | - | |||||||||||||||||||||||||
| 745 | if (!params->order || !params->base || !params->base->data) {
| 0-512 | ||||||||||||||||||||||||
| 746 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR); | - | ||||||||||||||||||||||||
| 747 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 748 | } | - | ||||||||||||||||||||||||
| 749 | - | |||||||||||||||||||||||||
| 750 | if ((point = EC_POINT_new(ret)) == NULL)
| 0-512 | ||||||||||||||||||||||||
| 751 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 752 | - | |||||||||||||||||||||||||
| 753 | /* set the point conversion form */ | - | ||||||||||||||||||||||||
| 754 | EC_GROUP_set_point_conversion_form(ret, (point_conversion_form_t) | - | ||||||||||||||||||||||||
| 755 | (params->base->data[0] & ~0x01)); | - | ||||||||||||||||||||||||
| 756 | - | |||||||||||||||||||||||||
| 757 | /* extract the ec point */ | - | ||||||||||||||||||||||||
| 758 | if (!EC_POINT_oct2point(ret, point, params->base->data,
| 190-322 | ||||||||||||||||||||||||
| 759 | params->base->length, NULL)) {
| 190-322 | ||||||||||||||||||||||||
| 760 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 761 | goto err; executed 190 times by 1 test: goto err;Executed by:
| 190 | ||||||||||||||||||||||||
| 762 | } | - | ||||||||||||||||||||||||
| 763 | - | |||||||||||||||||||||||||
| 764 | /* extract the order */ | - | ||||||||||||||||||||||||
| 765 | if ((a = ASN1_INTEGER_to_BN(params->order, a)) == NULL) {
| 0-322 | ||||||||||||||||||||||||
| 766 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_ASN1_LIB); | - | ||||||||||||||||||||||||
| 767 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 768 | } | - | ||||||||||||||||||||||||
| 769 | if (BN_is_negative(a) || BN_is_zero(a)) {
| 14-285 | ||||||||||||||||||||||||
| 770 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_INVALID_GROUP_ORDER); | - | ||||||||||||||||||||||||
| 771 | goto err; executed 51 times by 1 test: goto err;Executed by:
| 51 | ||||||||||||||||||||||||
| 772 | } | - | ||||||||||||||||||||||||
| 773 | if (BN_num_bits(a) > (int)field_bits + 1) { /* Hasse bound */
| 37-234 | ||||||||||||||||||||||||
| 774 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_INVALID_GROUP_ORDER); | - | ||||||||||||||||||||||||
| 775 | goto err; executed 37 times by 1 test: goto err;Executed by:
| 37 | ||||||||||||||||||||||||
| 776 | } | - | ||||||||||||||||||||||||
| 777 | - | |||||||||||||||||||||||||
| 778 | /* extract the cofactor (optional) */ | - | ||||||||||||||||||||||||
| 779 | if (params->cofactor == NULL) {
| 40-194 | ||||||||||||||||||||||||
| 780 | BN_free(b); | - | ||||||||||||||||||||||||
| 781 | b = NULL; | - | ||||||||||||||||||||||||
| 782 | } else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) { executed 40 times by 1 test: end of blockExecuted by:
| 0-194 | ||||||||||||||||||||||||
| 783 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_ASN1_LIB); | - | ||||||||||||||||||||||||
| 784 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 785 | } | - | ||||||||||||||||||||||||
| 786 | /* set the generator, order and cofactor (if present) */ | - | ||||||||||||||||||||||||
| 787 | if (!EC_GROUP_set_generator(ret, point, a, b)) {
| 0-234 | ||||||||||||||||||||||||
| 788 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 789 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 790 | } | - | ||||||||||||||||||||||||
| 791 | - | |||||||||||||||||||||||||
| 792 | ok = 1; | - | ||||||||||||||||||||||||
| 793 | - | |||||||||||||||||||||||||
| 794 | err: code before this statement executed 234 times by 1 test: err:Executed by:
| 234 | ||||||||||||||||||||||||
| 795 | if (!ok) {
| 234-812 | ||||||||||||||||||||||||
| 796 | EC_GROUP_clear_free(ret); | - | ||||||||||||||||||||||||
| 797 | ret = NULL; | - | ||||||||||||||||||||||||
| 798 | } executed 812 times by 1 test: end of blockExecuted by:
| 812 | ||||||||||||||||||||||||
| 799 | - | |||||||||||||||||||||||||
| 800 | BN_free(p); | - | ||||||||||||||||||||||||
| 801 | BN_free(a); | - | ||||||||||||||||||||||||
| 802 | BN_free(b); | - | ||||||||||||||||||||||||
| 803 | EC_POINT_free(point); | - | ||||||||||||||||||||||||
| 804 | return ret; executed 1046 times by 1 test: return ret;Executed by:
| 1046 | ||||||||||||||||||||||||
| 805 | } | - | ||||||||||||||||||||||||
| 806 | - | |||||||||||||||||||||||||
| 807 | EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params) | - | ||||||||||||||||||||||||
| 808 | { | - | ||||||||||||||||||||||||
| 809 | EC_GROUP *ret = NULL; | - | ||||||||||||||||||||||||
| 810 | int tmp = 0; | - | ||||||||||||||||||||||||
| 811 | - | |||||||||||||||||||||||||
| 812 | if (params == NULL) {
| 0-3165 | ||||||||||||||||||||||||
| 813 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPKPARAMETERS, EC_R_MISSING_PARAMETERS); | - | ||||||||||||||||||||||||
| 814 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 815 | } | - | ||||||||||||||||||||||||
| 816 | - | |||||||||||||||||||||||||
| 817 | if (params->type == 0) { /* the curve is given by an OID */
| 1048-2117 | ||||||||||||||||||||||||
| 818 | tmp = OBJ_obj2nid(params->value.named_curve); | - | ||||||||||||||||||||||||
| 819 | if ((ret = EC_GROUP_new_by_curve_name(tmp)) == NULL) {
| 17-2100 | ||||||||||||||||||||||||
| 820 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPKPARAMETERS, | - | ||||||||||||||||||||||||
| 821 | EC_R_EC_GROUP_NEW_BY_NAME_FAILURE); | - | ||||||||||||||||||||||||
| 822 | return NULL; executed 17 times by 1 test: return ((void *)0) ;Executed by:
| 17 | ||||||||||||||||||||||||
| 823 | } | - | ||||||||||||||||||||||||
| 824 | EC_GROUP_set_asn1_flag(ret, OPENSSL_EC_NAMED_CURVE); | - | ||||||||||||||||||||||||
| 825 | } else if (params->type == 1) { /* the parameters are given by a executed 2100 times by 1 test: end of blockExecuted by:
| 3-2100 | ||||||||||||||||||||||||
| 826 | * ECPARAMETERS structure */ | - | ||||||||||||||||||||||||
| 827 | ret = EC_GROUP_new_from_ecparameters(params->value.parameters); | - | ||||||||||||||||||||||||
| 828 | if (!ret) {
| 233-812 | ||||||||||||||||||||||||
| 829 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPKPARAMETERS, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 830 | return NULL; executed 812 times by 1 test: return ((void *)0) ;Executed by:
| 812 | ||||||||||||||||||||||||
| 831 | } | - | ||||||||||||||||||||||||
| 832 | EC_GROUP_set_asn1_flag(ret, OPENSSL_EC_EXPLICIT_CURVE); | - | ||||||||||||||||||||||||
| 833 | } else if (params->type == 2) { /* implicitlyCA */ executed 233 times by 1 test: end of blockExecuted by:
| 0-233 | ||||||||||||||||||||||||
| 834 | return NULL; executed 3 times by 1 test: return ((void *)0) ;Executed by:
| 3 | ||||||||||||||||||||||||
| 835 | } else { | - | ||||||||||||||||||||||||
| 836 | ECerr(EC_F_EC_GROUP_NEW_FROM_ECPKPARAMETERS, EC_R_ASN1_ERROR); | - | ||||||||||||||||||||||||
| 837 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 838 | } | - | ||||||||||||||||||||||||
| 839 | - | |||||||||||||||||||||||||
| 840 | return ret; executed 2333 times by 1 test: return ret;Executed by:
| 2333 | ||||||||||||||||||||||||
| 841 | } | - | ||||||||||||||||||||||||
| 842 | - | |||||||||||||||||||||||||
| 843 | /* EC_GROUP <-> DER encoding of ECPKPARAMETERS */ | - | ||||||||||||||||||||||||
| 844 | - | |||||||||||||||||||||||||
| 845 | EC_GROUP *d2i_ECPKParameters(EC_GROUP **a, const unsigned char **in, long len) | - | ||||||||||||||||||||||||
| 846 | { | - | ||||||||||||||||||||||||
| 847 | EC_GROUP *group = NULL; | - | ||||||||||||||||||||||||
| 848 | ECPKPARAMETERS *params = NULL; | - | ||||||||||||||||||||||||
| 849 | const unsigned char *p = *in; | - | ||||||||||||||||||||||||
| 850 | - | |||||||||||||||||||||||||
| 851 | if ((params = d2i_ECPKPARAMETERS(NULL, &p, len)) == NULL) {
| 1075-7624 | ||||||||||||||||||||||||
| 852 | ECerr(EC_F_D2I_ECPKPARAMETERS, EC_R_D2I_ECPKPARAMETERS_FAILURE); | - | ||||||||||||||||||||||||
| 853 | ECPKPARAMETERS_free(params); | - | ||||||||||||||||||||||||
| 854 | return NULL; executed 7624 times by 1 test: return ((void *)0) ;Executed by:
| 7624 | ||||||||||||||||||||||||
| 855 | } | - | ||||||||||||||||||||||||
| 856 | - | |||||||||||||||||||||||||
| 857 | if ((group = EC_GROUP_new_from_ecpkparameters(params)) == NULL) {
| 286-789 | ||||||||||||||||||||||||
| 858 | ECerr(EC_F_D2I_ECPKPARAMETERS, EC_R_PKPARAMETERS2GROUP_FAILURE); | - | ||||||||||||||||||||||||
| 859 | ECPKPARAMETERS_free(params); | - | ||||||||||||||||||||||||
| 860 | return NULL; executed 789 times by 1 test: return ((void *)0) ;Executed by:
| 789 | ||||||||||||||||||||||||
| 861 | } | - | ||||||||||||||||||||||||
| 862 | - | |||||||||||||||||||||||||
| 863 | if (a) {
| 133-153 | ||||||||||||||||||||||||
| 864 | EC_GROUP_clear_free(*a); | - | ||||||||||||||||||||||||
| 865 | *a = group; | - | ||||||||||||||||||||||||
| 866 | } executed 133 times by 1 test: end of blockExecuted by:
| 133 | ||||||||||||||||||||||||
| 867 | - | |||||||||||||||||||||||||
| 868 | ECPKPARAMETERS_free(params); | - | ||||||||||||||||||||||||
| 869 | *in = p; | - | ||||||||||||||||||||||||
| 870 | return group; executed 286 times by 1 test: return group;Executed by:
| 286 | ||||||||||||||||||||||||
| 871 | } | - | ||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||
| 873 | int i2d_ECPKParameters(const EC_GROUP *a, unsigned char **out) | - | ||||||||||||||||||||||||
| 874 | { | - | ||||||||||||||||||||||||
| 875 | int ret = 0; | - | ||||||||||||||||||||||||
| 876 | ECPKPARAMETERS *tmp = EC_GROUP_get_ecpkparameters(a, NULL); | - | ||||||||||||||||||||||||
| 877 | if (tmp == NULL) {
| 0-48 | ||||||||||||||||||||||||
| 878 | ECerr(EC_F_I2D_ECPKPARAMETERS, EC_R_GROUP2PKPARAMETERS_FAILURE); | - | ||||||||||||||||||||||||
| 879 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 880 | } | - | ||||||||||||||||||||||||
| 881 | if ((ret = i2d_ECPKPARAMETERS(tmp, out)) == 0) {
| 0-48 | ||||||||||||||||||||||||
| 882 | ECerr(EC_F_I2D_ECPKPARAMETERS, EC_R_I2D_ECPKPARAMETERS_FAILURE); | - | ||||||||||||||||||||||||
| 883 | ECPKPARAMETERS_free(tmp); | - | ||||||||||||||||||||||||
| 884 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 885 | } | - | ||||||||||||||||||||||||
| 886 | ECPKPARAMETERS_free(tmp); | - | ||||||||||||||||||||||||
| 887 | return ret; executed 48 times by 1 test: return ret;Executed by:
| 48 | ||||||||||||||||||||||||
| 888 | } | - | ||||||||||||||||||||||||
| 889 | - | |||||||||||||||||||||||||
| 890 | /* some EC_KEY functions */ | - | ||||||||||||||||||||||||
| 891 | - | |||||||||||||||||||||||||
| 892 | EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len) | - | ||||||||||||||||||||||||
| 893 | { | - | ||||||||||||||||||||||||
| 894 | EC_KEY *ret = NULL; | - | ||||||||||||||||||||||||
| 895 | EC_PRIVATEKEY *priv_key = NULL; | - | ||||||||||||||||||||||||
| 896 | const unsigned char *p = *in; | - | ||||||||||||||||||||||||
| 897 | - | |||||||||||||||||||||||||
| 898 | if ((priv_key = d2i_EC_PRIVATEKEY(NULL, &p, len)) == NULL) {
| 3060-3292 | ||||||||||||||||||||||||
| 899 | ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 900 | return NULL; executed 3292 times by 1 test: return ((void *)0) ;Executed by:
| 3292 | ||||||||||||||||||||||||
| 901 | } | - | ||||||||||||||||||||||||
| 902 | - | |||||||||||||||||||||||||
| 903 | if (a == NULL || *a == NULL) {
| 0-2091 | ||||||||||||||||||||||||
| 904 | if ((ret = EC_KEY_new()) == NULL) {
| 0-2091 | ||||||||||||||||||||||||
| 905 | ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 906 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 907 | } | - | ||||||||||||||||||||||||
| 908 | } else executed 2091 times by 1 test: end of blockExecuted by:
| 2091 | ||||||||||||||||||||||||
| 909 | ret = *a; executed 969 times by 1 test: ret = *a;Executed by:
| 969 | ||||||||||||||||||||||||
| 910 | - | |||||||||||||||||||||||||
| 911 | if (priv_key->parameters) {
| 970-2090 | ||||||||||||||||||||||||
| 912 | EC_GROUP_clear_free(ret->group); | - | ||||||||||||||||||||||||
| 913 | ret->group = EC_GROUP_new_from_ecpkparameters(priv_key->parameters); | - | ||||||||||||||||||||||||
| 914 | } executed 2090 times by 1 test: end of blockExecuted by:
| 2090 | ||||||||||||||||||||||||
| 915 | - | |||||||||||||||||||||||||
| 916 | if (ret->group == NULL) {
| 44-3016 | ||||||||||||||||||||||||
| 917 | ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 918 | goto err; executed 44 times by 1 test: goto err;Executed by:
| 44 | ||||||||||||||||||||||||
| 919 | } | - | ||||||||||||||||||||||||
| 920 | - | |||||||||||||||||||||||||
| 921 | ret->version = priv_key->version; | - | ||||||||||||||||||||||||
| 922 | - | |||||||||||||||||||||||||
| 923 | if (priv_key->privateKey) {
| 0-3016 | ||||||||||||||||||||||||
| 924 | ASN1_OCTET_STRING *pkey = priv_key->privateKey; | - | ||||||||||||||||||||||||
| 925 | if (EC_KEY_oct2priv(ret, ASN1_STRING_get0_data(pkey),
| 0-3016 | ||||||||||||||||||||||||
| 926 | ASN1_STRING_length(pkey)) == 0)
| 0-3016 | ||||||||||||||||||||||||
| 927 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 928 | } else { executed 3016 times by 1 test: end of blockExecuted by:
| 3016 | ||||||||||||||||||||||||
| 929 | ECerr(EC_F_D2I_ECPRIVATEKEY, EC_R_MISSING_PRIVATE_KEY); | - | ||||||||||||||||||||||||
| 930 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 931 | } | - | ||||||||||||||||||||||||
| 932 | - | |||||||||||||||||||||||||
| 933 | EC_POINT_clear_free(ret->pub_key); | - | ||||||||||||||||||||||||
| 934 | ret->pub_key = EC_POINT_new(ret->group); | - | ||||||||||||||||||||||||
| 935 | if (ret->pub_key == NULL) {
| 0-3016 | ||||||||||||||||||||||||
| 936 | ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 937 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 938 | } | - | ||||||||||||||||||||||||
| 939 | - | |||||||||||||||||||||||||
| 940 | if (priv_key->publicKey) {
| 399-2617 | ||||||||||||||||||||||||
| 941 | const unsigned char *pub_oct; | - | ||||||||||||||||||||||||
| 942 | int pub_oct_len; | - | ||||||||||||||||||||||||
| 943 | - | |||||||||||||||||||||||||
| 944 | pub_oct = ASN1_STRING_get0_data(priv_key->publicKey); | - | ||||||||||||||||||||||||
| 945 | pub_oct_len = ASN1_STRING_length(priv_key->publicKey); | - | ||||||||||||||||||||||||
| 946 | if (!EC_KEY_oct2key(ret, pub_oct, pub_oct_len, NULL)) {
| 7-2610 | ||||||||||||||||||||||||
| 947 | ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 948 | goto err; executed 7 times by 1 test: goto err;Executed by:
| 7 | ||||||||||||||||||||||||
| 949 | } | - | ||||||||||||||||||||||||
| 950 | } else { executed 2610 times by 1 test: end of blockExecuted by:
| 2610 | ||||||||||||||||||||||||
| 951 | if (ret->group->meth->keygenpub == NULL
| 0-399 | ||||||||||||||||||||||||
| 952 | || ret->group->meth->keygenpub(ret) == 0)
| 0-399 | ||||||||||||||||||||||||
| 953 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 954 | /* Remember the original private-key-only encoding. */ | - | ||||||||||||||||||||||||
| 955 | ret->enc_flag |= EC_PKEY_NO_PUBKEY; | - | ||||||||||||||||||||||||
| 956 | } executed 399 times by 1 test: end of blockExecuted by:
| 399 | ||||||||||||||||||||||||
| 957 | - | |||||||||||||||||||||||||
| 958 | if (a)
| 968-2041 | ||||||||||||||||||||||||
| 959 | *a = ret; executed 968 times by 1 test: *a = ret;Executed by:
| 968 | ||||||||||||||||||||||||
| 960 | EC_PRIVATEKEY_free(priv_key); | - | ||||||||||||||||||||||||
| 961 | *in = p; | - | ||||||||||||||||||||||||
| 962 | return ret; executed 3009 times by 1 test: return ret;Executed by:
| 3009 | ||||||||||||||||||||||||
| 963 | - | |||||||||||||||||||||||||
| 964 | err: | - | ||||||||||||||||||||||||
| 965 | if (a == NULL || *a != ret)
| 0-50 | ||||||||||||||||||||||||
| 966 | EC_KEY_free(ret); executed 50 times by 1 test: EC_KEY_free(ret);Executed by:
| 50 | ||||||||||||||||||||||||
| 967 | EC_PRIVATEKEY_free(priv_key); | - | ||||||||||||||||||||||||
| 968 | return NULL; executed 51 times by 1 test: return ((void *)0) ;Executed by:
| 51 | ||||||||||||||||||||||||
| 969 | } | - | ||||||||||||||||||||||||
| 970 | - | |||||||||||||||||||||||||
| 971 | int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out) | - | ||||||||||||||||||||||||
| 972 | { | - | ||||||||||||||||||||||||
| 973 | int ret = 0, ok = 0; | - | ||||||||||||||||||||||||
| 974 | unsigned char *priv= NULL, *pub= NULL; | - | ||||||||||||||||||||||||
| 975 | size_t privlen = 0, publen = 0; | - | ||||||||||||||||||||||||
| 976 | - | |||||||||||||||||||||||||
| 977 | EC_PRIVATEKEY *priv_key = NULL; | - | ||||||||||||||||||||||||
| 978 | - | |||||||||||||||||||||||||
| 979 | if (a == NULL || a->group == NULL ||
| 0-255 | ||||||||||||||||||||||||
| 980 | (!(a->enc_flag & EC_PKEY_NO_PUBKEY) && a->pub_key == NULL)) {
| 0-227 | ||||||||||||||||||||||||
| 981 | ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
| 982 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 983 | } | - | ||||||||||||||||||||||||
| 984 | - | |||||||||||||||||||||||||
| 985 | if ((priv_key = EC_PRIVATEKEY_new()) == NULL) {
| 0-255 | ||||||||||||||||||||||||
| 986 | ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 987 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 988 | } | - | ||||||||||||||||||||||||
| 989 | - | |||||||||||||||||||||||||
| 990 | priv_key->version = a->version; | - | ||||||||||||||||||||||||
| 991 | - | |||||||||||||||||||||||||
| 992 | privlen = EC_KEY_priv2buf(a, &priv); | - | ||||||||||||||||||||||||
| 993 | - | |||||||||||||||||||||||||
| 994 | if (privlen == 0) {
| 39-216 | ||||||||||||||||||||||||
| 995 | ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 996 | goto err; executed 39 times by 1 test: goto err;Executed by:
| 39 | ||||||||||||||||||||||||
| 997 | } | - | ||||||||||||||||||||||||
| 998 | - | |||||||||||||||||||||||||
| 999 | ASN1_STRING_set0(priv_key->privateKey, priv, privlen); | - | ||||||||||||||||||||||||
| 1000 | priv = NULL; | - | ||||||||||||||||||||||||
| 1001 | - | |||||||||||||||||||||||||
| 1002 | if (!(a->enc_flag & EC_PKEY_NO_PARAMETERS)) {
| 10-206 | ||||||||||||||||||||||||
| 1003 | if ((priv_key->parameters =
| 0-206 | ||||||||||||||||||||||||
| 1004 | EC_GROUP_get_ecpkparameters(a->group,
| 0-206 | ||||||||||||||||||||||||
| 1005 | priv_key->parameters)) == NULL) {
| 0-206 | ||||||||||||||||||||||||
| 1006 | ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 1007 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 1008 | } | - | ||||||||||||||||||||||||
| 1009 | } executed 206 times by 1 test: end of blockExecuted by:
| 206 | ||||||||||||||||||||||||
| 1010 | - | |||||||||||||||||||||||||
| 1011 | if (!(a->enc_flag & EC_PKEY_NO_PUBKEY)) {
| 28-188 | ||||||||||||||||||||||||
| 1012 | priv_key->publicKey = ASN1_BIT_STRING_new(); | - | ||||||||||||||||||||||||
| 1013 | if (priv_key->publicKey == NULL) {
| 0-28 | ||||||||||||||||||||||||
| 1014 | ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 1015 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 1016 | } | - | ||||||||||||||||||||||||
| 1017 | - | |||||||||||||||||||||||||
| 1018 | publen = EC_KEY_key2buf(a, a->conv_form, &pub, NULL); | - | ||||||||||||||||||||||||
| 1019 | - | |||||||||||||||||||||||||
| 1020 | if (publen == 0) {
| 0-28 | ||||||||||||||||||||||||
| 1021 | ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 1022 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 1023 | } | - | ||||||||||||||||||||||||
| 1024 | - | |||||||||||||||||||||||||
| 1025 | priv_key->publicKey->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); | - | ||||||||||||||||||||||||
| 1026 | priv_key->publicKey->flags |= ASN1_STRING_FLAG_BITS_LEFT; | - | ||||||||||||||||||||||||
| 1027 | ASN1_STRING_set0(priv_key->publicKey, pub, publen); | - | ||||||||||||||||||||||||
| 1028 | pub = NULL; | - | ||||||||||||||||||||||||
| 1029 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 1030 | - | |||||||||||||||||||||||||
| 1031 | if ((ret = i2d_EC_PRIVATEKEY(priv_key, out)) == 0) {
| 0-216 | ||||||||||||||||||||||||
| 1032 | ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 1033 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
| 1034 | } | - | ||||||||||||||||||||||||
| 1035 | ok = 1; | - | ||||||||||||||||||||||||
| 1036 | err: code before this statement executed 216 times by 1 test: err:Executed by:
| 216 | ||||||||||||||||||||||||
| 1037 | OPENSSL_clear_free(priv, privlen); | - | ||||||||||||||||||||||||
| 1038 | OPENSSL_free(pub); | - | ||||||||||||||||||||||||
| 1039 | EC_PRIVATEKEY_free(priv_key); | - | ||||||||||||||||||||||||
| 1040 | return (ok ? ret : 0); executed 255 times by 1 test: return (ok ? ret : 0);Executed by:
| 39-255 | ||||||||||||||||||||||||
| 1041 | } | - | ||||||||||||||||||||||||
| 1042 | - | |||||||||||||||||||||||||
| 1043 | int i2d_ECParameters(EC_KEY *a, unsigned char **out) | - | ||||||||||||||||||||||||
| 1044 | { | - | ||||||||||||||||||||||||
| 1045 | if (a == NULL) {
| 0-22 | ||||||||||||||||||||||||
| 1046 | ECerr(EC_F_I2D_ECPARAMETERS, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
| 1047 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1048 | } | - | ||||||||||||||||||||||||
| 1049 | return i2d_ECPKParameters(a->group, out); executed 22 times by 1 test: return i2d_ECPKParameters(a->group, out);Executed by:
| 22 | ||||||||||||||||||||||||
| 1050 | } | - | ||||||||||||||||||||||||
| 1051 | - | |||||||||||||||||||||||||
| 1052 | EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len) | - | ||||||||||||||||||||||||
| 1053 | { | - | ||||||||||||||||||||||||
| 1054 | EC_KEY *ret; | - | ||||||||||||||||||||||||
| 1055 | - | |||||||||||||||||||||||||
| 1056 | if (in == NULL || *in == NULL) {
| 0-5242 | ||||||||||||||||||||||||
| 1057 | ECerr(EC_F_D2I_ECPARAMETERS, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
| 1058 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 1059 | } | - | ||||||||||||||||||||||||
| 1060 | - | |||||||||||||||||||||||||
| 1061 | if (a == NULL || *a == NULL) {
| 0-5242 | ||||||||||||||||||||||||
| 1062 | if ((ret = EC_KEY_new()) == NULL) {
| 0-5242 | ||||||||||||||||||||||||
| 1063 | ECerr(EC_F_D2I_ECPARAMETERS, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 1064 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 1065 | } | - | ||||||||||||||||||||||||
| 1066 | } else executed 5242 times by 1 test: end of blockExecuted by:
| 5242 | ||||||||||||||||||||||||
| 1067 | ret = *a; never executed: ret = *a; | 0 | ||||||||||||||||||||||||
| 1068 | - | |||||||||||||||||||||||||
| 1069 | if (!d2i_ECPKParameters(&ret->group, in, len)) {
| 133-5109 | ||||||||||||||||||||||||
| 1070 | ECerr(EC_F_D2I_ECPARAMETERS, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 1071 | if (a == NULL || *a != ret)
| 0-5109 | ||||||||||||||||||||||||
| 1072 | EC_KEY_free(ret); executed 5109 times by 1 test: EC_KEY_free(ret);Executed by:
| 5109 | ||||||||||||||||||||||||
| 1073 | return NULL; executed 5109 times by 1 test: return ((void *)0) ;Executed by:
| 5109 | ||||||||||||||||||||||||
| 1074 | } | - | ||||||||||||||||||||||||
| 1075 | - | |||||||||||||||||||||||||
| 1076 | if (a)
| 0-133 | ||||||||||||||||||||||||
| 1077 | *a = ret; never executed: *a = ret; | 0 | ||||||||||||||||||||||||
| 1078 | - | |||||||||||||||||||||||||
| 1079 | return ret; executed 133 times by 1 test: return ret;Executed by:
| 133 | ||||||||||||||||||||||||
| 1080 | } | - | ||||||||||||||||||||||||
| 1081 | - | |||||||||||||||||||||||||
| 1082 | EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len) | - | ||||||||||||||||||||||||
| 1083 | { | - | ||||||||||||||||||||||||
| 1084 | EC_KEY *ret = NULL; | - | ||||||||||||||||||||||||
| 1085 | - | |||||||||||||||||||||||||
| 1086 | if (a == NULL || (*a) == NULL || (*a)->group == NULL) {
| 0-30886 | ||||||||||||||||||||||||
| 1087 | /* | - | ||||||||||||||||||||||||
| 1088 | * sorry, but a EC_GROUP-structure is necessary to set the public key | - | ||||||||||||||||||||||||
| 1089 | */ | - | ||||||||||||||||||||||||
| 1090 | ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
| 1091 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1092 | } | - | ||||||||||||||||||||||||
| 1093 | ret = *a; | - | ||||||||||||||||||||||||
| 1094 | if (!EC_KEY_oct2key(ret, *in, len, NULL)) {
| 7011-23875 | ||||||||||||||||||||||||
| 1095 | ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 1096 | return 0; executed 7011 times by 1 test: return 0;Executed by:
| 7011 | ||||||||||||||||||||||||
| 1097 | } | - | ||||||||||||||||||||||||
| 1098 | *in += len; | - | ||||||||||||||||||||||||
| 1099 | return ret; executed 23875 times by 1 test: return ret;Executed by:
| 23875 | ||||||||||||||||||||||||
| 1100 | } | - | ||||||||||||||||||||||||
| 1101 | - | |||||||||||||||||||||||||
| 1102 | int i2o_ECPublicKey(const EC_KEY *a, unsigned char **out) | - | ||||||||||||||||||||||||
| 1103 | { | - | ||||||||||||||||||||||||
| 1104 | size_t buf_len = 0; | - | ||||||||||||||||||||||||
| 1105 | int new_buffer = 0; | - | ||||||||||||||||||||||||
| 1106 | - | |||||||||||||||||||||||||
| 1107 | if (a == NULL) {
| 0-26186 | ||||||||||||||||||||||||
| 1108 | ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
| 1109 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1110 | } | - | ||||||||||||||||||||||||
| 1111 | - | |||||||||||||||||||||||||
| 1112 | buf_len = EC_POINT_point2oct(a->group, a->pub_key, | - | ||||||||||||||||||||||||
| 1113 | a->conv_form, NULL, 0, NULL); | - | ||||||||||||||||||||||||
| 1114 | - | |||||||||||||||||||||||||
| 1115 | if (out == NULL || buf_len == 0)
| 0-13093 | ||||||||||||||||||||||||
| 1116 | /* out == NULL => just return the length of the octet string */ | - | ||||||||||||||||||||||||
| 1117 | return buf_len; executed 13093 times by 1 test: return buf_len;Executed by:
| 13093 | ||||||||||||||||||||||||
| 1118 | - | |||||||||||||||||||||||||
| 1119 | if (*out == NULL) {
| 0-13093 | ||||||||||||||||||||||||
| 1120 | if ((*out = OPENSSL_malloc(buf_len)) == NULL) {
| 0 | ||||||||||||||||||||||||
| 1121 | ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
| 1122 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1123 | } | - | ||||||||||||||||||||||||
| 1124 | new_buffer = 1; | - | ||||||||||||||||||||||||
| 1125 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1126 | if (!EC_POINT_point2oct(a->group, a->pub_key, a->conv_form,
| 0-13093 | ||||||||||||||||||||||||
| 1127 | *out, buf_len, NULL)) {
| 0-13093 | ||||||||||||||||||||||||
| 1128 | ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
| 1129 | if (new_buffer) {
| 0 | ||||||||||||||||||||||||
| 1130 | OPENSSL_free(*out); | - | ||||||||||||||||||||||||
| 1131 | *out = NULL; | - | ||||||||||||||||||||||||
| 1132 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1133 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1134 | } | - | ||||||||||||||||||||||||
| 1135 | if (!new_buffer)
| 0-13093 | ||||||||||||||||||||||||
| 1136 | *out += buf_len; executed 13093 times by 1 test: *out += buf_len;Executed by:
| 13093 | ||||||||||||||||||||||||
| 1137 | return buf_len; executed 13093 times by 1 test: return buf_len;Executed by:
| 13093 | ||||||||||||||||||||||||
| 1138 | } | - | ||||||||||||||||||||||||
| 1139 | - | |||||||||||||||||||||||||
| 1140 | ASN1_SEQUENCE(ECDSA_SIG) = { | - | ||||||||||||||||||||||||
| 1141 | ASN1_SIMPLE(ECDSA_SIG, r, CBIGNUM), | - | ||||||||||||||||||||||||
| 1142 | ASN1_SIMPLE(ECDSA_SIG, s, CBIGNUM) | - | ||||||||||||||||||||||||
| 1143 | } static_ASN1_SEQUENCE_END(ECDSA_SIG) | - | ||||||||||||||||||||||||
| 1144 | - | |||||||||||||||||||||||||
| 1145 | DECLARE_ASN1_FUNCTIONS_const(ECDSA_SIG) | - | ||||||||||||||||||||||||
| 1146 | DECLARE_ASN1_ENCODE_FUNCTIONS_const(ECDSA_SIG, ECDSA_SIG) | - | ||||||||||||||||||||||||
| 1147 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ECDSA_SIG, ECDSA_SIG, ECDSA_SIG) executed 4060 times by 1 test: return (ECDSA_SIG *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(ECDSA_SIG_it)));Executed by:
executed 1106 times by 1 test: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(ECDSA_SIG_it)));Executed by:
| 1106-4060 | ||||||||||||||||||||||||
| 1148 | - | |||||||||||||||||||||||||
| 1149 | ECDSA_SIG *ECDSA_SIG_new(void) | - | ||||||||||||||||||||||||
| 1150 | { | - | ||||||||||||||||||||||||
| 1151 | ECDSA_SIG *sig = OPENSSL_zalloc(sizeof(*sig)); | - | ||||||||||||||||||||||||
| 1152 | if (sig == NULL)
| 0-1107 | ||||||||||||||||||||||||
| 1153 | ECerr(EC_F_ECDSA_SIG_NEW, ERR_R_MALLOC_FAILURE); never executed: ERR_put_error(16,(265),((1|64)),__FILE__,1153); | 0 | ||||||||||||||||||||||||
| 1154 | return sig; executed 1107 times by 2 tests: return sig;Executed by:
| 1107 | ||||||||||||||||||||||||
| 1155 | } | - | ||||||||||||||||||||||||
| 1156 | - | |||||||||||||||||||||||||
| 1157 | void ECDSA_SIG_free(ECDSA_SIG *sig) | - | ||||||||||||||||||||||||
| 1158 | { | - | ||||||||||||||||||||||||
| 1159 | if (sig == NULL)
| 76-1111 | ||||||||||||||||||||||||
| 1160 | return; executed 76 times by 1 test: return;Executed by:
| 76 | ||||||||||||||||||||||||
| 1161 | BN_clear_free(sig->r); | - | ||||||||||||||||||||||||
| 1162 | BN_clear_free(sig->s); | - | ||||||||||||||||||||||||
| 1163 | OPENSSL_free(sig); | - | ||||||||||||||||||||||||
| 1164 | } executed 1111 times by 2 tests: end of blockExecuted by:
| 1111 | ||||||||||||||||||||||||
| 1165 | - | |||||||||||||||||||||||||
| 1166 | void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) | - | ||||||||||||||||||||||||
| 1167 | { | - | ||||||||||||||||||||||||
| 1168 | if (pr != NULL)
| 0-79 | ||||||||||||||||||||||||
| 1169 | *pr = sig->r; executed 79 times by 2 tests: *pr = sig->r;Executed by:
| 79 | ||||||||||||||||||||||||
| 1170 | if (ps != NULL)
| 0-79 | ||||||||||||||||||||||||
| 1171 | *ps = sig->s; executed 79 times by 2 tests: *ps = sig->s;Executed by:
| 79 | ||||||||||||||||||||||||
| 1172 | } executed 79 times by 2 tests: end of blockExecuted by:
| 79 | ||||||||||||||||||||||||
| 1173 | - | |||||||||||||||||||||||||
| 1174 | const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig) | - | ||||||||||||||||||||||||
| 1175 | { | - | ||||||||||||||||||||||||
| 1176 | return sig->r; never executed: return sig->r; | 0 | ||||||||||||||||||||||||
| 1177 | } | - | ||||||||||||||||||||||||
| 1178 | - | |||||||||||||||||||||||||
| 1179 | const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig) | - | ||||||||||||||||||||||||
| 1180 | { | - | ||||||||||||||||||||||||
| 1181 | return sig->s; never executed: return sig->s; | 0 | ||||||||||||||||||||||||
| 1182 | } | - | ||||||||||||||||||||||||
| 1183 | - | |||||||||||||||||||||||||
| 1184 | int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) | - | ||||||||||||||||||||||||
| 1185 | { | - | ||||||||||||||||||||||||
| 1186 | if (r == NULL || s == NULL)
| 0-139 | ||||||||||||||||||||||||
| 1187 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1188 | BN_clear_free(sig->r); | - | ||||||||||||||||||||||||
| 1189 | BN_clear_free(sig->s); | - | ||||||||||||||||||||||||
| 1190 | sig->r = r; | - | ||||||||||||||||||||||||
| 1191 | sig->s = s; | - | ||||||||||||||||||||||||
| 1192 | return 1; executed 139 times by 2 tests: return 1;Executed by:
| 139 | ||||||||||||||||||||||||
| 1193 | } | - | ||||||||||||||||||||||||
| 1194 | - | |||||||||||||||||||||||||
| 1195 | int ECDSA_size(const EC_KEY *r) | - | ||||||||||||||||||||||||
| 1196 | { | - | ||||||||||||||||||||||||
| 1197 | int ret, i; | - | ||||||||||||||||||||||||
| 1198 | ASN1_INTEGER bs; | - | ||||||||||||||||||||||||
| 1199 | unsigned char buf[4]; | - | ||||||||||||||||||||||||
| 1200 | const EC_GROUP *group; | - | ||||||||||||||||||||||||
| 1201 | - | |||||||||||||||||||||||||
| 1202 | if (r == NULL)
| 0-849 | ||||||||||||||||||||||||
| 1203 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1204 | group = EC_KEY_get0_group(r); | - | ||||||||||||||||||||||||
| 1205 | if (group == NULL)
| 0-849 | ||||||||||||||||||||||||
| 1206 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1207 | - | |||||||||||||||||||||||||
| 1208 | i = EC_GROUP_order_bits(group); | - | ||||||||||||||||||||||||
| 1209 | if (i == 0)
| 0-849 | ||||||||||||||||||||||||
| 1210 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1211 | bs.length = (i + 7) / 8; | - | ||||||||||||||||||||||||
| 1212 | bs.data = buf; | - | ||||||||||||||||||||||||
| 1213 | bs.type = V_ASN1_INTEGER; | - | ||||||||||||||||||||||||
| 1214 | /* If the top bit is set the asn1 encoding is 1 larger. */ | - | ||||||||||||||||||||||||
| 1215 | buf[0] = 0xff; | - | ||||||||||||||||||||||||
| 1216 | - | |||||||||||||||||||||||||
| 1217 | i = i2d_ASN1_INTEGER(&bs, NULL); | - | ||||||||||||||||||||||||
| 1218 | i += i; /* r and s */ | - | ||||||||||||||||||||||||
| 1219 | ret = ASN1_object_size(1, i, V_ASN1_SEQUENCE); | - | ||||||||||||||||||||||||
| 1220 | return ret; executed 849 times by 1 test: return ret;Executed by:
| 849 | ||||||||||||||||||||||||
| 1221 | } | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |