aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/crypto.cpp
diff options
context:
space:
mode:
authormonero-project <sempre.amaro@gmail.com>2014-06-12 19:14:25 -0400
committermonero-project <sempre.amaro@gmail.com>2014-06-12 19:14:25 -0400
commitc3203c86c671d41ed4a07231c8a5054124d2e7d2 (patch)
tree06a7aceb34d1e53ca4bfd28d3fbc13b5ef0d8a30 /src/crypto/crypto.cpp
parentnew error code for rpc (diff)
parentallow two-random-numbers wallet generation (but not as default) (diff)
downloadmonero-c3203c86c671d41ed4a07231c8a5054124d2e7d2.tar.xz
Merge pull request #34 from tewinget/master
Add electrum-seed wallet backup/recovery
Diffstat (limited to 'src/crypto/crypto.cpp')
-rw-r--r--src/crypto/crypto.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp
index f5f525700..98a17a3e4 100644
--- a/src/crypto/crypto.cpp
+++ b/src/crypto/crypto.cpp
@@ -50,6 +50,7 @@ namespace crypto {
return &reinterpret_cast<const unsigned char &>(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,12 +63,32 @@ namespace crypto {
sc_reduce32(&res);
}
- void crypto_ops::generate_keys(public_key &pub, secret_key &sec) {
+ /*
+ * generate public and secret keys from a random 256-bit integer
+ * TODO: allow specifiying random value (for wallet recovery)
+ *
+ */
+ secret_key crypto_ops::generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key, bool recover) {
lock_guard<mutex> 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) {