jl777 7 years ago
parent
commit
6ed443337d
  1. 19
      iguana/segwit_addr.c

19
iguana/segwit_addr.c

@ -61,12 +61,14 @@ const int8_t charset_rev[128] = {
-1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, 1, 0, -1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, 1, 0,
3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1}; 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1};
int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t data_len) { int bech32_encode(char *output,const char *hrp,const uint8_t *data,size_t data_len)
uint64_t chk = 1; size_t i = 0; int32_t chklen = 8; //6; {
uint64_t chk = 1; size_t i = 0; int32_t ch,chklen = 8; //6;
while ( hrp[i] != 0 ) while ( hrp[i] != 0 )
{ {
int ch = hrp[i]; ch = hrp[i];
if (ch < 33 || ch > 126) { if ( ch < 33 || ch > 126 )
{
printf("bech32_encode illegal ch.%d\n",ch); printf("bech32_encode illegal ch.%d\n",ch);
return 0; return 0;
} }
@ -76,13 +78,16 @@ int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t dat
return 0; return 0;
} }
//chk = bech32_polymod_step(chk) ^ (ch >> 5); //chk = bech32_polymod_step(chk) ^ (ch >> 5);
chk = PolyMod_step(chk,ch >> 5); //chk = PolyMod_step(chk,ch >> 5);
++i; ++i;
} }
if (i + 7 + data_len > 90) return 0; printf("after hrp.(%s)\n",hrp);
if ( i + chklen + 2 + data_len > 90 )
return 0;
//chk = bech32_polymod_step(chk); //chk = bech32_polymod_step(chk);
chk = PolyMod_step(chk,0); chk = PolyMod_step(chk,0);
while (*hrp != 0) { while ( *hrp != 0 )
{
//chk = bech32_polymod_step(chk) ^ (*hrp & 0x1f); //chk = bech32_polymod_step(chk) ^ (*hrp & 0x1f);
chk = PolyMod_step(chk,*hrp & 0x1f); chk = PolyMod_step(chk,*hrp & 0x1f);
*(output++) = *(hrp++); *(output++) = *(hrp++);

Loading…
Cancel
Save