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

contains only the public point of an elliptic curve key. More...

#include <elliptic.hpp>

Public Member Functions

 public_key ()
 
 public_key (const public_key &k)
 
 ~public_key ()
 
public_key_data serialize () const
 
public_key_point_data serialize_ecc_point () const
 
 operator public_key_data () const
 
 public_key (const public_key_data &v)
 
 public_key (const public_key_point_data &v)
 
 public_key (const compact_signature &c, const fc::sha256 &digest, bool check_canonical=true)
 
public_key child (const fc::sha256 &offset) const
 
bool valid () const
 
 public_key (public_key &&pk)
 
public_keyoperator= (public_key &&pk)
 
public_keyoperator= (const public_key &pk)
 
std::string to_base58 () const
 Allows to convert current public key object into base58 number.
 
unsigned int fingerprint () const
 

Static Public Member Functions

static std::string to_base58 (const public_key_data &key)
 
static public_key from_base58 (const std::string &b58)
 

Friends

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

Detailed Description

Definition at line 35 of file elliptic.hpp.

Constructor & Destructor Documentation

◆ public_key() [1/6]

fc::ecc::public_key::public_key ( )

Definition at line 142 of file elliptic_impl_pub.cpp.

142{}

◆ public_key() [2/6]

fc::ecc::public_key::public_key ( const public_key & k)

Definition at line 144 of file elliptic_impl_pub.cpp.

144: my( pk.my ) {}

◆ ~public_key()

fc::ecc::public_key::~public_key ( )

Definition at line 148 of file elliptic_impl_pub.cpp.

148{}

◆ public_key() [3/6]

fc::ecc::public_key::public_key ( const public_key_data & v)

Definition at line 306 of file elliptic_impl_pub.cpp.

307 {
308 const char* front = &dat.data[0];
309 if( *front == 0 ){}
310 else
311 {
312 my->_key = EC_KEY_new_by_curve_name( NID_secp256k1 );
313 my->_key = o2i_ECPublicKey( &my->_key, (const unsigned char**)&front, sizeof(public_key_data) );
314 if( !my->_key )
315 {
316 FC_THROW_EXCEPTION( exception, "error decoding public key", ("s", ERR_error_string( ERR_get_error(), nullptr) ) );
317 }
318 }
319 }
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
fc::array< char, 33 > public_key_data
Definition elliptic.hpp:22

◆ public_key() [4/6]

fc::ecc::public_key::public_key ( const public_key_point_data & v)

Definition at line 292 of file elliptic_impl_pub.cpp.

293 {
294 const char* front = &dat.data[0];
295 if( *front == 0 ){}
296 else
297 {
298 my->_key = EC_KEY_new_by_curve_name( NID_secp256k1 );
299 my->_key = o2i_ECPublicKey( &my->_key, (const unsigned char**)&front, sizeof(dat) );
300 if( !my->_key )
301 {
302 FC_THROW_EXCEPTION( exception, "error decoding public key", ("s", ERR_error_string( ERR_get_error(), nullptr) ) );
303 }
304 }
305 }

◆ public_key() [5/6]

fc::ecc::public_key::public_key ( const compact_signature & c,
const fc::sha256 & digest,
bool check_canonical = true )

Definition at line 326 of file elliptic_impl_pub.cpp.

327 {
328 int nV = c.data[0];
329 if (nV<27 || nV>=35)
330 FC_THROW_EXCEPTION( exception, "unable to reconstruct public key from signature" );
331
332 ECDSA_SIG *sig = ECDSA_SIG_new();
333 BN_bin2bn(&c.data[1],32,sig->r);
334 BN_bin2bn(&c.data[33],32,sig->s);
335
336 if( check_canonical )
337 {
338 FC_ASSERT( is_canonical( c ), "signature is not canonical" );
339 }
340
341 my->_key = EC_KEY_new_by_curve_name(NID_secp256k1);
342
343 if (nV >= 31)
344 {
345 EC_KEY_set_conv_form( my->_key, POINT_CONVERSION_COMPRESSED );
346 nV -= 4;
347// fprintf( stderr, "compressed\n" );
348 }
349
350 if (detail::public_key_impl::ECDSA_SIG_recover_key_GFp(my->_key, sig, (unsigned char*)&digest, sizeof(digest), nV - 27, 0) == 1)
351 {
352 ECDSA_SIG_free(sig);
353 return;
354 }
355 ECDSA_SIG_free(sig);
356 FC_THROW_EXCEPTION( exception, "unable to reconstruct public key from signature" );
357 }
static int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned char *msg, int msglen, int recid, int check)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
fc::sha256 digest(const T &value)
Definition digest.hpp:9
Here is the call graph for this function:

◆ public_key() [6/6]

fc::ecc::public_key::public_key ( public_key && pk)

Definition at line 146 of file elliptic_impl_pub.cpp.

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

Member Function Documentation

◆ child()

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

◆ fingerprint()

unsigned int fc::ecc::public_key::fingerprint ( ) const

Definition at line 144 of file elliptic_common.cpp.

