device_ledger: factor the prologue code
This commit is contained in:
parent
896512b2b6
commit
87e158b5b9
@ -272,22 +272,32 @@ namespace hw {
|
|||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* MISC */
|
/* MISC */
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
bool device_ledger::reset() {
|
int device_ledger::set_command_header(BYTE ins, BYTE p1, BYTE p2) {
|
||||||
int offset;
|
|
||||||
reset_buffer();
|
reset_buffer();
|
||||||
|
int offset = 0;
|
||||||
this->buffer_send[0] = 0x00;
|
this->buffer_send[0] = 0x00;
|
||||||
this->buffer_send[1] = INS_RESET;
|
this->buffer_send[1] = ins;
|
||||||
this->buffer_send[2] = 0x00;
|
this->buffer_send[2] = p1;
|
||||||
this->buffer_send[3] = 0x00;
|
this->buffer_send[3] = p2;
|
||||||
this->buffer_send[4] = 0x00;
|
this->buffer_send[4] = 0x00;
|
||||||
offset = 5;
|
return 5;
|
||||||
//options
|
}
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
|
|
||||||
|
int device_ledger::set_command_header_noopt(BYTE ins, BYTE p1, BYTE p2) {
|
||||||
|
int offset = set_command_header(ins, p1, p2);
|
||||||
|
//options
|
||||||
|
this->buffer_send[offset++] = 0;
|
||||||
this->buffer_send[4] = offset - 5;
|
this->buffer_send[4] = offset - 5;
|
||||||
this->length_send = offset;
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void device_ledger::send_simple(BYTE ins, BYTE p1) {
|
||||||
|
this->length_send = set_command_header_noopt(ins, p1);
|
||||||
this->exchange();
|
this->exchange();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool device_ledger::reset() {
|
||||||
|
send_simple(INS_RESET);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,20 +458,10 @@ namespace hw {
|
|||||||
|
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
reset_buffer();
|
|
||||||
|
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
case TRANSACTION_CREATE_REAL:
|
case TRANSACTION_CREATE_REAL:
|
||||||
case TRANSACTION_CREATE_FAKE:
|
case TRANSACTION_CREATE_FAKE:
|
||||||
this->buffer_send[0] = 0x00;
|
offset = set_command_header_noopt(INS_SET_SIGNATURE_MODE, 1);
|
||||||
this->buffer_send[1] = INS_SET_SIGNATURE_MODE;
|
|
||||||
this->buffer_send[2] = 0x01;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
//account
|
//account
|
||||||
this->buffer_send[offset] = mode;
|
this->buffer_send[offset] = mode;
|
||||||
offset += 1;
|
offset += 1;
|
||||||
@ -492,22 +492,7 @@ namespace hw {
|
|||||||
bool device_ledger::get_public_address(cryptonote::account_public_address &pubkey){
|
bool device_ledger::get_public_address(cryptonote::account_public_address &pubkey){
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
|
|
||||||
int offset;
|
send_simple(INS_GET_KEY, 1);
|
||||||
reset_buffer();
|
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_GET_KEY;
|
|
||||||
this->buffer_send[2] = 0x01;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
|
|
||||||
this->buffer_send[4] = offset-5;
|
|
||||||
this->length_send = offset;
|
|
||||||
this->exchange();
|
|
||||||
|
|
||||||
memmove(pubkey.m_view_public_key.data, this->buffer_recv, 32);
|
memmove(pubkey.m_view_public_key.data, this->buffer_recv, 32);
|
||||||
memmove(pubkey.m_spend_public_key.data, this->buffer_recv+32, 32);
|
memmove(pubkey.m_spend_public_key.data, this->buffer_recv+32, 32);
|
||||||
@ -523,22 +508,7 @@ namespace hw {
|
|||||||
memset(skey.data, 0xFF, 32);
|
memset(skey.data, 0xFF, 32);
|
||||||
|
|
||||||
//spcialkey, normal conf handled in decrypt
|
//spcialkey, normal conf handled in decrypt
|
||||||
int offset;
|
send_simple(INS_GET_KEY, 0x02);
|
||||||
reset_buffer();
|
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_GET_KEY;
|
|
||||||
this->buffer_send[2] = 0x02;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
|
|
||||||
this->buffer_send[4] = offset-5;
|
|
||||||
this->length_send = offset;
|
|
||||||
this->exchange();
|
|
||||||
|
|
||||||
//View key is retrievied, if allowed, to speed up blockchain parsing
|
//View key is retrievied, if allowed, to speed up blockchain parsing
|
||||||
memmove(this->viewkey.data, this->buffer_recv+0, 32);
|
memmove(this->viewkey.data, this->buffer_recv+0, 32);
|
||||||
@ -560,7 +530,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) {
|
bool device_ledger::generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
crypto::chacha_key key_x;
|
crypto::chacha_key key_x;
|
||||||
@ -568,20 +537,7 @@ namespace hw {
|
|||||||
this->controle_device->generate_chacha_key(keys_x, key_x);
|
this->controle_device->generate_chacha_key(keys_x, key_x);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
send_simple(INS_GET_CHACHA8_PREKEY);
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_GET_CHACHA8_PREKEY;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
|
|
||||||
this->buffer_send[4] = offset-5;
|
|
||||||
this->length_send = offset;
|
|
||||||
this->exchange();
|
|
||||||
|
|
||||||
char prekey[200];
|
char prekey[200];
|
||||||
memmove(prekey, &this->buffer_recv[0], 200);
|
memmove(prekey, &this->buffer_recv[0], 200);
|
||||||
@ -624,19 +580,7 @@ namespace hw {
|
|||||||
crypto::derive_subaddress_public_key(pub, derivation, output_index,derived_pub);
|
crypto::derive_subaddress_public_key(pub, derivation, output_index,derived_pub);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
int offset =0;
|
int offset = set_command_header_noopt(INS_DERIVE_SUBADDRESS_PUBLIC_KEY);
|
||||||
|
|
||||||
reset_buffer();
|
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_DERIVE_SUBADDRESS_PUBLIC_KEY;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//pub
|
//pub
|
||||||
memmove(this->buffer_send+offset, pub.data, 32);
|
memmove(this->buffer_send+offset, pub.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -667,7 +611,6 @@ namespace hw {
|
|||||||
crypto::public_key device_ledger::get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) {
|
crypto::public_key device_ledger::get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
crypto::public_key D;
|
crypto::public_key D;
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const cryptonote::account_keys keys_x = hw::ledger::decrypt(keys);
|
const cryptonote::account_keys keys_x = hw::ledger::decrypt(keys);
|
||||||
@ -684,17 +627,7 @@ namespace hw {
|
|||||||
D = keys.m_account_address.m_spend_public_key;
|
D = keys.m_account_address.m_spend_public_key;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_GET_SUBADDRESS_SPEND_PUBLIC_KEY);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_GET_SUBADDRESS_SPEND_PUBLIC_KEY;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
//index
|
//index
|
||||||
static_assert(sizeof(cryptonote::subaddress_index) == 8, "cryptonote::subaddress_index shall be 8 bytes length");
|
static_assert(sizeof(cryptonote::subaddress_index) == 8, "cryptonote::subaddress_index shall be 8 bytes length");
|
||||||
memmove(this->buffer_send+offset, &index, sizeof(cryptonote::subaddress_index));
|
memmove(this->buffer_send+offset, &index, sizeof(cryptonote::subaddress_index));
|
||||||
@ -729,7 +662,6 @@ namespace hw {
|
|||||||
cryptonote::account_public_address device_ledger::get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) {
|
cryptonote::account_public_address device_ledger::get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
cryptonote::account_public_address address;
|
cryptonote::account_public_address address;
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const cryptonote::account_keys keys_x = hw::ledger::decrypt(keys);
|
const cryptonote::account_keys keys_x = hw::ledger::decrypt(keys);
|
||||||
@ -748,17 +680,7 @@ namespace hw {
|
|||||||
if (index.is_zero()) {
|
if (index.is_zero()) {
|
||||||
address = keys.m_account_address;
|
address = keys.m_account_address;
|
||||||
} else {
|
} else {
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_GET_SUBADDRESS);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_GET_SUBADDRESS;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
//index
|
//index
|
||||||
static_assert(sizeof(cryptonote::subaddress_index) == 8, "cryptonote::subaddress_index shall be 8 bytes length");
|
static_assert(sizeof(cryptonote::subaddress_index) == 8, "cryptonote::subaddress_index shall be 8 bytes length");
|
||||||
memmove(this->buffer_send+offset, &index, sizeof(cryptonote::subaddress_index));
|
memmove(this->buffer_send+offset, &index, sizeof(cryptonote::subaddress_index));
|
||||||
@ -783,7 +705,6 @@ namespace hw {
|
|||||||
crypto::secret_key device_ledger::get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index) {
|
crypto::secret_key device_ledger::get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
crypto::secret_key sub_sec;
|
crypto::secret_key sub_sec;
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
|
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
|
||||||
@ -795,17 +716,7 @@ namespace hw {
|
|||||||
hw::ledger::log_hexbuffer("get_subaddress_secret_key: [[OUT]] sub_sec", sub_sec_x.data, 32);
|
hw::ledger::log_hexbuffer("get_subaddress_secret_key: [[OUT]] sub_sec", sub_sec_x.data, 32);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_GET_SUBADDRESS_SECRET_KEY);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_GET_SUBADDRESS_SECRET_KEY;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//sec
|
//sec
|
||||||
memmove(this->buffer_send+offset, sec.data, 32);
|
memmove(this->buffer_send+offset, sec.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -836,16 +747,7 @@ namespace hw {
|
|||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset, sw;
|
int offset, sw;
|
||||||
|
|
||||||
reset_buffer();
|
offset = set_command_header_noopt(INS_VERIFY_KEY);
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_VERIFY_KEY;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
//sec
|
//sec
|
||||||
memmove(this->buffer_send+offset, secret_key.data, 32);
|
memmove(this->buffer_send+offset, secret_key.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -868,7 +770,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) {
|
bool device_ledger::scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const rct::key P_x = P;
|
const rct::key P_x = P;
|
||||||
@ -880,17 +781,7 @@ namespace hw {
|
|||||||
hw::ledger::log_hexbuffer("scalarmultKey: [[OUT]] aP", (char*)aP_x.bytes, 32);
|
hw::ledger::log_hexbuffer("scalarmultKey: [[OUT]] aP", (char*)aP_x.bytes, 32);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_SECRET_SCAL_MUL_KEY);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_SECRET_SCAL_MUL_KEY;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//pub
|
//pub
|
||||||
memmove(this->buffer_send+offset, P.bytes, 32);
|
memmove(this->buffer_send+offset, P.bytes, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -915,7 +806,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::scalarmultBase(rct::key &aG, const rct::key &a) {
|
bool device_ledger::scalarmultBase(rct::key &aG, const rct::key &a) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const rct::key a_x = hw::ledger::decrypt(a);
|
const rct::key a_x = hw::ledger::decrypt(a);
|
||||||
@ -925,17 +815,7 @@ namespace hw {
|
|||||||
hw::ledger::log_hexbuffer("scalarmultKey: [[OUT]] aG", (char*)aG_x.bytes, 32);
|
hw::ledger::log_hexbuffer("scalarmultKey: [[OUT]] aG", (char*)aG_x.bytes, 32);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_SECRET_SCAL_MUL_BASE);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_SECRET_SCAL_MUL_BASE;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//sec
|
//sec
|
||||||
memmove(this->buffer_send+offset, a.bytes, 32);
|
memmove(this->buffer_send+offset, a.bytes, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -956,7 +836,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::sc_secret_add( crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) {
|
bool device_ledger::sc_secret_add( crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const crypto::secret_key a_x = hw::ledger::decrypt(a);
|
const crypto::secret_key a_x = hw::ledger::decrypt(a);
|
||||||
@ -965,17 +844,7 @@ namespace hw {
|
|||||||
this->controle_device->sc_secret_add(r_x, a_x, b_x);
|
this->controle_device->sc_secret_add(r_x, a_x, b_x);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_SECRET_KEY_ADD);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_SECRET_KEY_ADD;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//sec key
|
//sec key
|
||||||
memmove(this->buffer_send+offset, a.data, 32);
|
memmove(this->buffer_send+offset, a.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1004,8 +873,6 @@ namespace hw {
|
|||||||
throw std::runtime_error("device generate key does not support recover");
|
throw std::runtime_error("device generate key does not support recover");
|
||||||
}
|
}
|
||||||
|
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
bool recover_x = recover;
|
bool recover_x = recover;
|
||||||
const crypto::secret_key recovery_key_x = recovery_key;
|
const crypto::secret_key recovery_key_x = recovery_key;
|
||||||
@ -1013,21 +880,7 @@ namespace hw {
|
|||||||
crypto::secret_key sec_x;
|
crypto::secret_key sec_x;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
send_simple(INS_GENERATE_KEYPAIR);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_GENERATE_KEYPAIR;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
|
|
||||||
this->buffer_send[4] = offset-5;
|
|
||||||
this->length_send = offset;
|
|
||||||
this->exchange();
|
|
||||||
|
|
||||||
//pub key
|
//pub key
|
||||||
memmove(pub.data, &this->buffer_recv[0], 32);
|
memmove(pub.data, &this->buffer_recv[0], 32);
|
||||||
@ -1067,19 +920,7 @@ namespace hw {
|
|||||||
r = crypto::generate_key_derivation(pub, this->viewkey, derivation);
|
r = crypto::generate_key_derivation(pub, this->viewkey, derivation);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
int offset;
|
int offset = set_command_header_noopt(INS_GEN_KEY_DERIVATION);
|
||||||
|
|
||||||
reset_buffer();
|
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_GEN_KEY_DERIVATION;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//pub
|
//pub
|
||||||
memmove(this->buffer_send+offset, pub.data, 32);
|
memmove(this->buffer_send+offset, pub.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1128,7 +969,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) {
|
bool device_ledger::derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const crypto::key_derivation derivation_x = hw::ledger::decrypt(derivation);
|
const crypto::key_derivation derivation_x = hw::ledger::decrypt(derivation);
|
||||||
@ -1140,17 +980,7 @@ namespace hw {
|
|||||||
hw::ledger::log_hexbuffer("derivation_to_scalar: [[OUT]] res ", res_x.data, 32);
|
hw::ledger::log_hexbuffer("derivation_to_scalar: [[OUT]] res ", res_x.data, 32);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_DERIVATION_TO_SCALAR);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_DERIVATION_TO_SCALAR;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//derivattion
|
//derivattion
|
||||||
memmove(this->buffer_send+offset, derivation.data, 32);
|
memmove(this->buffer_send+offset, derivation.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1178,7 +1008,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) {
|
bool device_ledger::derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const crypto::key_derivation derivation_x = hw::ledger::decrypt(derivation);
|
const crypto::key_derivation derivation_x = hw::ledger::decrypt(derivation);
|
||||||
@ -1192,17 +1021,7 @@ namespace hw {
|
|||||||
hw::ledger::log_hexbuffer("derive_secret_key: [[OUT]] derived_sec", derived_sec_x.data, 32);
|
hw::ledger::log_hexbuffer("derive_secret_key: [[OUT]] derived_sec", derived_sec_x.data, 32);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_DERIVE_SECRET_KEY);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_DERIVE_SECRET_KEY;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//derivation
|
//derivation
|
||||||
memmove(this->buffer_send+offset, derivation.data, 32);
|
memmove(this->buffer_send+offset, derivation.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1233,7 +1052,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub){
|
bool device_ledger::derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub){
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const crypto::key_derivation derivation_x = hw::ledger::decrypt(derivation);
|
const crypto::key_derivation derivation_x = hw::ledger::decrypt(derivation);
|
||||||
@ -1247,17 +1065,7 @@ namespace hw {
|
|||||||
hw::ledger::log_hexbuffer("derive_public_key: [[OUT]] derived_pub ", derived_pub_x.data, 32);
|
hw::ledger::log_hexbuffer("derive_public_key: [[OUT]] derived_pub ", derived_pub_x.data, 32);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_DERIVE_PUBLIC_KEY);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_DERIVE_PUBLIC_KEY;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//derivation
|
//derivation
|
||||||
memmove(this->buffer_send+offset, derivation.data, 32);
|
memmove(this->buffer_send+offset, derivation.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1287,7 +1095,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::secret_key_to_public_key(const crypto::secret_key &sec, crypto::public_key &pub) {
|
bool device_ledger::secret_key_to_public_key(const crypto::secret_key &sec, crypto::public_key &pub) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
|
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
|
||||||
@ -1300,17 +1107,7 @@ namespace hw {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_SECRET_KEY_TO_PUBLIC_KEY);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_SECRET_KEY_TO_PUBLIC_KEY;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//sec key
|
//sec key
|
||||||
memmove(this->buffer_send+offset, sec.data, 32);
|
memmove(this->buffer_send+offset, sec.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1331,7 +1128,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::generate_key_image(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_image &image){
|
bool device_ledger::generate_key_image(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_image &image){
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const crypto::public_key pub_x = pub;
|
const crypto::public_key pub_x = pub;
|
||||||
@ -1343,17 +1139,7 @@ namespace hw {
|
|||||||
hw::ledger::log_hexbuffer("generate_key_image: [[OUT]] image ", image_x.data, 32);
|
hw::ledger::log_hexbuffer("generate_key_image: [[OUT]] image ", image_x.data, 32);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_GEN_KEY_IMAGE);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_GEN_KEY_IMAGE;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0;
|
|
||||||
offset += 1;
|
|
||||||
//pub
|
//pub
|
||||||
memmove(this->buffer_send+offset, pub.data, 32);
|
memmove(this->buffer_send+offset, pub.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1381,20 +1167,10 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::open_tx(crypto::secret_key &tx_key) {
|
bool device_ledger::open_tx(crypto::secret_key &tx_key) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
reset_buffer();
|
|
||||||
key_map.clear();
|
key_map.clear();
|
||||||
|
int offset = set_command_header_noopt(INS_OPEN_TX, 0x01);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_OPEN_TX;
|
|
||||||
this->buffer_send[2] = 0x01;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
//account
|
//account
|
||||||
this->buffer_send[offset+0] = 0x00;
|
this->buffer_send[offset+0] = 0x00;
|
||||||
this->buffer_send[offset+1] = 0x00;
|
this->buffer_send[offset+1] = 0x00;
|
||||||
@ -1413,7 +1189,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) {
|
bool device_ledger::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const crypto::public_key public_key_x = public_key;
|
const crypto::public_key public_key_x = public_key;
|
||||||
@ -1422,17 +1197,7 @@ namespace hw {
|
|||||||
this->controle_device->encrypt_payment_id(payment_id_x, public_key_x, secret_key_x);
|
this->controle_device->encrypt_payment_id(payment_id_x, public_key_x, secret_key_x);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_STEALTH);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_STEALTH;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
//pub
|
//pub
|
||||||
memmove(&this->buffer_send[offset], public_key.data, 32);
|
memmove(&this->buffer_send[offset], public_key.data, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1464,7 +1229,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & AKout) {
|
bool device_ledger::ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & AKout) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const rct::key AKout_x = hw::ledger::decrypt(AKout);
|
const rct::key AKout_x = hw::ledger::decrypt(AKout);
|
||||||
@ -1472,17 +1236,7 @@ namespace hw {
|
|||||||
this->controle_device->ecdhEncode(unmasked_x, AKout_x);
|
this->controle_device->ecdhEncode(unmasked_x, AKout_x);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_BLIND);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_BLIND;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
// AKout
|
// AKout
|
||||||
memmove(this->buffer_send+offset, AKout.bytes, 32);
|
memmove(this->buffer_send+offset, AKout.bytes, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1512,7 +1266,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::ecdhDecode(rct::ecdhTuple & masked, const rct::key & AKout) {
|
bool device_ledger::ecdhDecode(rct::ecdhTuple & masked, const rct::key & AKout) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const rct::key AKout_x = hw::ledger::decrypt(AKout);
|
const rct::key AKout_x = hw::ledger::decrypt(AKout);
|
||||||
@ -1520,17 +1273,8 @@ namespace hw {
|
|||||||
this->controle_device->ecdhDecode(masked_x, AKout_x);
|
this->controle_device->ecdhDecode(masked_x, AKout_x);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_UNBLIND);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_UNBLIND;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
// AKout
|
// AKout
|
||||||
memmove(this->buffer_send+offset, AKout.bytes, 32);
|
memmove(this->buffer_send+offset, AKout.bytes, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1580,16 +1324,7 @@ namespace hw {
|
|||||||
data = blob.data();
|
data = blob.data();
|
||||||
|
|
||||||
// ====== u8 type, varint txnfee ======
|
// ====== u8 type, varint txnfee ======
|
||||||
int offset;
|
int offset = set_command_header(INS_VALIDATE, 0x01, 0x01);
|
||||||
|
|
||||||
reset_buffer();
|
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_VALIDATE;
|
|
||||||
this->buffer_send[2] = 0x01;
|
|
||||||
this->buffer_send[3] = 0x01;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
//options
|
||||||
this->buffer_send[offset] = (inputs_size == 0)?0x00:0x80;
|
this->buffer_send[offset] = (inputs_size == 0)?0x00:0x80;
|
||||||
offset += 1;
|
offset += 1;
|
||||||
@ -1617,13 +1352,7 @@ namespace hw {
|
|||||||
//pseudoOuts
|
//pseudoOuts
|
||||||
if ((type == rct::RCTTypeSimple) || (type == rct::RCTTypeSimpleBulletproof)) {
|
if ((type == rct::RCTTypeSimple) || (type == rct::RCTTypeSimpleBulletproof)) {
|
||||||
for ( i = 0; i < inputs_size; i++) {
|
for ( i = 0; i < inputs_size; i++) {
|
||||||
reset_buffer();
|
offset = set_command_header(INS_VALIDATE, 0x01, i+2);
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_VALIDATE;
|
|
||||||
this->buffer_send[2] = 0x01;
|
|
||||||
this->buffer_send[3] = i+2;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
//options
|
||||||
this->buffer_send[offset] = (i==inputs_size-1)? 0x00:0x80;
|
this->buffer_send[offset] = (i==inputs_size-1)? 0x00:0x80;
|
||||||
offset += 1;
|
offset += 1;
|
||||||
@ -1650,14 +1379,7 @@ namespace hw {
|
|||||||
log_hexbuffer("Pout not found", (char*)outPk[i].dest.bytes, 32);
|
log_hexbuffer("Pout not found", (char*)outPk[i].dest.bytes, 32);
|
||||||
CHECK_AND_ASSERT_THROW_MES(found, "Pout not found");
|
CHECK_AND_ASSERT_THROW_MES(found, "Pout not found");
|
||||||
}
|
}
|
||||||
reset_buffer();
|
offset = set_command_header(INS_VALIDATE, 0x02, i+1);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_VALIDATE;
|
|
||||||
this->buffer_send[2] = 0x02;
|
|
||||||
this->buffer_send[3] = i+1;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
//options
|
||||||
this->buffer_send[offset] = (i==outputs_size-1)? 0x00:0x80 ;
|
this->buffer_send[offset] = (i==outputs_size-1)? 0x00:0x80 ;
|
||||||
offset += 1;
|
offset += 1;
|
||||||
@ -1702,14 +1424,7 @@ namespace hw {
|
|||||||
// ====== C[], message, proof======
|
// ====== C[], message, proof======
|
||||||
C_offset = kv_offset;
|
C_offset = kv_offset;
|
||||||
for (i = 0; i < outputs_size; i++) {
|
for (i = 0; i < outputs_size; i++) {
|
||||||
reset_buffer();
|
offset = set_command_header(INS_VALIDATE, 0x03, i+1);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_VALIDATE;
|
|
||||||
this->buffer_send[2] = 0x03;
|
|
||||||
this->buffer_send[3] = i+1;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
//options
|
||||||
this->buffer_send[offset] = 0x80 ;
|
this->buffer_send[offset] = 0x80 ;
|
||||||
offset += 1;
|
offset += 1;
|
||||||
@ -1724,17 +1439,7 @@ namespace hw {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_buffer();
|
offset = set_command_header_noopt(INS_VALIDATE, 0x03, i+1);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_VALIDATE;
|
|
||||||
this->buffer_send[2] = 0x03;
|
|
||||||
this->buffer_send[3] = i+1;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
//message
|
//message
|
||||||
memmove(this->buffer_send+offset, hashes[0].bytes,32);
|
memmove(this->buffer_send+offset, hashes[0].bytes,32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1759,7 +1464,6 @@ namespace hw {
|
|||||||
bool device_ledger::mlsag_prepare(const rct::key &H, const rct::key &xx,
|
bool device_ledger::mlsag_prepare(const rct::key &H, const rct::key &xx,
|
||||||
rct::key &a, rct::key &aG, rct::key &aHP, rct::key &II) {
|
rct::key &a, rct::key &aG, rct::key &aHP, rct::key &II) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
unsigned char options;
|
unsigned char options;
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
@ -1771,17 +1475,7 @@ namespace hw {
|
|||||||
rct::key II_x;
|
rct::key II_x;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
int offset = set_command_header_noopt(INS_MLSAG, 0x01);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_MLSAG;
|
|
||||||
this->buffer_send[2] = 0x01;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
//value H
|
//value H
|
||||||
memmove(this->buffer_send+offset, H.bytes, 32);
|
memmove(this->buffer_send+offset, H.bytes, 32);
|
||||||
offset += 32;
|
offset += 32;
|
||||||
@ -1814,7 +1508,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::mlsag_prepare(rct::key &a, rct::key &aG) {
|
bool device_ledger::mlsag_prepare(rct::key &a, rct::key &aG) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
unsigned char options;
|
unsigned char options;
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
@ -1822,21 +1515,7 @@ namespace hw {
|
|||||||
rct::key aG_x;
|
rct::key aG_x;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reset_buffer();
|
send_simple(INS_MLSAG, 0x01);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_MLSAG;
|
|
||||||
this->buffer_send[2] = 0x01;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
|
|
||||||
this->buffer_send[4] = offset-5;
|
|
||||||
this->length_send = offset;
|
|
||||||
this->exchange();
|
|
||||||
|
|
||||||
memmove(a.bytes, &this->buffer_recv[32*0], 32);
|
memmove(a.bytes, &this->buffer_recv[32*0], 32);
|
||||||
memmove(aG.bytes, &this->buffer_recv[32*1], 32);
|
memmove(aG.bytes, &this->buffer_recv[32*1], 32);
|
||||||
@ -1852,7 +1531,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::mlsag_hash(const rct::keyV &long_message, rct::key &c) {
|
bool device_ledger::mlsag_hash(const rct::keyV &long_message, rct::key &c) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
unsigned char options;
|
unsigned char options;
|
||||||
size_t cnt;
|
size_t cnt;
|
||||||
|
|
||||||
@ -1864,14 +1542,7 @@ namespace hw {
|
|||||||
|
|
||||||
cnt = long_message.size();
|
cnt = long_message.size();
|
||||||
for (size_t i = 0; i<cnt; i++) {
|
for (size_t i = 0; i<cnt; i++) {
|
||||||
reset_buffer();
|
int offset = set_command_header(INS_MLSAG, 0x02, i+1);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_MLSAG;
|
|
||||||
this->buffer_send[2] = 0x02;
|
|
||||||
this->buffer_send[3] = i+1;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
//options
|
||||||
this->buffer_send[offset] =
|
this->buffer_send[offset] =
|
||||||
(i==(cnt-1))?0x00:0x80; //last
|
(i==(cnt-1))?0x00:0x80; //last
|
||||||
@ -1896,7 +1567,6 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::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) {
|
bool device_ledger::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) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
CHECK_AND_ASSERT_THROW_MES(dsRows<=rows, "dsRows greater than rows");
|
CHECK_AND_ASSERT_THROW_MES(dsRows<=rows, "dsRows greater than rows");
|
||||||
CHECK_AND_ASSERT_THROW_MES(xx.size() == rows, "xx size does not match rows");
|
CHECK_AND_ASSERT_THROW_MES(xx.size() == rows, "xx size does not match rows");
|
||||||
@ -1914,14 +1584,7 @@ namespace hw {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (size_t j = 0; j < dsRows; j++) {
|
for (size_t j = 0; j < dsRows; j++) {
|
||||||
reset_buffer();
|
int offset = set_command_header(INS_MLSAG, 0x03, j+1);
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_MLSAG;
|
|
||||||
this->buffer_send[2] = 0x03;
|
|
||||||
this->buffer_send[3] = j+1;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
//options
|
||||||
this->buffer_send[offset] = 0x00;
|
this->buffer_send[offset] = 0x00;
|
||||||
if (j==(dsRows-1)) {
|
if (j==(dsRows-1)) {
|
||||||
@ -1958,24 +1621,7 @@ namespace hw {
|
|||||||
|
|
||||||
bool device_ledger::close_tx() {
|
bool device_ledger::close_tx() {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
send_simple(INS_CLOSE_TX);
|
||||||
|
|
||||||
reset_buffer();
|
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_CLOSE_TX;
|
|
||||||
this->buffer_send[2] = 0x00;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
|
|
||||||
this->buffer_send[4] = offset-5;
|
|
||||||
this->length_send = offset;
|
|
||||||
this->exchange();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +102,9 @@ namespace hw {
|
|||||||
void logRESP(void);
|
void logRESP(void);
|
||||||
unsigned int exchange(unsigned int ok=0x9000, unsigned int mask=0xFFFF);
|
unsigned int exchange(unsigned int ok=0x9000, unsigned int mask=0xFFFF);
|
||||||
void reset_buffer(void);
|
void reset_buffer(void);
|
||||||
|
int set_command_header(BYTE ins, BYTE p1 = 0x00, BYTE p2 = 0x00);
|
||||||
|
int set_command_header_noopt(BYTE ins, BYTE p1 = 0x00, BYTE p2 = 0x00);
|
||||||
|
void send_simple(BYTE ins, BYTE p1 = 0x00);
|
||||||
|
|
||||||
// hw running mode
|
// hw running mode
|
||||||
device_mode mode;
|
device_mode mode;
|
||||||
|
Loading…
Reference in New Issue
Block a user