Lines Matching defs:dh
110 static FFBigNum dh_generate_key(FF_DH *dh)
114 num_bytes = bn_num_bytes(dh->p) - 1;
118 bn_new(dh->priv_key);
119 if (!dh->priv_key)
121 bn_random(dh->priv_key, num_bytes);
123 bn_new(dh->pub_key);
124 if (!dh->pub_key) {
125 bn_free(dh->priv_key);
129 bn_modexp(dh->pub_key, dh->g, dh->priv_key, dh->p);
131 return dh->pub_key;
134 static int dh_compute_key(FF_DH *dh, FFBigNum pub_key_bn,
140 num_bytes = bn_num_bytes(dh->p);
148 bn_modexp(k, pub_key_bn, dh->priv_key, dh->p);
156 void ff_dh_free(FF_DH *dh)
158 bn_free(dh->p);
159 bn_free(dh->g);
160 bn_free(dh->pub_key);
161 bn_free(dh->priv_key);
162 av_free(dh);
189 #define dh_generate_key(dh) DH_generate_key(dh)
190 #define dh_compute_key(dh, pub, len, secret) DH_compute_key(secret, pub, dh)
192 void ff_dh_free(FF_DH *dh)
194 DH_free(dh);
239 FF_DH *dh;
242 if (!(dh = dh_new()))
245 bn_new(dh->g);
246 if (!dh->g)
249 bn_hex2bn(dh->p, P1024, ret);
253 bn_set_word(dh->g, 2);
254 dh->length = key_len;
256 return dh;
259 ff_dh_free(dh);
264 int ff_dh_generate_public_key(FF_DH *dh)
271 if (!dh_generate_key(dh))
278 ret = dh_is_valid_public_key(dh->pub_key, dh->p, q1);
290 int ff_dh_write_public_key(FF_DH *dh, uint8_t *pub_key, int pub_key_len)
295 len = bn_num_bytes(dh->pub_key);
301 bn_bn2bin(dh->pub_key, pub_key + pub_key_len - len, len);
306 int ff_dh_compute_shared_secret_key(FF_DH *dh, const uint8_t *pub_key,
325 if ((ret = dh_is_valid_public_key(pub_key_bn, dh->p, q1)) < 0) {
327 } else if ((ret = dh_compute_key(dh, pub_key_bn, pub_key_len,