Specify ECDSA constant sizes as constants

This commit is contained in:
Jack Grigg
2017-06-06 19:21:34 +12:00
parent e4a10860a4
commit 17fa3913ef
4 changed files with 44 additions and 33 deletions

View File

@@ -1,5 +1,6 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Copyright (c) 2017 The Zcash developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -15,10 +16,12 @@
/**
* secp256k1:
* const unsigned int PRIVATE_KEY_SIZE = 279;
* const unsigned int PUBLIC_KEY_SIZE = 65;
* const unsigned int SIGNATURE_SIZE = 72;
*
*/
const unsigned int PUBLIC_KEY_SIZE = 65;
const unsigned int COMPRESSED_PUBLIC_KEY_SIZE = 33;
const unsigned int SIGNATURE_SIZE = 72;
const unsigned int COMPACT_SIGNATURE_SIZE = 65;
/**
* see www.keylength.com
* script supports up to 75 for single byte push
*/
@@ -44,15 +47,15 @@ private:
* Just store the serialized data.
* Its length can very cheaply be computed from the first byte.
*/
unsigned char vch[65];
unsigned char vch[PUBLIC_KEY_SIZE];
//! Compute the length of a pubkey with a given first byte.
unsigned int static GetLen(unsigned char chHeader)
{
if (chHeader == 2 || chHeader == 3)
return 33;
return COMPRESSED_PUBLIC_KEY_SIZE;
if (chHeader == 4 || chHeader == 6 || chHeader == 7)
return 65;
return PUBLIC_KEY_SIZE;
return 0;
}
@@ -127,7 +130,7 @@ public:
void Unserialize(Stream& s)
{
unsigned int len = ::ReadCompactSize(s);
if (len <= 65) {
if (len <= PUBLIC_KEY_SIZE) {
s.read((char*)vch, len);
} else {
// invalid pubkey, skip available data
@@ -166,7 +169,7 @@ public:
//! Check whether this is a compressed public key.
bool IsCompressed() const
{
return size() == 33;
return size() == COMPRESSED_PUBLIC_KEY_SIZE;
}
/**