From 779732a8bae55cfe066c1e72ad4e84c98dfb2e16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Mar 2017 20:46:02 +0200 Subject: [PATCH] support wifstr that encode to less than 38 bytes --- iguana/exchanges/bitcoin.c | 18 +++++++++++++++--- iguana/iguana_sign.c | 2 +- iguana/mini-gmp.c | 2 +- iguana/tests/KMD.batch13 | 1 + iguana/tests/crash | 1 + 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/bitcoin.c b/iguana/exchanges/bitcoin.c index bf37462f0..a40524d11 100755 --- a/iguana/exchanges/bitcoin.c +++ b/iguana/exchanges/bitcoin.c @@ -107,18 +107,30 @@ int32_t base58encode_checkbuf(uint8_t addrtype,uint8_t *data,int32_t data_len) int32_t bitcoin_wif2priv(uint8_t *addrtypep,bits256 *privkeyp,char *wifstr) { - int32_t len = -1; bits256 hash; uint8_t buf[64]; + int32_t len = -1; bits256 hash; uint8_t buf[256]; + memset(buf,0,sizeof(buf)); if ( (len= bitcoin_base58decode(buf,wifstr)) >= 4 ) { // validate with trailing hash, then remove hash + if ( len < 38 ) + len = 38; hash = bits256_doublesha256(0,buf,len - 4); *addrtypep = *buf; memcpy(privkeyp,buf+1,32); - if ( (buf[len - 4]&0xff) == hash.bytes[31] && (buf[len - 3]&0xff) == hash.bytes[30] &&(buf[len - 2]&0xff) == hash.bytes[29] &&(buf[len - 1]&0xff) == hash.bytes[28] ) + if ( (buf[len - 4]&0xff) == hash.bytes[31] && (buf[len - 3]&0xff) == hash.bytes[30] &&(buf[len - 2]&0xff) == hash.bytes[29] && (buf[len - 1]&0xff) == hash.bytes[28] ) { - //printf("coinaddr.(%s) valid checksum\n",coinaddr); + //int32_t i; for (i=0; isuppress_pubkeys)) != 0 ) { //printf("back from bitcoin_hex2json (%s)\n",jprint(vins,0)); diff --git a/iguana/mini-gmp.c b/iguana/mini-gmp.c index ef9e235df..c2c975f12 100644 --- a/iguana/mini-gmp.c +++ b/iguana/mini-gmp.c @@ -4394,7 +4394,7 @@ int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr) //memset(data,0,be_sz); //for (i=0; i