13 #include <secp256k1.h>
21 namespace fc {
namespace ecc {
25 static secp256k1_context_t* ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_RANGEPROOF | SECP256K1_CONTEXT_COMMIT );
42 memset(
_key.data(), 0,
_key.size() );
72 (
unsigned char*) my->_key.data() ) );
99 return my->_key != empty_pub;
106 memcpy( new_key.data(), my->_key.data(), new_key.size() );
128 unsigned int pk_len = my->_key.size();
129 memcpy( dat.data(), my->_key.data(), pk_len );
137 const unsigned char* front = dat.data();
141 EC_KEY *key = EC_KEY_new_by_curve_name( NID_secp256k1 );
142 key = o2i_ECPublicKey( &key, &front,
sizeof(dat) );
144 EC_KEY_set_conv_form( key, POINT_CONVERSION_COMPRESSED );
145 unsigned char* buffer = my->_key.data();
146 i2o_ECPublicKey( key, &buffer );
162 if( check_canonical )
164 FC_ASSERT( is_canonical( c ),
"signature is not canonical" );
169 c.data() + 1, my->_key.data(), (
int*) &pk_len, 1,
170 (*c.data() - 27) & 3 ) );
175 int child,
int parent, uint8_t depth )
176 :
public_key(k), c(c), child_num(child), parent_fp(parent), depth(depth) { }
182 const detail::chr37 data = detail::_derive_message( key, i );
187 (
unsigned char*) left.
data() ) > 0 );
194 int child,
int parent, uint8_t depth )
195 :
private_key(k), c(c), child_num(child), parent_fp(parent), depth(depth) { }
218 std::vector<const unsigned char*> blinds(blinds_in.size());
219 for( uint32_t i = 0; i < blinds_in.size(); ++i ) blinds[i] = (
unsigned char*) blinds_in[i].data();
225 bool verify_sum(
const std::vector<commitment_type>& commits_in,
const std::vector<commitment_type>& neg_commits_in, int64_t excess )
227 std::vector<const unsigned char*> commits(commits_in.size());
228 for( uint32_t i = 0; i < commits_in.size(); ++i ) commits[i] = commits_in[i].data();
229 std::vector<const unsigned char*> neg_commits(neg_commits_in.size());
230 for( uint32_t i = 0; i < neg_commits_in.size(); ++i ) neg_commits[i] = neg_commits_in[i].data();
232 return secp256k1_pedersen_verify_tally(
detail::_get_context(), commits.data(), commits.size(), neg_commits.data(), neg_commits.size(), excess );
237 return secp256k1_rangeproof_verify(
detail::_get_context(), &min_val, &max_val, commit.data(), (
const unsigned char*)proof.data(), proof.size() );
246 uint64_t actual_value
249 int proof_len = 5134;
250 std::vector<char> proof(proof_len);
253 (
unsigned char*)proof.data(),
254 &proof_len, min_value,
256 (
unsigned char*) commit_blind.
data(),
257 (
unsigned char*) nonce.
data(),
258 base10_exp, min_bits, actual_value ) );
259 proof.resize(proof_len);
271 const std::vector<char>& proof )
276 (
unsigned char*) blind_out.
data(),
278 (
unsigned char*) msg,
280 (
unsigned char*) nonce.
data(),
284 (
const unsigned char*)proof.data(),
287 message_out = std::string( msg, mlen );
299 (
const unsigned char*)proof.data(),
300 (
int)proof.size() ) );