From 51ba107e2ca2b510053a5459b318ced946ccf7df Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sat, 9 Jun 2012 02:22:00 -0700 Subject: [PATCH] Fix breakage. --- src/DeterministicKeys.cpp | 15 +++++++++++---- src/NewcoinAddress.cpp | 28 +++------------------------- src/NewcoinAddress.h | 1 - src/key.h | 8 ++++++-- 4 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/DeterministicKeys.cpp b/src/DeterministicKeys.cpp index 2373fe52c1..e95280c72c 100644 --- a/src/DeterministicKeys.cpp +++ b/src/DeterministicKeys.cpp @@ -3,6 +3,7 @@ #include #include #include +#include // Functions to add CKey support for deterministic EC keys @@ -115,26 +116,32 @@ EC_KEY* CKey::GenerateRootDeterministicKey(const uint128& seed) // <-- root public generator in EC format EC_KEY* CKey::GenerateRootPubKey(BIGNUM* pubGenerator) { - if(pubGenerator==NULL) return NULL; + if (pubGenerator == NULL) + { + assert(false); + return NULL; + } - EC_KEY* pkey=EC_KEY_new_by_curve_name(NID_secp256k1); - if(!pkey) + EC_KEY* pkey = EC_KEY_new_by_curve_name(NID_secp256k1); + if (!pkey) { BN_free(pubGenerator); return NULL; } EC_KEY_set_conv_form(pkey, POINT_CONVERSION_COMPRESSED); - EC_POINT* pubPoint=EC_POINT_bn2point(EC_KEY_get0_group(pkey), pubGenerator, NULL, NULL); + EC_POINT* pubPoint = EC_POINT_bn2point(EC_KEY_get0_group(pkey), pubGenerator, NULL, NULL); BN_free(pubGenerator); if(!pubPoint) { + assert(false); EC_KEY_free(pkey); return NULL; } if(!EC_KEY_set_public_key(pkey, pubPoint)) { + assert(false); EC_POINT_free(pubPoint); EC_KEY_free(pkey); return NULL; diff --git a/src/NewcoinAddress.cpp b/src/NewcoinAddress.cpp index ccb6e311fb..a621b7f75b 100644 --- a/src/NewcoinAddress.cpp +++ b/src/NewcoinAddress.cpp @@ -490,7 +490,7 @@ std::vector NewcoinAddress::accountPrivateDecrypt(const NewcoinAd // BIGNUM* NewcoinAddress::getFamilyGeneratorBN() const -{ +{ // returns the public generator switch (nVersion) { case VER_NONE: throw std::runtime_error("unset source"); @@ -503,35 +503,13 @@ BIGNUM* NewcoinAddress::getFamilyGeneratorBN() const throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } - assert(vchData.size() <= ((256 + 8) / 8)); - BIGNUM* ret = BN_bin2bn(&vchData[1], vchData.size() - 1, NULL); + BIGNUM* ret = BN_bin2bn(&vchData[0], vchData.size(), NULL); assert(ret); - - return ret; -} - -uint256 NewcoinAddress::getFamilyGeneratorU() const -{ - switch (nVersion) { - case VER_NONE: - throw std::runtime_error("unset source"); - - case VER_FAMILY_GENERATOR: - // Do nothing. - break; - - default: - throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); - } - - assert(vchData.size() <= ((256 + 1) / 8)); - uint256 ret; - memcpy(ret.begin() + (ret.size() - (vchData.size() - 1)), &vchData[1], vchData.size() - 1); return ret; } const std::vector& NewcoinAddress::getFamilyGenerator() const -{ +{ // returns the public generator switch (nVersion) { case VER_NONE: throw std::runtime_error("unset source"); diff --git a/src/NewcoinAddress.h b/src/NewcoinAddress.h index 8e3069d722..3418669152 100644 --- a/src/NewcoinAddress.h +++ b/src/NewcoinAddress.h @@ -136,7 +136,6 @@ public: // Use to generate a master or regular family. // BIGNUM* getFamilyGeneratorBN() const; // DEPRECATED - uint256 getFamilyGeneratorU() const; const std::vector& getFamilyGenerator() const; std::string humanFamilyGenerator() const; diff --git a/src/key.h b/src/key.h index 38a47e8c26..213bae4ddc 100644 --- a/src/key.h +++ b/src/key.h @@ -156,14 +156,16 @@ public: SetPrivateKeyU(privateKey); } +#if 0 CKey(const NewcoinAddress& masterKey, int keyNum, bool isPublic) : pkey(NULL), fSet(false) { if (isPublic) SetPubSeq(masterKey, keyNum); else - SetPrivSeq(masterKey, keyNum); + SetPrivSeq(masterKey, keyNum); // broken, need seed fSet = true; } +#endif bool IsNull() const { @@ -257,8 +259,9 @@ public: fSet = true; } +#if 0 void SetPrivSeq(const NewcoinAddress& masterKey, int keyNum) - { + { // broken: Need the seed uint256 privKey; EC_KEY* key = GeneratePrivateDeterministicKey(masterKey, masterKey.getFamilyGeneratorU(), keyNum); privKey.zero(); @@ -267,6 +270,7 @@ public: pkey = key; fSet = true; } +#endif CPrivKey GetPrivKey() {