This commit is contained in:
Jay D Dee
2017-01-31 20:12:56 -05:00
parent c1d6c3a57f
commit 698286189b
43 changed files with 844 additions and 481 deletions

View File

@@ -4,7 +4,7 @@ Jeff garzik, ig0tik3d, elmad, palmd, and Optiminer, with additional
optimizations by Jay D Dee.
All of the code is believed to be open and free. If anyone has a
claim to any of it post your case in the icpuminer-opt Bitcoin Talk forum
claim to any of it post your case in the cpuminer-opt Bitcoin Talk forum
or by email.
https://bitcointalk.org/index.php?topic=1326803.0
@@ -55,6 +55,7 @@ Supported Algorithms
shavite3 Shavite3
skein Skein+Sha (Skeincoin)
skein2 Double Skein (Woodcoin)
timetravel Machinecoin (MAC)
vanilla blake256r8vnl (VCash)
veltor
whirlpool

View File

@@ -3,6 +3,14 @@ Compile instruction for Linux and Windows are at the bottom of this file.
Change Log
----------
v3.5.4
x11evo fixed (broken in v3.5.2) and optimized 23% faster
Small improvements of 1% to 3% on many algos including timetravel,
xevan and cryptonight.
More code cleanup and compiler warning reduction.
Improved checking for missing command line arguments.
v3.5.3
More optimizations

View File

