Skip to content

Commit

Permalink
stratum: add deep, timetravel and hmq1725 algos
Browse files Browse the repository at this point in the history
Signed-off-by: Tanguy Pruvot <[email protected]>
  • Loading branch information
tpruvot committed Feb 27, 2017
1 parent 9b2d591 commit ca022f2
Show file tree
Hide file tree
Showing 16 changed files with 555 additions and 5 deletions.
4 changes: 4 additions & 0 deletions rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ screen -dmS debug tail -f $LOG_DIR/debug.log
# Stratum instances (skipped/exit if no .conf)

screen -dmS c11 $STRATUM_DIR/run.sh c11
screen -dmS deep $STRATUM_DIR/run.sh deep

screen -dmS x11 $STRATUM_DIR/run.sh x11
screen -dmS x11evo $STRATUM_DIR/run.sh x11evo
screen -dmS x13 $STRATUM_DIR/run.sh x13
screen -dmS x14 $STRATUM_DIR/run.sh x14
screen -dmS x15 $STRATUM_DIR/run.sh x15
screen -dmS x17 $STRATUM_DIR/run.sh x17
screen -dmS xevan $STRATUM_DIR/run.sh xevan
screen -dmS timetravel $STRATUM_DIR/run.sh timetravel
screen -dmS hmq1725 $STRATUM_DIR/run.sh hmq1725

screen -dmS sha $STRATUM_DIR/run.sh sha
screen -dmS scrypt $STRATUM_DIR/run.sh scrypt
Expand Down
29 changes: 29 additions & 0 deletions stratum/algos/deep.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <string.h>
#include <stdlib.h>

#include <sha3/sph_luffa.h>
#include <sha3/sph_cubehash.h>
#include <sha3/sph_echo.h>

void deep_hash(const char* input, char* output, uint32_t len)
{
sph_luffa512_context ctx_luffa;
sph_cubehash512_context ctx_cubehash;
sph_echo512_context ctx_echo;

char hash1[64], hash2[64];

sph_luffa512_init(&ctx_luffa);
sph_luffa512(&ctx_luffa, (const void*) input, len);
sph_luffa512_close(&ctx_luffa, (void*) &hash1);

sph_cubehash512_init(&ctx_cubehash);
sph_cubehash512(&ctx_cubehash, (const void*) &hash1, 64);
sph_cubehash512_close(&ctx_cubehash, (void*) &hash2);

sph_echo512_init(&ctx_echo);
sph_echo512(&ctx_echo, (const void*) &hash2, 64);
sph_echo512_close(&ctx_echo, (void*) &hash1);

memcpy(output, &hash1, 32);
}
17 changes: 17 additions & 0 deletions stratum/algos/deep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef DEEP_H
#define DEEP_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

void deep_hash(const char* input, char* output, uint32_t len);

#ifdef __cplusplus
}
#endif

#endif

218 changes: 218 additions & 0 deletions stratum/algos/hmq17.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sha3/sph_blake.h>
#include <sha3/sph_bmw.h>
#include <sha3/sph_groestl.h>
#include <sha3/sph_jh.h>
#include <sha3/sph_keccak.h>
#include <sha3/sph_skein.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>
#include <sha3/sph_hamsi.h>
#include <sha3/sph_fugue.h>
#include <sha3/sph_shabal.h>
#include <sha3/sph_whirlpool.h>
#include <sha3/sph_sha2.h>
#include <sha3/sph_haval.h>

typedef struct
{
sph_blake512_context blake1, blake2;
sph_bmw512_context bmw1, bmw2, bmw3;
sph_groestl512_context groestl1, groestl2;
sph_skein512_context skein1, skein2;
sph_jh512_context jh1, jh2;
sph_keccak512_context keccak1, keccak2;
sph_luffa512_context luffa1, luffa2;
sph_cubehash512_context cubehash;
sph_shavite512_context shavite1, shavite2;
sph_simd512_context simd1, simd2;
sph_echo512_context echo1, echo2;
sph_hamsi512_context hamsi;
sph_fugue512_context fugue1, fugue2;
sph_shabal512_context shabal;
sph_whirlpool_context whirlpool1, whirlpool2, whirlpool3, whirlpool4;
sph_sha512_context sha1, sha2;
sph_haval256_5_context haval1, haval2;
} hmq_contexts;

