aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/crypto.h
diff options
context:
space:
mode:
authorcslashm <cslashm@gmail.com>2018-02-20 17:01:27 +0100
committerCédric <cslashm@gmail.com>2018-03-04 12:54:53 +0100
commite745c1e38da8e54032660894bb2db0e9a49cccf2 (patch)
treefba40dea29a948b8a4904b4de189d4adc605ec6e /src/crypto/crypto.h
parentMerge pull request #3245 (diff)
downloadmonero-e745c1e38da8e54032660894bb2db0e9a49cccf2.tar.xz
Code modifications to integrate Ledger HW device into monero-wallet-cli.
The basic approach it to delegate all sensitive data (master key, secret ephemeral key, key derivation, ....) and related operations to the device. As device has low memory, it does not keep itself the values (except for view/spend keys) but once computed there are encrypted (with AES are equivalent) and return back to monero-wallet-cli. When they need to be manipulated by the device, they are decrypted on receive. Moreover, using the client for storing the value in encrypted form limits the modification in the client code. Those values are transfered from one C-structure to another one as previously. The code modification has been done with the wishes to be open to any other hardware wallet. To achieve that a C++ class hw::Device has been introduced. Two initial implementations are provided: the "default", which remaps all calls to initial Monero code, and the "Ledger", which delegates all calls to Ledger device.
Diffstat (limited to 'src/crypto/crypto.h')
-rw-r--r--src/crypto/crypto.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h
index 81ebfb9e2..75b333473 100644
--- a/src/crypto/crypto.h
+++ b/src/crypto/crypto.h
@@ -46,6 +46,10 @@
#include "hex.h"
#include "span.h"
#include "hash.h"
+#include "device/device_declare.hpp"
+extern "C" {
+ #include "crypto-ops.h"
+}
namespace crypto {
@@ -113,6 +117,9 @@ namespace crypto {
void operator=(const crypto_ops &);
~crypto_ops();
+ static void hash_to_ec(const public_key &key, ge_p3 &res) ;
+ friend void hash_to_ec(const public_key &key, ge_p3 &res) ;
+
static secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key = secret_key(), bool recover = false);
friend secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key, bool recover);
static bool check_key(const public_key &);
@@ -149,6 +156,17 @@ namespace crypto {
const public_key *const *, std::size_t, const signature *);
};
+ secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key, bool recover, hw::device &hwdev);
+ secret_key generate_keys(public_key &pub, secret_key &sec, hw::device &hwdev);
+ bool secret_key_to_public_key(const secret_key &sec, public_key &pub, hw::device &hwdev);
+ bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation, hw::device &hwdev);
+ void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res, hw::device &hwdev) ;
+ bool derive_public_key(const key_derivation &derivation, size_t output_index, const public_key &base, public_key &derived_key, hw::device &hwdev);
+ void derive_secret_key(const key_derivation &derivation, size_t output_index, const secret_key &base, secret_key &derived_key, hw::device &hwdev);
+ bool derive_subaddress_public_key(const public_key &out_key, const key_derivation &derivation, std::size_t output_index, public_key &derived_key, hw::device &hwdev);
+ void generate_key_image(const public_key &pub, const secret_key &sec, key_image &image, hw::device &hwdev);
+
+
/* Generate N random bytes
*/
inline void rand(size_t N, uint8_t *bytes) {
@@ -166,6 +184,9 @@ namespace crypto {
return res;
}
+ inline void hash_to_ec(const public_key &key, ge_p3 &res) {
+ crypto_ops::hash_to_ec(key,res);
+ }
/* Generate a new key pair
*/
inline secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key = secret_key(), bool recover = false) {