From 9db52a232a94eb1eed543f89fc7a5e613adc4fed Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sat, 23 Jun 2012 21:53:54 -0700 Subject: [PATCH] Split get signing hash operation and signature verify operation. --- src/LedgerProposal.cpp | 4 ++-- src/LedgerProposal.h | 3 ++- src/SerializedValidation.cpp | 8 ++++++-- src/SerializedValidation.h | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/LedgerProposal.cpp b/src/LedgerProposal.cpp index 9f435415bd..01cdd9607b 100644 --- a/src/LedgerProposal.cpp +++ b/src/LedgerProposal.cpp @@ -46,9 +46,9 @@ uint256 LedgerProposal::getSigningHash() const return s.getSHA512Half(); } -bool LedgerProposal::checkSign(const std::string& signature) +bool LedgerProposal::checkSign(const std::string& signature, const uint256& signingHash) { - return mPublicKey.verifyNodePublic(getSigningHash(), signature); + return mPublicKey.verifyNodePublic(signingHash, signature); } void LedgerProposal::changePosition(const uint256& newPosition) diff --git a/src/LedgerProposal.h b/src/LedgerProposal.h index f7e50cc639..4dd32cd75d 100644 --- a/src/LedgerProposal.h +++ b/src/LedgerProposal.h @@ -36,7 +36,8 @@ public: LedgerProposal(const uint256& prevLedger, const uint256& position); uint256 getSigningHash() const; - bool checkSign(const std::string& signature); + bool checkSign(const std::string& signature, const uint256& signingHash); + bool checkSign(const std::string& signature) { return checkSign(signature, getSigningHash()); } const uint160& getPeerID() const { return mPeerID; } const uint256& getCurrentHash() const { return mCurrentHash; } diff --git a/src/SerializedValidation.cpp b/src/SerializedValidation.cpp index 9c19bc7615..b9d89e4f2a 100644 --- a/src/SerializedValidation.cpp +++ b/src/SerializedValidation.cpp @@ -56,12 +56,16 @@ uint64 SerializedValidation::getCloseTime() const } bool SerializedValidation::isValid() const +{ + return isValid(getSigningHash()); +} + +bool SerializedValidation::isValid(const uint256& signingHash) const { try { NewcoinAddress naPublicKey = NewcoinAddress::createNodePublic(getValueFieldVL(sfSigningKey)); - - return naPublicKey.isValid() && naPublicKey.verifyNodePublic(getSigningHash(), mSignature.peekValue()); + return naPublicKey.isValid() && naPublicKey.verifyNodePublic(signingHash, mSignature.peekValue()); } catch (...) { diff --git a/src/SerializedValidation.h b/src/SerializedValidation.h index ab0886a6bf..863dea31b9 100644 --- a/src/SerializedValidation.h +++ b/src/SerializedValidation.h @@ -33,6 +33,7 @@ public: bool isTrusted() const { return mTrusted; } CKey::pointer getSigningKey() const; uint256 getSigningHash() const; + bool isValid(const uint256&) const; void setTrusted() { mTrusted = true; } void addSigned(Serializer&) const;