Browse Source

Merge pull request #10 from jl777/dev

dev update
win-cross^2
ca333 8 years ago
committed by GitHub
parent
commit
7bd30495b2
  1. 4
      crypto777/hmac/sha224.c
  2. 86
      crypto777/hmac/sha256.c
  3. 8
      crypto777/hmac/tomcrypt_hash.h
  4. 34
      crypto777/scrypt.c
  5. 2
      iguana/exchanges/LP_include.h
  6. 2
      iguana/exchanges/coins
  7. 2
      iguana/exchanges/stats.c
  8. 7
      iguana/m_MM_StaticNanoMsg
  9. 28
      iguana/m_mm_StaticNanoMsg
  10. 7
      iguana/secp256k1/m_unix_Makefile

4
crypto777/hmac/sha224.c

@ -26,7 +26,7 @@ const struct ltc_hash_descriptor sha224_desc =
9,
&sha224_init,
&sha256_process,
&sha256i_process,
&sha224_done,
&sha224_test,
NULL
@ -69,7 +69,7 @@ int sha224_done(hash_state * md, unsigned char *out)
LTC_ARGCHK(md != NULL);
LTC_ARGCHK(out != NULL);
err = sha256_done(md, buf);
err = sha256i_done(md, buf);
XMEMCPY(out, buf, 28);
#ifdef LTC_CLEAN_STACK
zeromem(buf, sizeof(buf));

86
crypto777/hmac/sha256.c

