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.hpp46
-rw-r--r--src/device/device_declare.hpp37
-rw-r--r--src/device/device_default.cpp130
-rw-r--r--src/device/device_default.hpp12
-rw-r--r--src/device/device_ledger.cpp34
-rw-r--r--src/device/device_ledger.hpp12
7 files changed, 178 insertions, 96 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.hpp b/src/device/device.hpp
index 614d2c243..b47460472 100644
--- a/src/device/device.hpp
+++ b/src/device/device.hpp
@@ -44,9 +44,9 @@
#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
@@ -61,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
@@ -109,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 */
@@ -121,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;
@@ -129,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 */
/* ======================================================================= */
@@ -137,7 +160,12 @@ 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;
diff --git a/src/device/device_declare.hpp b/src/device/device_declare.hpp
deleted file mode 100644
index fcf5762af..000000000
--- a/src/device/device_declare.hpp
+++ /dev/null
@@ -1,37 +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
-
-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 7ae72af44..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,7 +251,7 @@ 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;
}
@@ -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 d7fc2b914..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,7 +100,7 @@ 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;
diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp
index 51837b8a2..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"
@@ -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();
@@ -593,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;
@@ -646,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;
@@ -717,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;
@@ -771,7 +777,7 @@ namespace hw {
unlock_device();
throw;
}
- return true;
+ return sub_sec;
}
/* ======================================================================= */
@@ -979,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");
}
@@ -1030,7 +1036,7 @@ namespace hw {
unlock_device();
throw;
}
- return true;
+ return sec;
}
@@ -1457,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;
diff --git a/src/device/device_ledger.hpp b/src/device/device_ledger.hpp
index 37e35167c..e06c5f72c 100644
--- a/src/device/device_ledger.hpp
+++ b/src/device/device_ledger.hpp
@@ -142,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 */
@@ -154,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;
@@ -170,7 +170,7 @@ 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;