145 {
147 ripemd160 hash = ripemd160::hash( sha256::hash( key.begin(), key.size() ) );
148 unsigned char* fp = (unsigned char*) hash._hash;
149 return (fp[0] << 24) | (fp[1] << 16) | (fp[2] << 8) | fp[3];
150 }
public_key_data serialize() const
static ripemd160 hash(const fc::sha512 &h)
Definition ripemd160.cpp:44
static sha256 hash(const char *d, uint32_t dlen)
Definition sha256.cpp:44
constexpr const char ripemd160[]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ from_base58()

public_key fc::ecc::public_key::from_base58 ( const std::string & b58)
static

Definition at line 131 of file elliptic_common.cpp.

132 {
133 array<char, 37> data;
134 size_t s = fc::from_base58(b58, (char*)&data, sizeof(data) );
135 FC_ASSERT( s == sizeof(data) );
136
138 uint32_t check = (uint32_t)sha256::hash(data.data, sizeof(key))._hash[0];
139 FC_ASSERT( memcmp( (char*)&check, data.data + sizeof(key), sizeof(check) ) == 0 );
140 memcpy( (char*)key.data, data.data, sizeof(key) );
141 return from_key_data(key);
142 }
uint64_t _hash[4]
Definition sha256.hpp:100
std::vector< char > from_base58(const std::string &base58_str)
Definition base58.cpp:628
unsigned int uint32_t
Definition stdint.h:126
uint8_t key[16]
Definition yubico_otp.c:41
char * s
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:

◆ operator public_key_data()

fc::ecc::public_key::operator public_key_data ( ) const
inline

Definition at line 45 of file elliptic.hpp.

45{ return serialize(); }
Here is the call graph for this function:

◆ operator=() [1/2]

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

Definition at line 156 of file elliptic_impl_pub.cpp.

157 {
158 my = pk.my;
159 return *this;
160 }

◆ operator=() [2/2]

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

Definition at line 150 of file elliptic_impl_pub.cpp.

151 {
152 my = std::move(pk.my);
153 return *this;
154 }

◆ serialize()

public_key_data fc::ecc::public_key::serialize ( ) const

Definition at line 266 of file elliptic_impl_pub.cpp.

267 {
268 public_key_data dat;
269 if( !my->_key ) return dat;
270 EC_KEY_set_conv_form( my->_key, POINT_CONVERSION_COMPRESSED );
271 /*size_t nbytes = i2o_ECPublicKey( my->_key, nullptr ); */
272 /*assert( nbytes == 33 )*/
273 char* front = &dat.data[0];
274 i2o_ECPublicKey( my->_key, (unsigned char**)&front ); // FIXME: questionable memory handling
275 return dat;
276 /*
277 EC_POINT* pub = EC_KEY_get0_public_key( my->_key );
278 EC_GROUP* group = EC_KEY_get0_group( my->_key );
279 EC_POINT_get_affine_coordinates_GFp( group, pub, self.my->_pub_x.get(), self.my->_pub_y.get(), nullptr );
280 */
281 }
Here is the caller graph for this function:

◆ serialize_ecc_point()

public_key_point_data fc::ecc::public_key::serialize_ecc_point ( ) const

Definition at line 282 of file elliptic_impl_pub.cpp.

283 {
285 if( !my->_key ) return dat;
286 EC_KEY_set_conv_form( my->_key, POINT_CONVERSION_UNCOMPRESSED );
287 char* front = &dat.data[0];
288 i2o_ECPublicKey( my->_key, (unsigned char**)&front ); // FIXME: questionable memory handling
289 return dat;
290 }
fc::array< char, 65 > public_key_point_data
the full non-compressed version of the ECC point
Definition elliptic.hpp:24

◆ to_base58() [1/2]

std::string fc::ecc::public_key::to_base58 ( ) const

Definition at line 238 of file elliptic_impl_pub.cpp.

239 {
241 return to_base58( key );
242 }
std::string to_base58() const
Allows to convert current public key object into base58 number.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_base58() [2/2]

std::string fc::ecc::public_key::to_base58 ( const public_key_data & key)
static

Definition at line 121 of file elliptic_common.cpp.

122 {
123 uint32_t check = (uint32_t)sha256::hash(key.data, sizeof(key))._hash[0];
124 static_assert(sizeof(key) + sizeof(check) == 37, ""); // hack around gcc bug: key.size() should be constexpr, but isn't
125 array<char, 37> data;
126 memcpy(data.data, key.begin(), key.size());
127 memcpy(data.begin() + key.size(), (const char*)&check, sizeof(check));
128 return fc::to_base58(data.begin(), data.size(), fc::yield_function_t());
129 }
std::string to_base58(const char *d, size_t s, const fc::yield_function_t &yield)
Definition base58.cpp:618
Here is the call graph for this function:

◆ valid()

bool fc::ecc::public_key::valid ( ) const

Definition at line 162 of file elliptic_impl_pub.cpp.

163 {
164 return my->_key != nullptr;
165 }
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator!=

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

Definition at line 64 of file elliptic.hpp.

65 {
66 return a.serialize() != b.serialize();
67 }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181

◆ operator==

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

Definition at line 60 of file elliptic.hpp.

61 {
62 return a.serialize() == b.serialize();
63 }

◆ private_key

friend class private_key
friend

Definition at line 77 of file elliptic.hpp.


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