From 11529c6e4f7288d8a64c488a726ee3821c7adefe Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 21 Nov 2011 02:46:28 +0100 Subject: Compressed pubkeys This patch enabled compressed pubkeys when -compressedpubkeys is passed. These are 33 bytes instead of 65, and require only marginally more CPU power when verifying. Compressed pubkeys have a different corresponding address, so it is determined at generation. When -compressedpubkeys is given, all newly generated addresses will use a compressed key, while older/other addresses keep using normal keys. Unpatched clients will relay and verify these transactions. --- src/base58.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/base58.h') diff --git a/src/base58.h b/src/base58.h index ef6493d45b..dce932b4a8 100644 --- a/src/base58.h +++ b/src/base58.h @@ -359,22 +359,25 @@ public: class CBitcoinSecret : public CBase58Data { public: - void SetSecret(const CSecret& vchSecret) - { + void SetSecret(const CSecret& vchSecret, bool fCompressed) + { + assert(vchSecret.size() == 32); SetData(fTestNet ? 239 : 128, &vchSecret[0], vchSecret.size()); + if (fCompressed) + vchData.push_back(1); } - CSecret GetSecret() + CSecret GetSecret(bool &fCompressedOut) { CSecret vchSecret; - vchSecret.resize(vchData.size()); - memcpy(&vchSecret[0], &vchData[0], vchData.size()); + vchSecret.resize(32); + memcpy(&vchSecret[0], &vchData[0], 32); + fCompressedOut = vchData.size() == 33; return vchSecret; } bool IsValid() const { - int nExpectedSize = 32; bool fExpectTestNet = false; switch(nVersion) { @@ -388,12 +391,12 @@ public: default: return false; } - return fExpectTestNet == fTestNet && vchData.size() == nExpectedSize; + return fExpectTestNet == fTestNet && (vchData.size() == 32 || (vchData.size() == 33 && vchData[32] == 1)); } - CBitcoinSecret(const CSecret& vchSecret) + CBitcoinSecret(const CSecret& vchSecret, bool fCompressed) { - SetSecret(vchSecret); + SetSecret(vchSecret, fCompressed); } CBitcoinSecret() -- cgit v1.2.3