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

Merge pull request #58 from jhoenicke/master

Handle b58 address with shorter lengths
This commit is contained in:
Pavol Rusnak 2016-04-27 23:40:45 +02:00
commit f7e8c9442d
2 changed files with 7 additions and 9 deletions

View File

@ -42,7 +42,7 @@ static const int8_t b58digits_map[] = {
bool b58tobin(void *bin, size_t *binszp, const char *b58) bool b58tobin(void *bin, size_t *binszp, const char *b58)
{ {
size_t binsz = *binszp; size_t binsz = *binszp;
const unsigned char *b58u = (void*)b58; const unsigned char *b58u = (const unsigned char*)b58;
unsigned char *binu = bin; unsigned char *binu = bin;
size_t outisz = (binsz + 3) / 4; size_t outisz = (binsz + 3) / 4;
uint32_t outi[outisz]; uint32_t outi[outisz];
@ -59,7 +59,7 @@ bool b58tobin(void *bin, size_t *binszp, const char *b58)
memset(outi, 0, outisz * sizeof(*outi)); memset(outi, 0, outisz * sizeof(*outi));
// Leading zeros, just count // Leading zeros, just count
for (i = 0; i < b58sz && !b58digits_map[b58u[i]]; ++i) for (i = 0; i < b58sz && b58u[i] == '1'; ++i)
++zerocount; ++zerocount;
for ( ; i < b58sz; ++i) for ( ; i < b58sz; ++i)
@ -210,12 +210,10 @@ int base58_decode_check(const char *str, uint8_t *data, int datalen)
if (b58tobin(d, &res, str) != true) { if (b58tobin(d, &res, str) != true) {
return 0; return 0;
} }
if (res != (size_t)datalen + 4) { uint8_t *nd = d + datalen + 4 - res;
if (b58check(nd, res, str) < 0) {
return 0; return 0;
} }
if (b58check(d, res, str) < 0) { memcpy(data, nd, res - 4);
return 0; return res - 4;
}
memcpy(data, d, datalen);
return datalen;
} }

View File

@ -400,7 +400,7 @@ int hdnode_deserialize(const char *str, HDNode *node)
{ {
uint8_t node_data[78]; uint8_t node_data[78];
memset(node, 0, sizeof(HDNode)); memset(node, 0, sizeof(HDNode));
if (!base58_decode_check(str, node_data, sizeof(node_data))) { if (base58_decode_check(str, node_data, sizeof(node_data)) != sizeof(node_data)) {
return -1; return -1;
} }
node->curve = get_curve_by_name(SECP256K1_NAME); node->curve = get_curve_by_name(SECP256K1_NAME);