|
|
@ -1,21 +1,21 @@ |
|
|
|
// Copyright (c) 2014-2018, The Monero Project
|
|
|
|
// Copyright (c) 2014-2018, The Monero Project
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
|
|
|
// materials provided with the distribution.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
|
|
|
// prior written permission.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
@ -25,7 +25,7 @@ |
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
|
|
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
#pragma once |
|
|
@ -128,24 +128,12 @@ namespace crypto { |
|
|
|
friend void derive_secret_key(const key_derivation &, std::size_t, const secret_key &, secret_key &); |
|
|
|
friend void derive_secret_key(const key_derivation &, std::size_t, const secret_key &, secret_key &); |
|
|
|
static bool derive_subaddress_public_key(const public_key &, const key_derivation &, std::size_t, public_key &); |
|
|
|
static bool derive_subaddress_public_key(const public_key &, const key_derivation &, std::size_t, public_key &); |
|
|
|
friend bool derive_subaddress_public_key(const public_key &, const key_derivation &, std::size_t, public_key &); |
|
|
|
friend bool derive_subaddress_public_key(const public_key &, const key_derivation &, std::size_t, public_key &); |
|
|
|
static void generate_signature(const hash &, const public_key &, const secret_key &, signature &); |
|
|
|
|
|
|
|
friend void generate_signature(const hash &, const public_key &, const secret_key &, signature &); |
|
|
|
|
|
|
|
static bool check_signature(const hash &, const public_key &, const signature &); |
|
|
|
|
|
|
|
friend bool check_signature(const hash &, const public_key &, const signature &); |
|
|
|
|
|
|
|
static void generate_tx_proof(const hash &, const public_key &, const public_key &, const boost::optional<public_key> &, const public_key &, const secret_key &, signature &); |
|
|
|
|
|
|
|
friend void generate_tx_proof(const hash &, const public_key &, const public_key &, const boost::optional<public_key> &, const public_key &, const secret_key &, signature &); |
|
|
|
|
|
|
|
static bool check_tx_proof(const hash &, const public_key &, const public_key &, const boost::optional<public_key> &, const public_key &, const signature &); |
|
|
|
|
|
|
|
friend bool check_tx_proof(const hash &, const public_key &, const public_key &, const boost::optional<public_key> &, const public_key &, const signature &); |
|
|
|
|
|
|
|
static void generate_key_image(const public_key &, const secret_key &, key_image &); |
|
|
|
static void generate_key_image(const public_key &, const secret_key &, key_image &); |
|
|
|
friend void generate_key_image(const public_key &, const secret_key &, key_image &); |
|
|
|
friend void generate_key_image(const public_key &, const secret_key &, key_image &); |
|
|
|
static void generate_ring_signature(const hash &, const key_image &, |
|
|
|
static void generate_ring_signature(const hash &, const key_image &, |
|
|
|
const public_key *const *, std::size_t, const secret_key &, std::size_t, signature *); |
|
|
|
const public_key *const *, std::size_t, const secret_key &, std::size_t, signature *); |
|
|
|
friend void generate_ring_signature(const hash &, const key_image &, |
|
|
|
friend void generate_ring_signature(const hash &, const key_image &, |
|
|
|
const public_key *const *, std::size_t, const secret_key &, std::size_t, signature *); |
|
|
|
const public_key *const *, std::size_t, const secret_key &, std::size_t, signature *); |
|
|
|
static bool check_ring_signature(const hash &, const key_image &, |
|
|
|
|
|
|
|
const public_key *const *, std::size_t, const signature *); |
|
|
|
|
|
|
|
friend bool check_ring_signature(const hash &, const key_image &, |
|
|
|
|
|
|
|
const public_key *const *, std::size_t, const signature *); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void generate_random_bytes_thread_safe(size_t N, uint8_t *bytes); |
|
|
|
void generate_random_bytes_thread_safe(size_t N, uint8_t *bytes); |
|
|
@ -207,26 +195,6 @@ namespace crypto { |
|
|
|
return crypto_ops::derive_subaddress_public_key(out_key, derivation, output_index, result); |
|
|
|
return crypto_ops::derive_subaddress_public_key(out_key, derivation, output_index, result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Generation and checking of a standard signature.
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
inline void generate_signature(const hash &prefix_hash, const public_key &pub, const secret_key &sec, signature &sig) { |
|
|
|
|
|
|
|
crypto_ops::generate_signature(prefix_hash, pub, sec, sig); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
inline bool check_signature(const hash &prefix_hash, const public_key &pub, const signature &sig) { |
|
|
|
|
|
|
|
return crypto_ops::check_signature(prefix_hash, pub, sig); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Generation and checking of a tx proof; given a tx pubkey R, the recipient's view pubkey A, and the key
|
|
|
|
|
|
|
|
* derivation D, the signature proves the knowledge of the tx secret key r such that R=r*G and D=r*A |
|
|
|
|
|
|
|
* When the recipient's address is a subaddress, the tx pubkey R is defined as R=r*B where B is the recipient's spend pubkey |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
inline void generate_tx_proof(const hash &prefix_hash, const public_key &R, const public_key &A, const boost::optional<public_key> &B, const public_key &D, const secret_key &r, signature &sig) { |
|
|
|
|
|
|
|
crypto_ops::generate_tx_proof(prefix_hash, R, A, B, D, r, sig); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
inline bool check_tx_proof(const hash &prefix_hash, const public_key &R, const public_key &A, const boost::optional<public_key> &B, const public_key &D, const signature &sig) { |
|
|
|
|
|
|
|
return crypto_ops::check_tx_proof(prefix_hash, R, A, B, D, sig); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* To send money to a key:
|
|
|
|
/* To send money to a key:
|
|
|
|
* * The sender generates an ephemeral key and includes it in transaction output. |
|
|
|
* * The sender generates an ephemeral key and includes it in transaction output. |
|
|
|
* * To spend the money, the receiver generates a key image from it. |
|
|
|
* * To spend the money, the receiver generates a key image from it. |
|
|
@ -242,11 +210,6 @@ namespace crypto { |
|
|
|
signature *sig) { |
|
|
|
signature *sig) { |
|
|
|
crypto_ops::generate_ring_signature(prefix_hash, image, pubs, pubs_count, sec, sec_index, sig); |
|
|
|
crypto_ops::generate_ring_signature(prefix_hash, image, pubs, pubs_count, sec, sec_index, sig); |
|
|
|
} |
|
|
|
} |
|
|
|
inline 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) { |
|
|
|
|
|
|
|
return crypto_ops::check_ring_signature(prefix_hash, image, pubs, pubs_count, sig); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Variants with vector<const public_key *> parameters.
|
|
|
|
/* Variants with vector<const public_key *> parameters.
|
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -256,11 +219,6 @@ namespace crypto { |
|
|
|
signature *sig) { |
|
|
|
signature *sig) { |
|
|
|
generate_ring_signature(prefix_hash, image, pubs.data(), pubs.size(), sec, sec_index, sig); |
|
|
|
generate_ring_signature(prefix_hash, image, pubs.data(), pubs.size(), sec, sec_index, sig); |
|
|
|
} |
|
|
|
} |
|
|
|
inline bool check_ring_signature(const hash &prefix_hash, const key_image &image, |
|
|
|
|
|
|
|
const std::vector<const public_key *> &pubs, |
|
|
|
|
|
|
|
const signature *sig) { |
|
|
|
|
|
|
|
return check_ring_signature(prefix_hash, image, pubs.data(), pubs.size(), sig); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) { |
|
|
|
inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) { |
|
|
|
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o; |
|
|
|
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o; |
|
|
|