1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 23:18:13 +00:00

introduce MAX_ADDR_RAW_SIZE and MAX_WIF_RAW_SIZE macros

This commit is contained in:
Pavol Rusnak 2016-10-08 18:01:44 +02:00
parent d10ec230c0
commit 430a5087c8
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 7 additions and 5 deletions

View File

@ -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;

View File

@ -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];

View File

@ -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);