diff --git a/rc.local b/rc.local index 3b18fa5..cecc85c 100644 --- a/rc.local +++ b/rc.local @@ -43,6 +43,7 @@ screen -dmS nist5 $STRATUM_DIR/run.sh nist5 screen -dmS penta $STRATUM_DIR/run.sh penta screen -dmS quark $STRATUM_DIR/run.sh quark screen -dmS qubit $STRATUM_DIR/run.sh qubit +screen -dmS jha $STRATUM_DIR/run.sh jha #screen -dmS dmd-gr $STRATUM_DIR/run.sh dmd-gr screen -dmS myr-gr $STRATUM_DIR/run.sh myr-gr screen -dmS lbry $STRATUM_DIR/run.sh lbry diff --git a/stratum/algos/common.h b/stratum/algos/common.h new file mode 100644 index 0000000..eeaf89d --- /dev/null +++ b/stratum/algos/common.h @@ -0,0 +1,4 @@ +#define _ALIGN(x) __attribute__ ((aligned(x))) + +extern void debuglog_hex(void *data, int len); + diff --git a/stratum/algos/jha.c b/stratum/algos/jha.c index e5d75a4..4901c4c 100644 --- a/stratum/algos/jha.c +++ b/stratum/algos/jha.c @@ -1,135 +1,56 @@ -#include "jha.h" - #include #include #include #include -#include "../sha3/sph_blake.h" -#include "../sha3/sph_groestl.h" -#include "../sha3/sph_jh.h" -#include "../sha3/sph_keccak.h" -#include "../sha3/sph_skein.h" +#include +#include +#include +#include +#include +#include "jha.h" +#include "common.h" -void jha_hash(const char* input, char* output, uint32_t len) { +void jha_hash(const char* input, char* output, uint32_t len) +{ + 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; - 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; + uint32_t _ALIGN(64) hash[16]; - uint32_t hash[16]; + // JHA v8: SHA3 512, on 80 bytes (not 88) + sph_keccak512_init(&ctx_keccak); + sph_keccak512(&ctx_keccak, input, 80); + sph_keccak512_close(&ctx_keccak, (&hash)); - unsigned int round_mask = ( - (unsigned int)(((unsigned char *)input)[84]) << 0 | - (unsigned int)(((unsigned char *)input)[85]) << 8 | - (unsigned int)(((unsigned char *)input)[86]) << 16 | - (unsigned int)(((unsigned char *)input)[87]) << 24 ); + // Heavy & Light Pair Loop + for (int round = 0; round < 3; round++) + { + if (hash[0] & 0x01) { + sph_groestl512_init(&ctx_groestl); + sph_groestl512(&ctx_groestl, (&hash), 64); + sph_groestl512_close(&ctx_groestl, (&hash)); + } else { + sph_skein512_init(&ctx_skein); + sph_skein512(&ctx_skein, (&hash), 64); + sph_skein512_close(&ctx_skein, (&hash)); + } - // - // JHA V7 - // - if (round_mask == 7) { - - // - // Input Hashing with SHA3 512, 88 bytes - // - sph_keccak512_init(&ctx_keccak); - sph_keccak512 (&ctx_keccak, input, 88); - sph_keccak512_close(&ctx_keccak, hash); - - // - // Variable Rounds Loop - // - unsigned int rounds = hash[0] & 7; - unsigned int round; - for (round = 0; round < rounds; round++) { - switch (hash[0] & 3) { - case 0: - sph_blake512_init(&ctx_blake); - sph_blake512 (&ctx_blake, hash, 64); - sph_blake512_close(&ctx_blake, hash); - break; - case 1: - sph_groestl512_init(&ctx_groestl); - sph_groestl512 (&ctx_groestl, hash, 64); - sph_groestl512_close(&ctx_groestl, hash); - break; - case 2: - sph_jh512_init(&ctx_jh); - sph_jh512 (&ctx_jh, hash, 64); - sph_jh512_close(&ctx_jh, hash); - break; - case 3: - sph_skein512_init(&ctx_skein); - sph_skein512 (&ctx_skein, hash, 64); - sph_skein512_close(&ctx_skein, hash); - break; - } - } - - // - // Return 256bit(32x8) - // - memcpy(output, hash, 32); - - } - - // - // JHA V8 - // - else if (round_mask == 8) { - - // - // Input Hashing with SHA3 512, 80 bytes - // - sph_keccak512_init(&ctx_keccak); - sph_keccak512 (&ctx_keccak, input, 80); - sph_keccak512_close(&ctx_keccak, (&hash)); - - // - // Heavy & Light Pair Loop - // - unsigned int round; - for (round = 0; round < 3; round++) { - if (hash[0] & 0x01) { - sph_groestl512_init(&ctx_groestl); - sph_groestl512 (&ctx_groestl, (&hash), 64); - sph_groestl512_close(&ctx_groestl, (&hash)); - } - else { - sph_skein512_init(&ctx_skein); - sph_skein512 (&ctx_skein, (&hash), 64); - sph_skein512_close(&ctx_skein, (&hash)); - } - if (hash[0] & 0x01) { - sph_blake512_init(&ctx_blake); - sph_blake512 (&ctx_blake, (&hash), 64); - sph_blake512_close(&ctx_blake, (&hash)); - } - else { - sph_jh512_init(&ctx_jh); - sph_jh512 (&ctx_jh, (&hash), 64); - sph_jh512_close(&ctx_jh, (&hash)); - } - } - - // - // Return 256bit(32x8) - // - memcpy(output, hash, 32); - - } - - // - // Wrong Round Mask Data - // - else { - - memset(output, 0xFF, 32); - - } + if (hash[0] & 0x01) { + sph_blake512_init(&ctx_blake); + sph_blake512(&ctx_blake, (&hash), 64); + sph_blake512_close(&ctx_blake, (&hash)); + } else { + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, (&hash), 64); + sph_jh512_close(&ctx_jh, (&hash)); + } + } + // Return 256 bits (32x8) + memcpy(output, hash, 32); } diff --git a/stratum/algos/makefile b/stratum/algos/makefile index e25c018..ffde27f 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -9,7 +9,7 @@ CFLAGS= $(CXXFLAGS) -std=gnu99 LDFLAGS=-O2 -lgmp SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ - blake.c scrypt.c c11.c x11.c x13.c sha256.c sha256t.c keccak.c deep.c \ + blake.c scrypt.c c11.c x11.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c \ x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \ bitcore.c timetravel.c xevan.c bastion.c hmq17.c \ skein2.c zr5.c bmw.c luffa.c pentablake.c whirlpool.c whirlpoolx.c blakecoin.c \ diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index b79db9d..80a3ed6 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -218,6 +218,11 @@ static void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VAL memset(block_hex, 0, block_size); sprintf(block_hex, "%s%02x%s", submitvalues->header_be, (unsigned char)templ->txcount, submitvalues->coinbase); + if (g_current_algo->name && !strcmp("jha", g_current_algo->name)) { + // block header of 88 bytes + sprintf(block_hex, "%s8400000008000000%02x%s", submitvalues->header_be, (unsigned char)templ->txcount, submitvalues->coinbase); + } + vector::const_iterator i; for(i = templ->txdata.begin(); i != templ->txdata.end(); ++i) sprintf(block_hex+strlen(block_hex), "%s", (*i).c_str()); diff --git a/stratum/config.sample/jha.conf b/stratum/config.sample/jha.conf new file mode 100644 index 0000000..378b73a --- /dev/null +++ b/stratum/config.sample/jha.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 4633 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = jha +difficulty = 128 +max_ttf = 400000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 6f7541e..12a7875 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -110,6 +110,8 @@ YAAMP_ALGO g_algos[] = {"hmq1725", hmq17_hash, 0x10000, 0, 0}, + {"jha", jha_hash, 0x10000, 0}, + {"lyra2", lyra2re_hash, 0x80, 0, 0}, {"lyra2v2", lyra2v2_hash, 0x100, 0, 0}, {"lyra2z", lyra2z_hash, 0x100, 0, 0}, diff --git a/stratum/stratum.h b/stratum/stratum.h index 8bf5bfb..e3c00c3 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -150,6 +150,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/blake2.h" #include "algos/qubit.h" #include "algos/groestl.h" +#include "algos/jha.h" #include "algos/skein.h" #include "algos/keccak.h" #include "algos/sha256t.h" diff --git a/stratum/util.cpp b/stratum/util.cpp index c756188..2ac2d43 100644 --- a/stratum/util.cpp +++ b/stratum/util.cpp @@ -161,6 +161,18 @@ void debuglog(const char *format, ...) } } +void debuglog_hex(void *data, int len) +{ + uint8_t* const bin = (uint8_t*) data; + char *hex = (char*) calloc(1, len*2 + 2); + if (!hex) return; + for(int i=0; i < len; i++) + sprintf(hex+strlen(hex), "%02x", bin[i]); + strcpy(hex+strlen(hex), "\n"); + debuglog(hex); + free(hex); +} + void stratumlog(const char *format, ...) { char buffer[YAAMP_SMALLBUFSIZE]; diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index cd96d4b..9608b18 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -18,6 +18,7 @@ function yaamp_get_algos() 'deep', 'hmq1725', 'keccak', + 'jha', 'lbry', 'luffa', 'lyra2', @@ -131,6 +132,7 @@ function getAlgoColors($algo) 'blake' => '#f0f0f0', 'blakecoin' => '#f0f0f0', 'groestl' => '#d0a0a0', + 'jha' => '#a0d0c0', 'dmd-gr' => '#a0c0f0', 'myr-gr' => '#a0c0f0', 'hmq1725' => '#ffa0a0',