From 57769e4df9324c1d72c73b9f1de61b5f7f2caae5 Mon Sep 17 00:00:00 2001 From: Tzadik Vanderhoof Date: Mon, 24 Feb 2014 00:47:00 -0500 Subject: [PATCH 1/2] BSX-21 Import Bitcoin Private Key from String --- include/fc/crypto/sha256.hpp | 1 + src/crypto/sha256.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/include/fc/crypto/sha256.hpp b/include/fc/crypto/sha256.hpp index af0e6b2..8d7f2cd 100644 --- a/include/fc/crypto/sha256.hpp +++ b/include/fc/crypto/sha256.hpp @@ -11,6 +11,7 @@ class sha256 public: sha256(); explicit sha256( const string& hex_str ); + explicit sha256( const char *data ); string str()const; operator string()const; diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp index 63b38cc..d85b0d0 100644 --- a/src/crypto/sha256.cpp +++ b/src/crypto/sha256.cpp @@ -8,6 +8,7 @@ namespace fc { sha256::sha256() { memset( _hash, 0, sizeof(_hash) ); } + sha256::sha256( const char *data ) { memcpy(_hash, data, sizeof(_hash) ); } sha256::sha256( const string& hex_str ) { fc::from_hex( hex_str, (char*)_hash, sizeof(_hash) ); } From 0761d32d0125dbaf404ce6c56f27f3c04ac85fc4 Mon Sep 17 00:00:00 2001 From: Tzadik Vanderhoof Date: Mon, 24 Feb 2014 02:08:48 -0500 Subject: [PATCH 2/2] safer sha256 binary constructor --- include/fc/crypto/sha256.hpp | 2 +- src/crypto/sha256.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/fc/crypto/sha256.hpp b/include/fc/crypto/sha256.hpp index 8d7f2cd..f17e34e 100644 --- a/include/fc/crypto/sha256.hpp +++ b/include/fc/crypto/sha256.hpp @@ -11,7 +11,7 @@ class sha256 public: sha256(); explicit sha256( const string& hex_str ); - explicit sha256( const char *data ); + explicit sha256( const char *data, size_t size ); string str()const; operator string()const; diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp index d85b0d0..e197a9d 100644 --- a/src/crypto/sha256.cpp +++ b/src/crypto/sha256.cpp @@ -4,11 +4,16 @@ #include #include #include +#include namespace fc { sha256::sha256() { memset( _hash, 0, sizeof(_hash) ); } - sha256::sha256( const char *data ) { memcpy(_hash, data, sizeof(_hash) ); } + sha256::sha256( const char *data, size_t size ) { + if (size != sizeof(_hash)) + FC_THROW_EXCEPTION( exception, "sha256: size mismatch" ); + memcpy(_hash, data, size ); + } sha256::sha256( const string& hex_str ) { fc::from_hex( hex_str, (char*)_hash, sizeof(_hash) ); }