From fd0d1c7d603ff33c65a596c005aa2408481ae52c Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 8 Jun 2017 16:07:49 +1200 Subject: [PATCH] Ensure that ECDSA constant sizes are correctly-sized --- src/key.cpp | 3 +++ src/pubkey.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/key.cpp b/src/key.cpp index 9da5ec891..a43131613 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -92,6 +92,9 @@ static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *ou */ static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) { assert(*privkeylen >= PRIVATE_KEY_SIZE); + static_assert( + PRIVATE_KEY_SIZE >= COMPRESSED_PRIVATE_KEY_SIZE, + "COMPRESSED_PRIVATE_KEY_SIZE is larger than PRIVATE_KEY_SIZE"); secp256k1_pubkey pubkey; size_t pubkeylen = 0; if (!secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) { diff --git a/src/pubkey.h b/src/pubkey.h index fb1352266..fcfa019cf 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -46,6 +46,9 @@ private: * Its length can very cheaply be computed from the first byte. */ unsigned char vch[PUBLIC_KEY_SIZE]; + static_assert( + PUBLIC_KEY_SIZE >= COMPRESSED_PUBLIC_KEY_SIZE, + "COMPRESSED_PUBLIC_KEY_SIZE is larger than PUBLIC_KEY_SIZE"); //! Compute the length of a pubkey with a given first byte. unsigned int static GetLen(unsigned char chHeader)