Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
c64a5977be
  1. 54
      crypto777/iguana_secp.c
  2. 4
      iguana/iguana_peers.c
  3. 4
      iguana/iguana_sign.c
  4. 2
      iguana/main.c

54
crypto777/iguana_secp.c

@ -182,18 +182,6 @@ bits256 bitcoin_pubkey33(uint8_t *data,bits256 privkey)
return(pubkey);
}
int32_t bitcoin_sign(uint8_t *sig,int32_t maxlen,uint8_t *data,int32_t datalen,bits256 privkey)
{
uint32_t siglen; EC_KEY *KEY; uint8_t oddeven; bits256 pubkey; int32_t retval = -1;
if ( (KEY= bitcoin_privkeyset(&oddeven,&pubkey,privkey)) != 0 )
{
if ( ECDSA_sign(0,data,datalen,sig,&siglen,KEY) > 0 && siglen <= maxlen )
retval = siglen;
EC_KEY_free(KEY);
}
return(retval);
}
int32_t bitcoin_verify(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,uint8_t *pubkey,int32_t len)
{
ECDSA_SIG *esig; int32_t retval = -1; uint8_t tmp[33],*ptr,*sigptr = sig; EC_KEY *KEY = 0;
@ -235,4 +223,44 @@ int32_t bitcoin_verify(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen
return(retval);
}
int32_t bitcoin_sign(uint8_t *sig,int32_t maxlen,uint8_t *data,int32_t datalen,bits256 privkey)
{
EC_KEY *KEY; uint8_t oddeven; bits256 pubkey; uint8_t *ptr; int32_t siglen,retval = -1;
ECDSA_SIG *SIG; BN_CTX *ctx; const EC_GROUP *group; BIGNUM *order,*halforder;
if ( (KEY= bitcoin_privkeyset(&oddeven,&pubkey,privkey)) != 0 )
{
if ( (SIG= ECDSA_do_sign(data,datalen,KEY)) != 0 )
{
ctx = BN_CTX_new();
BN_CTX_start(ctx);
group = EC_KEY_get0_group(KEY);
order = BN_CTX_get(ctx);
halforder = BN_CTX_get(ctx);
EC_GROUP_get_order(group,order,ctx);
BN_rshift1(halforder,order);
if ( BN_cmp(SIG->s,halforder) > 0 )
{
// enforce low S values, by negating the value (modulo the order) if above order/2.
BN_sub(SIG->s,order,SIG->s);
}
ptr = 0;
siglen = i2d_ECDSA_SIG(SIG,&ptr);
if ( ptr != 0 )
{
if ( siglen > 0 )
{
memcpy(sig,ptr,siglen);
retval = siglen;
}
free(ptr);
}
BN_CTX_end(ctx);
BN_CTX_free(ctx);
ECDSA_SIG_free(SIG);
}
//if ( ECDSA_sign(0,data,datalen,sig,&siglen,KEY) > 0 && siglen <= maxlen )
// retval = siglen;
EC_KEY_free(KEY);
}
return(retval);
}

4
iguana/iguana_peers.c

@ -523,9 +523,9 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig
if ( strcmp(H->command,"block") == 0 || strcmp(H->command,"tx") == 0 )
{
if ( addr->RAWMEM.ptr == 0 )
iguana_meminit(&addr->RAWMEM,addr->ipaddr,0,IGUANA_MAXPACKETSIZE + 65536*3,0);
iguana_meminit(&addr->RAWMEM,addr->ipaddr,0,IGUANA_MAXPACKETSIZE * 1.25,0);
if ( addr->TXDATA.ptr == 0 )
iguana_meminit(&addr->TXDATA,"txdata",0,IGUANA_MAXPACKETSIZE*2,0);
iguana_meminit(&addr->TXDATA,"txdata",0,IGUANA_MAXPACKETSIZE*1.5,0);
if ( addr->HASHMEM.ptr == 0 )
iguana_meminit(&addr->HASHMEM,"HASHPTRS",0,256,0);//IGUANA_MAXPACKETSIZE*16,0);
//printf("Init %s memory %p %p %p\n",addr->ipaddr,addr->RAWMEM.ptr,addr->TXDATA.ptr,addr->HASHMEM.ptr);

4
iguana/iguana_sign.c

@ -702,8 +702,8 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char **
vp->signers[j].siglen = siglen;
msgtx->vins[vini].vinscript = calloc(1,siglen*2+256); // fix this memleak!
msgtx->vins[vini].scriptlen = bitcoin_scriptsig(coin,msgtx->vins[vini].vinscript,0,(const struct vin_info *)vp,msgtx);
//for (i=0; i<siglen; i++)
// printf("%02x",sig[i]);
for (i=0; i<siglen; i++)
printf("%02x",sig[i]);
// s2 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1;
printf(" SIGNEDTX.[%02x] plen.%d siglen.%d\n",sig[siglen-1],plen,siglen);
}

2
iguana/main.c

@ -1146,7 +1146,7 @@ void iguana_appletests(struct supernet_info *myinfo)
exit(-1);
}
sleep(1);*/
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":500,\"endpend\":500,\"services\":128,\"maxpeers\":64,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":100}"),0,myinfo->rpcport)) != 0 )
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":500,\"endpend\":500,\"services\":0,\"maxpeers\":64,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":100}"),0,myinfo->rpcport)) != 0 )
{
free(str);
if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":1024,\"maxpeers\":256,\"newcoin\":\"BTCD\",\"active\":1}"),0,myinfo->rpcport)) != 0 )

Loading…
Cancel
Save