aboutsummaryrefslogtreecommitdiff
path: root/src/device
diff options
context:
space:
mode:
Diffstat (limited to 'src/device')
-rw-r--r--src/device/CMakeLists.txt3
-rw-r--r--src/device/device.cpp2
-rw-r--r--src/device/device.hpp64
-rw-r--r--src/device/device_declare.hpp42
-rw-r--r--src/device/device_default.cpp132
-rw-r--r--src/device/device_default.hpp16
-rw-r--r--src/device/device_ledger.cpp224
-rw-r--r--src/device/device_ledger.hpp27
-rw-r--r--src/device/log.cpp8
9 files changed, 329 insertions, 189 deletions
diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt
index 7eccc1cc2..cc2d20a54 100644
--- a/src/device/CMakeLists.txt
+++ b/src/device/CMakeLists.txt
@@ -37,7 +37,6 @@ if(PCSC_FOUND)
endif()
set(device_headers
- device_declare.hpp
device.hpp
device_default.hpp
log.hpp
@@ -68,7 +67,7 @@ target_link_libraries(device
PUBLIC
${PCSC_LIBRARIES}
cncrypto
- ringct
+ ringct_basic
${OPENSSL_CRYPTO_LIBRARIES}
PRIVATE
${Blocks}
diff --git a/src/device/device.cpp b/src/device/device.cpp
index 068529388..983f59b60 100644
--- a/src/device/device.cpp
+++ b/src/device/device.cpp
@@ -67,4 +67,4 @@ namespace hw {
return *device->second;
}
-} \ No newline at end of file
+}
diff --git a/src/device/device.hpp b/src/device/device.hpp
index bdea7b8f6..b47460472 100644
--- a/src/device/device.hpp
+++ b/src/device/device.hpp
@@ -28,11 +28,25 @@
//
+/* Note about debug:
+ * To debug Device you can def the following :
+ * #define DEBUG_HWDEVICE
+ * Activate debug mechanism:
+ * - Add more trace
+ * - All computation done by device are checked by default device.
+ * Required IODUMMYCRYPT_HWDEVICE or IONOCRYPT_HWDEVICE for fully working
+ * #define IODUMMYCRYPT_HWDEVICE 1
+ * - It assumes sensitive data encryption is is off on device side. a XOR with 0x55. This allow Ledger Class to make check on clear value
+ * #define IONOCRYPT_HWDEVICE 1
+ * - It assumes sensitive data encryption is off on device side.
+ */
+
+
#pragma once
-#include "cryptonote_basic/cryptonote_basic.h"
-#include "cryptonote_basic/account.h"
-#include "cryptonote_basic/subaddress_index.h"
+#include "crypto/crypto.h"
+#include "crypto/chacha.h"
+#include "ringct/rctTypes.h"
#ifndef USE_DEVICE_LEDGER
#define USE_DEVICE_LEDGER 1
@@ -47,6 +61,14 @@
#define WITH_DEVICE_LEDGER
#endif
+// forward declaration needed because this header is included by headers in libcryptonote_basic which depends on libdevice
+namespace cryptonote
+{
+ struct account_public_address;
+ struct account_keys;
+ struct subaddress_index;
+}
+
namespace hw {
namespace {
//device funcion not supported
@@ -95,10 +117,10 @@ namespace hw {
/* SUB ADDRESS */
/* ======================================================================= */
virtual 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) = 0;
- virtual bool get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index& index, crypto::public_key &D) = 0;
- virtual bool get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end, std::vector<crypto::public_key> &pkeys) = 0;
- virtual bool get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, cryptonote::account_public_address &address) = 0;
- virtual bool get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index, crypto::secret_key &sub_sec) = 0;
+ virtual crypto::public_key get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index& index) = 0;
+ virtual std::vector<crypto::public_key> get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end) = 0;
+ virtual cryptonote::account_public_address get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) = 0;
+ virtual crypto::secret_key get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index) = 0;
/* ======================================================================= */
/* DERIVATION & KEY */
@@ -107,7 +129,7 @@ namespace hw {
virtual bool scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) = 0;
virtual bool scalarmultBase(rct::key &aG, const rct::key &a) = 0;
virtual bool sc_secret_add( crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) = 0;
- virtual bool generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover, crypto::secret_key &rng) = 0;
+ virtual 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) = 0;
virtual bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) = 0;
virtual bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) = 0;
virtual 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) = 0;
@@ -115,6 +137,21 @@ namespace hw {
virtual bool secret_key_to_public_key(const crypto::secret_key &sec, crypto::public_key &pub) = 0;
virtual bool generate_key_image(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_image &image) = 0;
+ // alternative prototypes available in libringct
+ rct::key scalarmultKey(const rct::key &P, const rct::key &a)
+ {
+ rct::key aP;
+ scalarmultKey(aP, P, a);
+ return aP;
+ }
+
+ rct::key scalarmultBase(const rct::key &a)
+ {
+ rct::key aG;
+ scalarmultBase(aG, a);
+ return aG;
+ }
+
/* ======================================================================= */
/* TRANSACTION */
/* ======================================================================= */
@@ -123,13 +160,18 @@ namespace hw {
virtual bool set_signature_mode(unsigned int sig_mode) = 0;
- virtual bool encrypt_payment_id(const crypto::public_key &public_key, const crypto::secret_key &secret_key, crypto::hash8 &payment_id ) = 0;
+ virtual bool encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) = 0;
+ bool decrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key)
+ {
+ // Encryption and decryption are the same operation (xor with a key)
+ return encrypt_payment_id(payment_id, public_key, secret_key);
+ }
virtual bool ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec) = 0;
virtual bool ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec) = 0;
- virtual bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, size_t real_output_index,
- const rct::key &amount_key, const crypto::public_key &out_eph_public_key) = 0;
+ virtual bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const size_t real_output_index,
+ const rct::key &amount_key, const crypto::public_key &out_eph_public_key) = 0;
virtual 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) = 0;
diff --git a/src/device/device_declare.hpp b/src/device/device_declare.hpp
deleted file mode 100644
index 799052ad2..000000000
--- a/src/device/device_declare.hpp
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (c) 2017-2018, The Monero Project
-//
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification, are
-// permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of
-// conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be
-// used to endorse or promote products derived from this software without specific
-// prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-
-#pragma once
-
-
-//#define DEBUG_HWDEVICE
-//#define IODUMMYCRYPT 1
-//#define IONOCRYPT 1
-
-namespace hw {
- class device;
-
- device& get_device(std::string device_descriptor);
-}
-
diff --git a/src/device/device_default.cpp b/src/device/device_default.cpp
index c3ba42000..d63dafe9e 100644
--- a/src/device/device_default.cpp
+++ b/src/device/device_default.cpp
@@ -31,10 +31,13 @@
#include "device_default.hpp"
-
-#include "cryptonote_basic/cryptonote_format_utils.h"
+#include "cryptonote_basic/account.h"
+#include "cryptonote_basic/subaddress_index.h"
#include "ringct/rctOps.h"
+#define ENCRYPTED_PAYMENT_ID_TAIL 0x8d
+#define CHACHA8_KEY_TAIL 0x8c
+
namespace hw {
namespace core {
@@ -83,7 +86,14 @@ namespace hw {
/* ======================================================================= */
bool device_default::generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) {
- return cryptonote::generate_chacha_key_from_secret_keys(keys, key);
+ const crypto::secret_key &view_key = keys.m_view_secret_key;
+ const crypto::secret_key &spend_key = keys.m_spend_secret_key;
+ tools::scrubbed_arr<char, sizeof(view_key) + sizeof(spend_key) + 1> data;
+ memcpy(data.data(), &view_key, sizeof(view_key));
+ memcpy(data.data() + sizeof(view_key), &spend_key, sizeof(spend_key));
+ data[sizeof(data) - 1] = CHACHA8_KEY_TAIL;
+ crypto::generate_chacha_key(data.data(), sizeof(data), key);
+ return true;
}
bool device_default::get_public_address(cryptonote::account_public_address &pubkey) {
dfns();
@@ -99,24 +109,85 @@ namespace hw {
return crypto::derive_subaddress_public_key(out_key, derivation, output_index,derived_key);
}
- bool device_default::get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, crypto::public_key &D) {
- D = cryptonote::get_subaddress_spend_public_key(keys,index);
- return true;
+ crypto::public_key device_default::get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) {
+ if (index.is_zero())
+ return keys.m_account_address.m_spend_public_key;
+
+ // m = Hs(a || index_major || index_minor)
+ crypto::secret_key m = get_subaddress_secret_key(keys.m_view_secret_key, index);
+
+ // M = m*G
+ crypto::public_key M;
+ crypto::secret_key_to_public_key(m, M);
+
+ // D = B + M
+ crypto::public_key D = rct::rct2pk(rct::addKeys(rct::pk2rct(keys.m_account_address.m_spend_public_key), rct::pk2rct(M)));
+ return D;
}
- bool device_default::get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end, std::vector<crypto::public_key> &pkeys) {
- pkeys = cryptonote::get_subaddress_spend_public_keys(keys, account, begin, end);
- return true;
+ std::vector<crypto::public_key> device_default::get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end) {
+ CHECK_AND_ASSERT_THROW_MES(begin <= end, "begin > end");
+
+ std::vector<crypto::public_key> pkeys;
+ pkeys.reserve(end - begin);
+ cryptonote::subaddress_index index = {account, begin};
+
+ ge_p3 p3;
+ ge_cached cached;
+ CHECK_AND_ASSERT_THROW_MES(ge_frombytes_vartime(&p3, (const unsigned char*)keys.m_account_address.m_spend_public_key.data) == 0,
+ "ge_frombytes_vartime failed to convert spend public key");
+ ge_p3_to_cached(&cached, &p3);
+
+ for (uint32_t idx = begin; idx < end; ++idx)
+ {
+ index.minor = idx;
+ if (index.is_zero())
+ {
+ pkeys.push_back(keys.m_account_address.m_spend_public_key);
+ continue;
+ }
+ crypto::secret_key m = get_subaddress_secret_key(keys.m_view_secret_key, index);
+
+ // M = m*G
+ ge_scalarmult_base(&p3, (const unsigned char*)m.data);
+
+ // D = B + M
+ crypto::public_key D;
+ ge_p1p1 p1p1;
+ ge_add(&p1p1, &p3, &cached);
+ ge_p1p1_to_p3(&p3, &p1p1);
+ ge_p3_tobytes((unsigned char*)D.data, &p3);
+
+ pkeys.push_back(D);
+ }
+ return pkeys;
}
- bool device_default::get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, cryptonote::account_public_address &address) {
- address = cryptonote::get_subaddress(keys,index);
- return true;
+ cryptonote::account_public_address device_default::get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) {
+ if (index.is_zero())
+ return keys.m_account_address;
+
+ crypto::public_key D = get_subaddress_spend_public_key(keys, index);
+
+ // C = a*D
+ crypto::public_key C = rct::rct2pk(rct::scalarmultKey(rct::pk2rct(D), rct::sk2rct(keys.m_view_secret_key)));
+
+ // result: (C, D)
+ cryptonote::account_public_address address;
+ address.m_view_public_key = C;
+ address.m_spend_public_key = D;
+ return address;
}
- bool device_default::get_subaddress_secret_key(const crypto::secret_key &a, const cryptonote::subaddress_index &index, crypto::secret_key &m) {
- m = cryptonote::get_subaddress_secret_key(a,index);
- return true;
+ crypto::secret_key device_default::get_subaddress_secret_key(const crypto::secret_key &a, const cryptonote::subaddress_index &index) {
+ const char prefix[] = "SubAddr";
+ char data[sizeof(prefix) + sizeof(crypto::secret_key) + sizeof(cryptonote::subaddress_index)];
+ memcpy(data, prefix, sizeof(prefix));
+ memcpy(data + sizeof(prefix), &a, sizeof(crypto::secret_key));
+ memcpy(data + sizeof(prefix) + sizeof(crypto::secret_key), &index, sizeof(cryptonote::subaddress_index));
+ crypto::secret_key m;
+ crypto::hash_to_scalar(data, sizeof(data), m);
+ return m;
}
/* ======================================================================= */
@@ -124,7 +195,9 @@ namespace hw {
/* ======================================================================= */
bool device_default::verify_keys(const crypto::secret_key &secret_key, const crypto::public_key &public_key) {
- return cryptonote::verify_keys(secret_key, public_key);
+ crypto::public_key calculated_pub;
+ bool r = crypto::secret_key_to_public_key(secret_key, calculated_pub);
+ return r && public_key == calculated_pub;
}
bool device_default::scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) {
@@ -142,9 +215,8 @@ namespace hw {
return true;
}
- bool device_default::generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover, crypto::secret_key &rng) {
- rng = crypto::generate_keys(pub, sec, recovery_key, recover);
- return true;
+ crypto::secret_key device_default::generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover) {
+ return crypto::generate_keys(pub, sec, recovery_key, recover);
}
bool device_default::generate_key_derivation(const crypto::public_key &key1, const crypto::secret_key &key2, crypto::key_derivation &derivation) {
@@ -179,13 +251,13 @@ namespace hw {
/* ======================================================================= */
bool device_default::open_tx(crypto::secret_key &tx_key) {
- cryptonote::keypair txkey = cryptonote::keypair::generate();
+ cryptonote::keypair txkey = cryptonote::keypair::generate(*this);
tx_key = txkey.sec;
return true;
}
- bool device_default::add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, size_t real_output_index,
+ bool device_default::add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const size_t real_output_index,
const rct::key &amount_key, const crypto::public_key &out_eph_public_key) {
return true;
}
@@ -194,8 +266,22 @@ namespace hw {
return true;
}
- bool device_default::encrypt_payment_id(const crypto::public_key &public_key, const crypto::secret_key &secret_key, crypto::hash8 &payment_id ) {
- return cryptonote::encrypt_payment_id(payment_id, public_key, secret_key);
+ bool device_default::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) {
+ crypto::key_derivation derivation;
+ crypto::hash hash;
+ char data[33]; /* A hash, and an extra byte */
+
+ if (!generate_key_derivation(public_key, secret_key, derivation))
+ return false;
+
+ memcpy(data, &derivation, 32);
+ data[32] = ENCRYPTED_PAYMENT_ID_TAIL;
+ cn_fast_hash(data, 33, hash);
+
+ for (size_t b = 0; b < 8; ++b)
+ payment_id.data[b] ^= hash.data[b];
+
+ return true;
}
bool device_default::ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec) {
diff --git a/src/device/device_default.hpp b/src/device/device_default.hpp
index f5b158a3b..02faeba0c 100644
--- a/src/device/device_default.hpp
+++ b/src/device/device_default.hpp
@@ -70,10 +70,10 @@ namespace hw {
/* SUB ADDRESS */
/* ======================================================================= */
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;
- bool get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index& index, crypto::public_key &D) override;
- bool get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end, std::vector<crypto::public_key> &pkeys) override;
- bool get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, cryptonote::account_public_address &address) override;
- bool get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index, crypto::secret_key &sub_sec) override;
+ crypto::public_key get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index& index) override;
+ 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;
+ cryptonote::account_public_address get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) override;
+ crypto::secret_key get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index) override;
/* ======================================================================= */
/* DERIVATION & KEY */
@@ -82,7 +82,7 @@ namespace hw {
bool scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) override;
bool scalarmultBase(rct::key &aG, const rct::key &a) override;
bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) override;
- bool generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover, crypto::secret_key &rng) override;
+ 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;
bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) override;
bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) override;
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;
@@ -100,13 +100,13 @@ namespace hw {
//bool get_additional_key(const bool subaddr, cryptonote::keypair &additional_txkey) override;
bool set_signature_mode(unsigned int sig_mode) override;
- bool encrypt_payment_id(const crypto::public_key &public_key, const crypto::secret_key &secret_key, crypto::hash8 &payment_id ) override;
+ bool encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) override;
bool ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec) override;
bool ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec) override;
- bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, size_t real_output_index,
- const rct::key &amount_key, const crypto::public_key &out_eph_public_key) override;
+ bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const size_t real_output_index,
+ const rct::key &amount_key, const crypto::public_key &out_eph_public_key) override;
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;
diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp
index 571d42724..b3c0035a1 100644
--- a/src/device/device_ledger.cpp
+++ b/src/device/device_ledger.cpp
@@ -30,6 +30,8 @@
#include "device_ledger.hpp"
#include "log.hpp"
#include "ringct/rctOps.h"
+#include "cryptonote_basic/account.h"
+#include "cryptonote_basic/subaddress_index.h"
@@ -55,30 +57,29 @@ namespace hw {
#define ASSERT_T0(exp) CHECK_AND_ASSERT_THROW_MES(exp, "Protocol assert failure: "#exp ) ;
#ifdef DEBUG_HWDEVICE
- #define DEVICE_CONTROLE :controle_device(hw::get_device("default"))
crypto::secret_key viewkey;
crypto::secret_key spendkey;
- #else
- #define DEVICE_CONTROLE
#endif
/* ===================================================================== */
/* === Keymap ==== */
/* ===================================================================== */
- ABPkeys::ABPkeys(const rct::key& A, const rct::key& B, size_t real_output_index, const rct::key& P, const rct::key& AK) {
+ ABPkeys::ABPkeys(const rct::key& A, const rct::key& B, const bool is_subaddr, const size_t real_output_index, const rct::key& P, const rct::key& AK) {
Aout = A;
Bout = B;
+ is_subaddress = is_subaddr;
index = real_output_index;
Pout = P;
AKout = AK;
}
ABPkeys::ABPkeys(const ABPkeys& keys) {
- Aout = keys.Aout;
- Bout = keys.Bout;
+ Aout = keys.Aout;
+ Bout = keys.Bout;
+ is_subaddress = keys.is_subaddress;
index = keys.index;
- Pout = keys.Pout;
+ Pout = keys.Pout;
AKout = keys.AKout;
}
@@ -109,6 +110,7 @@ namespace hw {
log_message(" keymap", std::to_string(i));
log_hexbuffer(" Aout", (char*)ABP[i].Aout.bytes, 32);
log_hexbuffer(" Bout", (char*)ABP[i].Bout.bytes, 32);
+ log_message (" is_sub", std::to_string(ABP[i].is_subaddress));
log_message (" index", std::to_string(ABP[i].index));
log_hexbuffer(" Pout", (char*)ABP[i].Pout.bytes, 32);
}
@@ -189,7 +191,7 @@ namespace hw {
}
/* -------------------------------------------------------------- */
- device_ledger::device_ledger() DEVICE_CONTROLE {
+ device_ledger::device_ledger() {
this->id = device_id++;
this->hCard = 0;
this->hContext = 0;
@@ -300,6 +302,9 @@ namespace hw {
}
bool device_ledger::init(void) {
+ #ifdef DEBUG_HWDEVICE
+ this->controle_device = &hw::get_device("default");
+ #endif
LONG rv;
this->release();
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM,0,0, &this->hContext);
@@ -411,12 +416,6 @@ namespace hw {
/* WALLET & ADDRESS */
/* ======================================================================= */
- bool device_ledger::get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) {
- memset(viewkey.data, 0x00, 32);
- memset(spendkey.data, 0xFF, 32);
- return true;
- }
-
/* Application API */
bool device_ledger::get_public_address(cryptonote::account_public_address &pubkey){
@@ -449,8 +448,11 @@ namespace hw {
return true;
}
- #ifdef DEBUG_HWDEVICE
bool device_ledger::get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) {
+ memset(viewkey.data, 0x00, 32);
+ memset(spendkey.data, 0xFF, 32);
+
+ #ifdef DEBUG_HWDEVICE
lock_device();
try {
//spcialkey, normal conf handled in decrypt
@@ -479,9 +481,9 @@ namespace hw {
unlock_device();
throw;
}
+ #endif
return true;
}
- #endif
bool device_ledger::generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) {
lock_device();
@@ -489,9 +491,9 @@ namespace hw {
int offset;
#ifdef DEBUG_HWDEVICE
- const cryptonote::account_keys keys_x = decrypt(keys);
crypto::chacha_key key_x;
- this->controle_device.generate_chacha_key(keys_x, key_x);
+ cryptonote::account_keys keys_x = hw::ledger::decrypt(keys);
+ this->controle_device->generate_chacha_key(keys_x, key_x);
#endif
reset_buffer();
@@ -511,10 +513,10 @@ namespace hw {
char prekey[200];
memmove(prekey, &this->buffer_recv[0], 200);
- crypto::generate_chacha_key(&prekey[0], sizeof(prekey), key, 0, true);
+ crypto::generate_chacha_key_prehashed(&prekey[0], sizeof(prekey), key);
#ifdef DEBUG_HWDEVICE
- hw::ledger::check32("generate_chacha_key", "key", (char*)key_x.data(), (char*)key.data());
+ hw::ledger::check32("generate_chacha_key_prehashed", "key", (char*)key_x.data(), (char*)key.data());
#endif
unlock_device();
@@ -541,7 +543,11 @@ namespace hw {
const crypto::key_derivation derivation_x = hw::ledger::decrypt(derivation);
const std::size_t output_index_x = output_index;
crypto::public_key derived_pub_x;
- this->controle_device.derive_subaddress_public_key(pub_x, derivation_x,output_index_x,derived_pub_x);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] pub ", pub_x.data, 32);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] derivation", derivation_x.data, 32);
+ hw::ledger::log_message ("derive_subaddress_public_key: [[IN]] index ", std::to_string((int)output_index_x));
+ this->controle_device->derive_subaddress_public_key(pub_x, derivation_x,output_index_x,derived_pub_x);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[OUT]] derived_pub", derived_pub_x.data, 32);
#endif
reset_buffer();
@@ -589,7 +595,8 @@ namespace hw {
return true;
}
- bool device_ledger::get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, crypto::public_key &D) {
+ crypto::public_key device_ledger::get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) {
+ crypto::public_key D;
lock_device();
try {
int offset =0;
@@ -599,7 +606,11 @@ namespace hw {
const cryptonote::account_keys keys_x = hw::ledger::decrypt(keys);
const cryptonote::subaddress_index index_x = index;
crypto::public_key D_x;
- this->controle_device.get_subaddress_spend_public_key(keys_x, index_x, D_x);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] keys.m_view_secret_key ", keys_x.m_view_secret_key.data,32);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] keys.m_spend_secret_key", keys_x.m_spend_secret_key.data,32);
+ hw::ledger::log_message ("get_subaddress_spend_public_key: [[IN]] index ", std::to_string(index_x.major)+"."+std::to_string(index_x.minor));
+ this->controle_device->get_subaddress_spend_public_key(keys_x, index_x, D_x);
+ hw::ledger::log_hexbuffer("get_subaddress_spend_public_key: [[OUT]] derivation ", D_x.data, 32);
#endif
if (index.is_zero()) {
@@ -638,21 +649,23 @@ namespace hw {
unlock_device();
throw;
}
- return true;
+ return D;
}
- bool device_ledger::get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end, std::vector<crypto::public_key> &pkeys) {
+ std::vector<crypto::public_key> device_ledger::get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end) {
+ std::vector<crypto::public_key> pkeys;
cryptonote::subaddress_index index = {account, begin};
crypto::public_key D;
for (uint32_t idx = begin; idx < end; ++idx) {
index.minor = idx;
- this->get_subaddress_spend_public_key(keys, index, D);
+ D = this->get_subaddress_spend_public_key(keys, index);
pkeys.push_back(D);
}
- return true;
+ return pkeys;
}
- bool device_ledger::get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, cryptonote::account_public_address &address) {
+ cryptonote::account_public_address device_ledger::get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) {
+ cryptonote::account_public_address address;
lock_device();
try {
int offset =0;
@@ -662,7 +675,14 @@ namespace hw {
const cryptonote::account_keys keys_x = hw::ledger::decrypt(keys);
const cryptonote::subaddress_index index_x = index;
cryptonote::account_public_address address_x;
- this->controle_device.get_subaddress(keys_x, index_x, address_x);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] keys.m_view_secret_key ", keys_x.m_view_secret_key.data, 32);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] keys.m_view_public_key", keys_x.m_account_address.m_view_public_key.data, 32);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] keys.m_view_secret_key ", keys_x.m_view_secret_key.data, 32);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] keys.m_spend_public_key", keys_x.m_account_address.m_spend_public_key.data, 32);
+ hw::ledger::log_message ("get_subaddress: [[IN]] index ", std::to_string(index_x.major)+"."+std::to_string(index_x.minor));
+ this->controle_device->get_subaddress(keys_x, index_x, address_x);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] keys.m_view_public_key ", address_x.m_view_public_key.data, 32);
+ hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] keys.m_spend_public_key", address_x.m_spend_public_key.data, 32);
#endif
if (index.is_zero()) {
@@ -702,10 +722,11 @@ namespace hw {
unlock_device();
throw;
}
- return true;
+ return address;
}
- bool device_ledger::get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index, crypto::secret_key &sub_sec) {
+ crypto::secret_key device_ledger::get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index) {
+ crypto::secret_key sub_sec;
lock_device();
try {
int offset =0;
@@ -715,7 +736,10 @@ namespace hw {
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
const cryptonote::subaddress_index index_x = index;
crypto::secret_key sub_sec_x;
- this->controle_device.get_subaddress_secret_key(sec_x, index_x, sub_sec_x);
+ hw::ledger::log_message ("get_subaddress_secret_key: [[IN]] index ", std::to_string(index.major)+"."+std::to_string(index.minor));
+ hw::ledger::log_hexbuffer("get_subaddress_secret_key: [[IN]] sec ", sec_x.data, 32);
+ this->controle_device->get_subaddress_secret_key(sec_x, index_x, sub_sec_x);
+ hw::ledger::log_hexbuffer("get_subaddress_secret_key: [[OUT]] sub_sec", sub_sec_x.data, 32);
#endif
reset_buffer();
@@ -753,7 +777,7 @@ namespace hw {
unlock_device();
throw;
}
- return true;
+ return sub_sec;
}
/* ======================================================================= */
@@ -808,10 +832,13 @@ namespace hw {
unsigned char options = 0;
#ifdef DEBUG_HWDEVICE
- const rct::key pub_x = pub;
- const rct::key sec_x = hw::ledger::decrypt(sec);
- rct::key mulkey_x;
- this->controle_device.scalarmultKey(pub_x, sec_x, mulkey_x);
+ const rct::key P_x = P;
+ const rct::key a_x = hw::ledger::decrypt(a);
+ rct::key aP_x;
+ hw::ledger::log_hexbuffer("scalarmultKey: [[IN]] P ", (char*)P_x.bytes, 32);
+ hw::ledger::log_hexbuffer("scalarmultKey: [[IN]] a ", (char*)a_x.bytes, 32);
+ this->controle_device->scalarmultKey(aP_x, P_x, a_x);
+ hw::ledger::log_hexbuffer("scalarmultKey: [[OUT]] aP", (char*)aP_x.bytes, 32);
#endif
reset_buffer();
@@ -843,7 +870,7 @@ namespace hw {
memmove(aP.bytes, &this->buffer_recv[0], 32);
#ifdef DEBUG_HWDEVICE
- hw::ledger::check32("scalarmultKey", "mulkey", (char*)mulkey_x.bytes, (char*)mulkey.bytes);
+ hw::ledger::check32("scalarmultKey", "mulkey", (char*)aP_x.bytes, (char*)aP.bytes);
#endif
unlock_device();
@@ -861,9 +888,11 @@ namespace hw {
unsigned char options = 0;
#ifdef DEBUG_HWDEVICE
- const rct::key sec_x = hw::ledger::decrypt(sec);
- rct::key mulkey_x;
- this->controle_device.scalarmultBase(sec_x, mulkey_x);
+ const rct::key a_x = hw::ledger::decrypt(a);
+ rct::key aG_x;
+ hw::ledger::log_hexbuffer("scalarmultKey: [[IN]] a ", (char*)a_x.bytes, 32);
+ this->controle_device->scalarmultBase(aG_x, a_x);
+ hw::ledger::log_hexbuffer("scalarmultKey: [[OUT]] aG", (char*)aG_x.bytes, 32);
#endif
reset_buffer();
@@ -891,7 +920,7 @@ namespace hw {
memmove(aG.bytes, &this->buffer_recv[0], 32);
#ifdef DEBUG_HWDEVICE
- hw::ledger::check32("scalarmultBase", "mulkey", (char*)mulkey_x.bytes, (char*)mulkey.bytes);
+ hw::ledger::check32("scalarmultBase", "mulkey", (char*)aG_x.bytes, (char*)aG.bytes);
#endif
unlock_device();
@@ -913,7 +942,7 @@ namespace hw {
const crypto::secret_key a_x = hw::ledger::decrypt(a);
const crypto::secret_key b_x = hw::ledger::decrypt(b);
crypto::secret_key r_x;
- 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
reset_buffer();
@@ -956,7 +985,7 @@ namespace hw {
return true;
}
- bool device_ledger::generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover, crypto::secret_key &rng) {
+ crypto::secret_key device_ledger::generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover) {
if (recover) {
throw std::runtime_error("device generate key does not support recover");
}
@@ -1007,7 +1036,7 @@ namespace hw {
unlock_device();
throw;
}
- return true;
+ return sec;
}
@@ -1021,10 +1050,10 @@ namespace hw {
const crypto::public_key pub_x = pub;
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
crypto::key_derivation derivation_x;
- this->controle_device.generate_key_derivation(pub_x, sec_x, derivation_x);
- hw::ledger::log_hexbuffer("generate_key_derivation: sec_x.data", sec_x.data, 32);
- hw::ledger::log_hexbuffer("generate_key_derivation: pub_x.data", pub_x.data, 32);
- hw::ledger::log_hexbuffer("generate_key_derivation: derivation_x.data", derivation_x.data, 32);
+ hw::ledger::log_hexbuffer("generate_key_derivation: [[IN]] pub ", pub_x.data, 32);
+ hw::ledger::log_hexbuffer("generate_key_derivation: [[IN]] sec ", sec_x.data, 32);
+ this->controle_device->generate_key_derivation(pub_x, sec_x, derivation_x);
+ hw::ledger::log_hexbuffer("generate_key_derivation: [[OUT]] derivation", derivation_x.data, 32);
#endif
reset_buffer();
@@ -1075,7 +1104,10 @@ namespace hw {
const crypto::key_derivation derivation_x = hw::ledger::decrypt(derivation);
const size_t output_index_x = output_index;
crypto::ec_scalar res_x;
- this->controle_device.derivation_to_scalar(derivation_x, output_index_x, res_x);
+ hw::ledger::log_hexbuffer("derivation_to_scalar: [[IN]] derivation ", derivation_x.data, 32);
+ hw::ledger::log_message ("derivation_to_scalar: [[IN]] output_index ", std::to_string(output_index_x));
+ this->controle_device->derivation_to_scalar(derivation_x, output_index_x, res_x);
+ hw::ledger::log_hexbuffer("derivation_to_scalar: [[OUT]] res ", res_x.data, 32);
#endif
reset_buffer();
@@ -1132,7 +1164,11 @@ namespace hw {
const std::size_t output_index_x = output_index;
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
crypto::secret_key derived_sec_x;
- this->controle_device.derive_secret_key(derivation_x, output_index_x, sec_x, derived_sec_x);
+ hw::ledger::log_hexbuffer("derive_secret_key: [[IN]] derivation ", derivation_x.data, 32);
+ hw::ledger::log_message ("derive_secret_key: [[IN]] index ", std::to_string(output_index_x));
+ hw::ledger::log_hexbuffer("derive_secret_key: [[IN]] sec ", sec_x.data, 32);
+ this->controle_device->derive_secret_key(derivation_x, output_index_x, sec_x, derived_sec_x);
+ hw::ledger::log_hexbuffer("derive_secret_key: [[OUT]] derived_sec", derived_sec_x.data, 32);
#endif
reset_buffer();
@@ -1192,7 +1228,11 @@ namespace hw {
const std::size_t output_index_x = output_index;
const crypto::public_key pub_x = pub;
crypto::public_key derived_pub_x;
- this->controle_device.derive_public_key(derivation_x, output_index_x, pub_x, derived_pub_x);
+ hw::ledger::log_hexbuffer("derive_public_key: [[IN]] derivation ", derivation_x.data, 32);
+ hw::ledger::log_message ("derive_public_key: [[IN]] output_index", std::to_string(output_index_x));
+ hw::ledger::log_hexbuffer("derive_public_key: [[IN]] pub ", pub_x.data, 32);
+ this->controle_device->derive_public_key(derivation_x, output_index_x, pub_x, derived_pub_x);
+ hw::ledger::log_hexbuffer("derive_public_key: [[OUT]] derived_pub ", derived_pub_x.data, 32);
#endif
reset_buffer();
@@ -1249,7 +1289,12 @@ namespace hw {
#ifdef DEBUG_HWDEVICE
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
crypto::public_key pub_x;
- this->controle_device.secret_key_to_public_key(sec_x, pub_x);
+ hw::ledger::log_hexbuffer("secret_key_to_public_key: [[IN]] sec ", sec_x.data, 32);
+ bool rc = this->controle_device->secret_key_to_public_key(sec_x, pub_x);
+ hw::ledger::log_hexbuffer("secret_key_to_public_key: [[OUT]] pub", pub_x.data, 32);
+ if (!rc){
+ hw::ledger::log_message("secret_key_to_public_key", "secret_key rejected");
+ }
#endif
reset_buffer();
@@ -1298,7 +1343,10 @@ namespace hw {
const crypto::public_key pub_x = pub;
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
crypto::key_image image_x;
- this->controle_device.generate_key_image(pub_x, sec_x, image_x);
+ hw::ledger::log_hexbuffer("generate_key_image: [[IN]] pub ", pub_x.data, 32);
+ hw::ledger::log_hexbuffer("generate_key_image: [[IN]] sec ", sec_x.data, 32);
+ this->controle_device->generate_key_image(pub_x, sec_x, image_x);
+ hw::ledger::log_hexbuffer("generate_key_image: [[OUT]] image ", image_x.data, 32);
#endif
reset_buffer();
@@ -1415,7 +1463,7 @@ namespace hw {
return true;
}
- bool device_ledger::encrypt_payment_id(const crypto::public_key &public_key, const crypto::secret_key &secret_key, crypto::hash8 &payment_id) {
+ bool device_ledger::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) {
lock_device();
try {
int offset =0;
@@ -1425,7 +1473,7 @@ namespace hw {
const crypto::public_key public_key_x = public_key;
const crypto::secret_key secret_key_x = hw::ledger::decrypt(secret_key);
crypto::hash8 payment_id_x = payment_id;
- this->controle_device.encrypt_payment_id(public_key_x, secret_key_x, payment_id_x);
+ this->controle_device->encrypt_payment_id(public_key_x, secret_key_x, payment_id_x);
#endif
reset_buffer();
@@ -1466,11 +1514,11 @@ namespace hw {
return true;
}
- bool device_ledger::add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, size_t real_output_index,
- const rct::key &amount_key, const crypto::public_key &out_eph_public_key) {
+ bool device_ledger::add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const size_t real_output_index,
+ const rct::key &amount_key, const crypto::public_key &out_eph_public_key) {
lock_device();
try {
- key_map.add(ABPkeys(rct::pk2rct(Aout),rct::pk2rct(Bout), real_output_index, rct::pk2rct(out_eph_public_key), amount_key));
+ key_map.add(ABPkeys(rct::pk2rct(Aout),rct::pk2rct(Bout), is_subaddress, real_output_index, rct::pk2rct(out_eph_public_key), amount_key));
unlock_device();
}catch (...) {
unlock_device();
@@ -1488,7 +1536,7 @@ namespace hw {
#ifdef DEBUG_HWDEVICE
const rct::key AKout_x = hw::ledger::decrypt(AKout);
rct::ecdhTuple unmasked_x = unmasked;
- this->controle_device.ecdhEncode(AKout_x, unmasked_x);
+ this->controle_device->ecdhEncode(unmasked_x, AKout_x);
#endif
reset_buffer();
@@ -1543,7 +1591,7 @@ namespace hw {
#ifdef DEBUG_HWDEVICE
const rct::key AKout_x = hw::ledger::decrypt(AKout);
rct::ecdhTuple masked_x = masked;
- this->controle_device.ecdhDecode(AKout_x, masked_x);
+ this->controle_device->ecdhDecode(masked_x, AKout_x);
#endif
reset_buffer();
@@ -1604,7 +1652,7 @@ namespace hw {
const rct::keyV hashes_x = hashes;
const rct::ctkeyV outPk_x = outPk;
rct::key prehash_x;
- this->controle_device.mlsag_prehash(blob_x, inputs_size_x, outputs_size_x, hashes_x, outPk_x, prehash_x);
+ this->controle_device->mlsag_prehash(blob_x, inputs_size_x, outputs_size_x, hashes_x, outPk_x, prehash_x);
if (inputs_size) {
log_message("mlsag_prehash", (std::string("inputs_size not null: ") + std::to_string(inputs_size)).c_str());
}
@@ -1629,6 +1677,7 @@ namespace hw {
offset += 1;
//type
+ uint8_t type = data[0];
this->buffer_send[offset] = data[0];
offset += 1;
@@ -1648,25 +1697,27 @@ namespace hw {
this->exchange();
//pseudoOuts
- for ( i = 0; i < inputs_size; i++) {
- reset_buffer();
- 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
- this->buffer_send[offset] = (i==inputs_size-1)? 0x00:0x80;
- offset += 1;
- //pseudoOut
- memmove(this->buffer_send+offset, data+data_offset,32);
- offset += 32;
- data_offset += 32;
-
- this->buffer_send[4] = offset-5;
- this->length_send = offset;
- this->exchange();
+ if ((type == rct::RCTTypeSimple) || (type == rct::RCTTypeSimpleBulletproof)) {
+ for ( i = 0; i < inputs_size; i++) {
+ reset_buffer();
+ 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
+ this->buffer_send[offset] = (i==inputs_size-1)? 0x00:0x80;
+ offset += 1;
+ //pseudoOut
+ memmove(this->buffer_send+offset, data+data_offset,32);
+ offset += 32;
+ data_offset += 32;
+
+ this->buffer_send[4] = offset-5;
+ this->length_send = offset;
+ this->exchange();
+ }
}
// ====== Aout, Bout, AKout, C, v, k ======
@@ -1693,6 +1744,9 @@ namespace hw {
this->buffer_send[offset] = (i==outputs_size-1)? 0x00:0x80 ;
offset += 1;
if (found) {
+ //is_subaddress
+ this->buffer_send[offset] = outKeys.is_subaddress;
+ offset++;
//Aout
memmove(this->buffer_send+offset, outKeys.Aout.bytes, 32);
offset+=32;
@@ -1703,8 +1757,8 @@ namespace hw {
memmove(this->buffer_send+offset, outKeys.AKout.bytes, 32);
offset+=32;
} else {
- // dummy: Aout Bout AKout
- offset += 32*3;
+ // dummy: is_subaddress Aout Bout AKout
+ offset += 1+32*3;
}
//C
memmove(this->buffer_send+offset, data+C_offset,32);
@@ -1905,7 +1959,7 @@ namespace hw {
#ifdef DEBUG_HWDEVICE
const rct::keyV long_message_x = long_message;
rct::key c_x;
- this->controle_device.mlsag_hash(long_message_x, c_x);
+ this->controle_device->mlsag_hash(long_message_x, c_x);
#endif
cnt = long_message.size();
@@ -1964,7 +2018,7 @@ namespace hw {
const int rows_x = rows;
const int dsRows_x = dsRows;
rct::keyV ss_x(ss.size());
- this->controle_device.mlsag_sign(c_x, xx_x, alpha_x, rows_x, dsRows_x, ss_x);
+ this->controle_device->mlsag_sign(c_x, xx_x, alpha_x, rows_x, dsRows_x, ss_x);
#endif
for (size_t j = 0; j < dsRows; j++) {
diff --git a/src/device/device_ledger.hpp b/src/device/device_ledger.hpp
index ab8e0c553..e06c5f72c 100644
--- a/src/device/device_ledger.hpp
+++ b/src/device/device_ledger.hpp
@@ -56,12 +56,13 @@ namespace hw {
public:
rct::key Aout;
rct::key Bout;
+ bool is_subaddress;
size_t index;
rct::key Pout;
rct::key AKout;
- ABPkeys(const rct::key& A, const rct::key& B, size_t index, const rct::key& P,const rct::key& AK);
+ ABPkeys(const rct::key& A, const rct::key& B, const bool is_subaddr, size_t index, const rct::key& P,const rct::key& AK);
ABPkeys(const ABPkeys& keys) ;
- ABPkeys() {index=0;}
+ ABPkeys() {index=0;is_subaddress=false;}
};
class Keymap {
@@ -103,8 +104,8 @@ namespace hw {
unsigned int exchange(unsigned int ok=0x9000, unsigned int mask=0xFFFF);
void reset_buffer(void);
- #ifdef DEBUGLEDGER
- Device &controle_device;
+ #ifdef DEBUG_HWDEVICE
+ device *controle_device;
#endif
public:
@@ -141,10 +142,10 @@ namespace hw {
/* SUB ADDRESS */
/* ======================================================================= */
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;
- bool get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index& index, crypto::public_key &D) override;
- bool get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end, std::vector<crypto::public_key> &pkeys) override;
- bool get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, cryptonote::account_public_address &address) override;
- bool get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index, crypto::secret_key &sub_sec) override;
+ crypto::public_key get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index& index) override;
+ 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;
+ cryptonote::account_public_address get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index) override;
+ crypto::secret_key get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index) override;
/* ======================================================================= */
/* DERIVATION & KEY */
@@ -153,7 +154,7 @@ namespace hw {
bool scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) override;
bool scalarmultBase(rct::key &aG, const rct::key &a) override;
bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) override;
- bool generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover, crypto::secret_key &rng) override;
+ 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;
bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) override;
bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) override;
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;
@@ -169,13 +170,13 @@ namespace hw {
bool set_signature_mode(unsigned int sig_mode) override;
- bool encrypt_payment_id(const crypto::public_key &public_key, const crypto::secret_key &secret_key, crypto::hash8 &payment_id ) override;
+ bool encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) override;
bool ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec) override;
bool ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec) override;
- bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, size_t real_output_index,
- const rct::key &amount_key, const crypto::public_key &out_eph_public_key) override;
+ bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const size_t real_output_index,
+ const rct::key &amount_key, const crypto::public_key &out_eph_public_key) override;
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;
@@ -190,7 +191,7 @@ namespace hw {
- #ifdef DEBUGLEDGER
+ #ifdef DEBUG_HWDEVICE
extern crypto::secret_key viewkey;
extern crypto::secret_key spendkey;
#endif
diff --git a/src/device/log.cpp b/src/device/log.cpp
index 103b2b3ba..a2ad0f4f4 100644
--- a/src/device/log.cpp
+++ b/src/device/log.cpp
@@ -55,14 +55,14 @@ namespace hw {
MDEBUG(msg << ": " << info);
}
- #ifdef DEBUGLEDGER
+ #ifdef DEBUG_HWDEVICE
extern crypto::secret_key viewkey;
extern crypto::secret_key spendkey;
void decrypt(char* buf, size_t len) {
- #ifdef IODUMMYCRYPT
- int i;
+ #ifdef IODUMMYCRYPT_HWDEVICE
+ size_t i;
if (len == 32) {
//view key?
for (i = 0; i<32; i++) {
@@ -144,7 +144,7 @@ namespace hw {
log_hexbuffer(" device", dd, len);
} else {
- buffer_to_str(logstr, dd, len);
+ buffer_to_str(logstr, 128, dd, len);
log_message("ASSERT EQ OK", msg + ": "+ info + ": "+ std::string(logstr) );
}
}