@@ -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
}
@@ -191,7 +188,7 @@ CPrivKey CKey::GetPrivKey() const {
191
188
CPubKey CKey::GetPubKey () const {
192
189
assert (fValid );
193
190
secp256k1_pubkey pubkey;
194
- size_t clen = PUBLIC_KEY_SIZE;
191
+ size_t clen = CPubKey:: PUBLIC_KEY_SIZE;
195
192
CPubKey result;
196
193
int ret = secp256k1_ec_pubkey_create (secp256k1_context_sign, &pubkey, begin ());
197
194
assert (ret);
@@ -204,8 +201,8 @@ CPubKey CKey::GetPubKey() const {
204
201
bool CKey::Sign (const uint256 &hash, std::vector<unsigned char >& vchSig, uint32_t test_case) const {
205
202
if (!fValid )
206
203
return false ;
207
- vchSig.resize (SIGNATURE_SIZE);
208
- size_t nSigLen = SIGNATURE_SIZE;
204
+ vchSig.resize (CPubKey:: SIGNATURE_SIZE);
205
+ size_t nSigLen = CPubKey:: SIGNATURE_SIZE;
209
206
unsigned char extra_entropy[32 ] = {0 };
210
207
WriteLE32 (extra_entropy, test_case);
211
208
secp256k1_ecdsa_signature sig;
@@ -233,7 +230,7 @@ bool CKey::VerifyPubKey(const CPubKey& pubkey) const {
233
230
bool CKey::SignCompact (const uint256 &hash, std::vector<unsigned char >& vchSig) const {
234
231
if (!fValid )
235
232
return false ;
236
- vchSig.resize (COMPACT_SIGNATURE_SIZE);
233
+ vchSig.resize (CPubKey:: COMPACT_SIGNATURE_SIZE);
237
234
int rec = -1 ;
238
235
secp256k1_ecdsa_recoverable_signature sig;
239
236
int ret = secp256k1_ecdsa_sign_recoverable (secp256k1_context_sign, &sig, hash.begin (), begin (), secp256k1_nonce_function_rfc6979, NULL );
@@ -264,7 +261,7 @@ bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const
264
261
LockObject (out);
265
262
if ((nChild >> 31 ) == 0 ) {
266
263
CPubKey pubkey = GetPubKey ();
267
- assert (pubkey.size () == COMPRESSED_PUBLIC_KEY_SIZE);
264
+ assert (pubkey.size () == CPubKey:: COMPRESSED_PUBLIC_KEY_SIZE);
268
265
BIP32Hash (cc, nChild, *pubkey.begin (), pubkey.begin ()+1 , out);
269
266
} else {
270
267
assert (size () == 32 );
0 commit comments