aboutsummaryrefslogtreecommitdiff
path: root/src/key.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2015-03-27 15:31:44 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2015-03-27 15:31:47 -0700
commit437ada3e55df8ae6f801cb2aa2e79ec5bb5f1971 (patch)
tree51fe5e19a064fc7637de9145c9004823fcb110d6 /src/key.cpp
parent223d8630b0bf1809d29660004255237ad9d15f86 (diff)
downloadbitcoin-437ada3e55df8ae6f801cb2aa2e79ec5bb5f1971.tar.xz
Switch test case signing to RFC6979 extra entropy
Instead of manually tweaking the deterministic nonce post-generation, pass the test case number in as extra entropy to RFC6979.
Diffstat (limited to 'src/key.cpp')
-rw-r--r--src/key.cpp18
1 files changed, 4 insertions, 14 deletions
diff --git a/src/key.cpp b/src/key.cpp
index 64c9bc7119..e146e47d0d 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -5,6 +5,7 @@
#include "key.h"
#include "arith_uint256.h"
+#include "crypto/common.h"
#include "crypto/hmac_sha512.h"
#include "eccryptoverify.h"
#include "pubkey.h"
@@ -73,25 +74,14 @@ CPubKey CKey::GetPubKey() const {
return result;
}
-extern "C"
-{
-static int secp256k1_nonce_function_test_case(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, unsigned int attempt, const void *data)
-{
- const uint32_t *test_case = static_cast<const uint32_t*>(data);
- uint256 nonce;
- secp256k1_nonce_function_rfc6979(nonce.begin(), msg32, key32, attempt, NULL);
- nonce = ArithToUint256(UintToArith256(nonce) + *test_case);
- memcpy(nonce32, nonce.begin(), 32);
- return 1;
-}
-}
-
bool CKey::Sign(const uint256 &hash, std::vector<unsigned char>& vchSig, uint32_t test_case) const {
if (!fValid)
return false;
vchSig.resize(72);
int nSigLen = 72;
- int ret = secp256k1_ecdsa_sign(hash.begin(), (unsigned char*)&vchSig[0], &nSigLen, begin(), test_case == 0 ? secp256k1_nonce_function_rfc6979 : secp256k1_nonce_function_test_case, test_case == 0 ? NULL : &test_case);
+ unsigned char extra_entropy[32] = {0};
+ WriteLE32(extra_entropy, test_case);
+ int ret = secp256k1_ecdsa_sign(hash.begin(), (unsigned char*)&vchSig[0], &nSigLen, begin(), secp256k1_nonce_function_rfc6979, test_case ? extra_entropy : NULL);
assert(ret);
vchSig.resize(nSigLen);
return true;