fix ecc point seralization
This commit is contained in:
parent
5f36e9acac
commit
4b2d221c05
3 changed files with 17 additions and 9 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <fc/string.hpp>
|
#include <fc/string.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
std::string to_base58( const char* d, size_t s );
|
std::string to_base58( const char* d, size_t s );
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ namespace fc {
|
||||||
|
|
||||||
|
|
||||||
public_key( const public_key_data& v );
|
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 );
|
public_key( const compact_signature& c, const fc::sha256& digest );
|
||||||
|
|
||||||
bool valid()const;
|
bool valid()const;
|
||||||
|
|
|
||||||
|
|
@ -384,17 +384,10 @@ namespace fc { namespace ecc {
|
||||||
{
|
{
|
||||||
public_key_point_data dat;
|
public_key_point_data dat;
|
||||||
if( !my->_key ) return dat;
|
if( !my->_key ) return dat;
|
||||||
// EC_KEY_set_conv_form( my->_key, POINT_CONVERSION_COMPRESSED );
|
EC_KEY_set_conv_form( my->_key, POINT_CONVERSION_UNCOMPRESSED );
|
||||||
// size_t nbytes = i2o_ECPublicKey( my->_key, nullptr );
|
|
||||||
// assert( nbytes == 65 )
|
|
||||||
char* front = &dat.data[0];
|
char* front = &dat.data[0];
|
||||||
i2o_ECPublicKey( my->_key, (unsigned char**)&front );
|
i2o_ECPublicKey( my->_key, (unsigned char**)&front );
|
||||||
return dat;
|
return dat;
|
||||||
/*
|
|
||||||
EC_POINT* pub = EC_KEY_get0_public_key( my->_key );
|
|
||||||
EC_GROUP* group = EC_KEY_get0_group( my->_key );
|
|
||||||
EC_POINT_get_affine_coordinates_GFp( group, pub, self.my->_pub_x.get(), self.my->_pub_y.get(), nullptr );
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public_key::public_key()
|
public_key::public_key()
|
||||||
|
|
@ -403,6 +396,20 @@ namespace fc { namespace ecc {
|
||||||
public_key::~public_key()
|
public_key::~public_key()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public_key::public_key( const public_key_point_data& dat )
|
||||||
|
{
|
||||||
|
const char* front = &dat.data[0];
|
||||||
|
if( *front == 0 ){}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*my->_key = EC_KEY_new_by_curve_name( NID_secp256k1 ); */
|
||||||
|
my->_key = o2i_ECPublicKey( &my->_key, (const unsigned char**)&front, sizeof(dat) );
|
||||||
|
if( !my->_key )
|
||||||
|
{
|
||||||
|
FC_THROW_EXCEPTION( exception, "error decoding public key", ("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public_key::public_key( const public_key_data& dat )
|
public_key::public_key( const public_key_data& dat )
|
||||||
{
|
{
|
||||||
const char* front = &dat.data[0];
|
const char* front = &dat.data[0];
|
||||||
|
|
@ -425,7 +432,6 @@ namespace fc { namespace ecc {
|
||||||
|
|
||||||
public_key private_key::get_public_key()const
|
public_key private_key::get_public_key()const
|
||||||
{
|
{
|
||||||
|
|
||||||
public_key pub;
|
public_key pub;
|
||||||
pub.my->_key = EC_KEY_new_by_curve_name( NID_secp256k1 );
|
pub.my->_key = EC_KEY_new_by_curve_name( NID_secp256k1 );
|
||||||
EC_KEY_set_public_key( pub.my->_key, EC_KEY_get0_public_key( my->_key ) );
|
EC_KEY_set_public_key( pub.my->_key, EC_KEY_get0_public_key( my->_key ) );
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue