OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | List of all members
OpenDDS::Security::SSL::DH_2048_MODP_256_PRIME Class Reference

#include <DiffieHellman.h>

Inheritance diagram for OpenDDS::Security::SSL::DH_2048_MODP_256_PRIME:
Inheritance graph
[legend]
Collaboration diagram for OpenDDS::Security::SSL::DH_2048_MODP_256_PRIME:
Collaboration graph
[legend]

Public Member Functions

 DH_2048_MODP_256_PRIME ()
 
 ~DH_2048_MODP_256_PRIME ()
 
int init ()
 
int pub_key (DDS::OctetSeq &dst)
 
int compute_shared_secret (const DDS::OctetSeq &pub_key)
 
const char * kagree_algo () const
 
- Public Member Functions inherited from OpenDDS::Security::SSL::DHAlgorithm
 DHAlgorithm ()
 
virtual ~DHAlgorithm ()
 
virtual int gen_shared_secret (const DDS::OctetSeq &pub_key)
 
virtual const DDS::OctetSeqget_shared_secret () const
 
virtual bool cmp_shared_secret (const DHAlgorithm &other) const
 

Additional Inherited Members

- Public Types inherited from OpenDDS::Security::SSL::DHAlgorithm
typedef DCPS::unique_ptr< DHAlgorithmunique_ptr
 
- Protected Member Functions inherited from OpenDDS::Security::SSL::DHAlgorithm
int hash_shared_secret ()
 
- Protected Attributes inherited from OpenDDS::Security::SSL::DHAlgorithm
EVP_PKEYk_
 
DDS::OctetSeq shared_secret_
 

Detailed Description

Definition at line 57 of file DiffieHellman.h.

Constructor & Destructor Documentation

◆ DH_2048_MODP_256_PRIME()

OpenDDS::Security::SSL::DH_2048_MODP_256_PRIME::DH_2048_MODP_256_PRIME ( )

Definition at line 76 of file DiffieHellman.cpp.

References init().

◆ ~DH_2048_MODP_256_PRIME()

OpenDDS::Security::SSL::DH_2048_MODP_256_PRIME::~DH_2048_MODP_256_PRIME ( )

Definition at line 78 of file DiffieHellman.cpp.

78 {}

Member Function Documentation

◆ compute_shared_secret()

int OpenDDS::Security::SSL::DH_2048_MODP_256_PRIME::compute_shared_secret ( const DDS::OctetSeq pub_key)
virtual
Returns
int 0 on success; 1 on failure.

Implements OpenDDS::Security::SSL::DHAlgorithm.

Definition at line 334 of file DiffieHellman.cpp.

335 {
336  dh_shared_secret secret(k_);
337  return secret(pub_key, shared_secret_);
338 }

◆ init()

int OpenDDS::Security::SSL::DH_2048_MODP_256_PRIME::init ( void  )
virtual
Returns
int 0 on success; 1 on failure.

Implements OpenDDS::Security::SSL::DHAlgorithm.

Definition at line 150 of file DiffieHellman.cpp.

References OpenDDS::Security::SSL::dh_constructor::get_key().

151 {
152  if (k_) return 0;
153 
154  dh_constructor dh;
155  k_ = dh.get_key();
156  return k_ ? 0 : 1;
157 }

◆ kagree_algo()

const char* OpenDDS::Security::SSL::DH_2048_MODP_256_PRIME::kagree_algo ( ) const
inlinevirtual

◆ pub_key()

int OpenDDS::Security::SSL::DH_2048_MODP_256_PRIME::pub_key ( DDS::OctetSeq dst)
virtual
Returns
int 0 on success; 1 on failure.

Implements OpenDDS::Security::SSL::DHAlgorithm.

Definition at line 159 of file DiffieHellman.cpp.

References DH_get0_key(), and OPENDDS_SSL_LOG_ERR.

160 {
161  int result = 1;
162 
163  if (k_) {
164 #ifndef OPENSSL_V_3_0
165  DH_Handle dh(k_);
166  if (dh) {
167  const BIGNUM *pubkey = 0, *privkey = 0;
168  DH_get0_key(dh, &pubkey, &privkey);
169  if (pubkey) {
170  dst.length(BN_num_bytes(pubkey));
171  if (0 < BN_bn2bin(pubkey, dst.get_buffer())) {
172  result = 0;
173  } else {
174  OPENDDS_SSL_LOG_ERR("BN_bn2bin failed");
175  }
176  } else {
177  OPENDDS_SSL_LOG_ERR("DH_get0_key failed");
178  }
179  }
180 #else
181  BIGNUM* pubkey = 0;
182  if (EVP_PKEY_get_bn_param(k_, OSSL_PKEY_PARAM_PUB_KEY, &pubkey)) {
183  dst.length(BN_num_bytes(pubkey));
184  if (0 < BN_bn2bin(pubkey, dst.get_buffer())) {
185  result = 0;
186  } else {
187  OPENDDS_SSL_LOG_ERR("BN_bn2bin failed");
188  }
189  } else {
190  OPENDDS_SSL_LOG_ERR("EVP_PKEY_get_bn_param failed");
191  }
192  BN_free(pubkey);
193 #endif
194  }
195  return result;
196 }
void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
#define OPENDDS_SSL_LOG_ERR(MSG)
Definition: Err.h:12

The documentation for this class was generated from the following files: