@@ -85,16 +85,13 @@ static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *ou
85
85
* <http://www.secg.org/sec1-v2.pdf>. The optional parameters and publicKey fields are
86
86
* included.
87
87
*
88
- * privkey must point to an output buffer of length at least PRIVATE_KEY_SIZE bytes.
88
+ * privkey must point to an output buffer of length at least CKey:: PRIVATE_KEY_SIZE bytes.
89
89
* privkeylen must initially be set to the size of the privkey buffer. Upon return it
90
90
* will be set to the number of bytes used in the buffer.
91
91
* key32 must point to a 32-byte raw private key.
92
92
*/
93
93
static int ec_privkey_export_der (const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
94
- assert (*privkeylen >= PRIVATE_KEY_SIZE);
95
- static_assert (
96
- PRIVATE_KEY_SIZE >= COMPRESSED_PRIVATE_KEY_SIZE,
97
- " COMPRESSED_PRIVATE_KEY_SIZE is larger than PRIVATE_KEY_SIZE" );
94
+ assert (*privkeylen >= CKey::PRIVATE_KEY_SIZE);
98
95
secp256k1_pubkey pubkey;
99
96
size_t pubkeylen = 0 ;
100
97
if (!secp256k1_ec_pubkey_create (ctx, &pubkey, key32)) {
@@ -120,11 +117,11 @@ static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *pr
120
117
memcpy (ptr, begin, sizeof (begin)); ptr += sizeof (begin);
121
118
memcpy (ptr, key32, 32 ); ptr += 32 ;
122
119
memcpy (ptr, middle, sizeof (middle)); ptr += sizeof (middle);
123
- pubkeylen = COMPRESSED_PUBLIC_KEY_SIZE;
120
+ pubkeylen = CPubKey:: COMPRESSED_PUBLIC_KEY_SIZE;
124
121
secp256k1_ec_pubkey_serialize (ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
125
122
ptr += pubkeylen;
126
123
*privkeylen = ptr - privkey;
127
- assert (*privkeylen == COMPRESSED_PRIVATE_KEY_SIZE);
124
+ assert (*privkeylen == CKey:: COMPRESSED_PRIVATE_KEY_SIZE);
128
125
} else {
129
126
static const unsigned char begin[] = {
130
127
0x30 ,0x82 ,0x01 ,0x13 ,0x02 ,0x01 ,0x01 ,0x04 ,0x20
@@ -146,11 +143,11 @@ static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *pr
146
143
memcpy (ptr, begin, sizeof (begin)); ptr += sizeof (begin);
147
144
memcpy (ptr, key32, 32 ); ptr += 32 ;
148
145
memcpy (ptr, middle, sizeof (middle)); ptr += sizeof (middle);
149
- pubkeylen = PUBLIC_KEY_SIZE;
146
+ pubkeylen = CPubKey:: PUBLIC_KEY_SIZE;
150
147
secp256k1_ec_pubkey_serialize (ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
151
148
ptr += pubkeylen;
152
149
*privkeylen = ptr - privkey;
153
- assert (*privkeylen == PRIVATE_KEY_SIZE);
150
+ assert (*privkeylen == CKey:: PRIVATE_KEY_SIZE);
154
151
}
155
152
return 1 ;
156
153
}
@@ -183,7 +180,7 @@ CPrivKey CKey::GetPrivKey() const {
183
180
CPubKey CKey::GetPubKey () const {
184
181
assert (fValid );
185
182
secp256k1_pubkey pubkey;
186
- size_t clen = PUBLIC_KEY_SIZE;
183
+ size_t clen = CPubKey:: PUBLIC_KEY_SIZE;
187
184
CPubKey result;
188
185
int ret = secp256k1_ec_pubkey_create (secp256k1_context_sign, &pubkey, begin ());
189
186
assert (ret);
@@ -196,8 +193,8 @@ CPubKey CKey::GetPubKey() const {
196
193
bool CKey::Sign (const uint256 &hash, std::vector<unsigned char >& vchSig, uint32_t test_case) const {
197
194
if (!fValid )
198
195
return false ;
199
- vchSig.resize (SIGNATURE_SIZE);
200
- size_t nSigLen = SIGNATURE_SIZE;
196
+ vchSig.resize (CPubKey:: SIGNATURE_SIZE);
197
+ size_t nSigLen = CPubKey:: SIGNATURE_SIZE;
201
198
unsigned char extra_entropy[32 ] = {0 };
202
199
WriteLE32 (extra_entropy, test_case);
203
200
secp256k1_ecdsa_signature sig;
@@ -225,7 +222,7 @@ bool CKey::VerifyPubKey(const CPubKey& pubkey) const {
225
222
bool CKey::SignCompact (const uint256 &hash, std::vector<unsigned char >& vchSig) const {
226
223
if (!fValid )
227
224
return false ;
228
- vchSig.resize (COMPACT_SIGNATURE_SIZE);
225
+ vchSig.resize (CPubKey:: COMPACT_SIGNATURE_SIZE);
229
226
int rec = -1 ;
230
227
secp256k1_ecdsa_recoverable_signature sig;
231
228
int ret = secp256k1_ecdsa_sign_recoverable (secp256k1_context_sign, &sig, hash.begin (), begin (), secp256k1_nonce_function_rfc6979, NULL );
@@ -255,7 +252,7 @@ bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const
255
252
std::vector<unsigned char , secure_allocator<unsigned char >> vout (64 );
256
253
if ((nChild >> 31 ) == 0 ) {
257
254
CPubKey pubkey = GetPubKey ();
258
- assert (pubkey.size () == COMPRESSED_PUBLIC_KEY_SIZE);
255
+ assert (pubkey.size () == CPubKey:: COMPRESSED_PUBLIC_KEY_SIZE);
259
256
BIP32Hash (cc, nChild, *pubkey.begin (), pubkey.begin ()+1 , vout.data ());
260
257
} else {
261
258
assert (size () == 32 );
0 commit comments