From f366fb81c5fa154ce1004f3619014c9034305bf7 Mon Sep 17 00:00:00 2001 From: Jochen Hoenicke Date: Tue, 31 Oct 2017 19:16:07 +0100 Subject: [PATCH] Updated to latest from bech32 repository. hrp is ASCII character, not 5 bit words --- segwit_addr.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/segwit_addr.c b/segwit_addr.c index e5b26ec91a..8202d84181 100644 --- a/segwit_addr.c +++ b/segwit_addr.c @@ -51,9 +51,13 @@ int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t dat uint32_t chk = 1; size_t i = 0; while (hrp[i] != 0) { - if (hrp[i] >= 'A' && hrp[i] <= 'Z') return 0; - if (!(hrp[i] >> 5)) return 0; - chk = bech32_polymod_step(chk) ^ (hrp[i] >> 5); + int ch = hrp[i]; + if (ch < 33 || ch > 126) { + return 0; + } + + if (ch >= 'A' && ch <= 'Z') return 0; + chk = bech32_polymod_step(chk) ^ (ch >> 5); ++i; } if (i + 7 + data_len > 90) return 0;