From 710c852f05d220601be311bbc4c97daba592e066 Mon Sep 17 00:00:00 2001 From: Jay D Dee Date: Mon, 9 Oct 2017 21:45:27 -0400 Subject: [PATCH] v3.6.9 --- Makefile.am | 3 + RELEASE_NOTES | 20 +++- algo-gate-api.c | 4 + algo/sm3/sm3.c | 226 ++++++++++++++++++++++++++++++++++++++++ algo/sm3/sph_sm3.h | 120 +++++++++++++++++++++ algo/x11/phi1612.c | 140 +++++++++++++++++++++++++ algo/x13/x13sm3.c | 253 +++++++++++++++++++++++++++++++++++++++++++++ configure | 20 ++-- configure.ac | 2 +- miner.h | 8 +- 10 files changed, 783 insertions(+), 13 deletions(-) create mode 100644 algo/sm3/sm3.c create mode 100644 algo/sm3/sph_sm3.h create mode 100644 algo/x11/phi1612.c create mode 100644 algo/x13/x13sm3.c diff --git a/Makefile.am b/Makefile.am index a15a980..b1ef4f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,6 +44,7 @@ cpuminer_SOURCES = \ algo/sha/sph_sha2.c \ algo/sha/sph_sha2big.c \ algo/shabal/sph_shabal.c \ + algo/sm3/sm3.c \ algo/whirlpool/sph_whirlpool.c\ crypto/blake2s.c \ crypto/oaes_lib.c \ @@ -125,11 +126,13 @@ cpuminer_SOURCES = \ algo/veltor.c \ algo/whirlpool/whirlpool.c \ algo/whirlpool/whirlpoolx.c \ + algo/x11/phi1612.c \ algo/x11/x11.c \ algo/x11/x11evo.c \ algo/x11/x11gost.c \ algo/x11/c11.c \ algo/x13/x13.c \ + algo/x13/x13sm3.c \ algo/x14/x14.c \ algo/x15/x15.c \ algo/x17/x17.c \ diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 87ad6af..b8ca2c5 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -9,6 +9,19 @@ are not yet available. cpuminer-opt is a console program, if you're using a mouse you're doing it wrong. +Security warning +---------------- + +Miner programs are often flagged as malware by antivirus programs. This is +a false positive, they are flagged simply because they are miners. The source +code is open for anyone to inspect. If you don't trust the software, don't use +it. + +The cryptographic code has been taken from trusted sources but has been +modified for speed at the expense of accepted security practices. This +code should not be imported into applications where secure cryptography is +required. + Compile Instructions -------------------- @@ -126,9 +139,14 @@ Support for even older x86_64 without AES_NI or SSE2 is not availble. Change Log ---------- +v3.6.9 + +Added phi1612 algo for LUX coin +Added x13sm3 algo, alias hsr, for Hshare coin + v3.6.8 -Fixes timetravel10 on Windows. +Fixed timetravel10 on Windows. v3.6.7 diff --git a/algo-gate-api.c b/algo-gate-api.c index 92ee549..486c023 100644 --- a/algo-gate-api.c +++ b/algo-gate-api.c @@ -182,6 +182,7 @@ bool register_algo_gate( int algo, algo_gate_t *gate ) case ALGO_NEOSCRYPT: register_neoscrypt_algo ( gate ); break; case ALGO_NIST5: register_nist5_algo ( gate ); break; case ALGO_PENTABLAKE: register_pentablake_algo ( gate ); break; + case ALGO_PHI1612: register_phi1612_algo ( gate ); break; case ALGO_PLUCK: register_pluck_algo ( gate ); break; case ALGO_QUARK: register_quark_algo ( gate ); break; case ALGO_QUBIT: register_qubit_algo ( gate ); break; @@ -204,6 +205,7 @@ bool register_algo_gate( int algo, algo_gate_t *gate ) case ALGO_X11EVO: register_x11evo_algo ( gate ); break; case ALGO_X11GOST: register_sib_algo ( gate ); break; case ALGO_X13: register_x13_algo ( gate ); break; + case ALGO_X13SM3: register_x13sm3_algo ( gate ); break; case ALGO_X14: register_x14_algo ( gate ); break; case ALGO_X15: register_x15_algo ( gate ); break; case ALGO_X17: register_x17_algo ( gate ); break; @@ -278,6 +280,7 @@ const char* const algo_alias_map[][2] = { "droplp", "drop" }, { "espers", "hmq1725" }, { "flax", "c11" }, + { "hsr", "x13sm3" }, { "jackpot", "jha" }, { "jane", "scryptjane" }, { "lyra2", "lyra2re" }, @@ -285,6 +288,7 @@ const char* const algo_alias_map[][2] = { "lyra2zoin", "lyra2z330" }, { "myriad", "myr-gr" }, { "neo", "neoscrypt" }, + { "phi", "phi1612" }, // { "sia", "blake2b" }, { "sib", "x11gost" }, { "timetravel8", "timetravel" }, diff --git a/algo/sm3/sm3.c b/algo/sm3/sm3.c new file mode 100644 index 0000000..e5c5805 --- /dev/null +++ b/algo/sm3/sm3.c @@ -0,0 +1,226 @@ +/* ==================================================================== + * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the GmSSL Project. + * (http://gmssl.org/)" + * + * 4. The name "GmSSL Project" must not be used to endorse or promote + * products derived from this software without prior written + * permission. For written permission, please contact + * guanzhi1980@gmail.com. + * + * 5. Products derived from this software may not be called "GmSSL" + * nor may "GmSSL" appear in their names without prior written + * permission of the GmSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the GmSSL Project + * (http://gmssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ + +#include +#include "sph_sm3.h" + +void sm3_init(sm3_ctx_t *ctx) +{ + ctx->digest[0] = 0x7380166F; + ctx->digest[1] = 0x4914B2B9; + ctx->digest[2] = 0x172442D7; + ctx->digest[3] = 0xDA8A0600; + ctx->digest[4] = 0xA96F30BC; + ctx->digest[5] = 0x163138AA; + ctx->digest[6] = 0xE38DEE4D; + ctx->digest[7] = 0xB0FB0E4E; + + ctx->nblocks = 0; + ctx->num = 0; +} + +void +sph_sm3(void *cc, const void *data, size_t len) +{ + sm3_update(cc, data, len); +} + +void sm3_update(sm3_ctx_t *ctx, const unsigned char* data, size_t data_len) +{ + if (ctx->num) { + unsigned int left = SM3_BLOCK_SIZE - ctx->num; + if (data_len < left) { + memcpy(ctx->block + ctx->num, data, data_len); + ctx->num += data_len; + return; + } else { + memcpy(ctx->block + ctx->num, data, left); + sm3_compress(ctx->digest, ctx->block); + ctx->nblocks++; + data += left; + data_len -= left; + } + } + while (data_len >= SM3_BLOCK_SIZE) { + sm3_compress(ctx->digest, data); + ctx->nblocks++; + data += SM3_BLOCK_SIZE; + data_len -= SM3_BLOCK_SIZE; + } + ctx->num = data_len; + if (data_len) { + memcpy(ctx->block, data, data_len); + } +} + +void +sph_sm3_close(void *cc, void *dst) +{ + sm3_final(cc, dst); + memset(cc, 0, sizeof(sm3_ctx_t)); +} + +void sm3_final(sm3_ctx_t *ctx, unsigned char *digest) +{ + int i; + uint32_t *pdigest = (uint32_t *)digest; + uint32_t *count = (uint32_t *)(ctx->block + SM3_BLOCK_SIZE - 8); + + ctx->block[ctx->num] = 0x80; + + if (ctx->num + 9 <= SM3_BLOCK_SIZE) { + memset(ctx->block + ctx->num + 1, 0, SM3_BLOCK_SIZE - ctx->num - 9); + } else { + memset(ctx->block + ctx->num + 1, 0, SM3_BLOCK_SIZE - ctx->num - 1); + sm3_compress(ctx->digest, ctx->block); + memset(ctx->block, 0, SM3_BLOCK_SIZE - 8); + } + + count[0] = cpu_to_be32((ctx->nblocks) >> 23); + count[1] = cpu_to_be32((ctx->nblocks << 9) + (ctx->num << 3)); + + sm3_compress(ctx->digest, ctx->block); + for (i = 0; i < sizeof(ctx->digest)/sizeof(ctx->digest[0]); i++) { + pdigest[i] = cpu_to_be32(ctx->digest[i]); + } +} + +#define ROTATELEFT(X,n) (((X)<<(n)) | ((X)>>(32-(n)))) + +#define P0(x) ((x) ^ ROTATELEFT((x),9) ^ ROTATELEFT((x),17)) +#define P1(x) ((x) ^ ROTATELEFT((x),15) ^ ROTATELEFT((x),23)) + +#define FF0(x,y,z) ( (x) ^ (y) ^ (z)) +#define FF1(x,y,z) (((x) & (y)) | ( (x) & (z)) | ( (y) & (z))) + +#define GG0(x,y,z) ( (x) ^ (y) ^ (z)) +#define GG1(x,y,z) (((x) & (y)) | ( (~(x)) & (z)) ) + + +void sm3_compress(uint32_t digest[8], const unsigned char block[64]) +{ + int j; + uint32_t W[68], W1[64]; + const uint32_t *pblock = (const uint32_t *)block; + + uint32_t A = digest[0]; + uint32_t B = digest[1]; + uint32_t C = digest[2]; + uint32_t D = digest[3]; + uint32_t E = digest[4]; + uint32_t F = digest[5]; + uint32_t G = digest[6]; + uint32_t H = digest[7]; + uint32_t SS1,SS2,TT1,TT2,T[64]; + + for (j = 0; j < 16; j++) { + W[j] = cpu_to_be32(pblock[j]); + } + for (j = 16; j < 68; j++) { + W[j] = P1( W[j-16] ^ W[j-9] ^ ROTATELEFT(W[j-3],15)) ^ ROTATELEFT(W[j - 13],7 ) ^ W[j-6];; + } + for( j = 0; j < 64; j++) { + W1[j] = W[j] ^ W[j+4]; + } + + for(j =0; j < 16; j++) { + + T[j] = 0x79CC4519; + SS1 = ROTATELEFT((ROTATELEFT(A,12) + E + ROTATELEFT(T[j],j)), 7); + SS2 = SS1 ^ ROTATELEFT(A,12); + TT1 = FF0(A,B,C) + D + SS2 + W1[j]; + TT2 = GG0(E,F,G) + H + SS1 + W[j]; + D = C; + C = ROTATELEFT(B,9); + B = A; + A = TT1; + H = G; + G = ROTATELEFT(F,19); + F = E; + E = P0(TT2); + } + + for(j =16; j < 64; j++) { + + T[j] = 0x7A879D8A; + SS1 = ROTATELEFT((ROTATELEFT(A,12) + E + ROTATELEFT(T[j],j)), 7); + SS2 = SS1 ^ ROTATELEFT(A,12); + TT1 = FF1(A,B,C) + D + SS2 + W1[j]; + TT2 = GG1(E,F,G) + H + SS1 + W[j]; + D = C; + C = ROTATELEFT(B,9); + B = A; + A = TT1; + H = G; + G = ROTATELEFT(F,19); + F = E; + E = P0(TT2); + } + + digest[0] ^= A; + digest[1] ^= B; + digest[2] ^= C; + digest[3] ^= D; + digest[4] ^= E; + digest[5] ^= F; + digest[6] ^= G; + digest[7] ^= H; +} + +void sm3(const unsigned char *msg, size_t msglen, + unsigned char dgst[SM3_DIGEST_LENGTH]) +{ + sm3_ctx_t ctx; + + sm3_init(&ctx); + sm3_update(&ctx, msg, msglen); + sm3_final(&ctx, dgst); + + memset(&ctx, 0, sizeof(sm3_ctx_t)); +} diff --git a/algo/sm3/sph_sm3.h b/algo/sm3/sph_sm3.h new file mode 100644 index 0000000..eab61d3 --- /dev/null +++ b/algo/sm3/sph_sm3.h @@ -0,0 +1,120 @@ +/* ==================================================================== + * Copyright (c) 2014 - 2016 The GmSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the GmSSL Project. + * (http://gmssl.org/)" + * + * 4. The name "GmSSL Project" must not be used to endorse or promote + * products derived from this software without prior written + * permission. For written permission, please contact + * guanzhi1980@gmail.com. + * + * 5. Products derived from this software may not be called "GmSSL" + * nor may "GmSSL" appear in their names without prior written + * permission of the GmSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the GmSSL Project + * (http://gmssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ + +#ifndef SPH_SM3_H +#define SPH_SM3_H + +#define SM3_DIGEST_LENGTH 32 +#define SM3_BLOCK_SIZE 64 +#define SM3_CBLOCK (SM3_BLOCK_SIZE) +#define SM3_HMAC_SIZE (SM3_DIGEST_LENGTH) + + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct { + uint32_t digest[8]; + int nblocks; + unsigned char block[64]; + int num; +} sm3_ctx_t; + +void sm3_init(sm3_ctx_t *ctx); +void sm3_update(sm3_ctx_t *ctx, const unsigned char* data, size_t data_len); +void sm3_final(sm3_ctx_t *ctx, unsigned char digest[SM3_DIGEST_LENGTH]); +void sm3_compress(uint32_t digest[8], const unsigned char block[SM3_BLOCK_SIZE]); +void sm3(const unsigned char *data, size_t datalen, + unsigned char digest[SM3_DIGEST_LENGTH]); + +void sph_sm3(void *cc, const void *data, size_t len); +void sph_sm3_close(void *cc, void *dst); + +typedef struct { + sm3_ctx_t sm3_ctx; + unsigned char key[SM3_BLOCK_SIZE]; +} sm3_hmac_ctx_t; + +void sm3_hmac_init(sm3_hmac_ctx_t *ctx, const unsigned char *key, size_t key_len); +void sm3_hmac_update(sm3_hmac_ctx_t *ctx, const unsigned char *data, size_t data_len); +void sm3_hmac_final(sm3_hmac_ctx_t *ctx, unsigned char mac[SM3_HMAC_SIZE]); +void sm3_hmac(const unsigned char *data, size_t data_len, + const unsigned char *key, size_t key_len, unsigned char mac[SM3_HMAC_SIZE]); + +#ifdef CPU_BIGENDIAN + +#define cpu_to_be16(v) (v) +#define cpu_to_be32(v) (v) +#define be16_to_cpu(v) (v) +#define be32_to_cpu(v) (v) + +#else + +#define cpu_to_le16(v) (v) +#define cpu_to_le32(v) (v) +#define le16_to_cpu(v) (v) +#define le32_to_cpu(v) (v) + +#define cpu_to_be16(v) (((v)<< 8) | ((v)>>8)) +#define cpu_to_be32(v) (((v)>>24) | (((v)>>8)&0xff00) | (((v)<<8)&0xff0000) | ((v)<<24)) +#define be16_to_cpu(v) cpu_to_be16(v) +#define be32_to_cpu(v) cpu_to_be32(v) + +#endif + +#ifdef __cplusplus +} +#endif +#endif diff --git a/algo/x11/phi1612.c b/algo/x11/phi1612.c new file mode 100644 index 0000000..2de0535 --- /dev/null +++ b/algo/x11/phi1612.c @@ -0,0 +1,140 @@ +#include "miner.h" +#include "algo-gate-api.h" + +#include +#include +#include +#include + +#include "algo/gost/sph_gost.h" +#include "algo/echo/sph_echo.h" +#include "algo/fugue//sph_fugue.h" +#include "algo/cubehash/sse2/cubehash_sse2.h" +#include "algo/skein/sse2/skein.c" +#include "algo/jh/sph_jh.h" + +#ifndef NO_AES_NI + #include "algo/echo/aes_ni/hash_api.h" +#endif + +typedef struct { + sph_skein512_context skein; + sph_jh512_context jh; + cubehashParam cube; + sph_fugue512_context fugue; + sph_gost512_context gost; +#ifdef NO_AES_NI + sph_echo512_context echo; +#else + hashState_echo echo; +#endif +} phi_ctx_holder; + +phi_ctx_holder phi_ctx; +static __thread sph_skein512_context phi_skein_mid + __attribute__ ((aligned (64))); + +void init_phi_ctx() +{ + sph_skein512_init( &phi_ctx.skein ); + sph_jh512_init( &phi_ctx.jh ); + cubehashInit( &phi_ctx.cube, 512, 16, 32 ); + sph_fugue512_init( &phi_ctx.fugue ); + sph_gost512_init( &phi_ctx.gost ); +#ifdef NO_AES_NI + sph_echo512_init( &phi_ctx.echo ); +#else + init_echo( &phi_ctx.echo, 512 ); +#endif +} + +void phi_skein_midstate( const void* input ) +{ + memcpy( &phi_skein_mid, &phi_ctx.skein, sizeof phi_skein_mid ); + sph_skein512( &phi_skein_mid, input, 64 ); +} + +void phi1612hash(void *output, const void *input) +{ + unsigned char hash[128] __attribute__ ((aligned (64))); + phi_ctx_holder ctx __attribute__ ((aligned (64))); + + memcpy( &ctx, &phi_ctx, sizeof(phi_ctx) ); + + memcpy( &ctx.skein, &phi_skein_mid, sizeof phi_skein_mid ); + sph_skein512( &ctx.skein, input + 64, 16 ); + sph_skein512_close( &ctx.skein, hash ); + +// sph_skein512( &ctx.skein, input, 80 ); +// sph_skein512_close( &ctx.skein, (void*)hash ); + + sph_jh512( &ctx.jh, (const void*)hash, 64 ); + sph_jh512_close( &ctx.jh, (void*)hash ); + + cubehashUpdateDigest( &ctx.cube, (byte*) hash, (const byte*)hash, 64 ); + + sph_fugue512( &ctx.fugue, (const void*)hash, 64 ); + sph_fugue512_close( &ctx.fugue, (void*)hash ); + + sph_gost512( &ctx.gost, hash, 64 ); + sph_gost512_close( &ctx.gost, hash ); + +#ifdef NO_AES_NI + sph_echo512( &ctx.echo, hash, 64 ); + sph_echo512_close( &ctx.echo, hash ); +#else + update_final_echo ( &ctx.echo, (BitSequence *)hash, + (const BitSequence *)hash, 512 ); +#endif + + memcpy(output, hash, 32); +} + +int scanhash_phi1612( int thr_id, struct work *work, uint32_t max_nonce, + uint64_t *hashes_done ) +{ + uint32_t *pdata = work->data; + uint32_t *ptarget = work->target; + + const uint32_t first_nonce = pdata[19]; + uint32_t _ALIGN(64) endiandata[20]; + uint32_t nonce = first_nonce; + volatile uint8_t *restart = &(work_restart[thr_id].restart); + + if (opt_benchmark) + ((uint32_t*)ptarget)[7] = 0x0cff; + + for (int k = 0; k < 19; k++) + be32enc(&endiandata[k], pdata[k]); + + phi_skein_midstate( endiandata ); + + const uint32_t Htarg = ptarget[7]; + do { + uint32_t hash[8]; + be32enc(&endiandata[19], nonce); + phi1612hash(hash, endiandata); + + if (hash[7] <= Htarg && fulltest(hash, ptarget)) { + pdata[19] = nonce; + *hashes_done = pdata[19] - first_nonce; + return 1; + } + nonce++; + + } while (nonce < max_nonce && !(*restart)); + + pdata[19] = nonce; + *hashes_done = pdata[19] - first_nonce + 1; + return 0; +} + +bool register_phi1612_algo( algo_gate_t* gate ) +{ + gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | AVX2_OPT; + init_phi_ctx(); + gate->scanhash = (void*)&scanhash_phi1612; + gate->hash = (void*)&phi1612hash; + gate->get_max64 = (void*)&get_max64_0x3ffff; + return true; +} diff --git a/algo/x13/x13sm3.c b/algo/x13/x13sm3.c new file mode 100644 index 0000000..850fab4 --- /dev/null +++ b/algo/x13/x13sm3.c @@ -0,0 +1,253 @@ +#include "miner.h" +#include "algo-gate-api.h" + +#include +#include +#include +#include + +#include "algo/groestl/sph_groestl.h" +#include "algo/shavite/sph_shavite.h" +#include "algo/luffa/sph_luffa.h" +#include "algo/cubehash/sph_cubehash.h" +#include "algo/simd/sph_simd.h" +#include "algo/echo/sph_echo.h" +#include "algo/hamsi/sph_hamsi.h" +#include "algo/fugue/sph_fugue.h" +#include "algo/sm3/sph_sm3.h" + +#include "algo/luffa/sse2/luffa_for_sse2.h" +#include "algo/cubehash/sse2/cubehash_sse2.h" +#include "algo/simd/sse2/nist.h" +#include "algo/echo/sse2/sph_echo.h" +#include "algo/blake/sse2/blake.c" +#include "algo/bmw/sse2/bmw.c" +#include "algo/keccak/sse2/keccak.c" +#include "algo/skein/sse2/skein.c" +#include "algo/jh/sse2/jh_sse2_opt64.h" + +#ifndef NO_AES_NI + #include "algo/groestl/aes_ni/hash-groestl.h" + #include "algo/echo/aes_ni/hash_api.h" +#endif + +typedef struct { +#ifdef NO_AES_NI + sph_groestl512_context groestl; + sph_echo512_context echo; +#else + hashState_echo echo; + hashState_groestl groestl; +#endif + hashState_luffa luffa; + cubehashParam cube; + sph_shavite512_context shavite; + hashState_sd simd; + sm3_ctx_t sm3; + sph_hamsi512_context hamsi; + sph_fugue512_context fugue; +} hsr_ctx_holder; + +hsr_ctx_holder hsr_ctx; + +void init_hsr_ctx() +{ +#ifdef NO_AES_NI + sph_groestl512_init(&hsr_ctx.groestl); + sph_echo512_init(&hsr_ctx.echo); +#else + init_echo(&hsr_ctx.echo, 512); + init_groestl(&hsr_ctx.groestl, 64 ); +#endif + init_luffa(&hsr_ctx.luffa,512); + cubehashInit(&hsr_ctx.cube,512,16,32); + sph_shavite512_init(&hsr_ctx.shavite); + init_sd(&hsr_ctx.simd,512); + sm3_init( &hsr_ctx.sm3 ); + sph_hamsi512_init(&hsr_ctx.hamsi); + sph_fugue512_init(&hsr_ctx.fugue); +}; + +static void x13sm3hash(void *output, const void *input) +{ + unsigned char hash[128]; __attribute__ ((aligned (32))) + + hsr_ctx_holder ctx; + memcpy(&ctx, &hsr_ctx, sizeof(hsr_ctx)); + + unsigned char hashbuf[128]; + size_t hashptr; + sph_u64 hashctA; + sph_u64 hashctB; + + //---blake1--- + + DECL_BLK; + BLK_I; + BLK_W; + BLK_C; + + //---bmw2--- + + DECL_BMW; + BMW_I; + BMW_U; + + #define M(x) sph_dec64le_aligned(data + 8 * (x)) + #define H(x) (h[x]) + #define dH(x) (dh[x]) + + BMW_C; + + #undef M + #undef H + #undef dH + + //---groestl---- + +#ifdef NO_AES_NI + sph_groestl512 (&ctx.groestl, hash, 64); + sph_groestl512_close(&ctx.groestl, hash); +#else + update_and_final_groestl( &ctx.groestl, (char*)hash, + (const char*)hash, 512 ); +#endif + + //---skein4--- + + DECL_SKN; + SKN_I; + SKN_U; + SKN_C; + + //---jh5------ + + DECL_JH; + JH_H; + + //---keccak6--- + + DECL_KEC; + KEC_I; + KEC_U; + KEC_C; + + //--- luffa7 + update_and_final_luffa( &ctx.luffa, (BitSequence*)hash, + (const BitSequence*)hash, 64 ); + + // 8 Cube + cubehashUpdateDigest( &ctx.cube, (byte*) hash, + (const byte*)hash, 64 ); + + // 9 Shavite + sph_shavite512( &ctx.shavite, hash, 64); + sph_shavite512_close( &ctx.shavite, hash); + + // 10 Simd + update_final_sd( &ctx.simd, (BitSequence *)hash, + (const BitSequence *)hash, 512 ); + + //11---echo--- +#ifdef NO_AES_NI + sph_echo512(&ctx.echo, hash, 64); + sph_echo512_close(&ctx.echo, hash); +#else + update_final_echo ( &ctx.echo, (BitSequence *)hash, + (const BitSequence *)hash, 512 ); +#endif + + uint32_t sm3_hash[32]; + memset(sm3_hash, 0, sizeof sm3_hash); + + sph_sm3(&ctx.sm3, hash, 64); + sph_sm3_close(&ctx.sm3, sm3_hash); + + sph_hamsi512(&ctx.hamsi, sm3_hash, 64); + sph_hamsi512_close(&ctx.hamsi, hash); + + sph_fugue512(&ctx.fugue, hash, 64); + sph_fugue512_close(&ctx.fugue, hash); + + asm volatile ("emms"); + memcpy(output, hash, 32); +} + +int scanhash_x13sm3( int thr_id, struct work *work, + uint32_t max_nonce, uint64_t *hashes_done) +{ + uint32_t endiandata[20] __attribute__((aligned(64))); + uint32_t hash64[8] __attribute__((aligned(64))); + uint32_t *pdata = work->data; + uint32_t *ptarget = work->target; + uint32_t n = pdata[19] - 1; + const uint32_t first_nonce = pdata[19]; + const uint32_t Htarg = ptarget[7]; + + uint64_t htmax[] = { + 0, + 0xF, + 0xFF, + 0xFFF, + 0xFFFF, + 0x10000000 + }; + uint32_t masks[] = { + 0xFFFFFFFF, + 0xFFFFFFF0, + 0xFFFFFF00, + 0xFFFFF000, + 0xFFFF0000, + 0 + }; + + // we need bigendian data... + swab32_array( endiandata, pdata, 20 ); + +#ifdef DEBUG_ALGO + if (Htarg != 0) + 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); + x13sm3hash(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; +} + +bool register_x13sm3_algo( algo_gate_t* gate ) +{ + gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | AVX2_OPT; + init_hsr_ctx(); + gate->scanhash = (void*)&scanhash_x13sm3; + gate->hash = (void*)&x13sm3hash; + gate->get_max64 = (void*)&get_max64_0x3ffff; + return true; +}; + diff --git a/configure b/configure index f794c6c..09f1896 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for cpuminer-opt 3.6.8. +# Generated by GNU Autoconf 2.69 for cpuminer-opt 3.6.9. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -577,8 +577,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='cpuminer-opt' PACKAGE_TARNAME='cpuminer-opt' -PACKAGE_VERSION='3.6.8' -PACKAGE_STRING='cpuminer-opt 3.6.8' +PACKAGE_VERSION='3.6.9' +PACKAGE_STRING='cpuminer-opt 3.6.9' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1321,7 +1321,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures cpuminer-opt 3.6.8 to adapt to many kinds of systems. +\`configure' configures cpuminer-opt 3.6.9 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1392,7 +1392,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of cpuminer-opt 3.6.8:";; + short | recursive ) echo "Configuration of cpuminer-opt 3.6.9:";; esac cat <<\_ACEOF @@ -1497,7 +1497,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -cpuminer-opt configure 3.6.8 +cpuminer-opt configure 3.6.9 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2000,7 +2000,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by cpuminer-opt $as_me 3.6.8, which was +It was created by cpuminer-opt $as_me 3.6.9, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2981,7 +2981,7 @@ fi # Define the identity of the package. PACKAGE='cpuminer-opt' - VERSION='3.6.8' + VERSION='3.6.9' cat >>confdefs.h <<_ACEOF @@ -6677,7 +6677,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by cpuminer-opt $as_me 3.6.8, which was +This file was extended by cpuminer-opt $as_me 3.6.9, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -6743,7 +6743,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -cpuminer-opt config.status 3.6.8 +cpuminer-opt config.status 3.6.9 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 6010ed8..fc7e22f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([cpuminer-opt], [3.6.8]) +AC_INIT([cpuminer-opt], [3.6.9]) AC_PREREQ([2.59c]) AC_CANONICAL_SYSTEM diff --git a/miner.h b/miner.h index 2f246b0..a4fc408 100644 --- a/miner.h +++ b/miner.h @@ -508,6 +508,7 @@ enum algos { ALGO_NEOSCRYPT, ALGO_NIST5, ALGO_PENTABLAKE, + ALGO_PHI1612, ALGO_PLUCK, ALGO_QUARK, ALGO_QUBIT, @@ -530,6 +531,7 @@ enum algos { ALGO_X11EVO, ALGO_X11GOST, ALGO_X13, + ALGO_X13SM3, ALGO_X14, ALGO_X15, ALGO_X17, @@ -573,6 +575,7 @@ static const char* const algo_names[] = { "neoscrypt", "nist5", "pentablake", + "phi1612", "pluck", "quark", "qubit", @@ -595,6 +598,7 @@ static const char* const algo_names[] = { "x11evo", "x11gost", "x13", + "x13sm3", "x14", "x15", "x17", @@ -691,8 +695,9 @@ Options:\n\ myr-gr Myriad-Groestl\n\ neoscrypt NeoScrypt(128, 2, 1)\n\ nist5 Nist5\n\ - pluck Pluck:128 (Supcoin)\n\ pentablake Pentablake\n\ + pluck Pluck:128 (Supcoin)\n\ + phi1612 phi, LUX coin\n\ quark Quark\n\ qubit Qubit\n\ scrypt scrypt(1024, 1, 1) (default)\n\ @@ -715,6 +720,7 @@ Options:\n\ x11evo Revolvercoin\n\ x11gost sib (SibCoin)\n\ x13 X13\n\ + x13sm3 hsr (Hshare)\n\ x14 X14\n\ x15 X15\n\ x17\n\