Monero
device_default.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017-2020, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #pragma once
31 
32 #include "device.hpp"
33 
34 namespace hw {
35 
36  namespace core {
37 
38  void register_all(std::map<std::string, std::unique_ptr<device>> &registry);
39 
40  class device_default : public hw::device {
41  public:
44 
47 
48  explicit operator bool() const override { return false; };
49 
50  /* ======================================================================= */
51  /* SETUP/TEARDOWN */
52  /* ======================================================================= */
53  bool set_name(const std::string &name) override;
54  const std::string get_name() const override;
55 
56  bool init(void) override;
57  bool release() override;
58 
59  bool connect(void) override;
60  bool disconnect() override;
61 
62  bool set_mode(device_mode mode) override;
63 
64  device_type get_type() const override {return device_type::SOFTWARE;};
65 
66  /* ======================================================================= */
67  /* LOCKER */
68  /* ======================================================================= */
69  void lock(void) override;
70  void unlock(void) override;
71  bool try_lock(void) override;
72 
73  /* ======================================================================= */
74  /* WALLET & ADDRESS */
75  /* ======================================================================= */
77  bool get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) override;
78  bool generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key, uint64_t kdf_rounds) override;
79 
80  /* ======================================================================= */
81  /* SUB ADDRESS */
82  /* ======================================================================= */
83  bool derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub) override;
85  std::vector<crypto::public_key> get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end) override;
88 
89  /* ======================================================================= */
90  /* DERIVATION & KEY */
91  /* ======================================================================= */
93  bool scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) override;
94  bool scalarmultBase(rct::key &aG, const rct::key &a) override;
95  bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) override;
96  crypto::secret_key generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false) override;
97  bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) override;
98  bool conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector<crypto::public_key> &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector<crypto::key_derivation> &additional_derivations) override;
99  bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) override;
100  bool derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) override;
101  bool derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub) override;
102  bool secret_key_to_public_key(const crypto::secret_key &sec, crypto::public_key &pub) override;
103  bool generate_key_image(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_image &image) override;
104 
105 
106  /* ======================================================================= */
107  /* TRANSACTION */
108  /* ======================================================================= */
109 
110  void generate_tx_proof(const crypto::hash &prefix_hash,
111  const crypto::public_key &R, const crypto::public_key &A, const boost::optional<crypto::public_key> &B, const crypto::public_key &D, const crypto::secret_key &r,
112  crypto::signature &sig) override;
113 
114  bool open_tx(crypto::secret_key &tx_key) override;
116 
118 
119  rct::key genCommitmentMask(const rct::key &amount_key) override;
120 
121  bool ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec, bool short_amount) override;
122  bool ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec, bool short_amount) override;
123 
124  bool generate_output_ephemeral_keys(const size_t tx_version, const cryptonote::account_keys &sender_account_keys, const crypto::public_key &txkey_pub, const crypto::secret_key &tx_key,
125  const cryptonote::tx_destination_entry &dst_entr, const boost::optional<cryptonote::account_public_address> &change_addr, const size_t output_index,
126  const bool &need_additional_txkeys, const std::vector<crypto::secret_key> &additional_tx_keys,
127  std::vector<crypto::public_key> &additional_tx_public_keys,
128  std::vector<rct::key> &amount_keys,
129  crypto::public_key &out_eph_public_key) override;
130 
131  bool mlsag_prehash(const std::string &blob, size_t inputs_size, size_t outputs_size, const rct::keyV &hashes, const rct::ctkeyV &outPk, rct::key &prehash) override;
132  bool mlsag_prepare(const rct::key &H, const rct::key &xx, rct::key &a, rct::key &aG, rct::key &aHP, rct::key &rvII) override;
133  bool mlsag_prepare(rct::key &a, rct::key &aG) override;
134  bool mlsag_hash(const rct::keyV &long_message, rct::key &c) override;
135  bool mlsag_sign(const rct::key &c, const rct::keyV &xx, const rct::keyV &alpha, const size_t rows, const size_t dsRows, rct::keyV &ss) override;
136 
137  bool clsag_prepare(const rct::key &p, const rct::key &z, rct::key &I, rct::key &D, const rct::key &H, rct::key &a, rct::key &aG, rct::key &aH) override;
138  bool clsag_hash(const rct::keyV &data, rct::key &hash) override;
139  bool clsag_sign(const rct::key &c, const rct::key &a, const rct::key &p, const rct::key &z, const rct::key &mu_P, const rct::key &mu_C, rct::key &s) override;
140 
141  bool close_tx(void) override;
142  };
143 
144  }
145 
146 
147 
148 }
149 
hw::core::device_default::generate_chacha_key
bool generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key, uint64_t kdf_rounds) override
Definition: device_default.cpp:103
hw::core::device_default::clsag_prepare
bool clsag_prepare(const rct::key &p, const rct::key &z, rct::key &I, rct::key &D, const rct::key &H, rct::key &a, rct::key &aG, rct::key &aH) override
Definition: device_default.cpp:405
hw::core::device_default::encrypt_payment_id
bool encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) override
Definition: device_default.cpp:340
hw::core::device_default::device_default
device_default()
Definition: device_default.cpp:46
hw::device::device_type
device_type
Definition: device.hpp:105
hw::core::device_default::mlsag_prehash
bool mlsag_prehash(const std::string &blob, size_t inputs_size, size_t outputs_size, const rct::keyV &hashes, const rct::ctkeyV &outPk, rct::key &prehash) override
Definition: device_default.cpp:383
cryptonote::tx_destination_entry
Definition: cryptonote_tx_utils.h:75
hw::core::device_default::derive_subaddress_public_key
bool derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub) override
Definition: device_default.cpp:123
cryptonote::subaddress_index
Definition: subaddress_index.h:39
hw::core::device_default::mlsag_hash
bool mlsag_hash(const rct::keyV &long_message, rct::key &c) override
Definition: device_default.cpp:389
rct::ecdhTuple
Definition: rctTypes.h:132
device.hpp
hw::core::device_default::scalarmultKey
bool scalarmultKey(rct::key &aP, const rct::key &P, const rct::key &a) override
Definition: device_default.cpp:220
rct::key
Definition: rctTypes.h:79
hw::core::device_default::unlock
void unlock(void) override
Definition: device_default.cpp:97
hw::core::device_default::scalarmultBase
bool scalarmultBase(rct::key &aG, const rct::key &a) override
Definition: device_default.cpp:225
base.B
list B
Definition: base.py:26
hw::core::device_default::derive_public_key
bool derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub) override
Definition: device_default.cpp:253
hw::core::device_default::mlsag_sign
bool mlsag_sign(const rct::key &c, const rct::keyV &xx, const rct::keyV &alpha, const size_t rows, const size_t dsRows, rct::keyV &ss) override
Definition: device_default.cpp:394
hw::core::device_default::connect
bool connect(void) override
Definition: device_default.cpp:78
hw::core::device_default::close_tx
bool close_tx(void) override
Definition: device_default.cpp:428
crypto::secret_key
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition: crypto.h:67
hw::core::device_default::sc_secret_add
bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) override
Definition: device_default.cpp:230
crypto::key_derivation
POD_CLASS key_derivation
Definition: crypto.h:83
hw::core::device_default::derivation_to_scalar
bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) override
Definition: device_default.cpp:243
hw::core::device_default::ecdhEncode
bool ecdhEncode(rct::ecdhTuple &unmasked, const rct::key &sharedSec, bool short_amount) override
Definition: device_default.cpp:362
hw::core::device_default::get_name
const std::string get_name() const override
Definition: device_default.cpp:67
s
#define s(x, c)
Definition: aesb.c:47
hw::core::device_default::clsag_hash
bool clsag_hash(const rct::keyV &data, rct::key &hash) override
Definition: device_default.cpp:413
hw::core::device_default::init
bool init(void) override
Definition: device_default.cpp:71
hw::core::device_default::open_tx
bool open_tx(crypto::secret_key &tx_key) override
Definition: device_default.cpp:279
crypto::ec_scalar
POD_CLASS ec_scalar
Definition: crypto.h:59
base.b
int b
Definition: base.py:1
hw::device::device_mode
device_mode
Definition: device.hpp:98
cryptonote::transaction_prefix
Definition: cryptonote_basic.h:160
rct::keyV
std::vector< key > keyV
Definition: rctTypes.h:89
hw::core::device_default::generate_keys
crypto::secret_key generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false) override
Definition: device_default.cpp:235
hw::core::device_default::ecdhDecode
bool ecdhDecode(rct::ecdhTuple &masked, const rct::key &sharedSec, bool short_amount) override
Definition: device_default.cpp:367
hw::core::device_default
Definition: device_default.hpp:40
hw::core::device_default::get_transaction_prefix_hash
void get_transaction_prefix_hash(const cryptonote::transaction_prefix &tx, crypto::hash &h) override
Definition: device_default.cpp:285
hw::core::device_default::conceal_derivation
bool conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector< crypto::public_key > &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector< crypto::key_derivation > &additional_derivations) override
Definition: device_default.cpp:266
cryptonote::account_keys
Definition: account.h:41
base.I
def I
Definition: base.py:15
hw::core::device_default::release
bool release() override
Definition: device_default.cpp:74
hw::device
Definition: device.hpp:87
hw::core::device_default::verify_keys
bool verify_keys(const crypto::secret_key &secret_key, const crypto::public_key &public_key) override
Definition: device_default.cpp:214
hw::device::mode
device_mode mode
Definition: device.hpp:249
hw::core::device_default::mlsag_prepare
bool mlsag_prepare(const rct::key &H, const rct::key &xx, rct::key &a, rct::key &aG, rct::key &aHP, rct::key &rvII) override
Definition: device_default.cpp:372
hw::core::device_default::try_lock
bool try_lock(void) override
Definition: device_default.cpp:95
rct::ctkeyV
std::vector< ctkey > ctkeyV
Definition: rctTypes.h:101
crypto::signature
POD_CLASS signature
Definition: crypto.h:93
hw::core::device_default::lock
void lock(void) override
Definition: device_default.cpp:93
crypto::public_key
POD_CLASS public_key
Definition: crypto.h:61
hw
Definition: device.cpp:38
bool
int bool
Definition: stdbool.h:35
hw::core::device_default::secret_key_to_public_key
bool secret_key_to_public_key(const crypto::secret_key &sec, crypto::public_key &pub) override
Definition: device_default.cpp:257
hw::core::device_default::get_subaddress_spend_public_keys
std::vector< crypto::public_key > get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end) override
Definition: device_default.cpp:143
cryptonote::account_public_address
Definition: cryptonote_basic.h:501
crypto::hash8
POD_CLASS hash8
Definition: hash.h:51
hw::core::device_default::generate_key_derivation
bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) override
Definition: device_default.cpp:239
hw::core::device_default::disconnect
bool disconnect() override
Definition: device_default.cpp:81
MakeCryptoOps.a
string a
Definition: MakeCryptoOps.py:15
hw::core::device_default::generate_output_ephemeral_keys
bool generate_output_ephemeral_keys(const size_t tx_version, const cryptonote::account_keys &sender_account_keys, const crypto::public_key &txkey_pub, const crypto::secret_key &tx_key, const cryptonote::tx_destination_entry &dst_entr, const boost::optional< cryptonote::account_public_address > &change_addr, const size_t output_index, const bool &need_additional_txkeys, const std::vector< crypto::secret_key > &additional_tx_keys, std::vector< crypto::public_key > &additional_tx_public_keys, std::vector< rct::key > &amount_keys, crypto::public_key &out_eph_public_key) override
Definition: device_default.cpp:289
hw::core::device_default::get_public_address
bool get_public_address(cryptonote::account_public_address &pubkey) override
Definition: device_default.cpp:113
hw::core::device_default::clsag_sign
bool clsag_sign(const rct::key &c, const rct::key &a, const rct::key &p, const rct::key &z, const rct::key &mu_P, const rct::key &mu_C, rct::key &s) override
Definition: device_default.cpp:418
crypto::rows
int rows
Definition: crypto.h:71
hw::core::device_default::get_secret_keys
bool get_secret_keys(crypto::secret_key &viewkey, crypto::secret_key &spendkey) override
Definition: device_default.cpp:116
hw::core::device_default::derive_secret_key
bool derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) override
Definition: device_default.cpp:248
hw::core::device_default::generate_tx_proof
void generate_tx_proof(const crypto::hash &prefix_hash, const crypto::public_key &R, const crypto::public_key &A, const boost::optional< crypto::public_key > &B, const crypto::public_key &D, const crypto::secret_key &r, crypto::signature &sig) override
Definition: device_default.cpp:273
hw::core::register_all
void register_all(std::map< std::string, std::unique_ptr< device >> &registry)
Definition: device_default.cpp:435
hw::core::device_default::operator=
device_default & operator=(const device_default &device)=delete
hw::core::device_default::get_subaddress_spend_public_key
crypto::public_key get_subaddress_spend_public_key(const cryptonote::account_keys &keys, const cryptonote::subaddress_index &index) override
Definition: device_default.cpp:127
hw::core::device_default::get_type
device_type get_type() const override
Definition: device_default.hpp:64
hw::core::device_default::~device_default
~device_default()
Definition: device_default.cpp:48
hw::core::device_default::get_subaddress_secret_key
crypto::secret_key get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index) override
Definition: device_default.cpp:197
crypto::key_image
POD_CLASS key_image
Definition: crypto.h:87
hw::core::device_default::device_default
device_default(const device_default &device)=delete
hw::core::device_default::set_mode
bool set_mode(device_mode mode) override
Definition: device_default.cpp:85
hw::core::device_default::get_subaddress
cryptonote::account_public_address get_subaddress(const cryptonote::account_keys &keys, const cryptonote::subaddress_index &index) override
Definition: device_default.cpp:181
hw::core::device_default::set_name
bool set_name(const std::string &name) override
Definition: device_default.cpp:63
hw::core::device_default::generate_key_image
bool generate_key_image(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_image &image) override
Definition: device_default.cpp:261
rct::H
static const key H
Definition: rctTypes.h:556
hw::device::name
std::string name
Definition: device.hpp:89
hw::core::device_default::genCommitmentMask
rct::key genCommitmentMask(const rct::key &amount_key) override
Definition: device_default.cpp:358
crypto::hash
POD_CLASS hash
Definition: hash.h:48