Lines Matching refs:dsa
28 static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
29 static int dsa_sign_setup_no_digest(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
31 static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
36 DSA_SIG *sig, DSA *dsa);
37 static int dsa_init(DSA *dsa);
38 static int dsa_finish(DSA *dsa);
76 DSA_SIG *ossl_dsa_do_sign_int(const unsigned char *dgst, int dlen, DSA *dsa, in ossl_dsa_do_sign_int() argument
88 if (dsa->params.p == NULL in ossl_dsa_do_sign_int()
89 || dsa->params.q == NULL in ossl_dsa_do_sign_int()
90 || dsa->params.g == NULL) { in ossl_dsa_do_sign_int()
94 if (dsa->priv_key == NULL) { in ossl_dsa_do_sign_int()
107 ctx = BN_CTX_new_ex(dsa->libctx); in ossl_dsa_do_sign_int()
118 if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen, in ossl_dsa_do_sign_int()
122 if (dlen > BN_num_bytes(dsa->params.q)) in ossl_dsa_do_sign_int()
128 dlen = BN_num_bytes(dsa->params.q); in ossl_dsa_do_sign_int()
147 if (!BN_priv_rand_ex(blind, BN_num_bits(dsa->params.q) - 1, in ossl_dsa_do_sign_int()
156 if (!BN_mod_mul(tmp, blind, dsa->priv_key, dsa->params.q, ctx)) in ossl_dsa_do_sign_int()
158 if (!BN_mod_mul(tmp, tmp, ret->r, dsa->params.q, ctx)) in ossl_dsa_do_sign_int()
162 if (!BN_mod_mul(blindm, blind, m, dsa->params.q, ctx)) in ossl_dsa_do_sign_int()
166 if (!BN_mod_add_quick(ret->s, tmp, blindm, dsa->params.q)) in ossl_dsa_do_sign_int()
170 if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->params.q, ctx)) in ossl_dsa_do_sign_int()
174 if (BN_mod_inverse(blind, blind, dsa->params.q, ctx) == NULL) in ossl_dsa_do_sign_int()
176 if (!BN_mod_mul(ret->s, ret->s, blind, dsa->params.q, ctx)) in ossl_dsa_do_sign_int()
204 static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) in dsa_do_sign() argument
206 return ossl_dsa_do_sign_int(dgst, dlen, dsa, in dsa_do_sign()
210 static int dsa_sign_setup_no_digest(DSA *dsa, BN_CTX *ctx_in, in dsa_sign_setup_no_digest() argument
213 return dsa_sign_setup(dsa, ctx_in, kinvp, rp, NULL, 0, in dsa_sign_setup_no_digest()
217 static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, in dsa_sign_setup() argument
229 if (!dsa->params.p || !dsa->params.q || !dsa->params.g) { in dsa_sign_setup()
235 if (BN_is_zero(dsa->params.p) in dsa_sign_setup()
236 || BN_is_zero(dsa->params.q) in dsa_sign_setup()
237 || BN_is_zero(dsa->params.g) in dsa_sign_setup()
238 || BN_is_negative(dsa->params.p) in dsa_sign_setup()
239 || BN_is_negative(dsa->params.q) in dsa_sign_setup()
240 || BN_is_negative(dsa->params.g)) { in dsa_sign_setup()
244 if (dsa->priv_key == NULL) { in dsa_sign_setup()
261 q_bits = BN_num_bits(dsa->params.q); in dsa_sign_setup()
262 q_words = bn_get_top(dsa->params.q); in dsa_sign_setup()
273 if (!ossl_gen_deterministic_nonce_rfc6979(k, dsa->params.q, in dsa_sign_setup()
274 dsa->priv_key, in dsa_sign_setup()
285 if (!ossl_bn_gen_dsa_nonce_fixed_top(k, dsa->params.q, in dsa_sign_setup()
286 dsa->priv_key, dgst, in dsa_sign_setup()
290 } else if (!ossl_bn_priv_rand_range_fixed_top(k, dsa->params.q, 0, ctx)) in dsa_sign_setup()
297 if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { in dsa_sign_setup()
298 if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p, in dsa_sign_setup()
299 dsa->lock, dsa->params.p, ctx)) in dsa_sign_setup()
318 if (!BN_add(l, k, dsa->params.q) in dsa_sign_setup()
319 || !BN_add(k, l, dsa->params.q)) in dsa_sign_setup()
324 if ((dsa)->meth->bn_mod_exp != NULL) { in dsa_sign_setup()
325 if (!dsa->meth->bn_mod_exp(dsa, r, dsa->params.g, k, dsa->params.p, in dsa_sign_setup()
326 ctx, dsa->method_mont_p)) in dsa_sign_setup()
329 if (!BN_mod_exp_mont(r, dsa->params.g, k, dsa->params.p, ctx, in dsa_sign_setup()
330 dsa->method_mont_p)) in dsa_sign_setup()
334 if (!BN_mod(r, r, dsa->params.q, ctx)) in dsa_sign_setup()
338 if ((kinv = dsa_mod_inverse_fermat(k, dsa->params.q, ctx)) == NULL) in dsa_sign_setup()
356 DSA_SIG *sig, DSA *dsa) in dsa_do_verify() argument
364 if (dsa->params.p == NULL in dsa_do_verify()
365 || dsa->params.q == NULL in dsa_do_verify()
366 || dsa->params.g == NULL) { in dsa_do_verify()
371 i = BN_num_bits(dsa->params.q); in dsa_do_verify()
378 if (BN_num_bits(dsa->params.p) > OPENSSL_DSA_MAX_MODULUS_BITS) { in dsa_do_verify()
392 BN_ucmp(r, dsa->params.q) >= 0) { in dsa_do_verify()
397 BN_ucmp(s, dsa->params.q) >= 0) { in dsa_do_verify()
405 if ((BN_mod_inverse(u2, s, dsa->params.q, ctx)) == NULL) in dsa_do_verify()
420 if (!BN_mod_mul(u1, u1, u2, dsa->params.q, ctx)) in dsa_do_verify()
424 if (!BN_mod_mul(u2, r, u2, dsa->params.q, ctx)) in dsa_do_verify()
427 if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { in dsa_do_verify()
428 mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p, in dsa_do_verify()
429 dsa->lock, dsa->params.p, ctx); in dsa_do_verify()
434 if (dsa->meth->dsa_mod_exp != NULL) { in dsa_do_verify()
435 if (!dsa->meth->dsa_mod_exp(dsa, t1, dsa->params.g, u1, dsa->pub_key, u2, in dsa_do_verify()
436 dsa->params.p, ctx, mont)) in dsa_do_verify()
439 if (!BN_mod_exp2_mont(t1, dsa->params.g, u1, dsa->pub_key, u2, in dsa_do_verify()
440 dsa->params.p, ctx, mont)) in dsa_do_verify()
445 if (!BN_mod(u1, t1, dsa->params.q, ctx)) in dsa_do_verify()
463 static int dsa_init(DSA *dsa) in dsa_init() argument
465 dsa->flags |= DSA_FLAG_CACHE_MONT_P; in dsa_init()
466 dsa->dirty_cnt++; in dsa_init()
470 static int dsa_finish(DSA *dsa) in dsa_finish() argument
472 BN_MONT_CTX_free(dsa->method_mont_p); in dsa_finish()