From 8138cbea3c405e142d70b43b6c452e1738de3332 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 20 Sep 2014 03:13:04 +0200 Subject: Add automatic script test generation, and actual checksig tests --- src/key.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/key.cpp') diff --git a/src/key.cpp b/src/key.cpp index 8ed787654..c2251b4f2 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -220,7 +220,7 @@ public: return o2i_ECPublicKey(&pkey, &pbegin, pubkey.size()) != NULL; } - bool Sign(const uint256 &hash, std::vector& vchSig) { + bool Sign(const uint256 &hash, std::vector& vchSig, bool lowS) { vchSig.clear(); ECDSA_SIG *sig = ECDSA_do_sign((unsigned char*)&hash, sizeof(hash), pkey); if (sig == NULL) @@ -232,7 +232,7 @@ public: BIGNUM *halforder = BN_CTX_get(ctx); EC_GROUP_get_order(group, order, ctx); BN_rshift1(halforder, order); - if (BN_cmp(sig->s, halforder) > 0) { + if (lowS && BN_cmp(sig->s, halforder) > 0) { // enforce low S values, by negating the value (modulo the order) if above order/2. BN_sub(sig->s, order, sig->s); } @@ -467,7 +467,7 @@ CPubKey CKey::GetPubKey() const { return pubkey; } -bool CKey::Sign(const uint256 &hash, std::vector& vchSig) const { +bool CKey::Sign(const uint256 &hash, std::vector& vchSig, bool lowS) const { if (!fValid) return false; #ifdef USE_SECP256K1 @@ -484,7 +484,7 @@ bool CKey::Sign(const uint256 &hash, std::vector& vchSig) const { #else CECKey key; key.SetSecretBytes(vch); - return key.Sign(hash, vchSig); + return key.Sign(hash, vchSig, lowS); #endif } -- cgit v1.2.3