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 6
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 #define SW_BYTES_REMAINING_00 0x6100
63 #define SW_WARNING_STATE_UNCHANGED 0x6200
64 #define SW_STATE_TERMINATED 0x6285
65 #define SW_MORE_DATA_AVAILABLE 0x6310
66 #define SW_WRONG_LENGTH 0x6700
67 #define SW_LOGICAL_CHANNEL_NOT_SUPPORTED 0x6881
68 #define SW_SECURE_MESSAGING_NOT_SUPPORTED 0x6882
69 #define SW_LAST_COMMAND_EXPECTED 0x6883
70 #define SW_COMMAND_CHAINING_NOT_SUPPORTED 0x6884
71 #define SW_SECURITY_LOAD_KEY 0x6900
72 #define SW_SECURITY_COMMITMENT_CONTROL 0x6911
73 #define SW_SECURITY_AMOUNT_CHAIN_CONTROL 0x6912
74 #define SW_SECURITY_COMMITMENT_CHAIN_CONTROL 0x6913
75 #define SW_SECURITY_OUTKEYS_CHAIN_CONTROL 0x6914
76 #define SW_SECURITY_MAXOUTPUT_REACHED 0x6915
77 #define SW_SECURITY_TRUSTED_INPUT 0x6916
78 #define SW_CLIENT_NOT_SUPPORTED 0x6930
79 #define SW_SECURITY_STATUS_NOT_SATISFIED 0x6982
80 #define SW_FILE_INVALID 0x6983
81 #define SW_PIN_BLOCKED 0x6983
82 #define SW_DATA_INVALID 0x6984
83 #define SW_CONDITIONS_NOT_SATISFIED 0x6985
84 #define SW_COMMAND_NOT_ALLOWED 0x6986
85 #define SW_APPLET_SELECT_FAILED 0x6999
86 #define SW_WRONG_DATA 0x6a80
87 #define SW_FUNC_NOT_SUPPORTED 0x6a81
88 #define SW_FILE_NOT_FOUND 0x6a82
89 #define SW_RECORD_NOT_FOUND 0x6a83
90 #define SW_FILE_FULL 0x6a84
91 #define SW_INCORRECT_P1P2 0x6a86
92 #define SW_REFERENCED_DATA_NOT_FOUND 0x6a88
93 #define SW_WRONG_P1P2 0x6b00
94 #define SW_CORRECT_LENGTH_00 0x6c00
95 #define SW_INS_NOT_SUPPORTED 0x6d00
96 #define SW_CLA_NOT_SUPPORTED 0x6e00
97 #define SW_UNKNOWN 0x6f00
99 #define SW_ALGORITHM_UNSUPPORTED 0x9484
102 bool apdu_verbose =
true;
105 void set_apdu_verbose(
bool verbose);
112 bool is_change_address;
113 bool additional_key ;
117 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);
118 ABPkeys(
const ABPkeys& keys) ;
119 ABPkeys() {index=0;is_subaddress=
false;is_change_address=
false;additional_key=
false;}
120 ABPkeys &operator=(
const ABPkeys &keys);
125 std::vector<ABPkeys> ABP;
127 bool find(
const rct::key& P, ABPkeys& keys)
const;
128 void add(
const ABPkeys& keys);
138 SecHMAC(
const uint8_t
s[32],
const uint8_t m[32]);
144 std::vector<SecHMAC> hmacs;
146 void find_mac(
const uint8_t sec[32], uint8_t hmac[32]) ;
147 void add_mac(
const uint8_t sec[32],
const uint8_t hmac[32]) ;
152 #define BUFFER_SEND_SIZE 262
153 #define BUFFER_RECV_SIZE 262
158 mutable boost::recursive_mutex device_locker;
159 mutable boost::mutex command_locker;
162 hw::io::device_io_hid hw_device;
163 unsigned int length_send;
164 unsigned char buffer_send[BUFFER_SEND_SIZE];
165 unsigned int length_recv;
166 unsigned char buffer_recv[BUFFER_RECV_SIZE];
171 unsigned int exchange(
unsigned int ok=SW_OK,
unsigned int mask=0xFFFF);
172 unsigned int exchange_wait_on_input(
unsigned int ok=SW_OK,
unsigned int mask=0xFFFF);
173 void reset_buffer(
void);
174 int set_command_header(
unsigned char ins,
unsigned char p1 = 0x00,
unsigned char p2 = 0x00);
175 int set_command_header_noopt(
unsigned char ins,
unsigned char p1 = 0x00,
unsigned char p2 = 0x00);
176 void send_simple(
unsigned char ins,
unsigned char p1 = 0x00);
177 void send_secret(
const unsigned char sec[32],
int &offset);
178 void receive_secret(
unsigned char sec[32],
int &offset);
187 const bool need_additional,
const size_t real_output_index,
197 #ifdef DEBUG_HWDEVICE
198 device *controle_device;
205 device_ledger(
const device_ledger &device) = delete ;
206 device_ledger& operator=(
const device_ledger &device) =
delete;
208 explicit operator bool()
const override {
return this->connected(); }
215 bool set_name(
const std::string &
name)
override;
217 const std::string get_name()
const override;
218 bool init(
void)
override;
219 bool release()
override;
220 bool connect(
void)
override;
221 bool disconnect()
override;
222 bool connected(
void)
const;
224 bool set_mode(device_mode mode)
override;
226 device_type get_type()
const override {
return device_type::LEDGER;};
227 device_protocol_t device_protocol()
const override {
return PROTOCOL_PROXY; };
232 void lock(
void)
override;
233 void unlock(
void)
override;
234 bool try_lock(
void)
override;
241 bool generate_chacha_key(
const cryptonote::account_keys &keys, crypto::chacha_key &key, uint64_t kdf_rounds)
override;
249 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;
289 const bool &need_additional_txkeys,
const std::vector<crypto::secret_key> &additional_tx_keys,
290 std::vector<crypto::public_key> &additional_tx_public_keys,
291 std::vector<rct::key> &amount_keys,
294 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;
305 bool close_tx(
void)
override;
310 #ifdef DEBUG_HWDEVICE
#define s(x, c)
Definition: aesb.c:47
static void init(std::string cache_filename)
Definition: blockchain_blackball.cpp:221
Definition: cryptonote_basic.h:160
Definition: device.hpp:87
string a
Definition: MakeCryptoOps.py:15
const char * name
Definition: simplewallet.cpp:417
list B
Definition: base.py:26
def I
Definition: base.py:15
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:250
POD_CLASS signature
Definition: crypto.h:93
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition: crypto.h:67
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:233
POD_CLASS hash8
Definition: hash.h:51
POD_CLASS key_derivation
Definition: crypto.h:83
secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key &recovery_key=secret_key(), bool recover=false)
Definition: crypto.h:197
void derive_secret_key(const key_derivation &derivation, std::size_t output_index, const secret_key &base, secret_key &derived_key)
Definition: crypto.h:229
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
Definition: crypto.h:219
POD_CLASS public_key
Definition: crypto.h:61
bool derive_public_key(const key_derivation &derivation, std::size_t output_index, const public_key &base, public_key &derived_key)
Definition: crypto.h:222
POD_CLASS key_image
Definition: crypto.h:87
POD_CLASS ec_scalar
Definition: crypto.h:59
bool secret_key_to_public_key(const secret_key &sec, public_key &pub)
Definition: crypto.h:209
int rows
Definition: crypto.h:71
POD_CLASS hash
Definition: hash.h:48
void generate_key_image(const public_key &pub, const secret_key &sec, key_image &image)
Definition: crypto.h:266
void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res)
Definition: crypto.h:226
void get_transaction_prefix_hash(const transaction_prefix &tx, crypto::hash &h, hw::device &hwdev)
Definition: cryptonote_format_utils.cpp:129
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:2301
Definition: device.cpp:38
void scalarmultBase(key &aG, const key &a)
Definition: rctOps.cpp:350
static const key H
Definition: rctTypes.h:556
void ecdhEncode(ecdhTuple &unmasked, const key &sharedSec, bool v2)
Definition: rctOps.cpp:698
std::vector< key > keyV
Definition: rctTypes.h:89
void scalarmultKey(key &aP, const key &P, const key &a)
Definition: rctOps.cpp:368
std::vector< ctkey > ctkeyV
Definition: rctTypes.h:101
void ecdhDecode(ecdhTuple &masked, const key &sharedSec, bool v2)
Definition: rctOps.cpp:713
static void add(ge_p3 &p3, const ge_cached &other)
Definition: multiexp.cc:143
key genCommitmentMask(const key &sk)
Definition: rctOps.cpp:688
cryptonote::simple_wallet sw
Definition: simplewallet.cpp:94
int bool
Definition: stdbool.h:35
Definition: cryptonote_basic.h:501
Definition: subaddress_index.h:39
Definition: cryptonote_tx_utils.h:75
Definition: rctTypes.h:132
Definition: rctTypes.h:79