Browse Source

gmp and libsecp256k

release/v0.1
jl777 9 years ago
parent
commit
54d6cd0afe
  1. 4
      iguana/SuperNET.c
  2. 4
      iguana/SuperNET.h
  3. 2
      iguana/SuperNET_keys.c
  4. 2
      iguana/exchanges/bitcoin.c
  5. 2
      iguana/iguana777.h
  6. 2
      iguana/iguana_payments.c
  7. 155
      iguana/iguana_secp.c
  8. 8
      iguana/iguana_sign.c
  9. 2
      iguana/iguana_wallet.c
  10. 3
      iguana/main.c
  11. 4425
      iguana/mini-gmp.c
  12. 295
      iguana/mini-gmp.h
  13. 6
      iguana/swaps/iguana_BTCswap.c

4
iguana/SuperNET.c

@ -898,7 +898,7 @@ cJSON *SuperNET_rosettajson(bits256 privkey,int32_t showprivs)
RS_encode(str,nxt64bits);
jaddstr(retjson,"RS",str);
jadd64bits(retjson,"NXT",nxt64bits);
bitcoin_pubkey33(pub,privkey);
bitcoin_pubkey33(0,pub,privkey);
init_hexbytes_noT(str,pub,33);
jaddstr(retjson,"btcpubkey",str);
calc_OP_HASH160(str2,rmd160,str);
@ -948,7 +948,7 @@ HASH_AND_INT(SuperNET,priv2pub,privkey,addrtype)
retjson = cJSON_CreateObject();
crypto_box_priv2pub(pub.bytes,privkey.bytes);
jaddbits256(retjson,"curve25519",pub);
pub = bitcoin_pubkey33(pubkey,privkey);
pub = bitcoin_pubkey33(myinfo->ctx,pubkey,privkey);
jaddbits256(retjson,"secp256k1",pub);
bitcoin_address(coinaddr,addrtype,pubkey,33);
jaddstr(retjson,"result",coinaddr);

4
iguana/SuperNET.h

@ -87,7 +87,7 @@ struct supernet_info
struct supernet_agent agents[SUPERNET_MAXAGENTS]; queue_t acceptQ;
int32_t numagents,numexchanges;
struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES];
struct iguana_waccount *wallet;
struct iguana_waccount *wallet; void *ctx;
char handle[1024],*decryptstr;
};
@ -178,7 +178,7 @@ char *SuperNET_keysinit(struct supernet_info *myinfo,char *jsonstr);
double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *sortbuf,int32_t max,double *totalvolp,char *base,char *rel,double volume,cJSON *argjson);
void SuperNET_setkeys(struct supernet_info *myinfo,void *pass,int32_t passlen,int32_t dosha256);
char *InstantDEX_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t len,char *remoteaddr);
bits256 bitcoin_pubkey33(uint8_t data[33],bits256 privkey);
bits256 bitcoin_pubkey33(void *ctx,uint8_t data[33],bits256 privkey);
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey,int32_t len);
uint8_t *cards777_recover(uint8_t *shares[],uint8_t *sharenrs,int32_t M,int32_t numcards,int32_t N);

2
iguana/SuperNET_keys.c

@ -285,7 +285,7 @@ void SuperNET_setkeys(struct supernet_info *myinfo,void *pass,int32_t passlen,in
myinfo->myaddr.nxt64bits = hash.txid;
}
RS_encode(myinfo->myaddr.NXTADDR,myinfo->myaddr.nxt64bits);
bitcoin_pubkey33(pubkey33,myinfo->persistent_priv);
bitcoin_pubkey33(myinfo->ctx,pubkey33,myinfo->persistent_priv);
//btc_priv2pub(pubkey33,myinfo->persistent_priv.bytes);
//init_hexbytes_noT(pubkeystr,pubkey33,33);
bitcoin_address(myinfo->myaddr.BTC,0,pubkey33,33);

2
iguana/exchanges/bitcoin.c

@ -432,7 +432,7 @@ uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,cha
{
if ( (other= iguana_coinfind(base)) != 0 )
{
bitcoin_pubkey33(pubkey,myinfo->persistent_priv);
bitcoin_pubkey33(0,pubkey,myinfo->persistent_priv);
bitcoin_address(coinaddr,other->chain->pubtype,pubkey,sizeof(pubkey));
jaddstr(argjson,base,coinaddr);
}

2
iguana/iguana777.h

@ -824,6 +824,7 @@ cJSON *bitcoin_addoutput(struct iguana_info *coin,cJSON *txobj,uint8_t *payments
int32_t bitcoin_changescript(struct iguana_info *coin,uint8_t *changescript,int32_t n,uint64_t *changep,char *changeaddr,uint64_t inputsatoshis,uint64_t satoshis,uint64_t txfee);
cJSON *bitcoin_addinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys);
int32_t bitcoin_verifytx(struct iguana_info *coin,bits256 *signedtxidp,char **signedtx,char *rawtxstr,struct vin_info *V,int32_t numinputs);
int32_t bitcoin_verify(void *ctx,uint8_t *sig,int32_t siglen,bits256 txhash2,uint8_t *pubkey,int32_t plen);
char *bitcoin_json2hex(struct iguana_info *coin,bits256 *txidp,cJSON *txjson);
int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr);
char *issue_startForging(struct supernet_info *myinfo,char *secret);
@ -944,6 +945,7 @@ int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 tx
uint8_t iguana_addrtype(struct iguana_info *coin,uint8_t script_type);
struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,struct iguana_waddress *addwaddr,char *redeemScript);
cJSON *iguana_createvins(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *txobj,cJSON *vins);
bits256 bitcoin_pubkey33(void *ctx,uint8_t *data,bits256 privkey);
extern int32_t HDRnet,netBLOCKS;

2
iguana/iguana_payments.c

@ -84,7 +84,7 @@ int32_t iguana_pubkeyget(struct supernet_info *myinfo,struct iguana_info *coin,u
return(-1);
else
{
pubkey = bitcoin_pubkey33(pubkeydata,privkey);
pubkey = bitcoin_pubkey33(myinfo->ctx,pubkeydata,privkey);
if ( bits256_nonz(pubkey) == 0 )
return(-1);
}

155
iguana/iguana_secp.c

@ -17,7 +17,7 @@
#include <string.h>
#include "../includes/curve25519.h"
#include "../includes/openssl/ec.h"
#include "../includes/openssl/ecdsa.h"
//#include "../includes/openssl/ecdsa.h"
#include "../includes/openssl/obj_mac.h"
#include "../../secp256k1-zkp/include/secp256k1.h"
@ -52,53 +52,9 @@ int32_t bn_bn2mpi(uint8_t *data,const BIGNUM *v)
return(sz);
}
char *bitcoin_base58encode(char *coinaddr,uint8_t *data_,int32_t datalen)
{
BIGNUM bn58,bn0,bn,dv,rem; BN_CTX *ctx; uint32_t i,n,flag=0; uint8_t swapbuf[512],rs[512];
const uint8_t *data = (void *)data_;
rs[0] = 0;
n = 0;
if ( datalen < (sizeof(swapbuf) >> 1) )
{
ctx = BN_CTX_new();
BN_init(&bn58), BN_init(&bn0), BN_init(&bn), BN_init(&dv), BN_init(&rem);
BN_set_word(&bn58,58);
BN_set_word(&bn0,0);
for (i=0; i<datalen; i++)
swapbuf[datalen - i - 1] = data[i];
swapbuf[datalen] = 0;
bn_mpi2bn(&bn,swapbuf,datalen+1);
while ( BN_cmp(&bn,&bn0) > 0 )
{
if ( BN_div(&dv,&rem,&bn,&bn58,ctx) == 0 )
{
flag = -1;
break;
}
BN_copy(&bn,&dv);
rs[n++] = base58_chars[BN_get_word(&rem)];
}
if ( flag == 0 )
{
for (i=0; i<datalen; i++)
{
if ( data[i] == 0 )
rs[n++] = base58_chars[0];
else break;
}
for (i=0; i<n; i++)
coinaddr[n - i - 1] = rs[i];
coinaddr[n] = 0;
}
BN_clear_free(&bn58), BN_clear_free(&bn0), BN_clear_free(&bn), BN_clear_free(&dv), BN_clear_free(&rem);
BN_CTX_free(ctx);
return(coinaddr);
}
return(0);
}
int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr)
{
int32_t bitcoin_base58decode_mpz(uint8_t *data,char *coinaddr);
uint32_t zeroes,be_sz=0,i,len; const char *p,*p1; BIGNUM bn58,bn,bnChar; uint8_t revdata[64]; BN_CTX *ctx;
ctx = BN_CTX_new();
BN_init(&bn58), BN_init(&bn), BN_init(&bnChar);
@ -134,6 +90,22 @@ int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr)
out:
BN_clear_free(&bn58), BN_clear_free(&bn), BN_clear_free(&bnChar);
BN_CTX_free(ctx);
{
int32_t checkval; uint8_t data2[256];
if ( (checkval= bitcoin_base58decode_mpz(data2,coinaddr)) != be_sz )
printf("base58 decode error checkval.%d != be_sz.%d\n",checkval,be_sz);
else if ( memcmp(data2,data,be_sz) != 0 )
{
for (i=0; i<be_sz; i++)
printf("%02x",data[i]);
printf(" data[%d]\n",be_sz);
for (i=0; i<be_sz; i++)
printf("%02x",data2[i]);
printf(" data\n");
printf("base58 decode data error\n");
}
else printf("base58 decode match\n");
}
return(be_sz);
}
@ -145,9 +117,15 @@ bits256 bitcoin_pubkey33(secp256k1_context *ctx,uint8_t *data,bits256 privkey)
ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY), flag++;
if ( ctx != 0 )
{
if ( secp256k1_ec_seckey_verify(ctx,privkey.bytes) == 0 )
{
printf("bitcoin_sign illegal privkey\n");
return(pubkey);
}
if ( secp256k1_ec_pubkey_create(ctx,&secppub,privkey.bytes) > 0 )
{
secp256k1_ec_pubkey_serialize(ctx,data,&plen,&secppub,1);
plen = 33;
secp256k1_ec_pubkey_serialize(ctx,data,&plen,&secppub,SECP256K1_EC_COMPRESSED);
if ( plen == 33 )
memcpy(pubkey.bytes,data+1,sizeof(pubkey));
}
@ -166,6 +144,11 @@ int32_t bitcoin_sign(void *ctx,uint8_t *sig,int32_t maxlen,bits256 txhash2,bits2
ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY), flag++;
if ( ctx != 0 )
{
if ( secp256k1_ec_seckey_verify(ctx,privkey.bytes) == 0 )
{
printf("bitcoin_sign illegal privkey\n");
return(-1);
}
if ( secp256k1_context_randomize(ctx,seed.bytes) > 0 )
{
if ( secp256k1_ecdsa_sign(ctx,&SIG,txhash2.bytes,privkey.bytes,secp256k1_nonce_function_rfc6979,extra_entropy.bytes) > 0 )
@ -180,6 +163,27 @@ int32_t bitcoin_sign(void *ctx,uint8_t *sig,int32_t maxlen,bits256 txhash2,bits2
return(retval);
}
int32_t bitcoin_verify(void *ctx,uint8_t *sig,int32_t siglen,bits256 txhash2,uint8_t *pubkey,int32_t plen)
{
int32_t flag=0,retval = -1; secp256k1_pubkey PUB; secp256k1_ecdsa_signature SIG;
if ( ctx == 0 )
ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY), flag++;
if ( ctx != 0 )
{
if ( secp256k1_ec_pubkey_parse(ctx,&PUB,pubkey,plen) > 0 )
{
secp256k1_ecdsa_signature_parse_der(ctx,&SIG,sig,siglen);
if ( secp256k1_ecdsa_verify(ctx,&SIG,txhash2.bytes,&PUB) > 0 )
retval = 0;
}
if ( flag != 0 )
secp256k1_context_destroy(ctx);
}
return(retval);
}
#ifdef oldway
struct bp_key { EC_KEY *k; };
EC_KEY *oldbitcoin_privkeyset(uint8_t *oddevenp,bits256 *pubkeyp,bits256 privkey)
@ -297,7 +301,7 @@ int32_t oldbitcoin_sign(uint8_t *sig,int32_t maxlen,uint8_t *data,int32_t datale
return(retval);
}
bits256 oldbitcoin_pubkey33(uint8_t *data,bits256 privkey)
bits256 oldbitcoin_pubkey33(void *_ctx,uint8_t *data,bits256 privkey)
{
uint8_t oddeven,data2[65]; size_t plen; bits256 pubkey; secp256k1_pubkey secppub; secp256k1_context *ctx;
EC_KEY *KEY;
@ -321,3 +325,58 @@ bits256 oldbitcoin_pubkey33(uint8_t *data,bits256 privkey)
return(pubkey);
}
char *oldbitcoin_base58encode(char *coinaddr,uint8_t *data_,int32_t datalen)
{
BIGNUM bn58,bn0,bn,dv,rem; BN_CTX *ctx; uint32_t i,n,flag=0; uint8_t swapbuf[512],rs[512];
const uint8_t *data = (void *)data_;
rs[0] = 0;
n = 0;
if ( datalen < (sizeof(swapbuf) >> 1) )
{
ctx = BN_CTX_new();
BN_init(&bn58), BN_init(&bn0), BN_init(&bn), BN_init(&dv), BN_init(&rem);
BN_set_word(&bn58,58);
BN_set_word(&bn0,0);
for (i=0; i<datalen; i++)
swapbuf[datalen - i - 1] = data[i];
swapbuf[datalen] = 0;
bn_mpi2bn(&bn,swapbuf,datalen+1);
while ( BN_cmp(&bn,&bn0) > 0 )
{
if ( BN_div(&dv,&rem,&bn,&bn58,ctx) == 0 )
{
flag = -1;
break;
}
BN_copy(&bn,&dv);
rs[n++] = base58_chars[BN_get_word(&rem)];
}
if ( flag == 0 )
{
for (i=0; i<datalen; i++)
{
if ( data[i] == 0 )
rs[n++] = base58_chars[0];
else break;
}
for (i=0; i<n; i++)
coinaddr[n - i - 1] = rs[i];
coinaddr[n] = 0;
}
BN_clear_free(&bn58), BN_clear_free(&bn0), BN_clear_free(&bn), BN_clear_free(&dv), BN_clear_free(&rem);
BN_CTX_free(ctx);
{
char *bitcoin_base58encode_mpz(char *coinaddr,uint8_t *data,int32_t datalen);
char checkaddr[64];
bitcoin_base58encode_mpz(checkaddr,data_,datalen);
if ( strcmp(checkaddr,coinaddr) != 0 )
printf("mpz base58 error (%s) vs (%s)\n",checkaddr,coinaddr);
else printf("mpz matches\n");
}
return(coinaddr);
}
return(0);
}
#endif

8
iguana/iguana_sign.c

@ -676,7 +676,7 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char **
if ( bits256_nonz(vp->signers[j].privkey) > 0 )
{
pubkey = vp->signers[j].pubkey;
bitcoin_pubkey33(pubkey,vp->signers[j].privkey);
bitcoin_pubkey33(coin->ctx,pubkey,vp->signers[j].privkey);
plen = bitcoin_pubkeylen(pubkey);
}
if ( plen < 0 )
@ -707,7 +707,7 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char **
// s2 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1;
printf(" SIGNEDTX.[%02x] plen.%d siglen.%d\n",sig[siglen-1],plen,siglen);
}
if ( oldbitcoin_verify(sig,siglen,sigtxid.bytes,sizeof(sigtxid),vp->signers[j].pubkey,bitcoin_pubkeylen(vp->signers[j].pubkey)) < 0 )
if ( bitcoin_verify(coin->ctx,sig,vp->signers[j].siglen-1,sigtxid,vp->signers[j].pubkey,bitcoin_pubkeylen(vp->signers[j].pubkey)) < 0 )
{
init_hexbytes_noT(bigstr,serialized,n2);
printf("(%s) doesnt verify hash2.%s\n",bigstr,bits256_str(str,sigtxid));
@ -798,7 +798,7 @@ cJSON *iguana_signtx(struct supernet_info *myinfo,struct iguana_info *coin,bits2
if ( bits256_nonz(spend->inputs[i].privkeys[j]) != 0 )
{
vp->signers[j].privkey = spend->inputs[i].privkeys[j];
bitcoin_pubkey33(vp->signers[j].pubkey,vp->signers[j].privkey);
bitcoin_pubkey33(coin->ctx,vp->signers[j].pubkey,vp->signers[j].privkey);
}
else
{
@ -968,7 +968,7 @@ STRING_ARRAY_OBJ_STRING(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys,sighas
spend->inputs[i].privkeys[0] = privkey;
if ( bits256_nonz(privkey) != 0 )
{
bitcoin_pubkey33(pubkey33,privkey);
bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey);
memcpy(spend->inputs[i].pubkeys[0],pubkey33,33);
bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33);
if ( myinfo->expiration != 0 && ((waddr= iguana_waddresssearch(myinfo,coin,&wacct,coinaddr)) == 0 || bits256_nonz(waddr->privkey) == 0) )

2
iguana/iguana_wallet.c

@ -186,7 +186,7 @@ struct iguana_waddress *iguana_waddresssearch(struct supernet_info *myinfo,struc
struct iguana_waddress *iguana_waddresscalc(uint8_t pubtype,uint8_t wiftype,struct iguana_waddress *addr,bits256 privkey)
{
addr->privkey = privkey;
bitcoin_pubkey33(addr->pubkey,addr->privkey);
bitcoin_pubkey33(0,addr->pubkey,addr->privkey);
calc_rmd160_sha256(addr->rmd160,addr->pubkey,33);
bitcoin_address(addr->coinaddr,pubtype,addr->rmd160,sizeof(addr->rmd160));
if ( bitcoin_priv2wif(addr->wifstr,addr->privkey,wiftype) > 0 )

3
iguana/main.c

@ -23,6 +23,7 @@
#include "../pnacl_main.h"
#include "iguana777.h"
#include "SuperNET.h"
#include "../../secp256k1-zkp/include/secp256k1.h"
#undef fopen
#undef fclose
@ -138,6 +139,8 @@ void SuperNET_hex2str(char *str,uint8_t *hex,int32_t len)
struct supernet_info *SuperNET_MYINFO(char *passphrase)
{
if ( MYINFO.ctx == 0 )
MYINFO.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
if ( passphrase == 0 || passphrase[0] == 0 )
return(&MYINFO);
else

4425
iguana/mini-gmp.c

File diff suppressed because it is too large

295
iguana/mini-gmp.h

@ -0,0 +1,295 @@
/* mini-gmp, a minimalistic implementation of a GNU GMP subset.
Copyright 2011-2015 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any
later version.
or both in parallel, as here.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received copies of the GNU General Public License and the
GNU Lesser General Public License along with the GNU MP Library. If not,
see https://www.gnu.org/licenses/. */
/* About mini-gmp: This is a minimal implementation of a subset of the
GMP interface. It is intended for inclusion into applications which
have modest bignums needs, as a fallback when the real GMP library
is not installed.
This file defines the public interface. */
#ifndef __MINI_GMP_H__
#define __MINI_GMP_H__
/* For size_t */
#include <stddef.h>
#if defined (__cplusplus)
extern "C" {
#endif
void mp_set_memory_functions (void *(*) (size_t),
void *(*) (void *, size_t, size_t),
void (*) (void *, size_t));
void mp_get_memory_functions (void *(**) (size_t),
void *(**) (void *, size_t, size_t),
void (**) (void *, size_t));
typedef unsigned long mp_limb_t;
typedef long mp_size_t;
typedef unsigned long mp_bitcnt_t;
typedef mp_limb_t *mp_ptr;
typedef const mp_limb_t *mp_srcptr;
typedef struct
{
int _mp_alloc; /* Number of *limbs* allocated and pointed
to by the _mp_d field. */
int _mp_size; /* abs(_mp_size) is the number of limbs the
last field points to. If _mp_size is
negative this is a negative number. */
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
typedef __mpz_struct mpz_t[1];
typedef __mpz_struct *mpz_ptr;
typedef const __mpz_struct *mpz_srcptr;
extern const int mp_bits_per_limb;
void mpn_copyi (mp_ptr, mp_srcptr, mp_size_t);
void mpn_copyd (mp_ptr, mp_srcptr, mp_size_t);
void mpn_zero (mp_ptr, mp_size_t);
int mpn_cmp (mp_srcptr, mp_srcptr, mp_size_t);
int mpn_zero_p (mp_srcptr, mp_size_t);
mp_limb_t mpn_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
mp_limb_t mpn_add_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
mp_limb_t mpn_add (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
mp_limb_t mpn_sub_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
mp_limb_t mpn_sub_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
mp_limb_t mpn_sub (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
mp_limb_t mpn_mul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
mp_limb_t mpn_addmul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
mp_limb_t mpn_submul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t);
int mpn_perfect_square_p (mp_srcptr, mp_size_t);
mp_size_t mpn_sqrtrem (mp_ptr, mp_ptr, mp_srcptr, mp_size_t);
mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int);
mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int);
mp_bitcnt_t mpn_scan0 (mp_srcptr, mp_bitcnt_t);
mp_bitcnt_t mpn_scan1 (mp_srcptr, mp_bitcnt_t);
mp_bitcnt_t mpn_popcount (mp_srcptr, mp_size_t);
mp_limb_t mpn_invert_3by2 (mp_limb_t, mp_limb_t);
#define mpn_invert_limb(x) mpn_invert_3by2 ((x), 0)
size_t mpn_get_str (unsigned char *, int, mp_ptr, mp_size_t);
mp_size_t mpn_set_str (mp_ptr, const unsigned char *, size_t, int);
void mpz_init (mpz_t);
void mpz_init2 (mpz_t, mp_bitcnt_t);
void mpz_clear (mpz_t);
#define mpz_odd_p(z) (((z)->_mp_size != 0) & (int) (z)->_mp_d[0])
#define mpz_even_p(z) (! mpz_odd_p (z))
int mpz_sgn (const mpz_t);
int mpz_cmp_si (const mpz_t, long);
int mpz_cmp_ui (const mpz_t, unsigned long);
int mpz_cmp (const mpz_t, const mpz_t);
int mpz_cmpabs_ui (const mpz_t, unsigned long);
int mpz_cmpabs (const mpz_t, const mpz_t);
int mpz_cmp_d (const mpz_t, double);
int mpz_cmpabs_d (const mpz_t, double);
void mpz_abs (mpz_t, const mpz_t);
void mpz_neg (mpz_t, const mpz_t);
void mpz_swap (mpz_t, mpz_t);
void mpz_add_ui (mpz_t, const mpz_t, unsigned long);
void mpz_add (mpz_t, const mpz_t, const mpz_t);
void mpz_sub_ui (mpz_t, const mpz_t, unsigned long);
void mpz_ui_sub (mpz_t, unsigned long, const mpz_t);
void mpz_sub (mpz_t, const mpz_t, const mpz_t);
void mpz_mul_si (mpz_t, const mpz_t, long int);
void mpz_mul_ui (mpz_t, const mpz_t, unsigned long int);
void mpz_mul (mpz_t, const mpz_t, const mpz_t);
void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
void mpz_addmul_ui (mpz_t, const mpz_t, unsigned long int);
void mpz_addmul (mpz_t, const mpz_t, const mpz_t);
void mpz_submul_ui (mpz_t, const mpz_t, unsigned long int);
void mpz_submul (mpz_t, const mpz_t, const mpz_t);
void mpz_cdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);
void mpz_fdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);
void mpz_tdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);
void mpz_cdiv_q (mpz_t, const mpz_t, const mpz_t);
void mpz_fdiv_q (mpz_t, const mpz_t, const mpz_t);
void mpz_tdiv_q (mpz_t, const mpz_t, const mpz_t);
void mpz_cdiv_r (mpz_t, const mpz_t, const mpz_t);
void mpz_fdiv_r (mpz_t, const mpz_t, const mpz_t);
void mpz_tdiv_r (mpz_t, const mpz_t, const mpz_t);
void mpz_cdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
void mpz_fdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
void mpz_tdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
void mpz_cdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
void mpz_fdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
void mpz_tdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
void mpz_mod (mpz_t, const mpz_t, const mpz_t);
void mpz_divexact (mpz_t, const mpz_t, const mpz_t);
int mpz_divisible_p (const mpz_t, const mpz_t);
int mpz_congruent_p (const mpz_t, const mpz_t, const mpz_t);
unsigned long mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long);
unsigned long mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long);
unsigned long mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long);
unsigned long mpz_cdiv_q_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_fdiv_q_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_tdiv_q_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_cdiv_r_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_fdiv_r_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_tdiv_r_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_cdiv_ui (const mpz_t, unsigned long);
unsigned long mpz_fdiv_ui (const mpz_t, unsigned long);
unsigned long mpz_tdiv_ui (const mpz_t, unsigned long);
unsigned long mpz_mod_ui (mpz_t, const mpz_t, unsigned long);
void mpz_divexact_ui (mpz_t, const mpz_t, unsigned long);
int mpz_divisible_ui_p (const mpz_t, unsigned long);
unsigned long mpz_gcd_ui (mpz_t, const mpz_t, unsigned long);
void mpz_gcd (mpz_t, const mpz_t, const mpz_t);
void mpz_gcdext (mpz_t, mpz_t, mpz_t, const mpz_t, const mpz_t);
void mpz_lcm_ui (mpz_t, const mpz_t, unsigned long);
void mpz_lcm (mpz_t, const mpz_t, const mpz_t);
int mpz_invert (mpz_t, const mpz_t, const mpz_t);
void mpz_sqrtrem (mpz_t, mpz_t, const mpz_t);
void mpz_sqrt (mpz_t, const mpz_t);
int mpz_perfect_square_p (const mpz_t);
void mpz_pow_ui (mpz_t, const mpz_t, unsigned long);
void mpz_ui_pow_ui (mpz_t, unsigned long, unsigned long);
void mpz_powm (mpz_t, const mpz_t, const mpz_t, const mpz_t);
void mpz_powm_ui (mpz_t, const mpz_t, unsigned long, const mpz_t);
void mpz_rootrem (mpz_t, mpz_t, const mpz_t, unsigned long);
int mpz_root (mpz_t, const mpz_t, unsigned long);
void mpz_fac_ui (mpz_t, unsigned long);
void mpz_bin_uiui (mpz_t, unsigned long, unsigned long);
int mpz_probab_prime_p (const mpz_t, int);
int mpz_tstbit (const mpz_t, mp_bitcnt_t);
void mpz_setbit (mpz_t, mp_bitcnt_t);
void mpz_clrbit (mpz_t, mp_bitcnt_t);
void mpz_combit (mpz_t, mp_bitcnt_t);
void mpz_com (mpz_t, const mpz_t);
void mpz_and (mpz_t, const mpz_t, const mpz_t);
void mpz_ior (mpz_t, const mpz_t, const mpz_t);
void mpz_xor (mpz_t, const mpz_t, const mpz_t);
mp_bitcnt_t mpz_popcount (const mpz_t);
mp_bitcnt_t mpz_hamdist (const mpz_t, const mpz_t);
mp_bitcnt_t mpz_scan0 (const mpz_t, mp_bitcnt_t);
mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t);
int mpz_fits_slong_p (const mpz_t);
int mpz_fits_ulong_p (const mpz_t);
long int mpz_get_si (const mpz_t);
unsigned long int mpz_get_ui (const mpz_t);
double mpz_get_d (const mpz_t);
size_t mpz_size (const mpz_t);
mp_limb_t mpz_getlimbn (const mpz_t, mp_size_t);
void mpz_realloc2 (mpz_t, mp_bitcnt_t);
mp_srcptr mpz_limbs_read (mpz_srcptr);
mp_ptr mpz_limbs_modify (mpz_t, mp_size_t);
mp_ptr mpz_limbs_write (mpz_t, mp_size_t);
void mpz_limbs_finish (mpz_t, mp_size_t);
mpz_srcptr mpz_roinit_n (mpz_t, mp_srcptr, mp_size_t);
#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
void mpz_set_si (mpz_t, signed long int);
void mpz_set_ui (mpz_t, unsigned long int);
void mpz_set (mpz_t, const mpz_t);
void mpz_set_d (mpz_t, double);
void mpz_init_set_si (mpz_t, signed long int);
void mpz_init_set_ui (mpz_t, unsigned long int);
void mpz_init_set (mpz_t, const mpz_t);
void mpz_init_set_d (mpz_t, double);
size_t mpz_sizeinbase (const mpz_t, int);
char *mpz_get_str (char *, int, const mpz_t);
int mpz_set_str (mpz_t, const char *, int);
int mpz_init_set_str (mpz_t, const char *, int);
/* This long list taken from gmp.h. */
/* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4,
<iostream> defines EOF but not FILE. */
#if defined (FILE) \
|| defined (H_STDIO) \
|| defined (_H_STDIO) /* AIX */ \
|| defined (_STDIO_H) /* glibc, Sun, SCO */ \
|| defined (_STDIO_H_) /* BSD, OSF */ \
|| defined (__STDIO_H) /* Borland */ \
|| defined (__STDIO_H__) /* IRIX */ \
|| defined (_STDIO_INCLUDED) /* HPUX */ \
|| defined (__dj_include_stdio_h_) /* DJGPP */ \
|| defined (_FILE_DEFINED) /* Microsoft */ \
|| defined (__STDIO__) /* Apple MPW MrC */ \
|| defined (_MSL_STDIO_H) /* Metrowerks */ \
|| defined (_STDIO_H_INCLUDED) /* QNX4 */ \
|| defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \
|| defined (__STDIO_LOADED) /* VMS */
size_t mpz_out_str (FILE *, int, const mpz_t);
#endif
void mpz_import (mpz_t, size_t, int, size_t, int, size_t, const void *);
void *mpz_export (void *, size_t *, int, size_t, int, size_t, const mpz_t);
#if defined (__cplusplus)
}
#endif
#endif /* __MINI_GMP_H__ */

