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 8
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
63 #define SW_WRONG_LENGTH 0x6700
64 #define SW_SECURITY_PIN_LOCKED 0x6910
65 #define SW_SECURITY_LOAD_KEY 0x6911
66 #define SW_SECURITY_COMMITMENT_CONTROL 0x6912
67 #define SW_SECURITY_AMOUNT_CHAIN_CONTROL 0x6913
68 #define SW_SECURITY_COMMITMENT_CHAIN_CONTROL 0x6914
69 #define SW_SECURITY_OUTKEYS_CHAIN_CONTROL 0x6915
70 #define SW_SECURITY_MAXOUTPUT_REACHED 0x6916
71 #define SW_SECURITY_HMAC 0x6917
72 #define SW_SECURITY_RANGE_VALUE 0x6918
73 #define SW_SECURITY_INTERNAL 0x6919
74 #define SW_SECURITY_MAX_SIGNATURE_REACHED 0x691A
75 #define SW_SECURITY_PREFIX_HASH 0x691B
76 #define SW_SECURITY_LOCKED 0x69EE
77 #define SW_COMMAND_NOT_ALLOWED 0x6980
78 #define SW_SUBCOMMAND_NOT_ALLOWED 0x6981
79 #define SW_DENY 0x6982
80 #define SW_KEY_NOT_SET 0x6983
81 #define SW_WRONG_DATA 0x6984
82 #define SW_WRONG_DATA_RANGE 0x6985
83 #define SW_IO_FULL 0x6986
84 #define SW_CLIENT_NOT_SUPPORTED 0x6A30
85 #define SW_WRONG_P1P2 0x6b00
86 #define SW_INS_NOT_SUPPORTED 0x6d00
87 #define SW_PROTOCOL_NOT_SUPPORTED 0x6e00
88 #define SW_UNKNOWN 0x6f00
91 bool apdu_verbose =
true;
94 void set_apdu_verbose(
bool verbose);
101 bool is_change_address;
102 bool additional_key ;
106 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);
107 ABPkeys(
const ABPkeys& keys) ;
108 ABPkeys() {index=0;is_subaddress=
false;is_change_address=
false;additional_key=
false;}
109 ABPkeys &operator=(
const ABPkeys &keys);
114 std::vector<ABPkeys> ABP;
116 bool find(
const rct::key& P, ABPkeys& keys)
const;
117 void add(
const ABPkeys& keys);
133 std::vector<SecHMAC> hmacs;
141 #define BUFFER_SEND_SIZE 262
142 #define BUFFER_RECV_SIZE 262
144 class device_ledger :
public hw::device {
147 mutable boost::recursive_mutex device_locker;
148 mutable boost::mutex command_locker;
151 hw::io::device_io_hid hw_device;
152 unsigned int length_send;
153 unsigned char buffer_send[BUFFER_SEND_SIZE];
154 unsigned int length_recv;
155 unsigned char buffer_recv[BUFFER_RECV_SIZE];
160 unsigned int exchange(
unsigned int ok=SW_OK,
unsigned int mask=0xFFFF);
161 unsigned int exchange_wait_on_input(
unsigned int ok=SW_OK,
unsigned int mask=0xFFFF);
162 void reset_buffer(
void);
163 int set_command_header(
unsigned char ins,
unsigned char p1 = 0x00,
unsigned char p2 = 0x00);
164 int set_command_header_noopt(
unsigned char ins,
unsigned char p1 = 0x00,
unsigned char p2 = 0x00);
165 void send_simple(
unsigned char ins,
unsigned char p1 = 0x00);
166 void send_secret(
const unsigned char sec[32],
int &offset);
167 void receive_secret(
unsigned char sec[32],
int &offset);
174 const bool need_additional,
const size_t real_output_index,
181 bool has_view_key =
false;
183 device *controle_device;
189 device_ledger(
const device_ledger &device) = delete ;
190 device_ledger& operator=(
const device_ledger &device) =
delete;
192 explicit operator bool()
const override {
return this->connected(); }
199 bool set_name(
const std::string &
name)
override;
201 const std::string get_name()
const override;
202 bool init(
void)
override;
204 bool connect(
void)
override;
205 bool disconnect()
override;
206 bool connected(
void)
const;
208 bool set_mode(device_mode
mode)
override;
210 device_type get_type()
const override {
return device_type::LEDGER;};
211 device_protocol_t device_protocol()
const override {
return PROTOCOL_PROXY; };
216 void lock(
void)
override;
217 void unlock(
void)
override;
218 bool try_lock(
void)
override;
223 bool get_public_address(cryptonote::account_public_address &pubkey)
override;
226 void display_address(
const cryptonote::subaddress_index& index,
const boost::optional<crypto::hash8> &payment_id)
override;
232 crypto::public_key get_subaddress_spend_public_key(
const cryptonote::account_keys& keys,
const cryptonote::subaddress_index& index)
override;
233 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;
234 cryptonote::account_public_address get_subaddress(
const cryptonote::account_keys& keys,
const cryptonote::subaddress_index &index)
override;
241 bool scalarmultKey(rct::key & aP,
const rct::key &P,
const rct::key &
a)
override;
269 bool ecdhEncode(rct::ecdhTuple & unmasked,
const rct::key & sharedSec,
bool short_format)
override;
270 bool ecdhDecode(rct::ecdhTuple & masked,
const rct::key & sharedSec,
bool short_format)
override;
273 const cryptonote::tx_destination_entry &dst_entr,
const boost::optional<cryptonote::account_public_address> &change_addr,
const size_t output_index,
274 const bool &need_additional_txkeys,
const std::vector<crypto::secret_key> &additional_tx_keys,
275 std::vector<crypto::public_key> &additional_tx_public_keys,
276 std::vector<rct::key> &amount_keys,
280 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;
281 bool mlsag_prepare(
const rct::key &H,
const rct::key &xx, rct::key &
a, rct::key &aG, rct::key &aHP, rct::key &rvII)
override;
282 bool mlsag_prepare(rct::key &
a, rct::key &aG)
override;
283 bool mlsag_hash(
const rct::keyV &long_message, rct::key &c)
override;
284 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;
286 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;
287 bool clsag_hash(
const rct::keyV &
data, rct::key &hash)
override;
288 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;
291 bool close_tx(
void)
override;
296 #ifdef DEBUG_HWDEVICE
#define s(x, c)
Definition aesb.c:47
cryptonote::block b
Definition block.cpp:40
static uint64_t h
Definition blockchain_stats.cpp:55
crypto::secret_key spendkey
Definition cold-outputs.cpp:44
const char * res
Definition hmac_keccak.cpp:42
const char * key
Definition hmac_keccak.cpp:40
static void log()
Definition logging.cpp:85
static void init()
Definition logging.cpp:42
static int mode
Definition mdb_dump.c:26
void derive_view_tag(const key_derivation &derivation, std::size_t output_index, view_tag &vt)
Definition crypto.h:312
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:263
POD_CLASS signature
Definition crypto.h:98
const crypto::secret_key null_skey
Definition crypto.cpp:75
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition crypto.h:72
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:246
POD_CLASS hash8
Definition hash.h:52
POD_CLASS key_derivation
Definition crypto.h:91
POD_CLASS view_tag
Definition crypto.h:103
secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key &recovery_key=secret_key(), bool recover=false)
Definition crypto.h:210
void derive_secret_key(const key_derivation &derivation, std::size_t output_index, const secret_key &base, secret_key &derived_key)
Definition crypto.h:242
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
Definition crypto.h:232
POD_CLASS public_key
Definition crypto.h:64
bool derive_public_key(const key_derivation &derivation, std::size_t output_index, const public_key &base, public_key &derived_key)
Definition crypto.h:235
POD_CLASS key_image
Definition crypto.h:95
POD_CLASS ec_scalar
Definition crypto.h:59
bool secret_key_to_public_key(const secret_key &sec, public_key &pub)
Definition crypto.h:222
POD_CLASS hash
Definition hash.h:49
int bool
Definition hash.h:36
void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res)
Definition crypto.h:239
void get_transaction_prefix_hash(const transaction_prefix &tx, crypto::hash &h, hw::device &hwdev)
Definition cryptonote_format_utils.cpp:131
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, const bool use_view_tags, crypto::view_tag &view_tag)
Definition device_ledger.cpp:42
void register_all(std::map< std::string, std::unique_ptr< device > > ®istry)
Definition device_ledger.cpp:2372
void scalarmultBase(key &aG, const key &a)
Definition rctOps.cpp:350
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:109
void ecdhDecode(ecdhTuple &masked, const key &sharedSec, bool v2)
Definition rctOps.cpp:713
key genCommitmentMask(const key &sk)
Definition rctOps.cpp:688
release(ctx, str device, version, git_tag, release_missing, dry_run, soon, force, add_all, verbose)
Definition support.py:316
const char * name
Definition options.c:30
enum upnpconfigoptions id
Definition options.c:29
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
cryptonote::simple_wallet sw
Definition simplewallet.cpp:95
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
std::string data
Definition base58.cpp:37
struct hash_func hashes[]
static crypto::chacha_key generate_chacha_key()
Definition ringdb.cpp:47
static crypto::key_image generate_key_image()
Definition ringdb.cpp:55
cryptonote::transaction tx
Definition transaction.cpp:40