35 #include <boost/thread/mutex.hpp> 36 #include <boost/thread/lock_guard.hpp> 37 #include <boost/archive/iterators/binary_from_base64.hpp> 38 #include <boost/archive/iterators/base64_from_binary.hpp> 39 #include <boost/archive/iterators/transform_width.hpp> 40 #include <boost/algorithm/string.hpp> 41 #include <boost/algorithm/hex.hpp> 44 #include "ed25519-donna/ed25519.h" 76 std::vector<public_key> keys;
81 std::vector<secret_key> keys;
108 sizeof(
signature) == 64,
"Invalid structure size");
149 static std::string
sign_message(
const std::string &message,
const std::string &privateKey);
150 friend std::string
sign_message(
const std::string &message,
const std::string &privateKey);
153 static bool verify_signature(
const std::string &message, std::vector<std::string> publicKey,
const std::string &
signature);
154 friend bool verify_signature(
const std::string &message, std::vector<std::string> publicKey,
const std::string &
signature);
167 inline void rand(
size_t N, uint8_t *bytes) {
250 const public_key *
const *pubs, std::size_t pubs_count,
256 const public_key *
const *pubs, std::size_t pubs_count,
264 const std::vector<const public_key *> &pubs,
270 const std::vector<const public_key *> &pubs,
275 inline std::string
sign_message(
const std::string &message,
const std::string &privateKey) {
292 using namespace boost::archive::iterators;
293 using It = transform_width<binary_from_base64<std::string::const_iterator>, 8, 6>;
294 return boost::algorithm::trim_right_copy_if(std::string(It(std::begin(val)), It(std::end(val))), [](
char c) {
300 using namespace boost::archive::iterators;
301 using It = base64_from_binary<transform_width<std::string::const_iterator, 6, 8>>;
302 auto tmp = std::string(It(std::begin(val)), It(std::end(val)));
303 return tmp.append((3 - val.size() % 3) % 3,
'=');
void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res)
Definition: crypto.h:213
POD_CLASS ec_point
Definition: crypto.h:59
const uint32_t T[512]
Definition: groestl_tables.h:34
void generate_tx_proof(const hash &prefix_hash, const public_key &R, const public_key &A, const public_key &D, const secret_key &r, signature &sig)
Definition: crypto.h:233
#define CRYPTO_MAKE_COMPARABLE(type)
Definition: generic-ops.h:38
static std::string base64_encode(std::string val)
static bool derive_public_key(const key_derivation &, std::size_t, const public_key &, public_key &)
void derive_secret_key(const key_derivation &derivation, std::size_t output_index, const secret_key &base, secret_key &derived_key)
Definition: crypto.h:216
static bool secret_key_to_public_key(const secret_key &, public_key &)
Definition: crypto.cpp:128
static bool check_signature(const hash &, const public_key &, const signature &)
Definition: crypto.cpp:229
static void generate_key_image(const public_key &, const secret_key &, key_image &)
Definition: crypto.cpp:378
POD_CLASS key_derivation
Definition: crypto.h:89
static bool check_key(const public_key &)
Definition: crypto.cpp:123
bool check_ring_signature(const hash &prefix_hash, const key_image &image, const public_key *const *pubs, std::size_t pubs_count, const signature *sig)
Definition: crypto.h:255
void generate_signature(const hash &prefix_hash, const public_key &pub, const secret_key &sec, signature &sig)
Definition: crypto.h:223
crypto namespace.
Definition: crypto.cpp:47
POD_CLASS secret_keyV
Definition: crypto.h:80
#define POD_CLASS
Definition: pod-class.h:44
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
Definition: crypto.h:206
void generate_random_bytes_not_thread_safe(size_t n, void *result)
Definition: random.c:117
boost::mutex random_lock
Definition: crypto.cpp:61
std::string base64_encode(const std::string &val)
Definition: crypto.h:299
void generate_key_image(const public_key &pub, const secret_key &sec, key_image &image)
Definition: crypto.h:246
void rand(size_t N, uint8_t *bytes)
Definition: crypto.h:167
bool verify_signature(const std::string &message, const std::string &publicKey, const std::string &signature)
Definition: crypto.h:279
POD_CLASS public_keyM
Definition: crypto.h:85
POD_CLASS ec_scalar
Definition: crypto.h:63
static void generate_tx_proof(const hash &, const public_key &, const public_key &, const public_key &, const secret_key &, signature &)
Definition: crypto.cpp:250
static secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key &recovery_key=secret_key(), bool recover=false)
Definition: crypto.cpp:101
void generate_ring_signature(const hash &prefix_hash, const key_image &image, const public_key *const *pubs, std::size_t pubs_count, const secret_key &sec, std::size_t sec_index, signature *sig)
Definition: crypto.h:249
friend class crypto_ops
Definition: crypto.h:101
static void derive_secret_key(const key_derivation &, std::size_t, const secret_key &, secret_key &)
secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key &recovery_key=secret_key(), bool recover=false)
Definition: crypto.h:184
type
Definition: json.h:74
std::string base64_decode(const std::string &val)
Definition: crypto.h:291
static bool check_tx_proof(const hash &, const public_key &, const public_key &, const public_key &, const signature &)
Definition: crypto.cpp:300
POD_CLASS public_key
Definition: crypto.h:65
bool check_tx_proof(const hash &prefix_hash, const public_key &R, const public_key &A, const public_key &D, const signature &sig)
Definition: crypto.h:236
static bool generate_key_derivation(const public_key &, const secret_key &, key_derivation &)
Definition: crypto.cpp:138
POD_CLASS signature
Definition: crypto.h:99
static std::string base64_decode(std::string val)
static bool verify_signature(const std::string &message, const std::string &publicKey, const std::string &signature)
Definition: crypto.cpp:522
POD_CLASS key_image
Definition: crypto.h:93
POD_CLASS secret_key
Definition: crypto.h:69
void operator=(const crypto_ops &)
bool derive_public_key(const key_derivation &derivation, std::size_t output_index, const public_key &base, public_key &derived_key)
Definition: crypto.h:209
bool check_key(const public_key &key)
Definition: crypto.h:190
static bool check_ring_signature(const hash &, const key_image &, const public_key *const *, std::size_t, const signature *)
POD_CLASS hash
Definition: hash.h:46
static void generate_ring_signature(const hash &, const key_image &, const public_key *const *, std::size_t, const secret_key &, std::size_t, signature *)
std::vector< std::string > create_ed25519_keypair()
Definition: crypto.h:287
std::vector< secret_keyV > column_vectors
Definition: crypto.h:88
bool secret_key_to_public_key(const secret_key &sec, public_key &pub)
Definition: crypto.h:196
POD_CLASS public_keyV
Definition: crypto.h:75
std::string sign_message(const std::string &message, const std::string &privateKey)
Definition: crypto.h:275
static void generate_signature(const hash &, const public_key &, const secret_key &, signature &)
Definition: crypto.cpp:206
static std::string sign_message(const std::string &message, const std::string &privateKey)
Definition: crypto.cpp:507
#define CRYPTO_MAKE_HASHABLE(type)
Definition: generic-ops.h:48
static void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res)
Definition: crypto.cpp:153
bool check_signature(const hash &prefix_hash, const public_key &pub, const signature &sig)
Definition: crypto.h:226
int rows
Definition: crypto.h:77
static std::vector< std::string > create_ed25519_keypair()
Definition: crypto.cpp:547