jl777 7 years ago
parent
commit
c61465be75
  1. 41
      iguana/exchanges/LP_signatures.c

41
iguana/exchanges/LP_signatures.c

@ -381,33 +381,38 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui
int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item)
{ {
int32_t i,siglen,len,retval=-1; uint8_t rmd160[20],pubsecp[33],sig[128],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr; int32_t i,siglen,len,retval=-1; uint8_t rmd160[20],checkrmd160[20],pubsecp[33],sig[128],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr;
if ( (hexstr= jstr(item,"rmd160")) != 0 && strlen(hexstr) == 2*sizeof(rmd160) ) if ( (hexstr= jstr(item,"rmd160")) != 0 && strlen(hexstr) == 2*sizeof(rmd160) )
{ {
decode_hex(rmd160,sizeof(rmd160),hexstr); decode_hex(rmd160,sizeof(rmd160),hexstr);
memset(zeroes,0,sizeof(zeroes)); memset(zeroes,0,sizeof(zeroes));
if ( memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 && memcmp(rmd160,pubp->rmd160,20) != 0 ) if ( memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 )
{ {
if ( (pubsecpstr= jstr(item,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) if ( memcmp(rmd160,pubp->rmd160,20) != 0 )
{ {
decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr); if ( (pubsecpstr= jstr(item,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 )
//memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); // transition
//memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp));
if ( (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) == 65*2 )
{ {
siglen = len >> 1; decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr);
decode_hex(sig,siglen,sigstr); calc_rmd160(0,checkrmd160,pubsecp,33);
if ( _LP_pubkey_sigcheck(sig,siglen,pubp->pubkey,rmd160,pubsecp) == 0 ) //memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); // transition
//memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp));
if ( memcmp(checkrmd160,rmd160,20) == 0 && (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) == 65*2 )
{ {
for (i=0; i<20; i++) siglen = len >> 1;
printf("%02x",pubp->rmd160[i]); decode_hex(sig,siglen,sigstr);
memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); if ( _LP_pubkey_sigcheck(sig,siglen,pubp->pubkey,rmd160,pubsecp) == 0 )
memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); {
char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr); for (i=0; i<20; i++)
retval = 0; printf("%02x",pubp->rmd160[i]);
} //else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr); memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160));
memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp));
char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr);
retval = 0;
pubp->timestamp = (uint32_t)time(NULL);
} //else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr);
}
} }
} } else pubp->timestamp = (uint32_t)time(NULL);
} }
} }
return(retval); return(retval);

Loading…
Cancel
Save