Lines Matching defs: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,
70 static int dh_init(DH *dh);
71 static int dh_finish(DH *dh);
73 int DH_generate_key(DH *dh)
76 if (FIPS_mode() && !(dh->meth->flags & DH_FLAG_FIPS_METHOD)
77 && !(dh->flags & DH_FLAG_NON_FIPS_ALLOW)) {
82 return dh->meth->generate_key(dh);
85 int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
88 if (FIPS_mode() && !(dh->meth->flags & DH_FLAG_FIPS_METHOD)
89 && !(dh->flags & DH_FLAG_NON_FIPS_ALLOW)) {
94 return dh->meth->compute_key(key, pub_key, dh);
114 static int generate_key(DH *dh)
127 if (dh->priv_key == NULL) {
133 priv_key = dh->priv_key;
135 if (dh->pub_key == NULL) {
140 pub_key = dh->pub_key;
142 if (dh->flags & DH_FLAG_CACHE_MONT_P) {
143 mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,
144 CRYPTO_LOCK_DH, dh->p, ctx);
150 if (dh->q) {
152 if (!BN_rand_range(priv_key, dh->q))
158 l = dh->length ? dh->length : BN_num_bits(dh->p) - 1;
168 if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) {
175 if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont))
179 dh->pub_key = pub_key;
180 dh->priv_key = priv_key;
186 if ((pub_key != NULL) && (dh->pub_key == NULL))
188 if ((priv_key != NULL) && (dh->priv_key == NULL))
194 static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
202 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
213 if (dh->priv_key == NULL) {
218 if (dh->flags & DH_FLAG_CACHE_MONT_P) {
219 mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,
220 CRYPTO_LOCK_DH, dh->p, ctx);
221 if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) {
223 BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME);
229 if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result) {
234 if (!dh->
235 meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key, dh->p, ctx, mont)) {
249 static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
257 if (a->top == 1 && ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) != 0)) {
264 static int dh_init(DH *dh)
266 dh->flags |= DH_FLAG_CACHE_MONT_P;
270 static int dh_finish(DH *dh)
272 if (dh->method_mont_p)
273 BN_MONT_CTX_free(dh->method_mont_p);