From 437ada3e55df8ae6f801cb2aa2e79ec5bb5f1971 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 27 Mar 2015 15:31:44 -0700 Subject: 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. --- src/key.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'src/key.cpp') 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(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& 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; -- cgit v1.2.3