@@ -149,6 +149,11 @@ bool register_algo_gate( int algo, algo_gate_t *gate )
switch (algo)
{
// Ignore warnings for not yet defined register fucntions
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
case ALGO_ARGON2: register_argon2_algo ( gate ); break;
case ALGO_AXIOM: register_axiom_algo ( gate ); break;
case ALGO_BASTION: register_bastion_algo ( gate ); break;
@@ -203,6 +208,9 @@ bool register_algo_gate( int algo, algo_gate_t *gate )
case ALGO_YESCRYPT: register_yescrypt_algo ( gate ); break;
case ALGO_ZR5: register_zr5_algo ( gate ); break;
// restore warnings
#pragma GCC diagnostic pop
default:
applog(LOG_ERR,"FAIL: algo_gate registration failed, unknown algo %s.\n", algo_names[opt_algo] );
return false;

View File

@@ -35,9 +35,8 @@ void do_groestl_hash(const void* input, size_t len, char* output) {
groestl(input, len * 8, (uint8_t*)output);
#else
hashState_groestl256 ctx;
init_groestl256( &ctx );
update_groestl256( &ctx, input, len * 8 );
final_groestl256( &ctx, output );
init_groestl256( &ctx, 32 );
update_and_final_groestl256( &ctx, output, input, len * 8 );
#endif
}

View File

@@ -23,9 +23,6 @@ static void transform( cubehashParam *sp )
#ifdef __AVX2__
__m256i x0, x1, x2, x3, y0, y1;
#ifdef UNUSED
__m256i y2, y3;
#endif
x0 = _mm256_load_si256( 0 + sp->x );
x1 = _mm256_load_si256( 2 + sp->x );
@@ -65,12 +62,8 @@ static void transform( cubehashParam *sp )
_mm256_store_si256( 4 + sp->x, x2 );
_mm256_store_si256( 6 + sp->x, x3 );
#elif defined OPTIMIZE_SSE2
#else
__m128i x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3;
#ifdef UNUSED
__m128i y4, y5, y6, y7;
#endif
x0 = _mm_load_si128(0 + sp->x);
x1 = _mm_load_si128(1 + sp->x);
@@ -133,39 +126,6 @@ static void transform( cubehashParam *sp )
_mm_store_si128(6 + sp->x, x6);
_mm_store_si128(7 + sp->x, x7);
#else /* OPTIMIZE_SSE2 */
// Tis code probably not used, sph used instead for uniptoimized mining.
#define ROTATE(a,b) (((a) << (b)) | ((a) >> (32 - b)))
uint32_t y[16];
int i;
for (r = 0; r < rounds; ++r) {
for (i = 0; i < 16; ++i) sp->x[i + 16] += sp->x[i];
for (i = 0; i < 16; ++i) sp->x[i] = ROTATE(y[i],7);
for (i = 0; i < 16; ++i) sp->x[i] ^= sp->x[i + 16];
for (i = 0; i < 16; ++i) y[i ^ 2] = sp->x[i + 16];
for (i = 0; i < 16; ++i) sp->x[i + 16] = y[i];
for (i = 0; i < 16; ++i) sp->x[i + 16] += sp->x[i];
for (i = 0; i < 16; ++i) y[i ^ 4] = sp->x[i];
for (i = 0; i < 16; ++i) sp->x[i] = ROTATE(y[i],11);
for (i = 0; i < 16; ++i) sp->x[i] ^= sp->x[i + 16];
for (i = 0; i < 16; ++i) y[i ^ 1] = sp->x[i + 16];
for (i = 0; i < 16; ++i) sp->x[i + 16] = y[i];
}
#endif
} // transform
@@ -173,27 +133,24 @@ int cubehashInit(cubehashParam *sp, int hashbitlen, int rounds, int blockbytes)
{
int i;
if (hashbitlen < 8) return BAD_HASHBITLEN;
if (hashbitlen > 512) return BAD_HASHBITLEN;
if (hashbitlen != 8 * (hashbitlen / 8)) return BAD_HASHBITLEN;
if ( hashbitlen < 8 ) return BAD_HASHBITLEN;
if ( hashbitlen > 512 ) return BAD_HASHBITLEN;
if ( hashbitlen != 8 * (hashbitlen / 8) ) return BAD_HASHBITLEN;
/* Sanity checks */
if (rounds <= 0 || rounds > 32) rounds = CUBEHASH_ROUNDS;
if (blockbytes <= 0 || blockbytes >= 256) blockbytes = CUBEHASH_BLOCKBYTES;
if ( rounds <= 0 || rounds > 32 )
rounds = CUBEHASH_ROUNDS;
if ( blockbytes <= 0 || blockbytes >= 256)
blockbytes = CUBEHASH_BLOCKBYTES;
sp->hashbitlen = hashbitlen;
sp->rounds = rounds;
sp->blockbytes = blockbytes;
#if defined(OPTIMIZE_SSE2)
for (i = 0; i < 8; ++i) sp->x[i] = _mm_set_epi32(0, 0, 0, 0);
for ( i = 0; i < 8; ++i )
sp->x[i] = _mm_set_epi32(0, 0, 0, 0);
sp->x[0] = _mm_set_epi32(0, sp->rounds, sp->blockbytes, hashbitlen / 8);
#else
for (i = 0; i < 32; ++i) sp->x[i] = 0;
sp->x[0] = hashbitlen / 8;
sp->x[1] = sp->blockbytes;
sp->x[2] = sp->rounds;
#endif
for (i = 0; i < 10; ++i) transform(sp);
for ( i = 0; i < 10; ++i )
transform(sp);
sp->pos = 0;
return SUCCESS;
}
@@ -204,65 +161,104 @@ cubehashReset(cubehashParam *sp)
return cubehashInit(sp, sp->hashbitlen, sp->rounds, sp->blockbytes);
}
int cubehashUpdate(cubehashParam *sp, const byte *data, size_t size)
int cubehashUpdate( cubehashParam *sp, const byte *data, size_t size )
{
uint64_t databitlen = 8 * size;
/* caller promises us that previous data had integral number of bytes */
/* so sp->pos is a multiple of 8 */
while (databitlen >= 8) {
#if defined(OPTIMIZE_SSE2)
((unsigned char *) sp->x)[sp->pos / 8] ^= *data;
#else
uint32_t u = *data;
u <<= 8 * ((sp->pos / 8) % 4);
sp->x[sp->pos / 32] ^= u;
#endif
while ( databitlen >= 8 )
{
( (unsigned char *)sp->x )[sp->pos/8] ^= *data;
data += 1;
databitlen -= 8;
sp->pos += 8;
if (sp->pos == 8 * sp->blockbytes) {
transform(sp);
if ( sp->pos == 8 * sp->blockbytes )
{
transform( sp );
sp->pos = 0;
}
}
if (databitlen > 0) {
#if defined(OPTIMIZE_SSE2)
((unsigned char *) sp->x)[sp->pos / 8] ^= *data;
#else
uint32_t u = *data;
u <<= 8 * ((sp->pos / 8) % 4);
sp->x[sp->pos / 32] ^= u;
#endif
if ( databitlen > 0 )
{
( (unsigned char *)sp->x )[sp->pos/8] ^= *data;
sp->pos += databitlen;
}
return SUCCESS;
}
int cubehashDigest(cubehashParam *sp, byte *digest)
int cubehashDigest( cubehashParam *sp, byte *digest )
{
int i;
#if defined(OPTIMIZE_SSE2)
((unsigned char *) sp->x)[sp->pos / 8] ^= (128 >> (sp->pos % 8));
( (unsigned char *)sp->x )[sp->pos/8] ^= ( 128 >> (sp->pos % 8) );
transform(sp);
sp->x[7] = _mm_xor_si128(sp->x[7], _mm_set_epi32(1, 0, 0, 0));
for (i = 0; i < 10; ++i) transform(sp);
for (i = 0; i < sp->hashbitlen / 8; ++i)
digest[i] = ((unsigned char *) sp->x)[i];
#else
uint32_t u;
u = (128 >> (sp->pos % 8));
u <<= 8 * ((sp->pos / 8) % 4);
sp->x[sp->pos / 32] ^= u;
sp->x[7] = _mm_xor_si128(sp->x[7], _mm_set_epi32(1, 0, 0, 0));
transform(sp);
sp->x[31] ^= 1;
for (i = 0; i < 10; ++i) transform(sp);
for (i = 0; i < sp->hashbitlen / 8; ++i)
digest[i] = sp->x[i / 4] >> (8 * (i % 4));
#endif
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
for ( i = 0; i < sp->hashbitlen / 8; ++i )
digest[i] = ((unsigned char *) sp->x)[i];
return SUCCESS;
}
int cubehashUpdateDigest( cubehashParam *sp, byte *digest,
const byte *data, size_t size )
{
uint64_t databitlen = 8 * size;
int hashlen128 = sp->hashbitlen/128;
int i;
/* caller promises us that previous data had integral number of bytes */
/* so sp->pos is a multiple of 8 */
while ( databitlen >= 8 )
{
( (unsigned char *)sp->x )[sp->pos/8] ^= *data;
data += 1;
databitlen -= 8;
sp->pos += 8;
if ( sp->pos == 8 * sp->blockbytes )
{
transform(sp);
sp->pos = 0;
}
}
if ( databitlen > 0 )
{
( (unsigned char *)sp->x )[sp->pos/8] ^= *data;
sp->pos += databitlen;
}
( (unsigned char *)sp->x )[sp->pos/8] ^= ( 128 >> (sp->pos % 8) );
transform( sp );
sp->x[7] = _mm_xor_si128( sp->x[7], _mm_set_epi32(1,0,0,0) );
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
transform(sp);
for ( i = 0; i < hashlen128; i++ )
( (__m128i*)digest )[i] = ( (__m128i*)sp->x )[i];
return SUCCESS;
}

View File

@@ -57,6 +57,9 @@ int cubehashUpdate(cubehashParam* sp, const byte *data, size_t size);
//BEECRYPTAPI
int cubehashDigest(cubehashParam* sp, byte *digest);
int cubehashUpdateDigest( cubehashParam *sp, byte *digest, const byte *data,
size_t size );
#ifdef __cplusplus
}
#endif

View File

@@ -561,6 +561,128 @@ HashReturn final_echo(hashState_echo *state, BitSequence *hashval)
return SUCCESS;
}
HashReturn update_final_echo( hashState_echo *state, BitSequence *hashval,
const BitSequence *data, DataLength databitlen )
{
unsigned int uByteLength, uBlockCount, uRemainingBytes;
uByteLength = (unsigned int)(databitlen / 8);
if( (state->uBufferBytes + uByteLength) >= state->uBlockLength )
{
if( state->uBufferBytes != 0 )
{
// Fill the buffer
memcpy( state->buffer + state->uBufferBytes,
(void*)data, state->uBlockLength - state->uBufferBytes );
// Process buffer
Compress( state, state->buffer, 1 );
state->processed_bits += state->uBlockLength * 8;
data += state->uBlockLength - state->uBufferBytes;
uByteLength -= state->uBlockLength - state->uBufferBytes;
}
// buffer now does not contain any unprocessed bytes
uBlockCount = uByteLength / state->uBlockLength;
uRemainingBytes = uByteLength % state->uBlockLength;
if( uBlockCount > 0 )
{
Compress( state, data, uBlockCount );
state->processed_bits += uBlockCount * state->uBlockLength * 8;
data += uBlockCount * state->uBlockLength;
}
if( uRemainingBytes > 0 )
memcpy(state->buffer, (void*)data, uRemainingBytes);
state->uBufferBytes = uRemainingBytes;
}
else
{
memcpy( state->buffer + state->uBufferBytes, (void*)data, uByteLength );
state->uBufferBytes += uByteLength;
}
__m128i remainingbits;
// Add remaining bytes in the buffer
state->processed_bits += state->uBufferBytes * 8;
remainingbits = _mm_set_epi32( 0, 0, 0, state->uBufferBytes * 8 );
// Pad with 0x80
state->buffer[state->uBufferBytes++] = 0x80;
// Enough buffer space for padding in this block?
if( (state->uBlockLength - state->uBufferBytes) >= 18 )
{
// Pad with zeros
memset( state->buffer + state->uBufferBytes, 0, state->uBlockLength - (state->uBufferBytes + 18) );
// Hash size
*( (unsigned short*)(state->buffer + state->uBlockLength - 18) ) = state->uHashSize;
// Processed bits
*( (DataLength*)(state->buffer + state->uBlockLength - 16) ) =
state->processed_bits;
*( (DataLength*)(state->buffer + state->uBlockLength - 8) ) = 0;
// Last block contains message bits?
if( state->uBufferBytes == 1 )
{
state->k = _mm_xor_si128( state->k, state->k );
state->k = _mm_sub_epi64( state->k, state->const1536 );
}
else
{
state->k = _mm_add_epi64( state->k, remainingbits );
state->k = _mm_sub_epi64( state->k, state->const1536 );
}
// Compress
Compress( state, state->buffer, 1 );
}
else
{
// Fill with zero and compress
memset( state->buffer + state->uBufferBytes, 0,
state->uBlockLength - state->uBufferBytes );
state->k = _mm_add_epi64( state->k, remainingbits );
state->k = _mm_sub_epi64( state->k, state->const1536 );
Compress( state, state->buffer, 1 );
// Last block
memset( state->buffer, 0, state->uBlockLength - 18 );
// Hash size
*( (unsigned short*)(state->buffer + state->uBlockLength - 18) ) =
state->uHashSize;
// Processed bits
*( (DataLength*)(state->buffer + state->uBlockLength - 16) ) =
state->processed_bits;
*( (DataLength*)(state->buffer + state->uBlockLength - 8) ) = 0;
// Compress the last block
state->k = _mm_xor_si128( state->k, state->k );
state->k = _mm_sub_epi64( state->k, state->const1536 );
Compress( state, state->buffer, 1) ;
}
// Store the hash value
_mm_storeu_si128( (__m128i*)hashval + 0, state->state[0][0] );
_mm_storeu_si128( (__m128i*)hashval + 1, state->state[1][0] );
if( state->uHashSize == 512 )
{
_mm_storeu_si128( (__m128i*)hashval + 2, state->state[2][0] );
_mm_storeu_si128( (__m128i*)hashval + 3, state->state[3][0] );
}
return SUCCESS;
}
HashReturn hash_echo(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval)

View File

@@ -53,6 +53,8 @@ HashReturn final_echo(hashState_echo *state, BitSequence *hashval);
HashReturn hash_echo(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval);
HashReturn update_final_echo( hashState_echo *state, BitSequence *hashval,
const BitSequence *data, DataLength databitlen );
#endif // HASH_API_H

View File

@@ -6,8 +6,10 @@
* This code is placed in the public domain
*/
#include <memory.h>
#include "hash-groestl.h"
#include "miner.h"
#include "avxdefs.h"
#ifndef NO_AES_NI
@@ -53,15 +55,9 @@ void Transform( hashState_groestl *ctx, const u8 *in, unsigned long long len )
{
/* increment block counter */
ctx->block_counter += len/SIZE;
/* digest message, one block at a time */
for (; len >= SIZE; len -= SIZE, in += SIZE)
#if LENGTH<=256
TF512((u64*)ctx->chaining, (u64*)in);
#else
TF1024((u64*)ctx->chaining, (u64*)in);
#endif
for ( ; len >= SIZE; len -= SIZE, in += SIZE )
TF1024( (u64*)ctx->chaining, (u64*)in );
asm volatile ("emms");
}
@@ -69,73 +65,57 @@ void Transform( hashState_groestl *ctx, const u8 *in, unsigned long long len )
void OutputTransformation( hashState_groestl *ctx )
{
/* determine variant */
#if (LENGTH <= 256)
OF512((u64*)ctx->chaining);
#else
OF1024((u64*)ctx->chaining);
#endif
OF1024( (u64*)ctx->chaining );
asm volatile ("emms");
}
/* initialise context */
HashReturn_gr init_groestl( hashState_groestl* ctx )
HashReturn_gr init_groestl( hashState_groestl* ctx, int hashlen )
{
u8 i = 0;
/* output size (in bits) must be a positive integer less than or
equal to 512, and divisible by 8 */
if (LENGTH <= 0 || (LENGTH%8) || LENGTH > 512)
return BAD_HASHBITLEN_GR;
/* set number of state columns and state size depending on
variant */
ctx->columns = COLS;
ctx->statesize = SIZE;
#if (LENGTH <= 256)
ctx->v = SHoRT;
#else
ctx->v = LoNG;
#endif
ctx->hashlen = hashlen;
SET_CONSTANTS();
for (i=0; i<SIZE/8; i++)
for ( i = 0; i < SIZE / 8; i++ )
ctx->chaining[i] = 0;
for (i=0; i<SIZE; i++)
for ( i = 0; i < SIZE; i++ )
ctx->buffer[i] = 0;
if (ctx->chaining == NULL || ctx->buffer == NULL)
return FAIL_GR;
/* set initial value */
ctx->chaining[ctx->columns-1] = U64BIG((u64)LENGTH);
ctx->chaining[COLS-1] = U64BIG((u64)LENGTH);
INIT(ctx->chaining);
/* set other variables */
ctx->buf_ptr = 0;
ctx->block_counter = 0;
return SUCCESS_GR;
}
/*
HashReturn_gr init_groestl( hashState_groestl* ctx )
{
return Xinit_groestl( ctx, 64 );
}
*/
HashReturn_gr reinit_groestl( hashState_groestl* ctx )
{
int i;
for (i=0; i<SIZE/8; i++)
for ( i = 0; i < SIZE / 8; i++ )
ctx->chaining[i] = 0;
for (i=0; i<SIZE; i++)
for ( i = 0; i < SIZE; i++ )
ctx->buffer[i] = 0;
if (ctx->chaining == NULL || ctx->buffer == NULL)
return FAIL_GR;
/* set initial value */
ctx->chaining[ctx->columns-1] = U64BIG((u64)LENGTH);
INIT(ctx->chaining);
/* set other variables */
ctx->chaining[COLS-1] = U64BIG( (u64)LENGTH );
INIT( ctx->chaining );
ctx->buf_ptr = 0;
ctx->block_counter = 0;
@@ -147,21 +127,16 @@ HashReturn_gr update_groestl( hashState_groestl* ctx,
const BitSequence_gr* input,
DataLength_gr databitlen )
{
int index = 0;
int msglen = (int)(databitlen/8);
int rem = (int)(databitlen%8); // not used
int i;
const int msglen = (int)(databitlen/8);
/* digest bulk of message */
Transform( ctx, input+index, msglen-index );
// this line makes no sense, index = 0 before and after
// but removing this line breaks the hash.
index += ((msglen-index)/ctx->statesize)*ctx->statesize;
Transform( ctx, input, msglen );
/* store remaining data in buffer */
while (index < msglen)
ctx->buffer[(int)ctx->buf_ptr++] = input[index++];
i = ( msglen / SIZE ) * SIZE;
while ( i < msglen )
ctx->buffer[(int)ctx->buf_ptr++] = input[i++];
return SUCCESS_GR;
}
@@ -171,43 +146,97 @@ HashReturn_gr update_groestl( hashState_groestl* ctx,
HashReturn_gr final_groestl( hashState_groestl* ctx,
BitSequence_gr* output )
{
int i, j = 0, hashbytelen = LENGTH/8;
u8 *s = (BitSequence_gr*)ctx->chaining;
int i, j;
ctx->buffer[(int)ctx->buf_ptr++] = 0x80;
/* pad with '0'-bits */
if ( ctx->buf_ptr > ctx->statesize-LENGTHFIELDLEN )
if ( ctx->buf_ptr > SIZE - LENGTHFIELDLEN )
{
/* padding requires two blocks */
while ( ctx->buf_ptr < ctx->statesize )
while ( ctx->buf_ptr < SIZE )
ctx->buffer[(int)ctx->buf_ptr++] = 0;
/* digest first padding block */
Transform( ctx, ctx->buffer, ctx->statesize );
Transform( ctx, ctx->buffer, SIZE );
ctx->buf_ptr = 0;
}
// this will pad up to 120 bytes
while (ctx->buf_ptr < ctx->statesize-LENGTHFIELDLEN)
while ( ctx->buf_ptr < SIZE - LENGTHFIELDLEN )
ctx->buffer[(int)ctx->buf_ptr++] = 0;
/* length padding */
ctx->block_counter++;
ctx->buf_ptr = ctx->statesize;
while (ctx->buf_ptr > ctx->statesize-LENGTHFIELDLEN)
ctx->buf_ptr = SIZE;
while ( ctx->buf_ptr > SIZE - LENGTHFIELDLEN )
{
ctx->buffer[(int)--ctx->buf_ptr] = (u8)ctx->block_counter;
ctx->block_counter >>= 8;
}
/* digest final padding block */
Transform(ctx, ctx->buffer, ctx->statesize);
Transform( ctx, ctx->buffer, SIZE );
/* perform output transformation */
OutputTransformation(ctx);
OutputTransformation( ctx );
/* store hash result in output */
for (i = ctx->statesize-hashbytelen; i < ctx->statesize; i++,j++)
output[j] = s[i];
// store hash result in output
for ( i = ( SIZE - ctx->hashlen) / 16, j = 0; i < SIZE / 16; i++, j++ )
casti_m128i( output, j ) = casti_m128i( ctx->chaining , i );
return SUCCESS_GR;
}
HashReturn_gr update_and_final_groestl( hashState_groestl* ctx,
BitSequence_gr* output, const BitSequence_gr* input,
DataLength_gr databitlen )
{
const int inlen = (int)(databitlen/8); // need bytes
int i, j;
/* digest bulk of message */
Transform( ctx, input, inlen );
/* store remaining data in buffer */
i = ( inlen / SIZE ) * SIZE;
while ( i < inlen )
ctx->buffer[(int)ctx->buf_ptr++] = input[i++];
// start of final
ctx->buffer[(int)ctx->buf_ptr++] = 0x80;
/* pad with '0'-bits */
if ( ctx->buf_ptr > SIZE - LENGTHFIELDLEN )
{
/* padding requires two blocks */
while ( ctx->buf_ptr < SIZE )
ctx->buffer[(int)ctx->buf_ptr++] = 0;
memset( ctx->buffer + ctx->buf_ptr, 0, SIZE - ctx->buf_ptr );
/* digest first padding block */
Transform( ctx, ctx->buffer, SIZE );
ctx->buf_ptr = 0;
}
// this will pad up to 120 bytes
memset( ctx->buffer + ctx->buf_ptr, 0, SIZE - ctx->buf_ptr - LENGTHFIELDLEN );
/* length padding */
ctx->block_counter++;
ctx->buf_ptr = SIZE;
while (ctx->buf_ptr > SIZE - LENGTHFIELDLEN)
{
ctx->buffer[(int)--ctx->buf_ptr] = (u8)ctx->block_counter;
ctx->block_counter >>= 8;
}
/* digest final padding block */
Transform( ctx, ctx->buffer, SIZE );
/* perform output transformation */
OutputTransformation( ctx );
// store hash result in output
for ( i = ( SIZE - ctx->hashlen) / 16, j = 0; i < SIZE / 16; i++, j++ )
casti_m128i( output, j ) = casti_m128i( ctx->chaining , i );
return SUCCESS_GR;
}
@@ -221,7 +250,7 @@ HashReturn_gr hash_groestl(int hashbitlen,
hashState_groestl context;
/* initialise */
if ((ret = init_groestl(&context)) != SUCCESS_GR)
if ((ret = init_groestl( &context, hashbitlen/8 )) != SUCCESS_GR)
return ret;
/* process message */

View File

@@ -15,35 +15,12 @@
#endif
#include <stdlib.h>
/* eBash API begin */
/*
#include "crypto_hash.h"
#ifdef crypto_hash_BYTES
#include <crypto_uint8.h>
#include <crypto_uint32.h>
#include <crypto_uint64.h>
typedef crypto_uint8 u8;
typedef crypto_uint32 u32;
typedef crypto_uint64 u64;
#endif
* /
/* eBash API end */
#define LENGTH (512)
#include "brg_endian.h"
#define NEED_UINT_64T
#include "brg_types.h"
#ifdef IACA_TRACE
#include IACA_MARKS
#endif
#ifndef LENGTH
#define LENGTH (256)
#endif
/* some sizes (number of bytes) */
#define ROWS (8)
#define LENGTHFIELDLEN (ROWS)
@@ -80,10 +57,6 @@ typedef crypto_uint64 u64;
(ROTL64(a,56) & li_64(FF000000FF000000)))
#endif /* IS_LITTLE_ENDIAN */
typedef enum { LoNG, SHoRT } Var;
/* NIST API begin */
typedef unsigned char BitSequence_gr;
typedef unsigned long long DataLength_gr;
typedef enum { SUCCESS_GR = 0, FAIL_GR = 1, BAD_HASHBITLEN_GR = 2} HashReturn_gr;
@@ -91,22 +64,28 @@ typedef enum { SUCCESS_GR = 0, FAIL_GR = 1, BAD_HASHBITLEN_GR = 2} HashReturn_gr
// Use area128 overlay for buffer to facilitate fast copying
typedef struct {
__attribute__ ((aligned (32))) u64 chaining[SIZE/8]; /* actual state */
__attribute__ ((aligned (32))) BitSequence_gr buffer[SIZE]; /* data buffer */
__attribute__ ((aligned (32))) u64 chaining[SIZE/8]; // actual state
__attribute__ ((aligned (32))) BitSequence_gr buffer[SIZE]; // data buffer
u64 block_counter; /* message block counter */
int hashlen; // bytes
int buf_ptr; /* data buffer pointer */
int columns; /* no. of columns in state */
int statesize; /* total no. of bytes in state */
Var v; /* LONG or SHORT */
} hashState_groestl;
HashReturn_gr init_groestl( hashState_groestl* );
//HashReturn_gr init_groestl( hashState_groestl* );
HashReturn_gr init_groestl( hashState_groestl*, int );
HashReturn_gr reinit_groestl( hashState_groestl* );
HashReturn_gr update_groestl( hashState_groestl*, const BitSequence_gr*,
DataLength_gr );
HashReturn_gr final_groestl( hashState_groestl*, BitSequence_gr* );
HashReturn_gr hash_groestl( int, const BitSequence_gr*, DataLength_gr,
BitSequence_gr* );
/* NIST API end */
HashReturn_gr update_and_final_groestl( hashState_groestl*,
BitSequence_gr*, const BitSequence_gr*, DataLength_gr );
#endif /* __hash_h */

View File

@@ -6,8 +6,10 @@
* This code is placed in the public domain
*/
#include <memory.h>
#include "hash-groestl256.h"
#include "miner.h"
#include "avxdefs.h"
#ifndef NO_AES_NI
@@ -71,16 +73,11 @@ void OutputTransformation256(hashState_groestl256 *ctx) {
}
/* initialise context */
HashReturn_gr init_groestl256(hashState_groestl256* ctx) {
HashReturn_gr init_groestl256( hashState_groestl256* ctx, int hashlen )
{
u8 i = 0;
/* output size (in bits) must be a positive integer less than or
equal to 512, and divisible by 8 */
/* set number of state columns and state size depending on
variant */
ctx->columns = COLS;
ctx->statesize = SIZE;
ctx->v = SHoRT;
ctx->hashlen = hashlen;
SET_CONSTANTS();
@@ -93,7 +90,7 @@ HashReturn_gr init_groestl256(hashState_groestl256* ctx) {
return FAIL_GR;
/* set initial value */
ctx->chaining[ctx->columns-1] = U64BIG((u64)256);
ctx->chaining[COLS-1] = U64BIG((u64)256);
INIT256(ctx->chaining);
@@ -104,7 +101,6 @@ HashReturn_gr init_groestl256(hashState_groestl256* ctx) {
return SUCCESS_GR;
}
HashReturn_gr reinit_groestl256(hashState_groestl256* ctx)
{
int i;
@@ -117,7 +113,7 @@ HashReturn_gr reinit_groestl256(hashState_groestl256* ctx)
return FAIL_GR;
/* set initial value */
ctx->chaining[ctx->columns-1] = 256;
ctx->chaining[COLS-1] = 256;
INIT256(ctx->chaining);
@@ -128,83 +124,124 @@ HashReturn_gr reinit_groestl256(hashState_groestl256* ctx)
return SUCCESS_GR;
}
/* update state with databitlen bits of input */
HashReturn_gr update_groestl256( hashState_groestl256* ctx,
const BitSequence_gr* input,
DataLength_gr databitlen )
const BitSequence_gr* input, DataLength_gr databitlen )
{
int index = 0;
int msglen = (int)(databitlen/8);
int rem = (int)(databitlen%8);
const int msglen = (int)(databitlen/8); // bytes
int i;
/* digest bulk of message */
Transform256( ctx, input+index, msglen-index );
index += ((msglen-index)/ctx->statesize)*ctx->statesize;
Transform256( ctx, input, msglen );
/* store remaining data in buffer */
while (index < msglen)
ctx->buffer[(int)ctx->buf_ptr++] = input[index++];
i = ( msglen / SIZE ) * SIZE;
while ( i < msglen )
ctx->buffer[(int)ctx->buf_ptr++] = input[i++];
return SUCCESS_GR;
}
/* finalise: process remaining data (including padding), perform
output transformation, and write hash result to 'output' */
HashReturn_gr final_groestl256( hashState_groestl256* ctx,
BitSequence_gr* output )
BitSequence_gr* output )
{
int i, j = 0, hashbytelen = 256/8;
u8 *s = (BitSequence_gr*)ctx->chaining;
ctx->buffer[(int)ctx->buf_ptr++] = 0x80;
/* pad with '0'-bits */
if ( ctx->buf_ptr > ctx->statesize-LENGTHFIELDLEN )
if ( ctx->buf_ptr > SIZE - LENGTHFIELDLEN )
{
/* padding requires two blocks */
while ( ctx->buf_ptr < ctx->statesize )
while ( ctx->buf_ptr < SIZE )
ctx->buffer[(int)ctx->buf_ptr++] = 0;
/* digest first padding block */
Transform256( ctx, ctx->buffer, ctx->statesize );
Transform256( ctx, ctx->buffer, SIZE );
ctx->buf_ptr = 0;
}
while ( ctx->buf_ptr < ctx->statesize-LENGTHFIELDLEN )
while ( ctx->buf_ptr < SIZE - LENGTHFIELDLEN )
ctx->buffer[(int)ctx->buf_ptr++] = 0;
/* length padding */
ctx->block_counter++;
ctx->buf_ptr = ctx->statesize;
while ( ctx->buf_ptr > ctx->statesize-LENGTHFIELDLEN )
ctx->buf_ptr = SIZE;
while ( ctx->buf_ptr > SIZE - LENGTHFIELDLEN )
{
ctx->buffer[(int)--ctx->buf_ptr] = (u8)ctx->block_counter;
ctx->block_counter >>= 8;
}
/* digest final padding block */
Transform256(ctx, ctx->buffer, ctx->statesize);
Transform256( ctx, ctx->buffer, SIZE );
/* perform output transformation */
OutputTransformation256(ctx);
OutputTransformation256( ctx );
/* store hash result in output */
for ( i = ctx->statesize-hashbytelen; i < ctx->statesize; i++,j++ )
output[j] = s[i];
for ( int i = ( (SIZE - ctx->hashlen) / 16 ), j = 0; i < SIZE/16; i++, j++ )
casti_m128i( output, j ) = casti_m128i( ctx->chaining, i );
return SUCCESS_GR;
}
HashReturn_gr update_and_final_groestl256( hashState_groestl256* ctx,
BitSequence_gr* output, const BitSequence_gr* input,
DataLength_gr databitlen )
{
const int msglen = (int)(databitlen/8); // bytes
int i, j;
/* digest bulk of message */
Transform256( ctx, input, msglen );
/* store remaining data in buffer */
i = ( msglen / SIZE ) * SIZE;
while ( i < msglen )
ctx->buffer[(int)ctx->buf_ptr++] = input[i++];
// start of final
ctx->buffer[(int)ctx->buf_ptr++] = 0x80;
/* pad with '0'-bits */
if ( ctx->buf_ptr > SIZE - LENGTHFIELDLEN )
{
/* padding requires two blocks */
while ( ctx->buf_ptr < SIZE )
ctx->buffer[(int)ctx->buf_ptr++] = 0;
/* digest first padding block */
Transform256( ctx, ctx->buffer, SIZE );
ctx->buf_ptr = 0;
}
while ( ctx->buf_ptr < SIZE - LENGTHFIELDLEN )
ctx->buffer[(int)ctx->buf_ptr++] = 0;
/* length padding */
ctx->block_counter++;
ctx->buf_ptr = SIZE;
while ( ctx->buf_ptr > SIZE - LENGTHFIELDLEN )
{
ctx->buffer[(int)--ctx->buf_ptr] = (u8)ctx->block_counter;
ctx->block_counter >>= 8;
}
/* digest final padding block */
Transform256( ctx, ctx->buffer, SIZE );
/* perform output transformation */
OutputTransformation256( ctx );
/* store hash result in output */
for ( i = ( (SIZE - ctx->hashlen) / 16 ), j = 0; i < SIZE/16; i++, j++ )
casti_m128i( output, j ) = casti_m128i( ctx->chaining, i );
return SUCCESS_GR;
}
/* hash bit sequence */
HashReturn_gr hash_groestl256(int hashbitlen,
const BitSequence_gr* data,
DataLength_gr databitlen,
BitSequence_gr* hashval) {
const BitSequence_gr* data,
DataLength_gr databitlen,
BitSequence_gr* hashval) {
HashReturn_gr ret;
hashState_groestl256 context;
/* initialise */
if ((ret = init_groestl256(&context)) != SUCCESS_GR)
if ((ret = init_groestl256(&context, hashbitlen/8)) != SUCCESS_GR)
return ret;
/* process message */

View File

@@ -80,31 +80,37 @@ typedef crypto_uint64 u64;
(ROTL64(a,56) & li_64(FF000000FF000000)))
#endif /* IS_LITTLE_ENDIAN */
typedef enum { LoNG, SHoRT } Var;
/* NIST API begin */
typedef unsigned char BitSequence_gr;
typedef unsigned long long DataLength_gr;
typedef enum { SUCCESS_GR = 0, FAIL_GR = 1, BAD_HASHBITLEN_GR = 2} HashReturn_gr;
typedef enum
{
SUCCESS_GR = 0,
FAIL_GR = 1,
BAD_HASHBITLEN_GR = 2
} HashReturn_gr;
typedef struct {
__attribute__ ((aligned (32))) u64 chaining[SIZE/8]; /* actual state */
__attribute__ ((aligned (32))) BitSequence_gr buffer[SIZE]; /* data buffer */
u64 block_counter; /* message block counter */
int hashlen; // bytes
int buf_ptr; /* data buffer pointer */
int columns; /* no. of columns in state */
int statesize; /* total no. of bytes in state */
Var v; /* LONG or SHORT */
} hashState_groestl256;
HashReturn_gr init_groestl( hashState_groestl256* );
HashReturn_gr init_groestl256( hashState_groestl256*, int );
HashReturn_gr reinit_groestl( hashState_groestl256* );
HashReturn_gr update_groestl( hashState_groestl256*, const BitSequence_gr*,
DataLength_gr );
HashReturn_gr final_groestl( hashState_groestl256*, BitSequence_gr* );
HashReturn_gr hash_groestl( int, const BitSequence_gr*, DataLength_gr,
BitSequence_gr* );
/* NIST API end */
HashReturn_gr update_and_final_groestl256( hashState_groestl256*,
BitSequence_gr*, const BitSequence_gr*,
DataLength_gr );
#endif /* __hash_h */

View File

@@ -29,8 +29,8 @@ void init_groestl_ctx()
#ifdef NO_AES_NI
sph_groestl512_init( &groestl_ctx.groestl );
#else
init_groestl( &groestl_ctx.groestl1 );
init_groestl( &groestl_ctx.groestl2 );
init_groestl( &groestl_ctx.groestl1, 64 );
init_groestl( &groestl_ctx.groestl2, 64 );
#endif
}

View File

@@ -29,7 +29,7 @@ void init_myrgr_ctx()
#ifdef NO_AES_NI
sph_groestl512_init( &myrgr_ctx.groestl );
#else
init_groestl (&myrgr_ctx.groestl );
init_groestl (&myrgr_ctx.groestl, 64 );
#endif
sph_sha256_init(&myrgr_ctx.sha);
}

View File

@@ -36,12 +36,12 @@ void bastionhash(void *output, const void *input)
sph_fugue512_context ctx_fugue;
sph_whirlpool_context ctx_whirlpool;
sph_shabal512_context ctx_shabal;
sph_skein512_context ctx_skein;
// sph_skein512_context ctx_skein;
sph_hamsi512_context ctx_hamsi;
unsigned char hashbuf[128] __attribute__ ((aligned (16)));
sph_u64 hashctA;
sph_u64 hashctB;
// sph_u64 hashctB;
size_t hashptr;
HEFTY1(input, 80, hash);

View File

@@ -31,7 +31,7 @@ static void combine_hashes(uint32_t *out, uint32_t *hash1, uint32_t *hash2, uint
extern void heavyhash(unsigned char* output, const unsigned char* input, int len)
{
/* unsigned char hash1[32];
unsigned char hash1[32];
HEFTY1(input, len, hash1);
// HEFTY1 is new, so take an extra security measure to eliminate
@@ -77,7 +77,7 @@ extern void heavyhash(unsigned char* output, const unsigned char* input, int len
uint32_t *final = (uint32_t *)output;
combine_hashes(final, (uint32_t *)hash2, hash3, hash4, hash5);
*/
}
int scanhash_heavy(int thr_id, uint32_t *pdata, const uint32_t *ptarget,

View File

@@ -80,16 +80,16 @@ void init_hmq1725_ctx()
sph_keccak512_init(&hmq1725_ctx.keccak1);
sph_keccak512_init(&hmq1725_ctx.keccak2);
init_luffa( &hmq1725_ctx.luffa1, 512 );
init_luffa( &hmq1725_ctx.luffa2, 512 );
init_luffa( &hmq1725_ctx.luffa1, 512 );
init_luffa( &hmq1725_ctx.luffa2, 512 );
cubehashInit( &hmq1725_ctx.cube, 512, 16, 32 );
cubehashInit( &hmq1725_ctx.cube, 512, 16, 32 );
sph_shavite512_init(&hmq1725_ctx.shavite1);
sph_shavite512_init(&hmq1725_ctx.shavite2);
init_sd( &hmq1725_ctx.simd1, 512 );
init_sd( &hmq1725_ctx.simd2, 512 );
init_sd( &hmq1725_ctx.simd1, 512 );
init_sd( &hmq1725_ctx.simd2, 512 );
sph_hamsi512_init(&hmq1725_ctx.hamsi1);
@@ -117,8 +117,8 @@ void init_hmq1725_ctx()
#else
init_echo( &hmq1725_ctx.echo1, 512 );
init_echo( &hmq1725_ctx.echo2, 512 );
init_groestl( &hmq1725_ctx.groestl1 );
init_groestl( &hmq1725_ctx.groestl2 );
init_groestl( &hmq1725_ctx.groestl1, 64 );
init_groestl( &hmq1725_ctx.groestl2, 64 );
#endif
}

View File

@@ -151,7 +151,7 @@ double lbry_calc_network_diff( struct work *work )
uint32_t nbits = swab32( work->data[ LBRY_NBITS_INDEX ] );
uint32_t bits = (nbits & 0xffffff);
int16_t shift = (swab32(nbits) & 0xff); // 0x1c = 28
uint64_t diffone = 0x0000FFFF00000000ull;
// uint64_t diffone = 0x0000FFFF00000000ull;
double d = (double)0x0000ffff / (double)bits;
for (int m=shift; m < 29; m++) d *= 256.0;

View File

@@ -327,6 +327,50 @@ HashReturn final_luffa(hashState_luffa *state, BitSequence *hashval)
return SUCCESS;
}
HashReturn update_and_final_luffa( hashState_luffa *state, BitSequence* output,
const BitSequence* data, size_t inlen )
{
HashReturn ret=SUCCESS;
int i, j;
int rem = inlen % 32;
int blocks = (int)( inlen / 32 );
uint8 *p = (uint8*)state->buffer;
// full blocks
for ( j = 0; j < blocks; j++ )
{
state->buffer[0] = BYTES_SWAP32( ((uint32*)data)[0] );
state->buffer[1] = BYTES_SWAP32( ((uint32*)data)[1] );
state->buffer[2] = BYTES_SWAP32( ((uint32*)data)[2] );
state->buffer[3] = BYTES_SWAP32( ((uint32*)data)[3] );
state->buffer[4] = BYTES_SWAP32( ((uint32*)data)[4] );
state->buffer[5] = BYTES_SWAP32( ((uint32*)data)[5] );
state->buffer[6] = BYTES_SWAP32( ((uint32*)data)[6] );
state->buffer[7] = BYTES_SWAP32( ((uint32*)data)[7] );
rnd512( state );
data += MSG_BLOCK_BYTE_LEN;
}
// remaining partial block, if any
for ( i = 0; i < rem/4; i++ )
state->buffer[i] = BYTES_SWAP32( ((uint32*)data)[i] );
// padding of partial block
memset( p+rem+1, 0, (31-rem)*sizeof(uint8) );
p[rem] = 0x80;
for ( i = rem/4; i < 8; i++ )
state->buffer[i] = BYTES_SWAP32(state->buffer[i]);
rnd512( state );
finalization512( state, (uint32*) output );
if ( state->hashbitlen > 512 )
finalization512( state, (uint32*)( output+128 ) );
return SUCCESS;
}
/***************************************************/
/* Round function */
/* state: hash context */

View File

@@ -61,3 +61,8 @@ HashReturn update_luffa( hashState_luffa *state, const BitSequence *data,
HashReturn final_luffa( hashState_luffa *state, BitSequence *hashval );
HashReturn update_and_final_luffa( hashState_luffa *state, BitSequence* output,
const BitSequence* data, size_t inlen );

View File

@@ -33,7 +33,7 @@ void init_lyra2re_ctx()
#ifdef NO_AES_NI
sph_groestl256_init(&lyra2re_ctx.groestl);
#else
init_groestl256( &lyra2re_ctx.groestl );
init_groestl256( &lyra2re_ctx.groestl, 32 );
#endif
}
@@ -62,8 +62,7 @@ void lyra2re_hash(void *state, const void *input)
sph_groestl256( &ctx.groestl, hashB, 32 );
sph_groestl256_close( &ctx.groestl, hashA );
#else
update_groestl256( &ctx.groestl, hashB, 256 );
final_groestl256( &ctx.groestl, hashA );
update_and_final_groestl256( &ctx.groestl, hashA, hashB, 256 );
#endif
memcpy(state, hashA, 32);

View File

@@ -48,16 +48,20 @@ void lyra2rev2_hash( void *state, const void *input )
sph_keccak256( &ctx.keccak, hashA, 32 );
sph_keccak256_close(&ctx.keccak, hashB);
cubehashUpdate( &ctx.cube1, (const byte*) hashB,32 );
cubehashDigest( &ctx.cube1, (byte*)hashA );
cubehashUpdateDigest( &ctx.cube1, (byte*) hashA,
(const byte*) hashB, 32 );
// cubehashUpdate( &ctx.cube1, (const byte*) hashB,32 );
// cubehashDigest( &ctx.cube1, (byte*)hashA );
LYRA2( hashA, 32, hashA, 32, hashA, 32, 1, 4, 4 );
sph_skein256( &ctx.skein, hashA, 32 );
sph_skein256_close( &ctx.skein, hashB );
cubehashUpdate( &ctx.cube2, (const byte*) hashB,32 );
cubehashDigest( &ctx.cube2, (byte*)hashA );
cubehashUpdateDigest( &ctx.cube2, (byte*) hashA,
(const byte*) hashB, 32 );
// cubehashUpdate( &ctx.cube2, (const byte*) hashB,32 );
// cubehashDigest( &ctx.cube2, (byte*)hashA );
sph_bmw256( &ctx.bmw, hashA, 32 );
sph_bmw256_close( &ctx.bmw, hashB );

View File

@@ -64,9 +64,9 @@ double GaussianQuad_N2(const double x1, const double x2)
double x[6], w[6];
//gauleg(a2, b2, x, w);
int m,j;
// int m;
double z1, z, xm, xl, pp, p3, p2, p1;
m=3;
// m=3;
xm=0.5*(x2+x1);
xl=0.5*(x2-x1);
for(int i=1;i<=3;i++)
@@ -165,7 +165,7 @@ int scanhash_m7m_hash( int thr_id, struct work* work,
//uint8_t *bdata = 0;
uint8_t bdata[8192];
int rc = 0, i, digits;
int bytes, nnNonce2;
int bytes;
size_t p = sizeof(unsigned long), a = 64/p, b = 32/p;
m7m_ctx_holder ctx1, ctx2;
@@ -183,49 +183,6 @@ int scanhash_m7m_hash( int thr_id, struct work* work,
sph_tiger( &ctx1.tiger, data, M7_MIDSTATE_LEN );
sph_ripemd160( &ctx1.ripemd, data, M7_MIDSTATE_LEN );
/*
sph_sha256_context ctx_final_sha256;
sph_sha256_context ctx_sha256;
sph_sha512_context ctx_sha512;
sph_keccak512_context ctx_keccak;
sph_whirlpool_context ctx_whirlpool;
sph_haval256_5_context ctx_haval;
sph_tiger_context ctx_tiger;
sph_ripemd160_context ctx_ripemd;
sph_sha256_init(&ctx_final_sha256);
sph_sha256_init(&ctx_sha256);
sph_sha256 (&ctx_sha256, data, M7_MIDSTATE_LEN);
sph_sha512_init(&ctx_sha512);
sph_sha512 (&ctx_sha512, data, M7_MIDSTATE_LEN);
sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, data, M7_MIDSTATE_LEN);
sph_whirlpool_init(&ctx_whirlpool);
sph_whirlpool (&ctx_whirlpool, data, M7_MIDSTATE_LEN);
sph_haval256_5_init(&ctx_haval);
sph_haval256_5 (&ctx_haval, data, M7_MIDSTATE_LEN);
sph_tiger_init(&ctx_tiger);
sph_tiger (&ctx_tiger, data, M7_MIDSTATE_LEN);
sph_ripemd160_init(&ctx_ripemd);
sph_ripemd160 (&ctx_ripemd, data, M7_MIDSTATE_LEN);
sph_sha256_context ctx2_sha256;
sph_sha512_context ctx2_sha512;
sph_keccak512_context ctx2_keccak;
sph_whirlpool_context ctx2_whirlpool;
sph_haval256_5_context ctx2_haval;
sph_tiger_context ctx2_tiger;
sph_ripemd160_context ctx2_ripemd;
*/
mpz_t magipi, magisw, product, bns0, bns1;
mpf_t magifpi, magifpi0, mpt1, mpt2, mptmp, mpten;
@@ -419,7 +376,7 @@ int scanhash_m7m_hash_t(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
//uint8_t *bdata = 0;
uint8_t bdata[8192];
int rc = 0, i, digits;
int bytes, nnNonce2;
int bytes;
size_t p = sizeof(unsigned long), a = 64/p, b = 32/p;
memcpy(data, pdata, 80);

View File

@@ -36,7 +36,7 @@ void init_nist5_ctx()
#ifdef NO_AES_NI
sph_groestl512_init( &nist5_ctx.groestl );
#else
init_groestl( &nist5_ctx.groestl );
init_groestl( &nist5_ctx.groestl, 64 );
#endif
}

View File

@@ -44,7 +44,7 @@ void init_quark_ctx()
#ifdef NO_AES_NI
sph_groestl512_init( &quark_ctx );
#else
init_groestl( &quark_ctx );
init_groestl( &quark_ctx, 64 );
#endif
}

View File

@@ -114,9 +114,9 @@ HashReturn init_sd(hashState_sd *state, int hashbitlen) {
return r;
}
HashReturn update_sd(hashState_sd *state, const BitSequence *data, DataLength databitlen) {
HashReturn update_sd( hashState_sd *state, const BitSequence *data,
DataLength databitlen )
{
unsigned current;
unsigned int bs = state->blocksize;
static int align = -1;
@@ -130,46 +130,49 @@ HashReturn update_sd(hashState_sd *state, const BitSequence *data, DataLength da
current = state->count_low & (bs - 1);
#endif
if (current & 7) {
/*
* The number of hashed bits is not a multiple of 8.
* Very painfull to implement and not required by the NIST API.
*/
if ( current & 7 )
{
// The number of hashed bits is not a multiple of 8.
// Very painfull to implement and not required by the NIST API.
return FAIL;
}
while (databitlen > 0) {
if (IS_ALIGNED(data,align) && current == 0 && databitlen >= bs) {
/*
* We can hash the data directly from the input buffer.
*/
while ( databitlen > 0 )
{
if ( IS_ALIGNED(data,align) && current == 0 && databitlen >= bs )
{
// We can hash the data directly from the input buffer.
SIMD_Compress(state, data, 0);
databitlen -= bs;
data += bs/8;
IncreaseCounter(state, bs);
} else {
/*
* Copy a chunk of data to the buffer
*/
}
else
{
// Copy a chunk of data to the buffer
unsigned int len = bs - current;
if (databitlen < len) {
memcpy(state->buffer+current/8, data, (databitlen+7)/8);
IncreaseCounter(state, databitlen);
if ( databitlen < len )
{
memcpy( state->buffer+current/8, data, (databitlen+7)/8 );
IncreaseCounter( state, databitlen );
return SUCCESS;
} else {
memcpy(state->buffer+current/8, data, len/8);
IncreaseCounter(state,len);
}
else
{
memcpy( state->buffer+current/8, data, len/8 );
IncreaseCounter( state,len );
databitlen -= len;
data += len/8;
current = 0;
SIMD_Compress(state, state->buffer, 0);
SIMD_Compress( state, state->buffer, 0 );
}
}
}
return SUCCESS;
}
HashReturn final_sd(hashState_sd *state, BitSequence *hashval) {
HashReturn final_sd( hashState_sd *state, BitSequence *hashval )
{
#ifdef HAS_64
u64 l;
int current = state->count & (state->blocksize - 1);
@@ -181,56 +184,53 @@ HashReturn final_sd(hashState_sd *state, BitSequence *hashval) {
BitSequence bs[64];
int isshort = 1;
/*
* If there is still some data in the buffer, hash it
*/
if (current) {
/*
* We first need to zero out the end of the buffer.
*/
if (current & 7) {
BitSequence mask = 0xff >> (current&7);
// If there is still some data in the buffer, hash it
if ( current )
{
// We first need to zero out the end of the buffer.
if ( current & 7 )
{
BitSequence mask = 0xff >> ( current & 7 );
state->buffer[current/8] &= ~mask;
}
current = (current+7)/8;
memset(state->buffer+current, 0, state->blocksize/8 - current);
SIMD_Compress(state, state->buffer, 0);
current = ( current+7 ) / 8;
memset( state->buffer+current, 0, state->blocksize/8 - current );
SIMD_Compress( state, state->buffer, 0 );
}
/*
* Input the message length as the last block
*/
memset(state->buffer, 0, state->blocksize/8);
//* Input the message length as the last block
memset( state->buffer, 0, state->blocksize / 8 );
#ifdef HAS_64
l = state->count;
for (i=0; i<8; i++) {
for ( i=0; i<8; i++ )
{
state->buffer[i] = l & 0xff;
l >>= 8;
}
if (state->count < 16384)
if ( state->count < 16384 )
isshort = 2;
#else
l = state->count_low;
for (i=0; i<4; i++) {
for ( i=0; i<4; i++ )
{
state->buffer[i] = l & 0xff;
l >>= 8;
}
l = state->count_high;
for (i=0; i<4; i++) {
for ( i=0; i<4; i++ )
{
state->buffer[4+i] = l & 0xff;
l >>= 8;
}
if (state->count_high == 0 && state->count_low < 16384)
if ( state->count_high == 0 && state->count_low < 16384 )
isshort = 2;
#endif
SIMD_Compress(state, state->buffer, isshort);
SIMD_Compress( state, state->buffer, isshort );
/*
* Decode the 32-bit words into a BitSequence
*/
for (i=0; i<2*state->n_feistels; i++) {
// Decode the 32-bit words into a BitSequence
for ( i=0; i < 2*state->n_feistels; i++ )
{
u32 x = state->A[i];
bs[4*i ] = x&0xff;
x >>= 8;
@@ -241,16 +241,123 @@ HashReturn final_sd(hashState_sd *state, BitSequence *hashval) {
bs[4*i+3] = x&0xff;
}
memcpy(hashval, bs, state->hashbitlen/8);
if (state->hashbitlen%8) {
BitSequence mask = 0xff << (8 - (state->hashbitlen%8));
memcpy( hashval, bs, state->hashbitlen / 8 );
if ( state->hashbitlen % 8 )
{
BitSequence mask = 0xff << ( 8 - (state->hashbitlen % 8) );
hashval[state->hashbitlen/8 + 1] = bs[state->hashbitlen/8 + 1] & mask;
}
//free(state->buffer);
//free(state->A);
return SUCCESS;
}
HashReturn update_final_sd( hashState_sd *state, BitSequence *hashval,
const BitSequence *data, DataLength databitlen )
{
int current, i;
unsigned int bs = state->blocksize;
static int align = -1;
BitSequence out[64];
int isshort = 1;
u64 l;
if (align == -1)
align = RequiredAlignment();
#ifdef HAS_64
current = state->count & (bs - 1);
#else
current = state->count_low & (bs - 1);
#endif
if ( current & 7 )
{
// The number of hashed bits is not a multiple of 8.
// Very painfull to implement and not required by the NIST API.
return FAIL;
}
while ( databitlen > 0 )
{
if ( IS_ALIGNED(data,align) && current == 0 && databitlen >= bs )
{
// We can hash the data directly from the input buffer.
SIMD_Compress(state, data, 0);
databitlen -= bs;
data += bs/8;
IncreaseCounter(state, bs);
}
else
{
// Copy a chunk of data to the buffer
unsigned int len = bs - current;
if ( databitlen < len )
{
memcpy( state->buffer+current/8, data, (databitlen+7)/8 );
IncreaseCounter( state, databitlen );
return SUCCESS;
}
else
{
memcpy( state->buffer+current/8, data, len/8 );
IncreaseCounter( state,len );
databitlen -= len;
data += len/8;
current = 0;
SIMD_Compress( state, state->buffer, 0 );
}
}
}
current = state->count & (state->blocksize - 1);
// If there is still some data in the buffer, hash it
if ( current )
{
// We first need to zero out the end of the buffer.
if ( current & 7 )
{
BitSequence mask = 0xff >> ( current & 7 );
state->buffer[current/8] &= ~mask;
}
current = ( current+7 ) / 8;
memset( state->buffer+current, 0, state->blocksize/8 - current );
SIMD_Compress( state, state->buffer, 0 );
}
//* Input the message length as the last block
memset( state->buffer, 0, state->blocksize / 8 );
l = state->count;
for ( i=0; i<8; i++ )
{
state->buffer[i] = l & 0xff;
l >>= 8;
}
if ( state->count < 16384 )
isshort = 2;
SIMD_Compress( state, state->buffer, isshort );
// Decode the 32-bit words into a BitSequence
for ( i=0; i < 2*state->n_feistels; i++ )
{
u32 x = state->A[i];
out[4*i ] = x&0xff;
x >>= 8;
out[4*i+1] = x&0xff;
x >>= 8;
out[4*i+2] = x&0xff;
x >>= 8;
out[4*i+3] = x&0xff;
}
memcpy( hashval, out, state->hashbitlen / 8 );
if ( state->hashbitlen % 8 )
{
BitSequence mask = 0xff << ( 8 - (state->hashbitlen % 8) );
hashval[state->hashbitlen/8 + 1] = out[state->hashbitlen/8 + 1] & mask;
}
return SUCCESS;
}
/*HashReturn Hash(int hashbitlen, const BitSequence *data, DataLength databitlen,

View File

@@ -55,8 +55,14 @@ typedef struct {
*/
HashReturn init_sd(hashState_sd *state, int hashbitlen);
HashReturn update_sd(hashState_sd *state, const BitSequence *data, DataLength databitlen);
HashReturn final_sd(hashState_sd *state, BitSequence *hashval);
HashReturn update_final_sd( hashState_sd *state, BitSequence *hashval,
const BitSequence *data, DataLength databitlen );
//HashReturn Hash(int hashbitlen, const BitSequence *data, DataLength databitlen,
// BitSequence *hashval);

View File

@@ -105,7 +105,7 @@ void init_tt_ctx()
#ifdef NO_AES_NI
sph_groestl512_init( &tt_ctx.groestl );
#else
init_groestl( &tt_ctx.groestl );
init_groestl( &tt_ctx.groestl, 64 );
#endif
};
@@ -148,8 +148,9 @@ void timetravel_hash(void *output, const void *input)
sph_groestl512( &ctx.groestl, hashA, dataLen );
sph_groestl512_close( &ctx.groestl, hashB );
#else
update_groestl( &ctx.groestl, (char*)hashA, dataLen*8 );
final_groestl( &ctx.groestl, (char*)hashB );
update_and_final_groestl( &ctx.groestl, (char*)hashB,
(char*)hashA, dataLen*8 );
#endif
break;
case 3:
@@ -165,12 +166,12 @@ void timetravel_hash(void *output, const void *input)
sph_keccak512_close( &ctx.keccak, hashB );
break;
case 6:
update_luffa( &ctx.luffa, (const BitSequence*)hashA, dataLen );
final_luffa( &ctx.luffa, (BitSequence*)hashB );
update_and_final_luffa( &ctx.luffa, (BitSequence*)hashB,
(const BitSequence*)hashA, dataLen );
break;
case 7:
cubehashUpdate( &ctx.cube, (const byte*) hashA, dataLen );
cubehashDigest( &ctx.cube, (byte*)hashB );
cubehashUpdateDigest( &ctx.cube, (byte*)hashB,
(const byte*) hashA, dataLen );
break;
default:
break;

View File

@@ -29,30 +29,20 @@ void init_veltor_ctx()
void veltorhash(void *output, const void *input)
{
// sph_skein512_context ctx_skein;
// sph_gost512_context ctx_gost;
// sph_shabal512_context ctx_shabal;
// sph_shavite512_context ctx_shavite;
//these uint512 in the c++ source of the client are backed by an array of uint32
uint32_t _ALIGN(64) hashA[16], hashB[16];
veltor_ctx_holder ctx;
memcpy( &ctx, &veltor_ctx, sizeof(veltor_ctx) );
// sph_skein512_init(&ctx_skein);
sph_skein512(&ctx.skein, input, 80);
sph_skein512_close(&ctx.skein, hashA);
// sph_shavite512_init(&ctx_shavite);
sph_shavite512(&ctx.shavite, hashA, 64);
sph_shavite512_close(&ctx.shavite, hashB);
// sph_shabal512_init(&ctx_shabal);
sph_shabal512(&ctx.shabal, hashB, 64);
sph_shabal512_close(&ctx.shabal, hashA);
// sph_gost512_init(&ctx_gost);
sph_gost512(&ctx.gost, hashA, 64);
sph_gost512_close(&ctx.gost, hashB);

View File

@@ -61,7 +61,7 @@ void init_c11_ctx()
sph_echo512_init( &c11_ctx.echo );
#else
init_echo( &c11_ctx.echo, 512 );
init_groestl( &c11_ctx.groestl );
init_groestl( &c11_ctx.groestl, 64 );
#endif
}

View File

@@ -58,7 +58,7 @@ void init_x11_ctx()
sph_echo512_init( &x11_ctx.echo );
#else
init_echo( &x11_ctx.echo, 512 );
init_groestl( &x11_ctx.groestl );
init_groestl( &x11_ctx.groestl, 64 );
#endif
}

View File

@@ -58,7 +58,7 @@ void init_x11evo_ctx()
sph_echo512_init( &x11evo_ctx.echo );
#else
init_echo( &x11evo_ctx.echo, 512 );
init_groestl( &x11evo_ctx.groestl );
init_groestl( &x11evo_ctx.groestl, 64 );
#endif
init_luffa( &x11evo_ctx.luffa, 512 );
cubehashInit( &x11evo_ctx.cube, 512, 16, 32 );
@@ -76,14 +76,13 @@ uint32_t getCurrentAlgoSeq(uint32_t current_time, uint32_t base_time)
return (current_time - base_time) / (60 * 60 * 24);
}
/*
void swap( uint8_t *a, uint8_t *b )
// swap_vars doesn't work here
void evo_swap( uint8_t *a, uint8_t *b )
{
uint8_t __tmp = *a;
*a = *b;
*b = __tmp;
}
*/
void initPerm( uint8_t n[], uint8_t count )
{
@@ -94,7 +93,7 @@ void initPerm( uint8_t n[], uint8_t count )
int nextPerm( uint8_t n[], uint32_t count )
{
uint32_t tail, i, j;
uint32_t tail = 0, i = 0, j = 0;
if (unlikely( count <= 1 ))
return 0;
@@ -104,10 +103,10 @@ int nextPerm( uint8_t n[], uint32_t count )
if ( tail > 0 )
for ( j = count - 1; j>tail && n[j] <= n[tail - 1]; j-- );
swap_vars( n[tail - 1], n[j] );
evo_swap( &n[tail - 1], &n[j] );
for ( i = tail, j = count - 1; i<j; i++, j-- )
swap_vars( n[i], n[j] );
evo_swap( &n[i], &n[j] );
return ( tail != 0 );
}
@@ -137,14 +136,20 @@ void getAlgoString( char *str, uint32_t count )
//applog(LOG_DEBUG, "nextPerm %s", str);
}
static __thread uint32_t saved_ntime = UINT32_MAX;
void evocoin_twisted_code( char *result, char *code )
{
uint32_t h32, *be32 = get_stratum_job_ntime();
h32 = be32toh(*be32);
uint32_t h32, *be32 = get_stratum_job_ntime();
if ( *be32 != saved_ntime )
{
h32 = be32toh(*be32);
uint32_t count = getCurrentAlgoSeq(h32, INITIAL_DATE);
getAlgoString(code, count);
sprintf(result, "_%d_%s_", count, code);
saved_ntime = *be32;
}
}
static inline void x11evo_hash( void *state, const void *input )
@@ -183,8 +188,10 @@ static inline void x11evo_hash( void *state, const void *input )
sph_groestl512( &ctx.groestl, (char*)hash, size );
sph_groestl512_close( &ctx.groestl, (char*)hash );
#else
update_groestl( &ctx.groestl, (char*)hash, 512 );
final_groestl( &ctx.groestl, (char*)hash );
update_and_final_groestl( &ctx.groestl, (char*)hash,
(const char*)hash, 512 );
// update_groestl( &ctx.groestl, (char*)hash, 512 );
// final_groestl( &ctx.groestl, (char*)hash );
#endif
break;
case 3:
@@ -200,12 +207,16 @@ static inline void x11evo_hash( void *state, const void *input )
sph_keccak512_close( &ctx.keccak, (char*)hash );
break;
case 6:
update_luffa( &ctx.luffa, (char*)hash, 64 );
final_luffa( &ctx.luffa, (char*)hash );
update_and_final_luffa( &ctx.luffa, (char*)hash,
(const char*)hash, 64 );
// update_luffa( &ctx.luffa, (char*)hash, 64 );
// final_luffa( &ctx.luffa, (char*)hash );
break;
case 7:
cubehashUpdate( &ctx.cube, (char*)hash, 64 );
cubehashDigest( &ctx.cube, (char*)hash );
cubehashUpdateDigest( &ctx.cube, (char*)hash,
(const char*)hash, 64 );
// cubehashUpdate( &ctx.cube, (char*)hash, 64 );
// cubehashDigest( &ctx.cube, (char*)hash );
break;
case 8:
sph_shavite512( &ctx.shavite, (char*)hash, size );
@@ -220,8 +231,10 @@ static inline void x11evo_hash( void *state, const void *input )
sph_echo512( &ctx.echo, (char*)hash, size );
sph_echo512_close( &ctx.echo, (char*)hash );
#else
update_echo( &ctx.echo, (char*)hash, 512 );
final_echo( &ctx.echo, (char*)hash );
update_final_echo( &ctx.echo, (char*)hash,
(const char*)hash, 512 );
// update_echo( &ctx.echo, (char*)hash, 512 );
// final_echo( &ctx.echo, (char*)hash );
#endif
break;
}
@@ -246,6 +259,7 @@ int scanhash_x11evo( int thr_id, struct work* work, uint32_t max_nonce,
uint32_t hmask = 0xFFFFFFFF;
if ( Htarg > 0 )
{
if ( Htarg <= 0xF )
hmask = 0xFFFFFFF0;
else if ( Htarg <= 0xFF )
@@ -254,6 +268,7 @@ int scanhash_x11evo( int thr_id, struct work* work, uint32_t max_nonce,
hmask = 0xFFFF000;
else if ( Htarg <= 0xFFFF )
hmask = 0xFFFF000;
}
do
{

View File

@@ -54,7 +54,7 @@ void init_sib_ctx()
sph_echo512_init( &sib_ctx.echo );
#else
init_echo( &sib_ctx.echo, 512 );
init_groestl( &sib_ctx.groestl );
init_groestl( &sib_ctx.groestl, 64 );
#endif
}
@@ -181,4 +181,5 @@ bool register_sib_algo( algo_gate_t* gate )
gate->hash = (void*)&sibhash;
gate->hash_alt = (void*)&sibhash;
gate->get_max64 = (void*)&get_max64_0x3ffff;
return true;
}

View File

@@ -59,7 +59,7 @@ void init_x13_ctx()
sph_echo512_init(&x13_ctx.echo);
#else
init_echo( &x13_ctx.echo, 512 );
init_groestl (&x13_ctx.groestl );
init_groestl (&x13_ctx.groestl, 64 );
#endif
init_luffa( &x13_ctx.luffa, 512 );
cubehashInit( &x13_ctx.cubehash, 512, 16, 32 );

View File

@@ -62,7 +62,7 @@ void init_x14_ctx()
sph_echo512_init(&x14_ctx.echo);
#else
init_echo(&x14_ctx.echo, 512);
init_groestl(&x14_ctx.groestl);
init_groestl(&x14_ctx.groestl, 64 );
#endif
init_luffa(&x14_ctx.luffa,512);
cubehashInit(&x14_ctx.cubehash,512,16,32);

View File

@@ -63,7 +63,7 @@ void init_x15_ctx()
sph_echo512_init(&x15_ctx.echo);
#else
init_echo( &x15_ctx.echo, 512 );
init_groestl( &x15_ctx.groestl );
init_groestl( &x15_ctx.groestl, 64 );
#endif
init_luffa( &x15_ctx.luffa, 512 );
cubehashInit( &x15_ctx.cubehash, 512, 16, 32 );

View File

@@ -63,11 +63,11 @@ x17_ctx_holder x17_ctx;
void init_x17_ctx()
{
#ifdef NO_AES_NI
sph_groestl512_init(&x17_ctx.groestl);
sph_groestl512_init(&x17_ctx.groestl );
sph_echo512_init(&x17_ctx.echo);
#else
init_echo( &x17_ctx.echo, 512 );
init_groestl( &x17_ctx.groestl );
init_groestl( &x17_ctx.groestl, 64 );
#endif
init_luffa( &x17_ctx.luffa, 512 );
cubehashInit( &x17_ctx.cubehash, 512, 16, 32 );

View File

@@ -78,14 +78,14 @@ void init_xevan_ctx()
sph_groestl512_init( &xevan_ctx.groestl );
sph_echo512_init( &xevan_ctx.echo );
#else
init_groestl( &xevan_ctx.groestl );
init_groestl( &xevan_ctx.groestl, 64 );
init_echo( &xevan_ctx.echo, 512 );
#endif
};
void xevan_hash(void *output, const void *input)
{
uint32_t _ALIGN(64) hash[32]; // 128 bytes required
uint32_t _ALIGN(64) hash[32]; // 128 bytes required
const int dataLen = 128;
xevan_ctx_holder ctx;
@@ -103,8 +103,8 @@ void xevan_hash(void *output, const void *input)
sph_groestl512(&ctx.groestl, hash, dataLen);
sph_groestl512_close(&ctx.groestl, hash);
#else
update_groestl( &ctx.groestl, (char*)hash, 1024 );
final_groestl( &ctx.groestl, (char*)hash );
update_and_final_groestl( &ctx.groestl, (char*)hash,
(const char*)hash, dataLen*8 );
#endif
sph_skein512(&ctx.skein, hash, dataLen);
@@ -116,26 +116,24 @@ void xevan_hash(void *output, const void *input)
sph_keccak512(&ctx.keccak, hash, dataLen);
sph_keccak512_close(&ctx.keccak, hash);
update_luffa( &ctx.luffa, (const BitSequence*)hash, dataLen );
final_luffa( &ctx.luffa, (BitSequence*)hash );
// sph_luffa512(&ctx.luffa, hash, dataLen);
// sph_luffa512_close(&ctx.luffa, hash);
update_and_final_luffa( &ctx.luffa, (BitSequence*)hash,
(const BitSequence*)hash, dataLen );
cubehashUpdate( &ctx.cubehash, (const byte*) hash, dataLen );
cubehashDigest( &ctx.cubehash, (byte*)hash);
cubehashUpdateDigest( &ctx.cubehash, (byte*)hash,
(const byte*) hash, dataLen );
sph_shavite512(&ctx.shavite, hash, dataLen);
sph_shavite512_close(&ctx.shavite, hash);
update_sd( &ctx.simd, (const BitSequence *)hash, 1024 );
final_sd( &ctx.simd, (BitSequence *)hash );
update_final_sd( &ctx.simd, (BitSequence *)hash,
(const BitSequence *)hash, dataLen*8 );
#ifdef NO_AES_NI
sph_echo512(&ctx.echo, hash, dataLen);
sph_echo512_close(&ctx.echo, hash);
#else
update_echo ( &ctx.echo, (const BitSequence *) hash, 1024 );
final_echo( &ctx.echo, (BitSequence *) hash );
update_final_echo( &ctx.echo, (BitSequence *) hash,
(const BitSequence *) hash, dataLen*8 );
#endif
sph_hamsi512(&ctx.hamsi, hash, dataLen);
@@ -170,8 +168,8 @@ void xevan_hash(void *output, const void *input)
sph_groestl512(&ctx.groestl, hash, dataLen);
sph_groestl512_close(&ctx.groestl, hash);
#else
update_groestl( &ctx.groestl, (char*)hash, 1024 );
final_groestl( &ctx.groestl, (char*)hash );
update_and_final_groestl( &ctx.groestl, (char*)hash,
(const BitSequence*)hash, dataLen*8 );
#endif
sph_skein512(&ctx.skein, hash, dataLen);
@@ -182,25 +180,24 @@ void xevan_hash(void *output, const void *input)
sph_keccak512(&ctx.keccak, hash, dataLen);
sph_keccak512_close(&ctx.keccak, hash);
update_and_final_luffa( &ctx.luffa, (BitSequence*)hash,
(const BitSequence*)hash, dataLen );
update_luffa( &ctx.luffa, (const BitSequence*)hash, dataLen );
final_luffa( &ctx.luffa, (BitSequence*)hash );
cubehashUpdate( &ctx.cubehash, (const byte*) hash, dataLen );
cubehashDigest( &ctx.cubehash, (byte*)hash);
cubehashUpdateDigest( &ctx.cubehash, (byte*)hash,
(const byte*) hash, dataLen );
sph_shavite512(&ctx.shavite, hash, dataLen);
sph_shavite512_close(&ctx.shavite, hash);
update_sd( &ctx.simd, (const BitSequence *)hash, 1024 );
final_sd( &ctx.simd, (BitSequence *)hash );
update_final_sd( &ctx.simd, (BitSequence *)hash,
(const BitSequence *)hash, dataLen*8 );
#ifdef NO_AES_NI
sph_echo512(&ctx.echo, hash, dataLen);
sph_echo512_close(&ctx.echo, hash);
#else
update_echo ( &ctx.echo, (const BitSequence *) hash, 1024 );
final_echo( &ctx.echo, (BitSequence *) hash );
update_final_echo( &ctx.echo, (BitSequence *) hash,
(const BitSequence *) hash, dataLen*8 );
#endif
sph_hamsi512(&ctx.hamsi, hash, dataLen);

View File

@@ -74,7 +74,7 @@ void init_zr5_ctx()
#ifdef NO_AES_NI
sph_groestl512_init( &zr5_ctx.groestl );
#else
init_groestl( &zr5_ctx.groestl );
init_groestl( &zr5_ctx.groestl, 64 );
#endif
sph_keccak512_init(&zr5_ctx.keccak);
}

View File

@@ -34,6 +34,22 @@ uint16_t v16[ 8];
uint8_t v8 [16];
} area128;
// For cheating with pointer types
// p = any aligned pointer
// returns p as pointer to vector type
#define castp_m256i(p) ((__m256i*)(p))
#define castp_m128i(p) ((__m128i*)(p))
// p = any aligned pointer
// returns *p, watch your pointer arithmetic
#define cast_m256i(p) (*((__m256i*)(p)))
#define cast_m128i(p) (*((__m128i*)(p)))
// p = any aligned pointer, i = scaled array index
// returns p[i]
#define casti_m256i(p,i) (((__m256i*)(p))[(i)])
#define casti_m128i(p,i) (((__m128i*)(p))[(i)])
// useful instrinsics to move data between regs
@@ -77,11 +93,11 @@ uint8_t v8 [16];
0xffffffffffffffffull, \
0xffffffffffffffffull, \
0xffffffffffffffffull ) )
// _mm256_set_epi64x( 0xffffffffffffffffull, \
// 0xffffffffffffffffull, \
// 0xffffffffffffffffull, \
// 0 ) )
/* _mm256_set_epi64x( 0xffffffffffffffffull, \
0xffffffffffffffffull, \
0xffffffffffffffffull, \
0 ) )
*/
#define mm256_slli256_2x64( w ) \
_mm256_and_si256( mm256_swap128( w ), \
@@ -117,10 +133,11 @@ uint8_t v8 [16];
0, \
0, \
0 ) )
// _mm256_set_epi64x( 0, \
// 0, \
// 0, \
// 0xffffffffffffffffull ) )
/* _mm256_set_epi64x( 0, \
0, \
0, \
0xffffffffffffffffull ) )
*/
#endif // AVX2

View File

@@ -1,4 +1,4 @@
AC_INIT([cpuminer-opt], [3.5.3])
AC_INIT([cpuminer-opt], [3.5.4])
AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM

View File

@@ -106,8 +106,8 @@ int opt_n_threads = 0;
int64_t opt_affinity = -1L;
int opt_priority = 0;
int num_cpus;
char *rpc_url;
char *rpc_userpass;
char *rpc_url = NULL;;
char *rpc_userpass = NULL;
char *rpc_user, *rpc_pass;
char *short_url = NULL;
static unsigned char pk_script[25] = { 0 };
@@ -224,6 +224,11 @@ static inline void drop_policy(void) { }
static void affine_to_cpu_mask(int id, unsigned long mask) { }
#endif
// not very useful, just index the arrray directly.
// but declaring this fuinction in miner.h eliminates
// an annoying compiler warning for not using a static.
char* algo_name( enum algos a ) {return algo_names[a];}
void get_currentalgo(char* buf, int sz)
{
snprintf(buf, sz, "%s", algo_names[opt_algo]);
@@ -2375,18 +2380,21 @@ void parse_arg(int key, char *arg )
case 'c': {
json_error_t err;
json_t *config;
if (arg && strstr(arg, "://")) {
if (arg && strstr(arg, "://"))
config = json_load_url(arg, &err);
} else {
else
config = JSON_LOADF(arg, &err);
}
if (!json_is_object(config)) {
if (!json_is_object(config))
{
if (err.line < 0)
fprintf(stderr, "%s\n", err.text);
else
fprintf(stderr, "%s:%d: %s\n",
arg, err.line, err.text);
} else {
}
else
{
parse_config(config, arg);
json_decref(config);
}
@@ -2682,24 +2690,26 @@ void parse_config(json_t *config, char *ref)
static void parse_cmdline(int argc, char *argv[])
{
int key;
int key;
while (1) {
while (1)
{
#if HAVE_GETOPT_LONG
key = getopt_long(argc, argv, short_options, options, NULL);
key = getopt_long(argc, argv, short_options, options, NULL);
#else
key = getopt(argc, argv, short_options);
key = getopt(argc, argv, short_options);
#endif
if (key < 0)
break;
if (key < 0)
break;
parse_arg(key, optarg);
}
if (optind < argc) {
fprintf(stderr, "%s: unsupported non-option argument -- '%s'\n",
argv[0], argv[optind]);
show_usage_and_exit(1);
}
parse_arg(key, optarg);
}
if (optind < argc)
{
fprintf(stderr, "%s: unsupported non-option argument -- '%s'\n",
argv[0], argv[optind]);
show_usage_and_exit(1);
}
}
#ifndef WIN32
@@ -2896,16 +2906,29 @@ int main(int argc, char *argv[])
if (!opt_n_threads)
opt_n_threads = num_cpus;
/*
// All options must be set before starting the gate
if ( !register_algo_gate( opt_algo, &algo_gate ) )
{
exit(1);
}
*/
if ( !check_cpu_capability() )
exit(1);
if ( opt_algo == ALGO_NULL )
{
fprintf(stderr, "%s: no algo supplied\n", argv[0]);
show_usage_and_exit(1);
}
if ( !opt_benchmark )
{
if ( !short_url )
{
fprintf(stderr, "%s: no URL supplied\n", argv[0]);
show_usage_and_exit(1);
}
/*
if ( !rpc_url )
{
// try default config file in binary folder
@@ -2924,6 +2947,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "%s: no URL supplied\n", argv[0]);
show_usage_and_exit(1);
}
*/
}
if (!rpc_userpass)
@@ -2935,6 +2959,10 @@ int main(int argc, char *argv[])
return 1;
}
// All options must be set before starting the gate
if ( !register_algo_gate( opt_algo, &algo_gate ) )
exit(1);
pthread_mutex_init(&stats_lock, NULL);
pthread_mutex_init(&g_work_lock, NULL);
pthread_mutex_init(&rpc2_job_lock, NULL);

View File

@@ -530,7 +530,7 @@ enum algos {
ALGO_ZR5,
ALGO_COUNT
};
static const char *algo_names[] = {
static const char* const algo_names[] = {
NULL,
"argon2",
"axiom",
@@ -589,6 +589,8 @@ static const char *algo_names[] = {
"\0"
};
char* algo_name( enum algos a );
extern enum algos opt_algo;
extern bool opt_debug;
extern bool opt_debug_diff;