From 36fa4a78acac0ae6bb0e95c6ef78630120a28bdd Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 26 Oct 2014 01:23:23 -0700 Subject: Split up crypto/sha2 --- src/key.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/key.cpp') diff --git a/src/key.cpp b/src/key.cpp index 76256b864..9b3cf8f01 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -4,7 +4,7 @@ #include "key.h" -#include "crypto/sha2.h" +#include "crypto/hmac_sha512.h" #include "eccryptoverify.h" #include "pubkey.h" #include "random.h" -- cgit v1.2.3 From a53fd4148596f5814409e15647714bdd2a71468b Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 6 Nov 2014 06:54:50 -0800 Subject: Deterministic signing --- src/key.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/key.cpp') diff --git a/src/key.cpp b/src/key.cpp index 9b3cf8f01..0fb7a5c7c 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -5,6 +5,7 @@ #include "key.h" #include "crypto/hmac_sha512.h" +#include "crypto/rfc6979_hmac_sha256.h" #include "eccryptoverify.h" #include "pubkey.h" #include "random.h" @@ -71,19 +72,22 @@ CPubKey CKey::GetPubKey() const { return result; } -bool CKey::Sign(const uint256 &hash, std::vector& vchSig) const { +bool CKey::Sign(const uint256 &hash, std::vector& vchSig, uint32_t test_case) const { if (!fValid) return false; vchSig.resize(72); - int nSigLen = 72; - CKey nonce; + RFC6979_HMAC_SHA256 prng(begin(), 32, (unsigned char*)&hash, 32); do { - nonce.MakeNewKey(true); - if (secp256k1_ecdsa_sign((const unsigned char*)&hash, 32, (unsigned char*)&vchSig[0], &nSigLen, begin(), nonce.begin())) - break; + uint256 nonce; + prng.Generate((unsigned char*)&nonce, 32); + nonce += test_case; + int nSigLen = 72; + int ret = secp256k1_ecdsa_sign((const unsigned char*)&hash, 32, (unsigned char*)&vchSig[0], &nSigLen, begin(), (unsigned char*)&nonce); + vchSig.resize(nSigLen); + nonce = 0; + if (ret) + return true; } while(true); - vchSig.resize(nSigLen); - return true; } bool CKey::SignCompact(const uint256 &hash, std::vector& vchSig) const { @@ -91,10 +95,13 @@ bool CKey::SignCompact(const uint256 &hash, std::vector& vchSig) return false; vchSig.resize(65); int rec = -1; - CKey nonce; + RFC6979_HMAC_SHA256 prng(begin(), 32, (unsigned char*)&hash, 32); do { - nonce.MakeNewKey(true); - if (secp256k1_ecdsa_sign_compact((const unsigned char*)&hash, 32, &vchSig[1], begin(), nonce.begin(), &rec)) + uint256 nonce; + prng.Generate((unsigned char*)&nonce, 32); + int ret = secp256k1_ecdsa_sign_compact((const unsigned char*)&hash, 32, &vchSig[1], begin(), (unsigned char*)&nonce, &rec); + nonce = 0; + if (ret) break; } while(true); assert(rec != -1); -- cgit v1.2.3 From 4cdaa95a209808276992dc1eb0ed0773f7927073 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 28 Nov 2014 21:16:51 +0100 Subject: Resize after succesful result --- src/key.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/key.cpp') diff --git a/src/key.cpp b/src/key.cpp index 0fb7a5c7c..07fffcb0e 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -83,10 +83,11 @@ bool CKey::Sign(const uint256 &hash, std::vector& vchSig, uint32_ nonce += test_case; int nSigLen = 72; int ret = secp256k1_ecdsa_sign((const unsigned char*)&hash, 32, (unsigned char*)&vchSig[0], &nSigLen, begin(), (unsigned char*)&nonce); - vchSig.resize(nSigLen); nonce = 0; - if (ret) + if (ret) { + vchSig.resize(nSigLen); return true; + } } while(true); } -- cgit v1.2.3