| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/dsa/dsa_ossl.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | - | ||||||||||||||||||
| 4 | static int dsa_sign_setup_no_digest(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, | - | ||||||||||||||||||
| 5 | BIGNUM **rp); | - | ||||||||||||||||||
| 6 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, | - | ||||||||||||||||||
| 7 | BIGNUM **rp, const unsigned char *dgst, int dlen); | - | ||||||||||||||||||
| 8 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, | - | ||||||||||||||||||
| 9 | DSA_SIG *sig, DSA *dsa); | - | ||||||||||||||||||
| 10 | static int dsa_init(DSA *dsa); | - | ||||||||||||||||||
| 11 | static int dsa_finish(DSA *dsa); | - | ||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | static DSA_METHOD openssl_dsa_meth = { | - | ||||||||||||||||||
| 14 | "OpenSSL DSA method", | - | ||||||||||||||||||
| 15 | dsa_do_sign, | - | ||||||||||||||||||
| 16 | dsa_sign_setup_no_digest, | - | ||||||||||||||||||
| 17 | dsa_do_verify, | - | ||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | ((void *)0) | - | ||||||||||||||||||
| 20 | , | - | ||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | ((void *)0) | - | ||||||||||||||||||
| 23 | , | - | ||||||||||||||||||
| 24 | dsa_init, | - | ||||||||||||||||||
| 25 | dsa_finish, | - | ||||||||||||||||||
| 26 | 0x0400, | - | ||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | ((void *)0) | - | ||||||||||||||||||
| 29 | , | - | ||||||||||||||||||
| 30 | - | |||||||||||||||||||
| 31 | ((void *)0) | - | ||||||||||||||||||
| 32 | , | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | ((void *)0) | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | }; | - | ||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | static const DSA_METHOD *default_DSA_method = &openssl_dsa_meth; | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | void DSA_set_default_method(const DSA_METHOD *meth) | - | ||||||||||||||||||
| 41 | { | - | ||||||||||||||||||
| 42 | default_DSA_method = meth; | - | ||||||||||||||||||
| 43 | } never executed: end of block | 0 | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | const DSA_METHOD *DSA_get_default_method(void) | - | ||||||||||||||||||
| 46 | { | - | ||||||||||||||||||
| 47 | return executed 15144 times by 1 test: default_DSA_method;return default_DSA_method;Executed by:
executed 15144 times by 1 test: return default_DSA_method;Executed by:
| 15144 | ||||||||||||||||||
| 48 | } | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | const DSA_METHOD *DSA_OpenSSL(void) | - | ||||||||||||||||||
| 51 | { | - | ||||||||||||||||||
| 52 | return never executed: &openssl_dsa_meth;return &openssl_dsa_meth;never executed: return &openssl_dsa_meth; | 0 | ||||||||||||||||||
| 53 | } | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | - | ||||||||||||||||||
| 56 | { | - | ||||||||||||||||||
| 57 | BIGNUM *kinv = | - | ||||||||||||||||||
| 58 | ((void *)0) | - | ||||||||||||||||||
| 59 | ; | - | ||||||||||||||||||
| 60 | BIGNUM *m, *blind, *blindm, *tmp; | - | ||||||||||||||||||
| 61 | BN_CTX *ctx = | - | ||||||||||||||||||
| 62 | ((void *)0) | - | ||||||||||||||||||
| 63 | ; | - | ||||||||||||||||||
| 64 | int reason = 3; | - | ||||||||||||||||||
| 65 | DSA_SIG *ret = | - | ||||||||||||||||||
| 66 | ((void *)0) | - | ||||||||||||||||||
| 67 | ; | - | ||||||||||||||||||
| 68 | int rv = 0; | - | ||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | if (dsa->p ==
| 0-64 | ||||||||||||||||||
| 71 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 72 | || dsa->q ==
| 0-64 | ||||||||||||||||||
| 73 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 74 | || dsa->g ==
| 0-64 | ||||||||||||||||||
| 75 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 76 | ) { | - | ||||||||||||||||||
| 77 | reason = 101; | - | ||||||||||||||||||
| 78 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 79 | } | - | ||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | ret = DSA_SIG_new(); | - | ||||||||||||||||||
| 82 | if (ret ==
| 0-64 | ||||||||||||||||||
| 83 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 84 | ) | - | ||||||||||||||||||
| 85 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 86 | ret->r = BN_new(); | - | ||||||||||||||||||
| 87 | ret->s = BN_new(); | - | ||||||||||||||||||
| 88 | if (ret->r ==
| 0-64 | ||||||||||||||||||
| 89 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 90 | || ret->s ==
| 0-64 | ||||||||||||||||||
| 91 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 92 | ) | - | ||||||||||||||||||
| 93 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | ctx = BN_CTX_new(); | - | ||||||||||||||||||
| 96 | if (ctx ==
| 0-64 | ||||||||||||||||||
| 97 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 98 | ) | - | ||||||||||||||||||
| 99 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 100 | m = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 101 | blind = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 102 | blindm = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 103 | tmp = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 104 | if (tmp ==
| 0-64 | ||||||||||||||||||
| 105 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 106 | ) | - | ||||||||||||||||||
| 107 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | redo: code before this statement executed 64 times by 1 test: redo:Executed by:
| 64 | ||||||||||||||||||
| 110 | if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen)
| 0-64 | ||||||||||||||||||
| 111 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | if (dlen > ((BN_num_bits(dsa->q)+7)/8)
| 16-48 | ||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | dlen = ((BN_num_bits(dsa->q)+7)/8); executed 16 times by 1 test: dlen = ((BN_num_bits(dsa->q)+7)/8);Executed by:
| 16 | ||||||||||||||||||
| 120 | if (BN_bin2bn(dgst, dlen, m) ==
| 0-64 | ||||||||||||||||||
| 121 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 122 | ) | - | ||||||||||||||||||
| 123 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 124 | do { | - | ||||||||||||||||||
| 125 | if (!BN_priv_rand(blind, BN_num_bits(dsa->q) - 1,
| 0-64 | ||||||||||||||||||
| 126 | -1, 0)
| 0-64 | ||||||||||||||||||
| 127 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 128 | } executed 64 times by 1 test: while (BN_is_zero(blind)end of blockExecuted by:
| 0-64 | ||||||||||||||||||
| 129 | BN_set_flags(blind, 0x04); | - | ||||||||||||||||||
| 130 | BN_set_flags(blindm, 0x04); | - | ||||||||||||||||||
| 131 | BN_set_flags(tmp, 0x04); | - | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | if (!BN_mod_mul(tmp, blind, dsa->priv_key, dsa->q, ctx)
| 0-64 | ||||||||||||||||||
| 135 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 136 | if (!BN_mod_mul(tmp, tmp, ret->r, dsa->q, ctx)
| 0-64 | ||||||||||||||||||
| 137 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | if (!BN_mod_mul(blindm, blind, m, dsa->q, ctx)
| 0-64 | ||||||||||||||||||
| 141 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | if (!BN_mod_add_quick(ret->s, tmp, blindm, dsa->q)
| 0-64 | ||||||||||||||||||
| 145 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->q, ctx)
| 0-64 | ||||||||||||||||||
| 149 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | if (BN_mod_inverse(blind, blind, dsa->q, ctx) ==
| 0-64 | ||||||||||||||||||
| 153 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 154 | ) | - | ||||||||||||||||||
| 155 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 156 | if (!BN_mod_mul(ret->s, ret->s, blind, dsa->q, ctx)
| 0-64 | ||||||||||||||||||
| 157 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | if (BN_is_zero(ret->r)
| 0-64 | ||||||||||||||||||
| 164 | goto never executed: redo;goto redo;never executed: goto redo; | 0 | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | rv = 1; | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | err: code before this statement executed 64 times by 1 test: err:Executed by:
| 64 | ||||||||||||||||||
| 169 | if (rv == 0
| 0-64 | ||||||||||||||||||
| 170 | ERR_put_error(10,(112),(reason),__FILE__,160); | - | ||||||||||||||||||
| 171 | DSA_SIG_free(ret); | - | ||||||||||||||||||
| 172 | ret = | - | ||||||||||||||||||
| 173 | ((void *)0) | - | ||||||||||||||||||
| 174 | ; | - | ||||||||||||||||||
| 175 | } never executed: end of block | 0 | ||||||||||||||||||
| 176 | BN_CTX_free(ctx); | - | ||||||||||||||||||
| 177 | BN_clear_free(kinv); | - | ||||||||||||||||||
| 178 | return executed 64 times by 1 test: ret;return ret;Executed by:
executed 64 times by 1 test: return ret;Executed by:
| 64 | ||||||||||||||||||
| 179 | } | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | static int dsa_sign_setup_no_digest(DSA *dsa, BN_CTX *ctx_in, | - | ||||||||||||||||||
| 182 | BIGNUM **kinvp, BIGNUM **rp) | - | ||||||||||||||||||
| 183 | { | - | ||||||||||||||||||
| 184 | return never executed: dsa_sign_setup(dsa, ctx_in, kinvp, rp, return dsa_sign_setup(dsa, ctx_in, kinvp, rp, ((void *)0) , 0);never executed: return dsa_sign_setup(dsa, ctx_in, kinvp, rp, ((void *)0) , 0); | 0 | ||||||||||||||||||
| 185 | ((void *)0) never executed: return dsa_sign_setup(dsa, ctx_in, kinvp, rp, ((void *)0) , 0); | 0 | ||||||||||||||||||
| 186 | , 0); never executed: return dsa_sign_setup(dsa, ctx_in, kinvp, rp, ((void *)0) , 0); | 0 | ||||||||||||||||||
| 187 | } | - | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, | - | ||||||||||||||||||
| 190 | BIGNUM **kinvp, BIGNUM **rp, | - | ||||||||||||||||||
| 191 | const unsigned char *dgst, int dlen) | - | ||||||||||||||||||
| 192 | { | - | ||||||||||||||||||
| 193 | BN_CTX *ctx = | - | ||||||||||||||||||
| 194 | ((void *)0) | - | ||||||||||||||||||
| 195 | ; | - | ||||||||||||||||||
| 196 | BIGNUM *k, *kinv = | - | ||||||||||||||||||
| 197 | ((void *)0) | - | ||||||||||||||||||
| 198 | , *r = *rp; | - | ||||||||||||||||||
| 199 | BIGNUM *l, *m; | - | ||||||||||||||||||
| 200 | int ret = 0; | - | ||||||||||||||||||
| 201 | int q_bits; | - | ||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | if (!dsa->p
| 0-64 | ||||||||||||||||||
| 204 | ERR_put_error(10,(107),(101),__FILE__,186); | - | ||||||||||||||||||
| 205 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 206 | } | - | ||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | k = BN_new(); | - | ||||||||||||||||||
| 209 | l = BN_new(); | - | ||||||||||||||||||
| 210 | m = BN_new(); | - | ||||||||||||||||||
| 211 | if (k ==
| 0-64 | ||||||||||||||||||
| 212 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 213 | || l ==
| 0-64 | ||||||||||||||||||
| 214 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 215 | || m ==
| 0-64 | ||||||||||||||||||
| 216 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 217 | ) | - | ||||||||||||||||||
| 218 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | if (ctx_in ==
| 0-64 | ||||||||||||||||||
| 221 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 222 | ) { | - | ||||||||||||||||||
| 223 | if ((
| 0 | ||||||||||||||||||
| 224 | ((void *)0)
| 0 | ||||||||||||||||||
| 225 | ) | - | ||||||||||||||||||
| 226 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 227 | } never executed: elseend of block | 0 | ||||||||||||||||||
| 228 | ctx = ctx_in; executed 64 times by 1 test: ctx = ctx_in;Executed by:
| 64 | ||||||||||||||||||
| 229 | - | |||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | q_bits = BN_num_bits(dsa->q); | - | ||||||||||||||||||
| 232 | if (!BN_set_bit(k, q_bits)
| 0-64 | ||||||||||||||||||
| 233 | || !BN_set_bit(l, q_bits)
| 0-64 | ||||||||||||||||||
| 234 | || !BN_set_bit(m, q_bits)
| 0-64 | ||||||||||||||||||
| 235 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | - | |||||||||||||||||||
| 238 | do { | - | ||||||||||||||||||
| 239 | if (dgst !=
| 0-64 | ||||||||||||||||||
| 240 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 241 | ) { | - | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | - | |||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,
| 0-64 | ||||||||||||||||||
| 247 | dlen, ctx)
| 0-64 | ||||||||||||||||||
| 248 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 249 | } executed 64 times by 1 test: else if (!BN_priv_rand_range(k, dsa->q)end of blockExecuted by:
| 0-64 | ||||||||||||||||||
| 250 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 251 | } executed 64 times by 1 test: while (BN_is_zero(k)end of blockExecuted by:
| 0-64 | ||||||||||||||||||
| 252 | - | |||||||||||||||||||
| 253 | BN_set_flags(k, 0x04); | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | if (dsa->flags & 0x01
| 0-64 | ||||||||||||||||||
| 256 | if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,
| 0-64 | ||||||||||||||||||
| 257 | dsa->lock, dsa->p, ctx)
| 0-64 | ||||||||||||||||||
| 258 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 259 | } executed 64 times by 1 test: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 260 | if (!BN_add(l, k, dsa->q)
| 0-64 | ||||||||||||||||||
| 261 | || !BN_add(m, l, dsa->q)
| 0-64 | ||||||||||||||||||
| 262 | || !BN_copy(k, BN_num_bits(l) > q_bits ? l : m)
| 0-64 | ||||||||||||||||||
| 263 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | if ((
| 0-64 | ||||||||||||||||||
| 266 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 267 | ) { | - | ||||||||||||||||||
| 268 | if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx,
| 0 | ||||||||||||||||||
| 269 | dsa->method_mont_p)
| 0 | ||||||||||||||||||
| 270 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 271 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 272 | if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p)
| 0-64 | ||||||||||||||||||
| 273 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 274 | } executed 64 times by 1 test: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | if (!BN_div(
| 0-64 | ||||||||||||||||||
| 277 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 278 | ,(r),(r),(dsa->q),(ctx))
| 0-64 | ||||||||||||||||||
| 279 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 280 | - | |||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | if ((
| 0-64 | ||||||||||||||||||
| 283 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 284 | , k, dsa->q, ctx)) ==
| 0-64 | ||||||||||||||||||
| 285 | ((void *)0)
| 0-64 | ||||||||||||||||||
| 286 | ) | - | ||||||||||||||||||
| 287 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | BN_clear_free(*kinvp); | - | ||||||||||||||||||
| 290 | *kinvp = kinv; | - | ||||||||||||||||||
| 291 | kinv = | - | ||||||||||||||||||
| 292 | ((void *)0) | - | ||||||||||||||||||
| 293 | ; | - | ||||||||||||||||||
| 294 | ret = 1; | - | ||||||||||||||||||
| 295 | err: code before this statement executed 64 times by 1 test: err:Executed by:
| 64 | ||||||||||||||||||
| 296 | if (!ret
| 0-64 | ||||||||||||||||||
| 297 | ERR_put_error(10,(107),(3),__FILE__,271); never executed: ERR_put_error(10,(107),(3),__FILE__,271); | 0 | ||||||||||||||||||
| 298 | if (ctx != ctx_in
| 0-64 | ||||||||||||||||||
| 299 | BN_CTX_free(ctx); never executed: BN_CTX_free(ctx); | 0 | ||||||||||||||||||
| 300 | BN_clear_free(k); | - | ||||||||||||||||||
| 301 | BN_clear_free(l); | - | ||||||||||||||||||
| 302 | BN_clear_free(m); | - | ||||||||||||||||||
| 303 | return executed 64 times by 1 test: ret;return ret;Executed by:
executed 64 times by 1 test: return ret;Executed by:
| 64 | ||||||||||||||||||
| 304 | } | - | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, | - | ||||||||||||||||||
| 307 | DSA_SIG *sig, DSA *dsa) | - | ||||||||||||||||||
| 308 | { | - | ||||||||||||||||||
| 309 | BN_CTX *ctx; | - | ||||||||||||||||||
| 310 | BIGNUM *u1, *u2, *t1; | - | ||||||||||||||||||
| 311 | BN_MONT_CTX *mont = | - | ||||||||||||||||||
| 312 | ((void *)0) | - | ||||||||||||||||||
| 313 | ; | - | ||||||||||||||||||
| 314 | const BIGNUM *r, *s; | - | ||||||||||||||||||
| 315 | int ret = -1, i; | - | ||||||||||||||||||
| 316 | if (!dsa->p
| 0-301 | ||||||||||||||||||
| 317 | ERR_put_error(10,(113),(101),__FILE__,289); | - | ||||||||||||||||||
| 318 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 319 | } | - | ||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | i = BN_num_bits(dsa->q); | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | if (i != 160
| 1-276 | ||||||||||||||||||
| 324 | ERR_put_error(10,(113),(102),__FILE__,296); | - | ||||||||||||||||||
| 325 | return executed 1 time by 1 test: -1;return -1;Executed by:
executed 1 time by 1 test: return -1;Executed by:
| 1 | ||||||||||||||||||
| 326 | } | - | ||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | if (BN_num_bits(dsa->p) > 10000
| 0-300 | ||||||||||||||||||
| 329 | ERR_put_error(10,(113),(103),__FILE__,301); | - | ||||||||||||||||||
| 330 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 331 | } | - | ||||||||||||||||||
| 332 | u1 = BN_new(); | - | ||||||||||||||||||
| 333 | u2 = BN_new(); | - | ||||||||||||||||||
| 334 | t1 = BN_new(); | - | ||||||||||||||||||
| 335 | ctx = BN_CTX_new(); | - | ||||||||||||||||||
| 336 | if (u1 ==
| 0-300 | ||||||||||||||||||
| 337 | ((void *)0)
| 0-300 | ||||||||||||||||||
| 338 | || u2 ==
| 0-300 | ||||||||||||||||||
| 339 | ((void *)0)
| 0-300 | ||||||||||||||||||
| 340 | || t1 ==
| 0-300 | ||||||||||||||||||
| 341 | ((void *)0)
| 0-300 | ||||||||||||||||||
| 342 | || ctx ==
| 0-300 | ||||||||||||||||||
| 343 | ((void *)0)
| 0-300 | ||||||||||||||||||
| 344 | ) | - | ||||||||||||||||||
| 345 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 346 | - | |||||||||||||||||||
| 347 | DSA_SIG_get0(sig, &r, &s); | - | ||||||||||||||||||
| 348 | - | |||||||||||||||||||
| 349 | if (BN_is_zero(r)
| 0-300 | ||||||||||||||||||
| 350 | BN_ucmp(r, dsa->q) >= 0
| 1-299 | ||||||||||||||||||
| 351 | ret = 0; | - | ||||||||||||||||||
| 352 | goto executed 1 time by 1 test: err;goto err;Executed by:
executed 1 time by 1 test: goto err;Executed by:
| 1 | ||||||||||||||||||
| 353 | } | - | ||||||||||||||||||
| 354 | if (BN_is_zero(s)
| 0-299 | ||||||||||||||||||
| 355 | BN_ucmp(s, dsa->q) >= 0
| 1-298 | ||||||||||||||||||
| 356 | ret = 0; | - | ||||||||||||||||||
| 357 | goto executed 1 time by 1 test: err;goto err;Executed by:
executed 1 time by 1 test: goto err;Executed by:
| 1 | ||||||||||||||||||
| 358 | } | - | ||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | - | |||||||||||||||||||
| 361 | - | |||||||||||||||||||
| 362 | - | |||||||||||||||||||
| 363 | if ((
| 10-288 | ||||||||||||||||||
| 364 | ((void *)0)
| 10-288 | ||||||||||||||||||
| 365 | ) | - | ||||||||||||||||||
| 366 | goto executed 10 times by 1 test: err;goto err;Executed by:
executed 10 times by 1 test: goto err;Executed by:
| 10 | ||||||||||||||||||
| 367 | - | |||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | if (dgst_len > (i >> 3)
| 99-189 | ||||||||||||||||||
| 370 | - | |||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | - | |||||||||||||||||||
| 373 | - | |||||||||||||||||||
| 374 | - | |||||||||||||||||||
| 375 | dgst_len = (i >> 3); executed 189 times by 1 test: dgst_len = (i >> 3);Executed by:
| 189 | ||||||||||||||||||
| 376 | if (BN_bin2bn(dgst, dgst_len, u1) ==
| 0-288 | ||||||||||||||||||
| 377 | ((void *)0)
| 0-288 | ||||||||||||||||||
| 378 | ) | - | ||||||||||||||||||
| 379 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 380 | - | |||||||||||||||||||
| 381 | - | |||||||||||||||||||
| 382 | if (!BN_mod_mul(u1, u1, u2, dsa->q, ctx)
| 0-288 | ||||||||||||||||||
| 383 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 384 | - | |||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | if (!BN_mod_mul(u2, r, u2, dsa->q, ctx)
| 0-288 | ||||||||||||||||||
| 387 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 388 | - | |||||||||||||||||||
| 389 | if (dsa->flags & 0x01
| 0-288 | ||||||||||||||||||
| 390 | mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p, | - | ||||||||||||||||||
| 391 | dsa->lock, dsa->p, ctx); | - | ||||||||||||||||||
| 392 | if (!mont
| 5-283 | ||||||||||||||||||
| 393 | goto executed 5 times by 1 test: err;goto err;Executed by:
executed 5 times by 1 test: goto err;Executed by:
| 5 | ||||||||||||||||||
| 394 | } executed 283 times by 1 test: end of blockExecuted by:
| 283 | ||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | if (dsa->meth->dsa_mod_exp !=
| 0-283 | ||||||||||||||||||
| 397 | ((void *)0)
| 0-283 | ||||||||||||||||||
| 398 | ) { | - | ||||||||||||||||||
| 399 | if (!dsa->meth->dsa_mod_exp(dsa, t1, dsa->g, u1, dsa->pub_key, u2,
| 0 | ||||||||||||||||||
| 400 | dsa->p, ctx, mont)
| 0 | ||||||||||||||||||
| 401 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 402 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 403 | if (!BN_mod_exp2_mont(t1, dsa->g, u1, dsa->pub_key, u2, dsa->p, ctx,
| 0-283 | ||||||||||||||||||
| 404 | mont)
| 0-283 | ||||||||||||||||||
| 405 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 406 | } executed 283 times by 1 test: end of blockExecuted by:
| 283 | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | if (!BN_div(
| 0-283 | ||||||||||||||||||
| 410 | ((void *)0)
| 0-283 | ||||||||||||||||||
| 411 | ,(u1),(t1),(dsa->q),(ctx))
| 0-283 | ||||||||||||||||||
| 412 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 413 | - | |||||||||||||||||||
| 414 | - | |||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | ret = (BN_ucmp(u1, r) == 0); | - | ||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | err: code before this statement executed 283 times by 1 test: err:Executed by:
| 283 | ||||||||||||||||||
| 420 | if (ret < 0
| 15-285 | ||||||||||||||||||
| 421 | ERR_put_error(10,(113),(3),__FILE__,377); executed 15 times by 1 test: ERR_put_error(10,(113),(3),__FILE__,377);Executed by:
| 15 | ||||||||||||||||||
| 422 | BN_CTX_free(ctx); | - | ||||||||||||||||||
| 423 | BN_free(u1); | - | ||||||||||||||||||
| 424 | BN_free(u2); | - | ||||||||||||||||||
| 425 | BN_free(t1); | - | ||||||||||||||||||
| 426 | return executed 300 times by 1 test: ret;return ret;Executed by:
executed 300 times by 1 test: return ret;Executed by:
| 300 | ||||||||||||||||||
| 427 | } | - | ||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | static int dsa_init(DSA *dsa) | - | ||||||||||||||||||
| 430 | { | - | ||||||||||||||||||
| 431 | dsa->flags |= 0x01; | - | ||||||||||||||||||
| 432 | return executed 15144 times by 1 test: 1;return 1;Executed by:
executed 15144 times by 1 test: return 1;Executed by:
| 15144 | ||||||||||||||||||
| 433 | } | - | ||||||||||||||||||
| 434 | - | |||||||||||||||||||
| 435 | static int dsa_finish(DSA *dsa) | - | ||||||||||||||||||
| 436 | { | - | ||||||||||||||||||
| 437 | BN_MONT_CTX_free(dsa->method_mont_p); | - | ||||||||||||||||||
| 438 | return executed 15144 times by 1 test: 1;return 1;Executed by:
executed 15144 times by 1 test: return 1;Executed by:
| 15144 | ||||||||||||||||||
| 439 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |