#include <dh.hpp>
Definition at line 8 of file dh.hpp.
◆ diffie_hellman()
fc::diffie_hellman::diffie_hellman |
( |
| ) |
|
|
inline |
Definition at line 9 of file dh.hpp.
◆ 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 {
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 );
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
std::vector< char > shared_key
std::vector< char > pub_key
◆ 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 {
89 }
bool compute_shared_key(const char *buf, uint32_t s)
◆ generate_params()
bool fc::diffie_hellman::generate_params |
( |
int | s, |
|
|
uint8_t | g ) |
Definition at line 13 of file dh.cpp.
14 {
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 ) );
21 BN_bn2bin( bn_p, (
unsigned char*)&
p.front() );
23 return fc::validate( dh, valid );
24 }
◆ generate_pub_key()
bool fc::diffie_hellman::generate_pub_key |
( |
| ) |
|
Definition at line 37 of file dh.cpp.
38 {
40 return valid = false;
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 ) );
58 BN_bn2bin( bn_pub_key.obj, (
unsigned char*)&
pub_key.front() );
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 {
29 return valid = false;
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 }
std::vector<char> fc::diffie_hellman::p |
◆ priv_key
std::vector<char> fc::diffie_hellman::priv_key |
◆ pub_key
std::vector<char> fc::diffie_hellman::pub_key |
◆ shared_key
std::vector<char> fc::diffie_hellman::shared_key |
◆ valid
bool fc::diffie_hellman::valid |
The documentation for this struct was generated from the following files:
- libraries/fc/include/fc/crypto/dh.hpp
- libraries/fc/src/crypto/dh.cpp