Browse Source

Merge pull request #653 from jl777/dev

Dev
patch-1
jl777 7 years ago
committed by GitHub
parent
commit
0273a09fad
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      iguana/exchanges/LP_bitcoin.c
  2. 1
      iguana/exchanges/LP_include.h
  3. 2
      iguana/exchanges/LP_remember.c
  4. 13
      iguana/exchanges/mm.c
  5. 1839
      iguana/keccak.c
  6. 2
      iguana/m_mm
  7. 2
      iguana/m_mm_StaticNanoMsg
  8. 293
      iguana/sph_keccak.h
  9. 3
      marketmaker.vcxproj
  10. 5
      marketmaker.vcxproj.filters

10
iguana/exchanges/LP_bitcoin.c

@ -2041,8 +2041,13 @@ bits256 bits256_calctxid(char *symbol,uint8_t *serialized,int32_t len)
bits256 bits256_calcaddrhash(char *symbol,uint8_t *serialized,int32_t len)
{
bits256 hash;
memset(hash.bytes,0,sizeof(hash));
if ( strcmp(symbol,"GRS") != 0 )
hash = bits256_doublesha256(0,serialized,len);
{
if ( strcmp(symbol,"SMART") != 0 )
hash = bits256_doublesha256(0,serialized,len);
else HashKeccak(hash.bytes,serialized,len);
}
else
{
HashGroestl(hash.bytes,serialized,len);
@ -3442,7 +3447,10 @@ bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2sht
hashtype |= (0x777 << 20);
#endif
if ( btcpflag != 0 )
{
hashtype = 0x2a41;
printf("BTCP detected: hardcode hashtype to %08x\n",hashtype);
}
len += iguana_rwnum(1,&serialized[len],sizeof(hashtype),&hashtype);
if ( sbtcflag != 0 )
{

1
iguana/exchanges/LP_include.h

@ -522,6 +522,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_
//void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo);
struct LP_address_utxo *LP_address_utxofind(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout);
int64_t LP_myzcredits();
void HashKeccak(uint8_t *hash,void *data,size_t len);
void test_validate(struct iguana_info *coin,char *signedtx);
void LP_instantdex_depositadd(char *coinaddr,bits256 txid);
int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr,char *origcoinaddr);

2
iguana/exchanges/LP_remember.c

@ -253,6 +253,8 @@ void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx
if ( rawtx != 0 )
jaddstr(reqjson,"update",rawtx->name);
else jaddstr(reqjson,"update","main");
jaddnum(reqjson,"requestid",swap->I.req.requestid);
jaddnum(reqjson,"quoteid",swap->I.req.quoteid);
outstr = jprint(reqjson,1);
LP_queuecommand(0,outstr,IPC_ENDPOINT,-1,0);
free(outstr);

13
iguana/exchanges/mm.c

@ -71,6 +71,9 @@ void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveas
#include "/usr/local/include/nanomsg/ws.h"
#endif
#endif
#ifndef NN_WS_MSG_TYPE
#define NN_WS_MSG_TYPE 1
#endif
#include "LP_nativeDEX.c"
@ -182,16 +185,22 @@ int main(int argc, const char * argv[])
}
else if ( argv[1] != 0 && strcmp(argv[1],"events") == 0 )
{
int32_t len; void *ptr;
int32_t len,bufsize = 1000000; void *ptr; char *buf;
if ( (IPC_ENDPOINT= nn_socket(AF_SP,NN_PAIR)) >= 0 )
{
if ( nn_connect(IPC_ENDPOINT,"ws://127.0.0.1:5555") >= 0 )
{
buf = calloc(1,bufsize);
while ( 1 )
{
if ( (len= nn_recv(IPC_ENDPOINT,&ptr,NN_MSG,0)) > 0 )
{
printf("%s\n",(char *)ptr);
if ( len < bufsize )
{
memcpy(buf,ptr,len);
buf[len] = 0;
printf("%s\n",(char *)buf);
}
nn_freemsg(ptr);
}
}

1839
iguana/keccak.c

File diff suppressed because it is too large

2
iguana/m_mm

@ -10,4 +10,4 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
nanomsg_lib="../OSlibs/osx/$(uname -m)/libnanomsg-static.a"
fi
gcc -g -o marketmaker -DNOTETOMIC -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a $nanomsg_lib -lcurl -lpthread -lm
gcc -g -o marketmaker -DNOTETOMIC -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c keccak.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a $nanomsg_lib -lcurl -lpthread -lm

2
iguana/m_mm_StaticNanoMsg

@ -19,7 +19,7 @@ all:
+$(MAKE) -C secp256k1 -f m_unix_Makefile all
+$(MAKE) -C ../crypto777 -f m_LP_StaticNanoMsg all
+$(MAKE) -C ../crypto777 -f m_LP_StaticNanoMsg clean
$(CC) -DNOTETOMIC -o ../agents/marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a ../OSlibs/linux/$(shell uname -m)/libnanomsg-static.a -lcurl -lpthread -lm -lanl
$(CC) -DNOTETOMIC -o ../agents/marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c keccak.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a ../OSlibs/linux/$(shell uname -m)/libnanomsg-static.a -lcurl -lpthread -lm -lanl
@echo "==========================="
@echo " marketmaker -> `pwd`/../agents/marketmaker"
@echo "==========================="

293
iguana/sph_keccak.h

@ -0,0 +1,293 @@
/* $Id: sph_keccak.h 216 2010-06-08 09:46:57Z tp $ */
/**
* Keccak interface. This is the interface for Keccak with the
* recommended parameters for SHA-3, with output lengths 224, 256,
* 384 and 512 bits.
*
* ==========================(LICENSE BEGIN)============================
*
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* ===========================(LICENSE END)=============================
*
* @file sph_keccak.h
* @author Thomas Pornin <thomas.pornin@cryptolog.com>
*/
#ifndef SPH_KECCAK_H__
#define SPH_KECCAK_H__
#ifdef __cplusplus
extern "C"{
#endif
#include <stddef.h>
#include "sph_types.h"
/**
* Output size (in bits) for Keccak-224.
*/
#define SPH_SIZE_keccak224 224
/**
* Output size (in bits) for Keccak-256.
*/
#define SPH_SIZE_keccak256 256
/**
* Output size (in bits) for Keccak-384.
*/
#define SPH_SIZE_keccak384 384
/**
* Output size (in bits) for Keccak-512.
*/
#define SPH_SIZE_keccak512 512
/**
* This structure is a context for Keccak computations: it contains the
* intermediate values and some data from the last entered block. Once a
* Keccak computation has been performed, the context can be reused for
* another computation.
*
* The contents of this structure are private. A running Keccak computation
* can be cloned by copying the context (e.g. with a simple
* <code>memcpy()</code>).
*/
typedef struct {
#ifndef DOXYGEN_IGNORE
unsigned char buf[144]; /* first field, for alignment */
size_t ptr, lim;
union {
#if SPH_64
sph_u64 wide[25];
#endif
sph_u32 narrow[50];
} u;
#endif
} sph_keccak_context;
/**
* Type for a Keccak-224 context (identical to the common context).
*/
typedef sph_keccak_context sph_keccak224_context;
/**
* Type for a Keccak-256 context (identical to the common context).
*/
typedef sph_keccak_context sph_keccak256_context;
/**
* Type for a Keccak-384 context (identical to the common context).
*/
typedef sph_keccak_context sph_keccak384_context;
/**
* Type for a Keccak-512 context (identical to the common context).
*/
typedef sph_keccak_context sph_keccak512_context;
/**
* Initialize a Keccak-224 context. This process performs no memory allocation.
*
* @param cc the Keccak-224 context (pointer to a
* <code>sph_keccak224_context</code>)
*/
void sph_keccak224_init(void *cc);
/**
* Process some data bytes. It is acceptable that <code>len</code> is zero
* (in which case this function does nothing).
*
* @param cc the Keccak-224 context
* @param data the input data
* @param len the input data length (in bytes)
*/
void sph_keccak224(void *cc, const void *data, size_t len);
/**
* Terminate the current Keccak-224 computation and output the result into
* the provided buffer. The destination buffer must be wide enough to
* accomodate the result (28 bytes). The context is automatically
* reinitialized.
*
* @param cc the Keccak-224 context
* @param dst the destination buffer
*/
void sph_keccak224_close(void *cc, void *dst);
/**
* Add a few additional bits (0 to 7) to the current computation, then
* terminate it and output the result in the provided buffer, which must
* be wide enough to accomodate the result (28 bytes). If bit number i
* in <code>ub</code> has value 2^i, then the extra bits are those
* numbered 7 downto 8-n (this is the big-endian convention at the byte
* level). The context is automatically reinitialized.
*
* @param cc the Keccak-224 context
* @param ub the extra bits
* @param n the number of extra bits (0 to 7)
* @param dst the destination buffer
*/
void sph_keccak224_addbits_and_close(
void *cc, unsigned ub, unsigned n, void *dst);
/**
* Initialize a Keccak-256 context. This process performs no memory allocation.
*
* @param cc the Keccak-256 context (pointer to a
* <code>sph_keccak256_context</code>)
*/
void sph_keccak256_init(void *cc);
/**
* Process some data bytes. It is acceptable that <code>len</code> is zero
* (in which case this function does nothing).
*
* @param cc the Keccak-256 context
* @param data the input data
* @param len the input data length (in bytes)
*/
void sph_keccak256(void *cc, const void *data, size_t len);
/**
* Terminate the current Keccak-256 computation and output the result into
* the provided buffer. The destination buffer must be wide enough to
* accomodate the result (32 bytes). The context is automatically
* reinitialized.
*
* @param cc the Keccak-256 context
* @param dst the destination buffer
*/
void sph_keccak256_close(void *cc, void *dst);
/**
* Add a few additional bits (0 to 7) to the current computation, then
* terminate it and output the result in the provided buffer, which must
* be wide enough to accomodate the result (32 bytes). If bit number i
* in <code>ub</code> has value 2^i, then the extra bits are those
* numbered 7 downto 8-n (this is the big-endian convention at the byte
* level). The context is automatically reinitialized.
*
* @param cc the Keccak-256 context
* @param ub the extra bits
* @param n the number of extra bits (0 to 7)
* @param dst the destination buffer
*/
void sph_keccak256_addbits_and_close(
void *cc, unsigned ub, unsigned n, void *dst);
/**
* Initialize a Keccak-384 context. This process performs no memory allocation.
*
* @param cc the Keccak-384 context (pointer to a
* <code>sph_keccak384_context</code>)
*/
void sph_keccak384_init(void *cc);
/**
* Process some data bytes. It is acceptable that <code>len</code> is zero
* (in which case this function does nothing).
*
* @param cc the Keccak-384 context
* @param data the input data
* @param len the input data length (in bytes)
*/
void sph_keccak384(void *cc, const void *data, size_t len);
/**
* Terminate the current Keccak-384 computation and output the result into
* the provided buffer. The destination buffer must be wide enough to
* accomodate the result (48 bytes). The context is automatically
* reinitialized.
*
* @param cc the Keccak-384 context
* @param dst the destination buffer
*/
void sph_keccak384_close(void *cc, void *dst);
/**
* Add a few additional bits (0 to 7) to the current computation, then
* terminate it and output the result in the provided buffer, which must
* be wide enough to accomodate the result (48 bytes). If bit number i
* in <code>ub</code> has value 2^i, then the extra bits are those
* numbered 7 downto 8-n (this is the big-endian convention at the byte
* level). The context is automatically reinitialized.
*
* @param cc the Keccak-384 context
* @param ub the extra bits
* @param n the number of extra bits (0 to 7)
* @param dst the destination buffer
*/
void sph_keccak384_addbits_and_close(
void *cc, unsigned ub, unsigned n, void *dst);
/**
* Initialize a Keccak-512 context. This process performs no memory allocation.
*
* @param cc the Keccak-512 context (pointer to a
* <code>sph_keccak512_context</code>)
*/
void sph_keccak512_init(void *cc);
/**
* Process some data bytes. It is acceptable that <code>len</code> is zero
* (in which case this function does nothing).
*
* @param cc the Keccak-512 context
* @param data the input data
* @param len the input data length (in bytes)
*/
void sph_keccak512(void *cc, const void *data, size_t len);
/**
* Terminate the current Keccak-512 computation and output the result into
* the provided buffer. The destination buffer must be wide enough to
* accomodate the result (64 bytes). The context is automatically
* reinitialized.
*
* @param cc the Keccak-512 context
* @param dst the destination buffer
*/
void sph_keccak512_close(void *cc, void *dst);
/**
* Add a few additional bits (0 to 7) to the current computation, then
* terminate it and output the result in the provided buffer, which must
* be wide enough to accomodate the result (64 bytes). If bit number i
* in <code>ub</code> has value 2^i, then the extra bits are those
* numbered 7 downto 8-n (this is the big-endian convention at the byte
* level). The context is automatically reinitialized.
*
* @param cc the Keccak-512 context
* @param ub the extra bits
* @param n the number of extra bits (0 to 7)
* @param dst the destination buffer
*/
void sph_keccak512_addbits_and_close(
void *cc, unsigned ub, unsigned n, void *dst);
#ifdef __cplusplus
}
#endif
#endif

3
marketmaker.vcxproj

@ -249,6 +249,7 @@
<ClCompile Include="crypto777\tweetnacl.c" />
<ClCompile Include="iguana\exchanges\mm.c" />
<ClCompile Include="iguana\groestl.c" />
<ClCompile Include="iguana\keccak.c" />
<ClCompile Include="iguana\mini-gmp.c" />
<ClCompile Include="iguana\secp256k1\src\secp256k1.c" />
<ClCompile Include="iguana\segwit_addr.c" />
@ -257,4 +258,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

5
marketmaker.vcxproj.filters

@ -296,8 +296,11 @@
<ClCompile Include="iguana\groestl.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="iguana\keccak.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
</Project>
</Project>

Loading…
Cancel
Save