From 4f382b383005d09f6056371d0fecdc8b6ce37a08 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 4 Jun 2014 18:59:47 -0400 Subject: most functions prototyped/modified for wallet recovery --- src/crypto/crypto.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/crypto/crypto.cpp') diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp index f5f525700..31fc31d5b 100644 --- a/src/crypto/crypto.cpp +++ b/src/crypto/crypto.cpp @@ -50,6 +50,7 @@ namespace crypto { return &reinterpret_cast(scalar); } + /* generate a random 32-byte (256-bit) integer and copy it to res */ static inline void random_scalar(ec_scalar &res) { unsigned char tmp[64]; generate_random_bytes(64, tmp); @@ -62,6 +63,11 @@ namespace crypto { sc_reduce32(&res); } + /* + * generate public and secret keys from a random 256-bit integer + * TODO: allow specifiying random value (for wallet recovery) + * + */ void crypto_ops::generate_keys(public_key &pub, secret_key &sec) { lock_guard lock(random_lock); ge_p3 point; -- cgit v1.2.3 From d22e458c6c680f4b5dcf56a58a37a5f79912e65c Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Fri, 6 Jun 2014 14:18:11 -0400 Subject: builds, but doesn't link. other than that, electrum-style recovery implemented (but not tested\!) --- src/crypto/crypto.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/crypto/crypto.cpp') diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp index 31fc31d5b..98a17a3e4 100644 --- a/src/crypto/crypto.cpp +++ b/src/crypto/crypto.cpp @@ -68,12 +68,27 @@ namespace crypto { * TODO: allow specifiying random value (for wallet recovery) * */ - void crypto_ops::generate_keys(public_key &pub, secret_key &sec) { + secret_key crypto_ops::generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key, bool recover) { lock_guard lock(random_lock); ge_p3 point; - random_scalar(sec); + + secret_key rng; + + if (recover) + { + rng = recovery_key; + } + else + { + random_scalar(rng); + } + sec = rng; + sc_reduce32(&sec); // reduce in case second round of keys (sendkeys) + ge_scalarmult_base(&point, &sec); ge_p3_tobytes(&pub, &point); + + return rng; } bool crypto_ops::check_key(const public_key &key) { -- cgit v1.2.3