Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::diffie_hellman Struct Reference

#include <dh.hpp>

Public Member Functions

 diffie_hellman ()
 
bool generate_params (int s, uint8_t g)
 
bool generate_pub_key ()
 
bool compute_shared_key (const char *buf, uint32_t s)
 
bool compute_shared_key (const std::vector< char > &pubk)
 
bool validate ()
 

Public Attributes

std::vector< char > p
 
std::vector< char > pub_key
 
std::vector< char > priv_key
 
std::vector< char > shared_key
 
bool valid
 
uint8_t g
 

Detailed Description

Definition at line 8 of file dh.hpp.

Constructor & Destructor Documentation

◆ diffie_hellman()

fc::diffie_hellman::diffie_hellman ( )
inline

Definition at line 9 of file dh.hpp.

9:valid(0),g(5){}
uint8_t g
Definition dh.hpp:21

Member Function Documentation

◆ compute_shared_key() [1/2]

bool fc::diffie_hellman::compute_shared_key ( const char * buf,
uint32_t s )

Definition at line 64 of file dh.cpp.

64 {
65 ssl_dh dh = DH_new();
66 auto bn_p = BN_bin2bn( (unsigned char*)&p.front(), p.size(), NULL );
67 auto bn_pub_key = BN_bin2bn( (unsigned char*)&pub_key.front(), pub_key.size(), NULL );
68 auto bn_priv_key = BN_bin2bn( (unsigned char*)&priv_key.front(), priv_key.size(), NULL );
69 auto bn_g = BN_bin2bn( (unsigned char*)&g, 1, NULL );
70 DH_set0_pqg(dh.obj, bn_p, NULL, bn_g);
71 DH_set0_key(dh.obj, bn_pub_key, bn_priv_key);
72
73 int check;
74 DH_check(dh,&check);
75 if( !fc::validate( dh, valid ) )
76 {
77 return false;
78 }
79
80 ssl_bignum pk;
81 BN_bin2bn( (unsigned char*)buf, s, pk );
82 shared_key.resize( DH_size(dh) );
83 DH_compute_key( (unsigned char*)&shared_key.front(), pk, dh );
84
85 return true;
86 }
static const Reg8 dh(Operand::DH)
std::vector< char > priv_key
Definition dh.hpp:18
std::vector< char > p
Definition dh.hpp:16
std::vector< char > shared_key
Definition dh.hpp:19
std::vector< char > pub_key
Definition dh.hpp:17
char * s
uint8_t buf[2048]
Here is the caller graph for this function:

◆ compute_shared_key() [2/2]

bool fc::diffie_hellman::compute_shared_key ( const std::vector< char > & pubk)

Definition at line 87 of file dh.cpp.

87 {
88 return compute_shared_key( &pubk.front(), pubk.size() );
89 }
bool compute_shared_key(const char *buf, uint32_t s)
Definition dh.cpp:64
Here is the call graph for this function:

◆ generate_params()

bool fc::diffie_hellman::generate_params ( int s,
uint8_t g )

Definition at line 13 of file dh.cpp.

14 {
15 ssl_dh dh;
16 DH_generate_parameters_ex(dh.obj, s, g, NULL);
17 ssl_bignum bn_p;
18 DH_get0_pqg(dh.obj, (const BIGNUM**)&bn_p.obj, NULL, NULL);
19 p.resize( BN_num_bytes( bn_p ) );
20 if( p.size() )
21 BN_bn2bin( bn_p, (unsigned char*)&p.front() );
22 this->g = g;
23 return fc::validate( dh, valid );
24 }
bignum_st BIGNUM
Definition bigint.hpp:7

◆ generate_pub_key()

bool fc::diffie_hellman::generate_pub_key ( )

Definition at line 37 of file dh.cpp.

38 {
39 if( !p.size() )
40 return valid = false;
41 ssl_dh dh = DH_new();
42 const auto bn_p = BN_bin2bn( (unsigned char*)&p.front(), p.size(), NULL );
43 const auto bn_g = BN_bin2bn( (unsigned char*)&g, 1, NULL );
44 DH_set0_pqg(dh.obj, bn_p, NULL, bn_g);
45
46 if( !fc::validate( dh, valid ) )
47 {
48 return false;
49 }
50 DH_generate_key(dh);
51
52 ssl_bignum bn_pub_key;
53 ssl_bignum bn_priv_key;
54 DH_get0_key(dh.obj, (const BIGNUM**)&bn_pub_key.obj, (const BIGNUM**)&bn_priv_key.obj);
55 pub_key.resize( BN_num_bytes( bn_pub_key ) );
56 priv_key.resize( BN_num_bytes( bn_priv_key ) );
57 if( pub_key.size() )
58 BN_bn2bin( bn_pub_key.obj, (unsigned char*)&pub_key.front() );
59 if( priv_key.size() )
60 BN_bn2bin( bn_priv_key.obj, (unsigned char*)&priv_key.front() );
61
62 return true;
63 }

◆ validate()

bool fc::diffie_hellman::validate ( )

Definition at line 26 of file dh.cpp.

27 {
28 if( !p.size() )
29 return valid = false;
30 ssl_dh dh = DH_new();
31 const auto bn_p = BN_bin2bn( (unsigned char*)&p.front(), p.size(), NULL );
32 const auto bn_g = BN_bin2bn( (unsigned char*)&g, 1, NULL );
33 DH_set0_pqg(dh.obj, bn_p, NULL, bn_g);
34 return fc::validate( dh, valid );
35 }

Member Data Documentation

◆ g

uint8_t fc::diffie_hellman::g

Definition at line 21 of file dh.hpp.

◆ p

std::vector<char> fc::diffie_hellman::p

Definition at line 16 of file dh.hpp.

◆ priv_key

std::vector<char> fc::diffie_hellman::priv_key

Definition at line 18 of file dh.hpp.

◆ pub_key

std::vector<char> fc::diffie_hellman::pub_key

Definition at line 17 of file dh.hpp.

◆ shared_key

std::vector<char> fc::diffie_hellman::shared_key

Definition at line 19 of file dh.hpp.

◆ valid

bool fc::diffie_hellman::valid

Definition at line 20 of file dh.hpp.


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