Lines Matching refs:dh

57 #include <openssl/dh.h>
79 DH *dh = (DH *)OPENSSL_malloc(sizeof(DH));
80 if (dh == NULL) {
85 memset(dh, 0, sizeof(DH));
88 dh->meth = ENGINE_get_DH_method(engine);
91 if (dh->meth == NULL) {
92 dh->meth = (DH_METHOD*) &DH_default_method;
94 METHOD_ref(dh->meth);
96 CRYPTO_MUTEX_init(&dh->method_mont_p_lock);
98 dh->references = 1;
99 if (!CRYPTO_new_ex_data(&g_ex_data_class, dh, &dh->ex_data)) {
100 OPENSSL_free(dh);
104 if (dh->meth->init && !dh->meth->init(dh)) {
105 CRYPTO_free_ex_data(&g_ex_data_class, dh, &dh->ex_data);
106 METHOD_unref(dh->meth);
107 OPENSSL_free(dh);
111 return dh;
114 void DH_free(DH *dh) {
115 if (dh == NULL) {
119 if (!CRYPTO_refcount_dec_and_test_zero(&dh->references)) {
123 if (dh->meth->finish) {
124 dh->meth->finish(dh);
126 METHOD_unref(dh->meth);
128 CRYPTO_free_ex_data(&g_ex_data_class, dh, &dh->ex_data);
130 if (dh->method_mont_p) BN_MONT_CTX_free(dh->method_mont_p);
131 if (dh->p != NULL) BN_clear_free(dh->p);
132 if (dh->g != NULL) BN_clear_free(dh->g);
133 if (dh->q != NULL) BN_clear_free(dh->q);
134 if (dh->j != NULL) BN_clear_free(dh->j);
135 if (dh->seed) OPENSSL_free(dh->seed);
136 if (dh->counter != NULL) BN_clear_free(dh->counter);
137 if (dh->pub_key != NULL) BN_clear_free(dh->pub_key);
138 if (dh->priv_key != NULL) BN_clear_free(dh->priv_key);
139 CRYPTO_MUTEX_cleanup(&dh->method_mont_p_lock);
141 OPENSSL_free(dh);
144 int DH_generate_parameters_ex(DH *dh, int prime_bits, int generator, BN_GENCB *cb) {
145 if (dh->meth->generate_parameters) {
146 return dh->meth->generate_parameters(dh, prime_bits, generator, cb);
148 return DH_default_method.generate_parameters(dh, prime_bits, generator, cb);
151 int DH_generate_key(DH *dh) {
152 if (dh->meth->generate_key) {
153 return dh->meth->generate_key(dh);
155 return DH_default_method.generate_key(dh);
158 int DH_compute_key(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
159 if (dh->meth->compute_key) {
160 return dh->meth->compute_key(dh, out, peers_key);
162 return DH_default_method.compute_key(dh, out, peers_key);
165 int DH_size(const DH *dh) { return BN_num_bytes(dh->p); }
167 unsigned DH_num_bits(const DH *dh) { return BN_num_bits(dh->p); }
169 int DH_up_ref(DH *dh) {
170 CRYPTO_refcount_inc(&dh->references);
222 DH *DHparams_dup(const DH *dh) {
228 if (!int_dh_param_copy(ret, dh, -1)) {