38 #include <boost/thread/mutex.hpp>
39 #include <boost/thread/recursive_mutex.hpp>
46 #define MINIMAL_APP_VERSION_MAJOR 1
47 #define MINIMAL_APP_VERSION_MINOR 0
48 #define MINIMAL_APP_VERSION_MICRO 0
50 #define VERSION(M,m,u) ((M)<<16|(m)<<8|(u))
51 #define VERSION_MAJOR(v) (((v)>>16)&0xFF)
52 #define VERSION_MINOR(v) (((v)>>8)&0xFF)
53 #define VERSION_MICRO(v) (((v)>>0)&0xFF)
55 #define MINIMAL_APP_VERSION VERSION(MINIMAL_APP_VERSION_MAJOR, MINIMAL_APP_VERSION_MINOR, MINIMAL_APP_VERSION_MICRO)
57 void register_all(std::map<std::string, std::unique_ptr<device>> ®istry);
59 #ifdef WITH_DEVICE_LEDGER
62 bool apdu_verbose =
true;
65 void set_apdu_verbose(
bool verbose);
72 bool is_change_address;
77 ABPkeys(
const rct::key& A,
const rct::key&
B,
const bool is_subaddr,
bool is_subaddress,
bool is_change_address,
size_t index,
const rct::key& P,
const rct::key& AK);
78 ABPkeys(
const ABPkeys& keys) ;
79 ABPkeys() {index=0;is_subaddress=
false;is_change_address=
false;additional_key=
false;}
80 ABPkeys &operator=(
const ABPkeys &keys);
85 std::vector<ABPkeys> ABP;
87 bool find(
const rct::key& P, ABPkeys& keys)
const;
88 void add(
const ABPkeys& keys);
98 SecHMAC(
const uint8_t
s[32],
const uint8_t m[32]);
104 std::vector<SecHMAC> hmacs;
106 void find_mac(
const uint8_t sec[32], uint8_t hmac[32]) ;
107 void add_mac(
const uint8_t sec[32],
const uint8_t hmac[32]) ;
112 #define BUFFER_SEND_SIZE 262
113 #define BUFFER_RECV_SIZE 262
118 mutable boost::recursive_mutex device_locker;
119 mutable boost::mutex command_locker;
122 hw::io::device_io_hid hw_device;
123 unsigned int length_send;
124 unsigned char buffer_send[BUFFER_SEND_SIZE];
125 unsigned int length_recv;
126 unsigned char buffer_recv[BUFFER_RECV_SIZE];
131 unsigned int exchange(
unsigned int ok=0x9000,
unsigned int mask=0xFFFF);
132 unsigned int exchange_wait_on_input(
unsigned int ok=0x9000,
unsigned int mask=0xFFFF);
133 void reset_buffer(
void);
134 int set_command_header(
unsigned char ins,
unsigned char p1 = 0x00,
unsigned char p2 = 0x00);
135 int set_command_header_noopt(
unsigned char ins,
unsigned char p1 = 0x00,
unsigned char p2 = 0x00);
136 void send_simple(
unsigned char ins,
unsigned char p1 = 0x00);
137 void send_secret(
const unsigned char sec[32],
int &offset);
138 void receive_secret(
unsigned char sec[32],
int &offset);
147 const bool need_additional,
const size_t real_output_index,
157 #ifdef DEBUG_HWDEVICE
158 device *controle_device;
165 device_ledger(
const device_ledger &device) = delete ;
166 device_ledger& operator=(
const device_ledger &device) =
delete;
168 explicit operator bool()
const override {
return this->connected(); }
175 bool set_name(
const std::string &
name)
override;
177 const std::string get_name()
const override;
178 bool init(
void)
override;
179 bool release()
override;
180 bool connect(
void)
override;
181 bool disconnect()
override;
182 bool connected(
void)
const;
184 bool set_mode(device_mode mode)
override;
186 device_type get_type()
const override {
return device_type::LEDGER;};
187 device_protocol_t device_protocol()
const override {
return PROTOCOL_PROXY; };
192 void lock(
void)
override;
193 void unlock(
void)
override;
194 bool try_lock(
void)
override;
201 bool generate_chacha_key(
const cryptonote::account_keys &keys, crypto::chacha_key &key, uint64_t kdf_rounds)
override;
209 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;
249 const bool &need_additional_txkeys,
const std::vector<crypto::secret_key> &additional_tx_keys,
250 std::vector<crypto::public_key> &additional_tx_public_keys,
251 std::vector<rct::key> &amount_keys,
254 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;
260 bool close_tx(
void)
override;
264 const std::vector<const crypto::public_key *> &pubsvector,
272 #ifdef DEBUG_HWDEVICE
#define s(x, c)
Definition: aesb.c:47
static void init(std::string cache_filename)
Definition: blockchain_blackball.cpp:224
Definition: cryptonote_basic.h:171
Definition: device.hpp:87
string a
Definition: MakeCryptoOps.py:15
const char * name
Definition: simplewallet.cpp:400
list B
Definition: base.py:26
int q
Definition: base.py:2
int b
Definition: base.py:1
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)
Definition: crypto.h:291
POD_CLASS signature
Definition: crypto.h:108
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition: crypto.h:82
bool derive_subaddress_public_key(const public_key &out_key, const key_derivation &derivation, std::size_t output_index, public_key &result)
Definition: crypto.h:274
POD_CLASS hash8
Definition: hash.h:53
POD_CLASS key_derivation
Definition: crypto.h:98
secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key &recovery_key=secret_key(), bool recover=false)
Definition: crypto.h:238
void derive_secret_key(const key_derivation &derivation, std::size_t output_index, const secret_key &base, secret_key &derived_key)
Definition: crypto.h:270
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
Definition: crypto.h:260
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:307
POD_CLASS public_key
Definition: crypto.h:76
bool derive_public_key(const key_derivation &derivation, std::size_t output_index, const public_key &base, public_key &derived_key)
Definition: crypto.h:263
POD_CLASS key_image
Definition: crypto.h:102
POD_CLASS ec_scalar
Definition: crypto.h:74
bool secret_key_to_public_key(const secret_key &sec, public_key &pub)
Definition: crypto.h:250
void hash_to_scalar(const void *data, size_t length, ec_scalar &res)
Definition: crypto.cpp:126
int rows
Definition: crypto.h:86
POD_CLASS hash
Definition: hash.h:50
void generate_key_image(const public_key &pub, const secret_key &sec, key_image &image)
Definition: crypto.h:304
void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res)
Definition: crypto.h:267
void get_transaction_prefix_hash(const transaction_prefix &tx, crypto::hash &h)
Definition: cryptonote_format_utils.cpp:112
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)
void register_all(std::map< std::string, std::unique_ptr< device >> ®istry)
Definition: device_ledger.cpp:2345
Definition: device.cpp:38
void scalarmultBase(key &aG, const key &a)
Definition: rctOps.cpp:350
static const key H
Definition: rctTypes.h:451
void ecdhEncode(ecdhTuple &unmasked, const key &sharedSec, bool v2)
Definition: rctOps.cpp:697
std::vector< key > keyV
Definition: rctTypes.h:88
void scalarmultKey(key &aP, const key &P, const key &a)
Definition: rctOps.cpp:368
std::vector< ctkey > ctkeyV
Definition: rctTypes.h:100
void ecdhDecode(ecdhTuple &masked, const key &sharedSec, bool v2)
Definition: rctOps.cpp:712
static void add(ge_p3 &p3, const ge_cached &other)
Definition: multiexp.cc:143
key genCommitmentMask(const key &sk)
Definition: rctOps.cpp:687
cryptonote::simple_wallet sw
Definition: simplewallet.cpp:90
int bool
Definition: stdbool.h:36
Definition: cryptonote_basic.h:453
Definition: subaddress_index.h:39
Definition: cryptonote_tx_utils.h:76
Definition: rctTypes.h:124
Definition: rctTypes.h:78