Lines Matching refs:dh

1 /* crypto/dh/dh_key.c */
63 #include <openssl/dh.h>
65 static int generate_key(DH *dh);
66 static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
67 static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
71 static int dh_init(DH *dh);
72 static int dh_finish(DH *dh);
74 int DH_generate_key(DH *dh)
77 if (FIPS_mode() && !(dh->meth->flags & DH_FLAG_FIPS_METHOD)
78 && !(dh->flags & DH_FLAG_NON_FIPS_ALLOW))
84 return dh->meth->generate_key(dh);
87 int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
90 if (FIPS_mode() && !(dh->meth->flags & DH_FLAG_FIPS_METHOD)
91 && !(dh->flags & DH_FLAG_NON_FIPS_ALLOW))
97 return dh->meth->compute_key(key, pub_key, dh);
117 static int generate_key(DH *dh)
129 if (dh->priv_key == NULL)
136 priv_key=dh->priv_key;
138 if (dh->pub_key == NULL)
144 pub_key=dh->pub_key;
147 if (dh->flags & DH_FLAG_CACHE_MONT_P)
149 mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,
150 CRYPTO_LOCK_DH, dh->p, ctx);
157 if (dh->q)
161 if (!BN_rand_range(priv_key, dh->q))
169 l = dh->length ? dh->length : BN_num_bits(dh->p)-1;
178 if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)
187 if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) goto err;
190 dh->pub_key=pub_key;
191 dh->priv_key=priv_key;
197 if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
198 if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
203 static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
211 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS)
222 if (dh->priv_key == NULL)
228 if (dh->flags & DH_FLAG_CACHE_MONT_P)
230 mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,
231 CRYPTO_LOCK_DH, dh->p, ctx);
232 if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)
235 BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME);
241 if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result)
247 if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key,dh->p,ctx,mont))
263 static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
271 if (a->top == 1 && ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) != 0))
281 static int dh_init(DH *dh)
283 dh->flags |= DH_FLAG_CACHE_MONT_P;
287 static int dh_finish(DH *dh)
289 if(dh->method_mont_p)
290 BN_MONT_CTX_free(dh->method_mont_p);