Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
elliptic_impl_priv.cpp
Go to the documentation of this file.
1#include <fc/fwd_impl.hpp>
2
3#include <secp256k1.h>
5
7
8/* used by mixed + secp256k1 */
9
10namespace fc { namespace ecc {
11 namespace detail {
12
14 {
15 _init_lib();
16 }
17
19 {
20 _init_lib();
21 this->_key = cpy._key;
22 }
23
25 {
26 _key = pk._key;
27 return *this;
28 }
29 }
30
31 static const private_key_secret empty_priv;
32
34
35 private_key::private_key( const private_key& pk ) : my( pk.my ) {}
36
37 private_key::private_key( private_key&& pk ) : my( std::move( pk.my ) ) {}
38
40
42 {
43 my = std::move( pk.my );
44 return *this;
45 }
46
48 {
49 my = pk.my;
50 return *this;
51 }
52
54 {
55 private_key self;
56 self.my->_key = secret;
57 return self;
58 }
59
61 {
62 return my->_key;
63 }
64
65 private_key::private_key( EC_KEY* k )
66 {
67 my->_key = get_secret( k );
68 EC_KEY_free(k);
69 }
70
72 {
73 FC_ASSERT( my->_key != empty_priv );
75 size_t pub_len = sizeof(pub);
76 secp256k1_pubkey secp_pub;
77 FC_ASSERT( secp256k1_ec_pubkey_create( detail::_get_context(), &secp_pub, (unsigned char*) my->_key.data() ) );
78 secp256k1_ec_pubkey_serialize( detail::_get_context(), (unsigned char*)&pub, &pub_len, &secp_pub, SECP256K1_EC_COMPRESSED );
79 FC_ASSERT( pub_len == pub.size() );
80 return public_key(pub);
81 }
82
83 static int extended_nonce_function( unsigned char *nonce32, const unsigned char *msg32,
84 const unsigned char *key32, const unsigned char* algo16,
85 void* data, unsigned int attempt ) {
86 unsigned int* extra = (unsigned int*) data;
87 (*extra)++;
88 return secp256k1_nonce_function_default( nonce32, msg32, key32, algo16, nullptr, *extra );
89 }
90
91 compact_signature private_key::sign_compact( const fc::sha256& digest, bool require_canonical )const
92 {
93 FC_ASSERT( my->_key != empty_priv );
94 compact_signature result;
96 int recid;
97 unsigned int counter = 0;
98 do
99 {
100 FC_ASSERT( secp256k1_ecdsa_sign_recoverable( detail::_get_context(), &secp_sig, (unsigned char*) digest.data(), (unsigned char*) my->_key.data(), extended_nonce_function, &counter ));
102 } while( require_canonical && !public_key::is_canonical( result ) );
103
104 result.begin()[0] = 27 + 4 + recid;
105 return result;
106 }
107
108}}
private_key_impl & operator=(const private_key_impl &pk) BOOST_NOEXCEPT
an elliptic curve private key.
Definition elliptic.hpp:88
public_key get_public_key() const
private_key_secret get_secret() const
private_key & operator=(private_key &&pk)
compact_signature sign_compact(const fc::sha256 &digest, bool require_canonical=true) const
static private_key regenerate(const fc::sha256 &secret)
contains only the public point of an elliptic curve key.
Definition elliptic.hpp:36
const char * data() const
Definition sha256.cpp:31
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
const secp256k1_context * _get_context()
namespace sysio::chain
Definition authority.cpp:3
fc::sha256 digest(const T &value)
Definition digest.hpp:9
Definition name.hpp:106
SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_default
Definition secp256k1.c:456
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition secp256k1.c:246
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Definition secp256k1.c:551
#define SECP256K1_EC_COMPRESSED
Definition secp256k1.h:201
SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(const secp256k1_context *ctx, unsigned char *output64, int *recid, const secp256k1_ecdsa_recoverable_signature *sig) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition main_impl.h:60
SECP256K1_API int secp256k1_ecdsa_sign_recoverable(const secp256k1_context *ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msghash32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Definition main_impl.h:123
bool pub