11#elif defined(__FreeBSD__)
19#define BTC_EXT_PUB_MAGIC (0x0488B21E)
20#define BTC_EXT_PRIV_MAGIC (0x0488ADE4)
22namespace fc {
namespace em {
41 static void _put(
unsigned char** dest,
unsigned int i)
43 *(*dest)++ = (i >> 24) & 0xff;
44 *(*dest)++ = (i >> 16) & 0xff;
45 *(*dest)++ = (i >> 8) & 0xff;
46 *(*dest)++ = i & 0xff;
53 unsigned char* dest = (
unsigned char*) result.begin();
55 memcpy( dest, key32, 32 ); dest += 32;
68 static const ec_group secp256k1( EC_GROUP_new_by_curve_name( NID_secp256k1 ) );
72 static private_key_secret _get_curve_order()
75 bn_ctx ctx(BN_CTX_new());
77 FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) );
78 private_key_secret bin;
79 FC_ASSERT( BN_num_bytes( order ) ==
static_cast<int>(bin.data_size()) );
80 FC_ASSERT( BN_bn2bin( order, (
unsigned char*) bin.data() ) ==
static_cast<int>(bin.data_size()) );
86 static private_key_secret order = _get_curve_order();
90 static private_key_secret _get_half_curve_order()
93 bn_ctx ctx(BN_CTX_new());
95 FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) );
96 BN_rshift1( order, order );
97 private_key_secret bin;
98 FC_ASSERT( BN_num_bytes( order ) ==
static_cast<int>(bin.data_size()) );
99 FC_ASSERT( BN_bn2bin( order, (
unsigned char*) bin.data() ) ==
static_cast<int>(bin.data_size()) );
105 static private_key_secret half_order = _get_half_curve_order();
125 static_assert(
sizeof(
key) +
sizeof(check) == 37,
"");
127 memcpy(data.data, key.begin(), key.size());
128 memcpy(data.begin() + key.size(), (
const char*)&check,
sizeof(check));
140 FC_ASSERT( memcmp( (
char*)&check, data.data +
sizeof(key),
sizeof(check) ) == 0 );
141 memcpy( (
char*)key.data, data.data,
sizeof(key) );
142 return from_key_data(key);
149 unsigned char* fp = (
unsigned char*) hash._hash;
150 return (fp[0] << 24) | (fp[1] << 16) | (fp[2] << 8) | fp[3];
154 return !(c.
data[1] & 0x80)
155 && !(c.
data[1] == 0 && !(c.
data[2] & 0x80))
156 && !(c.
data[33] & 0x80)
157 && !(c.
data[33] == 0 && !(c.
data[34] & 0x80));
163 BN_bin2bn((
unsigned char*)&offset,
sizeof(offset), z);
165 ec_group group(EC_GROUP_new_by_curve_name(NID_secp256k1));
166 bn_ctx ctx(BN_CTX_new());
168 EC_GROUP_get_order(group, order, ctx);
172 BN_bin2bn((
unsigned char*)&seed,
sizeof(seed), secexp);
173 BN_add(secexp, secexp, z);
174 BN_mod(secexp, secexp, order, ctx);
178 auto shift =
sizeof(secret) - BN_num_bytes(secexp);
179 BN_bn2bin(secexp, ((
unsigned char*)&secret)+shift);
191 const BIGNUM*
bn = EC_KEY_get0_private_key(k);
196 int nbytes = BN_num_bytes(
bn);
197 BN_bn2bin(
bn, &((
unsigned char*)&sec)[32-nbytes] );
203 EC_KEY* k = EC_KEY_new_by_curve_name( NID_secp256k1 );
205 if( !EC_KEY_generate_key( k ) )
an elliptic curve private key.
static private_key generate_from_seed(const fc::sha256 &seed, const fc::sha256 &offset=fc::sha256())
public_key get_public_key() const
private_key_secret get_secret() const
static private_key regenerate(const fc::sha256 &secret)
static private_key generate()
private_key child(const fc::sha256 &offset) const
contains only the public point of an elliptic curve key.
unsigned int fingerprint() const
std::string to_base58() const
Allows to convert current public key object into base58 number.
static public_key from_base58(const std::string &b58)
public_key_data serialize() const
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)
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 private_key_secret & get_curve_order()
const ec_group & get_curve()
chr37 _derive_message(const public_key_data &key, int i)
fc::sha256 _left(const fc::sha512 &v)
fc::array< char, 37 > chr37
fc::sha256 _right(const fc::sha512 &v)
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)