10#elif defined(__FreeBSD__)
18#define BTC_EXT_PUB_MAGIC (0x0488B21E)
19#define BTC_EXT_PRIV_MAGIC (0x0488ADE4)
21namespace fc {
namespace ecc {
40 static void _put(
unsigned char** dest,
unsigned int i)
42 *(*dest)++ = (i >> 24) & 0xff;
43 *(*dest)++ = (i >> 16) & 0xff;
44 *(*dest)++ = (i >> 8) & 0xff;
45 *(*dest)++ = i & 0xff;
49 static chr37 _derive_message(
char first,
const char* key32,
int i )
52 unsigned char* dest = (
unsigned char*) result.begin();
54 memcpy( dest, key32, 32 ); dest += 32;
61 return _derive_message( *key.begin(), key.begin() + 1, i );
67 static const ec_group secp256k1( EC_GROUP_new_by_curve_name( NID_secp256k1 ) );
74 bn_ctx ctx(BN_CTX_new());
76 FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) );
92 bn_ctx ctx(BN_CTX_new());
94 FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) );
95 BN_rshift1( order, order );
124 static_assert(
sizeof(
key) +
sizeof(check) == 37,
"");
126 memcpy(data.data, key.begin(), key.size());
127 memcpy(data.begin() + key.size(), (
const char*)&check,
sizeof(check));
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);
148 unsigned char* fp = (
unsigned char*) hash._hash;
149 return (fp[0] << 24) | (fp[1] << 16) | (fp[2] << 8) | fp[3];
153 return !(c.
data[1] & 0x80)
154 && !(c.
data[1] == 0 && !(c.
data[2] & 0x80))
155 && !(c.
data[33] & 0x80)
156 && !(c.
data[33] == 0 && !(c.
data[34] & 0x80));
162 BN_bin2bn((
unsigned char*)&offset,
sizeof(offset), z);
164 ec_group group(EC_GROUP_new_by_curve_name(NID_secp256k1));
165 bn_ctx ctx(BN_CTX_new());
167 EC_GROUP_get_order(group, order, ctx);
171 BN_bin2bn((
unsigned char*)&seed,
sizeof(seed), secexp);
172 BN_add(secexp, secexp, z);
173 BN_mod(secexp, secexp, order, ctx);
177 auto shift =
sizeof(secret) - BN_num_bytes(secexp);
178 BN_bn2bin(secexp, ((
unsigned char*)&secret)+shift);
190 const BIGNUM*
bn = EC_KEY_get0_private_key(k);
195 int nbytes = BN_num_bytes(
bn);
196 BN_bn2bin(
bn, &((
unsigned char*)&sec)[32-nbytes] );
202 EC_KEY* k = EC_KEY_new_by_curve_name( NID_secp256k1 );
204 if( !EC_KEY_generate_key( k ) )
an elliptic curve private key.
static private_key generate()
public_key get_public_key() const
private_key_secret get_secret() const
private_key child(const fc::sha256 &offset) const
static private_key generate_from_seed(const fc::sha256 &seed, const fc::sha256 &offset=fc::sha256())
static private_key regenerate(const fc::sha256 &secret)
contains only the public point of an elliptic curve key.
public_key_data serialize() const
std::string to_base58() const
Allows to convert current public key object into base58 number.
unsigned int fingerprint() const
static public_key from_base58(const std::string &b58)
Used to generate a useful error report when an exception is thrown.
static ripemd160 hash(const fc::sha512 &h)
static sha256 hash(const char *d, uint32_t dlen)
const char * data() const
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
const ec_group & get_curve()
const private_key_secret & get_curve_order()
fc::sha256 _right(const fc::sha512 &v)
fc::sha256 _left(const fc::sha512 &v)
fc::array< char, 37 > chr37
const private_key_secret & get_half_curve_order()
fc::array< char, 33 > public_key_data
void pack(Stream &s, const std::deque< T > &value)
std::string to_base58(const char *d, size_t s, const fc::yield_function_t &yield)
std::vector< char > from_base58(const std::string &base58_str)
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
memcpy((char *) pInfo->slotDescription, s, l)