Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
elliptic.hpp
Go to the documentation of this file.
1#pragma once
7#include <fc/fwd.hpp>
8#include <fc/array.hpp>
9#include <fc/io/raw_fwd.hpp>
10
11namespace fc {
12
13 namespace ecc {
14 namespace detail
15 {
16 class public_key_impl;
17 class private_key_impl;
18 }
19
30
36 {
37 public:
38 public_key();
39 public_key(const public_key& k);
41// bool verify( const fc::sha256& digest, const signature& sig );
44
45 operator public_key_data()const { return serialize(); }
46
47
48 public_key( const public_key_data& v );
50 public_key( const compact_signature& c, const fc::sha256& digest, bool check_canonical = true );
51
52 public_key child( const fc::sha256& offset )const;
53
54 bool valid()const;
55
56 public_key( public_key&& pk );
58 public_key& operator=( const public_key& pk );
59
60 inline friend bool operator==( const public_key& a, const public_key& b )
61 {
62 return a.serialize() == b.serialize();
63 }
64 inline friend bool operator!=( const public_key& a, const public_key& b )
65 {
66 return a.serialize() != b.serialize();
67 }
68
70 std::string to_base58() const;
71 static std::string to_base58( const public_key_data &key );
72 static public_key from_base58( const std::string& b58 );
73
74 unsigned int fingerprint() const;
75
76 private:
77 friend class private_key;
78 static public_key from_key_data( const public_key_data& v );
79 static bool is_canonical( const compact_signature& c );
81 };
82
88 {
89 public:
92 private_key( const private_key& pk );
94
96 private_key& operator=( const private_key& pk );
97
98 static private_key generate();
99 static private_key regenerate( const fc::sha256& secret );
100
101 private_key child( const fc::sha256& offset )const;
102
108 static private_key generate_from_seed( const fc::sha256& seed, const fc::sha256& offset = fc::sha256() );
109
110 private_key_secret get_secret()const; // get the private key secret
111
112 operator private_key_secret ()const { return get_secret(); }
113
118 fc::sha512 get_shared_secret( const public_key& pub )const;
119
120// signature sign( const fc::sha256& digest )const;
121 compact_signature sign_compact( const fc::sha256& digest, bool require_canonical = true )const;
122// bool verify( const fc::sha256& digest, const signature& sig );
123
125
126 inline friend bool operator==( const private_key& a, const private_key& b )
127 {
128 return a.get_secret() == b.get_secret();
129 }
130 inline friend bool operator!=( const private_key& a, const private_key& b )
131 {
132 return a.get_secret() != b.get_secret();
133 }
134 inline friend bool operator<( const private_key& a, const private_key& b )
135 {
136 return a.get_secret() < b.get_secret();
137 }
138
139 unsigned int fingerprint() const { return get_public_key().fingerprint(); }
140
141 private:
142 private_key( EC_KEY* k );
143 static fc::sha256 get_secret( const EC_KEY * const k );
145 };
146
150 struct public_key_shim : public crypto::shim<public_key_data> {
152
153 bool valid()const {
154 return public_key(_data).valid();
155 }
156 };
157
158 struct signature_shim : public crypto::shim<compact_signature> {
161
162 public_key_type recover(const sha256& digest, bool check_canonical) const {
163 return public_key_type(public_key(_data, digest, check_canonical).serialize());
164 }
165 };
166
167 struct private_key_shim : public crypto::shim<private_key_secret> {
171
172 signature_type sign( const sha256& digest, bool require_canonical = true ) const
173 {
174 return signature_type(private_key::regenerate(_data).sign_compact(digest, require_canonical));
175 }
176
181
186
188 {
189 return private_key_shim(private_key::generate().get_secret());
190 }
191
192 };
193
194 } // namespace ecc
195 void to_variant( const ecc::private_key& var, variant& vo );
196 void from_variant( const variant& var, ecc::private_key& vo );
197 void to_variant( const ecc::public_key& var, variant& vo );
198 void from_variant( const variant& var, ecc::public_key& vo );
199
200 namespace raw
201 {
202 template<typename Stream>
204 {
206 fc::raw::unpack(s,ser);
207 pk = fc::ecc::public_key( ser );
208 }
209
210 template<typename Stream>
211 void pack( Stream& s, const fc::ecc::public_key& pk)
212 {
213 fc::raw::pack( s, pk.serialize() );
214 }
215
216 template<typename Stream>
218 {
219 fc::sha256 sec;
220 unpack( s, sec );
222 }
223
224 template<typename Stream>
226 {
227 fc::raw::pack( s, pk.get_secret() );
228 }
229
230 } // namespace raw
231
232} // namespace fc
233#include <fc/reflect/reflect.hpp>
234
an elliptic curve private key.
Definition elliptic.hpp:88
static private_key generate()
friend bool operator<(const private_key &a, const private_key &b)
Definition elliptic.hpp:134
public_key get_public_key() const
private_key_secret get_secret() const
private_key & operator=(private_key &&pk)
private_key child(const fc::sha256 &offset) const
friend bool operator!=(const private_key &a, const private_key &b)
Definition elliptic.hpp:130
static private_key generate_from_seed(const fc::sha256 &seed, const fc::sha256 &offset=fc::sha256())
fc::sha512 get_shared_secret(const public_key &pub) const
compact_signature sign_compact(const fc::sha256 &digest, bool require_canonical=true) const
unsigned int fingerprint() const
Definition elliptic.hpp:139
static private_key regenerate(const fc::sha256 &secret)
friend bool operator==(const private_key &a, const private_key &b)
Definition elliptic.hpp:126
contains only the public point of an elliptic curve key.
Definition elliptic.hpp:36
public_key_data serialize() const
public_key child(const fc::sha256 &offset) const
std::string to_base58() const
Allows to convert current public key object into base58 number.
unsigned int fingerprint() const
friend bool operator==(const public_key &a, const public_key &b)
Definition elliptic.hpp:60
friend bool operator!=(const public_key &a, const public_key &b)
Definition elliptic.hpp:64
public_key & operator=(public_key &&pk)
static public_key from_base58(const std::string &b58)
public_key_point_data serialize_ecc_point() const
Used to forward declare value types.
Definition fwd.hpp:11
Concept for reading and writing characters.
fc::array< char, 65 > public_key_point_data
the full non-compressed version of the ECC point
Definition elliptic.hpp:24
fc::sha256 blind_signature
Definition elliptic.hpp:29
fc::sha256 blinded_hash
Definition elliptic.hpp:28
fc::array< char, 33 > commitment_type
Definition elliptic.hpp:21
fc::sha256 blind_factor_type
Definition elliptic.hpp:20
fc::array< unsigned char, 65 > compact_signature
Definition elliptic.hpp:26
fc::array< char, 78 > extended_key_data
Definition elliptic.hpp:27
fc::array< char, 72 > signature
Definition elliptic.hpp:25
fc::array< char, 33 > public_key_data
Definition elliptic.hpp:22
fc::sha256 private_key_secret
Definition elliptic.hpp:23
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
namespace sysio::chain
Definition authority.cpp:3
fc::sha256 digest(const T &value)
Definition digest.hpp:9
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)
Definition authority.cpp:4
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define FC_REFLECT_TYPENAME(TYPE)
Definition reflect.hpp:320
#define FC_REFLECT_DERIVED(TYPE, INHERITS, MEMBERS)
Specializes fc::reflector for TYPE where type inherits other reflected classes.
Definition reflect.hpp:298
const data_type & serialize() const
Definition common.hpp:188
public_key_type get_public_key() const
Definition elliptic.hpp:177
public_key_shim public_key_type
Definition elliptic.hpp:170
signature_type sign(const sha256 &digest, bool require_canonical=true) const
Definition elliptic.hpp:172
signature_shim signature_type
Definition elliptic.hpp:169
sha512 generate_shared_secret(const public_key_type &pub_key) const
Definition elliptic.hpp:182
static private_key_shim generate()
Definition elliptic.hpp:187
public_key_shim public_key_type
Definition elliptic.hpp:159
public_key_type recover(const sha256 &digest, bool check_canonical) const
Definition elliptic.hpp:162
char * s