This commit is contained in:
Jay D Dee
2018-03-27 20:20:05 -04:00
parent 3363d61524
commit f449c6725f
105 changed files with 4560 additions and 1846 deletions

View File

@@ -1,5 +1,4 @@
#include "algo-gate-api.h"
#include "sha256t-gate.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
@@ -7,25 +6,26 @@
#include "sph_sha2.h"
#include <openssl/sha.h>
#if !defined(SHA256T_4WAY)
#ifndef USE_SPH_SHA
static SHA256_CTX sha256t_ctx __attribute__ ((aligned (64)));
static __thread SHA256_CTX sha256t_mid __attribute__ ((aligned (64)));
static __thread SHA256_CTX sha256t_ctx __attribute__ ((aligned (64)));
#else
static sph_sha256_context sha256t_ctx __attribute__ ((aligned (64)));
static __thread sph_sha256_context sha256t_mid __attribute__ ((aligned (64)));
static __thread sph_sha256_context sha256t_ctx __attribute__ ((aligned (64)));
#endif
void sha256t_midstate( const void* input )
{
memcpy( &sha256t_mid, &sha256t_ctx, sizeof sha256t_mid );
#ifndef USE_SPH_SHA
SHA256_Update( &sha256t_mid, input, 64 );
SHA256_Init( &sha256t_ctx );
SHA256_Update( &sha256t_ctx, input, 64 );
#else
sph_sha256( &sha256t_mid, input, 64 );
sph_sha256_init( &sha256t_ctx );
sph_sha256( &sha256t_ctx, input, 64 );
#endif
}
void sha256t_hash(void* output, const void* input, uint32_t len)
void sha256t_hash( void* output, const void* input )
{
uint32_t _ALIGN(64) hashA[16];
const int midlen = 64; // bytes
@@ -33,16 +33,16 @@ void sha256t_hash(void* output, const void* input, uint32_t len)
#ifndef USE_SPH_SHA
SHA256_CTX ctx_sha256 __attribute__ ((aligned (64)));
memcpy( &ctx_sha256, &sha256t_mid, sizeof sha256t_mid );
memcpy( &ctx_sha256, &sha256t_ctx, sizeof sha256t_ctx );
SHA256_Update( &ctx_sha256, input + midlen, tail );
SHA256_Final( (unsigned char*)hashA, &ctx_sha256 );
memcpy( &ctx_sha256, &sha256t_ctx, sizeof sha256t_ctx );
SHA256_Init( &ctx_sha256 );
SHA256_Update( &ctx_sha256, hashA, 32 );
SHA256_Final( (unsigned char*)hashA, &ctx_sha256 );
memcpy( &ctx_sha256, &sha256t_ctx, sizeof sha256t_ctx );
SHA256_Init( &ctx_sha256 );
SHA256_Update( &ctx_sha256, hashA, 32 );
SHA256_Final( (unsigned char*)hashA, &ctx_sha256 );
#else
@@ -52,11 +52,11 @@ void sha256t_hash(void* output, const void* input, uint32_t len)
sph_sha256( &ctx_sha256, input + midlen, tail );
sph_sha256_close( &ctx_sha256, hashA );
memcpy( &ctx_sha256, &sha256t_ctx, sizeof sha256t_ctx );
sph_sha256_init( &ctx_sha256 );
sph_sha256( &ctx_sha256, hashA, 32 );
sph_sha256_close( &ctx_sha256, hashA );
memcpy( &ctx_sha256, &sha256t_ctx, sizeof sha256t_ctx );
sph_sha256_init( &ctx_sha256 );
sph_sha256( &ctx_sha256, hashA, 32 );
sph_sha256_close( &ctx_sha256, hashA );
#endif
@@ -68,8 +68,6 @@ int scanhash_sha256t(int thr_id, struct work *work,
{
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
uint32_t len = 80;
uint32_t n = pdata[19] - 1;
const uint32_t first_nonce = pdata[19];
const uint32_t Htarg = ptarget[7];
@@ -113,7 +111,7 @@ int scanhash_sha256t(int thr_id, struct work *work,
do {
pdata[19] = ++n;
be32enc(&endiandata[19], n);
sha256t_hash(hash64, endiandata, len);
sha256t_hash( hash64, endiandata );
#ifndef DEBUG_ALGO
if ((!(hash64[7] & mask)) && fulltest(hash64, ptarget)) {
*hashes_done = n - first_nonce + 1;
@@ -139,23 +137,4 @@ int scanhash_sha256t(int thr_id, struct work *work,
pdata[19] = n;
return 0;
}
void sha256t_set_target( struct work* work, double job_diff )
{
work_set_target( work, job_diff / (256.0 * opt_diff_factor) );
}
bool register_sha256t_algo( algo_gate_t* gate )
{
#ifndef USE_SPH_SHA
SHA256_Init( &sha256t_ctx );
#else
sph_sha256_init( &sha256t_ctx );
#endif
gate->optimizations = SSE2_OPT | AVX_OPT | AVX2_OPT | SHA_OPT;
gate->scanhash = (void*)&scanhash_sha256t;
gate->hash = (void*)&sha256t_hash;
// gate->set_target = (void*)&sha256t_set_target;
gate->get_max64 = (void*)&get_max64_0x3ffff;
return true;
}