@ -17,24 +17,6 @@
//#ifdef LTC_SHA256
const struct ltc_hash_descriptor sha256_desc =
{
"sha256",
0,
32,
64,
/* OID */
{ 2, 16, 840, 1, 101, 3, 4, 2, 1, },
9,
&sha256_init,
&sha256_process,
&sha256_done,
&sha256_test,
NULL
};
#ifdef LTC_SMALL_CODE
/* the K array */
static const ulong32 K[64] = {
@ -203,7 +185,7 @@ static int sha256_compress(hash_state * md, unsigned char *buf)
@param md The hash state you wish to initialize
@return CRYPT_OK if successful
*/
int sha256_init(hash_state * md)
int sha256i_init(hash_state * md)
{
LTC_ARGCHK(md != NULL);
@ -227,7 +209,7 @@ int sha256_init(hash_state * md)
@param inlen The length of the data (octets)
@return CRYPT_OK if successful
*/
HASH_PROCESS(sha256_process, sha256_compress, sha256, 64)
HASH_PROCESS(sha256i_process, sha256_compress, sha256, 64)
/**
Terminate the hash to get the digest
@ -235,7 +217,7 @@ HASH_PROCESS(sha256_process, sha256_compress, sha256, 64)
@param out [out] The destination of the hash (32 bytes)
@return CRYPT_OK if successful
*/
int sha256_done(hash_state * md, unsigned char *out)
int sha256i_done(hash_state * md, unsigned char *out)
{
int i;
@ -287,9 +269,9 @@ int sha256_done(hash_state * md, unsigned char *out)
void calc_sha256(char hashstr[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len)
{
hash_state md;
sha256_init(&md);
sha256_process(&md,src,len);
sha256_done(&md,hash);
sha256i_init(&md);
sha256i_process(&md,src,len);
sha256i_done(&md,hash);
if ( hashstr != 0 )
{
int32_t init_hexbytes_noT(char *hexbytes,uint8_t *message,long len);
@ -300,11 +282,11 @@ void calc_sha256(char hashstr[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t
void calc_sha256cat(uint8_t hash[256 >> 3],uint8_t *src,int32_t len,uint8_t *src2,int32_t len2)
{
hash_state md;
sha256_init(&md);
sha256_process(&md,src,len);
sha256i_init(&md);
sha256i_process(&md,src,len);
if ( src2 != 0 )
sha256_process(&md,src2,len2);
sha256_done(&md,hash);
sha256i_process(&md,src2,len2);
sha256i_done(&md,hash);
}
void update_sha256(uint8_t hash[256 >> 3],struct sha256_state *state,uint8_t *src,int32_t len)
@ -312,14 +294,14 @@ void update_sha256(uint8_t hash[256 >> 3],struct sha256_state *state,uint8_t *sr
hash_state md;
memset(&md,0,sizeof(md));
if ( src == 0 )
sha256_init(&md);
sha256i_init(&md);
else
{
md.sha256 = *state;
sha256_process(&md,src,len);
sha256i_process(&md,src,len);
}
*state = md.sha256;
sha256_done(&md,hash);
sha256i_done(&md,hash);
}
/*void calc_OP_HASH160(char hexstr[41],uint8_t hash160[20],char *pubkey)
@ -334,9 +316,9 @@ void update_sha256(uint8_t hash[256 >> 3],struct sha256_state *state,uint8_t *sr
return;
}
decode_hex(buf,len,pubkey);
sha256_init(&md);
sha256_process(&md,buf,len);
sha256_done(&md,sha256);
sha256i_init(&md);
sha256i_process(&md,buf,len);
sha256i_done(&md,sha256);
rmd160_init(&md);
rmd160_process(&md,sha256,256 >> 3);
@ -389,9 +371,9 @@ int sha256_test(void)
char *str;
for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
sha256_init(&md);
sha256_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg));
sha256_done(&md, tmp);
sha256i_init(&md);
sha256i_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg));
sha256i_done(&md, tmp);
if (XMEMCMP(tmp, tests[i].hash, 32) != 0) {
for (j=0; j<32; j++)
printf("%02x",tmp[j]);
@ -400,16 +382,16 @@ int sha256_test(void)
strcpy(str,(char*)tests[i].msg);
reverse_hexstr(str);
printf("reversed.(%s)\n",str);
sha256_init(&md);
sha256_process(&md, (unsigned char*)str, (unsigned long)strlen(str));
sha256_done(&md, tmp);
sha256i_init(&md);
sha256i_process(&md, (unsigned char*)str, (unsigned long)strlen(str));
sha256i_done(&md, tmp);
for (j=0; j<32; j++)
printf("%02x",tmp[j]);
printf(" <- sha256(%s)\n",str);
decode_hex(buf,(int)strlen(tests[i].msg),tests[i].msg);
sha256_init(&md);
sha256_process(&md, (unsigned char*)buf, (unsigned long)strlen(tests[i].msg)/2);
sha256_done(&md, tmp);
sha256i_init(&md);
sha256i_process(&md, (unsigned char*)buf, (unsigned long)strlen(tests[i].msg)/2);
sha256i_done(&md, tmp);
for (j=0; j<32; j++)
printf("%02x",tmp[j]);
printf(" <- sha256(binary %s)\n",tests[i].msg);
@ -436,6 +418,24 @@ int sha256_test(void)
#undef Maj
const struct ltc_hash_descriptor sha256_desc =
{
"sha256",
0,
32,
64,
/* OID */
{ 2, 16, 840, 1, 101, 3, 4, 2, 1, },
9,
&sha256i_init,
&sha256i_process,
&sha256i_done,
&sha256_test,
NULL
};
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha2/sha256.c,v $ */
/* $Revision: 1.11 $ */

8
crypto777/hmac/tomcrypt_hash.h

@ -228,9 +228,9 @@ extern const struct ltc_hash_descriptor sha384_desc;
#endif
#ifdef LTC_SHA256
int sha256_init(hash_state * md);
int sha256_process(hash_state * md, const unsigned char *in, unsigned long inlen);
int sha256_done(hash_state * md, unsigned char *hash);
int sha256i_init(hash_state * md);
int sha256i_process(hash_state * md, const unsigned char *in, unsigned long inlen);
int sha256i_done(hash_state * md, unsigned char *hash);
int sha256_test(void);
extern const struct ltc_hash_descriptor sha256_desc;
@ -239,7 +239,7 @@ extern const struct ltc_hash_descriptor sha256_desc;
#error LTC_SHA256 is required for LTC_SHA224
#endif
int sha224_init(hash_state * md);
#define sha224_process sha256_process
#define sha224_process sha256i_process
int sha224_done(hash_state * md, unsigned char *hash);
int sha224_test(void);
extern const struct ltc_hash_descriptor sha224_desc;

34
crypto777/scrypt.c

@ -69,7 +69,7 @@ static const uint32_t sha256_k[64] = {
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
static inline void sha256_init(uint32_t *state)
static inline void scrypt_sha256_init(uint32_t *state)
{
memcpy(state, sha256_h, 32);
}
@ -102,7 +102,7 @@ W[i] + sha256_k[i])
#define swab32(x) ((((x) << 24) & 0xff000000u) | (((x) << 8) & 0x00ff0000u) | (((x) >> 8) & 0x0000ff00u) | (((x) >> 24) & 0x000000ffu))
static inline void sha256_transform(uint32_t *state, const uint32_t *block, int swap)
static inline void scrypt_sha256_transform(uint32_t *state, const uint32_t *block, int swap)
{
uint32_t W[64];
uint32_t S[8];
@ -203,29 +203,29 @@ static inline void HMAC_SHA256_80_init(const uint32_t *key,uint32_t *tstate, uin
/* tstate is assumed to contain the midstate of key */
memcpy(pad, key + 16, 16);
memcpy(pad + 4, keypad, 48);
sha256_transform(tstate, pad, 0);
scrypt_sha256_transform(tstate, pad, 0);
memcpy(ihash, tstate, 32);
sha256_init(ostate);
scrypt_sha256_init(ostate);
for (i = 0; i < 8; i++)
pad[i] = ihash[i] ^ 0x5c5c5c5c;
for (; i < 16; i++)
pad[i] = 0x5c5c5c5c;
sha256_transform(ostate, pad, 0);
scrypt_sha256_transform(ostate, pad, 0);
sha256_init(tstate);
scrypt_sha256_init(tstate);
for (i = 0; i < 8; i++)
pad[i] = ihash[i] ^ 0x36363636;
for (; i < 16; i++)
pad[i] = 0x36363636;
sha256_transform(tstate, pad, 0);
scrypt_sha256_transform(tstate, pad, 0);
}
static inline void PBKDF2_SHA256_80_128(const uint32_t *tstate,const uint32_t *ostate, const uint32_t *salt, uint32_t *output)
{
uint32_t istate[8], ostate2[8],ibuf[16], obuf[16]; int i, j;
memcpy(istate, tstate, 32);
sha256_transform(istate, salt, 0);
scrypt_sha256_transform(istate, salt, 0);
memcpy(ibuf, salt + 16, 16);
memcpy(ibuf + 5, innerpad, 44);
memcpy(obuf + 8, outerpad, 32);
@ -233,9 +233,9 @@ static inline void PBKDF2_SHA256_80_128(const uint32_t *tstate,const uint32_t *o
{
memcpy(obuf, istate, 32);
ibuf[4] = i + 1;
sha256_transform(obuf, ibuf, 0);
scrypt_sha256_transform(obuf, ibuf, 0);
memcpy(ostate2, ostate, 32);
sha256_transform(ostate2, obuf, 0);
scrypt_sha256_transform(ostate2, obuf, 0);
for (j = 0; j < 8; j++)
output[8 * i + j] = swab32(ostate2[j]);
}
@ -244,12 +244,12 @@ static inline void PBKDF2_SHA256_80_128(const uint32_t *tstate,const uint32_t *o
static inline void PBKDF2_SHA256_128_32(uint32_t *tstate, uint32_t *ostate,const uint32_t *salt, uint32_t *output)
{
uint32_t buf[16]; int i;
sha256_transform(tstate, salt, 1);
sha256_transform(tstate, salt + 16, 1);
sha256_transform(tstate, finalblk, 0);
scrypt_sha256_transform(tstate, salt, 1);
scrypt_sha256_transform(tstate, salt + 16, 1);
scrypt_sha256_transform(tstate, finalblk, 0);
memcpy(buf, tstate, 32);
memcpy(buf + 8, outerpad, 32);
sha256_transform(ostate, buf, 0);
scrypt_sha256_transform(ostate, buf, 0);
for (i = 0; i < 8; i++)
output[i] = swab32(ostate[i]);
}
@ -363,11 +363,11 @@ void calc_scrypthash(uint32_t *hash,void *data)
uint8_t *scratchbuf; uint32_t midstate[8];
memset(midstate,0,sizeof(midstate));
memset(hash,0,32);
sha256_init(midstate);
sha256_transform(midstate,(void *)data,0);
scrypt_sha256_init(midstate);
scrypt_sha256_transform(midstate,(void *)data,0);
scratchbuf = malloc(1024 * 128 + 64);
scrypt_1024_1_1_256((void *)data,hash,midstate,scratchbuf,1024);
free(scratchbuf);
}
//010000000000000000000000000000000000000000000000000000000000000000000000d9ced4ed1130f7b7faad9be25323ffafa33232a17c3edf6cfd97bee6bafbdd97b9aa8e4ef0ff0f1ecd513f7c
//010000000000000000000000000000000000000000000000000000000000000000000000d9ced4ed1130f7b7faad9be25323ffafa33232a17c3edf6cfd97bee6bafbdd97b9aa8e4ef0ff0f1ecd513f7c00
//010000000000000000000000000000000000000000000000000000000000000000000000d9ced4ed1130f7b7faad9be25323ffafa33232a17c3edf6cfd97bee6bafbdd97b9aa8e4ef0ff0f1ecd513f7c00

2
iguana/exchanges/LP_include.h

@ -21,7 +21,7 @@
#ifndef LP_INCLUDE_H
#define LP_INCLUDE_H
#define LP_STRICTPEERS
//#define LP_STRICTPEERS
#define LP_COMMAND_SENDSOCK NN_PUSH
#define LP_COMMAND_RECVSOCK NN_PULL

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

2
iguana/exchanges/stats.c

@ -669,6 +669,8 @@ void stats_rpcloop(void *args)
//printf("RETURN.(%s) jsonflag.%d postflag.%d\n",retstr,jsonflag,postflag);
if ( jsonflag != 0 || postflag != 0 )
{
if ( retstr == 0 )
retstr = clonestr("{}");
response = malloc(strlen(retstr)+1024+1+1);
sprintf(hdrs,"HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nAccess-Control-Allow-Credentials: true\r\nAccess-Control-Allow-Methods: GET, POST\r\nCache-Control : no-cache, no-store, must-revalidate\r\n%sContent-Length : %8d\r\n\r\n",content_type,(int32_t)strlen(retstr));
response[0] = '\0';

7
iguana/m_MM_StaticNanoMsg

@ -1,7 +0,0 @@
#!/bin/bash
#./configure --enable-endomorphism --enable-module-ecdh --enable-module-schnorr --enable-module-rangeproof --enable-experimental --enable-module_recovery
rm -f marketmaker
git pull
cd secp256k1; ./m_unix; cd ..
cd ../crypto777; make -f m_LP_StaticNanoMsg all; make -f m_LP_StaticNanoMsg clean; cd ../iguana
gcc -g -o marketmaker -I../crypto777 exchanges/mm.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a ../OSlibs/linux/$(uname -m)/libnanomsg-static.a -lcurl -lpthread -lm

28
iguana/m_mm_StaticNanoMsg

@ -0,0 +1,28 @@
# makefile for marketmaker uses static nanomsg
# author: fadedreamz@SuperNet.org
# date: Aug, 2017
LIB_ARCH=$(uname -m)
.PHONY: clean all
err:
@echo "no rule specified, use {clean,all}"
exit 1
clean:
- rm -f ../agents/iguana *.o
- rm ../agents/marketmaker
all:
@echo "Add -j(core count + 1) to speed up build - e,g make -j5 -f m_mm_StaticNanoMsg; on a quad core cpu"
+$(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) -o ../agents/marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.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 "==========================="

7
iguana/secp256k1/m_unix_Makefile

@ -0,0 +1,7 @@
# author: fadedreamz@SuperNet.org
# date: August, 2017
all:
gcc -c -o ../secp256k1.o -I. -I./src -I./include -I./src -O3 -W -std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings -fvisibility=hidden -DHAVE_CONFIG_H src/secp256k1.c
.PHONY: all
Loading…
Cancel
Save