mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Merge pull request #5227
4cdaa95Resize after succesful result (Pieter Wuille)9d8604fHeader define style cleanups (Pieter Wuille)a53fd41Deterministic signing (Pieter Wuille)3060e36Add the RFC6979 PRNG (Pieter Wuille)a8f5087Add HMAC-SHA256 (Pieter Wuille)36fa4a7Split up crypto/sha2 (Pieter Wuille)
This commit is contained in:
32
src/key.cpp
32
src/key.cpp
@@ -4,7 +4,8 @@
|
||||
|
||||
#include "key.h"
|
||||
|
||||
#include "crypto/sha2.h"
|
||||
#include "crypto/hmac_sha512.h"
|
||||
#include "crypto/rfc6979_hmac_sha256.h"
|
||||
#include "eccryptoverify.h"
|
||||
#include "pubkey.h"
|
||||
#include "random.h"
|
||||
@@ -71,19 +72,23 @@ CPubKey CKey::GetPubKey() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CKey::Sign(const uint256 &hash, std::vector<unsigned char>& vchSig) const {
|
||||
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;
|
||||
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);
|
||||
nonce = 0;
|
||||
if (ret) {
|
||||
vchSig.resize(nSigLen);
|
||||
return true;
|
||||
}
|
||||
} while(true);
|
||||
vchSig.resize(nSigLen);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CKey::VerifyPubKey(const CPubKey& pubkey) const {
|
||||
@@ -105,10 +110,13 @@ bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& 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);
|
||||
|
||||
Reference in New Issue
Block a user