dist_man_MANS = minerd.1
-minerd_SOURCES = elist.h \
- miner.h \
- compat.h \
- cpu-miner.c \
- util.c \
- sha2.c \
- scrypt.c \
- keccak.c \
- heavy.c \
- quark.c \
- skein.c \
- ink.c \
- blake.c \
- cryptonight.c \
- fresh.c \
- neoscrypt.c \
- s3.c \
- x11.c \
- x13.c \
- x14.c \
- x15.c \
- pentablake.c \
- sha3/blake2s.c \
- sha3/sph_keccak.c \
- sha3/sph_hefty1.c \
- sha3/sph_groestl.c \
- sha3/sph_skein.c \
- sha3/sph_bmw.c \
- sha3/sph_jh.c \
- sha3/sph_shavite.c \
- sha3/sph_blake.c \
- sha3/sph_luffa.c \
- sha3/sph_cubehash.c \
- sha3/sph_simd.c \
- sha3/sph_echo.c \
- sha3/sph_hamsi.c \
- sha3/sph_fugue.c \
- sha3/sph_shabal.c \
- sha3/sph_whirlpool.c \
- crypto/oaes_lib.c \
- crypto/c_keccak.c \
- crypto/c_groestl.c \
- crypto/c_blake256.c \
- crypto/c_jh.c \
- crypto/c_skein.c \
- crypto/hash.c \
- crypto/aesb.c
+minerd_SOURCES = \
+ cpu-miner.c util.c \
+ sha3/sph_keccak.c \
+ sha3/sph_hefty1.c \
+ sha3/sph_groestl.c \
+ sha3/sph_skein.c \
+ sha3/sph_bmw.c \
+ sha3/sph_jh.c \
+ sha3/sph_shavite.c \
+ sha3/sph_blake.c \
+ sha3/sph_luffa.c \
+ sha3/sph_cubehash.c \
+ sha3/sph_simd.c \
+ sha3/sph_echo.c \
+ sha3/sph_hamsi.c \
+ sha3/sph_fugue.c \
+ sha3/sph_shabal.c \
+ sha3/sph_whirlpool.c \
+ crypto/blake2s \
+ crypto/oaes_lib.c \
+ crypto/c_keccak.c \
+ crypto/c_groestl.c \
+ crypto/c_blake256.c \
+ crypto/c_jh.c \
+ crypto/c_skein.c \
+ crypto/hash.c \
+ crypto/aesb.c \
+ blake.c \
+ cryptonight.c \
+ fresh.c \
+ heavy.c \
+ ink.c \
+ keccak.c \
+ pentablake.c \
+ quark.c \
+ neoscrypt.c \
+ nist5.c \
+ qubit.c \
+ scrypt.c sha2.c \
+ skein.c \
+ s3.c \
+ x11.c \
+ x13.c \
+ x14.c \
+ x15.c
if USE_ASM
minerd_SOURCES += neoscrypt_asm.S
minerd_LDFLAGS = @LDFLAGS@
minerd_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@
minerd_CPPFLAGS = @LIBCURL_CPPFLAGS@
-minerd_CFLAGS = -Wno-pointer-sign
+minerd_CFLAGS = -Wno-pointer-sign -Wno-pointer-to-int-cast
if HAVE_WINDOWS
minerd_CFLAGS += -Wl,--stack,10485760
-Version multi 1.0.6 (Tanguy Pruvot)
+Version 1.0.7 (Tanguy Pruvot)
+- Add NIST5 and QUBIT algos
+
+Version 1.0.6 (Tanguy Pruvot)
- Fix scrypt algo
- More work on VC2013
- Add -f tuning option to test with reduced difficulty
- Add S3 algo
-Version multi 1.0.5 (Tanguy Pruvot)
+Version 1.0.5 (Tanguy Pruvot)
- Merge remaining v2.4 cpu-miner changes
- Add colored output (disable with --no-color)
- Windows (VC++ 2013 and MinGW64 build support)
- Enhance --version informations (compiler + lib versions)
-Version multi 1.0.4 (Tanguy Pruvot)
+Version 1.0.4 (Tanguy Pruvot)
- Add x13 x14 and x15 algos (Sherlockcoin, X14Coin, Webcoin..)
- Add scrypt:N variants (Vertcoin)
-CPUMiner-Multi
+CPUMiner-Multi
==============
[](https://travis-ci.org/tpruvot/cpuminer-multi)
* ✓ __scrypt__ (Litecoin, Dogecoin, Feathercoin, etc..)
* ✓ __scrypt:N__ (Vertcoin [VTC])
* ✓ __sha256d__ (Bitcoin, Freicoin, Peercoin/PPCoin, Terracoin, etc..)
+ * ✓ __blake__ (Neos/Saffron Blake-256)
+ * ✓ __cryptonight__ (Bytecoin [BCN], Monero)
+ * ✓ __fresh__ (FreshCoin)
+ * ✓ __neoscrypt__ (Feathercoin)
+ * ✓ __nist5__
+ * ✓ __pentablake__ (Joincoin)
+ * ✓ __qubit__
* ✓ __s3__ (OneCoin)
* ✓ __x11__ (Darkcoin [DRK], Hirocoin, Limecoin)
* ✓ __x13__ (Sherlockcoin, [ACE], [B2B], [GRC], [XHC], etc..)
* ✓ __x14__ (X14, Webcoin [WEB])
* ✓ __x15__ (RadianceCoin [RCE])
- * ✓ __cryptonight__ (Bytecoin [BCN], Monero)
- * ✓ __fresh__ (FreshCoin)
- * ✓ __blake__ (Neos/Saffron Blake-256)
- * ✓ __neoscrypt__ (Feathercoin)
- * ✓ __pentablake__ (Joincoin)
#### Implemented, but untested
* ? keccak (Maxcoin HelixCoin, CryptoMeth, Galleon, 365coin, Slothcoin, BitcointalkCoin)
-AC_INIT([cpuminer-multi], [1.0.6])
+AC_INIT([cpuminer-multi], [1.0.7])
AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM
#include "miner.h"
#ifdef WIN32
-#include <Mmsystem.h>
-#pragma comment(lib, "winmm.lib")
#include "compat/winansi.h"
BOOL WINAPI ConsoleHandler(DWORD);
#endif
+#ifdef _MSC_VER
+#include <Mmsystem.h>
+#pragma comment(lib, "winmm.lib")
+#endif
#define PROGRAM_NAME "cpuminer-multi"
ALGO_SHAVITE3, /* Shavite3 */
ALGO_BLAKE, /* Blake */
ALGO_FRESH, /* Fresh */
+ ALGO_NIST5, /* Nist5 */
+ ALGO_QUBIT, /* Qubit */
ALGO_S3, /* S3 */
ALGO_X11, /* X11 */
ALGO_X13, /* X13 */
"shavite3",
"blake",
"fresh",
+ "nist5",
+ "qubit",
"s3",
"x11",
"x13",
scrypt scrypt(1024, 1, 1) (default)\n\
scrypt:N scrypt(N, 1, 1)\n\
sha256d SHA-256d\n\
- keccak Keccak\n\
- quark Quark\n\
+ blake Blake\n\
+ cryptonight CryptoNight\n\
+ fresh Fresh\n\
heavy Heavy\n\
+ keccak Keccak\n\
neoscrypt NeoScrypt(128, 2, 1)\n\
- skein Skein\n\
+ nist5 Nist5\n\
+ pentablake Pentablake\n\
+ quark Quark\n\
+ qubit Qubit\n\
shavite3 Shavite3\n\
- blake Blake\n\
- fresh Fresh\n\
+ skein Skein\n\
s3 S3\n\
x11 X11\n\
x13 X13\n\
x14 X14\n\
x15 X15\n\
- pentablake Pentablake\n\
- cryptonight CryptoNight\n\
-o, --url=URL URL of mining server\n\
-O, --userpass=U:P username:password pair for mining server\n\
-u, --user=USERNAME username for mining server\n\
rc = scanhash_fresh(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
+ case ALGO_NIST5:
+ rc = scanhash_nist5(thr_id, work.data, work.target, max_nonce,
+ &hashes_done);
+ break;
+ case ALGO_QUBIT:
+ rc = scanhash_qubit(thr_id, work.data, work.target, max_nonce,
+ &hashes_done);
+ break;
case ALGO_S3:
rc = scanhash_s3(thr_id, work.data, work.target, max_nonce,
&hashes_done);
<ClCompile Include="crypto\oaes_lib.c" />
<ClCompile Include="ink.c" />
<ClCompile Include="s3.c" />
- <ClCompile Include="sha3\blake2s.c" />
+ <ClCompile Include="crypto\blake2s.c" />
<ClCompile Include="sha3\sph_hefty1.c" />
<ClCompile Include="util.c">
<Optimization Condition="'$(Configuration)'=='Release'">Full</Optimization>
<ClCompile Include="heavy.c" />
<ClCompile Include="keccak.c" />
<ClCompile Include="neoscrypt.c" />
+ <ClCompile Include="nist5.c" />
<ClCompile Include="pentablake.c" />
<ClCompile Include="quark.c" />
+ <ClCompile Include="qubit.c" />
<ClCompile Include="sha2.c" />
<ClCompile Include="scrypt.c">
<Optimization Condition="'$(Configuration)'=='Release'">Full</Optimization>
<ClInclude Include="compat\unistd.h" />
<ClInclude Include="compat\winansi.h" />
<ClInclude Include="cpuminer-config.h" />
+ <ClInclude Include="crypto\blake2s.h" />
<ClInclude Include="crypto\c_blake256.h" />
<ClInclude Include="crypto\c_groestl.h" />
<ClInclude Include="crypto\c_jh.h" />
<ClInclude Include="scryptjane\scrypt-jane-romix.h" />
<ClInclude Include="scryptjane\scrypt-jane-salsa.h" />
<ClInclude Include="scryptjane\scrypt-jane-test-vectors.h" />
- <ClInclude Include="sha3\blake2s.h" />
<ClInclude Include="sha3\sph_blake.h" />
<ClInclude Include="sha3\sph_bmw.h" />
<ClInclude Include="sha3\sph_cubehash.h" />
<Target Name="AfterClean">
<Delete Files="@(FilesToCopy->'$(OutDir)%(Filename)%(Extension)')" TreatErrorsAsWarnings="true" />
</Target>
-</Project>
\ No newline at end of file
+</Project>
<Filter>jansson</Filter>
</ClCompile>
<ClCompile Include="ink.c" />
- <ClCompile Include="sha3\blake2s.c">
+ <ClCompile Include="crypto\blake2s.c">
<Filter>crypto</Filter>
</ClCompile>
<ClCompile Include="crypto\c_skein.c">
<ClInclude Include="..\ccminer\compat\jansson\config.h">
<Filter>jansson</Filter>
</ClInclude>
- <ClInclude Include="sha3\blake2s.h">
+ <ClInclude Include="crypto\blake2s.h">
<Filter>crypto</Filter>
</ClInclude>
<ClInclude Include="crypto\c_skein.h">
<Filter>arch\arm</Filter>
</None>
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
--- /dev/null
+/**
+ * BLAKE2 reference source code package - reference C implementations
+ *
+ *
+ * To the extent possible under law, the author(s) have dedicated all copyright
+ * and related and neighboring rights to this software to the public domain
+ * worldwide. This software is distributed without any warranty.
+ *
+ * You should have received a copy of the CC0 Public Domain Dedication along with
+ * this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "sha3/sph_types.h"
+#include "crypto/blake2s.h"
+
+static const uint32_t blake2s_IV[8] =
+{
+ 0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL,
+ 0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL
+};
+
+static const uint8_t blake2s_sigma[10][16] =
+{
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
+ { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
+ { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
+ { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
+ { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
+ { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
+ { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
+ { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
+ { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
+ { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
+};
+
+static inline int blake2s_set_lastnode( blake2s_state *S )
+{
+ S->f[1] = ~0U;
+ return 0;
+}
+
+static inline int blake2s_clear_lastnode( blake2s_state *S )
+{
+ S->f[1] = 0U;
+ return 0;
+}
+
+/* Some helper functions, not necessarily useful */
+static inline int blake2s_set_lastblock( blake2s_state *S )
+{
+ if( S->last_node ) blake2s_set_lastnode( S );
+
+ S->f[0] = ~0U;
+ return 0;
+}
+
+static inline int blake2s_clear_lastblock( blake2s_state *S )
+{
+ if( S->last_node ) blake2s_clear_lastnode( S );
+
+ S->f[0] = 0U;
+ return 0;
+}
+
+static inline int blake2s_increment_counter( blake2s_state *S, const uint32_t inc )
+{
+ S->t[0] += inc;
+ S->t[1] += ( S->t[0] < inc );
+ return 0;
+}
+
+// Parameter-related functions
+static inline int blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length )
+{
+ P->digest_length = digest_length;
+ return 0;
+}
+
+static inline int blake2s_param_set_fanout( blake2s_param *P, const uint8_t fanout )
+{
+ P->fanout = fanout;
+ return 0;
+}
+
+static inline int blake2s_param_set_max_depth( blake2s_param *P, const uint8_t depth )
+{
+ P->depth = depth;
+ return 0;
+}
+
+static inline int blake2s_param_set_leaf_length( blake2s_param *P, const uint32_t leaf_length )
+{
+ store32( &P->leaf_length, leaf_length );
+ return 0;
+}
+
+static inline int blake2s_param_set_node_offset( blake2s_param *P, const uint64_t node_offset )
+{
+ store48( P->node_offset, node_offset );
+ return 0;
+}
+
+static inline int blake2s_param_set_node_depth( blake2s_param *P, const uint8_t node_depth )
+{
+ P->node_depth = node_depth;
+ return 0;
+}
+
+static inline int blake2s_param_set_inner_length( blake2s_param *P, const uint8_t inner_length )
+{
+ P->inner_length = inner_length;
+ return 0;
+}
+
+static inline int blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] )
+{
+ memcpy( P->salt, salt, BLAKE2S_SALTBYTES );
+ return 0;
+}
+
+static inline int blake2s_param_set_personal( blake2s_param *P, const uint8_t personal[BLAKE2S_PERSONALBYTES] )
+{
+ memcpy( P->personal, personal, BLAKE2S_PERSONALBYTES );
+ return 0;
+}
+
+static inline int blake2s_init0( blake2s_state *S )
+{
+ memset( S, 0, sizeof( blake2s_state ) );
+
+ for( int i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i];
+
+ return 0;
+}
+
+/* init2 xors IV with input parameter block */
+int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
+{
+ blake2s_init0( S );
+ uint32_t *p = ( uint32_t * )( P );
+
+ /* IV XOR ParamBlock */
+ for( size_t i = 0; i < 8; ++i )
+ S->h[i] ^= load32( &p[i] );
+
+ return 0;
+}
+
+
+// Sequential blake2s initialization
+int blake2s_init( blake2s_state *S, const uint8_t outlen )
+{
+ blake2s_param P[1];
+
+ /* Move interval verification here? */
+ if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1;
+
+ P->digest_length = outlen;
+ P->key_length = 0;
+ P->fanout = 1;
+ P->depth = 1;
+ store32( &P->leaf_length, 0 );
+ store48( &P->node_offset, 0 );
+ P->node_depth = 0;
+ P->inner_length = 0;
+ // memset(P->reserved, 0, sizeof(P->reserved) );
+ memset( P->salt, 0, sizeof( P->salt ) );
+ memset( P->personal, 0, sizeof( P->personal ) );
+ return blake2s_init_param( S, P );
+}
+
+int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen )
+{
+ blake2s_param P[1];
+
+ if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1;
+
+ if ( !key || !keylen || keylen > BLAKE2S_KEYBYTES ) return -1;
+
+ P->digest_length = outlen;
+ P->key_length = keylen;
+ P->fanout = 1;
+ P->depth = 1;
+ store32( &P->leaf_length, 0 );
+ store48( &P->node_offset, 0 );
+ P->node_depth = 0;
+ P->inner_length = 0;
+ // memset(P->reserved, 0, sizeof(P->reserved) );
+ memset( P->salt, 0, sizeof( P->salt ) );
+ memset( P->personal, 0, sizeof( P->personal ) );
+
+ if( blake2s_init_param( S, P ) < 0 ) return -1;
+
+ {
+ uint8_t block[BLAKE2S_BLOCKBYTES];
+ memset( block, 0, BLAKE2S_BLOCKBYTES );
+ memcpy( block, key, keylen );
+ blake2s_update( S, block, BLAKE2S_BLOCKBYTES );
+ secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */
+ }
+ return 0;
+}
+
+int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] )
+{
+ uint32_t m[16];
+ uint32_t v[16];
+
+ for( size_t i = 0; i < 16; ++i )
+ m[i] = load32( block + i * sizeof( m[i] ) );
+
+ for( size_t i = 0; i < 8; ++i )
+ v[i] = S->h[i];
+
+ v[ 8] = blake2s_IV[0];
+ v[ 9] = blake2s_IV[1];
+ v[10] = blake2s_IV[2];
+ v[11] = blake2s_IV[3];
+ v[12] = S->t[0] ^ blake2s_IV[4];
+ v[13] = S->t[1] ^ blake2s_IV[5];
+ v[14] = S->f[0] ^ blake2s_IV[6];
+ v[15] = S->f[1] ^ blake2s_IV[7];
+#define G(r,i,a,b,c,d) \
+ do { \
+ a = a + b + m[blake2s_sigma[r][2*i+0]]; \
+ d = SPH_ROTR32(d ^ a, 16); \
+ c = c + d; \
+ b = SPH_ROTR32(b ^ c, 12); \
+ a = a + b + m[blake2s_sigma[r][2*i+1]]; \
+ d = SPH_ROTR32(d ^ a, 8); \
+ c = c + d; \
+ b = SPH_ROTR32(b ^ c, 7); \
+ } while(0)
+#define ROUND(r) \
+ do { \
+ G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
+ G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
+ G(r,2,v[ 2],v[ 6],v[10],v[14]); \
+ G(r,3,v[ 3],v[ 7],v[11],v[15]); \
+ G(r,4,v[ 0],v[ 5],v[10],v[15]); \
+ G(r,5,v[ 1],v[ 6],v[11],v[12]); \
+ G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
+ G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
+ } while(0)
+ ROUND( 0 );
+ ROUND( 1 );
+ ROUND( 2 );
+ ROUND( 3 );
+ ROUND( 4 );
+ ROUND( 5 );
+ ROUND( 6 );
+ ROUND( 7 );
+ ROUND( 8 );
+ ROUND( 9 );
+
+ for( size_t i = 0; i < 8; ++i )
+ S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
+
+#undef G
+#undef ROUND
+ return 0;
+}
+
+
+int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen )
+{
+ while( inlen > 0 )
+ {
+ size_t left = S->buflen;
+ size_t fill = 2 * BLAKE2S_BLOCKBYTES - left;
+
+ if( inlen > fill )
+ {
+ memcpy( S->buf + left, in, fill ); // Fill buffer
+ S->buflen += fill;
+ blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES );
+ blake2s_compress( S, S->buf ); // Compress
+ memcpy( S->buf, S->buf + BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES ); // Shift buffer left
+ S->buflen -= BLAKE2S_BLOCKBYTES;
+ in += fill;
+ inlen -= fill;
+ }
+ else // inlen <= fill
+ {
+ memcpy(S->buf + left, in, (size_t) inlen);
+ S->buflen += (size_t) inlen; // Be lazy, do not compress
+ in += inlen;
+ inlen -= inlen;
+ }
+ }
+
+ return 0;
+}
+
+int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen )
+{
+ uint8_t buffer[BLAKE2S_OUTBYTES];
+
+ if( S->buflen > BLAKE2S_BLOCKBYTES )
+ {
+ blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES );
+ blake2s_compress( S, S->buf );
+ S->buflen -= BLAKE2S_BLOCKBYTES;
+ memcpy( S->buf, S->buf + BLAKE2S_BLOCKBYTES, S->buflen );
+ }
+
+ blake2s_increment_counter( S, ( uint32_t )S->buflen );
+ blake2s_set_lastblock( S );
+ memset( S->buf + S->buflen, 0, 2 * BLAKE2S_BLOCKBYTES - S->buflen ); /* Padding */
+ blake2s_compress( S, S->buf );
+
+ for( int i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
+ store32( buffer + sizeof( S->h[i] ) * i, S->h[i] );
+
+ memcpy( out, buffer, outlen );
+ return 0;
+}
+
+int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen )
+{
+ blake2s_state S[1];
+
+ /* Verify parameters */
+ if ( NULL == in ) return -1;
+
+ if ( NULL == out ) return -1;
+
+ if ( NULL == key ) keylen = 0; /* Fail here instead if keylen != 0 and key == NULL? */
+
+ if( keylen > 0 )
+ {
+ if( blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1;
+ }
+ else
+ {
+ if( blake2s_init( S, outlen ) < 0 ) return -1;
+ }
+
+ blake2s_update( S, ( uint8_t * )in, inlen );
+ blake2s_final( S, out, outlen );
+ return 0;
+}
+
+#if defined(BLAKE2S_SELFTEST)
+#include <string.h>
+#include "blake2-kat.h" /* test data not included */
+int main( int argc, char **argv )
+{
+ uint8_t key[BLAKE2S_KEYBYTES];
+ uint8_t buf[KAT_LENGTH];
+
+ for( size_t i = 0; i < BLAKE2S_KEYBYTES; ++i )
+ key[i] = ( uint8_t )i;
+
+ for( size_t i = 0; i < KAT_LENGTH; ++i )
+ buf[i] = ( uint8_t )i;
+
+ for( size_t i = 0; i < KAT_LENGTH; ++i )
+ {
+ uint8_t hash[BLAKE2S_OUTBYTES];
+ blake2s( hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES );
+
+ if( 0 != memcmp( hash, blake2s_keyed_kat[i], BLAKE2S_OUTBYTES ) )
+ {
+ puts( "error" );
+ return -1;
+ }
+ }
+
+ puts( "ok" );
+ return 0;
+}
+#endif
--- /dev/null
+/**
+ * BLAKE2 reference source code package - reference C implementations
+ *
+ *
+ * To the extent possible under law, the author(s) have dedicated all copyright
+ * and related and neighboring rights to this software to the public domain
+ * worldwide. This software is distributed without any warranty.
+ *
+ * You should have received a copy of the CC0 Public Domain Dedication along with
+ * this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+ */
+#pragma once
+#ifndef __BLAKE2_H__
+#define __BLAKE2_H__
+
+#include <stddef.h>
+#include <stdint.h>
+
+#if defined(_MSC_VER)
+#include <inttypes.h>
+#define inline __inline
+#define ALIGN(x) __declspec(align(x))
+#else
+#define ALIGN(x) __attribute__((aligned(x)))
+#endif
+
+/* blake2-impl.h */
+
+static inline uint32_t load32(const void *src)
+{
+#if defined(NATIVE_LITTLE_ENDIAN)
+ return *(uint32_t *)(src);
+#else
+ const uint8_t *p = (uint8_t *)src;
+ uint32_t w = *p++;
+ w |= (uint32_t)(*p++) << 8;
+ w |= (uint32_t)(*p++) << 16;
+ w |= (uint32_t)(*p++) << 24;
+ return w;
+#endif
+}
+
+static inline void store32(void *dst, uint32_t w)
+{
+#if defined(NATIVE_LITTLE_ENDIAN)
+ *(uint32_t *)(dst) = w;
+#else
+ uint8_t *p = (uint8_t *)dst;
+ *p++ = (uint8_t)w; w >>= 8;
+ *p++ = (uint8_t)w; w >>= 8;
+ *p++ = (uint8_t)w; w >>= 8;
+ *p++ = (uint8_t)w;
+#endif
+}
+
+static inline uint64_t load48(const void *src)
+{
+ const uint8_t *p = (const uint8_t *)src;
+ uint64_t w = *p++;
+ w |= (uint64_t)(*p++) << 8;
+ w |= (uint64_t)(*p++) << 16;
+ w |= (uint64_t)(*p++) << 24;
+ w |= (uint64_t)(*p++) << 32;
+ w |= (uint64_t)(*p++) << 40;
+ return w;
+}
+
+static inline void store48(void *dst, uint64_t w)
+{
+ uint8_t *p = (uint8_t *)dst;
+ *p++ = (uint8_t)w; w >>= 8;
+ *p++ = (uint8_t)w; w >>= 8;
+ *p++ = (uint8_t)w; w >>= 8;
+ *p++ = (uint8_t)w; w >>= 8;
+ *p++ = (uint8_t)w; w >>= 8;
+ *p++ = (uint8_t)w;
+}
+
+/* prevents compiler optimizing out memset() */
+static inline void secure_zero_memory(void *v, size_t n)
+{
+ volatile uint8_t *p = ( volatile uint8_t * )v;
+
+ while( n-- ) *p++ = 0;
+}
+
+/* blake2.h */
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+ enum blake2s_constant
+ {
+ BLAKE2S_BLOCKBYTES = 64,
+ BLAKE2S_OUTBYTES = 32,
+ BLAKE2S_KEYBYTES = 32,
+ BLAKE2S_SALTBYTES = 8,
+ BLAKE2S_PERSONALBYTES = 8
+ };
+
+#pragma pack(push, 1)
+ typedef struct __blake2s_param
+ {
+ uint8_t digest_length; // 1
+ uint8_t key_length; // 2
+ uint8_t fanout; // 3
+ uint8_t depth; // 4
+ uint32_t leaf_length; // 8
+ uint8_t node_offset[6];// 14
+ uint8_t node_depth; // 15
+ uint8_t inner_length; // 16
+ // uint8_t reserved[0];
+ uint8_t salt[BLAKE2S_SALTBYTES]; // 24
+ uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32
+ } blake2s_param;
+
+ ALIGN( 64 ) typedef struct __blake2s_state
+ {
+ uint32_t h[8];
+ uint32_t t[2];
+ uint32_t f[2];
+ uint8_t buf[2 * BLAKE2S_BLOCKBYTES];
+ size_t buflen;
+ uint8_t last_node;
+ } blake2s_state ;
+#pragma pack(pop)
+
+ int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] );
+
+ // Streaming API
+ int blake2s_init( blake2s_state *S, const uint8_t outlen );
+ int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
+ int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
+ int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen );
+ int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen );
+
+ // Simple API
+ int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
+
+ // Direct Hash Mining Helpers
+ #define blake2s_salt32(out, in, inlen, key32) blake2s(out, in, key32, 32, inlen, 32) /* neoscrypt */
+ #define blake2s_simple(out, in, inlen) blake2s(out, in, NULL, 32, inlen, 0)
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
#include "int-util.h"
+#if 0
static inline void *padd(void *p, size_t i) {
return (char *) p + i;
}
static inline void place_length(uint8_t *buffer, size_t bufsize, size_t length) {
if (sizeof(size_t) == 4) {
- *(uint32_t *) padd(buffer, bufsize - 4) = swap32be(length);
+ *(uint32_t*) padd(buffer, bufsize - 4) = swap32be(length);
} else {
- *(uint64_t *) padd(buffer, bufsize - 8) = swap64be(length);
+ *(uint64_t*) padd(buffer, bufsize - 8) = swap64be(length);
}
}
+#endif
#pragma pack(push, 1)
union hash_state {
extern int scanhash_fresh(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done);
+extern int scanhash_nist5(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
+ uint32_t max_nonce, uint64_t *hashes_done);
+
+extern int scanhash_qubit(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
+ uint32_t max_nonce, uint64_t *hashes_done);
+
extern int scanhash_s3(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done);
void print_hash_tests(void);
void sha256d(unsigned char *hash, const unsigned char *data, int len);
void blakehash(void *state, const void *input);
+void cryptonight_hash(void* output, const void* input, size_t len);
void heavyhash(unsigned char* output, const unsigned char* input, int len);
void quarkhash(void *state, const void *input);
void skeinhash(void *state, const void *input);
void keccakhash(void *state, const void *input);
void inkhash(void *state, const void *input); /* shavite */
void neoscrypt(unsigned char *output, const unsigned char *password, uint32_t profile);
+void nist5hash(void *output, const void *input);
+void pentablakehash(void *output, const void *input);
+void qubithash(void *output, const void *input);
void s3hash(void *output, const void *input);
void x11hash(void *output, const void *input);
void x13hash(void *output, const void *input);
void x14hash(void *output, const void *input);
void x15hash(void *output, const void *input);
-void pentablakehash(void *output, const void *input);
-void cryptonight_hash(void* output, const void* input, size_t len);
#endif /* __MINER_H__ */
#define USE_CUSTOM_BLAKE2S
// TODO: try blake2sp
-//#include "sha3/blake2s.h"
+//#include "crypto/blake2s.h"
#define STACK_ALIGN 0x40
--- /dev/null
+#include "miner.h"
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "sha3/sph_blake.h"
+#include "sha3/sph_groestl.h"
+#include "sha3/sph_skein.h"
+#include "sha3/sph_jh.h"
+#include "sha3/sph_keccak.h"
+
+void nist5hash(void *output, const void *input)
+{
+ sph_blake512_context ctx_blake;
+ sph_groestl512_context ctx_groestl;
+ sph_jh512_context ctx_jh;
+ sph_keccak512_context ctx_keccak;
+ sph_skein512_context ctx_skein;
+
+ uint8_t hash[64];
+
+ sph_blake512_init(&ctx_blake);
+ sph_blake512(&ctx_blake, input, 80);
+ sph_blake512_close(&ctx_blake, (void*) hash);
+
+ sph_groestl512_init(&ctx_groestl);
+ sph_groestl512(&ctx_groestl, (const void*) hash, 64);
+ sph_groestl512_close(&ctx_groestl, (void*) hash);
+
+ sph_jh512_init(&ctx_jh);
+ sph_jh512(&ctx_jh, (const void*) hash, 64);
+ sph_jh512_close(&ctx_jh, (void*) hash);
+
+ sph_keccak512_init(&ctx_keccak);
+ sph_keccak512(&ctx_keccak, (const void*) hash, 64);
+ sph_keccak512_close(&ctx_keccak, (void*) hash);
+
+ sph_skein512_init(&ctx_skein);
+ sph_skein512(&ctx_skein, (const void*) hash, 64);
+ sph_skein512_close(&ctx_skein, (void*) hash);
+
+ memcpy(output, hash, 32);
+}
+
+int scanhash_nist5(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
+ uint32_t max_nonce, uint64_t *hashes_done)
+{
+ uint32_t n = pdata[19] - 1;
+ const uint32_t first_nonce = pdata[19];
+ const uint32_t Htarg = ptarget[7];
+
+ uint32_t _ALIGN(32) hash64[8];
+ uint32_t endiandata[32];
+
+
+ uint64_t htmax[] = {
+ 0,
+ 0xF,
+ 0xFF,
+ 0xFFF,
+ 0xFFFF,
+ 0x10000000
+ };
+ uint32_t masks[] = {
+ 0xFFFFFFFF,
+ 0xFFFFFFF0,
+ 0xFFFFFF00,
+ 0xFFFFF000,
+ 0xFFFF0000,
+ 0
+ };
+
+ // we need bigendian data...
+ for (int kk=0; kk < 32; kk++) {
+ be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
+ };
+#ifdef DEBUG_ALGO
+ printf("[%d] Htarg=%X\n", thr_id, Htarg);
+#endif
+ for (int m=0; m < 6; m++) {
+ if (Htarg <= htmax[m]) {
+ uint32_t mask = masks[m];
+ do {
+ pdata[19] = ++n;
+ be32enc(&endiandata[19], n);
+ nist5hash(hash64, endiandata);
+#ifndef DEBUG_ALGO
+ if ((!(hash64[7] & mask)) && fulltest(hash64, ptarget)) {
+ *hashes_done = n - first_nonce + 1;
+ return true;
+ }
+#else
+ if (!(n % 0x1000) && !thr_id) printf(".");
+ if (!(hash64[7] & mask)) {
+ printf("[%d]",thr_id);
+ if (fulltest(hash64, ptarget)) {
+ *hashes_done = n - first_nonce + 1;
+ return true;
+ }
+ }
+#endif
+ } while (n < max_nonce && !work_restart[thr_id].restart);
+ // see blake.c if else to understand the loop on htmax => mask
+ break;
+ }
+ }
+
+ *hashes_done = n - first_nonce + 1;
+ pdata[19] = n;
+ return 0;
+}
--- /dev/null
+#include "miner.h"
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "sha3/sph_luffa.h"
+#include "sha3/sph_cubehash.h"
+#include "sha3/sph_shavite.h"
+#include "sha3/sph_simd.h"
+#include "sha3/sph_echo.h"
+
+void qubithash(void *output, const void *input)
+{
+ sph_luffa512_context ctx_luffa;
+ sph_cubehash512_context ctx_cubehash;
+ sph_shavite512_context ctx_shavite;
+ sph_simd512_context ctx_simd;
+ sph_echo512_context ctx_echo;
+
+ uint8_t hash[64];
+
+ sph_luffa512_init(&ctx_luffa);
+ sph_luffa512 (&ctx_luffa, input, 80);
+ sph_luffa512_close(&ctx_luffa, (void*) hash);
+
+ sph_cubehash512_init(&ctx_cubehash);
+ sph_cubehash512 (&ctx_cubehash, (const void*) hash, 64);
+ sph_cubehash512_close(&ctx_cubehash, (void*) hash);
+
+ sph_shavite512_init(&ctx_shavite);
+ sph_shavite512 (&ctx_shavite, (const void*) hash, 64);
+ sph_shavite512_close(&ctx_shavite, (void*) hash);
+
+ sph_simd512_init(&ctx_simd);
+ sph_simd512 (&ctx_simd, (const void*) hash, 64);
+ sph_simd512_close(&ctx_simd, (void*) hash);
+
+ sph_echo512_init(&ctx_echo);
+ sph_echo512 (&ctx_echo, (const void*) hash, 64);
+ sph_echo512_close(&ctx_echo, (void*) hash);
+
+ memcpy(output, hash, 32);
+}
+
+int scanhash_qubit(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
+ uint32_t max_nonce, uint64_t *hashes_done)
+{
+ uint32_t n = pdata[19] - 1;
+ const uint32_t first_nonce = pdata[19];
+ const uint32_t Htarg = ptarget[7];
+
+ uint32_t _ALIGN(32) hash64[8];
+ uint32_t endiandata[32];
+
+
+ uint64_t htmax[] = {
+ 0,
+ 0xF,
+ 0xFF,
+ 0xFFF,
+ 0xFFFF,
+ 0x10000000
+ };
+ uint32_t masks[] = {
+ 0xFFFFFFFF,
+ 0xFFFFFFF0,
+ 0xFFFFFF00,
+ 0xFFFFF000,
+ 0xFFFF0000,
+ 0
+ };
+
+ // we need bigendian data...
+ for (int kk=0; kk < 32; kk++) {
+ be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
+ };
+#ifdef DEBUG_ALGO
+ printf("[%d] Htarg=%X\n", thr_id, Htarg);
+#endif
+ for (int m=0; m < 6; m++) {
+ if (Htarg <= htmax[m]) {
+ uint32_t mask = masks[m];
+ do {
+ pdata[19] = ++n;
+ be32enc(&endiandata[19], n);
+ qubithash(hash64, endiandata);
+#ifndef DEBUG_ALGO
+ if ((!(hash64[7] & mask)) && fulltest(hash64, ptarget)) {
+ *hashes_done = n - first_nonce + 1;
+ return true;
+ }
+#else
+ if (!(n % 0x1000) && !thr_id) printf(".");
+ if (!(hash64[7] & mask)) {
+ printf("[%d]",thr_id);
+ if (fulltest(hash64, ptarget)) {
+ *hashes_done = n - first_nonce + 1;
+ return true;
+ }
+ }
+#endif
+ } while (n < max_nonce && !work_restart[thr_id].restart);
+ // see blake.c if else to understand the loop on htmax => mask
+ break;
+ }
+ }
+
+ *hashes_done = n - first_nonce + 1;
+ pdata[19] = n;
+ return 0;
+}
+++ /dev/null
-/**
- * BLAKE2 reference source code package - reference C implementations
- *
- *
- * To the extent possible under law, the author(s) have dedicated all copyright
- * and related and neighboring rights to this software to the public domain
- * worldwide. This software is distributed without any warranty.
- *
- * You should have received a copy of the CC0 Public Domain Dedication along with
- * this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
- */
-
-#include <stdint.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "sha3/sph_types.h"
-#include "sha3/blake2s.h"
-
-static const uint32_t blake2s_IV[8] =
-{
- 0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL,
- 0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL
-};
-
-static const uint8_t blake2s_sigma[10][16] =
-{
- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
- { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
- { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
- { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
- { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
- { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
- { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
- { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
- { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
- { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
-};
-
-static inline int blake2s_set_lastnode( blake2s_state *S )
-{
- S->f[1] = ~0U;
- return 0;
-}
-
-static inline int blake2s_clear_lastnode( blake2s_state *S )
-{
- S->f[1] = 0U;
- return 0;
-}
-
-/* Some helper functions, not necessarily useful */
-static inline int blake2s_set_lastblock( blake2s_state *S )
-{
- if( S->last_node ) blake2s_set_lastnode( S );
-
- S->f[0] = ~0U;
- return 0;
-}
-
-static inline int blake2s_clear_lastblock( blake2s_state *S )
-{
- if( S->last_node ) blake2s_clear_lastnode( S );
-
- S->f[0] = 0U;
- return 0;
-}
-
-static inline int blake2s_increment_counter( blake2s_state *S, const uint32_t inc )
-{
- S->t[0] += inc;
- S->t[1] += ( S->t[0] < inc );
- return 0;
-}
-
-// Parameter-related functions
-static inline int blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length )
-{
- P->digest_length = digest_length;
- return 0;
-}
-
-static inline int blake2s_param_set_fanout( blake2s_param *P, const uint8_t fanout )
-{
- P->fanout = fanout;
- return 0;
-}
-
-static inline int blake2s_param_set_max_depth( blake2s_param *P, const uint8_t depth )
-{
- P->depth = depth;
- return 0;
-}
-
-static inline int blake2s_param_set_leaf_length( blake2s_param *P, const uint32_t leaf_length )
-{
- store32( &P->leaf_length, leaf_length );
- return 0;
-}
-
-static inline int blake2s_param_set_node_offset( blake2s_param *P, const uint64_t node_offset )
-{
- store48( P->node_offset, node_offset );
- return 0;
-}
-
-static inline int blake2s_param_set_node_depth( blake2s_param *P, const uint8_t node_depth )
-{
- P->node_depth = node_depth;
- return 0;
-}
-
-static inline int blake2s_param_set_inner_length( blake2s_param *P, const uint8_t inner_length )
-{
- P->inner_length = inner_length;
- return 0;
-}
-
-static inline int blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] )
-{
- memcpy( P->salt, salt, BLAKE2S_SALTBYTES );
- return 0;
-}
-
-static inline int blake2s_param_set_personal( blake2s_param *P, const uint8_t personal[BLAKE2S_PERSONALBYTES] )
-{
- memcpy( P->personal, personal, BLAKE2S_PERSONALBYTES );
- return 0;
-}
-
-static inline int blake2s_init0( blake2s_state *S )
-{
- memset( S, 0, sizeof( blake2s_state ) );
-
- for( int i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i];
-
- return 0;
-}
-
-/* init2 xors IV with input parameter block */
-int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
-{
- blake2s_init0( S );
- uint32_t *p = ( uint32_t * )( P );
-
- /* IV XOR ParamBlock */
- for( size_t i = 0; i < 8; ++i )
- S->h[i] ^= load32( &p[i] );
-
- return 0;
-}
-
-
-// Sequential blake2s initialization
-int blake2s_init( blake2s_state *S, const uint8_t outlen )
-{
- blake2s_param P[1];
-
- /* Move interval verification here? */
- if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1;
-
- P->digest_length = outlen;
- P->key_length = 0;
- P->fanout = 1;
- P->depth = 1;
- store32( &P->leaf_length, 0 );
- store48( &P->node_offset, 0 );
- P->node_depth = 0;
- P->inner_length = 0;
- // memset(P->reserved, 0, sizeof(P->reserved) );
- memset( P->salt, 0, sizeof( P->salt ) );
- memset( P->personal, 0, sizeof( P->personal ) );
- return blake2s_init_param( S, P );
-}
-
-int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen )
-{
- blake2s_param P[1];
-
- if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return -1;
-
- if ( !key || !keylen || keylen > BLAKE2S_KEYBYTES ) return -1;
-
- P->digest_length = outlen;
- P->key_length = keylen;
- P->fanout = 1;
- P->depth = 1;
- store32( &P->leaf_length, 0 );
- store48( &P->node_offset, 0 );
- P->node_depth = 0;
- P->inner_length = 0;
- // memset(P->reserved, 0, sizeof(P->reserved) );
- memset( P->salt, 0, sizeof( P->salt ) );
- memset( P->personal, 0, sizeof( P->personal ) );
-
- if( blake2s_init_param( S, P ) < 0 ) return -1;
-
- {
- uint8_t block[BLAKE2S_BLOCKBYTES];
- memset( block, 0, BLAKE2S_BLOCKBYTES );
- memcpy( block, key, keylen );
- blake2s_update( S, block, BLAKE2S_BLOCKBYTES );
- secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */
- }
- return 0;
-}
-
-int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] )
-{
- uint32_t m[16];
- uint32_t v[16];
-
- for( size_t i = 0; i < 16; ++i )
- m[i] = load32( block + i * sizeof( m[i] ) );
-
- for( size_t i = 0; i < 8; ++i )
- v[i] = S->h[i];
-
- v[ 8] = blake2s_IV[0];
- v[ 9] = blake2s_IV[1];
- v[10] = blake2s_IV[2];
- v[11] = blake2s_IV[3];
- v[12] = S->t[0] ^ blake2s_IV[4];
- v[13] = S->t[1] ^ blake2s_IV[5];
- v[14] = S->f[0] ^ blake2s_IV[6];
- v[15] = S->f[1] ^ blake2s_IV[7];
-#define G(r,i,a,b,c,d) \
- do { \
- a = a + b + m[blake2s_sigma[r][2*i+0]]; \
- d = SPH_ROTR32(d ^ a, 16); \
- c = c + d; \
- b = SPH_ROTR32(b ^ c, 12); \
- a = a + b + m[blake2s_sigma[r][2*i+1]]; \
- d = SPH_ROTR32(d ^ a, 8); \
- c = c + d; \
- b = SPH_ROTR32(b ^ c, 7); \
- } while(0)
-#define ROUND(r) \
- do { \
- G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
- G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
- G(r,2,v[ 2],v[ 6],v[10],v[14]); \
- G(r,3,v[ 3],v[ 7],v[11],v[15]); \
- G(r,4,v[ 0],v[ 5],v[10],v[15]); \
- G(r,5,v[ 1],v[ 6],v[11],v[12]); \
- G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
- G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
- } while(0)
- ROUND( 0 );
- ROUND( 1 );
- ROUND( 2 );
- ROUND( 3 );
- ROUND( 4 );
- ROUND( 5 );
- ROUND( 6 );
- ROUND( 7 );
- ROUND( 8 );
- ROUND( 9 );
-
- for( size_t i = 0; i < 8; ++i )
- S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
-
-#undef G
-#undef ROUND
- return 0;
-}
-
-
-int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen )
-{
- while( inlen > 0 )
- {
- size_t left = S->buflen;
- size_t fill = 2 * BLAKE2S_BLOCKBYTES - left;
-
- if( inlen > fill )
- {
- memcpy( S->buf + left, in, fill ); // Fill buffer
- S->buflen += fill;
- blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES );
- blake2s_compress( S, S->buf ); // Compress
- memcpy( S->buf, S->buf + BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES ); // Shift buffer left
- S->buflen -= BLAKE2S_BLOCKBYTES;
- in += fill;
- inlen -= fill;
- }
- else // inlen <= fill
- {
- memcpy(S->buf + left, in, (size_t) inlen);
- S->buflen += (size_t) inlen; // Be lazy, do not compress
- in += inlen;
- inlen -= inlen;
- }
- }
-
- return 0;
-}
-
-int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen )
-{
- uint8_t buffer[BLAKE2S_OUTBYTES];
-
- if( S->buflen > BLAKE2S_BLOCKBYTES )
- {
- blake2s_increment_counter( S, BLAKE2S_BLOCKBYTES );
- blake2s_compress( S, S->buf );
- S->buflen -= BLAKE2S_BLOCKBYTES;
- memcpy( S->buf, S->buf + BLAKE2S_BLOCKBYTES, S->buflen );
- }
-
- blake2s_increment_counter( S, ( uint32_t )S->buflen );
- blake2s_set_lastblock( S );
- memset( S->buf + S->buflen, 0, 2 * BLAKE2S_BLOCKBYTES - S->buflen ); /* Padding */
- blake2s_compress( S, S->buf );
-
- for( int i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
- store32( buffer + sizeof( S->h[i] ) * i, S->h[i] );
-
- memcpy( out, buffer, outlen );
- return 0;
-}
-
-int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen )
-{
- blake2s_state S[1];
-
- /* Verify parameters */
- if ( NULL == in ) return -1;
-
- if ( NULL == out ) return -1;
-
- if ( NULL == key ) keylen = 0; /* Fail here instead if keylen != 0 and key == NULL? */
-
- if( keylen > 0 )
- {
- if( blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1;
- }
- else
- {
- if( blake2s_init( S, outlen ) < 0 ) return -1;
- }
-
- blake2s_update( S, ( uint8_t * )in, inlen );
- blake2s_final( S, out, outlen );
- return 0;
-}
-
-#if defined(BLAKE2S_SELFTEST)
-#include <string.h>
-#include "blake2-kat.h" /* test data not included */
-int main( int argc, char **argv )
-{
- uint8_t key[BLAKE2S_KEYBYTES];
- uint8_t buf[KAT_LENGTH];
-
- for( size_t i = 0; i < BLAKE2S_KEYBYTES; ++i )
- key[i] = ( uint8_t )i;
-
- for( size_t i = 0; i < KAT_LENGTH; ++i )
- buf[i] = ( uint8_t )i;
-
- for( size_t i = 0; i < KAT_LENGTH; ++i )
- {
- uint8_t hash[BLAKE2S_OUTBYTES];
- blake2s( hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES );
-
- if( 0 != memcmp( hash, blake2s_keyed_kat[i], BLAKE2S_OUTBYTES ) )
- {
- puts( "error" );
- return -1;
- }
- }
-
- puts( "ok" );
- return 0;
-}
-#endif
+++ /dev/null
-/**
- * BLAKE2 reference source code package - reference C implementations
- *
- *
- * To the extent possible under law, the author(s) have dedicated all copyright
- * and related and neighboring rights to this software to the public domain
- * worldwide. This software is distributed without any warranty.
- *
- * You should have received a copy of the CC0 Public Domain Dedication along with
- * this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
- */
-#pragma once
-#ifndef __BLAKE2_H__
-#define __BLAKE2_H__
-
-#include <stddef.h>
-#include <stdint.h>
-
-#if defined(_MSC_VER)
-#include <inttypes.h>
-#define inline __inline
-#define ALIGN(x) __declspec(align(x))
-#else
-#define ALIGN(x) __attribute__((aligned(x)))
-#endif
-
-/* blake2-impl.h */
-
-static inline uint32_t load32(const void *src)
-{
-#if defined(NATIVE_LITTLE_ENDIAN)
- return *(uint32_t *)(src);
-#else
- const uint8_t *p = (uint8_t *)src;
- uint32_t w = *p++;
- w |= (uint32_t)(*p++) << 8;
- w |= (uint32_t)(*p++) << 16;
- w |= (uint32_t)(*p++) << 24;
- return w;
-#endif
-}
-
-static inline void store32(void *dst, uint32_t w)
-{
-#if defined(NATIVE_LITTLE_ENDIAN)
- *(uint32_t *)(dst) = w;
-#else
- uint8_t *p = (uint8_t *)dst;
- *p++ = (uint8_t)w; w >>= 8;
- *p++ = (uint8_t)w; w >>= 8;
- *p++ = (uint8_t)w; w >>= 8;
- *p++ = (uint8_t)w;
-#endif
-}
-
-static inline uint64_t load48(const void *src)
-{
- const uint8_t *p = (const uint8_t *)src;
- uint64_t w = *p++;
- w |= (uint64_t)(*p++) << 8;
- w |= (uint64_t)(*p++) << 16;
- w |= (uint64_t)(*p++) << 24;
- w |= (uint64_t)(*p++) << 32;
- w |= (uint64_t)(*p++) << 40;
- return w;
-}
-
-static inline void store48(void *dst, uint64_t w)
-{
- uint8_t *p = (uint8_t *)dst;
- *p++ = (uint8_t)w; w >>= 8;
- *p++ = (uint8_t)w; w >>= 8;
- *p++ = (uint8_t)w; w >>= 8;
- *p++ = (uint8_t)w; w >>= 8;
- *p++ = (uint8_t)w; w >>= 8;
- *p++ = (uint8_t)w;
-}
-
-/* prevents compiler optimizing out memset() */
-static inline void secure_zero_memory(void *v, size_t n)
-{
- volatile uint8_t *p = ( volatile uint8_t * )v;
-
- while( n-- ) *p++ = 0;
-}
-
-/* blake2.h */
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
- enum blake2s_constant
- {
- BLAKE2S_BLOCKBYTES = 64,
- BLAKE2S_OUTBYTES = 32,
- BLAKE2S_KEYBYTES = 32,
- BLAKE2S_SALTBYTES = 8,
- BLAKE2S_PERSONALBYTES = 8
- };
-
-#pragma pack(push, 1)
- typedef struct __blake2s_param
- {
- uint8_t digest_length; // 1
- uint8_t key_length; // 2
- uint8_t fanout; // 3
- uint8_t depth; // 4
- uint32_t leaf_length; // 8
- uint8_t node_offset[6];// 14
- uint8_t node_depth; // 15
- uint8_t inner_length; // 16
- // uint8_t reserved[0];
- uint8_t salt[BLAKE2S_SALTBYTES]; // 24
- uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32
- } blake2s_param;
-
- ALIGN( 64 ) typedef struct __blake2s_state
- {
- uint32_t h[8];
- uint32_t t[2];
- uint32_t f[2];
- uint8_t buf[2 * BLAKE2S_BLOCKBYTES];
- size_t buflen;
- uint8_t last_node;
- } blake2s_state ;
-#pragma pack(pop)
-
- int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] );
-
- // Streaming API
- int blake2s_init( blake2s_state *S, const uint8_t outlen );
- int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
- int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
- int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen );
- int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen );
-
- // Simple API
- int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
-
- // Direct Hash Mining Helpers
- #define blake2s_salt32(out, in, inlen, key32) blake2s(out, in, key32, 32, inlen, 32) /* neoscrypt */
- #define blake2s_simple(out, in, inlen) blake2s(out, in, NULL, 32, inlen, 0)
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif
static int sockopt_keepalive_cb(void *userdata, curl_socket_t fd,
curlsocktype purpose)
{
- int keepalive = 1;
+#ifdef __linux
int tcp_keepcnt = 3;
- int tcp_keepidle = 50;
+#endif
int tcp_keepintvl = 50;
-
+ int tcp_keepidle = 50;
#ifndef WIN32
+ int keepalive = 1;
if (unlikely(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keepalive,
sizeof(keepalive))))
return 1;
sha256d((uint8_t*) &hash[0], (uint8_t*)&buf[0], 64);
printpfx("SHA 256D", hash);
+ memset(hash, 0, sizeof hash);
+ blakehash(&hash[0], &buf[0]);
+ printpfx("Blake", hash);
+
+ memset(hash, 0, sizeof hash);
+ freshhash(&hash[0], &buf[0], 80);
+ printpfx("Fresh", hash);
+
memset(hash, 0, sizeof hash);
heavyhash((uint8_t*) &hash[0], (uint8_t*) &buf[0], 32);
printpfx("Heavy", hash);
printpfx("Neoscrypt", hash);
memset(hash, 0, sizeof hash);
- quarkhash(&hash[0], &buf[0]);
- printpfx("Quark", hash);
+ nist5hash(&hash[0], &buf[0]);
+ printpfx("Nist5", hash);
memset(hash, 0, sizeof hash);
- skeinhash(&hash[0], &buf[0]);
- printpfx("Skein", hash);
+ pentablakehash(&hash[0], &buf[0]);
+ printpfx("Pentablake", hash);
memset(hash, 0, sizeof hash);
- blakehash(&hash[0], &buf[0]);
- printpfx("Blake", hash);
+ quarkhash(&hash[0], &buf[0]);
+ printpfx("Quark", hash);
memset(hash, 0, sizeof hash);
- pentablakehash(&hash[0], &buf[0]);
- printpfx("Pentablake", hash);
+ qubithash(&hash[0], &buf[0]);
+ printpfx("Qubit", hash);
memset(hash, 0, sizeof hash);
inkhash(&hash[0], &buf[0]);
printpfx("Shavite", hash);
memset(hash, 0, sizeof hash);
- freshhash(&hash[0], &buf[0], 80);
- printpfx("Fresh", hash);
+ skeinhash(&hash[0], &buf[0]);
+ printpfx("Skein", hash);
memset(hash, 0, sizeof hash);
s3hash(&hash[0], &buf[0]);