aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <sipa@ulyssis.org>2011-12-25 15:02:31 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2012-01-09 15:18:19 +0100
commitd4d9c734c315e99136fe245c5733ca75cab9f8bf (patch)
treebcbe825e800b516a9c93ca5aea1bb5fbb7327b03 /src
parent11529c6e4f7288d8a64c488a726ee3821c7adefe (diff)
Compact signatures with compressed pubkeys
Diffstat (limited to 'src')
-rw-r--r--src/key.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/key.h b/src/key.h
index b6d805c0c1..c28222a9a1 100644
--- a/src/key.h
+++ b/src/key.h
@@ -236,6 +236,8 @@ public:
{
CKey keyRec;
keyRec.fSet = true;
+ if (fCompressedPubKey)
+ keyRec.SetCompressedPubKey();
if (ECDSA_SIG_recover_key_GFp(keyRec.pkey, sig, (unsigned char*)&hash, sizeof(hash), i, 1) == 1)
if (keyRec.GetPubKey() == this->GetPubKey())
{
@@ -247,7 +249,7 @@ public:
if (nRecId == -1)
throw key_error("CKey::SignCompact() : unable to construct recoverable key");
- vchSig[0] = nRecId+27;
+ vchSig[0] = nRecId+27+(fCompressedPubKey ? 4 : 0);
BN_bn2bin(sig->r,&vchSig[33-(nBitsR+7)/8]);
BN_bn2bin(sig->s,&vchSig[65-(nBitsS+7)/8]);
fOk = true;
@@ -264,7 +266,8 @@ public:
{
if (vchSig.size() != 65)
return false;
- if (vchSig[0]<27 || vchSig[0]>=31)
+ int nV = vchSig[0];
+ if (nV<27 || nV>=35)
return false;
ECDSA_SIG *sig = ECDSA_SIG_new();
BN_bin2bn(&vchSig[1],32,sig->r);
@@ -272,7 +275,12 @@ public:
EC_KEY_free(pkey);
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
- if (ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), vchSig[0] - 27, 0) == 1)
+ if (nV >= 31)
+ {
+ SetCompressedPubKey();
+ nV -= 4;
+ }
+ if (ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), nV - 27, 0) == 1)
{
fSet = true;
ECDSA_SIG_free(sig);