From f82aec69aa0b6e724721928e44a2afcb22f227ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Jan 2018 20:32:12 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_nativeDEX.c | 4 +++- iguana/segwit_addr.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 48278aa20..2ede36e41 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -754,7 +754,9 @@ void bech32_tests() } if ( bech32_encode(rebuild,hrp,data,data_len) == 0 ) { - printf("bech32_encode fails: '%s'\n",test); + for (i=0; i hrp.(%s) datalen.%d\n",test,hrp,(int32_t)data_len); } if ( my_strncasecmp(rebuild,test,92)) { diff --git a/iguana/segwit_addr.c b/iguana/segwit_addr.c index e0fb8b975..9d48e571a 100644 --- a/iguana/segwit_addr.c +++ b/iguana/segwit_addr.c @@ -66,12 +66,22 @@ int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t dat while (hrp[i] != 0) { int ch = hrp[i]; if (ch < 33 || ch > 126) { + printf("bech32_encode illegal ch.%d\n",ch); return 0; } - if (ch >= 'A' && ch <= 'Z') return 0; + if (ch >= 'A' && ch <= 'Z') + { + printf("bech32_encode illegal uppercase.%c\n",ch); + return 0; + } + if ( (c= charset_rev[ch]) < 0 ) + { + printf("bech32_encode illegal base32.%d\n",ch); + return 0; + } //chk = bech32_polymod_step(chk) ^ (ch >> 5); - chk = PolyMod_step(chk,ch >> 5); + chk = PolyMod_step(chk,c); ++i; } if (i + 7 + data_len > 90) return 0; @@ -98,6 +108,7 @@ int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t dat *(output++) = charset[(chk >> ((5 - i) * 5)) & 0x1f]; } *output = 0; + printf("checksum %llx\n",(long long)chk); return 1; }