diff --git a/ecdsa.c b/ecdsa.c index e166ff8f0..1f0e836c9 100644 --- a/ecdsa.c +++ b/ecdsa.c @@ -879,7 +879,7 @@ void ecdsa_get_address_raw(const uint8_t *pub_key, uint32_t version, uint8_t *ad void ecdsa_get_address(const uint8_t *pub_key, uint32_t version, char *addr, int addrsize) { - uint8_t raw[20+4]; + uint8_t raw[MAX_ADDR_RAW_SIZE]; ecdsa_get_address_raw(pub_key, version, raw); if (version <= 0xFF) { base58_encode_check(raw, 21, addr, addrsize); @@ -896,7 +896,7 @@ void ecdsa_get_address(const uint8_t *pub_key, uint32_t version, char *addr, int void ecdsa_get_wif(const uint8_t *priv_key, uint32_t version, char *wif, int wifsize) { - uint8_t wif_raw[4 + 32 + 1]; + uint8_t wif_raw[MAX_WIF_RAW_SIZE]; if (version <= 0xFF) { wif_raw[0] = version; diff --git a/ecdsa.h b/ecdsa.h index a07e418ca..5b785617a 100644 --- a/ecdsa.h +++ b/ecdsa.h @@ -48,6 +48,9 @@ typedef struct { } ecdsa_curve; +#define MAX_ADDR_RAW_SIZE (4 + 20) +#define MAX_WIF_RAW_SIZE (4 + 32 + 1) + // rfc6979 pseudo random number generator state typedef struct { uint8_t v[32], k[32]; diff --git a/tests.c b/tests.c index 0eda9710e..964e6e11a 100644 --- a/tests.c +++ b/tests.c @@ -2150,9 +2150,8 @@ END_TEST START_TEST(test_address_decode) { int res; - uint8_t decode[21]; - // byte 0 : address type - // bytes 1-20 : pubkey hash 160 + uint8_t decode[MAX_ADDR_RAW_SIZE]; + res = ecdsa_address_decode("1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T", decode); ck_assert_int_eq(res, 1); ck_assert_mem_eq(decode, fromhex("00c4c5d791fcb4654a1ef5e03fe0ad3d9c598f9827"), 21);