static __thread hmq_contexts base_contexts;
static __thread int hmq_context_init = 0;

static void init_contexts(hmq_contexts *ctx)
{
sph_bmw512_init(&ctx->bmw1);
sph_bmw512_init(&ctx->bmw2);
sph_bmw512_init(&ctx->bmw2);
sph_bmw512_init(&ctx->bmw3);
sph_whirlpool_init(&ctx->whirlpool1);
sph_whirlpool_init(&ctx->whirlpool2);
sph_whirlpool_init(&ctx->whirlpool3);
sph_whirlpool_init(&ctx->whirlpool4);
sph_groestl512_init(&ctx->groestl1);
sph_groestl512_init(&ctx->groestl2);
sph_skein512_init(&ctx->skein1);
sph_skein512_init(&ctx->skein2);
sph_jh512_init(&ctx->jh1);
sph_jh512_init(&ctx->jh2);
sph_keccak512_init(&ctx->keccak1);
sph_keccak512_init(&ctx->keccak2);
sph_blake512_init(&ctx->blake1);
sph_blake512_init(&ctx->blake2);
sph_luffa512_init(&ctx->luffa1);
sph_luffa512_init(&ctx->luffa2);
sph_cubehash512_init(&ctx->cubehash);
sph_shavite512_init(&ctx->shavite1);
sph_shavite512_init(&ctx->shavite2);
sph_simd512_init(&ctx->simd1);
sph_simd512_init(&ctx->simd2);
sph_echo512_init(&ctx->echo1);
sph_echo512_init(&ctx->echo2);
sph_hamsi512_init(&ctx->hamsi);
sph_fugue512_init(&ctx->fugue1);
sph_fugue512_init(&ctx->fugue2);
sph_shabal512_init(&ctx->shabal);
sph_sha512_init(&ctx->sha1);
sph_sha512_init(&ctx->sha2);
sph_haval256_5_init(&ctx->haval1);
sph_haval256_5_init(&ctx->haval2);
}

