Skip to content

Commit 2a96154

Browse files
Introduce signature version flags
1 parent 5b669ff commit 2a96154

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

src/pubkey.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int ecdsa_signature_parse_der_lax(secp256k1_ecdsa_signature* sig, const unsigned
5353
secp256k1_ecdsa_signature_parse_compact(secp256k1_context_static, sig, tmpsig);
5454

5555
/* Sequence tag byte */
56-
if (pos == inputlen || input[pos] != 0x30) {
56+
if (pos == inputlen || input[pos] != CPubKey::SigFlag::VERSION_SIG_DER) {
5757
return 0;
5858
}
5959
pos++;

src/pubkey.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,41 @@ class CPubKey
4848
SIZE >= COMPRESSED_SIZE,
4949
"COMPRESSED_SIZE is larger than SIZE");
5050

51+
enum SigType {
52+
SIG_COMPACT = 0,
53+
SIG_DER = 1,
54+
SIG_COUNT
55+
};
56+
57+
enum SigFlag {
58+
VERSION_SIG_COMPACT = 1<<3, // must be greater than zero to avoid being interpreted as an uncompressed public key
59+
VERSION_SIG_DER = 6<<3,
60+
VERSION_SIG_MASK = 31<<3
61+
};
62+
63+
static int GetSigType(unsigned char flag)
64+
{
65+
switch (flag & VERSION_SIG_MASK) {
66+
case VERSION_SIG_COMPACT:
67+
return SIG_COMPACT;
68+
case VERSION_SIG_DER:
69+
return SIG_DER;
70+
default:
71+
return -1;
72+
}
73+
}
74+
75+
static unsigned char GetSigFlag(int type)
76+
{
77+
switch (type) {
78+
case SIG_COMPACT:
79+
return VERSION_SIG_COMPACT;
80+
case SIG_DER:
81+
default:
82+
return VERSION_SIG_DER;
83+
}
84+
}
85+
5186
private:
5287

5388
/**

src/script/interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ bool static IsValidSignatureEncoding(const std::vector<unsigned char> &sig) {
122122
if (sig.size() > 73) return false;
123123

124124
// A signature is of type 0x30 (compound).
125-
if (sig[0] != 0x30) return false;
125+
if (sig[0] != CPubKey::SigFlag::VERSION_SIG_DER) return false;
126126

127127
// Make sure the length covers the entire signature.
128128
if (sig[1] != sig.size() - 3) return false;

src/script/sign.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ class DummySignatureCreator final : public BaseSignatureCreator {
721721
{
722722
// Create a dummy signature that is a valid DER-encoding
723723
vchSig.assign(m_r_len + m_s_len + 7, '\000');
724-
vchSig[0] = 0x30;
724+
vchSig[0] = CPubKey::SigFlag::VERSION_SIG_DER;
725725
vchSig[1] = m_r_len + m_s_len + 4;
726726
vchSig[2] = 0x02;
727727
vchSig[3] = m_r_len;

0 commit comments

Comments
 (0)