Skip to content

Commit 1ce9f0a

Browse files
committed
Ensure that ECDSA constant sizes are correctly-sized
1 parent 48abe78 commit 1ce9f0a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/key.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *ou
9292
*/
9393
static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
9494
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");
9598
secp256k1_pubkey pubkey;
9699
size_t pubkeylen = 0;
97100
if (!secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) {

src/pubkey.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class CPubKey
4848
* Its length can very cheaply be computed from the first byte.
4949
*/
5050
unsigned char vch[PUBLIC_KEY_SIZE];
51+
static_assert(
52+
PUBLIC_KEY_SIZE >= COMPRESSED_PUBLIC_KEY_SIZE,
53+
"COMPRESSED_PUBLIC_KEY_SIZE is larger than PUBLIC_KEY_SIZE");
5154

5255
//! Compute the length of a pubkey with a given first byte.
5356
unsigned int static GetLen(unsigned char chHeader)

0 commit comments

Comments
 (0)