void hmq17_hash(const char* input, char* output, uint32_t len)
{
uint32_t hash[32];

const uint32_t mask = 24;

hmq_contexts ctx;

if (!hmq_context_init) {
init_contexts(&base_contexts);
hmq_context_init = 1;
}
memcpy(&ctx, &base_contexts, sizeof(hmq_contexts));

sph_bmw512(&ctx.bmw1, input, len);
sph_bmw512_close(&ctx.bmw1, hash);

sph_whirlpool(&ctx.whirlpool1, hash, 64);
sph_whirlpool_close(&ctx.whirlpool1, hash);

if (hash[0] & mask) {
sph_groestl512(&ctx.groestl1, hash, 64);
sph_groestl512_close(&ctx.groestl1, hash);
} else {
sph_skein512(&ctx.skein1, hash, 64);
sph_skein512_close(&ctx.skein1, hash);
}

sph_jh512(&ctx.jh1, hash, 64);
sph_jh512_close(&ctx.jh1, hash);

sph_keccak512(&ctx.keccak1, hash, 64);
sph_keccak512_close(&ctx.keccak1, hash);

if (hash[0] & mask) {
sph_blake512(&ctx.blake1, hash, 64);
sph_blake512_close(&ctx.blake1, hash);
} else {
sph_bmw512 (&ctx.bmw2, hash, 64);
sph_bmw512_close(&ctx.bmw2, hash);
}

sph_luffa512(&ctx.luffa1, hash, 64);
sph_luffa512_close(&ctx.luffa1, hash);

sph_cubehash512(&ctx.cubehash, hash, 64);
sph_cubehash512_close(&ctx.cubehash, hash);

if (hash[0] & mask) {
sph_keccak512(&ctx.keccak2, hash, 64);
sph_keccak512_close(&ctx.keccak2, hash);
} else {
sph_jh512(&ctx.jh2, hash, 64);
sph_jh512_close(&ctx.jh2, hash);
}

sph_shavite512(&ctx.shavite1, hash, 64);
sph_shavite512_close(&ctx.shavite1, hash);

sph_simd512(&ctx.simd1, hash, 64);
sph_simd512_close(&ctx.simd1, hash);

if (hash[0] & mask) {
sph_whirlpool(&ctx.whirlpool2, hash, 64);
sph_whirlpool_close(&ctx.whirlpool2, hash);
} else {
sph_haval256_5(&ctx.haval1, hash, 64);
sph_haval256_5_close(&ctx.haval1, hash);
memset(&hash[8], 0, 32);
}

sph_echo512(&ctx.echo1, hash, 64);
sph_echo512_close(&ctx.echo1, hash);

sph_blake512(&ctx.blake2, hash, 64);
sph_blake512_close(&ctx.blake2, hash);

if (hash[0] & mask) {
sph_shavite512(&ctx.shavite2, hash, 64);
sph_shavite512_close(&ctx.shavite2, hash);
} else {
sph_luffa512 (&ctx.luffa2, hash, 64);
sph_luffa512_close(&ctx.luffa2, hash);
}

sph_hamsi512(&ctx.hamsi, hash, 64);
sph_hamsi512_close(&ctx.hamsi, hash);

sph_fugue512(&ctx.fugue1, hash, 64);
sph_fugue512_close(&ctx.fugue1, hash);

if (hash[0] & mask) {
sph_echo512(&ctx.echo2, hash, 64);
sph_echo512_close(&ctx.echo2, hash);
} else {
sph_simd512(&ctx.simd2, hash, 64);
sph_simd512_close(&ctx.simd2, hash);
}

sph_shabal512(&ctx.shabal, hash, 64);
sph_shabal512_close(&ctx.shabal, hash);

sph_whirlpool(&ctx.whirlpool3, hash, 64);
sph_whirlpool_close(&ctx.whirlpool3, hash);

if (hash[0] & mask) {
sph_fugue512(&ctx.fugue2, hash, 64);
sph_fugue512_close(&ctx.fugue2, hash);
} else {
sph_sha512(&ctx.sha1, hash, 64);
sph_sha512_close(&ctx.sha1, hash);
}

sph_groestl512(&ctx.groestl2, hash, 64);
sph_groestl512_close(&ctx.groestl2, hash);

sph_sha512(&ctx.sha2, hash, 64);
sph_sha512_close(&ctx.sha2, hash);

if (hash[0] & mask) {
sph_haval256_5(&ctx.haval2, hash, 64);
sph_haval256_5_close(&ctx.haval2, hash);
memset(&hash[8], 0, 32);
} else {
sph_whirlpool(&ctx.whirlpool4, hash, 64);
sph_whirlpool_close(&ctx.whirlpool4, hash);
}

sph_bmw512(&ctx.bmw3, hash, 64);
sph_bmw512_close(&ctx.bmw3, hash);

memcpy(output, hash, 32);
}
16 changes: 16 additions & 0 deletions stratum/algos/hmq17.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef HMQ17_H
#define HMQ17_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

void hmq17_hash(const char* input, char* output, uint32_t len);

#ifdef __cplusplus
}
#endif

#endif
4 changes: 2 additions & 2 deletions stratum/algos/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ 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 keccak.c \
blake.c scrypt.c c11.c x11.c x13.c sha256.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 \
xevan.c \
timetravel.c xevan.c hmq17.c \
skein2.c zr5.c bmw.c luffa.c pentablake.c whirlpool.c whirlpoolx.c blakecoin.c \
blake2.c \
yescrypt.c yescrypt-opt.c sha256_Y.c lbry.c \
Expand Down
Loading

0 comments on commit ca022f2

Please sign in to comment.