Lines Matching refs:dh

76   DH *dh = OPENSSL_malloc(sizeof(DH));  in DH_new()  local
77 if (dh == NULL) { in DH_new()
82 OPENSSL_memset(dh, 0, sizeof(DH)); in DH_new()
84 CRYPTO_MUTEX_init(&dh->method_mont_p_lock); in DH_new()
86 dh->references = 1; in DH_new()
87 CRYPTO_new_ex_data(&dh->ex_data); in DH_new()
89 return dh; in DH_new()
92 void DH_free(DH *dh) { in DH_free() argument
93 if (dh == NULL) { in DH_free()
97 if (!CRYPTO_refcount_dec_and_test_zero(&dh->references)) { in DH_free()
101 CRYPTO_free_ex_data(&g_ex_data_class, dh, &dh->ex_data); in DH_free()
103 BN_MONT_CTX_free(dh->method_mont_p); in DH_free()
104 BN_clear_free(dh->p); in DH_free()
105 BN_clear_free(dh->g); in DH_free()
106 BN_clear_free(dh->q); in DH_free()
107 BN_clear_free(dh->j); in DH_free()
108 OPENSSL_free(dh->seed); in DH_free()
109 BN_clear_free(dh->counter); in DH_free()
110 BN_clear_free(dh->pub_key); in DH_free()
111 BN_clear_free(dh->priv_key); in DH_free()
112 CRYPTO_MUTEX_cleanup(&dh->method_mont_p_lock); in DH_free()
114 OPENSSL_free(dh); in DH_free()
117 void DH_get0_key(const DH *dh, const BIGNUM **out_pub_key, in DH_get0_key() argument
120 *out_pub_key = dh->pub_key; in DH_get0_key()
123 *out_priv_key = dh->priv_key; in DH_get0_key()
127 int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key) { in DH_set0_key() argument
129 BN_free(dh->pub_key); in DH_set0_key()
130 dh->pub_key = pub_key; in DH_set0_key()
134 BN_free(dh->priv_key); in DH_set0_key()
135 dh->priv_key = priv_key; in DH_set0_key()
141 void DH_get0_pqg(const DH *dh, const BIGNUM **out_p, const BIGNUM **out_q, in DH_get0_pqg() argument
144 *out_p = dh->p; in DH_get0_pqg()
147 *out_q = dh->q; in DH_get0_pqg()
150 *out_g = dh->g; in DH_get0_pqg()
154 int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g) { in DH_set0_pqg() argument
155 if ((dh->p == NULL && p == NULL) || in DH_set0_pqg()
156 (dh->g == NULL && g == NULL)) { in DH_set0_pqg()
161 BN_free(dh->p); in DH_set0_pqg()
162 dh->p = p; in DH_set0_pqg()
166 BN_free(dh->q); in DH_set0_pqg()
167 dh->q = q; in DH_set0_pqg()
171 BN_free(dh->g); in DH_set0_pqg()
172 dh->g = g; in DH_set0_pqg()
178 int DH_generate_parameters_ex(DH *dh, int prime_bits, int generator, BN_GENCB *cb) { in DH_generate_parameters_ex() argument
220 if (dh->p == NULL) { in DH_generate_parameters_ex()
221 dh->p = BN_new(); in DH_generate_parameters_ex()
222 if (dh->p == NULL) { in DH_generate_parameters_ex()
226 if (dh->g == NULL) { in DH_generate_parameters_ex()
227 dh->g = BN_new(); in DH_generate_parameters_ex()
228 if (dh->g == NULL) { in DH_generate_parameters_ex()
269 if (!BN_generate_prime_ex(dh->p, prime_bits, 1, t1, t2, cb)) { in DH_generate_parameters_ex()
275 if (!BN_set_word(dh->g, g)) { in DH_generate_parameters_ex()
292 int DH_generate_key(DH *dh) { in DH_generate_key() argument
298 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { in DH_generate_key()
308 if (dh->priv_key == NULL) { in DH_generate_key()
315 priv_key = dh->priv_key; in DH_generate_key()
318 if (dh->pub_key == NULL) { in DH_generate_key()
324 pub_key = dh->pub_key; in DH_generate_key()
327 if (!BN_MONT_CTX_set_locked(&dh->method_mont_p, &dh->method_mont_p_lock, in DH_generate_key()
328 dh->p, ctx)) { in DH_generate_key()
333 if (dh->q) { in DH_generate_key()
334 if (!BN_rand_range_ex(priv_key, 2, dh->q)) { in DH_generate_key()
339 unsigned priv_bits = dh->priv_length; in DH_generate_key()
341 const unsigned p_bits = BN_num_bits(dh->p); in DH_generate_key()
355 if (!BN_mod_exp_mont_consttime(pub_key, dh->g, priv_key, dh->p, ctx, in DH_generate_key()
356 dh->method_mont_p)) { in DH_generate_key()
360 dh->pub_key = pub_key; in DH_generate_key()
361 dh->priv_key = priv_key; in DH_generate_key()
369 if (dh->pub_key == NULL) { in DH_generate_key()
372 if (dh->priv_key == NULL) { in DH_generate_key()
379 int DH_compute_key(unsigned char *out, const BIGNUM *peers_key, DH *dh) { in DH_compute_key() argument
385 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { in DH_compute_key()
400 if (dh->priv_key == NULL) { in DH_compute_key()
405 if (!BN_MONT_CTX_set_locked(&dh->method_mont_p, &dh->method_mont_p_lock, in DH_compute_key()
406 dh->p, ctx)) { in DH_compute_key()
410 if (!DH_check_pub_key(dh, peers_key, &check_result) || check_result) { in DH_compute_key()
415 if (!BN_mod_exp_mont_consttime(shared_key, peers_key, dh->priv_key, dh->p, in DH_compute_key()
416 ctx, dh->method_mont_p)) { in DH_compute_key()
432 int DH_size(const DH *dh) { return BN_num_bytes(dh->p); } in DH_size() argument
434 unsigned DH_num_bits(const DH *dh) { return BN_num_bits(dh->p); } in DH_num_bits() argument
436 int DH_up_ref(DH *dh) { in DH_up_ref() argument
437 CRYPTO_refcount_inc(&dh->references); in DH_up_ref()
489 DH *DHparams_dup(const DH *dh) { in DHparams_dup() argument
495 if (!int_dh_param_copy(ret, dh, -1)) { in DHparams_dup()