3 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
7 static bool validate(
const ssl_dh& dh,
bool& valid ) {
10 return valid = !(check );
16 DH_generate_parameters_ex(dh.obj, s,
g, NULL);
17 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
19 DH_get0_pqg(dh.obj, &bn_p, NULL, NULL);
20 p.resize( BN_num_bytes( bn_p ) );
22 BN_bn2bin( bn_p, (
unsigned char*)&
p.front() );
24 p.resize( BN_num_bytes( dh->p ) );
26 BN_bn2bin( dh->p, (
unsigned char*)&
p.front() );
29 return fc::validate( dh,
valid );
37 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
38 const auto bn_p = BN_bin2bn( (
unsigned char*)&
p.front(),
p.size(), NULL );
39 const auto bn_g = BN_bin2bn( (
unsigned char*)&
g, 1, NULL );
40 DH_set0_pqg(dh.obj, bn_p, NULL, bn_g);
42 dh->p = BN_bin2bn( (
unsigned char*)&
p.front(),
p.size(), NULL );
43 dh->g = BN_bin2bn( (
unsigned char*)&
g, 1, NULL );
45 return fc::validate( dh,
valid );
53 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
54 const auto bn_p = BN_bin2bn( (
unsigned char*)&
p.front(),
p.size(), NULL );
55 const auto bn_g = BN_bin2bn( (
unsigned char*)&
g, 1, NULL );
56 DH_set0_pqg(dh.obj, bn_p, NULL, bn_g);
58 dh->p = BN_bin2bn( (
unsigned char*)&
p.front(),
p.size(), NULL );
59 dh->g = BN_bin2bn( (
unsigned char*)&
g, 1, NULL );
62 if( !fc::validate( dh,
valid ) )
68 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
71 DH_get0_key(dh.obj, &bn_pub_key, &bn_priv_key);
72 pub_key.resize( BN_num_bytes( bn_pub_key ) );
73 priv_key.resize( BN_num_bytes( bn_priv_key ) );
75 BN_bn2bin( bn_pub_key, (
unsigned char*)&
pub_key.front() );
77 BN_bn2bin( bn_priv_key, (
unsigned char*)&
priv_key.front() );
79 pub_key.resize( BN_num_bytes( dh->pub_key ) );
80 priv_key.resize( BN_num_bytes( dh->priv_key ) );
82 BN_bn2bin( dh->pub_key, (
unsigned char*)&
pub_key.front() );
84 BN_bn2bin( dh->priv_key, (
unsigned char*)&
priv_key.front() );
91 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
92 auto bn_p = BN_bin2bn( (
unsigned char*)&
p.front(),
p.size(), NULL );
93 auto bn_pub_key = BN_bin2bn( (
unsigned char*)&
pub_key.front(),
pub_key.size(), NULL );
94 auto bn_priv_key = BN_bin2bn( (
unsigned char*)&
priv_key.front(),
priv_key.size(), NULL );
95 auto bn_g = BN_bin2bn( (
unsigned char*)&
g, 1, NULL );
96 DH_set0_pqg(dh.obj, bn_p, NULL, bn_g);
97 DH_set0_key(dh.obj, bn_pub_key, bn_priv_key);
99 dh->p = BN_bin2bn( (
unsigned char*)&
p.front(),
p.size(), NULL );
100 dh->pub_key = BN_bin2bn( (
unsigned char*)&
pub_key.front(),
pub_key.size(), NULL );
101 dh->priv_key = BN_bin2bn( (
unsigned char*)&
priv_key.front(),
priv_key.size(), NULL );
102 dh->g = BN_bin2bn( (
unsigned char*)&
g, 1, NULL );
107 if( !fc::validate( dh,
valid ) )
113 BN_bin2bn( (
unsigned char*)buf, s, pk );
114 int est_size = DH_size(dh);
116 int actual_size = DH_compute_key( (
unsigned char*)&
shared_key.front(), pk, dh );
117 if ( actual_size < 0 )
return false;
118 if ( actual_size != est_size )