This commit is contained in:
Jay D Dee
2017-07-24 21:38:32 -04:00
parent f8907677f6
commit ec4f6028a2
18 changed files with 158 additions and 183 deletions

View File

@@ -21,7 +21,7 @@
#include "brg_endian.h"
#define NEED_UINT_64T
#include "brg_types.h"
#include "algo/sha/brg_types.h"
/* some sizes (number of bytes) */
#define ROWS (8)

View File

@@ -35,7 +35,7 @@ typedef crypto_uint64 u64;
#include "brg_endian.h"
#define NEED_UINT_64T
#include "brg_types.h"
#include "algo/sha/brg_types.h"
#ifdef IACA_TRACE
#include IACA_MARKS

View File

@@ -22,15 +22,12 @@
*/
#include <emmintrin.h>
#include <stdint.h>
#include <string.h>
#include "algo/sha/sha3-defs.h"
typedef __m128i word128; /*word128 defines a 128-bit SSE2 word*/
typedef unsigned char BitSequence;
typedef unsigned long long DataLength;
typedef enum {jhSUCCESS = 0, jhFAIL = 1, jhBAD_HASHLEN = 2} jhReturn;
/*define data alignment for different C compilers*/

View File

@@ -21,8 +21,9 @@
#define LYRA2_H_
#include <stdint.h>
#include "algo/sha/sha3-defs.h"
typedef unsigned char byte;
//typedef unsigned char byte;
//Block length required so Blake2's Initialization Vector (IV) is not overwritten (THIS SHOULD NOT BE MODIFIED)
#define BLOCK_LEN_BLAKE2_SAFE_INT64 8 //512 bits (=64 bytes, =8 uint64_t)

116
algo/s3.c
View File

