From d76a15ec896dddb021ef8aeb9f77bba34dadd27b Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Thu, 23 Jul 2015 18:45:35 -0400 Subject: [PATCH] adding child key derivation for ecc keys --- include/fc/crypto/elliptic.hpp | 4 ++++ src/crypto/elliptic_common.cpp | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/fc/crypto/elliptic.hpp b/include/fc/crypto/elliptic.hpp index 31e50a0..b05dc58 100644 --- a/include/fc/crypto/elliptic.hpp +++ b/include/fc/crypto/elliptic.hpp @@ -46,6 +46,8 @@ namespace fc { public_key( const public_key_point_data& v ); public_key( const compact_signature& c, const fc::sha256& digest, bool check_canonical = true ); + public_key child( const fc::sha256& offset )const; + bool valid()const; /** Computes new pubkey = generator * offset + old pubkey ?! */ // public_key mult( const fc::sha256& offset )const; @@ -96,6 +98,8 @@ namespace fc { static private_key generate(); static private_key regenerate( const fc::sha256& secret ); + private_key child( const fc::sha256& offset )const; + /** * This method of generation enables creating a new private key in a deterministic manner relative to * an initial seed. A public_key created from the seed can be multiplied by the offset to calculate diff --git a/src/crypto/elliptic_common.cpp b/src/crypto/elliptic_common.cpp index 741682e..a66c26b 100644 --- a/src/crypto/elliptic_common.cpp +++ b/src/crypto/elliptic_common.cpp @@ -1,5 +1,6 @@ #include #include +#include /* stuff common to all ecc implementations */ @@ -9,6 +10,23 @@ namespace fc { namespace ecc { return public_key(data); } + public_key public_key::child( const fc::sha256& offset )const + { + fc::sha256::encoder enc; + fc::raw::pack( enc, *this ); + fc::raw::pack( enc, offset ); + + return add( enc.result() ); + } + + private_key private_key::child( const fc::sha256& offset )const + { + fc::sha256::encoder enc; + fc::raw::pack( enc, get_public_key() ); + fc::raw::pack( enc, offset ); + return generate_from_seed( get_secret(), enc.result() ); + } + std::string public_key::to_base58( const public_key_data &key ) { uint32_t check = (uint32_t)sha256::hash(key.data, sizeof(key))._hash[0];