From b9076fa94d5222e551f7770bce619d35db5a7622 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Dec 2017 15:41:37 +0700 Subject: [PATCH] Test --- iguana/exchanges/LP_bitcoin.c | 24 ++++++++++++++++-------- iguana/mini-gmp.c | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index f4264563b..071355287 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2137,29 +2137,37 @@ int32_t base58encode_checkbuf(uint8_t taddr,uint8_t addrtype,uint8_t *data,int32 int32_t bitcoin_wif2priv(uint8_t wiftaddr,uint8_t *addrtypep,bits256 *privkeyp,char *wifstr) { - int32_t offset,len = -1; bits256 hash; uint8_t buf[256]; + int32_t offset,len = -1; bits256 hash; uint8_t buf[256],*ptr; offset = 1 + (wiftaddr != 0); memset(buf,0,sizeof(buf)); if ( (len= bitcoin_base58decode(buf,wifstr)) >= 4 ) { // validate with trailing hash, then remove hash if ( len < 38 ) + { + printf("len.%d -> 38\n",len); len = 38; - hash = bits256_doublesha256(0,buf,len - 4); - *addrtypep = (wiftaddr == 0) ? *buf : buf[1]; - memcpy(privkeyp,buf+offset,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[0] == 0x80 && buf[len-1] == 0 ) + { + ptr = buf+1; + len--; + } else ptr = buf; + hash = bits256_doublesha256(0,ptr,len - 4); + *addrtypep = (wiftaddr == 0) ? *ptr : ptr[1]; + memcpy(privkeyp,ptr+offset,32); + if ( (ptr[len - 4]&0xff) == hash.bytes[31] && (ptr[len - 3]&0xff) == hash.bytes[30] &&(ptr[len - 2]&0xff) == hash.bytes[29] && (ptr[len - 1]&0xff) == hash.bytes[28] ) { //int32_t i; for (i=0; i %s\n",bits256_str(str,privkey)); }*/ - while ( count >= 2 && data[count - 1] == 0 && data[count - 2] >= 0x80 ) + if ( count >= 2 && data[count - 1] == 0 && data[count - 2] >= 0x80 ) count--; be_sz = (uint32_t)count + (uint32_t)zeroes; //memset(data,0,be_sz);