mirror of
https://github.com/JayDDee/cpuminer-opt.git
synced 2025-09-17 23:44:27 +00:00
Initial upload v3.4.7
This commit is contained in:
0
algo/blake/.dirstamp
Normal file
0
algo/blake/.dirstamp
Normal file
108
algo/blake/blake.c
Normal file
108
algo/blake/blake.c
Normal file
@@ -0,0 +1,108 @@
|
||||
#include "miner.h"
|
||||
#include "algo-gate-api.h"
|
||||
#include "sph_blake.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
|
||||
/* Move init out of loop, so init once externally,
|
||||
* and then use one single memcpy */
|
||||
static __thread sph_blake256_context blake_mid;
|
||||
static __thread bool ctx_midstate_done = false;
|
||||
|
||||
static void init_blake_hash(void)
|
||||
{
|
||||
sph_blake256_init(&blake_mid);
|
||||
ctx_midstate_done = true;
|
||||
}
|
||||
|
||||
void blakehash(void *state, const void *input)
|
||||
{
|
||||
sph_blake256_context ctx;
|
||||
|
||||
uint8_t hash[64];
|
||||
uint8_t *ending = (uint8_t*) input;
|
||||
ending += 64;
|
||||
|
||||
// do one memcopy to get a fresh context
|
||||
if (!ctx_midstate_done) {
|
||||
init_blake_hash();
|
||||
sph_blake256(&blake_mid, input, 64);
|
||||
}
|
||||
|
||||
memcpy(&ctx, &blake_mid, sizeof(blake_mid));
|
||||
|
||||
sph_blake256(&ctx, ending, 16);
|
||||
sph_blake256_close(&ctx, hash);
|
||||
|
||||
memcpy(state, hash, 32);
|
||||
|
||||
}
|
||||
|
||||
int scanhash_blake( 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 HTarget = ptarget[7];
|
||||
uint32_t _ALIGN(32) hash64[8];
|
||||
uint32_t _ALIGN(32) endiandata[20];
|
||||
uint32_t n = first_nonce;
|
||||
|
||||
ctx_midstate_done = false;
|
||||
|
||||
if (opt_benchmark)
|
||||
HTarget = 0x7f;
|
||||
|
||||
// we need big endian data...
|
||||
swab32_array( endiandata, pdata, 20 );
|
||||
|
||||
#ifdef DEBUG_ALGO
|
||||
applog(LOG_DEBUG,"[%d] Target=%08x %08x", thr_id, ptarget[6], ptarget[7]);
|
||||
#endif
|
||||
|
||||
do {
|
||||
be32enc(&endiandata[19], n);
|
||||
blakehash(hash64, endiandata);
|
||||
#ifndef DEBUG_ALGO
|
||||
if (hash64[7] <= HTarget && fulltest(hash64, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
if (!(n % 0x1000) && !thr_id) printf(".");
|
||||
if (hash64[7] == 0) {
|
||||
printf("[%d]",thr_id);
|
||||
if (fulltest(hash64, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
n++; pdata[19] = n;
|
||||
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// changed to get_max64_0x3fffffLL in cpuminer-multi-decred
|
||||
int64_t blake_get_max64 ()
|
||||
{
|
||||
return 0x7ffffLL;
|
||||
}
|
||||
|
||||
bool register_blake_algo( algo_gate_t* gate )
|
||||
{
|
||||
gate->scanhash = (void*)&scanhash_blake;
|
||||
gate->hash = (void*)&blakehash;
|
||||
gate->hash_alt = (void*)&blakehash;
|
||||
gate->get_max64 = (void*)&blake_get_max64;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
85
algo/blake/blake2.c
Normal file
85
algo/blake/blake2.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "miner.h"
|
||||
#include "algo-gate-api.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "crypto/blake2s.h"
|
||||
|
||||
static __thread blake2s_state s_midstate;
|
||||
static __thread blake2s_state s_ctx;
|
||||
#define MIDLEN 76
|
||||
|
||||
void blake2s_hash(void *output, const void *input)
|
||||
{
|
||||
unsigned char _ALIGN(64) hash[BLAKE2S_OUTBYTES];
|
||||
blake2s_state blake2_ctx;
|
||||
|
||||
blake2s_init(&blake2_ctx, BLAKE2S_OUTBYTES);
|
||||
blake2s_update(&blake2_ctx, input, 80);
|
||||
blake2s_final(&blake2_ctx, hash, BLAKE2S_OUTBYTES);
|
||||
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
static void blake2s_hash_end(uint32_t *output, const uint32_t *input)
|
||||
{
|
||||
s_ctx.buflen = MIDLEN;
|
||||
memcpy(&s_ctx, &s_midstate, 32 + 16 + MIDLEN);
|
||||
blake2s_update(&s_ctx, (uint8_t*) &input[MIDLEN/4], 80 - MIDLEN);
|
||||
blake2s_final(&s_ctx, (uint8_t*) output, BLAKE2S_OUTBYTES);
|
||||
}
|
||||
|
||||
int scanhash_blake2s(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 _ALIGN(64) hash64[8];
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
|
||||
uint32_t n = first_nonce;
|
||||
|
||||
swab32_array( endiandata, pdata, 20 );
|
||||
|
||||
// midstate
|
||||
blake2s_init(&s_midstate, BLAKE2S_OUTBYTES);
|
||||
blake2s_update(&s_midstate, (uint8_t*) endiandata, MIDLEN);
|
||||
memcpy(&s_ctx, &s_midstate, sizeof(blake2s_state));
|
||||
|
||||
do {
|
||||
be32enc(&endiandata[19], n);
|
||||
blake2s_hash_end(hash64, endiandata);
|
||||
if (hash64[7] < Htarg && fulltest(hash64, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return true;
|
||||
}
|
||||
n++;
|
||||
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// changed to get_max64_0x3fffffLL in cpuminer-multi-decred
|
||||
int64_t blake2s_get_max64 ()
|
||||
{
|
||||
return 0x7ffffLL;
|
||||
}
|
||||
|
||||
bool register_blake2s_algo( algo_gate_t* gate )
|
||||
{
|
||||
gate->scanhash = (void*)&scanhash_blake2s;
|
||||
gate->hash = (void*)&blake2s_hash;
|
||||
gate->get_max64 = (void*)&blake2s_get_max64;
|
||||
return true;
|
||||
};
|
||||
|
||||
129
algo/blake/blakecoin.c
Normal file
129
algo/blake/blakecoin.c
Normal file
@@ -0,0 +1,129 @@
|
||||
#include "miner.h"
|
||||
#include "algo-gate-api.h"
|
||||
#define BLAKE32_ROUNDS 8
|
||||
#include "sph_blake.h"
|
||||
|
||||
void blakecoin_init(void *cc);
|
||||
void blakecoin(void *cc, const void *data, size_t len);
|
||||
void blakecoin_close(void *cc, void *dst);
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
/* Move init out of loop, so init once externally,
|
||||
* and then use one single memcpy */
|
||||
static sph_blake256_context blake_mid;
|
||||
static bool ctx_midstate_done = false;
|
||||
|
||||
static void init_blake_hash(void)
|
||||
{
|
||||
blakecoin_init(&blake_mid);
|
||||
ctx_midstate_done = true;
|
||||
}
|
||||
|
||||
void blakecoinhash(void *state, const void *input)
|
||||
{
|
||||
sph_blake256_context ctx;
|
||||
|
||||
uint8_t hash[64];
|
||||
uint8_t *ending = (uint8_t*) input;
|
||||
ending += 64;
|
||||
|
||||
// do one memcopy to get a fresh context
|
||||
if (!ctx_midstate_done) {
|
||||
init_blake_hash();
|
||||
blakecoin(&blake_mid, input, 64);
|
||||
}
|
||||
memcpy(&ctx, &blake_mid, sizeof(blake_mid));
|
||||
|
||||
blakecoin(&ctx, ending, 16);
|
||||
blakecoin_close(&ctx, hash);
|
||||
|
||||
memcpy(state, hash, 32);
|
||||
}
|
||||
|
||||
int scanhash_blakecoin(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 HTarget = ptarget[7];
|
||||
|
||||
uint32_t _ALIGN(32) hash64[8];
|
||||
uint32_t _ALIGN(32) endiandata[20];
|
||||
|
||||
uint32_t n = first_nonce;
|
||||
|
||||
ctx_midstate_done = false;
|
||||
|
||||
if (opt_benchmark)
|
||||
HTarget = 0x7f;
|
||||
|
||||
// we need big endian data...
|
||||
// be32enc_array( endiandata, pdata, 19 );
|
||||
for (int kk=0; kk < 19; kk++)
|
||||
be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
|
||||
|
||||
|
||||
#ifdef DEBUG_ALGO
|
||||
applog(LOG_DEBUG,"[%d] Target=%08x %08x", thr_id, ptarget[6], ptarget[7]);
|
||||
#endif
|
||||
|
||||
do {
|
||||
be32enc(&endiandata[19], n);
|
||||
blakecoinhash(hash64, endiandata);
|
||||
#ifndef DEBUG_ALGO
|
||||
if (hash64[7] <= HTarget && fulltest(hash64, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
if (!(n % 0x1000) && !thr_id) printf(".");
|
||||
if (hash64[7] == 0) {
|
||||
printf("[%d]",thr_id);
|
||||
if (fulltest(hash64, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
n++; pdata[19] = n;
|
||||
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void blakecoin_gen_merkle_root ( char* merkle_root, struct stratum_ctx* sctx )
|
||||
{
|
||||
SHA256( sctx->job.coinbase, (int)sctx->job.coinbase_size, merkle_root );
|
||||
}
|
||||
|
||||
// changed to get_max64_0x3fffffLL in cpuminer-multi-decred
|
||||
int64_t blakecoin_get_max64 ()
|
||||
{
|
||||
return 0x7ffffLL;
|
||||
}
|
||||
|
||||
// vanilla uses default gen merkle root, otherwise identical to blakecoin
|
||||
bool register_vanilla_algo( algo_gate_t* gate )
|
||||
{
|
||||
gate->scanhash = (void*)&scanhash_blakecoin;
|
||||
gate->hash = (void*)&blakecoinhash;
|
||||
gate->hash_alt = (void*)&blakecoinhash;
|
||||
gate->get_max64 = (void*)&blakecoin_get_max64;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool register_blakecoin_algo( algo_gate_t* gate )
|
||||
{
|
||||
register_vanilla_algo( gate );
|
||||
gate->gen_merkle_root = (void*)&SHA256_gen_merkle_root;
|
||||
return true;
|
||||
}
|
||||
|
||||
248
algo/blake/decred.c
Normal file
248
algo/blake/decred.c
Normal file
@@ -0,0 +1,248 @@
|
||||
#include "miner.h"
|
||||
#include "algo-gate-api.h"
|
||||
#include "sph_blake.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) (a>b ? b : a)
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a,b) (a<b ? b : a)
|
||||
#endif
|
||||
|
||||
#define DECRED_NBITS_INDEX 29
|
||||
#define DECRED_NTIME_INDEX 34
|
||||
#define DECRED_NONCE_INDEX 35
|
||||
#define DECRED_XNONCE_INDEX 36
|
||||
#define DECRED_DATA_SIZE 192
|
||||
#define DECRED_WORK_COMPARE_SIZE 140
|
||||
|
||||
static __thread sph_blake256_context blake_mid;
|
||||
static __thread bool ctx_midstate_done = false;
|
||||
|
||||
void decred_hash(void *state, const void *input)
|
||||
{
|
||||
#define MIDSTATE_LEN 128
|
||||
sph_blake256_context ctx;
|
||||
|
||||
uint8_t *ending = (uint8_t*) input;
|
||||
ending += MIDSTATE_LEN;
|
||||
|
||||
if (!ctx_midstate_done) {
|
||||
sph_blake256_init(&blake_mid);
|
||||
sph_blake256(&blake_mid, input, MIDSTATE_LEN);
|
||||
ctx_midstate_done = true;
|
||||
}
|
||||
memcpy(&ctx, &blake_mid, sizeof(blake_mid));
|
||||
|
||||
sph_blake256(&ctx, ending, (180 - MIDSTATE_LEN));
|
||||
sph_blake256_close(&ctx, state);
|
||||
}
|
||||
|
||||
void decred_hash_simple(void *state, const void *input)
|
||||
{
|
||||
sph_blake256_context ctx;
|
||||
sph_blake256_init(&ctx);
|
||||
sph_blake256(&ctx, input, 180);
|
||||
sph_blake256_close(&ctx, state);
|
||||
}
|
||||
|
||||
int scanhash_decred(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(128) endiandata[48];
|
||||
uint32_t _ALIGN(128) hash32[8];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
|
||||
#define DCR_NONCE_OFT32 35
|
||||
|
||||
const uint32_t first_nonce = pdata[DCR_NONCE_OFT32];
|
||||
const uint32_t HTarget = opt_benchmark ? 0x7f : ptarget[7];
|
||||
|
||||
uint32_t n = first_nonce;
|
||||
|
||||
ctx_midstate_done = false;
|
||||
|
||||
#if 1
|
||||
memcpy(endiandata, pdata, 180);
|
||||
#else
|
||||
for (int k=0; k < (180/4); k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_ALGO
|
||||
if (!thr_id) applog(LOG_DEBUG,"[%d] Target=%08x %08x", thr_id, ptarget[6], ptarget[7]);
|
||||
#endif
|
||||
|
||||
do {
|
||||
//be32enc(&endiandata[DCR_NONCE_OFT32], n);
|
||||
endiandata[DCR_NONCE_OFT32] = n;
|
||||
decred_hash(hash32, endiandata);
|
||||
|
||||
if (hash32[7] <= HTarget && fulltest(hash32, ptarget)) {
|
||||
work_set_target_ratio(work, hash32);
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
#ifdef DEBUG_ALGO
|
||||
applog(LOG_BLUE, "Nonce : %08x %08x", n, swab32(n));
|
||||
applog_hash(ptarget);
|
||||
applog_compare_hash(hash32, ptarget);
|
||||
#endif
|
||||
pdata[DCR_NONCE_OFT32] = n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
n++;
|
||||
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[DCR_NONCE_OFT32] = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t *decred_get_nonceptr( uint32_t *work_data )
|
||||
{
|
||||
return &work_data[ DECRED_NONCE_INDEX ];
|
||||
}
|
||||
|
||||
// does decred need a custom stratum_get_g_work to fix nicehash
|
||||
// bad extranonce2 size?
|
||||
//
|
||||
// does decred need a custom init_nonce?
|
||||
// does it need to increment nonce, seems not because gen_work_now always
|
||||
// returns true
|
||||
|
||||
void decred_calc_network_diff( struct work* work )
|
||||
{
|
||||
// sample for diff 43.281 : 1c05ea29
|
||||
// todo: endian reversed on longpoll could be zr5 specific...
|
||||
uint32_t nbits = work->data[ DECRED_NBITS_INDEX ];
|
||||
uint32_t bits = ( nbits & 0xffffff );
|
||||
int16_t shift = ( swab32(nbits) & 0xff ); // 0x1c = 28
|
||||
int m;
|
||||
net_diff = (double)0x0000ffff / (double)bits;
|
||||
|
||||
for ( m = shift; m < 29; m++ )
|
||||
net_diff *= 256.0;
|
||||
for ( m = 29; m < shift; m++ )
|
||||
net_diff /= 256.0;
|
||||
if ( shift == 28 )
|
||||
net_diff *= 256.0; // testnet
|
||||
if ( opt_debug_diff )
|
||||
applog( LOG_DEBUG, "net diff: %f -> shift %u, bits %08x", net_diff,
|
||||
shift, bits);
|
||||
}
|
||||
|
||||
void decred_decode_extradata( struct work* work, uint64_t* net_blocks )
|
||||
{
|
||||
// some random extradata to make the work unique
|
||||
work->data[ DECRED_XNONCE_INDEX ] = (rand()*4);
|
||||
work->height = work->data[32];
|
||||
if (!have_longpoll && work->height > *net_blocks + 1)
|
||||
{
|
||||
char netinfo[64] = { 0 };
|
||||
if (opt_showdiff && net_diff > 0.)
|
||||
{
|
||||
if (net_diff != work->targetdiff)
|
||||
sprintf(netinfo, ", diff %.3f, target %.1f", net_diff,
|
||||
work->targetdiff);
|
||||
else
|
||||
sprintf(netinfo, ", diff %.3f", net_diff);
|
||||
}
|
||||
applog(LOG_BLUE, "%s block %d%s", algo_names[opt_algo], work->height,
|
||||
netinfo);
|
||||
*net_blocks = work->height - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void decred_be_build_stratum_request( char *req, struct work *work,
|
||||
struct stratum_ctx *sctx )
|
||||
{
|
||||
unsigned char *xnonce2str;
|
||||
uint32_t ntime, nonce;
|
||||
char ntimestr[9], noncestr[9];
|
||||
|
||||
be32enc( &ntime, work->data[ DECRED_NTIME_INDEX ] );
|
||||
be32enc( &nonce, work->data[ DECRED_NONCE_INDEX ] );
|
||||
bin2hex( ntimestr, (char*)(&ntime), sizeof(uint32_t) );
|
||||
bin2hex( noncestr, (char*)(&nonce), sizeof(uint32_t) );
|
||||
xnonce2str = abin2hex( (char*)( &work->data[ DECRED_XNONCE_INDEX ] ),
|
||||
sctx->xnonce1_size );
|
||||
snprintf( req, JSON_BUF_LEN,
|
||||
"{\"method\": \"mining.submit\", \"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\":4}",
|
||||
rpc_user, work->job_id, xnonce2str, ntimestr, noncestr );
|
||||
free(xnonce2str);
|
||||
}
|
||||
|
||||
// data shared between gen_merkle_root and build_extraheader.
|
||||
uint32_t decred_extraheader[32] = { 0 };
|
||||
int decred_headersize = 0;
|
||||
|
||||
void decred_gen_merkle_root( char* merkle_root, struct stratum_ctx* sctx )
|
||||
{
|
||||
// getwork over stratum, getwork merkle + header passed in coinb1
|
||||
memcpy(merkle_root, sctx->job.coinbase, 32);
|
||||
decred_headersize = min((int)sctx->job.coinbase_size - 32,
|
||||
sizeof(decred_extraheader) );
|
||||
memcpy( decred_extraheader, &sctx->job.coinbase[32], decred_headersize);
|
||||
}
|
||||
|
||||
void decred_build_extraheader( struct work* work, struct stratum_ctx* sctx )
|
||||
{
|
||||
uint32_t* extradata = (uint32_t*) sctx->xnonce1;
|
||||
int i;
|
||||
for ( i = 0; i < 8; i++ ) // prevhash
|
||||
work->data[1 + i] = swab32( work->data[1 + i] );
|
||||
for ( i = 0; i < 8; i++ ) // merkle
|
||||
work->data[9 + i] = swab32( work->data[9 + i] );
|
||||
for ( i = 0; i < decred_headersize/4; i++ ) // header
|
||||
work->data[17 + i] = decred_extraheader[i];
|
||||
// extradata
|
||||
for ( i = 0; i < sctx->xnonce1_size/4; i++ )
|
||||
work->data[ DECRED_XNONCE_INDEX + i ] = extradata[i];
|
||||
for ( i = DECRED_XNONCE_INDEX + sctx->xnonce1_size/4; i < 45; i++ )
|
||||
work->data[i] = 0;
|
||||
work->data[37] = (rand()*4) << 8;
|
||||
sctx->bloc_height = work->data[32];
|
||||
//applog_hex(work->data, 180);
|
||||
//applog_hex(&work->data[36], 36);
|
||||
}
|
||||
|
||||
bool decred_prevent_dupes( struct work* work, struct stratum_ctx* stratum,
|
||||
int thr_id )
|
||||
{
|
||||
if ( have_stratum && strcmp(stratum->job.job_id, work->job_id) )
|
||||
// need to regen g_work..
|
||||
return true;
|
||||
// extradata: prevent duplicates
|
||||
work->data[ DECRED_XNONCE_INDEX ] += 1;
|
||||
work->data[ DECRED_XNONCE_INDEX + 1 ] |= thr_id;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool register_decred_algo( algo_gate_t* gate )
|
||||
{
|
||||
gate->optimizations = SSE2_OPT;
|
||||
gate->scanhash = (void*)&scanhash_decred;
|
||||
gate->hash = (void*)&decred_hash;
|
||||
gate->hash_alt = (void*)&decred_hash;
|
||||
gate->get_nonceptr = (void*)&decred_get_nonceptr;
|
||||
gate->get_max64 = (void*)&get_max64_0x3fffffLL;
|
||||
gate->display_extra_data = (void*)&decred_decode_extradata;
|
||||
gate->build_stratum_request = (void*)&decred_be_build_stratum_request;
|
||||
gate->gen_merkle_root = (void*)&decred_gen_merkle_root;
|
||||
gate->build_extraheader = (void*)&decred_build_extraheader;
|
||||
gate->prevent_dupes = (void*)&decred_prevent_dupes;
|
||||
gate->nbits_index = DECRED_NBITS_INDEX;
|
||||
gate->ntime_index = DECRED_NTIME_INDEX;
|
||||
gate->nonce_index = DECRED_NONCE_INDEX;
|
||||
gate->work_data_size = DECRED_DATA_SIZE;
|
||||
gate->work_cmp_size = DECRED_WORK_COMPARE_SIZE;
|
||||
allow_mininginfo = false;
|
||||
have_gbt = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
531
algo/blake/mod_blakecoin.c
Normal file
531
algo/blake/mod_blakecoin.c
Normal file
@@ -0,0 +1,531 @@
|
||||
/* $Id: blake.c 252 2011-06-07 17:55:14Z tp $ */
|
||||
/*
|
||||
* BLAKECOIN implementation. (Stripped to 256 bits only)
|
||||
*
|
||||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* ===========================(LICENSE END)=============================
|
||||
*
|
||||
* @author Thomas Pornin <thomas.pornin@cryptolog.com>
|
||||
* @author Tanguy Pruvot (cpuminer implementation)
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "sph_blake.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable: 4146)
|
||||
#endif
|
||||
|
||||
static const sph_u32 IV256[8] = {
|
||||
SPH_C32(0x6A09E667), SPH_C32(0xBB67AE85),
|
||||
SPH_C32(0x3C6EF372), SPH_C32(0xA54FF53A),
|
||||
SPH_C32(0x510E527F), SPH_C32(0x9B05688C),
|
||||
SPH_C32(0x1F83D9AB), SPH_C32(0x5BE0CD19)
|
||||
};
|
||||
|
||||
#define Z00 0
|
||||
#define Z01 1
|
||||
#define Z02 2
|
||||
#define Z03 3
|
||||
#define Z04 4
|
||||
#define Z05 5
|
||||
#define Z06 6
|
||||
#define Z07 7
|
||||
#define Z08 8
|
||||
#define Z09 9
|
||||
#define Z0A A
|
||||
#define Z0B B
|
||||
#define Z0C C
|
||||
#define Z0D D
|
||||
#define Z0E E
|
||||
#define Z0F F
|
||||
|
||||
#define Z10 E
|
||||
#define Z11 A
|
||||
#define Z12 4
|
||||
#define Z13 8
|
||||
#define Z14 9
|
||||
#define Z15 F
|
||||
#define Z16 D
|
||||
#define Z17 6
|
||||
#define Z18 1
|
||||
#define Z19 C
|
||||
#define Z1A 0
|
||||
#define Z1B 2
|
||||
#define Z1C B
|
||||
#define Z1D 7
|
||||
#define Z1E 5
|
||||
#define Z1F 3
|
||||
|
||||
#define Z20 B
|
||||
#define Z21 8
|
||||
#define Z22 C
|
||||
#define Z23 0
|
||||
#define Z24 5
|
||||
#define Z25 2
|
||||
#define Z26 F
|
||||
#define Z27 D
|
||||
#define Z28 A
|
||||
#define Z29 E
|
||||
#define Z2A 3
|
||||
#define Z2B 6
|
||||
#define Z2C 7
|
||||
#define Z2D 1
|
||||
#define Z2E 9
|
||||
#define Z2F 4
|
||||
|
||||
#define Z30 7
|
||||
#define Z31 9
|
||||
#define Z32 3
|
||||
#define Z33 1
|
||||
#define Z34 D
|
||||
#define Z35 C
|
||||
#define Z36 B
|
||||
#define Z37 E
|
||||
#define Z38 2
|
||||
#define Z39 6
|
||||
#define Z3A 5
|
||||
#define Z3B A
|
||||
#define Z3C 4
|
||||
#define Z3D 0
|
||||
#define Z3E F
|
||||
#define Z3F 8
|
||||
|
||||
#define Z40 9
|
||||
#define Z41 0
|
||||
#define Z42 5
|
||||
#define Z43 7
|
||||
#define Z44 2
|
||||
#define Z45 4
|
||||
#define Z46 A
|
||||
#define Z47 F
|
||||
#define Z48 E
|
||||
#define Z49 1
|
||||
#define Z4A B
|
||||
#define Z4B C
|
||||
#define Z4C 6
|
||||
#define Z4D 8
|
||||
#define Z4E 3
|
||||
#define Z4F D
|
||||
|
||||
#define Z50 2
|
||||
#define Z51 C
|
||||
#define Z52 6
|
||||
#define Z53 A
|
||||
#define Z54 0
|
||||
#define Z55 B
|
||||
#define Z56 8
|
||||
#define Z57 3
|
||||
#define Z58 4
|
||||
#define Z59 D
|
||||
#define Z5A 7
|
||||
#define Z5B 5
|
||||
#define Z5C F
|
||||
#define Z5D E
|
||||
#define Z5E 1
|
||||
#define Z5F 9
|
||||
|
||||
#define Z60 C
|
||||
#define Z61 5
|
||||
#define Z62 1
|
||||
#define Z63 F
|
||||
#define Z64 E
|
||||
#define Z65 D
|
||||
#define Z66 4
|
||||
#define Z67 A
|
||||
#define Z68 0
|
||||
#define Z69 7
|
||||
#define Z6A 6
|
||||
#define Z6B 3
|
||||
#define Z6C 9
|
||||
#define Z6D 2
|
||||
#define Z6E 8
|
||||
#define Z6F B
|
||||
|
||||
#define Z70 D
|
||||
#define Z71 B
|
||||
#define Z72 7
|
||||
#define Z73 E
|
||||
#define Z74 C
|
||||
#define Z75 1
|
||||
#define Z76 3
|
||||
#define Z77 9
|
||||
#define Z78 5
|
||||
#define Z79 0
|
||||
#define Z7A F
|
||||
#define Z7B 4
|
||||
#define Z7C 8
|
||||
#define Z7D 6
|
||||
#define Z7E 2
|
||||
#define Z7F A
|
||||
|
||||
#define Z80 6
|
||||
#define Z81 F
|
||||
#define Z82 E
|
||||
#define Z83 9
|
||||
#define Z84 B
|
||||
#define Z85 3
|
||||
#define Z86 0
|
||||
#define Z87 8
|
||||
#define Z88 C
|
||||
#define Z89 2
|
||||
#define Z8A D
|
||||
#define Z8B 7
|
||||
#define Z8C 1
|
||||
#define Z8D 4
|
||||
#define Z8E A
|
||||
#define Z8F 5
|
||||
|
||||
#define Z90 A
|
||||
#define Z91 2
|
||||
#define Z92 8
|
||||
#define Z93 4
|
||||
#define Z94 7
|
||||
#define Z95 6
|
||||
#define Z96 1
|
||||
#define Z97 5
|
||||
#define Z98 F
|
||||
#define Z99 B
|
||||
#define Z9A 9
|
||||
#define Z9B E
|
||||
#define Z9C 3
|
||||
#define Z9D C
|
||||
#define Z9E D
|
||||
#define Z9F 0
|
||||
|
||||
#define Mx(r, i) Mx_(Z ## r ## i)
|
||||
#define Mx_(n) Mx__(n)
|
||||
#define Mx__(n) M ## n
|
||||
|
||||
#define CSx(r, i) CSx_(Z ## r ## i)
|
||||
#define CSx_(n) CSx__(n)
|
||||
#define CSx__(n) CS ## n
|
||||
|
||||
#define CS0 SPH_C32(0x243F6A88)
|
||||
#define CS1 SPH_C32(0x85A308D3)
|
||||
#define CS2 SPH_C32(0x13198A2E)
|
||||
#define CS3 SPH_C32(0x03707344)
|
||||
#define CS4 SPH_C32(0xA4093822)
|
||||
#define CS5 SPH_C32(0x299F31D0)
|
||||
#define CS6 SPH_C32(0x082EFA98)
|
||||
#define CS7 SPH_C32(0xEC4E6C89)
|
||||
#define CS8 SPH_C32(0x452821E6)
|
||||
#define CS9 SPH_C32(0x38D01377)
|
||||
#define CSA SPH_C32(0xBE5466CF)
|
||||
#define CSB SPH_C32(0x34E90C6C)
|
||||
#define CSC SPH_C32(0xC0AC29B7)
|
||||
#define CSD SPH_C32(0xC97C50DD)
|
||||
#define CSE SPH_C32(0x3F84D5B5)
|
||||
#define CSF SPH_C32(0xB5470917)
|
||||
|
||||
#if SPH_64
|
||||
|
||||
#define CBx(r, i) CBx_(Z ## r ## i)
|
||||
#define CBx_(n) CBx__(n)
|
||||
#define CBx__(n) CB ## n
|
||||
|
||||
#define CB0 SPH_C64(0x243F6A8885A308D3)
|
||||
#define CB1 SPH_C64(0x13198A2E03707344)
|
||||
#define CB2 SPH_C64(0xA4093822299F31D0)
|
||||
#define CB3 SPH_C64(0x082EFA98EC4E6C89)
|
||||
#define CB4 SPH_C64(0x452821E638D01377)
|
||||
#define CB5 SPH_C64(0xBE5466CF34E90C6C)
|
||||
#define CB6 SPH_C64(0xC0AC29B7C97C50DD)
|
||||
#define CB7 SPH_C64(0x3F84D5B5B5470917)
|
||||
#define CB8 SPH_C64(0x9216D5D98979FB1B)
|
||||
#define CB9 SPH_C64(0xD1310BA698DFB5AC)
|
||||
#define CBA SPH_C64(0x2FFD72DBD01ADFB7)
|
||||
#define CBB SPH_C64(0xB8E1AFED6A267E96)
|
||||
#define CBC SPH_C64(0xBA7C9045F12C7F99)
|
||||
#define CBD SPH_C64(0x24A19947B3916CF7)
|
||||
#define CBE SPH_C64(0x0801F2E2858EFC16)
|
||||
#define CBF SPH_C64(0x636920D871574E69)
|
||||
|
||||
#endif
|
||||
|
||||
#define GS(m0, m1, c0, c1, a, b, c, d) do { \
|
||||
a = SPH_T32(a + b + (m0 ^ c1)); \
|
||||
d = SPH_ROTR32(d ^ a, 16); \
|
||||
c = SPH_T32(c + d); \
|
||||
b = SPH_ROTR32(b ^ c, 12); \
|
||||
a = SPH_T32(a + b + (m1 ^ c0)); \
|
||||
d = SPH_ROTR32(d ^ a, 8); \
|
||||
c = SPH_T32(c + d); \
|
||||
b = SPH_ROTR32(b ^ c, 7); \
|
||||
} while (0)
|
||||
|
||||
#define ROUND_S(r) do { \
|
||||
GS(Mx(r, 0), Mx(r, 1), CSx(r, 0), CSx(r, 1), V0, V4, V8, VC); \
|
||||
GS(Mx(r, 2), Mx(r, 3), CSx(r, 2), CSx(r, 3), V1, V5, V9, VD); \
|
||||
GS(Mx(r, 4), Mx(r, 5), CSx(r, 4), CSx(r, 5), V2, V6, VA, VE); \
|
||||
GS(Mx(r, 6), Mx(r, 7), CSx(r, 6), CSx(r, 7), V3, V7, VB, VF); \
|
||||
GS(Mx(r, 8), Mx(r, 9), CSx(r, 8), CSx(r, 9), V0, V5, VA, VF); \
|
||||
GS(Mx(r, A), Mx(r, B), CSx(r, A), CSx(r, B), V1, V6, VB, VC); \
|
||||
GS(Mx(r, C), Mx(r, D), CSx(r, C), CSx(r, D), V2, V7, V8, VD); \
|
||||
GS(Mx(r, E), Mx(r, F), CSx(r, E), CSx(r, F), V3, V4, V9, VE); \
|
||||
} while (0)
|
||||
|
||||
#define DECL_STATE32 \
|
||||
sph_u32 H0, H1, H2, H3, H4, H5, H6, H7; \
|
||||
sph_u32 S0, S1, S2, S3, T0, T1;
|
||||
|
||||
#define READ_STATE32(state) do { \
|
||||
H0 = (state)->H[0]; \
|
||||
H1 = (state)->H[1]; \
|
||||
H2 = (state)->H[2]; \
|
||||
H3 = (state)->H[3]; \
|
||||
H4 = (state)->H[4]; \
|
||||
H5 = (state)->H[5]; \
|
||||
H6 = (state)->H[6]; \
|
||||
H7 = (state)->H[7]; \
|
||||
S0 = (state)->S[0]; \
|
||||
S1 = (state)->S[1]; \
|
||||
S2 = (state)->S[2]; \
|
||||
S3 = (state)->S[3]; \
|
||||
T0 = (state)->T0; \
|
||||
T1 = (state)->T1; \
|
||||
} while (0)
|
||||
|
||||
#define WRITE_STATE32(state) do { \
|
||||
(state)->H[0] = H0; \
|
||||
(state)->H[1] = H1; \
|
||||
(state)->H[2] = H2; \
|
||||
(state)->H[3] = H3; \
|
||||
(state)->H[4] = H4; \
|
||||
(state)->H[5] = H5; \
|
||||
(state)->H[6] = H6; \
|
||||
(state)->H[7] = H7; \
|
||||
(state)->S[0] = S0; \
|
||||
(state)->S[1] = S1; \
|
||||
(state)->S[2] = S2; \
|
||||
(state)->S[3] = S3; \
|
||||
(state)->T0 = T0; \
|
||||
(state)->T1 = T1; \
|
||||
} while (0)
|
||||
|
||||
#define BLAKE32_ROUNDS 8
|
||||
|
||||
#define COMPRESS32 do { \
|
||||
sph_u32 M0, M1, M2, M3, M4, M5, M6, M7; \
|
||||
sph_u32 M8, M9, MA, MB, MC, MD, ME, MF; \
|
||||
sph_u32 V0, V1, V2, V3, V4, V5, V6, V7; \
|
||||
sph_u32 V8, V9, VA, VB, VC, VD, VE, VF; \
|
||||
V0 = H0; \
|
||||
V1 = H1; \
|
||||
V2 = H2; \
|
||||
V3 = H3; \
|
||||
V4 = H4; \
|
||||
V5 = H5; \
|
||||
V6 = H6; \
|
||||
V7 = H7; \
|
||||
V8 = S0 ^ CS0; \
|
||||
V9 = S1 ^ CS1; \
|
||||
VA = S2 ^ CS2; \
|
||||
VB = S3 ^ CS3; \
|
||||
VC = T0 ^ CS4; \
|
||||
VD = T0 ^ CS5; \
|
||||
VE = T1 ^ CS6; \
|
||||
VF = T1 ^ CS7; \
|
||||
M0 = sph_dec32be_aligned(buf + 0); \
|
||||
M1 = sph_dec32be_aligned(buf + 4); \
|
||||
M2 = sph_dec32be_aligned(buf + 8); \
|
||||
M3 = sph_dec32be_aligned(buf + 12); \
|
||||
M4 = sph_dec32be_aligned(buf + 16); \
|
||||
M5 = sph_dec32be_aligned(buf + 20); \
|
||||
M6 = sph_dec32be_aligned(buf + 24); \
|
||||
M7 = sph_dec32be_aligned(buf + 28); \
|
||||
M8 = sph_dec32be_aligned(buf + 32); \
|
||||
M9 = sph_dec32be_aligned(buf + 36); \
|
||||
MA = sph_dec32be_aligned(buf + 40); \
|
||||
MB = sph_dec32be_aligned(buf + 44); \
|
||||
MC = sph_dec32be_aligned(buf + 48); \
|
||||
MD = sph_dec32be_aligned(buf + 52); \
|
||||
ME = sph_dec32be_aligned(buf + 56); \
|
||||
MF = sph_dec32be_aligned(buf + 60); \
|
||||
ROUND_S(0); \
|
||||
ROUND_S(1); \
|
||||
ROUND_S(2); \
|
||||
ROUND_S(3); \
|
||||
ROUND_S(4); \
|
||||
ROUND_S(5); \
|
||||
ROUND_S(6); \
|
||||
ROUND_S(7); \
|
||||
if (BLAKE32_ROUNDS == 14) { \
|
||||
ROUND_S(8); \
|
||||
ROUND_S(9); \
|
||||
ROUND_S(0); \
|
||||
ROUND_S(1); \
|
||||
ROUND_S(2); \
|
||||
ROUND_S(3); \
|
||||
} \
|
||||
H0 ^= S0 ^ V0 ^ V8; \
|
||||
H1 ^= S1 ^ V1 ^ V9; \
|
||||
H2 ^= S2 ^ V2 ^ VA; \
|
||||
H3 ^= S3 ^ V3 ^ VB; \
|
||||
H4 ^= S0 ^ V4 ^ VC; \
|
||||
H5 ^= S1 ^ V5 ^ VD; \
|
||||
H6 ^= S2 ^ V6 ^ VE; \
|
||||
H7 ^= S3 ^ V7 ^ VF; \
|
||||
} while (0)
|
||||
|
||||
|
||||
static const sph_u32 salt_zero_small[4] = { 0, 0, 0, 0 };
|
||||
|
||||
static void
|
||||
blake32_init(sph_blake_small_context *sc,
|
||||
const sph_u32 *iv, const sph_u32 *salt)
|
||||
{
|
||||
memcpy(sc->H, iv, 8 * sizeof(sph_u32));
|
||||
memcpy(sc->S, salt, 4 * sizeof(sph_u32));
|
||||
sc->T0 = sc->T1 = 0;
|
||||
sc->ptr = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
blake32(sph_blake_small_context *sc, const void *data, size_t len)
|
||||
{
|
||||
unsigned char *buf;
|
||||
size_t ptr;
|
||||
DECL_STATE32
|
||||
|
||||
buf = sc->buf;
|
||||
ptr = sc->ptr;
|
||||
if (len < (sizeof sc->buf) - ptr) {
|
||||
memcpy(buf + ptr, data, len);
|
||||
ptr += len;
|
||||
sc->ptr = ptr;
|
||||
return;
|
||||
}
|
||||
|
||||
READ_STATE32(sc);
|
||||
while (len > 0) {
|
||||
size_t clen;
|
||||
|
||||
clen = (sizeof sc->buf) - ptr;
|
||||
if (clen > len)
|
||||
clen = len;
|
||||
memcpy(buf + ptr, data, clen);
|
||||
ptr += clen;
|
||||
data = (const unsigned char *)data + clen;
|
||||
len -= clen;
|
||||
if (ptr == sizeof sc->buf) {
|
||||
if ((T0 = SPH_T32(T0 + 512)) < 512)
|
||||
T1 = SPH_T32(T1 + 1);
|
||||
COMPRESS32;
|
||||
ptr = 0;
|
||||
}
|
||||
}
|
||||
WRITE_STATE32(sc);
|
||||
sc->ptr = ptr;
|
||||
}
|
||||
|
||||
static void
|
||||
blake32_close(sph_blake_small_context *sc,
|
||||
unsigned ub, unsigned n, void *dst, size_t out_size_w32)
|
||||
{
|
||||
union {
|
||||
unsigned char buf[64];
|
||||
sph_u32 dummy;
|
||||
} u;
|
||||
size_t ptr, k;
|
||||
unsigned bit_len;
|
||||
unsigned z;
|
||||
sph_u32 th, tl;
|
||||
unsigned char *out;
|
||||
|
||||
ptr = sc->ptr;
|
||||
bit_len = ((unsigned)ptr << 3) + n;
|
||||
z = 0x80 >> n;
|
||||
u.buf[ptr] = ((ub & -z) | z) & 0xFF;
|
||||
tl = sc->T0 + bit_len;
|
||||
th = sc->T1;
|
||||
if (ptr == 0 && n == 0) {
|
||||
sc->T0 = SPH_C32(0xFFFFFE00);
|
||||
sc->T1 = SPH_C32(0xFFFFFFFF);
|
||||
} else if (sc->T0 == 0) {
|
||||
sc->T0 = SPH_C32(0xFFFFFE00) + bit_len;
|
||||
sc->T1 = SPH_T32(sc->T1 - 1);
|
||||
} else {
|
||||
sc->T0 -= 512 - bit_len;
|
||||
}
|
||||
if (bit_len <= 446) {
|
||||
memset(u.buf + ptr + 1, 0, 55 - ptr);
|
||||
if (out_size_w32 == 8)
|
||||
u.buf[55] |= 1;
|
||||
sph_enc32be_aligned(u.buf + 56, th);
|
||||
sph_enc32be_aligned(u.buf + 60, tl);
|
||||
blake32(sc, u.buf + ptr, 64 - ptr);
|
||||
} else {
|
||||
memset(u.buf + ptr + 1, 0, 63 - ptr);
|
||||
blake32(sc, u.buf + ptr, 64 - ptr);
|
||||
sc->T0 = SPH_C32(0xFFFFFE00);
|
||||
sc->T1 = SPH_C32(0xFFFFFFFF);
|
||||
memset(u.buf, 0, 56);
|
||||
if (out_size_w32 == 8)
|
||||
u.buf[55] = 1;
|
||||
sph_enc32be_aligned(u.buf + 56, th);
|
||||
sph_enc32be_aligned(u.buf + 60, tl);
|
||||
blake32(sc, u.buf, 64);
|
||||
}
|
||||
out = dst;
|
||||
for (k = 0; k < out_size_w32; k ++)
|
||||
sph_enc32be(out + (k << 2), sc->H[k]);
|
||||
}
|
||||
|
||||
void
|
||||
blakecoin_init(void *cc)
|
||||
{
|
||||
blake32_init(cc, IV256, salt_zero_small);
|
||||
}
|
||||
|
||||
void
|
||||
blakecoin(void *cc, const void *data, size_t len)
|
||||
{
|
||||
blake32(cc, data, len);
|
||||
}
|
||||
|
||||
static void
|
||||
blakecoin_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
|
||||
{
|
||||
blake32_close(cc, ub, n, dst, 8);
|
||||
blakecoin_init(cc);
|
||||
}
|
||||
|
||||
void
|
||||
blakecoin_close(void *cc, void *dst)
|
||||
{
|
||||
blakecoin_addbits_and_close(cc, 0, 0, dst);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
121
algo/blake/pentablake.c
Normal file
121
algo/blake/pentablake.c
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "miner.h"
|
||||
#include "algo-gate-api.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sph_blake.h"
|
||||
|
||||
//#define DEBUG_ALGO
|
||||
|
||||
extern void pentablakehash(void *output, const void *input)
|
||||
{
|
||||
unsigned char _ALIGN(32) hash[128];
|
||||
// same as uint32_t hashA[16], hashB[16];
|
||||
#define hashB hash+64
|
||||
|
||||
sph_blake512_context ctx_blake;
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512(&ctx_blake, input, 80);
|
||||
sph_blake512_close(&ctx_blake, hash);
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512(&ctx_blake, hash, 64);
|
||||
sph_blake512_close(&ctx_blake, hashB);
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512(&ctx_blake, hashB, 64);
|
||||
sph_blake512_close(&ctx_blake, hash);
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512(&ctx_blake, hash, 64);
|
||||
sph_blake512_close(&ctx_blake, hashB);
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512(&ctx_blake, hashB, 64);
|
||||
sph_blake512_close(&ctx_blake, hash);
|
||||
|
||||
memcpy(output, hash, 32);
|
||||
|
||||
}
|
||||
|
||||
int scanhash_pentablake(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 _ALIGN(32) endiandata[32];
|
||||
|
||||
uint64_t htmax[] = {
|
||||
0,
|
||||
0xF,
|
||||
0xFF,
|
||||
0xFFF,
|
||||
0xFFFF,
|
||||
0x10000000
|
||||
};
|
||||
uint32_t masks[] = {
|
||||
0xFFFFFFFF,
|
||||
0xFFFFFFF0,
|
||||
0xFFFFFF00,
|
||||
0xFFFFF000,
|
||||
0xFFFF0000,
|
||||
0
|
||||
};
|
||||
|
||||
// we need bigendian data...
|
||||
swab32_array( endiandata, pdata, 20 );
|
||||
|
||||
#ifdef DEBUG_ALGO
|
||||
if (Htarg != 0)
|
||||
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);
|
||||
pentablakehash(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_pentablake_algo( algo_gate_t* gate )
|
||||
{
|
||||
gate->scanhash = (void*)&scanhash_pentablake;
|
||||
gate->hash = (void*)&pentablakehash;
|
||||
gate->get_max64 = (void*)&get_max64_0x3ffff;
|
||||
return true;
|
||||
};
|
||||
|
||||
1127
algo/blake/sph_blake.c
Normal file
1127
algo/blake/sph_blake.c
Normal file
File diff suppressed because it is too large
Load Diff
327
algo/blake/sph_blake.h
Normal file
327
algo/blake/sph_blake.h
Normal file
@@ -0,0 +1,327 @@
|
||||
/* $Id: sph_blake.h 252 2011-06-07 17:55:14Z tp $ */
|
||||
/**
|
||||
* BLAKE interface. BLAKE is a family of functions which differ by their
|
||||
* output size; this implementation defines BLAKE for output sizes 224,
|
||||
* 256, 384 and 512 bits. This implementation conforms to the "third
|
||||
* round" specification.
|
||||
*
|
||||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* ===========================(LICENSE END)=============================
|
||||
*
|
||||
* @file sph_blake.h
|
||||
* @author Thomas Pornin <thomas.pornin@cryptolog.com>
|
||||
*/
|
||||
|
||||
#ifndef SPH_BLAKE_H__
|
||||
#define SPH_BLAKE_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include "algo/sha3/sph_types.h"
|
||||
|
||||
/**
|
||||
* Output size (in bits) for BLAKE-224.
|
||||
*/
|
||||
#define SPH_SIZE_blake224 224
|
||||
|
||||
/**
|
||||
* Output size (in bits) for BLAKE-256.
|
||||
*/
|
||||
#define SPH_SIZE_blake256 256
|
||||
|
||||
#if SPH_64
|
||||
|
||||
/**
|
||||
* Output size (in bits) for BLAKE-384.
|
||||
*/
|
||||
#define SPH_SIZE_blake384 384
|
||||
|
||||
/**
|
||||
* Output size (in bits) for BLAKE-512.
|
||||
*/
|
||||
#define SPH_SIZE_blake512 512
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This structure is a context for BLAKE-224 and BLAKE-256 computations:
|
||||
* it contains the intermediate values and some data from the last
|
||||
* entered block. Once a BLAKE computation has been performed, the
|
||||
* context can be reused for another computation.
|
||||
*
|
||||
* The contents of this structure are private. A running BLAKE
|
||||
* computation can be cloned by copying the context (e.g. with a simple
|
||||
* <code>memcpy()</code>).
|
||||
*/
|
||||
typedef struct {
|
||||
#ifndef DOXYGEN_IGNORE
|
||||
unsigned char buf[64]; /* first field, for alignment */
|
||||
size_t ptr;
|
||||
sph_u32 H[8];
|
||||
sph_u32 S[4];
|
||||
sph_u32 T0, T1;
|
||||
#endif
|
||||
} sph_blake_small_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for BLAKE-224 computations. It is
|
||||
* identical to the common <code>sph_blake_small_context</code>.
|
||||
*/
|
||||
typedef sph_blake_small_context sph_blake224_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for BLAKE-256 computations. It is
|
||||
* identical to the common <code>sph_blake_small_context</code>.
|
||||
*/
|
||||
typedef sph_blake_small_context sph_blake256_context;
|
||||
|
||||
#if SPH_64
|
||||
|
||||
/**
|
||||
* This structure is a context for BLAKE-384 and BLAKE-512 computations:
|
||||
* it contains the intermediate values and some data from the last
|
||||
* entered block. Once a BLAKE computation has been performed, the
|
||||
* context can be reused for another computation.
|
||||
*
|
||||
* The contents of this structure are private. A running BLAKE
|
||||
* computation can be cloned by copying the context (e.g. with a simple
|
||||
* <code>memcpy()</code>).
|
||||
*/
|
||||
typedef struct {
|
||||
#ifndef DOXYGEN_IGNORE
|
||||
unsigned char buf[128]; /* first field, for alignment */
|
||||
size_t ptr;
|
||||
sph_u64 H[8];
|
||||
sph_u64 S[4];
|
||||
sph_u64 T0, T1;
|
||||
#endif
|
||||
} sph_blake_big_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for BLAKE-384 computations. It is
|
||||
* identical to the common <code>sph_blake_small_context</code>.
|
||||
*/
|
||||
typedef sph_blake_big_context sph_blake384_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for BLAKE-512 computations. It is
|
||||
* identical to the common <code>sph_blake_small_context</code>.
|
||||
*/
|
||||
typedef sph_blake_big_context sph_blake512_context;
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialize a BLAKE-224 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the BLAKE-224 context (pointer to a
|
||||
* <code>sph_blake224_context</code>)
|
||||
*/
|
||||
void sph_blake224_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the BLAKE-224 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_blake224(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current BLAKE-224 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (28 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the BLAKE-224 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_blake224_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (28 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the BLAKE-224 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_blake224_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
/**
|
||||
* Initialize a BLAKE-256 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the BLAKE-256 context (pointer to a
|
||||
* <code>sph_blake256_context</code>)
|
||||
*/
|
||||
void sph_blake256_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the BLAKE-256 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_blake256(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current BLAKE-256 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (32 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the BLAKE-256 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_blake256_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (32 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the BLAKE-256 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_blake256_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
#if SPH_64
|
||||
|
||||
/**
|
||||
* Initialize a BLAKE-384 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the BLAKE-384 context (pointer to a
|
||||
* <code>sph_blake384_context</code>)
|
||||
*/
|
||||
void sph_blake384_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the BLAKE-384 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_blake384(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current BLAKE-384 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (48 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the BLAKE-384 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_blake384_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (48 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the BLAKE-384 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_blake384_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
/**
|
||||
* Initialize a BLAKE-512 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the BLAKE-512 context (pointer to a
|
||||
* <code>sph_blake512_context</code>)
|
||||
*/
|
||||
void sph_blake512_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the BLAKE-512 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_blake512(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current BLAKE-512 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (64 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the BLAKE-512 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_blake512_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (64 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the BLAKE-512 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_blake512_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
477
algo/blake/sse2/blake.c
Normal file
477
algo/blake/sse2/blake.c
Normal file
@@ -0,0 +1,477 @@
|
||||
/* $Id: blake.c 252 2011-06-07 17:55:14Z tp $ */
|
||||
/*
|
||||
* BLAKE implementation.
|
||||
*
|
||||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* ===========================(LICENSE END)=============================
|
||||
*
|
||||
* @author Thomas Pornin <thomas.pornin@cryptolog.com>
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "../sph_blake.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable: 4146)
|
||||
#endif
|
||||
|
||||
static const sph_u64 blkIV512[8] = {
|
||||
SPH_C64(0x6A09E667F3BCC908), SPH_C64(0xBB67AE8584CAA73B),
|
||||
SPH_C64(0x3C6EF372FE94F82B), SPH_C64(0xA54FF53A5F1D36F1),
|
||||
SPH_C64(0x510E527FADE682D1), SPH_C64(0x9B05688C2B3E6C1F),
|
||||
SPH_C64(0x1F83D9ABFB41BD6B), SPH_C64(0x5BE0CD19137E2179)
|
||||
};
|
||||
|
||||
#define Z00 0
|
||||
#define Z01 1
|
||||
#define Z02 2
|
||||
#define Z03 3
|
||||
#define Z04 4
|
||||
#define Z05 5
|
||||
#define Z06 6
|
||||
#define Z07 7
|
||||
#define Z08 8
|
||||
#define Z09 9
|
||||
#define Z0A A
|
||||
#define Z0B B
|
||||
#define Z0C C
|
||||
#define Z0D D
|
||||
#define Z0E E
|
||||
#define Z0F F
|
||||
|
||||
#define Z10 E
|
||||
#define Z11 A
|
||||
#define Z12 4
|
||||
#define Z13 8
|
||||
#define Z14 9
|
||||
#define Z15 F
|
||||
#define Z16 D
|
||||
#define Z17 6
|
||||
#define Z18 1
|
||||
#define Z19 C
|
||||
#define Z1A 0
|
||||
#define Z1B 2
|
||||
#define Z1C B
|
||||
#define Z1D 7
|
||||
#define Z1E 5
|
||||
#define Z1F 3
|
||||
|
||||
#define Z20 B
|
||||
#define Z21 8
|
||||
#define Z22 C
|
||||
#define Z23 0
|
||||
#define Z24 5
|
||||
#define Z25 2
|
||||
#define Z26 F
|
||||
#define Z27 D
|
||||
#define Z28 A
|
||||
#define Z29 E
|
||||
#define Z2A 3
|
||||
#define Z2B 6
|
||||
#define Z2C 7
|
||||
#define Z2D 1
|
||||
#define Z2E 9
|
||||
#define Z2F 4
|
||||
|
||||
#define Z30 7
|
||||
#define Z31 9
|
||||
#define Z32 3
|
||||
#define Z33 1
|
||||
#define Z34 D
|
||||
#define Z35 C
|
||||
#define Z36 B
|
||||
#define Z37 E
|
||||
#define Z38 2
|
||||
#define Z39 6
|
||||
#define Z3A 5
|
||||
#define Z3B A
|
||||
#define Z3C 4
|
||||
#define Z3D 0
|
||||
#define Z3E F
|
||||
#define Z3F 8
|
||||
|
||||
#define Z40 9
|
||||
#define Z41 0
|
||||
#define Z42 5
|
||||
#define Z43 7
|
||||
#define Z44 2
|
||||
#define Z45 4
|
||||
#define Z46 A
|
||||
#define Z47 F
|
||||
#define Z48 E
|
||||
#define Z49 1
|
||||
#define Z4A B
|
||||
#define Z4B C
|
||||
#define Z4C 6
|
||||
#define Z4D 8
|
||||
#define Z4E 3
|
||||
#define Z4F D
|
||||
|
||||
#define Z50 2
|
||||
#define Z51 C
|
||||
#define Z52 6
|
||||
#define Z53 A
|
||||
#define Z54 0
|
||||
#define Z55 B
|
||||
#define Z56 8
|
||||
#define Z57 3
|
||||
#define Z58 4
|
||||
#define Z59 D
|
||||
#define Z5A 7
|
||||
#define Z5B 5
|
||||
#define Z5C F
|
||||
#define Z5D E
|
||||
#define Z5E 1
|
||||
#define Z5F 9
|
||||
|
||||
#define Z60 C
|
||||
#define Z61 5
|
||||
#define Z62 1
|
||||
#define Z63 F
|
||||
#define Z64 E
|
||||
#define Z65 D
|
||||
#define Z66 4
|
||||
#define Z67 A
|
||||
#define Z68 0
|
||||
#define Z69 7
|
||||
#define Z6A 6
|
||||
#define Z6B 3
|
||||
#define Z6C 9
|
||||
#define Z6D 2
|
||||
#define Z6E 8
|
||||
#define Z6F B
|
||||
|
||||
#define Z70 D
|
||||
#define Z71 B
|
||||
#define Z72 7
|
||||
#define Z73 E
|
||||
#define Z74 C
|
||||
#define Z75 1
|
||||
#define Z76 3
|
||||
#define Z77 9
|
||||
#define Z78 5
|
||||
#define Z79 0
|
||||
#define Z7A F
|
||||
#define Z7B 4
|
||||
#define Z7C 8
|
||||
#define Z7D 6
|
||||
#define Z7E 2
|
||||
#define Z7F A
|
||||
|
||||
#define Z80 6
|
||||
#define Z81 F
|
||||
#define Z82 E
|
||||
#define Z83 9
|
||||
#define Z84 B
|
||||
#define Z85 3
|
||||
#define Z86 0
|
||||
#define Z87 8
|
||||
#define Z88 C
|
||||
#define Z89 2
|
||||
#define Z8A D
|
||||
#define Z8B 7
|
||||
#define Z8C 1
|
||||
#define Z8D 4
|
||||
#define Z8E A
|
||||
#define Z8F 5
|
||||
|
||||
#define Z90 A
|
||||
#define Z91 2
|
||||
#define Z92 8
|
||||
#define Z93 4
|
||||
#define Z94 7
|
||||
#define Z95 6
|
||||
#define Z96 1
|
||||
#define Z97 5
|
||||
#define Z98 F
|
||||
#define Z99 B
|
||||
#define Z9A 9
|
||||
#define Z9B E
|
||||
#define Z9C 3
|
||||
#define Z9D C
|
||||
#define Z9E D
|
||||
#define Z9F 0
|
||||
|
||||
#define Mx(r, i) Mx_(Z ## r ## i)
|
||||
#define Mx_(n) Mx__(n)
|
||||
#define Mx__(n) M ## n
|
||||
|
||||
#define CSx(r, i) CSx_(Z ## r ## i)
|
||||
#define CSx_(n) CSx__(n)
|
||||
#define CSx__(n) CS ## n
|
||||
|
||||
#define CS0 SPH_C32(0x243F6A88)
|
||||
#define CS1 SPH_C32(0x85A308D3)
|
||||
#define CS2 SPH_C32(0x13198A2E)
|
||||
#define CS3 SPH_C32(0x03707344)
|
||||
#define CS4 SPH_C32(0xA4093822)
|
||||
#define CS5 SPH_C32(0x299F31D0)
|
||||
#define CS6 SPH_C32(0x082EFA98)
|
||||
#define CS7 SPH_C32(0xEC4E6C89)
|
||||
#define CS8 SPH_C32(0x452821E6)
|
||||
#define CS9 SPH_C32(0x38D01377)
|
||||
#define CSA SPH_C32(0xBE5466CF)
|
||||
#define CSB SPH_C32(0x34E90C6C)
|
||||
#define CSC SPH_C32(0xC0AC29B7)
|
||||
#define CSD SPH_C32(0xC97C50DD)
|
||||
#define CSE SPH_C32(0x3F84D5B5)
|
||||
#define CSF SPH_C32(0xB5470917)
|
||||
|
||||
|
||||
|
||||
#define CBx(r, i) CBx_(Z ## r ## i)
|
||||
#define CBx_(n) CBx__(n)
|
||||
#define CBx__(n) CB ## n
|
||||
|
||||
#define CB0 SPH_C64(0x243F6A8885A308D3)
|
||||
#define CB1 SPH_C64(0x13198A2E03707344)
|
||||
#define CB2 SPH_C64(0xA4093822299F31D0)
|
||||
#define CB3 SPH_C64(0x082EFA98EC4E6C89)
|
||||
#define CB4 SPH_C64(0x452821E638D01377)
|
||||
#define CB5 SPH_C64(0xBE5466CF34E90C6C)
|
||||
#define CB6 SPH_C64(0xC0AC29B7C97C50DD)
|
||||
#define CB7 SPH_C64(0x3F84D5B5B5470917)
|
||||
#define CB8 SPH_C64(0x9216D5D98979FB1B)
|
||||
#define CB9 SPH_C64(0xD1310BA698DFB5AC)
|
||||
#define CBA SPH_C64(0x2FFD72DBD01ADFB7)
|
||||
#define CBB SPH_C64(0xB8E1AFED6A267E96)
|
||||
#define CBC SPH_C64(0xBA7C9045F12C7F99)
|
||||
#define CBD SPH_C64(0x24A19947B3916CF7)
|
||||
#define CBE SPH_C64(0x0801F2E2858EFC16)
|
||||
#define CBF SPH_C64(0x636920D871574E69)
|
||||
|
||||
|
||||
#define GS(m0, m1, c0, c1, a, b, c, d) do { \
|
||||
a = SPH_T32(a + b + (m0 ^ c1)); \
|
||||
d = SPH_ROTR32(d ^ a, 16); \
|
||||
c = SPH_T32(c + d); \
|
||||
b = SPH_ROTR32(b ^ c, 12); \
|
||||
a = SPH_T32(a + b + (m1 ^ c0)); \
|
||||
d = SPH_ROTR32(d ^ a, 8); \
|
||||
c = SPH_T32(c + d); \
|
||||
b = SPH_ROTR32(b ^ c, 7); \
|
||||
} while (0)
|
||||
|
||||
#define ROUND_S(r) do { \
|
||||
GS(Mx(r, 0), Mx(r, 1), CSx(r, 0), CSx(r, 1), V0, V4, V8, VC); \
|
||||
GS(Mx(r, 2), Mx(r, 3), CSx(r, 2), CSx(r, 3), V1, V5, V9, VD); \
|
||||
GS(Mx(r, 4), Mx(r, 5), CSx(r, 4), CSx(r, 5), V2, V6, VA, VE); \
|
||||
GS(Mx(r, 6), Mx(r, 7), CSx(r, 6), CSx(r, 7), V3, V7, VB, VF); \
|
||||
GS(Mx(r, 8), Mx(r, 9), CSx(r, 8), CSx(r, 9), V0, V5, VA, VF); \
|
||||
GS(Mx(r, A), Mx(r, B), CSx(r, A), CSx(r, B), V1, V6, VB, VC); \
|
||||
GS(Mx(r, C), Mx(r, D), CSx(r, C), CSx(r, D), V2, V7, V8, VD); \
|
||||
GS(Mx(r, E), Mx(r, F), CSx(r, E), CSx(r, F), V3, V4, V9, VE); \
|
||||
} while (0)
|
||||
|
||||
|
||||
|
||||
#define GB(m0, m1, c0, c1, a, b, c, d) do { \
|
||||
a = SPH_T64(a + b + (m0 ^ c1)); \
|
||||
d = SPH_ROTR64(d ^ a, 32); \
|
||||
c = SPH_T64(c + d); \
|
||||
b = SPH_ROTR64(b ^ c, 25); \
|
||||
a = SPH_T64(a + b + (m1 ^ c0)); \
|
||||
d = SPH_ROTR64(d ^ a, 16); \
|
||||
c = SPH_T64(c + d); \
|
||||
b = SPH_ROTR64(b ^ c, 11); \
|
||||
} while (0)
|
||||
|
||||
#define ROUND_B(r) do { \
|
||||
GB(Mx(r, 0), Mx(r, 1), CBx(r, 0), CBx(r, 1), V0, V4, V8, VC); \
|
||||
GB(Mx(r, 2), Mx(r, 3), CBx(r, 2), CBx(r, 3), V1, V5, V9, VD); \
|
||||
GB(Mx(r, 4), Mx(r, 5), CBx(r, 4), CBx(r, 5), V2, V6, VA, VE); \
|
||||
GB(Mx(r, 6), Mx(r, 7), CBx(r, 6), CBx(r, 7), V3, V7, VB, VF); \
|
||||
GB(Mx(r, 8), Mx(r, 9), CBx(r, 8), CBx(r, 9), V0, V5, VA, VF); \
|
||||
GB(Mx(r, A), Mx(r, B), CBx(r, A), CBx(r, B), V1, V6, VB, VC); \
|
||||
GB(Mx(r, C), Mx(r, D), CBx(r, C), CBx(r, D), V2, V7, V8, VD); \
|
||||
GB(Mx(r, E), Mx(r, F), CBx(r, E), CBx(r, F), V3, V4, V9, VE); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define COMPRESS64 do { \
|
||||
int r; \
|
||||
int b=0; \
|
||||
sph_u64 M0, M1, M2, M3, M4, M5, M6, M7; \
|
||||
sph_u64 M8, M9, MA, MB, MC, MD, ME, MF; \
|
||||
sph_u64 V0, V1, V2, V3, V4, V5, V6, V7; \
|
||||
sph_u64 V8, V9, VA, VB, VC, VD, VE, VF; \
|
||||
V0 = blkH0, \
|
||||
V1 = blkH1, \
|
||||
V2 = blkH2, \
|
||||
V3 = blkH3, \
|
||||
V4 = blkH4, \
|
||||
V5 = blkH5, \
|
||||
V6 = blkH6, \
|
||||
V7 = blkH7; \
|
||||
V8 = blkS0 ^ CB0, \
|
||||
V9 = blkS1 ^ CB1, \
|
||||
VA = blkS2 ^ CB2, \
|
||||
VB = blkS3 ^ CB3, \
|
||||
VC = hashctA ^ CB4, \
|
||||
VD = hashctA ^ CB5, \
|
||||
VE = hashctB ^ CB6, \
|
||||
VF = hashctB ^ CB7; \
|
||||
M0 = sph_dec64be_aligned(buf + 0), \
|
||||
M1 = sph_dec64be_aligned(buf + 8), \
|
||||
M2 = sph_dec64be_aligned(buf + 16), \
|
||||
M3 = sph_dec64be_aligned(buf + 24), \
|
||||
M4 = sph_dec64be_aligned(buf + 32), \
|
||||
M5 = sph_dec64be_aligned(buf + 40), \
|
||||
M6 = sph_dec64be_aligned(buf + 48), \
|
||||
M7 = sph_dec64be_aligned(buf + 56), \
|
||||
M8 = sph_dec64be_aligned(buf + 64), \
|
||||
M9 = sph_dec64be_aligned(buf + 72), \
|
||||
MA = sph_dec64be_aligned(buf + 80), \
|
||||
MB = sph_dec64be_aligned(buf + 88), \
|
||||
MC = sph_dec64be_aligned(buf + 96), \
|
||||
MD = sph_dec64be_aligned(buf + 104), \
|
||||
ME = sph_dec64be_aligned(buf + 112), \
|
||||
MF = sph_dec64be_aligned(buf + 120); \
|
||||
/* loop once and a half */ \
|
||||
/* save some space */ \
|
||||
for (;;) { \
|
||||
ROUND_B(0); \
|
||||
ROUND_B(1); \
|
||||
ROUND_B(2); \
|
||||
ROUND_B(3); \
|
||||
ROUND_B(4); \
|
||||
ROUND_B(5); \
|
||||
if (b) break; \
|
||||
b = 1; \
|
||||
ROUND_B(6); \
|
||||
ROUND_B(7); \
|
||||
ROUND_B(8); \
|
||||
ROUND_B(9); \
|
||||
}; \
|
||||
blkH0 ^= blkS0 ^ V0 ^ V8, \
|
||||
blkH1 ^= blkS1 ^ V1 ^ V9, \
|
||||
blkH2 ^= blkS2 ^ V2 ^ VA, \
|
||||
blkH3 ^= blkS3 ^ V3 ^ VB, \
|
||||
blkH4 ^= blkS0 ^ V4 ^ VC, \
|
||||
blkH5 ^= blkS1 ^ V5 ^ VD, \
|
||||
blkH6 ^= blkS2 ^ V6 ^ VE, \
|
||||
blkH7 ^= blkS3 ^ V7 ^ VF; \
|
||||
} while (0)
|
||||
/*
|
||||
*/
|
||||
#define DECL_BLK \
|
||||
sph_u64 blkH0; \
|
||||
sph_u64 blkH1; \
|
||||
sph_u64 blkH2; \
|
||||
sph_u64 blkH3; \
|
||||
sph_u64 blkH4; \
|
||||
sph_u64 blkH5; \
|
||||
sph_u64 blkH6; \
|
||||
sph_u64 blkH7; \
|
||||
sph_u64 blkS0; \
|
||||
sph_u64 blkS1; \
|
||||
sph_u64 blkS2; \
|
||||
sph_u64 blkS3; \
|
||||
|
||||
/* load initial constants */
|
||||
#define BLK_I \
|
||||
do { \
|
||||
blkH0 = SPH_C64(0x6A09E667F3BCC908); \
|
||||
blkH1 = SPH_C64(0xBB67AE8584CAA73B); \
|
||||
blkH2 = SPH_C64(0x3C6EF372FE94F82B); \
|
||||
blkH3 = SPH_C64(0xA54FF53A5F1D36F1); \
|
||||
blkH4 = SPH_C64(0x510E527FADE682D1); \
|
||||
blkH5 = SPH_C64(0x9B05688C2B3E6C1F); \
|
||||
blkH6 = SPH_C64(0x1F83D9ABFB41BD6B); \
|
||||
blkH7 = SPH_C64(0x5BE0CD19137E2179); \
|
||||
blkS0 = 0; \
|
||||
blkS1 = 0; \
|
||||
blkS2 = 0; \
|
||||
blkS3 = 0; \
|
||||
hashctB = SPH_T64(0- 1); \
|
||||
} while (0)
|
||||
|
||||
/* copy in 80 for initial hash */
|
||||
#define BLK_W \
|
||||
do { \
|
||||
memcpy(hashbuf, input, 80); \
|
||||
hashctA = SPH_C64(0xFFFFFFFFFFFFFC00) + 80*8; \
|
||||
hashptr = 80; \
|
||||
} while (0)
|
||||
|
||||
/* copy in 64 for looped hash */
|
||||
#define BLK_U \
|
||||
do { \
|
||||
memcpy(hashbuf, hash , 64); \
|
||||
hashctA = SPH_C64(0xFFFFFFFFFFFFFC00) + 64*8; \
|
||||
hashptr = 64; \
|
||||
} while (0)
|
||||
|
||||
/* blake compress function */
|
||||
/* hash = blake512(loaded) */
|
||||
#define BLK_C \
|
||||
do { \
|
||||
\
|
||||
union { \
|
||||
unsigned char buf[128]; \
|
||||
sph_u64 dummy; \
|
||||
} u; \
|
||||
size_t ptr; \
|
||||
unsigned bit_len; \
|
||||
\
|
||||
ptr = hashptr; \
|
||||
bit_len = ((unsigned)ptr << 3) + 0; \
|
||||
u.buf[ptr] = ((0 & -(0x80)) | (0x80)) & 0xFF; \
|
||||
memset(u.buf + ptr + 1, 0, 111 - ptr); \
|
||||
u.buf[111] |= 1; \
|
||||
sph_enc64be_aligned(u.buf + 112, 0); \
|
||||
sph_enc64be_aligned(u.buf + 120, bit_len); \
|
||||
do { \
|
||||
const void *data = u.buf + ptr; \
|
||||
unsigned char *buf; \
|
||||
buf = hashbuf; \
|
||||
size_t clen; \
|
||||
clen = (sizeof(char)*128) - hashptr; \
|
||||
memcpy(buf + hashptr, data, clen); \
|
||||
hashctA = SPH_T64(hashctA + 1024); \
|
||||
hashctB = SPH_T64(hashctB + 1); \
|
||||
COMPRESS64; \
|
||||
} while (0); \
|
||||
/* end blake64(sc, u.buf + ptr, 128 - ptr); */ \
|
||||
sph_enc64be((unsigned char*)(hash) + (0 << 3), blkH0), \
|
||||
sph_enc64be((unsigned char*)(hash) + (1 << 3), blkH1); \
|
||||
sph_enc64be((unsigned char*)(hash) + (2 << 3), blkH2), \
|
||||
sph_enc64be((unsigned char*)(hash) + (3 << 3), blkH3); \
|
||||
sph_enc64be((unsigned char*)(hash) + (4 << 3), blkH4), \
|
||||
sph_enc64be((unsigned char*)(hash) + (5 << 3), blkH5); \
|
||||
sph_enc64be((unsigned char*)(hash) + (6 << 3), blkH6), \
|
||||
sph_enc64be((unsigned char*)(hash) + (7 << 3), blkH7); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
2
algo/blake/sse2/blake/sse41/api.h
Normal file
2
algo/blake/sse2/blake/sse41/api.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define CRYPTO_BYTES 64
|
||||
|
||||
2
algo/blake/sse2/blake/sse41/architectures
Normal file
2
algo/blake/sse2/blake/sse41/architectures
Normal file
@@ -0,0 +1,2 @@
|
||||
amd64
|
||||
x86
|
||||
8
algo/blake/sse2/blake/sse41/config.h
Normal file
8
algo/blake/sse2/blake/sse41/config.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef __BLAKE512_CONFIG_H__
|
||||
#define __BLAKE512_CONFIG_H__
|
||||
|
||||
#define AVOID_BRANCHING 1
|
||||
//#define HAVE_XOP 1
|
||||
|
||||
#endif
|
||||
|
||||
287
algo/blake/sse2/blake/sse41/hash.c
Normal file
287
algo/blake/sse2/blake/sse41/hash.c
Normal file
@@ -0,0 +1,287 @@
|
||||
|
||||
#include "hash.h"
|
||||
/*
|
||||
#ifndef NOT_SUPERCOP
|
||||
|
||||
#include "crypto_hash.h"
|
||||
#include "crypto_uint64.h"
|
||||
#include "crypto_uint32.h"
|
||||
#include "crypto_uint8.h"
|
||||
|
||||
typedef crypto_uint64 u64;
|
||||
typedef crypto_uint32 u32;
|
||||
typedef crypto_uint8 u8;
|
||||
|
||||
#else
|
||||
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned char u8;
|
||||
|
||||
#endif
|
||||
*/
|
||||
#define U8TO32(p) \
|
||||
(((u32)((p)[0]) << 24) | ((u32)((p)[1]) << 16) | \
|
||||
((u32)((p)[2]) << 8) | ((u32)((p)[3]) ))
|
||||
#define U8TO64(p) \
|
||||
(((u64)U8TO32(p) << 32) | (u64)U8TO32((p) + 4))
|
||||
#define U32TO8(p, v) \
|
||||
(p)[0] = (u8)((v) >> 24); (p)[1] = (u8)((v) >> 16); \
|
||||
(p)[2] = (u8)((v) >> 8); (p)[3] = (u8)((v) );
|
||||
#define U64TO8(p, v) \
|
||||
U32TO8((p), (u32)((v) >> 32)); \
|
||||
U32TO8((p) + 4, (u32)((v) ));
|
||||
/*
|
||||
typedef struct
|
||||
{
|
||||
__m128i h[4];
|
||||
u64 s[4], t[2];
|
||||
u32 buflen, nullt;
|
||||
u8 buf[128];
|
||||
} state __attribute__ ((aligned (64)));
|
||||
*/
|
||||
static const u8 padding[129] =
|
||||
{
|
||||
0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
static inline int blake512_compress( hashState_blake * state, const u8 * datablock )
|
||||
{
|
||||
|
||||
__m128i row1l,row1h;
|
||||
__m128i row2l,row2h;
|
||||
__m128i row3l,row3h;
|
||||
__m128i row4l,row4h;
|
||||
|
||||
const __m128i r16 = _mm_setr_epi8(2,3,4,5,6,7,0,1,10,11,12,13,14,15,8,9);
|
||||
const __m128i u8to64 = _mm_set_epi8(8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7);
|
||||
|
||||
__m128i m0, m1, m2, m3, m4, m5, m6, m7;
|
||||
__m128i t0, t1, t2, t3, t4, t5, t6, t7;
|
||||
__m128i b0, b1, b2, b3;
|
||||
|
||||
m0 = _mm_loadu_si128((__m128i*)(datablock + 0));
|
||||
m1 = _mm_loadu_si128((__m128i*)(datablock + 16));
|
||||
m2 = _mm_loadu_si128((__m128i*)(datablock + 32));
|
||||
m3 = _mm_loadu_si128((__m128i*)(datablock + 48));
|
||||
m4 = _mm_loadu_si128((__m128i*)(datablock + 64));
|
||||
m5 = _mm_loadu_si128((__m128i*)(datablock + 80));
|
||||
m6 = _mm_loadu_si128((__m128i*)(datablock + 96));
|
||||
m7 = _mm_loadu_si128((__m128i*)(datablock + 112));
|
||||
|
||||
m0 = BSWAP64(m0);
|
||||
m1 = BSWAP64(m1);
|
||||
m2 = BSWAP64(m2);
|
||||
m3 = BSWAP64(m3);
|
||||
m4 = BSWAP64(m4);
|
||||
m5 = BSWAP64(m5);
|
||||
m6 = BSWAP64(m6);
|
||||
m7 = BSWAP64(m7);
|
||||
|
||||
row1l = state->h[0];
|
||||
row1h = state->h[1];
|
||||
row2l = state->h[2];
|
||||
row2h = state->h[3];
|
||||
row3l = _mm_set_epi64x(0x13198A2E03707344ULL, 0x243F6A8885A308D3ULL);
|
||||
row3h = _mm_set_epi64x(0x082EFA98EC4E6C89ULL, 0xA4093822299F31D0ULL);
|
||||
|
||||
row4l = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0x452821E638D01377ULL);
|
||||
row4h = _mm_set_epi64x(0x3F84D5B5B5470917ULL, 0xC0AC29B7C97C50DDULL);
|
||||
|
||||
#ifdef AVOID_BRANCHING
|
||||
do
|
||||
{
|
||||
const __m128i mask = _mm_cmpeq_epi32(_mm_setzero_si128(), _mm_set1_epi32(state->nullt));
|
||||
const __m128i xor1 = _mm_and_si128(_mm_set1_epi64x(state->t[0]), mask);
|
||||
const __m128i xor2 = _mm_and_si128(_mm_set1_epi64x(state->t[1]), mask);
|
||||
row4l = _mm_xor_si128(row4l, xor1);
|
||||
row4h = _mm_xor_si128(row4h, xor2);
|
||||
} while(0);
|
||||
#else
|
||||
if(!state->nullt)
|
||||
{
|
||||
row4l = _mm_xor_si128(row4l, _mm_set1_epi64x(state->t[0]));
|
||||
row4h = _mm_xor_si128(row4h, _mm_set1_epi64x(state->t[1]));
|
||||
}
|
||||
#endif
|
||||
|
||||
ROUND( 0);
|
||||
ROUND( 1);
|
||||
ROUND( 2);
|
||||
ROUND( 3);
|
||||
ROUND( 4);
|
||||
ROUND( 5);
|
||||
ROUND( 6);
|
||||
ROUND( 7);
|
||||
ROUND( 8);
|
||||
ROUND( 9);
|
||||
ROUND(10);
|
||||
ROUND(11);
|
||||
ROUND(12);
|
||||
ROUND(13);
|
||||
ROUND(14);
|
||||
ROUND(15);
|
||||
|
||||
row1l = _mm_xor_si128(row3l,row1l);
|
||||
row1h = _mm_xor_si128(row3h,row1h);
|
||||
|
||||
state->h[0] = _mm_xor_si128(row1l, state->h[0]);
|
||||
state->h[1] = _mm_xor_si128(row1h, state->h[1]);
|
||||
|
||||
row2l = _mm_xor_si128(row4l,row2l);
|
||||
row2h = _mm_xor_si128(row4h,row2h);
|
||||
|
||||
state->h[2] = _mm_xor_si128(row2l, state->h[2]);
|
||||
state->h[3] = _mm_xor_si128(row2h, state->h[3]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void blake512_init( hashState_blake * S, u64 databitlen )
|
||||
{
|
||||
memset(S, 0, sizeof(hashState_blake));
|
||||
S->h[0] = _mm_set_epi64x(0xBB67AE8584CAA73BULL, 0x6A09E667F3BCC908ULL);
|
||||
S->h[1] = _mm_set_epi64x(0xA54FF53A5F1D36F1ULL, 0x3C6EF372FE94F82BULL);
|
||||
S->h[2] = _mm_set_epi64x(0x9B05688C2B3E6C1FULL, 0x510E527FADE682D1ULL);
|
||||
S->h[3] = _mm_set_epi64x(0x5BE0CD19137E2179ULL, 0x1F83D9ABFB41BD6BULL);
|
||||
S->buflen = databitlen;
|
||||
}
|
||||
|
||||
|
||||
static void blake512_update( hashState_blake * S, const u8 * data, u64 datalen )
|
||||
{
|
||||
|
||||
|
||||
int left = (S->buflen >> 3);
|
||||
int fill = 128 - left;
|
||||
|
||||
if( left && ( ((datalen >> 3) & 0x7F) >= fill ) ) {
|
||||
memcpy( (void *) (S->buf + left), (void *) data, fill );
|
||||
S->t[0] += 1024;
|
||||
blake512_compress( S, S->buf );
|
||||
data += fill;
|
||||
datalen -= (fill << 3);
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( datalen >= 1024 ) {
|
||||
S->t[0] += 1024;
|
||||
blake512_compress( S, data );
|
||||
data += 128;
|
||||
datalen -= 1024;
|
||||
}
|
||||
|
||||
if( datalen > 0 ) {
|
||||
memcpy( (void *) (S->buf + left), (void *) data, ( datalen>>3 ) & 0x7F );
|
||||
S->buflen = (left<<3) + datalen;
|
||||
}
|
||||
else S->buflen=0;
|
||||
}
|
||||
|
||||
static inline void blake512_final( hashState_blake * S, u8 * digest )
|
||||
{
|
||||
|
||||
u8 msglen[16], zo=0x01,oo=0x81;
|
||||
u64 lo=S->t[0] + S->buflen, hi = S->t[1];
|
||||
if ( lo < S->buflen ) hi++;
|
||||
U64TO8( msglen + 0, hi );
|
||||
U64TO8( msglen + 8, lo );
|
||||
|
||||
if ( S->buflen == 888 ) /* one padding byte */
|
||||
{
|
||||
S->t[0] -= 8;
|
||||
blake512_update( S, &oo, 8 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( S->buflen < 888 ) /* enough space to fill the block */
|
||||
{
|
||||
if ( S->buflen == 0 ) S->nullt=1;
|
||||
S->t[0] -= 888 - S->buflen;
|
||||
blake512_update( S, padding, 888 - S->buflen );
|
||||
}
|
||||
else /* NOT enough space, need 2 compressions */
|
||||
{
|
||||
S->t[0] -= 1024 - S->buflen;
|
||||
blake512_update( S, padding, 1024 - S->buflen );
|
||||
S->t[0] -= 888;
|
||||
blake512_update( S, padding+1, 888 );
|
||||
S->nullt = 1;
|
||||
}
|
||||
blake512_update( S, &zo, 8 );
|
||||
S->t[0] -= 8;
|
||||
}
|
||||
S->t[0] -= 128;
|
||||
blake512_update( S, msglen, 128 );
|
||||
|
||||
do
|
||||
{
|
||||
const __m128i u8to64 = _mm_set_epi8(8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7);
|
||||
_mm_storeu_si128((__m128i*)(digest + 0), BSWAP64(S->h[0]));
|
||||
_mm_storeu_si128((__m128i*)(digest + 16), BSWAP64(S->h[1]));
|
||||
_mm_storeu_si128((__m128i*)(digest + 32), BSWAP64(S->h[2]));
|
||||
_mm_storeu_si128((__m128i*)(digest + 48), BSWAP64(S->h[3]));
|
||||
} while(0);
|
||||
}
|
||||
|
||||
/*
|
||||
int crypto_hash( unsigned char *out, const unsigned char *in, unsigned long long inlen )
|
||||
{
|
||||
|
||||
hashState_blake S;
|
||||
blake512_init( &S );
|
||||
blake512_update( &S, in, inlen*8 );
|
||||
blake512_final( &S, out );
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
#ifdef NOT_SUPERCOP
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
int i, v;
|
||||
u8 data[144], digest[64];
|
||||
u8 test1[]= {0x97, 0x96, 0x15, 0x87, 0xF6, 0xD9, 0x70, 0xFA, 0xBA, 0x6D, 0x24, 0x78, 0x04, 0x5D, 0xE6, 0xD1,
|
||||
0xFA, 0xBD, 0x09, 0xB6, 0x1A, 0xE5, 0x09, 0x32, 0x05, 0x4D, 0x52, 0xBC, 0x29, 0xD3, 0x1B, 0xE4,
|
||||
0xFF, 0x91, 0x02, 0xB9, 0xF6, 0x9E, 0x2B, 0xBD, 0xB8, 0x3B, 0xE1, 0x3D, 0x4B, 0x9C, 0x06, 0x09,
|
||||
0x1E, 0x5F, 0xA0, 0xB4, 0x8B, 0xD0, 0x81, 0xB6, 0x34, 0x05, 0x8B, 0xE0, 0xEC, 0x49, 0xBE, 0xB3};
|
||||
u8 test2[]= {0x31, 0x37, 0x17, 0xD6, 0x08, 0xE9, 0xCF, 0x75, 0x8D, 0xCB, 0x1E, 0xB0, 0xF0, 0xC3, 0xCF, 0x9F,
|
||||
0xC1, 0x50, 0xB2, 0xD5, 0x00, 0xFB, 0x33, 0xF5, 0x1C, 0x52, 0xAF, 0xC9, 0x9D, 0x35, 0x8A, 0x2F,
|
||||
0x13, 0x74, 0xB8, 0xA3, 0x8B, 0xBA, 0x79, 0x74, 0xE7, 0xF6, 0xEF, 0x79, 0xCA, 0xB1, 0x6F, 0x22,
|
||||
0xCE, 0x1E, 0x64, 0x9D, 0x6E, 0x01, 0xAD, 0x95, 0x89, 0xC2, 0x13, 0x04, 0x5D, 0x54, 0x5D, 0xDE};
|
||||
|
||||
for(i=0; i<144; ++i) data[i]=0;
|
||||
|
||||
crypto_hash( digest, data, 1 );
|
||||
v=0;
|
||||
for(i=0; i<64; ++i) {
|
||||
printf("%02X", digest[i]);
|
||||
if ( digest[i] != test1[i]) v=1;
|
||||
}
|
||||
if (v) printf("\nerror\n");
|
||||
else printf("\nok\n");
|
||||
|
||||
for(i=0; i<144; ++i) data[i]=0;
|
||||
|
||||
crypto_hash( digest, data, 144 );
|
||||
v=0;
|
||||
for(i=0; i<64; ++i) {
|
||||
printf("%02X", digest[i]);
|
||||
if ( digest[i] != test2[i]) v=1;
|
||||
}
|
||||
if (v) printf("\nerror\n");
|
||||
else printf("\nok\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
*/
|
||||
|
||||
|
||||
74
algo/blake/sse2/blake/sse41/hash.h
Normal file
74
algo/blake/sse2/blake/sse41/hash.h
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <x86intrin.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "rounds.h"
|
||||
/*
|
||||
#ifndef NOT_SUPERCOP
|
||||
|
||||
#include "crypto_hash.h"
|
||||
#include "crypto_uint64.h"
|
||||
#include "crypto_uint32.h"
|
||||
#include "crypto_uint8.h"
|
||||
|
||||
typedef crypto_uint64 u64;
|
||||
typedef crypto_uint32 u32;
|
||||
typedef crypto_uint8 u8;
|
||||
|
||||
#else
|
||||
*/
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned char u8;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
__m128i h[4];
|
||||
u64 s[4], t[2];
|
||||
u32 buflen, nullt;
|
||||
u8 buf[128];
|
||||
} hashState_blake __attribute__ ((aligned (64)));
|
||||
/*
|
||||
#endif
|
||||
|
||||
#define U8TO32(p) \
|
||||
(((u32)((p)[0]) << 24) | ((u32)((p)[1]) << 16) | \
|
||||
((u32)((p)[2]) << 8) | ((u32)((p)[3]) ))
|
||||
#define U8TO64(p) \
|
||||
(((u64)U8TO32(p) << 32) | (u64)U8TO32((p) + 4))
|
||||
#define U32TO8(p, v) \
|
||||
(p)[0] = (u8)((v) >> 24); (p)[1] = (u8)((v) >> 16); \
|
||||
(p)[2] = (u8)((v) >> 8); (p)[3] = (u8)((v) );
|
||||
#define U64TO8(p, v) \
|
||||
U32TO8((p), (u32)((v) >> 32)); \
|
||||
U32TO8((p) + 4, (u32)((v) ));
|
||||
*/
|
||||
|
||||
/*
|
||||
static const u8 padding[129] =
|
||||
{
|
||||
0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
*/
|
||||
static inline void blake512_init( hashState_blake * S, u64 datalen );
|
||||
|
||||
|
||||
static void blake512_update( hashState_blake * S, const u8 * data, u64 datalen ) ;
|
||||
|
||||
static inline void blake512_final( hashState_blake * S, u8 * digest ) ;
|
||||
|
||||
|
||||
int crypto_hash( unsigned char *out, const unsigned char *in, unsigned long long inlen ) ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
2
algo/blake/sse2/blake/sse41/implementors
Normal file
2
algo/blake/sse2/blake/sse41/implementors
Normal file
@@ -0,0 +1,2 @@
|
||||
Jean-Philippe Aumasson
|
||||
Samuel Neves
|
||||
871
algo/blake/sse2/blake/sse41/rounds.h
Normal file
871
algo/blake/sse2/blake/sse41/rounds.h
Normal file
@@ -0,0 +1,871 @@
|
||||
|
||||
#ifndef __BLAKE512_ROUNDS_H__
|
||||
#define __BLAKE512_ROUNDS_H__
|
||||
|
||||
#ifndef HAVE_XOP
|
||||
#define BSWAP64(x) _mm_shuffle_epi8((x), u8to64)
|
||||
|
||||
#define _mm_roti_epi64(x, c) \
|
||||
(-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \
|
||||
: (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \
|
||||
: _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-c)))
|
||||
#else
|
||||
#define BSWAP64(x) _mm_perm_epi8((x),(x),u8to64)
|
||||
#endif
|
||||
|
||||
|
||||
#define LOAD_MSG_0_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m0, m1); \
|
||||
t1 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0x13198A2E03707344ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m2, m3); \
|
||||
t3 = _mm_set_epi64x(0x3F84D5B5B5470917ULL, 0xBE5466CF34E90C6CULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_0_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m0, m1); \
|
||||
t1 = _mm_set_epi64x(0xA4093822299F31D0ULL, 0x243F6A8885A308D3ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m2, m3); \
|
||||
t3 = _mm_set_epi64x(0xC0AC29B7C97C50DDULL, 0x452821E638D01377ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_0_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m4, m5); \
|
||||
t1 = _mm_set_epi64x(0xB8E1AFED6A267E96ULL, 0xD1310BA698DFB5ACULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m6, m7); \
|
||||
t3 = _mm_set_epi64x(0x636920D871574E69ULL, 0x24A19947B3916CF7ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_0_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m4, m5); \
|
||||
t1 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0x9216D5D98979FB1BULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m6, m7); \
|
||||
t3 = _mm_set_epi64x(0x801F2E2858EFC16ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_1_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m7, m2); \
|
||||
t1 = _mm_set_epi64x(0x9216D5D98979FB1BULL, 0x2FFD72DBD01ADFB7ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m4, m6); \
|
||||
t3 = _mm_set_epi64x(0xC0AC29B7C97C50DDULL, 0x636920D871574E69ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_1_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m5, m4); \
|
||||
t1 = _mm_set_epi64x(0x452821E638D01377ULL, 0x801F2E2858EFC16ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_alignr_epi8(m3, m7, 8); \
|
||||
t3 = _mm_set_epi64x(0x24A19947B3916CF7ULL, 0xD1310BA698DFB5ACULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_1_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_shuffle_epi32(m0, _MM_SHUFFLE(1,0,3,2)); \
|
||||
t1 = _mm_set_epi64x(0xA4093822299F31D0ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m5, m2); \
|
||||
t3 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0x3F84D5B5B5470917ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_1_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m6, m1); \
|
||||
t1 = _mm_set_epi64x(0x243F6A8885A308D3ULL, 0x13198A2E03707344ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m3, m1); \
|
||||
t3 = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0xB8E1AFED6A267E96ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_2_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_alignr_epi8(m6, m5, 8); \
|
||||
t1 = _mm_set_epi64x(0x243F6A8885A308D3ULL, 0x9216D5D98979FB1BULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m2, m7); \
|
||||
t3 = _mm_set_epi64x(0x24A19947B3916CF7ULL, 0xA4093822299F31D0ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_2_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m4, m0); \
|
||||
t1 = _mm_set_epi64x(0xBA7C9045F12C7F99ULL, 0xB8E1AFED6A267E96ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m1, m6, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x636920D871574E69ULL, 0xBE5466CF34E90C6CULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_2_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m5, m1, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0xC0AC29B7C97C50DDULL, 0x801F2E2858EFC16ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m3, m4); \
|
||||
t3 = _mm_set_epi64x(0x452821E638D01377ULL, 0x13198A2E03707344ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_2_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m7, m3); \
|
||||
t1 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0x2FFD72DBD01ADFB7ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_alignr_epi8(m2, m0, 8); \
|
||||
t3 = _mm_set_epi64x(0xD1310BA698DFB5ACULL, 0x3F84D5B5B5470917ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_3_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m3, m1); \
|
||||
t1 = _mm_set_epi64x(0x13198A2E03707344ULL, 0xD1310BA698DFB5ACULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m6, m5); \
|
||||
t3 = _mm_set_epi64x(0x801F2E2858EFC16ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_3_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m4, m0); \
|
||||
t1 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0x3F84D5B5B5470917ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m6, m7); \
|
||||
t3 = _mm_set_epi64x(0xB8E1AFED6A267E96ULL, 0x24A19947B3916CF7ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_3_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m1, m2, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0xC0AC29B7C97C50DDULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m2, m7, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x9216D5D98979FB1BULL, 0x243F6A8885A308D3ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_3_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m3, m5); \
|
||||
t1 = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0xA4093822299F31D0ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m0, m4); \
|
||||
t3 = _mm_set_epi64x(0x636920D871574E69ULL, 0x452821E638D01377ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_4_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m4, m2); \
|
||||
t1 = _mm_set_epi64x(0x3F84D5B5B5470917ULL, 0x243F6A8885A308D3ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m1, m5); \
|
||||
t3 = _mm_set_epi64x(0x636920D871574E69ULL, 0x452821E638D01377ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_4_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m0, m3, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0xD1310BA698DFB5ACULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m2, m7, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0xA4093822299F31D0ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_4_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m7, m5, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0xBA7C9045F12C7F99ULL, 0x13198A2E03707344ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m3, m1, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x24A19947B3916CF7ULL, 0x9216D5D98979FB1BULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_4_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_alignr_epi8(m6, m0, 8); \
|
||||
t1 = _mm_set_epi64x(0xB8E1AFED6A267E96ULL, 0x801F2E2858EFC16ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m4, m6, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0xC0AC29B7C97C50DDULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_5_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m1, m3); \
|
||||
t1 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m0, m4); \
|
||||
t3 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0xB8E1AFED6A267E96ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_5_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m6, m5); \
|
||||
t1 = _mm_set_epi64x(0xC0AC29B7C97C50DDULL, 0xA4093822299F31D0ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m5, m1); \
|
||||
t3 = _mm_set_epi64x(0x9216D5D98979FB1BULL, 0x243F6A8885A308D3ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_5_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m2, m3, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0x24A19947B3916CF7ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m7, m0); \
|
||||
t3 = _mm_set_epi64x(0xD1310BA698DFB5ACULL, 0x801F2E2858EFC16ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_5_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m6, m2); \
|
||||
t1 = _mm_set_epi64x(0x3F84D5B5B5470917ULL, 0x452821E638D01377ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m7, m4, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x13198A2E03707344ULL, 0x636920D871574E69ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_6_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m6, m0, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0x636920D871574E69ULL, 0xBE5466CF34E90C6CULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m7, m2); \
|
||||
t3 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0x24A19947B3916CF7ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_6_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m2, m7); \
|
||||
t1 = _mm_set_epi64x(0x13198A2E03707344ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_alignr_epi8(m5, m6, 8); \
|
||||
t3 = _mm_set_epi64x(0x452821E638D01377ULL, 0x801F2E2858EFC16ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_6_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m0, m3); \
|
||||
t1 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0x3F84D5B5B5470917ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_shuffle_epi32(m4, _MM_SHUFFLE(1,0,3,2)); \
|
||||
t3 = _mm_set_epi64x(0xB8E1AFED6A267E96ULL, 0xA4093822299F31D0ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_6_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m3, m1); \
|
||||
t1 = _mm_set_epi64x(0xC0AC29B7C97C50DDULL, 0x243F6A8885A308D3ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m1, m5, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x9216D5D98979FB1BULL, 0xD1310BA698DFB5ACULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_7_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m6, m3); \
|
||||
t1 = _mm_set_epi64x(0x801F2E2858EFC16ULL, 0xB8E1AFED6A267E96ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m6, m1, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0xD1310BA698DFB5ACULL, 0x13198A2E03707344ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_7_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_alignr_epi8(m7, m5, 8); \
|
||||
t1 = _mm_set_epi64x(0x3F84D5B5B5470917ULL, 0x24A19947B3916CF7ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m0, m4); \
|
||||
t3 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_7_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m2, m7); \
|
||||
t1 = _mm_set_epi64x(0x452821E638D01377ULL, 0x243F6A8885A308D3ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m4, m1); \
|
||||
t3 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0xC0AC29B7C97C50DDULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_7_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m0, m2); \
|
||||
t1 = _mm_set_epi64x(0x636920D871574E69ULL, 0xBE5466CF34E90C6CULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m3, m5); \
|
||||
t3 = _mm_set_epi64x(0xA4093822299F31D0ULL, 0x9216D5D98979FB1BULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_8_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m3, m7); \
|
||||
t1 = _mm_set_epi64x(0xD1310BA698DFB5ACULL, 0x636920D871574E69ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_alignr_epi8(m0, m5, 8); \
|
||||
t3 = _mm_set_epi64x(0x9216D5D98979FB1BULL, 0x82EFA98EC4E6C89ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_8_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m7, m4); \
|
||||
t1 = _mm_set_epi64x(0x801F2E2858EFC16ULL, 0xC0AC29B7C97C50DDULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_alignr_epi8(m4, m1, 8); \
|
||||
t3 = _mm_set_epi64x(0x243F6A8885A308D3ULL, 0xB8E1AFED6A267E96ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_8_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = m6; \
|
||||
t1 = _mm_set_epi64x(0x3F84D5B5B5470917ULL, 0xA4093822299F31D0ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_alignr_epi8(m5, m0, 8); \
|
||||
t3 = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0x452821E638D01377ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_8_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m1, m3, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0x24A19947B3916CF7ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = m2; \
|
||||
t3 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0x13198A2E03707344ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_9_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m5, m4); \
|
||||
t1 = _mm_set_epi64x(0x452821E638D01377ULL, 0xA4093822299F31D0ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m3, m0); \
|
||||
t3 = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0xC0AC29B7C97C50DDULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_9_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m1, m2); \
|
||||
t1 = _mm_set_epi64x(0x9216D5D98979FB1BULL, 0x2FFD72DBD01ADFB7ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m3, m2, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x13198A2E03707344ULL, 0x3F84D5B5B5470917ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_9_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m7, m4); \
|
||||
t1 = _mm_set_epi64x(0x801F2E2858EFC16ULL, 0xB8E1AFED6A267E96ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m1, m6); \
|
||||
t3 = _mm_set_epi64x(0x243F6A8885A308D3ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_9_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_alignr_epi8(m7, m5, 8); \
|
||||
t1 = _mm_set_epi64x(0xD1310BA698DFB5ACULL, 0x636920D871574E69ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m6, m0); \
|
||||
t3 = _mm_set_epi64x(0x24A19947B3916CF7ULL, 0x82EFA98EC4E6C89ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_10_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m0, m1); \
|
||||
t1 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0x13198A2E03707344ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m2, m3); \
|
||||
t3 = _mm_set_epi64x(0x3F84D5B5B5470917ULL, 0xBE5466CF34E90C6CULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_10_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m0, m1); \
|
||||
t1 = _mm_set_epi64x(0xA4093822299F31D0ULL, 0x243F6A8885A308D3ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m2, m3); \
|
||||
t3 = _mm_set_epi64x(0xC0AC29B7C97C50DDULL, 0x452821E638D01377ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_10_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m4, m5); \
|
||||
t1 = _mm_set_epi64x(0xB8E1AFED6A267E96ULL, 0xD1310BA698DFB5ACULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m6, m7); \
|
||||
t3 = _mm_set_epi64x(0x636920D871574E69ULL, 0x24A19947B3916CF7ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_10_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m4, m5); \
|
||||
t1 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0x9216D5D98979FB1BULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m6, m7); \
|
||||
t3 = _mm_set_epi64x(0x801F2E2858EFC16ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_11_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m7, m2); \
|
||||
t1 = _mm_set_epi64x(0x9216D5D98979FB1BULL, 0x2FFD72DBD01ADFB7ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m4, m6); \
|
||||
t3 = _mm_set_epi64x(0xC0AC29B7C97C50DDULL, 0x636920D871574E69ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_11_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m5, m4); \
|
||||
t1 = _mm_set_epi64x(0x452821E638D01377ULL, 0x801F2E2858EFC16ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_alignr_epi8(m3, m7, 8); \
|
||||
t3 = _mm_set_epi64x(0x24A19947B3916CF7ULL, 0xD1310BA698DFB5ACULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_11_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_shuffle_epi32(m0, _MM_SHUFFLE(1,0,3,2)); \
|
||||
t1 = _mm_set_epi64x(0xA4093822299F31D0ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m5, m2); \
|
||||
t3 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0x3F84D5B5B5470917ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_11_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m6, m1); \
|
||||
t1 = _mm_set_epi64x(0x243F6A8885A308D3ULL, 0x13198A2E03707344ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m3, m1); \
|
||||
t3 = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0xB8E1AFED6A267E96ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_12_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_alignr_epi8(m6, m5, 8); \
|
||||
t1 = _mm_set_epi64x(0x243F6A8885A308D3ULL, 0x9216D5D98979FB1BULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m2, m7); \
|
||||
t3 = _mm_set_epi64x(0x24A19947B3916CF7ULL, 0xA4093822299F31D0ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_12_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m4, m0); \
|
||||
t1 = _mm_set_epi64x(0xBA7C9045F12C7F99ULL, 0xB8E1AFED6A267E96ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m1, m6, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x636920D871574E69ULL, 0xBE5466CF34E90C6CULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_12_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m5, m1, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0xC0AC29B7C97C50DDULL, 0x801F2E2858EFC16ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m3, m4); \
|
||||
t3 = _mm_set_epi64x(0x452821E638D01377ULL, 0x13198A2E03707344ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_12_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m7, m3); \
|
||||
t1 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0x2FFD72DBD01ADFB7ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_alignr_epi8(m2, m0, 8); \
|
||||
t3 = _mm_set_epi64x(0xD1310BA698DFB5ACULL, 0x3F84D5B5B5470917ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_13_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m3, m1); \
|
||||
t1 = _mm_set_epi64x(0x13198A2E03707344ULL, 0xD1310BA698DFB5ACULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m6, m5); \
|
||||
t3 = _mm_set_epi64x(0x801F2E2858EFC16ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_13_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m4, m0); \
|
||||
t1 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0x3F84D5B5B5470917ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m6, m7); \
|
||||
t3 = _mm_set_epi64x(0xB8E1AFED6A267E96ULL, 0x24A19947B3916CF7ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_13_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m1, m2, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0xC0AC29B7C97C50DDULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m2, m7, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x9216D5D98979FB1BULL, 0x243F6A8885A308D3ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_13_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m3, m5); \
|
||||
t1 = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0xA4093822299F31D0ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m0, m4); \
|
||||
t3 = _mm_set_epi64x(0x636920D871574E69ULL, 0x452821E638D01377ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_14_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m4, m2); \
|
||||
t1 = _mm_set_epi64x(0x3F84D5B5B5470917ULL, 0x243F6A8885A308D3ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m1, m5); \
|
||||
t3 = _mm_set_epi64x(0x636920D871574E69ULL, 0x452821E638D01377ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_14_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m0, m3, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0xD1310BA698DFB5ACULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m2, m7, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0xA4093822299F31D0ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_14_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m7, m5, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0xBA7C9045F12C7F99ULL, 0x13198A2E03707344ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m3, m1, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x24A19947B3916CF7ULL, 0x9216D5D98979FB1BULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_14_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_alignr_epi8(m6, m0, 8); \
|
||||
t1 = _mm_set_epi64x(0xB8E1AFED6A267E96ULL, 0x801F2E2858EFC16ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m4, m6, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0xC0AC29B7C97C50DDULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_15_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m1, m3); \
|
||||
t1 = _mm_set_epi64x(0x2FFD72DBD01ADFB7ULL, 0xBA7C9045F12C7F99ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpacklo_epi64(m0, m4); \
|
||||
t3 = _mm_set_epi64x(0x82EFA98EC4E6C89ULL, 0xB8E1AFED6A267E96ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_15_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpacklo_epi64(m6, m5); \
|
||||
t1 = _mm_set_epi64x(0xC0AC29B7C97C50DDULL, 0xA4093822299F31D0ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m5, m1); \
|
||||
t3 = _mm_set_epi64x(0x9216D5D98979FB1BULL, 0x243F6A8885A308D3ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_15_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_blend_epi16(m2, m3, 0xF0); \
|
||||
t1 = _mm_set_epi64x(0xBE5466CF34E90C6CULL, 0x24A19947B3916CF7ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_unpackhi_epi64(m7, m0); \
|
||||
t3 = _mm_set_epi64x(0xD1310BA698DFB5ACULL, 0x801F2E2858EFC16ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_15_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
t0 = _mm_unpackhi_epi64(m6, m2); \
|
||||
t1 = _mm_set_epi64x(0x3F84D5B5B5470917ULL, 0x452821E638D01377ULL); \
|
||||
b0 = _mm_xor_si128(t0, t1); \
|
||||
t2 = _mm_blend_epi16(m7, m4, 0xF0); \
|
||||
t3 = _mm_set_epi64x(0x13198A2E03707344ULL, 0x636920D871574E69ULL); \
|
||||
b1 = _mm_xor_si128(t2, t3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1) \
|
||||
row1l = _mm_add_epi64(_mm_add_epi64(row1l, b0), row2l); \
|
||||
row1h = _mm_add_epi64(_mm_add_epi64(row1h, b1), row2h); \
|
||||
\
|
||||
row4l = _mm_xor_si128(row4l, row1l); \
|
||||
row4h = _mm_xor_si128(row4h, row1h); \
|
||||
\
|
||||
row4l = _mm_roti_epi64(row4l, -32); \
|
||||
row4h = _mm_roti_epi64(row4h, -32); \
|
||||
\
|
||||
row3l = _mm_add_epi64(row3l, row4l); \
|
||||
row3h = _mm_add_epi64(row3h, row4h); \
|
||||
\
|
||||
row2l = _mm_xor_si128(row2l, row3l); \
|
||||
row2h = _mm_xor_si128(row2h, row3h); \
|
||||
\
|
||||
row2l = _mm_roti_epi64(row2l, -25); \
|
||||
row2h = _mm_roti_epi64(row2h, -25); \
|
||||
|
||||
#define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1) \
|
||||
row1l = _mm_add_epi64(_mm_add_epi64(row1l, b0), row2l); \
|
||||
row1h = _mm_add_epi64(_mm_add_epi64(row1h, b1), row2h); \
|
||||
\
|
||||
row4l = _mm_xor_si128(row4l, row1l); \
|
||||
row4h = _mm_xor_si128(row4h, row1h); \
|
||||
\
|
||||
row4l = _mm_roti_epi64(row4l, -16); \
|
||||
row4h = _mm_roti_epi64(row4h, -16); \
|
||||
\
|
||||
row3l = _mm_add_epi64(row3l, row4l); \
|
||||
row3h = _mm_add_epi64(row3h, row4h); \
|
||||
\
|
||||
row2l = _mm_xor_si128(row2l, row3l); \
|
||||
row2h = _mm_xor_si128(row2h, row3h); \
|
||||
\
|
||||
row2l = _mm_roti_epi64(row2l, -11); \
|
||||
row2h = _mm_roti_epi64(row2h, -11); \
|
||||
|
||||
|
||||
#define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \
|
||||
t0 = _mm_alignr_epi8(row2h, row2l, 8); \
|
||||
t1 = _mm_alignr_epi8(row2l, row2h, 8); \
|
||||
row2l = t0; \
|
||||
row2h = t1; \
|
||||
\
|
||||
t0 = row3l; \
|
||||
row3l = row3h; \
|
||||
row3h = t0; \
|
||||
\
|
||||
t0 = _mm_alignr_epi8(row4h, row4l, 8); \
|
||||
t1 = _mm_alignr_epi8(row4l, row4h, 8); \
|
||||
row4l = t1; \
|
||||
row4h = t0;
|
||||
|
||||
#define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \
|
||||
t0 = _mm_alignr_epi8(row2l, row2h, 8); \
|
||||
t1 = _mm_alignr_epi8(row2h, row2l, 8); \
|
||||
row2l = t0; \
|
||||
row2h = t1; \
|
||||
\
|
||||
t0 = row3l; \
|
||||
row3l = row3h; \
|
||||
row3h = t0; \
|
||||
\
|
||||
t0 = _mm_alignr_epi8(row4l, row4h, 8); \
|
||||
t1 = _mm_alignr_epi8(row4h, row4l, 8); \
|
||||
row4l = t1; \
|
||||
row4h = t0;
|
||||
|
||||
#define ROUND(r) \
|
||||
LOAD_MSG_ ##r ##_1(b0, b1); \
|
||||
G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1); \
|
||||
LOAD_MSG_ ##r ##_2(b0, b1); \
|
||||
G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1); \
|
||||
DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
|
||||
LOAD_MSG_ ##r ##_3(b0, b1); \
|
||||
G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1); \
|
||||
LOAD_MSG_ ##r ##_4(b0, b1); \
|
||||
G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h,b0,b1); \
|
||||
UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user