Lines Matching refs:dh
29 static int generate_key(DH *dh);
30 static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
33 static int dh_init(DH *dh);
34 static int dh_finish(DH *dh);
40 int ossl_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) in ossl_dh_compute_key() argument
47 if (BN_num_bits(dh->params.p) > OPENSSL_DH_MAX_MODULUS_BITS) { in ossl_dh_compute_key()
52 if (dh->params.q != NULL in ossl_dh_compute_key()
53 && BN_num_bits(dh->params.q) > OPENSSL_DH_MAX_MODULUS_BITS) { in ossl_dh_compute_key()
58 if (BN_num_bits(dh->params.p) < DH_MIN_MODULUS_BITS) { in ossl_dh_compute_key()
63 ctx = BN_CTX_new_ex(dh->libctx); in ossl_dh_compute_key()
72 if (dh->priv_key == NULL) { in ossl_dh_compute_key()
77 if (dh->flags & DH_FLAG_CACHE_MONT_P) { in ossl_dh_compute_key()
78 mont = BN_MONT_CTX_set_locked(&dh->method_mont_p, in ossl_dh_compute_key()
79 dh->lock, dh->params.p, ctx); in ossl_dh_compute_key()
80 BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME); in ossl_dh_compute_key()
86 if (!dh->meth->bn_mod_exp(dh, z, pub_key, dh->priv_key, dh->params.p, ctx, in ossl_dh_compute_key()
93 if (BN_copy(pminus1, dh->params.p) == NULL in ossl_dh_compute_key()
102 ret = BN_bn2binpad(z, key, BN_num_bytes(dh->params.p)); in ossl_dh_compute_key()
114 int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) in DH_compute_key() argument
121 ret = ossl_dh_compute_key(key, pub_key, dh); in DH_compute_key()
123 ret = dh->meth->compute_key(key, pub_key, dh); in DH_compute_key()
144 int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh) in DH_compute_key_padded() argument
150 rv = ossl_dh_compute_key(key, pub_key, dh); in DH_compute_key_padded()
152 rv = dh->meth->compute_key(key, pub_key, dh); in DH_compute_key_padded()
156 pad = BN_num_bytes(dh->params.p) - rv; in DH_compute_key_padded()
189 static int dh_bn_mod_exp(const DH *dh, BIGNUM *r, in dh_bn_mod_exp() argument
200 static int dh_init(DH *dh) in dh_init() argument
202 dh->flags |= DH_FLAG_CACHE_MONT_P; in dh_init()
203 dh->dirty_cnt++; in dh_init()
207 static int dh_finish(DH *dh) in dh_finish() argument
209 BN_MONT_CTX_free(dh->method_mont_p); in dh_finish()
220 int DH_generate_key(DH *dh) in DH_generate_key() argument
223 return generate_key(dh); in DH_generate_key()
225 return dh->meth->generate_key(dh); in DH_generate_key()
229 int ossl_dh_generate_public_key(BN_CTX *ctx, const DH *dh, in ossl_dh_generate_public_key() argument
239 if (dh->flags & DH_FLAG_CACHE_MONT_P) { in ossl_dh_generate_public_key()
247 BN_MONT_CTX **pmont = (BN_MONT_CTX **)&dh->method_mont_p; in ossl_dh_generate_public_key()
249 mont = BN_MONT_CTX_set_locked(pmont, dh->lock, dh->params.p, ctx); in ossl_dh_generate_public_key()
256 if (!dh->meth->bn_mod_exp(dh, pub_key, dh->params.g, prk, dh->params.p, in ossl_dh_generate_public_key()
265 static int generate_key(DH *dh) in generate_key() argument
275 if (BN_num_bits(dh->params.p) > OPENSSL_DH_MAX_MODULUS_BITS) { in generate_key()
280 if (dh->params.q != NULL in generate_key()
281 && BN_num_bits(dh->params.q) > OPENSSL_DH_MAX_MODULUS_BITS) { in generate_key()
286 if (BN_num_bits(dh->params.p) < DH_MIN_MODULUS_BITS) { in generate_key()
291 ctx = BN_CTX_new_ex(dh->libctx); in generate_key()
295 if (dh->priv_key == NULL) { in generate_key()
301 priv_key = dh->priv_key; in generate_key()
304 if (dh->pub_key == NULL) { in generate_key()
309 pub_key = dh->pub_key; in generate_key()
313 if (DH_get_nid(dh) != NID_undef) { in generate_key()
315 ossl_ifc_ffc_compute_security_bits(BN_num_bits(dh->params.p)); in generate_key()
317 if (dh->params.q == NULL in generate_key()
318 || dh->length > BN_num_bits(dh->params.q)) in generate_key()
321 if (!ossl_ffc_generate_private_key(ctx, &dh->params, dh->length, in generate_key()
326 if (dh->params.q == NULL) in generate_key()
329 if (dh->params.q == NULL) { in generate_key()
331 if (dh->length != 0 in generate_key()
332 && dh->length >= BN_num_bits(dh->params.p)) in generate_key()
334 l = dh->length ? dh->length : BN_num_bits(dh->params.p) - 1; in generate_key()
342 if (BN_is_word(dh->params.g, DH_GENERATOR_2) in generate_key()
343 && !BN_is_bit_set(dh->params.p, 2)) { in generate_key()
352 if (!ossl_ffc_params_simple_validate(dh->libctx, &dh->params, in generate_key()
360 if (!ossl_ffc_generate_private_key(ctx, &dh->params, in generate_key()
361 BN_num_bits(dh->params.q), in generate_key()
369 if (!ossl_dh_generate_public_key(ctx, dh, priv_key, pub_key)) in generate_key()
372 dh->pub_key = pub_key; in generate_key()
373 dh->priv_key = priv_key; in generate_key()
374 dh->dirty_cnt++; in generate_key()
380 if (pub_key != dh->pub_key) in generate_key()
382 if (priv_key != dh->priv_key) in generate_key()
388 int ossl_dh_buf2key(DH *dh, const unsigned char *buf, size_t len) in ossl_dh_buf2key() argument
397 DH_get0_pqg(dh, &p, NULL, NULL); in ossl_dh_buf2key()
403 if (!ossl_dh_check_pub_key_partial(dh, pubkey, &ret)) { in ossl_dh_buf2key()
407 if (DH_set0_key(dh, pubkey, NULL) != 1) in ossl_dh_buf2key()
416 size_t ossl_dh_key2buf(const DH *dh, unsigned char **pbuf_out, size_t size, in ossl_dh_key2buf() argument
424 DH_get0_pqg(dh, &p, NULL, NULL); in ossl_dh_key2buf()
425 DH_get0_key(dh, &pubkey, NULL); in ossl_dh_key2buf()