6
iguana/swaps/iguana_BTCswap.c

@ -403,7 +403,7 @@ bits256 instantdex_derivekeypair(bits256 *newprivp,uint8_t pubkey[33],bits256 pr
bits256 sharedsecret;
sharedsecret = curve25519_shared(privkey,orderhash);
vcalc_sha256cat(newprivp->bytes,orderhash.bytes,sizeof(orderhash),sharedsecret.bytes,sizeof(sharedsecret));
return(bitcoin_pubkey33(pubkey,*newprivp));
return(bitcoin_pubkey33(0,pubkey,*newprivp));
}
int32_t instantdex_pubkeyargs(struct bitcoin_swapinfo *swap,cJSON *newjson,int32_t numpubs,bits256 privkey,bits256 hash,int32_t firstbyte)
@ -506,7 +506,7 @@ void instantdex_privkeyextract(struct supernet_info *myinfo,struct bitcoin_swapi
}
continue;
}
pubi = bitcoin_pubkey33(otherpubkey,otherpriv);
pubi = bitcoin_pubkey33(myinfo->ctx,otherpubkey,otherpriv);
vcalc_sha256(0,hashpriv.bytes,otherpriv.bytes,sizeof(otherpriv));
if ( otherpubkey[0] != (instantdex_isbob(swap) ^ 1) + 0x02 )
{
@ -1102,7 +1102,7 @@ cJSON *instantdex_bailinspend(struct iguana_info *coin,bits256 privkey,uint64_t
{
int32_t n; cJSON *txobj;
int32_t scriptv0len; uint8_t p2shscript[256],rmd160[20],scriptv0[128],pubkey[35];
bitcoin_pubkey33(pubkey,privkey);
bitcoin_pubkey33(coin->ctx,pubkey,privkey);
n = bitcoin_pubkeyspend(p2shscript,0,pubkey);
calc_rmd160_sha256(rmd160,p2shscript,n);
scriptv0len = bitcoin_p2shspend(scriptv0,0,rmd160);

Loading…
Cancel
Save