| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ecdsa_ossl.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | int ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen, | - | ||||||||||||||||||
| 3 | unsigned char *sig, unsigned int *siglen, | - | ||||||||||||||||||
| 4 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey) | - | ||||||||||||||||||
| 5 | { | - | ||||||||||||||||||
| 6 | ECDSA_SIG *s; | - | ||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | s = ECDSA_do_sign_ex(dgst, dlen, kinv, r, eckey); | - | ||||||||||||||||||
| 9 | if (s ==
| 0-363 | ||||||||||||||||||
| 10 | ((void *)0)
| 0-363 | ||||||||||||||||||
| 11 | ) { | - | ||||||||||||||||||
| 12 | *siglen = 0; | - | ||||||||||||||||||
| 13 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 14 | } | - | ||||||||||||||||||
| 15 | *siglen = i2d_ECDSA_SIG(s, &sig); | - | ||||||||||||||||||
| 16 | ECDSA_SIG_free(s); | - | ||||||||||||||||||
| 17 | return executed 363 times by 1 test: 1;return 1;Executed by:
executed 363 times by 1 test: return 1;Executed by:
| 363 | ||||||||||||||||||
| 18 | } | - | ||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, | - | ||||||||||||||||||
| 21 | BIGNUM **kinvp, BIGNUM **rp, | - | ||||||||||||||||||
| 22 | const unsigned char *dgst, int dlen) | - | ||||||||||||||||||
| 23 | { | - | ||||||||||||||||||
| 24 | BN_CTX *ctx = | - | ||||||||||||||||||
| 25 | ((void *)0) | - | ||||||||||||||||||
| 26 | ; | - | ||||||||||||||||||
| 27 | BIGNUM *k = | - | ||||||||||||||||||
| 28 | ((void *)0) | - | ||||||||||||||||||
| 29 | , *r = | - | ||||||||||||||||||
| 30 | ((void *)0) | - | ||||||||||||||||||
| 31 | , *X = | - | ||||||||||||||||||
| 32 | ((void *)0) | - | ||||||||||||||||||
| 33 | ; | - | ||||||||||||||||||
| 34 | const BIGNUM *order; | - | ||||||||||||||||||
| 35 | EC_POINT *tmp_point = | - | ||||||||||||||||||
| 36 | ((void *)0) | - | ||||||||||||||||||
| 37 | ; | - | ||||||||||||||||||
| 38 | const EC_GROUP *group; | - | ||||||||||||||||||
| 39 | int ret = 0; | - | ||||||||||||||||||
| 40 | int order_bits; | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | if (eckey ==
| 0-367 | ||||||||||||||||||
| 43 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 44 | || (
| 0-367 | ||||||||||||||||||
| 45 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 46 | ) { | - | ||||||||||||||||||
| 47 | ERR_put_error(16,(248),((3|64)),__FILE__,46); | - | ||||||||||||||||||
| 48 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 49 | } | - | ||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | if (!EC_KEY_can_sign(eckey)
| 0-367 | ||||||||||||||||||
| 52 | ERR_put_error(16,(248),(159),__FILE__,51); | - | ||||||||||||||||||
| 53 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 54 | } | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | if ((
| 4-363 | ||||||||||||||||||
| 57 | ((void *)0)
| 4-363 | ||||||||||||||||||
| 58 | ) { | - | ||||||||||||||||||
| 59 | if ((
| 0-4 | ||||||||||||||||||
| 60 | ((void *)0)
| 0-4 | ||||||||||||||||||
| 61 | ) { | - | ||||||||||||||||||
| 62 | ERR_put_error(16,(248),((1|64)),__FILE__,57); | - | ||||||||||||||||||
| 63 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 64 | } | - | ||||||||||||||||||
| 65 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | k = BN_new(); | - | ||||||||||||||||||
| 68 | r = BN_new(); | - | ||||||||||||||||||
| 69 | X = BN_new(); | - | ||||||||||||||||||
| 70 | if (k ==
| 0-367 | ||||||||||||||||||
| 71 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 72 | || r ==
| 0-367 | ||||||||||||||||||
| 73 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 74 | || X ==
| 0-367 | ||||||||||||||||||
| 75 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 76 | ) { | - | ||||||||||||||||||
| 77 | ERR_put_error(16,(248),((1|64)),__FILE__,66); | - | ||||||||||||||||||
| 78 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 79 | } | - | ||||||||||||||||||
| 80 | if ((
| 0-367 | ||||||||||||||||||
| 81 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 82 | ) { | - | ||||||||||||||||||
| 83 | ERR_put_error(16,(248),(16),__FILE__,70); | - | ||||||||||||||||||
| 84 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 85 | } | - | ||||||||||||||||||
| 86 | order = EC_GROUP_get0_order(group); | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | order_bits = BN_num_bits(order); | - | ||||||||||||||||||
| 90 | if (!BN_set_bit(k, order_bits)
| 0-367 | ||||||||||||||||||
| 91 | || !BN_set_bit(r, order_bits)
| 0-367 | ||||||||||||||||||
| 92 | || !BN_set_bit(X, order_bits)
| 0-367 | ||||||||||||||||||
| 93 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | do { | - | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | do { | - | ||||||||||||||||||
| 98 | if (dgst !=
| 4-363 | ||||||||||||||||||
| 99 | ((void *)0)
| 4-363 | ||||||||||||||||||
| 100 | ) { | - | ||||||||||||||||||
| 101 | if (!BN_generate_dsa_nonce(k, order,
| 0-363 | ||||||||||||||||||
| 102 | EC_KEY_get0_private_key(eckey),
| 0-363 | ||||||||||||||||||
| 103 | dgst, dlen, ctx)
| 0-363 | ||||||||||||||||||
| 104 | ERR_put_error(16,(248),(158),__FILE__,90) | - | ||||||||||||||||||
| 105 | ; | - | ||||||||||||||||||
| 106 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 107 | } | - | ||||||||||||||||||
| 108 | } executed 363 times by 1 test: else {end of blockExecuted by:
| 363 | ||||||||||||||||||
| 109 | if (!BN_priv_rand_range(k, order)
| 0-4 | ||||||||||||||||||
| 110 | ERR_put_error(16,(248),(158),__FILE__,96) | - | ||||||||||||||||||
| 111 | ; | - | ||||||||||||||||||
| 112 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 113 | } | - | ||||||||||||||||||
| 114 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 115 | } while (BN_is_zero(k)
| 0-367 | ||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | if (!EC_POINT_mul(group, tmp_point, k,
| 0-367 | ||||||||||||||||||
| 119 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 120 | ,
| 0-367 | ||||||||||||||||||
| 121 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 122 | , ctx)
| 0-367 | ||||||||||||||||||
| 123 | ERR_put_error(16,(248),(16),__FILE__,104); | - | ||||||||||||||||||
| 124 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 125 | } | - | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | if (!EC_POINT_get_affine_coordinates(group, tmp_point, X,
| 0-367 | ||||||||||||||||||
| 128 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 129 | , ctx)
| 0-367 | ||||||||||||||||||
| 130 | ERR_put_error(16,(248),(16),__FILE__,109); | - | ||||||||||||||||||
| 131 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 132 | } | - | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | if (!BN_nnmod(r, X, order, ctx)
| 0-367 | ||||||||||||||||||
| 135 | ERR_put_error(16,(248),(3),__FILE__,114); | - | ||||||||||||||||||
| 136 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 137 | } | - | ||||||||||||||||||
| 138 | } executed 367 times by 1 test: while (BN_is_zero(r)end of blockExecuted by:
| 0-367 | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | if (!ec_group_do_inverse_ord(group, k, k, ctx)
| 0-367 | ||||||||||||||||||
| 142 | ERR_put_error(16,(248),(3),__FILE__,121); | - | ||||||||||||||||||
| 143 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 144 | } | - | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | BN_clear_free(*rp); | - | ||||||||||||||||||
| 148 | BN_clear_free(*kinvp); | - | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | *rp = r; | - | ||||||||||||||||||
| 151 | *kinvp = k; | - | ||||||||||||||||||
| 152 | ret = 1; | - | ||||||||||||||||||
| 153 | err: code before this statement executed 367 times by 1 test: err:Executed by:
| 367 | ||||||||||||||||||
| 154 | if (!ret
| 0-367 | ||||||||||||||||||
| 155 | BN_clear_free(k); | - | ||||||||||||||||||
| 156 | BN_clear_free(r); | - | ||||||||||||||||||
| 157 | } never executed: end of block | 0 | ||||||||||||||||||
| 158 | if (ctx != ctx_in
| 4-363 | ||||||||||||||||||
| 159 | BN_CTX_free(ctx); executed 4 times by 1 test: BN_CTX_free(ctx);Executed by:
| 4 | ||||||||||||||||||
| 160 | EC_POINT_free(tmp_point); | - | ||||||||||||||||||
| 161 | BN_clear_free(X); | - | ||||||||||||||||||
| 162 | return executed 367 times by 1 test: ret;return ret;Executed by:
executed 367 times by 1 test: return ret;Executed by:
| 367 | ||||||||||||||||||
| 163 | } | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, | - | ||||||||||||||||||
| 166 | BIGNUM **rp) | - | ||||||||||||||||||
| 167 | { | - | ||||||||||||||||||
| 168 | return executed 4 times by 1 test: ecdsa_sign_setup(eckey, ctx_in, kinvp, rp, return ecdsa_sign_setup(eckey, ctx_in, kinvp, rp, ((void *)0) , 0);Executed by:
executed 4 times by 1 test: return ecdsa_sign_setup(eckey, ctx_in, kinvp, rp, ((void *)0) , 0);Executed by:
| 4 | ||||||||||||||||||
| 169 | ((void *)0) executed 4 times by 1 test: return ecdsa_sign_setup(eckey, ctx_in, kinvp, rp, ((void *)0) , 0);Executed by:
| 4 | ||||||||||||||||||
| 170 | , 0); executed 4 times by 1 test: return ecdsa_sign_setup(eckey, ctx_in, kinvp, rp, ((void *)0) , 0);Executed by:
| 4 | ||||||||||||||||||
| 171 | } | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len, | - | ||||||||||||||||||
| 174 | const BIGNUM *in_kinv, const BIGNUM *in_r, | - | ||||||||||||||||||
| 175 | EC_KEY *eckey) | - | ||||||||||||||||||
| 176 | { | - | ||||||||||||||||||
| 177 | int ok = 0, i; | - | ||||||||||||||||||
| 178 | BIGNUM *kinv = | - | ||||||||||||||||||
| 179 | ((void *)0) | - | ||||||||||||||||||
| 180 | , *s, *m = | - | ||||||||||||||||||
| 181 | ((void *)0) | - | ||||||||||||||||||
| 182 | ; | - | ||||||||||||||||||
| 183 | const BIGNUM *order, *ckinv; | - | ||||||||||||||||||
| 184 | BN_CTX *ctx = | - | ||||||||||||||||||
| 185 | ((void *)0) | - | ||||||||||||||||||
| 186 | ; | - | ||||||||||||||||||
| 187 | const EC_GROUP *group; | - | ||||||||||||||||||
| 188 | ECDSA_SIG *ret; | - | ||||||||||||||||||
| 189 | const BIGNUM *priv_key; | - | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | group = EC_KEY_get0_group(eckey); | - | ||||||||||||||||||
| 192 | priv_key = EC_KEY_get0_private_key(eckey); | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | if (group ==
| 0-367 | ||||||||||||||||||
| 195 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 196 | || priv_key ==
| 0-367 | ||||||||||||||||||
| 197 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 198 | ) { | - | ||||||||||||||||||
| 199 | ERR_put_error(16,(249),((3|64)),__FILE__,166); | - | ||||||||||||||||||
| 200 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 201 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 202 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 203 | } | - | ||||||||||||||||||
| 204 | - | |||||||||||||||||||
| 205 | if (!EC_KEY_can_sign(eckey)
| 0-367 | ||||||||||||||||||
| 206 | ERR_put_error(16,(249),(159),__FILE__,171); | - | ||||||||||||||||||
| 207 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 208 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 209 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 210 | } | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | ret = ECDSA_SIG_new(); | - | ||||||||||||||||||
| 213 | if (ret ==
| 0-367 | ||||||||||||||||||
| 214 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 215 | ) { | - | ||||||||||||||||||
| 216 | ERR_put_error(16,(249),((1|64)),__FILE__,177); | - | ||||||||||||||||||
| 217 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 218 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 219 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 220 | } | - | ||||||||||||||||||
| 221 | ret->r = BN_new(); | - | ||||||||||||||||||
| 222 | ret->s = BN_new(); | - | ||||||||||||||||||
| 223 | if (ret->r ==
| 0-367 | ||||||||||||||||||
| 224 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 225 | || ret->s ==
| 0-367 | ||||||||||||||||||
| 226 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 227 | ) { | - | ||||||||||||||||||
| 228 | ERR_put_error(16,(249),((1|64)),__FILE__,183); | - | ||||||||||||||||||
| 229 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 230 | } | - | ||||||||||||||||||
| 231 | s = ret->s; | - | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | if ((
| 0-367 | ||||||||||||||||||
| 234 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 235 | - | |||||||||||||||||||
| 236 | || (
| 0-367 | ||||||||||||||||||
| 237 | ((void *)0)
| 0-367 | ||||||||||||||||||
| 238 | ) { | - | ||||||||||||||||||
| 239 | ERR_put_error(16,(249),((1|64)),__FILE__,190); | - | ||||||||||||||||||
| 240 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 241 | } | - | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | order = EC_GROUP_get0_order(group); | - | ||||||||||||||||||
| 244 | i = BN_num_bits(order); | - | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | - | |||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | if (8 * dgst_len > i
| 7-360 | ||||||||||||||||||
| 249 | dgst_len = (i + 7) / 8; executed 7 times by 1 test: dgst_len = (i + 7) / 8;Executed by:
| 7 | ||||||||||||||||||
| 250 | if (!BN_bin2bn(dgst, dgst_len, m)
| 0-367 | ||||||||||||||||||
| 251 | ERR_put_error(16,(249),(3),__FILE__,202); | - | ||||||||||||||||||
| 252 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 253 | } | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | if ((
| 0-367 | ||||||||||||||||||
| 256 | ERR_put_error(16,(249),(3),__FILE__,207); | - | ||||||||||||||||||
| 257 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 258 | } | - | ||||||||||||||||||
| 259 | do { | - | ||||||||||||||||||
| 260 | if (in_kinv ==
| 4-363 | ||||||||||||||||||
| 261 | ((void *)0)
| 4-363 | ||||||||||||||||||
| 262 | || in_r ==
| 0-4 | ||||||||||||||||||
| 263 | ((void *)0)
| 0-4 | ||||||||||||||||||
| 264 | ) { | - | ||||||||||||||||||
| 265 | if (!ecdsa_sign_setup(eckey, ctx, &kinv, &ret->r, dgst, dgst_len)
| 0-363 | ||||||||||||||||||
| 266 | ERR_put_error(16,(249),(42),__FILE__,213); | - | ||||||||||||||||||
| 267 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 268 | } | - | ||||||||||||||||||
| 269 | ckinv = kinv; | - | ||||||||||||||||||
| 270 | } executed 363 times by 1 test: else {end of blockExecuted by:
| 363 | ||||||||||||||||||
| 271 | ckinv = in_kinv; | - | ||||||||||||||||||
| 272 | if (BN_copy(ret->r, in_r) ==
| 0-4 | ||||||||||||||||||
| 273 | ((void *)0)
| 0-4 | ||||||||||||||||||
| 274 | ) { | - | ||||||||||||||||||
| 275 | ERR_put_error(16,(249),((1|64)),__FILE__,220); | - | ||||||||||||||||||
| 276 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 277 | } | - | ||||||||||||||||||
| 278 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 279 | if (!bn_to_mont_fixed_top(s, ret->r, group->mont_data, ctx)
| 0-367 | ||||||||||||||||||
| 280 | || !bn_mul_mont_fixed_top(s, s, priv_key, group->mont_data, ctx)
| 0-367 | ||||||||||||||||||
| 281 | ERR_put_error(16,(249),(3),__FILE__,234); | - | ||||||||||||||||||
| 282 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 283 | } | - | ||||||||||||||||||
| 284 | if (!bn_mod_add_fixed_top(s, s, m, order)
| 0-367 | ||||||||||||||||||
| 285 | ERR_put_error(16,(249),(3),__FILE__,238); | - | ||||||||||||||||||
| 286 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 287 | } | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | - | |||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | if (!bn_to_mont_fixed_top(s, s, group->mont_data, ctx)
| 0-367 | ||||||||||||||||||
| 293 | || !BN_mod_mul_montgomery(s, s, ckinv, group->mont_data, ctx)
| 0-367 | ||||||||||||||||||
| 294 | ERR_put_error(16,(249),(3),__FILE__,247); | - | ||||||||||||||||||
| 295 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 296 | } | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | if (BN_is_zero(s)
| 0-367 | ||||||||||||||||||
| 299 | - | |||||||||||||||||||
| 300 | - | |||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | if (in_kinv !=
| 0 | ||||||||||||||||||
| 304 | ((void *)0)
| 0 | ||||||||||||||||||
| 305 | && in_r !=
| 0 | ||||||||||||||||||
| 306 | ((void *)0)
| 0 | ||||||||||||||||||
| 307 | ) { | - | ||||||||||||||||||
| 308 | ERR_put_error(16,(249),(157),__FILE__,257); | - | ||||||||||||||||||
| 309 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 310 | } | - | ||||||||||||||||||
| 311 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | break; executed 367 times by 1 test: break;Executed by:
| 367 | ||||||||||||||||||
| 314 | } | - | ||||||||||||||||||
| 315 | } while (1); | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | ok = 1; | - | ||||||||||||||||||
| 318 | err: code before this statement executed 367 times by 1 test: err:Executed by:
| 367 | ||||||||||||||||||
| 319 | if (!ok
| 0-367 | ||||||||||||||||||
| 320 | ECDSA_SIG_free(ret); | - | ||||||||||||||||||
| 321 | ret = | - | ||||||||||||||||||
| 322 | ((void *)0) | - | ||||||||||||||||||
| 323 | ; | - | ||||||||||||||||||
| 324 | } never executed: end of block | 0 | ||||||||||||||||||
| 325 | BN_CTX_free(ctx); | - | ||||||||||||||||||
| 326 | BN_clear_free(m); | - | ||||||||||||||||||
| 327 | BN_clear_free(kinv); | - | ||||||||||||||||||
| 328 | return executed 367 times by 1 test: ret;return ret;Executed by:
executed 367 times by 1 test: return ret;Executed by:
| 367 | ||||||||||||||||||
| 329 | } | - | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | - | |||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | - | |||||||||||||||||||
| 336 | - | |||||||||||||||||||
| 337 | int ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len, | - | ||||||||||||||||||
| 338 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey) | - | ||||||||||||||||||
| 339 | { | - | ||||||||||||||||||
| 340 | ECDSA_SIG *s; | - | ||||||||||||||||||
| 341 | const unsigned char *p = sigbuf; | - | ||||||||||||||||||
| 342 | unsigned char *der = | - | ||||||||||||||||||
| 343 | ((void *)0) | - | ||||||||||||||||||
| 344 | ; | - | ||||||||||||||||||
| 345 | int derlen = -1; | - | ||||||||||||||||||
| 346 | int ret = -1; | - | ||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | s = ECDSA_SIG_new(); | - | ||||||||||||||||||
| 349 | if (s ==
| 0-664 | ||||||||||||||||||
| 350 | ((void *)0)
| 0-664 | ||||||||||||||||||
| 351 | ) | - | ||||||||||||||||||
| 352 | return never executed: ret;return ret;never executed: return ret; | 0 | ||||||||||||||||||
| 353 | if (d2i_ECDSA_SIG(&s, &p, sig_len) ==
| 74-590 | ||||||||||||||||||
| 354 | ((void *)0)
| 74-590 | ||||||||||||||||||
| 355 | ) | - | ||||||||||||||||||
| 356 | goto executed 74 times by 1 test: err;goto err;Executed by:
executed 74 times by 1 test: goto err;Executed by:
| 74 | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | derlen = i2d_ECDSA_SIG(s, &der); | - | ||||||||||||||||||
| 359 | if (derlen != sig_len
| 1-587 | ||||||||||||||||||
| 360 | goto executed 4 times by 1 test: err;goto err;Executed by:
executed 4 times by 1 test: goto err;Executed by:
| 4 | ||||||||||||||||||
| 361 | ret = ECDSA_do_verify(dgst, dgst_len, s, eckey); | - | ||||||||||||||||||
| 362 | err: code before this statement executed 586 times by 1 test: err:Executed by:
| 586 | ||||||||||||||||||
| 363 | CRYPTO_clear_free(der, derlen, __FILE__, 304); | - | ||||||||||||||||||
| 364 | ECDSA_SIG_free(s); | - | ||||||||||||||||||
| 365 | return executed 664 times by 1 test: ret;return ret;Executed by:
executed 664 times by 1 test: return ret;Executed by:
| 664 | ||||||||||||||||||
| 366 | } | - | ||||||||||||||||||
| 367 | - | |||||||||||||||||||
| 368 | int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len, | - | ||||||||||||||||||
| 369 | const ECDSA_SIG *sig, EC_KEY *eckey) | - | ||||||||||||||||||
| 370 | { | - | ||||||||||||||||||
| 371 | int ret = -1, i; | - | ||||||||||||||||||
| 372 | BN_CTX *ctx; | - | ||||||||||||||||||
| 373 | const BIGNUM *order; | - | ||||||||||||||||||
| 374 | BIGNUM *u1, *u2, *m, *X; | - | ||||||||||||||||||
| 375 | EC_POINT *point = | - | ||||||||||||||||||
| 376 | ((void *)0) | - | ||||||||||||||||||
| 377 | ; | - | ||||||||||||||||||
| 378 | const EC_GROUP *group; | - | ||||||||||||||||||
| 379 | const EC_POINT *pub_key; | - | ||||||||||||||||||
| 380 | - | |||||||||||||||||||
| 381 | - | |||||||||||||||||||
| 382 | if (eckey ==
| 0-590 | ||||||||||||||||||
| 383 | ((void *)0)
| 0-590 | ||||||||||||||||||
| 384 | || (
| 0-590 | ||||||||||||||||||
| 385 | ((void *)0)
| 0-590 | ||||||||||||||||||
| 386 | || | - | ||||||||||||||||||
| 387 | (
| 0-590 | ||||||||||||||||||
| 388 | ((void *)0)
| 0-590 | ||||||||||||||||||
| 389 | || sig ==
| 0-590 | ||||||||||||||||||
| 390 | ((void *)0)
| 0-590 | ||||||||||||||||||
| 391 | ) { | - | ||||||||||||||||||
| 392 | ERR_put_error(16,(250),(124),__FILE__,323); | - | ||||||||||||||||||
| 393 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 394 | } | - | ||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | if (!EC_KEY_can_sign(eckey)
| 0-590 | ||||||||||||||||||
| 397 | ERR_put_error(16,(250),(159),__FILE__,328); | - | ||||||||||||||||||
| 398 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 399 | } | - | ||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | ctx = BN_CTX_new(); | - | ||||||||||||||||||
| 402 | if (ctx ==
| 0-590 | ||||||||||||||||||
| 403 | ((void *)0)
| 0-590 | ||||||||||||||||||
| 404 | ) { | - | ||||||||||||||||||
| 405 | ERR_put_error(16,(250),((1|64)),__FILE__,334); | - | ||||||||||||||||||
| 406 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 407 | } | - | ||||||||||||||||||
| 408 | BN_CTX_start(ctx); | - | ||||||||||||||||||
| 409 | u1 = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 410 | u2 = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 411 | m = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 412 | X = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 413 | if (X ==
| 0-590 | ||||||||||||||||||
| 414 | ((void *)0)
| 0-590 | ||||||||||||||||||
| 415 | ) { | - | ||||||||||||||||||
| 416 | ERR_put_error(16,(250),(3),__FILE__,343); | - | ||||||||||||||||||
| 417 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 418 | } | - | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | order = EC_GROUP_get0_order(group); | - | ||||||||||||||||||
| 421 | if (order ==
| 0-590 | ||||||||||||||||||
| 422 | ((void *)0)
| 0-590 | ||||||||||||||||||
| 423 | ) { | - | ||||||||||||||||||
| 424 | ERR_put_error(16,(250),(16),__FILE__,349); | - | ||||||||||||||||||
| 425 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 426 | } | - | ||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | if (BN_is_zero(sig->r)
| 0-589 | ||||||||||||||||||
| 429 | BN_ucmp(sig->r, order) >= 0
| 1-587 | ||||||||||||||||||
| 430 | BN_is_negative(sig->s)
| 0-586 | ||||||||||||||||||
| 431 | ERR_put_error(16,(250),(156),__FILE__,356); | - | ||||||||||||||||||
| 432 | ret = 0; | - | ||||||||||||||||||
| 433 | goto executed 6 times by 1 test: err;goto err;Executed by:
executed 6 times by 1 test: goto err;Executed by:
| 6 | ||||||||||||||||||
| 434 | } | - | ||||||||||||||||||
| 435 | - | |||||||||||||||||||
| 436 | if (!ec_group_do_inverse_ord(group, u2, sig->s, ctx)
| 0-584 | ||||||||||||||||||
| 437 | ERR_put_error(16,(250),(3),__FILE__,362); | - | ||||||||||||||||||
| 438 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 439 | } | - | ||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | i = BN_num_bits(order); | - | ||||||||||||||||||
| 442 | - | |||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | - | |||||||||||||||||||
| 445 | if (8 * dgst_len > i
| 2-582 | ||||||||||||||||||
| 446 | dgst_len = (i + 7) / 8; executed 2 times by 1 test: dgst_len = (i + 7) / 8;Executed by:
| 2 | ||||||||||||||||||
| 447 | if (!BN_bin2bn(dgst, dgst_len, m)
| 0-584 | ||||||||||||||||||
| 448 | ERR_put_error(16,(250),(3),__FILE__,373); | - | ||||||||||||||||||
| 449 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 450 | } | - | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | if ((
| 0-584 | ||||||||||||||||||
| 453 | ERR_put_error(16,(250),(3),__FILE__,378); | - | ||||||||||||||||||
| 454 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 455 | } | - | ||||||||||||||||||
| 456 | - | |||||||||||||||||||
| 457 | if (!BN_mod_mul(u1, m, u2, order, ctx)
| 0-584 | ||||||||||||||||||
| 458 | ERR_put_error(16,(250),(3),__FILE__,383); | - | ||||||||||||||||||
| 459 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 460 | } | - | ||||||||||||||||||
| 461 | - | |||||||||||||||||||
| 462 | if (!BN_mod_mul(u2, sig->r, u2, order, ctx)
| 0-584 | ||||||||||||||||||
| 463 | ERR_put_error(16,(250),(3),__FILE__,388); | - | ||||||||||||||||||
| 464 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 465 | } | - | ||||||||||||||||||
| 466 | - | |||||||||||||||||||
| 467 | if ((
| 0-584 | ||||||||||||||||||
| 468 | ((void *)0)
| 0-584 | ||||||||||||||||||
| 469 | ) { | - | ||||||||||||||||||
| 470 | ERR_put_error(16,(250),((1|64)),__FILE__,393); | - | ||||||||||||||||||
| 471 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 472 | } | - | ||||||||||||||||||
| 473 | if (!EC_POINT_mul(group, point, u1, pub_key, u2, ctx)
| 0-584 | ||||||||||||||||||
| 474 | ERR_put_error(16,(250),(16),__FILE__,397); | - | ||||||||||||||||||
| 475 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 476 | } | - | ||||||||||||||||||
| 477 | - | |||||||||||||||||||
| 478 | if (!EC_POINT_get_affine_coordinates(group, point, X,
| 0-584 | ||||||||||||||||||
| 479 | ((void *)0)
| 0-584 | ||||||||||||||||||
| 480 | , ctx)
| 0-584 | ||||||||||||||||||
| 481 | ERR_put_error(16,(250),(16),__FILE__,402); | - | ||||||||||||||||||
| 482 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 483 | } | - | ||||||||||||||||||
| 484 | - | |||||||||||||||||||
| 485 | if (!BN_nnmod(u1, X, order, ctx)
| 0-584 | ||||||||||||||||||
| 486 | ERR_put_error(16,(250),(3),__FILE__,407); | - | ||||||||||||||||||
| 487 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 488 | } | - | ||||||||||||||||||
| 489 | - | |||||||||||||||||||
| 490 | ret = (BN_ucmp(u1, sig->r) == 0); | - | ||||||||||||||||||
| 491 | err: code before this statement executed 584 times by 1 test: err:Executed by:
| 584 | ||||||||||||||||||
| 492 | BN_CTX_end(ctx); | - | ||||||||||||||||||
| 493 | BN_CTX_free(ctx); | - | ||||||||||||||||||
| 494 | EC_POINT_free(point); | - | ||||||||||||||||||
| 495 | return executed 590 times by 1 test: ret;return ret;Executed by:
executed 590 times by 1 test: return ret;Executed by:
| 590 | ||||||||||||||||||
| 496 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |