Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::ecc::private_key Class Reference

an elliptic curve private key. More...

#include <elliptic.hpp>

Public Member Functions

 private_key ()
 
 private_key (private_key &&pk)
 
 private_key (const private_key &pk)
 
 ~private_key ()
 
private_keyoperator= (private_key &&pk)
 
private_keyoperator= (const private_key &pk)
 
private_key child (const fc::sha256 &offset) const
 
private_key_secret get_secret () const
 
 operator private_key_secret () const
 
fc::sha512 get_shared_secret (const public_key &pub) const
 
compact_signature sign_compact (const fc::sha256 &digest, bool require_canonical=true) const
 
public_key get_public_key () const
 
unsigned int fingerprint () const
 

Static Public Member Functions

static private_key generate ()
 
static private_key regenerate (const fc::sha256 &secret)
 
static private_key generate_from_seed (const fc::sha256 &seed, const fc::sha256 &offset=fc::sha256())
 

Friends

bool operator== (const private_key &a, const private_key &b)
 
bool operator!= (const private_key &a, const private_key &b)
 
bool operator< (const private_key &a, const private_key &b)
 

Detailed Description

Definition at line 87 of file elliptic.hpp.

Constructor & Destructor Documentation

◆ private_key() [1/3]

fc::ecc::private_key::private_key ( )

Definition at line 33 of file elliptic_impl_priv.cpp.

33{}
Here is the caller graph for this function:

◆ private_key() [2/3]

fc::ecc::private_key::private_key ( private_key && pk)

Definition at line 37 of file elliptic_impl_priv.cpp.

37: my( std::move( pk.my ) ) {}

◆ private_key() [3/3]

fc::ecc::private_key::private_key ( const private_key & pk)

Definition at line 35 of file elliptic_impl_priv.cpp.

35: my( pk.my ) {}

◆ ~private_key()

fc::ecc::private_key::~private_key ( )

Definition at line 39 of file elliptic_impl_priv.cpp.

39{}

Member Function Documentation

◆ child()

private_key fc::ecc::private_key::child ( const fc::sha256 & offset) const

Definition at line 113 of file elliptic_common.cpp.

114 {
117 fc::raw::pack( enc, offset );
118 return generate_from_seed( get_secret(), enc.result() );
119 }
public_key get_public_key() const
private_key_secret get_secret() const
static private_key generate_from_seed(const fc::sha256 &seed, const fc::sha256 &offset=fc::sha256())
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
Here is the call graph for this function:

◆ fingerprint()

unsigned int fc::ecc::private_key::fingerprint ( ) const
inline

Definition at line 139 of file elliptic.hpp.

139{ return get_public_key().fingerprint(); }
unsigned int fingerprint() const
Here is the call graph for this function:

◆ generate()

private_key fc::ecc::private_key::generate ( )
static

Definition at line 200 of file elliptic_common.cpp.

201 {
202 EC_KEY* k = EC_KEY_new_by_curve_name( NID_secp256k1 );
203 if( !k ) FC_THROW_EXCEPTION( exception, "Unable to generate EC key" );
204 if( !EC_KEY_generate_key( k ) )
205 {
206 FC_THROW_EXCEPTION( exception, "ecc key generation error" );
207
208 }
209
210 return private_key( k );
211 }
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_from_seed()

private_key fc::ecc::private_key::generate_from_seed ( const fc::sha256 & seed,
const fc::sha256 & offset = fc::sha256() )
static

This method of generation enables creating a new private key in a deterministic manner relative to an initial seed. A public_key created from the seed can be multiplied by the offset to calculate the new public key without having to know the private key.

Definition at line 159 of file elliptic_common.cpp.

160 {
161 ssl_bignum z;
162 BN_bin2bn((unsigned char*)&offset, sizeof(offset), z);
163
164 ec_group group(EC_GROUP_new_by_curve_name(NID_secp256k1));
165 bn_ctx ctx(BN_CTX_new());
166 ssl_bignum order;
167 EC_GROUP_get_order(group, order, ctx);
168
169 // secexp = (seed + z) % order
170 ssl_bignum secexp;
171 BN_bin2bn((unsigned char*)&seed, sizeof(seed), secexp);
172 BN_add(secexp, secexp, z);
173 BN_mod(secexp, secexp, order, ctx);
174
175 fc::sha256 secret;
176 FC_ASSERT(BN_num_bytes(secexp) <= int64_t(sizeof(secret)));
177 auto shift = sizeof(secret) - BN_num_bytes(secexp);
178 BN_bn2bin(secexp, ((unsigned char*)&secret)+shift);
179 return regenerate( secret );
180 }
static private_key regenerate(const fc::sha256 &secret)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
signed __int64 int64_t
Definition stdint.h:135
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_public_key()

public_key fc::ecc::private_key::get_public_key ( ) const

Definition at line 71 of file elliptic_impl_priv.cpp.

72 {
73 FC_ASSERT( my->_key != empty_priv );
75 size_t pub_len = sizeof(pub);
76 secp256k1_pubkey secp_pub;
77 FC_ASSERT( secp256k1_ec_pubkey_create( detail::_get_context(), &secp_pub, (unsigned char*) my->_key.data() ) );
78 secp256k1_ec_pubkey_serialize( detail::_get_context(), (unsigned char*)&pub, &pub_len, &secp_pub, SECP256K1_EC_COMPRESSED );
79 FC_ASSERT( pub_len == pub.size() );
80 return public_key(pub);
81 }
const secp256k1_context * _get_context()
fc::array< char, 33 > public_key_data
Definition elliptic.hpp:22
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition secp256k1.c:246
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Definition secp256k1.c:551
#define SECP256K1_EC_COMPRESSED
Definition secp256k1.h:201
bool pub
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_secret()

fc::sha256 fc::ecc::private_key::get_secret ( ) const

Definition at line 60 of file elliptic_impl_priv.cpp.

61 {
62 return my->_key;
63 }
Here is the caller graph for this function:

◆ get_shared_secret()

fc::sha512 fc::ecc::private_key::get_shared_secret ( const public_key & pub) const

Given a public key, calculatse a 512 bit shared secret between that key and this private key.

Definition at line 29 of file elliptic_mixed.cpp.

30 {
31 FC_ASSERT( my->_key != empty_priv );
32 FC_ASSERT( other.my->_key != nullptr );
33 public_key_data pub(other.serialize());
34 FC_ASSERT( secp256k1_ec_pubkey_tweak_mul( detail::_get_context(), (unsigned char*) pub.begin(), pub.size(), (unsigned char*) my->_key.data() ) );
35 return fc::sha512::hash( pub.begin() + 1, pub.size() - 1 );
36 }
static sha512 hash(const char *d, uint32_t dlen)
Definition sha512.cpp:37
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Definition secp256k1.c:683
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator private_key_secret()

fc::ecc::private_key::operator private_key_secret ( ) const
inline

Definition at line 112 of file elliptic.hpp.

112{ return get_secret(); }
Here is the call graph for this function:

◆ operator=() [1/2]

private_key & fc::ecc::private_key::operator= ( const private_key & pk)

Definition at line 47 of file elliptic_impl_priv.cpp.

48 {
49 my = pk.my;
50 return *this;
51 }

◆ operator=() [2/2]

private_key & fc::ecc::private_key::operator= ( private_key && pk)

Definition at line 41 of file elliptic_impl_priv.cpp.

42 {
43 my = std::move( pk.my );
44 return *this;
45 }

◆ regenerate()

private_key fc::ecc::private_key::regenerate ( const fc::sha256 & secret)
static

Definition at line 53 of file elliptic_impl_priv.cpp.

54 {
56 self.my->_key = secret;
57 return self;
58 }
@ self
the connection is to itself
Definition protocol.hpp:48
Here is the caller graph for this function:

◆ sign_compact()

compact_signature fc::ecc::private_key::sign_compact ( const fc::sha256 & digest,
bool require_canonical = true ) const

Definition at line 91 of file elliptic_impl_priv.cpp.

92 {
93 FC_ASSERT( my->_key != empty_priv );
94 compact_signature result;
96 int recid;
97 unsigned int counter = 0;
98 do
99 {
100 FC_ASSERT( secp256k1_ecdsa_sign_recoverable( detail::_get_context(), &secp_sig, (unsigned char*) digest.data(), (unsigned char*) my->_key.data(), extended_nonce_function, &counter ));
102 } while( require_canonical && !public_key::is_canonical( result ) );
103
104 result.begin()[0] = 27 + 4 + recid;
105 return result;
106 }
const char * data() const
Definition sha256.cpp:31
fc::array< unsigned char, 65 > compact_signature
Definition elliptic.hpp:26
fc::sha256 digest(const T &value)
Definition digest.hpp:9
SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(const secp256k1_context *ctx, unsigned char *output64, int *recid, const secp256k1_ecdsa_recoverable_signature *sig) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition main_impl.h:60
SECP256K1_API int secp256k1_ecdsa_sign_recoverable(const secp256k1_context *ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msghash32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition main_impl.h:123
Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const private_key & a,
const private_key & b )
friend

Definition at line 130 of file elliptic.hpp.

131 {
132 return a.get_secret() != b.get_secret();
133 }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181

◆ operator<

bool operator< ( const private_key & a,
const private_key & b )
friend

Definition at line 134 of file elliptic.hpp.

135 {
136 return a.get_secret() < b.get_secret();
137 }

◆ operator==

bool operator== ( const private_key & a,
const private_key & b )
friend

Definition at line 126 of file elliptic.hpp.

127 {
128 return a.get_secret() == b.get_secret();
129 }

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