@@ -1,116 +0,0 @@
#include "miner.h"
#include "algo-gate-api.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "algo/skein/sph_skein.h"
#include "algo/shavite/sph_shavite.h"
#include "algo/simd/sph_simd.h"
void s3hash(void *output, const void *input)
{
sph_shavite512_context ctx_shavite;
sph_simd512_context ctx_simd;
sph_skein512_context ctx_skein;
unsigned char _ALIGN(128) hash[64];
sph_shavite512_init(&ctx_shavite);
sph_shavite512(&ctx_shavite, input, 80);
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_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_s3(int thr_id, struct work *work, uint32_t max_nonce,
uint64_t *hashes_done)
{
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];
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);
s3hash(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_s3_algo( algo_gate_t* gate )
{
algo_not_tested();
gate->scanhash = (void*)&scanhash_s3;
gate->hash = (void*)&s3hash;
// gate->get_max64 = &s3_get_max64;
return true;
};

View File

@@ -780,7 +780,7 @@ bool register_scrypt_algo( algo_gate_t* gate )
{
gate->miner_thread_init =(void*)&scrypt_miner_thread_init;
gate->scanhash = (void*)&scanhash_scrypt;
gate->hash = (void*)&scrypt_1024_1_1_256_24way;
// gate->hash = (void*)&scrypt_1024_1_1_256_24way;
gate->set_target = (void*)&scrypt_set_target;
gate->get_max64 = (void*)&scrypt_get_max64;

View File

@@ -8,28 +8,12 @@
#define DATA_ALIGN(x) __declspec(align(16)) x
#endif
#include "compat.h"
#include "simd-compat.h"
#include "algo/sha/sha3-defs.h"
/*
* NIST API Specific types.
*/
//typedef unsigned char BitSequence;
//#ifdef HAS_64
// typedef u64 DataLength;
//#else
// typedef unsigned long DataLength;
//#endif
// can't find u32 or fft-t
#include <stdint.h>
typedef uint32_t u32;
typedef int fft_t;
//typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHBITLEN = 2} HashReturn;
typedef struct {
unsigned int hashbitlen;
unsigned int blocksize;

View File

@@ -1,5 +1,5 @@
#ifndef __COMPAT_H__
#define __COMPAT_H__
#ifndef __SIMD_COMPAT_H__
#define __SIMD_COMPAT_H__
#include <limits.h>
@@ -24,14 +24,7 @@
*/
#include <stdint.h>
#ifdef UINT32_MAX
typedef uint32_t u32;
#else
typedef uint_fast32_t u32;
#endif
typedef unsigned long long u64;
#include "algo/sha/brg_types.h"
#define C32(x) ((u32)(x))

102
algo/skunk.c Normal file
View File

@@ -0,0 +1,102 @@
#include "miner.h"
#include "algo-gate-api.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "algo/gost/sph_gost.h"
#include "algo/skein/sph_skein.h"
#include "algo/fugue/sph_fugue.h"
#include "algo/cubehash/sse2/cubehash_sse2.h"
typedef struct {
sph_skein512_context skein;
cubehashParam cube;
sph_fugue512_context fugue;
sph_gost512_context gost;
} skunk_ctx_holder;
static __thread skunk_ctx_holder skunk_ctx;
void skunkhash( void *output, const void *input )
{
unsigned char hash[128] __attribute__ ((aligned (64)));
skunk_ctx_holder ctx __attribute__ ((aligned (64)));
memcpy( &ctx, &skunk_ctx, sizeof(skunk_ctx) );
sph_skein512( &ctx.skein, input+64, 16 );
sph_skein512_close( &ctx.skein, (void*) hash );
cubehashUpdateDigest( &ctx.cube, (byte*) hash, (const byte*)hash, 64 );
sph_fugue512( &ctx.fugue, hash, 64 );
sph_fugue512_close( &ctx.fugue, hash );
sph_gost512( &ctx.gost, hash, 64 );
sph_gost512_close( &ctx.gost, hash );
memcpy(output, hash, 32);
}
int scanhash_skunk( 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] );
// precalc midstate
sph_skein512_init( &skunk_ctx.skein );
sph_skein512( &skunk_ctx.skein, endiandata, 64 );
const uint32_t Htarg = ptarget[7];
do
{
uint32_t hash[8];
be32enc( &endiandata[19], nonce );
skunkhash( 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 skunk_thread_init()
{
sph_skein512_init( &skunk_ctx.skein );
cubehashInit( &skunk_ctx.cube, 512, 16, 32 );
sph_fugue512_init( &skunk_ctx.fugue );
sph_gost512_init( &skunk_ctx.gost );
return true;
}
bool register_skunk_algo( algo_gate_t* gate )
{
gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | AVX2_OPT;
gate->miner_thread_init = (void*)&skunk_thread_init;
gate->scanhash = (void*)&scanhash_skunk;
gate->hash = (void*)&skunkhash;
return true;
}

View File

@@ -24,19 +24,7 @@ typedef struct {
#endif
} tribus_ctx_holder;
tribus_ctx_holder tribus_ctx;
void init_tribus_ctx()
{
sph_jh512_init( &tribus_ctx.jh );
sph_keccak512_init( &tribus_ctx.keccak );
#ifdef NO_AES_NI
sph_echo512_init( &tribus_ctx.echo );
#else
init_echo( &tribus_ctx.echo, 512 );
#endif
}
static __thread tribus_ctx_holder tribus_ctx;
void tribus_hash(void *state, const void *input)
{
@@ -44,7 +32,7 @@ void tribus_hash(void *state, const void *input)
tribus_ctx_holder ctx;
memcpy( &ctx, &tribus_ctx, sizeof(tribus_ctx) );
sph_jh512( &ctx.jh, input, 80 );
sph_jh512( &ctx.jh, input+64, 16 );
sph_jh512_close( &ctx.jh, (void*) hash );
sph_keccak512( &ctx.keccak, (const void*) hash, 64 );
@@ -93,6 +81,10 @@ int scanhash_tribus(int thr_id, struct work *work, uint32_t max_nonce, uint64_t
be32enc(&endiandata[i], pdata[i]);
}
// precalc midstate
sph_jh512_init( &tribus_ctx.jh );
sph_jh512( &tribus_ctx.jh, endiandata, 64 );
#ifdef DEBUG_ALGO
printf("[%d] Htarg=%X\n", thr_id, Htarg);
#endif
@@ -131,9 +123,21 @@ int scanhash_tribus(int thr_id, struct work *work, uint32_t max_nonce, uint64_t
return 0;
}
bool tribus_thread_init()
{
sph_jh512_init( &tribus_ctx.jh );
sph_keccak512_init( &tribus_ctx.keccak );
#ifdef NO_AES_NI
sph_echo512_init( &tribus_ctx.echo );
#else
init_echo( &tribus_ctx.echo, 512 );
#endif
return true;
}
bool register_tribus_algo( algo_gate_t* gate )
{
init_tribus_ctx();
gate->miner_thread_init = (void*)&tribus_thread_init;
gate->optimizations = SSE2_OPT | AES_OPT;
gate->get_max64 = (void*)&get_max64_0x1ffff;
gate->scanhash = (void*)&scanhash_tribus;