Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f262850270 |
No files matched your search
+2
-18
@@ -15,7 +15,7 @@ depcomp
|
||||
missing
|
||||
install-sh
|
||||
stamp-h1
|
||||
ccminer-config.h*
|
||||
cpuminer-config.h*
|
||||
compile
|
||||
config.log
|
||||
config.status
|
||||
@@ -25,7 +25,7 @@ config.sub
|
||||
|
||||
mingw32-config.cache
|
||||
|
||||
.dirstamp
|
||||
*/.dirstamp
|
||||
.DS_Store
|
||||
Desktop.ini
|
||||
Thumbs.db
|
||||
@@ -41,8 +41,6 @@ x64/Release/
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.pdb
|
||||
*.VC.opendb
|
||||
*.VC.db
|
||||
|
||||
.settings/
|
||||
.project
|
||||
@@ -54,17 +52,3 @@ x64/Release/
|
||||
|
||||
compat/curl-for-windows/
|
||||
|
||||
*.ptx
|
||||
*.i
|
||||
*.ii
|
||||
*.gpu
|
||||
*.cubin
|
||||
*.stub.c
|
||||
*.module_id
|
||||
*.hash
|
||||
*.fatbin.c
|
||||
*.fatbin
|
||||
*.cudafe1.cpp
|
||||
*.cudafe1.c
|
||||
*.cudafe2.c
|
||||
|
||||
+19
-29
@@ -45,7 +45,7 @@ static uint32_t *h_resNonce[MAX_GPUS];
|
||||
|
||||
/* max count of found nonces in one call */
|
||||
#define NBN 2
|
||||
static __thread uint32_t extra_results[NBN] = { UINT32_MAX };
|
||||
static uint32_t extra_results[NBN] = { UINT32_MAX };
|
||||
|
||||
#define GSPREC(a,b,c,d,x,y) { \
|
||||
v[a] += (m[x] ^ c_u256[y]) + v[b]; \
|
||||
@@ -504,9 +504,6 @@ extern "C" int scanhash_blake256(int thr_id, struct work* work, uint32_t max_non
|
||||
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
|
||||
cuda_get_arch(thr_id);
|
||||
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
|
||||
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
|
||||
@@ -521,53 +518,46 @@ extern "C" int scanhash_blake256(int thr_id, struct work* work, uint32_t max_non
|
||||
|
||||
do {
|
||||
// GPU HASH (second block only, first is midstate)
|
||||
work->nonces[0] = blake256_cpu_hash_16(thr_id, throughput, pdata[19], targetHigh, blakerounds);
|
||||
uint32_t foundNonce = blake256_cpu_hash_16(thr_id, throughput, pdata[19], targetHigh, blakerounds);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
if (work->nonces[0] != UINT32_MAX)
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
uint32_t _ALIGN(64) vhashcpu[8];
|
||||
const uint32_t Htarg = ptarget[6];
|
||||
uint32_t vhashcpu[8];
|
||||
uint32_t Htarg = ptarget[6];
|
||||
|
||||
for (int k=16; k < 19; k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
|
||||
be32enc(&endiandata[19], work->nonces[0]);
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
blake256hash(vhashcpu, endiandata, blakerounds);
|
||||
|
||||
if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget))
|
||||
{
|
||||
work->valid_nonces = 1;
|
||||
rc = 1;
|
||||
work_set_target_ratio(work, vhashcpu);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
pdata[19] = foundNonce;
|
||||
#if NBN > 1
|
||||
if (extra_results[0] != UINT32_MAX) {
|
||||
work->nonces[1] = extra_results[0];
|
||||
be32enc(&endiandata[19], work->nonces[1]);
|
||||
be32enc(&endiandata[19], extra_results[0]);
|
||||
blake256hash(vhashcpu, endiandata, blakerounds);
|
||||
if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget)) {
|
||||
if (bn_hash_target_ratio(vhashcpu, ptarget) > work->shareratio[0]) {
|
||||
pdata[21] = extra_results[0];
|
||||
if (bn_hash_target_ratio(vhashcpu, ptarget) > work->shareratio) {
|
||||
work_set_target_ratio(work, vhashcpu);
|
||||
xchg(work->nonces[0], work->nonces[1]);
|
||||
} else {
|
||||
bn_set_target_ratio(work, vhashcpu, 1);
|
||||
xchg(pdata[21], pdata[19]);
|
||||
}
|
||||
work->valid_nonces = 2;
|
||||
rc = 2;
|
||||
}
|
||||
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
|
||||
extra_results[0] = UINT32_MAX;
|
||||
} else {
|
||||
pdata[19] = work->nonces[0] + 1; // cursor
|
||||
}
|
||||
#endif
|
||||
return work->valid_nonces;
|
||||
return rc;
|
||||
}
|
||||
else if (vhashcpu[6] > Htarg) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
|
||||
pdata[19] = work->nonces[0] + 1;
|
||||
continue;
|
||||
else if (opt_debug) {
|
||||
applog_hash((uchar*)ptarget);
|
||||
applog_compare_hash((uchar*)vhashcpu, (uchar*)ptarget);
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+404
-454
@@ -1,429 +1,402 @@
|
||||
/**
|
||||
* Based on the SPH implementation of blake2s
|
||||
* Provos Alexis - 2016
|
||||
* Blake2-S 256 CUDA implementation
|
||||
* @author tpruvot@github March 2016
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "miner.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
extern "C" {
|
||||
#define NATIVE_LITTLE_ENDIAN
|
||||
#include <sph/blake2s.h>
|
||||
}
|
||||
|
||||
#include "sph/blake2s.h"
|
||||
#include "sph/sph_types.h"
|
||||
//#define GPU_MIDSTATE
|
||||
#define MIDLEN 76
|
||||
#define A 64
|
||||
|
||||
static __thread blake2s_state ALIGN(A) s_midstate;
|
||||
static __thread blake2s_state ALIGN(A) s_ctx;
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#ifdef __INTELLISENSE__
|
||||
#define __byte_perm(x, y, b) x
|
||||
#endif
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#ifdef __CUDA_ARCH__
|
||||
|
||||
__device__ __forceinline__
|
||||
uint32_t ROR8(const uint32_t a) {
|
||||
return __byte_perm(a, 0, 0x0321);
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
uint32_t ROL16(const uint32_t a) {
|
||||
return __byte_perm(a, 0, 0x1032);
|
||||
}
|
||||
|
||||
#ifndef GPU_MIDSTATE
|
||||
__constant__ uint2 d_data[10];
|
||||
#else
|
||||
#define ROR8(u) (u >> 8)
|
||||
#define ROL16(u) (u << 16)
|
||||
__constant__ blake2s_state ALIGN(8) d_state[1];
|
||||
#endif
|
||||
|
||||
__device__ __forceinline__
|
||||
uint32_t xor3x(uint32_t a, uint32_t b, uint32_t c)
|
||||
{
|
||||
uint32_t result;
|
||||
#if __CUDA_ARCH__ >= 500 && CUDA_VERSION >= 7050
|
||||
asm ("lop3.b32 %0, %1, %2, %3, 0x96;" : "=r"(result) : "r"(a), "r"(b),"r"(c)); //0x96 = 0xF0 ^ 0xCC ^ 0xAA
|
||||
#else
|
||||
result = a^b^c;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
static const uint32_t blake2s_IV[8] = {
|
||||
0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL,
|
||||
0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL
|
||||
};
|
||||
|
||||
static const uint8_t blake2s_sigma[10][16] = {
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
||||
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
|
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
|
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
|
||||
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
|
||||
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
|
||||
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
|
||||
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
|
||||
};
|
||||
|
||||
#define G(r,i,a,b,c,d) \
|
||||
do { \
|
||||
a = a + b + m[blake2s_sigma[r][2*i+0]]; \
|
||||
d = SPH_ROTR32(d ^ a, 16); \
|
||||
c = c + d; \
|
||||
b = SPH_ROTR32(b ^ c, 12); \
|
||||
a = a + b + m[blake2s_sigma[r][2*i+1]]; \
|
||||
d = SPH_ROTR32(d ^ a, 8); \
|
||||
c = c + d; \
|
||||
b = SPH_ROTR32(b ^ c, 7); \
|
||||
} while(0)
|
||||
#define ROUND(r) \
|
||||
do { \
|
||||
G(r,0,v[0],v[4],v[ 8],v[12]); \
|
||||
G(r,1,v[1],v[5],v[ 9],v[13]); \
|
||||
G(r,2,v[2],v[6],v[10],v[14]); \
|
||||
G(r,3,v[3],v[7],v[11],v[15]); \
|
||||
G(r,4,v[0],v[5],v[10],v[15]); \
|
||||
G(r,5,v[1],v[6],v[11],v[12]); \
|
||||
G(r,6,v[2],v[7],v[ 8],v[13]); \
|
||||
G(r,7,v[3],v[4],v[ 9],v[14]); \
|
||||
} while(0)
|
||||
|
||||
extern "C" void blake2s_hash(void *output, const void *input)
|
||||
{
|
||||
uint32_t m[16];
|
||||
uint32_t v[16];
|
||||
uint32_t h[8];
|
||||
|
||||
uint32_t *in = (uint32_t*)input;
|
||||
// COMPRESS
|
||||
for(int i = 0; i < 16; ++i )
|
||||
m[i] = in[i];
|
||||
|
||||
h[0] = 0x01010020 ^ blake2s_IV[0];
|
||||
h[1] = blake2s_IV[1];
|
||||
h[2] = blake2s_IV[2];
|
||||
h[3] = blake2s_IV[3];
|
||||
h[4] = blake2s_IV[4];
|
||||
h[5] = blake2s_IV[5];
|
||||
h[6] = blake2s_IV[6];
|
||||
h[7] = blake2s_IV[7];
|
||||
|
||||
for(int i = 0; i < 8; ++i )
|
||||
v[i] = h[i];
|
||||
|
||||
v[ 8] = blake2s_IV[0]; v[ 9] = blake2s_IV[1];
|
||||
v[10] = blake2s_IV[2]; v[11] = blake2s_IV[3];
|
||||
v[12] = 64 ^ blake2s_IV[4]; v[13] = blake2s_IV[5];
|
||||
v[14] = blake2s_IV[6]; v[15] = blake2s_IV[7];
|
||||
|
||||
ROUND( 0 ); ROUND( 1 );
|
||||
ROUND( 2 ); ROUND( 3 );
|
||||
ROUND( 4 ); ROUND( 5 );
|
||||
ROUND( 6 ); ROUND( 7 );
|
||||
ROUND( 8 ); ROUND( 9 );
|
||||
|
||||
for(size_t i = 0; i < 8; ++i)
|
||||
h[i] ^= v[i] ^ v[i + 8];
|
||||
|
||||
// COMPRESS
|
||||
m[0] = in[16]; m[1] = in[17];
|
||||
m[2] = in[18]; m[3] = in[19];
|
||||
for(size_t i = 4; i < 16; ++i)
|
||||
m[i] = 0;
|
||||
|
||||
for(size_t i = 0; i < 8; ++i)
|
||||
v[i] = h[i];
|
||||
|
||||
v[ 8] = blake2s_IV[0]; v[ 9] = blake2s_IV[1];
|
||||
v[10] = blake2s_IV[2]; v[11] = blake2s_IV[3];
|
||||
v[12] = 0x50 ^ blake2s_IV[4]; v[13] = blake2s_IV[5];
|
||||
v[14] = ~blake2s_IV[6]; v[15] = blake2s_IV[7];
|
||||
|
||||
ROUND( 0 ); ROUND( 1 );
|
||||
ROUND( 2 ); ROUND( 3 );
|
||||
ROUND( 4 ); ROUND( 5 );
|
||||
ROUND( 6 ); ROUND( 7 );
|
||||
ROUND( 8 ); ROUND( 9 );
|
||||
|
||||
for(size_t i = 0; i < 8; ++i)
|
||||
h[i] ^= v[i] ^ v[i + 8];
|
||||
|
||||
memcpy(output, h, 32);
|
||||
}
|
||||
|
||||
#define TPB 1024
|
||||
#define NPT 256
|
||||
#define maxResults 16
|
||||
#define NBN 1
|
||||
|
||||
__constant__ uint32_t _ALIGN(32) midstate[20];
|
||||
|
||||
/* 16 adapters max */
|
||||
static uint32_t *d_resNonce[MAX_GPUS];
|
||||
static uint32_t *h_resNonce[MAX_GPUS];
|
||||
|
||||
#define GS4(a,b,c,d,e,f,a1,b1,c1,d1,e1,f1,a2,b2,c2,d2,e2,f2,a3,b3,c3,d3,e3,f3){ \
|
||||
a += b + e; a1+= b1 + e1; a2+= b2 + e2; a3+= b3 + e3; \
|
||||
d = ROL16( d ^ a); d1 = ROL16(d1 ^ a1); d2 = ROL16(d2 ^ a2); d3 = ROL16(d3 ^ a3); \
|
||||
c +=d; c1+=d1; c2+=d2; c3+=d3;\
|
||||
b = ROTR32(b ^ c, 12); b1 = ROTR32(b1^c1, 12); b2 = ROTR32(b2^c2, 12); b3 = ROTR32(b3^c3, 12); \
|
||||
a += b + f; a1+= b1 + f1; a2+= b2 + f2; a3+= b3 + f3; \
|
||||
d = ROR8(d ^ a); d1 = ROR8(d1^a1); d2 = ROR8(d2^a2); d3 = ROR8(d3^a3); \
|
||||
c += d; c1 += d1; c2 += d2; c3 += d3;\
|
||||
b = ROTR32(b ^ c, 7); b1 = ROTR32(b1^c1, 7); b2 = ROTR32(b2^c2, 7); b3 = ROTR32(b3^c3, 7); \
|
||||
/* threads per block */
|
||||
#define TPB 512
|
||||
|
||||
/* max count of found nonces in one call */
|
||||
#define NBN 2
|
||||
#if NBN > 1
|
||||
static uint32_t extra_results[NBN] = { UINT32_MAX };
|
||||
#endif
|
||||
|
||||
extern "C" void blake2s_hash(void *output, const void *input)
|
||||
{
|
||||
uint8_t _ALIGN(A) hash[BLAKE2S_OUTBYTES];
|
||||
blake2s_state blake2_ctx;
|
||||
|
||||
blake2s_init(&blake2_ctx, BLAKE2S_OUTBYTES);
|
||||
blake2s_update(&blake2_ctx, (uint8_t*) input, 80);
|
||||
blake2s_final(&blake2_ctx, hash, BLAKE2S_OUTBYTES);
|
||||
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(TPB,1)
|
||||
void blake2s_gpu_hash_nonce(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce, const uint32_t ptarget7)
|
||||
__host__
|
||||
inline void blake2s_hash_end(uint32_t *output, const uint32_t *input)
|
||||
{
|
||||
const uint32_t step = gridDim.x * blockDim.x;
|
||||
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);
|
||||
}
|
||||
|
||||
uint32_t m[ 3];
|
||||
__host__
|
||||
void blake2s_setBlock(uint32_t *penddata, blake2s_state *pstate)
|
||||
{
|
||||
#ifndef GPU_MIDSTATE
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(d_data, penddata, 80, 0, cudaMemcpyHostToDevice));
|
||||
#else
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(d_state, pstate, sizeof(blake2s_state), 0, cudaMemcpyHostToDevice));
|
||||
#endif
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
uint64_t gpu_load64(void *src) {
|
||||
return *(uint64_t*)(src);
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void gpu_store32(void *dst, uint32_t dw) {
|
||||
*(uint32_t*)(dst) = dw;
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void gpu_store64(void *dst, uint64_t lw) {
|
||||
*(uint64_t*)(dst) = lw;
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void gpu_blake2s_set_lastnode(blake2s_state *S) {
|
||||
S->f[1] = ~0U;
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void gpu_blake2s_clear_lastnode(blake2s_state *S) {
|
||||
S->f[1] = 0U;
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void gpu_blake2s_increment_counter(blake2s_state *S, const uint32_t inc)
|
||||
{
|
||||
S->t[0] += inc;
|
||||
S->t[1] += ( S->t[0] < inc );
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void gpu_blake2s_set_lastblock(blake2s_state *S)
|
||||
{
|
||||
if (S->last_node) gpu_blake2s_set_lastnode(S);
|
||||
S->f[0] = ~0U;
|
||||
}
|
||||
|
||||
__device__
|
||||
void gpu_blake2s_compress(blake2s_state *S, const uint32_t *block)
|
||||
{
|
||||
uint32_t m[16];
|
||||
uint32_t v[16];
|
||||
|
||||
m[0] = midstate[16];
|
||||
m[1] = midstate[17];
|
||||
m[2] = midstate[18];
|
||||
const uint32_t blake2s_IV[8] = {
|
||||
0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL,
|
||||
0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL
|
||||
};
|
||||
|
||||
const uint32_t h7 = midstate[19];
|
||||
const uint8_t blake2s_sigma[10][16] = {
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
||||
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
|
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
|
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
|
||||
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
|
||||
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
|
||||
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
|
||||
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
|
||||
};
|
||||
|
||||
for(uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x ; thread <threads; thread+=step){
|
||||
#pragma unroll
|
||||
for(int i=0;i<16;i++){
|
||||
v[ i] = midstate[ i];
|
||||
}
|
||||
#pragma unroll
|
||||
for(int i = 0; i < 16; i++)
|
||||
m[i] = block[i];
|
||||
|
||||
uint32_t nonce = cuda_swab32(startNonce + thread);
|
||||
// Round( 0 );
|
||||
v[ 1] += nonce;
|
||||
v[13] = ROR8(v[13] ^ v[ 1]);
|
||||
v[ 9] += v[13];
|
||||
v[ 5] = ROTR32(v[ 5] ^ v[ 9], 7);
|
||||
#pragma unroll
|
||||
for(int i = 0; i < 8; i++)
|
||||
v[i] = S->h[i];
|
||||
|
||||
v[ 1]+= v[ 6];
|
||||
v[ 0]+= v[ 5];
|
||||
v[ 8] = blake2s_IV[0];
|
||||
v[ 9] = blake2s_IV[1];
|
||||
v[10] = blake2s_IV[2];
|
||||
v[11] = blake2s_IV[3];
|
||||
v[12] = S->t[0] ^ blake2s_IV[4];
|
||||
v[13] = S->t[1] ^ blake2s_IV[5];
|
||||
v[14] = S->f[0] ^ blake2s_IV[6];
|
||||
v[15] = S->f[1] ^ blake2s_IV[7];
|
||||
|
||||
v[12] = ROL16(v[12] ^ v[ 1]);
|
||||
v[13] = ROL16(v[13] ^ v[ 2]);
|
||||
v[15] = ROL16(v[15] ^ v[ 0]);
|
||||
|
||||
v[11]+= v[12]; v[ 8]+= v[13]; v[ 9]+= v[14]; v[10]+= v[15];
|
||||
v[ 6] = ROTR32(v[ 6] ^ v[11], 12); v[ 7] = ROTR32(v[ 7] ^ v[ 8], 12); v[ 4] = ROTR32(v[ 4] ^ v[ 9], 12); v[ 5] = ROTR32(v[ 5] ^ v[10], 12);
|
||||
v[ 1]+= v[ 6]; v[ 2]+= v[ 7]; v[ 3]+= v[ 4]; v[ 0]+= v[ 5];
|
||||
v[12] = ROR8(v[12] ^ v[ 1]); v[13] = ROR8(v[13] ^ v[ 2]); v[14] = ROR8(v[14] ^ v[ 3]); v[15] = ROR8(v[15] ^ v[ 0]);
|
||||
v[11]+= v[12]; v[ 8]+= v[13]; v[ 9]+= v[14]; v[10]+= v[15];
|
||||
v[ 6] = ROTR32(v[ 6] ^ v[11], 7); v[ 7] = ROTR32(v[ 7] ^ v[ 8], 7); v[ 4] = ROTR32(v[ 4] ^ v[ 9], 7); v[ 5] = ROTR32(v[ 5] ^ v[10], 7);
|
||||
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],m[ 1],0, v[ 1],v[ 6],v[11],v[12],m[ 0],m[ 2], v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],0,nonce);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,m[ 0], v[ 2],v[ 6],v[10],v[14],0,m[ 2], v[ 3],v[ 7],v[11],v[15],0,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],0,0, v[ 1],v[ 6],v[11],v[12],nonce,0, v[ 2],v[ 7],v[ 8],v[13],0,m[ 1], v[ 3],v[ 4],v[ 9],v[14],0,0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],nonce,m[ 1], v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],m[ 2],0, v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,m[ 0], v[ 3],v[ 4],v[ 9],v[14],0,0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,m[ 0], v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],m[ 2],0, v[ 3],v[ 7],v[11],v[15],0,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 1], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],nonce,0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],m[ 2],0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],m[ 0],0, v[ 3],v[ 7],v[11],v[15],0,nonce);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],0,0, v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],m[ 1],0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],m[ 1],0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],m[ 0],0, v[ 1],v[ 6],v[11],v[12],0,nonce, v[ 2],v[ 7],v[ 8],v[13],0,m[ 2], v[ 3],v[ 4],v[ 9],v[14],0,0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,m[ 1], v[ 3],v[ 7],v[11],v[15],nonce,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 0], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],m[ 2],0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,nonce, v[ 3],v[ 7],v[11],v[15],m[ 0],0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 2], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],m[ 1],0, v[ 3],v[ 4],v[ 9],v[14],0,0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,m[ 2], v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],m[ 1],0);
|
||||
|
||||
// GS(9,4,v[ 0],v[ 5],v[10],v[15]);
|
||||
v[ 0] += v[ 5];
|
||||
v[ 2] += v[ 7] + nonce;
|
||||
v[15] = ROL16(v[15] ^ v[ 0]);
|
||||
v[13] = ROL16(v[13] ^ v[ 2]);
|
||||
v[10] += v[15];
|
||||
v[ 8] += v[13];
|
||||
v[ 5] = ROTR32(v[ 5] ^ v[10], 12);
|
||||
v[ 7] = ROTR32(v[ 7] ^ v[ 8], 12);
|
||||
v[ 0] += v[ 5];
|
||||
v[ 2] += v[ 7];
|
||||
v[15] = ROR8(v[15] ^ v[ 0]);
|
||||
v[13] = ROR8(v[13] ^ v[ 2]);
|
||||
|
||||
v[ 8] += v[13];
|
||||
v[ 7] = ROTR32(v[ 7] ^ v[ 8], 7);
|
||||
|
||||
if (xor3x(h7,v[7],v[15]) <= ptarget7){
|
||||
uint32_t pos = atomicInc(&resNonce[0],0xffffffff)+1;
|
||||
if(pos < maxResults)
|
||||
resNonce[pos] = nonce;
|
||||
return;
|
||||
}
|
||||
#define G(r,i,a,b,c,d) { \
|
||||
a += b + m[blake2s_sigma[r][2*i+0]]; \
|
||||
d = __byte_perm(d ^ a, 0, 0x1032); /* d = ROTR32(d ^ a, 16); */ \
|
||||
c = c + d; \
|
||||
b = ROTR32(b ^ c, 12); \
|
||||
a += b + m[blake2s_sigma[r][2*i+1]]; \
|
||||
d = __byte_perm(d ^ a, 0, 0x0321); /* ROTR32(d ^ a, 8); */ \
|
||||
c = c + d; \
|
||||
b = ROTR32(b ^ c, 7); \
|
||||
}
|
||||
|
||||
#define ROUND(r) { \
|
||||
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
|
||||
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
|
||||
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
|
||||
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
|
||||
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
|
||||
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
|
||||
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
|
||||
G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
|
||||
}
|
||||
|
||||
ROUND( 0 );
|
||||
ROUND( 1 );
|
||||
ROUND( 2 );
|
||||
ROUND( 3 );
|
||||
ROUND( 4 );
|
||||
ROUND( 5 );
|
||||
ROUND( 6 );
|
||||
ROUND( 7 );
|
||||
ROUND( 8 );
|
||||
ROUND( 9 );
|
||||
|
||||
#pragma unroll
|
||||
for(int i = 0; i < 8; i++)
|
||||
S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
|
||||
|
||||
#undef G
|
||||
#undef ROUND
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(TPB,1)
|
||||
void blake2s_gpu_hash_nonce(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce)
|
||||
#if 0
|
||||
/* unused but kept as reference */
|
||||
__device__ __forceinline__
|
||||
void gpu_blake2s_update(blake2s_state *S, const uint8_t *in, uint64_t inlen)
|
||||
{
|
||||
const uint32_t step = gridDim.x * blockDim.x;
|
||||
|
||||
uint32_t m[ 3];
|
||||
uint32_t v[16];
|
||||
|
||||
m[0] = midstate[16];
|
||||
m[1] = midstate[17];
|
||||
m[2] = midstate[18];
|
||||
|
||||
const uint32_t h7 = midstate[19];
|
||||
|
||||
for(uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x ; thread <threads; thread+=step)
|
||||
while(inlen > 0)
|
||||
{
|
||||
#pragma unroll
|
||||
for(int i=0;i<16;i++){
|
||||
v[ i] = midstate[ i];
|
||||
const int left = S->buflen;
|
||||
size_t fill = 2 * BLAKE2S_BLOCKBYTES - left;
|
||||
if(inlen > fill)
|
||||
{
|
||||
memcpy(S->buf + left, in, fill); // Fill buffer
|
||||
S->buflen += fill;
|
||||
|
||||
gpu_blake2s_increment_counter(S, BLAKE2S_BLOCKBYTES);
|
||||
gpu_blake2s_compress(S, (uint32_t*) S->buf); // Compress
|
||||
memcpy(S->buf, S->buf + BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES); // Shift buffer left
|
||||
S->buflen -= BLAKE2S_BLOCKBYTES;
|
||||
in += fill;
|
||||
inlen -= fill;
|
||||
}
|
||||
|
||||
uint32_t nonce = cuda_swab32(startNonce+thread);
|
||||
|
||||
// Round( 0 );
|
||||
v[ 1] += nonce;
|
||||
v[13] = ROR8(v[13] ^ v[ 1]);
|
||||
v[ 9] += v[13];
|
||||
v[ 5] = ROTR32(v[ 5] ^ v[ 9], 7);
|
||||
|
||||
v[ 1]+= v[ 6];
|
||||
v[ 0]+= v[ 5];
|
||||
|
||||
v[13] = ROL16(v[13] ^ v[ 2]); v[12] = ROL16(v[12] ^ v[ 1]); v[15] = ROL16(v[15] ^ v[ 0]);
|
||||
|
||||
v[ 8]+= v[13]; v[11]+= v[12]; v[ 9]+= v[14]; v[10]+= v[15];
|
||||
v[ 7] = ROTR32(v[ 7] ^ v[ 8], 12); v[ 6] = ROTR32(v[ 6] ^ v[11], 12); v[ 4] = ROTR32(v[ 4] ^ v[ 9], 12); v[ 5] = ROTR32(v[ 5] ^ v[10], 12);
|
||||
v[ 2]+= v[ 7]; v[ 1]+= v[ 6]; v[ 3]+= v[ 4]; v[ 0]+= v[ 5];
|
||||
v[13] = ROR8(v[13] ^ v[ 2]); v[12] = ROR8(v[12] ^ v[ 1]); v[14] = ROR8(v[14] ^ v[ 3]); v[15] = ROR8(v[15] ^ v[ 0]);
|
||||
v[ 8]+= v[13]; v[11]+= v[12]; v[ 9]+= v[14]; v[10]+= v[15];
|
||||
v[ 6] = ROTR32(v[ 6] ^ v[11], 7); v[ 7] = ROTR32(v[ 7] ^ v[8], 7); v[ 4] = ROTR32(v[ 4] ^ v[ 9], 7); v[ 5] = ROTR32(v[ 5] ^ v[10], 7);
|
||||
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],m[ 1],0, v[ 1],v[ 6],v[11],v[12],m[ 0],m[ 2], v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],0,nonce);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,m[ 0], v[ 2],v[ 6],v[10],v[14],0,m[ 2], v[ 3],v[ 7],v[11],v[15],0,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],0,0, v[ 1],v[ 6],v[11],v[12],nonce,0, v[ 2],v[ 7],v[ 8],v[13],0,m[ 1], v[ 3],v[ 4],v[ 9],v[14],0,0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],nonce,m[ 1], v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],m[ 2],0, v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,m[ 0], v[ 3],v[ 4],v[ 9],v[14],0,0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,m[ 0], v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],m[ 2],0, v[ 3],v[ 7],v[11],v[15],0,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 1], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],nonce,0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],m[ 2],0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],m[ 0],0, v[ 3],v[ 7],v[11],v[15],0,nonce);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],0,0, v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],m[ 1],0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],m[ 1],0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],m[ 0],0, v[ 1],v[ 6],v[11],v[12],0,nonce, v[ 2],v[ 7],v[ 8],v[13],0,m[ 2], v[ 3],v[ 4],v[ 9],v[14],0,0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,m[ 1], v[ 3],v[ 7],v[11],v[15],nonce,0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 0], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],m[ 2],0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,nonce, v[ 3],v[ 7],v[11],v[15],m[ 0],0);
|
||||
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 2], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],m[ 1],0, v[ 3],v[ 4],v[ 9],v[14],0,0);
|
||||
GS4(v[ 0],v[ 4],v[ 8],v[12],0,m[ 2], v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],m[ 1],0);
|
||||
|
||||
v[ 0] += v[ 5];
|
||||
v[ 2] += v[ 7] + nonce;
|
||||
v[15] = ROL16(v[15] ^ v[ 0]);
|
||||
v[13] = ROL16(v[13] ^ v[ 2]);
|
||||
v[10] += v[15];
|
||||
v[ 8] += v[13];
|
||||
v[ 5] = ROTR32(v[ 5] ^ v[10], 12);
|
||||
v[ 7] = ROTR32(v[ 7] ^ v[ 8], 12);
|
||||
v[ 0] += v[ 5];
|
||||
v[ 2] += v[ 7];
|
||||
v[15] = ROTR32(v[15] ^ v[ 0],1);
|
||||
v[13] = ROR8(v[13] ^ v[ 2]);
|
||||
|
||||
v[ 8] += v[13];
|
||||
|
||||
if(xor3x(v[ 7],h7,v[ 8])==v[15]){
|
||||
uint32_t pos = atomicInc(&resNonce[0],0xffffffff)+1;
|
||||
if(pos < maxResults)
|
||||
resNonce[pos]=nonce;
|
||||
return;
|
||||
else // inlen <= fill
|
||||
{
|
||||
memcpy(S->buf + left, in, (size_t) inlen);
|
||||
S->buflen += (size_t) inlen; // Be lazy, do not compress
|
||||
in += inlen;
|
||||
inlen -= inlen;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void blake2s_setBlock(const uint32_t* input,const uint32_t ptarget7)
|
||||
#ifndef GPU_MIDSTATE
|
||||
__device__ __forceinline__
|
||||
void gpu_blake2s_fill_data(blake2s_state *S, const uint32_t nonce)
|
||||
{
|
||||
uint32_t _ALIGN(64) m[16];
|
||||
uint32_t _ALIGN(64) v[16];
|
||||
uint32_t _ALIGN(64) h[21];
|
||||
uint2 *b2 = (uint2*) S->buf;
|
||||
#pragma unroll
|
||||
for (int i=0; i < 9; i++)
|
||||
b2[i] = d_data[i];
|
||||
b2[9].x = d_data[9].x;
|
||||
b2[9].y = nonce;
|
||||
S->buflen = 80;
|
||||
}
|
||||
#endif
|
||||
|
||||
// COMPRESS
|
||||
for(int i = 0; i < 16; ++i )
|
||||
m[i] = input[i];
|
||||
__device__ __forceinline__
|
||||
void gpu_blake2s_update_nonce(blake2s_state *S, const uint32_t nonce)
|
||||
{
|
||||
gpu_store32(&S->buf[76], nonce);
|
||||
S->buflen = 80;
|
||||
}
|
||||
|
||||
h[0] = 0x01010020 ^ blake2s_IV[0];
|
||||
h[1] = blake2s_IV[1];
|
||||
h[2] = blake2s_IV[2]; h[3] = blake2s_IV[3];
|
||||
h[4] = blake2s_IV[4]; h[5] = blake2s_IV[5];
|
||||
h[6] = blake2s_IV[6]; h[7] = blake2s_IV[7];
|
||||
|
||||
for(int i = 0; i < 8; ++i )
|
||||
v[i] = h[i];
|
||||
|
||||
v[ 8] = blake2s_IV[0]; v[ 9] = blake2s_IV[1];
|
||||
v[10] = blake2s_IV[2]; v[11] = blake2s_IV[3];
|
||||
v[12] = 64 ^ blake2s_IV[4]; v[13] = blake2s_IV[5];
|
||||
v[14] = blake2s_IV[6]; v[15] = blake2s_IV[7];
|
||||
|
||||
ROUND( 0 ); ROUND( 1 );
|
||||
ROUND( 2 ); ROUND( 3 );
|
||||
ROUND( 4 ); ROUND( 5 );
|
||||
ROUND( 6 ); ROUND( 7 );
|
||||
ROUND( 8 ); ROUND( 9 );
|
||||
|
||||
for(int i = 0; i < 8; ++i )
|
||||
h[i] ^= v[i] ^ v[i + 8];
|
||||
|
||||
h[16] = input[16];
|
||||
h[17] = input[17];
|
||||
h[18] = input[18];
|
||||
|
||||
h[ 8] = 0x6A09E667; h[ 9] = 0xBB67AE85;
|
||||
h[10] = 0x3C6EF372; h[11] = 0xA54FF53A;
|
||||
h[12] = 0x510E522F; h[13] = 0x9B05688C;
|
||||
h[14] =~0x1F83D9AB; h[15] = 0x5BE0CD19;
|
||||
|
||||
h[ 0]+= h[ 4] + h[16];
|
||||
h[12] = SPH_ROTR32(h[12] ^ h[ 0],16);
|
||||
h[ 8]+= h[12];
|
||||
h[ 4] = SPH_ROTR32(h[ 4] ^ h[ 8],12);
|
||||
h[ 0]+= h[ 4] + h[17];
|
||||
h[12] = SPH_ROTR32(h[12] ^ h[ 0],8);
|
||||
h[ 8]+= h[12];
|
||||
h[ 4] = SPH_ROTR32(h[ 4] ^ h[ 8],7);
|
||||
|
||||
h[ 1]+= h[ 5] + h[18];
|
||||
h[13] = SPH_ROTR32(h[13] ^ h[ 1], 16);
|
||||
h[ 9]+= h[13];
|
||||
h[ 5] = ROTR32(h[ 5] ^ h[ 9], 12);
|
||||
|
||||
h[ 2]+= h[ 6];
|
||||
h[14] = SPH_ROTR32(h[14] ^ h[ 2],16);
|
||||
h[10]+= h[14];
|
||||
h[ 6] = SPH_ROTR32(h[ 6] ^ h[10], 12);
|
||||
h[ 2]+= h[ 6];
|
||||
h[14] = SPH_ROTR32(h[14] ^ h[ 2],8);
|
||||
h[10]+= h[14];
|
||||
h[ 6] = SPH_ROTR32(h[ 6] ^ h[10], 7);
|
||||
|
||||
h[19] = h[7]; //constant h[7] for nonce check
|
||||
|
||||
h[ 3]+= h[ 7];
|
||||
h[15] = SPH_ROTR32(h[15] ^ h[ 3],16);
|
||||
h[11]+= h[15];
|
||||
h[ 7] = SPH_ROTR32(h[ 7] ^ h[11], 12);
|
||||
h[ 3]+= h[ 7];
|
||||
h[15] = SPH_ROTR32(h[15] ^ h[ 3],8);
|
||||
h[11]+= h[15];
|
||||
h[ 7] = SPH_ROTR32(h[ 7] ^ h[11], 7);
|
||||
|
||||
h[ 1]+= h[ 5];
|
||||
h[ 3]+= h[ 4];
|
||||
h[14] = SPH_ROTR32(h[14] ^ h[ 3],16);
|
||||
|
||||
h[ 2]+= h[ 7];
|
||||
if(ptarget7==0){
|
||||
h[19] = SPH_ROTL32(h[19],7); //align the rotation with v[7] v[15];
|
||||
__device__ __forceinline__
|
||||
uint2 gpu_blake2s_final(blake2s_state *S)
|
||||
{
|
||||
//if (S->buflen > BLAKE2S_BLOCKBYTES)
|
||||
{
|
||||
gpu_blake2s_increment_counter(S, BLAKE2S_BLOCKBYTES);
|
||||
gpu_blake2s_compress(S, (uint32_t*) S->buf);
|
||||
S->buflen -= BLAKE2S_BLOCKBYTES;
|
||||
//memcpy(S->buf, S->buf + BLAKE2S_BLOCKBYTES, S->buflen);
|
||||
}
|
||||
cudaMemcpyToSymbol(midstate, h, 20*sizeof(uint32_t), 0, cudaMemcpyHostToDevice);
|
||||
|
||||
gpu_blake2s_increment_counter(S, (uint32_t)S->buflen);
|
||||
gpu_blake2s_set_lastblock(S);
|
||||
//memset(&S->buf[S->buflen], 0, 2 * BLAKE2S_BLOCKBYTES - S->buflen); /* Padding */
|
||||
gpu_blake2s_compress(S, (uint32_t*) (S->buf + BLAKE2S_BLOCKBYTES));
|
||||
|
||||
//#pragma unroll
|
||||
//for (int i = 0; i < 8; i++)
|
||||
// out[i] = S->h[i];
|
||||
return make_uint2(S->h[6], S->h[7]);
|
||||
}
|
||||
|
||||
/* init2 xors IV with input parameter block */
|
||||
__device__ __forceinline__
|
||||
void gpu_blake2s_init_param(blake2s_state *S, const blake2s_param *P)
|
||||
{
|
||||
//blake2s_IV
|
||||
S->h[0] = 0x6A09E667UL;
|
||||
S->h[1] = 0xBB67AE85UL;
|
||||
S->h[2] = 0x3C6EF372UL;
|
||||
S->h[3] = 0xA54FF53AUL;
|
||||
S->h[4] = 0x510E527FUL;
|
||||
S->h[5] = 0x9B05688CUL;
|
||||
S->h[6] = 0x1F83D9ABUL;
|
||||
S->h[7] = 0x5BE0CD19UL;
|
||||
|
||||
S->t[0] = 0; S->t[1] = 0;
|
||||
S->f[0] = 0; S->f[1] = 0;
|
||||
S->last_node = 0;
|
||||
|
||||
S->buflen = 0;
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 8; i < sizeof(S->buf)/8; i++)
|
||||
gpu_store64(S->buf + (8*i), 0);
|
||||
|
||||
uint64_t *p = (uint64_t*) P;
|
||||
|
||||
/* IV XOR ParamBlock */
|
||||
#pragma unroll
|
||||
for (int i = 0; i < 4; i++)
|
||||
S->h[i] ^= gpu_load64(&p[i]);
|
||||
}
|
||||
|
||||
// Sequential blake2s initialization
|
||||
__device__ __forceinline__
|
||||
void gpu_blake2s_init(blake2s_state *S, const uint8_t outlen)
|
||||
{
|
||||
blake2s_param P[1];
|
||||
|
||||
// if (!outlen || outlen > BLAKE2S_OUTBYTES) return;
|
||||
|
||||
P->digest_length = outlen;
|
||||
P->key_length = 0;
|
||||
P->fanout = 1;
|
||||
P->depth = 1;
|
||||
|
||||
P->leaf_length = 0;
|
||||
gpu_store64(P->node_offset, 0);
|
||||
//P->node_depth = 0;
|
||||
//P->inner_length = 0;
|
||||
|
||||
gpu_store64(&P->salt, 0);
|
||||
gpu_store64(&P->personal, 0);
|
||||
|
||||
gpu_blake2s_init_param(S, P);
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void gpu_copystate(blake2s_state *dst, blake2s_state *src)
|
||||
{
|
||||
uint64_t* d64 = (uint64_t*) dst;
|
||||
uint64_t* s64 = (uint64_t*) src;
|
||||
#pragma unroll
|
||||
for (int i=0; i < (32 + 16 + 2 * BLAKE2S_BLOCKBYTES)/8; i++)
|
||||
gpu_store64(&d64[i], s64[i]);
|
||||
dst->buflen = src->buflen;
|
||||
dst->last_node = src->last_node;
|
||||
}
|
||||
|
||||
__global__
|
||||
void blake2s_gpu_hash(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce, const uint2 target2, const int swap)
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
const uint32_t nonce = swap ? cuda_swab32(startNonce + thread) : startNonce + thread;
|
||||
blake2s_state ALIGN(8) blake2_ctx;
|
||||
|
||||
#ifndef GPU_MIDSTATE
|
||||
gpu_blake2s_init(&blake2_ctx, BLAKE2S_OUTBYTES);
|
||||
//gpu_blake2s_update(&blake2_ctx, (uint8_t*) d_data, 76);
|
||||
gpu_blake2s_fill_data(&blake2_ctx, nonce);
|
||||
#else
|
||||
gpu_copystate(&blake2_ctx, &d_state[0]);
|
||||
gpu_blake2s_update_nonce(&blake2_ctx, nonce);
|
||||
#endif
|
||||
|
||||
uint2 h2 = gpu_blake2s_final(&blake2_ctx);
|
||||
if (h2.y <= target2.y && h2.x <= target2.x) {
|
||||
#if NBN == 2
|
||||
if (resNonce[0] != UINT32_MAX)
|
||||
resNonce[1] = nonce;
|
||||
else
|
||||
resNonce[0] = nonce;
|
||||
#else
|
||||
resNonce[0] = nonce;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static __inline uint32_t swab32_if(uint32_t val, bool iftrue) {
|
||||
return iftrue ? swab32(val) : val;
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t blake2s_hash_cuda(const int thr_id, const uint32_t threads, const uint32_t startNonce, const uint2 target2, const int swap)
|
||||
{
|
||||
uint32_t result = UINT32_MAX;
|
||||
|
||||
dim3 grid((threads + TPB-1)/TPB);
|
||||
dim3 block(TPB);
|
||||
|
||||
/* Check error on Ctrl+C or kill to prevent segfaults on exit */
|
||||
if (cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)) != cudaSuccess)
|
||||
return result;
|
||||
|
||||
blake2s_gpu_hash <<<grid, block>>> (threads, startNonce, d_resNonce[thr_id], target2, swap);
|
||||
cudaThreadSynchronize();
|
||||
|
||||
if (cudaSuccess == cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost)) {
|
||||
result = swab32_if(h_resNonce[thr_id][0], swap);
|
||||
#if NBN > 1
|
||||
for (int n=0; n < (NBN-1); n++)
|
||||
extra_results[n] = swab32_if(h_resNonce[thr_id][n+1], swap);
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
@@ -431,21 +404,23 @@ static bool init[MAX_GPUS] = { 0 };
|
||||
extern "C" int scanhash_blake2s(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
uint32_t *resNonces;
|
||||
const int swap = 1; // to toggle nonce endian
|
||||
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
|
||||
const int dev_id = device_map[thr_id];
|
||||
int rc = 0;
|
||||
int intensity = is_windows() ? 25 : 28;
|
||||
int dev_id = device_map[thr_id];
|
||||
int intensity = (device_sm[dev_id] >= 500 && !is_windows()) ? 28 : 25;
|
||||
if (device_sm[dev_id] < 350) intensity = 22;
|
||||
|
||||
uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity);
|
||||
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
const dim3 grid((throughput + (NPT*TPB)-1)/(NPT*TPB));
|
||||
const dim3 block(TPB);
|
||||
if (opt_benchmark) {
|
||||
ptarget[6] = swab32(0xFFFF0);
|
||||
ptarget[7] = 0;
|
||||
}
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
@@ -454,97 +429,73 @@ extern "C" int scanhash_blake2s(int thr_id, struct work *work, uint32_t max_nonc
|
||||
cudaDeviceReset();
|
||||
// reduce cpu usage (linux)
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
|
||||
cuda_get_arch(thr_id);
|
||||
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], maxResults * sizeof(uint32_t)), -1);
|
||||
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], maxResults * sizeof(uint32_t)), -1);
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
|
||||
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
|
||||
init[thr_id] = true;
|
||||
}
|
||||
resNonces = h_resNonce[thr_id];
|
||||
|
||||
for (int i=0; i < 19; i++) {
|
||||
be32enc(&endiandata[i], pdata[i]);
|
||||
}
|
||||
blake2s_setBlock(endiandata,ptarget[7]);
|
||||
|
||||
cudaMemset(d_resNonce[thr_id], 0x00, maxResults*sizeof(uint32_t));
|
||||
// midstate
|
||||
memset(s_midstate.buf, 0, sizeof(s_midstate.buf));
|
||||
blake2s_init(&s_midstate, BLAKE2S_OUTBYTES);
|
||||
blake2s_update(&s_midstate, (uint8_t*) endiandata, MIDLEN);
|
||||
memcpy(&s_ctx, &s_midstate, sizeof(blake2s_state));
|
||||
|
||||
blake2s_setBlock(endiandata, &s_midstate);
|
||||
|
||||
const uint2 target = make_uint2(ptarget[6], ptarget[7]);
|
||||
|
||||
do {
|
||||
if(ptarget[7]) {
|
||||
blake2s_gpu_hash_nonce<<<grid, block>>>(throughput,pdata[19],d_resNonce[thr_id],ptarget[7]);
|
||||
} else {
|
||||
blake2s_gpu_hash_nonce<<<grid, block>>>(throughput,pdata[19],d_resNonce[thr_id]);
|
||||
}
|
||||
cudaMemcpy(resNonces, d_resNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
uint32_t foundNonce = blake2s_hash_cuda(thr_id, throughput, pdata[19], target, swap);
|
||||
|
||||
if(resNonces[0])
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
cudaMemcpy(resNonces, d_resNonce[thr_id], maxResults*sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
cudaMemset(d_resNonce[thr_id], 0x00, sizeof(uint32_t));
|
||||
uint32_t _ALIGN(A) vhashcpu[8];
|
||||
|
||||
if(resNonces[0] >= maxResults) {
|
||||
gpulog(LOG_WARNING, thr_id, "candidates flood: %u", resNonces[0]);
|
||||
resNonces[0] = maxResults-1;
|
||||
}
|
||||
//blake2s_hash(vhashcpu, endiandata);
|
||||
endiandata[19] = swab32_if(foundNonce, swap);
|
||||
blake2s_hash_end(vhashcpu, endiandata);
|
||||
|
||||
uint32_t vhashcpu[8];
|
||||
uint32_t nonce = sph_bswap32(resNonces[1]);
|
||||
be32enc(&endiandata[19], nonce);
|
||||
blake2s_hash(vhashcpu, endiandata);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
if(vhashcpu[6] <= ptarget[6] && fulltest(vhashcpu, ptarget))
|
||||
{
|
||||
if (vhashcpu[7] <= target.y && fulltest(vhashcpu, ptarget)) {
|
||||
work_set_target_ratio(work, vhashcpu);
|
||||
work->nonces[0] = nonce;
|
||||
rc = work->valid_nonces = 1;
|
||||
|
||||
// search for 2nd best nonce
|
||||
for(uint32_t j=2; j <= resNonces[0]; j++)
|
||||
{
|
||||
nonce = sph_bswap32(resNonces[j]);
|
||||
be32enc(&endiandata[19], nonce);
|
||||
blake2s_hash(vhashcpu, endiandata);
|
||||
if(vhashcpu[6] <= ptarget[6] && fulltest(vhashcpu, ptarget))
|
||||
{
|
||||
gpulog(LOG_DEBUG, thr_id, "Multiple nonces: 1/%08x - %u/%08x", work->nonces[0], j, nonce);
|
||||
|
||||
work->nonces[1] = nonce;
|
||||
if (bn_hash_target_ratio(vhashcpu, ptarget) > work->shareratio[0]) {
|
||||
work->shareratio[1] = work->shareratio[0];
|
||||
work->sharediff[1] = work->sharediff[0];
|
||||
xchg(work->nonces[1], work->nonces[0]);
|
||||
pdata[19] = work->nonces[0] = swab32_if(foundNonce, !swap);
|
||||
#if NBN > 1
|
||||
if (extra_results[0] != UINT32_MAX) {
|
||||
endiandata[19] = swab32_if(extra_results[0], swap);
|
||||
blake2s_hash_end(vhashcpu, endiandata);
|
||||
if (vhashcpu[7] <= target.y && fulltest(vhashcpu, ptarget)) {
|
||||
work->nonces[1] = swab32_if(extra_results[0], !swap);
|
||||
if (bn_hash_target_ratio(vhashcpu, ptarget) > work->shareratio) {
|
||||
work_set_target_ratio(work, vhashcpu);
|
||||
} else if (work->valid_nonces == 1) {
|
||||
bn_set_target_ratio(work, vhashcpu, 1);
|
||||
xchg(work->nonces[1], pdata[19]);
|
||||
}
|
||||
|
||||
work->valid_nonces++;
|
||||
rc = 2;
|
||||
break;
|
||||
return 2;
|
||||
}
|
||||
extra_results[0] = UINT32_MAX;
|
||||
}
|
||||
pdata[19] = max(work->nonces[0], work->nonces[1]); // next scan start
|
||||
return rc;
|
||||
} else if (vhashcpu[7] > ptarget[7]) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", resNonces[0]);
|
||||
#endif
|
||||
return 1;
|
||||
} else {
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (!work_restart[thr_id].restart && (uint64_t)max_nonce > (uint64_t)throughput + pdata[19]);
|
||||
} while (!work_restart[thr_id].restart && max_nonce > (uint64_t)throughput + pdata[19]);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
|
||||
return rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
@@ -562,4 +513,3 @@ extern "C" void free_blake2s(int thr_id)
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
|
||||
+21
-38
@@ -6,8 +6,9 @@ extern "C" {
|
||||
#include "sph/sph_bmw.h"
|
||||
}
|
||||
|
||||
#include <miner.h>
|
||||
#include <cuda_helper.h>
|
||||
#include "miner.h"
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS];
|
||||
|
||||
@@ -33,12 +34,17 @@ extern "C" void bmw_hash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
static __inline uint32_t swab32_if(uint32_t val, bool iftrue) {
|
||||
return iftrue ? swab32(val) : val;
|
||||
}
|
||||
|
||||
extern "C" int scanhash_bmw(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
bool swapnonce = true;
|
||||
uint32_t throughput = cuda_default_throughput(thr_id, 1U << 21);
|
||||
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
@@ -47,12 +53,6 @@ extern "C" int scanhash_bmw(int thr_id, struct work* work, uint32_t max_nonce, u
|
||||
|
||||
if (!init[thr_id]) {
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
if (opt_cudaschedule == -1 && gpu_threads == 1) {
|
||||
cudaDeviceReset();
|
||||
// reduce cpu usage
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
}
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
|
||||
cuda_check_cpu_init(thr_id, throughput);
|
||||
bmw256_midstate_init(thr_id, throughput);
|
||||
@@ -72,39 +72,22 @@ extern "C" int scanhash_bmw(int thr_id, struct work* work, uint32_t max_nonce, u
|
||||
cuda_check_cpu_setTarget(ptarget);
|
||||
|
||||
do {
|
||||
bmw256_cpu_hash_80(thr_id, (int) throughput, pdata[19], d_hash[thr_id], 1);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
work->nonces[0] = cuda_check_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (work->nonces[0] != UINT32_MAX)
|
||||
bmw256_cpu_hash_80(thr_id, (int) throughput, pdata[19], d_hash[thr_id], (int) swapnonce);
|
||||
uint32_t foundNonce = cuda_check_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t _ALIGN(64) vhash[8];
|
||||
be32enc(&endiandata[19], work->nonces[0]);
|
||||
bmw_hash(vhash, endiandata);
|
||||
uint32_t _ALIGN(64) vhash64[8];
|
||||
endiandata[19] = swab32_if(foundNonce, swapnonce);
|
||||
bmw_hash(vhash64, endiandata);
|
||||
|
||||
if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
|
||||
work->valid_nonces = 1;
|
||||
work_set_target_ratio(work, vhash);
|
||||
work->nonces[1] = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
if (work->nonces[1] != 0) {
|
||||
be32enc(&endiandata[19], work->nonces[1]);
|
||||
bmw_hash(vhash, endiandata);
|
||||
bn_set_target_ratio(work, vhash, 1);
|
||||
work->valid_nonces++;
|
||||
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
|
||||
} else {
|
||||
pdata[19] = work->nonces[0] + 1; // cursor
|
||||
}
|
||||
return work->valid_nonces;
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
*hashes_done = foundNonce - first_nonce + 1;
|
||||
pdata[19] = swab32_if(foundNonce,!swapnonce);
|
||||
work_set_target_ratio(work, vhash64);
|
||||
return 1;
|
||||
}
|
||||
else if (vhash[7] > Htarg) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
|
||||
pdata[19] = work->nonces[0] + 1;
|
||||
continue;
|
||||
else {
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+337
-199
@@ -2,39 +2,34 @@
|
||||
* Blake-256 Cuda Kernel (Tested on SM 5.0)
|
||||
*
|
||||
* Tanguy Pruvot - Nov. 2014
|
||||
*
|
||||
* + merged blake+keccak kernel for lyra2v2
|
||||
*/
|
||||
extern "C" {
|
||||
#include "sph/sph_blake.h"
|
||||
}
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
#ifdef __INTELLISENSE__
|
||||
/* just for vstudio code colors */
|
||||
__device__ uint32_t __byte_perm(uint32_t a, uint32_t b, uint32_t c);
|
||||
#endif
|
||||
|
||||
#define UINT2(x,y) make_uint2(x,y)
|
||||
|
||||
__device__ __inline__ uint2 ROR8(const uint2 a) {
|
||||
__device__ __inline__ uint2 ROR8(const uint2 a)
|
||||
{
|
||||
uint2 result;
|
||||
result.x = __byte_perm(a.y, a.x, 0x0765);
|
||||
result.y = __byte_perm(a.x, a.y, 0x0765);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static __device__ uint64_t cuda_swab32ll(uint64_t x) {
|
||||
return MAKE_ULONGLONG(cuda_swab32(_LODWORD(x)), cuda_swab32(_HIDWORD(x)));
|
||||
}
|
||||
|
||||
__constant__ static uint32_t c_data[3 + 1];
|
||||
//static __device__ uint64_t cuda_swab32ll(uint64_t x) {
|
||||
// return MAKE_ULONGLONG(cuda_swab32(_LOWORD(x)), cuda_swab32(_HIWORD(x)));
|
||||
//}
|
||||
|
||||
__constant__ static uint32_t sigma[16][16];
|
||||
static uint32_t c_sigma[16][16] = {
|
||||
__constant__ static uint32_t c_data[3];
|
||||
|
||||
//__constant__ static uint8_t sigma[16][16];
|
||||
static uint8_t c_sigma[16][16] = {
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
||||
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
||||
@@ -62,7 +57,7 @@ static const uint32_t c_IV256[8] = {
|
||||
|
||||
__device__ __constant__ static uint32_t cpu_h[8];
|
||||
|
||||
__device__ __constant__ static uint32_t u256[16];
|
||||
//__device__ __constant__ static uint32_t u256[16];
|
||||
static const uint32_t c_u256[16] = {
|
||||
0x243F6A88, 0x85A308D3,
|
||||
0x13198A2E, 0x03707344,
|
||||
@@ -74,6 +69,60 @@ static const uint32_t c_u256[16] = {
|
||||
0x3F84D5B5, 0xB5470917
|
||||
};
|
||||
|
||||
#define GS2(a,b,c,d,x) { \
|
||||
const uint8_t idx1 = sigma[r][x]; \
|
||||
const uint8_t idx2 = sigma[r][x+1]; \
|
||||
v[a] += (m[idx1] ^ u256[idx2]) + v[b]; \
|
||||
v[d] = __byte_perm(v[d] ^ v[a],0, 0x1032); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 12); \
|
||||
\
|
||||
v[a] += (m[idx2] ^ u256[idx1]) + v[b]; \
|
||||
v[d] = __byte_perm(v[d] ^ v[a],0, 0x0321); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 7); \
|
||||
}
|
||||
|
||||
#define hostGS(a,b,c,d,x) { \
|
||||
const uint8_t idx1 = c_sigma[r][x]; \
|
||||
const uint8_t idx2 = c_sigma[r][x+1]; \
|
||||
v[a] += (m[idx1] ^ c_u256[idx2]) + v[b]; \
|
||||
v[d] = ROTR32(v[d] ^ v[a], 16); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = ROTR32(v[b] ^ v[c], 12); \
|
||||
\
|
||||
v[a] += (m[idx2] ^ c_u256[idx1]) + v[b]; \
|
||||
v[d] = ROTR32(v[d] ^ v[a], 8); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = ROTR32(v[b] ^ v[c], 7); \
|
||||
}
|
||||
|
||||
#define GSPREC(a,b,c,d,x,y) { \
|
||||
v[a] += (m[x] ^ u256[y]) + v[b]; \
|
||||
v[d] = __byte_perm(v[d] ^ v[a],0, 0x1032); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 12); \
|
||||
v[a] += (m[y] ^ u256[x]) + v[b]; \
|
||||
v[d] = __byte_perm(v[d] ^ v[a],0, 0x0321); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 7); \
|
||||
}
|
||||
|
||||
__constant__ uint64_t keccak_round_constants[24] = {
|
||||
0x0000000000000001ull, 0x0000000000008082ull,
|
||||
0x800000000000808aull, 0x8000000080008000ull,
|
||||
0x000000000000808bull, 0x0000000080000001ull,
|
||||
0x8000000080008081ull, 0x8000000000008009ull,
|
||||
0x000000000000008aull, 0x0000000000000088ull,
|
||||
0x0000000080008009ull, 0x000000008000000aull,
|
||||
0x000000008000808bull, 0x800000000000008bull,
|
||||
0x8000000000008089ull, 0x8000000000008003ull,
|
||||
0x8000000000008002ull, 0x8000000000000080ull,
|
||||
0x000000000000800aull, 0x800000008000000aull,
|
||||
0x8000000080008081ull, 0x8000000000008080ull,
|
||||
0x0000000080000001ull, 0x8000000080008008ull
|
||||
};
|
||||
|
||||
__constant__ uint2 keccak_round_constants35[24] = {
|
||||
{ 0x00000001ul, 0x00000000 }, { 0x00008082ul, 0x00000000 },
|
||||
{ 0x0000808aul, 0x80000000 }, { 0x80008000ul, 0x80000000 },
|
||||
@@ -89,56 +138,6 @@ __constant__ uint2 keccak_round_constants35[24] = {
|
||||
{ 0x80000001ul, 0x00000000 }, { 0x80008008ul, 0x80000000 }
|
||||
};
|
||||
|
||||
|
||||
#define GS2(a,b,c,d,x) { \
|
||||
const uint32_t idx1 = sigma[r][x]; \
|
||||
const uint32_t idx2 = sigma[r][(x)+1]; \
|
||||
v[a] += (m[idx1] ^ u256[idx2]) + v[b]; \
|
||||
v[d] = SPH_ROTL32(v[d] ^ v[a], 16); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 12); \
|
||||
\
|
||||
v[a] += (m[idx2] ^ u256[idx1]) + v[b]; \
|
||||
v[d] = SPH_ROTR32(v[d] ^ v[a], 8); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 7); \
|
||||
}
|
||||
|
||||
//#define ROTL32(x, n) ((x) << (n)) | ((x) >> (32 - (n)))
|
||||
//#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
|
||||
#define hostGS(a,b,c,d,x) { \
|
||||
const uint32_t idx1 = c_sigma[r][x]; \
|
||||
const uint32_t idx2 = c_sigma[r][(x)+1]; \
|
||||
v[a] += (m[idx1] ^ c_u256[idx2]) + v[b]; \
|
||||
v[d] = ROTR32(v[d] ^ v[a], 16); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = ROTR32(v[b] ^ v[c], 12); \
|
||||
\
|
||||
v[a] += (m[idx2] ^ c_u256[idx1]) + v[b]; \
|
||||
v[d] = ROTR32(v[d] ^ v[a], 8); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = ROTR32(v[b] ^ v[c], 7); \
|
||||
}
|
||||
|
||||
#define GSPREC(a,b,c,d,x,y) { \
|
||||
v[a] += (m[x] ^ u256[y]) + v[b]; \
|
||||
v[d] = __byte_perm(v[d] ^ v[a],0, 0x1032); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 12); \
|
||||
v[a] += (m[y] ^ u256[x]) + v[b]; \
|
||||
v[d] = __byte_perm(v[d] ^ v[a],0, 0x0321); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 7); \
|
||||
}
|
||||
|
||||
/* Second part (64-80) msg never change, store it */
|
||||
__device__ __constant__ static const uint32_t c_Padding[16] = {
|
||||
0, 0, 0, 0,
|
||||
0x80000000, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 1, 0, 640,
|
||||
};
|
||||
|
||||
__host__ __forceinline__
|
||||
static void blake256_compress1st(uint32_t *h, const uint32_t *block, const uint32_t T0)
|
||||
{
|
||||
@@ -175,72 +174,26 @@ static void blake256_compress1st(uint32_t *h, const uint32_t *block, const uint3
|
||||
hostGS(3, 4, 0x9, 0xE, 0xE);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int j = i & 7;
|
||||
h[j] ^= v[i];
|
||||
}
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
static void blake256_compress2nd(uint32_t *h, const uint32_t *block, const uint32_t T0)
|
||||
{
|
||||
uint32_t m[16];
|
||||
uint32_t v[16];
|
||||
|
||||
m[0] = block[0];
|
||||
m[1] = block[1];
|
||||
m[2] = block[2];
|
||||
m[3] = block[3];
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 4; i < 16; i++) {
|
||||
m[i] = c_Padding[i];
|
||||
}
|
||||
|
||||
#pragma unroll 8
|
||||
for (int i = 0; i < 8; i++)
|
||||
v[i] = h[i];
|
||||
|
||||
v[8] = u256[0];
|
||||
v[9] = u256[1];
|
||||
v[10] = u256[2];
|
||||
v[11] = u256[3];
|
||||
|
||||
v[12] = u256[4] ^ T0;
|
||||
v[13] = u256[5] ^ T0;
|
||||
v[14] = u256[6];
|
||||
v[15] = u256[7];
|
||||
|
||||
#pragma unroll 14
|
||||
for (int r = 0; r < 14; r++) {
|
||||
/* column step */
|
||||
GS2(0, 4, 0x8, 0xC, 0x0);
|
||||
GS2(1, 5, 0x9, 0xD, 0x2);
|
||||
GS2(2, 6, 0xA, 0xE, 0x4);
|
||||
GS2(3, 7, 0xB, 0xF, 0x6);
|
||||
/* diagonal step */
|
||||
GS2(0, 5, 0xA, 0xF, 0x8);
|
||||
GS2(1, 6, 0xB, 0xC, 0xA);
|
||||
GS2(2, 7, 0x8, 0xD, 0xC);
|
||||
GS2(3, 4, 0x9, 0xE, 0xE);
|
||||
}
|
||||
|
||||
#pragma unroll 16
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int j = i & 7;
|
||||
h[j] ^= v[i];
|
||||
}
|
||||
h[0] ^= v[0] ^ v[8];
|
||||
h[1] ^= v[1] ^ v[9];
|
||||
h[2] ^= v[2] ^ v[10];
|
||||
h[3] ^= v[3] ^ v[11];
|
||||
h[4] ^= v[4] ^ v[12];
|
||||
h[5] ^= v[5] ^ v[13];
|
||||
h[6] ^= v[6] ^ v[14];
|
||||
h[7] ^= v[7] ^ v[15];
|
||||
}
|
||||
#define bitselect(a, b, c) ((a) ^ ((c) & ((b) ^ (a))))
|
||||
|
||||
static void __forceinline__ __device__ keccak_block(uint2 *s)
|
||||
{
|
||||
uint2 bc[5], tmpxor[5], u, v;
|
||||
uint2 bc[5], tmpxor[5], tmp1, tmp2;
|
||||
// uint2 s[25];
|
||||
|
||||
#pragma unroll 1
|
||||
#pragma unroll 1
|
||||
for (int i = 0; i < 24; i++)
|
||||
{
|
||||
#pragma unroll
|
||||
#pragma unroll
|
||||
for (uint32_t x = 0; x < 5; x++)
|
||||
tmpxor[x] = s[x] ^ s[x + 5] ^ s[x + 10] ^ s[x + 15] ^ s[x + 20];
|
||||
|
||||
@@ -250,7 +203,7 @@ static void __forceinline__ __device__ keccak_block(uint2 *s)
|
||||
bc[3] = tmpxor[3] ^ ROL2(tmpxor[0], 1);
|
||||
bc[4] = tmpxor[4] ^ ROL2(tmpxor[1], 1);
|
||||
|
||||
u = s[1] ^ bc[0];
|
||||
tmp1 = s[1] ^ bc[0];
|
||||
|
||||
s[0] ^= bc[4];
|
||||
s[1] = ROL2(s[6] ^ bc[0], 44);
|
||||
@@ -276,18 +229,17 @@ static void __forceinline__ __device__ keccak_block(uint2 *s)
|
||||
s[17] = ROL2(s[11] ^ bc[0], 10);
|
||||
s[11] = ROL2(s[7] ^ bc[1], 6);
|
||||
s[7] = ROL2(s[10] ^ bc[4], 3);
|
||||
s[10] = ROL2(u, 1);
|
||||
s[10] = ROL2(tmp1, 1);
|
||||
|
||||
u = s[0]; v = s[1]; s[0] ^= (~v) & s[2]; s[1] ^= (~s[2]) & s[3]; s[2] ^= (~s[3]) & s[4]; s[3] ^= (~s[4]) & u; s[4] ^= (~u) & v;
|
||||
u = s[5]; v = s[6]; s[5] ^= (~v) & s[7]; s[6] ^= (~s[7]) & s[8]; s[7] ^= (~s[8]) & s[9]; s[8] ^= (~s[9]) & u; s[9] ^= (~u) & v;
|
||||
u = s[10]; v = s[11]; s[10] ^= (~v) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & u; s[14] ^= (~u) & v;
|
||||
u = s[15]; v = s[16]; s[15] ^= (~v) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & u; s[19] ^= (~u) & v;
|
||||
u = s[20]; v = s[21]; s[20] ^= (~v) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & u; s[24] ^= (~u) & v;
|
||||
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1);
|
||||
tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1);
|
||||
tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1);
|
||||
tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1);
|
||||
tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1);
|
||||
s[0] ^= keccak_round_constants35[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//__launch_bounds__(256)
|
||||
__global__
|
||||
void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonce, uint32_t * Hash)
|
||||
@@ -296,10 +248,10 @@ void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonc
|
||||
if (thread < threads)
|
||||
{
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
const uint32_t T0 = 640;
|
||||
|
||||
uint32_t h[8];
|
||||
#pragma unroll 8
|
||||
// uint32_t input[4];
|
||||
const uint32_t T0 = 640;
|
||||
#pragma unroll 8
|
||||
for (int i = 0; i<8; i++) { h[i] = cpu_h[i]; }
|
||||
|
||||
uint32_t v[16];
|
||||
@@ -310,7 +262,8 @@ void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonc
|
||||
0, 1, 0, 640
|
||||
};
|
||||
|
||||
const uint32_t u256[16] = {
|
||||
const uint32_t u256[16] =
|
||||
{
|
||||
0x243F6A88, 0x85A308D3,
|
||||
0x13198A2E, 0x03707344,
|
||||
0xA4093822, 0x299F31D0,
|
||||
@@ -321,14 +274,15 @@ void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonc
|
||||
0x3F84D5B5, 0xB5470917
|
||||
};
|
||||
|
||||
uint32_t m[16] = {
|
||||
uint32_t m[16] =
|
||||
{
|
||||
c_data[0], c_data[1], c_data[2], nonce,
|
||||
c_Padding[0], c_Padding[1], c_Padding[2], c_Padding[3],
|
||||
c_Padding[4], c_Padding[5], c_Padding[6], c_Padding[7],
|
||||
c_Padding[8], c_Padding[9], c_Padding[10], c_Padding[11]
|
||||
};
|
||||
|
||||
#pragma unroll 8
|
||||
#pragma unroll 8
|
||||
for (int i = 0; i < 8; i++)
|
||||
v[i] = h[i];
|
||||
|
||||
@@ -377,6 +331,7 @@ void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonc
|
||||
GSPREC(1, 6, 0xB, 0xC, 5, 10);
|
||||
GSPREC(2, 7, 0x8, 0xD, 4, 0);
|
||||
GSPREC(3, 4, 0x9, 0xE, 15, 8);
|
||||
|
||||
// { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 9, 0);
|
||||
GSPREC(1, 5, 0x9, 0xD, 5, 7);
|
||||
@@ -395,6 +350,7 @@ void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonc
|
||||
GSPREC(1, 6, 0xB, 0xC, 7, 5);
|
||||
GSPREC(2, 7, 0x8, 0xD, 15, 14);
|
||||
GSPREC(3, 4, 0x9, 0xE, 1, 9);
|
||||
|
||||
// { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 12, 5);
|
||||
GSPREC(1, 5, 0x9, 0xD, 1, 15);
|
||||
@@ -404,6 +360,7 @@ void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonc
|
||||
GSPREC(1, 6, 0xB, 0xC, 6, 3);
|
||||
GSPREC(2, 7, 0x8, 0xD, 9, 2);
|
||||
GSPREC(3, 4, 0x9, 0xE, 8, 11);
|
||||
|
||||
// { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 13, 11);
|
||||
GSPREC(1, 5, 0x9, 0xD, 7, 14);
|
||||
@@ -431,6 +388,135 @@ void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonc
|
||||
GSPREC(1, 6, 0xB, 0xC, 9, 14);
|
||||
GSPREC(2, 7, 0x8, 0xD, 3, 12);
|
||||
GSPREC(3, 4, 0x9, 0xE, 13, 0);
|
||||
// { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 0, 1);
|
||||
GSPREC(1, 5, 0x9, 0xD, 2, 3);
|
||||
GSPREC(2, 6, 0xA, 0xE, 4, 5);
|
||||
GSPREC(3, 7, 0xB, 0xF, 6, 7);
|
||||
GSPREC(0, 5, 0xA, 0xF, 8, 9);
|
||||
GSPREC(1, 6, 0xB, 0xC, 10, 11);
|
||||
GSPREC(2, 7, 0x8, 0xD, 12, 13);
|
||||
GSPREC(3, 4, 0x9, 0xE, 14, 15);
|
||||
|
||||
// { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 14, 10);
|
||||
GSPREC(1, 5, 0x9, 0xD, 4, 8);
|
||||
GSPREC(2, 6, 0xA, 0xE, 9, 15);
|
||||
GSPREC(3, 7, 0xB, 0xF, 13, 6);
|
||||
GSPREC(0, 5, 0xA, 0xF, 1, 12);
|
||||
GSPREC(1, 6, 0xB, 0xC, 0, 2);
|
||||
GSPREC(2, 7, 0x8, 0xD, 11, 7);
|
||||
GSPREC(3, 4, 0x9, 0xE, 5, 3);
|
||||
|
||||
// { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 11, 8);
|
||||
GSPREC(1, 5, 0x9, 0xD, 12, 0);
|
||||
GSPREC(2, 6, 0xA, 0xE, 5, 2);
|
||||
GSPREC(3, 7, 0xB, 0xF, 15, 13);
|
||||
GSPREC(0, 5, 0xA, 0xF, 10, 14);
|
||||
GSPREC(1, 6, 0xB, 0xC, 3, 6);
|
||||
GSPREC(2, 7, 0x8, 0xD, 7, 1);
|
||||
GSPREC(3, 4, 0x9, 0xE, 9, 4);
|
||||
// { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 7, 9);
|
||||
GSPREC(1, 5, 0x9, 0xD, 3, 1);
|
||||
GSPREC(2, 6, 0xA, 0xE, 13, 12);
|
||||
GSPREC(3, 7, 0xB, 0xF, 11, 14);
|
||||
GSPREC(0, 5, 0xA, 0xF, 2, 6);
|
||||
GSPREC(1, 6, 0xB, 0xC, 5, 10);
|
||||
GSPREC(2, 7, 0x8, 0xD, 4, 0);
|
||||
GSPREC(3, 4, 0x9, 0xE, 15, 8);
|
||||
|
||||
|
||||
|
||||
|
||||
h[0] = cuda_swab32(h[0] ^ v[0] ^ v[8]);
|
||||
h[1] = cuda_swab32(h[1] ^ v[1] ^ v[9]);
|
||||
h[2] = cuda_swab32(h[2] ^ v[2] ^ v[10]);
|
||||
h[3] = cuda_swab32(h[3] ^ v[3] ^ v[11]);
|
||||
h[4] = cuda_swab32(h[4] ^ v[4] ^ v[12]);
|
||||
h[5] = cuda_swab32(h[5] ^ v[5] ^ v[13]);
|
||||
h[6] = cuda_swab32(h[6] ^ v[6] ^ v[14]);
|
||||
h[7] = cuda_swab32(h[7] ^ v[7] ^ v[15]);
|
||||
|
||||
uint2 keccak_gpu_state[25] = { 0 };
|
||||
keccak_gpu_state[0].x = h[0];
|
||||
keccak_gpu_state[0].y = h[1];
|
||||
keccak_gpu_state[1].x = h[2];
|
||||
keccak_gpu_state[1].y = h[3];
|
||||
keccak_gpu_state[2].x = h[4];
|
||||
keccak_gpu_state[2].y = h[5];
|
||||
keccak_gpu_state[3].x = h[6];
|
||||
keccak_gpu_state[3].y = h[7];
|
||||
keccak_gpu_state[4] = UINT2(1, 0);
|
||||
|
||||
keccak_gpu_state[16] = UINT2(0, 0x80000000);
|
||||
keccak_block(keccak_gpu_state);
|
||||
uint64_t *outputHash = (uint64_t *)Hash;
|
||||
#pragma unroll 4
|
||||
for (int i = 0; i<4; i++)
|
||||
outputHash[i*threads + thread] = devectorize(keccak_gpu_state[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
__global__ __launch_bounds__(256, 4)
|
||||
void blake256_gpu_hash_80(const uint32_t threads, const uint32_t startNonce, uint32_t * Hash)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
uint32_t h[8];
|
||||
// uint32_t input[4];
|
||||
const uint32_t T0 = 640;
|
||||
#pragma unroll 8
|
||||
for (int i = 0; i<8; i++) { h[i] = cpu_h[i]; }
|
||||
|
||||
uint32_t v[16];
|
||||
|
||||
const uint32_t c_Padding[12] = {
|
||||
0x80000000, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 1, 0, 640
|
||||
};
|
||||
|
||||
const uint32_t u256[16] =
|
||||
{
|
||||
0x243F6A88, 0x85A308D3,
|
||||
0x13198A2E, 0x03707344,
|
||||
0xA4093822, 0x299F31D0,
|
||||
0x082EFA98, 0xEC4E6C89,
|
||||
0x452821E6, 0x38D01377,
|
||||
0xBE5466CF, 0x34E90C6C,
|
||||
0xC0AC29B7, 0xC97C50DD,
|
||||
0x3F84D5B5, 0xB5470917
|
||||
};
|
||||
|
||||
uint32_t m[16] =
|
||||
{
|
||||
c_data[0], c_data[1], c_data[2], nonce,
|
||||
c_Padding[0], c_Padding[1], c_Padding[2], c_Padding[3],
|
||||
c_Padding[4], c_Padding[5], c_Padding[6], c_Padding[7],
|
||||
c_Padding[8], c_Padding[9], c_Padding[10], c_Padding[11]
|
||||
};
|
||||
|
||||
#pragma unroll 8
|
||||
for (int i = 0; i < 8; i++)
|
||||
v[i] = h[i];
|
||||
|
||||
v[8] = u256[0];
|
||||
v[9] = u256[1];
|
||||
v[10] = u256[2];
|
||||
v[11] = u256[3];
|
||||
v[12] = u256[4] ^ T0;
|
||||
v[13] = u256[5] ^ T0;
|
||||
v[14] = u256[6];
|
||||
v[15] = u256[7];
|
||||
|
||||
// { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 0, 1);
|
||||
GSPREC(1, 5, 0x9, 0xD, 2, 3);
|
||||
@@ -468,6 +554,101 @@ void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonc
|
||||
GSPREC(2, 7, 0x8, 0xD, 4, 0);
|
||||
GSPREC(3, 4, 0x9, 0xE, 15, 8);
|
||||
|
||||
// { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 9, 0);
|
||||
GSPREC(1, 5, 0x9, 0xD, 5, 7);
|
||||
GSPREC(2, 6, 0xA, 0xE, 2, 4);
|
||||
GSPREC(3, 7, 0xB, 0xF, 10, 15);
|
||||
GSPREC(0, 5, 0xA, 0xF, 14, 1);
|
||||
GSPREC(1, 6, 0xB, 0xC, 11, 12);
|
||||
GSPREC(2, 7, 0x8, 0xD, 6, 8);
|
||||
GSPREC(3, 4, 0x9, 0xE, 3, 13);
|
||||
// { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 2, 12);
|
||||
GSPREC(1, 5, 0x9, 0xD, 6, 10);
|
||||
GSPREC(2, 6, 0xA, 0xE, 0, 11);
|
||||
GSPREC(3, 7, 0xB, 0xF, 8, 3);
|
||||
GSPREC(0, 5, 0xA, 0xF, 4, 13);
|
||||
GSPREC(1, 6, 0xB, 0xC, 7, 5);
|
||||
GSPREC(2, 7, 0x8, 0xD, 15, 14);
|
||||
GSPREC(3, 4, 0x9, 0xE, 1, 9);
|
||||
|
||||
// { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 12, 5);
|
||||
GSPREC(1, 5, 0x9, 0xD, 1, 15);
|
||||
GSPREC(2, 6, 0xA, 0xE, 14, 13);
|
||||
GSPREC(3, 7, 0xB, 0xF, 4, 10);
|
||||
GSPREC(0, 5, 0xA, 0xF, 0, 7);
|
||||
GSPREC(1, 6, 0xB, 0xC, 6, 3);
|
||||
GSPREC(2, 7, 0x8, 0xD, 9, 2);
|
||||
GSPREC(3, 4, 0x9, 0xE, 8, 11);
|
||||
|
||||
// { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 13, 11);
|
||||
GSPREC(1, 5, 0x9, 0xD, 7, 14);
|
||||
GSPREC(2, 6, 0xA, 0xE, 12, 1);
|
||||
GSPREC(3, 7, 0xB, 0xF, 3, 9);
|
||||
GSPREC(0, 5, 0xA, 0xF, 5, 0);
|
||||
GSPREC(1, 6, 0xB, 0xC, 15, 4);
|
||||
GSPREC(2, 7, 0x8, 0xD, 8, 6);
|
||||
GSPREC(3, 4, 0x9, 0xE, 2, 10);
|
||||
// { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 6, 15);
|
||||
GSPREC(1, 5, 0x9, 0xD, 14, 9);
|
||||
GSPREC(2, 6, 0xA, 0xE, 11, 3);
|
||||
GSPREC(3, 7, 0xB, 0xF, 0, 8);
|
||||
GSPREC(0, 5, 0xA, 0xF, 12, 2);
|
||||
GSPREC(1, 6, 0xB, 0xC, 13, 7);
|
||||
GSPREC(2, 7, 0x8, 0xD, 1, 4);
|
||||
GSPREC(3, 4, 0x9, 0xE, 10, 5);
|
||||
// { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 10, 2);
|
||||
GSPREC(1, 5, 0x9, 0xD, 8, 4);
|
||||
GSPREC(2, 6, 0xA, 0xE, 7, 6);
|
||||
GSPREC(3, 7, 0xB, 0xF, 1, 5);
|
||||
GSPREC(0, 5, 0xA, 0xF, 15, 11);
|
||||
GSPREC(1, 6, 0xB, 0xC, 9, 14);
|
||||
GSPREC(2, 7, 0x8, 0xD, 3, 12);
|
||||
GSPREC(3, 4, 0x9, 0xE, 13, 0);
|
||||
// { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 0, 1);
|
||||
GSPREC(1, 5, 0x9, 0xD, 2, 3);
|
||||
GSPREC(2, 6, 0xA, 0xE, 4, 5);
|
||||
GSPREC(3, 7, 0xB, 0xF, 6, 7);
|
||||
GSPREC(0, 5, 0xA, 0xF, 8, 9);
|
||||
GSPREC(1, 6, 0xB, 0xC, 10, 11);
|
||||
GSPREC(2, 7, 0x8, 0xD, 12, 13);
|
||||
GSPREC(3, 4, 0x9, 0xE, 14, 15);
|
||||
|
||||
// { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 14, 10);
|
||||
GSPREC(1, 5, 0x9, 0xD, 4, 8);
|
||||
GSPREC(2, 6, 0xA, 0xE, 9, 15);
|
||||
GSPREC(3, 7, 0xB, 0xF, 13, 6);
|
||||
GSPREC(0, 5, 0xA, 0xF, 1, 12);
|
||||
GSPREC(1, 6, 0xB, 0xC, 0, 2);
|
||||
GSPREC(2, 7, 0x8, 0xD, 11, 7);
|
||||
GSPREC(3, 4, 0x9, 0xE, 5, 3);
|
||||
|
||||
// { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 11, 8);
|
||||
GSPREC(1, 5, 0x9, 0xD, 12, 0);
|
||||
GSPREC(2, 6, 0xA, 0xE, 5, 2);
|
||||
GSPREC(3, 7, 0xB, 0xF, 15, 13);
|
||||
GSPREC(0, 5, 0xA, 0xF, 10, 14);
|
||||
GSPREC(1, 6, 0xB, 0xC, 3, 6);
|
||||
GSPREC(2, 7, 0x8, 0xD, 7, 1);
|
||||
GSPREC(3, 4, 0x9, 0xE, 9, 4);
|
||||
// { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
|
||||
GSPREC(0, 4, 0x8, 0xC, 7, 9);
|
||||
GSPREC(1, 5, 0x9, 0xD, 3, 1);
|
||||
GSPREC(2, 6, 0xA, 0xE, 13, 12);
|
||||
GSPREC(3, 7, 0xB, 0xF, 11, 14);
|
||||
GSPREC(0, 5, 0xA, 0xF, 2, 6);
|
||||
GSPREC(1, 6, 0xB, 0xC, 5, 10);
|
||||
GSPREC(2, 7, 0x8, 0xD, 4, 0);
|
||||
GSPREC(3, 4, 0x9, 0xE, 15, 8);
|
||||
|
||||
h[0] = cuda_swab32(h[0] ^ v[0] ^ v[8]);
|
||||
h[1] = cuda_swab32(h[1] ^ v[1] ^ v[9]);
|
||||
h[2] = cuda_swab32(h[2] ^ v[2] ^ v[10]);
|
||||
@@ -477,86 +658,43 @@ void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonc
|
||||
h[6] = cuda_swab32(h[6] ^ v[6] ^ v[14]);
|
||||
h[7] = cuda_swab32(h[7] ^ v[7] ^ v[15]);
|
||||
|
||||
uint2 keccak_gpu_state[25] = { 0 };
|
||||
keccak_gpu_state[0].x = h[0];
|
||||
keccak_gpu_state[0].y = h[1];
|
||||
keccak_gpu_state[1].x = h[2];
|
||||
keccak_gpu_state[1].y = h[3];
|
||||
keccak_gpu_state[2].x = h[4];
|
||||
keccak_gpu_state[2].y = h[5];
|
||||
keccak_gpu_state[3].x = h[6];
|
||||
keccak_gpu_state[3].y = h[7];
|
||||
keccak_gpu_state[4] = UINT2(1, 0);
|
||||
|
||||
keccak_gpu_state[16] = UINT2(0, 0x80000000);
|
||||
keccak_block(keccak_gpu_state);
|
||||
|
||||
uint64_t *outputHash = (uint64_t *)Hash;
|
||||
#pragma unroll 4
|
||||
for (int i = 0; i<4; i++)
|
||||
outputHash[i*threads + thread] = devectorize(keccak_gpu_state[i]);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(256, 3)
|
||||
void blake256_gpu_hash_80(const uint32_t threads, const uint32_t startNonce, uint64_t * Hash)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t h[8];
|
||||
uint32_t input[4];
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 0; i < 8; i++) h[i] = cpu_h[i];
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 0; i < 3; ++i) input[i] = c_data[i];
|
||||
|
||||
input[3] = startNonce + thread;
|
||||
blake256_compress2nd(h, input, 640);
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 0; i<4; i++) {
|
||||
Hash[i*threads + thread] = cuda_swab32ll(MAKE_ULONGLONG(h[2 * i], h[2 * i + 1]));
|
||||
}
|
||||
Hash[((0 * threads) + thread) * 2] = (h[0]);
|
||||
Hash[((0 * threads) + thread) * 2 + 1] = (h[1]);
|
||||
Hash[((1 * threads) + thread) * 2] = (h[2]);
|
||||
Hash[((1 * threads) + thread) * 2 + 1] = (h[3]);
|
||||
Hash[((2 * threads) + thread) * 2] = (h[4]);
|
||||
Hash[((2 * threads) + thread) * 2 + 1] = (h[5]);
|
||||
Hash[((3 * threads) + thread) * 2] = (h[6]);
|
||||
Hash[((3 * threads) + thread) * 2 + 1] = (h[7]);
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void blake256_cpu_hash_80(const int thr_id, const uint32_t threads, const uint32_t startNonce, uint64_t *Hash, int order)
|
||||
{
|
||||
const uint32_t threadsperblock = 256;
|
||||
const uint32_t threadsperblock = 64;
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
blake256_gpu_hash_80 << <grid, block >> > (threads, startNonce, Hash);
|
||||
MyStreamSynchronize(NULL, order, thr_id);
|
||||
blake256_gpu_hash_80 << <grid, block >> > (threads, startNonce, (uint32_t *)Hash);
|
||||
}
|
||||
|
||||
__host__
|
||||
void blake256_cpu_setBlock_80(uint32_t *pdata)
|
||||
{
|
||||
uint32_t h[8], data[20];
|
||||
|
||||
uint32_t h[8];
|
||||
uint32_t data[20];
|
||||
memcpy(data, pdata, 80);
|
||||
memcpy(h, c_IV256, sizeof(c_IV256));
|
||||
for (int i = 0; i<8; i++) {
|
||||
h[i] = c_IV256[i];
|
||||
}
|
||||
blake256_compress1st(h, pdata, 512);
|
||||
|
||||
cudaMemcpyToSymbol(cpu_h, h, sizeof(h), 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(c_data, &data[16], sizeof(c_data), 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(c_data, &data[16], 3 * 4, 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
__host__
|
||||
void blake256_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
cudaMemcpyToSymbol(u256, c_u256, sizeof(c_u256), 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(sigma, c_sigma, sizeof(c_sigma), 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
/** for lyra2v2 **/
|
||||
|
||||
__host__
|
||||
void blakeKeccak256_cpu_hash_80(const int thr_id, const uint32_t threads, const uint32_t startNonce, uint64_t *Hash, int order)
|
||||
{
|
||||
@@ -565,7 +703,7 @@ void blakeKeccak256_cpu_hash_80(const int thr_id, const uint32_t threads, const
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
blakeKeccak256_gpu_hash_80 <<<grid, block>>> (threads, startNonce, (uint32_t *)Hash);
|
||||
blakeKeccak256_gpu_hash_80 << <grid, block >> > (threads, startNonce, (uint32_t *)Hash);
|
||||
}
|
||||
|
||||
__host__
|
||||
@@ -576,5 +714,5 @@ void blakeKeccak256_cpu_hash_80(const int thr_id, const uint32_t threads, const
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
blakeKeccak256_gpu_hash_80 <<<grid, block, 0, stream>>> (threads, startNonce, (uint32_t *)Hash);
|
||||
blakeKeccak256_gpu_hash_80 << <grid, block, 0, stream >> > (threads, startNonce, (uint32_t *)Hash);
|
||||
}
|
||||
+244
-142
@@ -14,149 +14,57 @@ __constant__ uint64_t pTarget[4];
|
||||
#define shl(x, n) ((x) << (n))
|
||||
#define shr(x, n) ((x) >> (n))
|
||||
|
||||
#define ss0(x) (shr((x), 1) ^ shl((x), 3) ^ SPH_ROTL32((x), 4) ^ SPH_ROTL32((x), 19))
|
||||
#define ss1(x) (shr((x), 1) ^ shl((x), 2) ^ SPH_ROTL32((x), 8) ^ SPH_ROTL32((x), 23))
|
||||
#define ss2(x) (shr((x), 2) ^ shl((x), 1) ^ SPH_ROTL32((x), 12) ^ SPH_ROTL32((x), 25))
|
||||
#define ss3(x) (shr((x), 2) ^ shl((x), 2) ^ SPH_ROTL32((x), 15) ^ SPH_ROTL32((x), 29))
|
||||
#define ss4(x) (shr((x), 1) ^ (x))
|
||||
#define ss5(x) (shr((x), 2) ^ (x))
|
||||
|
||||
#define ss0(x) (shr((x), 1) ^ shl((x), 3) ^ SPH_ROTL32((x), 4) ^ SPH_ROTL32((x), 19))
|
||||
#define ss1(x) (shr((x), 1) ^ shl((x), 2) ^ __byte_perm(x,0,0x2103) ^ SPH_ROTL32((x), 23))
|
||||
#define ss2(x) (shr((x), 2) ^ shl((x), 1) ^ SPH_ROTL32((x), 12) ^ SPH_ROTL32((x), 25))
|
||||
#define ss3(x) (shr((x), 2) ^ shl((x), 2) ^ SPH_ROTL32((x), 15) ^ SPH_ROTL32((x), 29))
|
||||
#define ss4(x) (shr((x), 1) ^ (x))
|
||||
#define ss5(x) (shr((x), 2) ^ (x))
|
||||
#define rs1(x) SPH_ROTL32((x), 3)
|
||||
#define rs2(x) SPH_ROTL32((x), 7)
|
||||
#define rs3(x) SPH_ROTL32((x), 13)
|
||||
#define rs4(x) SPH_ROTL32((x), 16)
|
||||
#define rs4(x) __byte_perm(x,0,0x1032)
|
||||
#define rs5(x) SPH_ROTL32((x), 19)
|
||||
#define rs6(x) SPH_ROTL32((x), 23)
|
||||
#define rs7(x) SPH_ROTL32((x), 27)
|
||||
|
||||
/* Message expansion function 1 */
|
||||
__forceinline__ __device__
|
||||
uint32_t expand32_1(int i, uint32_t *M32, const uint32_t *H, uint32_t *Q)
|
||||
__forceinline__ __device__ uint32_t expand32_1(int i, uint32_t *M32, const uint32_t *H, uint32_t *Q)
|
||||
{
|
||||
return (ss1(Q[i - 16]) + ss2(Q[i - 15]) + ss3(Q[i - 14]) + ss0(Q[i - 13])
|
||||
+ ss1(Q[i - 12]) + ss2(Q[i - 11]) + ss3(Q[i - 10]) + ss0(Q[i - 9])
|
||||
+ ss1(Q[i - 8]) + ss2(Q[i - 7]) + ss3(Q[i - 6]) + ss0(Q[i - 5])
|
||||
+ ss1(Q[i - 4]) + ss2(Q[i - 3]) + ss3(Q[i - 2]) + ss0(Q[i - 1])
|
||||
+ ((i*(0x05555555ul) + SPH_ROTL32(M32[(i - 16) % 16], ((i - 16) % 16) + 1)
|
||||
+ SPH_ROTL32(M32[(i - 13) % 16], ((i - 13) % 16) + 1)
|
||||
- SPH_ROTL32(M32[(i - 6) % 16], ((i - 6) % 16) + 1)) ^ H[(i - 16 + 7) % 16]));
|
||||
+ ((i*(0x05555555ul) + SPH_ROTL32(M32[(i - 16) % 16], ((i - 16) % 16) + 1) + SPH_ROTL32(M32[(i - 13) % 16], ((i - 13) % 16) + 1) - SPH_ROTL32(M32[(i - 6) % 16], ((i - 6) % 16) + 1)) ^ H[(i - 16 + 7) % 16]));
|
||||
}
|
||||
|
||||
/* Message expansion function 2 */
|
||||
__forceinline__ __device__
|
||||
uint32_t expand32_2(int i, uint32_t *M32, const uint32_t *H, uint32_t *Q)
|
||||
__forceinline__ __device__ uint32_t expand32_2(const int i, uint32_t *M32, const uint32_t *H, uint32_t *Q)
|
||||
{
|
||||
return (Q[i - 16] + rs1(Q[i - 15]) + Q[i - 14] + rs2(Q[i - 13])
|
||||
+ Q[i - 12] + rs3(Q[i - 11]) + Q[i - 10] + rs4(Q[i - 9])
|
||||
+ Q[i - 8] + rs5(Q[i - 7]) + Q[i - 6] + rs6(Q[i - 5])
|
||||
+ Q[i - 4] + rs7(Q[i - 3]) + ss4(Q[i - 2]) + ss5(Q[i - 1])
|
||||
+ ((i*(0x05555555ul) + SPH_ROTL32(M32[(i - 16) % 16], ((i - 16) % 16) + 1)
|
||||
+ SPH_ROTL32(M32[(i - 13) % 16], ((i - 13) % 16) + 1)
|
||||
- SPH_ROTL32(M32[(i - 6) % 16], ((i - 6) % 16) + 1)) ^ H[(i - 16 + 7) % 16]));
|
||||
return (
|
||||
rs2(Q[i - 13]) + rs3(Q[i - 11]) + rs4(Q[i - 9]) + rs1(Q[i - 15]) +
|
||||
+rs5(Q[i - 7]) + rs6(Q[i - 5]) + rs7(Q[i - 3]) + ss4(Q[i - 2]) + ss5(Q[i - 1]));
|
||||
}
|
||||
|
||||
__forceinline__ __device__
|
||||
void Compression256(uint32_t * M32)
|
||||
__forceinline__ __device__ void Compression256(uint32_t M32[16])
|
||||
{
|
||||
uint32_t Q[32], XL32, XH32;
|
||||
|
||||
const uint32_t H[16] = {
|
||||
0x40414243, 0x44454647, 0x48494A4B, 0x4C4D4E4F,
|
||||
0x50515253, 0x54555657, 0x58595A5B, 0x5C5D5E5F,
|
||||
0x60616263, 0x64656667, 0x68696A6B, 0x6C6D6E6F,
|
||||
0x70717273, 0x74757677, 0x78797A7B, 0x7C7D7E7F
|
||||
(0x40414243), (0x44454647),
|
||||
(0x48494A4B), (0x4C4D4E4F),
|
||||
(0x50515253), (0x54555657),
|
||||
(0x58595A5B), (0x5C5D5E5F),
|
||||
(0x60616263), (0x64656667),
|
||||
(0x68696A6B), (0x6C6D6E6F),
|
||||
(0x70717273), (0x74757677),
|
||||
(0x78797A7B), (0x7C7D7E7F)
|
||||
};
|
||||
|
||||
Q[0] = (M32[5] ^ H[5]) - (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[13] ^ H[13]) + (M32[14] ^ H[14]);
|
||||
Q[1] = (M32[6] ^ H[6]) - (M32[8] ^ H[8]) + (M32[11] ^ H[11]) + (M32[14] ^ H[14]) - (M32[15] ^ H[15]);
|
||||
Q[2] = (M32[0] ^ H[0]) + (M32[7] ^ H[7]) + (M32[9] ^ H[9]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
|
||||
Q[3] = (M32[0] ^ H[0]) - (M32[1] ^ H[1]) + (M32[8] ^ H[8]) - (M32[10] ^ H[10]) + (M32[13] ^ H[13]);
|
||||
Q[4] = (M32[1] ^ H[1]) + (M32[2] ^ H[2]) + (M32[9] ^ H[9]) - (M32[11] ^ H[11]) - (M32[14] ^ H[14]);
|
||||
Q[5] = (M32[3] ^ H[3]) - (M32[2] ^ H[2]) + (M32[10] ^ H[10]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
|
||||
Q[6] = (M32[4] ^ H[4]) - (M32[0] ^ H[0]) - (M32[3] ^ H[3]) - (M32[11] ^ H[11]) + (M32[13] ^ H[13]);
|
||||
Q[7] = (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[5] ^ H[5]) - (M32[12] ^ H[12]) - (M32[14] ^ H[14]);
|
||||
Q[8] = (M32[2] ^ H[2]) - (M32[5] ^ H[5]) - (M32[6] ^ H[6]) + (M32[13] ^ H[13]) - (M32[15] ^ H[15]);
|
||||
Q[9] = (M32[0] ^ H[0]) - (M32[3] ^ H[3]) + (M32[6] ^ H[6]) - (M32[7] ^ H[7]) + (M32[14] ^ H[14]);
|
||||
Q[10] = (M32[8] ^ H[8]) - (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[7] ^ H[7]) + (M32[15] ^ H[15]);
|
||||
Q[11] = (M32[8] ^ H[8]) - (M32[0] ^ H[0]) - (M32[2] ^ H[2]) - (M32[5] ^ H[5]) + (M32[9] ^ H[9]);
|
||||
Q[12] = (M32[1] ^ H[1]) + (M32[3] ^ H[3]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[10] ^ H[10]);
|
||||
Q[13] = (M32[2] ^ H[2]) + (M32[4] ^ H[4]) + (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[11] ^ H[11]);
|
||||
Q[14] = (M32[3] ^ H[3]) - (M32[5] ^ H[5]) + (M32[8] ^ H[8]) - (M32[11] ^ H[11]) - (M32[12] ^ H[12]);
|
||||
Q[15] = (M32[12] ^ H[12]) - (M32[4] ^ H[4]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[13] ^ H[13]);
|
||||
M32[8] = 0x80;
|
||||
M32[14] = 0x100;
|
||||
|
||||
/* Diffuse the differences in every word in a bijective manner with ssi, and then add the values of the previous double pipe. */
|
||||
Q[0] = ss0(Q[0]) + H[1];
|
||||
Q[1] = ss1(Q[1]) + H[2];
|
||||
Q[2] = ss2(Q[2]) + H[3];
|
||||
Q[3] = ss3(Q[3]) + H[4];
|
||||
Q[4] = ss4(Q[4]) + H[5];
|
||||
Q[5] = ss0(Q[5]) + H[6];
|
||||
Q[6] = ss1(Q[6]) + H[7];
|
||||
Q[7] = ss2(Q[7]) + H[8];
|
||||
Q[8] = ss3(Q[8]) + H[9];
|
||||
Q[9] = ss4(Q[9]) + H[10];
|
||||
Q[10] = ss0(Q[10]) + H[11];
|
||||
Q[11] = ss1(Q[11]) + H[12];
|
||||
Q[12] = ss2(Q[12]) + H[13];
|
||||
Q[13] = ss3(Q[13]) + H[14];
|
||||
Q[14] = ss4(Q[14]) + H[15];
|
||||
Q[15] = ss0(Q[15]) + H[0];
|
||||
|
||||
/* This is the Message expansion or f_1 in the documentation. */
|
||||
/* It has 16 rounds. */
|
||||
/* Blue Midnight Wish has two tunable security parameters. */
|
||||
/* The parameters are named EXPAND_1_ROUNDS and EXPAND_2_ROUNDS. */
|
||||
/* The following relation for these parameters should is satisfied: */
|
||||
/* EXPAND_1_ROUNDS + EXPAND_2_ROUNDS = 16 */
|
||||
|
||||
#pragma unroll
|
||||
for (int i=16; i<18; i++)
|
||||
Q[i] = expand32_1(i, M32, H, Q);
|
||||
|
||||
#pragma nounroll
|
||||
for (int i=18; i<32; i++)
|
||||
Q[i] = expand32_2(i, M32, H, Q);
|
||||
|
||||
/* Blue Midnight Wish has two temporary cummulative variables that accumulate via XORing */
|
||||
/* 16 new variables that are prooduced in the Message Expansion part. */
|
||||
XL32 = Q[16] ^ Q[17] ^ Q[18] ^ Q[19] ^ Q[20] ^ Q[21] ^ Q[22] ^ Q[23];
|
||||
XH32 = XL32^Q[24] ^ Q[25] ^ Q[26] ^ Q[27] ^ Q[28] ^ Q[29] ^ Q[30] ^ Q[31];
|
||||
|
||||
|
||||
/* This part is the function f_2 - in the documentation */
|
||||
|
||||
/* Compute the double chaining pipe for the next message block. */
|
||||
M32[0] = (shl(XH32, 5) ^ shr(Q[16], 5) ^ M32[0]) + (XL32 ^ Q[24] ^ Q[0]);
|
||||
M32[1] = (shr(XH32, 7) ^ shl(Q[17], 8) ^ M32[1]) + (XL32 ^ Q[25] ^ Q[1]);
|
||||
M32[2] = (shr(XH32, 5) ^ shl(Q[18], 5) ^ M32[2]) + (XL32 ^ Q[26] ^ Q[2]);
|
||||
M32[3] = (shr(XH32, 1) ^ shl(Q[19], 5) ^ M32[3]) + (XL32 ^ Q[27] ^ Q[3]);
|
||||
M32[4] = (shr(XH32, 3) ^ Q[20] ^ M32[4]) + (XL32 ^ Q[28] ^ Q[4]);
|
||||
M32[5] = (shl(XH32, 6) ^ shr(Q[21], 6) ^ M32[5]) + (XL32 ^ Q[29] ^ Q[5]);
|
||||
M32[6] = (shr(XH32, 4) ^ shl(Q[22], 6) ^ M32[6]) + (XL32 ^ Q[30] ^ Q[6]);
|
||||
M32[7] = (shr(XH32, 11) ^ shl(Q[23], 2) ^ M32[7]) + (XL32 ^ Q[31] ^ Q[7]);
|
||||
|
||||
M32[8] = SPH_ROTL32(M32[4], 9) + (XH32 ^ Q[24] ^ M32[8]) + (shl(XL32, 8) ^ Q[23] ^ Q[8]);
|
||||
M32[9] = SPH_ROTL32(M32[5], 10) + (XH32 ^ Q[25] ^ M32[9]) + (shr(XL32, 6) ^ Q[16] ^ Q[9]);
|
||||
M32[10] = SPH_ROTL32(M32[6], 11) + (XH32 ^ Q[26] ^ M32[10]) + (shl(XL32, 6) ^ Q[17] ^ Q[10]);
|
||||
M32[11] = SPH_ROTL32(M32[7], 12) + (XH32 ^ Q[27] ^ M32[11]) + (shl(XL32, 4) ^ Q[18] ^ Q[11]);
|
||||
M32[12] = SPH_ROTL32(M32[0], 13) + (XH32 ^ Q[28] ^ M32[12]) + (shr(XL32, 3) ^ Q[19] ^ Q[12]);
|
||||
M32[13] = SPH_ROTL32(M32[1], 14) + (XH32 ^ Q[29] ^ M32[13]) + (shr(XL32, 4) ^ Q[20] ^ Q[13]);
|
||||
M32[14] = SPH_ROTL32(M32[2], 15) + (XH32 ^ Q[30] ^ M32[14]) + (shr(XL32, 7) ^ Q[21] ^ Q[14]);
|
||||
M32[15] = SPH_ROTL32(M32[3], 16) + (XH32 ^ Q[31] ^ M32[15]) + (shr(XL32, 2) ^ Q[22] ^ Q[15]);
|
||||
}
|
||||
|
||||
__forceinline__ __device__
|
||||
void Compression256_2(uint32_t * M32)
|
||||
{
|
||||
// int i;
|
||||
uint32_t XL32, XH32, Q[32];
|
||||
|
||||
const uint32_t H[16] = {
|
||||
0xaaaaaaa0, 0xaaaaaaa1, 0xaaaaaaa2, 0xaaaaaaa3,
|
||||
0xaaaaaaa4, 0xaaaaaaa5, 0xaaaaaaa6, 0xaaaaaaa7,
|
||||
0xaaaaaaa8, 0xaaaaaaa9, 0xaaaaaaaa, 0xaaaaaaab,
|
||||
0xaaaaaaac, 0xaaaaaaad, 0xaaaaaaae, 0xaaaaaaaf
|
||||
};
|
||||
|
||||
Q[0] = (M32[5] ^ H[5]) - (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[13] ^ H[13]) + (M32[14] ^ H[14]);
|
||||
Q[1] = (M32[6] ^ H[6]) - (M32[8] ^ H[8]) + (M32[11] ^ H[11]) + (M32[14] ^ H[14]) - (M32[15] ^ H[15]);
|
||||
Q[2] = (M32[0] ^ H[0]) + (M32[7] ^ H[7]) + (M32[9] ^ H[9]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
|
||||
@@ -199,45 +107,238 @@ void Compression256_2(uint32_t * M32)
|
||||
/* The following relation for these parameters should is satisfied: */
|
||||
/* EXPAND_1_ROUNDS + EXPAND_2_ROUNDS = 16 */
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 16; i<18; i++)
|
||||
Q[i] = expand32_1(i, M32, H, Q);
|
||||
// #pragma unroll
|
||||
// for (i = 0; i<2; i++)
|
||||
// Q[i + 16] = expand32_1(i + 16, M32, H, Q);
|
||||
|
||||
#pragma nounroll
|
||||
for (int i = 18; i<32; i++)
|
||||
Q[i] = expand32_2(i, M32, H, Q);
|
||||
Q[16] = ss1(Q[16 - 16]) + ss2(Q[16 - 15]) + ss3(Q[16 - 14]) + ss0(Q[16 - 13])
|
||||
+ ss1(Q[16 - 12]) + ss2(Q[16 - 11]) + ss3(Q[16 - 10]) + ss0(Q[16 - 9])
|
||||
+ ss1(Q[16 - 8]) + ss2(Q[16 - 7]) + ss3(Q[16 - 6]) + ss0(Q[16 - 5])
|
||||
+ ss1(Q[16 - 4]) + ss2(Q[16 - 3]) + ss3(Q[16 - 2]) + ss0(Q[16 - 1])
|
||||
+ ((16 * (0x05555555ul) + SPH_ROTL32(M32[0], ((16 - 16) % 16) + 1) + SPH_ROTL32(M32[3], ((16 - 13) % 16) + 1)) ^ H[(16 - 16 + 7) % 16]);
|
||||
|
||||
Q[17] = ss1(Q[17 - 16]) + ss2(Q[17 - 15]) + ss3(Q[17 - 14]) + ss0(Q[17 - 13])
|
||||
+ ss1(Q[17 - 12]) + ss2(Q[17 - 11]) + ss3(Q[17 - 10]) + ss0(Q[17 - 9])
|
||||
+ ss1(Q[17 - 8]) + ss2(Q[17 - 7]) + ss3(Q[17 - 6]) + ss0(Q[17 - 5])
|
||||
+ ss1(Q[17 - 4]) + ss2(Q[17 - 3]) + ss3(Q[17 - 2]) + ss0(Q[17 - 1])
|
||||
+ ((17 * (0x05555555ul) + SPH_ROTL32(M32[(17 - 16) % 16], ((17 - 16) % 16) + 1) + SPH_ROTL32(M32[(17 - 13) % 16], ((17 - 13) % 16) + 1)) ^ H[(17 - 16 + 7) % 16]);
|
||||
|
||||
|
||||
uint32_t precalc = Q[18 - 16] + Q[18 - 14] + Q[18 - 12] + Q[18 - 10] + Q[18 - 8] + Q[18 - 6]; //+ Q[18 - 4]
|
||||
uint32_t precalc2 = Q[19 - 16] + Q[19 - 14] + Q[19 - 12] + Q[19 - 10] + Q[19 - 8] + Q[19 - 6];//+ Q[19 - 4]
|
||||
|
||||
// #pragma unroll
|
||||
// for (i = 2 + 16; i < 16 + 16; i+=2)
|
||||
// {
|
||||
precalc = precalc + Q[18 - 4];
|
||||
precalc2 = precalc2 + Q[18 + 1 - 4];
|
||||
uint32_t p1 = ((18 * (0x05555555ul) + SPH_ROTL32(M32[2], ((18 - 16) % 16) + 1) + SPH_ROTL32(M32[5], ((18 - 13) % 16) + 1)) ^ H[(18 - 16 + 7) % 16]);
|
||||
uint32_t p2 = (((18 + 1)*(0x05555555ul) + SPH_ROTL32(M32[3], (((18 + 1) - 16) % 16) + 1) + SPH_ROTL32(M32[6], (((18 + 1) - 13) % 16) + 1)) ^ H[((18 + 1) - 16 + 7) % 16]);
|
||||
Q[18] = precalc + expand32_2(18, M32, H, Q) + p1;
|
||||
Q[18 + 1] = precalc2 + expand32_2(18 + 1, M32, H, Q) + p2;
|
||||
precalc = precalc - Q[18 - 16];
|
||||
precalc2 = precalc2 - Q[18 + 1 - 16];
|
||||
|
||||
precalc = precalc + Q[20 - 4];
|
||||
precalc2 = precalc2 + Q[20 + 1 - 4];
|
||||
p1 = ((20 * (0x05555555ul) + SPH_ROTL32(M32[4], ((20 - 16) % 16) + 1) + SPH_ROTL32(M32[7], ((20 - 13) % 16) + 1) - (0x100 << 15)) ^ H[(20 - 16 + 7) % 16]);
|
||||
p2 = (((20 + 1)*(0x05555555ul) + SPH_ROTL32(M32[5], (((20 + 1) - 16) % 16) + 1) + (0x80 << 9)) ^ H[((20 + 1) - 16 + 7) % 16]);
|
||||
Q[20] = precalc + expand32_2(20, M32, H, Q) + p1;
|
||||
Q[20 + 1] = precalc2 + expand32_2(20 + 1, M32, H, Q) + p2;
|
||||
precalc = precalc - Q[20 - 16];
|
||||
precalc2 = precalc2 - Q[20 + 1 - 16];
|
||||
|
||||
precalc = precalc + Q[22 - 4];
|
||||
precalc2 = precalc2 + Q[22 + 1 - 4];
|
||||
p1 = ((22 * (0x05555555ul) + SPH_ROTL32(M32[6], ((22 - 16) % 16) + 1) - SPH_ROTL32(M32[0], ((22 - 6) % 16) + 1)) ^ H[(22 - 16 + 7) % 16]);
|
||||
p2 = (((22 + 1)*(0x05555555ul) + SPH_ROTL32(M32[7], (((22 + 1) - 16) % 16) + 1) - SPH_ROTL32(M32[1], (((22 + 1) - 6) % 16) + 1)) ^ H[((22 + 1) - 16 + 7) % 16]);
|
||||
Q[22] = precalc + expand32_2(22, M32, H, Q) + p1;
|
||||
Q[22 + 1] = precalc2 + expand32_2(22 + 1, M32, H, Q) + p2;
|
||||
precalc = precalc - Q[22 - 16];
|
||||
precalc2 = precalc2 - Q[22 + 1 - 16];
|
||||
|
||||
precalc = precalc + Q[24 - 4];
|
||||
precalc2 = precalc2 + Q[24 + 1 - 4];
|
||||
p1 = ((24 * (0x05555555ul) + (0x80 << 9) - SPH_ROTL32(M32[2], ((24 - 6) % 16) + 1)) ^ H[(24 - 16 + 7) % 16]);
|
||||
p2 = (((24 + 1)*(0x05555555ul) - SPH_ROTL32(M32[3], (((24 + 1) - 6) % 16) + 1)) ^ H[((24 + 1) - 16 + 7) % 16]);
|
||||
Q[24] = precalc + expand32_2(24, M32, H, Q) + p1;
|
||||
Q[24 + 1] = precalc2 + expand32_2(24 + 1, M32, H, Q) + p2;
|
||||
precalc = precalc - Q[24 - 16];
|
||||
precalc2 = precalc2 - Q[24 + 1 - 16];
|
||||
|
||||
precalc = precalc + Q[26 - 4];
|
||||
precalc2 = precalc2 + Q[26 + 1 - 4];
|
||||
p1 = ((26 * (0x05555555ul) - SPH_ROTL32(M32[4], ((26 - 6) % 16) + 1)) ^ H[(26 - 16 + 7) % 16]);
|
||||
p2 = (((26 + 1)*(0x05555555ul) + (0x100 << 15) - SPH_ROTL32(M32[5], (((26 + 1) - 6) % 16) + 1)) ^ H[((26 + 1) - 16 + 7) % 16]);
|
||||
Q[26] = precalc + expand32_2(26, M32, H, Q) + p1;
|
||||
Q[26 + 1] = precalc2 + expand32_2(26 + 1, M32, H, Q) + p2;
|
||||
precalc = precalc - Q[26 - 16];
|
||||
precalc2 = precalc2 - Q[26 + 1 - 16];
|
||||
|
||||
precalc = precalc + Q[28 - 4];
|
||||
precalc2 = precalc2 + Q[28 + 1 - 4];
|
||||
p1 = ((28 * (0x05555555ul) - SPH_ROTL32(M32[6], ((28 - 6) % 16) + 1)) ^ H[(28 - 16 + 7) % 16]);
|
||||
p2 = (((28 + 1)*(0x05555555ul) + SPH_ROTL32(M32[0], (((28 + 1) - 13) % 16) + 1) - SPH_ROTL32(M32[7], (((28 + 1) - 6) % 16) + 1)) ^ H[((28 + 1) - 16 + 7) % 16]);
|
||||
Q[28] = precalc + expand32_2(28, M32, H, Q) + p1;
|
||||
Q[28 + 1] = precalc2 + expand32_2(28 + 1, M32, H, Q) + p2;
|
||||
precalc = precalc - Q[28 - 16];
|
||||
precalc2 = precalc2 - Q[28 + 1 - 16];
|
||||
|
||||
precalc = precalc + Q[30 - 4];
|
||||
precalc2 = precalc2 + Q[30 + 1 - 4];
|
||||
p1 = ((30 * (0x05555555ul) + (0x100 << 15) + SPH_ROTL32(M32[1], ((30 - 13) % 16) + 1) - (0x80 << 9)) ^ H[(30 - 16 + 7) % 16]);
|
||||
p2 = (((30 + 1)*(0x05555555ul) + SPH_ROTL32(M32[2], (((30 + 1) - 13) % 16) + 1)) ^ H[((30 + 1) - 16 + 7) % 16]);
|
||||
Q[30] = precalc + expand32_2(30, M32, H, Q) + p1;
|
||||
Q[30 + 1] = precalc2 + expand32_2(30 + 1, M32, H, Q) + p2;
|
||||
precalc = precalc - Q[30 - 16];
|
||||
precalc2 = precalc2 - Q[30 + 1 - 16];
|
||||
|
||||
/* Blue Midnight Wish has two temporary cummulative variables that accumulate via XORing */
|
||||
/* 16 new variables that are prooduced in the Message Expansion part. */
|
||||
XL32 = Q[16] ^ Q[17] ^ Q[18] ^ Q[19] ^ Q[20] ^ Q[21] ^ Q[22] ^ Q[23];
|
||||
XH32 = XL32 ^ Q[24] ^ Q[25] ^ Q[26] ^ Q[27] ^ Q[28] ^ Q[29] ^ Q[30] ^ Q[31];
|
||||
XH32 = XL32^Q[24] ^ Q[25] ^ Q[26] ^ Q[27] ^ Q[28] ^ Q[29] ^ Q[30] ^ Q[31];
|
||||
|
||||
|
||||
/* This part is the function f_2 - in the documentation */
|
||||
|
||||
/* Compute the double chaining pipe for the next message block. */
|
||||
M32[0] = (shl(XH32, 5) ^ shr(Q[16], 5) ^ M32[0]) + (XL32 ^ Q[24] ^ Q[0]);
|
||||
M32[1] = (shr(XH32, 7) ^ shl(Q[17], 8) ^ M32[1]) + (XL32 ^ Q[25] ^ Q[1]);
|
||||
M32[2] = (shr(XH32, 5) ^ shl(Q[18], 5) ^ M32[2]) + (XL32 ^ Q[26] ^ Q[2]);
|
||||
M32[3] = (shr(XH32, 1) ^ shl(Q[19], 5) ^ M32[3]) + (XL32 ^ Q[27] ^ Q[3]);
|
||||
M32[4] = (shr(XH32, 3) ^ Q[20] ^ M32[4]) + (XL32 ^ Q[28] ^ Q[4]);
|
||||
M32[5] = (shl(XH32, 6) ^ shr(Q[21], 6) ^ M32[5]) + (XL32 ^ Q[29] ^ Q[5]);
|
||||
M32[6] = (shr(XH32, 4) ^ shl(Q[22], 6) ^ M32[6]) + (XL32 ^ Q[30] ^ Q[6]);
|
||||
M32[7] = (shr(XH32, 11) ^ shl(Q[23], 2) ^ M32[7]) + (XL32 ^ Q[31] ^ Q[7]);
|
||||
|
||||
M32[8] = SPH_ROTL32(M32[4], 9) + (XH32 ^ Q[24] ^ M32[8]) + (shl(XL32, 8) ^ Q[23] ^ Q[8]);
|
||||
M32[9] = SPH_ROTL32(M32[5], 10) + (XH32 ^ Q[25] ^ M32[9]) + (shr(XL32, 6) ^ Q[16] ^ Q[9]);
|
||||
M32[10] = SPH_ROTL32(M32[6], 11) + (XH32 ^ Q[26] ^ M32[10]) + (shl(XL32, 6) ^ Q[17] ^ Q[10]);
|
||||
M32[11] = SPH_ROTL32(M32[7], 12) + (XH32 ^ Q[27] ^ M32[11]) + (shl(XL32, 4) ^ Q[18] ^ Q[11]);
|
||||
M32[12] = SPH_ROTL32(M32[0], 13) + (XH32 ^ Q[28] ^ M32[12]) + (shr(XL32, 3) ^ Q[19] ^ Q[12]);
|
||||
M32[13] = SPH_ROTL32(M32[1], 14) + (XH32 ^ Q[29] ^ M32[13]) + (shr(XL32, 4) ^ Q[20] ^ Q[13]);
|
||||
M32[14] = SPH_ROTL32(M32[2], 15) + (XH32 ^ Q[30] ^ M32[14]) + (shr(XL32, 7) ^ Q[21] ^ Q[14]);
|
||||
M32[15] = SPH_ROTL32(M32[3], 16) + (XH32 ^ Q[31] ^ M32[15]) + (shr(XL32, 2) ^ Q[22] ^ Q[15]);
|
||||
}
|
||||
|
||||
__forceinline__ __device__ void Compression256_2(uint32_t M32[16])
|
||||
{
|
||||
const uint32_t H[16] = {
|
||||
(0xaaaaaaa0), (0xaaaaaaa1), (0xaaaaaaa2),
|
||||
(0xaaaaaaa3), (0xaaaaaaa4), (0xaaaaaaa5),
|
||||
(0xaaaaaaa6), (0xaaaaaaa7), (0xaaaaaaa8),
|
||||
(0xaaaaaaa9), (0xaaaaaaaa), (0xaaaaaaab),
|
||||
(0xaaaaaaac), (0xaaaaaaad), (0xaaaaaaae),
|
||||
(0xaaaaaaaf)
|
||||
};
|
||||
int i;
|
||||
uint32_t XL32, XH32, Q[32];
|
||||
|
||||
Q[0] = (M32[5] ^ H[5]) - (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[13] ^ H[13]) + (M32[14] ^ H[14]);
|
||||
Q[1] = (M32[6] ^ H[6]) - (M32[8] ^ H[8]) + (M32[11] ^ H[11]) + (M32[14] ^ H[14]) - (M32[15] ^ H[15]);
|
||||
Q[2] = (M32[0] ^ H[0]) + (M32[7] ^ H[7]) + (M32[9] ^ H[9]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
|
||||
Q[3] = (M32[0] ^ H[0]) - (M32[1] ^ H[1]) + (M32[8] ^ H[8]) - (M32[10] ^ H[10]) + (M32[13] ^ H[13]);
|
||||
Q[4] = (M32[1] ^ H[1]) + (M32[2] ^ H[2]) + (M32[9] ^ H[9]) - (M32[11] ^ H[11]) - (M32[14] ^ H[14]);
|
||||
Q[5] = (M32[3] ^ H[3]) - (M32[2] ^ H[2]) + (M32[10] ^ H[10]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
|
||||
Q[6] = (M32[4] ^ H[4]) - (M32[0] ^ H[0]) - (M32[3] ^ H[3]) - (M32[11] ^ H[11]) + (M32[13] ^ H[13]);
|
||||
Q[7] = (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[5] ^ H[5]) - (M32[12] ^ H[12]) - (M32[14] ^ H[14]);
|
||||
Q[8] = (M32[2] ^ H[2]) - (M32[5] ^ H[5]) - (M32[6] ^ H[6]) + (M32[13] ^ H[13]) - (M32[15] ^ H[15]);
|
||||
Q[9] = (M32[0] ^ H[0]) - (M32[3] ^ H[3]) + (M32[6] ^ H[6]) - (M32[7] ^ H[7]) + (M32[14] ^ H[14]);
|
||||
Q[10] = (M32[8] ^ H[8]) - (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[7] ^ H[7]) + (M32[15] ^ H[15]);
|
||||
Q[11] = (M32[8] ^ H[8]) - (M32[0] ^ H[0]) - (M32[2] ^ H[2]) - (M32[5] ^ H[5]) + (M32[9] ^ H[9]);
|
||||
Q[12] = (M32[1] ^ H[1]) + (M32[3] ^ H[3]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[10] ^ H[10]);
|
||||
Q[13] = (M32[2] ^ H[2]) + (M32[4] ^ H[4]) + (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[11] ^ H[11]);
|
||||
Q[14] = (M32[3] ^ H[3]) - (M32[5] ^ H[5]) + (M32[8] ^ H[8]) - (M32[11] ^ H[11]) - (M32[12] ^ H[12]);
|
||||
Q[15] = (M32[12] ^ H[12]) - (M32[4] ^ H[4]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[13] ^ H[13]);
|
||||
|
||||
/* Diffuse the differences in every word in a bijective manner with ssi, and then add the values of the previous double pipe.*/
|
||||
Q[0] = ss0(Q[0]) + H[1];
|
||||
Q[1] = ss1(Q[1]) + H[2];
|
||||
Q[2] = ss2(Q[2]) + H[3];
|
||||
Q[3] = ss3(Q[3]) + H[4];
|
||||
Q[4] = ss4(Q[4]) + H[5];
|
||||
Q[5] = ss0(Q[5]) + H[6];
|
||||
Q[6] = ss1(Q[6]) + H[7];
|
||||
Q[7] = ss2(Q[7]) + H[8];
|
||||
Q[8] = ss3(Q[8]) + H[9];
|
||||
Q[9] = ss4(Q[9]) + H[10];
|
||||
Q[10] = ss0(Q[10]) + H[11];
|
||||
Q[11] = ss1(Q[11]) + H[12];
|
||||
Q[12] = ss2(Q[12]) + H[13];
|
||||
Q[13] = ss3(Q[13]) + H[14];
|
||||
Q[14] = ss4(Q[14]) + H[15];
|
||||
Q[15] = ss0(Q[15]) + H[0];
|
||||
|
||||
/* This is the Message expansion or f_1 in the documentation. */
|
||||
/* It has 16 rounds. */
|
||||
/* Blue Midnight Wish has two tunable security parameters. */
|
||||
/* The parameters are named EXPAND_1_ROUNDS and EXPAND_2_ROUNDS. */
|
||||
/* The following relation for these parameters should is satisfied: */
|
||||
/* EXPAND_1_ROUNDS + EXPAND_2_ROUNDS = 16 */
|
||||
|
||||
#pragma unroll
|
||||
for (i = 0; i<2; i++)
|
||||
Q[i + 16] = expand32_1(i + 16, M32, H, Q);
|
||||
|
||||
/* #pragma unroll
|
||||
for (i = 2; i<16; i++)
|
||||
Q[i + 16] = expand32_2(i + 16, M32, H, Q);
|
||||
*/
|
||||
uint32_t precalc = Q[18 - 16] + Q[18 - 14] + Q[18 - 12] + Q[18 - 10] + Q[18 - 8] + Q[18 - 6]; //+ Q[18 - 4]
|
||||
uint32_t precalc2 = Q[19 - 16] + Q[19 - 14] + Q[19 - 12] + Q[19 - 10] + Q[19 - 8] + Q[19 - 6];//+ Q[19 - 4]
|
||||
|
||||
#pragma unroll
|
||||
for (i = 2 + 16; i < 16 + 16; i += 2)
|
||||
{
|
||||
precalc = precalc + Q[i - 4];
|
||||
precalc2 = precalc2 + Q[i + 1 - 4];
|
||||
uint32_t p1 = ((i*(0x05555555ul) + SPH_ROTL32(M32[(i - 16) % 16], ((i - 16) % 16) + 1) + SPH_ROTL32(M32[(i - 13) % 16], ((i - 13) % 16) + 1) - SPH_ROTL32(M32[(i - 6) % 16], ((i - 6) % 16) + 1)) ^ H[(i - 16 + 7) % 16]);
|
||||
uint32_t p2 = (((i + 1)*(0x05555555ul) + SPH_ROTL32(M32[((i + 1) - 16) % 16], (((i + 1) - 16) % 16) + 1) + SPH_ROTL32(M32[((i + 1) - 13) % 16], (((i + 1) - 13) % 16) + 1) - SPH_ROTL32(M32[((i + 1) - 6) % 16], (((i + 1) - 6) % 16) + 1)) ^ H[((i + 1) - 16 + 7) % 16]);
|
||||
Q[i] = precalc + expand32_2(i, M32, H, Q) + p1;
|
||||
Q[i + 1] = precalc2 + expand32_2(i + 1, M32, H, Q) + p2;
|
||||
precalc = precalc - Q[i - 16];
|
||||
precalc2 = precalc2 - Q[i + 1 - 16];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Blue Midnight Wish has two temporary cummulative variables that accumulate via XORing */
|
||||
/* 16 new variables that are prooduced in the Message Expansion part. */
|
||||
XL32 = Q[16] ^ Q[17] ^ Q[18] ^ Q[19] ^ Q[20] ^ Q[21] ^ Q[22] ^ Q[23];
|
||||
XH32 = XL32^Q[24] ^ Q[25] ^ Q[26] ^ Q[27] ^ Q[28] ^ Q[29] ^ Q[30] ^ Q[31];
|
||||
|
||||
|
||||
M32[2] = (shr(XH32, 5) ^ shl(Q[18], 5) ^ M32[2]) + (XL32 ^ Q[26] ^ Q[2]);
|
||||
M32[3] = (shr(XH32, 1) ^ shl(Q[19], 5) ^ M32[3]) + (XL32 ^ Q[27] ^ Q[3]);
|
||||
M32[14] = SPH_ROTL32(M32[2], 15) + (XH32 ^ Q[30] ^ M32[14]) + (shr(XL32, 7) ^ Q[21] ^ Q[14]);
|
||||
M32[15] = SPH_ROTL32(M32[3], 16) + (XH32 ^ Q[31] ^ M32[15]) + (shr(XL32, 2) ^ Q[22] ^ Q[15]);
|
||||
|
||||
|
||||
M32[2] = (shr(XH32, 5) ^ shl(Q[18], 5) ^ M32[2]) + (XL32 ^ Q[26] ^ Q[2]);
|
||||
M32[3] = (shr(XH32, 1) ^ shl(Q[19], 5) ^ M32[3]) + (XL32 ^ Q[27] ^ Q[3]);
|
||||
M32[14] = SPH_ROTL32(M32[2], 15) + (XH32 ^ Q[30] ^ M32[14]) + (shr(XL32, 7) ^ Q[21] ^ Q[14]);
|
||||
M32[15] = SPH_ROTL32(M32[3], 16) + (XH32 ^ Q[31] ^ M32[15]) + (shr(XL32, 2) ^ Q[22] ^ Q[15]);
|
||||
}
|
||||
|
||||
#define TPB 512
|
||||
__global__ __launch_bounds__(TPB, 2)
|
||||
void bmw256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *g_hash, uint32_t *const __restrict__ nonceVector)
|
||||
void bmw256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint2 *g_hash, uint32_t *const __restrict__ nonceVector, uint32_t Target)
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t message[16] = { 0 };
|
||||
uint2 message[8] = { 0 };
|
||||
|
||||
LOHI(message[0], message[1], __ldg(&g_hash[thread]));
|
||||
LOHI(message[2], message[3], __ldg(&g_hash[thread + 1 * threads]));
|
||||
LOHI(message[4], message[5], __ldg(&g_hash[thread + 2 * threads]));
|
||||
LOHI(message[6], message[7], __ldg(&g_hash[thread + 3 * threads]));
|
||||
message[0] = __ldg(&g_hash[thread + 0 * threads]);
|
||||
message[1] = __ldg(&g_hash[thread + 1 * threads]);
|
||||
message[2] = __ldg(&g_hash[thread + 2 * threads]);
|
||||
message[3] = __ldg(&g_hash[thread + 3 * threads]);
|
||||
//LOHI(message[2], message[3], __ldg(&g_hash[thread + 1 * threads]));
|
||||
//LOHI(message[4], message[5], __ldg(&g_hash[thread + 2 * threads]));
|
||||
//LOHI(message[6], message[7], __ldg(&g_hash[thread + 3 * threads]));
|
||||
|
||||
message[8]=0x80;
|
||||
message[14]=0x100;
|
||||
Compression256(message);
|
||||
Compression256_2(message);
|
||||
message[4].x = 0x80;
|
||||
message[7].x = 0x100;
|
||||
Compression256((uint32_t*)message);
|
||||
Compression256_2((uint32_t*)message);
|
||||
|
||||
if (((uint64_t*)message)[7] <= pTarget[3])
|
||||
if (message[7].y <= Target)
|
||||
{
|
||||
uint32_t tmp = atomicExch(&nonceVector[0], startNounce + thread);
|
||||
if (tmp != 0)
|
||||
@@ -247,7 +348,7 @@ void bmw256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *g_hash
|
||||
}
|
||||
|
||||
__host__
|
||||
void bmw256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *g_hash, uint32_t *resultnonces)
|
||||
void bmw256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *g_hash, uint32_t *resultnonces, uint32_t Target)
|
||||
{
|
||||
const uint32_t threadsperblock = TPB;
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
@@ -255,13 +356,12 @@ void bmw256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint
|
||||
|
||||
cudaMemset(d_GNonce[thr_id], 0, 2 * sizeof(uint32_t));
|
||||
|
||||
bmw256_gpu_hash_32 << <grid, block >> >(threads, startNounce, g_hash, d_GNonce[thr_id]);
|
||||
bmw256_gpu_hash_32 << <grid, block >> >(threads, startNounce, (uint2*)g_hash, d_GNonce[thr_id], Target);
|
||||
cudaMemcpy(d_gnounce[thr_id], d_GNonce[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
resultnonces[0] = *(d_gnounce[thr_id]);
|
||||
resultnonces[1] = *(d_gnounce[thr_id] + 1);
|
||||
}
|
||||
|
||||
|
||||
__host__
|
||||
void bmw256_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
@@ -276,8 +376,10 @@ void bmw256_cpu_free(int thr_id)
|
||||
cudaFreeHost(d_gnounce[thr_id]);
|
||||
}
|
||||
|
||||
/*
|
||||
__host__
|
||||
void bmw256_setTarget(const void *pTargetIn)
|
||||
{
|
||||
cudaMemcpyToSymbol(pTarget, pTargetIn, 32, 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
*/
|
||||
@@ -267,9 +267,9 @@ void Final(uint32_t x[2][2][2][2][2], uint32_t *hashval)
|
||||
}
|
||||
|
||||
#if __CUDA_ARCH__ >= 500
|
||||
__global__ __launch_bounds__(TPB50, 1)
|
||||
__global__ __launch_bounds__(TPB50, 1)
|
||||
#else
|
||||
__global__ __launch_bounds__(TPB35, 1)
|
||||
__global__ __launch_bounds__(TPB35, 1)
|
||||
#endif
|
||||
void cubehash256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint2 *g_hash)
|
||||
{
|
||||
@@ -354,9 +354,8 @@ void cubehash256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce,
|
||||
dim3 grid((threads + tpb - 1) / tpb);
|
||||
dim3 block(tpb);
|
||||
|
||||
cubehash256_gpu_hash_32 <<<grid, block >>> (threads, startNounce, (uint2*)d_hash);
|
||||
cubehash256_gpu_hash_32 << <grid, block >> > (threads, startNounce, (uint2*)d_hash);
|
||||
}
|
||||
|
||||
__host__
|
||||
void cubehash256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_hash, int order, cudaStream_t stream)
|
||||
{
|
||||
@@ -366,5 +365,5 @@ void cubehash256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce,
|
||||
dim3 grid((threads + tpb - 1) / tpb);
|
||||
dim3 block(tpb);
|
||||
|
||||
cubehash256_gpu_hash_32 <<<grid, block, 0, stream >>> (threads, startNounce, (uint2*)d_hash);
|
||||
cubehash256_gpu_hash_32 << <grid, block, 0, stream >> > (threads, startNounce, (uint2*)d_hash);
|
||||
}
|
||||
+261
-335
@@ -1,383 +1,309 @@
|
||||
/**
|
||||
* KECCAK-256 CUDA optimised implementation, based on ccminer-alexis code
|
||||
*/
|
||||
|
||||
#include <miner.h>
|
||||
#include "miner.h"
|
||||
|
||||
extern "C" {
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
}
|
||||
|
||||
#include <cuda_helper.h>
|
||||
#include <cuda_vectors.h>
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#define TPB52 1024
|
||||
#define TPB50 384
|
||||
#define NPT 2
|
||||
#define NBN 2
|
||||
|
||||
static uint32_t *d_nonces[MAX_GPUS];
|
||||
static uint32_t *h_nonces[MAX_GPUS];
|
||||
|
||||
__constant__ uint2 c_message48[6];
|
||||
__constant__ uint2 c_mid[17];
|
||||
|
||||
__constant__ uint2 keccak_round_constants[24] = {
|
||||
{ 0x00000001, 0x00000000 }, { 0x00008082, 0x00000000 }, { 0x0000808a, 0x80000000 }, { 0x80008000, 0x80000000 },
|
||||
{ 0x0000808b, 0x00000000 }, { 0x80000001, 0x00000000 }, { 0x80008081, 0x80000000 }, { 0x00008009, 0x80000000 },
|
||||
{ 0x0000008a, 0x00000000 }, { 0x00000088, 0x00000000 }, { 0x80008009, 0x00000000 }, { 0x8000000a, 0x00000000 },
|
||||
{ 0x8000808b, 0x00000000 }, { 0x0000008b, 0x80000000 }, { 0x00008089, 0x80000000 }, { 0x00008003, 0x80000000 },
|
||||
{ 0x00008002, 0x80000000 }, { 0x00000080, 0x80000000 }, { 0x0000800a, 0x00000000 }, { 0x8000000a, 0x80000000 },
|
||||
{ 0x80008081, 0x80000000 }, { 0x00008080, 0x80000000 }, { 0x80000001, 0x00000000 }, { 0x80008008, 0x80000000 }
|
||||
static const uint64_t host_keccak_round_constants[24] = {
|
||||
0x0000000000000001ull, 0x0000000000008082ull,
|
||||
0x800000000000808aull, 0x8000000080008000ull,
|
||||
0x000000000000808bull, 0x0000000080000001ull,
|
||||
0x8000000080008081ull, 0x8000000000008009ull,
|
||||
0x000000000000008aull, 0x0000000000000088ull,
|
||||
0x0000000080008009ull, 0x000000008000000aull,
|
||||
0x000000008000808bull, 0x800000000000008bull,
|
||||
0x8000000000008089ull, 0x8000000000008003ull,
|
||||
0x8000000000008002ull, 0x8000000000000080ull,
|
||||
0x000000000000800aull, 0x800000008000000aull,
|
||||
0x8000000080008081ull, 0x8000000000008080ull,
|
||||
0x0000000080000001ull, 0x8000000080008008ull
|
||||
};
|
||||
|
||||
__device__ __forceinline__
|
||||
uint2 xor3x(const uint2 a,const uint2 b,const uint2 c) {
|
||||
uint2 result;
|
||||
#if __CUDA_ARCH__ >= 500 && CUDA_VERSION >= 7050
|
||||
asm ("lop3.b32 %0, %1, %2, %3, 0x96;" : "=r"(result.x) : "r"(a.x), "r"(b.x),"r"(c.x)); //0x96 = 0xF0 ^ 0xCC ^ 0xAA
|
||||
asm ("lop3.b32 %0, %1, %2, %3, 0x96;" : "=r"(result.y) : "r"(a.y), "r"(b.y),"r"(c.y)); //0x96 = 0xF0 ^ 0xCC ^ 0xAA
|
||||
#else
|
||||
result = a^b^c;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
uint32_t *d_nounce[MAX_GPUS];
|
||||
uint32_t *d_KNonce[MAX_GPUS];
|
||||
|
||||
__device__ __forceinline__
|
||||
uint2 chi(const uint2 a,const uint2 b,const uint2 c) { // keccak chi
|
||||
uint2 result;
|
||||
#if __CUDA_ARCH__ >= 500 && CUDA_VERSION >= 7050
|
||||
asm ("lop3.b32 %0, %1, %2, %3, 0xD2;" : "=r"(result.x) : "r"(a.x), "r"(b.x),"r"(c.x)); //0xD2 = 0xF0 ^ ((~0xCC) & 0xAA)
|
||||
asm ("lop3.b32 %0, %1, %2, %3, 0xD2;" : "=r"(result.y) : "r"(a.y), "r"(b.y),"r"(c.y)); //0xD2 = 0xF0 ^ ((~0xCC) & 0xAA)
|
||||
#else
|
||||
result = a ^ (~b) & c;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
__constant__ uint32_t pTarget[8];
|
||||
__constant__ uint64_t keccak_round_constants[24];
|
||||
__constant__ uint64_t c_PaddedMessage80[10]; // padded message (80 bytes + padding?)
|
||||
|
||||
#if __CUDA_ARCH__ >= 350
|
||||
__device__ __forceinline__
|
||||
uint64_t xor5(uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e)
|
||||
static void keccak_blockv35(uint2 *s, const uint64_t *keccak_round_constants)
|
||||
{
|
||||
uint64_t result;
|
||||
asm("xor.b64 %0, %1, %2;" : "=l"(result) : "l"(d) ,"l"(e));
|
||||
asm("xor.b64 %0, %0, %1;" : "+l"(result) : "l"(c));
|
||||
asm("xor.b64 %0, %0, %1;" : "+l"(result) : "l"(b));
|
||||
asm("xor.b64 %0, %0, %1;" : "+l"(result) : "l"(a));
|
||||
return result;
|
||||
}
|
||||
size_t i;
|
||||
uint2 t[5], u[5], v, w;
|
||||
|
||||
#if __CUDA_ARCH__ <= 500
|
||||
__global__ __launch_bounds__(TPB50, 2)
|
||||
#else
|
||||
__global__ __launch_bounds__(TPB52, 1)
|
||||
#endif
|
||||
void keccak256_gpu_hash_80(uint32_t threads, uint32_t startNonce, uint32_t *resNounce, const uint2 highTarget)
|
||||
{
|
||||
uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
uint2 s[25], t[5], v, w, u[5];
|
||||
#if __CUDA_ARCH__ > 500
|
||||
uint64_t step = gridDim.x * blockDim.x;
|
||||
uint64_t maxNonce = startNonce + threads;
|
||||
for(uint64_t nounce = startNonce + thread; nounce<maxNonce;nounce+=step) {
|
||||
#else
|
||||
uint32_t nounce = startNonce+thread;
|
||||
if(thread<threads) {
|
||||
#endif
|
||||
s[ 9] = make_uint2(c_message48[0].x,cuda_swab32(nounce));
|
||||
s[10] = keccak_round_constants[0];
|
||||
#pragma unroll
|
||||
for (i = 0; i < 24; i++) {
|
||||
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
|
||||
t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
|
||||
t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
|
||||
t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
|
||||
t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
|
||||
t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
|
||||
|
||||
t[ 4] = c_message48[1]^s[ 9];
|
||||
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
|
||||
u[ 0] = t[4] ^ c_mid[ 0];
|
||||
u[ 1] = c_mid[ 1] ^ ROL2(t[4],1);
|
||||
u[ 2] = c_mid[ 2];
|
||||
/* thetarho pi: b[..] = rotl(a[..] ^ d[...], ..)*/
|
||||
s[ 7] = ROL2(s[10]^u[0], 3);
|
||||
s[10] = c_mid[ 3];
|
||||
w = c_mid[ 4];
|
||||
s[20] = c_mid[ 5];
|
||||
s[ 6] = ROL2(s[ 9]^u[2],20);
|
||||
s[ 9] = c_mid[ 6];
|
||||
s[22] = c_mid[ 7];
|
||||
s[14] = ROL2(u[0],18);
|
||||
s[ 2] = c_mid[ 8];
|
||||
s[12] = ROL2(u[1],25);
|
||||
s[13] = c_mid[ 9];
|
||||
s[19] = ROR8(u[1]);
|
||||
s[23] = ROR2(u[0],23);
|
||||
s[15] = c_mid[10];
|
||||
s[ 4] = c_mid[11];
|
||||
s[24] = c_mid[12];
|
||||
s[21] = ROR2(c_message48[2]^u[1], 9);
|
||||
s[ 8] = c_mid[13];
|
||||
s[16] = ROR2(c_message48[3]^u[0],28);
|
||||
s[ 5] = ROL2(c_message48[4]^u[1],28);
|
||||
s[ 3] = ROL2(u[1],21);
|
||||
s[18] = c_mid[14];
|
||||
s[17] = c_mid[15];
|
||||
s[11] = c_mid[16];
|
||||
u[0] = t[4] ^ ROL2(t[1], 1);
|
||||
u[1] = t[0] ^ ROL2(t[2], 1);
|
||||
u[2] = t[1] ^ ROL2(t[3], 1);
|
||||
u[3] = t[2] ^ ROL2(t[4], 1);
|
||||
u[4] = t[3] ^ ROL2(t[0], 1);
|
||||
|
||||
/* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */
|
||||
s[0] ^= u[0]; s[5] ^= u[0]; s[10] ^= u[0]; s[15] ^= u[0]; s[20] ^= u[0];
|
||||
s[1] ^= u[1]; s[6] ^= u[1]; s[11] ^= u[1]; s[16] ^= u[1]; s[21] ^= u[1];
|
||||
s[2] ^= u[2]; s[7] ^= u[2]; s[12] ^= u[2]; s[17] ^= u[2]; s[22] ^= u[2];
|
||||
s[3] ^= u[3]; s[8] ^= u[3]; s[13] ^= u[3]; s[18] ^= u[3]; s[23] ^= u[3];
|
||||
s[4] ^= u[4]; s[9] ^= u[4]; s[14] ^= u[4]; s[19] ^= u[4]; s[24] ^= u[4];
|
||||
|
||||
/* rho pi: b[..] = rotl(a[..], ..) */
|
||||
v = s[1];
|
||||
s[1] = ROL2(s[6], 44);
|
||||
s[6] = ROL2(s[9], 20);
|
||||
s[9] = ROL2(s[22], 61);
|
||||
s[22] = ROL2(s[14], 39);
|
||||
s[14] = ROL2(s[20], 18);
|
||||
s[20] = ROL2(s[2], 62);
|
||||
s[2] = ROL2(s[12], 43);
|
||||
s[12] = ROL2(s[13], 25);
|
||||
s[13] = ROL2(s[19], 8);
|
||||
s[19] = ROL2(s[23], 56);
|
||||
s[23] = ROL2(s[15], 41);
|
||||
s[15] = ROL2(s[4], 27);
|
||||
s[4] = ROL2(s[24], 14);
|
||||
s[24] = ROL2(s[21], 2);
|
||||
s[21] = ROL2(s[8], 55);
|
||||
s[8] = ROL2(s[16], 45);
|
||||
s[16] = ROL2(s[5], 36);
|
||||
s[5] = ROL2(s[3], 28);
|
||||
s[3] = ROL2(s[18], 21);
|
||||
s[18] = ROL2(s[17], 15);
|
||||
s[17] = ROL2(s[11], 10);
|
||||
s[11] = ROL2(s[7], 6);
|
||||
s[7] = ROL2(s[10], 3);
|
||||
s[10] = ROL2(v, 1);
|
||||
|
||||
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
|
||||
v = c_message48[5]^u[0];
|
||||
s[ 0] = chi(v,w,s[ 2]);
|
||||
s[ 1] = chi(w,s[ 2],s[ 3]);
|
||||
s[ 2] = chi(s[ 2],s[ 3],s[ 4]);
|
||||
s[ 3] = chi(s[ 3],s[ 4],v);
|
||||
s[ 4] = chi(s[ 4],v,w);
|
||||
v = s[ 5]; w = s[ 6]; s[ 5] = chi(v,w,s[ 7]); s[ 6] = chi(w,s[ 7],s[ 8]); s[ 7] = chi(s[ 7],s[ 8],s[ 9]); s[ 8] = chi(s[ 8],s[ 9],v);s[ 9] = chi(s[ 9],v,w);
|
||||
v = s[10]; w = s[11]; s[10] = chi(v,w,s[12]); s[11] = chi(w,s[12],s[13]); s[12] = chi(s[12],s[13],s[14]); s[13] = chi(s[13],s[14],v);s[14] = chi(s[14],v,w);
|
||||
v = s[15]; w = s[16]; s[15] = chi(v,w,s[17]); s[16] = chi(w,s[17],s[18]); s[17] = chi(s[17],s[18],s[19]); s[18] = chi(s[18],s[19],v);s[19] = chi(s[19],v,w);
|
||||
v = s[20]; w = s[21]; s[20] = chi(v,w,s[22]); s[21] = chi(w,s[22],s[23]); s[22] = chi(s[22],s[23],s[24]); s[23] = chi(s[23],s[24],v);s[24] = chi(s[24],v,w);
|
||||
v = s[0]; w = s[1]; s[0] ^= (~w) & s[2]; s[1] ^= (~s[2]) & s[3]; s[2] ^= (~s[3]) & s[4]; s[3] ^= (~s[4]) & v; s[4] ^= (~v) & w;
|
||||
v = s[5]; w = s[6]; s[5] ^= (~w) & s[7]; s[6] ^= (~s[7]) & s[8]; s[7] ^= (~s[8]) & s[9]; s[8] ^= (~s[9]) & v; s[9] ^= (~v) & w;
|
||||
v = s[10]; w = s[11]; s[10] ^= (~w) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & v; s[14] ^= (~v) & w;
|
||||
v = s[15]; w = s[16]; s[15] ^= (~w) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & v; s[19] ^= (~v) & w;
|
||||
v = s[20]; w = s[21]; s[20] ^= (~w) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & v; s[24] ^= (~v) & w;
|
||||
|
||||
/* iota: a[0,0] ^= round constant */
|
||||
s[ 0] ^=keccak_round_constants[ 0];
|
||||
|
||||
#if __CUDA_ARCH__ > 500
|
||||
#pragma unroll 22
|
||||
#else
|
||||
#pragma unroll 4
|
||||
#endif
|
||||
for (int i = 1; i < 23; i++) {
|
||||
#pragma unroll
|
||||
for(int j=0;j<5;j++) {
|
||||
t[ j] = vectorize(xor5(devectorize(s[ j]),devectorize(s[j+5]),devectorize(s[j+10]),devectorize(s[j+15]),devectorize(s[j+20])));
|
||||
}
|
||||
/*theta*/
|
||||
#pragma unroll
|
||||
for(int j=0;j<5;j++) {
|
||||
u[j] = ROL2(t[j], 1);
|
||||
}
|
||||
s[ 4] = xor3x(s[ 4], t[3], u[0]);s[ 9] = xor3x(s[ 9], t[3], u[0]);s[14] = xor3x(s[14], t[3], u[0]);s[19] = xor3x(s[19], t[3], u[0]);s[24] = xor3x(s[24], t[3], u[0]);
|
||||
s[ 0] = xor3x(s[ 0], t[4], u[1]);s[ 5] = xor3x(s[ 5], t[4], u[1]);s[10] = xor3x(s[10], t[4], u[1]);s[15] = xor3x(s[15], t[4], u[1]);s[20] = xor3x(s[20], t[4], u[1]);
|
||||
s[ 1] = xor3x(s[ 1], t[0], u[2]);s[ 6] = xor3x(s[ 6], t[0], u[2]);s[11] = xor3x(s[11], t[0], u[2]);s[16] = xor3x(s[16], t[0], u[2]);s[21] = xor3x(s[21], t[0], u[2]);
|
||||
s[ 2] = xor3x(s[ 2], t[1], u[3]);s[ 7] = xor3x(s[ 7], t[1], u[3]);s[12] = xor3x(s[12], t[1], u[3]);s[17] = xor3x(s[17], t[1], u[3]);s[22] = xor3x(s[22], t[1], u[3]);
|
||||
s[ 3] = xor3x(s[ 3], t[2], u[4]);s[ 8] = xor3x(s[ 8], t[2], u[4]);s[13] = xor3x(s[13], t[2], u[4]);s[18] = xor3x(s[18], t[2], u[4]);s[23] = xor3x(s[23], t[2], u[4]);
|
||||
/*rho pi: b[..] = rotl(a[..] ^ d[...], ..)*/
|
||||
v = s[ 1];
|
||||
s[ 1] = ROL2(s[ 6],44); s[ 6] = ROL2(s[ 9],20); s[ 9] = ROL2(s[22],61); s[22] = ROL2(s[14],39);
|
||||
s[14] = ROL2(s[20],18); s[20] = ROL2(s[ 2],62); s[ 2] = ROL2(s[12],43); s[12] = ROL2(s[13],25);
|
||||
s[13] = ROL8(s[19]); s[19] = ROR8(s[23]); s[23] = ROL2(s[15],41); s[15] = ROL2(s[ 4],27);
|
||||
s[ 4] = ROL2(s[24],14); s[24] = ROL2(s[21], 2); s[21] = ROL2(s[ 8],55); s[ 8] = ROL2(s[16],45);
|
||||
s[16] = ROL2(s[ 5],36); s[ 5] = ROL2(s[ 3],28); s[ 3] = ROL2(s[18],21); s[18] = ROL2(s[17],15);
|
||||
s[17] = ROL2(s[11],10); s[11] = ROL2(s[ 7], 6); s[ 7] = ROL2(s[10], 3); s[10] = ROL2(v, 1);
|
||||
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
|
||||
#pragma unroll
|
||||
for(int j=0;j<25;j+=5) {
|
||||
v=s[j];w=s[j + 1];s[j] = chi(s[j],s[j+1],s[j+2]);s[j+1] = chi(s[j+1],s[j+2],s[j+3]);s[j+2]=chi(s[j+2],s[j+3],s[j+4]);s[j+3]=chi(s[j+3],s[j+4],v);s[j+4]=chi(s[j+4],v,w);
|
||||
}
|
||||
/* iota: a[0,0] ^= round constant */
|
||||
s[ 0] ^=keccak_round_constants[ i];
|
||||
}
|
||||
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
|
||||
#pragma unroll 5
|
||||
for(int j=0;j<5;j++) {
|
||||
t[ j] = xor3x(xor3x(s[j+0],s[j+5],s[j+10]), s[j+15], s[j+20]);
|
||||
}
|
||||
s[24] = xor3x(s[24],t[3],ROL2(t[0],1));
|
||||
s[18] = xor3x(s[18],t[2],ROL2(t[4],1));
|
||||
s[ 0] = xor3x(s[ 0],t[4],ROL2(t[1],1));
|
||||
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
|
||||
s[24] = ROL2(s[24],14);
|
||||
s[18] = ROL2(s[18],21);
|
||||
if (devectorize(chi(s[18],s[24],s[ 0])) <= devectorize(highTarget)) {
|
||||
// if(chi(s[18].x,s[24].x,s[0].x)<=highTarget.x) {
|
||||
// if(chi(s[18].y,s[24].y,s[0].y)<=highTarget.y) {
|
||||
const uint32_t tmp = atomicExch(&resNounce[0], nounce);
|
||||
if (tmp != UINT32_MAX)
|
||||
resNounce[1] = tmp;
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
s[0] ^= vectorize(keccak_round_constants[i]);
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t* resNonces, const uint2 highTarget)
|
||||
{
|
||||
uint32_t tpb;
|
||||
dim3 grid;
|
||||
if (device_sm[device_map[thr_id]] <= 500) {
|
||||
tpb = TPB50;
|
||||
grid.x = (threads + tpb-1)/tpb;
|
||||
} else {
|
||||
tpb = TPB52;
|
||||
grid.x = (threads + (NPT*tpb)-1)/(NPT*tpb);
|
||||
}
|
||||
const dim3 block(tpb);
|
||||
|
||||
keccak256_gpu_hash_80<<<grid, block>>>(threads, startNonce, d_nonces[thr_id], highTarget);
|
||||
// cudaThreadSynchronize();
|
||||
cudaMemcpy(h_nonces[thr_id], d_nonces[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
memcpy(resNonces, h_nonces[thr_id], NBN*sizeof(uint32_t));
|
||||
}
|
||||
|
||||
#if 0
|
||||
#if __CUDA_ARCH__ <= 500
|
||||
__global__ __launch_bounds__(TPB50, 2)
|
||||
#else
|
||||
__global__ __launch_bounds__(TPB52, 1)
|
||||
#endif
|
||||
void keccak256_gpu_hash_32(uint32_t threads, uint2* outputHash)
|
||||
{
|
||||
uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
uint2 s[25], t[5], v, w, u[5];
|
||||
|
||||
if(thread < threads) {
|
||||
#pragma unroll 25
|
||||
for (int i = 0; i<25; i++) {
|
||||
if (i<4) s[i] = __ldg(&outputHash[i*threads+thread]);
|
||||
else s[i] = make_uint2(0, 0);
|
||||
}
|
||||
s[4] = keccak_round_constants[ 0];
|
||||
s[16] = make_uint2(0, 0x80000000);
|
||||
#if __CUDA_ARCH__ > 500
|
||||
#pragma unroll
|
||||
#else
|
||||
#pragma unroll 4
|
||||
#endif
|
||||
for (uint32_t i = 0; i < 23; i++) {
|
||||
/*theta*/
|
||||
#pragma unroll 5
|
||||
for(int j=0; j<5; j++) {
|
||||
t[ j] = vectorize(xor5(devectorize(s[ j]),devectorize(s[j+5]),devectorize(s[j+10]),devectorize(s[j+15]),devectorize(s[j+20])));
|
||||
}
|
||||
/*theta*/
|
||||
#pragma unroll 5
|
||||
for(int j=0; j<5; j++) {
|
||||
u[j] = ROL2(t[j], 1);
|
||||
}
|
||||
s[ 4] = xor3x(s[ 4], t[3], u[0]);s[ 9] = xor3x(s[ 9], t[3], u[0]);s[14] = xor3x(s[14], t[3], u[0]);s[19] = xor3x(s[19], t[3], u[0]);s[24] = xor3x(s[24], t[3], u[0]);
|
||||
s[ 0] = xor3x(s[ 0], t[4], u[1]);s[ 5] = xor3x(s[ 5], t[4], u[1]);s[10] = xor3x(s[10], t[4], u[1]);s[15] = xor3x(s[15], t[4], u[1]);s[20] = xor3x(s[20], t[4], u[1]);
|
||||
s[ 1] = xor3x(s[ 1], t[0], u[2]);s[ 6] = xor3x(s[ 6], t[0], u[2]);s[11] = xor3x(s[11], t[0], u[2]);s[16] = xor3x(s[16], t[0], u[2]);s[21] = xor3x(s[21], t[0], u[2]);
|
||||
s[ 2] = xor3x(s[ 2], t[1], u[3]);s[ 7] = xor3x(s[ 7], t[1], u[3]);s[12] = xor3x(s[12], t[1], u[3]);s[17] = xor3x(s[17], t[1], u[3]);s[22] = xor3x(s[22], t[1], u[3]);
|
||||
s[ 3] = xor3x(s[ 3], t[2], u[4]);s[ 8] = xor3x(s[ 8], t[2], u[4]);s[13] = xor3x(s[13], t[2], u[4]);s[18] = xor3x(s[18], t[2], u[4]);s[23] = xor3x(s[23], t[2], u[4]);
|
||||
/*rho pi: b[..] = rotl(a[..] ^ d[...], ..)*/
|
||||
v = s[ 1];
|
||||
s[ 1] = ROL2(s[ 6],44); s[ 6] = ROL2(s[ 9],20); s[ 9] = ROL2(s[22],61); s[22] = ROL2(s[14],39);
|
||||
s[14] = ROL2(s[20],18); s[20] = ROL2(s[ 2],62); s[ 2] = ROL2(s[12],43); s[12] = ROL2(s[13],25);
|
||||
s[13] = ROL8(s[19]); s[19] = ROR8(s[23]); s[23] = ROL2(s[15],41); s[15] = ROL2(s[ 4],27);
|
||||
s[ 4] = ROL2(s[24],14); s[24] = ROL2(s[21], 2); s[21] = ROL2(s[ 8],55); s[ 8] = ROL2(s[16],45);
|
||||
s[16] = ROL2(s[ 5],36); s[ 5] = ROL2(s[ 3],28); s[ 3] = ROL2(s[18],21); s[18] = ROL2(s[17],15);
|
||||
s[17] = ROL2(s[11],10); s[11] = ROL2(s[ 7], 6); s[ 7] = ROL2(s[10], 3); s[10] = ROL2(v, 1);
|
||||
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
|
||||
#pragma unroll 5
|
||||
for(int j=0; j<25; j+=5) {
|
||||
v=s[j];w=s[j + 1]; s[j] = chi(v,w,s[j+2]); s[j+1] = chi(w,s[j+2],s[j+3]); s[j+2]=chi(s[j+2],s[j+3],s[j+4]); s[j+3]=chi(s[j+3],s[j+4],v); s[j+4]=chi(s[j+4],v,w);
|
||||
}
|
||||
/* iota: a[0,0] ^= round constant */
|
||||
s[ 0] ^=keccak_round_constants[ i];
|
||||
}
|
||||
__device__ __forceinline__
|
||||
static void keccak_blockv30(uint64_t *s, const uint64_t *keccak_round_constants)
|
||||
{
|
||||
size_t i;
|
||||
uint64_t t[5], u[5], v, w;
|
||||
|
||||
/* absorb input */
|
||||
|
||||
for (i = 0; i < 24; i++) {
|
||||
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
|
||||
#pragma unroll 5
|
||||
for(int j=0;j<5;j++) {
|
||||
t[ j] = xor3x(xor3x(s[j+0],s[j+5],s[j+10]), s[j+15], s[j+20]);
|
||||
}
|
||||
t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
|
||||
t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
|
||||
t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
|
||||
t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
|
||||
t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
|
||||
|
||||
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
|
||||
#pragma unroll 5
|
||||
for(int j=0;j<5;j++) {
|
||||
u[j] = ROL2(t[j],1);
|
||||
}
|
||||
/* thetarho pi: b[..] = rotl(a[..] ^ d[...], ..) //There's no need to perform theta and -store- the result since it's unique for each a[..]*/
|
||||
s[ 4] = xor3x(s[24], t[3], u[0]);
|
||||
s[ 0] = xor3x(s[ 0], t[4], u[1]);
|
||||
s[ 1] = xor3x(s[ 6], t[0], u[2]);
|
||||
s[ 2] = xor3x(s[12], t[1], u[3]);
|
||||
s[ 3] = xor3x(s[18], t[2], u[4]);
|
||||
s[ 1] = ROR2(s[ 1],20);
|
||||
s[ 2] = ROR2(s[ 2],21);
|
||||
s[ 3] = ROL2(s[ 3],21);
|
||||
s[ 4] = ROL2(s[ 4],14);
|
||||
u[0] = t[4] ^ ROTL64(t[1], 1);
|
||||
u[1] = t[0] ^ ROTL64(t[2], 1);
|
||||
u[2] = t[1] ^ ROTL64(t[3], 1);
|
||||
u[3] = t[2] ^ ROTL64(t[4], 1);
|
||||
u[4] = t[3] ^ ROTL64(t[0], 1);
|
||||
|
||||
/* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */
|
||||
s[0] ^= u[0]; s[5] ^= u[0]; s[10] ^= u[0]; s[15] ^= u[0]; s[20] ^= u[0];
|
||||
s[1] ^= u[1]; s[6] ^= u[1]; s[11] ^= u[1]; s[16] ^= u[1]; s[21] ^= u[1];
|
||||
s[2] ^= u[2]; s[7] ^= u[2]; s[12] ^= u[2]; s[17] ^= u[2]; s[22] ^= u[2];
|
||||
s[3] ^= u[3]; s[8] ^= u[3]; s[13] ^= u[3]; s[18] ^= u[3]; s[23] ^= u[3];
|
||||
s[4] ^= u[4]; s[9] ^= u[4]; s[14] ^= u[4]; s[19] ^= u[4]; s[24] ^= u[4];
|
||||
|
||||
/* rho pi: b[..] = rotl(a[..], ..) */
|
||||
v = s[ 1];
|
||||
s[ 1] = ROTL64(s[ 6], 44);
|
||||
s[ 6] = ROTL64(s[ 9], 20);
|
||||
s[ 9] = ROTL64(s[22], 61);
|
||||
s[22] = ROTL64(s[14], 39);
|
||||
s[14] = ROTL64(s[20], 18);
|
||||
s[20] = ROTL64(s[ 2], 62);
|
||||
s[ 2] = ROTL64(s[12], 43);
|
||||
s[12] = ROTL64(s[13], 25);
|
||||
s[13] = ROTL64(s[19], 8);
|
||||
s[19] = ROTL64(s[23], 56);
|
||||
s[23] = ROTL64(s[15], 41);
|
||||
s[15] = ROTL64(s[ 4], 27);
|
||||
s[ 4] = ROTL64(s[24], 14);
|
||||
s[24] = ROTL64(s[21], 2);
|
||||
s[21] = ROTL64(s[ 8], 55);
|
||||
s[ 8] = ROTL64(s[16], 45);
|
||||
s[16] = ROTL64(s[ 5], 36);
|
||||
s[ 5] = ROTL64(s[ 3], 28);
|
||||
s[ 3] = ROTL64(s[18], 21);
|
||||
s[18] = ROTL64(s[17], 15);
|
||||
s[17] = ROTL64(s[11], 10);
|
||||
s[11] = ROTL64(s[ 7], 6);
|
||||
s[ 7] = ROTL64(s[10], 3);
|
||||
s[10] = ROTL64( v, 1);
|
||||
|
||||
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
|
||||
outputHash[0*threads+thread] = chi(s[ 0],s[ 1],s[ 2]) ^ keccak_round_constants[23];
|
||||
outputHash[1*threads+thread] = chi(s[ 1],s[ 2],s[ 3]);
|
||||
outputHash[2*threads+thread] = chi(s[ 2],s[ 3],s[ 4]);
|
||||
outputHash[3*threads+thread] = chi(s[ 3],s[ 4],s[ 0]);
|
||||
v = s[ 0]; w = s[ 1]; s[ 0] ^= (~w) & s[ 2]; s[ 1] ^= (~s[ 2]) & s[ 3]; s[ 2] ^= (~s[ 3]) & s[ 4]; s[ 3] ^= (~s[ 4]) & v; s[ 4] ^= (~v) & w;
|
||||
v = s[ 5]; w = s[ 6]; s[ 5] ^= (~w) & s[ 7]; s[ 6] ^= (~s[ 7]) & s[ 8]; s[ 7] ^= (~s[ 8]) & s[ 9]; s[ 8] ^= (~s[ 9]) & v; s[ 9] ^= (~v) & w;
|
||||
v = s[10]; w = s[11]; s[10] ^= (~w) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & v; s[14] ^= (~v) & w;
|
||||
v = s[15]; w = s[16]; s[15] ^= (~w) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & v; s[19] ^= (~v) & w;
|
||||
v = s[20]; w = s[21]; s[20] ^= (~w) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & v; s[24] ^= (~v) & w;
|
||||
|
||||
/* iota: a[0,0] ^= round constant */
|
||||
s[0] ^= keccak_round_constants[i];
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_cpu_hash_32(const int thr_id,const uint32_t threads, uint2* d_hash)
|
||||
{
|
||||
uint32_t tpb = TPB52;
|
||||
if (device_sm[device_map[thr_id]] == 500) tpb = TPB50;
|
||||
const dim3 grid((threads + tpb-1)/tpb);
|
||||
const dim3 block(tpb);
|
||||
|
||||
keccak256_gpu_hash_32 <<<grid, block>>> (threads, d_hash);
|
||||
}
|
||||
#endif
|
||||
|
||||
__host__
|
||||
void keccak256_setBlock_80(uint64_t *endiandata)
|
||||
__global__ __launch_bounds__(128,5)
|
||||
void keccak256_gpu_hash_80(uint32_t threads, uint32_t startNounce, void *outputHash, uint32_t *resNounce)
|
||||
{
|
||||
uint64_t midstate[17], s[25];
|
||||
uint64_t t[5], u[5];
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t nounce = startNounce + thread;
|
||||
|
||||
s[10] = 1; //(uint64_t)make_uint2(1, 0);
|
||||
s[16] = ((uint64_t)1)<<63; //(uint64_t)make_uint2(0, 0x80000000);
|
||||
#if __CUDA_ARCH__ >= 350
|
||||
uint2 keccak_gpu_state[25];
|
||||
#pragma unroll 25
|
||||
for (int i=0; i<25; i++) {
|
||||
if (i<9) keccak_gpu_state[i] = vectorize(c_PaddedMessage80[i]);
|
||||
else keccak_gpu_state[i] = make_uint2(0, 0);
|
||||
}
|
||||
|
||||
t[0] = endiandata[0] ^ endiandata[5] ^ s[10];
|
||||
t[1] = endiandata[1] ^ endiandata[6] ^ s[16];
|
||||
t[2] = endiandata[2] ^ endiandata[7];
|
||||
t[3] = endiandata[3] ^ endiandata[8];
|
||||
keccak_gpu_state[9]= vectorize(c_PaddedMessage80[9]);
|
||||
keccak_gpu_state[9].y = cuda_swab32(nounce);
|
||||
keccak_gpu_state[10] = make_uint2(1, 0);
|
||||
keccak_gpu_state[16] = make_uint2(0, 0x80000000);
|
||||
|
||||
midstate[ 0] = ROTL64(t[1], 1); //u[0] -partial
|
||||
u[1] = t[ 0] ^ ROTL64(t[2], 1); //u[1]
|
||||
u[2] = t[ 1] ^ ROTL64(t[3], 1); //u[2]
|
||||
midstate[ 1] = t[ 2]; //u[3] -partial
|
||||
midstate[ 2] = t[ 3] ^ ROTL64(t[0], 1); //u[4]
|
||||
midstate[ 3] = ROTL64(endiandata[1]^u[1], 1); //v
|
||||
midstate[ 4] = ROTL64(endiandata[6]^u[1], 44);
|
||||
midstate[ 5] = ROTL64(endiandata[2]^u[2], 62);
|
||||
midstate[ 6] = ROTL64(u[2], 61);
|
||||
midstate[ 7] = ROTL64(midstate[2], 39);
|
||||
midstate[ 8] = ROTL64(u[2], 43);
|
||||
midstate[ 9] = ROTL64(midstate[2], 8);
|
||||
midstate[10] = ROTL64(endiandata[4]^midstate[ 2],27);
|
||||
midstate[11] = ROTL64(midstate[2], 14);
|
||||
midstate[12] = ROTL64(u[1], 2);
|
||||
midstate[13] = ROTL64(s[16] ^ u[1], 45);
|
||||
midstate[14] = ROTL64(u[2],15);
|
||||
midstate[15] = ROTL64(u[1],10);
|
||||
midstate[16] = ROTL64(endiandata[7]^u[2], 6);
|
||||
keccak_blockv35(keccak_gpu_state,keccak_round_constants);
|
||||
if (devectorize(keccak_gpu_state[3]) <= ((uint64_t*)pTarget)[3]) {resNounce[0] = nounce;}
|
||||
#else
|
||||
uint64_t keccak_gpu_state[25];
|
||||
#pragma unroll 25
|
||||
for (int i=0; i<25; i++) {
|
||||
if (i<9) keccak_gpu_state[i] = c_PaddedMessage80[i];
|
||||
else keccak_gpu_state[i] = 0;
|
||||
}
|
||||
keccak_gpu_state[9] = REPLACE_HIDWORD(c_PaddedMessage80[9], cuda_swab32(nounce));
|
||||
keccak_gpu_state[10] = 0x0000000000000001;
|
||||
keccak_gpu_state[16] = 0x8000000000000000;
|
||||
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_mid, midstate,17*sizeof(uint64_t), 0, cudaMemcpyHostToDevice));
|
||||
|
||||
// pass only what's needed
|
||||
uint64_t message48[6];
|
||||
message48[0] = endiandata[9];
|
||||
message48[1] = endiandata[4];
|
||||
message48[2] = endiandata[8];
|
||||
message48[3] = endiandata[5];
|
||||
message48[4] = endiandata[3];
|
||||
message48[5] = endiandata[0];
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_message48, message48, 6*sizeof(uint64_t), 0, cudaMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_cpu_init(int thr_id)
|
||||
{
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_nonces[thr_id], NBN*sizeof(uint32_t)));
|
||||
//CUDA_SAFE_CALL(cudaMallocHost(&h_nonces[thr_id], NBN*sizeof(uint32_t)));
|
||||
h_nonces[thr_id] = (uint32_t*) malloc(NBN * sizeof(uint32_t));
|
||||
if(h_nonces[thr_id] == NULL) {
|
||||
gpulog(LOG_ERR,thr_id,"Host memory allocation failed");
|
||||
exit(EXIT_FAILURE);
|
||||
keccak_blockv30(keccak_gpu_state, keccak_round_constants);
|
||||
if (keccak_gpu_state[3] <= ((uint64_t*)pTarget)[3]) { resNounce[0] = nounce; }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_setOutput(int thr_id)
|
||||
uint32_t keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_outputHash, int order)
|
||||
{
|
||||
CUDA_SAFE_CALL(cudaMemset(d_nonces[thr_id], 0xff, NBN*sizeof(uint32_t)));
|
||||
uint32_t result = UINT32_MAX;
|
||||
cudaMemset(d_KNonce[thr_id], 0xff, sizeof(uint32_t));
|
||||
const uint32_t threadsperblock = 128;
|
||||
|
||||
dim3 grid((threads + threadsperblock-1)/threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
size_t shared_size = 0;
|
||||
|
||||
keccak256_gpu_hash_80<<<grid, block, shared_size>>>(threads, startNounce, d_outputHash, d_KNonce[thr_id]);
|
||||
|
||||
MyStreamSynchronize(NULL, order, thr_id);
|
||||
cudaMemcpy(d_nounce[thr_id], d_KNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
cudaThreadSynchronize();
|
||||
result = *d_nounce[thr_id];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(256,3)
|
||||
void keccak256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *outputHash)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 350 /* tpr: to double check if faster on SM5+ */
|
||||
uint2 keccak_gpu_state[25];
|
||||
#pragma unroll 25
|
||||
for (int i = 0; i<25; i++) {
|
||||
if (i<4) keccak_gpu_state[i] = vectorize(outputHash[i*threads+thread]);
|
||||
else keccak_gpu_state[i] = make_uint2(0, 0);
|
||||
}
|
||||
keccak_gpu_state[4] = make_uint2(1, 0);
|
||||
keccak_gpu_state[16] = make_uint2(0, 0x80000000);
|
||||
keccak_blockv35(keccak_gpu_state, keccak_round_constants);
|
||||
|
||||
#pragma unroll 4
|
||||
for (int i=0; i<4; i++)
|
||||
outputHash[i*threads+thread] = devectorize(keccak_gpu_state[i]);
|
||||
#else
|
||||
uint64_t keccak_gpu_state[25];
|
||||
#pragma unroll 25
|
||||
for (int i = 0; i<25; i++) {
|
||||
if (i<4)
|
||||
keccak_gpu_state[i] = outputHash[i*threads+thread];
|
||||
else
|
||||
keccak_gpu_state[i] = 0;
|
||||
}
|
||||
keccak_gpu_state[4] = 0x0000000000000001;
|
||||
keccak_gpu_state[16] = 0x8000000000000000;
|
||||
|
||||
keccak_blockv30(keccak_gpu_state, keccak_round_constants);
|
||||
#pragma unroll 4
|
||||
for (int i = 0; i<4; i++)
|
||||
outputHash[i*threads + thread] = keccak_gpu_state[i];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_outputHash, int order)
|
||||
{
|
||||
const uint32_t threadsperblock = 256;
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
keccak256_gpu_hash_32 <<<grid, block>>> (threads, startNounce, d_outputHash);
|
||||
MyStreamSynchronize(NULL, order, thr_id);
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_setBlock_80(void *pdata,const void *pTargetIn)
|
||||
{
|
||||
unsigned char PaddedMessage[80];
|
||||
memcpy(PaddedMessage, pdata, 80);
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(pTarget, pTargetIn, 8*sizeof(uint32_t), 0, cudaMemcpyHostToDevice));
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_PaddedMessage80, PaddedMessage, 10*sizeof(uint64_t), 0, cudaMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(keccak_round_constants, host_keccak_round_constants,
|
||||
sizeof(host_keccak_round_constants), 0, cudaMemcpyHostToDevice));
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_KNonce[thr_id], sizeof(uint32_t)));
|
||||
CUDA_SAFE_CALL(cudaMallocHost(&d_nounce[thr_id], 1*sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_nonces[thr_id]);
|
||||
//cudaFreeHost(h_nonces[thr_id]);
|
||||
free(h_nonces[thr_id]);
|
||||
cudaFree(d_KNonce[thr_id]);
|
||||
cudaFreeHost(d_nounce[thr_id]);
|
||||
}
|
||||
@@ -1,303 +0,0 @@
|
||||
#include "miner.h"
|
||||
|
||||
extern "C" {
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
}
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static const uint64_t host_keccak_round_constants[24] = {
|
||||
0x0000000000000001ull, 0x0000000000008082ull,
|
||||
0x800000000000808aull, 0x8000000080008000ull,
|
||||
0x000000000000808bull, 0x0000000080000001ull,
|
||||
0x8000000080008081ull, 0x8000000000008009ull,
|
||||
0x000000000000008aull, 0x0000000000000088ull,
|
||||
0x0000000080008009ull, 0x000000008000000aull,
|
||||
0x000000008000808bull, 0x800000000000008bull,
|
||||
0x8000000000008089ull, 0x8000000000008003ull,
|
||||
0x8000000000008002ull, 0x8000000000000080ull,
|
||||
0x000000000000800aull, 0x800000008000000aull,
|
||||
0x8000000080008081ull, 0x8000000000008080ull,
|
||||
0x0000000080000001ull, 0x8000000080008008ull
|
||||
};
|
||||
|
||||
static uint32_t *d_KNonce[MAX_GPUS];
|
||||
|
||||
__constant__ uint32_t pTarget[8];
|
||||
__constant__ uint64_t keccak_round_constants[24];
|
||||
__constant__ uint64_t c_PaddedMessage80[10]; // padded message (80 bytes + padding?)
|
||||
|
||||
#if __CUDA_ARCH__ >= 350
|
||||
__device__ __forceinline__
|
||||
static void keccak_blockv35(uint2 *s, const uint64_t *keccak_round_constants)
|
||||
{
|
||||
size_t i;
|
||||
uint2 t[5], u[5], v, w;
|
||||
|
||||
#pragma unroll
|
||||
for (i = 0; i < 24; i++) {
|
||||
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
|
||||
t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
|
||||
t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
|
||||
t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
|
||||
t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
|
||||
t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
|
||||
|
||||
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
|
||||
u[0] = t[4] ^ ROL2(t[1], 1);
|
||||
u[1] = t[0] ^ ROL2(t[2], 1);
|
||||
u[2] = t[1] ^ ROL2(t[3], 1);
|
||||
u[3] = t[2] ^ ROL2(t[4], 1);
|
||||
u[4] = t[3] ^ ROL2(t[0], 1);
|
||||
|
||||
/* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */
|
||||
s[0] ^= u[0]; s[5] ^= u[0]; s[10] ^= u[0]; s[15] ^= u[0]; s[20] ^= u[0];
|
||||
s[1] ^= u[1]; s[6] ^= u[1]; s[11] ^= u[1]; s[16] ^= u[1]; s[21] ^= u[1];
|
||||
s[2] ^= u[2]; s[7] ^= u[2]; s[12] ^= u[2]; s[17] ^= u[2]; s[22] ^= u[2];
|
||||
s[3] ^= u[3]; s[8] ^= u[3]; s[13] ^= u[3]; s[18] ^= u[3]; s[23] ^= u[3];
|
||||
s[4] ^= u[4]; s[9] ^= u[4]; s[14] ^= u[4]; s[19] ^= u[4]; s[24] ^= u[4];
|
||||
|
||||
/* rho pi: b[..] = rotl(a[..], ..) */
|
||||
v = s[1];
|
||||
s[1] = ROL2(s[6], 44);
|
||||
s[6] = ROL2(s[9], 20);
|
||||
s[9] = ROL2(s[22], 61);
|
||||
s[22] = ROL2(s[14], 39);
|
||||
s[14] = ROL2(s[20], 18);
|
||||
s[20] = ROL2(s[2], 62);
|
||||
s[2] = ROL2(s[12], 43);
|
||||
s[12] = ROL2(s[13], 25);
|
||||
s[13] = ROL2(s[19], 8);
|
||||
s[19] = ROL2(s[23], 56);
|
||||
s[23] = ROL2(s[15], 41);
|
||||
s[15] = ROL2(s[4], 27);
|
||||
s[4] = ROL2(s[24], 14);
|
||||
s[24] = ROL2(s[21], 2);
|
||||
s[21] = ROL2(s[8], 55);
|
||||
s[8] = ROL2(s[16], 45);
|
||||
s[16] = ROL2(s[5], 36);
|
||||
s[5] = ROL2(s[3], 28);
|
||||
s[3] = ROL2(s[18], 21);
|
||||
s[18] = ROL2(s[17], 15);
|
||||
s[17] = ROL2(s[11], 10);
|
||||
s[11] = ROL2(s[7], 6);
|
||||
s[7] = ROL2(s[10], 3);
|
||||
s[10] = ROL2(v, 1);
|
||||
|
||||
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
|
||||
v = s[0]; w = s[1]; s[0] ^= (~w) & s[2]; s[1] ^= (~s[2]) & s[3]; s[2] ^= (~s[3]) & s[4]; s[3] ^= (~s[4]) & v; s[4] ^= (~v) & w;
|
||||
v = s[5]; w = s[6]; s[5] ^= (~w) & s[7]; s[6] ^= (~s[7]) & s[8]; s[7] ^= (~s[8]) & s[9]; s[8] ^= (~s[9]) & v; s[9] ^= (~v) & w;
|
||||
v = s[10]; w = s[11]; s[10] ^= (~w) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & v; s[14] ^= (~v) & w;
|
||||
v = s[15]; w = s[16]; s[15] ^= (~w) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & v; s[19] ^= (~v) & w;
|
||||
v = s[20]; w = s[21]; s[20] ^= (~w) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & v; s[24] ^= (~v) & w;
|
||||
|
||||
/* iota: a[0,0] ^= round constant */
|
||||
s[0] ^= vectorize(keccak_round_constants[i]);
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
__device__ __forceinline__
|
||||
static void keccak_blockv30(uint64_t *s, const uint64_t *keccak_round_constants)
|
||||
{
|
||||
size_t i;
|
||||
uint64_t t[5], u[5], v, w;
|
||||
|
||||
/* absorb input */
|
||||
|
||||
for (i = 0; i < 24; i++) {
|
||||
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
|
||||
t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
|
||||
t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
|
||||
t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
|
||||
t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
|
||||
t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
|
||||
|
||||
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
|
||||
u[0] = t[4] ^ ROTL64(t[1], 1);
|
||||
u[1] = t[0] ^ ROTL64(t[2], 1);
|
||||
u[2] = t[1] ^ ROTL64(t[3], 1);
|
||||
u[3] = t[2] ^ ROTL64(t[4], 1);
|
||||
u[4] = t[3] ^ ROTL64(t[0], 1);
|
||||
|
||||
/* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */
|
||||
s[0] ^= u[0]; s[5] ^= u[0]; s[10] ^= u[0]; s[15] ^= u[0]; s[20] ^= u[0];
|
||||
s[1] ^= u[1]; s[6] ^= u[1]; s[11] ^= u[1]; s[16] ^= u[1]; s[21] ^= u[1];
|
||||
s[2] ^= u[2]; s[7] ^= u[2]; s[12] ^= u[2]; s[17] ^= u[2]; s[22] ^= u[2];
|
||||
s[3] ^= u[3]; s[8] ^= u[3]; s[13] ^= u[3]; s[18] ^= u[3]; s[23] ^= u[3];
|
||||
s[4] ^= u[4]; s[9] ^= u[4]; s[14] ^= u[4]; s[19] ^= u[4]; s[24] ^= u[4];
|
||||
|
||||
/* rho pi: b[..] = rotl(a[..], ..) */
|
||||
v = s[ 1];
|
||||
s[ 1] = ROTL64(s[ 6], 44);
|
||||
s[ 6] = ROTL64(s[ 9], 20);
|
||||
s[ 9] = ROTL64(s[22], 61);
|
||||
s[22] = ROTL64(s[14], 39);
|
||||
s[14] = ROTL64(s[20], 18);
|
||||
s[20] = ROTL64(s[ 2], 62);
|
||||
s[ 2] = ROTL64(s[12], 43);
|
||||
s[12] = ROTL64(s[13], 25);
|
||||
s[13] = ROTL64(s[19], 8);
|
||||
s[19] = ROTL64(s[23], 56);
|
||||
s[23] = ROTL64(s[15], 41);
|
||||
s[15] = ROTL64(s[ 4], 27);
|
||||
s[ 4] = ROTL64(s[24], 14);
|
||||
s[24] = ROTL64(s[21], 2);
|
||||
s[21] = ROTL64(s[ 8], 55);
|
||||
s[ 8] = ROTL64(s[16], 45);
|
||||
s[16] = ROTL64(s[ 5], 36);
|
||||
s[ 5] = ROTL64(s[ 3], 28);
|
||||
s[ 3] = ROTL64(s[18], 21);
|
||||
s[18] = ROTL64(s[17], 15);
|
||||
s[17] = ROTL64(s[11], 10);
|
||||
s[11] = ROTL64(s[ 7], 6);
|
||||
s[ 7] = ROTL64(s[10], 3);
|
||||
s[10] = ROTL64( v, 1);
|
||||
|
||||
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
|
||||
v = s[ 0]; w = s[ 1]; s[ 0] ^= (~w) & s[ 2]; s[ 1] ^= (~s[ 2]) & s[ 3]; s[ 2] ^= (~s[ 3]) & s[ 4]; s[ 3] ^= (~s[ 4]) & v; s[ 4] ^= (~v) & w;
|
||||
v = s[ 5]; w = s[ 6]; s[ 5] ^= (~w) & s[ 7]; s[ 6] ^= (~s[ 7]) & s[ 8]; s[ 7] ^= (~s[ 8]) & s[ 9]; s[ 8] ^= (~s[ 9]) & v; s[ 9] ^= (~v) & w;
|
||||
v = s[10]; w = s[11]; s[10] ^= (~w) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & v; s[14] ^= (~v) & w;
|
||||
v = s[15]; w = s[16]; s[15] ^= (~w) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & v; s[19] ^= (~v) & w;
|
||||
v = s[20]; w = s[21]; s[20] ^= (~w) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & v; s[24] ^= (~v) & w;
|
||||
|
||||
/* iota: a[0,0] ^= round constant */
|
||||
s[0] ^= keccak_round_constants[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
__global__ __launch_bounds__(128,5)
|
||||
void keccak256_sm3_gpu_hash_80(uint32_t threads, uint32_t startNounce, uint32_t *resNounce)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t nounce = startNounce + thread;
|
||||
|
||||
#if __CUDA_ARCH__ >= 350
|
||||
uint2 keccak_gpu_state[25];
|
||||
#pragma unroll 25
|
||||
for (int i=0; i<25; i++) {
|
||||
if (i<9) keccak_gpu_state[i] = vectorize(c_PaddedMessage80[i]);
|
||||
else keccak_gpu_state[i] = make_uint2(0, 0);
|
||||
}
|
||||
|
||||
keccak_gpu_state[9]= vectorize(c_PaddedMessage80[9]);
|
||||
keccak_gpu_state[9].y = cuda_swab32(nounce);
|
||||
keccak_gpu_state[10] = make_uint2(1, 0);
|
||||
keccak_gpu_state[16] = make_uint2(0, 0x80000000);
|
||||
|
||||
keccak_blockv35(keccak_gpu_state,keccak_round_constants);
|
||||
if (devectorize(keccak_gpu_state[3]) <= ((uint64_t*)pTarget)[3]) {resNounce[0] = nounce;}
|
||||
#else
|
||||
uint64_t keccak_gpu_state[25];
|
||||
#pragma unroll 25
|
||||
for (int i=0; i<25; i++) {
|
||||
if (i<9) keccak_gpu_state[i] = c_PaddedMessage80[i];
|
||||
else keccak_gpu_state[i] = 0;
|
||||
}
|
||||
keccak_gpu_state[9] = REPLACE_HIDWORD(c_PaddedMessage80[9], cuda_swab32(nounce));
|
||||
keccak_gpu_state[10] = 0x0000000000000001;
|
||||
keccak_gpu_state[16] = 0x8000000000000000;
|
||||
|
||||
keccak_blockv30(keccak_gpu_state, keccak_round_constants);
|
||||
if (keccak_gpu_state[3] <= ((uint64_t*)pTarget)[3]) { resNounce[0] = nounce; }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_sm3_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *resNonces, int order)
|
||||
{
|
||||
cudaMemset(d_KNonce[thr_id], 0xff, 2*sizeof(uint32_t));
|
||||
const uint32_t threadsperblock = 128;
|
||||
|
||||
dim3 grid((threads + threadsperblock-1)/threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
size_t shared_size = 0;
|
||||
|
||||
keccak256_sm3_gpu_hash_80<<<grid, block, shared_size>>>(threads, startNounce, d_KNonce[thr_id]);
|
||||
|
||||
cudaMemcpy(resNonces, d_KNonce[thr_id], 2*sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
cudaThreadSynchronize();
|
||||
}
|
||||
|
||||
#if 0
|
||||
__global__ __launch_bounds__(256,3)
|
||||
void keccak256_sm3_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *outputHash)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 350 /* tpr: to double check if faster on SM5+ */
|
||||
uint2 keccak_gpu_state[25];
|
||||
#pragma unroll 25
|
||||
for (int i = 0; i<25; i++) {
|
||||
if (i<4) keccak_gpu_state[i] = vectorize(outputHash[i*threads+thread]);
|
||||
else keccak_gpu_state[i] = make_uint2(0, 0);
|
||||
}
|
||||
keccak_gpu_state[4] = make_uint2(1, 0);
|
||||
keccak_gpu_state[16] = make_uint2(0, 0x80000000);
|
||||
keccak_blockv35(keccak_gpu_state, keccak_round_constants);
|
||||
|
||||
#pragma unroll 4
|
||||
for (int i=0; i<4; i++)
|
||||
outputHash[i*threads+thread] = devectorize(keccak_gpu_state[i]);
|
||||
#else
|
||||
uint64_t keccak_gpu_state[25];
|
||||
#pragma unroll 25
|
||||
for (int i = 0; i<25; i++) {
|
||||
if (i<4)
|
||||
keccak_gpu_state[i] = outputHash[i*threads+thread];
|
||||
else
|
||||
keccak_gpu_state[i] = 0;
|
||||
}
|
||||
keccak_gpu_state[4] = 0x0000000000000001;
|
||||
keccak_gpu_state[16] = 0x8000000000000000;
|
||||
|
||||
keccak_blockv30(keccak_gpu_state, keccak_round_constants);
|
||||
#pragma unroll 4
|
||||
for (int i = 0; i<4; i++)
|
||||
outputHash[i*threads + thread] = keccak_gpu_state[i];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_sm3_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_outputHash, int order)
|
||||
{
|
||||
const uint32_t threadsperblock = 256;
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
keccak256_sm3_gpu_hash_32 <<<grid, block>>> (threads, startNounce, d_outputHash);
|
||||
MyStreamSynchronize(NULL, order, thr_id);
|
||||
}
|
||||
#endif
|
||||
|
||||
__host__
|
||||
void keccak256_sm3_setBlock_80(void *pdata,const void *pTargetIn)
|
||||
{
|
||||
unsigned char PaddedMessage[80];
|
||||
memcpy(PaddedMessage, pdata, 80);
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(pTarget, pTargetIn, 8*sizeof(uint32_t), 0, cudaMemcpyHostToDevice));
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_PaddedMessage80, PaddedMessage, 10*sizeof(uint64_t), 0, cudaMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_sm3_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(keccak_round_constants, host_keccak_round_constants,
|
||||
sizeof(host_keccak_round_constants), 0, cudaMemcpyHostToDevice));
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_KNonce[thr_id], 2*sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_sm3_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_KNonce[thr_id]);
|
||||
}
|
||||
+357
-92
@@ -13,40 +13,296 @@ void Round512v35(uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p
|
||||
}
|
||||
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35(const uint2 *const __restrict__ ks, const uint2 *const __restrict__ ts,
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7, int R)
|
||||
void Round_8_512v35_1(const uint2 ks[9], const uint2 ts[3],
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[(R+0) % 9];
|
||||
p1 += ks[(R+1) % 9];
|
||||
p2 += ks[(R+2) % 9];
|
||||
p3 += ks[(R+3) % 9];
|
||||
p4 += ks[(R+4) % 9];
|
||||
p5 += ks[(R+5) % 9] + ts[(R+0) % 3];
|
||||
p6 += ks[(R+6) % 9] + ts[(R+1) % 3];
|
||||
p7 += ks[(R+7) % 9] + make_uint2(R, 0);
|
||||
p0 += ks[1];
|
||||
p1 += ks[2];
|
||||
p2 += ks[3];
|
||||
p3 += ks[4];
|
||||
p4 += ks[5];
|
||||
p5 += ks[6] + ts[1];
|
||||
p6 += ks[7] + ts[2];
|
||||
p7 += ks[8] + make_uint2(1, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[(R+1) % 9];
|
||||
p1 += ks[(R+2) % 9];
|
||||
p2 += ks[(R+3) % 9];
|
||||
p3 += ks[(R+4) % 9];
|
||||
p4 += ks[(R+5) % 9];
|
||||
p5 += ks[(R+6) % 9] + ts[(R+1) % 3];
|
||||
p6 += ks[(R+7) % 9] + ts[(R+2) % 3];
|
||||
p7 += ks[(R+8) % 9] + make_uint2(R+1, 0);
|
||||
p0 += ks[2];
|
||||
p1 += ks[3];
|
||||
p2 += ks[4];
|
||||
p3 += ks[5];
|
||||
p4 += ks[6];
|
||||
p5 += ks[7] + ts[2];
|
||||
p6 += ks[8] + ts[0];
|
||||
p7 += ks[0] + make_uint2(2, 0);
|
||||
}
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35_3(const uint2 ks[9], const uint2 ts[3],
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[3];
|
||||
p1 += ks[4];
|
||||
p2 += ks[5];
|
||||
p3 += ks[6];
|
||||
p4 += ks[7];
|
||||
p5 += ks[8] + ts[0];
|
||||
p6 += ks[0] + ts[1];
|
||||
p7 += ks[1] + make_uint2(3, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[4];
|
||||
p1 += ks[5];
|
||||
p2 += ks[6];
|
||||
p3 += ks[7];
|
||||
p4 += ks[8];
|
||||
p5 += ks[0] + ts[1];
|
||||
p6 += ks[1] + ts[2];
|
||||
p7 += ks[2] + make_uint2(4, 0);
|
||||
}
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35_5(const uint2 ks[9], const uint2 ts[3],
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[5];
|
||||
p1 += ks[6];
|
||||
p2 += ks[7];
|
||||
p3 += ks[8];
|
||||
p4 += ks[0];
|
||||
p5 += ks[1] + ts[2];
|
||||
p6 += ks[2] + ts[0];
|
||||
p7 += ks[3] + make_uint2(5, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[6];
|
||||
p1 += ks[7];
|
||||
p2 += ks[8];
|
||||
p3 += ks[0];
|
||||
p4 += ks[1];
|
||||
p5 += ks[2] + ts[0];
|
||||
p6 += ks[3] + ts[1];
|
||||
p7 += ks[4] + make_uint2(6, 0);
|
||||
}
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35_7(const uint2 ks[9], const uint2 ts[3],
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[7];
|
||||
p1 += ks[8];
|
||||
p2 += ks[0];
|
||||
p3 += ks[1];
|
||||
p4 += ks[2];
|
||||
p5 += ks[3] + ts[1];
|
||||
p6 += ks[4] + ts[2];
|
||||
p7 += ks[5] + make_uint2(7, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[8];
|
||||
p1 += ks[0];
|
||||
p2 += ks[1];
|
||||
p3 += ks[2];
|
||||
p4 += ks[3];
|
||||
p5 += ks[4] + ts[2];
|
||||
p6 += ks[5] + ts[0];
|
||||
p7 += ks[6] + make_uint2(8, 0);
|
||||
}
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35_9(const uint2 ks[9], const uint2 ts[3],
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[0];
|
||||
p1 += ks[1];
|
||||
p2 += ks[2];
|
||||
p3 += ks[3];
|
||||
p4 += ks[4];
|
||||
p5 += ks[5] + ts[0];
|
||||
p6 += ks[6] + ts[1];
|
||||
p7 += ks[7] + make_uint2(9, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[1];
|
||||
p1 += ks[2];
|
||||
p2 += ks[3];
|
||||
p3 += ks[4];
|
||||
p4 += ks[5];
|
||||
p5 += ks[6] + ts[1];
|
||||
p6 += ks[7] + ts[2];
|
||||
p7 += ks[8] + make_uint2(10, 0);
|
||||
}
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35_11(const uint2 ks[9], const uint2 ts[3],
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[2];
|
||||
p1 += ks[3];
|
||||
p2 += ks[4];
|
||||
p3 += ks[5];
|
||||
p4 += ks[6];
|
||||
p5 += ks[7] + ts[2];
|
||||
p6 += ks[8] + ts[0];
|
||||
p7 += ks[0] + make_uint2(11, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[3];
|
||||
p1 += ks[4];
|
||||
p2 += ks[5];
|
||||
p3 += ks[6];
|
||||
p4 += ks[7];
|
||||
p5 += ks[8] + ts[0];
|
||||
p6 += ks[0] + ts[1];
|
||||
p7 += ks[1] + make_uint2(12, 0);
|
||||
}
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35_13(const uint2 ks[9], const uint2 ts[3],
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[4];
|
||||
p1 += ks[5];
|
||||
p2 += ks[6];
|
||||
p3 += ks[7];
|
||||
p4 += ks[8];
|
||||
p5 += ks[0] + ts[1];
|
||||
p6 += ks[1] + ts[2];
|
||||
p7 += ks[2] + make_uint2(13, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[5];
|
||||
p1 += ks[6];
|
||||
p2 += ks[7];
|
||||
p3 += ks[8];
|
||||
p4 += ks[0];
|
||||
p5 += ks[1] + ts[2];
|
||||
p6 += ks[2] + ts[0];
|
||||
p7 += ks[3] + make_uint2(14, 0);
|
||||
}
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35_15(const uint2 ks[9], const uint2 ts[3],
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[6];
|
||||
p1 += ks[7];
|
||||
p2 += ks[8];
|
||||
p3 += ks[0];
|
||||
p4 += ks[1];
|
||||
p5 += ks[2] + ts[0];
|
||||
p6 += ks[3] + ts[1];
|
||||
p7 += ks[4] + make_uint2(15, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[7];
|
||||
p1 += ks[8];
|
||||
p2 += ks[0];
|
||||
p3 += ks[1];
|
||||
p4 += ks[2];
|
||||
p5 += ks[3] + ts[1];
|
||||
p6 += ks[4] + ts[2];
|
||||
p7 += ks[5] + make_uint2(16, 0);
|
||||
}
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35_17(const uint2 ks[9], const uint2 ts[3],
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[8];
|
||||
p1 += ks[0];
|
||||
p2 += ks[1];
|
||||
p3 += ks[2];
|
||||
p4 += ks[3];
|
||||
p5 += ks[4] + ts[2];
|
||||
p6 += ks[5] + ts[0];
|
||||
p7 += ks[6] + make_uint2(17, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[0];
|
||||
p1 += ks[1];
|
||||
p2 += ks[2];
|
||||
p3 += ks[3];
|
||||
p4 += ks[4];
|
||||
p5 += ks[5] + ts[0];
|
||||
p6 += ks[6] + ts[1];
|
||||
p7 += ks[7] + make_uint2(18, 0);
|
||||
}
|
||||
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35_final(const uint2 *const __restrict__ ks, const uint2 *const __restrict__ ts,
|
||||
void Round_8_512v35_final(const uint2 ks[9], const uint2 ts[3],
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
@@ -74,96 +330,88 @@ void Round_8_512v35_final(const uint2 *const __restrict__ ks, const uint2 *const
|
||||
p3 += ks[3];
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(256,3)
|
||||
void skein256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *outputHash)
|
||||
__global__ __launch_bounds__(256, 4)
|
||||
void skein256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint2 *outputHash)
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
const uint2 skein_ks_parity = { 0xA9FC1A22, 0x1BD11BDA };
|
||||
|
||||
const uint2 h2[9] = {
|
||||
{ 0x2FDB3E13, 0xCCD044A1 },
|
||||
{ 0x1A79A9EB, 0xE8359030 },
|
||||
{ 0x4F816E6F, 0x55AEA061 },
|
||||
{ 0xAE9B94DB, 0x2A2767A4 },
|
||||
{ 0x74DD7683, 0xEC06025E },
|
||||
{ 0xC4746251, 0xE7A436CD },
|
||||
{ 0x393AD185, 0xC36FBAF9 },
|
||||
{ 0x33EDFC13, 0x3EEDBA18 },
|
||||
{ 0xC73A4E2A, 0xB69D3CFC }
|
||||
};
|
||||
const uint2 t12[2][3] = {
|
||||
{ { 0x20, 0 },
|
||||
{ 0, 0xf0000000 },
|
||||
{ 0x20, 0xf0000000 } },
|
||||
{ { 0x08, 0 },
|
||||
{ 0, 0xff000000 },
|
||||
{ 0x08, 0xff000000 } }
|
||||
};
|
||||
|
||||
if (thread < threads)
|
||||
{
|
||||
const uint2 skein_ks_parity = { 0xA9FC1A22, 0x1BD11BDA };
|
||||
const uint2 t12[6] = {
|
||||
{ 0x20, 0 },
|
||||
{ 0, 0xf0000000 },
|
||||
{ 0x20, 0xf0000000 },
|
||||
{ 0x08, 0 },
|
||||
{ 0, 0xff000000 },
|
||||
{ 0x08, 0xff000000 }
|
||||
};
|
||||
|
||||
uint2 h[9] = {
|
||||
{ 0x2FDB3E13, 0xCCD044A1 },
|
||||
{ 0x1A79A9EB, 0xE8359030 },
|
||||
{ 0x4F816E6F, 0x55AEA061 },
|
||||
{ 0xAE9B94DB, 0x2A2767A4 },
|
||||
{ 0x74DD7683, 0xEC06025E },
|
||||
{ 0xC4746251, 0xE7A436CD },
|
||||
{ 0x393AD185, 0xC36FBAF9 },
|
||||
{ 0x33EDFC13, 0x3EEDBA18 },
|
||||
{ 0xC73A4E2A, 0xB69D3CFC }
|
||||
};
|
||||
uint2 dt0,dt1,dt2,dt3;
|
||||
uint2 p0, p1, p2, p3, p4, p5, p6, p7;
|
||||
|
||||
LOHI(dt0.x,dt0.y,outputHash[thread]);
|
||||
LOHI(dt1.x,dt1.y,outputHash[threads+thread]);
|
||||
LOHI(dt2.x,dt2.y,outputHash[2*threads+thread]);
|
||||
LOHI(dt3.x,dt3.y,outputHash[3*threads+thread]);
|
||||
dt0 = __ldg(&outputHash[0 * threads + thread]);
|
||||
dt1 = __ldg(&outputHash[1 * threads + thread]);
|
||||
dt2 = __ldg(&outputHash[2 * threads + thread]);
|
||||
dt3 = __ldg(&outputHash[3 * threads + thread]);
|
||||
|
||||
p0 = h[0] + dt0;
|
||||
p1 = h[1] + dt1;
|
||||
p2 = h[2] + dt2;
|
||||
p3 = h[3] + dt3;
|
||||
p4 = h[4];
|
||||
p5 = h[5] + t12[0];
|
||||
p6 = h[6] + t12[1];
|
||||
p7 = h[7];
|
||||
p0 = h2[0] + dt0;
|
||||
p1 = h2[1] + dt1;
|
||||
p2 = h2[2] + dt2;
|
||||
p3 = h2[3] + dt3;
|
||||
p4 = h2[4];
|
||||
p5 = h2[5] + t12[0][0];
|
||||
p6 = h2[6] + t12[0][1];
|
||||
p7 = h2[7];
|
||||
|
||||
// forced unroll required
|
||||
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 1);
|
||||
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 3);
|
||||
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 5);
|
||||
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 7);
|
||||
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 9);
|
||||
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 11);
|
||||
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 13);
|
||||
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 15);
|
||||
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 17);
|
||||
Round_8_512v35_1(h2, t12[0], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_3(h2, t12[0], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_5(h2, t12[0], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_7(h2, t12[0], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_9(h2, t12[0], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_11(h2, t12[0], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_13(h2, t12[0], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_15(h2, t12[0], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_17(h2, t12[0], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
|
||||
p0 ^= dt0;
|
||||
p1 ^= dt1;
|
||||
p2 ^= dt2;
|
||||
p3 ^= dt3;
|
||||
|
||||
h[0] = p0;
|
||||
h[1] = p1;
|
||||
h[2] = p2;
|
||||
h[3] = p3;
|
||||
h[4] = p4;
|
||||
h[5] = p5;
|
||||
h[6] = p6;
|
||||
h[7] = p7;
|
||||
h[8] = skein_ks_parity ^ h[0] ^ h[1] ^ h[2] ^ h[3] ^ h[4] ^ h[5] ^ h[6] ^ h[7];
|
||||
const uint2 h[9] = { p0, p1, p2, p3, p4, p5, p6, p7, skein_ks_parity ^ h[0] ^ h[1] ^ h[2] ^ h[3] ^ h[4] ^ h[5] ^ h[6] ^ h[7] };
|
||||
|
||||
const uint2 *t = t12+3;
|
||||
p5 += t12[3]; //p5 already equal h[5]
|
||||
p6 += t12[4];
|
||||
p5 += t12[1][0]; //p5 already equal h[5]
|
||||
p6 += t12[1][1];
|
||||
|
||||
// forced unroll
|
||||
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 1);
|
||||
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 3);
|
||||
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 5);
|
||||
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 7);
|
||||
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 9);
|
||||
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 11);
|
||||
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 13);
|
||||
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 15);
|
||||
Round_8_512v35_final(h, t, p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_1(h, t12[1], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_3(h, t12[1], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_5(h, t12[1], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_7(h, t12[1], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_9(h, t12[1], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_11(h, t12[1], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_13(h, t12[1], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_15(h, t12[1], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
Round_8_512v35_final(h, t12[1], p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
|
||||
outputHash[thread] = devectorize(p0);
|
||||
outputHash[threads+thread] = devectorize(p1);
|
||||
outputHash[2*threads+thread] = devectorize(p2);
|
||||
outputHash[3*threads+thread] = devectorize(p3);
|
||||
outputHash[0 * threads + thread] = p0;
|
||||
outputHash[1 * threads + thread] = p1;
|
||||
outputHash[2 * threads + thread] = p2;
|
||||
outputHash[3 * threads + thread] = p3;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,10 +552,27 @@ void skein256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, ui
|
||||
|
||||
// only 1kH/s perf change between kernels on a 960...
|
||||
if (device_sm[dev_id] > 300 && cuda_arch[dev_id] > 300)
|
||||
skein256_gpu_hash_32<<<grid, block>>>(threads, startNounce, d_outputHash);
|
||||
skein256_gpu_hash_32 << <grid, block >> >(threads, startNounce, (uint2*)d_outputHash);
|
||||
else
|
||||
skein256_gpu_hash_32_v30<<<grid, block>>>(threads, startNounce, d_outputHash);
|
||||
skein256_gpu_hash_32_v30 << <grid, block >> >(threads, startNounce, d_outputHash);
|
||||
|
||||
MyStreamSynchronize(NULL, order, thr_id);
|
||||
//MyStreamSynchronize(NULL, order, thr_id);
|
||||
}
|
||||
|
||||
__host__
|
||||
void skein256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_outputHash, int order, cudaStream_t stream)
|
||||
{
|
||||
const uint32_t threadsperblock = 256;
|
||||
int dev_id = device_map[thr_id];
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
// only 1kH/s perf change between kernels on a 960...
|
||||
if (device_sm[dev_id] > 300 && cuda_arch[dev_id] > 300)
|
||||
skein256_gpu_hash_32 << <grid, block, 0, stream >> >(threads, startNounce, (uint2*)d_outputHash);
|
||||
else
|
||||
skein256_gpu_hash_32_v30 << <grid, block,0, stream >> >(threads, startNounce, d_outputHash);
|
||||
|
||||
//MyStreamSynchronize(NULL, order, thr_id);
|
||||
}
|
||||
+325
-331
@@ -1,11 +1,14 @@
|
||||
/**
|
||||
* Blake-256 Decred 180-Bytes input Cuda Kernel
|
||||
* Blake-256 Decred 180-Bytes input Cuda Kernel (Tested on SM 5/5.2)
|
||||
*
|
||||
* Tanguy Pruvot, Alexis Provos - Feb/Sep 2016
|
||||
* Tanguy Pruvot - Feb 2016
|
||||
*
|
||||
* Revised for optimisation by pallas @ bitcointalk - Apr 2016
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include <miner.h>
|
||||
|
||||
extern "C" {
|
||||
@@ -13,10 +16,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
/* threads per block */
|
||||
#define TPB 640
|
||||
|
||||
/* max count of found nonces in one call (like sgminer) */
|
||||
#define MAX_RESULTS 4
|
||||
#define TPB 512
|
||||
/* nonces per round */
|
||||
#define NPR 128
|
||||
|
||||
/* hash by cpu with blake 256 */
|
||||
extern "C" void decred_hash(void *output, const void *input)
|
||||
@@ -34,142 +36,255 @@ extern "C" void decred_hash(void *output, const void *input)
|
||||
|
||||
#ifdef __INTELLISENSE__
|
||||
#define __byte_perm(x, y, b) x
|
||||
#define atomicInc(p, max) (*p)++
|
||||
#endif
|
||||
|
||||
__constant__ uint32_t _ALIGN(16) c_h[2];
|
||||
__constant__ uint32_t _ALIGN(16) c_data[32];
|
||||
__constant__ uint32_t _ALIGN(16) c_xors[215];
|
||||
__constant__ uint32_t _ALIGN(4) d_data[24];
|
||||
|
||||
/* Buffers of candidate nonce(s) */
|
||||
/* 16 adapters max */
|
||||
static uint32_t *d_resNonce[MAX_GPUS];
|
||||
static uint32_t *h_resNonce[MAX_GPUS];
|
||||
|
||||
#define ROR8(a) __byte_perm(a, 0, 0x0321)
|
||||
#define ROL16(a) __byte_perm(a, 0, 0x1032)
|
||||
/* max count of found nonces in one call */
|
||||
#define NBN 2
|
||||
#if NBN > 1
|
||||
static uint32_t extra_results[NBN] = { UINT32_MAX };
|
||||
#endif
|
||||
|
||||
/* macro bodies */
|
||||
#define pxorGS(a,b,c,d) { \
|
||||
v[a]+= c_xors[i++] + v[b]; \
|
||||
v[d] = ROL16(v[d] ^ v[a]); \
|
||||
v[c]+= v[d]; \
|
||||
v[b] = ROTR32(v[b] ^ v[c], 12); \
|
||||
v[a]+= c_xors[i++] + v[b]; \
|
||||
v[d] = ROR8(v[d] ^ v[a]); \
|
||||
v[c]+= v[d]; \
|
||||
v[b] = ROTR32(v[b] ^ v[c], 7); \
|
||||
|
||||
/* ############################################################################################################################### */
|
||||
|
||||
#define GSPREC(a,b,c,d,x,y) { \
|
||||
v[a] += (m[x] ^ c_u256[y]) + v[b]; \
|
||||
v[d] = __byte_perm(v[d] ^ v[a], 0, 0x1032); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 12); \
|
||||
v[a] += (m[y] ^ c_u256[x]) + v[b]; \
|
||||
v[d] = __byte_perm(v[d] ^ v[a], 0, 0x0321); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 7); \
|
||||
}
|
||||
|
||||
#define pxorGS2(a,b,c,d, a1,b1,c1,d1) {\
|
||||
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
|
||||
v[ d] = ROL16(v[ d] ^ v[ a]); v[d1] = ROL16(v[d1] ^ v[a1]); \
|
||||
v[ c]+= v[ d]; v[c1]+= v[d1]; \
|
||||
v[ b] = ROTR32(v[ b] ^ v[ c], 12); v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
|
||||
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
|
||||
v[ d] = ROR8(v[ d] ^ v[ a]); v[d1] = ROR8(v[d1] ^ v[a1]); \
|
||||
v[ c]+= v[ d]; v[c1]+= v[d1]; \
|
||||
v[ b] = ROTR32(v[ b] ^ v[ c], 7); v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
|
||||
|
||||
#define GSPREC4(a0,b0,c0,d0,x0,y0,a1,b1,c1,d1,x1,y1,a2,b2,c2,d2,x2,y2,a3,b3,c3,d3,x3,y3) { \
|
||||
v[a0] += (m[x0] ^ c_u256[y0]) + v[b0]; \
|
||||
v[a1] += (m[x1] ^ c_u256[y1]) + v[b1]; \
|
||||
v[a2] += (m[x2] ^ c_u256[y2]) + v[b2]; \
|
||||
v[a3] += (m[x3] ^ c_u256[y3]) + v[b3]; \
|
||||
v[d0] = __byte_perm(v[d0] ^ v[a0], 0, 0x1032); \
|
||||
v[d1] = __byte_perm(v[d1] ^ v[a1], 0, 0x1032); \
|
||||
v[d2] = __byte_perm(v[d2] ^ v[a2], 0, 0x1032); \
|
||||
v[d3] = __byte_perm(v[d3] ^ v[a3], 0, 0x1032); \
|
||||
v[c0] += v[d0]; \
|
||||
v[c1] += v[d1]; \
|
||||
v[c2] += v[d2]; \
|
||||
v[c3] += v[d3]; \
|
||||
v[b0] = SPH_ROTR32(v[b0] ^ v[c0], 12); \
|
||||
v[b1] = SPH_ROTR32(v[b1] ^ v[c1], 12); \
|
||||
v[b2] = SPH_ROTR32(v[b2] ^ v[c2], 12); \
|
||||
v[b3] = SPH_ROTR32(v[b3] ^ v[c3], 12); \
|
||||
v[a0] += (m[y0] ^ c_u256[x0]) + v[b0]; \
|
||||
v[a1] += (m[y1] ^ c_u256[x1]) + v[b1]; \
|
||||
v[a2] += (m[y2] ^ c_u256[x2]) + v[b2]; \
|
||||
v[a3] += (m[y3] ^ c_u256[x3]) + v[b3]; \
|
||||
v[d0] = __byte_perm(v[d0] ^ v[a0], 0, 0x0321); \
|
||||
v[d1] = __byte_perm(v[d1] ^ v[a1], 0, 0x0321); \
|
||||
v[d2] = __byte_perm(v[d2] ^ v[a2], 0, 0x0321); \
|
||||
v[d3] = __byte_perm(v[d3] ^ v[a3], 0, 0x0321); \
|
||||
v[c0] += v[d0]; \
|
||||
v[c1] += v[d1]; \
|
||||
v[c2] += v[d2]; \
|
||||
v[c3] += v[d3]; \
|
||||
v[b0] = SPH_ROTR32(v[b0] ^ v[c0], 7); \
|
||||
v[b1] = SPH_ROTR32(v[b1] ^ v[c1], 7); \
|
||||
v[b2] = SPH_ROTR32(v[b2] ^ v[c2], 7); \
|
||||
v[b3] = SPH_ROTR32(v[b3] ^ v[c3], 7); \
|
||||
}
|
||||
|
||||
#define pxory1GS2(a,b,c,d, a1,b1,c1,d1) { \
|
||||
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
|
||||
v[ d] = ROL16(v[ d] ^ v[ a]); v[d1] = ROL16(v[d1] ^ v[a1]); \
|
||||
v[ c]+= v[ d]; v[c1]+= v[d1]; \
|
||||
v[ b] = ROTR32(v[ b] ^ v[ c], 12); v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
|
||||
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= (c_xors[i++]^nonce) + v[b1]; \
|
||||
v[ d] = ROR8(v[ d] ^ v[ a]); v[d1] = ROR8(v[d1] ^ v[a1]); \
|
||||
v[ c]+= v[ d]; v[c1]+= v[d1]; \
|
||||
v[ b] = ROTR32(v[ b] ^ v[ c], 7); v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
|
||||
}
|
||||
|
||||
#define pxory0GS2(a,b,c,d, a1,b1,c1,d1) { \
|
||||
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
|
||||
v[ d] = ROL16(v[ d] ^ v[ a]); v[d1] = ROL16(v[d1] ^ v[a1]); \
|
||||
v[ c]+= v[ d]; v[c1]+= v[d1]; \
|
||||
v[ b] = ROTR32(v[ b] ^ v[ c], 12); v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
|
||||
v[ a]+= (c_xors[i++]^nonce) + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
|
||||
v[ d] = ROR8(v[ d] ^ v[ a]); v[d1] = ROR8(v[d1] ^ v[a1]); \
|
||||
v[ c]+= v[ d]; v[c1]+= v[d1]; \
|
||||
v[ b] = ROTR32(v[ b] ^ v[ c], 7); v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
|
||||
}
|
||||
static const __constant__ uint32_t c_u256[16] = {
|
||||
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
|
||||
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
|
||||
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
|
||||
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917
|
||||
};
|
||||
|
||||
#define pxorx1GS2(a,b,c,d, a1,b1,c1,d1) { \
|
||||
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= (c_xors[i++]^nonce) + v[b1]; \
|
||||
v[ d] = ROL16(v[ d] ^ v[ a]); v[d1] = ROL16(v[d1] ^ v[a1]); \
|
||||
v[ c]+= v[ d]; v[c1]+= v[d1]; \
|
||||
v[ b] = ROTR32(v[ b] ^ v[ c], 12); v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
|
||||
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
|
||||
v[ d] = ROR8(v[ d] ^ v[ a]); v[d1] = ROR8(v[d1] ^ v[a1]); \
|
||||
v[ c]+= v[ d]; v[c1]+= v[d1]; \
|
||||
v[ b] = ROTR32(v[ b] ^ v[ c], 7); v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
|
||||
}
|
||||
|
||||
#define pxorx0GS2(a,b,c,d, a1,b1,c1,d1) { \
|
||||
v[ a]+= (c_xors[i++]^nonce) + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
|
||||
v[ d] = ROL16(v[ d] ^ v[ a]); v[d1] = ROL16(v[d1] ^ v[a1]); \
|
||||
v[ c]+= v[ d]; v[c1]+= v[d1]; \
|
||||
v[ b] = ROTR32(v[ b] ^ v[ c], 12); v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
|
||||
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
|
||||
v[ d] = ROR8(v[ d] ^ v[ a]); v[d1] = ROR8(v[d1] ^ v[a1]); \
|
||||
v[ c]+= v[ d]; v[c1]+= v[d1]; \
|
||||
v[ b] = ROTR32(v[ b] ^ v[ c], 7); v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(TPB,1)
|
||||
void decred_gpu_hash_nonce(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce, const uint32_t highTarget)
|
||||
__device__ __forceinline__
|
||||
uint32_t blake256_compress_14(uint32_t *m, uint32_t *v_init, uint32_t d_data6, uint32_t d_data7)
|
||||
{
|
||||
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
uint32_t v[16];
|
||||
|
||||
if (thread < threads)
|
||||
#pragma unroll
|
||||
for (uint32_t i = 0; i < 16; i++) v[i] = v_init[i];
|
||||
// these two are not modified:
|
||||
v[ 9] = 0x85A308D3;
|
||||
v[13] = 0x299F31D0 ^ (180U*8U);
|
||||
|
||||
// round 1 with nonce
|
||||
GSPREC(1, 5, 0x9, 0xD, 2, 3);
|
||||
GSPREC(0, 5, 0xA, 0xF, 8, 9);
|
||||
GSPREC(1, 6, 0xB, 0xC, 10, 11);
|
||||
GSPREC(2, 7, 0x8, 0xD, 12, 13);
|
||||
GSPREC(3, 4, 0x9, 0xE, 14, 15);
|
||||
// round 2
|
||||
GSPREC4(0, 4, 0x8, 0xC, 14, 10, 1, 5, 0x9, 0xD, 4, 8, 2, 6, 0xA, 0xE, 9, 15, 3, 7, 0xB, 0xF, 13, 6);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 1, 12, 1, 6, 0xB, 0xC, 0, 2, 2, 7, 0x8, 0xD, 11, 7, 3, 4, 0x9, 0xE, 5, 3);
|
||||
// round 3
|
||||
GSPREC4(0, 4, 0x8, 0xC, 11, 8, 1, 5, 0x9, 0xD, 12, 0, 2, 6, 0xA, 0xE, 5, 2, 3, 7, 0xB, 0xF, 15, 13);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 10, 14, 1, 6, 0xB, 0xC, 3, 6, 2, 7, 0x8, 0xD, 7, 1, 3, 4, 0x9, 0xE, 9, 4);
|
||||
// round 4
|
||||
GSPREC4(0, 4, 0x8, 0xC, 7, 9, 1, 5, 0x9, 0xD, 3, 1, 2, 6, 0xA, 0xE, 13, 12, 3, 7, 0xB, 0xF, 11, 14);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 2, 6, 1, 6, 0xB, 0xC, 5, 10, 2, 7, 0x8, 0xD, 4, 0, 3, 4, 0x9, 0xE, 15, 8);
|
||||
// round 5
|
||||
GSPREC4(0, 4, 0x8, 0xC, 9, 0, 1, 5, 0x9, 0xD, 5, 7, 2, 6, 0xA, 0xE, 2, 4, 3, 7, 0xB, 0xF, 10, 15);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 14, 1, 1, 6, 0xB, 0xC, 11, 12, 2, 7, 0x8, 0xD, 6, 8, 3, 4, 0x9, 0xE, 3, 13);
|
||||
// round 6
|
||||
GSPREC4(0, 4, 0x8, 0xC, 2, 12, 1, 5, 0x9, 0xD, 6, 10, 2, 6, 0xA, 0xE, 0, 11, 3, 7, 0xB, 0xF, 8, 3);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 4, 13, 1, 6, 0xB, 0xC, 7, 5, 2, 7, 0x8, 0xD, 15,14, 3, 4, 0x9, 0xE, 1, 9);
|
||||
// round 7
|
||||
GSPREC4(0, 4, 0x8, 0xC, 12, 5, 1, 5, 0x9, 0xD, 1, 15, 2, 6, 0xA, 0xE, 14,13, 3, 7, 0xB, 0xF, 4, 10);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 0, 7, 1, 6, 0xB, 0xC, 6, 3, 2, 7, 0x8, 0xD, 9, 2, 3, 4, 0x9, 0xE, 8, 11);
|
||||
#ifdef FULL_4WAY
|
||||
// round 8
|
||||
GSPREC4(0, 4, 0x8, 0xC, 13,11, 1, 5, 0x9, 0xD, 7, 14, 2, 6, 0xA, 0xE, 12, 1, 3, 7, 0xB, 0xF, 3, 9);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 5, 0, 1, 6, 0xB, 0xC, 15, 4, 2, 7, 0x8, 0xD, 8, 6, 3, 4, 0x9, 0xE, 2, 10);
|
||||
// round 9
|
||||
GSPREC4(0, 4, 0x8, 0xC, 6, 15, 1, 5, 0x9, 0xD, 14, 9, 2, 6, 0xA, 0xE, 11, 3, 3, 7, 0xB, 0xF, 0, 8);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 12, 2, 1, 6, 0xB, 0xC, 13, 7, 2, 7, 0x8, 0xD, 1, 4, 3, 4, 0x9, 0xE, 10, 5);
|
||||
// round 10
|
||||
GSPREC4(0, 4, 0x8, 0xC, 10, 2, 1, 5, 0x9, 0xD, 8, 4, 2, 6, 0xA, 0xE, 7, 6, 3, 7, 0xB, 0xF, 1, 5);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 15,11, 1, 6, 0xB, 0xC, 9, 14, 2, 7, 0x8, 0xD, 3, 12, 3, 4, 0x9, 0xE, 13, 0);
|
||||
// round 11
|
||||
GSPREC4(0, 4, 0x8, 0xC, 0, 1, 1, 5, 0x9, 0xD, 2, 3, 2, 6, 0xA, 0xE, 4, 5, 3, 7, 0xB, 0xF, 6, 7);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 8, 9, 1, 6, 0xB, 0xC, 10,11, 2, 7, 0x8, 0xD, 12,13, 3, 4, 0x9, 0xE, 14,15);
|
||||
// round 12
|
||||
GSPREC4(0, 4, 0x8, 0xC, 14,10, 1, 5, 0x9, 0xD, 4, 8, 2, 6, 0xA, 0xE, 9, 15, 3, 7, 0xB, 0xF, 13, 6);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 1, 12, 1, 6, 0xB, 0xC, 0, 2, 2, 7, 0x8, 0xD, 11, 7, 3, 4, 0x9, 0xE, 5, 3);
|
||||
// round 13
|
||||
GSPREC4(0, 4, 0x8, 0xC, 11, 8, 1, 5, 0x9, 0xD, 12, 0, 2, 6, 0xA, 0xE, 5, 2, 3, 7, 0xB, 0xF, 15,13);
|
||||
GSPREC4(0, 5, 0xA, 0xF, 10,14, 1, 6, 0xB, 0xC, 3, 6, 2, 7, 0x8, 0xD, 7, 1, 3, 4, 0x9, 0xE, 9, 4);
|
||||
#else
|
||||
// round 8
|
||||
GSPREC(0, 4, 0x8, 0xC, 13,11);
|
||||
GSPREC(1, 5, 0x9, 0xD, 7, 14);
|
||||
GSPREC(2, 6, 0xA, 0xE, 12, 1);
|
||||
GSPREC(3, 7, 0xB, 0xF, 3, 9);
|
||||
GSPREC(0, 5, 0xA, 0xF, 5, 0);
|
||||
GSPREC(1, 6, 0xB, 0xC, 15, 4);
|
||||
GSPREC(2, 7, 0x8, 0xD, 8, 6);
|
||||
GSPREC(3, 4, 0x9, 0xE, 2, 10);
|
||||
// round 9
|
||||
GSPREC(0, 4, 0x8, 0xC, 6, 15);
|
||||
GSPREC(1, 5, 0x9, 0xD, 14, 9);
|
||||
GSPREC(2, 6, 0xA, 0xE, 11, 3);
|
||||
GSPREC(3, 7, 0xB, 0xF, 0, 8);
|
||||
GSPREC(0, 5, 0xA, 0xF, 12, 2);
|
||||
GSPREC(1, 6, 0xB, 0xC, 13, 7);
|
||||
GSPREC(2, 7, 0x8, 0xD, 1, 4);
|
||||
GSPREC(3, 4, 0x9, 0xE, 10, 5);
|
||||
// round 10
|
||||
GSPREC(0, 4, 0x8, 0xC, 10, 2);
|
||||
GSPREC(1, 5, 0x9, 0xD, 8, 4);
|
||||
GSPREC(2, 6, 0xA, 0xE, 7, 6);
|
||||
GSPREC(3, 7, 0xB, 0xF, 1, 5);
|
||||
GSPREC(0, 5, 0xA, 0xF, 15,11);
|
||||
GSPREC(1, 6, 0xB, 0xC, 9, 14);
|
||||
GSPREC(2, 7, 0x8, 0xD, 3, 12);
|
||||
GSPREC(3, 4, 0x9, 0xE, 13, 0);
|
||||
// round 11
|
||||
GSPREC(0, 4, 0x8, 0xC, 0, 1);
|
||||
GSPREC(1, 5, 0x9, 0xD, 2, 3);
|
||||
GSPREC(2, 6, 0xA, 0xE, 4, 5);
|
||||
GSPREC(3, 7, 0xB, 0xF, 6, 7);
|
||||
GSPREC(0, 5, 0xA, 0xF, 8, 9);
|
||||
GSPREC(1, 6, 0xB, 0xC, 10,11);
|
||||
GSPREC(2, 7, 0x8, 0xD, 12,13);
|
||||
GSPREC(3, 4, 0x9, 0xE, 14,15);
|
||||
// round 12
|
||||
GSPREC(0, 4, 0x8, 0xC, 14,10);
|
||||
GSPREC(1, 5, 0x9, 0xD, 4, 8);
|
||||
GSPREC(2, 6, 0xA, 0xE, 9, 15);
|
||||
GSPREC(3, 7, 0xB, 0xF, 13, 6);
|
||||
GSPREC(0, 5, 0xA, 0xF, 1, 12);
|
||||
GSPREC(1, 6, 0xB, 0xC, 0, 2);
|
||||
GSPREC(2, 7, 0x8, 0xD, 11, 7);
|
||||
GSPREC(3, 4, 0x9, 0xE, 5, 3);
|
||||
// round 13
|
||||
GSPREC(0, 4, 0x8, 0xC, 11, 8);
|
||||
GSPREC(1, 5, 0x9, 0xD, 12, 0);
|
||||
GSPREC(2, 6, 0xA, 0xE, 5, 2);
|
||||
GSPREC(3, 7, 0xB, 0xF, 15,13);
|
||||
GSPREC(0, 5, 0xA, 0xF, 10,14);
|
||||
GSPREC(1, 6, 0xB, 0xC, 3, 6);
|
||||
GSPREC(2, 7, 0x8, 0xD, 7, 1);
|
||||
GSPREC(3, 4, 0x9, 0xE, 9, 4);
|
||||
#endif
|
||||
// round 14
|
||||
GSPREC(0, 4, 0x8, 0xC, 7, 9);
|
||||
GSPREC(1, 5, 0x9, 0xD, 3, 1);
|
||||
GSPREC(2, 6, 0xA, 0xE, 13,12);
|
||||
GSPREC(3, 7, 0xB, 0xF, 11,14);
|
||||
GSPREC(0, 5, 0xA, 0xF, 2, 6);
|
||||
GSPREC(2, 7, 0x8, 0xD, 4, 0);
|
||||
|
||||
if ((d_data7 ^ v[7] ^ v[15]) == 0) {
|
||||
GSPREC(1, 6, 0xB, 0xC, 5, 10);
|
||||
GSPREC(3, 4, 0x9, 0xE, 15, 8);
|
||||
return (d_data6 ^ v[6] ^ v[14]);
|
||||
}
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
|
||||
/* ############################################################################################################################### */
|
||||
|
||||
// ------ Close: Last 52/64 bytes ------
|
||||
__global__
|
||||
void blake256_gpu_hash_nonce(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce, const uint64_t highTarget)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
// if (thread < threads)
|
||||
{
|
||||
uint32_t v[16];
|
||||
const uint32_t nonce = startNonce + thread * NPR;
|
||||
uint32_t m[16], v[16], temp;
|
||||
const uint32_t d_data6 = d_data[6], d_data7 = d_data[7];
|
||||
|
||||
#pragma unroll
|
||||
for(int i=0; i<16; i+=4) {
|
||||
*(uint4*)&v[i] = *(uint4*)&c_data[i];
|
||||
}
|
||||
for(int i = 0; i < 8; i++) v[i] = d_data[i];
|
||||
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
v[ 1]+= (nonce ^ 0x13198A2E);
|
||||
v[13] = ROR8(v[13] ^ v[1]);
|
||||
v[ 9]+= v[13];
|
||||
v[ 5] = ROTR32(v[5] ^ v[9], 7);
|
||||
#pragma unroll
|
||||
for (uint32_t i = 0; i < 16; i++) m[i] = d_data[i+8U];
|
||||
|
||||
int i = 0;
|
||||
v[ 1]+= c_xors[i++];// + v[ 6];
|
||||
v[ 0]+= v[5];
|
||||
v[12] = ROL16(v[12] ^ v[ 1]); v[15] = ROL16(v[15] ^ v[ 0]);
|
||||
v[11]+= v[12]; v[10]+= v[15];
|
||||
v[ 6] = ROTR32(v[ 6] ^ v[11], 12); v[ 5] = ROTR32(v[5] ^ v[10], 12);
|
||||
v[ 1]+= c_xors[i++] + v[ 6]; v[ 0]+= c_xors[i++] + v[ 5];
|
||||
v[12] = ROR8(v[12] ^ v[ 1]); v[15] = ROR8(v[15] ^ v[ 0]);
|
||||
v[11]+= v[12]; v[10]+= v[15];
|
||||
v[ 6] = ROTR32(v[ 6] ^ v[11], 7); v[ 5] = ROTR32(v[ 5] ^ v[10], 7);
|
||||
v[ 8] = 0x243F6A88;
|
||||
v[ 9] = 0x85A308D3;
|
||||
v[10] = 0x13198A2E;
|
||||
v[11] = 0x03707344;
|
||||
|
||||
pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxory1GS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorx1GS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorx1GS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorx1GS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxory1GS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxory1GS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorx1GS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxory0GS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorx0GS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxory1GS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxory1GS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorx1GS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
|
||||
pxorx1GS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS( 2, 7, 8, 13);
|
||||
v[12] = 0xA4093822 ^ (180U*8U);
|
||||
v[13] = 0x299F31D0 ^ (180U*8U);
|
||||
v[14] = 0x082EFA98;
|
||||
v[15] = 0xEC4E6C89;
|
||||
|
||||
if ((c_h[1]^v[15]) == v[7]) {
|
||||
v[ 3] += c_xors[i++] + v[4];
|
||||
v[14] = ROL16(v[14] ^ v[3]);
|
||||
v[ 9] += v[14];
|
||||
v[ 4] = ROTR32(v[4] ^ v[9], 12);
|
||||
v[ 3] += c_xors[i++] + v[4];
|
||||
v[14] = ROR8(v[14] ^ v[3]);
|
||||
if(cuda_swab32((c_h[0]^v[6]^v[14])) <= highTarget) {
|
||||
uint32_t pos = atomicInc(&resNonce[0], UINT32_MAX)+1;
|
||||
resNonce[pos] = nonce;
|
||||
// round 1 without nonce
|
||||
GSPREC(0, 4, 0x8, 0xC, 0, 1);
|
||||
GSPREC(2, 6, 0xA, 0xE, 4, 5);
|
||||
GSPREC(3, 7, 0xB, 0xF, 6, 7);
|
||||
|
||||
for (m[3] = nonce; m[3] < nonce + NPR; m[3]++) {
|
||||
temp = blake256_compress_14(m, v, d_data6, d_data7);
|
||||
|
||||
if (temp != UINT32_MAX && cuda_swab32(temp) <= highTarget) {
|
||||
#if NBN == 2
|
||||
if (resNonce[0] != UINT32_MAX) resNonce[1] = m[3];
|
||||
else resNonce[0] = m[3];
|
||||
#else
|
||||
resNonce[0] = m[3];
|
||||
#endif
|
||||
// from alexis78:
|
||||
// return statement allows CUDA7.5 to :
|
||||
// 1. Store the values fetched from constant memory in registers.
|
||||
// 2. Perform more precomputations on the outside of the for loop.
|
||||
// 3. Stop the continuous fetches from the constant memory while iterating
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -177,163 +292,60 @@ void decred_gpu_hash_nonce(const uint32_t threads, const uint32_t startNonce, ui
|
||||
}
|
||||
|
||||
__host__
|
||||
void decred_cpu_setBlock_52(const uint32_t *input)
|
||||
static uint32_t decred_cpu_hash_nonce(const int thr_id, const uint32_t threads, const uint32_t startNonce, const uint64_t highTarget)
|
||||
{
|
||||
/*
|
||||
Precompute everything possible and pass it on constant memory
|
||||
*/
|
||||
const uint32_t z[16] = {
|
||||
0x243F6A88U, 0x85A308D3U, 0x13198A2EU, 0x03707344U,
|
||||
0xA4093822U, 0x299F31D0U, 0x082EFA98U, 0xEC4E6C89U,
|
||||
0x452821E6U, 0x38D01377U, 0xBE5466CFU, 0x34E90C6CU,
|
||||
0xC0AC29B7U, 0xC97C50DDU, 0x3F84D5B5U, 0xB5470917U
|
||||
};
|
||||
uint32_t result = UINT32_MAX;
|
||||
const uint32_t real_threads = threads / NPR;
|
||||
|
||||
int i=0;
|
||||
uint32_t _ALIGN(64) preXOR[215];
|
||||
uint32_t _ALIGN(64) data[16];
|
||||
uint32_t _ALIGN(64) m[16];
|
||||
uint32_t _ALIGN(64) h[ 2];
|
||||
dim3 grid((real_threads + TPB-1)/TPB);
|
||||
dim3 block(TPB);
|
||||
|
||||
/* Check error on Ctrl+C or kill to prevent segfaults on exit */
|
||||
if (cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)) != cudaSuccess)
|
||||
return result;
|
||||
|
||||
blake256_gpu_hash_nonce <<<grid, block>>> (real_threads, startNonce, d_resNonce[thr_id], highTarget);
|
||||
cudaThreadSynchronize();
|
||||
|
||||
if (cudaSuccess == cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost)) {
|
||||
result = h_resNonce[thr_id][0];
|
||||
#if NBN > 1
|
||||
for (int n=0; n < (NBN-1); n++)
|
||||
extra_results[n] = h_resNonce[thr_id][n+1];
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
__host__
|
||||
static void decred_midstate_128(uint32_t *output, const uint32_t *input)
|
||||
{
|
||||
sph_blake256_context ctx;
|
||||
|
||||
sph_blake256_set_rounds(14);
|
||||
|
||||
sph_blake256_init(&ctx);
|
||||
sph_blake256(&ctx, input, 128);
|
||||
|
||||
data[ 0] = ctx.H[0];
|
||||
data[ 1] = ctx.H[1];
|
||||
data[ 2] = ctx.H[2];
|
||||
data[ 3] = ctx.H[3];
|
||||
data[ 4] = ctx.H[4];
|
||||
data[ 5] = ctx.H[5];
|
||||
data[ 8] = ctx.H[6];
|
||||
memcpy(output, (void*)ctx.H, 32);
|
||||
}
|
||||
|
||||
data[12] = swab32(input[35]);
|
||||
data[13] = ctx.H[7];
|
||||
|
||||
__host__
|
||||
void decred_cpu_setBlock_52(uint32_t *penddata, const uint32_t *midstate, const uint32_t *ptarget)
|
||||
{
|
||||
uint32_t _ALIGN(64) data[24];
|
||||
memcpy(data, midstate, 32);
|
||||
// pre swab32
|
||||
m[ 0] = swab32(input[32]); m[ 1] = swab32(input[33]);
|
||||
m[ 2] = swab32(input[34]); m[ 3] = 0;
|
||||
m[ 4] = swab32(input[36]); m[ 5] = swab32(input[37]);
|
||||
m[ 6] = swab32(input[38]); m[ 7] = swab32(input[39]);
|
||||
m[ 8] = swab32(input[40]); m[ 9] = swab32(input[41]);
|
||||
m[10] = swab32(input[42]); m[11] = swab32(input[43]);
|
||||
m[12] = swab32(input[44]); m[13] = 0x80000001;
|
||||
m[14] = 0;
|
||||
m[15] = 0x000005a0;
|
||||
|
||||
h[ 0] = data[ 8];
|
||||
h[ 1] = data[13];
|
||||
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_h,h, 8, 0, cudaMemcpyHostToDevice));
|
||||
|
||||
data[ 0]+= (m[ 0] ^ z[1]) + data[ 4];
|
||||
data[12] = SPH_ROTR32(z[4] ^ SPH_C32(0x5A0) ^ data[ 0], 16);
|
||||
|
||||
data[ 8] = z[0]+data[12];
|
||||
data[ 4] = SPH_ROTR32(data[ 4] ^ data[ 8], 12);
|
||||
data[ 0]+= (m[ 1] ^ z[0]) + data[ 4];
|
||||
data[12] = SPH_ROTR32(data[12] ^ data[ 0],8);
|
||||
data[ 8]+= data[12];
|
||||
data[ 4] = SPH_ROTR32(data[ 4] ^ data[ 8], 7);
|
||||
|
||||
data[ 1]+= (m[ 2] ^ z[3]) + data[ 5];
|
||||
data[13] = SPH_ROTR32((z[5] ^ SPH_C32(0x5A0)) ^ data[ 1], 16);
|
||||
data[ 9] = z[1]+data[13];
|
||||
data[ 5] = SPH_ROTR32(data[ 5] ^ data[ 9], 12);
|
||||
data[ 1]+= data[ 5]; //+nonce ^ ...
|
||||
|
||||
data[ 2]+= (m[ 4] ^ z[5]) + h[ 0];
|
||||
data[14] = SPH_ROTR32(z[6] ^ data[ 2],16);
|
||||
data[10] = z[2] + data[14];
|
||||
data[ 6] = SPH_ROTR32(h[ 0] ^ data[10], 12);
|
||||
data[ 2]+= (m[ 5] ^ z[4]) + data[ 6];
|
||||
data[14] = SPH_ROTR32(data[14] ^ data[ 2], 8);
|
||||
data[10]+= data[14];
|
||||
data[ 6] = SPH_ROTR32(data[ 6] ^ data[10], 7);
|
||||
|
||||
data[ 3]+= (m[ 6] ^ z[7]) + h[ 1];
|
||||
data[15] = SPH_ROTR32(z[7] ^ data[ 3],16);
|
||||
data[11] = z[3] + data[15];
|
||||
data[ 7] = SPH_ROTR32(h[ 1] ^ data[11], 12);
|
||||
data[ 3]+= (m[ 7] ^ z[6]) + data[ 7];
|
||||
data[15] = SPH_ROTR32(data[15] ^ data[ 3],8);
|
||||
data[11]+= data[15];
|
||||
data[ 7] = SPH_ROTR32(data[11] ^ data[ 7], 7);
|
||||
data[ 0]+= m[ 8] ^ z[9];
|
||||
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_data, data, 64, 0, cudaMemcpyHostToDevice));
|
||||
|
||||
#define precalcXORGS(x,y) { \
|
||||
preXOR[i++]= (m[x] ^ z[y]); \
|
||||
preXOR[i++]= (m[y] ^ z[x]); \
|
||||
for (int i=0; i<13; i++)
|
||||
data[8+i] = swab32(penddata[i]);
|
||||
data[21] = 0x80000001;
|
||||
data[22] = 0;
|
||||
data[23] = 0x000005a0;
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(d_data, data, 32 + 64, 0, cudaMemcpyHostToDevice));
|
||||
}
|
||||
#define precalcXORGS2(x,y,x1,y1){\
|
||||
preXOR[i++] = (m[ x] ^ z[ y]);\
|
||||
preXOR[i++] = (m[x1] ^ z[y1]);\
|
||||
preXOR[i++] = (m[ y] ^ z[ x]);\
|
||||
preXOR[i++] = (m[y1] ^ z[x1]);\
|
||||
}
|
||||
precalcXORGS(10,11);
|
||||
preXOR[ 0]+=data[ 6];
|
||||
preXOR[i++] = (m[9] ^ z[8]);
|
||||
precalcXORGS2(12,13,14,15);
|
||||
precalcXORGS2(14,10, 4, 8);
|
||||
precalcXORGS2( 9,15,13, 6);
|
||||
precalcXORGS2( 1,12, 0, 2);
|
||||
precalcXORGS2(11, 7, 5, 3);
|
||||
precalcXORGS2(11, 8,12, 0);
|
||||
precalcXORGS2( 5, 2,15,13);
|
||||
precalcXORGS2(10,14, 3, 6);
|
||||
precalcXORGS2( 7, 1, 9, 4);
|
||||
precalcXORGS2( 7, 9, 3, 1);
|
||||
precalcXORGS2(13,12,11,14);
|
||||
precalcXORGS2( 2, 6, 5,10);
|
||||
precalcXORGS2( 4, 0,15, 8);
|
||||
precalcXORGS2( 9, 0, 5, 7);
|
||||
precalcXORGS2( 2, 4,10,15);
|
||||
precalcXORGS2(14, 1,11,12);
|
||||
precalcXORGS2( 6, 8, 3,13);
|
||||
precalcXORGS2( 2,12, 6,10);
|
||||
precalcXORGS2( 0,11, 8, 3);
|
||||
precalcXORGS2( 4,13, 7, 5);
|
||||
precalcXORGS2(15,14, 1, 9);
|
||||
precalcXORGS2(12, 5, 1,15);
|
||||
precalcXORGS2(14,13, 4,10);
|
||||
precalcXORGS2( 0, 7, 6, 3);
|
||||
precalcXORGS2( 9, 2, 8,11);
|
||||
precalcXORGS2(13,11, 7,14);
|
||||
precalcXORGS2(12, 1, 3, 9);
|
||||
precalcXORGS2( 5, 0,15, 4);
|
||||
precalcXORGS2( 8, 6, 2,10);
|
||||
precalcXORGS2( 6,15,14, 9);
|
||||
precalcXORGS2(11, 3, 0, 8);
|
||||
precalcXORGS2(12, 2,13, 7);
|
||||
precalcXORGS2( 1, 4,10, 5);
|
||||
precalcXORGS2(10, 2, 8, 4);
|
||||
precalcXORGS2( 7, 6, 1, 5);
|
||||
precalcXORGS2(15,11, 9,14);
|
||||
precalcXORGS2( 3,12,13, 0);
|
||||
precalcXORGS2( 0, 1, 2, 3);
|
||||
precalcXORGS2( 4, 5, 6, 7);
|
||||
precalcXORGS2( 8, 9,10,11);
|
||||
precalcXORGS2(12,13,14,15);
|
||||
precalcXORGS2(14,10, 4, 8);
|
||||
precalcXORGS2( 9,15,13, 6);
|
||||
precalcXORGS2( 1,12, 0, 2);
|
||||
precalcXORGS2(11, 7, 5, 3);
|
||||
precalcXORGS2(11, 8,12, 0);
|
||||
precalcXORGS2( 5, 2,15,13);
|
||||
precalcXORGS2(10,14, 3, 6);
|
||||
precalcXORGS2( 7, 1, 9, 4);
|
||||
precalcXORGS2( 7, 9, 3, 1);
|
||||
precalcXORGS2(13,12,11,14);
|
||||
precalcXORGS2( 2, 6, 5,10);
|
||||
precalcXORGS( 4, 0);
|
||||
precalcXORGS(15, 8);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_xors, preXOR, 215*sizeof(uint32_t), 0, cudaMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
/* ############################################################################################################################### */
|
||||
|
||||
@@ -345,25 +357,31 @@ static bool init[MAX_GPUS] = { 0 };
|
||||
extern "C" int scanhash_decred(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[48];
|
||||
uint32_t _ALIGN(64) midstate[8];
|
||||
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
uint32_t *pnonce = &pdata[DCR_NONCE_OFT32];
|
||||
|
||||
const uint32_t first_nonce = *pnonce;
|
||||
const uint32_t targetHigh = opt_benchmark ? 0x1ULL : ptarget[6];
|
||||
uint64_t targetHigh = ((uint64_t*)ptarget)[3];
|
||||
|
||||
const int dev_id = device_map[thr_id];
|
||||
int dev_id = device_map[thr_id];
|
||||
int intensity = (device_sm[dev_id] > 500 && !is_windows()) ? 29 : 25;
|
||||
if (device_sm[dev_id] < 350) intensity = 22;
|
||||
|
||||
uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity);
|
||||
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
const dim3 grid((throughput + TPB-1)/(TPB));
|
||||
const dim3 block(TPB);
|
||||
int rc = 0;
|
||||
|
||||
if (!init[thr_id]) {
|
||||
if (opt_benchmark) {
|
||||
targetHigh = 0x1ULL << 32;
|
||||
ptarget[6] = swab32(0xff);
|
||||
}
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(dev_id);
|
||||
if (opt_cudaschedule == -1 && gpu_threads == 1) {
|
||||
cudaDeviceReset();
|
||||
@@ -372,93 +390,68 @@ extern "C" int scanhash_decred(int thr_id, struct work* work, uint32_t max_nonce
|
||||
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
|
||||
cuda_get_arch(thr_id);
|
||||
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], MAX_RESULTS*sizeof(uint32_t)), -1);
|
||||
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], MAX_RESULTS*sizeof(uint32_t)), -1);
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
|
||||
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
|
||||
init[thr_id] = true;
|
||||
}
|
||||
memcpy(endiandata, pdata, 180);
|
||||
|
||||
decred_cpu_setBlock_52(endiandata);
|
||||
cudaMemset(d_resNonce[thr_id], 0x00, sizeof(uint32_t));
|
||||
memcpy(endiandata, pdata, 180);
|
||||
decred_midstate_128(midstate, endiandata);
|
||||
decred_cpu_setBlock_52(&pdata[32], midstate, ptarget);
|
||||
|
||||
do {
|
||||
uint32_t* resNonces = h_resNonce[thr_id];
|
||||
|
||||
if (resNonces[0]) cudaMemset(d_resNonce[thr_id], 0x00, sizeof(uint32_t));
|
||||
|
||||
// GPU HASH
|
||||
decred_gpu_hash_nonce <<<grid, block>>> (throughput, (*pnonce), d_resNonce[thr_id], targetHigh);
|
||||
uint32_t foundNonce = decred_cpu_hash_nonce(thr_id, throughput, (*pnonce), targetHigh);
|
||||
|
||||
*hashes_done = (*pnonce) - first_nonce + throughput;
|
||||
|
||||
// first cell contains the valid nonces count
|
||||
cudaMemcpy(resNonces, d_resNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
|
||||
if (resNonces[0])
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
uint32_t _ALIGN(64) vhash[8];
|
||||
uint32_t vhashcpu[8];
|
||||
uint32_t Htarg = ptarget[6];
|
||||
|
||||
cudaMemcpy(resNonces, d_resNonce[thr_id], (resNonces[0]+1)*sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
be32enc(&endiandata[DCR_NONCE_OFT32], foundNonce);
|
||||
decred_hash(vhashcpu, endiandata);
|
||||
|
||||
be32enc(&endiandata[DCR_NONCE_OFT32], resNonces[1]);
|
||||
decred_hash(vhash, endiandata);
|
||||
if (vhash[6] <= ptarget[6] && fulltest(vhash, ptarget))
|
||||
if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget))
|
||||
{
|
||||
work->valid_nonces = 1;
|
||||
work_set_target_ratio(work, vhash);
|
||||
work->nonces[0] = swab32(resNonces[1]);
|
||||
*pnonce = work->nonces[0];
|
||||
|
||||
// search for another nonce
|
||||
for(uint32_t n=2; n <= resNonces[0]; n++)
|
||||
{
|
||||
be32enc(&endiandata[DCR_NONCE_OFT32], resNonces[n]);
|
||||
decred_hash(vhash, endiandata);
|
||||
if (vhash[6] <= ptarget[6] && fulltest(vhash, ptarget)) {
|
||||
work->nonces[1] = swab32(resNonces[n]);
|
||||
if (bn_hash_target_ratio(vhash, ptarget) > work->shareratio[0]) {
|
||||
// we really want the best first ? depends...
|
||||
work->shareratio[1] = work->shareratio[0];
|
||||
work->sharediff[1] = work->sharediff[0];
|
||||
rc = 1;
|
||||
work_set_target_ratio(work, vhashcpu);
|
||||
*hashes_done = (*pnonce) - first_nonce + throughput;
|
||||
work->nonces[0] = swab32(foundNonce);
|
||||
#if NBN > 1
|
||||
if (extra_results[0] != UINT32_MAX) {
|
||||
be32enc(&endiandata[DCR_NONCE_OFT32], extra_results[0]);
|
||||
decred_hash(vhashcpu, endiandata);
|
||||
if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget)) {
|
||||
work->nonces[1] = swab32(extra_results[0]);
|
||||
if (bn_hash_target_ratio(vhashcpu, ptarget) > work->shareratio) {
|
||||
work_set_target_ratio(work, vhashcpu);
|
||||
xchg(work->nonces[1], work->nonces[0]);
|
||||
work_set_target_ratio(work, vhash);
|
||||
work->valid_nonces++;
|
||||
} else if (work->valid_nonces == 1) {
|
||||
bn_set_target_ratio(work, vhash, 1);
|
||||
work->valid_nonces++;
|
||||
}
|
||||
work->valid_nonces = 2; // MAX_NONCES submit limited to 2
|
||||
|
||||
gpulog(LOG_DEBUG, thr_id, "multiple nonces 1:%08x (%g) %u:%08x (%g)",
|
||||
work->nonces[0], work->sharediff[0], n, work->nonces[1], work->sharediff[1]);
|
||||
|
||||
} else if (vhash[6] > ptarget[6]) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result %u for %08x does not validate on CPU!", n, resNonces[n]);
|
||||
rc = 2;
|
||||
}
|
||||
extra_results[0] = UINT32_MAX;
|
||||
}
|
||||
return work->valid_nonces;
|
||||
|
||||
} else if (vhash[6] > ptarget[6]) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", resNonces[1]);
|
||||
#endif
|
||||
*pnonce = work->nonces[0];
|
||||
return rc;
|
||||
}
|
||||
else if (opt_debug) {
|
||||
applog_hash(ptarget);
|
||||
applog_compare_hash(vhashcpu, ptarget);
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
*pnonce += throughput;
|
||||
|
||||
} while (!work_restart[thr_id].restart && max_nonce > (uint64_t)throughput + (*pnonce));
|
||||
|
||||
*hashes_done = (*pnonce) - first_nonce;
|
||||
MyStreamSynchronize(NULL, 0, device_map[thr_id]);
|
||||
return 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_decred(int thr_id)
|
||||
{
|
||||
@@ -466,6 +459,7 @@ extern "C" void free_decred(int thr_id)
|
||||
return;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
|
||||
cudaFreeHost(h_resNonce[thr_id]);
|
||||
cudaFree(d_resNonce[thr_id]);
|
||||
|
||||
|
||||
+26
-87
@@ -14,18 +14,12 @@ extern "C"
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
// SM5+ cuda
|
||||
extern void keccak256_cpu_init(int thr_id);
|
||||
extern void keccak256_cpu_free(int thr_id);
|
||||
extern void keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t* resNonces, const uint2 highTarget);
|
||||
extern void keccak256_setBlock_80(uint64_t *endiandata);
|
||||
extern void keccak256_setOutput(int thr_id);
|
||||
static uint32_t *d_hash[MAX_GPUS];
|
||||
|
||||
// compat
|
||||
extern void keccak256_sm3_init(int thr_id, uint32_t threads);
|
||||
extern void keccak256_sm3_free(int thr_id);
|
||||
extern void keccak256_sm3_setBlock_80(void *pdata, const void *ptarget);
|
||||
extern void keccak256_sm3_hash_80(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t* resNonces, int order);
|
||||
extern void keccak256_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void keccak256_cpu_free(int thr_id);
|
||||
extern void keccak256_setBlock_80(void *pdata,const void *ptarget);
|
||||
extern uint32_t keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash, int order);
|
||||
|
||||
// CPU Hash
|
||||
extern "C" void keccak256_hash(void *state, const void *input)
|
||||
@@ -41,7 +35,6 @@ extern "C" void keccak256_hash(void *state, const void *input)
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
static bool use_compat_kernels[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_keccak256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
@@ -49,97 +42,45 @@ extern "C" int scanhash_keccak256(int thr_id, struct work* work, uint32_t max_no
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const int dev_id = device_map[thr_id];
|
||||
uint32_t throughput;
|
||||
uint32_t intensity = 23;
|
||||
if(!use_compat_kernels[thr_id]) {
|
||||
if (strstr(device_name[dev_id], "GTX 1070")) intensity = 25;
|
||||
if (strstr(device_name[dev_id], "GTX 1080")) intensity = 26;
|
||||
}
|
||||
throughput = cuda_default_throughput(thr_id, 1U << intensity);
|
||||
uint32_t throughput = cuda_default_throughput(thr_id, 1U << 21); // 256*256*8*4
|
||||
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (opt_benchmark)
|
||||
ptarget[7] = 0x000f;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(dev_id);
|
||||
if (opt_cudaschedule == -1 && gpu_threads == 1) {
|
||||
cudaDeviceReset();
|
||||
// reduce cpu usage
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
cuda_get_arch(thr_id);
|
||||
use_compat_kernels[thr_id] = (cuda_arch[dev_id] < 500);
|
||||
if (!init[thr_id]) {
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
if(!use_compat_kernels[thr_id]) {
|
||||
keccak256_cpu_init(thr_id);
|
||||
} else {
|
||||
// really useful ?
|
||||
keccak256_sm3_init(thr_id, throughput);
|
||||
}
|
||||
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], throughput * 64));
|
||||
keccak256_cpu_init(thr_id, throughput);
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
for (int k=0; k < 19; k++) {
|
||||
for (int k=0; k < 20; k++) {
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
}
|
||||
|
||||
const uint2 highTarget = make_uint2(ptarget[6], ptarget[7]);
|
||||
if(use_compat_kernels[thr_id])
|
||||
keccak256_sm3_setBlock_80((void*)endiandata, ptarget);
|
||||
else {
|
||||
keccak256_setBlock_80((uint64_t*)endiandata);
|
||||
keccak256_setOutput(thr_id);
|
||||
}
|
||||
|
||||
keccak256_setBlock_80((void*)endiandata, ptarget);
|
||||
do {
|
||||
int order = 0;
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
if(use_compat_kernels[thr_id])
|
||||
keccak256_sm3_hash_80(thr_id, throughput, pdata[19], work->nonces, order++);
|
||||
else {
|
||||
keccak256_cpu_hash_80(thr_id, throughput, pdata[19], work->nonces, highTarget);
|
||||
}
|
||||
|
||||
if (work->nonces[0] != UINT32_MAX && bench_algo < 0)
|
||||
uint32_t foundNonce = keccak256_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
if (foundNonce != UINT32_MAX && bench_algo < 0)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t _ALIGN(64) vhash[8];
|
||||
uint32_t _ALIGN(64) vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
keccak256_hash(vhash64, endiandata);
|
||||
|
||||
be32enc(&endiandata[19], work->nonces[0]);
|
||||
keccak256_hash(vhash, endiandata);
|
||||
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
work->valid_nonces = 1;
|
||||
work_set_target_ratio(work, vhash);
|
||||
if (!use_compat_kernels[thr_id] && work->nonces[1] != UINT32_MAX) {
|
||||
be32enc(&endiandata[19], work->nonces[1]);
|
||||
keccak256_hash(vhash, endiandata);
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
work->valid_nonces++;
|
||||
bn_set_target_ratio(work, vhash, 1);
|
||||
}
|
||||
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
|
||||
} else {
|
||||
pdata[19] = work->nonces[0] + 1;
|
||||
}
|
||||
return work->valid_nonces;
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
work_set_target_ratio(work, vhash64);
|
||||
pdata[19] = foundNonce;
|
||||
return 1;
|
||||
}
|
||||
else if (vhash[7] > Htarg) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
|
||||
pdata[19] = work->nonces[0] + 1;
|
||||
//keccak256_setOutput(thr_id);
|
||||
continue;
|
||||
else {
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,11 +105,9 @@ extern "C" void free_keccak256(int thr_id)
|
||||
|
||||
cudaThreadSynchronize();
|
||||
|
||||
if(!use_compat_kernels[thr_id])
|
||||
keccak256_cpu_free(thr_id);
|
||||
else {
|
||||
keccak256_sm3_free(thr_id);
|
||||
}
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
keccak256_cpu_free(thr_id);
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
init[thr_id] = false;
|
||||
|
||||
+16
-33
@@ -378,11 +378,6 @@ extern "C" int scanhash_vanilla(int thr_id, struct work* work, uint32_t max_nonc
|
||||
const uint32_t targetHigh = ptarget[6];
|
||||
int dev_id = device_map[thr_id];
|
||||
|
||||
int intensity = (device_sm[dev_id] > 500 && !is_windows()) ? 30 : 24;
|
||||
if (device_sm[dev_id] < 350) intensity = 22;
|
||||
uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity);
|
||||
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (!init[thr_id]) {
|
||||
cudaSetDevice(dev_id);
|
||||
if (opt_cudaschedule == -1 && gpu_threads == 1) {
|
||||
@@ -392,10 +387,6 @@ extern "C" int scanhash_vanilla(int thr_id, struct work* work, uint32_t max_nonc
|
||||
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
|
||||
cuda_get_arch(thr_id);
|
||||
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
|
||||
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
|
||||
cudaStreamCreate(&streams[thr_id]);
|
||||
@@ -411,6 +402,11 @@ extern "C" int scanhash_vanilla(int thr_id, struct work* work, uint32_t max_nonc
|
||||
|
||||
vanilla_cpu_setBlock_16(thr_id,endiandata,&pdata[16]);
|
||||
|
||||
int intensity = (device_sm[dev_id] > 500 && !is_windows()) ? 30 : 24;
|
||||
if (device_sm[dev_id] < 350) intensity = 22;
|
||||
uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity);
|
||||
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
const dim3 grid((throughput + (NPT*TPB)-1)/(NPT*TPB));
|
||||
const dim3 block(TPB);
|
||||
int rc = 0;
|
||||
@@ -418,7 +414,6 @@ extern "C" int scanhash_vanilla(int thr_id, struct work* work, uint32_t max_nonc
|
||||
do {
|
||||
vanilla_gpu_hash_16_8<<<grid,block, 0, streams[thr_id]>>>(throughput, pdata[19], d_resNonce[thr_id], targetHigh);
|
||||
cudaMemcpyAsync(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost,streams[thr_id]);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
cudaStreamSynchronize(streams[thr_id]);
|
||||
|
||||
if (h_resNonce[thr_id][0] != UINT32_MAX){
|
||||
@@ -432,43 +427,31 @@ extern "C" int scanhash_vanilla(int thr_id, struct work* work, uint32_t max_nonc
|
||||
vanillahash(vhashcpu, endiandata, blakerounds);
|
||||
|
||||
if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget)) {
|
||||
work->valid_nonces = 1;
|
||||
work->nonces[0] = h_resNonce[thr_id][0];
|
||||
rc = 1;
|
||||
work_set_target_ratio(work, vhashcpu);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
pdata[19] = h_resNonce[thr_id][0];
|
||||
#if NBN > 1
|
||||
if (h_resNonce[thr_id][1] != UINT32_MAX) {
|
||||
work->nonces[1] = h_resNonce[thr_id][1];
|
||||
be32enc(&endiandata[19], h_resNonce[thr_id][1]);
|
||||
vanillahash(vhashcpu, endiandata, blakerounds);
|
||||
if (bn_hash_target_ratio(vhashcpu, ptarget) > work->shareratio[0]) {
|
||||
pdata[21] = h_resNonce[thr_id][1];
|
||||
if (bn_hash_target_ratio(vhashcpu, ptarget) > work->shareratio) {
|
||||
work_set_target_ratio(work, vhashcpu);
|
||||
xchg(work->nonces[0], work->nonces[1]);
|
||||
xchg(pdata[19], pdata[21]);
|
||||
}
|
||||
work->valid_nonces = 2;
|
||||
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
|
||||
} else {
|
||||
pdata[19] = work->nonces[0] + 1; // cursor
|
||||
rc = 2;
|
||||
}
|
||||
#endif
|
||||
return work->valid_nonces;
|
||||
return rc;
|
||||
}
|
||||
else if (vhashcpu[6] > Htarg) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", h_resNonce[thr_id][0]);
|
||||
pdata[19] = work->nonces[0] + 1;
|
||||
continue;
|
||||
else {
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", h_resNonce[thr_id][0]);
|
||||
}
|
||||
}
|
||||
|
||||
if ((uint64_t) throughput + pdata[19] >= max_nonce) {
|
||||
pdata[19] = max_nonce;
|
||||
break;
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (!work_restart[thr_id].restart);
|
||||
} while (!work_restart[thr_id].restart && ((uint64_t)max_nonce > ((uint64_t)(pdata[19]) + (uint64_t)throughput)));
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
MyStreamSynchronize(NULL, 0, dev_id);
|
||||
|
||||
@@ -1,97 +1,42 @@
|
||||
|
||||
You can use ./build.sh to configure and build with default options.
|
||||
|
||||
It is advised to run ./autogen.sh before ./configure (autoconf and automake
|
||||
need to be installed on your system for autogen.sh to work)
|
||||
|
||||
./configure has an option named --with-cuda that allows you to specify
|
||||
where your CUDA 6.5 toolkit is installed (usually /usr/local/cuda,
|
||||
but some distros may have a different default location)
|
||||
|
||||
|
||||
** How to compile on Ubuntu (16.04 LTS)
|
||||
|
||||
First, install Cuda toolkit and nVidia Driver, and type `nvidia-smi` to check if your card is detected.
|
||||
|
||||
Install dependencies
|
||||
```sudo apt-get install libcurl4-openssl-dev libssl-dev libjansson-dev automake autotools-dev build-essential```
|
||||
|
||||
Ubuntu is now shipped with gcc 6 or 7 so please install gcc/g++ 5 and make it the default (required by the cuda toolkit)
|
||||
```
|
||||
sudo apt-get install gcc-5 g++-5
|
||||
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 1
|
||||
```
|
||||
|
||||
Then use the helper ./build.sh in ccminer source folder, edit configure.sh and the Makefile.am if required.
|
||||
```
|
||||
./build.sh
|
||||
./ccminer --version
|
||||
```
|
||||
|
||||
|
||||
** How to compile on Fedora 25 **
|
||||
|
||||
Note: You may find an alternative method via rpms :
|
||||
see https://negativo17.org/nvidia-driver/ and https://negativo17.org/repos/multimedia/
|
||||
|
||||
|
||||
# Step 1: gcc and dependencies
|
||||
dnf install gcc gcc-c++ autoconf automake
|
||||
dnf install jansson-devel openssl-devel libcurl-devel zlib-devel
|
||||
|
||||
# Step 2: nvidia drivers (Download common linux drivers from nvidia site)
|
||||
dnf install kernel-devel
|
||||
dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
|
||||
dnf check-update
|
||||
dnf install xorg-x11-drv-nvidia-cuda kmod-nvidia
|
||||
ln -s libnvidia-ml.so.1 /usr/lib64/libnvidia-ml.so
|
||||
|
||||
# Step 3: CUDA SDK (Download from nvidia the generic ".run" archive)
|
||||
# --override is required to ignore "too recent" gcc 6.3
|
||||
# --silent is required to install only the toolkit (no kmod)
|
||||
./cuda_8.0.61_375.26_linux.run --toolkit --silent --override
|
||||
nvcc --version
|
||||
|
||||
# add the nvcc binary path to the system
|
||||
ln -s /usr/local/cuda-8.0 /usr/local/cuda # (if not already made)
|
||||
echo 'export PATH=$PATH:/usr/local/cuda/bin' > /etc/profile.d/cuda.sh
|
||||
|
||||
# add the cudart library path to the system
|
||||
echo /usr/local/cuda/lib64 > /etc/ld.so.conf.d/cuda.conf
|
||||
ldconfig
|
||||
|
||||
# Step 4: Fix the toolkit incompatibility with gcc 6
|
||||
|
||||
# You need to build yourself an older GCC/G++ version, i recommend the 5.4
|
||||
# see https://gcc.gnu.org/mirrors.html
|
||||
# Note: this manual method will override the default gcc, it could be better to use a custom toolchain prefix
|
||||
|
||||
wget ftp://ftp.lip6.fr/pub/gcc/releases/gcc-5.4.0/gcc-5.4.0.tar.bz2
|
||||
dnf install libmpc-devel mpfr-devel gmp-devel
|
||||
./configure --prefix=/usr/local --enable-languages=c,c++,lto --disable-multilib
|
||||
make -j 8 && make install
|
||||
(while this step, you have the time to cook something :p)
|
||||
|
||||
# or, for previous fedora versions, edit the file /usr/local/cuda/include/host_config.h
|
||||
# and comment/delete the line 121 : #error -- unsupported GNU version! gcc versions later than 5 are not supported!
|
||||
|
||||
./build.sh
|
||||
|
||||
./ccminer -n
|
||||
|
||||
|
||||
** How to compile on macOS **
|
||||
|
||||
# Step 1: download and install CUDA Toolkit 8 or more recent
|
||||
# https://developer.nvidia.com/cuda-toolkit-archive
|
||||
|
||||
# Step 2: install Homebrew
|
||||
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
||||
|
||||
# Step 3: dependencies
|
||||
brew install pkg-config autoconf automake curl openssl llvm
|
||||
|
||||
./build.sh
|
||||
|
||||
./ccminer -n
|
||||
|
||||
|
||||
You can use ./build.sh to configure and build with default options.
|
||||
|
||||
It is advised to run ./autogen.sh before ./configure (autoconf and automake
|
||||
need to be installed on your system for autogen.sh to work)
|
||||
|
||||
./configure has an option named --with-cuda that allows you to specify
|
||||
where your CUDA 6.5 toolkit is installed (usually /usr/local/cuda,
|
||||
but some distros may have a different default location)
|
||||
|
||||
|
||||
** How to compile on Fedora 22 (2015) **
|
||||
|
||||
# Step 1: gcc and dependencies
|
||||
dnf install gcc gcc-c++ automake
|
||||
dnf install jansson-devel openssl-devel libcurl-devel zlib-devel pciutils-devel
|
||||
|
||||
# Step 2: nvidia drivers (Download common linux drivers from nvidia site)
|
||||
dnf install kernel-devel
|
||||
modprobe -r nouveau
|
||||
./NVIDIA-Linux-x86_64-346.72.run
|
||||
|
||||
# Step 3: CUDA SDK (Download from nvidia archive)
|
||||
dnf install cuda-repo-fedora20-6-5-prod-6.5-19.x86_64.rpm
|
||||
dnf install cuda-minimal-build-6-5.x86_64
|
||||
|
||||
# add the nvcc binary path to the system
|
||||
ln -s /usr/local/cuda-6.5 /usr/local/cuda
|
||||
echo 'export PATH=$PATH:/usr/local/cuda/bin' > /etc/profile.d/cuda.sh
|
||||
|
||||
# add the cudart library path to the system
|
||||
echo /usr/local/cuda/lib64 > /etc/ld.so.conf.d/cuda.conf
|
||||
ldconfig
|
||||
|
||||
# Step 4: Fix the toolkit warning with gcc 5.1
|
||||
edit the file /usr/local/cuda/include/host_config.h
|
||||
and comment/delete the line 82 : #error -- unsupported GNU version! gcc 4.9
|
||||
|
||||
./build.sh
|
||||
|
||||
./ccminer -n
|
||||
|
||||
+24
-31
@@ -30,8 +30,8 @@ extern void jackpot_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32
|
||||
|
||||
extern uint32_t cuda_check_hash_branch(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_inputHash, int order);
|
||||
|
||||
// CPU HASH JHA v8
|
||||
extern "C" void jackpothash(void *state, const void *input)
|
||||
// Original jackpothash Funktion aus einem miner Quelltext
|
||||
extern "C" unsigned int jackpothash(void *state, const void *input)
|
||||
{
|
||||
uint32_t hash[16];
|
||||
unsigned int rnd;
|
||||
@@ -71,6 +71,8 @@ extern "C" void jackpothash(void *state, const void *input)
|
||||
}
|
||||
}
|
||||
memcpy(state, hash, 32);
|
||||
|
||||
return rnd;
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
@@ -103,7 +105,6 @@ extern "C" int scanhash_jackpot(int thr_id, struct work *work, uint32_t max_nonc
|
||||
gpulog(LOG_ERR, thr_id, "Sorry, This algo is not supported by this GPU arch (SM 3.0 required)");
|
||||
proper_exit(EXIT_CODE_CUDA_ERROR);
|
||||
}
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t) 64 * throughput));
|
||||
|
||||
@@ -212,42 +213,34 @@ extern "C" int scanhash_jackpot(int thr_id, struct work *work, uint32_t max_nonc
|
||||
|
||||
CUDA_LOG_ERROR();
|
||||
|
||||
work->nonces[0] = cuda_check_hash_branch(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
|
||||
uint32_t foundNonce = cuda_check_hash_branch(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
if (work->nonces[0] != UINT32_MAX)
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t _ALIGN(64) vhash[8];
|
||||
be32enc(&endiandata[19], work->nonces[0]);
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
|
||||
// jackpothash function gibt die Zahl der Runden zurück
|
||||
jackpothash(vhash, endiandata);
|
||||
jackpothash(vhash64, endiandata);
|
||||
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
work->valid_nonces = 1;
|
||||
work_set_target_ratio(work, vhash);
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
work_set_target_ratio(work, vhash64);
|
||||
#if 0
|
||||
work->nonces[1] = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
if (work->nonces[1] != 0) {
|
||||
be32enc(&endiandata[19], work->nonces[1]);
|
||||
jackpothash(vhash, endiandata);
|
||||
bn_set_target_ratio(work, vhash, 1);
|
||||
work->valid_nonces++;
|
||||
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
|
||||
} else {
|
||||
pdata[19] = work->nonces[0] + 1; // cursor
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
nist5hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
work_set_target_ratio(work, vhash64);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
#else
|
||||
pdata[19] = work->nonces[0] + 1; // cursor
|
||||
#endif
|
||||
return work->valid_nonces;
|
||||
}
|
||||
else if (vhash[7] > Htarg) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
|
||||
pdata[19] = work->nonces[0] + 1;
|
||||
continue;
|
||||
pdata[19] = foundNonce;
|
||||
return res;
|
||||
} else {
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-265
@@ -1,265 +0,0 @@
|
||||
/**
|
||||
* JHA v8 algorithm - compatible implementation
|
||||
* @author tpruvot@github 05-2017
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "sph/sph_keccak.h"
|
||||
#include "sph/sph_blake.h"
|
||||
#include "sph/sph_groestl.h"
|
||||
#include "sph/sph_jh.h"
|
||||
#include "sph/sph_skein.h"
|
||||
}
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
#include "quark/cuda_quark.h"
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS] = { 0 };
|
||||
static uint32_t *d_hash_br2[MAX_GPUS];
|
||||
static uint32_t *d_tempBranch[MAX_GPUS];
|
||||
|
||||
extern void jackpot_keccak512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void jackpot_keccak512_cpu_setBlock(void *pdata, size_t inlen);
|
||||
extern void jackpot_keccak512_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash, int order);
|
||||
|
||||
// CPU HASH
|
||||
extern "C" void jha_hash(void *output, const void *input)
|
||||
{
|
||||
uint32_t hash[16];
|
||||
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_skein512_context ctx_skein;
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, input, 80);
|
||||
sph_keccak512_close(&ctx_keccak, hash);
|
||||
|
||||
for (int rnd = 0; rnd < 3; rnd++)
|
||||
{
|
||||
if (hash[0] & 0x01) {
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, (&hash), 64);
|
||||
sph_groestl512_close(&ctx_groestl, (&hash));
|
||||
}
|
||||
else {
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, (&hash), 64);
|
||||
sph_skein512_close(&ctx_skein, (&hash));
|
||||
}
|
||||
|
||||
if (hash[0] & 0x01) {
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, (&hash), 64);
|
||||
sph_blake512_close(&ctx_blake, (&hash));
|
||||
}
|
||||
else {
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, (&hash), 64);
|
||||
sph_jh512_close(&ctx_jh, (&hash));
|
||||
}
|
||||
}
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(128, 8)
|
||||
void jha_filter_gpu(const uint32_t threads, const uint32_t* d_hash, uint32_t* d_branch2, uint32_t* d_NonceBranch)
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
const uint32_t offset = thread * 16U; // 64U / sizeof(uint32_t);
|
||||
uint4 *psrc = (uint4*) (&d_hash[offset]);
|
||||
d_NonceBranch[thread] = ((uint8_t*)psrc)[0] & 0x01;
|
||||
if (d_NonceBranch[thread]) return;
|
||||
// uint4 = 4x uint32_t = 16 bytes
|
||||
uint4 *pdst = (uint4*) (&d_branch2[offset]);
|
||||
pdst[0] = psrc[0];
|
||||
pdst[1] = psrc[1];
|
||||
pdst[2] = psrc[2];
|
||||
pdst[3] = psrc[3];
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(128, 8)
|
||||
void jha_merge_gpu(const uint32_t threads, uint32_t* d_hash, uint32_t* d_branch2, uint32_t* const d_NonceBranch)
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads && !d_NonceBranch[thread])
|
||||
{
|
||||
const uint32_t offset = thread * 16U;
|
||||
uint4 *pdst = (uint4*) (&d_hash[offset]);
|
||||
uint4 *psrc = (uint4*) (&d_branch2[offset]);
|
||||
pdst[0] = psrc[0];
|
||||
pdst[1] = psrc[1];
|
||||
pdst[2] = psrc[2];
|
||||
pdst[3] = psrc[3];
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t jha_filter_cpu(const int thr_id, const uint32_t threads, const uint32_t *inpHashes, uint32_t* d_branch2)
|
||||
{
|
||||
const uint32_t threadsperblock = 128;
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
// extract algo permution hashes to a second branch buffer
|
||||
jha_filter_gpu <<<grid, block>>> (threads, inpHashes, d_branch2, d_tempBranch[thr_id]);
|
||||
return threads;
|
||||
}
|
||||
|
||||
__host__
|
||||
void jha_merge_cpu(const int thr_id, const uint32_t threads, uint32_t *outpHashes, uint32_t* d_branch2)
|
||||
{
|
||||
const uint32_t threadsperblock = 128;
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
// put back second branch hashes to the common buffer d_hash
|
||||
jha_merge_gpu <<<grid, block>>> (threads, outpHashes, d_branch2, d_tempBranch[thr_id]);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_jha(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[22];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
int dev_id = device_map[thr_id];
|
||||
|
||||
uint32_t throughput = cuda_default_throughput(thr_id, 1U << 20);
|
||||
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (opt_benchmark)
|
||||
ptarget[7] = 0x000f;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(dev_id);
|
||||
if (opt_cudaschedule == -1 && gpu_threads == 1) {
|
||||
cudaDeviceReset();
|
||||
// reduce cpu usage
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
cuda_get_arch(thr_id);
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t) 64 * throughput));
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash_br2[thr_id], (size_t) 64 * throughput));
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_tempBranch[thr_id], sizeof(uint32_t) * throughput));
|
||||
|
||||
jackpot_keccak512_cpu_init(thr_id, throughput);
|
||||
quark_blake512_cpu_init(thr_id, throughput);
|
||||
quark_groestl512_cpu_init(thr_id, throughput);
|
||||
quark_jh512_cpu_init(thr_id, throughput);
|
||||
quark_skein512_cpu_init(thr_id, throughput);
|
||||
|
||||
cuda_check_cpu_init(thr_id, throughput);
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
for (int k=0; k < 22; k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
|
||||
jackpot_keccak512_cpu_setBlock((void*)endiandata, 80);
|
||||
cuda_check_cpu_setTarget(ptarget);
|
||||
|
||||
do {
|
||||
int order = 0;
|
||||
|
||||
jackpot_keccak512_cpu_hash(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
|
||||
for (int rnd = 0; rnd < 3; rnd++)
|
||||
{
|
||||
jha_filter_cpu(thr_id, throughput, d_hash[thr_id], d_hash_br2[thr_id]);
|
||||
quark_groestl512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
quark_skein512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash_br2[thr_id], order++);
|
||||
jha_merge_cpu(thr_id, throughput, d_hash[thr_id], d_hash_br2[thr_id]);
|
||||
|
||||
jha_filter_cpu(thr_id, throughput, d_hash[thr_id], d_hash_br2[thr_id]);
|
||||
quark_blake512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
quark_jh512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash_br2[thr_id], order++);
|
||||
jha_merge_cpu(thr_id, throughput, d_hash[thr_id], d_hash_br2[thr_id]);
|
||||
}
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
CUDA_LOG_ERROR();
|
||||
|
||||
work->nonces[0] = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
|
||||
if (work->nonces[0] != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t _ALIGN(64) vhash[8];
|
||||
|
||||
be32enc(&endiandata[19], work->nonces[0]);
|
||||
jha_hash(vhash, endiandata);
|
||||
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
work->valid_nonces = 1;
|
||||
work_set_target_ratio(work, vhash);
|
||||
work->nonces[1] = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
if (work->nonces[1] != 0) {
|
||||
be32enc(&endiandata[19], work->nonces[1]);
|
||||
jha_hash(vhash, endiandata);
|
||||
bn_set_target_ratio(work, vhash, 1);
|
||||
work->valid_nonces++;
|
||||
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
|
||||
} else {
|
||||
pdata[19] = work->nonces[0] + 1; // cursor
|
||||
}
|
||||
return work->valid_nonces;
|
||||
}
|
||||
else if (vhash[7] > Htarg) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
|
||||
pdata[19] = work->nonces[0] + 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ((uint64_t) throughput + pdata[19] >= max_nonce) {
|
||||
pdata[19] = max_nonce;
|
||||
break;
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (!work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
|
||||
CUDA_LOG_ERROR();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_jha(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaThreadSynchronize();
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
cudaFree(d_hash_br2[thr_id]);
|
||||
cudaFree(d_tempBranch[thr_id]);
|
||||
|
||||
quark_blake512_cpu_free(thr_id);
|
||||
quark_groestl512_cpu_free(thr_id);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
CUDA_LOG_ERROR();
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
init[thr_id] = false;
|
||||
}
|
||||
+15
-63
@@ -9,7 +9,7 @@ endif
|
||||
|
||||
EXTRA_DIST = autogen.sh README.md README.txt LICENSE.txt \
|
||||
ccminer.sln ccminer.vcxproj ccminer.vcxproj.filters \
|
||||
compat/gettimeofday.c compat/getopt/getopt_long.c
|
||||
compat/gettimeofday.c compat/getopt/getopt_long.c cpuminer-config.h.in
|
||||
|
||||
SUBDIRS = compat
|
||||
|
||||
@@ -21,9 +21,6 @@ ccminer_SOURCES = elist.h miner.h compat.h \
|
||||
crc32.c hefty1.c \
|
||||
ccminer.cpp pools.cpp util.cpp bench.cpp bignum.cpp \
|
||||
api.cpp hashlog.cpp nvml.cpp stats.cpp sysinfos.cpp cuda.cpp \
|
||||
nvsettings.cpp \
|
||||
equi/equi-stratum.cpp equi/equi.cpp equi/blake2/blake2bx.cpp \
|
||||
equi/equihash.cpp equi/cuda_equi.cu \
|
||||
heavy/heavy.cu \
|
||||
heavy/cuda_blake512.cu heavy/cuda_blake512.h \
|
||||
heavy/cuda_combine.cu heavy/cuda_combine.h \
|
||||
@@ -31,60 +28,37 @@ ccminer_SOURCES = elist.h miner.h compat.h \
|
||||
heavy/cuda_hefty1.cu heavy/cuda_hefty1.h \
|
||||
heavy/cuda_keccak512.cu heavy/cuda_keccak512.h \
|
||||
heavy/cuda_sha256.cu heavy/cuda_sha256.h \
|
||||
heavy/bastion.cu heavy/cuda_bastion.cu \
|
||||
fuguecoin.cpp Algo256/cuda_fugue256.cu sph/fugue.c uint256.h \
|
||||
groestlcoin.cpp cuda_groestlcoin.cu cuda_groestlcoin.h \
|
||||
myriadgroestl.cpp cuda_myriadgroestl.cu \
|
||||
lyra2/Lyra2.c lyra2/Sponge.c \
|
||||
lyra2/lyra2RE.cu lyra2/cuda_lyra2.cu \
|
||||
lyra2/lyra2REv2.cu lyra2/cuda_lyra2v2.cu \
|
||||
lyra2/lyra2REv3.cu lyra2/cuda_lyra2v3.cu \
|
||||
lyra2/Lyra2Z.c lyra2/lyra2Z.cu lyra2/cuda_lyra2Z.cu \
|
||||
lyra2/allium.cu \
|
||||
Algo256/cuda_bmw256.cu Algo256/cuda_cubehash256.cu \
|
||||
Algo256/cuda_blake256.cu Algo256/cuda_groestl256.cu \
|
||||
Algo256/cuda_keccak256_sm3.cu Algo256/cuda_keccak256.cu Algo256/cuda_skein256.cu \
|
||||
Algo256/cuda_blake256.cu Algo256/cuda_groestl256.cu Algo256/cuda_keccak256.cu Algo256/cuda_skein256.cu \
|
||||
Algo256/blake256.cu Algo256/decred.cu Algo256/vanilla.cu Algo256/keccak256.cu \
|
||||
Algo256/blake2s.cu sph/blake2s.c \
|
||||
Algo256/bmw.cu Algo256/cuda_bmw.cu \
|
||||
blake2b.cu \
|
||||
crypto/xmr-rpc.cpp crypto/wildkeccak-cpu.cpp crypto/wildkeccak.cu \
|
||||
crypto/cryptolight.cu crypto/cryptolight-core.cu crypto/cryptolight-cpu.cpp \
|
||||
crypto/cryptonight.cu crypto/cryptonight-core.cu crypto/cryptonight-extra.cu \
|
||||
crypto/cryptonight-cpu.cpp crypto/oaes_lib.cpp crypto/aesb.cpp crypto/cpu/c_keccak.c \
|
||||
JHA/jha.cu JHA/jackpotcoin.cu JHA/cuda_jha_keccak512.cu \
|
||||
JHA/jackpotcoin.cu JHA/cuda_jha_keccak512.cu \
|
||||
JHA/cuda_jha_compactionTest.cu cuda_checkhash.cu \
|
||||
quark/cuda_jh512.cu quark/cuda_quark_blake512.cu quark/cuda_quark_groestl512.cu quark/cuda_skein512.cu \
|
||||
quark/cuda_bmw512.cu quark/cuda_quark_keccak512.cu \
|
||||
quark/nist5.cu \
|
||||
quark/quarkcoin.cu quark/cuda_quark_compactionTest.cu \
|
||||
neoscrypt/neoscrypt.cpp neoscrypt/neoscrypt-cpu.c neoscrypt/cuda_neoscrypt.cu \
|
||||
pentablake.cu skein.cu cuda_skeincoin.cu skein2.cpp zr5.cu \
|
||||
skunk/skunk.cu skunk/cuda_skunk.cu skunk/cuda_skunk_streebog.cu \
|
||||
sha256/sha256d.cu sha256/cuda_sha256d.cu sha256/sha256t.cu sha256/cuda_sha256t.cu sha256/sha256q.cu sha256/cuda_sha256q.cu \
|
||||
sia/sia.cu sia/sia-rpc.cpp sph/blake2b.c \
|
||||
cuda_nist5.cu pentablake.cu skein.cu cuda_skeincoin.cu skein2.cpp zr5.cu \
|
||||
sph/bmw.c sph/blake.c sph/groestl.c sph/jh.c sph/keccak.c sph/skein.c \
|
||||
sph/cubehash.c sph/echo.c sph/luffa.c sph/sha2.c sph/shavite.c sph/simd.c \
|
||||
sph/hamsi.c sph/hamsi_helper.c sph/streebog.c \
|
||||
sph/shabal.c sph/whirlpool.c sph/sha2big.c sph/haval.c \
|
||||
sph/ripemd.c sph/sph_sha2.c \
|
||||
polytimos.cu \
|
||||
lbry/lbry.cu lbry/cuda_sha256_lbry.cu lbry/cuda_sha512_lbry.cu lbry/cuda_lbry_merged.cu \
|
||||
qubit/qubit.cu qubit/qubit_luffa512.cu qubit/deep.cu qubit/luffa.cu \
|
||||
tribus/tribus.cu tribus/cuda_echo512_final.cu \
|
||||
x11/x11.cu x12/x12.cu x11/fresh.cu x11/cuda_x11_luffa512.cu x11/cuda_x11_cubehash512.cu \
|
||||
x11/cuda_x11_shavite512.cu x11/cuda_x11_simd512.cu x11/cuda_x11_echo.cu x11/exosis.cu \
|
||||
x11/cuda_x11_luffa512_Cubehash.cu x11/x11evo.cu x11/timetravel.cu x11/bitcore.cu \
|
||||
x11/x11.cu x11/fresh.cu x11/cuda_x11_luffa512.cu x11/cuda_x11_cubehash512.cu \
|
||||
x11/cuda_x11_shavite512.cu x11/cuda_x11_simd512.cu x11/cuda_x11_echo.cu \
|
||||
x11/cuda_x11_luffa512_Cubehash.cu \
|
||||
x13/x13.cu x13/cuda_x13_hamsi512.cu x13/cuda_x13_fugue512.cu \
|
||||
x13/hsr.cu x13/cuda_hsr_sm3.cu x13/sm3.c \
|
||||
x15/x14.cu x15/x15.cu x15/cuda_x14_shabal512.cu x15/cuda_x15_whirlpool.cu \
|
||||
x15/whirlpool.cu x15/cuda_x15_whirlpool_sm3.cu \
|
||||
x16/x16r.cu x16/x16s.cu x16/cuda_x16_echo512.cu x16/cuda_x16_fugue512.cu \
|
||||
x16/cuda_x16_shabal512.cu x16/cuda_x16_simd512_80.cu \
|
||||
x16/cuda_x16_echo512_64.cu \
|
||||
x17/x17.cu x17/hmq17.cu x17/sonoa.cu x17/cuda_x17_haval256.cu x17/cuda_x17_sha512.cu \
|
||||
phi/phi.cu phi/phi2.cu phi/cuda_phi2.cu phi/cuda_phi2_cubehash512.cu x11/cuda_streebog_maxwell.cu \
|
||||
x11/c11.cu x11/s3.cu x11/sib.cu x11/veltor.cu x11/cuda_streebog.cu
|
||||
x15/whirlpool.cu \
|
||||
x17/x17.cu x17/cuda_x17_haval256.cu x17/cuda_x17_sha512.cu \
|
||||
x11/c11.cu x11/s3.cu x11/sib.cu x11/cuda_streebog.cu
|
||||
|
||||
# scrypt
|
||||
ccminer_SOURCES += scrypt.cpp scrypt-jane.cpp \
|
||||
@@ -106,25 +80,12 @@ ccminer_LDFLAGS = $(PTHREAD_FLAGS) @CUDA_LDFLAGS@
|
||||
ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @OPENMP_CFLAGS@ @LIBS@ $(nvml_libs)
|
||||
ccminer_CPPFLAGS = @LIBCURL_CPPFLAGS@ @OPENMP_CFLAGS@ $(CPPFLAGS) $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(DEF_INCLUDES) $(nvml_defs)
|
||||
|
||||
if HAVE_OSX
|
||||
ccminer_CPPFLAGS += -I/usr/local/llvm/lib/clang/4.0.0/include
|
||||
ccminer_LDFLAGS += -L/usr/local/llvm/lib
|
||||
ccminer_LDADD += -lomp
|
||||
endif
|
||||
nvcc_ARCH = -gencode=arch=compute_50,code=\"sm_50,compute_50\"
|
||||
|
||||
#ccminer_CPPFLAGS += -DUSE_LIBSODIUM
|
||||
#ccminer_LDFLAGS += -Lequi/lib
|
||||
#ccminer_LDADD += -lsodium
|
||||
ccminer_LDADD += -lcuda
|
||||
|
||||
nvcc_ARCH :=
|
||||
#nvcc_ARCH += -gencode=arch=compute_75,code=\"sm_75,compute_75\" # CUDA 10 req.
|
||||
#nvcc_ARCH += -gencode=arch=compute_70,code=\"sm_70,compute_70\" # CUDA 9.1
|
||||
#nvcc_ARCH += -gencode=arch=compute_61,code=\"sm_61,compute_61\" # CUDA 8
|
||||
nvcc_ARCH += -gencode=arch=compute_52,code=\"sm_52,compute_52\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_50,code=\"sm_50,compute_50\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_35,code=\"sm_35,compute_35\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_30,code=\"sm_30,compute_30\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_20,code=\"sm_21,compute_20\"
|
||||
|
||||
nvcc_FLAGS = $(nvcc_ARCH) @CUDA_INCLUDES@ -I. @CUDA_CFLAGS@
|
||||
nvcc_FLAGS += $(JANSSON_INCLUDES) --ptxas-options="-v"
|
||||
@@ -139,12 +100,6 @@ Algo256/blake256.o: Algo256/blake256.cu
|
||||
Algo256/cuda_bmw.o: Algo256/cuda_bmw.cu
|
||||
$(NVCC) $(nvcc_FLAGS) --maxrregcount=76 -o $@ -c $<
|
||||
|
||||
crypto/cryptonight-core.o: crypto/cryptonight-core.cu
|
||||
$(NVCC) $(nvcc_FLAGS) --maxrregcount=64 -o $@ -c $<
|
||||
|
||||
crypto/cryptonight-extra.o: crypto/cryptonight-extra.cu
|
||||
$(NVCC) $(nvcc_FLAGS) -o $@ -c $<
|
||||
|
||||
heavy/cuda_hefty1.o: heavy/cuda_hefty1.cu
|
||||
$(NVCC) $(nvcc_FLAGS) --maxrregcount=80 -o $@ -c $<
|
||||
|
||||
@@ -170,9 +125,6 @@ x17/cuda_x17_sha512.o: x17/cuda_x17_sha512.cu
|
||||
quark/cuda_quark_blake512.o: quark/cuda_quark_blake512.cu
|
||||
$(NVCC) $(nvcc_FLAGS) --maxrregcount=80 -o $@ -c $<
|
||||
|
||||
quark/cuda_jh512.o: quark/cuda_jh512.cu
|
||||
$(NVCC) $(nvcc_FLAGS) --maxrregcount=80 -o $@ -c $<
|
||||
|
||||
quark/cuda_quark_keccak512.o: quark/cuda_quark_keccak512.cu
|
||||
$(NVCC) $(nvcc_FLAGS) --maxrregcount=88 -o $@ -c $<
|
||||
|
||||
@@ -184,15 +136,15 @@ JHA/cuda_jha_compactionTest.o: JHA/cuda_jha_compactionTest.cu
|
||||
|
||||
# This object does not use cuda device code but call the different kernels (autotune)
|
||||
scrypt/salsa_kernel.o: scrypt/salsa_kernel.cu
|
||||
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_30,code=\"sm_30,compute_30\" -o $@ -c $<
|
||||
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_20,code=\"sm_21,compute_20\" -o $@ -c $<
|
||||
|
||||
# These kernels are for older devices (SM)
|
||||
|
||||
scrypt/test_kernel.o: scrypt/test_kernel.cu
|
||||
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_30,code=\"sm_30,compute_30\" -o $@ -c $<
|
||||
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_20,code=\"sm_20,compute_20\" -o $@ -c $<
|
||||
|
||||
scrypt/fermi_kernel.o: scrypt/fermi_kernel.cu
|
||||
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_30,code=\"sm_30,compute_30\" -o $@ -c $<
|
||||
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_20,code=\"sm_21,compute_20\" -o $@ -c $<
|
||||
|
||||
scrypt/kepler_kernel.o: scrypt/kepler_kernel.cu
|
||||
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_30,code=\"sm_30,compute_30\" -o $@ -c $<
|
||||
|
||||
@@ -1,23 +1,38 @@
|
||||
## ccminer
|
||||
ccminer
|
||||
=======
|
||||
|
||||
This is a fork of https://github.com/tpruvot/ccminer.git with additions for mining LBRY. It is a CUDA miner. It requires nVidia hardware.
|
||||
Early editions of ccminer included support for LBRY through the old getwork interface that is still in use by many pools. This fork also includes support for direct use of getblocktemplate (GBT).
|
||||
Based on Christian Buchner's & Christian H.'s CUDA project, no more active on github recently.
|
||||
|
||||
Fork by tpruvot@github with X14,X15,X17,Blake256,BlakeCoin,Lyra2RE,Skein,ZR5 and others, check the [README.txt](README.txt)
|
||||
|
||||
### Solo mining direct:
|
||||
```
|
||||
# start a lbrycrd daemon on testnet:
|
||||
./lbrycrdd -server -txindex -rpcuser=ruser -rpcpassword=rpswd -testnet
|
||||
BTC donation address: 1AJdfCpLWPNoAMDfHF1wD5y8VgKSSTHxPo
|
||||
[](https://tip4commit.com/github/tpruvot/ccminer)
|
||||
|
||||
# in a separate console, run ccminer:
|
||||
./ccminer -a lbry -o 127.0.0.1:19245 -u ruser -p rpswd -D
|
||||
A part of the recent algos were originally written by [djm34](https://github.com/djm34).
|
||||
|
||||
```
|
||||
This requires support for coinbasetxn in lbrycrd's getblocktemplate implementation, which is fairly new.
|
||||
This variant was tested and built on Linux (ubuntu server 14.04) and VStudio 2013 on Windows 7.
|
||||
|
||||
Note that the x86 releases are generally faster than x64 ones on Windows.
|
||||
|
||||
The recommended CUDA Toolkit version is [6.5.19](http://developer.download.nvidia.com/compute/cuda/6_5/rel/installers/cuda_6.5.19_windows_general_64.exe), but some light algos could be faster with the version 7.5 (like blake and skein).
|
||||
|
||||
About source code dependencies
|
||||
------------------------------
|
||||
|
||||
This project requires some libraries to be built :
|
||||
|
||||
- OpenSSL (prebuilt for win)
|
||||
|
||||
- Curl (prebuilt for win)
|
||||
|
||||
- pthreads (prebuilt for win)
|
||||
|
||||
The tree now contains recent prebuilt openssl and curl .lib for both x86 and x64 platforms (windows).
|
||||
|
||||
To rebuild them, you need to clone this repository and its submodules :
|
||||
git clone https://github.com/peters/curl-for-windows.git compat/curl-for-windows
|
||||
|
||||
On Linux, you can use the helper ./build.sh (edit it if required)
|
||||
|
||||
There is also an old [Tutorial for windows](http://cudamining.co.uk/url/tutorials/id/3) on [CudaMining](http://cudamining.co.uk) website.
|
||||
|
||||
### Compilation:
|
||||
```
|
||||
./autogen.sh
|
||||
./configure --with-cuda=/usr/lib/cuda-10.1/targets/x86_64-linux CXXFLAGS="-Og -march=native -g -Wfatal-errors -L/usr/lib/cuda-10.1/targets/x86_64-linux/lib" CFLAGS="-Og -march=native -g"
|
||||
make -j5
|
||||
```
|
||||
+33
-163
@@ -1,5 +1,5 @@
|
||||
|
||||
ccminer 2.3.1 "lyra2v3, exosis and sha256q"
|
||||
ccMiner release 1.7.6 (May 2016) "DCR vote & pool device stats"
|
||||
---------------------------------------------------------------
|
||||
|
||||
***************************************************************
|
||||
@@ -8,7 +8,8 @@ If you find this tool useful and like to support its continuous
|
||||
|
||||
tpruvot@github:
|
||||
BTC : 1AJdfCpLWPNoAMDfHF1wD5y8VgKSSTHxPo
|
||||
DCR : DsUCcACGcyP8McNMRXQwbtpDxaVUYLDQDeU
|
||||
DRK : XeVrkPrWB7pDbdFLfKhF1Z3xpqhsx6wkH3
|
||||
ZRC : ZEcubH2xp2mpuwxMjy7wZThr5AzLGu3mqT
|
||||
|
||||
DJM34:
|
||||
BTC donation address: 1NENYmxwZGHsKFmyjTc5WferTn5VTFb7Ze
|
||||
@@ -27,109 +28,83 @@ Decred (Blake256 14-rounds - 180 bytes)
|
||||
HeavyCoin & MjollnirCoin
|
||||
FugueCoin
|
||||
GroestlCoin & Myriad-Groestl
|
||||
Lbry Credits
|
||||
JackpotCoin (JHA)
|
||||
JackpotCoin
|
||||
QuarkCoin family & AnimeCoin
|
||||
TalkCoin
|
||||
DarkCoin and other X11 coins
|
||||
Chaincoin and Flaxscript (C11)
|
||||
Saffroncoin blake (256 14-rounds)
|
||||
BlakeCoin (256 8-rounds)
|
||||
Midnight (BMW 256)
|
||||
Qubit (Digibyte, ...)
|
||||
Luffa (Joincoin)
|
||||
Keccak (Maxcoin)
|
||||
Pentablake (Blake 512 x5)
|
||||
1Coin Triple S
|
||||
Neoscrypt (FeatherCoin)
|
||||
x11evo (Revolver)
|
||||
phi2 (LUXCoin)
|
||||
Scrypt and Scrypt:N
|
||||
Scrypt-Jane (Chacha)
|
||||
sib (Sibcoin)
|
||||
Sibcoin (sib)
|
||||
Skein (Skein + SHA)
|
||||
Signatum (Skein cubehash fugue Streebog)
|
||||
SonoA (Sono)
|
||||
Tribus (JH, keccak, simd)
|
||||
Woodcoin (Double Skein)
|
||||
Vanilla (Blake256 8-rounds - double sha256)
|
||||
Vertcoin Lyra2REv3
|
||||
Boolberry (Wild Keccak)
|
||||
Monero (Cryptonight v7 with -a monero)
|
||||
Aeon (Cryptonight-lite)
|
||||
Vertcoin Lyra2RE
|
||||
Ziftrcoin (ZR5)
|
||||
|
||||
where some of these coins have a VERY NOTABLE nVidia advantage
|
||||
over competing AMD (OpenCL Only) implementations.
|
||||
|
||||
We did not take a big effort on improving usability, so please set
|
||||
your parameters carefuly.
|
||||
|
||||
THIS PROGRAMM IS PROVIDED "AS-IS", USE IT AT YOUR OWN RISK!
|
||||
|
||||
If you're interessted and read the source-code, please excuse
|
||||
that the most of our comments are in german.
|
||||
|
||||
>>> Command Line Interface <<<
|
||||
|
||||
The code is based on the pooler cpuminer and inherits
|
||||
This code is based on the pooler cpuminer and inherits
|
||||
its command line interface and options.
|
||||
|
||||
-a, --algo=ALGO specify the algorithm to use
|
||||
allium use to mine Garlic
|
||||
bastion use to mine Joincoin
|
||||
bitcore use to mine Bitcore's Timetravel10
|
||||
blake use to mine Saffroncoin (Blake256)
|
||||
blakecoin use to mine Old Blake 256
|
||||
blake2s use to mine Nevacoin (Blake2-S 256)
|
||||
bmw use to mine Midnight
|
||||
cryptolight use to mine AEON cryptonight variant 1 (MEM/2)
|
||||
cryptonight use to mine original cryptonight
|
||||
c11/flax use to mine Chaincoin and Flax
|
||||
decred use to mine Decred 180 bytes Blake256-14
|
||||
deep use to mine Deepcoin
|
||||
dmd-gr use to mine Diamond-Groestl
|
||||
equihash use to mine ZEC, HUSH and KMD
|
||||
exosis use to mine EXO
|
||||
fresh use to mine Freshcoin
|
||||
fugue256 use to mine Fuguecoin
|
||||
groestl use to mine Groestlcoin
|
||||
hsr use to mine Hshare
|
||||
jackpot use to mine Sweepcoin
|
||||
heavy use to mine Heavycoin
|
||||
jackpot use to mine Jackpotcoin
|
||||
keccak use to mine Maxcoin
|
||||
keccakc use to mine CreativeCoin
|
||||
lbry use to mine LBRY Credits
|
||||
luffa use to mine Joincoin
|
||||
lyra2 use to mine CryptoCoin
|
||||
lyra2v2 use to mine Monacoin
|
||||
lyra2v3 use to mine Vertcoin
|
||||
lyra2z use to mine Zerocoin (XZC)
|
||||
monero use to mine Monero (XMR)
|
||||
lyra2 use to mine Vertcoin
|
||||
mjollnir use to mine Mjollnircoin
|
||||
myr-gr use to mine Myriad-Groest
|
||||
neoscrypt use to mine FeatherCoin, Trezarcoin, Orbitcoin, etc
|
||||
neoscrypt use to mine FeatherCoin
|
||||
nist5 use to mine TalkCoin
|
||||
penta use to mine Joincoin / Pentablake
|
||||
phi1612 use to mine Seraph
|
||||
phi2 use to mine LUXCoin
|
||||
polytimos use to mine Polytimos
|
||||
quark use to mine Quarkcoin
|
||||
qubit use to mine Qubit
|
||||
scrypt use to mine Scrypt coins (Litecoin, Dogecoin, etc)
|
||||
scrypt use to mine Scrypt coins
|
||||
scrypt:N use to mine Scrypt-N (:10 for 2048 iterations)
|
||||
scrypt-jane use to mine Chacha coins like Cache and Ultracoin
|
||||
s3 use to mine 1coin (ONE)
|
||||
sha256t use to mine OneCoin (OC)
|
||||
sha256q use to mine Pyrite
|
||||
sia use to mine SIA
|
||||
s3 use to mine 1coin
|
||||
sib use to mine Sibcoin
|
||||
skein use to mine Skeincoin
|
||||
skein2 use to mine Woodcoin
|
||||
skunk use to mine Signatum
|
||||
sonoa use to mine Sono
|
||||
stellite use to mine Stellite (a cryptonight variant)
|
||||
timetravel use to mine MachineCoin
|
||||
tribus use to mine Denarius
|
||||
x11evo use to mine Revolver
|
||||
x11 use to mine DarkCoin
|
||||
x12 use to mine GalaxyCash
|
||||
x13 use to mine X13
|
||||
x14 use to mine X14
|
||||
x14 use to mine X14Coin
|
||||
x15 use to mine Halcyon
|
||||
x16r use to mine Raven
|
||||
x16s use to mine Pigeon and Eden
|
||||
x17 use to mine X17
|
||||
x17 use to mine X17
|
||||
vanilla use to mine Vanilla (Blake256)
|
||||
veltor use to mine VeltorCoin
|
||||
whirlpool use to mine Joincoin
|
||||
wildkeccak use to mine Boolberry (Stratum only)
|
||||
zr5 use to mine ZiftrCoin
|
||||
|
||||
-d, --devices gives a comma separated list of CUDA device IDs
|
||||
@@ -142,6 +117,8 @@ its command line interface and options.
|
||||
--cuda-schedule Set device threads scheduling mode (default: auto)
|
||||
-f, --diff-factor Divide difficulty by this factor (default 1.0)
|
||||
-m, --diff-multiplier Multiply difficulty by this value (default 1.0)
|
||||
--vote=VOTE block reward vote (for HeavyCoin)
|
||||
--trust-pool trust the max block reward vote (maxvote) sent by the pool
|
||||
-o, --url=URL URL of mining server
|
||||
-O, --userpass=U:P username:password pair for mining server
|
||||
-u, --user=USERNAME username for mining server
|
||||
@@ -157,7 +134,6 @@ its command line interface and options.
|
||||
-T, --timeout=N network timeout, in seconds (default: 300)
|
||||
-s, --scantime=N upper bound on time spent scanning current work when
|
||||
long polling is unavailable, in seconds (default: 5)
|
||||
--submit-stale ignore stale job checks, may create more rejected shares
|
||||
-n, --ndevs list cuda devices
|
||||
-N, --statsavg number of samples used to display hashrate (default: 30)
|
||||
--no-gbt disable getblocktemplate support (height check in solo)
|
||||
@@ -167,19 +143,15 @@ its command line interface and options.
|
||||
--no-color disable colored output
|
||||
-D, --debug enable debug output
|
||||
-P, --protocol-dump verbose dump of protocol-level activities
|
||||
-b, --api-bind=port IP:port for the miner API (default: 127.0.0.1:4068), 0 disabled
|
||||
--api-remote Allow remote control, like pool switching, imply --api-allow=0/0
|
||||
--api-allow=... IP/mask of the allowed api client(s), 0/0 for all
|
||||
-b, --api-bind IP/Port for the miner API (default: 127.0.0.1:4068)
|
||||
--api-remote Allow remote control
|
||||
--max-temp=N Only mine if gpu temp is less than specified value
|
||||
--max-rate=N[KMG] Only mine if net hashrate is less than specified value
|
||||
--max-diff=N Only mine if net difficulty is less than specified value
|
||||
--max-log-rate Interval to reduce per gpu hashrate logs (default: 3)
|
||||
--pstate=0 will force the Geforce 9xx to run in P0 P-State
|
||||
--plimit=150W set the gpu power limit, allow multiple values for N cards
|
||||
on windows this parameter use percentages (like OC tools)
|
||||
--tlimit=85 Set the gpu thermal limit (windows only)
|
||||
--keep-clocks prevent reset clocks and/or power limit on exit
|
||||
--hide-diff Hide submitted shares diff and net difficulty
|
||||
--show-diff display submitted block and net difficulty
|
||||
-B, --background run the miner in the background
|
||||
--benchmark run in offline benchmark mode
|
||||
--cputest debug hashes from cpu algorithms
|
||||
@@ -205,18 +177,6 @@ Scrypt specific options:
|
||||
cache for mining. Kepler devices may profit.
|
||||
--no-autotune disable auto-tuning of kernel launch parameters
|
||||
|
||||
CryptoNight specific options:
|
||||
-l, --launch-config gives the launch configuration for each kernel
|
||||
in a comma separated list, one per device.
|
||||
--bfactor=[0-12] Run Cryptonight core kernel in smaller pieces,
|
||||
From 0 (ui freeze) to 12 (smooth), win default is 11
|
||||
This is a per-device setting like the launch config.
|
||||
|
||||
Wildkeccak specific:
|
||||
-l, --launch-config gives the launch configuration for each kernel
|
||||
in a comma separated list, one per device.
|
||||
-k, --scratchpad url Url used to download the scratchpad cache.
|
||||
|
||||
|
||||
>>> Examples <<<
|
||||
|
||||
@@ -240,8 +200,6 @@ Example for Fuguecoin pool mining on dwarfpool.com with all your GPUs
|
||||
Example for Groestlcoin solo mining
|
||||
ccminer -q -s 1 -a groestl -o http://127.0.0.1:1441/ -u USERNAME -p PASSWORD
|
||||
|
||||
Example for Boolberry
|
||||
ccminer -a wildkeccak -o stratum+tcp://bbr.suprnova.cc:7777 -u tpruvot.donate -p x -k http://bbr.suprnova.cc/scratchpad.bin -l 64x360
|
||||
|
||||
Example for Scrypt-N (2048) on Nicehash
|
||||
ccminer -a scrypt:10 -o stratum+tcp://stratum.nicehash.com:3335 -u 3EujYFcoBzWvpUEvbe3obEG95mBuU88QBD -p x
|
||||
@@ -280,94 +238,6 @@ so we can more efficiently implement new algorithms using the latest hardware
|
||||
features.
|
||||
|
||||
>>> RELEASE HISTORY <<<
|
||||
Jan. 30th 2019 v2.3.1
|
||||
Handle Lyra2v3 algo
|
||||
Handle sha256q algo
|
||||
Handle exosis algo
|
||||
Handle blake2b standard algo
|
||||
|
||||
June 23th 2018 v2.3
|
||||
Handle phi2 header variation for smart contracts
|
||||
Handle monero, stellite, graft and cryptolight variants
|
||||
Handle SonoA algo
|
||||
|
||||
June 10th 2018 v2.2.6
|
||||
New phi2 algo for LUX
|
||||
New allium algo for Garlic
|
||||
|
||||
Apr. 02nd 2018 v2.2.5
|
||||
New x16r algo for Raven
|
||||
New x16s algo for Pigeon and Eden
|
||||
New x12 algo for Galaxycash
|
||||
Equihash (SIMT) sync issues for the Volta generation
|
||||
|
||||
Jan. 04th 2018 v2.2.4
|
||||
Improve lyra2v2
|
||||
Higher keccak default intensity
|
||||
Drop SM 2.x support by default, for CUDA 9 and more recent
|
||||
|
||||
Dec. 04th 2017 v2.2.3
|
||||
Polytimos Algo
|
||||
Handle keccakc variant (with refreshed sha256d merkle)
|
||||
Optimised keccak for SM5+, based on alexis improvements
|
||||
|
||||
Oct. 09th 2017 v2.2.2
|
||||
Import and clean the hsr algo (x13 + custom hash)
|
||||
Import and optimise phi algo from LuxCoin repository
|
||||
Improve sib algo too for maxwell and pascal cards
|
||||
Small fix to handle more than 9 cards on linux (-d 10+)
|
||||
Attempt to free equihash memory "properly"
|
||||
--submit-stale parameter for supernova pool (which change diff too fast)
|
||||
|
||||
Sep. 01st 2017 v2.2.1
|
||||
Improve tribus algo on recent cards (up to +10%)
|
||||
|
||||
Aug. 13th 2017 v2.2
|
||||
New skunk algo, using the heavy streebog algorithm
|
||||
Enhance tribus algo (+10%)
|
||||
equihash protocol enhancement on yiimp.ccminer.org and zpool.ca
|
||||
|
||||
June 16th 2017 v2.1-tribus
|
||||
Interface equihash algo with djeZo solver (from nheqminer 0.5c)
|
||||
New api parameters (and multicast announces for local networks)
|
||||
New tribus algo
|
||||
|
||||
May. 14th 2017 v2.0
|
||||
Handle cryptonight, wildkeccak and cryptonight-lite
|
||||
Add a serie of new algos: timetravel, bastion, hmq1725, sha256t
|
||||
Import lyra2z from djm34 work...
|
||||
Rework the common skein512 (used in most algos except skein ;)
|
||||
Upgrade whirlpool algo with alexis version (2x faster)
|
||||
Store the share diff of second nonce(s) in most algos
|
||||
Hardware monitoring thread to get more accurate power readings
|
||||
Small changes for the quiet mode & max-log-rate to reduce logs
|
||||
Add bitcore and a compatible jha algo
|
||||
|
||||
Dec. 21th 2016 v1.8.4
|
||||
Improve streebog based algos, veltor and sib (from alexis work)
|
||||
Blake2s greetly improved (3x), thanks to alexis too...
|
||||
|
||||
Sep. 28th 2016 v1.8.3
|
||||
show intensity on startup for each cards
|
||||
show-diff is now used by default, use --hide-diff if not wanted
|
||||
|
||||
Sep. 22th 2016 v1.8.2
|
||||
lbry improvements by Alexis Provos
|
||||
Prevent Windows hibernate while mining
|
||||
veltor algo (basic implementation)
|
||||
|
||||
Aug. 10th 2016 v1.8.1
|
||||
SIA Blake2-B Algo (getwork over stratum for Suprnova)
|
||||
SIA Nanopool RPC (getwork over http)
|
||||
Update also the older lyra2 with Nanashi version
|
||||
|
||||
July 20th 2016 v1.8.0
|
||||
Pascal support with cuda 8
|
||||
lbry new multi sha / ripemd algo (LBC)
|
||||
x11evo algo (XRE)
|
||||
Lyra2v2, Neoscrypt and Decred improvements
|
||||
Enhance windows NVAPI clock and power limits
|
||||
Led support for mining/shares activity on windows
|
||||
|
||||
May 18th 2016 v1.7.6
|
||||
Decred vote support
|
||||
|
||||
@@ -7,79 +7,44 @@
|
||||
enum sha_algos {
|
||||
ALGO_BLAKECOIN = 0,
|
||||
ALGO_BLAKE,
|
||||
ALGO_BLAKE2B,
|
||||
ALGO_BLAKE2S,
|
||||
ALGO_ALLIUM,
|
||||
ALGO_BMW,
|
||||
ALGO_BASTION,
|
||||
ALGO_C11,
|
||||
ALGO_CRYPTOLIGHT,
|
||||
ALGO_CRYPTONIGHT,
|
||||
ALGO_DEEP,
|
||||
ALGO_DECRED,
|
||||
ALGO_DMD_GR,
|
||||
ALGO_EQUIHASH,
|
||||
ALGO_EXOSIS,
|
||||
ALGO_FRESH,
|
||||
ALGO_FUGUE256, /* Fugue256 */
|
||||
ALGO_GROESTL,
|
||||
ALGO_HEAVY, /* Heavycoin hash */
|
||||
ALGO_HMQ1725,
|
||||
ALGO_HSR,
|
||||
ALGO_KECCAK,
|
||||
ALGO_KECCAKC, /* refreshed Keccak with pool factor 256 */
|
||||
ALGO_JACKPOT,
|
||||
ALGO_JHA,
|
||||
ALGO_LBRY,
|
||||
ALGO_LUFFA,
|
||||
ALGO_LYRA2,
|
||||
ALGO_LYRA2v2,
|
||||
ALGO_LYRA2v3,
|
||||
ALGO_LYRA2Z,
|
||||
ALGO_MJOLLNIR, /* Hefty hash */
|
||||
ALGO_MYR_GR,
|
||||
ALGO_NEOSCRYPT,
|
||||
ALGO_NIST5,
|
||||
ALGO_PENTABLAKE,
|
||||
ALGO_PHI,
|
||||
ALGO_PHI2,
|
||||
ALGO_POLYTIMOS,
|
||||
ALGO_QUARK,
|
||||
ALGO_QUBIT,
|
||||
ALGO_SCRYPT,
|
||||
ALGO_SCRYPT_JANE,
|
||||
ALGO_SHA256D,
|
||||
ALGO_SHA256T,
|
||||
ALGO_SHA256Q,
|
||||
ALGO_SIA,
|
||||
ALGO_SIB,
|
||||
ALGO_SKEIN,
|
||||
ALGO_SKEIN2,
|
||||
ALGO_SKUNK,
|
||||
ALGO_SONOA,
|
||||
ALGO_S3,
|
||||
ALGO_TIMETRAVEL,
|
||||
ALGO_TRIBUS,
|
||||
ALGO_BITCORE,
|
||||
ALGO_X11EVO,
|
||||
ALGO_X11,
|
||||
ALGO_X12,
|
||||
ALGO_X13,
|
||||
ALGO_X14,
|
||||
ALGO_X15,
|
||||
ALGO_X16R,
|
||||
ALGO_X16S,
|
||||
ALGO_X17,
|
||||
ALGO_VANILLA,
|
||||
ALGO_VELTOR,
|
||||
ALGO_WHIRLCOIN,
|
||||
ALGO_WHIRLPOOL,
|
||||
ALGO_WHIRLPOOLX,
|
||||
ALGO_WILDKECCAK,
|
||||
ALGO_ZR5,
|
||||
ALGO_MONERO,
|
||||
ALGO_GRAFT,
|
||||
ALGO_STELLITE,
|
||||
ALGO_AUTO,
|
||||
ALGO_COUNT
|
||||
};
|
||||
@@ -89,79 +54,44 @@ extern volatile enum sha_algos opt_algo;
|
||||
static const char *algo_names[] = {
|
||||
"blakecoin",
|
||||
"blake",
|
||||
"blake2b",
|
||||
"blake2s",
|
||||
"allium",
|
||||
"bmw",
|
||||
"bastion",
|
||||
"c11",
|
||||
"cryptolight",
|
||||
"cryptonight",
|
||||
"deep",
|
||||
"decred",
|
||||
"dmd-gr",
|
||||
"equihash",
|
||||
"exosis",
|
||||
"fresh",
|
||||
"fugue256",
|
||||
"groestl",
|
||||
"heavy",
|
||||
"hmq1725",
|
||||
"hsr",
|
||||
"keccak",
|
||||
"keccakc",
|
||||
"jackpot",
|
||||
"jha",
|
||||
"lbry",
|
||||
"luffa",
|
||||
"lyra2",
|
||||
"lyra2v2",
|
||||
"lyra2v3",
|
||||
"lyra2z",
|
||||
"mjollnir",
|
||||
"myr-gr",
|
||||
"neoscrypt",
|
||||
"nist5",
|
||||
"penta",
|
||||
"phi",
|
||||
"phi2",
|
||||
"polytimos",
|
||||
"quark",
|
||||
"qubit",
|
||||
"scrypt",
|
||||
"scrypt-jane",
|
||||
"sha256d",
|
||||
"sha256t",
|
||||
"sha256q",
|
||||
"sia",
|
||||
"sib",
|
||||
"skein",
|
||||
"skein2",
|
||||
"skunk",
|
||||
"sonoa",
|
||||
"s3",
|
||||
"timetravel",
|
||||
"tribus",
|
||||
"bitcore",
|
||||
"x11evo",
|
||||
"x11",
|
||||
"x12",
|
||||
"x13",
|
||||
"x14",
|
||||
"x15",
|
||||
"x16r",
|
||||
"x16s",
|
||||
"x17",
|
||||
"vanilla",
|
||||
"veltor",
|
||||
"whirlcoin",
|
||||
"whirlpool",
|
||||
"whirlpoolx",
|
||||
"wildkeccak",
|
||||
"zr5",
|
||||
"monero",
|
||||
"graft",
|
||||
"stellite",
|
||||
"auto", /* reserved for multi algo */
|
||||
""
|
||||
};
|
||||
@@ -181,38 +111,16 @@ static inline int algo_to_int(char* arg)
|
||||
// some aliases...
|
||||
if (!strcasecmp("all", arg))
|
||||
i = ALGO_AUTO;
|
||||
else if (!strcasecmp("cryptonight-light", arg))
|
||||
i = ALGO_CRYPTOLIGHT;
|
||||
else if (!strcasecmp("cryptonight-lite", arg))
|
||||
i = ALGO_CRYPTOLIGHT;
|
||||
else if (!strcasecmp("flax", arg))
|
||||
i = ALGO_C11;
|
||||
else if (!strcasecmp("diamond", arg))
|
||||
i = ALGO_DMD_GR;
|
||||
else if (!strcasecmp("equi", arg))
|
||||
i = ALGO_EQUIHASH;
|
||||
else if (!strcasecmp("doom", arg))
|
||||
i = ALGO_LUFFA;
|
||||
else if (!strcasecmp("hmq17", arg))
|
||||
i = ALGO_HMQ1725;
|
||||
else if (!strcasecmp("hshare", arg))
|
||||
i = ALGO_HSR;
|
||||
else if (!strcasecmp("lyra2re", arg))
|
||||
i = ALGO_LYRA2;
|
||||
else if (!strcasecmp("lyra2rev2", arg))
|
||||
i = ALGO_LYRA2v2;
|
||||
else if (!strcasecmp("lyra2rev3", arg))
|
||||
i = ALGO_LYRA2v3;
|
||||
else if (!strcasecmp("phi1612", arg))
|
||||
i = ALGO_PHI;
|
||||
else if (!strcasecmp("bitcoin", arg))
|
||||
i = ALGO_SHA256D;
|
||||
else if (!strcasecmp("sha256", arg))
|
||||
i = ALGO_SHA256D;
|
||||
else if (!strcasecmp("thorsriddle", arg))
|
||||
i = ALGO_VELTOR;
|
||||
else if (!strcasecmp("timetravel10", arg))
|
||||
i = ALGO_BITCORE;
|
||||
else if (!strcasecmp("whirl", arg))
|
||||
i = ALGO_WHIRLPOOL;
|
||||
else if (!strcasecmp("ziftr", arg))
|
||||
@@ -224,29 +132,4 @@ static inline int algo_to_int(char* arg)
|
||||
return i;
|
||||
}
|
||||
|
||||
static inline int get_cryptonight_algo(int fork)
|
||||
{
|
||||
int algo = ALGO_COUNT;
|
||||
|
||||
switch (fork) {
|
||||
case 8:
|
||||
algo = ALGO_GRAFT;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
algo = ALGO_MONERO;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
algo = ALGO_STELLITE;
|
||||
break;
|
||||
|
||||
default:
|
||||
algo = ALGO_CRYPTONIGHT;
|
||||
break;
|
||||
}
|
||||
|
||||
return algo;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,7 +8,7 @@
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version. See COPYING for more details.
|
||||
*/
|
||||
#define APIVERSION "1.9"
|
||||
#define APIVERSION "1.8"
|
||||
|
||||
#ifdef WIN32
|
||||
# define _WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
@@ -86,20 +86,13 @@ static struct IP4ACCESS *ipaccess = NULL;
|
||||
#define ALLIP4 "0.0.0.0"
|
||||
static const char *localaddr = "127.0.0.1";
|
||||
static const char *UNAVAILABLE = " - API will not be available";
|
||||
static const char *MUNAVAILABLE = " - API multicast listener will not be available";
|
||||
static char *buffer = NULL;
|
||||
static time_t startup = 0;
|
||||
static int bye = 0;
|
||||
|
||||
extern char *opt_api_bind;
|
||||
extern int opt_api_port;
|
||||
extern char *opt_api_allow;
|
||||
extern char *opt_api_groups;
|
||||
extern bool opt_api_mcast;
|
||||
extern char *opt_api_mcast_addr;
|
||||
extern char *opt_api_mcast_code;
|
||||
extern char *opt_api_mcast_des;
|
||||
extern int opt_api_mcast_port;
|
||||
extern int opt_api_listen; /* port */
|
||||
extern int opt_api_remote;
|
||||
|
||||
// current stratum...
|
||||
extern struct stratum_ctx stratum;
|
||||
@@ -119,14 +112,10 @@ static void gpustatus(int thr_id)
|
||||
|
||||
if (thr_id >= 0 && thr_id < opt_n_threads) {
|
||||
struct cgpu_info *cgpu = &thr_info[thr_id].gpu;
|
||||
double khashes_per_watt = 0;
|
||||
int gpuid = cgpu->gpu_id;
|
||||
char buf[512]; *buf = '\0';
|
||||
char* card;
|
||||
|
||||
cuda_gpu_info(cgpu);
|
||||
cgpu->gpu_plimit = device_plimit[cgpu->gpu_id];
|
||||
|
||||
#ifdef USE_WRAPNVML
|
||||
cgpu->has_monitoring = true;
|
||||
cgpu->gpu_bus = gpu_busid(cgpu);
|
||||
@@ -134,30 +123,23 @@ static void gpustatus(int thr_id)
|
||||
cgpu->gpu_fan = (uint16_t) gpu_fanpercent(cgpu);
|
||||
cgpu->gpu_fan_rpm = (uint16_t) gpu_fanrpm(cgpu);
|
||||
cgpu->gpu_power = gpu_power(cgpu); // mWatts
|
||||
cgpu->gpu_plimit = gpu_plimit(cgpu); // mW or %
|
||||
#endif
|
||||
cuda_gpu_clocks(cgpu);
|
||||
|
||||
// todo: per gpu
|
||||
cgpu->accepted = p->accepted_count;
|
||||
cgpu->rejected = p->rejected_count;
|
||||
|
||||
cgpu->khashes = stats_get_speed(thr_id, 0.0) / 1000.0;
|
||||
if (cgpu->monitor.gpu_power) {
|
||||
cgpu->gpu_power = cgpu->monitor.gpu_power;
|
||||
khashes_per_watt = (double)cgpu->khashes / cgpu->monitor.gpu_power;
|
||||
khashes_per_watt *= 1000; // power in mW
|
||||
//gpulog(LOG_BLUE, thr_id, "KHW: %g", khashes_per_watt);
|
||||
}
|
||||
|
||||
card = device_name[gpuid];
|
||||
|
||||
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;TEMP=%.1f;"
|
||||
"POWER=%u;FAN=%hu;RPM=%hu;"
|
||||
"FREQ=%u;MEMFREQ=%u;GPUF=%u;MEMF=%u;"
|
||||
"KHS=%.2f;KHW=%.5f;PLIM=%u;"
|
||||
"ACC=%u;REJ=%u;HWF=%u;I=%.1f;THR=%u|",
|
||||
"POWER=%u;FAN=%hu;RPM=%hu;FREQ=%d;KHS=%.2f;HWF=%d;I=%.1f;THR=%u|",
|
||||
gpuid, cgpu->gpu_bus, card, cgpu->gpu_temp,
|
||||
cgpu->gpu_power, cgpu->gpu_fan, cgpu->gpu_fan_rpm,
|
||||
cgpu->gpu_clock/1000, cgpu->gpu_memclock/1000, // base freqs in MHz
|
||||
cgpu->monitor.gpu_clock, cgpu->monitor.gpu_memclock, // current
|
||||
cgpu->khashes, khashes_per_watt, cgpu->gpu_plimit,
|
||||
cgpu->accepted, (unsigned) cgpu->rejected, (unsigned) cgpu->hw_errors,
|
||||
cgpu->intensity, cgpu->throughput);
|
||||
cgpu->gpu_clock, cgpu->khashes,
|
||||
cgpu->hw_errors, cgpu->intensity, cgpu->throughput);
|
||||
|
||||
// append to buffer for multi gpus
|
||||
strcat(buffer, buf);
|
||||
@@ -257,7 +239,7 @@ static char *getpoolnfo(char *params)
|
||||
|
||||
static void gpuhwinfos(int gpu_id)
|
||||
{
|
||||
char buf[512];
|
||||
char buf[256];
|
||||
char pstate[8];
|
||||
char* card;
|
||||
struct cgpu_info *cgpu = NULL;
|
||||
@@ -272,9 +254,6 @@ static void gpuhwinfos(int gpu_id)
|
||||
if (cgpu == NULL)
|
||||
return;
|
||||
|
||||
cuda_gpu_info(cgpu);
|
||||
cgpu->gpu_plimit = device_plimit[cgpu->gpu_id];
|
||||
|
||||
#ifdef USE_WRAPNVML
|
||||
cgpu->has_monitoring = true;
|
||||
cgpu->gpu_bus = gpu_busid(cgpu);
|
||||
@@ -283,28 +262,24 @@ static void gpuhwinfos(int gpu_id)
|
||||
cgpu->gpu_fan_rpm = (uint16_t) gpu_fanrpm(cgpu);
|
||||
cgpu->gpu_pstate = (int16_t) gpu_pstate(cgpu);
|
||||
cgpu->gpu_power = gpu_power(cgpu);
|
||||
cgpu->gpu_plimit = gpu_plimit(cgpu);
|
||||
gpu_info(cgpu);
|
||||
#ifdef WIN32
|
||||
if (opt_debug) nvapi_pstateinfo(cgpu->gpu_id);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
cuda_gpu_clocks(cgpu);
|
||||
|
||||
memset(pstate, 0, sizeof(pstate));
|
||||
if (cgpu->gpu_pstate != -1)
|
||||
snprintf(pstate, sizeof(pstate), "P%d", (int) cgpu->gpu_pstate);
|
||||
|
||||
card = device_name[gpu_id];
|
||||
|
||||
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;SM=%hu;MEM=%u;"
|
||||
"TEMP=%.1f;FAN=%hu;RPM=%hu;FREQ=%u;MEMFREQ=%u;GPUF=%u;MEMF=%u;"
|
||||
"PST=%s;POWER=%u;PLIM=%u;"
|
||||
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;SM=%u;MEM=%lu;"
|
||||
"TEMP=%.1f;FAN=%hu;RPM=%hu;FREQ=%d;MEMFREQ=%d;PST=%s;POWER=%u;"
|
||||
"VID=%hx;PID=%hx;NVML=%d;NVAPI=%d;SN=%s;BIOS=%s|",
|
||||
gpu_id, cgpu->gpu_bus, card, cgpu->gpu_arch, (uint32_t) cgpu->gpu_mem,
|
||||
gpu_id, cgpu->gpu_bus, card, cgpu->gpu_arch, cgpu->gpu_mem,
|
||||
cgpu->gpu_temp, cgpu->gpu_fan, cgpu->gpu_fan_rpm,
|
||||
cgpu->gpu_clock/1000U, cgpu->gpu_memclock/1000U, // base clocks
|
||||
cgpu->monitor.gpu_clock, cgpu->monitor.gpu_memclock, // current
|
||||
pstate, cgpu->gpu_power, cgpu->gpu_plimit,
|
||||
cgpu->gpu_clock, cgpu->gpu_memclock,
|
||||
pstate, cgpu->gpu_power,
|
||||
cgpu->gpu_vid, cgpu->gpu_pid, cgpu->nvml_id, cgpu->nvapi_id,
|
||||
cgpu->gpu_sn, cgpu->gpu_desc);
|
||||
|
||||
@@ -321,12 +296,8 @@ static const char* os_name()
|
||||
return "windows";
|
||||
#else
|
||||
FILE *fd = fopen("/proc/version", "r");
|
||||
if (!fd)
|
||||
if (!fd || !fscanf(fd, "Linux version %48s", &os_version[6]))
|
||||
return "linux";
|
||||
if (!fscanf(fd, "Linux version %48s", &os_version[6])) {
|
||||
fclose(fd);
|
||||
return "linux";
|
||||
}
|
||||
fclose(fd);
|
||||
os_version[48] = '\0';
|
||||
return (const char*) os_version;
|
||||
@@ -345,7 +316,7 @@ static void syshwinfos()
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
snprintf(buf, sizeof(buf), "OS=%s;NVDRIVER=%s;CPUS=%d;CPUTEMP=%d;CPUFREQ=%d|",
|
||||
os_name(), driver_version, num_cpus, cputc, cpuclk/1000);
|
||||
os_name(), driver_version, num_cpus, cputc, cpuclk);
|
||||
strcat(buffer, buf);
|
||||
}
|
||||
|
||||
@@ -376,7 +347,7 @@ static char *gethistory(char *params)
|
||||
*buffer = '\0';
|
||||
for (int i = 0; i < records; i++) {
|
||||
time_t ts = data[i].tm_stat;
|
||||
p += sprintf(p, "GPU=%d;H=%u;KHS=%.2f;DIFF=%g;"
|
||||
p += sprintf(p, "GPU=%d;H=%u;KHS=%.2f;DIFF=%.6f;"
|
||||
"COUNT=%u;FOUND=%u;ID=%u;TS=%u|",
|
||||
data[i].gpu_id, data[i].height, data[i].hashrate, data[i].difficulty,
|
||||
data[i].hashcount, data[i].hashfound, data[i].uid, (uint32_t)ts);
|
||||
@@ -385,7 +356,7 @@ static char *gethistory(char *params)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the job scans ranges (debug purpose, only with -D)
|
||||
* Returns the job scans ranges (debug purpose)
|
||||
*/
|
||||
static char *getscanlog(char *params)
|
||||
{
|
||||
@@ -395,11 +366,9 @@ static char *getscanlog(char *params)
|
||||
*buffer = '\0';
|
||||
for (int i = 0; i < records; i++) {
|
||||
time_t ts = data[i].tm_upd;
|
||||
p += sprintf(p, "H=%u;P=%u;JOB=%u;ID=%d;DIFF=%g;"
|
||||
"N=0x%x;FROM=0x%x;SCANTO=0x%x;"
|
||||
p += sprintf(p, "H=%u;P=%u;JOB=%u;N=%u;FROM=0x%x;SCANTO=0x%x;"
|
||||
"COUNT=0x%x;FOUND=%u;TS=%u|",
|
||||
data[i].height, data[i].npool, data[i].njobid, (int)data[i].job_nonce_id, data[i].sharediff,
|
||||
data[i].nonce, data[i].scanned_from, data[i].scanned_to,
|
||||
data[i].height, data[i].npool, data[i].njobid, data[i].nonce, data[i].scanned_from, data[i].scanned_to,
|
||||
(data[i].scanned_to - data[i].scanned_from), data[i].tm_sent ? 1 : 0, (uint32_t)ts);
|
||||
}
|
||||
return buffer;
|
||||
@@ -426,6 +395,15 @@ static char *getmeminfo(char *params)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Remote control allowed ?
|
||||
* TODO: ip filters
|
||||
*/
|
||||
static bool check_remote_access(void)
|
||||
{
|
||||
return (opt_api_remote > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set pool by index (pools array in json config)
|
||||
* switchpool|1|
|
||||
@@ -434,6 +412,8 @@ static char *remote_switchpool(char *params)
|
||||
{
|
||||
bool ret = false;
|
||||
*buffer = '\0';
|
||||
if (!check_remote_access())
|
||||
return buffer;
|
||||
if (!params || strlen(params) == 0) {
|
||||
// rotate pool test
|
||||
ret = pool_switch_next(-1);
|
||||
@@ -456,6 +436,8 @@ static char *remote_seturl(char *params)
|
||||
{
|
||||
bool ret;
|
||||
*buffer = '\0';
|
||||
if (!check_remote_access())
|
||||
return buffer;
|
||||
if (!params || strlen(params) == 0) {
|
||||
// rotate pool test
|
||||
ret = pool_switch_next(-1);
|
||||
@@ -472,6 +454,8 @@ static char *remote_seturl(char *params)
|
||||
static char *remote_quit(char *params)
|
||||
{
|
||||
*buffer = '\0';
|
||||
if (!check_remote_access())
|
||||
return buffer;
|
||||
bye = 1;
|
||||
sprintf(buffer, "%s", "bye|");
|
||||
return buffer;
|
||||
@@ -483,23 +467,22 @@ static char *gethelp(char *params);
|
||||
struct CMDS {
|
||||
const char *name;
|
||||
char *(*func)(char *);
|
||||
bool iswritemode;
|
||||
} cmds[] = {
|
||||
{ "summary", getsummary, false },
|
||||
{ "threads", getthreads, false },
|
||||
{ "pool", getpoolnfo, false },
|
||||
{ "histo", gethistory, false },
|
||||
{ "hwinfo", gethwinfos, false },
|
||||
{ "meminfo", getmeminfo, false },
|
||||
{ "scanlog", getscanlog, false },
|
||||
{ "summary", getsummary },
|
||||
{ "threads", getthreads },
|
||||
{ "pool", getpoolnfo },
|
||||
{ "histo", gethistory },
|
||||
{ "hwinfo", gethwinfos },
|
||||
{ "meminfo", getmeminfo },
|
||||
{ "scanlog", getscanlog },
|
||||
|
||||
/* remote functions */
|
||||
{ "seturl", remote_seturl, true }, /* prefer switchpool, deprecated */
|
||||
{ "switchpool", remote_switchpool, true },
|
||||
{ "quit", remote_quit, true },
|
||||
{ "seturl", remote_seturl }, /* prefer switchpool, deprecated */
|
||||
{ "switchpool", remote_switchpool },
|
||||
{ "quit", remote_quit },
|
||||
|
||||
/* keep it the last */
|
||||
{ "help", gethelp, false },
|
||||
{ "help", gethelp },
|
||||
};
|
||||
#define CMDMAX ARRAY_SIZE(cmds)
|
||||
|
||||
@@ -507,10 +490,8 @@ static char *gethelp(char *params)
|
||||
{
|
||||
*buffer = '\0';
|
||||
char * p = buffer;
|
||||
for (int i = 0; i < CMDMAX-1; i++) {
|
||||
bool displayed = !cmds[i].iswritemode || opt_api_allow;
|
||||
if (displayed) p += sprintf(p, "%s\n", cmds[i].name);
|
||||
}
|
||||
for (int i = 0; i < CMDMAX-1; i++)
|
||||
p += sprintf(p, "%s\n", cmds[i].name);
|
||||
sprintf(p, "|");
|
||||
return buffer;
|
||||
}
|
||||
@@ -673,146 +654,6 @@ static int websocket_handshake(SOCKETTYPE c, char *result, char *clientkey)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Interpret --api-groups G:cmd1:cmd2:cmd3,P:cmd4,*,...
|
||||
*/
|
||||
static void setup_groups()
|
||||
{
|
||||
const char *api_groups = opt_api_groups ? opt_api_groups : "";
|
||||
char *buf, *cmd, *ptr, *next, *colon;
|
||||
char commands[512] = { 0 };
|
||||
char cmdbuf[128] = { 0 };
|
||||
char group;
|
||||
bool addstar;
|
||||
int i;
|
||||
|
||||
buf = (char *)calloc(1, strlen(api_groups) + 1);
|
||||
if (unlikely(!buf))
|
||||
proper_exit(1); //, "Failed to malloc ipgroups buf");
|
||||
|
||||
strcpy(buf, api_groups);
|
||||
|
||||
next = buf;
|
||||
// for each group defined
|
||||
while (next && *next) {
|
||||
ptr = next;
|
||||
next = strchr(ptr, ',');
|
||||
if (next)
|
||||
*(next++) = '\0';
|
||||
|
||||
// Validate the group
|
||||
if (*(ptr+1) != ':') {
|
||||
colon = strchr(ptr, ':');
|
||||
if (colon)
|
||||
*colon = '\0';
|
||||
proper_exit(1); //, "API invalid group name '%s'", ptr);
|
||||
}
|
||||
|
||||
group = GROUP(*ptr);
|
||||
if (!VALIDGROUP(group))
|
||||
proper_exit(1); //, "API invalid group name '%c'", *ptr);
|
||||
|
||||
if (group == PRIVGROUP)
|
||||
proper_exit(1); //, "API group name can't be '%c'", PRIVGROUP);
|
||||
|
||||
if (group == NOPRIVGROUP)
|
||||
proper_exit(1); //, "API group name can't be '%c'", NOPRIVGROUP);
|
||||
|
||||
if (apigroups[GROUPOFFSET(group)].commands != NULL)
|
||||
proper_exit(1); //, "API duplicate group name '%c'", *ptr);
|
||||
|
||||
ptr += 2;
|
||||
|
||||
// Validate the command list (and handle '*')
|
||||
cmd = &(commands[0]);
|
||||
*(cmd++) = '|';
|
||||
*cmd = '\0';
|
||||
addstar = false;
|
||||
while (ptr && *ptr) {
|
||||
colon = strchr(ptr, ':');
|
||||
if (colon)
|
||||
*(colon++) = '\0';
|
||||
|
||||
if (strcmp(ptr, "*") == 0)
|
||||
addstar = true;
|
||||
else {
|
||||
bool did = false;
|
||||
for (i = 0; i < CMDMAX-1; i++) {
|
||||
if (strcasecmp(ptr, cmds[i].name) == 0) {
|
||||
did = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (did) {
|
||||
// skip duplicates
|
||||
sprintf(cmdbuf, "|%s|", cmds[i].name);
|
||||
if (strstr(commands, cmdbuf) == NULL) {
|
||||
strcpy(cmd, cmds[i].name);
|
||||
cmd += strlen(cmds[i].name);
|
||||
*(cmd++) = '|';
|
||||
*cmd = '\0';
|
||||
}
|
||||
} else {
|
||||
proper_exit(1); //, "API unknown command '%s' in group '%c'", ptr, group);
|
||||
}
|
||||
}
|
||||
|
||||
ptr = colon;
|
||||
}
|
||||
|
||||
// * = allow all non-iswritemode commands
|
||||
if (addstar) {
|
||||
for (i = 0; i < CMDMAX-1; i++) {
|
||||
if (cmds[i].iswritemode == false) {
|
||||
// skip duplicates
|
||||
sprintf(cmdbuf, "|%s|", cmds[i].name);
|
||||
if (strstr(commands, cmdbuf) == NULL) {
|
||||
strcpy(cmd, cmds[i].name);
|
||||
cmd += strlen(cmds[i].name);
|
||||
*(cmd++) = '|';
|
||||
*cmd = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ptr = apigroups[GROUPOFFSET(group)].commands = (char *)calloc(1, strlen(commands) + 1);
|
||||
if (unlikely(!ptr))
|
||||
proper_exit(1); //, "Failed to malloc group commands buf");
|
||||
|
||||
strcpy(ptr, commands);
|
||||
}
|
||||
|
||||
// Now define R (NOPRIVGROUP) as all non-iswritemode commands
|
||||
cmd = &(commands[0]);
|
||||
*(cmd++) = '|';
|
||||
*cmd = '\0';
|
||||
for (i = 0; i < CMDMAX-1; i++) {
|
||||
if (cmds[i].iswritemode == false) {
|
||||
strcpy(cmd, cmds[i].name);
|
||||
cmd += strlen(cmds[i].name);
|
||||
*(cmd++) = '|';
|
||||
*cmd = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
ptr = apigroups[GROUPOFFSET(NOPRIVGROUP)].commands = (char *)calloc(1, strlen(commands) + 1);
|
||||
if (unlikely(!ptr))
|
||||
proper_exit(1); //, "Failed to malloc noprivgroup commands buf");
|
||||
|
||||
strcpy(ptr, commands);
|
||||
|
||||
// W (PRIVGROUP) is handled as a special case since it simply means all commands
|
||||
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Interpret [W:]IP[/Prefix][,[R|W:]IP2[/Prefix2][,...]] --api-allow option
|
||||
* special case of 0/0 allows /0 (means all IP addresses)
|
||||
*/
|
||||
#define ALLIPS "0/0"
|
||||
/*
|
||||
* N.B. IP4 addresses are by Definition 32bit big endian on all platforms
|
||||
*/
|
||||
@@ -862,7 +703,7 @@ static void setup_ipaccess()
|
||||
|
||||
ipaccess[ips].group = group;
|
||||
|
||||
if (strcmp(ptr, ALLIPS) == 0 || strcmp(ptr, ALLIP4) == 0)
|
||||
if (strcmp(ptr, ALLIP4) == 0)
|
||||
ipaccess[ips].ip = ipaccess[ips].mask = 0;
|
||||
else
|
||||
{
|
||||
@@ -925,184 +766,16 @@ static bool check_connect(struct sockaddr_in *cli, char **connectaddr, char *gro
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (strcmp(opt_api_bind, ALLIP4) == 0)
|
||||
addrok = true;
|
||||
else
|
||||
addrok = (strcmp(*connectaddr, localaddr) == 0);
|
||||
|
||||
return addrok;
|
||||
}
|
||||
|
||||
static void mcast()
|
||||
{
|
||||
struct sockaddr_in listen;
|
||||
struct ip_mreq grp;
|
||||
struct sockaddr_in came_from;
|
||||
time_t bindstart;
|
||||
char *binderror;
|
||||
SOCKETTYPE mcast_sock;
|
||||
SOCKETTYPE reply_sock;
|
||||
socklen_t came_from_siz;
|
||||
char *connectaddr;
|
||||
ssize_t rep;
|
||||
int bound;
|
||||
int count;
|
||||
int reply_port;
|
||||
bool addrok;
|
||||
char group;
|
||||
|
||||
char expect[] = "ccminer-"; // first 8 bytes constant
|
||||
char *expect_code;
|
||||
size_t expect_code_len;
|
||||
char buf[1024];
|
||||
char replybuf[1024];
|
||||
|
||||
memset(&grp, 0, sizeof(grp));
|
||||
grp.imr_multiaddr.s_addr = inet_addr(opt_api_mcast_addr);
|
||||
if (grp.imr_multiaddr.s_addr == INADDR_NONE)
|
||||
proper_exit(1); //, "Invalid Multicast Address");
|
||||
grp.imr_interface.s_addr = INADDR_ANY;
|
||||
|
||||
mcast_sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
int optval = 1;
|
||||
if (SOCKETFAIL(setsockopt(mcast_sock, SOL_SOCKET, SO_REUSEADDR, (const char *)(&optval), sizeof(optval)))) {
|
||||
applog(LOG_ERR, "API mcast setsockopt SO_REUSEADDR failed (%s)%s", strerror(errno), MUNAVAILABLE);
|
||||
goto die;
|
||||
}
|
||||
|
||||
memset(&listen, 0, sizeof(listen));
|
||||
listen.sin_family = AF_INET;
|
||||
listen.sin_addr.s_addr = INADDR_ANY;
|
||||
listen.sin_port = htons(opt_api_mcast_port);
|
||||
|
||||
// try for more than 1 minute ... in case the old one hasn't completely gone yet
|
||||
bound = 0;
|
||||
bindstart = time(NULL);
|
||||
while (bound == 0) {
|
||||
if (SOCKETFAIL(bind(mcast_sock, (struct sockaddr *)(&listen), sizeof(listen)))) {
|
||||
binderror = strerror(errno);;
|
||||
if ((time(NULL) - bindstart) > 61)
|
||||
break;
|
||||
else
|
||||
sleep(30);
|
||||
}
|
||||
else
|
||||
bound = 1;
|
||||
}
|
||||
|
||||
if (bound == 0) {
|
||||
applog(LOG_ERR, "API mcast bind to port %d failed (%s)%s", opt_api_port, binderror, MUNAVAILABLE);
|
||||
goto die;
|
||||
}
|
||||
|
||||
if (SOCKETFAIL(setsockopt(mcast_sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char *)(&grp), sizeof(grp)))) {
|
||||
applog(LOG_ERR, "API mcast join failed (%s)%s", strerror(errno), MUNAVAILABLE);
|
||||
goto die;
|
||||
}
|
||||
|
||||
expect_code_len = sizeof(expect) + strlen(opt_api_mcast_code);
|
||||
expect_code = (char *)calloc(1, expect_code_len + 1);
|
||||
if (!expect_code)
|
||||
proper_exit(1); //, "Failed to malloc mcast expect_code");
|
||||
snprintf(expect_code, expect_code_len + 1, "%s%s-", expect, opt_api_mcast_code);
|
||||
|
||||
count = 0;
|
||||
while (42) {
|
||||
sleep(1);
|
||||
|
||||
count++;
|
||||
came_from_siz = sizeof(came_from);
|
||||
if (SOCKETFAIL(rep = recvfrom(mcast_sock, buf, sizeof(buf) - 1,
|
||||
0, (struct sockaddr *)(&came_from), &came_from_siz))) {
|
||||
applog(LOG_DEBUG, "API mcast failed count=%d (%s) (%d)",
|
||||
count, strerror(errno), (int)mcast_sock);
|
||||
continue;
|
||||
}
|
||||
|
||||
addrok = check_connect(&came_from, &connectaddr, &group);
|
||||
applog(LOG_DEBUG, "API mcast from %s - %s",
|
||||
connectaddr, addrok ? "Accepted" : "Ignored");
|
||||
if (!addrok) {
|
||||
continue;
|
||||
}
|
||||
|
||||
buf[rep] = '\0';
|
||||
if (rep > 0 && buf[rep - 1] == '\n')
|
||||
buf[--rep] = '\0';
|
||||
|
||||
applog(LOG_DEBUG, "API mcast request rep=%d (%s) from %s:%d",
|
||||
(int)rep, buf,
|
||||
inet_ntoa(came_from.sin_addr),
|
||||
ntohs(came_from.sin_port));
|
||||
|
||||
if ((size_t)rep > expect_code_len && memcmp(buf, expect_code, expect_code_len) == 0) {
|
||||
reply_port = atoi(&buf[expect_code_len]);
|
||||
if (reply_port < 1 || reply_port > 65535) {
|
||||
applog(LOG_DEBUG, "API mcast request ignored - invalid port (%s)",
|
||||
&buf[expect_code_len]);
|
||||
}
|
||||
else {
|
||||
applog(LOG_DEBUG, "API mcast request OK port %s=%d",
|
||||
&buf[expect_code_len], reply_port);
|
||||
|
||||
came_from.sin_port = htons(reply_port);
|
||||
reply_sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
snprintf(replybuf, sizeof(replybuf),
|
||||
"ccm-%s-%d-%s", opt_api_mcast_code, opt_api_port, opt_api_mcast_des);
|
||||
|
||||
rep = sendto(reply_sock, replybuf, (int) strlen(replybuf) + 1,
|
||||
0, (struct sockaddr *)(&came_from), (int) sizeof(came_from));
|
||||
if (SOCKETFAIL(rep)) {
|
||||
applog(LOG_DEBUG, "API mcast send reply failed (%s) (%d)",
|
||||
strerror(errno), (int)reply_sock);
|
||||
} else {
|
||||
applog(LOG_DEBUG, "API mcast send reply (%s) succeeded (%d) (%d)",
|
||||
replybuf, (int)rep, (int)reply_sock);
|
||||
}
|
||||
|
||||
CLOSESOCKET(reply_sock);
|
||||
}
|
||||
}
|
||||
else
|
||||
applog(LOG_DEBUG, "API mcast request was no good");
|
||||
}
|
||||
|
||||
die:
|
||||
CLOSESOCKET(mcast_sock);
|
||||
}
|
||||
|
||||
static void *mcast_thread(void *userdata)
|
||||
{
|
||||
struct thr_info *mythr = (struct thr_info *)userdata;
|
||||
|
||||
pthread_detach(pthread_self());
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
|
||||
mcast();
|
||||
|
||||
//PTH(mythr) = 0L;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void mcast_init()
|
||||
{
|
||||
struct thr_info *thr;
|
||||
|
||||
thr = (struct thr_info *)calloc(1, sizeof(*thr));
|
||||
if (!thr)
|
||||
proper_exit(1); //, "Failed to calloc mcast thr");
|
||||
|
||||
if (unlikely(pthread_create(&thr->pth, NULL, mcast_thread, thr)))
|
||||
proper_exit(1); //, "API mcast thread create failed");
|
||||
}
|
||||
|
||||
static void api()
|
||||
{
|
||||
const char *addr = opt_api_bind;
|
||||
unsigned short port = (unsigned short) opt_api_port; // 4068
|
||||
const char *addr = opt_api_allow;
|
||||
unsigned short port = (unsigned short) opt_api_listen; // 4068
|
||||
char buf[MYBUFSIZ];
|
||||
int n, bound;
|
||||
char *connectaddr;
|
||||
@@ -1120,13 +793,11 @@ static void api()
|
||||
|
||||
SOCKETTYPE c;
|
||||
SOCKETTYPE *apisock;
|
||||
if (!opt_api_port && opt_debug) {
|
||||
if (!opt_api_listen && opt_debug) {
|
||||
applog(LOG_DEBUG, "API disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
setup_groups();
|
||||
|
||||
if (opt_api_allow) {
|
||||
setup_ipaccess();
|
||||
if (ips == 0) {
|
||||
@@ -1147,10 +818,9 @@ static void api()
|
||||
|
||||
memset(&serv, 0, sizeof(serv));
|
||||
serv.sin_family = AF_INET;
|
||||
serv.sin_addr.s_addr = inet_addr(addr); // TODO: allow bind to ip/interface
|
||||
serv.sin_addr.s_addr = inet_addr(addr);
|
||||
if (serv.sin_addr.s_addr == (in_addr_t)INVINETADDR) {
|
||||
applog(LOG_ERR, "API initialisation 2 failed (%s)%s", strerror(errno), UNAVAILABLE);
|
||||
// free(apisock); FIXME!!
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1178,7 +848,7 @@ static void api()
|
||||
binderror = strerror(errno);
|
||||
if ((time(NULL) - bindstart) > 61)
|
||||
break;
|
||||
else if (opt_api_port == 4068) {
|
||||
else if (opt_api_listen == 4068) {
|
||||
/* when port is default one, use first available */
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG, "API bind to port %d failed, trying port %u",
|
||||
@@ -1195,10 +865,10 @@ static void api()
|
||||
}
|
||||
else {
|
||||
bound = 1;
|
||||
if (opt_api_port != port) {
|
||||
if (opt_api_listen != port) {
|
||||
applog(LOG_WARNING, "API bind to port %d failed - using port %u",
|
||||
opt_api_port, (uint32_t)port);
|
||||
opt_api_port = port;
|
||||
opt_api_listen, (uint32_t) port);
|
||||
opt_api_listen = port;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1216,16 +886,6 @@ static void api()
|
||||
return;
|
||||
}
|
||||
|
||||
if (opt_api_allow && strcmp(opt_api_bind, "127.0.0.1") == 0)
|
||||
applog(LOG_WARNING, "API open locally in full access mode on port %d", opt_api_port);
|
||||
else if (opt_api_allow)
|
||||
applog(LOG_WARNING, "API open in full access mode to %s on port %d", opt_api_allow, opt_api_port);
|
||||
else if (strcmp(opt_api_bind, "127.0.0.1") != 0)
|
||||
applog(LOG_INFO, "API open to the network in read-only mode on port %d", opt_api_port);
|
||||
|
||||
if (opt_api_mcast)
|
||||
mcast_init();
|
||||
|
||||
buffer = (char *) calloc(1, MYBUFSIZ + 1);
|
||||
|
||||
counter = 0;
|
||||
@@ -1252,7 +912,7 @@ static void api()
|
||||
char *wskey = NULL;
|
||||
n = recv(c, &buf[0], SOCK_REC_BUFSZ, 0);
|
||||
|
||||
fail = SOCKETFAIL(n) || n < 0;
|
||||
fail = SOCKETFAIL(n);
|
||||
if (fail)
|
||||
buf[0] = '\0';
|
||||
else if (n > 0 && buf[n-1] == '\n') {
|
||||
@@ -1261,7 +921,7 @@ static void api()
|
||||
if (n > 0 && buf[n-1] == '\r')
|
||||
buf[n-1] = '\0';
|
||||
}
|
||||
else buf[n] = '\0';
|
||||
buf[n] = '\0';
|
||||
|
||||
//if (opt_debug && opt_protocol && n > 0)
|
||||
// applog(LOG_DEBUG, "API: recv command: (%d) '%s'+char(%x)", n, buf, buf[n-1]);
|
||||
@@ -1312,8 +972,8 @@ static void api()
|
||||
break;
|
||||
}
|
||||
}
|
||||
CLOSESOCKET(c);
|
||||
}
|
||||
CLOSESOCKET(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1344,8 +1004,16 @@ void api_set_throughput(int thr_id, uint32_t throughput)
|
||||
{
|
||||
if (thr_id < MAX_GPUS && thr_info) {
|
||||
struct cgpu_info *cgpu = &thr_info[thr_id].gpu;
|
||||
cgpu->intensity = throughput2intensity(throughput);
|
||||
if (cgpu->throughput != throughput) cgpu->throughput = throughput;
|
||||
uint32_t ws = throughput;
|
||||
uint8_t i = 0;
|
||||
cgpu->throughput = throughput;
|
||||
while (ws > 1 && i++ < 32)
|
||||
ws = ws >> 1;
|
||||
cgpu->intensity_int = i;
|
||||
cgpu->intensity = (float) i;
|
||||
if (i && (1U << i) < throughput) {
|
||||
cgpu->intensity += ((float) (throughput-(1U << i)) / (1U << i));
|
||||
}
|
||||
}
|
||||
// to display in bench results
|
||||
if (opt_benchmark)
|
||||
|
||||
+3
-16
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/* ccminer API sample UI (API 1.9) */
|
||||
/* ccminer API sample UI (API 1.7) */
|
||||
|
||||
$host = 'http://localhost/api/'; // 'http://'.$_SERVER['SERVER_NAME'].'/api/';
|
||||
$configs = array(
|
||||
@@ -65,14 +65,8 @@ function translateField($key)
|
||||
|
||||
$intl['TEMP'] = 'T°c';
|
||||
$intl['FAN'] = 'Fan %';
|
||||
$intl['CPUFREQ'] = 'CPU Freq.';
|
||||
$intl['FREQ'] = 'Base Freq.';
|
||||
$intl['MEMFREQ'] = 'Mem. Freq.';
|
||||
$intl['GPUF'] = 'Curr Freq.';
|
||||
$intl['MEMF'] = 'Mem. Freq.';
|
||||
$intl['KHW'] = 'Efficiency';
|
||||
$intl['FREQ'] = 'Freq.';
|
||||
$intl['POWER'] = 'Power';
|
||||
$intl['PLIM'] = 'P.Limit';
|
||||
$intl['PST'] = 'P-State';
|
||||
|
||||
// pool infos
|
||||
@@ -104,12 +98,8 @@ function translateValue($key,$val,$data=array())
|
||||
case 'NAME':
|
||||
$val = $data['NAME'].' '.$data['VER'];
|
||||
break;
|
||||
case 'CPUFREQ':
|
||||
case 'FREQ':
|
||||
case 'MEMFREQ':
|
||||
case 'GPUF':
|
||||
case 'MEMF':
|
||||
$val = sprintf("%d MHz", $val);
|
||||
$val = sprintf("%d MHz", round(floatval($val)/1000.0));
|
||||
break;
|
||||
case 'POWER':
|
||||
$val = sprintf("%d W", round(floatval($val)/1000.0));
|
||||
@@ -121,9 +111,6 @@ function translateValue($key,$val,$data=array())
|
||||
case 'NETKHS':
|
||||
$val = '<span class="bold">'.$val.'</span> kH/s';
|
||||
break;
|
||||
case 'KHW':
|
||||
$val = $val.' kH/W';
|
||||
break;
|
||||
case 'NAME':
|
||||
case 'POOL';
|
||||
case 'USER':
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# sample script to query ccminer API
|
||||
|
||||
my $command = "summary|";
|
||||
|
||||
use Socket;
|
||||
use IO::Socket::INET;
|
||||
|
||||
my $sock = new IO::Socket::INET (
|
||||
PeerAddr => '127.0.0.1',
|
||||
PeerPort => 4068,
|
||||
Proto => 'tcp',
|
||||
ReuseAddr => 1,
|
||||
Timeout => 10,
|
||||
);
|
||||
|
||||
if ($sock) {
|
||||
|
||||
print $sock $command;
|
||||
my $res = "";
|
||||
|
||||
while(<$sock>) {
|
||||
$res .= $_;
|
||||
}
|
||||
|
||||
close($sock);
|
||||
print("$res\n");
|
||||
|
||||
} else {
|
||||
|
||||
print("ccminer socket failed\n");
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="http://code.highcharts.com/highcharts.js"></script>
|
||||
<script src="http://code.highcharts.com/modules/exporting.js"></script>
|
||||
</head>
|
||||
|
||||
@@ -8,11 +8,6 @@
|
||||
|
||||
#include "miner.h"
|
||||
#include "algos.h"
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "compat/pthreads/pthread_barrier.hpp"
|
||||
#endif
|
||||
|
||||
int bench_algo = -1;
|
||||
|
||||
@@ -49,76 +44,42 @@ void bench_free()
|
||||
void algo_free_all(int thr_id)
|
||||
{
|
||||
// only initialized algos will be freed
|
||||
free_allium(thr_id);
|
||||
free_bastion(thr_id);
|
||||
free_bitcore(thr_id);
|
||||
free_blake256(thr_id);
|
||||
free_blake2b(thr_id);
|
||||
free_blake2s(thr_id);
|
||||
free_bmw(thr_id);
|
||||
free_c11(thr_id);
|
||||
free_cryptolight(thr_id);
|
||||
free_cryptonight(thr_id);
|
||||
free_decred(thr_id);
|
||||
free_deep(thr_id);
|
||||
free_equihash(thr_id);
|
||||
free_exosis(thr_id);
|
||||
free_keccak256(thr_id);
|
||||
free_fresh(thr_id);
|
||||
free_fugue256(thr_id);
|
||||
free_groestlcoin(thr_id);
|
||||
#ifdef WITH_HEAVY_ALGO
|
||||
free_heavy(thr_id);
|
||||
#endif
|
||||
free_hmq17(thr_id);
|
||||
free_hsr(thr_id);
|
||||
free_jackpot(thr_id);
|
||||
free_jha(thr_id);
|
||||
free_lbry(thr_id);
|
||||
free_luffa(thr_id);
|
||||
free_lyra2(thr_id);
|
||||
free_lyra2v2(thr_id);
|
||||
free_lyra2v3(thr_id);
|
||||
free_lyra2Z(thr_id);
|
||||
free_myriad(thr_id);
|
||||
free_neoscrypt(thr_id);
|
||||
free_nist5(thr_id);
|
||||
free_pentablake(thr_id);
|
||||
free_phi(thr_id);
|
||||
free_phi2(thr_id);
|
||||
free_polytimos(thr_id);
|
||||
free_quark(thr_id);
|
||||
free_qubit(thr_id);
|
||||
free_skeincoin(thr_id);
|
||||
free_skein2(thr_id);
|
||||
free_skunk(thr_id);
|
||||
free_sha256d(thr_id);
|
||||
free_sha256t(thr_id);
|
||||
free_sha256q(thr_id);
|
||||
free_sia(thr_id);
|
||||
free_sib(thr_id);
|
||||
free_sonoa(thr_id);
|
||||
free_s3(thr_id);
|
||||
free_vanilla(thr_id);
|
||||
free_veltor(thr_id);
|
||||
free_whirl(thr_id);
|
||||
//free_whirlx(thr_id);
|
||||
free_wildkeccak(thr_id);
|
||||
free_x11evo(thr_id);
|
||||
free_x11(thr_id);
|
||||
free_x12(thr_id);
|
||||
free_x13(thr_id);
|
||||
free_x14(thr_id);
|
||||
free_x15(thr_id);
|
||||
free_x16r(thr_id);
|
||||
free_x16s(thr_id);
|
||||
free_x17(thr_id);
|
||||
free_zr5(thr_id);
|
||||
//free_sha256d(thr_id);
|
||||
free_scrypt(thr_id);
|
||||
free_scrypt_jane(thr_id);
|
||||
free_timetravel(thr_id);
|
||||
free_tribus(thr_id);
|
||||
free_bitcore(thr_id);
|
||||
}
|
||||
|
||||
// benchmark all algos (called once per mining thread)
|
||||
@@ -137,22 +98,14 @@ bool bench_algo_switch_next(int thr_id)
|
||||
// skip some duplicated algos
|
||||
if (algo == ALGO_C11) algo++; // same as x11
|
||||
if (algo == ALGO_DMD_GR) algo++; // same as groestl
|
||||
if (algo == ALGO_HEAVY) algo++; // dead
|
||||
if (algo == ALGO_MJOLLNIR) algo++; // same as heavy
|
||||
if (algo == ALGO_KECCAKC) algo++; // same as keccak
|
||||
if (algo == ALGO_WHIRLCOIN) algo++; // same as whirlpool
|
||||
if (algo == ALGO_WHIRLPOOLX) algo++; // disabled
|
||||
// todo: algo switch from RPC 2.0
|
||||
if (algo == ALGO_CRYPTOLIGHT) algo++;
|
||||
if (algo == ALGO_CRYPTONIGHT) algo++;
|
||||
if (algo == ALGO_WILDKECCAK) algo++;
|
||||
if (algo == ALGO_QUARK) algo++; // to fix
|
||||
if (algo == ALGO_LBRY && CUDART_VERSION < 7000) algo++;
|
||||
|
||||
if (device_sm[dev_id] && device_sm[dev_id] < 300) {
|
||||
// incompatible SM 2.1 kernels...
|
||||
if (algo == ALGO_GROESTL) algo++;
|
||||
if (algo == ALGO_MYR_GR) algo++;
|
||||
if (algo == ALGO_JACKPOT) algo++; // compact shuffle
|
||||
if (algo == ALGO_NEOSCRYPT) algo++;
|
||||
if (algo == ALGO_WHIRLPOOLX) algo++;
|
||||
}
|
||||
@@ -160,22 +113,6 @@ bool bench_algo_switch_next(int thr_id)
|
||||
if (algo == ALGO_SCRYPT) algo++;
|
||||
if (algo == ALGO_SCRYPT_JANE) algo++;
|
||||
|
||||
// Set cryptonight variant
|
||||
switch (algo) {
|
||||
case ALGO_MONERO:
|
||||
cryptonight_fork = 7;
|
||||
break;
|
||||
case ALGO_GRAFT:
|
||||
cryptonight_fork = 8;
|
||||
break;
|
||||
case ALGO_STELLITE:
|
||||
cryptonight_fork = 3;
|
||||
break;
|
||||
case ALGO_CRYPTONIGHT:
|
||||
cryptonight_fork = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// free current algo memory and track mem usage
|
||||
mused = cuda_available_memory(thr_id);
|
||||
algo_free_all(thr_id);
|
||||
|
||||
+6
-20
@@ -5,13 +5,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "uint256.h"
|
||||
|
||||
#include <openssl/opensslv.h>
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
#include "compat/bignum_ssl10.hpp"
|
||||
#else
|
||||
#include "bignum.hpp"
|
||||
#endif
|
||||
|
||||
#include "miner.h" // hex2bin
|
||||
|
||||
@@ -76,25 +70,17 @@ extern "C" double bn_hash_target_ratio(uint32_t* hash, uint32_t* target)
|
||||
}
|
||||
|
||||
// store ratio in work struct
|
||||
extern "C" void bn_store_hash_target_ratio(uint32_t* hash, uint32_t* target, struct work* work, int nonce)
|
||||
extern "C" void bn_store_hash_target_ratio(uint32_t* hash, uint32_t* target, struct work* work)
|
||||
{
|
||||
// only if the option is enabled (to reduce cpu usage)
|
||||
if (!opt_showdiff) return;
|
||||
if (nonce < 0 || nonce >= MAX_NONCES) return;
|
||||
|
||||
work->shareratio[nonce] = bn_hash_target_ratio(hash, target);
|
||||
work->sharediff[nonce] = work->targetdiff * work->shareratio[nonce];
|
||||
if (opt_showdiff) {
|
||||
work->shareratio = bn_hash_target_ratio(hash, target);
|
||||
work->sharediff = work->targetdiff * work->shareratio;
|
||||
}
|
||||
}
|
||||
|
||||
// new method to save all nonce(s) share diff/ration
|
||||
extern "C" void bn_set_target_ratio(struct work* work, uint32_t* hash, int nonce)
|
||||
{
|
||||
bn_store_hash_target_ratio(hash, work->target, work, nonce);
|
||||
}
|
||||
|
||||
// compat (only store single nonce share diff per work)
|
||||
extern "C" void work_set_target_ratio(struct work* work, uint32_t* hash)
|
||||
{
|
||||
bn_store_hash_target_ratio(hash, work->target, work, work->submit_nonce_id);
|
||||
bn_store_hash_target_ratio(hash, work->target, work);
|
||||
}
|
||||
|
||||
+129
-111
@@ -9,13 +9,20 @@
|
||||
#define PROTOCOL_VERSION 70001
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "uint256.h"
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include "serialize.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** Errors thrown by the bignum class */
|
||||
class bignum_error : public std::runtime_error
|
||||
{
|
||||
@@ -53,90 +60,75 @@ public:
|
||||
|
||||
|
||||
/** C++ wrapper for BIGNUM (OpenSSL bignum) */
|
||||
class CBigNum
|
||||
class CBigNum : public BIGNUM
|
||||
{
|
||||
private:
|
||||
BIGNUM *self = NULL;
|
||||
|
||||
void init()
|
||||
{
|
||||
if (self)
|
||||
BN_clear_free(self);
|
||||
self = BN_new();
|
||||
if (!self)
|
||||
throw bignum_error("CBigNum::init(): BN_new() returned NULL");
|
||||
}
|
||||
|
||||
public:
|
||||
BIGNUM *get() { return self; }
|
||||
const BIGNUM *getc() const { return self; }
|
||||
|
||||
CBigNum()
|
||||
{
|
||||
init();
|
||||
BN_init(this);
|
||||
}
|
||||
|
||||
CBigNum(const CBigNum& b)
|
||||
{
|
||||
init();
|
||||
if (!BN_copy(self, b.getc()))
|
||||
BN_init(this);
|
||||
if (!BN_copy(this, &b))
|
||||
{
|
||||
BN_clear_free(self);
|
||||
BN_clear_free(this);
|
||||
throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed");
|
||||
}
|
||||
}
|
||||
|
||||
CBigNum& operator=(const CBigNum& b)
|
||||
{
|
||||
if (!BN_copy(self, b.getc()))
|
||||
if (!BN_copy(this, &b))
|
||||
throw bignum_error("CBigNum::operator= : BN_copy failed");
|
||||
return (*this);
|
||||
}
|
||||
|
||||
~CBigNum()
|
||||
{
|
||||
BN_clear_free(self);
|
||||
BN_clear_free(this);
|
||||
}
|
||||
|
||||
//CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
|
||||
CBigNum(signed char n) { init(); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(short n) { init(); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(int n) { init(); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(long n) { init(); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(int64 n) { init(); setint64(n); }
|
||||
CBigNum(unsigned char n) { init(); setulong(n); }
|
||||
CBigNum(unsigned short n) { init(); setulong(n); }
|
||||
CBigNum(unsigned int n) { init(); setulong(n); }
|
||||
CBigNum(unsigned long n) { init(); setulong(n); }
|
||||
CBigNum(uint64 n) { init(); setuint64(n); }
|
||||
explicit CBigNum(uint256 n) { init(); setuint256(n); }
|
||||
CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(int64 n) { BN_init(this); setint64(n); }
|
||||
CBigNum(unsigned char n) { BN_init(this); setulong(n); }
|
||||
CBigNum(unsigned short n) { BN_init(this); setulong(n); }
|
||||
CBigNum(unsigned int n) { BN_init(this); setulong(n); }
|
||||
CBigNum(unsigned long n) { BN_init(this); setulong(n); }
|
||||
CBigNum(uint64 n) { BN_init(this); setuint64(n); }
|
||||
explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); }
|
||||
|
||||
explicit CBigNum(const std::vector<unsigned char>& vch)
|
||||
{
|
||||
init();
|
||||
BN_init(this);
|
||||
setvch(vch);
|
||||
}
|
||||
|
||||
void setulong(unsigned long n)
|
||||
{
|
||||
if (!BN_set_word(self, n))
|
||||
if (!BN_set_word(this, n))
|
||||
throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed");
|
||||
}
|
||||
|
||||
unsigned long getulong() const
|
||||
{
|
||||
return BN_get_word(self);
|
||||
return (unsigned long) BN_get_word(this);
|
||||
}
|
||||
|
||||
unsigned int getuint() const
|
||||
{
|
||||
return BN_get_word(self);
|
||||
return (unsigned int) BN_get_word(this);
|
||||
}
|
||||
|
||||
int getint() const
|
||||
{
|
||||
unsigned long n = BN_get_word(self);
|
||||
if (!BN_is_negative(self))
|
||||
unsigned long n = (unsigned long) BN_get_word(this);
|
||||
if (!BN_is_negative(this))
|
||||
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
|
||||
else
|
||||
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
|
||||
@@ -149,9 +141,11 @@ public:
|
||||
bool fNegative;
|
||||
uint64 n;
|
||||
|
||||
if (sn < (int64)0)
|
||||
if (sn < 0LL)
|
||||
{
|
||||
// Since the minimum signed integer cannot be represented as positive so long as its type is signed, and it's not well-defined what happens if you make it unsigned before negating it, we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
|
||||
// Since the minimum signed integer cannot be represented as positive so long as its type is signed,
|
||||
// and it's not well-defined what happens if you make it unsigned before negating it,
|
||||
// we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
|
||||
n = -(sn + 1);
|
||||
++n;
|
||||
fNegative = true;
|
||||
@@ -177,27 +171,12 @@ public:
|
||||
}
|
||||
*p++ = c;
|
||||
}
|
||||
unsigned int nSize = p - (pch + 4);
|
||||
unsigned int nSize = (unsigned int) (p - (pch + 4));
|
||||
pch[0] = (nSize >> 24) & 0xff;
|
||||
pch[1] = (nSize >> 16) & 0xff;
|
||||
pch[2] = (nSize >> 8) & 0xff;
|
||||
pch[3] = (nSize) & 0xff;
|
||||
BN_mpi2bn(pch, p - pch, self);
|
||||
}
|
||||
|
||||
uint64 getuint64()
|
||||
{
|
||||
unsigned int nSize = BN_bn2mpi(self, NULL);
|
||||
if (nSize < 4)
|
||||
return 0;
|
||||
std::vector<unsigned char> vch(nSize);
|
||||
BN_bn2mpi(self, &vch[0]);
|
||||
if (vch.size() > 4)
|
||||
vch[4] &= 0x7f;
|
||||
uint64 n = 0;
|
||||
for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
|
||||
((unsigned char*)&n)[i] = vch[j];
|
||||
return n;
|
||||
BN_mpi2bn(pch, (int) (p - pch), this);
|
||||
}
|
||||
|
||||
void setuint64(uint64 n)
|
||||
@@ -219,12 +198,12 @@ public:
|
||||
}
|
||||
*p++ = c;
|
||||
}
|
||||
unsigned int nSize = p - (pch + 4);
|
||||
unsigned int nSize = (unsigned int) (p - (pch + 4));
|
||||
pch[0] = (nSize >> 24) & 0xff;
|
||||
pch[1] = (nSize >> 16) & 0xff;
|
||||
pch[2] = (nSize >> 8) & 0xff;
|
||||
pch[3] = (nSize) & 0xff;
|
||||
BN_mpi2bn(pch, p - pch, self);
|
||||
BN_mpi2bn(pch, (int) (p - pch), this);
|
||||
}
|
||||
|
||||
void setuint256(uint256 n)
|
||||
@@ -247,34 +226,33 @@ public:
|
||||
}
|
||||
*p++ = c;
|
||||
}
|
||||
unsigned int nSize = p - (pch + 4);
|
||||
unsigned int nSize = (unsigned int) (p - (pch + 4));
|
||||
pch[0] = (nSize >> 24) & 0xff;
|
||||
pch[1] = (nSize >> 16) & 0xff;
|
||||
pch[2] = (nSize >> 8) & 0xff;
|
||||
pch[3] = (nSize >> 0) & 0xff;
|
||||
BN_mpi2bn(pch, p - pch, self);
|
||||
BN_mpi2bn(pch, (int) (p - pch), this);
|
||||
}
|
||||
|
||||
uint256 getuint256()
|
||||
uint256 getuint256() const
|
||||
{
|
||||
unsigned int nSize = BN_bn2mpi(self, NULL);
|
||||
unsigned int nSize = BN_bn2mpi(this, NULL);
|
||||
if (nSize < 4)
|
||||
return 0;
|
||||
std::vector<unsigned char> vch(nSize);
|
||||
BN_bn2mpi(self, &vch[0]);
|
||||
BN_bn2mpi(this, &vch[0]);
|
||||
if (vch.size() > 4)
|
||||
vch[4] &= 0x7f;
|
||||
uint256 n = 0;
|
||||
for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
|
||||
for (unsigned int i = 0, j = (unsigned int) vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
|
||||
((unsigned char*)&n)[i] = vch[j];
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
void setvch(const std::vector<unsigned char>& vch)
|
||||
{
|
||||
std::vector<unsigned char> vch2(vch.size() + 4);
|
||||
unsigned int nSize = vch.size();
|
||||
unsigned int nSize = (unsigned int) vch.size();
|
||||
// BIGNUM's byte stream format expects 4 bytes of
|
||||
// big endian size data info at the front
|
||||
vch2[0] = (nSize >> 24) & 0xff;
|
||||
@@ -283,43 +261,83 @@ public:
|
||||
vch2[3] = (nSize >> 0) & 0xff;
|
||||
// swap data to big endian
|
||||
reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);
|
||||
BN_mpi2bn(&vch2[0], vch2.size(), self);
|
||||
BN_mpi2bn(&vch2[0], (int) vch2.size(), this);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> getvch() const
|
||||
{
|
||||
unsigned int nSize = BN_bn2mpi(self, NULL);
|
||||
unsigned int nSize = BN_bn2mpi(this, NULL);
|
||||
if (nSize <= 4)
|
||||
return std::vector<unsigned char>();
|
||||
std::vector<unsigned char> vch(nSize);
|
||||
BN_bn2mpi(self, &vch[0]);
|
||||
BN_bn2mpi(this, &vch[0]);
|
||||
vch.erase(vch.begin(), vch.begin() + 4);
|
||||
reverse(vch.begin(), vch.end());
|
||||
return vch;
|
||||
}
|
||||
|
||||
// The "compact" format is a representation of a whole
|
||||
// number N using an unsigned 32bit number similar to a
|
||||
// floating point format.
|
||||
// The most significant 8 bits are the unsigned exponent of base 256.
|
||||
// This exponent can be thought of as "number of bytes of N".
|
||||
// The lower 23 bits are the mantissa.
|
||||
// Bit number 24 (0x800000) represents the sign of N.
|
||||
// N = (-1^sign) * mantissa * 256^(exponent-3)
|
||||
//
|
||||
// Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn().
|
||||
// MPI uses the most significant bit of the first byte as sign.
|
||||
// Thus 0x1234560000 is compact (0x05123456)
|
||||
// and 0xc0de000000 is compact (0x0600c0de)
|
||||
// (0x05c0de00) would be -0x40de000000
|
||||
//
|
||||
// Bitcoin only uses this "compact" format for encoding difficulty
|
||||
// targets, which are unsigned 256bit quantities. Thus, all the
|
||||
// complexities of the sign bit and using base 256 are probably an
|
||||
// implementation accident.
|
||||
//
|
||||
// This implementation directly uses shifts instead of going
|
||||
// through an intermediate MPI representation.
|
||||
CBigNum& SetCompact(unsigned int nCompact)
|
||||
{
|
||||
unsigned int nSize = nCompact >> 24;
|
||||
std::vector<unsigned char> vch(4 + nSize);
|
||||
vch[3] = nSize;
|
||||
if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff;
|
||||
if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff;
|
||||
if (nSize >= 3) vch[6] = (nCompact >> 0) & 0xff;
|
||||
BN_mpi2bn(&vch[0], vch.size(), self);
|
||||
bool fNegative =(nCompact & 0x00800000) != 0;
|
||||
unsigned int nWord = nCompact & 0x007fffff;
|
||||
if (nSize <= 3)
|
||||
{
|
||||
nWord >>= 8*(3-nSize);
|
||||
BN_set_word(this, nWord);
|
||||
}
|
||||
else
|
||||
{
|
||||
BN_set_word(this, nWord);
|
||||
BN_lshift(this, this, 8*(nSize-3));
|
||||
}
|
||||
BN_set_negative(this, fNegative);
|
||||
return *this;
|
||||
}
|
||||
|
||||
unsigned int GetCompact() const
|
||||
{
|
||||
unsigned int nSize = BN_bn2mpi(self, NULL);
|
||||
std::vector<unsigned char> vch(nSize);
|
||||
nSize -= 4;
|
||||
BN_bn2mpi(self, &vch[0]);
|
||||
unsigned int nCompact = nSize << 24;
|
||||
if (nSize >= 1) nCompact |= (vch[4] << 16);
|
||||
if (nSize >= 2) nCompact |= (vch[5] << 8);
|
||||
if (nSize >= 3) nCompact |= (vch[6] << 0);
|
||||
unsigned int nSize = BN_num_bytes(this);
|
||||
unsigned int nCompact = 0;
|
||||
if (nSize <= 3)
|
||||
nCompact = (unsigned int) BN_get_word(this) << 8*(3-nSize);
|
||||
else
|
||||
{
|
||||
CBigNum bn;
|
||||
BN_rshift(&bn, this, 8*(nSize-3));
|
||||
nCompact = (unsigned int) BN_get_word(&bn);
|
||||
}
|
||||
// The 0x00800000 bit denotes the sign.
|
||||
// Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
|
||||
if (nCompact & 0x00800000)
|
||||
{
|
||||
nCompact >>= 8;
|
||||
nSize++;
|
||||
}
|
||||
nCompact |= nSize << 24;
|
||||
nCompact |= (BN_is_negative(this) ? 0x00800000 : 0);
|
||||
return nCompact;
|
||||
}
|
||||
|
||||
@@ -360,20 +378,20 @@ public:
|
||||
CBigNum bn0 = 0;
|
||||
std::string str;
|
||||
CBigNum bn = *this;
|
||||
BN_set_negative(bn.get(), false);
|
||||
BN_set_negative(&bn, false);
|
||||
CBigNum dv;
|
||||
CBigNum rem;
|
||||
if (BN_cmp(bn.getc(), bn0.getc()) == 0)
|
||||
if (BN_cmp(&bn, &bn0) == 0)
|
||||
return "0";
|
||||
while (BN_cmp(bn.getc(), bn0.getc()) > 0)
|
||||
while (BN_cmp(&bn, &bn0) > 0)
|
||||
{
|
||||
if (!BN_div(dv.get(), rem.get(), bn.getc(), bnBase.getc(), pctx))
|
||||
if (!BN_div(&dv, &rem, &bn, &bnBase, pctx))
|
||||
throw bignum_error("CBigNum::ToString() : BN_div failed");
|
||||
bn = dv;
|
||||
unsigned int c = rem.getulong();
|
||||
str += "0123456789abcdef"[c];
|
||||
}
|
||||
if (BN_is_negative(self))
|
||||
if (BN_is_negative(this))
|
||||
str += "-";
|
||||
reverse(str.begin(), str.end());
|
||||
return str;
|
||||
@@ -406,12 +424,12 @@ public:
|
||||
|
||||
bool operator!() const
|
||||
{
|
||||
return BN_is_zero(self);
|
||||
return BN_is_zero(this);
|
||||
}
|
||||
|
||||
CBigNum& operator+=(const CBigNum& b)
|
||||
{
|
||||
if (!BN_add(self, self, b.getc()))
|
||||
if (!BN_add(this, this, &b))
|
||||
throw bignum_error("CBigNum::operator+= : BN_add failed");
|
||||
return *this;
|
||||
}
|
||||
@@ -425,7 +443,7 @@ public:
|
||||
CBigNum& operator*=(const CBigNum& b)
|
||||
{
|
||||
CAutoBN_CTX pctx;
|
||||
if (!BN_mul(self, self, b.getc(), pctx))
|
||||
if (!BN_mul(this, this, &b, pctx))
|
||||
throw bignum_error("CBigNum::operator*= : BN_mul failed");
|
||||
return *this;
|
||||
}
|
||||
@@ -444,7 +462,7 @@ public:
|
||||
|
||||
CBigNum& operator<<=(unsigned int shift)
|
||||
{
|
||||
if (!BN_lshift(self, self, shift))
|
||||
if (!BN_lshift(this, this, shift))
|
||||
throw bignum_error("CBigNum:operator<<= : BN_lshift failed");
|
||||
return *this;
|
||||
}
|
||||
@@ -455,13 +473,13 @@ public:
|
||||
// if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL
|
||||
CBigNum a = 1;
|
||||
a <<= shift;
|
||||
if (BN_cmp(a.getc(), self) > 0)
|
||||
if (BN_cmp(&a, this) > 0)
|
||||
{
|
||||
*this = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (!BN_rshift(self, self, shift))
|
||||
if (!BN_rshift(this, this, shift))
|
||||
throw bignum_error("CBigNum:operator>>= : BN_rshift failed");
|
||||
return *this;
|
||||
}
|
||||
@@ -470,7 +488,7 @@ public:
|
||||
CBigNum& operator++()
|
||||
{
|
||||
// prefix operator
|
||||
if (!BN_add(self, self, BN_value_one()))
|
||||
if (!BN_add(this, this, BN_value_one()))
|
||||
throw bignum_error("CBigNum::operator++ : BN_add failed");
|
||||
return *this;
|
||||
}
|
||||
@@ -487,7 +505,7 @@ public:
|
||||
{
|
||||
// prefix operator
|
||||
CBigNum r;
|
||||
if (!BN_sub(r.get(), self, BN_value_one()))
|
||||
if (!BN_sub(&r, this, BN_value_one()))
|
||||
throw bignum_error("CBigNum::operator-- : BN_sub failed");
|
||||
*this = r;
|
||||
return *this;
|
||||
@@ -512,7 +530,7 @@ public:
|
||||
inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
|
||||
{
|
||||
CBigNum r;
|
||||
if (!BN_add(r.get(), a.getc(), b.getc()))
|
||||
if (!BN_add(&r, &a, &b))
|
||||
throw bignum_error("CBigNum::operator+ : BN_add failed");
|
||||
return r;
|
||||
}
|
||||
@@ -520,7 +538,7 @@ inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
|
||||
inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
|
||||
{
|
||||
CBigNum r;
|
||||
if (!BN_sub(r.get(), a.getc(), b.getc()))
|
||||
if (!BN_sub(&r, &a, &b))
|
||||
throw bignum_error("CBigNum::operator- : BN_sub failed");
|
||||
return r;
|
||||
}
|
||||
@@ -528,7 +546,7 @@ inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
|
||||
inline const CBigNum operator-(const CBigNum& a)
|
||||
{
|
||||
CBigNum r(a);
|
||||
BN_set_negative(r.get(), !BN_is_negative(r.getc()));
|
||||
BN_set_negative(&r, !BN_is_negative(&r));
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -536,7 +554,7 @@ inline const CBigNum operator*(const CBigNum& a, const CBigNum& b)
|
||||
{
|
||||
CAutoBN_CTX pctx;
|
||||
CBigNum r;
|
||||
if (!BN_mul(r.get(), a.getc(), b.getc(), pctx))
|
||||
if (!BN_mul(&r, &a, &b, pctx))
|
||||
throw bignum_error("CBigNum::operator* : BN_mul failed");
|
||||
return r;
|
||||
}
|
||||
@@ -545,7 +563,7 @@ inline const CBigNum operator/(const CBigNum& a, const CBigNum& b)
|
||||
{
|
||||
CAutoBN_CTX pctx;
|
||||
CBigNum r;
|
||||
if (!BN_div(r.get(), NULL, a.getc(), b.getc(), pctx))
|
||||
if (!BN_div(&r, NULL, &a, &b, pctx))
|
||||
throw bignum_error("CBigNum::operator/ : BN_div failed");
|
||||
return r;
|
||||
}
|
||||
@@ -554,7 +572,7 @@ inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
|
||||
{
|
||||
CAutoBN_CTX pctx;
|
||||
CBigNum r;
|
||||
if (!BN_mod(r.get(), a.getc(), b.getc(), pctx))
|
||||
if (!BN_mod(&r, &a, &b, pctx))
|
||||
throw bignum_error("CBigNum::operator% : BN_div failed");
|
||||
return r;
|
||||
}
|
||||
@@ -562,7 +580,7 @@ inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
|
||||
inline const CBigNum operator<<(const CBigNum& a, unsigned int shift)
|
||||
{
|
||||
CBigNum r;
|
||||
if (!BN_lshift(r.get(), a.getc(), shift))
|
||||
if (!BN_lshift(&r, &a, shift))
|
||||
throw bignum_error("CBigNum:operator<< : BN_lshift failed");
|
||||
return r;
|
||||
}
|
||||
@@ -574,11 +592,11 @@ inline const CBigNum operator>>(const CBigNum& a, unsigned int shift)
|
||||
return r;
|
||||
}
|
||||
|
||||
inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) == 0); }
|
||||
inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) != 0); }
|
||||
inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) <= 0); }
|
||||
inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) >= 0); }
|
||||
inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) < 0); }
|
||||
inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) > 0); }
|
||||
inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); }
|
||||
inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); }
|
||||
inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); }
|
||||
inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
|
||||
inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) < 0); }
|
||||
inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) > 0); }
|
||||
|
||||
#endif
|
||||
-273
@@ -1,273 +0,0 @@
|
||||
/**
|
||||
* Blake2-B CUDA Implementation
|
||||
*
|
||||
* tpruvot@github July 2016
|
||||
*
|
||||
*/
|
||||
|
||||
#include <miner.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <sph/blake2b.h>
|
||||
|
||||
#include <cuda_helper.h>
|
||||
#include <cuda_vector_uint2x4.h>
|
||||
|
||||
#define TPB 512
|
||||
#define NBN 2
|
||||
|
||||
static uint32_t *d_resNonces[MAX_GPUS];
|
||||
|
||||
__device__ uint64_t d_data[10];
|
||||
|
||||
static __constant__ const int8_t blake2b_sigma[12][16] = {
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
|
||||
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
|
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
|
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
|
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
|
||||
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
|
||||
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
|
||||
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
|
||||
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 } ,
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
|
||||
};
|
||||
|
||||
// host mem align
|
||||
#define A 64
|
||||
|
||||
extern "C" void blake2b_hash(void *output, const void *input)
|
||||
{
|
||||
uint8_t _ALIGN(A) hash[32];
|
||||
blake2b_ctx ctx;
|
||||
|
||||
blake2b_init(&ctx, 32, NULL, 0);
|
||||
blake2b_update(&ctx, input, 80);
|
||||
blake2b_final(&ctx, hash);
|
||||
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
__device__ __forceinline__
|
||||
static void G(const int r, const int i, uint64_t &a, uint64_t &b, uint64_t &c, uint64_t &d, uint64_t const m[16])
|
||||
{
|
||||
a = a + b + m[ blake2b_sigma[r][2*i] ];
|
||||
((uint2*)&d)[0] = SWAPUINT2( ((uint2*)&d)[0] ^ ((uint2*)&a)[0] );
|
||||
c = c + d;
|
||||
((uint2*)&b)[0] = ROR24( ((uint2*)&b)[0] ^ ((uint2*)&c)[0] );
|
||||
a = a + b + m[ blake2b_sigma[r][2*i+1] ];
|
||||
((uint2*)&d)[0] = ROR16( ((uint2*)&d)[0] ^ ((uint2*)&a)[0] );
|
||||
c = c + d;
|
||||
((uint2*)&b)[0] = ROR2( ((uint2*)&b)[0] ^ ((uint2*)&c)[0], 63U);
|
||||
}
|
||||
|
||||
#define ROUND(r) \
|
||||
G(r, 0, v[0], v[4], v[ 8], v[12], m); \
|
||||
G(r, 1, v[1], v[5], v[ 9], v[13], m); \
|
||||
G(r, 2, v[2], v[6], v[10], v[14], m); \
|
||||
G(r, 3, v[3], v[7], v[11], v[15], m); \
|
||||
G(r, 4, v[0], v[5], v[10], v[15], m); \
|
||||
G(r, 5, v[1], v[6], v[11], v[12], m); \
|
||||
G(r, 6, v[2], v[7], v[ 8], v[13], m); \
|
||||
G(r, 7, v[3], v[4], v[ 9], v[14], m);
|
||||
|
||||
__global__
|
||||
//__launch_bounds__(128, 8) /* to force 64 regs */
|
||||
void blake2b_gpu_hash(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce, const uint2 target2)
|
||||
{
|
||||
const uint32_t nonce = (blockDim.x * blockIdx.x + threadIdx.x) + startNonce;
|
||||
|
||||
uint64_t m[16];
|
||||
|
||||
m[0] = d_data[0];
|
||||
m[1] = d_data[1];
|
||||
m[2] = d_data[2];
|
||||
m[3] = d_data[3];
|
||||
m[4] = d_data[4];
|
||||
m[5] = d_data[5];
|
||||
m[6] = d_data[6];
|
||||
m[7] = d_data[7];
|
||||
m[8] = d_data[8];
|
||||
((uint32_t*)m)[18] = AS_U32(&d_data[9]);
|
||||
((uint32_t*)m)[19] = nonce;
|
||||
|
||||
m[10] = m[11] = 0;
|
||||
m[12] = m[13] = 0;
|
||||
m[14] = m[15] = 0;
|
||||
|
||||
uint64_t v[16] = {
|
||||
0x6a09e667f2bdc928, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
|
||||
0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179,
|
||||
0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
|
||||
0x510e527fade68281, 0x9b05688c2b3e6c1f, 0xe07c265404be4294, 0x5be0cd19137e2179
|
||||
};
|
||||
|
||||
ROUND( 0);
|
||||
ROUND( 1);
|
||||
ROUND( 2);
|
||||
ROUND( 3);
|
||||
ROUND( 4);
|
||||
ROUND( 5);
|
||||
ROUND( 6);
|
||||
ROUND( 7);
|
||||
ROUND( 8);
|
||||
ROUND( 9);
|
||||
ROUND(10);
|
||||
ROUND(11);
|
||||
|
||||
uint2 last = vectorize(v[3] ^ v[11] ^ 0xa54ff53a5f1d36f1);
|
||||
if (last.y <= target2.y && last.x <= target2.x) {
|
||||
resNonce[1] = resNonce[0];
|
||||
resNonce[0] = nonce;
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t blake2b_hash_cuda(const int thr_id, const uint32_t threads, const uint32_t startNonce, const uint2 target2, uint32_t &secNonce)
|
||||
{
|
||||
uint32_t resNonces[NBN] = { UINT32_MAX, UINT32_MAX };
|
||||
uint32_t result = UINT32_MAX;
|
||||
|
||||
dim3 grid((threads + TPB-1)/TPB);
|
||||
dim3 block(TPB);
|
||||
|
||||
/* Check error on Ctrl+C or kill to prevent segfaults on exit */
|
||||
if (cudaMemset(d_resNonces[thr_id], 0xff, NBN*sizeof(uint32_t)) != cudaSuccess)
|
||||
return result;
|
||||
|
||||
blake2b_gpu_hash <<<grid, block, 8>>> (threads, startNonce, d_resNonces[thr_id], target2);
|
||||
cudaThreadSynchronize();
|
||||
|
||||
if (cudaSuccess == cudaMemcpy(resNonces, d_resNonces[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost)) {
|
||||
result = resNonces[0];
|
||||
secNonce = resNonces[1];
|
||||
if (secNonce == result) secNonce = UINT32_MAX;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
__host__
|
||||
void blake2b_setBlock(uint32_t *data)
|
||||
{
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(d_data, data, 80, 0, cudaMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
int scanhash_blake2b(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(A) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
|
||||
int dev_id = device_map[thr_id];
|
||||
int intensity = (device_sm[dev_id] >= 500 && !is_windows()) ? 28 : 25;
|
||||
if (device_sm[dev_id] >= 520 && is_windows()) intensity = 26;
|
||||
if (device_sm[dev_id] < 350) intensity = 22;
|
||||
|
||||
uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity);
|
||||
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(dev_id);
|
||||
if (opt_cudaschedule == -1 && gpu_threads == 1) {
|
||||
cudaDeviceReset();
|
||||
// reduce cpu usage (linux)
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonces[thr_id], NBN * sizeof(uint32_t)), -1);
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
for (int i=0; i < 20; i++)
|
||||
be32enc(&endiandata[i], pdata[i]);
|
||||
|
||||
const uint2 target = make_uint2(ptarget[6], ptarget[7]);
|
||||
blake2b_setBlock(endiandata);
|
||||
|
||||
do {
|
||||
work->nonces[0] = blake2b_hash_cuda(thr_id, throughput, pdata[19], target, work->nonces[1]);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
if (work->nonces[0] != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t _ALIGN(A) vhash[8];
|
||||
work->valid_nonces = 0;
|
||||
endiandata[19] = work->nonces[0];
|
||||
blake2b_hash(vhash, endiandata);
|
||||
if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
|
||||
work_set_target_ratio(work, vhash);
|
||||
work->valid_nonces++;
|
||||
pdata[19] = work->nonces[0] + 1;
|
||||
} else {
|
||||
gpu_increment_reject(thr_id);
|
||||
}
|
||||
|
||||
if (work->nonces[1] != UINT32_MAX) {
|
||||
endiandata[19] = work->nonces[1];
|
||||
blake2b_hash(vhash, endiandata);
|
||||
if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
|
||||
if (bn_hash_target_ratio(vhash, ptarget) > work->shareratio[0]) {
|
||||
work->sharediff[1] = work->sharediff[0];
|
||||
work->shareratio[1] = work->shareratio[0];
|
||||
xchg(work->nonces[1], work->nonces[0]);
|
||||
work_set_target_ratio(work, vhash);
|
||||
} else {
|
||||
bn_set_target_ratio(work, vhash, 1);
|
||||
}
|
||||
work->valid_nonces++;
|
||||
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1; // next scan start
|
||||
} else {
|
||||
gpu_increment_reject(thr_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (work->valid_nonces) {
|
||||
work->nonces[0] = cuda_swab32(work->nonces[0]);
|
||||
work->nonces[1] = cuda_swab32(work->nonces[1]);
|
||||
return work->valid_nonces;
|
||||
}
|
||||
}
|
||||
|
||||
if ((uint64_t) throughput + pdata[19] >= max_nonce) {
|
||||
pdata[19] = max_nonce;
|
||||
break;
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (!work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_blake2b(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
//cudaThreadSynchronize();
|
||||
|
||||
cudaFree(d_resNonces[thr_id]);
|
||||
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+5
-6
@@ -2,19 +2,18 @@
|
||||
"_comment1" : "Possible keys are the long options (ccminer --help)",
|
||||
"_comment2" : "todo: support /* comments */",
|
||||
|
||||
"algo" : "lbry",
|
||||
"intensity": 22,
|
||||
"algo" : "blake",
|
||||
"intensity": 19,
|
||||
|
||||
"api-bind": "127.0.0.1:4068",
|
||||
"statsavg": 20,
|
||||
|
||||
"max-log-rate": 60,
|
||||
"quiet" : false,
|
||||
"debug" : false,
|
||||
"protocol" : false,
|
||||
"cpu-priority" : 3,
|
||||
|
||||
"url" : "stratum+tcp://yiimp.ccminer.org:3334",
|
||||
"user" : "bK2wcSFJv2nnNjFvTN5Q7VX8X8unJktJsa",
|
||||
"pass" : "donate"
|
||||
"url" : "stratum+tcp://stratum.eu.miners-pool.eu:8421",
|
||||
"user" : "ShGCAFrspnLDo414EzUyJm4k5Qr2Kkrmvh",
|
||||
"pass" : "x"
|
||||
}
|
||||
+414
-1008
File diff suppressed because it is too large.
Load diff
+63
-167
@@ -23,23 +23,26 @@
|
||||
<RootNamespace>ccminer</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Label="Configuration">
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CLRSupport>false</CLRSupport>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CLRSupport>false</CLRSupport>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 9.0.props" />
|
||||
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 7.5.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
@@ -77,10 +80,10 @@
|
||||
<CudaCompile>
|
||||
<CInterleavedPTX>false</CInterleavedPTX>
|
||||
<GenerateLineInfo>true</GenerateLineInfo>
|
||||
<MaxRegCount>80</MaxRegCount>
|
||||
<MaxRegCount>255</MaxRegCount>
|
||||
<PtxAsOptionV>true</PtxAsOptionV>
|
||||
<Keep>true</Keep>
|
||||
<CodeGeneration>compute_50,sm_50</CodeGeneration>
|
||||
<CodeGeneration>compute_50,sm_50;compute_52,sm_52;compute_35,sm_35;compute_30,sm_30;compute_20,sm_20</CodeGeneration>
|
||||
<Include>$(NVTOOLSEXT_PATH)\include;..\..\..\Common\C99</Include>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
@@ -109,15 +112,16 @@
|
||||
<CudaCompile>
|
||||
<CInterleavedPTX>false</CInterleavedPTX>
|
||||
<GenerateLineInfo>true</GenerateLineInfo>
|
||||
<MaxRegCount>80</MaxRegCount>
|
||||
<MaxRegCount>255</MaxRegCount>
|
||||
<PtxAsOptionV>true</PtxAsOptionV>
|
||||
<Keep>true</Keep>
|
||||
<CodeGeneration>compute_52,sm_52</CodeGeneration>
|
||||
<CodeGeneration>compute_50,sm_50;compute_52,sm_52;compute_35,sm_35;compute_30,sm_30;compute_20,sm_20</CodeGeneration>
|
||||
<Include>$(NVTOOLSEXT_PATH)\include;..\..\..\Common\C99</Include>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
<CudaLink>
|
||||
<PerformDeviceLink>false</PerformDeviceLink>
|
||||
<Optimization>O3</Optimization>
|
||||
</CudaLink>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@@ -152,16 +156,16 @@
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CInterleavedPTX>false</CInterleavedPTX>
|
||||
<MaxRegCount>80</MaxRegCount>
|
||||
<MaxRegCount>255</MaxRegCount>
|
||||
<PtxAsOptionV>true</PtxAsOptionV>
|
||||
<Keep>true</Keep>
|
||||
<CodeGeneration>compute_50,sm_50;compute_52,sm_52;compute_30,sm_30</CodeGeneration>
|
||||
<AdditionalOptions>--ptxas-options="-O2" --Wno-deprecated-gpu-targets %(AdditionalOptions)</AdditionalOptions>
|
||||
<Optimization>O2</Optimization>
|
||||
<CodeGeneration>compute_50,sm_50;compute_52,sm_52;compute_35,sm_35;compute_30,sm_30;compute_20,sm_20</CodeGeneration>
|
||||
<AdditionalOptions>--ptxas-options="-O2" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Optimization>O3</Optimization>
|
||||
</CudaCompile>
|
||||
<CudaLink>
|
||||
<GPUDebugInfo>false</GPUDebugInfo>
|
||||
<Optimization>O3</Optimization>
|
||||
<Optimization>O2</Optimization>
|
||||
</CudaLink>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@@ -195,14 +199,13 @@
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CInterleavedPTX>false</CInterleavedPTX>
|
||||
<MaxRegCount>80</MaxRegCount>
|
||||
<MaxRegCount>255</MaxRegCount>
|
||||
<PtxAsOptionV>true</PtxAsOptionV>
|
||||
<Keep>true</Keep>
|
||||
<CodeGeneration>compute_52,sm_52;compute_50,sm_50;compute_35,sm_35;compute_30,sm_30</CodeGeneration>
|
||||
<Include>$(NVTOOLSEXT_PATH)\include</Include>
|
||||
<CodeGeneration>compute_50,sm_50;compute_52,sm_52;compute_35,sm_35;compute_30,sm_30;compute_20,sm_20</CodeGeneration>
|
||||
<Include>$(NVTOOLSEXT_PATH)\include;..\..\..\Common\C99</Include>
|
||||
<Optimization>O3</Optimization>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
<AdditionalOptions>--Wno-deprecated-gpu-targets %(AdditionalOptions)</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
<CudaLink>
|
||||
<Optimization>O3</Optimization>
|
||||
@@ -222,28 +225,11 @@
|
||||
<ClCompile Include="compat\jansson\strconv.c" />
|
||||
<ClCompile Include="compat\jansson\utf.c" />
|
||||
<ClCompile Include="compat\jansson\value.c" />
|
||||
<ClInclude Include="compat\pthreads\pthread.h" />
|
||||
<ClCompile Include="compat\winansi.c" />
|
||||
<ClCompile Include="ccminer.cpp">
|
||||
<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
|
||||
<Optimization Condition="'$(Configuration)'=='Release'">Full</Optimization>
|
||||
</ClCompile>
|
||||
<ClCompile Include="crypto\mman.c" />
|
||||
<ClCompile Include="crypto\wildkeccak-cpu.cpp" />
|
||||
<ClCompile Include="crypto\xmr-rpc.cpp" />
|
||||
<ClCompile Include="crypto\aesb.cpp" />
|
||||
<ClCompile Include="crypto\oaes_lib.cpp" />
|
||||
<ClCompile Include="crypto\cryptolight-cpu.cpp" />
|
||||
<ClCompile Include="crypto\cryptonight-cpu.cpp" />
|
||||
<ClCompile Include="crypto\cpu\c_keccak.c" />
|
||||
<ClCompile Include="equi\blake2\blake2bx.cpp">
|
||||
<EnableEnhancedInstructionSet Condition="'$(Platform)'=='Win32'">StreamingSIMDExtensions</EnableEnhancedInstructionSet>
|
||||
</ClCompile>
|
||||
<ClCompile Include="equi\equi-stratum.cpp" />
|
||||
<ClCompile Include="equi\equi.cpp" />
|
||||
<ClCompile Include="equi\equihash.cpp" />
|
||||
<ClCompile Include="nvapi.cpp" />
|
||||
<ClCompile Include="nvsettings.cpp" />
|
||||
<ClCompile Include="pools.cpp" />
|
||||
<ClCompile Include="util.cpp" />
|
||||
<ClCompile Include="bench.cpp" />
|
||||
@@ -261,55 +247,23 @@
|
||||
<ClCompile Include="myriadgroestl.cpp" />
|
||||
<ClCompile Include="lyra2\Lyra2.c" />
|
||||
<ClCompile Include="lyra2\Sponge.c" />
|
||||
<ClCompile Include="lyra2\Lyra2Z.c" />
|
||||
<ClInclude Include="equi\eqcuda.hpp" />
|
||||
<ClInclude Include="equi\equihash.h" />
|
||||
<ClInclude Include="lyra2\cuda_lyra2_sm2.cuh" />
|
||||
<ClInclude Include="lyra2\cuda_lyra2_sm5.cuh" />
|
||||
<ClInclude Include="neoscrypt\neoscrypt.h" />
|
||||
<ClCompile Include="neoscrypt\neoscrypt.cpp" />
|
||||
<ClCompile Include="neoscrypt\neoscrypt-cpu.c" />
|
||||
<ClInclude Include="neoscrypt\cuda_vectors.h" />
|
||||
<ClInclude Include="x11\cuda_x11_simd512_sm2.cuh" />
|
||||
<ClInclude Include="x16\cuda_x16.h" />
|
||||
<CudaCompile Include="Algo256\bmw.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_bmw.cu">
|
||||
<MaxRegCount>76</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="crypto\cryptolight.cu" />
|
||||
<CudaCompile Include="crypto\cryptolight-core.cu">
|
||||
<MaxRegCount>64</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="crypto\cryptonight.cu" />
|
||||
<CudaCompile Include="crypto\cryptonight-core.cu">
|
||||
<MaxRegCount>64</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="crypto\cryptonight-extra.cu">
|
||||
<MaxRegCount>255</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<ClInclude Include="crypto\cn_aes.cuh" />
|
||||
<ClInclude Include="crypto\cn_blake.cuh" />
|
||||
<ClInclude Include="crypto\cn_groestl.cuh" />
|
||||
<ClInclude Include="crypto\cn_jh.cuh" />
|
||||
<ClInclude Include="crypto\cn_keccak.cuh" />
|
||||
<ClInclude Include="crypto\cn_skein.cuh" />
|
||||
<CudaCompile Include="crypto\wildkeccak.cu">
|
||||
<MaxRegCount>128</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="equi\cuda_equi.cu">
|
||||
<CodeGeneration>compute_52,sm_52;compute_50,sm_50;compute_30,sm_30</CodeGeneration>
|
||||
<AdditionalOptions> -Xptxas -dlcm=ca -Xptxas -dscm=cs %(AdditionalOptions)</AdditionalOptions>
|
||||
<MaxRegCount>0</MaxRegCount>
|
||||
<CodeGeneration Condition="'$(Configuration)|$(Platform)'=='Release|x64'">compute_61,sm_61;compute_52,sm_52;compute_50,sm_50;compute_30,sm_30</CodeGeneration>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="neoscrypt\cuda_neoscrypt.cu">
|
||||
<MaxRegCount>160</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="neoscrypt\cuda_neoscrypt.cu" />
|
||||
<ClCompile Include="scrypt-jane.cpp" />
|
||||
<ClCompile Include="scrypt.cpp" />
|
||||
<ClCompile Include="sia\sia-rpc.cpp" />
|
||||
<ClCompile Include="skein2.cpp" />
|
||||
<ClCompile Include="sph\aes_helper.c" />
|
||||
<ClCompile Include="sph\blake.c" />
|
||||
<ClCompile Include="sph\blake2b.c" />
|
||||
<ClCompile Include="sph\blake2s.c" />
|
||||
<ClCompile Include="sph\bmw.c" />
|
||||
<ClCompile Include="sph\cubehash.c" />
|
||||
@@ -317,11 +271,15 @@
|
||||
<ClCompile Include="sph\fugue.c" />
|
||||
<ClCompile Include="sph\groestl.c" />
|
||||
<ClCompile Include="sph\haval.c" />
|
||||
<ClCompile Include="sph\haval_helper.c">
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\jh.c" />
|
||||
<ClCompile Include="sph\keccak.c" />
|
||||
<ClCompile Include="sph\luffa.c" />
|
||||
<ClCompile Include="sph\ripemd.c" />
|
||||
<ClCompile Include="sph\sph_sha2.c" />
|
||||
<ClCompile Include="sph\md_helper.c">
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\sha2.c" />
|
||||
<ClCompile Include="sph\sha2big.c" />
|
||||
<ClCompile Include="sph\shabal.c" />
|
||||
@@ -332,7 +290,6 @@
|
||||
<ClCompile Include="sph\hamsi.c" />
|
||||
<ClCompile Include="sph\hamsi_helper.c" />
|
||||
<ClCompile Include="sph\whirlpool.c" />
|
||||
<ClCompile Include="x13\sm3.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="compat.h" />
|
||||
@@ -352,12 +309,7 @@
|
||||
<ClInclude Include="compat\sys\time.h" />
|
||||
<ClInclude Include="compat\unistd.h" />
|
||||
<ClInclude Include="compat\winansi.h" />
|
||||
<ClInclude Include="compat\ccminer-config.h" />
|
||||
<ClInclude Include="crypto\cryptolight.h" />
|
||||
<ClInclude Include="crypto\cryptonight.h" />
|
||||
<ClInclude Include="crypto\mman.h" />
|
||||
<ClInclude Include="crypto\wildkeccak.h" />
|
||||
<ClInclude Include="crypto\xmr-rpc.h" />
|
||||
<ClInclude Include="cpuminer-config.h" />
|
||||
<ClInclude Include="cuda_groestlcoin.h" />
|
||||
<ClInclude Include="cuda_helper.h" />
|
||||
<ClInclude Include="cuda_vector_uint2x4.h" />
|
||||
@@ -368,13 +320,10 @@
|
||||
<ClInclude Include="miner.h" />
|
||||
<ClInclude Include="nvml.h" />
|
||||
<ClInclude Include="quark\cuda_bmw512_sm3.cuh" />
|
||||
<ClInclude Include="quark\cuda_quark_groestl512_sm2.cuh" />
|
||||
<ClInclude Include="quark\cuda_quark_blake512_sp.cuh" />
|
||||
<ClInclude Include="quark\cuda_skein512_sp.cuh" />
|
||||
<ClInclude Include="res\resource.h" />
|
||||
<ClInclude Include="sia\sia-rpc.h" />
|
||||
<ClInclude Include="scrypt\salsa_kernel.h" />
|
||||
<ClInclude Include="sph\blake2b.h" />
|
||||
<ClInclude Include="sph\blake2s.h" />
|
||||
<ClInclude Include="sph\sph_blake.h" />
|
||||
<ClInclude Include="sph\sph_bmw.h" />
|
||||
<ClInclude Include="sph\sph_cubehash.h" />
|
||||
@@ -397,7 +346,6 @@
|
||||
<ClInclude Include="uint256.h" />
|
||||
<ClInclude Include="lyra2\Lyra2.h" />
|
||||
<ClInclude Include="lyra2\Sponge.h" />
|
||||
<ClInclude Include="lyra2\Lyra2Z.h" />
|
||||
<ClInclude Include="quark\groestl_transf_quad.h" />
|
||||
<ClInclude Include="quark\groestl_functions_quad.h" />
|
||||
<ClInclude Include="quark\cuda_quark.h" />
|
||||
@@ -407,14 +355,16 @@
|
||||
<CudaCompile Include="cuda.cpp" />
|
||||
<CudaCompile Include="cuda_groestlcoin.cu" />
|
||||
<CudaCompile Include="cuda_myriadgroestl.cu" />
|
||||
<CudaCompile Include="cuda_nist5.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="scrypt\blake.cu" />
|
||||
<CudaCompile Include="scrypt\keccak.cu" />
|
||||
<CudaCompile Include="scrypt\sha256.cu" />
|
||||
<CudaCompile Include="scrypt\salsa_kernel.cu">
|
||||
<CodeGeneration>compute_30,sm_30</CodeGeneration>
|
||||
<CodeGeneration>compute_20,sm_21</CodeGeneration>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="scrypt\fermi_kernel.cu">
|
||||
<CodeGeneration>compute_30,sm_30</CodeGeneration>
|
||||
<CodeGeneration>compute_20,sm_21</CodeGeneration>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="scrypt\kepler_kernel.cu">
|
||||
<CodeGeneration>compute_30,sm_30</CodeGeneration>
|
||||
@@ -426,17 +376,11 @@
|
||||
<CodeGeneration>compute_35,sm_35;compute_50,sm_50;compute_52,sm_52</CodeGeneration>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="scrypt\test_kernel.cu">
|
||||
<CodeGeneration>compute_30,sm_30</CodeGeneration>
|
||||
<CodeGeneration>compute_20,sm_21</CodeGeneration>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="scrypt\titan_kernel.cu">
|
||||
<CodeGeneration>compute_35,sm_35;compute_50,sm_50</CodeGeneration>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\cuda_sha256d.cu" />
|
||||
<CudaCompile Include="sha256\sha256d.cu" />
|
||||
<CudaCompile Include="sha256\cuda_sha256t.cu" />
|
||||
<CudaCompile Include="sha256\sha256t.cu" />
|
||||
<CudaCompile Include="sha256\cuda_sha256q.cu" />
|
||||
<CudaCompile Include="sha256\sha256q.cu" />
|
||||
<CudaCompile Include="zr5.cu" />
|
||||
<CudaCompile Include="heavy\cuda_blake512.cu">
|
||||
</CudaCompile>
|
||||
@@ -453,16 +397,14 @@
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="heavy\heavy.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="heavy\bastion.cu" />
|
||||
<CudaCompile Include="heavy\cuda_bastion.cu" />
|
||||
<CudaCompile Include="JHA\jha.cu" />
|
||||
<CudaCompile Include="JHA\jackpotcoin.cu" />
|
||||
<CudaCompile Include="JHA\cuda_jha_compactionTest.cu">
|
||||
<AdditionalOptions>-Xptxas "-abi=yes" %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions Condition="'$(Configuration)'=='Release'">-Xptxas "-abi=yes" %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions Condition="'$(Configuration)'=='Debug'">-Xptxas "-abi=yes" %(AdditionalOptions)</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="JHA\cuda_jha_keccak512.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="blake2b.cu" />
|
||||
<CudaCompile Include="JHA\jackpotcoin.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\blake256.cu">
|
||||
<MaxRegCount>64</MaxRegCount>
|
||||
<AdditionalOptions Condition="'$(Configuration)'=='Release'">--ptxas-options="-dlcm=cg" %(AdditionalOptions)</AdditionalOptions>
|
||||
@@ -479,15 +421,10 @@
|
||||
<CudaCompile Include="Algo256\cuda_cubehash256.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_fugue256.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_groestl256.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_keccak256.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_keccak256_sm3.cu">
|
||||
<CudaCompile Include="Algo256\cuda_keccak256.cu">
|
||||
<MaxRegCount>92</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\cuda_skein256.cu" />
|
||||
<CudaCompile Include="lbry\cuda_sha256_lbry.cu" />
|
||||
<CudaCompile Include="lbry\cuda_sha512_lbry.cu" />
|
||||
<CudaCompile Include="lbry\cuda_lbry_merged.cu" />
|
||||
<CudaCompile Include="lbry\lbry.cu" />
|
||||
<CudaCompile Include="pentablake.cu">
|
||||
<MaxRegCount>80</MaxRegCount>
|
||||
<AdditionalOptions Condition="'$(Configuration)'=='Release'">--ptxas-options="-dlcm=cg" %(AdditionalOptions)</AdditionalOptions>
|
||||
@@ -516,49 +453,26 @@
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\cuda_skein512.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\quarkcoin.cu" />
|
||||
<CudaCompile Include="quark\nist5.cu" />
|
||||
<CudaCompile Include="qubit\deep.cu" />
|
||||
<CudaCompile Include="qubit\luffa.cu" />
|
||||
<CudaCompile Include="qubit\qubit.cu" />
|
||||
<CudaCompile Include="qubit\qubit_luffa512.cu" />
|
||||
<CudaCompile Include="lyra2\allium.cu" />
|
||||
<CudaCompile Include="quark\quarkcoin.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="qubit\deep.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="qubit\luffa.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="qubit\qubit.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="qubit\qubit_luffa512.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lyra2\lyra2RE.cu" />
|
||||
<CudaCompile Include="lyra2\cuda_lyra2.cu" />
|
||||
<CudaCompile Include="lyra2\lyra2REv2.cu" />
|
||||
<CudaCompile Include="lyra2\cuda_lyra2v2.cu" />
|
||||
<ClInclude Include="lyra2\cuda_lyra2_sm2.cuh" />
|
||||
<ClInclude Include="lyra2\cuda_lyra2_sm5.cuh" />
|
||||
<ClInclude Include="lyra2\cuda_lyra2v2_sm3.cuh" />
|
||||
<CudaCompile Include="lyra2\lyra2REv3.cu" />
|
||||
<CudaCompile Include="lyra2\cuda_lyra2v3.cu" />
|
||||
<ClInclude Include="lyra2\cuda_lyra2v3_sm3.cuh" />
|
||||
<CudaCompile Include="lyra2\lyra2Z.cu" />
|
||||
<CudaCompile Include="lyra2\cuda_lyra2Z.cu" />
|
||||
<ClInclude Include="lyra2\cuda_lyra2Z_sm5.cuh" />
|
||||
<CudaCompile Include="polytimos.cu" />
|
||||
<CudaCompile Include="sia\sia.cu" />
|
||||
<CudaCompile Include="skein.cu">
|
||||
<MaxRegCount>64</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="cuda_skeincoin.cu">
|
||||
<MaxRegCount>48</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="phi\phi.cu" />
|
||||
<CudaCompile Include="phi\phi2.cu" />
|
||||
<CudaCompile Include="phi\cuda_phi2.cu" />
|
||||
<CudaCompile Include="phi\cuda_phi2_cubehash512.cu" />
|
||||
<CudaCompile Include="skunk\skunk.cu" />
|
||||
<CudaCompile Include="skunk\cuda_skunk.cu">
|
||||
<CodeGeneration>compute_50,sm_50;compute_52,sm_52</CodeGeneration>
|
||||
<MaxRegCount>64</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="skunk\cuda_skunk_streebog.cu" />
|
||||
<ClInclude Include="tribus\cuda_echo512_aes.cuh" />
|
||||
<CudaCompile Include="tribus\cuda_echo512_final.cu">
|
||||
<CodeGeneration>compute_50,sm_50;compute_52,sm_52</CodeGeneration>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="tribus\tribus.cu" />
|
||||
<ClInclude Include="x11\cuda_x11_aes.cuh" />
|
||||
<CudaCompile Include="x11\cuda_x11_cubehash512.cu" />
|
||||
<CudaCompile Include="x11\cuda_x11_echo.cu">
|
||||
@@ -575,44 +489,26 @@
|
||||
<MaxRegCount>64</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\cuda_streebog.cu" />
|
||||
<CudaCompile Include="x11\cuda_streebog_maxwell.cu" />
|
||||
<CudaCompile Include="x11\c11.cu" />
|
||||
<CudaCompile Include="x11\fresh.cu" />
|
||||
<CudaCompile Include="x11\sib.cu" />
|
||||
<CudaCompile Include="x11\s3.cu" />
|
||||
<CudaCompile Include="x11\timetravel.cu" />
|
||||
<CudaCompile Include="x11\bitcore.cu" />
|
||||
<CudaCompile Include="x11\exosis.cu" />
|
||||
<CudaCompile Include="x11\veltor.cu" />
|
||||
<CudaCompile Include="x11\x11.cu" />
|
||||
<CudaCompile Include="x11\x11evo.cu" />
|
||||
<CudaCompile Include="x12\x12.cu" />
|
||||
<CudaCompile Include="x13\cuda_x13_hamsi512.cu">
|
||||
<MaxRegCount>72</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x13\cuda_x13_fugue512.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x13\x13.cu" />
|
||||
<CudaCompile Include="x13\cuda_hsr_sm3.cu" />
|
||||
<CudaCompile Include="x13\hsr.cu" />
|
||||
<CudaCompile Include="x15\x14.cu" />
|
||||
<CudaCompile Include="x13\x13.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\x14.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\cuda_x14_shabal512.cu" />
|
||||
<CudaCompile Include="x15\cuda_x15_whirlpool.cu" />
|
||||
<CudaCompile Include="x15\x15.cu" />
|
||||
<CudaCompile Include="x15\whirlpool.cu" />
|
||||
<CudaCompile Include="x15\cuda_x15_whirlpool_sm3.cu" />
|
||||
<CudaCompile Include="x16\x16r.cu" />
|
||||
<CudaCompile Include="x16\x16s.cu" />
|
||||
<CudaCompile Include="x16\cuda_x16_echo512.cu" />
|
||||
<CudaCompile Include="x16\cuda_x16_fugue512.cu" />
|
||||
<CudaCompile Include="x16\cuda_x16_shabal512.cu" />
|
||||
<CudaCompile Include="x16\cuda_x16_simd512_80.cu" />
|
||||
<CudaCompile Include="x16\cuda_x16_echo512_64.cu">
|
||||
<CodeGeneration>compute_50,sm_50;compute_52,sm_52</CodeGeneration>
|
||||
<CudaCompile Include="x17\x17.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x17\hmq17.cu" />
|
||||
<CudaCompile Include="x17\sonoa.cu" />
|
||||
<CudaCompile Include="x17\x17.cu" />
|
||||
<CudaCompile Include="x17\cuda_x17_haval256.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x17\cuda_x17_sha512.cu">
|
||||
@@ -630,7 +526,7 @@
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 9.0.targets" />
|
||||
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 7.5.targets" />
|
||||
</ImportGroup>
|
||||
<!-- Copy the required dlls -->
|
||||
<Target Name="AfterBuild">
|
||||
@@ -639,4 +535,4 @@
|
||||
<Target Name="AfterClean">
|
||||
<Delete Files="@(FilesToCopy->'$(OutDir)%(Filename)%(Extension)')" TreatErrorsAsWarnings="true" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
+18
-351
@@ -46,9 +46,6 @@
|
||||
<Filter Include="Source Files\CUDA\qubit">
|
||||
<UniqueIdentifier>{f3ed23a2-8ce7-41a5-b051-6da56047dc35}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\skunk">
|
||||
<UniqueIdentifier>{23ed23a2-8e7a-65a2-b051-8aa63047d352}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\x11">
|
||||
<UniqueIdentifier>{dd751f2d-bfd6-42c1-8f9b-cbe94e539353}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@@ -58,9 +55,6 @@
|
||||
<Filter Include="Source Files\CUDA\x15">
|
||||
<UniqueIdentifier>{a2403c22-6777-46ab-a55a-3fcc7386c974}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\x16">
|
||||
<UniqueIdentifier>{55dfae6a-66ba-43e2-8ceb-98ee70cbdf16}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\x17">
|
||||
<UniqueIdentifier>{85dfae6a-66ca-4332-8cec-98ee70cbdf2f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@@ -88,39 +82,6 @@
|
||||
<Filter Include="Source Files\CUDA\lyra2">
|
||||
<UniqueIdentifier>{1613763f-895c-4321-b58b-6f5849868956}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\lbry">
|
||||
<UniqueIdentifier>{3079ea1f-f768-455a-acd6-f517fac535b4}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\sha256">
|
||||
<UniqueIdentifier>{86a896c0-1688-4854-98e3-285d166069a3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\sia">
|
||||
<UniqueIdentifier>{86a896c0-1688-4854-98e0-285d166069a3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\crypto">
|
||||
<UniqueIdentifier>{fea0fce3-c0fe-42f7-aa37-0cbba10b008a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\crypto\xmr">
|
||||
<UniqueIdentifier>{af52b078-ed91-4c6e-b07a-e9243acc85d2}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\crypto\bbr">
|
||||
<UniqueIdentifier>{af387eac-e9e6-4e91-a5e8-637b1e7a8d93}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\xmr">
|
||||
<UniqueIdentifier>{0f9aec5e-5409-488f-992a-2c108590d1ac}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\equi">
|
||||
<UniqueIdentifier>{031afae7-2a78-4e32-9738-4b589b6f7ff3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\tribus">
|
||||
<UniqueIdentifier>{1e548d79-c217-4203-989a-a592fe2b2de3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\phi">
|
||||
<UniqueIdentifier>{311e8d79-1612-4f0f-8591-23a592f2b2d3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\x12">
|
||||
<UniqueIdentifier>{xde48d89-fx12-1323-129a-b592fe2b2de3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="compat\jansson\dump.c">
|
||||
@@ -165,12 +126,6 @@
|
||||
<ClCompile Include="sph\blake.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\blake2b.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\blake2s.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\bmw.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
@@ -195,6 +150,9 @@
|
||||
<ClCompile Include="sph\luffa.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\md_helper.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\sha2.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
@@ -222,10 +180,7 @@
|
||||
<ClCompile Include="sph\haval.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\ripemd.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\sph_sha2.c">
|
||||
<ClCompile Include="sph\haval_helper.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\sha2big.c">
|
||||
@@ -234,9 +189,6 @@
|
||||
<ClCompile Include="sph\streebog.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="x13\sm3.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="compat\winansi.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -267,18 +219,12 @@
|
||||
<ClCompile Include="compat\jansson\error.c">
|
||||
<Filter>Source Files\jansson</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="compat\pthreads\pthread.h">
|
||||
<Filter>Header Files\compat</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="lyra2\Lyra2.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="lyra2\Sponge.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="lyra2\Lyra2Z.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="scrypt.cpp">
|
||||
<Filter>Source Files\CUDA\scrypt</Filter>
|
||||
</ClCompile>
|
||||
@@ -312,50 +258,8 @@
|
||||
<ClCompile Include="bignum.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nvapi.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nvsettings.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sia\sia-rpc.cpp">
|
||||
<Filter>Source Files\sia</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="crypto\xmr-rpc.cpp">
|
||||
<Filter>Source Files\crypto</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="crypto\aesb.cpp">
|
||||
<Filter>Source Files\crypto\xmr</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="crypto\cpu\c_keccak.c">
|
||||
<Filter>Source Files\crypto\xmr</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="crypto\oaes_lib.cpp">
|
||||
<Filter>Source Files\crypto\xmr</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="crypto\cryptolight-cpu.cpp">
|
||||
<Filter>Source Files\crypto\xmr</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="crypto\cryptonight-cpu.cpp">
|
||||
<Filter>Source Files\crypto\xmr</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="crypto\mman.c">
|
||||
<Filter>Source Files\crypto\bbr</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="crypto\wildkeccak-cpu.cpp">
|
||||
<Filter>Source Files\crypto\bbr</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="equi\equi.cpp">
|
||||
<Filter>Source Files\equi</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="equi\equihash.cpp">
|
||||
<Filter>Source Files\equi</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="equi\equi-stratum.cpp">
|
||||
<Filter>Source Files\equi</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="equi\blake2\blake2bx.cpp">
|
||||
<Filter>Source Files\equi</Filter>
|
||||
<ClCompile Include="sph\blake2s.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -363,7 +267,7 @@
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="compat.h">
|
||||
<Filter>Header Files\compat</Filter>
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="elist.h">
|
||||
<Filter>Header Files</Filter>
|
||||
@@ -386,8 +290,8 @@
|
||||
<ClInclude Include="compat\stdbool.h">
|
||||
<Filter>Header Files\compat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="compat\ccminer-config.h">
|
||||
<Filter>Header Files\compat</Filter>
|
||||
<ClInclude Include="cpuminer-config.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="uint256.h">
|
||||
<Filter>Header Files</Filter>
|
||||
@@ -401,12 +305,6 @@
|
||||
<ClInclude Include="x11\cuda_x11.h">
|
||||
<Filter>Header Files\CUDA</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sph\blake2b.h">
|
||||
<Filter>Header Files\sph</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sph\blake2s.h">
|
||||
<Filter>Header Files\sph</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sph\sph_blake.h">
|
||||
<Filter>Header Files\sph</Filter>
|
||||
</ClInclude>
|
||||
@@ -512,9 +410,6 @@
|
||||
<ClInclude Include="lyra2\Lyra2.h">
|
||||
<Filter>Header Files\lyra2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lyra2\Lyra2Z.h">
|
||||
<Filter>Header Files\lyra2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lyra2\Sponge.h">
|
||||
<Filter>Header Files\lyra2</Filter>
|
||||
</ClInclude>
|
||||
@@ -542,74 +437,23 @@
|
||||
<ClInclude Include="bignum.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lyra2\cuda_lyra2v2_sm3.cuh">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lyra2\cuda_lyra2_sm2.cuh">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lyra2\cuda_lyra2_sm5.cuh">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lyra2\cuda_lyra2Z_sm5.cuh">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="quark\cuda_quark_blake512_sp.cuh">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="quark\cuda_bmw512_sm3.cuh">
|
||||
<ClInclude Include="quark\cuda_skein512_sp.cuh">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="quark\cuda_quark_groestl512_sm2.cuh">
|
||||
<ClInclude Include="quark\cuda_bmw512_sm3.cuh">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="x11\cuda_x11_simd512_sm2.cuh">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sia\sia-rpc.h">
|
||||
<Filter>Source Files\sia</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\xmr-rpc.h">
|
||||
<Filter>Source Files\crypto</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\mman.h">
|
||||
<Filter>Source Files\crypto\bbr</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\wildkeccak.h">
|
||||
<Filter>Source Files\crypto\bbr</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\cn_aes.cuh">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\cn_blake.cuh">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\cn_groestl.cuh">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\cn_jh.cuh">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\cn_keccak.cuh">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\cn_skein.cuh">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\cryptolight.h">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="crypto\cryptonight.h">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="equi\eqcuda.hpp">
|
||||
<Filter>Source Files\equi</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="equi\equihash.h">
|
||||
<Filter>Source Files\equi</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="x16\cuda_x16.h">
|
||||
<Filter>Header Files\CUDA</Filter>
|
||||
<ClInclude Include="lyra2\cuda_lyra2_sm5.cuh">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -622,9 +466,6 @@
|
||||
<CudaCompile Include="JHA\cuda_jha_keccak512.cu">
|
||||
<Filter>Source Files\CUDA\JHA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="JHA\jha.cu">
|
||||
<Filter>Source Files\CUDA\JHA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="JHA\jackpotcoin.cu">
|
||||
<Filter>Source Files\CUDA\JHA</Filter>
|
||||
</CudaCompile>
|
||||
@@ -667,12 +508,6 @@
|
||||
<CudaCompile Include="heavy\heavy.cu">
|
||||
<Filter>Source Files\CUDA\heavy</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="heavy\bastion.cu">
|
||||
<Filter>Source Files\CUDA\heavy</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="heavy\cuda_bastion.cu">
|
||||
<Filter>Source Files\CUDA\heavy</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\cuda_bmw512.cu">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</CudaCompile>
|
||||
@@ -682,9 +517,6 @@
|
||||
<CudaCompile Include="quark\cuda_quark_keccak512.cu">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\nist5.cu">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\quarkcoin.cu">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</CudaCompile>
|
||||
@@ -700,6 +532,9 @@
|
||||
<CudaCompile Include="qubit\qubit_luffa512.cu">
|
||||
<Filter>Source Files\CUDA\qubit</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="cuda_nist5.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<ClInclude Include="x11\cuda_x11_aes.cuh">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</ClInclude>
|
||||
@@ -733,9 +568,6 @@
|
||||
<CudaCompile Include="x11\x11.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\x11evo.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x13\cuda_x13_fugue512.cu">
|
||||
<Filter>Source Files\CUDA\x13</Filter>
|
||||
</CudaCompile>
|
||||
@@ -745,12 +577,6 @@
|
||||
<CudaCompile Include="x13\x13.cu">
|
||||
<Filter>Source Files\CUDA\x13</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x13\cuda_hsr_sm3.cu">
|
||||
<Filter>Source Files\CUDA\x13</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x13\hsr.cu">
|
||||
<Filter>Source Files\CUDA\x13</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="cuda_checkhash.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
@@ -775,78 +601,21 @@
|
||||
<CudaCompile Include="x17\cuda_x17_sha512.cu">
|
||||
<Filter>Source Files\CUDA\x17</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x17\hmq17.cu">
|
||||
<Filter>Source Files\CUDA\x17</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x17\sonoa.cu">
|
||||
<Filter>Source Files\CUDA\x17</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x17\x17.cu">
|
||||
<Filter>Source Files\CUDA\x17</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="pentablake.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="polytimos.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="phi\phi.cu">
|
||||
<Filter>Source Files\CUDA\phi</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="phi\phi2.cu">
|
||||
<Filter>Source Files\CUDA\phi</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="phi\cuda_phi2.cu">
|
||||
<Filter>Source Files\CUDA\phi</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="phi\cuda_phi2_cubehash512.cu">
|
||||
<Filter>Source Files\CUDA\phi</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="skunk\skunk.cu">
|
||||
<Filter>Source Files\CUDA\skunk</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="skunk\cuda_skunk.cu">
|
||||
<Filter>Source Files\CUDA\skunk</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="skunk\cuda_skunk_streebog.cu">
|
||||
<Filter>Source Files\CUDA\skunk</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="tribus\tribus.cu">
|
||||
<Filter>Source Files\CUDA\tribus</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="tribus\cuda_echo512_final.cu">
|
||||
<Filter>Source Files\CUDA\tribus</Filter>
|
||||
</CudaCompile>
|
||||
<ClInclude Include="tribus\cuda_echo512_aes.cuh">
|
||||
<Filter>Source Files\CUDA\tribus</Filter>
|
||||
</ClInclude>
|
||||
<CudaCompile Include="x11\sib.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\cuda_streebog.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\cuda_streebog_maxwell.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\s3.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x12\x12.cu">
|
||||
<Filter>Source Files\CUDA\x12</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\timetravel.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\bitcore.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\exosis.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\veltor.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\blake256.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
@@ -857,7 +626,7 @@
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\keccak256.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\cuda_blake256.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
@@ -877,9 +646,6 @@
|
||||
<CudaCompile Include="Algo256\cuda_keccak256.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\cuda_keccak256_sm3.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\cuda_skein256.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
@@ -931,9 +697,6 @@
|
||||
<CudaCompile Include="Algo256\cuda_bmw.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lyra2\allium.cu">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lyra2\cuda_lyra2.cu">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</CudaCompile>
|
||||
@@ -946,105 +709,9 @@
|
||||
<CudaCompile Include="lyra2\lyra2REv2.cu">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lyra2\cuda_lyra2v3.cu">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</CudaCompile>
|
||||
<ClInclude Include="lyra2\cuda_lyra2v3_sm3.cuh">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</ClInclude>
|
||||
<CudaCompile Include="lyra2\lyra2REv3.cu">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lyra2\cuda_lyra2Z.cu">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lyra2\lyra2Z.cu">
|
||||
<Filter>Source Files\CUDA\lyra2</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="blake2b.cu">
|
||||
<Filter>Source Files\CUDA\</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\blake2s.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lbry\cuda_sha256_lbry.cu">
|
||||
<Filter>Source Files\CUDA\lbry</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lbry\cuda_sha512_lbry.cu">
|
||||
<Filter>Source Files\CUDA\lbry</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lbry\cuda_lbry_merged.cu">
|
||||
<Filter>Source Files\CUDA\lbry</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lbry\lbry.cu">
|
||||
<Filter>Source Files\CUDA\lbry</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\cuda_sha256d.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\sha256d.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\cuda_sha256t.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\sha256t.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\cuda_sha256q.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\sha256q.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sia\sia.cu">
|
||||
<Filter>Source Files\sia</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="crypto\cryptolight.cu">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="crypto\cryptolight-core.cu">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="crypto\cryptonight.cu">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="crypto\cryptonight-core.cu">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="crypto\cryptonight-extra.cu">
|
||||
<Filter>Source Files\CUDA\xmr</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="crypto\wildkeccak.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="equi\cuda_equi.cu">
|
||||
<Filter>Source Files\equi</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\cuda_x15_whirlpool_sm3.cu">
|
||||
<Filter>Source Files\CUDA\x15</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x16\cuda_x16_echo512.cu">
|
||||
<Filter>Source Files\CUDA\x16</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x16\cuda_x16_echo512_64.cu">
|
||||
<Filter>Source Files\CUDA\x16</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x16\cuda_x16_fugue512.cu">
|
||||
<Filter>Source Files\CUDA\x16</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x16\cuda_x16_shabal512.cu">
|
||||
<Filter>Source Files\CUDA\x16</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x16\cuda_x16_simd512_80.cu">
|
||||
<Filter>Source Files\CUDA\x16</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x16\x16r.cu">
|
||||
<Filter>Source Files\CUDA\x16</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x16\x16s.cu">
|
||||
<Filter>Source Files\CUDA\x16</Filter>
|
||||
</CudaCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="res\ccminer.ico">
|
||||
@@ -1061,4 +728,4 @@
|
||||
<Filter>Ressources</Filter>
|
||||
</Text>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -51,17 +51,6 @@ static __inline int setpriority(int which, int who, int prio)
|
||||
#define strcasecmp(x,y) _stricmp(x,y)
|
||||
typedef int ssize_t;
|
||||
|
||||
__inline int msver(void) {
|
||||
switch (_MSC_VER) {
|
||||
case 1500: return 2008;
|
||||
case 1600: return 2010;
|
||||
case 1700: return 2012;
|
||||
case 1800: return 2013;
|
||||
case 1900: return 2015;
|
||||
default: return (_MSC_VER/100);
|
||||
}
|
||||
}
|
||||
|
||||
#include <stdlib.h>
|
||||
static __inline char * dirname(char *file) {
|
||||
char buffer[_MAX_PATH] = { 0 };
|
||||
|
||||
@@ -1,602 +0,0 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_BIGNUM_H
|
||||
#define BITCOIN_BIGNUM_H
|
||||
|
||||
#ifndef PROTOCOL_VERSION
|
||||
#define PROTOCOL_VERSION 70001
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "uint256.h"
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include "serialize.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** Errors thrown by the bignum class */
|
||||
class bignum_error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit bignum_error(const std::string& str) : std::runtime_error(str) {}
|
||||
};
|
||||
|
||||
|
||||
/** RAII encapsulated BN_CTX (OpenSSL bignum context) */
|
||||
class CAutoBN_CTX
|
||||
{
|
||||
protected:
|
||||
BN_CTX* pctx;
|
||||
BN_CTX* operator=(BN_CTX* pnew) { return pctx = pnew; }
|
||||
|
||||
public:
|
||||
CAutoBN_CTX()
|
||||
{
|
||||
pctx = BN_CTX_new();
|
||||
if (pctx == NULL)
|
||||
throw bignum_error("CAutoBN_CTX : BN_CTX_new() returned NULL");
|
||||
}
|
||||
|
||||
~CAutoBN_CTX()
|
||||
{
|
||||
if (pctx != NULL)
|
||||
BN_CTX_free(pctx);
|
||||
}
|
||||
|
||||
operator BN_CTX*() { return pctx; }
|
||||
BN_CTX& operator*() { return *pctx; }
|
||||
BN_CTX** operator&() { return &pctx; }
|
||||
bool operator!() { return (pctx == NULL); }
|
||||
};
|
||||
|
||||
|
||||
/** C++ wrapper for BIGNUM (OpenSSL bignum) */
|
||||
class CBigNum : public BIGNUM
|
||||
{
|
||||
public:
|
||||
CBigNum()
|
||||
{
|
||||
BN_init(this);
|
||||
}
|
||||
|
||||
CBigNum(const CBigNum& b)
|
||||
{
|
||||
BN_init(this);
|
||||
if (!BN_copy(this, &b))
|
||||
{
|
||||
BN_clear_free(this);
|
||||
throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed");
|
||||
}
|
||||
}
|
||||
|
||||
CBigNum& operator=(const CBigNum& b)
|
||||
{
|
||||
if (!BN_copy(this, &b))
|
||||
throw bignum_error("CBigNum::operator= : BN_copy failed");
|
||||
return (*this);
|
||||
}
|
||||
|
||||
~CBigNum()
|
||||
{
|
||||
BN_clear_free(this);
|
||||
}
|
||||
|
||||
//CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
|
||||
CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(int64 n) { BN_init(this); setint64(n); }
|
||||
CBigNum(unsigned char n) { BN_init(this); setulong(n); }
|
||||
CBigNum(unsigned short n) { BN_init(this); setulong(n); }
|
||||
CBigNum(unsigned int n) { BN_init(this); setulong(n); }
|
||||
CBigNum(unsigned long n) { BN_init(this); setulong(n); }
|
||||
CBigNum(uint64 n) { BN_init(this); setuint64(n); }
|
||||
explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); }
|
||||
|
||||
explicit CBigNum(const std::vector<unsigned char>& vch)
|
||||
{
|
||||
BN_init(this);
|
||||
setvch(vch);
|
||||
}
|
||||
|
||||
void setulong(unsigned long n)
|
||||
{
|
||||
if (!BN_set_word(this, n))
|
||||
throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed");
|
||||
}
|
||||
|
||||
unsigned long getulong() const
|
||||
{
|
||||
return (unsigned long) BN_get_word(this);
|
||||
}
|
||||
|
||||
unsigned int getuint() const
|
||||
{
|
||||
return (unsigned int) BN_get_word(this);
|
||||
}
|
||||
|
||||
int getint() const
|
||||
{
|
||||
unsigned long n = (unsigned long) BN_get_word(this);
|
||||
if (!BN_is_negative(this))
|
||||
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
|
||||
else
|
||||
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
|
||||
}
|
||||
|
||||
void setint64(int64 sn)
|
||||
{
|
||||
unsigned char pch[sizeof(sn) + 6];
|
||||
unsigned char* p = pch + 4;
|
||||
bool fNegative;
|
||||
uint64 n;
|
||||
|
||||
if (sn < 0LL)
|
||||
{
|
||||
// Since the minimum signed integer cannot be represented as positive so long as its type is signed,
|
||||
// and it's not well-defined what happens if you make it unsigned before negating it,
|
||||
// we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
|
||||
n = -(sn + 1);
|
||||
++n;
|
||||
fNegative = true;
|
||||
} else {
|
||||
n = sn;
|
||||
fNegative = false;
|
||||
}
|
||||
|
||||
bool fLeadingZeroes = true;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
unsigned char c = (n >> 56) & 0xff;
|
||||
n <<= 8;
|
||||
if (fLeadingZeroes)
|
||||
{
|
||||
if (c == 0)
|
||||
continue;
|
||||
if (c & 0x80)
|
||||
*p++ = (fNegative ? 0x80 : 0);
|
||||
else if (fNegative)
|
||||
c |= 0x80;
|
||||
fLeadingZeroes = false;
|
||||
}
|
||||
*p++ = c;
|
||||
}
|
||||
unsigned int nSize = (unsigned int) (p - (pch + 4));
|
||||
pch[0] = (nSize >> 24) & 0xff;
|
||||
pch[1] = (nSize >> 16) & 0xff;
|
||||
pch[2] = (nSize >> 8) & 0xff;
|
||||
pch[3] = (nSize) & 0xff;
|
||||
BN_mpi2bn(pch, (int) (p - pch), this);
|
||||
}
|
||||
|
||||
void setuint64(uint64 n)
|
||||
{
|
||||
unsigned char pch[sizeof(n) + 6];
|
||||
unsigned char* p = pch + 4;
|
||||
bool fLeadingZeroes = true;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
unsigned char c = (n >> 56) & 0xff;
|
||||
n <<= 8;
|
||||
if (fLeadingZeroes)
|
||||
{
|
||||
if (c == 0)
|
||||
continue;
|
||||
if (c & 0x80)
|
||||
*p++ = 0;
|
||||
fLeadingZeroes = false;
|
||||
}
|
||||
*p++ = c;
|
||||
}
|
||||
unsigned int nSize = (unsigned int) (p - (pch + 4));
|
||||
pch[0] = (nSize >> 24) & 0xff;
|
||||
pch[1] = (nSize >> 16) & 0xff;
|
||||
pch[2] = (nSize >> 8) & 0xff;
|
||||
pch[3] = (nSize) & 0xff;
|
||||
BN_mpi2bn(pch, (int) (p - pch), this);
|
||||
}
|
||||
|
||||
void setuint256(uint256 n)
|
||||
{
|
||||
unsigned char pch[sizeof(n) + 6];
|
||||
unsigned char* p = pch + 4;
|
||||
bool fLeadingZeroes = true;
|
||||
unsigned char* pbegin = (unsigned char*)&n;
|
||||
unsigned char* psrc = pbegin + sizeof(n);
|
||||
while (psrc != pbegin)
|
||||
{
|
||||
unsigned char c = *(--psrc);
|
||||
if (fLeadingZeroes)
|
||||
{
|
||||
if (c == 0)
|
||||
continue;
|
||||
if (c & 0x80)
|
||||
*p++ = 0;
|
||||
fLeadingZeroes = false;
|
||||
}
|
||||
*p++ = c;
|
||||
}
|
||||
unsigned int nSize = (unsigned int) (p - (pch + 4));
|
||||
pch[0] = (nSize >> 24) & 0xff;
|
||||
pch[1] = (nSize >> 16) & 0xff;
|
||||
pch[2] = (nSize >> 8) & 0xff;
|
||||
pch[3] = (nSize >> 0) & 0xff;
|
||||
BN_mpi2bn(pch, (int) (p - pch), this);
|
||||
}
|
||||
|
||||
uint256 getuint256() const
|
||||
{
|
||||
unsigned int nSize = BN_bn2mpi(this, NULL);
|
||||
if (nSize < 4)
|
||||
return 0;
|
||||
std::vector<unsigned char> vch(nSize);
|
||||
BN_bn2mpi(this, &vch[0]);
|
||||
if (vch.size() > 4)
|
||||
vch[4] &= 0x7f;
|
||||
uint256 n = 0;
|
||||
for (unsigned int i = 0, j = (unsigned int) vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
|
||||
((unsigned char*)&n)[i] = vch[j];
|
||||
return n;
|
||||
}
|
||||
|
||||
void setvch(const std::vector<unsigned char>& vch)
|
||||
{
|
||||
std::vector<unsigned char> vch2(vch.size() + 4);
|
||||
unsigned int nSize = (unsigned int) vch.size();
|
||||
// BIGNUM's byte stream format expects 4 bytes of
|
||||
// big endian size data info at the front
|
||||
vch2[0] = (nSize >> 24) & 0xff;
|
||||
vch2[1] = (nSize >> 16) & 0xff;
|
||||
vch2[2] = (nSize >> 8) & 0xff;
|
||||
vch2[3] = (nSize >> 0) & 0xff;
|
||||
// swap data to big endian
|
||||
reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);
|
||||
BN_mpi2bn(&vch2[0], (int) vch2.size(), this);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> getvch() const
|
||||
{
|
||||
unsigned int nSize = BN_bn2mpi(this, NULL);
|
||||
if (nSize <= 4)
|
||||
return std::vector<unsigned char>();
|
||||
std::vector<unsigned char> vch(nSize);
|
||||
BN_bn2mpi(this, &vch[0]);
|
||||
vch.erase(vch.begin(), vch.begin() + 4);
|
||||
reverse(vch.begin(), vch.end());
|
||||
return vch;
|
||||
}
|
||||
|
||||
// The "compact" format is a representation of a whole
|
||||
// number N using an unsigned 32bit number similar to a
|
||||
// floating point format.
|
||||
// The most significant 8 bits are the unsigned exponent of base 256.
|
||||
// This exponent can be thought of as "number of bytes of N".
|
||||
// The lower 23 bits are the mantissa.
|
||||
// Bit number 24 (0x800000) represents the sign of N.
|
||||
// N = (-1^sign) * mantissa * 256^(exponent-3)
|
||||
//
|
||||
// Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn().
|
||||
// MPI uses the most significant bit of the first byte as sign.
|
||||
// Thus 0x1234560000 is compact (0x05123456)
|
||||
// and 0xc0de000000 is compact (0x0600c0de)
|
||||
// (0x05c0de00) would be -0x40de000000
|
||||
//
|
||||
// Bitcoin only uses this "compact" format for encoding difficulty
|
||||
// targets, which are unsigned 256bit quantities. Thus, all the
|
||||
// complexities of the sign bit and using base 256 are probably an
|
||||
// implementation accident.
|
||||
//
|
||||
// This implementation directly uses shifts instead of going
|
||||
// through an intermediate MPI representation.
|
||||
CBigNum& SetCompact(unsigned int nCompact)
|
||||
{
|
||||
unsigned int nSize = nCompact >> 24;
|
||||
bool fNegative =(nCompact & 0x00800000) != 0;
|
||||
unsigned int nWord = nCompact & 0x007fffff;
|
||||
if (nSize <= 3)
|
||||
{
|
||||
nWord >>= 8*(3-nSize);
|
||||
BN_set_word(this, nWord);
|
||||
}
|
||||
else
|
||||
{
|
||||
BN_set_word(this, nWord);
|
||||
BN_lshift(this, this, 8*(nSize-3));
|
||||
}
|
||||
BN_set_negative(this, fNegative);
|
||||
return *this;
|
||||
}
|
||||
|
||||
unsigned int GetCompact() const
|
||||
{
|
||||
unsigned int nSize = BN_num_bytes(this);
|
||||
unsigned int nCompact = 0;
|
||||
if (nSize <= 3)
|
||||
nCompact = (unsigned int) BN_get_word(this) << 8*(3-nSize);
|
||||
else
|
||||
{
|
||||
CBigNum bn;
|
||||
BN_rshift(&bn, this, 8*(nSize-3));
|
||||
nCompact = (unsigned int) BN_get_word(&bn);
|
||||
}
|
||||
// The 0x00800000 bit denotes the sign.
|
||||
// Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
|
||||
if (nCompact & 0x00800000)
|
||||
{
|
||||
nCompact >>= 8;
|
||||
nSize++;
|
||||
}
|
||||
nCompact |= nSize << 24;
|
||||
nCompact |= (BN_is_negative(this) ? 0x00800000 : 0);
|
||||
return nCompact;
|
||||
}
|
||||
|
||||
void SetHex(const std::string& str)
|
||||
{
|
||||
// skip 0x
|
||||
const char* psz = str.c_str();
|
||||
while (isspace(*psz))
|
||||
psz++;
|
||||
bool fNegative = false;
|
||||
if (*psz == '-')
|
||||
{
|
||||
fNegative = true;
|
||||
psz++;
|
||||
}
|
||||
if (psz[0] == '0' && tolower(psz[1]) == 'x')
|
||||
psz += 2;
|
||||
while (isspace(*psz))
|
||||
psz++;
|
||||
|
||||
// hex string to bignum
|
||||
static const signed char phexdigit[256] = { 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,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,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,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 };
|
||||
*this = 0;
|
||||
while (isxdigit(*psz))
|
||||
{
|
||||
*this <<= 4;
|
||||
int n = phexdigit[(unsigned char)*psz++];
|
||||
*this += n;
|
||||
}
|
||||
if (fNegative)
|
||||
*this = 0 - *this;
|
||||
}
|
||||
|
||||
std::string ToString(int nBase=10) const
|
||||
{
|
||||
CAutoBN_CTX pctx;
|
||||
CBigNum bnBase = nBase;
|
||||
CBigNum bn0 = 0;
|
||||
std::string str;
|
||||
CBigNum bn = *this;
|
||||
BN_set_negative(&bn, false);
|
||||
CBigNum dv;
|
||||
CBigNum rem;
|
||||
if (BN_cmp(&bn, &bn0) == 0)
|
||||
return "0";
|
||||
while (BN_cmp(&bn, &bn0) > 0)
|
||||
{
|
||||
if (!BN_div(&dv, &rem, &bn, &bnBase, pctx))
|
||||
throw bignum_error("CBigNum::ToString() : BN_div failed");
|
||||
bn = dv;
|
||||
unsigned int c = rem.getulong();
|
||||
str += "0123456789abcdef"[c];
|
||||
}
|
||||
if (BN_is_negative(this))
|
||||
str += "-";
|
||||
reverse(str.begin(), str.end());
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string GetHex() const
|
||||
{
|
||||
return ToString(16);
|
||||
}
|
||||
|
||||
unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const
|
||||
{
|
||||
return ::GetSerializeSize(getvch(), nType, nVersion);
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const
|
||||
{
|
||||
::Serialize(s, getvch(), nType, nVersion);
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION)
|
||||
{
|
||||
std::vector<unsigned char> vch;
|
||||
::Unserialize(s, vch, nType, nVersion);
|
||||
setvch(vch);
|
||||
}
|
||||
|
||||
|
||||
bool operator!() const
|
||||
{
|
||||
return BN_is_zero(this);
|
||||
}
|
||||
|
||||
CBigNum& operator+=(const CBigNum& b)
|
||||
{
|
||||
if (!BN_add(this, this, &b))
|
||||
throw bignum_error("CBigNum::operator+= : BN_add failed");
|
||||
return *this;
|
||||
}
|
||||
|
||||
CBigNum& operator-=(const CBigNum& b)
|
||||
{
|
||||
*this = *this - b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CBigNum& operator*=(const CBigNum& b)
|
||||
{
|
||||
CAutoBN_CTX pctx;
|
||||
if (!BN_mul(this, this, &b, pctx))
|
||||
throw bignum_error("CBigNum::operator*= : BN_mul failed");
|
||||
return *this;
|
||||
}
|
||||
|
||||
CBigNum& operator/=(const CBigNum& b)
|
||||
{
|
||||
*this = *this / b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CBigNum& operator%=(const CBigNum& b)
|
||||
{
|
||||
*this = *this % b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CBigNum& operator<<=(unsigned int shift)
|
||||
{
|
||||
if (!BN_lshift(this, this, shift))
|
||||
throw bignum_error("CBigNum:operator<<= : BN_lshift failed");
|
||||
return *this;
|
||||
}
|
||||
|
||||
CBigNum& operator>>=(unsigned int shift)
|
||||
{
|
||||
// Note: BN_rshift segfaults on 64-bit if 2^shift is greater than the number
|
||||
// if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL
|
||||
CBigNum a = 1;
|
||||
a <<= shift;
|
||||
if (BN_cmp(&a, this) > 0)
|
||||
{
|
||||
*this = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (!BN_rshift(this, this, shift))
|
||||
throw bignum_error("CBigNum:operator>>= : BN_rshift failed");
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
CBigNum& operator++()
|
||||
{
|
||||
// prefix operator
|
||||
if (!BN_add(this, this, BN_value_one()))
|
||||
throw bignum_error("CBigNum::operator++ : BN_add failed");
|
||||
return *this;
|
||||
}
|
||||
|
||||
const CBigNum operator++(int)
|
||||
{
|
||||
// postfix operator
|
||||
const CBigNum ret = *this;
|
||||
++(*this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
CBigNum& operator--()
|
||||
{
|
||||
// prefix operator
|
||||
CBigNum r;
|
||||
if (!BN_sub(&r, this, BN_value_one()))
|
||||
throw bignum_error("CBigNum::operator-- : BN_sub failed");
|
||||
*this = r;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const CBigNum operator--(int)
|
||||
{
|
||||
// postfix operator
|
||||
const CBigNum ret = *this;
|
||||
--(*this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
friend inline const CBigNum operator-(const CBigNum& a, const CBigNum& b);
|
||||
friend inline const CBigNum operator/(const CBigNum& a, const CBigNum& b);
|
||||
friend inline const CBigNum operator%(const CBigNum& a, const CBigNum& b);
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
|
||||
{
|
||||
CBigNum r;
|
||||
if (!BN_add(&r, &a, &b))
|
||||
throw bignum_error("CBigNum::operator+ : BN_add failed");
|
||||
return r;
|
||||
}
|
||||
|
||||
inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
|
||||
{
|
||||
CBigNum r;
|
||||
if (!BN_sub(&r, &a, &b))
|
||||
throw bignum_error("CBigNum::operator- : BN_sub failed");
|
||||
return r;
|
||||
}
|
||||
|
||||
inline const CBigNum operator-(const CBigNum& a)
|
||||
{
|
||||
CBigNum r(a);
|
||||
BN_set_negative(&r, !BN_is_negative(&r));
|
||||
return r;
|
||||
}
|
||||
|
||||
inline const CBigNum operator*(const CBigNum& a, const CBigNum& b)
|
||||
{
|
||||
CAutoBN_CTX pctx;
|
||||
CBigNum r;
|
||||
if (!BN_mul(&r, &a, &b, pctx))
|
||||
throw bignum_error("CBigNum::operator* : BN_mul failed");
|
||||
return r;
|
||||
}
|
||||
|
||||
inline const CBigNum operator/(const CBigNum& a, const CBigNum& b)
|
||||
{
|
||||
CAutoBN_CTX pctx;
|
||||
CBigNum r;
|
||||
if (!BN_div(&r, NULL, &a, &b, pctx))
|
||||
throw bignum_error("CBigNum::operator/ : BN_div failed");
|
||||
return r;
|
||||
}
|
||||
|
||||
inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
|
||||
{
|
||||
CAutoBN_CTX pctx;
|
||||
CBigNum r;
|
||||
if (!BN_mod(&r, &a, &b, pctx))
|
||||
throw bignum_error("CBigNum::operator% : BN_div failed");
|
||||
return r;
|
||||
}
|
||||
|
||||
inline const CBigNum operator<<(const CBigNum& a, unsigned int shift)
|
||||
{
|
||||
CBigNum r;
|
||||
if (!BN_lshift(&r, &a, shift))
|
||||
throw bignum_error("CBigNum:operator<< : BN_lshift failed");
|
||||
return r;
|
||||
}
|
||||
|
||||
inline const CBigNum operator>>(const CBigNum& a, unsigned int shift)
|
||||
{
|
||||
CBigNum r = a;
|
||||
r >>= shift;
|
||||
return r;
|
||||
}
|
||||
|
||||
inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); }
|
||||
inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); }
|
||||
inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); }
|
||||
inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
|
||||
inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) < 0); }
|
||||
inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) > 0); }
|
||||
|
||||
#endif
|
||||
@@ -23,9 +23,6 @@
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define inline __inline
|
||||
#if !defined(HAVE_STRUCT_TIMESPEC) && _MSC_VER >= 1900
|
||||
#define HAVE_STRUCT_TIMESPEC
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Binary file not shown.
+192
-1196
File diff suppressed because it is too large.
Load diff
@@ -1,371 +1,2 @@
|
||||
#pragma once
|
||||
|
||||
#define NVAPI_INTERNAL
|
||||
#include "nvapi.h"
|
||||
|
||||
NvAPI_Status nvapi_dll_init();
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU8 valid;
|
||||
NvU8 count;
|
||||
struct
|
||||
{
|
||||
NvU32 pstate; // Assumption
|
||||
NvU32 unknown1[2];
|
||||
NvU32 min_power;
|
||||
NvU32 unknown2[2];
|
||||
NvU32 def_power;
|
||||
NvU32 unknown3[2];
|
||||
NvU32 max_power;
|
||||
NvU32 unknown4; // 0
|
||||
} entries[4];
|
||||
} NVAPI_GPU_POWER_INFO;
|
||||
#define NVAPI_GPU_POWER_INFO_VER MAKE_NVAPI_VERSION(NVAPI_GPU_POWER_INFO, 1)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 flags;
|
||||
struct {
|
||||
NvU32 unknown1;
|
||||
NvU32 unknown2;
|
||||
NvU32 power; // percent * 1000
|
||||
NvU32 unknown4;
|
||||
} entries[4];
|
||||
} NVAPI_GPU_POWER_STATUS;
|
||||
#define NVAPI_GPU_POWER_STATUS_VER MAKE_NVAPI_VERSION(NVAPI_GPU_POWER_STATUS, 1)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 count;
|
||||
struct {
|
||||
NvU32 unknown1;
|
||||
NvU32 unknown2;
|
||||
NvU32 power; // unsure ?? 85536 to 95055 on 1080, 104825+ on 970
|
||||
NvU32 unknown4;
|
||||
} entries[4];
|
||||
} NVAPI_GPU_POWER_TOPO;
|
||||
#define NVAPI_GPU_POWER_TOPO_VER MAKE_NVAPI_VERSION(NVAPI_GPU_POWER_TOPO, 1)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 flags;
|
||||
struct {
|
||||
NvU32 controller;
|
||||
NvU32 unknown;
|
||||
NvS32 min_temp;
|
||||
NvS32 def_temp;
|
||||
NvS32 max_temp;
|
||||
NvU32 defaultFlags;
|
||||
} entries[4];
|
||||
} NVAPI_GPU_THERMAL_INFO;
|
||||
#define NVAPI_GPU_THERMAL_INFO_VER MAKE_NVAPI_VERSION(NVAPI_GPU_THERMAL_INFO, 2)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 flags;
|
||||
struct {
|
||||
NvU32 controller;
|
||||
NvU32 value;
|
||||
NvU32 flags;
|
||||
} entries[4];
|
||||
} NVAPI_GPU_THERMAL_LIMIT;
|
||||
#define NVAPI_GPU_THERMAL_LIMIT_VER MAKE_NVAPI_VERSION(NVAPI_GPU_THERMAL_LIMIT, 2)
|
||||
|
||||
// Maxwell gpu core voltage reading
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 flags;
|
||||
NvU32 count; // unsure
|
||||
NvU32 unknown;
|
||||
NvU32 value_uV;
|
||||
NvU32 buf1[30];
|
||||
} NVAPI_VOLT_STATUS; // 140 bytes (1-008c)
|
||||
#define NVAPI_VOLT_STATUS_VER MAKE_NVAPI_VERSION(NVAPI_VOLT_STATUS, 1)
|
||||
|
||||
// Pascal gpu core voltage reading
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 flags;
|
||||
NvU32 nul[8];
|
||||
NvU32 value_uV;
|
||||
NvU32 buf1[8];
|
||||
} NVAPI_VOLTAGE_STATUS; // 76 bytes (1-004c)
|
||||
#define NVAPI_VOLTAGE_STATUS_VER MAKE_NVAPI_VERSION(NVAPI_VOLTAGE_STATUS, 1)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 numClocks; // unsure
|
||||
NvU32 nul[8];
|
||||
struct {
|
||||
NvU32 a;
|
||||
NvU32 clockType;
|
||||
NvU32 c;
|
||||
NvU32 d;
|
||||
NvU32 e;
|
||||
NvU32 f;
|
||||
NvU32 g;
|
||||
NvU32 h;
|
||||
NvU32 i;
|
||||
NvU32 j;
|
||||
NvS32 rangeMax;
|
||||
NvS32 rangeMin;
|
||||
NvS32 tempMax; // ? unsure
|
||||
NvU32 n;
|
||||
NvU32 o;
|
||||
NvU32 p;
|
||||
NvU32 q;
|
||||
NvU32 r;
|
||||
} entries[32]; // NVAPI_MAX_GPU_CLOCKS ?
|
||||
} NVAPI_CLOCKS_RANGE; // 2344 bytes
|
||||
#define NVAPI_CLOCKS_RANGE_VER MAKE_NVAPI_VERSION(NVAPI_CLOCKS_RANGE, 1)
|
||||
|
||||
// seems to return a clock table mask
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 mask[4]; // 80 bits mask
|
||||
NvU32 buf0[8];
|
||||
struct {
|
||||
NvU32 a;
|
||||
NvU32 b;
|
||||
NvU32 c;
|
||||
NvU32 d;
|
||||
NvU32 memDelta; // 1 for mem
|
||||
NvU32 gpuDelta; // 1 for gpu
|
||||
} clocks[80 + 23];
|
||||
NvU32 buf1[916];
|
||||
} NVAPI_CLOCK_MASKS; // 6188 bytes
|
||||
#define NVAPI_CLOCK_MASKS_VER MAKE_NVAPI_VERSION(NVAPI_CLOCK_MASKS, 1)
|
||||
|
||||
// contains the gpu/mem clocks deltas
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 mask[4]; // 80 bits mask (could be 8x 32bits)
|
||||
NvU32 buf0[12];
|
||||
struct {
|
||||
NvU32 a;
|
||||
NvU32 b;
|
||||
NvU32 c;
|
||||
NvU32 d;
|
||||
NvU32 e;
|
||||
NvS32 freqDelta; // 84000 = +84MHz
|
||||
NvU32 g;
|
||||
NvU32 h;
|
||||
NvU32 i;
|
||||
} gpuDeltas[80];
|
||||
NvU32 memFilled[23]; // maybe only 4 max
|
||||
NvS32 memDeltas[23];
|
||||
NvU32 buf1[1529];
|
||||
} NVAPI_CLOCK_TABLE; // 9248 bytes
|
||||
#define NVAPI_CLOCK_TABLE_VER MAKE_NVAPI_VERSION(NVAPI_CLOCK_TABLE, 1)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 mask[4]; // 80 bits mask
|
||||
NvU32 buf0[12];
|
||||
struct {
|
||||
NvU32 a; // 0
|
||||
NvU32 freq_kHz;
|
||||
NvU32 volt_uV;
|
||||
NvU32 d;
|
||||
NvU32 e;
|
||||
NvU32 f;
|
||||
NvU32 g;
|
||||
} gpuEntries[80];
|
||||
struct {
|
||||
NvU32 a; // 1 for idle values ?
|
||||
NvU32 freq_kHz;
|
||||
NvU32 volt_uV;
|
||||
NvU32 d;
|
||||
NvU32 e;
|
||||
NvU32 f;
|
||||
NvU32 g;
|
||||
} memEntries[23];
|
||||
NvU32 buf1[1064];
|
||||
} NVAPI_VFP_CURVE; // 7208 bytes (1-1c28)
|
||||
#define NVAPI_VFP_CURVE_VER MAKE_NVAPI_VERSION(NVAPI_VFP_CURVE, 1)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvS32 percent;
|
||||
NvU32 pad[8];
|
||||
} NVAPI_VOLTBOOST_PERCENT; // 40 bytes (1-0028)
|
||||
#define NVAPI_VOLTBOOST_PERCENT_VER MAKE_NVAPI_VERSION(NVAPI_VOLTBOOST_PERCENT, 1)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 flags;
|
||||
NvU32 filled; // 1
|
||||
struct {
|
||||
NvU32 volt_uV;
|
||||
NvU32 unknown;
|
||||
} entries[128];
|
||||
// some empty tables then...
|
||||
NvU32 buf1[3888];
|
||||
} NVAPI_VOLTAGES_TABLE; // 16588 bytes (1-40cc)
|
||||
#define NVAPI_VOLTAGES_TABLE_VER MAKE_NVAPI_VERSION(NVAPI_VOLTAGES_TABLE, 1)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 val1; // 7
|
||||
NvU32 val2; // 0x3F (63.)
|
||||
NvU32 pad[16];
|
||||
} NVAPI_GPU_PERF_INFO; // 76 bytes (1-004c)
|
||||
#define NVAPI_GPU_PERF_INFO_VER MAKE_NVAPI_VERSION(NVAPI_GPU_PERF_INFO, 1)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 flags; // 0
|
||||
NvU64 timeRef; // increment with time
|
||||
NvU64 val1; // seen 1 4 5 while mining, 16 else
|
||||
NvU64 val2; // seen 7 and 3
|
||||
NvU64 values[3]; // increment with time
|
||||
NvU32 pad[326]; // empty
|
||||
} NVAPI_GPU_PERF_STATUS; // 1360 bytes (1-0550)
|
||||
#define NVAPI_GPU_PERF_STATUS_VER MAKE_NVAPI_VERSION(NVAPI_GPU_PERF_STATUS, 1)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 val1; // 4
|
||||
NvU32 val2; // 2 or 0
|
||||
NvU32 val3; // 2
|
||||
NvU32 val4; // 3
|
||||
NV_GPU_PERF_PSTATE_ID pStateId;
|
||||
NvU32 val6; // 0 or 2
|
||||
NvU32 val7; // 4
|
||||
NvU32 val8; // 0
|
||||
NvU32 memFreq1; // 405000.
|
||||
NvU32 memFreq2; // 405000.
|
||||
NvU32 memFreqMin;// 101250.
|
||||
NvU32 memFreqMax;// 486000.
|
||||
NvU32 zeros[3];
|
||||
NvU32 gpuFreq1; // 696000. Unsure about those
|
||||
NvU32 gpuFreq2; // 696000.
|
||||
NvU32 gpuFreqMin;// 174000.
|
||||
NvU32 gpuFreqMax;// 658000.
|
||||
NvU32 pad[2697];
|
||||
} NVAPI_GPU_PERF_CLOCKS; // 10868 bytes (2-2a74)
|
||||
#define NVAPI_GPU_PERF_CLOCKS_VER MAKE_NVAPI_VERSION(NVAPI_GPU_PERF_CLOCKS, 2)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 level;
|
||||
NvU32 count;
|
||||
NvU32 pad[339]; // (4-0558)
|
||||
} NVAPI_COOLER_SETTINGS;
|
||||
#define NVAPI_COOLER_SETTINGS_VER MAKE_NVAPI_VERSION(NVAPI_COOLER_SETTINGS, 4)
|
||||
|
||||
typedef struct {
|
||||
NvU32 version;
|
||||
NvU32 level; // 0 = auto ?
|
||||
NvU32 count; // 1
|
||||
NvU32 pad[38]; // (1-00a4)
|
||||
} NVAPI_COOLER_LEVEL;
|
||||
#define NVAPI_COOLER_LEVEL_VER MAKE_NVAPI_VERSION(NVAPI_COOLER_LEVEL, 1)
|
||||
|
||||
NvAPI_Status NvAPI_DLL_GetInterfaceVersionString(NvAPI_ShortString string);
|
||||
|
||||
NvAPI_Status NvAPI_DLL_PerfPoliciesGetInfo(NvPhysicalGpuHandle, NVAPI_GPU_PERF_INFO*); // 409D9841 1-004c
|
||||
NvAPI_Status NvAPI_DLL_PerfPoliciesGetStatus(NvPhysicalGpuHandle, NVAPI_GPU_PERF_STATUS*); // 3D358A0C 1-0550
|
||||
|
||||
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesGetInfo(NvPhysicalGpuHandle, NVAPI_GPU_POWER_INFO*);
|
||||
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesGetStatus(NvPhysicalGpuHandle, NVAPI_GPU_POWER_STATUS*);
|
||||
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesSetStatus(NvPhysicalGpuHandle, NVAPI_GPU_POWER_STATUS*);
|
||||
NvAPI_Status NvAPI_DLL_ClientPowerTopologyGetStatus(NvPhysicalGpuHandle, NVAPI_GPU_POWER_TOPO*); // EDCF624E 1-0048
|
||||
|
||||
NvAPI_Status NvAPI_DLL_ClientThermalPoliciesGetInfo(NvPhysicalGpuHandle, NVAPI_GPU_THERMAL_INFO*);
|
||||
NvAPI_Status NvAPI_DLL_ClientThermalPoliciesGetLimit(NvPhysicalGpuHandle, NVAPI_GPU_THERMAL_LIMIT*);
|
||||
NvAPI_Status NvAPI_DLL_ClientThermalPoliciesSetLimit(NvPhysicalGpuHandle, NVAPI_GPU_THERMAL_LIMIT*);
|
||||
|
||||
// Pascal GTX only
|
||||
NvAPI_Status NvAPI_DLL_GetClockBoostRanges(NvPhysicalGpuHandle, NVAPI_CLOCKS_RANGE*);
|
||||
NvAPI_Status NvAPI_DLL_GetClockBoostMask(NvPhysicalGpuHandle, NVAPI_CLOCK_MASKS*); // 0x507B4B59
|
||||
NvAPI_Status NvAPI_DLL_GetClockBoostTable(NvPhysicalGpuHandle, NVAPI_CLOCK_TABLE*); // 0x23F1B133
|
||||
NvAPI_Status NvAPI_DLL_SetClockBoostTable(NvPhysicalGpuHandle, NVAPI_CLOCK_TABLE*); // 0x0733E009
|
||||
NvAPI_Status NvAPI_DLL_GetVFPCurve(NvPhysicalGpuHandle, NVAPI_VFP_CURVE*); // 0x21537AD4
|
||||
NvAPI_Status NvAPI_DLL_GetCurrentVoltage(NvPhysicalGpuHandle, NVAPI_VOLTAGE_STATUS*); // 0x465F9BCF 1-004c
|
||||
NvAPI_Status NvAPI_DLL_GetCoreVoltageBoostPercent(NvPhysicalGpuHandle, NVAPI_VOLTBOOST_PERCENT*);
|
||||
NvAPI_Status NvAPI_DLL_SetCoreVoltageBoostPercent(NvPhysicalGpuHandle, NVAPI_VOLTBOOST_PERCENT*);
|
||||
|
||||
// Maxwell only
|
||||
NvAPI_Status NvAPI_DLL_GetVoltageDomainsStatus(NvPhysicalGpuHandle, NVAPI_VOLT_STATUS*); // 0xC16C7E2C
|
||||
NvAPI_Status NvAPI_DLL_GetVoltages(NvPhysicalGpuHandle, NVAPI_VOLTAGES_TABLE*); // 0x7D656244 1-40CC
|
||||
NvAPI_Status NvAPI_DLL_GetVoltageStep(NvPhysicalGpuHandle, NVAPI_VOLT_STATUS*); // 0x28766157 1-008C unsure of the name
|
||||
|
||||
NvAPI_Status NvAPI_DLL_GetCoolerSettings(NvPhysicalGpuHandle, uint32_t, NVAPI_COOLER_SETTINGS*); // 0xDA141340 4-0558
|
||||
NvAPI_Status NvAPI_DLL_SetCoolerLevels(NvPhysicalGpuHandle, uint32_t, NVAPI_COOLER_LEVEL*); // 0x891FA0AE 1-00A4
|
||||
NvAPI_Status NvAPI_DLL_RestoreCoolerSettings(NvPhysicalGpuHandle, NVAPI_COOLER_SETTINGS*, uint32_t);
|
||||
|
||||
NvAPI_Status NvAPI_DLL_GetSerialNumber(NvPhysicalGpuHandle, NvAPI_ShortString serial);
|
||||
|
||||
NvAPI_Status NvAPI_DLL_GetPerfClocks(NvPhysicalGpuHandle, uint32_t num, NVAPI_GPU_PERF_CLOCKS* pClocks); // 2-2A74
|
||||
//NvAPI_Status NvAPI_DLL_SetPerfClocks(NvPhysicalGpuHandle, uint32_t num, NVAPI_GPU_PERF_CLOCKS* pClocks); // error
|
||||
|
||||
//invalid..
|
||||
//NvAPI_Status NvAPI_DLL_GetPstateClientLimits(NvPhysicalGpuHandle, NV_GPU_PERF_PSTATE_ID, uint32_t* pLimits);
|
||||
//NvAPI_Status NvAPI_DLL_SetPstateClientLimits(NvPhysicalGpuHandle, NV_GPU_PERF_PSTATE_ID, uint32_t* pLimits);
|
||||
|
||||
NvAPI_Status NvAPI_DLL_SetPstates20v1(NvPhysicalGpuHandle handle, NV_GPU_PERF_PSTATES20_INFO_V1 *pSet);
|
||||
NvAPI_Status NvAPI_DLL_SetPstates20v2(NvPhysicalGpuHandle handle, NV_GPU_PERF_PSTATES20_INFO_V2 *pSet);
|
||||
|
||||
NvAPI_Status NvAPI_DLL_Unload();
|
||||
|
||||
#define NV_ASSERT(x) { NvAPI_Status ret = x; if(ret != NVAPI_OK) return ret; }
|
||||
|
||||
// to reduce stack size, allow to reuse a mem buffer
|
||||
#define NV_INIT_STRUCT_ON(TYPE, var, mem) { \
|
||||
var = (TYPE*) mem; \
|
||||
memset(var, 0, sizeof(TYPE)); \
|
||||
var->version = TYPE##_VER; \
|
||||
}
|
||||
|
||||
// alloc a struct, need free(var)
|
||||
#define NV_INIT_STRUCT_ALLOC(TYPE, var) { \
|
||||
var = (TYPE*) calloc(1, TYPE##_VER & 0xFFFF); \
|
||||
if (var) var->version = TYPE##_VER; \
|
||||
}
|
||||
|
||||
//! Used in NvAPI_I2CReadEx()
|
||||
typedef struct
|
||||
{
|
||||
NvU32 version;
|
||||
NvU32 displayMask; // Display Mask of the concerned display.
|
||||
NvU8 bIsDDCPort; // indicates either the DDC port (TRUE) or the communication port (FALSE) of the concerned display.
|
||||
NvU8 i2cDevAddress; // address of the I2C slave. The address should be shifted left by one. 0x50 -> 0xA0.
|
||||
NvU8* pbI2cRegAddress; // I2C target register address. May be NULL, which indicates no register address should be sent.
|
||||
NvU32 regAddrSize; // size in bytes of target register address. If pbI2cRegAddress is NULL, this field must be 0.
|
||||
NvU8* pbData; // buffer of data which is to be read or written (depending on the command).
|
||||
NvU32 cbRead; // bytes to read ??? seems required on write too
|
||||
NvU32 cbSize; // full size of the data buffer, pbData, to be read or written.
|
||||
NV_I2C_SPEED i2cSpeedKhz; // target speed of the transaction in (kHz) (Chosen from the enum NV_I2C_SPEED).
|
||||
NvU8 portId; // portid on which device is connected (remember to set bIsPortIdSet if this value is set)
|
||||
NvU32 bIsPortIdSet; // set this flag on if and only if portid value is set
|
||||
|
||||
} NV_I2C_INFO_EX;
|
||||
#define NV_I2C_INFO_EX_VER MAKE_NVAPI_VERSION(NV_I2C_INFO_EX,3)
|
||||
/*
|
||||
sample evga x64 call (struct of 0x40 bytes)
|
||||
ReadEx
|
||||
$ ==> 40 00 03 00 00 00 00 00 00 40 00 00 00 00 00 00
|
||||
$+10 58 F9 2B 00 00 00 00 00 01 00 00 00 00 00 00 00
|
||||
$+20 C0 F9 2B 00 00 00 00 00 02 00 00 00 FF FF 00 00
|
||||
$+30 00 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00
|
||||
|
||||
$ ==> 40 00 03 00 00 00 00 00 00 10 00 00 00 00 00 00
|
||||
$+10 68 F9 2B 00 00 00 00 00 01 00 00 00 00 00 00 00
|
||||
$+20 C0 F9 2B 00 00 00 00 00 01 00 00 00 FF FF 00 00
|
||||
$+30 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00
|
||||
00000000002BF968 > 75 83 CF 3F 01 00 00 00
|
||||
00000000002BF9C0 > 0
|
||||
|
||||
WriteEx
|
||||
$ ==> 40 00 03 00 00 00 00 00 00 8C 00 00 00 00 00 00
|
||||
$+10 30 F9 2B 00 00 00 00 00 01 00 00 00 00 00 00 00
|
||||
$+20 38 F9 2B 00 00 00 00 00 02 00 00 00 FF FF 00 00
|
||||
$+30 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00
|
||||
00000000002BF930 > D1 00 00 00 00 00 00 00
|
||||
00000000002BF938 > 38 00 00 00 00 00 00 00
|
||||
*/
|
||||
|
||||
NvAPI_Status NvAPI_DLL_I2CReadEx(NvPhysicalGpuHandle, NV_I2C_INFO_EX*, NvU32*);
|
||||
NvAPI_Status NvAPI_DLL_I2CWriteEx(NvPhysicalGpuHandle, NV_I2C_INFO_EX*, NvU32*);
|
||||
/* todo: stripped version... or not */
|
||||
#include "nvapi.h"
|
||||
@@ -1,36 +1,3 @@
|
||||
/************************************************************************************************************************************\
|
||||
|* *|
|
||||
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|
||||
|* *|
|
||||
|* NOTICE TO USER: *|
|
||||
|* *|
|
||||
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|
||||
|* *|
|
||||
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|
||||
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|
||||
|* Otherwise, you have no rights to use or access this software in any manner. *|
|
||||
|* *|
|
||||
|* If not covered by the applicable NVIDIA software license agreement: *|
|
||||
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|
||||
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|
||||
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|
||||
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|
||||
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|
||||
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|
||||
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|
||||
|* *|
|
||||
|* U.S. Government End Users. *|
|
||||
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|
||||
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|
||||
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|
||||
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|
||||
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|
||||
|* *|
|
||||
|* Any use of this software in individual and commercial software must include, *|
|
||||
|* in the user documentation and internal comments to the code, *|
|
||||
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|
||||
|* *|
|
||||
\************************************************************************************************************************************/
|
||||
#pragma once
|
||||
#include"nvapi_lite_salstart.h"
|
||||
#pragma pack(push,8)
|
||||
@@ -53,7 +20,6 @@ extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* 64-bit types for compilers that support them, plus some obsolete variants */
|
||||
#if defined(__GNUC__) || defined(__arm) || defined(__IAR_SYSTEMS_ICC__) || defined(__ghs__) || defined(_WIN64)
|
||||
typedef unsigned long long NvU64; /* 0 to 18446744073709551615 */
|
||||
@@ -70,7 +36,6 @@ typedef signed long NvS32; /* -2147483648 to 2147483647 */
|
||||
typedef signed int NvS32; /* -2147483648 to 2147483647 */
|
||||
#endif
|
||||
|
||||
#ifndef __unix
|
||||
// mac os 32-bit still needs this
|
||||
#if ( (defined(macintosh) && defined(__LP64__) && (__NVAPI_RESERVED0__)) || \
|
||||
(!defined(macintosh) && defined(__NVAPI_RESERVED0__)) )
|
||||
@@ -78,22 +43,12 @@ typedef unsigned int NvU32; /* 0 to 4294967295 */
|
||||
#else
|
||||
typedef unsigned long NvU32; /* 0 to 4294967295 */
|
||||
#endif
|
||||
#else
|
||||
typedef unsigned int NvU32; /* 0 to 4294967295 */
|
||||
#endif
|
||||
|
||||
typedef unsigned long temp_NvU32; /* 0 to 4294967295 */
|
||||
typedef signed short NvS16;
|
||||
typedef unsigned short NvU16;
|
||||
typedef unsigned char NvU8;
|
||||
typedef signed char NvS8;
|
||||
|
||||
/* Boolean type */
|
||||
typedef NvU8 NvBool;
|
||||
#define NV_TRUE ((NvBool)(0 == 0))
|
||||
#define NV_FALSE ((NvBool)(0 != 0))
|
||||
|
||||
|
||||
typedef struct _NV_RECT
|
||||
{
|
||||
NvU32 left;
|
||||
@@ -344,20 +299,11 @@ typedef enum _NvAPI_Status
|
||||
NVAPI_TIMEOUT = -191, //!< Requested operation timed out
|
||||
NVAPI_GPU_WORKSTATION_FEATURE_INCOMPLETE = -192, //!< The requested workstation feature set has incomplete driver internal allocation resources
|
||||
NVAPI_STEREO_INIT_ACTIVATION_NOT_DONE = -193, //!< Call failed because InitActivation was not called.
|
||||
NVAPI_SYNC_NOT_ACTIVE = -194, //!< The requested action cannot be performed without Sync being enabled.
|
||||
NVAPI_SYNC_MASTER_NOT_FOUND = -195, //!< The requested action cannot be performed without Sync Master being enabled.
|
||||
NVAPI_INVALID_SYNC_TOPOLOGY = -196, //!< Invalid displays passed in the NV_GSYNC_DISPLAY pointer.
|
||||
NVAPI_SYNC_NOT_ACTIVE = -194, //!< The requested action cannot be performed without Sync being enabled.
|
||||
NVAPI_SYNC_MASTER_NOT_FOUND = -195, //!< The requested action cannot be performed without Sync Master being enabled.
|
||||
NVAPI_INVALID_SYNC_TOPOLOGY = -196, //!< Invalid displays passed in the NV_GSYNC_DISPLAY pointer.
|
||||
NVAPI_ECID_SIGN_ALGO_UNSUPPORTED = -197, //!< The specified signing algorithm is not supported. Either an incorrect value was entered or the current installed driver/hardware does not support the input value.
|
||||
NVAPI_ECID_KEY_VERIFICATION_FAILED = -198, //!< The encrypted public key verification has failed.
|
||||
NVAPI_FIRMWARE_OUT_OF_DATE = -199, //!< The device's firmware is out of date.
|
||||
NVAPI_FIRMWARE_REVISION_NOT_SUPPORTED = -200, //!< The device's firmware is not supported.
|
||||
NVAPI_LICENSE_CALLER_AUTHENTICATION_FAILED = -201, //!< The caller is not authorized to modify the License.
|
||||
NVAPI_D3D_DEVICE_NOT_REGISTERED = -202, //!< The user tried to use a deferred context without registering the device first
|
||||
NVAPI_RESOURCE_NOT_ACQUIRED = -203, //!< Head or SourceId was not reserved for the VR Display before doing the Modeset.
|
||||
NVAPI_TIMING_NOT_SUPPORTED = -204, //!< Provided timing is not supported.
|
||||
NVAPI_HDCP_ENCRYPTION_FAILED = -205, //!< HDCP Encryption Failed for the device. Would be applicable when the device is HDCP Capable.
|
||||
NVAPI_PCLK_LIMITATION_FAILED = -206, //!< Provided mode is over sink device pclk limitation.
|
||||
NVAPI_NO_CONNECTOR_FOUND = -207, //!< No connector on GPU found.
|
||||
NVAPI_ECID_KEY_VERIFICATION_FAILED = -198, //!< The encrypted public key verification has failed.
|
||||
} NvAPI_Status;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -406,23 +352,9 @@ typedef struct
|
||||
|
||||
} NV_DISPLAY_DRIVER_MEMORY_INFO_V2;
|
||||
|
||||
//! \ingroup driverapi
|
||||
//! Used in NvAPI_GPU_GetMemoryInfo().
|
||||
typedef struct
|
||||
{
|
||||
NvU32 version; //!< Version info
|
||||
NvU32 dedicatedVideoMemory; //!< Size(in kb) of the physical framebuffer.
|
||||
NvU32 availableDedicatedVideoMemory; //!< Size(in kb) of the available physical framebuffer for allocating video memory surfaces.
|
||||
NvU32 systemVideoMemory; //!< Size(in kb) of system memory the driver allocates at load time.
|
||||
NvU32 sharedSystemMemory; //!< Size(in kb) of shared system memory that driver is allowed to commit for surfaces across all allocations.
|
||||
NvU32 curAvailableDedicatedVideoMemory; //!< Size(in kb) of the current available physical framebuffer for allocating video memory surfaces.
|
||||
NvU32 dedicatedVideoMemoryEvictionsSize; //!< Size(in kb) of the total size of memory released as a result of the evictions.
|
||||
NvU32 dedicatedVideoMemoryEvictionCount; //!< Indicates the number of eviction events that caused an allocation to be removed from dedicated video memory to free GPU
|
||||
//!< video memory to make room for other allocations.
|
||||
} NV_DISPLAY_DRIVER_MEMORY_INFO_V3;
|
||||
|
||||
//! \ingroup driverapi
|
||||
typedef NV_DISPLAY_DRIVER_MEMORY_INFO_V3 NV_DISPLAY_DRIVER_MEMORY_INFO;
|
||||
typedef NV_DISPLAY_DRIVER_MEMORY_INFO_V2 NV_DISPLAY_DRIVER_MEMORY_INFO;
|
||||
|
||||
//! \ingroup driverapi
|
||||
//! Macro for constructing the version field of NV_DISPLAY_DRIVER_MEMORY_INFO_V1
|
||||
@@ -433,11 +365,7 @@ typedef NV_DISPLAY_DRIVER_MEMORY_INFO_V3 NV_DISPLAY_DRIVER_MEMORY_INFO;
|
||||
#define NV_DISPLAY_DRIVER_MEMORY_INFO_VER_2 MAKE_NVAPI_VERSION(NV_DISPLAY_DRIVER_MEMORY_INFO_V2,2)
|
||||
|
||||
//! \ingroup driverapi
|
||||
//! Macro for constructing the version field of NV_DISPLAY_DRIVER_MEMORY_INFO_V3
|
||||
#define NV_DISPLAY_DRIVER_MEMORY_INFO_VER_3 MAKE_NVAPI_VERSION(NV_DISPLAY_DRIVER_MEMORY_INFO_V3,3)
|
||||
|
||||
//! \ingroup driverapi
|
||||
#define NV_DISPLAY_DRIVER_MEMORY_INFO_VER NV_DISPLAY_DRIVER_MEMORY_INFO_VER_3
|
||||
#define NV_DISPLAY_DRIVER_MEMORY_INFO_VER NV_DISPLAY_DRIVER_MEMORY_INFO_VER_2
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,36 +1,3 @@
|
||||
/************************************************************************************************************************************\
|
||||
|* *|
|
||||
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|
||||
|* *|
|
||||
|* NOTICE TO USER: *|
|
||||
|* *|
|
||||
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|
||||
|* *|
|
||||
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|
||||
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|
||||
|* Otherwise, you have no rights to use or access this software in any manner. *|
|
||||
|* *|
|
||||
|* If not covered by the applicable NVIDIA software license agreement: *|
|
||||
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|
||||
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|
||||
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|
||||
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|
||||
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|
||||
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|
||||
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|
||||
|* *|
|
||||
|* U.S. Government End Users. *|
|
||||
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|
||||
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|
||||
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|
||||
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|
||||
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|
||||
|* *|
|
||||
|* Any use of this software in individual and commercial software must include, *|
|
||||
|* in the user documentation and internal comments to the code, *|
|
||||
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|
||||
|* *|
|
||||
\************************************************************************************************************************************/
|
||||
#pragma once
|
||||
#include"nvapi_lite_salstart.h"
|
||||
#include"nvapi_lite_common.h"
|
||||
@@ -62,10 +29,6 @@ typedef enum
|
||||
//! argument (D3D_FEATURE_LEVEL supported by the device) that the function fills in. This argument
|
||||
//! can contain -1 (NVAPI_DEVICE_FEATURE_LEVEL_NULL), if the requested featureLevel is less than DirecX 10.0.
|
||||
//!
|
||||
//! NOTE: When NvAPI_D3D11_CreateDevice is called with 10+ feature level we have an issue on few set of
|
||||
//! tesla hardware (G80/G84/G86/G92/G94/G96) which does not support all feature level 10+ functionality
|
||||
//! e.g. calling driver with mismatch between RenderTarget and Depth Buffer. App developers should
|
||||
//! take into consideration such limitation when using NVAPI on such tesla hardwares.
|
||||
//! SUPPORTED OS: Windows Vista and higher
|
||||
//!
|
||||
//!
|
||||
|
||||
@@ -1,36 +1,3 @@
|
||||
/************************************************************************************************************************************\
|
||||
|* *|
|
||||
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|
||||
|* *|
|
||||
|* NOTICE TO USER: *|
|
||||
|* *|
|
||||
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|
||||
|* *|
|
||||
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|
||||
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|
||||
|* Otherwise, you have no rights to use or access this software in any manner. *|
|
||||
|* *|
|
||||
|* If not covered by the applicable NVIDIA software license agreement: *|
|
||||
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|
||||
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|
||||
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|
||||
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|
||||
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|
||||
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|
||||
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|
||||
|* *|
|
||||
|* U.S. Government End Users. *|
|
||||
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|
||||
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|
||||
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|
||||
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|
||||
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|
||||
|* *|
|
||||
|* Any use of this software in individual and commercial software must include, *|
|
||||
|* in the user documentation and internal comments to the code, *|
|
||||
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|
||||
|* *|
|
||||
\************************************************************************************************************************************/
|
||||
#ifndef __NVAPI_EMPTY_SAL
|
||||
#ifdef __nvapi_undef__ecount
|
||||
#undef __ecount
|
||||
|
||||
@@ -1,37 +1,3 @@
|
||||
/************************************************************************************************************************************\
|
||||
|* *|
|
||||
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|
||||
|* *|
|
||||
|* NOTICE TO USER: *|
|
||||
|* *|
|
||||
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|
||||
|* *|
|
||||
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|
||||
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|
||||
|* Otherwise, you have no rights to use or access this software in any manner. *|
|
||||
|* *|
|
||||
|* If not covered by the applicable NVIDIA software license agreement: *|
|
||||
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|
||||
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|
||||
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|
||||
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|
||||
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|
||||
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|
||||
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|
||||
|* *|
|
||||
|* U.S. Government End Users. *|
|
||||
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|
||||
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|
||||
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|
||||
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|
||||
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|
||||
|* *|
|
||||
|* Any use of this software in individual and commercial software must include, *|
|
||||
|* in the user documentation and internal comments to the code, *|
|
||||
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|
||||
|* *|
|
||||
\************************************************************************************************************************************/
|
||||
|
||||
// ====================================================
|
||||
// SAL related support
|
||||
// ====================================================
|
||||
|
||||
@@ -1,37 +1,3 @@
|
||||
/************************************************************************************************************************************\
|
||||
|* *|
|
||||
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|
||||
|* *|
|
||||
|* NOTICE TO USER: *|
|
||||
|* *|
|
||||
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|
||||
|* *|
|
||||
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|
||||
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|
||||
|* Otherwise, you have no rights to use or access this software in any manner. *|
|
||||
|* *|
|
||||
|* If not covered by the applicable NVIDIA software license agreement: *|
|
||||
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|
||||
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|
||||
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|
||||
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|
||||
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|
||||
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|
||||
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|
||||
|* *|
|
||||
|* U.S. Government End Users. *|
|
||||
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|
||||
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|
||||
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|
||||
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|
||||
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|
||||
|* *|
|
||||
|* Any use of this software in individual and commercial software must include, *|
|
||||
|* in the user documentation and internal comments to the code, *|
|
||||
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|
||||
|* *|
|
||||
\************************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include"nvapi_lite_salstart.h"
|
||||
#include"nvapi_lite_common.h"
|
||||
@@ -127,7 +93,6 @@ typedef enum _NVAPI_D3D_SETRESOURCEHINT_CATEGORY
|
||||
|
||||
//
|
||||
// NVAPI_D3D_SRH_SLI_APP_CONTROLLED_INTERFRAME_CONTENT_SYNC:
|
||||
// NVAPI_D3D_SRH_SLI_ASK_FOR_BROADCAST_USING:
|
||||
|
||||
|
||||
//! \ingroup dx
|
||||
@@ -136,15 +101,9 @@ typedef enum _NVAPI_D3D_SETRESOURCEHINT_CATEGORY
|
||||
//! Default value: 0 \n
|
||||
//! Explanation: If the value is 1, the driver will not track any rendering operations that would mark this resource as dirty,
|
||||
//! avoiding any form of synchronization across frames rendered in parallel in multiple GPUs in AFR mode.
|
||||
//!
|
||||
//! NVAPI_D3D_SRH_SLI_ASK_FOR_BROADCAST_USAGE: Valid values : 0 or 1 \n
|
||||
//! Default value: 0 \n
|
||||
//! Explanation: If the value is 1, the driver will try to perform operations which involved target resource in broadcast,
|
||||
//! where its possible. Hint is static and must be set before resource starts using.
|
||||
typedef enum _NVAPI_D3D_SETRESOURCEHINT_SLI
|
||||
{
|
||||
NVAPI_D3D_SRH_SLI_APP_CONTROLLED_INTERFRAME_CONTENT_SYNC = 1,
|
||||
NVAPI_D3D_SRH_SLI_ASK_FOR_BROADCAST_USAGE = 2
|
||||
NVAPI_D3D_SRH_SLI_APP_CONTROLLED_INTERFRAME_CONTENT_SYNC = 1
|
||||
} NVAPI_D3D_SETRESOURCEHINT_SLI;
|
||||
|
||||
//! \ingroup dx
|
||||
|
||||
@@ -1,37 +1,3 @@
|
||||
/************************************************************************************************************************************\
|
||||
|* *|
|
||||
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|
||||
|* *|
|
||||
|* NOTICE TO USER: *|
|
||||
|* *|
|
||||
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|
||||
|* *|
|
||||
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|
||||
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|
||||
|* Otherwise, you have no rights to use or access this software in any manner. *|
|
||||
|* *|
|
||||
|* If not covered by the applicable NVIDIA software license agreement: *|
|
||||
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|
||||
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|
||||
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|
||||
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|
||||
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|
||||
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|
||||
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|
||||
|* *|
|
||||
|* U.S. Government End Users. *|
|
||||
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|
||||
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|
||||
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|
||||
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|
||||
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|
||||
|* *|
|
||||
|* Any use of this software in individual and commercial software must include, *|
|
||||
|* in the user documentation and internal comments to the code, *|
|
||||
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|
||||
|* *|
|
||||
\************************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include"nvapi_lite_salstart.h"
|
||||
#include"nvapi_lite_common.h"
|
||||
|
||||
@@ -1,37 +1,3 @@
|
||||
/************************************************************************************************************************************\
|
||||
|* *|
|
||||
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|
||||
|* *|
|
||||
|* NOTICE TO USER: *|
|
||||
|* *|
|
||||
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|
||||
|* *|
|
||||
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|
||||
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|
||||
|* Otherwise, you have no rights to use or access this software in any manner. *|
|
||||
|* *|
|
||||
|* If not covered by the applicable NVIDIA software license agreement: *|
|
||||
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|
||||
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|
||||
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|
||||
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|
||||
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|
||||
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|
||||
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|
||||
|* *|
|
||||
|* U.S. Government End Users. *|
|
||||
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|
||||
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|
||||
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|
||||
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|
||||
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|
||||
|* *|
|
||||
|* Any use of this software in individual and commercial software must include, *|
|
||||
|* in the user documentation and internal comments to the code, *|
|
||||
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|
||||
|* *|
|
||||
\************************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include"nvapi_lite_salstart.h"
|
||||
#include"nvapi_lite_common.h"
|
||||
|
||||
Binary file not shown.
@@ -37,10 +37,6 @@
|
||||
#if !defined( PTHREAD_H )
|
||||
#define PTHREAD_H
|
||||
|
||||
#if !defined(HAVE_STRUCT_TIMESPEC) && _MSC_VER >= 1900
|
||||
#define HAVE_STRUCT_TIMESPEC
|
||||
#endif
|
||||
|
||||
/*
|
||||
* See the README file for an explanation of the pthreads-win32 version
|
||||
* numbering scheme and how the DLL is named etc.
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* Meant to improve clang 4 / macos compatibility (untested)
|
||||
*/
|
||||
|
||||
#ifndef PTHREAD_BARRIER_H_
|
||||
#define PTHREAD_BARRIER_H_
|
||||
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
typedef int pthread_barrierattr_t;
|
||||
typedef struct
|
||||
{
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
int count;
|
||||
int tripCount;
|
||||
} pthread_barrier_t;
|
||||
|
||||
|
||||
int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
|
||||
{
|
||||
if(count == 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if(pthread_mutex_init(&barrier->mutex, 0) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(pthread_cond_init(&barrier->cond, 0) < 0)
|
||||
{
|
||||
pthread_mutex_destroy(&barrier->mutex);
|
||||
return -1;
|
||||
}
|
||||
barrier->tripCount = count;
|
||||
barrier->count = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_barrier_destroy(pthread_barrier_t *barrier)
|
||||
{
|
||||
pthread_cond_destroy(&barrier->cond);
|
||||
pthread_mutex_destroy(&barrier->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_barrier_wait(pthread_barrier_t *barrier)
|
||||
{
|
||||
pthread_mutex_lock(&barrier->mutex);
|
||||
++(barrier->count);
|
||||
if(barrier->count >= barrier->tripCount)
|
||||
{
|
||||
barrier->count = 0;
|
||||
pthread_cond_broadcast(&barrier->cond);
|
||||
pthread_mutex_unlock(&barrier->mutex);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
|
||||
pthread_mutex_unlock(&barrier->mutex);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // PTHREAD_BARRIER_H_
|
||||
+3
-13
@@ -1,10 +1,10 @@
|
||||
AC_INIT([ccminer], [2.3.1], [], [ccminer], [http://github.com/lbryio/ccminer])
|
||||
AC_INIT([ccminer], [1.7.6-r10], [], [ccminer], [http://github.com/tpruvot/ccminer])
|
||||
|
||||
AC_PREREQ([2.59c])
|
||||
AC_CANONICAL_SYSTEM
|
||||
AC_CONFIG_SRCDIR([ccminer.cpp])
|
||||
AM_INIT_AUTOMAKE([foreign subdir-objects])
|
||||
AC_CONFIG_HEADERS([ccminer-config.h])
|
||||
AC_CONFIG_HEADERS([cpuminer-config.h])
|
||||
|
||||
dnl Make sure anyone changing configure.ac/Makefile.am has a clue
|
||||
AM_MAINTAINER_MODE
|
||||
@@ -63,10 +63,6 @@ case $target in
|
||||
PTHREAD_FLAGS=""
|
||||
WS2_LIBS="-lws2_32"
|
||||
;;
|
||||
*86*-apple-darwin*)
|
||||
have_osx=true
|
||||
PTHREAD_FLAGS=""
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_CHECK_LIB(jansson, json_loads, request_jansson=false, request_jansson=true)
|
||||
@@ -77,12 +73,11 @@ AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS="-lpthread",
|
||||
))))
|
||||
|
||||
AC_CHECK_LIB([z],[gzopen], [], [])
|
||||
AC_CHECK_LIB([ssl],[SSL_free], [], [AC_MSG_ERROR([OpenSSL library required])])
|
||||
AC_CHECK_LIB([ssl],[SSL_library_init], [], [AC_MSG_ERROR([OpenSSL library required])])
|
||||
AC_CHECK_LIB([crypto],[EVP_DigestFinal_ex], [], [AC_MSG_ERROR([OpenSSL library required])])
|
||||
|
||||
AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue])
|
||||
AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
|
||||
AM_CONDITIONAL([HAVE_OSX], [test x$have_osx = xtrue])
|
||||
AM_CONDITIONAL([ARCH_x86], [test x$have_x86 = xtrue])
|
||||
AM_CONDITIONAL([ARCH_x86_64], [test x$have_x86_64 = xtrue])
|
||||
|
||||
@@ -116,11 +111,6 @@ else
|
||||
SUFFIX=""
|
||||
fi
|
||||
|
||||
if test x$have_osx = xtrue
|
||||
then
|
||||
SUFFIX=""
|
||||
fi
|
||||
|
||||
dnl Setup CUDA paths
|
||||
AC_ARG_WITH([cuda],
|
||||
[ --with-cuda=PATH prefix where cuda is installed [default=/usr/local/cuda]])
|
||||
|
||||
+7
-1
@@ -1,4 +1,10 @@
|
||||
# To change the cuda arch, edit Makefile.am and run ./build.sh
|
||||
# possible additional CUDA_CFLAGS
|
||||
#-gencode=arch=compute_52,code=\"sm_52,compute_52\"
|
||||
#-gencode=arch=compute_50,code=\"sm_50,compute_50\"
|
||||
#-gencode=arch=compute_35,code=\"sm_35,compute_35\"
|
||||
#-gencode=arch=compute_30,code=\"sm_30,compute_30\"
|
||||
|
||||
#--ptxas-options=\"-v -dlcm=cg\""
|
||||
|
||||
extracflags="-march=native -D_REENTRANT -falign-functions=16 -falign-jumps=16 -falign-labels=16"
|
||||
|
||||
|
||||
@@ -1,188 +1,194 @@
|
||||
/* CONFIG ONLY FOR MS VC++ BUILD */
|
||||
|
||||
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
|
||||
systems. This function is required for `alloca.c' support on those systems.
|
||||
*/
|
||||
/* #undef CRAY_STACKSEG_END */
|
||||
|
||||
/* Define to 1 if using `alloca.c'. */
|
||||
/* #undef C_ALLOCA */
|
||||
|
||||
/* Define to 1 if you have `alloca', as a function or macro. */
|
||||
#define HAVE_ALLOCA 1
|
||||
|
||||
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
|
||||
*/
|
||||
#define HAVE_ALLOCA_H 1
|
||||
|
||||
/* Define to 1 if you have the declaration of `be32dec', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_BE32DEC 0
|
||||
|
||||
/* Define to 1 if you have the declaration of `be32enc', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_BE32ENC 0
|
||||
|
||||
/* Define to 1 if you have the declaration of `le32dec', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_LE32DEC 0
|
||||
|
||||
/* Define to 1 if you have the declaration of `le32enc', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_LE32ENC 0
|
||||
|
||||
/* Define to 1 if you have the `getopt_long' function. */
|
||||
#define HAVE_GETOPT_LONG 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||
#define HAVE_LIBCRYPTO 1
|
||||
|
||||
/* Define to 1 if you have a functional curl library. */
|
||||
#define HAVE_LIBCURL 1
|
||||
|
||||
/* Define to 1 if you have the `ssl' library (-lssl). */
|
||||
#define HAVE_LIBSSL 1
|
||||
|
||||
/* Define to 1 if you have the `z' library (-lz). */
|
||||
#define HAVE_LIBZ 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
/* #undef HAVE_SYSLOG_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/endian.h> header file. */
|
||||
/* #undef HAVE_SYS_ENDIAN_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/sysctl.h> header file. */
|
||||
#define HAVE_SYS_SYSCTL_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Defined if libcurl supports AsynchDNS */
|
||||
/* #undef LIBCURL_FEATURE_ASYNCHDNS */
|
||||
|
||||
/* Defined if libcurl supports IDN */
|
||||
#define LIBCURL_FEATURE_IDN 1
|
||||
|
||||
/* Defined if libcurl supports IPv6 */
|
||||
#define LIBCURL_FEATURE_IPV6 1
|
||||
|
||||
/* Defined if libcurl supports KRB4 */
|
||||
/* #undef LIBCURL_FEATURE_KRB4 */
|
||||
|
||||
/* Defined if libcurl supports libz */
|
||||
#define LIBCURL_FEATURE_LIBZ 1
|
||||
|
||||
/* Defined if libcurl supports NTLM */
|
||||
#define LIBCURL_FEATURE_NTLM 1
|
||||
|
||||
/* Defined if libcurl supports SSL */
|
||||
#define LIBCURL_FEATURE_SSL 1
|
||||
|
||||
/* Defined if libcurl supports SSPI */
|
||||
/* #undef LIBCURL_FEATURE_SSPI */
|
||||
|
||||
/* Defined if libcurl supports DICT */
|
||||
/* #undef LIBCURL_PROTOCOL_DICT */
|
||||
|
||||
/* Defined if libcurl supports FILE */
|
||||
#define LIBCURL_PROTOCOL_FILE 1
|
||||
|
||||
/* Defined if libcurl supports FTP */
|
||||
#define LIBCURL_PROTOCOL_FTP 1
|
||||
|
||||
/* Defined if libcurl supports FTPS */
|
||||
#define LIBCURL_PROTOCOL_FTPS 1
|
||||
|
||||
/* Defined if libcurl supports HTTP */
|
||||
#define LIBCURL_PROTOCOL_HTTP 1
|
||||
|
||||
/* Defined if libcurl supports HTTPS */
|
||||
#define LIBCURL_PROTOCOL_HTTPS 1
|
||||
|
||||
/* Defined if libcurl supports IMAP */
|
||||
/* #undef LIBCURL_PROTOCOL_IMAP */
|
||||
|
||||
/* Defined if libcurl supports LDAP */
|
||||
/* #undef LIBCURL_PROTOCOL_LDAP */
|
||||
|
||||
/* Defined if libcurl supports POP3 */
|
||||
/* #undef LIBCURL_PROTOCOL_POP3 */
|
||||
|
||||
/* Defined if libcurl supports RTSP */
|
||||
/* #undef LIBCURL_PROTOCOL_RTSP */
|
||||
|
||||
/* Defined if libcurl supports SMTP */
|
||||
/* #undef LIBCURL_PROTOCOL_SMTP */
|
||||
|
||||
/* Defined if libcurl supports TELNET */
|
||||
/* #undef LIBCURL_PROTOCOL_TELNET */
|
||||
|
||||
/* Defined if libcurl supports TFTP */
|
||||
/* #undef LIBCURL_PROTOCOL_TFTP */
|
||||
|
||||
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
|
||||
/* #undef NO_MINUS_C_MINUS_O */
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "ccminer"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "ccminer"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL "http://github.com/tpruvot/ccminer"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "2.3.1"
|
||||
|
||||
/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
automatically deduced at runtime.
|
||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||
STACK_DIRECTION = 0 => direction of growth unknown */
|
||||
/* #undef STACK_DIRECTION */
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define curl_free() as free() if our version of curl lacks curl_free. */
|
||||
/* #undef curl_free */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
//#define size_t unsigned int
|
||||
|
||||
#if !defined(HAVE_STRUCT_TIMESPEC) && _MSC_VER >= 1900
|
||||
#define HAVE_STRUCT_TIMESPEC
|
||||
#endif
|
||||
/* cpuminer-config.h. Generated from cpuminer-config.h.in by configure. */
|
||||
/* cpuminer-config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
|
||||
systems. This function is required for `alloca.c' support on those systems.
|
||||
*/
|
||||
/* #undef CRAY_STACKSEG_END */
|
||||
|
||||
/* Define to 1 if using `alloca.c'. */
|
||||
/* #undef C_ALLOCA */
|
||||
|
||||
/* Define to 1 if you have `alloca', as a function or macro. */
|
||||
#define HAVE_ALLOCA 1
|
||||
|
||||
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
|
||||
*/
|
||||
#define HAVE_ALLOCA_H 1
|
||||
|
||||
/* Define to 1 if you have the declaration of `be32dec', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_BE32DEC 0
|
||||
|
||||
/* Define to 1 if you have the declaration of `be32enc', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_BE32ENC 0
|
||||
|
||||
/* Define to 1 if you have the declaration of `le32dec', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_LE32DEC 0
|
||||
|
||||
/* Define to 1 if you have the declaration of `le32enc', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_LE32ENC 0
|
||||
|
||||
/* Define to 1 if you have the `getopt_long' function. */
|
||||
#define HAVE_GETOPT_LONG 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||
#define HAVE_LIBCRYPTO 1
|
||||
|
||||
/* Define to 1 if you have a functional curl library. */
|
||||
#define HAVE_LIBCURL 1
|
||||
|
||||
/* Define to 1 if you have the `ssl' library (-lssl). */
|
||||
#define HAVE_LIBSSL 1
|
||||
|
||||
/* Define to 1 if you have the `z' library (-lz). */
|
||||
#define HAVE_LIBZ 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
/* #undef HAVE_SYSLOG_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/endian.h> header file. */
|
||||
/* #undef HAVE_SYS_ENDIAN_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/sysctl.h> header file. */
|
||||
#define HAVE_SYS_SYSCTL_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Defined if libcurl supports AsynchDNS */
|
||||
/* #undef LIBCURL_FEATURE_ASYNCHDNS */
|
||||
|
||||
/* Defined if libcurl supports IDN */
|
||||
#define LIBCURL_FEATURE_IDN 1
|
||||
|
||||
/* Defined if libcurl supports IPv6 */
|
||||
#define LIBCURL_FEATURE_IPV6 1
|
||||
|
||||
/* Defined if libcurl supports KRB4 */
|
||||
/* #undef LIBCURL_FEATURE_KRB4 */
|
||||
|
||||
/* Defined if libcurl supports libz */
|
||||
#define LIBCURL_FEATURE_LIBZ 1
|
||||
|
||||
/* Defined if libcurl supports NTLM */
|
||||
#define LIBCURL_FEATURE_NTLM 1
|
||||
|
||||
/* Defined if libcurl supports SSL */
|
||||
#define LIBCURL_FEATURE_SSL 1
|
||||
|
||||
/* Defined if libcurl supports SSPI */
|
||||
/* #undef LIBCURL_FEATURE_SSPI */
|
||||
|
||||
/* Defined if libcurl supports DICT */
|
||||
/* #undef LIBCURL_PROTOCOL_DICT */
|
||||
|
||||
/* Defined if libcurl supports FILE */
|
||||
#define LIBCURL_PROTOCOL_FILE 1
|
||||
|
||||
/* Defined if libcurl supports FTP */
|
||||
#define LIBCURL_PROTOCOL_FTP 1
|
||||
|
||||
/* Defined if libcurl supports FTPS */
|
||||
#define LIBCURL_PROTOCOL_FTPS 1
|
||||
|
||||
/* Defined if libcurl supports HTTP */
|
||||
#define LIBCURL_PROTOCOL_HTTP 1
|
||||
|
||||
/* Defined if libcurl supports HTTPS */
|
||||
#define LIBCURL_PROTOCOL_HTTPS 1
|
||||
|
||||
/* Defined if libcurl supports IMAP */
|
||||
/* #undef LIBCURL_PROTOCOL_IMAP */
|
||||
|
||||
/* Defined if libcurl supports LDAP */
|
||||
/* #undef LIBCURL_PROTOCOL_LDAP */
|
||||
|
||||
/* Defined if libcurl supports POP3 */
|
||||
/* #undef LIBCURL_PROTOCOL_POP3 */
|
||||
|
||||
/* Defined if libcurl supports RTSP */
|
||||
/* #undef LIBCURL_PROTOCOL_RTSP */
|
||||
|
||||
/* Defined if libcurl supports SMTP */
|
||||
/* #undef LIBCURL_PROTOCOL_SMTP */
|
||||
|
||||
/* Defined if libcurl supports TELNET */
|
||||
/* #undef LIBCURL_PROTOCOL_TELNET */
|
||||
|
||||
/* Defined if libcurl supports TFTP */
|
||||
/* #undef LIBCURL_PROTOCOL_TFTP */
|
||||
|
||||
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
|
||||
/* #undef NO_MINUS_C_MINUS_O */
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "ccminer"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "ccminer"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "ccminer 1.7.6"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "ccminer"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL "http://github.com/tpruvot/ccminer"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.7.6"
|
||||
|
||||
/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
automatically deduced at runtime.
|
||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||
STACK_DIRECTION = 0 => direction of growth unknown */
|
||||
/* #undef STACK_DIRECTION */
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.7.6"
|
||||
|
||||
/* Define curl_free() as free() if our version of curl lacks curl_free. */
|
||||
/* #undef curl_free */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
//#define size_t unsigned int
|
||||
-170
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
The redistribution and use of this software (with or without changes)
|
||||
is allowed without the payment of fees or royalties provided that:
|
||||
|
||||
source code distributions include the above copyright notice, this
|
||||
list of conditions and the following disclaimer;
|
||||
|
||||
binary distributions include the above copyright notice, this list
|
||||
of conditions and the following disclaimer in their documentation.
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its operation, including, but not limited to, correctness
|
||||
and fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 20/12/2007
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define TABLE_ALIGN 32
|
||||
#define WPOLY 0x011b
|
||||
#define N_COLS 4
|
||||
#define AES_BLOCK_SIZE 16
|
||||
#define RC_LENGTH (5 * (AES_BLOCK_SIZE / 4 - 2))
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define ALIGN __declspec(align(TABLE_ALIGN))
|
||||
#elif defined(__GNUC__)
|
||||
#define ALIGN __attribute__ ((aligned(16)))
|
||||
#else
|
||||
#define ALIGN
|
||||
#endif
|
||||
|
||||
#define rf1(r,c) (r)
|
||||
#define word_in(x,c) (*((uint32_t*)(x)+(c)))
|
||||
#define word_out(x,c,v) (*((uint32_t*)(x)+(c)) = (v))
|
||||
|
||||
#define s(x,c) x[c]
|
||||
#define si(y,x,c) (s(y,c) = word_in(x, c))
|
||||
#define so(y,x,c) word_out(y, c, s(x,c))
|
||||
#define state_in(y,x) si(y,x,0); si(y,x,1); si(y,x,2); si(y,x,3)
|
||||
#define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3)
|
||||
#define round(y,x,k) \
|
||||
y[0] = (k)[0] ^ (t_fn[0][x[0] & 0xff] ^ t_fn[1][(x[1] >> 8) & 0xff] ^ t_fn[2][(x[2] >> 16) & 0xff] ^ t_fn[3][x[3] >> 24]); \
|
||||
y[1] = (k)[1] ^ (t_fn[0][x[1] & 0xff] ^ t_fn[1][(x[2] >> 8) & 0xff] ^ t_fn[2][(x[3] >> 16) & 0xff] ^ t_fn[3][x[0] >> 24]); \
|
||||
y[2] = (k)[2] ^ (t_fn[0][x[2] & 0xff] ^ t_fn[1][(x[3] >> 8) & 0xff] ^ t_fn[2][(x[0] >> 16) & 0xff] ^ t_fn[3][x[1] >> 24]); \
|
||||
y[3] = (k)[3] ^ (t_fn[0][x[3] & 0xff] ^ t_fn[1][(x[0] >> 8) & 0xff] ^ t_fn[2][(x[1] >> 16) & 0xff] ^ t_fn[3][x[2] >> 24]);
|
||||
#define to_byte(x) ((x) & 0xff)
|
||||
#define bval(x,n) to_byte((x) >> (8 * (n)))
|
||||
|
||||
#define fwd_var(x,r,c)\
|
||||
( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\
|
||||
: r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\
|
||||
: r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\
|
||||
: ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2)))
|
||||
|
||||
#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,n),fwd_var,rf1,c))
|
||||
|
||||
#define sb_data(w) {\
|
||||
w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\
|
||||
w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\
|
||||
w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\
|
||||
w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\
|
||||
w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\
|
||||
w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\
|
||||
w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\
|
||||
w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\
|
||||
w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\
|
||||
w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\
|
||||
w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\
|
||||
w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\
|
||||
w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\
|
||||
w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\
|
||||
w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\
|
||||
w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\
|
||||
w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\
|
||||
w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\
|
||||
w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\
|
||||
w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\
|
||||
w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\
|
||||
w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\
|
||||
w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\
|
||||
w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\
|
||||
w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\
|
||||
w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\
|
||||
w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\
|
||||
w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\
|
||||
w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\
|
||||
w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\
|
||||
w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\
|
||||
w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) }
|
||||
|
||||
#define rc_data(w) {\
|
||||
w(0x01), w(0x02), w(0x04), w(0x08), w(0x10),w(0x20), w(0x40), w(0x80),\
|
||||
w(0x1b), w(0x36) }
|
||||
|
||||
#define bytes2word(b0, b1, b2, b3) (((uint32_t)(b3) << 24) | \
|
||||
((uint32_t)(b2) << 16) | ((uint32_t)(b1) << 8) | (b0))
|
||||
|
||||
#define h0(x) (x)
|
||||
#define w0(p) bytes2word(p, 0, 0, 0)
|
||||
#define w1(p) bytes2word(0, p, 0, 0)
|
||||
#define w2(p) bytes2word(0, 0, p, 0)
|
||||
#define w3(p) bytes2word(0, 0, 0, p)
|
||||
|
||||
#define u0(p) bytes2word(f2(p), p, p, f3(p))
|
||||
#define u1(p) bytes2word(f3(p), f2(p), p, p)
|
||||
#define u2(p) bytes2word(p, f3(p), f2(p), p)
|
||||
#define u3(p) bytes2word(p, p, f3(p), f2(p))
|
||||
|
||||
#define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p))
|
||||
#define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p))
|
||||
#define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p))
|
||||
#define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p))
|
||||
|
||||
#define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY))
|
||||
#define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY))
|
||||
#define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) ^ (((x>>5) & 4) * WPOLY))
|
||||
#define f3(x) (f2(x) ^ x)
|
||||
#define f9(x) (f8(x) ^ x)
|
||||
#define fb(x) (f8(x) ^ f2(x) ^ x)
|
||||
#define fd(x) (f8(x) ^ f4(x) ^ x)
|
||||
#define fe(x) (f8(x) ^ f4(x) ^ f2(x))
|
||||
|
||||
#define t_dec(m,n) t_##m##n
|
||||
#define t_set(m,n) t_##m##n
|
||||
#define t_use(m,n) t_##m##n
|
||||
|
||||
#define d_4(t,n,b,e,f,g,h) ALIGN const t n[4][256] = { b(e), b(f), b(g), b(h) }
|
||||
|
||||
#define four_tables(x,tab,vf,rf,c) \
|
||||
(tab[0][bval(vf(x,0,c),rf(0,c))] \
|
||||
^ tab[1][bval(vf(x,1,c),rf(1,c))] \
|
||||
^ tab[2][bval(vf(x,2,c),rf(2,c))] \
|
||||
^ tab[3][bval(vf(x,3,c),rf(3,c))])
|
||||
|
||||
d_4(uint32_t, t_dec(f,n), sb_data, u0, u1, u2, u3);
|
||||
|
||||
void aesb_single_round(const uint8_t *in, uint8_t *out, uint8_t *expandedKey)
|
||||
{
|
||||
round(((uint32_t*) out), ((uint32_t*) in), ((uint32_t*) expandedKey));
|
||||
}
|
||||
|
||||
void aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey)
|
||||
{
|
||||
uint32_t b1[4];
|
||||
round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey));
|
||||
round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 1 * N_COLS);
|
||||
round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 2 * N_COLS);
|
||||
round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 3 * N_COLS);
|
||||
round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 4 * N_COLS);
|
||||
round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 5 * N_COLS);
|
||||
round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 6 * N_COLS);
|
||||
round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 7 * N_COLS);
|
||||
round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 8 * N_COLS);
|
||||
round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 9 * N_COLS);
|
||||
}
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
@@ -1,990 +0,0 @@
|
||||
|
||||
#define N_COLS 4
|
||||
#define WPOLY 0x011b
|
||||
/*
|
||||
static const __device__ __align__(16) uint32_t d_t_fn[1024] = {
|
||||
0xa56363c6U, 0x847c7cf8U, 0x997777eeU, 0x8d7b7bf6U, 0x0df2f2ffU, 0xbd6b6bd6U, 0xb16f6fdeU, 0x54c5c591U,
|
||||
0x50303060U, 0x03010102U, 0xa96767ceU, 0x7d2b2b56U, 0x19fefee7U, 0x62d7d7b5U, 0xe6abab4dU, 0x9a7676ecU,
|
||||
0x45caca8fU, 0x9d82821fU, 0x40c9c989U, 0x877d7dfaU, 0x15fafaefU, 0xeb5959b2U, 0xc947478eU, 0x0bf0f0fbU,
|
||||
0xecadad41U, 0x67d4d4b3U, 0xfda2a25fU, 0xeaafaf45U, 0xbf9c9c23U, 0xf7a4a453U, 0x967272e4U, 0x5bc0c09bU,
|
||||
0xc2b7b775U, 0x1cfdfde1U, 0xae93933dU, 0x6a26264cU, 0x5a36366cU, 0x413f3f7eU, 0x02f7f7f5U, 0x4fcccc83U,
|
||||
0x5c343468U, 0xf4a5a551U, 0x34e5e5d1U, 0x08f1f1f9U, 0x937171e2U, 0x73d8d8abU, 0x53313162U, 0x3f15152aU,
|
||||
0x0c040408U, 0x52c7c795U, 0x65232346U, 0x5ec3c39dU, 0x28181830U, 0xa1969637U, 0x0f05050aU, 0xb59a9a2fU,
|
||||
0x0907070eU, 0x36121224U, 0x9b80801bU, 0x3de2e2dfU, 0x26ebebcdU, 0x6927274eU, 0xcdb2b27fU, 0x9f7575eaU,
|
||||
0x1b090912U, 0x9e83831dU, 0x742c2c58U, 0x2e1a1a34U, 0x2d1b1b36U, 0xb26e6edcU, 0xee5a5ab4U, 0xfba0a05bU,
|
||||
0xf65252a4U, 0x4d3b3b76U, 0x61d6d6b7U, 0xceb3b37dU, 0x7b292952U, 0x3ee3e3ddU, 0x712f2f5eU, 0x97848413U,
|
||||
0xf55353a6U, 0x68d1d1b9U, 0x00000000U, 0x2cededc1U, 0x60202040U, 0x1ffcfce3U, 0xc8b1b179U, 0xed5b5bb6U,
|
||||
0xbe6a6ad4U, 0x46cbcb8dU, 0xd9bebe67U, 0x4b393972U, 0xde4a4a94U, 0xd44c4c98U, 0xe85858b0U, 0x4acfcf85U,
|
||||
0x6bd0d0bbU, 0x2aefefc5U, 0xe5aaaa4fU, 0x16fbfbedU, 0xc5434386U, 0xd74d4d9aU, 0x55333366U, 0x94858511U,
|
||||
0xcf45458aU, 0x10f9f9e9U, 0x06020204U, 0x817f7ffeU, 0xf05050a0U, 0x443c3c78U, 0xba9f9f25U, 0xe3a8a84bU,
|
||||
0xf35151a2U, 0xfea3a35dU, 0xc0404080U, 0x8a8f8f05U, 0xad92923fU, 0xbc9d9d21U, 0x48383870U, 0x04f5f5f1U,
|
||||
0xdfbcbc63U, 0xc1b6b677U, 0x75dadaafU, 0x63212142U, 0x30101020U, 0x1affffe5U, 0x0ef3f3fdU, 0x6dd2d2bfU,
|
||||
0x4ccdcd81U, 0x140c0c18U, 0x35131326U, 0x2fececc3U, 0xe15f5fbeU, 0xa2979735U, 0xcc444488U, 0x3917172eU,
|
||||
0x57c4c493U, 0xf2a7a755U, 0x827e7efcU, 0x473d3d7aU, 0xac6464c8U, 0xe75d5dbaU, 0x2b191932U, 0x957373e6U,
|
||||
0xa06060c0U, 0x98818119U, 0xd14f4f9eU, 0x7fdcdca3U, 0x66222244U, 0x7e2a2a54U, 0xab90903bU, 0x8388880bU,
|
||||
0xca46468cU, 0x29eeeec7U, 0xd3b8b86bU, 0x3c141428U, 0x79dedea7U, 0xe25e5ebcU, 0x1d0b0b16U, 0x76dbdbadU,
|
||||
0x3be0e0dbU, 0x56323264U, 0x4e3a3a74U, 0x1e0a0a14U, 0xdb494992U, 0x0a06060cU, 0x6c242448U, 0xe45c5cb8U,
|
||||
0x5dc2c29fU, 0x6ed3d3bdU, 0xefacac43U, 0xa66262c4U, 0xa8919139U, 0xa4959531U, 0x37e4e4d3U, 0x8b7979f2U,
|
||||
0x32e7e7d5U, 0x43c8c88bU, 0x5937376eU, 0xb76d6ddaU, 0x8c8d8d01U, 0x64d5d5b1U, 0xd24e4e9cU, 0xe0a9a949U,
|
||||
0xb46c6cd8U, 0xfa5656acU, 0x07f4f4f3U, 0x25eaeacfU, 0xaf6565caU, 0x8e7a7af4U, 0xe9aeae47U, 0x18080810U,
|
||||
0xd5baba6fU, 0x887878f0U, 0x6f25254aU, 0x722e2e5cU, 0x241c1c38U, 0xf1a6a657U, 0xc7b4b473U, 0x51c6c697U,
|
||||
0x23e8e8cbU, 0x7cdddda1U, 0x9c7474e8U, 0x211f1f3eU, 0xdd4b4b96U, 0xdcbdbd61U, 0x868b8b0dU, 0x858a8a0fU,
|
||||
0x907070e0U, 0x423e3e7cU, 0xc4b5b571U, 0xaa6666ccU, 0xd8484890U, 0x05030306U, 0x01f6f6f7U, 0x120e0e1cU,
|
||||
0xa36161c2U, 0x5f35356aU, 0xf95757aeU, 0xd0b9b969U, 0x91868617U, 0x58c1c199U, 0x271d1d3aU, 0xb99e9e27U,
|
||||
0x38e1e1d9U, 0x13f8f8ebU, 0xb398982bU, 0x33111122U, 0xbb6969d2U, 0x70d9d9a9U, 0x898e8e07U, 0xa7949433U,
|
||||
0xb69b9b2dU, 0x221e1e3cU, 0x92878715U, 0x20e9e9c9U, 0x49cece87U, 0xff5555aaU, 0x78282850U, 0x7adfdfa5U,
|
||||
0x8f8c8c03U, 0xf8a1a159U, 0x80898909U, 0x170d0d1aU, 0xdabfbf65U, 0x31e6e6d7U, 0xc6424284U, 0xb86868d0U,
|
||||
0xc3414182U, 0xb0999929U, 0x772d2d5aU, 0x110f0f1eU, 0xcbb0b07bU, 0xfc5454a8U, 0xd6bbbb6dU, 0x3a16162cU,
|
||||
|
||||
0x6363c6a5U, 0x7c7cf884U, 0x7777ee99U, 0x7b7bf68dU, 0xf2f2ff0dU, 0x6b6bd6bdU, 0x6f6fdeb1U, 0xc5c59154U,
|
||||
0x30306050U, 0x01010203U, 0x6767cea9U, 0x2b2b567dU, 0xfefee719U, 0xd7d7b562U, 0xabab4de6U, 0x7676ec9aU,
|
||||
0xcaca8f45U, 0x82821f9dU, 0xc9c98940U, 0x7d7dfa87U, 0xfafaef15U, 0x5959b2ebU, 0x47478ec9U, 0xf0f0fb0bU,
|
||||
0xadad41ecU, 0xd4d4b367U, 0xa2a25ffdU, 0xafaf45eaU, 0x9c9c23bfU, 0xa4a453f7U, 0x7272e496U, 0xc0c09b5bU,
|
||||
0xb7b775c2U, 0xfdfde11cU, 0x93933daeU, 0x26264c6aU, 0x36366c5aU, 0x3f3f7e41U, 0xf7f7f502U, 0xcccc834fU,
|
||||
0x3434685cU, 0xa5a551f4U, 0xe5e5d134U, 0xf1f1f908U, 0x7171e293U, 0xd8d8ab73U, 0x31316253U, 0x15152a3fU,
|
||||
0x0404080cU, 0xc7c79552U, 0x23234665U, 0xc3c39d5eU, 0x18183028U, 0x969637a1U, 0x05050a0fU, 0x9a9a2fb5U,
|
||||
0x07070e09U, 0x12122436U, 0x80801b9bU, 0xe2e2df3dU, 0xebebcd26U, 0x27274e69U, 0xb2b27fcdU, 0x7575ea9fU,
|
||||
0x0909121bU, 0x83831d9eU, 0x2c2c5874U, 0x1a1a342eU, 0x1b1b362dU, 0x6e6edcb2U, 0x5a5ab4eeU, 0xa0a05bfbU,
|
||||
0x5252a4f6U, 0x3b3b764dU, 0xd6d6b761U, 0xb3b37dceU, 0x2929527bU, 0xe3e3dd3eU, 0x2f2f5e71U, 0x84841397U,
|
||||
0x5353a6f5U, 0xd1d1b968U, 0x00000000U, 0xededc12cU, 0x20204060U, 0xfcfce31fU, 0xb1b179c8U, 0x5b5bb6edU,
|
||||
0x6a6ad4beU, 0xcbcb8d46U, 0xbebe67d9U, 0x3939724bU, 0x4a4a94deU, 0x4c4c98d4U, 0x5858b0e8U, 0xcfcf854aU,
|
||||
0xd0d0bb6bU, 0xefefc52aU, 0xaaaa4fe5U, 0xfbfbed16U, 0x434386c5U, 0x4d4d9ad7U, 0x33336655U, 0x85851194U,
|
||||
0x45458acfU, 0xf9f9e910U, 0x02020406U, 0x7f7ffe81U, 0x5050a0f0U, 0x3c3c7844U, 0x9f9f25baU, 0xa8a84be3U,
|
||||
0x5151a2f3U, 0xa3a35dfeU, 0x404080c0U, 0x8f8f058aU, 0x92923fadU, 0x9d9d21bcU, 0x38387048U, 0xf5f5f104U,
|
||||
0xbcbc63dfU, 0xb6b677c1U, 0xdadaaf75U, 0x21214263U, 0x10102030U, 0xffffe51aU, 0xf3f3fd0eU, 0xd2d2bf6dU,
|
||||
0xcdcd814cU, 0x0c0c1814U, 0x13132635U, 0xececc32fU, 0x5f5fbee1U, 0x979735a2U, 0x444488ccU, 0x17172e39U,
|
||||
0xc4c49357U, 0xa7a755f2U, 0x7e7efc82U, 0x3d3d7a47U, 0x6464c8acU, 0x5d5dbae7U, 0x1919322bU, 0x7373e695U,
|
||||
0x6060c0a0U, 0x81811998U, 0x4f4f9ed1U, 0xdcdca37fU, 0x22224466U, 0x2a2a547eU, 0x90903babU, 0x88880b83U,
|
||||
0x46468ccaU, 0xeeeec729U, 0xb8b86bd3U, 0x1414283cU, 0xdedea779U, 0x5e5ebce2U, 0x0b0b161dU, 0xdbdbad76U,
|
||||
0xe0e0db3bU, 0x32326456U, 0x3a3a744eU, 0x0a0a141eU, 0x494992dbU, 0x06060c0aU, 0x2424486cU, 0x5c5cb8e4U,
|
||||
0xc2c29f5dU, 0xd3d3bd6eU, 0xacac43efU, 0x6262c4a6U, 0x919139a8U, 0x959531a4U, 0xe4e4d337U, 0x7979f28bU,
|
||||
0xe7e7d532U, 0xc8c88b43U, 0x37376e59U, 0x6d6ddab7U, 0x8d8d018cU, 0xd5d5b164U, 0x4e4e9cd2U, 0xa9a949e0U,
|
||||
0x6c6cd8b4U, 0x5656acfaU, 0xf4f4f307U, 0xeaeacf25U, 0x6565caafU, 0x7a7af48eU, 0xaeae47e9U, 0x08081018U,
|
||||
0xbaba6fd5U, 0x7878f088U, 0x25254a6fU, 0x2e2e5c72U, 0x1c1c3824U, 0xa6a657f1U, 0xb4b473c7U, 0xc6c69751U,
|
||||
0xe8e8cb23U, 0xdddda17cU, 0x7474e89cU, 0x1f1f3e21U, 0x4b4b96ddU, 0xbdbd61dcU, 0x8b8b0d86U, 0x8a8a0f85U,
|
||||
0x7070e090U, 0x3e3e7c42U, 0xb5b571c4U, 0x6666ccaaU, 0x484890d8U, 0x03030605U, 0xf6f6f701U, 0x0e0e1c12U,
|
||||
0x6161c2a3U, 0x35356a5fU, 0x5757aef9U, 0xb9b969d0U, 0x86861791U, 0xc1c19958U, 0x1d1d3a27U, 0x9e9e27b9U,
|
||||
0xe1e1d938U, 0xf8f8eb13U, 0x98982bb3U, 0x11112233U, 0x6969d2bbU, 0xd9d9a970U, 0x8e8e0789U, 0x949433a7U,
|
||||
0x9b9b2db6U, 0x1e1e3c22U, 0x87871592U, 0xe9e9c920U, 0xcece8749U, 0x5555aaffU, 0x28285078U, 0xdfdfa57aU,
|
||||
0x8c8c038fU, 0xa1a159f8U, 0x89890980U, 0x0d0d1a17U, 0xbfbf65daU, 0xe6e6d731U, 0x424284c6U, 0x6868d0b8U,
|
||||
0x414182c3U, 0x999929b0U, 0x2d2d5a77U, 0x0f0f1e11U, 0xb0b07bcbU, 0x5454a8fcU, 0xbbbb6dd6U, 0x16162c3aU,
|
||||
|
||||
0x63c6a563U, 0x7cf8847cU, 0x77ee9977U, 0x7bf68d7bU, 0xf2ff0df2U, 0x6bd6bd6bU, 0x6fdeb16fU, 0xc59154c5U,
|
||||
0x30605030U, 0x01020301U, 0x67cea967U, 0x2b567d2bU, 0xfee719feU, 0xd7b562d7U, 0xab4de6abU, 0x76ec9a76U,
|
||||
0xca8f45caU, 0x821f9d82U, 0xc98940c9U, 0x7dfa877dU, 0xfaef15faU, 0x59b2eb59U, 0x478ec947U, 0xf0fb0bf0U,
|
||||
0xad41ecadU, 0xd4b367d4U, 0xa25ffda2U, 0xaf45eaafU, 0x9c23bf9cU, 0xa453f7a4U, 0x72e49672U, 0xc09b5bc0U,
|
||||
0xb775c2b7U, 0xfde11cfdU, 0x933dae93U, 0x264c6a26U, 0x366c5a36U, 0x3f7e413fU, 0xf7f502f7U, 0xcc834fccU,
|
||||
0x34685c34U, 0xa551f4a5U, 0xe5d134e5U, 0xf1f908f1U, 0x71e29371U, 0xd8ab73d8U, 0x31625331U, 0x152a3f15U,
|
||||
0x04080c04U, 0xc79552c7U, 0x23466523U, 0xc39d5ec3U, 0x18302818U, 0x9637a196U, 0x050a0f05U, 0x9a2fb59aU,
|
||||
0x070e0907U, 0x12243612U, 0x801b9b80U, 0xe2df3de2U, 0xebcd26ebU, 0x274e6927U, 0xb27fcdb2U, 0x75ea9f75U,
|
||||
0x09121b09U, 0x831d9e83U, 0x2c58742cU, 0x1a342e1aU, 0x1b362d1bU, 0x6edcb26eU, 0x5ab4ee5aU, 0xa05bfba0U,
|
||||
0x52a4f652U, 0x3b764d3bU, 0xd6b761d6U, 0xb37dceb3U, 0x29527b29U, 0xe3dd3ee3U, 0x2f5e712fU, 0x84139784U,
|
||||
0x53a6f553U, 0xd1b968d1U, 0x00000000U, 0xedc12cedU, 0x20406020U, 0xfce31ffcU, 0xb179c8b1U, 0x5bb6ed5bU,
|
||||
0x6ad4be6aU, 0xcb8d46cbU, 0xbe67d9beU, 0x39724b39U, 0x4a94de4aU, 0x4c98d44cU, 0x58b0e858U, 0xcf854acfU,
|
||||
0xd0bb6bd0U, 0xefc52aefU, 0xaa4fe5aaU, 0xfbed16fbU, 0x4386c543U, 0x4d9ad74dU, 0x33665533U, 0x85119485U,
|
||||
0x458acf45U, 0xf9e910f9U, 0x02040602U, 0x7ffe817fU, 0x50a0f050U, 0x3c78443cU, 0x9f25ba9fU, 0xa84be3a8U,
|
||||
0x51a2f351U, 0xa35dfea3U, 0x4080c040U, 0x8f058a8fU, 0x923fad92U, 0x9d21bc9dU, 0x38704838U, 0xf5f104f5U,
|
||||
0xbc63dfbcU, 0xb677c1b6U, 0xdaaf75daU, 0x21426321U, 0x10203010U, 0xffe51affU, 0xf3fd0ef3U, 0xd2bf6dd2U,
|
||||
0xcd814ccdU, 0x0c18140cU, 0x13263513U, 0xecc32fecU, 0x5fbee15fU, 0x9735a297U, 0x4488cc44U, 0x172e3917U,
|
||||
0xc49357c4U, 0xa755f2a7U, 0x7efc827eU, 0x3d7a473dU, 0x64c8ac64U, 0x5dbae75dU, 0x19322b19U, 0x73e69573U,
|
||||
0x60c0a060U, 0x81199881U, 0x4f9ed14fU, 0xdca37fdcU, 0x22446622U, 0x2a547e2aU, 0x903bab90U, 0x880b8388U,
|
||||
0x468cca46U, 0xeec729eeU, 0xb86bd3b8U, 0x14283c14U, 0xdea779deU, 0x5ebce25eU, 0x0b161d0bU, 0xdbad76dbU,
|
||||
0xe0db3be0U, 0x32645632U, 0x3a744e3aU, 0x0a141e0aU, 0x4992db49U, 0x060c0a06U, 0x24486c24U, 0x5cb8e45cU,
|
||||
0xc29f5dc2U, 0xd3bd6ed3U, 0xac43efacU, 0x62c4a662U, 0x9139a891U, 0x9531a495U, 0xe4d337e4U, 0x79f28b79U,
|
||||
0xe7d532e7U, 0xc88b43c8U, 0x376e5937U, 0x6ddab76dU, 0x8d018c8dU, 0xd5b164d5U, 0x4e9cd24eU, 0xa949e0a9U,
|
||||
0x6cd8b46cU, 0x56acfa56U, 0xf4f307f4U, 0xeacf25eaU, 0x65caaf65U, 0x7af48e7aU, 0xae47e9aeU, 0x08101808U,
|
||||
0xba6fd5baU, 0x78f08878U, 0x254a6f25U, 0x2e5c722eU, 0x1c38241cU, 0xa657f1a6U, 0xb473c7b4U, 0xc69751c6U,
|
||||
0xe8cb23e8U, 0xdda17cddU, 0x74e89c74U, 0x1f3e211fU, 0x4b96dd4bU, 0xbd61dcbdU, 0x8b0d868bU, 0x8a0f858aU,
|
||||
0x70e09070U, 0x3e7c423eU, 0xb571c4b5U, 0x66ccaa66U, 0x4890d848U, 0x03060503U, 0xf6f701f6U, 0x0e1c120eU,
|
||||
0x61c2a361U, 0x356a5f35U, 0x57aef957U, 0xb969d0b9U, 0x86179186U, 0xc19958c1U, 0x1d3a271dU, 0x9e27b99eU,
|
||||
0xe1d938e1U, 0xf8eb13f8U, 0x982bb398U, 0x11223311U, 0x69d2bb69U, 0xd9a970d9U, 0x8e07898eU, 0x9433a794U,
|
||||
0x9b2db69bU, 0x1e3c221eU, 0x87159287U, 0xe9c920e9U, 0xce8749ceU, 0x55aaff55U, 0x28507828U, 0xdfa57adfU,
|
||||
0x8c038f8cU, 0xa159f8a1U, 0x89098089U, 0x0d1a170dU, 0xbf65dabfU, 0xe6d731e6U, 0x4284c642U, 0x68d0b868U,
|
||||
0x4182c341U, 0x9929b099U, 0x2d5a772dU, 0x0f1e110fU, 0xb07bcbb0U, 0x54a8fc54U, 0xbb6dd6bbU, 0x162c3a16U,
|
||||
|
||||
0xc6a56363U, 0xf8847c7cU, 0xee997777U, 0xf68d7b7bU, 0xff0df2f2U, 0xd6bd6b6bU, 0xdeb16f6fU, 0x9154c5c5U,
|
||||
0x60503030U, 0x02030101U, 0xcea96767U, 0x567d2b2bU, 0xe719fefeU, 0xb562d7d7U, 0x4de6ababU, 0xec9a7676U,
|
||||
0x8f45cacaU, 0x1f9d8282U, 0x8940c9c9U, 0xfa877d7dU, 0xef15fafaU, 0xb2eb5959U, 0x8ec94747U, 0xfb0bf0f0U,
|
||||
0x41ecadadU, 0xb367d4d4U, 0x5ffda2a2U, 0x45eaafafU, 0x23bf9c9cU, 0x53f7a4a4U, 0xe4967272U, 0x9b5bc0c0U,
|
||||
0x75c2b7b7U, 0xe11cfdfdU, 0x3dae9393U, 0x4c6a2626U, 0x6c5a3636U, 0x7e413f3fU, 0xf502f7f7U, 0x834fccccU,
|
||||
0x685c3434U, 0x51f4a5a5U, 0xd134e5e5U, 0xf908f1f1U, 0xe2937171U, 0xab73d8d8U, 0x62533131U, 0x2a3f1515U,
|
||||
0x080c0404U, 0x9552c7c7U, 0x46652323U, 0x9d5ec3c3U, 0x30281818U, 0x37a19696U, 0x0a0f0505U, 0x2fb59a9aU,
|
||||
0x0e090707U, 0x24361212U, 0x1b9b8080U, 0xdf3de2e2U, 0xcd26ebebU, 0x4e692727U, 0x7fcdb2b2U, 0xea9f7575U,
|
||||
0x121b0909U, 0x1d9e8383U, 0x58742c2cU, 0x342e1a1aU, 0x362d1b1bU, 0xdcb26e6eU, 0xb4ee5a5aU, 0x5bfba0a0U,
|
||||
0xa4f65252U, 0x764d3b3bU, 0xb761d6d6U, 0x7dceb3b3U, 0x527b2929U, 0xdd3ee3e3U, 0x5e712f2fU, 0x13978484U,
|
||||
0xa6f55353U, 0xb968d1d1U, 0x00000000U, 0xc12cededU, 0x40602020U, 0xe31ffcfcU, 0x79c8b1b1U, 0xb6ed5b5bU,
|
||||
0xd4be6a6aU, 0x8d46cbcbU, 0x67d9bebeU, 0x724b3939U, 0x94de4a4aU, 0x98d44c4cU, 0xb0e85858U, 0x854acfcfU,
|
||||
0xbb6bd0d0U, 0xc52aefefU, 0x4fe5aaaaU, 0xed16fbfbU, 0x86c54343U, 0x9ad74d4dU, 0x66553333U, 0x11948585U,
|
||||
0x8acf4545U, 0xe910f9f9U, 0x04060202U, 0xfe817f7fU, 0xa0f05050U, 0x78443c3cU, 0x25ba9f9fU, 0x4be3a8a8U,
|
||||
0xa2f35151U, 0x5dfea3a3U, 0x80c04040U, 0x058a8f8fU, 0x3fad9292U, 0x21bc9d9dU, 0x70483838U, 0xf104f5f5U,
|
||||
0x63dfbcbcU, 0x77c1b6b6U, 0xaf75dadaU, 0x42632121U, 0x20301010U, 0xe51affffU, 0xfd0ef3f3U, 0xbf6dd2d2U,
|
||||
0x814ccdcdU, 0x18140c0cU, 0x26351313U, 0xc32fececU, 0xbee15f5fU, 0x35a29797U, 0x88cc4444U, 0x2e391717U,
|
||||
0x9357c4c4U, 0x55f2a7a7U, 0xfc827e7eU, 0x7a473d3dU, 0xc8ac6464U, 0xbae75d5dU, 0x322b1919U, 0xe6957373U,
|
||||
0xc0a06060U, 0x19988181U, 0x9ed14f4fU, 0xa37fdcdcU, 0x44662222U, 0x547e2a2aU, 0x3bab9090U, 0x0b838888U,
|
||||
0x8cca4646U, 0xc729eeeeU, 0x6bd3b8b8U, 0x283c1414U, 0xa779dedeU, 0xbce25e5eU, 0x161d0b0bU, 0xad76dbdbU,
|
||||
0xdb3be0e0U, 0x64563232U, 0x744e3a3aU, 0x141e0a0aU, 0x92db4949U, 0x0c0a0606U, 0x486c2424U, 0xb8e45c5cU,
|
||||
0x9f5dc2c2U, 0xbd6ed3d3U, 0x43efacacU, 0xc4a66262U, 0x39a89191U, 0x31a49595U, 0xd337e4e4U, 0xf28b7979U,
|
||||
0xd532e7e7U, 0x8b43c8c8U, 0x6e593737U, 0xdab76d6dU, 0x018c8d8dU, 0xb164d5d5U, 0x9cd24e4eU, 0x49e0a9a9U,
|
||||
0xd8b46c6cU, 0xacfa5656U, 0xf307f4f4U, 0xcf25eaeaU, 0xcaaf6565U, 0xf48e7a7aU, 0x47e9aeaeU, 0x10180808U,
|
||||
0x6fd5babaU, 0xf0887878U, 0x4a6f2525U, 0x5c722e2eU, 0x38241c1cU, 0x57f1a6a6U, 0x73c7b4b4U, 0x9751c6c6U,
|
||||
0xcb23e8e8U, 0xa17cddddU, 0xe89c7474U, 0x3e211f1fU, 0x96dd4b4bU, 0x61dcbdbdU, 0x0d868b8bU, 0x0f858a8aU,
|
||||
0xe0907070U, 0x7c423e3eU, 0x71c4b5b5U, 0xccaa6666U, 0x90d84848U, 0x06050303U, 0xf701f6f6U, 0x1c120e0eU,
|
||||
0xc2a36161U, 0x6a5f3535U, 0xaef95757U, 0x69d0b9b9U, 0x17918686U, 0x9958c1c1U, 0x3a271d1dU, 0x27b99e9eU,
|
||||
0xd938e1e1U, 0xeb13f8f8U, 0x2bb39898U, 0x22331111U, 0xd2bb6969U, 0xa970d9d9U, 0x07898e8eU, 0x33a79494U,
|
||||
0x2db69b9bU, 0x3c221e1eU, 0x15928787U, 0xc920e9e9U, 0x8749ceceU, 0xaaff5555U, 0x50782828U, 0xa57adfdfU,
|
||||
0x038f8c8cU, 0x59f8a1a1U, 0x09808989U, 0x1a170d0dU, 0x65dabfbfU, 0xd731e6e6U, 0x84c64242U, 0xd0b86868U,
|
||||
0x82c34141U, 0x29b09999U, 0x5a772d2dU, 0x1e110f0fU, 0x7bcbb0b0U, 0xa8fc5454U, 0x6dd6bbbbU, 0x2c3a1616U
|
||||
};
|
||||
*/
|
||||
|
||||
#define AS_U32(addr) *((uint32_t*)(addr))
|
||||
#define AS_U64(addr) *((uint64_t*)(addr))
|
||||
#define AS_UINT2(addr) *((uint2*)(addr))
|
||||
#define AS_UINT4(addr) *((uint4*)(addr))
|
||||
#define AS_UL2(addr) *((ulonglong2*)(addr))
|
||||
|
||||
#define t_fn0(x) (sharedMemory[x])
|
||||
#define t_fn1(x) (sharedMemory[0x100U | (x)])
|
||||
#define t_fn2(x) (sharedMemory[0x200U | (x)])
|
||||
#define t_fn3(x) (sharedMemory[0x300U | (x)])
|
||||
|
||||
#define round(shared, out, x, k) \
|
||||
out[0] = (k)[0] ^ (t_fn0(x[0] & 0xff) ^ t_fn1((x[1] >> 8) & 0xff) ^ t_fn2((x[2] >> 16) & 0xff) ^ t_fn3((x[3] >> 24) & 0xff)); \
|
||||
out[1] = (k)[1] ^ (t_fn0(x[1] & 0xff) ^ t_fn1((x[2] >> 8) & 0xff) ^ t_fn2((x[3] >> 16) & 0xff) ^ t_fn3((x[0] >> 24) & 0xff)); \
|
||||
out[2] = (k)[2] ^ (t_fn0(x[2] & 0xff) ^ t_fn1((x[3] >> 8) & 0xff) ^ t_fn2((x[0] >> 16) & 0xff) ^ t_fn3((x[1] >> 24) & 0xff)); \
|
||||
out[3] = (k)[3] ^ (t_fn0(x[3] & 0xff) ^ t_fn1((x[0] >> 8) & 0xff) ^ t_fn2((x[1] >> 16) & 0xff) ^ t_fn3((x[2] >> 24) & 0xff));
|
||||
|
||||
#define round_u4(shared, out, in, k) \
|
||||
((uint32_t*)out)[0] = (k)[0] ^ t_fn0(in[0].x) ^ t_fn1(in[1].y) ^ t_fn2(in[2].z) ^ t_fn3(in[3].w); \
|
||||
((uint32_t*)out)[1] = (k)[1] ^ t_fn0(in[1].x) ^ t_fn1(in[2].y) ^ t_fn2(in[3].z) ^ t_fn3(in[0].w); \
|
||||
((uint32_t*)out)[2] = (k)[2] ^ t_fn0(in[2].x) ^ t_fn1(in[3].y) ^ t_fn2(in[0].z) ^ t_fn3(in[1].w); \
|
||||
((uint32_t*)out)[3] = (k)[3] ^ t_fn0(in[3].x) ^ t_fn1(in[0].y) ^ t_fn2(in[1].z) ^ t_fn3(in[2].w);
|
||||
|
||||
#ifdef __INTELLISENSE__
|
||||
#define __byte_perm(a,b,c) a
|
||||
#endif
|
||||
|
||||
#define OFF32_0(x) (x & 0xFFu)
|
||||
#define OFF32_1(x) __byte_perm(x, 0x01, 0x5541)
|
||||
#define OFF32_2(x) __byte_perm(x, 0x02, 0x5542)
|
||||
#define OFF32_3(x) __byte_perm(x, 0x03, 0x5543)
|
||||
|
||||
#define SHARED_0(x) sharedMemory[OFF32_0(x)]
|
||||
#define SHARED_1(x) sharedMemory[OFF32_1(x)]
|
||||
#define SHARED_2(x) sharedMemory[OFF32_2(x)]
|
||||
#define SHARED_3(x) sharedMemory[OFF32_3(x)]
|
||||
|
||||
__device__ __forceinline__
|
||||
void cn_aes_single_round(uint32_t * const sharedMemory, uint32_t * const in, uint32_t * out, uint32_t* expandedKey)
|
||||
{
|
||||
asm("// aes_single_round");
|
||||
out[0] = expandedKey[0] ^ SHARED_0(in[0]) ^ SHARED_1(in[1]) ^ SHARED_2(in[2]) ^ SHARED_3(in[3]);
|
||||
out[1] = expandedKey[1] ^ SHARED_0(in[1]) ^ SHARED_1(in[2]) ^ SHARED_2(in[3]) ^ SHARED_3(in[0]);
|
||||
out[2] = expandedKey[2] ^ SHARED_0(in[2]) ^ SHARED_1(in[3]) ^ SHARED_2(in[0]) ^ SHARED_3(in[1]);
|
||||
out[3] = expandedKey[3] ^ SHARED_0(in[3]) ^ SHARED_1(in[0]) ^ SHARED_2(in[1]) ^ SHARED_3(in[2]);
|
||||
}
|
||||
|
||||
//
|
||||
#ifdef _WIN64
|
||||
/* do a mul.wide.u32 to prevent a shl + cvt 32 to 64 on ld.shared [ptr] */
|
||||
#define OFF8_0(x) (x & 0xFFu) * sizeof(uint32_t)
|
||||
#define OFF8_1(x) __byte_perm(x, 0x01, 0x5541) * sizeof(uint32_t)
|
||||
#define OFF8_2(x) __byte_perm(x, 0x02, 0x5542) * sizeof(uint32_t)
|
||||
#define OFF8_3(x) __byte_perm(x, 0x03, 0x5543) * sizeof(uint32_t)
|
||||
#else
|
||||
#define OFF8_0(x) (x & 0xFFu) << 2
|
||||
#define OFF8_1(x) __byte_perm(x, 0x01, 0x5541) << 2
|
||||
#define OFF8_2(x) __byte_perm(x, 0x02, 0x5542) << 2
|
||||
#define OFF8_3(x) __byte_perm(x, 0x03, 0x5543) << 2
|
||||
#endif
|
||||
|
||||
#define SHAR8_0(x) AS_U32(&sharedMemory[OFF8_0(x)])
|
||||
#define SHAR8_1(x) AS_U32(&sharedMemory[OFF8_1(x)])
|
||||
#define SHAR8_2(x) AS_U32(&sharedMemory[OFF8_2(x)])
|
||||
#define SHAR8_3(x) AS_U32(&sharedMemory[OFF8_3(x)])
|
||||
|
||||
__device__ __forceinline__
|
||||
void cn_aes_single_round_b(uint8_t * const sharedMemory, void * const long_state, const uint4 key, uint4 *res)
|
||||
{
|
||||
asm("// aes_single_round_b");
|
||||
uint4 in = AS_UINT4(long_state);
|
||||
*res = key;
|
||||
res->x ^= SHAR8_0(in.x) ^ SHAR8_1(in.y) ^ SHAR8_2(in.z) ^ SHAR8_3(in.w);
|
||||
res->y ^= SHAR8_0(in.y) ^ SHAR8_1(in.z) ^ SHAR8_2(in.w) ^ SHAR8_3(in.x);
|
||||
res->z ^= SHAR8_0(in.z) ^ SHAR8_1(in.w) ^ SHAR8_2(in.x) ^ SHAR8_3(in.y);
|
||||
res->w ^= SHAR8_0(in.w) ^ SHAR8_1(in.x) ^ SHAR8_2(in.y) ^ SHAR8_3(in.z);
|
||||
}
|
||||
|
||||
#define round_perm(shared, out, in, k) \
|
||||
out[0] = (k)[0] ^ SHARED_0(in[0]) ^ SHARED_1(in[1]) ^ SHARED_2(in[2]) ^ SHARED_3(in[3]); \
|
||||
out[1] = (k)[1] ^ SHARED_0(in[1]) ^ SHARED_1(in[2]) ^ SHARED_2(in[3]) ^ SHARED_3(in[0]); \
|
||||
out[2] = (k)[2] ^ SHARED_0(in[2]) ^ SHARED_1(in[3]) ^ SHARED_2(in[0]) ^ SHARED_3(in[1]); \
|
||||
out[3] = (k)[3] ^ SHARED_0(in[3]) ^ SHARED_1(in[0]) ^ SHARED_2(in[1]) ^ SHARED_3(in[2]);
|
||||
|
||||
__device__ __forceinline__
|
||||
void cn_aes_pseudo_round_mut(const uint32_t * sharedMemory, uint32_t * val, uint32_t const * expandedKey)
|
||||
{
|
||||
asm("// aes_pseudo_round_mut");
|
||||
uint32_t b[4];
|
||||
round_perm(sharedMemory, b, val, expandedKey);
|
||||
round_perm(sharedMemory, val, b, expandedKey + (1 * N_COLS));
|
||||
round_perm(sharedMemory, b, val, expandedKey + (2 * N_COLS));
|
||||
round_perm(sharedMemory, val, b, expandedKey + (3 * N_COLS));
|
||||
round_perm(sharedMemory, b, val, expandedKey + (4 * N_COLS));
|
||||
round_perm(sharedMemory, val, b, expandedKey + (5 * N_COLS));
|
||||
round_perm(sharedMemory, b, val, expandedKey + (6 * N_COLS));
|
||||
round_perm(sharedMemory, val, b, expandedKey + (7 * N_COLS));
|
||||
round_perm(sharedMemory, b, val, expandedKey + (8 * N_COLS));
|
||||
round_perm(sharedMemory, val, b, expandedKey + (9 * N_COLS));
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint4 operator ^ (const uint4 &a, const uint4 &b) {
|
||||
return make_uint4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w);
|
||||
}
|
||||
|
||||
#define round_perm4(in, k) {\
|
||||
uint4 tmp; \
|
||||
tmp.x = SHARED_0(in.x) ^ SHARED_1(in.y) ^ SHARED_2(in.z) ^ SHARED_3(in.w); \
|
||||
tmp.y = SHARED_0(in.y) ^ SHARED_1(in.z) ^ SHARED_2(in.w) ^ SHARED_3(in.x); \
|
||||
tmp.z = SHARED_0(in.z) ^ SHARED_1(in.w) ^ SHARED_2(in.x) ^ SHARED_3(in.y); \
|
||||
tmp.w = SHARED_0(in.w) ^ SHARED_1(in.x) ^ SHARED_2(in.y) ^ SHARED_3(in.z); \
|
||||
val = tmp ^ key[k]; \
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void cn_aes_pseudo_round_mut_uint4(uint32_t * const sharedMemory, uint4 &val, uint4 const key[10])
|
||||
{
|
||||
asm("// aes_pseudo_round_mut_uint4");
|
||||
round_perm4(val, 0);
|
||||
round_perm4(val, 1);
|
||||
round_perm4(val, 2);
|
||||
round_perm4(val, 3);
|
||||
round_perm4(val, 4);
|
||||
round_perm4(val, 5);
|
||||
round_perm4(val, 6);
|
||||
round_perm4(val, 7);
|
||||
round_perm4(val, 8);
|
||||
round_perm4(val, 9);
|
||||
}
|
||||
|
||||
/*
|
||||
__device__ __forceinline__
|
||||
void cn_aes_gpu_init2(uint32_t* sharedMemory)
|
||||
{
|
||||
#if 0
|
||||
if(blockDim.x >= 64)
|
||||
{
|
||||
if(threadIdx.x < 64) {
|
||||
#define thrX (threadIdx.x << 2U) // ensure offsets aligned (16) to vector
|
||||
#pragma unroll 4
|
||||
for (uint32_t i = 0; i < 1024U; i += 256U) // 32x32 = 1024, 4 * 256 also
|
||||
AS_UINT4(&sharedMemory[i + thrX]) = AS_UINT4(&d_t_fn[i + thrX]);
|
||||
}
|
||||
|
||||
} else
|
||||
#endif
|
||||
if(blockDim.x >= 32) {
|
||||
|
||||
if(threadIdx.x < 32) {
|
||||
#if 0
|
||||
#pragma unroll 32
|
||||
for(uint32_t i = 0; i < 1024; i += 32)
|
||||
sharedMemory[threadIdx.x + i] = d_t_fn[threadIdx.x + i];
|
||||
#else
|
||||
#define thrX (threadIdx.x << 2U) // ensure offsets aligned (16) to vector
|
||||
#pragma unroll 8
|
||||
for (uint32_t i = 0; i < 1024; i += 128U) // 32x32 = 1024, 8 * 128 also
|
||||
AS_UINT4(&sharedMemory[i + thrX]) = AS_UINT4(&d_t_fn[i + thrX]);
|
||||
#endif
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if(threadIdx.x < 4) {
|
||||
#if 0
|
||||
for (uint32_t i = 0; i < 1024; i += 4)
|
||||
sharedMemory[threadIdx.x + i] = d_t_fn[threadIdx.x + i];
|
||||
#else
|
||||
#define thrX (threadIdx.x << 2U) // ensure offsets aligned (16) to vector
|
||||
#pragma unroll 64
|
||||
for (uint32_t i = 0; i < 1024; i += 16U)
|
||||
AS_UINT4(&sharedMemory[i + thrX]) = AS_UINT4(&d_t_fn[i + thrX]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
__device__ __forceinline__
|
||||
void cn_aes_gpu_init(uint32_t* sharedMemory)
|
||||
{
|
||||
// AES 0
|
||||
switch (threadIdx.x) {
|
||||
case 0:
|
||||
AS_UL2(&sharedMemory[0x000]) = make_ulonglong2(0x847c7cf8a56363c6, 0x8d7b7bf6997777ee);
|
||||
AS_UL2(&sharedMemory[0x004]) = make_ulonglong2(0xbd6b6bd60df2f2ff, 0x54c5c591b16f6fde);
|
||||
AS_UL2(&sharedMemory[0x008]) = make_ulonglong2(0x0301010250303060, 0x7d2b2b56a96767ce);
|
||||
AS_UL2(&sharedMemory[0x00C]) = make_ulonglong2(0x62d7d7b519fefee7, 0x9a7676ece6abab4d);
|
||||
AS_UL2(&sharedMemory[0x010]) = make_ulonglong2(0x9d82821f45caca8f, 0x877d7dfa40c9c989);
|
||||
AS_UL2(&sharedMemory[0x014]) = make_ulonglong2(0xeb5959b215fafaef, 0x0bf0f0fbc947478e);
|
||||
AS_UL2(&sharedMemory[0x018]) = make_ulonglong2(0x67d4d4b3ecadad41, 0xeaafaf45fda2a25f);
|
||||
AS_UL2(&sharedMemory[0x01C]) = make_ulonglong2(0xf7a4a453bf9c9c23, 0x5bc0c09b967272e4);
|
||||
break;
|
||||
case 1:
|
||||
AS_UL2(&sharedMemory[0x020]) = make_ulonglong2(0x1cfdfde1c2b7b775, 0x6a26264cae93933d);
|
||||
AS_UL2(&sharedMemory[0x024]) = make_ulonglong2(0x413f3f7e5a36366c, 0x4fcccc8302f7f7f5);
|
||||
AS_UL2(&sharedMemory[0x028]) = make_ulonglong2(0xf4a5a5515c343468, 0x08f1f1f934e5e5d1);
|
||||
AS_UL2(&sharedMemory[0x02C]) = make_ulonglong2(0x73d8d8ab937171e2, 0x3f15152a53313162);
|
||||
AS_UL2(&sharedMemory[0x030]) = make_ulonglong2(0x52c7c7950c040408, 0x5ec3c39d65232346);
|
||||
AS_UL2(&sharedMemory[0x034]) = make_ulonglong2(0xa196963728181830, 0xb59a9a2f0f05050a);
|
||||
AS_UL2(&sharedMemory[0x038]) = make_ulonglong2(0x361212240907070e, 0x3de2e2df9b80801b);
|
||||
AS_UL2(&sharedMemory[0x03C]) = make_ulonglong2(0x6927274e26ebebcd, 0x9f7575eacdb2b27f);
|
||||
break;
|
||||
case 2:
|
||||
AS_UL2(&sharedMemory[0x040]) = make_ulonglong2(0x9e83831d1b090912, 0x2e1a1a34742c2c58);
|
||||
AS_UL2(&sharedMemory[0x044]) = make_ulonglong2(0xb26e6edc2d1b1b36, 0xfba0a05bee5a5ab4);
|
||||
AS_UL2(&sharedMemory[0x048]) = make_ulonglong2(0x4d3b3b76f65252a4, 0xceb3b37d61d6d6b7);
|
||||
AS_UL2(&sharedMemory[0x04C]) = make_ulonglong2(0x3ee3e3dd7b292952, 0x97848413712f2f5e);
|
||||
AS_UL2(&sharedMemory[0x050]) = make_ulonglong2(0x68d1d1b9f55353a6, 0x2cededc100000000);
|
||||
AS_UL2(&sharedMemory[0x054]) = make_ulonglong2(0x1ffcfce360202040, 0xed5b5bb6c8b1b179);
|
||||
AS_UL2(&sharedMemory[0x058]) = make_ulonglong2(0x46cbcb8dbe6a6ad4, 0x4b393972d9bebe67);
|
||||
AS_UL2(&sharedMemory[0x05C]) = make_ulonglong2(0xd44c4c98de4a4a94, 0x4acfcf85e85858b0);
|
||||
break;
|
||||
case 3:
|
||||
AS_UL2(&sharedMemory[0x060]) = make_ulonglong2(0x2aefefc56bd0d0bb, 0x16fbfbede5aaaa4f);
|
||||
AS_UL2(&sharedMemory[0x064]) = make_ulonglong2(0xd74d4d9ac5434386, 0x9485851155333366);
|
||||
AS_UL2(&sharedMemory[0x068]) = make_ulonglong2(0x10f9f9e9cf45458a, 0x817f7ffe06020204);
|
||||
AS_UL2(&sharedMemory[0x06C]) = make_ulonglong2(0x443c3c78f05050a0, 0xe3a8a84bba9f9f25);
|
||||
AS_UL2(&sharedMemory[0x070]) = make_ulonglong2(0xfea3a35df35151a2, 0x8a8f8f05c0404080);
|
||||
AS_UL2(&sharedMemory[0x074]) = make_ulonglong2(0xbc9d9d21ad92923f, 0x04f5f5f148383870);
|
||||
AS_UL2(&sharedMemory[0x078]) = make_ulonglong2(0xc1b6b677dfbcbc63, 0x6321214275dadaaf);
|
||||
AS_UL2(&sharedMemory[0x07C]) = make_ulonglong2(0x1affffe530101020, 0x6dd2d2bf0ef3f3fd);
|
||||
break;
|
||||
case 4:
|
||||
AS_UL2(&sharedMemory[0x080]) = make_ulonglong2(0x140c0c184ccdcd81, 0x2fececc335131326);
|
||||
AS_UL2(&sharedMemory[0x084]) = make_ulonglong2(0xa2979735e15f5fbe, 0x3917172ecc444488);
|
||||
AS_UL2(&sharedMemory[0x088]) = make_ulonglong2(0xf2a7a75557c4c493, 0x473d3d7a827e7efc);
|
||||
AS_UL2(&sharedMemory[0x08C]) = make_ulonglong2(0xe75d5dbaac6464c8, 0x957373e62b191932);
|
||||
AS_UL2(&sharedMemory[0x090]) = make_ulonglong2(0x98818119a06060c0, 0x7fdcdca3d14f4f9e);
|
||||
AS_UL2(&sharedMemory[0x094]) = make_ulonglong2(0x7e2a2a5466222244, 0x8388880bab90903b);
|
||||
AS_UL2(&sharedMemory[0x098]) = make_ulonglong2(0x29eeeec7ca46468c, 0x3c141428d3b8b86b);
|
||||
AS_UL2(&sharedMemory[0x09C]) = make_ulonglong2(0xe25e5ebc79dedea7, 0x76dbdbad1d0b0b16);
|
||||
break;
|
||||
case 5:
|
||||
AS_UL2(&sharedMemory[0x0A0]) = make_ulonglong2(0x563232643be0e0db, 0x1e0a0a144e3a3a74);
|
||||
AS_UL2(&sharedMemory[0x0A4]) = make_ulonglong2(0x0a06060cdb494992, 0xe45c5cb86c242448);
|
||||
AS_UL2(&sharedMemory[0x0A8]) = make_ulonglong2(0x6ed3d3bd5dc2c29f, 0xa66262c4efacac43);
|
||||
AS_UL2(&sharedMemory[0x0AC]) = make_ulonglong2(0xa4959531a8919139, 0x8b7979f237e4e4d3);
|
||||
AS_UL2(&sharedMemory[0x0B0]) = make_ulonglong2(0x43c8c88b32e7e7d5, 0xb76d6dda5937376e);
|
||||
AS_UL2(&sharedMemory[0x0B4]) = make_ulonglong2(0x64d5d5b18c8d8d01, 0xe0a9a949d24e4e9c);
|
||||
AS_UL2(&sharedMemory[0x0B8]) = make_ulonglong2(0xfa5656acb46c6cd8, 0x25eaeacf07f4f4f3);
|
||||
AS_UL2(&sharedMemory[0x0BC]) = make_ulonglong2(0x8e7a7af4af6565ca, 0x18080810e9aeae47);
|
||||
break;
|
||||
case 6:
|
||||
AS_UL2(&sharedMemory[0x0C0]) = make_ulonglong2(0x887878f0d5baba6f, 0x722e2e5c6f25254a);
|
||||
AS_UL2(&sharedMemory[0x0C4]) = make_ulonglong2(0xf1a6a657241c1c38, 0x51c6c697c7b4b473);
|
||||
AS_UL2(&sharedMemory[0x0C8]) = make_ulonglong2(0x7cdddda123e8e8cb, 0x211f1f3e9c7474e8);
|
||||
AS_UL2(&sharedMemory[0x0CC]) = make_ulonglong2(0xdcbdbd61dd4b4b96, 0x858a8a0f868b8b0d);
|
||||
AS_UL2(&sharedMemory[0x0D0]) = make_ulonglong2(0x423e3e7c907070e0, 0xaa6666ccc4b5b571);
|
||||
AS_UL2(&sharedMemory[0x0D4]) = make_ulonglong2(0x05030306d8484890, 0x120e0e1c01f6f6f7);
|
||||
AS_UL2(&sharedMemory[0x0D8]) = make_ulonglong2(0x5f35356aa36161c2, 0xd0b9b969f95757ae);
|
||||
AS_UL2(&sharedMemory[0x0DC]) = make_ulonglong2(0x58c1c19991868617, 0xb99e9e27271d1d3a);
|
||||
break;
|
||||
case 7:
|
||||
AS_UL2(&sharedMemory[0x0E0]) = make_ulonglong2(0x13f8f8eb38e1e1d9, 0x33111122b398982b);
|
||||
AS_UL2(&sharedMemory[0x0E4]) = make_ulonglong2(0x70d9d9a9bb6969d2, 0xa7949433898e8e07);
|
||||
AS_UL2(&sharedMemory[0x0E8]) = make_ulonglong2(0x221e1e3cb69b9b2d, 0x20e9e9c992878715);
|
||||
AS_UL2(&sharedMemory[0x0EC]) = make_ulonglong2(0xff5555aa49cece87, 0x7adfdfa578282850);
|
||||
AS_UL2(&sharedMemory[0x0F0]) = make_ulonglong2(0xf8a1a1598f8c8c03, 0x170d0d1a80898909);
|
||||
AS_UL2(&sharedMemory[0x0F4]) = make_ulonglong2(0x31e6e6d7dabfbf65, 0xb86868d0c6424284);
|
||||
AS_UL2(&sharedMemory[0x0F8]) = make_ulonglong2(0xb0999929c3414182, 0x110f0f1e772d2d5a);
|
||||
AS_UL2(&sharedMemory[0x0FC]) = make_ulonglong2(0xfc5454a8cbb0b07b, 0x3a16162cd6bbbb6d);
|
||||
break;
|
||||
}
|
||||
// AES 1
|
||||
switch (threadIdx.x) {
|
||||
case 0:
|
||||
AS_UL2(&sharedMemory[0x100]) = make_ulonglong2(0x7c7cf8846363c6a5, 0x7b7bf68d7777ee99);
|
||||
AS_UL2(&sharedMemory[0x104]) = make_ulonglong2(0x6b6bd6bdf2f2ff0d, 0xc5c591546f6fdeb1);
|
||||
AS_UL2(&sharedMemory[0x108]) = make_ulonglong2(0x0101020330306050, 0x2b2b567d6767cea9);
|
||||
AS_UL2(&sharedMemory[0x10C]) = make_ulonglong2(0xd7d7b562fefee719, 0x7676ec9aabab4de6);
|
||||
AS_UL2(&sharedMemory[0x110]) = make_ulonglong2(0x82821f9dcaca8f45, 0x7d7dfa87c9c98940);
|
||||
AS_UL2(&sharedMemory[0x114]) = make_ulonglong2(0x5959b2ebfafaef15, 0xf0f0fb0b47478ec9);
|
||||
AS_UL2(&sharedMemory[0x118]) = make_ulonglong2(0xd4d4b367adad41ec, 0xafaf45eaa2a25ffd);
|
||||
AS_UL2(&sharedMemory[0x11C]) = make_ulonglong2(0xa4a453f79c9c23bf, 0xc0c09b5b7272e496);
|
||||
break;
|
||||
case 1:
|
||||
AS_UL2(&sharedMemory[0x120]) = make_ulonglong2(0xfdfde11cb7b775c2, 0x26264c6a93933dae);
|
||||
AS_UL2(&sharedMemory[0x124]) = make_ulonglong2(0x3f3f7e4136366c5a, 0xcccc834ff7f7f502);
|
||||
AS_UL2(&sharedMemory[0x128]) = make_ulonglong2(0xa5a551f43434685c, 0xf1f1f908e5e5d134);
|
||||
AS_UL2(&sharedMemory[0x12C]) = make_ulonglong2(0xd8d8ab737171e293, 0x15152a3f31316253);
|
||||
AS_UL2(&sharedMemory[0x130]) = make_ulonglong2(0xc7c795520404080c, 0xc3c39d5e23234665);
|
||||
AS_UL2(&sharedMemory[0x134]) = make_ulonglong2(0x969637a118183028, 0x9a9a2fb505050a0f);
|
||||
AS_UL2(&sharedMemory[0x138]) = make_ulonglong2(0x1212243607070e09, 0xe2e2df3d80801b9b);
|
||||
AS_UL2(&sharedMemory[0x13C]) = make_ulonglong2(0x27274e69ebebcd26, 0x7575ea9fb2b27fcd);
|
||||
break;
|
||||
case 2:
|
||||
AS_UL2(&sharedMemory[0x140]) = make_ulonglong2(0x83831d9e0909121b, 0x1a1a342e2c2c5874);
|
||||
AS_UL2(&sharedMemory[0x144]) = make_ulonglong2(0x6e6edcb21b1b362d, 0xa0a05bfb5a5ab4ee);
|
||||
AS_UL2(&sharedMemory[0x148]) = make_ulonglong2(0x3b3b764d5252a4f6, 0xb3b37dced6d6b761);
|
||||
AS_UL2(&sharedMemory[0x14C]) = make_ulonglong2(0xe3e3dd3e2929527b, 0x848413972f2f5e71);
|
||||
AS_UL2(&sharedMemory[0x150]) = make_ulonglong2(0xd1d1b9685353a6f5, 0xededc12c00000000);
|
||||
AS_UL2(&sharedMemory[0x154]) = make_ulonglong2(0xfcfce31f20204060, 0x5b5bb6edb1b179c8);
|
||||
AS_UL2(&sharedMemory[0x158]) = make_ulonglong2(0xcbcb8d466a6ad4be, 0x3939724bbebe67d9);
|
||||
AS_UL2(&sharedMemory[0x15C]) = make_ulonglong2(0x4c4c98d44a4a94de, 0xcfcf854a5858b0e8);
|
||||
break;
|
||||
case 3:
|
||||
AS_UL2(&sharedMemory[0x160]) = make_ulonglong2(0xefefc52ad0d0bb6b, 0xfbfbed16aaaa4fe5);
|
||||
AS_UL2(&sharedMemory[0x164]) = make_ulonglong2(0x4d4d9ad7434386c5, 0x8585119433336655);
|
||||
AS_UL2(&sharedMemory[0x168]) = make_ulonglong2(0xf9f9e91045458acf, 0x7f7ffe8102020406);
|
||||
AS_UL2(&sharedMemory[0x16C]) = make_ulonglong2(0x3c3c78445050a0f0, 0xa8a84be39f9f25ba);
|
||||
AS_UL2(&sharedMemory[0x170]) = make_ulonglong2(0xa3a35dfe5151a2f3, 0x8f8f058a404080c0);
|
||||
AS_UL2(&sharedMemory[0x174]) = make_ulonglong2(0x9d9d21bc92923fad, 0xf5f5f10438387048);
|
||||
AS_UL2(&sharedMemory[0x178]) = make_ulonglong2(0xb6b677c1bcbc63df, 0x21214263dadaaf75);
|
||||
AS_UL2(&sharedMemory[0x17C]) = make_ulonglong2(0xffffe51a10102030, 0xd2d2bf6df3f3fd0e);
|
||||
break;
|
||||
case 4:
|
||||
AS_UL2(&sharedMemory[0x180]) = make_ulonglong2(0x0c0c1814cdcd814c, 0xececc32f13132635);
|
||||
AS_UL2(&sharedMemory[0x184]) = make_ulonglong2(0x979735a25f5fbee1, 0x17172e39444488cc);
|
||||
AS_UL2(&sharedMemory[0x188]) = make_ulonglong2(0xa7a755f2c4c49357, 0x3d3d7a477e7efc82);
|
||||
AS_UL2(&sharedMemory[0x18C]) = make_ulonglong2(0x5d5dbae76464c8ac, 0x7373e6951919322b);
|
||||
AS_UL2(&sharedMemory[0x190]) = make_ulonglong2(0x818119986060c0a0, 0xdcdca37f4f4f9ed1);
|
||||
AS_UL2(&sharedMemory[0x194]) = make_ulonglong2(0x2a2a547e22224466, 0x88880b8390903bab);
|
||||
AS_UL2(&sharedMemory[0x198]) = make_ulonglong2(0xeeeec72946468cca, 0x1414283cb8b86bd3);
|
||||
AS_UL2(&sharedMemory[0x19C]) = make_ulonglong2(0x5e5ebce2dedea779, 0xdbdbad760b0b161d);
|
||||
break;
|
||||
case 5:
|
||||
AS_UL2(&sharedMemory[0x1A0]) = make_ulonglong2(0x32326456e0e0db3b, 0x0a0a141e3a3a744e);
|
||||
AS_UL2(&sharedMemory[0x1A4]) = make_ulonglong2(0x06060c0a494992db, 0x5c5cb8e42424486c);
|
||||
AS_UL2(&sharedMemory[0x1A8]) = make_ulonglong2(0xd3d3bd6ec2c29f5d, 0x6262c4a6acac43ef);
|
||||
AS_UL2(&sharedMemory[0x1AC]) = make_ulonglong2(0x959531a4919139a8, 0x7979f28be4e4d337);
|
||||
AS_UL2(&sharedMemory[0x1B0]) = make_ulonglong2(0xc8c88b43e7e7d532, 0x6d6ddab737376e59);
|
||||
AS_UL2(&sharedMemory[0x1B4]) = make_ulonglong2(0xd5d5b1648d8d018c, 0xa9a949e04e4e9cd2);
|
||||
AS_UL2(&sharedMemory[0x1B8]) = make_ulonglong2(0x5656acfa6c6cd8b4, 0xeaeacf25f4f4f307);
|
||||
AS_UL2(&sharedMemory[0x1BC]) = make_ulonglong2(0x7a7af48e6565caaf, 0x08081018aeae47e9);
|
||||
break;
|
||||
case 6:
|
||||
AS_UL2(&sharedMemory[0x1C0]) = make_ulonglong2(0x7878f088baba6fd5, 0x2e2e5c7225254a6f);
|
||||
AS_UL2(&sharedMemory[0x1C4]) = make_ulonglong2(0xa6a657f11c1c3824, 0xc6c69751b4b473c7);
|
||||
AS_UL2(&sharedMemory[0x1C8]) = make_ulonglong2(0xdddda17ce8e8cb23, 0x1f1f3e217474e89c);
|
||||
AS_UL2(&sharedMemory[0x1CC]) = make_ulonglong2(0xbdbd61dc4b4b96dd, 0x8a8a0f858b8b0d86);
|
||||
AS_UL2(&sharedMemory[0x1D0]) = make_ulonglong2(0x3e3e7c427070e090, 0x6666ccaab5b571c4);
|
||||
AS_UL2(&sharedMemory[0x1D4]) = make_ulonglong2(0x03030605484890d8, 0x0e0e1c12f6f6f701);
|
||||
AS_UL2(&sharedMemory[0x1D8]) = make_ulonglong2(0x35356a5f6161c2a3, 0xb9b969d05757aef9);
|
||||
AS_UL2(&sharedMemory[0x1DC]) = make_ulonglong2(0xc1c1995886861791, 0x9e9e27b91d1d3a27);
|
||||
break;
|
||||
case 7:
|
||||
AS_UL2(&sharedMemory[0x1E0]) = make_ulonglong2(0xf8f8eb13e1e1d938, 0x1111223398982bb3);
|
||||
AS_UL2(&sharedMemory[0x1E4]) = make_ulonglong2(0xd9d9a9706969d2bb, 0x949433a78e8e0789);
|
||||
AS_UL2(&sharedMemory[0x1E8]) = make_ulonglong2(0x1e1e3c229b9b2db6, 0xe9e9c92087871592);
|
||||
AS_UL2(&sharedMemory[0x1EC]) = make_ulonglong2(0x5555aaffcece8749, 0xdfdfa57a28285078);
|
||||
AS_UL2(&sharedMemory[0x1F0]) = make_ulonglong2(0xa1a159f88c8c038f, 0x0d0d1a1789890980);
|
||||
AS_UL2(&sharedMemory[0x1F4]) = make_ulonglong2(0xe6e6d731bfbf65da, 0x6868d0b8424284c6);
|
||||
AS_UL2(&sharedMemory[0x1F8]) = make_ulonglong2(0x999929b0414182c3, 0x0f0f1e112d2d5a77);
|
||||
AS_UL2(&sharedMemory[0x1FC]) = make_ulonglong2(0x5454a8fcb0b07bcb, 0x16162c3abbbb6dd6);
|
||||
break;
|
||||
}
|
||||
// AES 2
|
||||
switch (threadIdx.x) {
|
||||
case 0:
|
||||
AS_UL2(&sharedMemory[0x200]) = make_ulonglong2(0x7cf8847c63c6a563, 0x7bf68d7b77ee9977);
|
||||
AS_UL2(&sharedMemory[0x204]) = make_ulonglong2(0x6bd6bd6bf2ff0df2, 0xc59154c56fdeb16f);
|
||||
AS_UL2(&sharedMemory[0x208]) = make_ulonglong2(0x0102030130605030, 0x2b567d2b67cea967);
|
||||
AS_UL2(&sharedMemory[0x20C]) = make_ulonglong2(0xd7b562d7fee719fe, 0x76ec9a76ab4de6ab);
|
||||
AS_UL2(&sharedMemory[0x210]) = make_ulonglong2(0x821f9d82ca8f45ca, 0x7dfa877dc98940c9);
|
||||
AS_UL2(&sharedMemory[0x214]) = make_ulonglong2(0x59b2eb59faef15fa, 0xf0fb0bf0478ec947);
|
||||
AS_UL2(&sharedMemory[0x218]) = make_ulonglong2(0xd4b367d4ad41ecad, 0xaf45eaafa25ffda2);
|
||||
AS_UL2(&sharedMemory[0x21C]) = make_ulonglong2(0xa453f7a49c23bf9c, 0xc09b5bc072e49672);
|
||||
break;
|
||||
case 1:
|
||||
AS_UL2(&sharedMemory[0x220]) = make_ulonglong2(0xfde11cfdb775c2b7, 0x264c6a26933dae93);
|
||||
AS_UL2(&sharedMemory[0x224]) = make_ulonglong2(0x3f7e413f366c5a36, 0xcc834fccf7f502f7);
|
||||
AS_UL2(&sharedMemory[0x228]) = make_ulonglong2(0xa551f4a534685c34, 0xf1f908f1e5d134e5);
|
||||
AS_UL2(&sharedMemory[0x22C]) = make_ulonglong2(0xd8ab73d871e29371, 0x152a3f1531625331);
|
||||
AS_UL2(&sharedMemory[0x230]) = make_ulonglong2(0xc79552c704080c04, 0xc39d5ec323466523);
|
||||
AS_UL2(&sharedMemory[0x234]) = make_ulonglong2(0x9637a19618302818, 0x9a2fb59a050a0f05);
|
||||
AS_UL2(&sharedMemory[0x238]) = make_ulonglong2(0x12243612070e0907, 0xe2df3de2801b9b80);
|
||||
AS_UL2(&sharedMemory[0x23C]) = make_ulonglong2(0x274e6927ebcd26eb, 0x75ea9f75b27fcdb2);
|
||||
break;
|
||||
case 2:
|
||||
AS_UL2(&sharedMemory[0x240]) = make_ulonglong2(0x831d9e8309121b09, 0x1a342e1a2c58742c);
|
||||
AS_UL2(&sharedMemory[0x244]) = make_ulonglong2(0x6edcb26e1b362d1b, 0xa05bfba05ab4ee5a);
|
||||
AS_UL2(&sharedMemory[0x248]) = make_ulonglong2(0x3b764d3b52a4f652, 0xb37dceb3d6b761d6);
|
||||
AS_UL2(&sharedMemory[0x24C]) = make_ulonglong2(0xe3dd3ee329527b29, 0x841397842f5e712f);
|
||||
AS_UL2(&sharedMemory[0x250]) = make_ulonglong2(0xd1b968d153a6f553, 0xedc12ced00000000);
|
||||
AS_UL2(&sharedMemory[0x254]) = make_ulonglong2(0xfce31ffc20406020, 0x5bb6ed5bb179c8b1);
|
||||
AS_UL2(&sharedMemory[0x258]) = make_ulonglong2(0xcb8d46cb6ad4be6a, 0x39724b39be67d9be);
|
||||
AS_UL2(&sharedMemory[0x25C]) = make_ulonglong2(0x4c98d44c4a94de4a, 0xcf854acf58b0e858);
|
||||
break;
|
||||
case 3:
|
||||
AS_UL2(&sharedMemory[0x260]) = make_ulonglong2(0xefc52aefd0bb6bd0, 0xfbed16fbaa4fe5aa);
|
||||
AS_UL2(&sharedMemory[0x264]) = make_ulonglong2(0x4d9ad74d4386c543, 0x8511948533665533);
|
||||
AS_UL2(&sharedMemory[0x268]) = make_ulonglong2(0xf9e910f9458acf45, 0x7ffe817f02040602);
|
||||
AS_UL2(&sharedMemory[0x26C]) = make_ulonglong2(0x3c78443c50a0f050, 0xa84be3a89f25ba9f);
|
||||
AS_UL2(&sharedMemory[0x270]) = make_ulonglong2(0xa35dfea351a2f351, 0x8f058a8f4080c040);
|
||||
AS_UL2(&sharedMemory[0x274]) = make_ulonglong2(0x9d21bc9d923fad92, 0xf5f104f538704838);
|
||||
AS_UL2(&sharedMemory[0x278]) = make_ulonglong2(0xb677c1b6bc63dfbc, 0x21426321daaf75da);
|
||||
AS_UL2(&sharedMemory[0x27C]) = make_ulonglong2(0xffe51aff10203010, 0xd2bf6dd2f3fd0ef3);
|
||||
break;
|
||||
case 4:
|
||||
AS_UL2(&sharedMemory[0x280]) = make_ulonglong2(0x0c18140ccd814ccd, 0xecc32fec13263513);
|
||||
AS_UL2(&sharedMemory[0x284]) = make_ulonglong2(0x9735a2975fbee15f, 0x172e39174488cc44);
|
||||
AS_UL2(&sharedMemory[0x288]) = make_ulonglong2(0xa755f2a7c49357c4, 0x3d7a473d7efc827e);
|
||||
AS_UL2(&sharedMemory[0x28C]) = make_ulonglong2(0x5dbae75d64c8ac64, 0x73e6957319322b19);
|
||||
AS_UL2(&sharedMemory[0x290]) = make_ulonglong2(0x8119988160c0a060, 0xdca37fdc4f9ed14f);
|
||||
AS_UL2(&sharedMemory[0x294]) = make_ulonglong2(0x2a547e2a22446622, 0x880b8388903bab90);
|
||||
AS_UL2(&sharedMemory[0x298]) = make_ulonglong2(0xeec729ee468cca46, 0x14283c14b86bd3b8);
|
||||
AS_UL2(&sharedMemory[0x29C]) = make_ulonglong2(0x5ebce25edea779de, 0xdbad76db0b161d0b);
|
||||
break;
|
||||
case 5:
|
||||
AS_UL2(&sharedMemory[0x2A0]) = make_ulonglong2(0x32645632e0db3be0, 0x0a141e0a3a744e3a);
|
||||
AS_UL2(&sharedMemory[0x2A4]) = make_ulonglong2(0x060c0a064992db49, 0x5cb8e45c24486c24);
|
||||
AS_UL2(&sharedMemory[0x2A8]) = make_ulonglong2(0xd3bd6ed3c29f5dc2, 0x62c4a662ac43efac);
|
||||
AS_UL2(&sharedMemory[0x2AC]) = make_ulonglong2(0x9531a4959139a891, 0x79f28b79e4d337e4);
|
||||
AS_UL2(&sharedMemory[0x2B0]) = make_ulonglong2(0xc88b43c8e7d532e7, 0x6ddab76d376e5937);
|
||||
AS_UL2(&sharedMemory[0x2B4]) = make_ulonglong2(0xd5b164d58d018c8d, 0xa949e0a94e9cd24e);
|
||||
AS_UL2(&sharedMemory[0x2B8]) = make_ulonglong2(0x56acfa566cd8b46c, 0xeacf25eaf4f307f4);
|
||||
AS_UL2(&sharedMemory[0x2BC]) = make_ulonglong2(0x7af48e7a65caaf65, 0x08101808ae47e9ae);
|
||||
break;
|
||||
case 6:
|
||||
AS_UL2(&sharedMemory[0x2C0]) = make_ulonglong2(0x78f08878ba6fd5ba, 0x2e5c722e254a6f25);
|
||||
AS_UL2(&sharedMemory[0x2C4]) = make_ulonglong2(0xa657f1a61c38241c, 0xc69751c6b473c7b4);
|
||||
AS_UL2(&sharedMemory[0x2C8]) = make_ulonglong2(0xdda17cdde8cb23e8, 0x1f3e211f74e89c74);
|
||||
AS_UL2(&sharedMemory[0x2CC]) = make_ulonglong2(0xbd61dcbd4b96dd4b, 0x8a0f858a8b0d868b);
|
||||
AS_UL2(&sharedMemory[0x2D0]) = make_ulonglong2(0x3e7c423e70e09070, 0x66ccaa66b571c4b5);
|
||||
AS_UL2(&sharedMemory[0x2D4]) = make_ulonglong2(0x030605034890d848, 0x0e1c120ef6f701f6);
|
||||
AS_UL2(&sharedMemory[0x2D8]) = make_ulonglong2(0x356a5f3561c2a361, 0xb969d0b957aef957);
|
||||
AS_UL2(&sharedMemory[0x2DC]) = make_ulonglong2(0xc19958c186179186, 0x9e27b99e1d3a271d);
|
||||
break;
|
||||
case 7:
|
||||
AS_UL2(&sharedMemory[0x2E0]) = make_ulonglong2(0xf8eb13f8e1d938e1, 0x11223311982bb398);
|
||||
AS_UL2(&sharedMemory[0x2E4]) = make_ulonglong2(0xd9a970d969d2bb69, 0x9433a7948e07898e);
|
||||
AS_UL2(&sharedMemory[0x2E8]) = make_ulonglong2(0x1e3c221e9b2db69b, 0xe9c920e987159287);
|
||||
AS_UL2(&sharedMemory[0x2EC]) = make_ulonglong2(0x55aaff55ce8749ce, 0xdfa57adf28507828);
|
||||
AS_UL2(&sharedMemory[0x2F0]) = make_ulonglong2(0xa159f8a18c038f8c, 0x0d1a170d89098089);
|
||||
AS_UL2(&sharedMemory[0x2F4]) = make_ulonglong2(0xe6d731e6bf65dabf, 0x68d0b8684284c642);
|
||||
AS_UL2(&sharedMemory[0x2F8]) = make_ulonglong2(0x9929b0994182c341, 0x0f1e110f2d5a772d);
|
||||
AS_UL2(&sharedMemory[0x2FC]) = make_ulonglong2(0x54a8fc54b07bcbb0, 0x162c3a16bb6dd6bb);
|
||||
break;
|
||||
}
|
||||
// AES 3
|
||||
switch (threadIdx.x) {
|
||||
case 0:
|
||||
AS_UL2(&sharedMemory[0x300]) = make_ulonglong2(0xf8847c7cc6a56363, 0xf68d7b7bee997777);
|
||||
AS_UL2(&sharedMemory[0x304]) = make_ulonglong2(0xd6bd6b6bff0df2f2, 0x9154c5c5deb16f6f);
|
||||
AS_UL2(&sharedMemory[0x308]) = make_ulonglong2(0x0203010160503030, 0x567d2b2bcea96767);
|
||||
AS_UL2(&sharedMemory[0x30C]) = make_ulonglong2(0xb562d7d7e719fefe, 0xec9a76764de6abab);
|
||||
AS_UL2(&sharedMemory[0x310]) = make_ulonglong2(0x1f9d82828f45caca, 0xfa877d7d8940c9c9);
|
||||
AS_UL2(&sharedMemory[0x314]) = make_ulonglong2(0xb2eb5959ef15fafa, 0xfb0bf0f08ec94747);
|
||||
AS_UL2(&sharedMemory[0x318]) = make_ulonglong2(0xb367d4d441ecadad, 0x45eaafaf5ffda2a2);
|
||||
AS_UL2(&sharedMemory[0x31C]) = make_ulonglong2(0x53f7a4a423bf9c9c, 0x9b5bc0c0e4967272);
|
||||
break;
|
||||
case 1:
|
||||
AS_UL2(&sharedMemory[0x320]) = make_ulonglong2(0xe11cfdfd75c2b7b7, 0x4c6a26263dae9393);
|
||||
AS_UL2(&sharedMemory[0x324]) = make_ulonglong2(0x7e413f3f6c5a3636, 0x834fccccf502f7f7);
|
||||
AS_UL2(&sharedMemory[0x328]) = make_ulonglong2(0x51f4a5a5685c3434, 0xf908f1f1d134e5e5);
|
||||
AS_UL2(&sharedMemory[0x32C]) = make_ulonglong2(0xab73d8d8e2937171, 0x2a3f151562533131);
|
||||
AS_UL2(&sharedMemory[0x330]) = make_ulonglong2(0x9552c7c7080c0404, 0x9d5ec3c346652323);
|
||||
AS_UL2(&sharedMemory[0x334]) = make_ulonglong2(0x37a1969630281818, 0x2fb59a9a0a0f0505);
|
||||
AS_UL2(&sharedMemory[0x338]) = make_ulonglong2(0x243612120e090707, 0xdf3de2e21b9b8080);
|
||||
AS_UL2(&sharedMemory[0x33C]) = make_ulonglong2(0x4e692727cd26ebeb, 0xea9f75757fcdb2b2);
|
||||
break;
|
||||
case 2:
|
||||
AS_UL2(&sharedMemory[0x340]) = make_ulonglong2(0x1d9e8383121b0909, 0x342e1a1a58742c2c);
|
||||
AS_UL2(&sharedMemory[0x344]) = make_ulonglong2(0xdcb26e6e362d1b1b, 0x5bfba0a0b4ee5a5a);
|
||||
AS_UL2(&sharedMemory[0x348]) = make_ulonglong2(0x764d3b3ba4f65252, 0x7dceb3b3b761d6d6);
|
||||
AS_UL2(&sharedMemory[0x34C]) = make_ulonglong2(0xdd3ee3e3527b2929, 0x139784845e712f2f);
|
||||
AS_UL2(&sharedMemory[0x350]) = make_ulonglong2(0xb968d1d1a6f55353, 0xc12ceded00000000);
|
||||
AS_UL2(&sharedMemory[0x354]) = make_ulonglong2(0xe31ffcfc40602020, 0xb6ed5b5b79c8b1b1);
|
||||
AS_UL2(&sharedMemory[0x358]) = make_ulonglong2(0x8d46cbcbd4be6a6a, 0x724b393967d9bebe);
|
||||
AS_UL2(&sharedMemory[0x35C]) = make_ulonglong2(0x98d44c4c94de4a4a, 0x854acfcfb0e85858);
|
||||
break;
|
||||
case 3:
|
||||
AS_UL2(&sharedMemory[0x360]) = make_ulonglong2(0xc52aefefbb6bd0d0, 0xed16fbfb4fe5aaaa);
|
||||
AS_UL2(&sharedMemory[0x364]) = make_ulonglong2(0x9ad74d4d86c54343, 0x1194858566553333);
|
||||
AS_UL2(&sharedMemory[0x368]) = make_ulonglong2(0xe910f9f98acf4545, 0xfe817f7f04060202);
|
||||
AS_UL2(&sharedMemory[0x36C]) = make_ulonglong2(0x78443c3ca0f05050, 0x4be3a8a825ba9f9f);
|
||||
AS_UL2(&sharedMemory[0x370]) = make_ulonglong2(0x5dfea3a3a2f35151, 0x058a8f8f80c04040);
|
||||
AS_UL2(&sharedMemory[0x374]) = make_ulonglong2(0x21bc9d9d3fad9292, 0xf104f5f570483838);
|
||||
AS_UL2(&sharedMemory[0x378]) = make_ulonglong2(0x77c1b6b663dfbcbc, 0x42632121af75dada);
|
||||
AS_UL2(&sharedMemory[0x37C]) = make_ulonglong2(0xe51affff20301010, 0xbf6dd2d2fd0ef3f3);
|
||||
break;
|
||||
case 4:
|
||||
AS_UL2(&sharedMemory[0x380]) = make_ulonglong2(0x18140c0c814ccdcd, 0xc32fecec26351313);
|
||||
AS_UL2(&sharedMemory[0x384]) = make_ulonglong2(0x35a29797bee15f5f, 0x2e39171788cc4444);
|
||||
AS_UL2(&sharedMemory[0x388]) = make_ulonglong2(0x55f2a7a79357c4c4, 0x7a473d3dfc827e7e);
|
||||
AS_UL2(&sharedMemory[0x38C]) = make_ulonglong2(0xbae75d5dc8ac6464, 0xe6957373322b1919);
|
||||
AS_UL2(&sharedMemory[0x390]) = make_ulonglong2(0x19988181c0a06060, 0xa37fdcdc9ed14f4f);
|
||||
AS_UL2(&sharedMemory[0x394]) = make_ulonglong2(0x547e2a2a44662222, 0x0b8388883bab9090);
|
||||
AS_UL2(&sharedMemory[0x398]) = make_ulonglong2(0xc729eeee8cca4646, 0x283c14146bd3b8b8);
|
||||
AS_UL2(&sharedMemory[0x39C]) = make_ulonglong2(0xbce25e5ea779dede, 0xad76dbdb161d0b0b);
|
||||
break;
|
||||
case 5:
|
||||
AS_UL2(&sharedMemory[0x3A0]) = make_ulonglong2(0x64563232db3be0e0, 0x141e0a0a744e3a3a);
|
||||
AS_UL2(&sharedMemory[0x3A4]) = make_ulonglong2(0x0c0a060692db4949, 0xb8e45c5c486c2424);
|
||||
AS_UL2(&sharedMemory[0x3A8]) = make_ulonglong2(0xbd6ed3d39f5dc2c2, 0xc4a6626243efacac);
|
||||
AS_UL2(&sharedMemory[0x3AC]) = make_ulonglong2(0x31a4959539a89191, 0xf28b7979d337e4e4);
|
||||
AS_UL2(&sharedMemory[0x3B0]) = make_ulonglong2(0x8b43c8c8d532e7e7, 0xdab76d6d6e593737);
|
||||
AS_UL2(&sharedMemory[0x3B4]) = make_ulonglong2(0xb164d5d5018c8d8d, 0x49e0a9a99cd24e4e);
|
||||
AS_UL2(&sharedMemory[0x3B8]) = make_ulonglong2(0xacfa5656d8b46c6c, 0xcf25eaeaf307f4f4);
|
||||
AS_UL2(&sharedMemory[0x3BC]) = make_ulonglong2(0xf48e7a7acaaf6565, 0x1018080847e9aeae);
|
||||
break;
|
||||
case 6:
|
||||
AS_UL2(&sharedMemory[0x3C0]) = make_ulonglong2(0xf08878786fd5baba, 0x5c722e2e4a6f2525);
|
||||
AS_UL2(&sharedMemory[0x3C4]) = make_ulonglong2(0x57f1a6a638241c1c, 0x9751c6c673c7b4b4);
|
||||
AS_UL2(&sharedMemory[0x3C8]) = make_ulonglong2(0xa17cddddcb23e8e8, 0x3e211f1fe89c7474);
|
||||
AS_UL2(&sharedMemory[0x3CC]) = make_ulonglong2(0x61dcbdbd96dd4b4b, 0x0f858a8a0d868b8b);
|
||||
AS_UL2(&sharedMemory[0x3D0]) = make_ulonglong2(0x7c423e3ee0907070, 0xccaa666671c4b5b5);
|
||||
AS_UL2(&sharedMemory[0x3D4]) = make_ulonglong2(0x0605030390d84848, 0x1c120e0ef701f6f6);
|
||||
AS_UL2(&sharedMemory[0x3D8]) = make_ulonglong2(0x6a5f3535c2a36161, 0x69d0b9b9aef95757);
|
||||
AS_UL2(&sharedMemory[0x3DC]) = make_ulonglong2(0x9958c1c117918686, 0x27b99e9e3a271d1d);
|
||||
break;
|
||||
case 7:
|
||||
AS_UL2(&sharedMemory[0x3E0]) = make_ulonglong2(0xeb13f8f8d938e1e1, 0x223311112bb39898);
|
||||
AS_UL2(&sharedMemory[0x3E4]) = make_ulonglong2(0xa970d9d9d2bb6969, 0x33a7949407898e8e);
|
||||
AS_UL2(&sharedMemory[0x3E8]) = make_ulonglong2(0x3c221e1e2db69b9b, 0xc920e9e915928787);
|
||||
AS_UL2(&sharedMemory[0x3EC]) = make_ulonglong2(0xaaff55558749cece, 0xa57adfdf50782828);
|
||||
AS_UL2(&sharedMemory[0x3F0]) = make_ulonglong2(0x59f8a1a1038f8c8c, 0x1a170d0d09808989);
|
||||
AS_UL2(&sharedMemory[0x3F4]) = make_ulonglong2(0xd731e6e665dabfbf, 0xd0b8686884c64242);
|
||||
AS_UL2(&sharedMemory[0x3F8]) = make_ulonglong2(0x29b0999982c34141, 0x1e110f0f5a772d2d);
|
||||
AS_UL2(&sharedMemory[0x3FC]) = make_ulonglong2(0xa8fc54547bcbb0b0, 0x2c3a16166dd6bbbb);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void cn_aes_gpu_init_u4(uint32_t* sharedMemory)
|
||||
{
|
||||
// AES 0
|
||||
switch (threadIdx.x) {
|
||||
case 0:
|
||||
AS_UINT4(&sharedMemory[0x000]) = make_uint4(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6);
|
||||
AS_UINT4(&sharedMemory[0x004]) = make_uint4(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591);
|
||||
AS_UINT4(&sharedMemory[0x008]) = make_uint4(0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56);
|
||||
AS_UINT4(&sharedMemory[0x00C]) = make_uint4(0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec);
|
||||
AS_UINT4(&sharedMemory[0x010]) = make_uint4(0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa);
|
||||
AS_UINT4(&sharedMemory[0x014]) = make_uint4(0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb);
|
||||
AS_UINT4(&sharedMemory[0x018]) = make_uint4(0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45);
|
||||
AS_UINT4(&sharedMemory[0x01C]) = make_uint4(0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b);
|
||||
break;
|
||||
case 1:
|
||||
AS_UINT4(&sharedMemory[0x020]) = make_uint4(0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c);
|
||||
AS_UINT4(&sharedMemory[0x024]) = make_uint4(0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83);
|
||||
AS_UINT4(&sharedMemory[0x028]) = make_uint4(0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9);
|
||||
AS_UINT4(&sharedMemory[0x02C]) = make_uint4(0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a);
|
||||
AS_UINT4(&sharedMemory[0x030]) = make_uint4(0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d);
|
||||
AS_UINT4(&sharedMemory[0x034]) = make_uint4(0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f);
|
||||
AS_UINT4(&sharedMemory[0x038]) = make_uint4(0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df);
|
||||
AS_UINT4(&sharedMemory[0x03C]) = make_uint4(0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea);
|
||||
break;
|
||||
case 2:
|
||||
AS_UINT4(&sharedMemory[0x040]) = make_uint4(0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34);
|
||||
AS_UINT4(&sharedMemory[0x044]) = make_uint4(0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b);
|
||||
AS_UINT4(&sharedMemory[0x048]) = make_uint4(0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d);
|
||||
AS_UINT4(&sharedMemory[0x04C]) = make_uint4(0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413);
|
||||
AS_UINT4(&sharedMemory[0x050]) = make_uint4(0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1);
|
||||
AS_UINT4(&sharedMemory[0x054]) = make_uint4(0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6);
|
||||
AS_UINT4(&sharedMemory[0x058]) = make_uint4(0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972);
|
||||
AS_UINT4(&sharedMemory[0x05C]) = make_uint4(0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85);
|
||||
break;
|
||||
case 3:
|
||||
AS_UINT4(&sharedMemory[0x060]) = make_uint4(0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed);
|
||||
AS_UINT4(&sharedMemory[0x064]) = make_uint4(0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511);
|
||||
AS_UINT4(&sharedMemory[0x068]) = make_uint4(0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe);
|
||||
AS_UINT4(&sharedMemory[0x06C]) = make_uint4(0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b);
|
||||
AS_UINT4(&sharedMemory[0x070]) = make_uint4(0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05);
|
||||
AS_UINT4(&sharedMemory[0x074]) = make_uint4(0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1);
|
||||
AS_UINT4(&sharedMemory[0x078]) = make_uint4(0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142);
|
||||
AS_UINT4(&sharedMemory[0x07C]) = make_uint4(0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf);
|
||||
break;
|
||||
case 4:
|
||||
AS_UINT4(&sharedMemory[0x080]) = make_uint4(0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3);
|
||||
AS_UINT4(&sharedMemory[0x084]) = make_uint4(0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e);
|
||||
AS_UINT4(&sharedMemory[0x088]) = make_uint4(0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a);
|
||||
AS_UINT4(&sharedMemory[0x08C]) = make_uint4(0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6);
|
||||
AS_UINT4(&sharedMemory[0x090]) = make_uint4(0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3);
|
||||
AS_UINT4(&sharedMemory[0x094]) = make_uint4(0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b);
|
||||
AS_UINT4(&sharedMemory[0x098]) = make_uint4(0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428);
|
||||
AS_UINT4(&sharedMemory[0x09C]) = make_uint4(0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad);
|
||||
break;
|
||||
case 5:
|
||||
AS_UINT4(&sharedMemory[0x0A0]) = make_uint4(0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14);
|
||||
AS_UINT4(&sharedMemory[0x0A4]) = make_uint4(0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8);
|
||||
AS_UINT4(&sharedMemory[0x0A8]) = make_uint4(0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4);
|
||||
AS_UINT4(&sharedMemory[0x0AC]) = make_uint4(0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2);
|
||||
AS_UINT4(&sharedMemory[0x0B0]) = make_uint4(0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda);
|
||||
AS_UINT4(&sharedMemory[0x0B4]) = make_uint4(0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949);
|
||||
AS_UINT4(&sharedMemory[0x0B8]) = make_uint4(0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf);
|
||||
AS_UINT4(&sharedMemory[0x0BC]) = make_uint4(0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810);
|
||||
break;
|
||||
case 6:
|
||||
AS_UINT4(&sharedMemory[0x0C0]) = make_uint4(0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c);
|
||||
AS_UINT4(&sharedMemory[0x0C4]) = make_uint4(0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697);
|
||||
AS_UINT4(&sharedMemory[0x0C8]) = make_uint4(0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e);
|
||||
AS_UINT4(&sharedMemory[0x0CC]) = make_uint4(0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f);
|
||||
AS_UINT4(&sharedMemory[0x0D0]) = make_uint4(0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc);
|
||||
AS_UINT4(&sharedMemory[0x0D4]) = make_uint4(0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c);
|
||||
AS_UINT4(&sharedMemory[0x0D8]) = make_uint4(0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969);
|
||||
AS_UINT4(&sharedMemory[0x0DC]) = make_uint4(0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27);
|
||||
break;
|
||||
case 7:
|
||||
AS_UINT4(&sharedMemory[0x0E0]) = make_uint4(0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122);
|
||||
AS_UINT4(&sharedMemory[0x0E4]) = make_uint4(0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433);
|
||||
AS_UINT4(&sharedMemory[0x0E8]) = make_uint4(0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9);
|
||||
AS_UINT4(&sharedMemory[0x0EC]) = make_uint4(0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5);
|
||||
AS_UINT4(&sharedMemory[0x0F0]) = make_uint4(0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a);
|
||||
AS_UINT4(&sharedMemory[0x0F4]) = make_uint4(0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0);
|
||||
AS_UINT4(&sharedMemory[0x0F8]) = make_uint4(0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e);
|
||||
AS_UINT4(&sharedMemory[0x0FC]) = make_uint4(0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c);
|
||||
break;
|
||||
}
|
||||
// AES 1
|
||||
switch (threadIdx.x) {
|
||||
case 0:
|
||||
AS_UINT4(&sharedMemory[0x100]) = make_uint4(0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d);
|
||||
AS_UINT4(&sharedMemory[0x104]) = make_uint4(0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154);
|
||||
AS_UINT4(&sharedMemory[0x108]) = make_uint4(0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d);
|
||||
AS_UINT4(&sharedMemory[0x10C]) = make_uint4(0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a);
|
||||
AS_UINT4(&sharedMemory[0x110]) = make_uint4(0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87);
|
||||
AS_UINT4(&sharedMemory[0x114]) = make_uint4(0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b);
|
||||
AS_UINT4(&sharedMemory[0x118]) = make_uint4(0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea);
|
||||
AS_UINT4(&sharedMemory[0x11C]) = make_uint4(0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b);
|
||||
break;
|
||||
case 1:
|
||||
AS_UINT4(&sharedMemory[0x120]) = make_uint4(0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a);
|
||||
AS_UINT4(&sharedMemory[0x124]) = make_uint4(0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f);
|
||||
AS_UINT4(&sharedMemory[0x128]) = make_uint4(0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908);
|
||||
AS_UINT4(&sharedMemory[0x12C]) = make_uint4(0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f);
|
||||
AS_UINT4(&sharedMemory[0x130]) = make_uint4(0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e);
|
||||
AS_UINT4(&sharedMemory[0x134]) = make_uint4(0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5);
|
||||
AS_UINT4(&sharedMemory[0x138]) = make_uint4(0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d);
|
||||
AS_UINT4(&sharedMemory[0x13C]) = make_uint4(0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f);
|
||||
break;
|
||||
case 2:
|
||||
AS_UINT4(&sharedMemory[0x140]) = make_uint4(0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e);
|
||||
AS_UINT4(&sharedMemory[0x144]) = make_uint4(0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb);
|
||||
AS_UINT4(&sharedMemory[0x148]) = make_uint4(0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce);
|
||||
AS_UINT4(&sharedMemory[0x14C]) = make_uint4(0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397);
|
||||
AS_UINT4(&sharedMemory[0x150]) = make_uint4(0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c);
|
||||
AS_UINT4(&sharedMemory[0x154]) = make_uint4(0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed);
|
||||
AS_UINT4(&sharedMemory[0x158]) = make_uint4(0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b);
|
||||
AS_UINT4(&sharedMemory[0x15C]) = make_uint4(0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a);
|
||||
break;
|
||||
case 3:
|
||||
AS_UINT4(&sharedMemory[0x160]) = make_uint4(0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16);
|
||||
AS_UINT4(&sharedMemory[0x164]) = make_uint4(0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194);
|
||||
AS_UINT4(&sharedMemory[0x168]) = make_uint4(0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81);
|
||||
AS_UINT4(&sharedMemory[0x16C]) = make_uint4(0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3);
|
||||
AS_UINT4(&sharedMemory[0x170]) = make_uint4(0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a);
|
||||
AS_UINT4(&sharedMemory[0x174]) = make_uint4(0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104);
|
||||
AS_UINT4(&sharedMemory[0x178]) = make_uint4(0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263);
|
||||
AS_UINT4(&sharedMemory[0x17C]) = make_uint4(0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d);
|
||||
break;
|
||||
case 4:
|
||||
AS_UINT4(&sharedMemory[0x180]) = make_uint4(0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f);
|
||||
AS_UINT4(&sharedMemory[0x184]) = make_uint4(0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39);
|
||||
AS_UINT4(&sharedMemory[0x188]) = make_uint4(0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47);
|
||||
AS_UINT4(&sharedMemory[0x18C]) = make_uint4(0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695);
|
||||
AS_UINT4(&sharedMemory[0x190]) = make_uint4(0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f);
|
||||
AS_UINT4(&sharedMemory[0x194]) = make_uint4(0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83);
|
||||
AS_UINT4(&sharedMemory[0x198]) = make_uint4(0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c);
|
||||
AS_UINT4(&sharedMemory[0x19C]) = make_uint4(0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76);
|
||||
break;
|
||||
case 5:
|
||||
AS_UINT4(&sharedMemory[0x1A0]) = make_uint4(0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e);
|
||||
AS_UINT4(&sharedMemory[0x1A4]) = make_uint4(0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4);
|
||||
AS_UINT4(&sharedMemory[0x1A8]) = make_uint4(0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6);
|
||||
AS_UINT4(&sharedMemory[0x1AC]) = make_uint4(0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b);
|
||||
AS_UINT4(&sharedMemory[0x1B0]) = make_uint4(0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7);
|
||||
AS_UINT4(&sharedMemory[0x1B4]) = make_uint4(0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0);
|
||||
AS_UINT4(&sharedMemory[0x1B8]) = make_uint4(0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25);
|
||||
AS_UINT4(&sharedMemory[0x1BC]) = make_uint4(0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018);
|
||||
break;
|
||||
case 6:
|
||||
AS_UINT4(&sharedMemory[0x1C0]) = make_uint4(0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72);
|
||||
AS_UINT4(&sharedMemory[0x1C4]) = make_uint4(0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751);
|
||||
AS_UINT4(&sharedMemory[0x1C8]) = make_uint4(0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21);
|
||||
AS_UINT4(&sharedMemory[0x1CC]) = make_uint4(0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85);
|
||||
AS_UINT4(&sharedMemory[0x1D0]) = make_uint4(0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa);
|
||||
AS_UINT4(&sharedMemory[0x1D4]) = make_uint4(0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12);
|
||||
AS_UINT4(&sharedMemory[0x1D8]) = make_uint4(0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0);
|
||||
AS_UINT4(&sharedMemory[0x1DC]) = make_uint4(0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9);
|
||||
break;
|
||||
case 7:
|
||||
AS_UINT4(&sharedMemory[0x1E0]) = make_uint4(0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233);
|
||||
AS_UINT4(&sharedMemory[0x1E4]) = make_uint4(0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7);
|
||||
AS_UINT4(&sharedMemory[0x1E8]) = make_uint4(0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920);
|
||||
AS_UINT4(&sharedMemory[0x1EC]) = make_uint4(0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a);
|
||||
AS_UINT4(&sharedMemory[0x1F0]) = make_uint4(0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17);
|
||||
AS_UINT4(&sharedMemory[0x1F4]) = make_uint4(0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8);
|
||||
AS_UINT4(&sharedMemory[0x1F8]) = make_uint4(0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11);
|
||||
AS_UINT4(&sharedMemory[0x1FC]) = make_uint4(0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a);
|
||||
break;
|
||||
}
|
||||
// AES 2
|
||||
switch (threadIdx.x) {
|
||||
case 0:
|
||||
AS_UINT4(&sharedMemory[0x200]) = make_uint4(0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b);
|
||||
AS_UINT4(&sharedMemory[0x204]) = make_uint4(0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5);
|
||||
AS_UINT4(&sharedMemory[0x208]) = make_uint4(0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b);
|
||||
AS_UINT4(&sharedMemory[0x20C]) = make_uint4(0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76);
|
||||
AS_UINT4(&sharedMemory[0x210]) = make_uint4(0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d);
|
||||
AS_UINT4(&sharedMemory[0x214]) = make_uint4(0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0);
|
||||
AS_UINT4(&sharedMemory[0x218]) = make_uint4(0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf);
|
||||
AS_UINT4(&sharedMemory[0x21C]) = make_uint4(0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0);
|
||||
break;
|
||||
case 1:
|
||||
AS_UINT4(&sharedMemory[0x220]) = make_uint4(0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26);
|
||||
AS_UINT4(&sharedMemory[0x224]) = make_uint4(0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc);
|
||||
AS_UINT4(&sharedMemory[0x228]) = make_uint4(0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1);
|
||||
AS_UINT4(&sharedMemory[0x22C]) = make_uint4(0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15);
|
||||
AS_UINT4(&sharedMemory[0x230]) = make_uint4(0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3);
|
||||
AS_UINT4(&sharedMemory[0x234]) = make_uint4(0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a);
|
||||
AS_UINT4(&sharedMemory[0x238]) = make_uint4(0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2);
|
||||
AS_UINT4(&sharedMemory[0x23C]) = make_uint4(0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75);
|
||||
break;
|
||||
case 2:
|
||||
AS_UINT4(&sharedMemory[0x240]) = make_uint4(0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a);
|
||||
AS_UINT4(&sharedMemory[0x244]) = make_uint4(0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0);
|
||||
AS_UINT4(&sharedMemory[0x248]) = make_uint4(0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3);
|
||||
AS_UINT4(&sharedMemory[0x24C]) = make_uint4(0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784);
|
||||
AS_UINT4(&sharedMemory[0x250]) = make_uint4(0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced);
|
||||
AS_UINT4(&sharedMemory[0x254]) = make_uint4(0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b);
|
||||
AS_UINT4(&sharedMemory[0x258]) = make_uint4(0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39);
|
||||
AS_UINT4(&sharedMemory[0x25C]) = make_uint4(0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf);
|
||||
break;
|
||||
case 3:
|
||||
AS_UINT4(&sharedMemory[0x260]) = make_uint4(0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb);
|
||||
AS_UINT4(&sharedMemory[0x264]) = make_uint4(0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485);
|
||||
AS_UINT4(&sharedMemory[0x268]) = make_uint4(0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f);
|
||||
AS_UINT4(&sharedMemory[0x26C]) = make_uint4(0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8);
|
||||
AS_UINT4(&sharedMemory[0x270]) = make_uint4(0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f);
|
||||
AS_UINT4(&sharedMemory[0x274]) = make_uint4(0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5);
|
||||
AS_UINT4(&sharedMemory[0x278]) = make_uint4(0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321);
|
||||
AS_UINT4(&sharedMemory[0x27C]) = make_uint4(0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2);
|
||||
break;
|
||||
case 4:
|
||||
AS_UINT4(&sharedMemory[0x280]) = make_uint4(0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec);
|
||||
AS_UINT4(&sharedMemory[0x284]) = make_uint4(0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917);
|
||||
AS_UINT4(&sharedMemory[0x288]) = make_uint4(0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d);
|
||||
AS_UINT4(&sharedMemory[0x28C]) = make_uint4(0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573);
|
||||
AS_UINT4(&sharedMemory[0x290]) = make_uint4(0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc);
|
||||
AS_UINT4(&sharedMemory[0x294]) = make_uint4(0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388);
|
||||
AS_UINT4(&sharedMemory[0x298]) = make_uint4(0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14);
|
||||
AS_UINT4(&sharedMemory[0x29C]) = make_uint4(0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db);
|
||||
break;
|
||||
case 5:
|
||||
AS_UINT4(&sharedMemory[0x2A0]) = make_uint4(0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a);
|
||||
AS_UINT4(&sharedMemory[0x2A4]) = make_uint4(0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c);
|
||||
AS_UINT4(&sharedMemory[0x2A8]) = make_uint4(0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662);
|
||||
AS_UINT4(&sharedMemory[0x2AC]) = make_uint4(0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79);
|
||||
AS_UINT4(&sharedMemory[0x2B0]) = make_uint4(0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d);
|
||||
AS_UINT4(&sharedMemory[0x2B4]) = make_uint4(0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9);
|
||||
AS_UINT4(&sharedMemory[0x2B8]) = make_uint4(0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea);
|
||||
AS_UINT4(&sharedMemory[0x2BC]) = make_uint4(0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808);
|
||||
break;
|
||||
case 6:
|
||||
AS_UINT4(&sharedMemory[0x2C0]) = make_uint4(0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e);
|
||||
AS_UINT4(&sharedMemory[0x2C4]) = make_uint4(0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6);
|
||||
AS_UINT4(&sharedMemory[0x2C8]) = make_uint4(0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f);
|
||||
AS_UINT4(&sharedMemory[0x2CC]) = make_uint4(0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a);
|
||||
AS_UINT4(&sharedMemory[0x2D0]) = make_uint4(0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66);
|
||||
AS_UINT4(&sharedMemory[0x2D4]) = make_uint4(0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e);
|
||||
AS_UINT4(&sharedMemory[0x2D8]) = make_uint4(0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9);
|
||||
AS_UINT4(&sharedMemory[0x2DC]) = make_uint4(0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e);
|
||||
break;
|
||||
case 7:
|
||||
AS_UINT4(&sharedMemory[0x2E0]) = make_uint4(0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311);
|
||||
AS_UINT4(&sharedMemory[0x2E4]) = make_uint4(0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794);
|
||||
AS_UINT4(&sharedMemory[0x2E8]) = make_uint4(0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9);
|
||||
AS_UINT4(&sharedMemory[0x2EC]) = make_uint4(0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf);
|
||||
AS_UINT4(&sharedMemory[0x2F0]) = make_uint4(0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d);
|
||||
AS_UINT4(&sharedMemory[0x2F4]) = make_uint4(0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868);
|
||||
AS_UINT4(&sharedMemory[0x2F8]) = make_uint4(0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f);
|
||||
AS_UINT4(&sharedMemory[0x2FC]) = make_uint4(0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16);
|
||||
break;
|
||||
}
|
||||
// AES 3
|
||||
switch (threadIdx.x) {
|
||||
case 0:
|
||||
AS_UINT4(&sharedMemory[0x300]) = make_uint4(0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b);
|
||||
AS_UINT4(&sharedMemory[0x304]) = make_uint4(0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5);
|
||||
AS_UINT4(&sharedMemory[0x308]) = make_uint4(0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b);
|
||||
AS_UINT4(&sharedMemory[0x30C]) = make_uint4(0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676);
|
||||
AS_UINT4(&sharedMemory[0x310]) = make_uint4(0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d);
|
||||
AS_UINT4(&sharedMemory[0x314]) = make_uint4(0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0);
|
||||
AS_UINT4(&sharedMemory[0x318]) = make_uint4(0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf);
|
||||
AS_UINT4(&sharedMemory[0x31C]) = make_uint4(0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0);
|
||||
break;
|
||||
case 1:
|
||||
AS_UINT4(&sharedMemory[0x320]) = make_uint4(0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626);
|
||||
AS_UINT4(&sharedMemory[0x324]) = make_uint4(0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc);
|
||||
AS_UINT4(&sharedMemory[0x328]) = make_uint4(0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1);
|
||||
AS_UINT4(&sharedMemory[0x32C]) = make_uint4(0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515);
|
||||
AS_UINT4(&sharedMemory[0x330]) = make_uint4(0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3);
|
||||
AS_UINT4(&sharedMemory[0x334]) = make_uint4(0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a);
|
||||
AS_UINT4(&sharedMemory[0x338]) = make_uint4(0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2);
|
||||
AS_UINT4(&sharedMemory[0x33C]) = make_uint4(0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575);
|
||||
break;
|
||||
case 2:
|
||||
AS_UINT4(&sharedMemory[0x340]) = make_uint4(0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a);
|
||||
AS_UINT4(&sharedMemory[0x344]) = make_uint4(0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0);
|
||||
AS_UINT4(&sharedMemory[0x348]) = make_uint4(0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3);
|
||||
AS_UINT4(&sharedMemory[0x34C]) = make_uint4(0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484);
|
||||
AS_UINT4(&sharedMemory[0x350]) = make_uint4(0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded);
|
||||
AS_UINT4(&sharedMemory[0x354]) = make_uint4(0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b);
|
||||
AS_UINT4(&sharedMemory[0x358]) = make_uint4(0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939);
|
||||
AS_UINT4(&sharedMemory[0x35C]) = make_uint4(0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf);
|
||||
break;
|
||||
case 3:
|
||||
AS_UINT4(&sharedMemory[0x360]) = make_uint4(0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb);
|
||||
AS_UINT4(&sharedMemory[0x364]) = make_uint4(0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585);
|
||||
AS_UINT4(&sharedMemory[0x368]) = make_uint4(0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f);
|
||||
AS_UINT4(&sharedMemory[0x36C]) = make_uint4(0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8);
|
||||
AS_UINT4(&sharedMemory[0x370]) = make_uint4(0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f);
|
||||
AS_UINT4(&sharedMemory[0x374]) = make_uint4(0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5);
|
||||
AS_UINT4(&sharedMemory[0x378]) = make_uint4(0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121);
|
||||
AS_UINT4(&sharedMemory[0x37C]) = make_uint4(0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2);
|
||||
break;
|
||||
case 4:
|
||||
AS_UINT4(&sharedMemory[0x380]) = make_uint4(0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec);
|
||||
AS_UINT4(&sharedMemory[0x384]) = make_uint4(0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717);
|
||||
AS_UINT4(&sharedMemory[0x388]) = make_uint4(0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d);
|
||||
AS_UINT4(&sharedMemory[0x38C]) = make_uint4(0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373);
|
||||
AS_UINT4(&sharedMemory[0x390]) = make_uint4(0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc);
|
||||
AS_UINT4(&sharedMemory[0x394]) = make_uint4(0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888);
|
||||
AS_UINT4(&sharedMemory[0x398]) = make_uint4(0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414);
|
||||
AS_UINT4(&sharedMemory[0x39C]) = make_uint4(0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb);
|
||||
break;
|
||||
case 5:
|
||||
AS_UINT4(&sharedMemory[0x3A0]) = make_uint4(0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a);
|
||||
AS_UINT4(&sharedMemory[0x3A4]) = make_uint4(0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c);
|
||||
AS_UINT4(&sharedMemory[0x3A8]) = make_uint4(0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262);
|
||||
AS_UINT4(&sharedMemory[0x3AC]) = make_uint4(0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979);
|
||||
AS_UINT4(&sharedMemory[0x3B0]) = make_uint4(0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d);
|
||||
AS_UINT4(&sharedMemory[0x3B4]) = make_uint4(0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9);
|
||||
AS_UINT4(&sharedMemory[0x3B8]) = make_uint4(0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea);
|
||||
AS_UINT4(&sharedMemory[0x3BC]) = make_uint4(0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808);
|
||||
break;
|
||||
case 6:
|
||||
AS_UINT4(&sharedMemory[0x3C0]) = make_uint4(0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e);
|
||||
AS_UINT4(&sharedMemory[0x3C4]) = make_uint4(0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6);
|
||||
AS_UINT4(&sharedMemory[0x3C8]) = make_uint4(0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f);
|
||||
AS_UINT4(&sharedMemory[0x3CC]) = make_uint4(0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a);
|
||||
AS_UINT4(&sharedMemory[0x3D0]) = make_uint4(0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666);
|
||||
AS_UINT4(&sharedMemory[0x3D4]) = make_uint4(0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e);
|
||||
AS_UINT4(&sharedMemory[0x3D8]) = make_uint4(0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9);
|
||||
AS_UINT4(&sharedMemory[0x3DC]) = make_uint4(0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e);
|
||||
break;
|
||||
case 7:
|
||||
AS_UINT4(&sharedMemory[0x3E0]) = make_uint4(0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111);
|
||||
AS_UINT4(&sharedMemory[0x3E4]) = make_uint4(0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494);
|
||||
AS_UINT4(&sharedMemory[0x3E8]) = make_uint4(0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9);
|
||||
AS_UINT4(&sharedMemory[0x3EC]) = make_uint4(0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf);
|
||||
AS_UINT4(&sharedMemory[0x3F0]) = make_uint4(0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d);
|
||||
AS_UINT4(&sharedMemory[0x3F4]) = make_uint4(0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868);
|
||||
AS_UINT4(&sharedMemory[0x3F8]) = make_uint4(0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f);
|
||||
AS_UINT4(&sharedMemory[0x3FC]) = make_uint4(0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
//#include <cuda_helper.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t h[8], s[4], t[2];
|
||||
int buflen, nullt;
|
||||
uint8_t buf[64];
|
||||
} blake_state;
|
||||
|
||||
#define U8TO32(p) \
|
||||
(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \
|
||||
((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) ))
|
||||
|
||||
#define U32TO8(p, v) \
|
||||
(p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \
|
||||
(p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) );
|
||||
|
||||
#define BLAKE_ROT(x,n) ROTR32(x, n)
|
||||
#define BLAKE_G(a,b,c,d,e) \
|
||||
v[a] += (m[d_blake_sigma[i][e]] ^ d_blake_cst[d_blake_sigma[i][e+1]]) + v[b]; \
|
||||
v[d] = BLAKE_ROT(v[d] ^ v[a],16); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = BLAKE_ROT(v[b] ^ v[c],12); \
|
||||
v[a] += (m[d_blake_sigma[i][e+1]] ^ d_blake_cst[d_blake_sigma[i][e]]) + v[b]; \
|
||||
v[d] = BLAKE_ROT(v[d] ^ v[a], 8); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = BLAKE_ROT(v[b] ^ v[c], 7);
|
||||
|
||||
__constant__ uint8_t d_blake_sigma[14][16] = {
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
|
||||
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
|
||||
{7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8},
|
||||
{9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13},
|
||||
{2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9},
|
||||
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11},
|
||||
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10},
|
||||
{6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5},
|
||||
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
|
||||
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
|
||||
{7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8}
|
||||
};
|
||||
|
||||
__constant__ uint32_t d_blake_cst[16] = {
|
||||
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
|
||||
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
|
||||
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
|
||||
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917
|
||||
};
|
||||
|
||||
__device__
|
||||
void cn_blake_compress(blake_state * __restrict__ S, const uint8_t * __restrict__ block)
|
||||
{
|
||||
uint32_t v[16], m[16], i;
|
||||
|
||||
for (i = 0; i < 16; ++i) m[i] = U8TO32(block + i * 4);
|
||||
for (i = 0; i < 8; ++i) v[i] = S->h[i];
|
||||
v[ 8] = S->s[0] ^ 0x243F6A88;
|
||||
v[ 9] = S->s[1] ^ 0x85A308D3;
|
||||
v[10] = S->s[2] ^ 0x13198A2E;
|
||||
v[11] = S->s[3] ^ 0x03707344;
|
||||
v[12] = 0xA4093822;
|
||||
v[13] = 0x299F31D0;
|
||||
v[14] = 0x082EFA98;
|
||||
v[15] = 0xEC4E6C89;
|
||||
|
||||
if (S->nullt == 0) {
|
||||
v[12] ^= S->t[0];
|
||||
v[13] ^= S->t[0];
|
||||
v[14] ^= S->t[1];
|
||||
v[15] ^= S->t[1];
|
||||
}
|
||||
|
||||
for (i = 0; i < 14; ++i) {
|
||||
BLAKE_G(0, 4, 8, 12, 0);
|
||||
BLAKE_G(1, 5, 9, 13, 2);
|
||||
BLAKE_G(2, 6, 10, 14, 4);
|
||||
BLAKE_G(3, 7, 11, 15, 6);
|
||||
BLAKE_G(3, 4, 9, 14, 14);
|
||||
BLAKE_G(2, 7, 8, 13, 12);
|
||||
BLAKE_G(0, 5, 10, 15, 8);
|
||||
BLAKE_G(1, 6, 11, 12, 10);
|
||||
}
|
||||
|
||||
for (i = 0; i < 16; ++i) S->h[i % 8] ^= v[i];
|
||||
for (i = 0; i < 8; ++i) S->h[i] ^= S->s[i % 4];
|
||||
}
|
||||
|
||||
__device__ void cn_blake_update(blake_state * __restrict__ S, const uint8_t * __restrict__ data, uint64_t datalen)
|
||||
{
|
||||
int left = S->buflen >> 3;
|
||||
int fill = 64 - left;
|
||||
|
||||
if (left && (((datalen >> 3) & 0x3F) >= (unsigned) fill)) {
|
||||
memcpy((void *) (S->buf + left), (void *) data, fill);
|
||||
S->t[0] += 512;
|
||||
if (S->t[0] == 0) S->t[1]++;
|
||||
cn_blake_compress(S, S->buf);
|
||||
data += fill;
|
||||
datalen -= (fill << 3);
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while (datalen >= 512) {
|
||||
S->t[0] += 512;
|
||||
if (S->t[0] == 0) S->t[1]++;
|
||||
cn_blake_compress(S, data);
|
||||
data += 64;
|
||||
datalen -= 512;
|
||||
}
|
||||
|
||||
if (datalen > 0) {
|
||||
memcpy((void *) (S->buf + left), (void *) data, datalen >> 3);
|
||||
S->buflen = (left << 3) + datalen;
|
||||
} else {
|
||||
S->buflen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_blake_final(blake_state * __restrict__ S, uint8_t * __restrict__ digest)
|
||||
{
|
||||
const uint8_t padding[] = {
|
||||
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
|
||||
};
|
||||
uint8_t pa = 0x81, pb = 0x01;
|
||||
uint8_t msglen[8];
|
||||
uint32_t lo = S->t[0] + S->buflen, hi = S->t[1];
|
||||
if (lo < (unsigned) S->buflen) hi++;
|
||||
U32TO8(msglen + 0, hi);
|
||||
U32TO8(msglen + 4, lo);
|
||||
|
||||
if (S->buflen == 440) {
|
||||
S->t[0] -= 8;
|
||||
cn_blake_update(S, &pa, 8);
|
||||
} else {
|
||||
if (S->buflen < 440) {
|
||||
if (S->buflen == 0) S->nullt = 1;
|
||||
S->t[0] -= 440 - S->buflen;
|
||||
cn_blake_update(S, padding, 440 - S->buflen);
|
||||
} else {
|
||||
S->t[0] -= 512 - S->buflen;
|
||||
cn_blake_update(S, padding, 512 - S->buflen);
|
||||
S->t[0] -= 440;
|
||||
cn_blake_update(S, padding + 1, 440);
|
||||
S->nullt = 1;
|
||||
}
|
||||
cn_blake_update(S, &pb, 8);
|
||||
S->t[0] -= 8;
|
||||
}
|
||||
S->t[0] -= 64;
|
||||
cn_blake_update(S, msglen, 64);
|
||||
|
||||
U32TO8(digest + 0, S->h[0]);
|
||||
U32TO8(digest + 4, S->h[1]);
|
||||
U32TO8(digest + 8, S->h[2]);
|
||||
U32TO8(digest + 12, S->h[3]);
|
||||
U32TO8(digest + 16, S->h[4]);
|
||||
U32TO8(digest + 20, S->h[5]);
|
||||
U32TO8(digest + 24, S->h[6]);
|
||||
U32TO8(digest + 28, S->h[7]);
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_blake(const uint8_t * __restrict__ in, uint64_t inlen, uint32_t * out)
|
||||
{
|
||||
blake_state bs;
|
||||
blake_state *S = (blake_state *)&bs;
|
||||
|
||||
S->h[0] = 0x6A09E667; S->h[1] = 0xBB67AE85; S->h[2] = 0x3C6EF372;
|
||||
S->h[3] = 0xA54FF53A; S->h[4] = 0x510E527F; S->h[5] = 0x9B05688C;
|
||||
S->h[6] = 0x1F83D9AB; S->h[7] = 0x5BE0CD19;
|
||||
S->t[0] = S->t[1] = S->buflen = S->nullt = 0;
|
||||
S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0;
|
||||
|
||||
cn_blake_update(S, (uint8_t *)in, inlen * 8);
|
||||
cn_blake_final(S, (uint8_t *)out);
|
||||
}
|
||||
@@ -1,348 +0,0 @@
|
||||
|
||||
#define GROESTL_ROWS 8
|
||||
#define GROESTL_LENGTHFIELDLEN GROESTL_ROWS
|
||||
#define GROESTL_COLS512 8
|
||||
#define GROESTL_SIZE512 (GROESTL_ROWS*GROESTL_COLS512)
|
||||
#define GROESTL_ROUNDS512 10
|
||||
#define GROESTL_HASH_BIT_LEN 256
|
||||
|
||||
#define GROESTL_ROTL32(v, n) ROTL32(v, n)
|
||||
|
||||
#define li_32(h) 0x##h##u
|
||||
#define GROESTL_EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n)))
|
||||
#define u32BIG(a) \
|
||||
((GROESTL_ROTL32(a,8) & li_32(00FF00FF)) | \
|
||||
(GROESTL_ROTL32(a,24) & li_32(FF00FF00)))
|
||||
|
||||
typedef struct {
|
||||
uint32_t chaining[GROESTL_SIZE512/sizeof(uint32_t)];
|
||||
uint32_t block_counter1, block_counter2;
|
||||
BitSequence buffer[GROESTL_SIZE512];
|
||||
int buf_ptr;
|
||||
int bits_in_last_byte;
|
||||
} groestlHashState;
|
||||
|
||||
__constant__ uint32_t d_groestl_T[512] = {
|
||||
0xa5f432c6, 0xc6a597f4, 0x84976ff8, 0xf884eb97, 0x99b05eee, 0xee99c7b0, 0x8d8c7af6, 0xf68df78c, 0x0d17e8ff, 0xff0de517, 0xbddc0ad6, 0xd6bdb7dc, 0xb1c816de, 0xdeb1a7c8, 0x54fc6d91, 0x915439fc,
|
||||
0x50f09060, 0x6050c0f0, 0x03050702, 0x02030405, 0xa9e02ece, 0xcea987e0, 0x7d87d156, 0x567dac87, 0x192bcce7, 0xe719d52b, 0x62a613b5, 0xb56271a6, 0xe6317c4d, 0x4de69a31, 0x9ab559ec, 0xec9ac3b5,
|
||||
0x45cf408f, 0x8f4505cf, 0x9dbca31f, 0x1f9d3ebc, 0x40c04989, 0x894009c0, 0x879268fa, 0xfa87ef92, 0x153fd0ef, 0xef15c53f, 0xeb2694b2, 0xb2eb7f26, 0xc940ce8e, 0x8ec90740, 0x0b1de6fb, 0xfb0bed1d,
|
||||
0xec2f6e41, 0x41ec822f, 0x67a91ab3, 0xb3677da9, 0xfd1c435f, 0x5ffdbe1c, 0xea256045, 0x45ea8a25, 0xbfdaf923, 0x23bf46da, 0xf7025153, 0x53f7a602, 0x96a145e4, 0xe496d3a1, 0x5bed769b, 0x9b5b2ded,
|
||||
0xc25d2875, 0x75c2ea5d, 0x1c24c5e1, 0xe11cd924, 0xaee9d43d, 0x3dae7ae9, 0x6abef24c, 0x4c6a98be, 0x5aee826c, 0x6c5ad8ee, 0x41c3bd7e, 0x7e41fcc3, 0x0206f3f5, 0xf502f106, 0x4fd15283, 0x834f1dd1,
|
||||
0x5ce48c68, 0x685cd0e4, 0xf4075651, 0x51f4a207, 0x345c8dd1, 0xd134b95c, 0x0818e1f9, 0xf908e918, 0x93ae4ce2, 0xe293dfae, 0x73953eab, 0xab734d95, 0x53f59762, 0x6253c4f5, 0x3f416b2a, 0x2a3f5441,
|
||||
0x0c141c08, 0x080c1014, 0x52f66395, 0x955231f6, 0x65afe946, 0x46658caf, 0x5ee27f9d, 0x9d5e21e2, 0x28784830, 0x30286078, 0xa1f8cf37, 0x37a16ef8, 0x0f111b0a, 0x0a0f1411, 0xb5c4eb2f, 0x2fb55ec4,
|
||||
0x091b150e, 0x0e091c1b, 0x365a7e24, 0x2436485a, 0x9bb6ad1b, 0x1b9b36b6, 0x3d4798df, 0xdf3da547, 0x266aa7cd, 0xcd26816a, 0x69bbf54e, 0x4e699cbb, 0xcd4c337f, 0x7fcdfe4c, 0x9fba50ea, 0xea9fcfba,
|
||||
0x1b2d3f12, 0x121b242d, 0x9eb9a41d, 0x1d9e3ab9, 0x749cc458, 0x5874b09c, 0x2e724634, 0x342e6872, 0x2d774136, 0x362d6c77, 0xb2cd11dc, 0xdcb2a3cd, 0xee299db4, 0xb4ee7329, 0xfb164d5b, 0x5bfbb616,
|
||||
0xf601a5a4, 0xa4f65301, 0x4dd7a176, 0x764decd7, 0x61a314b7, 0xb76175a3, 0xce49347d, 0x7dcefa49, 0x7b8ddf52, 0x527ba48d, 0x3e429fdd, 0xdd3ea142, 0x7193cd5e, 0x5e71bc93, 0x97a2b113, 0x139726a2,
|
||||
0xf504a2a6, 0xa6f55704, 0x68b801b9, 0xb96869b8, 0, 0, 0x2c74b5c1, 0xc12c9974, 0x60a0e040, 0x406080a0, 0x1f21c2e3, 0xe31fdd21, 0xc8433a79, 0x79c8f243, 0xed2c9ab6, 0xb6ed772c,
|
||||
0xbed90dd4, 0xd4beb3d9, 0x46ca478d, 0x8d4601ca, 0xd9701767, 0x67d9ce70, 0x4bddaf72, 0x724be4dd, 0xde79ed94, 0x94de3379, 0xd467ff98, 0x98d42b67, 0xe82393b0, 0xb0e87b23, 0x4ade5b85, 0x854a11de,
|
||||
0x6bbd06bb, 0xbb6b6dbd, 0x2a7ebbc5, 0xc52a917e, 0xe5347b4f, 0x4fe59e34, 0x163ad7ed, 0xed16c13a, 0xc554d286, 0x86c51754, 0xd762f89a, 0x9ad72f62, 0x55ff9966, 0x6655ccff, 0x94a7b611, 0x119422a7,
|
||||
0xcf4ac08a, 0x8acf0f4a, 0x1030d9e9, 0xe910c930, 0x060a0e04, 0x0406080a, 0x819866fe, 0xfe81e798, 0xf00baba0, 0xa0f05b0b, 0x44ccb478, 0x7844f0cc, 0xbad5f025, 0x25ba4ad5, 0xe33e754b, 0x4be3963e,
|
||||
0xf30eaca2, 0xa2f35f0e, 0xfe19445d, 0x5dfeba19, 0xc05bdb80, 0x80c01b5b, 0x8a858005, 0x058a0a85, 0xadecd33f, 0x3fad7eec, 0xbcdffe21, 0x21bc42df, 0x48d8a870, 0x7048e0d8, 0x040cfdf1, 0xf104f90c,
|
||||
0xdf7a1963, 0x63dfc67a, 0xc1582f77, 0x77c1ee58, 0x759f30af, 0xaf75459f, 0x63a5e742, 0x426384a5, 0x30507020, 0x20304050, 0x1a2ecbe5, 0xe51ad12e, 0x0e12effd, 0xfd0ee112, 0x6db708bf, 0xbf6d65b7,
|
||||
0x4cd45581, 0x814c19d4, 0x143c2418, 0x1814303c, 0x355f7926, 0x26354c5f, 0x2f71b2c3, 0xc32f9d71, 0xe13886be, 0xbee16738, 0xa2fdc835, 0x35a26afd, 0xcc4fc788, 0x88cc0b4f, 0x394b652e, 0x2e395c4b,
|
||||
0x57f96a93, 0x93573df9, 0xf20d5855, 0x55f2aa0d, 0x829d61fc, 0xfc82e39d, 0x47c9b37a, 0x7a47f4c9, 0xacef27c8, 0xc8ac8bef, 0xe73288ba, 0xbae76f32, 0x2b7d4f32, 0x322b647d, 0x95a442e6, 0xe695d7a4,
|
||||
0xa0fb3bc0, 0xc0a09bfb, 0x98b3aa19, 0x199832b3, 0xd168f69e, 0x9ed12768, 0x7f8122a3, 0xa37f5d81, 0x66aaee44, 0x446688aa, 0x7e82d654, 0x547ea882, 0xabe6dd3b, 0x3bab76e6, 0x839e950b, 0xb83169e,
|
||||
0xca45c98c, 0x8cca0345, 0x297bbcc7, 0xc729957b, 0xd36e056b, 0x6bd3d66e, 0x3c446c28, 0x283c5044, 0x798b2ca7, 0xa779558b, 0xe23d81bc, 0xbce2633d, 0x1d273116, 0x161d2c27, 0x769a37ad, 0xad76419a,
|
||||
0x3b4d96db, 0xdb3bad4d, 0x56fa9e64, 0x6456c8fa, 0x4ed2a674, 0x744ee8d2, 0x1e223614, 0x141e2822, 0xdb76e492, 0x92db3f76, 0x0a1e120c, 0x0c0a181e, 0x6cb4fc48, 0x486c90b4, 0xe4378fb8, 0xb8e46b37,
|
||||
0x5de7789f, 0x9f5d25e7, 0x6eb20fbd, 0xbd6e61b2, 0xef2a6943, 0x43ef862a, 0xa6f135c4, 0xc4a693f1, 0xa8e3da39, 0x39a872e3, 0xa4f7c631, 0x31a462f7, 0x37598ad3, 0xd337bd59, 0x8b8674f2, 0xf28bff86,
|
||||
0x325683d5, 0xd532b156, 0x43c54e8b, 0x8b430dc5, 0x59eb856e, 0x6e59dceb, 0xb7c218da, 0xdab7afc2, 0x8c8f8e01, 0x018c028f, 0x64ac1db1, 0xb16479ac, 0xd26df19c, 0x9cd2236d, 0xe03b7249, 0x49e0923b,
|
||||
0xb4c71fd8, 0xd8b4abc7, 0xfa15b9ac, 0xacfa4315, 0x0709faf3, 0xf307fd09, 0x256fa0cf, 0xcf25856f, 0xafea20ca, 0xcaaf8fea, 0x8e897df4, 0xf48ef389, 0xe9206747, 0x47e98e20, 0x18283810, 0x10182028,
|
||||
0xd5640b6f, 0x6fd5de64, 0x888373f0, 0xf088fb83, 0x6fb1fb4a, 0x4a6f94b1, 0x7296ca5c, 0x5c72b896, 0x246c5438, 0x3824706c, 0xf1085f57, 0x57f1ae08, 0xc7522173, 0x73c7e652, 0x51f36497, 0x975135f3,
|
||||
0x2365aecb, 0xcb238d65, 0x7c8425a1, 0xa17c5984, 0x9cbf57e8, 0xe89ccbbf, 0x21635d3e, 0x3e217c63, 0xdd7cea96, 0x96dd377c, 0xdc7f1e61, 0x61dcc27f, 0x86919c0d, 0x0d861a91, 0x85949b0f, 0xf851e94,
|
||||
0x90ab4be0, 0xe090dbab, 0x42c6ba7c, 0x7c42f8c6, 0xc4572671, 0x71c4e257, 0xaae529cc, 0xccaa83e5, 0xd873e390, 0x90d83b73, 0x050f0906, 0x06050c0f, 0x0103f4f7, 0xf701f503, 0x12362a1c, 0x1c123836,
|
||||
0xa3fe3cc2, 0xc2a39ffe, 0x5fe18b6a, 0x6a5fd4e1, 0xf910beae, 0xaef94710, 0xd06b0269, 0x69d0d26b, 0x91a8bf17, 0x17912ea8, 0x58e87199, 0x995829e8, 0x2769533a, 0x3a277469, 0xb9d0f727, 0x27b94ed0,
|
||||
0x384891d9, 0xd938a948, 0x1335deeb, 0xeb13cd35, 0xb3cee52b, 0x2bb356ce, 0x33557722, 0x22334455, 0xbbd604d2, 0xd2bbbfd6, 0x709039a9, 0xa9704990, 0x89808707, 0x07890e80, 0xa7f2c133, 0x33a766f2,
|
||||
0xb6c1ec2d, 0x2db65ac1, 0x22665a3c, 0x3c227866, 0x92adb815, 0x15922aad, 0x2060a9c9, 0xc9208960, 0x49db5c87, 0x874915db, 0xff1ab0aa, 0xaaff4f1a, 0x7888d850, 0x5078a088, 0x7a8e2ba5, 0xa57a518e,
|
||||
0x8f8a8903, 0x038f068a, 0xf8134a59, 0x59f8b213, 0x809b9209, 0x0980129b, 0x1739231a, 0x1a173439, 0xda751065, 0x65daca75, 0x315384d7, 0xd731b553, 0xc651d584, 0x84c61351, 0xb8d303d0, 0xd0b8bbd3,
|
||||
0xc35edc82, 0x82c31f5e, 0xb0cbe229, 0x29b052cb, 0x7799c35a, 0x5a77b499, 0x11332d1e, 0x1e113c33, 0xcb463d7b, 0x7bcbf646, 0xfc1fb7a8, 0xa8fc4b1f, 0xd6610c6d, 0x6dd6da61, 0x3a4e622c, 0x2c3a584e
|
||||
};
|
||||
|
||||
#define GROESTL_ROTATE_COLUMN_DOWN(v1, v2, amount_bytes, temp_var) { \
|
||||
temp_var = (v1<<(8*amount_bytes))|(v2>>(8*(4-amount_bytes))); \
|
||||
v2 = (v2<<(8*amount_bytes))|(v1>>(8*(4-amount_bytes))); \
|
||||
v1 = temp_var; \
|
||||
}
|
||||
|
||||
#define GROESTL_COLUMN(x,y,i, c0,c1,c2,c3,c4,c5,c6,c7, tv1,tv2,tu,tl,t) \
|
||||
tu = d_groestl_T[2*(uint32_t)x[4*c0+0]]; \
|
||||
tl = d_groestl_T[2*(uint32_t)x[4*c0+0]+1]; \
|
||||
tv1 = d_groestl_T[2*(uint32_t)x[4*c1+1]]; \
|
||||
tv2 = d_groestl_T[2*(uint32_t)x[4*c1+1]+1]; \
|
||||
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,1,t) \
|
||||
tu ^= tv1; \
|
||||
tl ^= tv2; \
|
||||
tv1 = d_groestl_T[2*(uint32_t)x[4*c2+2]]; \
|
||||
tv2 = d_groestl_T[2*(uint32_t)x[4*c2+2]+1]; \
|
||||
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,2,t) \
|
||||
tu ^= tv1; \
|
||||
tl ^= tv2; \
|
||||
tv1 = d_groestl_T[2*(uint32_t)x[4*c3+3]]; \
|
||||
tv2 = d_groestl_T[2*(uint32_t)x[4*c3+3]+1]; \
|
||||
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,3,t) \
|
||||
tu ^= tv1; \
|
||||
tl ^= tv2; \
|
||||
tl ^= d_groestl_T[2*(uint32_t)x[4*c4+0]]; \
|
||||
tu ^= d_groestl_T[2*(uint32_t)x[4*c4+0]+1]; \
|
||||
tv1 = d_groestl_T[2*(uint32_t)x[4*c5+1]]; \
|
||||
tv2 = d_groestl_T[2*(uint32_t)x[4*c5+1]+1]; \
|
||||
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,1,t) \
|
||||
tl ^= tv1; \
|
||||
tu ^= tv2; \
|
||||
tv1 = d_groestl_T[2*(uint32_t)x[4*c6+2]]; \
|
||||
tv2 = d_groestl_T[2*(uint32_t)x[4*c6+2]+1]; \
|
||||
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,2,t) \
|
||||
tl ^= tv1; \
|
||||
tu ^= tv2; \
|
||||
tv1 = d_groestl_T[2*(uint32_t)x[4*c7+3]]; \
|
||||
tv2 = d_groestl_T[2*(uint32_t)x[4*c7+3]+1]; \
|
||||
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,3,t) \
|
||||
tl ^= tv1; \
|
||||
tu ^= tv2; \
|
||||
y[i] = tu; \
|
||||
y[i+1] = tl;
|
||||
|
||||
__device__
|
||||
void cn_groestl_RND512P(uint8_t * __restrict__ x, uint32_t * __restrict__ y, uint32_t r)
|
||||
{
|
||||
uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp;
|
||||
uint32_t* x32 = (uint32_t*)x;
|
||||
x32[ 0] ^= 0x00000000^r;
|
||||
x32[ 2] ^= 0x00000010^r;
|
||||
x32[ 4] ^= 0x00000020^r;
|
||||
x32[ 6] ^= 0x00000030^r;
|
||||
x32[ 8] ^= 0x00000040^r;
|
||||
x32[10] ^= 0x00000050^r;
|
||||
x32[12] ^= 0x00000060^r;
|
||||
x32[14] ^= 0x00000070^r;
|
||||
GROESTL_COLUMN(x,y, 0, 0, 2, 4, 6, 9, 11, 13, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y, 2, 2, 4, 6, 8, 11, 13, 15, 1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y, 4, 4, 6, 8, 10, 13, 15, 1, 3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y, 6, 6, 8, 10, 12, 15, 1, 3, 5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y, 8, 8, 10, 12, 14, 1, 3, 5, 7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y,10, 10, 12, 14, 0, 3, 5, 7, 9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y,12, 12, 14, 0, 2, 5, 7, 9, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y,14, 14, 0, 2, 4, 7, 9, 11, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_groestl_RND512Q(uint8_t * __restrict__ x, uint32_t * __restrict__ y, uint32_t r)
|
||||
{
|
||||
uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp;
|
||||
uint32_t* x32 = (uint32_t*)x;
|
||||
x32[ 0] = ~x32[ 0];
|
||||
x32[ 1] ^= 0xffffffff^r;
|
||||
x32[ 2] = ~x32[ 2];
|
||||
x32[ 3] ^= 0xefffffff^r;
|
||||
x32[ 4] = ~x32[ 4];
|
||||
x32[ 5] ^= 0xdfffffff^r;
|
||||
x32[ 6] = ~x32[ 6];
|
||||
x32[ 7] ^= 0xcfffffff^r;
|
||||
x32[ 8] = ~x32[ 8];
|
||||
x32[ 9] ^= 0xbfffffff^r;
|
||||
x32[10] = ~x32[10];
|
||||
x32[11] ^= 0xafffffff^r;
|
||||
x32[12] = ~x32[12];
|
||||
x32[13] ^= 0x9fffffff^r;
|
||||
x32[14] = ~x32[14];
|
||||
x32[15] ^= 0x8fffffff^r;
|
||||
GROESTL_COLUMN(x,y, 0, 2, 6, 10, 14, 1, 5, 9, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y, 2, 4, 8, 12, 0, 3, 7, 11, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y, 4, 6, 10, 14, 2, 5, 9, 13, 1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y, 6, 8, 12, 0, 4, 7, 11, 15, 3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y, 8, 10, 14, 2, 6, 9, 13, 1, 5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y,10, 12, 0, 4, 8, 11, 15, 3, 7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y,12, 14, 2, 6, 10, 13, 1, 5, 9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
GROESTL_COLUMN(x,y,14, 0, 4, 8, 12, 15, 3, 7, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_groestl_F512(uint32_t * __restrict__ h, const uint32_t * __restrict__ m)
|
||||
{
|
||||
int i;
|
||||
uint32_t Ptmp[2*GROESTL_COLS512];
|
||||
uint32_t Qtmp[2*GROESTL_COLS512];
|
||||
uint32_t y[2*GROESTL_COLS512];
|
||||
uint32_t z[2*GROESTL_COLS512];
|
||||
|
||||
for (i = 0; i < 2*GROESTL_COLS512; i++) {
|
||||
z[i] = m[i];
|
||||
Ptmp[i] = h[i]^m[i];
|
||||
}
|
||||
|
||||
cn_groestl_RND512Q((uint8_t*)z, y, 0x00000000);
|
||||
cn_groestl_RND512Q((uint8_t*)y, z, 0x01000000);
|
||||
cn_groestl_RND512Q((uint8_t*)z, y, 0x02000000);
|
||||
cn_groestl_RND512Q((uint8_t*)y, z, 0x03000000);
|
||||
cn_groestl_RND512Q((uint8_t*)z, y, 0x04000000);
|
||||
cn_groestl_RND512Q((uint8_t*)y, z, 0x05000000);
|
||||
cn_groestl_RND512Q((uint8_t*)z, y, 0x06000000);
|
||||
cn_groestl_RND512Q((uint8_t*)y, z, 0x07000000);
|
||||
cn_groestl_RND512Q((uint8_t*)z, y, 0x08000000);
|
||||
cn_groestl_RND512Q((uint8_t*)y, Qtmp, 0x09000000);
|
||||
|
||||
cn_groestl_RND512P((uint8_t*)Ptmp, y, 0x00000000);
|
||||
cn_groestl_RND512P((uint8_t*)y, z, 0x00000001);
|
||||
cn_groestl_RND512P((uint8_t*)z, y, 0x00000002);
|
||||
cn_groestl_RND512P((uint8_t*)y, z, 0x00000003);
|
||||
cn_groestl_RND512P((uint8_t*)z, y, 0x00000004);
|
||||
cn_groestl_RND512P((uint8_t*)y, z, 0x00000005);
|
||||
cn_groestl_RND512P((uint8_t*)z, y, 0x00000006);
|
||||
cn_groestl_RND512P((uint8_t*)y, z, 0x00000007);
|
||||
cn_groestl_RND512P((uint8_t*)z, y, 0x00000008);
|
||||
cn_groestl_RND512P((uint8_t*)y, Ptmp, 0x00000009);
|
||||
|
||||
for (i = 0; i < 2*GROESTL_COLS512; i++)
|
||||
h[i] ^= Ptmp[i]^Qtmp[i];
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_groestl_outputtransformation(groestlHashState *ctx)
|
||||
{
|
||||
int j;
|
||||
uint32_t temp[2*GROESTL_COLS512];
|
||||
uint32_t y[2*GROESTL_COLS512];
|
||||
uint32_t z[2*GROESTL_COLS512];
|
||||
|
||||
for (j = 0; j < 2*GROESTL_COLS512; j++)
|
||||
temp[j] = ctx->chaining[j];
|
||||
|
||||
cn_groestl_RND512P((uint8_t*)temp, y, 0x00000000);
|
||||
cn_groestl_RND512P((uint8_t*)y, z, 0x00000001);
|
||||
cn_groestl_RND512P((uint8_t*)z, y, 0x00000002);
|
||||
cn_groestl_RND512P((uint8_t*)y, z, 0x00000003);
|
||||
cn_groestl_RND512P((uint8_t*)z, y, 0x00000004);
|
||||
cn_groestl_RND512P((uint8_t*)y, z, 0x00000005);
|
||||
cn_groestl_RND512P((uint8_t*)z, y, 0x00000006);
|
||||
cn_groestl_RND512P((uint8_t*)y, z, 0x00000007);
|
||||
cn_groestl_RND512P((uint8_t*)z, y, 0x00000008);
|
||||
cn_groestl_RND512P((uint8_t*)y, temp, 0x00000009);
|
||||
|
||||
for (j = 0; j < 2*GROESTL_COLS512; j++)
|
||||
ctx->chaining[j] ^= temp[j];
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_groestl_transform(groestlHashState * __restrict__ ctx,
|
||||
const uint8_t * __restrict__ input, int msglen)
|
||||
{
|
||||
for (; msglen >= GROESTL_SIZE512; msglen -= GROESTL_SIZE512, input += GROESTL_SIZE512) {
|
||||
cn_groestl_F512(ctx->chaining,(uint32_t*)input);
|
||||
ctx->block_counter1++;
|
||||
if (ctx->block_counter1 == 0) ctx->block_counter2++;
|
||||
}
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_groestl_final(groestlHashState* __restrict__ ctx, BitSequence* __restrict__ output)
|
||||
{
|
||||
int i, j = 0, hashbytelen = GROESTL_HASH_BIT_LEN/8;
|
||||
uint8_t *s = (BitSequence*)ctx->chaining;
|
||||
|
||||
if (ctx->bits_in_last_byte) {
|
||||
ctx->buffer[(int)ctx->buf_ptr-1] &= ((1<<ctx->bits_in_last_byte)-1)<<(8-ctx->bits_in_last_byte);
|
||||
ctx->buffer[(int)ctx->buf_ptr-1] ^= 0x1<<(7-ctx->bits_in_last_byte);
|
||||
ctx->bits_in_last_byte = 0;
|
||||
}
|
||||
else ctx->buffer[(int)ctx->buf_ptr++] = 0x80;
|
||||
|
||||
if (ctx->buf_ptr > GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) {
|
||||
while (ctx->buf_ptr < GROESTL_SIZE512) {
|
||||
ctx->buffer[(int)ctx->buf_ptr++] = 0;
|
||||
}
|
||||
cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512);
|
||||
ctx->buf_ptr = 0;
|
||||
}
|
||||
while (ctx->buf_ptr < GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) {
|
||||
ctx->buffer[(int)ctx->buf_ptr++] = 0;
|
||||
}
|
||||
|
||||
ctx->block_counter1++;
|
||||
if (ctx->block_counter1 == 0) ctx->block_counter2++;
|
||||
ctx->buf_ptr = GROESTL_SIZE512;
|
||||
|
||||
while (ctx->buf_ptr > GROESTL_SIZE512-(int)sizeof(uint32_t)) {
|
||||
ctx->buffer[(int)--ctx->buf_ptr] = (uint8_t)ctx->block_counter1;
|
||||
ctx->block_counter1 >>= 8;
|
||||
}
|
||||
while (ctx->buf_ptr > GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) {
|
||||
ctx->buffer[(int)--ctx->buf_ptr] = (uint8_t)ctx->block_counter2;
|
||||
ctx->block_counter2 >>= 8;
|
||||
}
|
||||
cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512);
|
||||
cn_groestl_outputtransformation(ctx);
|
||||
|
||||
for (i = GROESTL_SIZE512-hashbytelen; i < GROESTL_SIZE512; i++,j++) {
|
||||
output[j] = s[i];
|
||||
}
|
||||
#if 0
|
||||
for (i = 0; i < GROESTL_COLS512; i++) {
|
||||
ctx->chaining[i] = 0;
|
||||
}
|
||||
for (i = 0; i < GROESTL_SIZE512; i++) {
|
||||
ctx->buffer[i] = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_groestl_update(groestlHashState* __restrict__ ctx,
|
||||
const BitSequence* __restrict__ input, DataLength databitlen)
|
||||
{
|
||||
int index = 0;
|
||||
int msglen = (int)(databitlen/8);
|
||||
int rem = (int)(databitlen%8);
|
||||
|
||||
if (ctx->buf_ptr) {
|
||||
while (ctx->buf_ptr < GROESTL_SIZE512 && index < msglen) {
|
||||
ctx->buffer[(int)ctx->buf_ptr++] = input[index++];
|
||||
}
|
||||
if (ctx->buf_ptr < GROESTL_SIZE512) {
|
||||
if (rem) {
|
||||
ctx->bits_in_last_byte = rem;
|
||||
ctx->buffer[(int)ctx->buf_ptr++] = input[index];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->buf_ptr = 0;
|
||||
cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512);
|
||||
}
|
||||
|
||||
cn_groestl_transform(ctx, input+index, msglen-index);
|
||||
index += ((msglen-index)/GROESTL_SIZE512)*GROESTL_SIZE512;
|
||||
|
||||
while (index < msglen) {
|
||||
ctx->buffer[(int)ctx->buf_ptr++] = input[index++];
|
||||
}
|
||||
|
||||
if (rem) {
|
||||
ctx->bits_in_last_byte = rem;
|
||||
ctx->buffer[(int)ctx->buf_ptr++] = input[index];
|
||||
}
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_groestl_init(groestlHashState* ctx)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for(;i<(GROESTL_SIZE512/sizeof(uint32_t));i++)
|
||||
ctx->chaining[i] = 0;
|
||||
|
||||
ctx->chaining[2*GROESTL_COLS512-1] = u32BIG((uint32_t)GROESTL_HASH_BIT_LEN);
|
||||
ctx->buf_ptr = 0;
|
||||
ctx->block_counter1 = 0;
|
||||
ctx->block_counter2 = 0;
|
||||
ctx->bits_in_last_byte = 0;
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_groestl(const uint8_t * __restrict__ data, DataLength len, uint32_t * hashval)
|
||||
{
|
||||
DataLength databitlen = len << 3;
|
||||
groestlHashState context;
|
||||
|
||||
cn_groestl_init(&context);
|
||||
cn_groestl_update(&context, (BitSequence*) data, databitlen);
|
||||
cn_groestl_final(&context, (BitSequence*) hashval);
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
|
||||
typedef struct {
|
||||
int hashbitlen;
|
||||
unsigned long long databitlen;
|
||||
unsigned long long datasize_in_buffer;
|
||||
uint64_t x[8][2];
|
||||
unsigned char buffer[64];
|
||||
} jhHashState;
|
||||
|
||||
__constant__ unsigned char d_JH256_H0[512] = {
|
||||
0xeb, 0x98, 0xa3, 0x41, 0x2c, 0x20, 0xd3, 0xeb, 0x92, 0xcd, 0xbe, 0x7b, 0x9c, 0xb2, 0x45, 0xc1,
|
||||
0x1c, 0x93, 0x51, 0x91, 0x60, 0xd4, 0xc7, 0xfa, 0x26, 0x0, 0x82, 0xd6, 0x7e, 0x50, 0x8a, 0x3,
|
||||
0xa4, 0x23, 0x9e, 0x26, 0x77, 0x26, 0xb9, 0x45, 0xe0, 0xfb, 0x1a, 0x48, 0xd4, 0x1a, 0x94, 0x77,
|
||||
0xcd, 0xb5, 0xab, 0x26, 0x2, 0x6b, 0x17, 0x7a, 0x56, 0xf0, 0x24, 0x42, 0xf, 0xff, 0x2f, 0xa8,
|
||||
0x71, 0xa3, 0x96, 0x89, 0x7f, 0x2e, 0x4d, 0x75, 0x1d, 0x14, 0x49, 0x8, 0xf7, 0x7d, 0xe2, 0x62,
|
||||
0x27, 0x76, 0x95, 0xf7, 0x76, 0x24, 0x8f, 0x94, 0x87, 0xd5, 0xb6, 0x57, 0x47, 0x80, 0x29, 0x6c,
|
||||
0x5c, 0x5e, 0x27, 0x2d, 0xac, 0x8e, 0xd, 0x6c, 0x51, 0x84, 0x50, 0xc6, 0x57, 0x5, 0x7a, 0xf,
|
||||
0x7b, 0xe4, 0xd3, 0x67, 0x70, 0x24, 0x12, 0xea, 0x89, 0xe3, 0xab, 0x13, 0xd3, 0x1c, 0xd7, 0x69
|
||||
};
|
||||
|
||||
__constant__ unsigned char d_E8_rc[42][32] = {
|
||||
{0x72, 0xd5, 0xde, 0xa2, 0xdf, 0x15, 0xf8, 0x67, 0x7b, 0x84, 0x15, 0xa, 0xb7, 0x23, 0x15, 0x57, 0x81, 0xab, 0xd6, 0x90, 0x4d, 0x5a, 0x87, 0xf6, 0x4e, 0x9f, 0x4f, 0xc5, 0xc3, 0xd1, 0x2b, 0x40},
|
||||
{0xea, 0x98, 0x3a, 0xe0, 0x5c, 0x45, 0xfa, 0x9c, 0x3, 0xc5, 0xd2, 0x99, 0x66, 0xb2, 0x99, 0x9a, 0x66, 0x2, 0x96, 0xb4, 0xf2, 0xbb, 0x53, 0x8a, 0xb5, 0x56, 0x14, 0x1a, 0x88, 0xdb, 0xa2, 0x31},
|
||||
{0x3, 0xa3, 0x5a, 0x5c, 0x9a, 0x19, 0xe, 0xdb, 0x40, 0x3f, 0xb2, 0xa, 0x87, 0xc1, 0x44, 0x10, 0x1c, 0x5, 0x19, 0x80, 0x84, 0x9e, 0x95, 0x1d, 0x6f, 0x33, 0xeb, 0xad, 0x5e, 0xe7, 0xcd, 0xdc},
|
||||
{0x10, 0xba, 0x13, 0x92, 0x2, 0xbf, 0x6b, 0x41, 0xdc, 0x78, 0x65, 0x15, 0xf7, 0xbb, 0x27, 0xd0, 0xa, 0x2c, 0x81, 0x39, 0x37, 0xaa, 0x78, 0x50, 0x3f, 0x1a, 0xbf, 0xd2, 0x41, 0x0, 0x91, 0xd3},
|
||||
{0x42, 0x2d, 0x5a, 0xd, 0xf6, 0xcc, 0x7e, 0x90, 0xdd, 0x62, 0x9f, 0x9c, 0x92, 0xc0, 0x97, 0xce, 0x18, 0x5c, 0xa7, 0xb, 0xc7, 0x2b, 0x44, 0xac, 0xd1, 0xdf, 0x65, 0xd6, 0x63, 0xc6, 0xfc, 0x23},
|
||||
{0x97, 0x6e, 0x6c, 0x3, 0x9e, 0xe0, 0xb8, 0x1a, 0x21, 0x5, 0x45, 0x7e, 0x44, 0x6c, 0xec, 0xa8, 0xee, 0xf1, 0x3, 0xbb, 0x5d, 0x8e, 0x61, 0xfa, 0xfd, 0x96, 0x97, 0xb2, 0x94, 0x83, 0x81, 0x97},
|
||||
{0x4a, 0x8e, 0x85, 0x37, 0xdb, 0x3, 0x30, 0x2f, 0x2a, 0x67, 0x8d, 0x2d, 0xfb, 0x9f, 0x6a, 0x95, 0x8a, 0xfe, 0x73, 0x81, 0xf8, 0xb8, 0x69, 0x6c, 0x8a, 0xc7, 0x72, 0x46, 0xc0, 0x7f, 0x42, 0x14},
|
||||
{0xc5, 0xf4, 0x15, 0x8f, 0xbd, 0xc7, 0x5e, 0xc4, 0x75, 0x44, 0x6f, 0xa7, 0x8f, 0x11, 0xbb, 0x80, 0x52, 0xde, 0x75, 0xb7, 0xae, 0xe4, 0x88, 0xbc, 0x82, 0xb8, 0x0, 0x1e, 0x98, 0xa6, 0xa3, 0xf4},
|
||||
{0x8e, 0xf4, 0x8f, 0x33, 0xa9, 0xa3, 0x63, 0x15, 0xaa, 0x5f, 0x56, 0x24, 0xd5, 0xb7, 0xf9, 0x89, 0xb6, 0xf1, 0xed, 0x20, 0x7c, 0x5a, 0xe0, 0xfd, 0x36, 0xca, 0xe9, 0x5a, 0x6, 0x42, 0x2c, 0x36},
|
||||
{0xce, 0x29, 0x35, 0x43, 0x4e, 0xfe, 0x98, 0x3d, 0x53, 0x3a, 0xf9, 0x74, 0x73, 0x9a, 0x4b, 0xa7, 0xd0, 0xf5, 0x1f, 0x59, 0x6f, 0x4e, 0x81, 0x86, 0xe, 0x9d, 0xad, 0x81, 0xaf, 0xd8, 0x5a, 0x9f},
|
||||
{0xa7, 0x5, 0x6, 0x67, 0xee, 0x34, 0x62, 0x6a, 0x8b, 0xb, 0x28, 0xbe, 0x6e, 0xb9, 0x17, 0x27, 0x47, 0x74, 0x7, 0x26, 0xc6, 0x80, 0x10, 0x3f, 0xe0, 0xa0, 0x7e, 0x6f, 0xc6, 0x7e, 0x48, 0x7b},
|
||||
{0xd, 0x55, 0xa, 0xa5, 0x4a, 0xf8, 0xa4, 0xc0, 0x91, 0xe3, 0xe7, 0x9f, 0x97, 0x8e, 0xf1, 0x9e, 0x86, 0x76, 0x72, 0x81, 0x50, 0x60, 0x8d, 0xd4, 0x7e, 0x9e, 0x5a, 0x41, 0xf3, 0xe5, 0xb0, 0x62},
|
||||
{0xfc, 0x9f, 0x1f, 0xec, 0x40, 0x54, 0x20, 0x7a, 0xe3, 0xe4, 0x1a, 0x0, 0xce, 0xf4, 0xc9, 0x84, 0x4f, 0xd7, 0x94, 0xf5, 0x9d, 0xfa, 0x95, 0xd8, 0x55, 0x2e, 0x7e, 0x11, 0x24, 0xc3, 0x54, 0xa5},
|
||||
{0x5b, 0xdf, 0x72, 0x28, 0xbd, 0xfe, 0x6e, 0x28, 0x78, 0xf5, 0x7f, 0xe2, 0xf, 0xa5, 0xc4, 0xb2, 0x5, 0x89, 0x7c, 0xef, 0xee, 0x49, 0xd3, 0x2e, 0x44, 0x7e, 0x93, 0x85, 0xeb, 0x28, 0x59, 0x7f},
|
||||
{0x70, 0x5f, 0x69, 0x37, 0xb3, 0x24, 0x31, 0x4a, 0x5e, 0x86, 0x28, 0xf1, 0x1d, 0xd6, 0xe4, 0x65, 0xc7, 0x1b, 0x77, 0x4, 0x51, 0xb9, 0x20, 0xe7, 0x74, 0xfe, 0x43, 0xe8, 0x23, 0xd4, 0x87, 0x8a},
|
||||
{0x7d, 0x29, 0xe8, 0xa3, 0x92, 0x76, 0x94, 0xf2, 0xdd, 0xcb, 0x7a, 0x9, 0x9b, 0x30, 0xd9, 0xc1, 0x1d, 0x1b, 0x30, 0xfb, 0x5b, 0xdc, 0x1b, 0xe0, 0xda, 0x24, 0x49, 0x4f, 0xf2, 0x9c, 0x82, 0xbf},
|
||||
{0xa4, 0xe7, 0xba, 0x31, 0xb4, 0x70, 0xbf, 0xff, 0xd, 0x32, 0x44, 0x5, 0xde, 0xf8, 0xbc, 0x48, 0x3b, 0xae, 0xfc, 0x32, 0x53, 0xbb, 0xd3, 0x39, 0x45, 0x9f, 0xc3, 0xc1, 0xe0, 0x29, 0x8b, 0xa0},
|
||||
{0xe5, 0xc9, 0x5, 0xfd, 0xf7, 0xae, 0x9, 0xf, 0x94, 0x70, 0x34, 0x12, 0x42, 0x90, 0xf1, 0x34, 0xa2, 0x71, 0xb7, 0x1, 0xe3, 0x44, 0xed, 0x95, 0xe9, 0x3b, 0x8e, 0x36, 0x4f, 0x2f, 0x98, 0x4a},
|
||||
{0x88, 0x40, 0x1d, 0x63, 0xa0, 0x6c, 0xf6, 0x15, 0x47, 0xc1, 0x44, 0x4b, 0x87, 0x52, 0xaf, 0xff, 0x7e, 0xbb, 0x4a, 0xf1, 0xe2, 0xa, 0xc6, 0x30, 0x46, 0x70, 0xb6, 0xc5, 0xcc, 0x6e, 0x8c, 0xe6},
|
||||
{0xa4, 0xd5, 0xa4, 0x56, 0xbd, 0x4f, 0xca, 0x0, 0xda, 0x9d, 0x84, 0x4b, 0xc8, 0x3e, 0x18, 0xae, 0x73, 0x57, 0xce, 0x45, 0x30, 0x64, 0xd1, 0xad, 0xe8, 0xa6, 0xce, 0x68, 0x14, 0x5c, 0x25, 0x67},
|
||||
{0xa3, 0xda, 0x8c, 0xf2, 0xcb, 0xe, 0xe1, 0x16, 0x33, 0xe9, 0x6, 0x58, 0x9a, 0x94, 0x99, 0x9a, 0x1f, 0x60, 0xb2, 0x20, 0xc2, 0x6f, 0x84, 0x7b, 0xd1, 0xce, 0xac, 0x7f, 0xa0, 0xd1, 0x85, 0x18},
|
||||
{0x32, 0x59, 0x5b, 0xa1, 0x8d, 0xdd, 0x19, 0xd3, 0x50, 0x9a, 0x1c, 0xc0, 0xaa, 0xa5, 0xb4, 0x46, 0x9f, 0x3d, 0x63, 0x67, 0xe4, 0x4, 0x6b, 0xba, 0xf6, 0xca, 0x19, 0xab, 0xb, 0x56, 0xee, 0x7e},
|
||||
{0x1f, 0xb1, 0x79, 0xea, 0xa9, 0x28, 0x21, 0x74, 0xe9, 0xbd, 0xf7, 0x35, 0x3b, 0x36, 0x51, 0xee, 0x1d, 0x57, 0xac, 0x5a, 0x75, 0x50, 0xd3, 0x76, 0x3a, 0x46, 0xc2, 0xfe, 0xa3, 0x7d, 0x70, 0x1},
|
||||
{0xf7, 0x35, 0xc1, 0xaf, 0x98, 0xa4, 0xd8, 0x42, 0x78, 0xed, 0xec, 0x20, 0x9e, 0x6b, 0x67, 0x79, 0x41, 0x83, 0x63, 0x15, 0xea, 0x3a, 0xdb, 0xa8, 0xfa, 0xc3, 0x3b, 0x4d, 0x32, 0x83, 0x2c, 0x83},
|
||||
{0xa7, 0x40, 0x3b, 0x1f, 0x1c, 0x27, 0x47, 0xf3, 0x59, 0x40, 0xf0, 0x34, 0xb7, 0x2d, 0x76, 0x9a, 0xe7, 0x3e, 0x4e, 0x6c, 0xd2, 0x21, 0x4f, 0xfd, 0xb8, 0xfd, 0x8d, 0x39, 0xdc, 0x57, 0x59, 0xef},
|
||||
{0x8d, 0x9b, 0xc, 0x49, 0x2b, 0x49, 0xeb, 0xda, 0x5b, 0xa2, 0xd7, 0x49, 0x68, 0xf3, 0x70, 0xd, 0x7d, 0x3b, 0xae, 0xd0, 0x7a, 0x8d, 0x55, 0x84, 0xf5, 0xa5, 0xe9, 0xf0, 0xe4, 0xf8, 0x8e, 0x65},
|
||||
{0xa0, 0xb8, 0xa2, 0xf4, 0x36, 0x10, 0x3b, 0x53, 0xc, 0xa8, 0x7, 0x9e, 0x75, 0x3e, 0xec, 0x5a, 0x91, 0x68, 0x94, 0x92, 0x56, 0xe8, 0x88, 0x4f, 0x5b, 0xb0, 0x5c, 0x55, 0xf8, 0xba, 0xbc, 0x4c},
|
||||
{0xe3, 0xbb, 0x3b, 0x99, 0xf3, 0x87, 0x94, 0x7b, 0x75, 0xda, 0xf4, 0xd6, 0x72, 0x6b, 0x1c, 0x5d, 0x64, 0xae, 0xac, 0x28, 0xdc, 0x34, 0xb3, 0x6d, 0x6c, 0x34, 0xa5, 0x50, 0xb8, 0x28, 0xdb, 0x71},
|
||||
{0xf8, 0x61, 0xe2, 0xf2, 0x10, 0x8d, 0x51, 0x2a, 0xe3, 0xdb, 0x64, 0x33, 0x59, 0xdd, 0x75, 0xfc, 0x1c, 0xac, 0xbc, 0xf1, 0x43, 0xce, 0x3f, 0xa2, 0x67, 0xbb, 0xd1, 0x3c, 0x2, 0xe8, 0x43, 0xb0},
|
||||
{0x33, 0xa, 0x5b, 0xca, 0x88, 0x29, 0xa1, 0x75, 0x7f, 0x34, 0x19, 0x4d, 0xb4, 0x16, 0x53, 0x5c, 0x92, 0x3b, 0x94, 0xc3, 0xe, 0x79, 0x4d, 0x1e, 0x79, 0x74, 0x75, 0xd7, 0xb6, 0xee, 0xaf, 0x3f},
|
||||
{0xea, 0xa8, 0xd4, 0xf7, 0xbe, 0x1a, 0x39, 0x21, 0x5c, 0xf4, 0x7e, 0x9, 0x4c, 0x23, 0x27, 0x51, 0x26, 0xa3, 0x24, 0x53, 0xba, 0x32, 0x3c, 0xd2, 0x44, 0xa3, 0x17, 0x4a, 0x6d, 0xa6, 0xd5, 0xad},
|
||||
{0xb5, 0x1d, 0x3e, 0xa6, 0xaf, 0xf2, 0xc9, 0x8, 0x83, 0x59, 0x3d, 0x98, 0x91, 0x6b, 0x3c, 0x56, 0x4c, 0xf8, 0x7c, 0xa1, 0x72, 0x86, 0x60, 0x4d, 0x46, 0xe2, 0x3e, 0xcc, 0x8, 0x6e, 0xc7, 0xf6},
|
||||
{0x2f, 0x98, 0x33, 0xb3, 0xb1, 0xbc, 0x76, 0x5e, 0x2b, 0xd6, 0x66, 0xa5, 0xef, 0xc4, 0xe6, 0x2a, 0x6, 0xf4, 0xb6, 0xe8, 0xbe, 0xc1, 0xd4, 0x36, 0x74, 0xee, 0x82, 0x15, 0xbc, 0xef, 0x21, 0x63},
|
||||
{0xfd, 0xc1, 0x4e, 0xd, 0xf4, 0x53, 0xc9, 0x69, 0xa7, 0x7d, 0x5a, 0xc4, 0x6, 0x58, 0x58, 0x26, 0x7e, 0xc1, 0x14, 0x16, 0x6, 0xe0, 0xfa, 0x16, 0x7e, 0x90, 0xaf, 0x3d, 0x28, 0x63, 0x9d, 0x3f},
|
||||
{0xd2, 0xc9, 0xf2, 0xe3, 0x0, 0x9b, 0xd2, 0xc, 0x5f, 0xaa, 0xce, 0x30, 0xb7, 0xd4, 0xc, 0x30, 0x74, 0x2a, 0x51, 0x16, 0xf2, 0xe0, 0x32, 0x98, 0xd, 0xeb, 0x30, 0xd8, 0xe3, 0xce, 0xf8, 0x9a},
|
||||
{0x4b, 0xc5, 0x9e, 0x7b, 0xb5, 0xf1, 0x79, 0x92, 0xff, 0x51, 0xe6, 0x6e, 0x4, 0x86, 0x68, 0xd3, 0x9b, 0x23, 0x4d, 0x57, 0xe6, 0x96, 0x67, 0x31, 0xcc, 0xe6, 0xa6, 0xf3, 0x17, 0xa, 0x75, 0x5},
|
||||
{0xb1, 0x76, 0x81, 0xd9, 0x13, 0x32, 0x6c, 0xce, 0x3c, 0x17, 0x52, 0x84, 0xf8, 0x5, 0xa2, 0x62, 0xf4, 0x2b, 0xcb, 0xb3, 0x78, 0x47, 0x15, 0x47, 0xff, 0x46, 0x54, 0x82, 0x23, 0x93, 0x6a, 0x48},
|
||||
{0x38, 0xdf, 0x58, 0x7, 0x4e, 0x5e, 0x65, 0x65, 0xf2, 0xfc, 0x7c, 0x89, 0xfc, 0x86, 0x50, 0x8e, 0x31, 0x70, 0x2e, 0x44, 0xd0, 0xb, 0xca, 0x86, 0xf0, 0x40, 0x9, 0xa2, 0x30, 0x78, 0x47, 0x4e},
|
||||
{0x65, 0xa0, 0xee, 0x39, 0xd1, 0xf7, 0x38, 0x83, 0xf7, 0x5e, 0xe9, 0x37, 0xe4, 0x2c, 0x3a, 0xbd, 0x21, 0x97, 0xb2, 0x26, 0x1, 0x13, 0xf8, 0x6f, 0xa3, 0x44, 0xed, 0xd1, 0xef, 0x9f, 0xde, 0xe7},
|
||||
{0x8b, 0xa0, 0xdf, 0x15, 0x76, 0x25, 0x92, 0xd9, 0x3c, 0x85, 0xf7, 0xf6, 0x12, 0xdc, 0x42, 0xbe, 0xd8, 0xa7, 0xec, 0x7c, 0xab, 0x27, 0xb0, 0x7e, 0x53, 0x8d, 0x7d, 0xda, 0xaa, 0x3e, 0xa8, 0xde},
|
||||
{0xaa, 0x25, 0xce, 0x93, 0xbd, 0x2, 0x69, 0xd8, 0x5a, 0xf6, 0x43, 0xfd, 0x1a, 0x73, 0x8, 0xf9, 0xc0, 0x5f, 0xef, 0xda, 0x17, 0x4a, 0x19, 0xa5, 0x97, 0x4d, 0x66, 0x33, 0x4c, 0xfd, 0x21, 0x6a},
|
||||
{0x35, 0xb4, 0x98, 0x31, 0xdb, 0x41, 0x15, 0x70, 0xea, 0x1e, 0xf, 0xbb, 0xed, 0xcd, 0x54, 0x9b, 0x9a, 0xd0, 0x63, 0xa1, 0x51, 0x97, 0x40, 0x72, 0xf6, 0x75, 0x9d, 0xbf, 0x91, 0x47, 0x6f, 0xe2}
|
||||
};
|
||||
|
||||
#define JH_SWAP1(x) (x) = ((((x) & 0x5555555555555555ULL) << 1) | (((x) & 0xaaaaaaaaaaaaaaaaULL) >> 1));
|
||||
#define JH_SWAP2(x) (x) = ((((x) & 0x3333333333333333ULL) << 2) | (((x) & 0xccccccccccccccccULL) >> 2));
|
||||
#define JH_SWAP4(x) (x) = ((((x) & 0x0f0f0f0f0f0f0f0fULL) << 4) | (((x) & 0xf0f0f0f0f0f0f0f0ULL) >> 4));
|
||||
#define JH_SWAP8(x) (x) = ((((x) & 0x00ff00ff00ff00ffULL) << 8) | (((x) & 0xff00ff00ff00ff00ULL) >> 8));
|
||||
#define JH_SWAP16(x) (x) = ((((x) & 0x0000ffff0000ffffULL) << 16) | (((x) & 0xffff0000ffff0000ULL) >> 16));
|
||||
#define JH_SWAP32(x) (x) = (((x) << 32) | ((x) >> 32));
|
||||
|
||||
#define JH_L(m0,m1,m2,m3,m4,m5,m6,m7) \
|
||||
(m4) ^= (m1); \
|
||||
(m5) ^= (m2); \
|
||||
(m6) ^= (m0) ^ (m3); \
|
||||
(m7) ^= (m0); \
|
||||
(m0) ^= (m5); \
|
||||
(m1) ^= (m6); \
|
||||
(m2) ^= (m4) ^ (m7); \
|
||||
(m3) ^= (m4);
|
||||
|
||||
#define JH_SS(m0,m1,m2,m3,m4,m5,m6,m7,cc0,cc1) \
|
||||
m3 = ~(m3); \
|
||||
m7 = ~(m7); \
|
||||
m0 ^= ((~(m2)) & (cc0)); \
|
||||
m4 ^= ((~(m6)) & (cc1)); \
|
||||
temp0 = (cc0) ^ ((m0) & (m1));\
|
||||
temp1 = (cc1) ^ ((m4) & (m5));\
|
||||
m0 ^= ((m2) & (m3)); \
|
||||
m4 ^= ((m6) & (m7)); \
|
||||
m3 ^= ((~(m1)) & (m2)); \
|
||||
m7 ^= ((~(m5)) & (m6)); \
|
||||
m1 ^= ((m0) & (m2)); \
|
||||
m5 ^= ((m4) & (m6)); \
|
||||
m2 ^= ((m0) & (~(m3))); \
|
||||
m6 ^= ((m4) & (~(m7))); \
|
||||
m0 ^= ((m1) | (m3)); \
|
||||
m4 ^= ((m5) | (m7)); \
|
||||
m3 ^= ((m1) & (m2)); \
|
||||
m7 ^= ((m5) & (m6)); \
|
||||
m1 ^= (temp0 & (m0)); \
|
||||
m5 ^= (temp1 & (m4)); \
|
||||
m2 ^= temp0; \
|
||||
m6 ^= temp1;
|
||||
|
||||
__device__
|
||||
void cn_jh_E8(jhHashState *state)
|
||||
{
|
||||
uint64_t i,roundnumber,temp0,temp1;
|
||||
|
||||
for (roundnumber = 0; roundnumber < 42; roundnumber = roundnumber+7)
|
||||
{
|
||||
for (i = 0; i < 2; i++) {
|
||||
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
|
||||
((uint64_t *)d_E8_rc[roundnumber+0])[i],((uint64_t *)d_E8_rc[roundnumber+0])[i+2] );
|
||||
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
|
||||
JH_SWAP1(state->x[1][i]); JH_SWAP1(state->x[3][i]); JH_SWAP1(state->x[5][i]); JH_SWAP1(state->x[7][i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
|
||||
((uint64_t *)d_E8_rc[roundnumber+1])[i],((uint64_t *)d_E8_rc[roundnumber+1])[i+2] );
|
||||
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
|
||||
JH_SWAP2(state->x[1][i]); JH_SWAP2(state->x[3][i]); JH_SWAP2(state->x[5][i]); JH_SWAP2(state->x[7][i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
|
||||
((uint64_t *)d_E8_rc[roundnumber+2])[i],((uint64_t *)d_E8_rc[roundnumber+2])[i+2] );
|
||||
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
|
||||
JH_SWAP4(state->x[1][i]); JH_SWAP4(state->x[3][i]); JH_SWAP4(state->x[5][i]); JH_SWAP4(state->x[7][i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
|
||||
((uint64_t *)d_E8_rc[roundnumber+3])[i],((uint64_t *)d_E8_rc[roundnumber+3])[i+2] );
|
||||
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
|
||||
JH_SWAP8(state->x[1][i]); JH_SWAP8(state->x[3][i]); JH_SWAP8(state->x[5][i]); JH_SWAP8(state->x[7][i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
|
||||
((uint64_t *)d_E8_rc[roundnumber+4])[i],((uint64_t *)d_E8_rc[roundnumber+4])[i+2] );
|
||||
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
|
||||
JH_SWAP16(state->x[1][i]); JH_SWAP16(state->x[3][i]); JH_SWAP16(state->x[5][i]); JH_SWAP16(state->x[7][i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
|
||||
((uint64_t *)d_E8_rc[roundnumber+5])[i],((uint64_t *)d_E8_rc[roundnumber+5])[i+2] );
|
||||
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
|
||||
JH_SWAP32(state->x[1][i]); JH_SWAP32(state->x[3][i]); JH_SWAP32(state->x[5][i]); JH_SWAP32(state->x[7][i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
|
||||
((uint64_t *)d_E8_rc[roundnumber+6])[i],((uint64_t *)d_E8_rc[roundnumber+6])[i+2] );
|
||||
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
|
||||
}
|
||||
|
||||
for (i = 1; i < 8; i = i+2) {
|
||||
temp0 = state->x[i][0]; state->x[i][0] = state->x[i][1]; state->x[i][1] = temp0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_jh_F8(jhHashState *state)
|
||||
{
|
||||
uint64_t i;
|
||||
for (i = 0; i < 8; i++) {
|
||||
state->x[i >> 1][i & 1] ^= ((uint64_t *)state->buffer)[i];
|
||||
}
|
||||
|
||||
cn_jh_E8(state);
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
state->x[(8+i) >> 1][(8+i) & 1] ^= ((uint64_t *)state->buffer)[i];
|
||||
}
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_jh_update(jhHashState * __restrict__ state, const uint8_t * __restrict__ data, DataLength databitlen)
|
||||
{
|
||||
DataLength index;
|
||||
|
||||
state->databitlen += databitlen;
|
||||
index = 0;
|
||||
|
||||
if ( (state->datasize_in_buffer > 0 ) && (( state->datasize_in_buffer + databitlen) < 512) )
|
||||
{
|
||||
if ( (databitlen & 7) == 0 ) {
|
||||
memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3));
|
||||
}
|
||||
else memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3)+1);
|
||||
state->datasize_in_buffer += databitlen;
|
||||
databitlen = 0;
|
||||
}
|
||||
|
||||
if ( (state->datasize_in_buffer > 0 ) && (( state->datasize_in_buffer + databitlen) >= 512) )
|
||||
{
|
||||
memcpy( state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3) );
|
||||
index = 64-(state->datasize_in_buffer >> 3);
|
||||
databitlen = databitlen - (512 - state->datasize_in_buffer);
|
||||
cn_jh_F8(state);
|
||||
state->datasize_in_buffer = 0;
|
||||
}
|
||||
|
||||
for ( ; databitlen >= 512; index = index+64, databitlen = databitlen - 512) {
|
||||
memcpy(state->buffer, data+index, 64);
|
||||
cn_jh_F8(state);
|
||||
}
|
||||
|
||||
if ( databitlen > 0) {
|
||||
if ((databitlen & 7) == 0)
|
||||
memcpy(state->buffer, data+index, (databitlen & 0x1ff) >> 3);
|
||||
else
|
||||
memcpy(state->buffer, data+index, ((databitlen & 0x1ff) >> 3)+1);
|
||||
state->datasize_in_buffer = databitlen;
|
||||
}
|
||||
}
|
||||
|
||||
/* pad the message, process the padded block(s), truncate the hash value H to obtain the message digest */
|
||||
__device__
|
||||
void cn_jh_final(jhHashState * __restrict__ state, uint8_t * __restrict__ hashval)
|
||||
{
|
||||
unsigned int i;
|
||||
//uint32_t *bufptr = (uint32_t *)state->buffer;
|
||||
|
||||
if ( (state->databitlen & 0x1ff) == 0 ) {
|
||||
/* pad the message when databitlen is multiple of 512 bits, then process the padded block */
|
||||
memset(state->buffer, 0, 64);
|
||||
//for( i = 0; i < 16; i++ ) *(bufptr+i) = 0x00000000;
|
||||
state->buffer[0] = 0x80;
|
||||
state->buffer[63] = state->databitlen & 0xff;
|
||||
state->buffer[62] = (state->databitlen >> 8) & 0xff;
|
||||
state->buffer[61] = (state->databitlen >> 16) & 0xff;
|
||||
state->buffer[60] = (state->databitlen >> 24) & 0xff;
|
||||
state->buffer[59] = (state->databitlen >> 32) & 0xff;
|
||||
state->buffer[58] = (state->databitlen >> 40) & 0xff;
|
||||
state->buffer[57] = (state->databitlen >> 48) & 0xff;
|
||||
state->buffer[56] = (state->databitlen >> 56) & 0xff;
|
||||
cn_jh_F8(state);
|
||||
|
||||
} else {
|
||||
|
||||
/* set the rest of the bytes in the buffer to 0 */
|
||||
if ( (state->datasize_in_buffer & 7) == 0) {
|
||||
for (i = (state->databitlen & 0x1ff) >> 3; i < 64; i++) state->buffer[i] = 0;
|
||||
} else {
|
||||
for (i = ((state->databitlen & 0x1ff) >> 3)+1; i < 64; i++) state->buffer[i] = 0;
|
||||
}
|
||||
|
||||
/*pad and process the partial block when databitlen is not multiple of 512 bits, then hash the padded blocks*/
|
||||
state->buffer[((state->databitlen & 0x1ff) >> 3)] |= 1 << (7- (state->databitlen & 7));
|
||||
|
||||
cn_jh_F8(state);
|
||||
memset(state->buffer, 0, 64);
|
||||
//for( i = 0; i < 16; i++ ) *(bufptr+i) = 0x00000000;
|
||||
state->buffer[63] = state->databitlen & 0xff;
|
||||
state->buffer[62] = (state->databitlen >> 8) & 0xff;
|
||||
state->buffer[61] = (state->databitlen >> 16) & 0xff;
|
||||
state->buffer[60] = (state->databitlen >> 24) & 0xff;
|
||||
state->buffer[59] = (state->databitlen >> 32) & 0xff;
|
||||
state->buffer[58] = (state->databitlen >> 40) & 0xff;
|
||||
state->buffer[57] = (state->databitlen >> 48) & 0xff;
|
||||
state->buffer[56] = (state->databitlen >> 56) & 0xff;
|
||||
cn_jh_F8(state);
|
||||
}
|
||||
|
||||
memcpy(hashval, ((unsigned char*)state->x) + 64 + 32, 32);
|
||||
//MEMCPY4(hashval, ((unsigned char*)state->x) + 64 + 32, 8);
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_jh_init(jhHashState *state, int hashbitlen)
|
||||
{
|
||||
state->databitlen = 0;
|
||||
state->datasize_in_buffer = 0;
|
||||
state->hashbitlen = hashbitlen;
|
||||
memcpy(state->x, d_JH256_H0, 128);
|
||||
//MEMCPY8(state->x, d_JH256_H0, 128 / 8);
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_jh(const uint8_t * __restrict__ data, DataLength len, uint32_t * hashval)
|
||||
{
|
||||
const int hashbitlen = 256;
|
||||
DataLength databitlen = len << 3;
|
||||
jhHashState state;
|
||||
|
||||
cn_jh_init(&state, hashbitlen);
|
||||
cn_jh_update(&state, data, databitlen);
|
||||
cn_jh_final(&state, (uint8_t*) hashval);
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
__constant__ uint64_t keccakf_rndc[24] = {
|
||||
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
|
||||
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
|
||||
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
|
||||
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
|
||||
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
|
||||
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
|
||||
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
|
||||
0x8000000000008080, 0x0000000080000001, 0x8000000080008008
|
||||
};
|
||||
|
||||
#if __CUDA_ARCH__ >= 350
|
||||
__forceinline__ __device__ uint64_t cuda_rotl64(const uint64_t value, const int offset)
|
||||
{
|
||||
uint2 result;
|
||||
if(offset >= 32)
|
||||
{
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
|
||||
}
|
||||
else
|
||||
{
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
|
||||
}
|
||||
return __double_as_longlong(__hiloint2double(result.y, result.x));
|
||||
}
|
||||
#define rotl64_1(x, y) (cuda_rotl64((x), (y)))
|
||||
#else
|
||||
#define rotl64_1(x, y) ((x) << (y) | ((x) >> (64 - (y))))
|
||||
#endif
|
||||
|
||||
#define rotl64_2(x, y) rotl64_1(((x) >> 32) | ((x) << 32), (y))
|
||||
#define bitselect(a, b, c) ((a) ^ ((c) & ((b) ^ (a))))
|
||||
|
||||
__device__ __forceinline__
|
||||
void cn_keccakf2(uint64_t *s)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < 24; ++i)
|
||||
{
|
||||
uint64_t bc[5], tmpxor[5], tmp1, tmp2;
|
||||
|
||||
tmpxor[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
|
||||
tmpxor[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
|
||||
tmpxor[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
|
||||
tmpxor[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
|
||||
tmpxor[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
|
||||
|
||||
bc[0] = tmpxor[0] ^ rotl64_1(tmpxor[2], 1);
|
||||
bc[1] = tmpxor[1] ^ rotl64_1(tmpxor[3], 1);
|
||||
bc[2] = tmpxor[2] ^ rotl64_1(tmpxor[4], 1);
|
||||
bc[3] = tmpxor[3] ^ rotl64_1(tmpxor[0], 1);
|
||||
bc[4] = tmpxor[4] ^ rotl64_1(tmpxor[1], 1);
|
||||
|
||||
tmp1 = s[1] ^ bc[0];
|
||||
|
||||
s[0] ^= bc[4];
|
||||
s[1] = rotl64_2(s[6] ^ bc[0], 12);
|
||||
s[6] = rotl64_1(s[9] ^ bc[3], 20);
|
||||
s[9] = rotl64_2(s[22] ^ bc[1], 29);
|
||||
s[22] = rotl64_2(s[14] ^ bc[3], 7);
|
||||
s[14] = rotl64_1(s[20] ^ bc[4], 18);
|
||||
s[20] = rotl64_2(s[2] ^ bc[1], 30);
|
||||
s[2] = rotl64_2(s[12] ^ bc[1], 11);
|
||||
s[12] = rotl64_1(s[13] ^ bc[2], 25);
|
||||
s[13] = rotl64_1(s[19] ^ bc[3], 8);
|
||||
s[19] = rotl64_2(s[23] ^ bc[2], 24);
|
||||
s[23] = rotl64_2(s[15] ^ bc[4], 9);
|
||||
s[15] = rotl64_1(s[4] ^ bc[3], 27);
|
||||
s[4] = rotl64_1(s[24] ^ bc[3], 14);
|
||||
s[24] = rotl64_1(s[21] ^ bc[0], 2);
|
||||
s[21] = rotl64_2(s[8] ^ bc[2], 23);
|
||||
s[8] = rotl64_2(s[16] ^ bc[0], 13);
|
||||
s[16] = rotl64_2(s[5] ^ bc[4], 4);
|
||||
s[5] = rotl64_1(s[3] ^ bc[2], 28);
|
||||
s[3] = rotl64_1(s[18] ^ bc[2], 21);
|
||||
s[18] = rotl64_1(s[17] ^ bc[1], 15);
|
||||
s[17] = rotl64_1(s[11] ^ bc[0], 10);
|
||||
s[11] = rotl64_1(s[7] ^ bc[1], 6);
|
||||
s[7] = rotl64_1(s[10] ^ bc[4], 3);
|
||||
s[10] = rotl64_1(tmp1, 1);
|
||||
|
||||
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1);
|
||||
tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1);
|
||||
tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1);
|
||||
tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1);
|
||||
tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1);
|
||||
s[0] ^= keccakf_rndc[i];
|
||||
}
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void cn_keccakf(uint64_t *s)
|
||||
{
|
||||
uint64_t bc[5], tmpxor[5], tmp1, tmp2;
|
||||
|
||||
tmpxor[0] = s[0] ^ s[5];
|
||||
tmpxor[1] = s[1] ^ s[6] ^ 0x8000000000000000ULL;
|
||||
tmpxor[2] = s[2] ^ s[7];
|
||||
tmpxor[3] = s[3] ^ s[8];
|
||||
tmpxor[4] = s[4] ^ s[9];
|
||||
|
||||
bc[0] = tmpxor[0] ^ rotl64_1(tmpxor[2], 1);
|
||||
bc[1] = tmpxor[1] ^ rotl64_1(tmpxor[3], 1);
|
||||
bc[2] = tmpxor[2] ^ rotl64_1(tmpxor[4], 1);
|
||||
bc[3] = tmpxor[3] ^ rotl64_1(tmpxor[0], 1);
|
||||
bc[4] = tmpxor[4] ^ rotl64_1(tmpxor[1], 1);
|
||||
|
||||
tmp1 = s[1] ^ bc[0];
|
||||
|
||||
s[0] ^= bc[4];
|
||||
s[1] = rotl64_2(s[6] ^ bc[0], 12);
|
||||
s[6] = rotl64_1(s[9] ^ bc[3], 20);
|
||||
s[9] = rotl64_2(bc[1], 29);
|
||||
s[22] = rotl64_2(bc[3], 7);
|
||||
s[14] = rotl64_1(bc[4], 18);
|
||||
s[20] = rotl64_2(s[2] ^ bc[1], 30);
|
||||
s[2] = rotl64_2(bc[1], 11);
|
||||
s[12] = rotl64_1(bc[2], 25);
|
||||
s[13] = rotl64_1(bc[3], 8);
|
||||
s[19] = rotl64_2(bc[2], 24);
|
||||
s[23] = rotl64_2(bc[4], 9);
|
||||
s[15] = rotl64_1(s[4] ^ bc[3], 27);
|
||||
s[4] = rotl64_1(bc[3], 14);
|
||||
s[24] = rotl64_1(bc[0], 2);
|
||||
s[21] = rotl64_2(s[8] ^ bc[2], 23);
|
||||
s[8] = rotl64_2(0x8000000000000000ULL ^ bc[0], 13);
|
||||
s[16] = rotl64_2(s[5] ^ bc[4], 4);
|
||||
s[5] = rotl64_1(s[3] ^ bc[2], 28);
|
||||
s[3] = rotl64_1(bc[2], 21);
|
||||
s[18] = rotl64_1(bc[1], 15);
|
||||
s[17] = rotl64_1(bc[0], 10);
|
||||
s[11] = rotl64_1(s[7] ^ bc[1], 6);
|
||||
s[7] = rotl64_1(bc[4], 3);
|
||||
s[10] = rotl64_1(tmp1, 1);
|
||||
|
||||
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1);
|
||||
tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1);
|
||||
tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1);
|
||||
tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1);
|
||||
tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1);
|
||||
s[0] ^= 0x0000000000000001;
|
||||
|
||||
for(int i = 1; i < 24; ++i)
|
||||
{
|
||||
tmpxor[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
|
||||
tmpxor[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
|
||||
tmpxor[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
|
||||
tmpxor[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
|
||||
tmpxor[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
|
||||
|
||||
bc[0] = tmpxor[0] ^ rotl64_1(tmpxor[2], 1);
|
||||
bc[1] = tmpxor[1] ^ rotl64_1(tmpxor[3], 1);
|
||||
bc[2] = tmpxor[2] ^ rotl64_1(tmpxor[4], 1);
|
||||
bc[3] = tmpxor[3] ^ rotl64_1(tmpxor[0], 1);
|
||||
bc[4] = tmpxor[4] ^ rotl64_1(tmpxor[1], 1);
|
||||
|
||||
tmp1 = s[1] ^ bc[0];
|
||||
|
||||
s[0] ^= bc[4];
|
||||
s[1] = rotl64_2(s[6] ^ bc[0], 12);
|
||||
s[6] = rotl64_1(s[9] ^ bc[3], 20);
|
||||
s[9] = rotl64_2(s[22] ^ bc[1], 29);
|
||||
s[22] = rotl64_2(s[14] ^ bc[3], 7);
|
||||
s[14] = rotl64_1(s[20] ^ bc[4], 18);
|
||||
s[20] = rotl64_2(s[2] ^ bc[1], 30);
|
||||
s[2] = rotl64_2(s[12] ^ bc[1], 11);
|
||||
s[12] = rotl64_1(s[13] ^ bc[2], 25);
|
||||
s[13] = rotl64_1(s[19] ^ bc[3], 8);
|
||||
s[19] = rotl64_2(s[23] ^ bc[2], 24);
|
||||
s[23] = rotl64_2(s[15] ^ bc[4], 9);
|
||||
s[15] = rotl64_1(s[4] ^ bc[3], 27);
|
||||
s[4] = rotl64_1(s[24] ^ bc[3], 14);
|
||||
s[24] = rotl64_1(s[21] ^ bc[0], 2);
|
||||
s[21] = rotl64_2(s[8] ^ bc[2], 23);
|
||||
s[8] = rotl64_2(s[16] ^ bc[0], 13);
|
||||
s[16] = rotl64_2(s[5] ^ bc[4], 4);
|
||||
s[5] = rotl64_1(s[3] ^ bc[2], 28);
|
||||
s[3] = rotl64_1(s[18] ^ bc[2], 21);
|
||||
s[18] = rotl64_1(s[17] ^ bc[1], 15);
|
||||
s[17] = rotl64_1(s[11] ^ bc[0], 10);
|
||||
s[11] = rotl64_1(s[7] ^ bc[1], 6);
|
||||
s[7] = rotl64_1(s[10] ^ bc[4], 3);
|
||||
s[10] = rotl64_1(tmp1, 1);
|
||||
|
||||
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1);
|
||||
tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1);
|
||||
tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1);
|
||||
tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1);
|
||||
tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1);
|
||||
s[0] ^= keccakf_rndc[i];
|
||||
}
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void cn_keccak(const uint32_t * __restrict__ in, uint64_t * __restrict__ md)
|
||||
{
|
||||
uint64_t st[25];
|
||||
|
||||
MEMCPY4(st, in, 19);
|
||||
MEMSET8(&st[10], 0x00, 15);
|
||||
st[9] = (st[9] & 0x00000000FFFFFFFFULL) | 0x0000000100000000ULL;
|
||||
st[16] = 0x8000000000000000ULL;
|
||||
|
||||
cn_keccakf(st);
|
||||
|
||||
MEMCPY8(md, st, 25);
|
||||
return;
|
||||
}
|
||||
@@ -1,319 +0,0 @@
|
||||
typedef unsigned int uint_t; /* native unsigned integer */
|
||||
|
||||
#define SKEIN_MODIFIER_WORDS ( 2) /* number of modifier (tweak) words */
|
||||
|
||||
#define SKEIN_256_STATE_WORDS ( 4)
|
||||
#define SKEIN_512_STATE_WORDS ( 8)
|
||||
|
||||
#define SKEIN_256_STATE_BYTES ( 8*SKEIN_256_STATE_WORDS)
|
||||
#define SKEIN_512_STATE_BYTES ( 8*SKEIN_512_STATE_WORDS)
|
||||
|
||||
#define SKEIN_256_STATE_BITS (64*SKEIN_256_STATE_WORDS)
|
||||
#define SKEIN_512_STATE_BITS (64*SKEIN_512_STATE_WORDS)
|
||||
|
||||
#define SKEIN_256_BLOCK_BYTES ( 8*SKEIN_256_STATE_WORDS)
|
||||
#define SKEIN_512_BLOCK_BYTES ( 8*SKEIN_512_STATE_WORDS)
|
||||
|
||||
#define SKEIN_MK_64(hi32,lo32) ((lo32) + (((uint64_t) (hi32)) << 32))
|
||||
#define SKEIN_KS_PARITY SKEIN_MK_64(0x1BD11BDA,0xA9FC1A22)
|
||||
|
||||
#define SKEIN_T1_BIT(BIT) ((BIT) - 64) /* offset 64 because it's the second word */
|
||||
|
||||
#define SKEIN_T1_POS_FIRST SKEIN_T1_BIT(126) /* bits 126 : first block flag */
|
||||
#define SKEIN_T1_POS_BIT_PAD SKEIN_T1_BIT(119) /* bit 119 : partial final input byte */
|
||||
#define SKEIN_T1_POS_FINAL SKEIN_T1_BIT(127) /* bit 127 : final block flag */
|
||||
#define SKEIN_T1_POS_BLK_TYPE SKEIN_T1_BIT(120) /* bits 120..125: type field */
|
||||
|
||||
#define SKEIN_T1_FLAG_FIRST (((uint64_t) 1 ) << SKEIN_T1_POS_FIRST)
|
||||
#define SKEIN_T1_FLAG_BIT_PAD (((uint64_t) 1 ) << SKEIN_T1_POS_BIT_PAD)
|
||||
#define SKEIN_T1_FLAG_FINAL (((uint64_t) 1 ) << SKEIN_T1_POS_FINAL)
|
||||
|
||||
#define SKEIN_BLK_TYPE_MSG (48) /* message processing */
|
||||
#define SKEIN_BLK_TYPE_OUT (63) /* output stage */
|
||||
|
||||
#define SKEIN_T1_BLK_TYPE(T) (((uint64_t) (SKEIN_BLK_TYPE_##T)) << SKEIN_T1_POS_BLK_TYPE)
|
||||
|
||||
#define SKEIN_T1_BLK_TYPE_MSG SKEIN_T1_BLK_TYPE(MSG) /* message processing */
|
||||
#define SKEIN_T1_BLK_TYPE_OUT SKEIN_T1_BLK_TYPE(OUT) /* output stage */
|
||||
|
||||
#define SKEIN_T1_BLK_TYPE_OUT_FINAL (SKEIN_T1_BLK_TYPE_OUT | SKEIN_T1_FLAG_FINAL)
|
||||
|
||||
#define Skein_Set_Tweak(ctxPtr,TWK_NUM,tVal) {(ctxPtr)->h.T[TWK_NUM] = (tVal);}
|
||||
|
||||
#define Skein_Set_T0(ctxPtr,T0) Skein_Set_Tweak(ctxPtr,0,T0)
|
||||
#define Skein_Set_T1(ctxPtr,T1) Skein_Set_Tweak(ctxPtr,1,T1)
|
||||
|
||||
#define Skein_Set_T0_T1(ctxPtr,T0,T1) { \
|
||||
Skein_Set_T0(ctxPtr,(T0)); \
|
||||
Skein_Set_T1(ctxPtr,(T1)); }
|
||||
|
||||
#define Skein_Start_New_Type(ctxPtr,BLK_TYPE) \
|
||||
{ Skein_Set_T0_T1(ctxPtr,0,SKEIN_T1_FLAG_FIRST | SKEIN_T1_BLK_TYPE_##BLK_TYPE); (ctxPtr)->h.bCnt=0; }
|
||||
|
||||
#define Skein_Set_Bit_Pad_Flag(hdr) { (hdr).T[1] |= SKEIN_T1_FLAG_BIT_PAD; }
|
||||
|
||||
#define KW_TWK_BASE (0)
|
||||
#define KW_KEY_BASE (3)
|
||||
#define ks (kw + KW_KEY_BASE)
|
||||
#define ts (kw + KW_TWK_BASE)
|
||||
|
||||
#define R512(p0,p1,p2,p3,p4,p5,p6,p7,R512ROT,rNum) \
|
||||
X##p0 += X##p1; X##p1 = ROTL64(X##p1,R512ROT##_0); X##p1 ^= X##p0; \
|
||||
X##p2 += X##p3; X##p3 = ROTL64(X##p3,R512ROT##_1); X##p3 ^= X##p2; \
|
||||
X##p4 += X##p5; X##p5 = ROTL64(X##p5,R512ROT##_2); X##p5 ^= X##p4; \
|
||||
X##p6 += X##p7; X##p7 = ROTL64(X##p7,R512ROT##_3); X##p7 ^= X##p6;
|
||||
|
||||
#define I512(R) \
|
||||
X0 += ks[((R)+1) % 9]; \
|
||||
X1 += ks[((R)+2) % 9]; \
|
||||
X2 += ks[((R)+3) % 9]; \
|
||||
X3 += ks[((R)+4) % 9]; \
|
||||
X4 += ks[((R)+5) % 9]; \
|
||||
X5 += ks[((R)+6) % 9] + ts[((R)+1) % 3]; \
|
||||
X6 += ks[((R)+7) % 9] + ts[((R)+2) % 3]; \
|
||||
X7 += ks[((R)+8) % 9] + (R)+1;
|
||||
|
||||
|
||||
#define R512_8_rounds(R) \
|
||||
R512(0,1,2,3,4,5,6,7,R_512_0,8*(R)+ 1); \
|
||||
R512(2,1,4,7,6,5,0,3,R_512_1,8*(R)+ 2); \
|
||||
R512(4,1,6,3,0,5,2,7,R_512_2,8*(R)+ 3); \
|
||||
R512(6,1,0,7,2,5,4,3,R_512_3,8*(R)+ 4); \
|
||||
I512(2*(R)); \
|
||||
R512(0,1,2,3,4,5,6,7,R_512_4,8*(R)+ 5); \
|
||||
R512(2,1,4,7,6,5,0,3,R_512_5,8*(R)+ 6); \
|
||||
R512(4,1,6,3,0,5,2,7,R_512_6,8*(R)+ 7); \
|
||||
R512(6,1,0,7,2,5,4,3,R_512_7,8*(R)+ 8); \
|
||||
I512(2*(R)+1);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t hashBitLen;
|
||||
size_t bCnt;
|
||||
uint64_t T[SKEIN_MODIFIER_WORDS];
|
||||
} Skein_Ctxt_Hdr_t;
|
||||
|
||||
typedef struct {
|
||||
Skein_Ctxt_Hdr_t h;
|
||||
uint64_t X[SKEIN_256_STATE_WORDS];
|
||||
uint8_t b[SKEIN_256_BLOCK_BYTES];
|
||||
} Skein_256_Ctxt_t;
|
||||
|
||||
typedef struct {
|
||||
Skein_Ctxt_Hdr_t h;
|
||||
uint64_t X[SKEIN_512_STATE_WORDS];
|
||||
uint8_t b[SKEIN_512_BLOCK_BYTES];
|
||||
} Skein_512_Ctxt_t;
|
||||
|
||||
typedef struct {
|
||||
uint_t statebits;
|
||||
union {
|
||||
Skein_Ctxt_Hdr_t h;
|
||||
Skein_256_Ctxt_t ctx_256;
|
||||
Skein_512_Ctxt_t ctx_512;
|
||||
} u;
|
||||
} skeinHashState;
|
||||
|
||||
__device__
|
||||
void cn_skein_init(skeinHashState *state, size_t hashBitLen)
|
||||
{
|
||||
const uint64_t SKEIN_512_IV_256[] =
|
||||
{
|
||||
SKEIN_MK_64(0xCCD044A1,0x2FDB3E13),
|
||||
SKEIN_MK_64(0xE8359030,0x1A79A9EB),
|
||||
SKEIN_MK_64(0x55AEA061,0x4F816E6F),
|
||||
SKEIN_MK_64(0x2A2767A4,0xAE9B94DB),
|
||||
SKEIN_MK_64(0xEC06025E,0x74DD7683),
|
||||
SKEIN_MK_64(0xE7A436CD,0xC4746251),
|
||||
SKEIN_MK_64(0xC36FBAF9,0x393AD185),
|
||||
SKEIN_MK_64(0x3EEDBA18,0x33EDFC13)
|
||||
};
|
||||
|
||||
Skein_512_Ctxt_t *ctx = &state->u.ctx_512;
|
||||
|
||||
ctx->h.hashBitLen = hashBitLen;
|
||||
|
||||
memcpy(ctx->X, SKEIN_512_IV_256, sizeof(ctx->X));
|
||||
|
||||
Skein_Start_New_Type(ctx, MSG);
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_skein_processblock(Skein_512_Ctxt_t * __restrict__ ctx, const uint8_t * __restrict__ blkPtr, size_t blkCnt, size_t byteCntAdd)
|
||||
{
|
||||
enum {
|
||||
R_512_0_0=46, R_512_0_1=36, R_512_0_2=19, R_512_0_3=37,
|
||||
R_512_1_0=33, R_512_1_1=27, R_512_1_2=14, R_512_1_3=42,
|
||||
R_512_2_0=17, R_512_2_1=49, R_512_2_2=36, R_512_2_3=39,
|
||||
R_512_3_0=44, R_512_3_1= 9, R_512_3_2=54, R_512_3_3=56,
|
||||
R_512_4_0=39, R_512_4_1=30, R_512_4_2=34, R_512_4_3=24,
|
||||
R_512_5_0=13, R_512_5_1=50, R_512_5_2=10, R_512_5_3=17,
|
||||
R_512_6_0=25, R_512_6_1=29, R_512_6_2=39, R_512_6_3=43,
|
||||
R_512_7_0= 8, R_512_7_1=35, R_512_7_2=56, R_512_7_3=22
|
||||
};
|
||||
uint64_t X0,X1,X2,X3,X4,X5,X6,X7;
|
||||
uint64_t w[SKEIN_512_STATE_WORDS];
|
||||
uint64_t kw[SKEIN_512_STATE_WORDS+4];
|
||||
|
||||
ts[0] = ctx->h.T[0];
|
||||
ts[1] = ctx->h.T[1];
|
||||
|
||||
do {
|
||||
|
||||
ts[0] += byteCntAdd;
|
||||
|
||||
ks[0] = ctx->X[0];
|
||||
ks[1] = ctx->X[1];
|
||||
ks[2] = ctx->X[2];
|
||||
ks[3] = ctx->X[3];
|
||||
ks[4] = ctx->X[4];
|
||||
ks[5] = ctx->X[5];
|
||||
ks[6] = ctx->X[6];
|
||||
ks[7] = ctx->X[7];
|
||||
ks[8] = ks[0] ^ ks[1] ^ ks[2] ^ ks[3] ^
|
||||
ks[4] ^ ks[5] ^ ks[6] ^ ks[7] ^ SKEIN_KS_PARITY;
|
||||
|
||||
ts[2] = ts[0] ^ ts[1];
|
||||
|
||||
memcpy(w, blkPtr, SKEIN_512_STATE_WORDS << 3);
|
||||
|
||||
X0 = w[0] + ks[0];
|
||||
X1 = w[1] + ks[1];
|
||||
X2 = w[2] + ks[2];
|
||||
X3 = w[3] + ks[3];
|
||||
X4 = w[4] + ks[4];
|
||||
X5 = w[5] + ks[5] + ts[0];
|
||||
X6 = w[6] + ks[6] + ts[1];
|
||||
X7 = w[7] + ks[7];
|
||||
|
||||
blkPtr += SKEIN_512_BLOCK_BYTES;
|
||||
|
||||
R512_8_rounds( 0);
|
||||
R512_8_rounds( 1);
|
||||
R512_8_rounds( 2);
|
||||
R512_8_rounds( 3);
|
||||
R512_8_rounds( 4);
|
||||
R512_8_rounds( 5);
|
||||
R512_8_rounds( 6);
|
||||
R512_8_rounds( 7);
|
||||
R512_8_rounds( 8);
|
||||
|
||||
ctx->X[0] = X0 ^ w[0];
|
||||
ctx->X[1] = X1 ^ w[1];
|
||||
ctx->X[2] = X2 ^ w[2];
|
||||
ctx->X[3] = X3 ^ w[3];
|
||||
ctx->X[4] = X4 ^ w[4];
|
||||
ctx->X[5] = X5 ^ w[5];
|
||||
ctx->X[6] = X6 ^ w[6];
|
||||
ctx->X[7] = X7 ^ w[7];
|
||||
|
||||
ts[1] &= ~SKEIN_T1_FLAG_FIRST;
|
||||
} while (--blkCnt);
|
||||
|
||||
ctx->h.T[0] = ts[0];
|
||||
ctx->h.T[1] = ts[1];
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_skein_block(Skein_512_Ctxt_t * __restrict__ ctx, const uint8_t * __restrict__ msg, size_t msgByteCnt)
|
||||
{
|
||||
size_t n;
|
||||
|
||||
if (msgByteCnt + ctx->h.bCnt > SKEIN_512_BLOCK_BYTES)
|
||||
{
|
||||
if (ctx->h.bCnt) {
|
||||
|
||||
n = SKEIN_512_BLOCK_BYTES - ctx->h.bCnt;
|
||||
|
||||
if (n) {
|
||||
|
||||
memcpy(&ctx->b[ctx->h.bCnt],msg,n);
|
||||
msgByteCnt -= n;
|
||||
msg += n;
|
||||
ctx->h.bCnt += n;
|
||||
}
|
||||
|
||||
cn_skein_processblock(ctx, ctx->b, 1, SKEIN_512_BLOCK_BYTES);
|
||||
ctx->h.bCnt = 0;
|
||||
}
|
||||
|
||||
if (msgByteCnt > SKEIN_512_BLOCK_BYTES) {
|
||||
|
||||
n = (msgByteCnt - 1) / SKEIN_512_BLOCK_BYTES;
|
||||
cn_skein_processblock(ctx, msg, n, SKEIN_512_BLOCK_BYTES);
|
||||
msgByteCnt -= n * SKEIN_512_BLOCK_BYTES;
|
||||
msg += n * SKEIN_512_BLOCK_BYTES;
|
||||
}
|
||||
}
|
||||
|
||||
if (msgByteCnt) {
|
||||
|
||||
memcpy(&ctx->b[ctx->h.bCnt],msg,msgByteCnt);
|
||||
ctx->h.bCnt += msgByteCnt;
|
||||
}
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_skein_update(skeinHashState * __restrict__ state, const uint8_t * __restrict__ data, DataLength databitlen)
|
||||
{
|
||||
if ((databitlen & 7) == 0) {
|
||||
cn_skein_block(&state->u.ctx_512, data, databitlen >> 3);
|
||||
}
|
||||
else {
|
||||
size_t bCnt = (databitlen >> 3) + 1;
|
||||
uint8_t b,mask;
|
||||
|
||||
mask = (uint8_t) (1u << (7 - (databitlen & 7)));
|
||||
b = (uint8_t) ((data[bCnt-1] & (0-mask)) | mask);
|
||||
|
||||
cn_skein_block(&state->u.ctx_512, data, bCnt - 1);
|
||||
cn_skein_block(&state->u.ctx_512, &b, 1);
|
||||
|
||||
Skein_Set_Bit_Pad_Flag(state->u.h);
|
||||
}
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_skein_final(skeinHashState * __restrict__ state, uint8_t * __restrict__ hashVal)
|
||||
{
|
||||
uint64_t X[SKEIN_512_STATE_WORDS];
|
||||
Skein_512_Ctxt_t *ctx = (Skein_512_Ctxt_t *)&state->u.ctx_512;
|
||||
const int byteCnt = (ctx->h.hashBitLen + 7) >> 3;
|
||||
|
||||
ctx->h.T[1] |= SKEIN_T1_FLAG_FINAL;
|
||||
|
||||
if (ctx->h.bCnt < SKEIN_512_BLOCK_BYTES)
|
||||
{
|
||||
memset(&ctx->b[ctx->h.bCnt], 0, SKEIN_512_BLOCK_BYTES - ctx->h.bCnt);
|
||||
}
|
||||
|
||||
cn_skein_processblock(ctx, ctx->b, 1, ctx->h.bCnt);
|
||||
|
||||
memset(ctx->b, 0, sizeof(ctx->b));
|
||||
memcpy(X, ctx->X, sizeof(X));
|
||||
|
||||
for (int i = 0; i*SKEIN_512_BLOCK_BYTES < byteCnt; i++)
|
||||
{
|
||||
int n = byteCnt - i*SKEIN_512_BLOCK_BYTES;
|
||||
if (n > SKEIN_512_BLOCK_BYTES) n = SKEIN_512_BLOCK_BYTES;
|
||||
((uint64_t *)ctx->b)[0] = (uint64_t)i;
|
||||
Skein_Start_New_Type(ctx, OUT_FINAL);
|
||||
cn_skein_processblock(ctx, ctx->b, 1, sizeof(uint64_t));
|
||||
memcpy(hashVal + (i*SKEIN_512_BLOCK_BYTES), ctx->X, n);
|
||||
memcpy(ctx->X, X, sizeof(X)); // restore the counter mode key for next time
|
||||
}
|
||||
}
|
||||
|
||||
__device__
|
||||
void cn_skein(const uint8_t * __restrict__ data, DataLength len, uint32_t * hashval)
|
||||
{
|
||||
int hashbitlen = 256;
|
||||
DataLength databitlen = len << 3;
|
||||
skeinHashState state;
|
||||
|
||||
state.statebits = 64*SKEIN_512_STATE_WORDS;
|
||||
|
||||
cn_skein_init(&state, hashbitlen);
|
||||
cn_skein_update(&state, data, databitlen);
|
||||
cn_skein_final(&state, (uint8_t*) hashval);
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
// keccak.c
|
||||
// 19-Nov-11 Markku-Juhani O. Saarinen <mjos@iki.fi>
|
||||
// A baseline Keccak (3rd round) implementation.
|
||||
|
||||
#include "c_keccak.h"
|
||||
|
||||
const uint64_t keccakf_rndc[24] =
|
||||
{
|
||||
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
|
||||
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
|
||||
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
|
||||
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
|
||||
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
|
||||
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
|
||||
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
|
||||
0x8000000000008080, 0x0000000080000001, 0x8000000080008008
|
||||
};
|
||||
|
||||
const int keccakf_rotc[24] =
|
||||
{
|
||||
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
|
||||
27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44
|
||||
};
|
||||
|
||||
const int keccakf_piln[24] =
|
||||
{
|
||||
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
|
||||
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
|
||||
};
|
||||
|
||||
// update the state with given number of rounds
|
||||
|
||||
void keccakf(uint64_t st[25], int rounds)
|
||||
{
|
||||
int i, j, round;
|
||||
uint64_t t, bc[5];
|
||||
|
||||
for (round = 0; round < rounds; ++round) {
|
||||
|
||||
// Theta
|
||||
bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20];
|
||||
bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21];
|
||||
bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22];
|
||||
bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23];
|
||||
bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24];
|
||||
|
||||
for (i = 0; i < 5; ++i) {
|
||||
t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1);
|
||||
st[i ] ^= t;
|
||||
st[i + 5] ^= t;
|
||||
st[i + 10] ^= t;
|
||||
st[i + 15] ^= t;
|
||||
st[i + 20] ^= t;
|
||||
}
|
||||
|
||||
// Rho Pi
|
||||
t = st[1];
|
||||
for (i = 0; i < 24; ++i) {
|
||||
bc[0] = st[keccakf_piln[i]];
|
||||
st[keccakf_piln[i]] = ROTL64(t, keccakf_rotc[i]);
|
||||
t = bc[0];
|
||||
}
|
||||
|
||||
// Chi
|
||||
for (j = 0; j < 25; j += 5) {
|
||||
bc[0] = st[j ];
|
||||
bc[1] = st[j + 1];
|
||||
bc[2] = st[j + 2];
|
||||
bc[3] = st[j + 3];
|
||||
bc[4] = st[j + 4];
|
||||
st[j ] ^= (~bc[1]) & bc[2];
|
||||
st[j + 1] ^= (~bc[2]) & bc[3];
|
||||
st[j + 2] ^= (~bc[3]) & bc[4];
|
||||
st[j + 3] ^= (~bc[4]) & bc[0];
|
||||
st[j + 4] ^= (~bc[0]) & bc[1];
|
||||
}
|
||||
|
||||
// Iota
|
||||
st[0] ^= keccakf_rndc[round];
|
||||
}
|
||||
}
|
||||
|
||||
// compute a keccak hash (md) of given byte length from "in"
|
||||
typedef uint64_t state_t[25];
|
||||
|
||||
int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen)
|
||||
{
|
||||
state_t st;
|
||||
uint8_t temp[144];
|
||||
int i, rsiz, rsizw;
|
||||
|
||||
rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen;
|
||||
rsizw = rsiz / 8;
|
||||
|
||||
memset(st, 0, sizeof(st));
|
||||
|
||||
for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) {
|
||||
for (i = 0; i < rsizw; i++)
|
||||
st[i] ^= ((uint64_t *) in)[i];
|
||||
keccakf(st, KECCAK_ROUNDS);
|
||||
}
|
||||
|
||||
// last block and padding
|
||||
memcpy(temp, in, inlen);
|
||||
temp[inlen++] = 1;
|
||||
memset(temp + inlen, 0, rsiz - inlen);
|
||||
temp[rsiz - 1] |= 0x80;
|
||||
|
||||
for (i = 0; i < rsizw; i++)
|
||||
st[i] ^= ((uint64_t *) temp)[i];
|
||||
|
||||
keccakf(st, KECCAK_ROUNDS);
|
||||
|
||||
memcpy(md, st, mdlen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void keccak1600(const uint8_t *in, int inlen, uint8_t *md)
|
||||
{
|
||||
keccak(in, inlen, md, sizeof(state_t));
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
// keccak.h
|
||||
// 19-Nov-11 Markku-Juhani O. Saarinen <mjos@iki.fi>
|
||||
|
||||
#ifndef KECCAK_H
|
||||
#define KECCAK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef KECCAK_ROUNDS
|
||||
#define KECCAK_ROUNDS 24
|
||||
#endif
|
||||
|
||||
#ifndef ROTL64
|
||||
#define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y))))
|
||||
#endif
|
||||
|
||||
#ifndef HASH_SIZE
|
||||
#define HASH_SIZE 32
|
||||
#endif
|
||||
|
||||
#ifndef HASH_DATA_AREA
|
||||
#define HASH_DATA_AREA 136
|
||||
#endif
|
||||
|
||||
// compute a keccak hash (md) of given byte length from "in"
|
||||
int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen);
|
||||
|
||||
// update the state
|
||||
void keccakf(uint64_t st[25], int norounds);
|
||||
|
||||
void keccak1600(const uint8_t *in, int inlen, uint8_t *md);
|
||||
|
||||
#endif
|
||||
@@ -1,351 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cryptolight.h"
|
||||
#define LONG_SHL_IDX 18
|
||||
#define LONG_LOOPS32 0x40000
|
||||
|
||||
#include "cn_aes.cuh"
|
||||
|
||||
#define MUL_SUM_XOR_DST(a,c,dst) { \
|
||||
uint64_t hi, lo = cuda_mul128(((uint64_t *)a)[0], ((uint64_t *)dst)[0], &hi) + ((uint64_t *)c)[1]; \
|
||||
hi += ((uint64_t *)c)[0]; \
|
||||
((uint64_t *)c)[0] = ((uint64_t *)dst)[0] ^ hi; \
|
||||
((uint64_t *)c)[1] = ((uint64_t *)dst)[1] ^ lo; \
|
||||
((uint64_t *)dst)[0] = hi; \
|
||||
((uint64_t *)dst)[1] = lo; }
|
||||
|
||||
__device__ __forceinline__ uint64_t cuda_mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi)
|
||||
{
|
||||
*product_hi = __umul64hi(multiplier, multiplicand);
|
||||
return(multiplier * multiplicand);
|
||||
}
|
||||
|
||||
__global__
|
||||
void cryptolight_core_gpu_phase1(int threads, uint32_t * long_state, uint32_t * ctx_state, uint32_t * ctx_key1)
|
||||
{
|
||||
__shared__ uint32_t __align__(16) sharedMemory[1024];
|
||||
|
||||
cn_aes_gpu_init(sharedMemory);
|
||||
|
||||
const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3;
|
||||
const int sub = (threadIdx.x & 7) << 2;
|
||||
|
||||
if(thread < threads)
|
||||
{
|
||||
const int oft = thread * 50 + sub + 16; // not aligned 16!
|
||||
const int long_oft = (thread << LONG_SHL_IDX) + sub;
|
||||
uint32_t __align__(16) key[40];
|
||||
uint32_t __align__(16) text[4];
|
||||
|
||||
// copy 160 bytes
|
||||
#pragma unroll
|
||||
for (int i = 0; i < 40; i += 4)
|
||||
AS_UINT4(&key[i]) = AS_UINT4(ctx_key1 + thread * 40 + i);
|
||||
|
||||
AS_UINT2(&text[0]) = AS_UINT2(&ctx_state[oft]);
|
||||
AS_UINT2(&text[2]) = AS_UINT2(&ctx_state[oft + 2]);
|
||||
|
||||
__syncthreads();
|
||||
for(int i = 0; i < LONG_LOOPS32; i += 32) {
|
||||
cn_aes_pseudo_round_mut(sharedMemory, text, key);
|
||||
AS_UINT4(&long_state[long_oft + i]) = AS_UINT4(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
__global__
|
||||
void cryptolight_old_gpu_phase2(const int threads, const int bfactor, const int partidx, uint32_t * d_long_state, uint32_t * d_ctx_a, uint32_t * d_ctx_b)
|
||||
{
|
||||
__shared__ uint32_t __align__(16) sharedMemory[1024];
|
||||
|
||||
cn_aes_gpu_init(sharedMemory);
|
||||
|
||||
__syncthreads();
|
||||
|
||||
#if 0 && __CUDA_ARCH__ >= 300
|
||||
|
||||
const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 2;
|
||||
const int sub = threadIdx.x & 3;
|
||||
|
||||
if(thread < threads)
|
||||
{
|
||||
const int batchsize = ITER >> (2 + bfactor);
|
||||
const int start = partidx * batchsize;
|
||||
const int end = start + batchsize;
|
||||
uint32_t * __restrict__ long_state = &d_long_state[thread << LONG_SHL_IDX];
|
||||
uint32_t * __restrict__ ctx_a = d_ctx_a + thread * 4;
|
||||
uint32_t * __restrict__ ctx_b = d_ctx_b + thread * 4;
|
||||
uint32_t a, b, c, x[4];
|
||||
uint32_t t1[4], t2[4], res;
|
||||
uint64_t reshi, reslo;
|
||||
int j;
|
||||
|
||||
a = ctx_a[sub];
|
||||
b = ctx_b[sub];
|
||||
|
||||
#pragma unroll 8
|
||||
for(int i = start; i < end; ++i)
|
||||
{
|
||||
//j = ((uint32_t *)a)[0] & 0xFFFF0;
|
||||
j = (__shfl((int)a, 0, 4) & E2I_MASK1) >> 2;
|
||||
|
||||
//cn_aes_single_round(sharedMemory, &long_state[j], c, a);
|
||||
x[0] = long_state[j + sub];
|
||||
x[1] = __shfl((int)x[0], sub + 1, 4);
|
||||
x[2] = __shfl((int)x[0], sub + 2, 4);
|
||||
x[3] = __shfl((int)x[0], sub + 3, 4);
|
||||
c = a ^
|
||||
t_fn0(x[0] & 0xff) ^
|
||||
t_fn1((x[1] >> 8) & 0xff) ^
|
||||
t_fn2((x[2] >> 16) & 0xff) ^
|
||||
t_fn3((x[3] >> 24) & 0xff);
|
||||
|
||||
//XOR_BLOCKS_DST(c, b, &long_state[j]);
|
||||
long_state[j + sub] = c ^ b;
|
||||
|
||||
//MUL_SUM_XOR_DST(c, a, &long_state[((uint32_t *)c)[0] & 0xFFFF0]);
|
||||
j = (__shfl((int)c, 0, 4) & E2I_MASK1) >> 2;
|
||||
#pragma unroll
|
||||
for(int k = 0; k < 2; k++)
|
||||
t1[k] = __shfl((int)c, k, 4);
|
||||
#pragma unroll
|
||||
for(int k = 0; k < 4; k++)
|
||||
t2[k] = __shfl((int)a, k, 4);
|
||||
asm(
|
||||
"mad.lo.u64 %0, %2, %3, %4;\n\t"
|
||||
"mad.hi.u64 %1, %2, %3, %5;\n\t"
|
||||
: "=l"(reslo), "=l"(reshi)
|
||||
: "l"(((uint64_t *)t1)[0]), "l"(((uint64_t *)long_state)[j >> 1]), "l"(((uint64_t *)t2)[1]), "l"(((uint64_t *)t2)[0]));
|
||||
res = (sub & 2 ? reslo : reshi) >> (sub & 1 ? 32 : 0);
|
||||
a = long_state[j + sub] ^ res;
|
||||
long_state[j + sub] = res;
|
||||
|
||||
//j = ((uint32_t *)a)[0] & 0xFFFF0;
|
||||
j = (__shfl((int)a, 0, 4) & E2I_MASK1) >> 2;
|
||||
|
||||
//cn_aes_single_round(sharedMemory, &long_state[j], b, a);
|
||||
x[0] = long_state[j + sub];
|
||||
x[1] = __shfl((int)x[0], sub + 1, 4);
|
||||
x[2] = __shfl((int)x[0], sub + 2, 4);
|
||||
x[3] = __shfl((int)x[0], sub + 3, 4);
|
||||
b = a ^
|
||||
t_fn0(x[0] & 0xff) ^
|
||||
t_fn1((x[1] >> 8) & 0xff) ^
|
||||
t_fn2((x[2] >> 16) & 0xff) ^
|
||||
t_fn3((x[3] >> 24) & 0xff);
|
||||
|
||||
//XOR_BLOCKS_DST(b, c, &long_state[j]);
|
||||
long_state[j + sub] = c ^ b;
|
||||
|
||||
//MUL_SUM_XOR_DST(b, a, &long_state[((uint32_t *)b)[0] & 0xFFFF0]);
|
||||
j = (__shfl((int)b, 0, 4) & E2I_MASK1) >> 2;
|
||||
|
||||
#pragma unroll
|
||||
for(int k = 0; k < 2; k++)
|
||||
t1[k] = __shfl((int)b, k, 4);
|
||||
|
||||
#pragma unroll
|
||||
for(int k = 0; k < 4; k++)
|
||||
t2[k] = __shfl((int)a, k, 4);
|
||||
asm(
|
||||
"mad.lo.u64 %0, %2, %3, %4;\n\t"
|
||||
"mad.hi.u64 %1, %2, %3, %5;\n\t"
|
||||
: "=l"(reslo), "=l"(reshi)
|
||||
: "l"(((uint64_t *)t1)[0]), "l"(((uint64_t *)long_state)[j >> 1]), "l"(((uint64_t *)t2)[1]), "l"(((uint64_t *)t2)[0]));
|
||||
res = (sub & 2 ? reslo : reshi) >> (sub & 1 ? 32 : 0);
|
||||
a = long_state[j + sub] ^ res;
|
||||
long_state[j + sub] = res;
|
||||
}
|
||||
|
||||
if(bfactor > 0)
|
||||
{
|
||||
ctx_a[sub] = a;
|
||||
ctx_b[sub] = b;
|
||||
}
|
||||
}
|
||||
|
||||
#else // __CUDA_ARCH__ < 300
|
||||
|
||||
const int thread = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
|
||||
if (thread < threads)
|
||||
{
|
||||
const int batchsize = ITER >> (2 + bfactor);
|
||||
const int start = partidx * batchsize;
|
||||
const int end = start + batchsize;
|
||||
const int longptr = thread << LONG_SHL_IDX;
|
||||
uint32_t * long_state = &d_long_state[longptr];
|
||||
|
||||
uint64_t * ctx_a = (uint64_t*)(&d_ctx_a[thread * 4]);
|
||||
uint64_t * ctx_b = (uint64_t*)(&d_ctx_b[thread * 4]);
|
||||
uint4 A = AS_UINT4(ctx_a);
|
||||
uint4 B = AS_UINT4(ctx_b);
|
||||
uint32_t* a = (uint32_t*)&A;
|
||||
uint32_t* b = (uint32_t*)&B;
|
||||
|
||||
for (int i = start; i < end; i++) // end = 262144
|
||||
{
|
||||
uint32_t c[4];
|
||||
uint32_t j = (a[0] >> 2) & E2I_MASK2;
|
||||
cn_aes_single_round(sharedMemory, &long_state[j], c, a);
|
||||
XOR_BLOCKS_DST(c, b, &long_state[j]);
|
||||
MUL_SUM_XOR_DST(c, a, &long_state[(c[0] >> 2) & E2I_MASK2]);
|
||||
|
||||
j = (a[0] >> 2) & E2I_MASK2;
|
||||
cn_aes_single_round(sharedMemory, &long_state[j], b, a);
|
||||
XOR_BLOCKS_DST(b, c, &long_state[j]);
|
||||
MUL_SUM_XOR_DST(b, a, &long_state[(b[0] >> 2) & E2I_MASK2]);
|
||||
}
|
||||
|
||||
if (bfactor > 0) {
|
||||
AS_UINT4(ctx_a) = A;
|
||||
AS_UINT4(ctx_b) = B;
|
||||
}
|
||||
}
|
||||
#endif // __CUDA_ARCH__ >= 300
|
||||
}
|
||||
|
||||
__device__ __forceinline__ void store_variant1(uint32_t* long_state)
|
||||
{
|
||||
uint4* Z = (uint4*) long_state;
|
||||
const uint32_t tmp = (Z->z >> 24); // __byte_perm(src, 0, 0x7773);
|
||||
const uint32_t index = (((tmp >> 3) & 6u) | (tmp & 1u)) << 1;
|
||||
Z->z = (Z->z & 0x00ffffffu) | ((tmp ^ ((0x75310u >> index) & 0x30u)) << 24);
|
||||
}
|
||||
|
||||
#define MUL_SUM_XOR_DST_1(a,c,dst,tweak) { \
|
||||
uint64_t hi, lo = cuda_mul128(((uint64_t *)a)[0], ((uint64_t *)dst)[0], &hi) + ((uint64_t *)c)[1]; \
|
||||
hi += ((uint64_t *)c)[0]; \
|
||||
((uint64_t *)c)[0] = ((uint64_t *)dst)[0] ^ hi; \
|
||||
((uint64_t *)c)[1] = ((uint64_t *)dst)[1] ^ lo; \
|
||||
((uint64_t *)dst)[0] = hi; \
|
||||
((uint64_t *)dst)[1] = lo ^ tweak; }
|
||||
|
||||
__global__
|
||||
void cryptolight_gpu_phase2(const uint32_t threads, const uint16_t bfactor, const uint32_t partidx,
|
||||
uint32_t * __restrict__ d_long_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b,
|
||||
uint64_t * __restrict__ d_tweak)
|
||||
{
|
||||
__shared__ __align__(16) uint32_t sharedMemory[1024];
|
||||
cn_aes_gpu_init(sharedMemory);
|
||||
__syncthreads();
|
||||
|
||||
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
if (thread < threads)
|
||||
{
|
||||
const uint32_t batchsize = ITER >> (2 + bfactor);
|
||||
const uint32_t start = partidx * batchsize;
|
||||
const uint32_t end = start + batchsize;
|
||||
const uint32_t longptr = thread << LONG_SHL_IDX;
|
||||
uint32_t * long_state = &d_long_state[longptr];
|
||||
uint64_t tweak = d_tweak[thread];
|
||||
|
||||
void * ctx_a = (void*)(&d_ctx_a[thread << 2]);
|
||||
void * ctx_b = (void*)(&d_ctx_b[thread << 2]);
|
||||
uint4 A = AS_UINT4(ctx_a); // ld.global.u32.v4
|
||||
uint4 B = AS_UINT4(ctx_b);
|
||||
uint32_t* a = (uint32_t*)&A;
|
||||
uint32_t* b = (uint32_t*)&B;
|
||||
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
uint32_t c[4];
|
||||
uint32_t j = (A.x >> 2) & E2I_MASK2;
|
||||
cn_aes_single_round(sharedMemory, &long_state[j], c, a);
|
||||
XOR_BLOCKS_DST(c, b, &long_state[j]);
|
||||
store_variant1(&long_state[j]);
|
||||
MUL_SUM_XOR_DST_1(c, a, &long_state[(c[0] >> 2) & E2I_MASK2], tweak);
|
||||
|
||||
j = (A.x >> 2) & E2I_MASK2;
|
||||
cn_aes_single_round(sharedMemory, &long_state[j], b, a);
|
||||
XOR_BLOCKS_DST(b, c, &long_state[j]);
|
||||
store_variant1(&long_state[j]);
|
||||
MUL_SUM_XOR_DST_1(b, a, &long_state[(b[0] >> 2) & E2I_MASK2], tweak);
|
||||
}
|
||||
if (bfactor) {
|
||||
AS_UINT4(ctx_a) = A;
|
||||
AS_UINT4(ctx_b) = B;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__global__
|
||||
void cryptolight_core_gpu_phase3(int threads, const uint32_t * long_state, uint32_t * ctx_state, uint32_t * ctx_key2)
|
||||
{
|
||||
__shared__ uint32_t __align__(16) sharedMemory[1024];
|
||||
|
||||
cn_aes_gpu_init(sharedMemory);
|
||||
|
||||
const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3;
|
||||
const int sub = (threadIdx.x & 7) << 2;
|
||||
|
||||
if(thread < threads)
|
||||
{
|
||||
const int long_oft = (thread << LONG_SHL_IDX) + sub;
|
||||
const int oft = thread * 50 + sub + 16;
|
||||
uint32_t __align__(16) key[40];
|
||||
uint32_t __align__(16) text[4];
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 0; i < 40; i += 4)
|
||||
AS_UINT4(&key[i]) = AS_UINT4(ctx_key2 + thread * 40 + i);
|
||||
|
||||
AS_UINT2(&text[0]) = AS_UINT2(&ctx_state[oft + 0]);
|
||||
AS_UINT2(&text[2]) = AS_UINT2(&ctx_state[oft + 2]);
|
||||
|
||||
__syncthreads();
|
||||
for(int i = 0; i < LONG_LOOPS32; i += 32)
|
||||
{
|
||||
#pragma unroll
|
||||
for(int j = 0; j < 4; j++)
|
||||
text[j] ^= long_state[long_oft + i + j];
|
||||
|
||||
cn_aes_pseudo_round_mut(sharedMemory, text, key);
|
||||
}
|
||||
|
||||
AS_UINT2(&ctx_state[oft + 0]) = AS_UINT2(&text[0]);
|
||||
AS_UINT2(&ctx_state[oft + 2]) = AS_UINT2(&text[2]);
|
||||
}
|
||||
}
|
||||
|
||||
extern int device_bfactor[MAX_GPUS];
|
||||
|
||||
__host__
|
||||
void cryptolight_core_hash(int thr_id, int blocks, int threads, uint32_t *d_long_state, uint32_t *d_ctx_state,
|
||||
uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak)
|
||||
{
|
||||
dim3 grid(blocks);
|
||||
dim3 block(threads);
|
||||
dim3 block4(threads << 2);
|
||||
dim3 block8(threads << 3);
|
||||
|
||||
const int bfactor = device_bfactor[thr_id];
|
||||
const int bsleep = bfactor ? 100 : 0;
|
||||
|
||||
int i, partcount = 1 << bfactor;
|
||||
int dev_id = device_map[thr_id];
|
||||
|
||||
cryptolight_core_gpu_phase1 <<<grid, block8 >>>(blocks*threads, d_long_state, d_ctx_state, d_ctx_key1);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
if(partcount > 1) usleep(bsleep);
|
||||
|
||||
for(i = 0; i < partcount; i++)
|
||||
{
|
||||
dim3 b = device_sm[dev_id] >= 300 ? block4 : block;
|
||||
if (variant == 0)
|
||||
cryptolight_old_gpu_phase2 <<<grid, b>>> (blocks*threads, bfactor, i, d_long_state, d_ctx_a, d_ctx_b);
|
||||
else
|
||||
cryptolight_gpu_phase2 <<<grid, b>>> (blocks*threads, bfactor, i, d_long_state, d_ctx_a, d_ctx_b, d_ctx_tweak);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
if(partcount > 1) usleep(bsleep);
|
||||
}
|
||||
|
||||
cryptolight_core_gpu_phase3 <<<grid, block8 >>>(blocks*threads, d_long_state, d_ctx_state, d_ctx_key2);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
#include <miner.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "oaes_lib.h"
|
||||
#include "cryptolight.h"
|
||||
|
||||
extern "C" {
|
||||
#include <sph/sph_blake.h>
|
||||
#include <sph/sph_groestl.h>
|
||||
#include <sph/sph_jh.h>
|
||||
#include <sph/sph_skein.h>
|
||||
#include "cpu/c_keccak.h"
|
||||
}
|
||||
|
||||
struct cryptonight_ctx {
|
||||
uint8_t long_state[MEMORY];
|
||||
union cn_slow_hash_state state;
|
||||
uint8_t text[INIT_SIZE_BYTE];
|
||||
uint8_t a[AES_BLOCK_SIZE];
|
||||
uint8_t b[AES_BLOCK_SIZE];
|
||||
uint8_t c[AES_BLOCK_SIZE];
|
||||
oaes_ctx* aes_ctx;
|
||||
};
|
||||
|
||||
static void do_blake_hash(const void* input, int len, void* output)
|
||||
{
|
||||
uchar hash[32];
|
||||
sph_blake256_context ctx;
|
||||
sph_blake256_set_rounds(14);
|
||||
sph_blake256_init(&ctx);
|
||||
sph_blake256(&ctx, input, len);
|
||||
sph_blake256_close(&ctx, hash);
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
static void do_groestl_hash(const void* input, int len, void* output)
|
||||
{
|
||||
uchar hash[32];
|
||||
sph_groestl256_context ctx;
|
||||
sph_groestl256_init(&ctx);
|
||||
sph_groestl256(&ctx, input, len);
|
||||
sph_groestl256_close(&ctx, hash);
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
static void do_jh_hash(const void* input, int len, void* output)
|
||||
{
|
||||
uchar hash[64];
|
||||
sph_jh256_context ctx;
|
||||
sph_jh256_init(&ctx);
|
||||
sph_jh256(&ctx, input, len);
|
||||
sph_jh256_close(&ctx, hash);
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
static void do_skein_hash(const void* input, int len, void* output)
|
||||
{
|
||||
uchar hash[32];
|
||||
sph_skein256_context ctx;
|
||||
sph_skein256_init(&ctx);
|
||||
sph_skein256(&ctx, input, len);
|
||||
sph_skein256_close(&ctx, hash);
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
// todo: use sph if possible
|
||||
static void keccak_hash_permutation(union hash_state *state) {
|
||||
keccakf((uint64_t*)state, 24);
|
||||
}
|
||||
|
||||
static void keccak_hash_process(union hash_state *state, const uint8_t *buf, int count) {
|
||||
keccak1600(buf, (int)count, (uint8_t*)state);
|
||||
}
|
||||
|
||||
extern "C" int fast_aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
|
||||
extern "C" int aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
|
||||
extern "C" int aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey);
|
||||
extern "C" int fast_aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey);
|
||||
|
||||
static void (* const extra_hashes[4])(const void*, int, void *) = {
|
||||
do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash
|
||||
};
|
||||
|
||||
static uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi)
|
||||
{
|
||||
// multiplier = ab = a * 2^32 + b
|
||||
// multiplicand = cd = c * 2^32 + d
|
||||
// ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d
|
||||
uint64_t a = hi_dword(multiplier);
|
||||
uint64_t b = lo_dword(multiplier);
|
||||
uint64_t c = hi_dword(multiplicand);
|
||||
uint64_t d = lo_dword(multiplicand);
|
||||
|
||||
uint64_t ac = a * c;
|
||||
uint64_t ad = a * d;
|
||||
uint64_t bc = b * c;
|
||||
uint64_t bd = b * d;
|
||||
|
||||
uint64_t adbc = ad + bc;
|
||||
uint64_t adbc_carry = adbc < ad ? 1 : 0;
|
||||
|
||||
// multiplier * multiplicand = product_hi * 2^64 + product_lo
|
||||
uint64_t product_lo = bd + (adbc << 32);
|
||||
uint64_t product_lo_carry = product_lo < bd ? 1 : 0;
|
||||
*product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry;
|
||||
|
||||
return product_lo;
|
||||
}
|
||||
|
||||
static size_t e2i(const uint8_t* a) {
|
||||
//const uint32_t mask = (MEMORY / AES_BLOCK_SIZE - 1);
|
||||
//return (*((uint64_t*) a) / AES_BLOCK_SIZE) & mask;
|
||||
return *((uint64_t*) a) & 0xFFFF0; /* mask * AES_BLOCK_SIZE */
|
||||
}
|
||||
|
||||
static void mul(const uint8_t* a, const uint8_t* b, uint8_t* res) {
|
||||
((uint64_t*) res)[1] = mul128(((uint64_t*) a)[0], ((uint64_t*) b)[0], (uint64_t*) res);
|
||||
}
|
||||
|
||||
static void sum_half_blocks(uint8_t* a, const uint8_t* b) {
|
||||
((uint64_t*) a)[0] += ((uint64_t*) b)[0];
|
||||
((uint64_t*) a)[1] += ((uint64_t*) b)[1];
|
||||
}
|
||||
|
||||
static void sum_half_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) {
|
||||
((uint64_t*) dst)[0] = ((uint64_t*) a)[0] + ((uint64_t*) b)[0];
|
||||
((uint64_t*) dst)[1] = ((uint64_t*) a)[1] + ((uint64_t*) b)[1];
|
||||
}
|
||||
|
||||
static void mul_sum_dst(const uint8_t* a, const uint8_t* b, const uint8_t* c, uint8_t* dst) {
|
||||
((uint64_t*) dst)[1] = mul128(((uint64_t*) a)[0], ((uint64_t*) b)[0], (uint64_t*) dst) + ((uint64_t*) c)[1];
|
||||
((uint64_t*) dst)[0] += ((uint64_t*) c)[0];
|
||||
}
|
||||
|
||||
static void mul_sum_xor_dst(const uint8_t* a, uint8_t* c, uint8_t* dst, const int variant, const uint64_t tweak) {
|
||||
uint64_t hi, lo = mul128(((uint64_t*) a)[0], ((uint64_t*) dst)[0], &hi) + ((uint64_t*) c)[1];
|
||||
hi += ((uint64_t*) c)[0];
|
||||
((uint64_t*) c)[0] = ((uint64_t*) dst)[0] ^ hi;
|
||||
((uint64_t*) c)[1] = ((uint64_t*) dst)[1] ^ lo;
|
||||
((uint64_t*) dst)[0] = hi;
|
||||
((uint64_t*) dst)[1] = variant ? lo ^ tweak : lo;
|
||||
}
|
||||
|
||||
static void copy_block(uint8_t* dst, const uint8_t* src) {
|
||||
((uint64_t*) dst)[0] = ((uint64_t*) src)[0];
|
||||
((uint64_t*) dst)[1] = ((uint64_t*) src)[1];
|
||||
}
|
||||
|
||||
static void xor_blocks(uint8_t* a, const uint8_t* b) {
|
||||
((uint64_t*) a)[0] ^= ((uint64_t*) b)[0];
|
||||
((uint64_t*) a)[1] ^= ((uint64_t*) b)[1];
|
||||
}
|
||||
|
||||
static void xor_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) {
|
||||
((uint64_t*) dst)[0] = ((uint64_t*) a)[0] ^ ((uint64_t*) b)[0];
|
||||
((uint64_t*) dst)[1] = ((uint64_t*) a)[1] ^ ((uint64_t*) b)[1];
|
||||
}
|
||||
|
||||
static void cryptolight_store_variant(void* state, int variant) {
|
||||
if (variant == 1) {
|
||||
// use variant 1 like monero since june 2018
|
||||
const uint8_t tmp = ((const uint8_t*)(state))[11];
|
||||
const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1;
|
||||
((uint8_t*)(state))[11] = tmp ^ ((0x75310 >> index) & 0x30);
|
||||
}
|
||||
}
|
||||
|
||||
static void cryptolight_hash_ctx(void* output, const void* input, const int len, struct cryptonight_ctx* ctx, const int variant)
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
keccak_hash_process(&ctx->state.hs, (const uint8_t*) input, len);
|
||||
ctx->aes_ctx = (oaes_ctx*) oaes_alloc();
|
||||
memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
|
||||
|
||||
const uint64_t tweak = variant ? *((uint64_t*) (((uint8_t*)input) + 35)) ^ ctx->state.hs.w[24] : 0;
|
||||
|
||||
oaes_key_import_data(ctx->aes_ctx, ctx->state.hs.b, AES_KEY_SIZE);
|
||||
for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) {
|
||||
#undef RND
|
||||
#define RND(p) aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * p], ctx->aes_ctx->key->exp_data);
|
||||
RND(0);
|
||||
RND(1);
|
||||
RND(2);
|
||||
RND(3);
|
||||
RND(4);
|
||||
RND(5);
|
||||
RND(6);
|
||||
RND(7);
|
||||
memcpy(&ctx->long_state[i], ctx->text, INIT_SIZE_BYTE);
|
||||
}
|
||||
|
||||
xor_blocks_dst(&ctx->state.k[0], &ctx->state.k[32], ctx->a);
|
||||
xor_blocks_dst(&ctx->state.k[16], &ctx->state.k[48], ctx->b);
|
||||
|
||||
for (i = 0; likely(i < ITER / 4); ++i) {
|
||||
j = e2i(ctx->a);
|
||||
aesb_single_round(&ctx->long_state[j], ctx->c, ctx->a);
|
||||
xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]);
|
||||
cryptolight_store_variant(&ctx->long_state[j], variant);
|
||||
mul_sum_xor_dst(ctx->c, ctx->a, &ctx->long_state[e2i(ctx->c)], variant, tweak);
|
||||
|
||||
j = e2i(ctx->a);
|
||||
aesb_single_round(&ctx->long_state[j], ctx->b, ctx->a);
|
||||
xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]);
|
||||
cryptolight_store_variant(&ctx->long_state[j], variant);
|
||||
mul_sum_xor_dst(ctx->b, ctx->a, &ctx->long_state[e2i(ctx->b)], variant, tweak);
|
||||
}
|
||||
|
||||
memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
|
||||
oaes_key_import_data(ctx->aes_ctx, &ctx->state.hs.b[32], AES_KEY_SIZE);
|
||||
for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) {
|
||||
#undef RND
|
||||
#define RND(p) xor_blocks(&ctx->text[p * AES_BLOCK_SIZE], &ctx->long_state[i + p * AES_BLOCK_SIZE]); \
|
||||
aesb_pseudo_round_mut(&ctx->text[p * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data);
|
||||
RND(0);
|
||||
RND(1);
|
||||
RND(2);
|
||||
RND(3);
|
||||
RND(4);
|
||||
RND(5);
|
||||
RND(6);
|
||||
RND(7);
|
||||
}
|
||||
memcpy(ctx->state.init, ctx->text, INIT_SIZE_BYTE);
|
||||
keccak_hash_permutation(&ctx->state.hs);
|
||||
|
||||
int extra_algo = ctx->state.hs.b[0] & 3;
|
||||
extra_hashes[extra_algo](&ctx->state, 200, output);
|
||||
if (opt_debug) applog(LOG_DEBUG, "extra algo=%d", extra_algo);
|
||||
|
||||
oaes_free((OAES_CTX **) &ctx->aes_ctx);
|
||||
}
|
||||
|
||||
void cryptolight_hash_variant(void* output, const void* input, int len, int variant)
|
||||
{
|
||||
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));
|
||||
cryptolight_hash_ctx(output, input, len, ctx, variant);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
void cryptolight_hash(void* output, const void* input)
|
||||
{
|
||||
cryptolight_hash_variant(output, input, 76, 1);
|
||||
}
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
|
||||
#include "cryptolight.h"
|
||||
|
||||
extern char *device_config[MAX_GPUS]; // -l 32x16
|
||||
|
||||
static __thread uint32_t cn_blocks = 32;
|
||||
static __thread uint32_t cn_threads = 16;
|
||||
|
||||
static uint32_t *d_long_state[MAX_GPUS];
|
||||
static uint32_t *d_ctx_state[MAX_GPUS];
|
||||
static uint32_t *d_ctx_key1[MAX_GPUS];
|
||||
static uint32_t *d_ctx_key2[MAX_GPUS];
|
||||
static uint32_t *d_ctx_text[MAX_GPUS];
|
||||
static uint64_t *d_ctx_tweak[MAX_GPUS];
|
||||
static uint32_t *d_ctx_a[MAX_GPUS];
|
||||
static uint32_t *d_ctx_b[MAX_GPUS];
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_cryptolight(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, int variant)
|
||||
{
|
||||
int res = 0;
|
||||
uint32_t throughput = 0;
|
||||
|
||||
uint32_t *ptarget = work->target;
|
||||
uint8_t *pdata = (uint8_t*) work->data;
|
||||
uint32_t *nonceptr = (uint32_t*) (&pdata[39]);
|
||||
const uint32_t first_nonce = *nonceptr;
|
||||
uint32_t nonce = first_nonce;
|
||||
int dev_id = device_map[thr_id];
|
||||
|
||||
if(opt_benchmark) {
|
||||
ptarget[7] = 0x00ff;
|
||||
}
|
||||
|
||||
if(!init[thr_id])
|
||||
{
|
||||
if (!device_config[thr_id] && strcmp(device_name[dev_id], "TITAN V") == 0) {
|
||||
device_config[thr_id] = strdup("80x32");
|
||||
}
|
||||
|
||||
if (device_config[thr_id]) {
|
||||
sscanf(device_config[thr_id], "%ux%u", &cn_blocks, &cn_threads);
|
||||
throughput = cuda_default_throughput(thr_id, cn_blocks*cn_threads);
|
||||
gpulog(LOG_INFO, thr_id, "Using %u x %u kernel launch config, %u threads",
|
||||
cn_blocks, cn_threads, throughput);
|
||||
} else {
|
||||
throughput = cuda_default_throughput(thr_id, cn_blocks*cn_threads);
|
||||
if (throughput != cn_blocks*cn_threads && cn_threads) {
|
||||
cn_blocks = throughput / cn_threads;
|
||||
throughput = cn_threads * cn_blocks;
|
||||
}
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u threads (%ux%u)",
|
||||
throughput2intensity(throughput), throughput, cn_blocks, cn_threads);
|
||||
}
|
||||
|
||||
if(sizeof(size_t) == 4 && throughput > UINT32_MAX / MEMORY) {
|
||||
gpulog(LOG_ERR, thr_id, "THE 32bit VERSION CAN'T ALLOCATE MORE THAN 4GB OF MEMORY!");
|
||||
gpulog(LOG_ERR, thr_id, "PLEASE REDUCE THE NUMBER OF THREADS OR BLOCKS");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
if (opt_cudaschedule == -1 && gpu_threads == 1) {
|
||||
cudaDeviceReset();
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
|
||||
const size_t alloc = MEMORY * throughput;
|
||||
cryptonight_extra_init(thr_id);
|
||||
|
||||
cudaMalloc(&d_long_state[thr_id], alloc);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_state[thr_id], 25 * sizeof(uint64_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_key1[thr_id], 40 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_key2[thr_id], 40 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_text[thr_id], 32 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_a[thr_id], 4 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_b[thr_id], 4 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_tweak[thr_id], sizeof(uint64_t) * throughput);
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
throughput = cn_blocks*cn_threads;
|
||||
|
||||
do
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t resNonces[2] = { UINT32_MAX, UINT32_MAX };
|
||||
|
||||
cryptonight_extra_setData(thr_id, pdata, ptarget);
|
||||
cryptonight_extra_prepare(thr_id, throughput, nonce, d_ctx_state[thr_id], d_ctx_a[thr_id], d_ctx_b[thr_id], d_ctx_key1[thr_id], d_ctx_key2[thr_id], variant, d_ctx_tweak[thr_id]);
|
||||
cryptolight_core_hash(thr_id, cn_blocks, cn_threads, d_long_state[thr_id], d_ctx_state[thr_id], d_ctx_a[thr_id], d_ctx_b[thr_id], d_ctx_key1[thr_id], d_ctx_key2[thr_id], variant, d_ctx_tweak[thr_id]);
|
||||
cryptonight_extra_final(thr_id, throughput, nonce, resNonces, d_ctx_state[thr_id]);
|
||||
|
||||
*hashes_done = nonce - first_nonce + throughput;
|
||||
|
||||
if(resNonces[0] != UINT32_MAX)
|
||||
{
|
||||
uint32_t vhash[8];
|
||||
uint32_t tempdata[19];
|
||||
uint32_t *tempnonceptr = (uint32_t*)(((char*)tempdata) + 39);
|
||||
memcpy(tempdata, pdata, 76);
|
||||
*tempnonceptr = resNonces[0];
|
||||
cryptolight_hash_variant(vhash, tempdata, 76, variant);
|
||||
if(vhash[7] <= Htarg && fulltest(vhash, ptarget))
|
||||
{
|
||||
res = 1;
|
||||
work->nonces[0] = resNonces[0];
|
||||
work_set_target_ratio(work, vhash);
|
||||
// second nonce
|
||||
if(resNonces[1] != UINT32_MAX)
|
||||
{
|
||||
*tempnonceptr = resNonces[1];
|
||||
cryptolight_hash_variant(vhash, tempdata, 76, variant);
|
||||
if(vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
|
||||
res++;
|
||||
work->nonces[1] = resNonces[1];
|
||||
} else if (vhash[7] > Htarg) {
|
||||
gpu_increment_reject(thr_id);
|
||||
}
|
||||
}
|
||||
goto done;
|
||||
} else if (vhash[7] > Htarg) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for nonce %08x does not validate on CPU!", resNonces[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if ((uint64_t) throughput + nonce >= max_nonce - 127) {
|
||||
nonce = max_nonce;
|
||||
break;
|
||||
}
|
||||
|
||||
nonce += throughput;
|
||||
gpulog(LOG_DEBUG, thr_id, "nonce %08x", nonce);
|
||||
|
||||
} while (!work_restart[thr_id].restart && max_nonce > (uint64_t)throughput + nonce);
|
||||
|
||||
done:
|
||||
gpulog(LOG_DEBUG, thr_id, "nonce %08x exit", nonce);
|
||||
work->valid_nonces = res;
|
||||
*nonceptr = nonce;
|
||||
return res;
|
||||
}
|
||||
|
||||
void free_cryptolight(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaFree(d_long_state[thr_id]);
|
||||
cudaFree(d_ctx_state[thr_id]);
|
||||
cudaFree(d_ctx_key1[thr_id]);
|
||||
cudaFree(d_ctx_key2[thr_id]);
|
||||
cudaFree(d_ctx_text[thr_id]);
|
||||
cudaFree(d_ctx_tweak[thr_id]);
|
||||
cudaFree(d_ctx_a[thr_id]);
|
||||
cudaFree(d_ctx_b[thr_id]);
|
||||
|
||||
cryptonight_extra_free(thr_id);
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
|
||||
init[thr_id] = false;
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
#pragma once
|
||||
#include <cuda_runtime.h>
|
||||
#include <miner.h>
|
||||
|
||||
#ifdef __INTELLISENSE__
|
||||
/* avoid red underlining */
|
||||
#define __CUDA_ARCH__ 520
|
||||
struct uint3 {
|
||||
unsigned int x, y, z;
|
||||
};
|
||||
struct uint3 threadIdx;
|
||||
struct uint3 blockIdx;
|
||||
struct uint3 blockDim;
|
||||
#define atomicExch(p,y) (*p) = y
|
||||
#define __funnelshift_r(a,b,c) 1
|
||||
#define __syncthreads()
|
||||
#define __threadfence_block()
|
||||
#define asm(x)
|
||||
#define __shfl(a,b,c) 1
|
||||
#define __umul64hi(a,b) a*b
|
||||
#endif
|
||||
|
||||
#define MEMORY (1UL << 20) /* 1 MiB - 1048576 */
|
||||
#define ITER (1UL << 19) /* 512k */
|
||||
#define E2I_MASK1 0xFFFF0 /* MEMORY / AES_BLOCK_SIZE - 1 = 0xFFFF */
|
||||
#define E2I_MASK2 0x3FFFC /* 0xFFFF0 >> 2 */
|
||||
|
||||
#define AES_BLOCK_SIZE 16
|
||||
#define AES_KEY_SIZE 32
|
||||
#define INIT_SIZE_BLK 8
|
||||
#define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) // 128 B
|
||||
|
||||
#define AES_RKEY_LEN 4
|
||||
#define AES_COL_LEN 4
|
||||
#define AES_ROUND_BASE 7
|
||||
|
||||
#ifndef HASH_SIZE
|
||||
#define HASH_SIZE 32
|
||||
#endif
|
||||
|
||||
#ifndef HASH_DATA_AREA
|
||||
#define HASH_DATA_AREA 136
|
||||
#endif
|
||||
|
||||
#define hi_dword(x) (x >> 32)
|
||||
#define lo_dword(x) (x & 0xFFFFFFFF)
|
||||
|
||||
#define C32(x) ((uint32_t)(x ## U))
|
||||
#define T32(x) ((x) & C32(0xFFFFFFFF))
|
||||
|
||||
#ifndef ROTL64
|
||||
#if __CUDA_ARCH__ >= 350
|
||||
__forceinline__ __device__ uint64_t cuda_ROTL64(const uint64_t value, const int offset) {
|
||||
uint2 result;
|
||||
if(offset >= 32) {
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
|
||||
} else {
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
|
||||
}
|
||||
return __double_as_longlong(__hiloint2double(result.y, result.x));
|
||||
}
|
||||
#define ROTL64(x, n) (cuda_ROTL64(x, n))
|
||||
#else
|
||||
#define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ROTL32
|
||||
#if __CUDA_ARCH__ < 350
|
||||
#define ROTL32(x, n) T32(((x) << (n)) | ((x) >> (32 - (n))))
|
||||
#else
|
||||
#define ROTL32(x, n) __funnelshift_l( (x), (x), (n) )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ROTR32
|
||||
#if __CUDA_ARCH__ < 350
|
||||
#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
|
||||
#else
|
||||
#define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MEMSET8(dst,what,cnt) { \
|
||||
int i_memset8; \
|
||||
uint64_t *out_memset8 = (uint64_t *)(dst); \
|
||||
for( i_memset8 = 0; i_memset8 < cnt; i_memset8++ ) \
|
||||
out_memset8[i_memset8] = (what); }
|
||||
|
||||
#define MEMSET4(dst,what,cnt) { \
|
||||
int i_memset4; \
|
||||
uint32_t *out_memset4 = (uint32_t *)(dst); \
|
||||
for( i_memset4 = 0; i_memset4 < cnt; i_memset4++ ) \
|
||||
out_memset4[i_memset4] = (what); }
|
||||
|
||||
#define MEMCPY8(dst,src,cnt) { \
|
||||
int i_memcpy8; \
|
||||
uint64_t *in_memcpy8 = (uint64_t *)(src); \
|
||||
uint64_t *out_memcpy8 = (uint64_t *)(dst); \
|
||||
for( i_memcpy8 = 0; i_memcpy8 < cnt; i_memcpy8++ ) \
|
||||
out_memcpy8[i_memcpy8] = in_memcpy8[i_memcpy8]; }
|
||||
|
||||
#define MEMCPY4(dst,src,cnt) { \
|
||||
int i_memcpy4; \
|
||||
uint32_t *in_memcpy4 = (uint32_t *)(src); \
|
||||
uint32_t *out_memcpy4 = (uint32_t *)(dst); \
|
||||
for( i_memcpy4 = 0; i_memcpy4 < cnt; i_memcpy4++ ) \
|
||||
out_memcpy4[i_memcpy4] = in_memcpy4[i_memcpy4]; }
|
||||
|
||||
#define XOR_BLOCKS_DST(x,y,z) { \
|
||||
((uint64_t *)z)[0] = ((uint64_t *)(x))[0] ^ ((uint64_t *)(y))[0]; \
|
||||
((uint64_t *)z)[1] = ((uint64_t *)(x))[1] ^ ((uint64_t *)(y))[1]; }
|
||||
|
||||
union hash_state {
|
||||
uint8_t b[200];
|
||||
uint64_t w[25];
|
||||
};
|
||||
|
||||
union cn_slow_hash_state {
|
||||
union hash_state hs;
|
||||
struct {
|
||||
uint8_t k[64];
|
||||
uint8_t init[INIT_SIZE_BYTE];
|
||||
};
|
||||
};
|
||||
|
||||
static inline void exit_if_cudaerror(int thr_id, const char *src, int line)
|
||||
{
|
||||
cudaError_t err = cudaGetLastError();
|
||||
if(err != cudaSuccess) {
|
||||
gpulog(LOG_ERR, thr_id, "%s %s line %d", cudaGetErrorString(err), src, line);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void cryptolight_core_hash(int thr_id, int blocks, int threads, uint32_t *d_long_state, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak);
|
||||
|
||||
void cryptonight_extra_setData(int thr_id, const void *data, const void *ptarget);
|
||||
void cryptonight_extra_init(int thr_id/*, uint32_t threads*/);
|
||||
void cryptonight_extra_free(int thr_id);
|
||||
void cryptonight_extra_prepare(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak);
|
||||
void cryptonight_extra_final(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *resNonces, uint32_t *d_ctx_state);
|
||||
@@ -1,316 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#if CUDA_VERSION >= 9000 && __CUDA_ARCH__ >= 300
|
||||
#undef __shfl
|
||||
#define __shfl(var, srcLane, width) __shfl_sync(0xFFFFFFFFu, var, srcLane, width)
|
||||
#endif
|
||||
|
||||
#include "cryptonight.h"
|
||||
|
||||
#define LONG_SHL32 19 // 1<<19 (uint32_t* index)
|
||||
#define LONG_SHL64 18 // 1<<18 (uint64_t* index)
|
||||
#define LONG_LOOPS32 0x80000U
|
||||
|
||||
#include "cn_aes.cuh"
|
||||
|
||||
__global__
|
||||
void cryptonight_gpu_phase1(const uint32_t threads, uint32_t * __restrict__ d_long_state,
|
||||
uint32_t * __restrict__ ctx_state, uint32_t * __restrict__ ctx_key1)
|
||||
{
|
||||
__shared__ uint32_t sharedMemory[1024];
|
||||
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3;
|
||||
if(thread < threads)
|
||||
{
|
||||
cn_aes_gpu_init(sharedMemory);
|
||||
__syncthreads();
|
||||
|
||||
const uint32_t sub = (threadIdx.x & 0x7U) << 2;
|
||||
uint32_t *longstate = &d_long_state[(thread << LONG_SHL32) + sub];
|
||||
uint32_t __align__(8) key[40];
|
||||
MEMCPY8(key, &ctx_key1[thread * 40U], 20);
|
||||
uint32_t __align__(8) text[4];
|
||||
MEMCPY8(text, &ctx_state[thread * 50U + sub + 16U], 2);
|
||||
|
||||
for(int i = 0; i < LONG_LOOPS32; i += 32)
|
||||
{
|
||||
cn_aes_pseudo_round_mut(sharedMemory, text, key);
|
||||
MEMCPY8(&longstate[i], text, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
__device__ __forceinline__ ulonglong2 cuda_mul128(const uint64_t multiplier, const uint64_t multiplicand)
|
||||
{
|
||||
ulonglong2 product;
|
||||
product.x = __umul64hi(multiplier, multiplicand);
|
||||
product.y = multiplier * multiplicand;
|
||||
return product;
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ void operator += (ulonglong2 &a, const ulonglong2 b) {
|
||||
a.x += b.x; a.y += b.y;
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ ulonglong2 operator ^ (const ulonglong2 &a, const ulonglong2 &b) {
|
||||
return make_ulonglong2(a.x ^ b.x, a.y ^ b.y);
|
||||
}
|
||||
|
||||
__device__ __forceinline__ void MUL_SUM_XOR_DST_0(const uint64_t m, uint4 &a, void* far_dst)
|
||||
{
|
||||
ulonglong2 d = AS_UL2(far_dst);
|
||||
ulonglong2 p = cuda_mul128(m, d.x);
|
||||
p += AS_UL2(&a);
|
||||
AS_UL2(&a) = p ^ d;
|
||||
AS_UL2(far_dst) = p;
|
||||
}
|
||||
|
||||
__global__
|
||||
#if __CUDA_ARCH__ >= 500
|
||||
//__launch_bounds__(128,12) /* force 40 regs to allow -l ...x32 */
|
||||
#endif
|
||||
void cryptonight_gpu_phase2(const uint32_t threads, const uint16_t bfactor, const uint32_t partidx,
|
||||
uint64_t * __restrict__ d_long_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b)
|
||||
{
|
||||
__shared__ __align__(16) uint32_t sharedMemory[1024];
|
||||
cn_aes_gpu_init(sharedMemory);
|
||||
__syncthreads();
|
||||
|
||||
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
|
||||
if (thread < threads)
|
||||
{
|
||||
const uint32_t batchsize = ITER >> (2 + bfactor);
|
||||
const uint32_t start = partidx * batchsize;
|
||||
const uint32_t end = start + batchsize;
|
||||
|
||||
void * ctx_a = (void*)(&d_ctx_a[thread << 2U]);
|
||||
void * ctx_b = (void*)(&d_ctx_b[thread << 2U]);
|
||||
uint4 A = AS_UINT4(ctx_a); // ld.global.u32.v4
|
||||
uint4 B = AS_UINT4(ctx_b);
|
||||
|
||||
uint64_t * long_state = &d_long_state[thread << LONG_SHL64];
|
||||
for (int i = start; i < end; i++) // end = 262144
|
||||
{
|
||||
uint4 C;
|
||||
|
||||
uint32_t j = (A.x & E2I_MASK) >> 3;
|
||||
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &C);
|
||||
AS_UINT4(&long_state[j]) = C ^ B; // st.global.u32.v4
|
||||
MUL_SUM_XOR_DST_0((AS_UL2(&C)).x, A, &long_state[(C.x & E2I_MASK) >> 3]);
|
||||
|
||||
j = (A.x & E2I_MASK) >> 3;
|
||||
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &B);
|
||||
AS_UINT4(&long_state[j]) = C ^ B;
|
||||
MUL_SUM_XOR_DST_0((AS_UL2(&B)).x, A, &long_state[(B.x & E2I_MASK) >> 3]);
|
||||
}
|
||||
|
||||
if (bfactor) {
|
||||
AS_UINT4(ctx_a) = A;
|
||||
AS_UINT4(ctx_b) = B;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
__device__ __forceinline__ void store_variant1(uint64_t* long_state, uint4 Z)
|
||||
{
|
||||
const uint32_t tmp = (Z.z >> 24); // __byte_perm(src, 0, 0x7773);
|
||||
const uint32_t index = (((tmp >> 3) & 6u) | (tmp & 1u)) << 1;
|
||||
Z.z = (Z.z & 0x00ffffffu) | ((tmp ^ ((0x75310u >> index) & 0x30u)) << 24);
|
||||
AS_UINT4(long_state) = Z;
|
||||
}
|
||||
|
||||
__device__ __forceinline__ void store_variant2(uint64_t* long_state, uint4 Z)
|
||||
{
|
||||
const uint32_t tmp = (Z.z >> 24); // __byte_perm(src, 0, 0x7773);
|
||||
const uint32_t index = (((tmp >> 4) & 6u) | (tmp & 1u)) << 1;
|
||||
Z.z = (Z.z & 0x00ffffffu) | ((tmp ^ ((0x75312u >> index) & 0x30u)) << 24);
|
||||
AS_UINT4(long_state) = Z;
|
||||
}
|
||||
|
||||
__device__ __forceinline__ void MUL_SUM_XOR_DST_1(const uint64_t m, uint4 &a, void* far_dst, uint64_t tweak)
|
||||
{
|
||||
ulonglong2 d = AS_UL2(far_dst);
|
||||
ulonglong2 p = cuda_mul128(m, d.x);
|
||||
p += AS_UL2(&a);
|
||||
AS_UL2(&a) = p ^ d;
|
||||
p.y = p.y ^ tweak;
|
||||
AS_UL2(far_dst) = p;
|
||||
}
|
||||
|
||||
__global__
|
||||
void monero_gpu_phase2(const uint32_t threads, const uint16_t bfactor, const uint32_t partidx,
|
||||
uint64_t * __restrict__ d_long_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b,
|
||||
uint64_t * __restrict__ d_tweak)
|
||||
{
|
||||
__shared__ __align__(16) uint32_t sharedMemory[1024];
|
||||
cn_aes_gpu_init(sharedMemory);
|
||||
__syncthreads();
|
||||
|
||||
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
if (thread < threads)
|
||||
{
|
||||
const uint32_t batchsize = ITER >> (2 + bfactor);
|
||||
const uint32_t start = partidx * batchsize;
|
||||
const uint32_t end = start + batchsize;
|
||||
uint64_t tweak = d_tweak[thread];
|
||||
|
||||
void * ctx_a = (void*)(&d_ctx_a[thread << 2]);
|
||||
void * ctx_b = (void*)(&d_ctx_b[thread << 2]);
|
||||
uint4 A = AS_UINT4(ctx_a); // ld.global.u32.v4
|
||||
uint4 B = AS_UINT4(ctx_b);
|
||||
|
||||
uint64_t * long_state = &d_long_state[thread << LONG_SHL64];
|
||||
for (int i = start; i < end; i++) // end = 262144
|
||||
{
|
||||
uint4 C;
|
||||
uint32_t j = (A.x & E2I_MASK) >> 3;
|
||||
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &C);
|
||||
store_variant1(&long_state[j], C ^ B); // st.global
|
||||
MUL_SUM_XOR_DST_1((AS_UL2(&C)).x, A, &long_state[(C.x & E2I_MASK) >> 3], tweak);
|
||||
|
||||
j = (A.x & E2I_MASK) >> 3;
|
||||
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &B);
|
||||
store_variant1(&long_state[j], C ^ B);
|
||||
MUL_SUM_XOR_DST_1((AS_UL2(&B)).x, A, &long_state[(B.x & E2I_MASK) >> 3], tweak);
|
||||
}
|
||||
if (bfactor) {
|
||||
AS_UINT4(ctx_a) = A;
|
||||
AS_UINT4(ctx_b) = B;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
__global__
|
||||
void stellite_gpu_phase2(const uint32_t threads, const uint16_t bfactor, const uint32_t partidx,
|
||||
uint64_t * __restrict__ d_long_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b,
|
||||
uint64_t * __restrict__ d_tweak)
|
||||
{
|
||||
__shared__ __align__(16) uint32_t sharedMemory[1024];
|
||||
cn_aes_gpu_init(sharedMemory);
|
||||
__syncthreads();
|
||||
|
||||
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
if (thread < threads)
|
||||
{
|
||||
const uint32_t batchsize = ITER >> (2 + bfactor);
|
||||
const uint32_t start = partidx * batchsize;
|
||||
const uint32_t end = start + batchsize;
|
||||
uint64_t tweak = d_tweak[thread];
|
||||
|
||||
void * ctx_a = (void*)(&d_ctx_a[thread << 2]);
|
||||
void * ctx_b = (void*)(&d_ctx_b[thread << 2]);
|
||||
uint4 A = AS_UINT4(ctx_a); // ld.global.u32.v4
|
||||
uint4 B = AS_UINT4(ctx_b);
|
||||
|
||||
uint64_t * long_state = &d_long_state[thread << LONG_SHL64];
|
||||
for (int i = start; i < end; i++) // end = 262144
|
||||
{
|
||||
uint4 C;
|
||||
uint32_t j = (A.x & E2I_MASK) >> 3;
|
||||
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &C);
|
||||
store_variant2(&long_state[j], C ^ B); // st.global
|
||||
MUL_SUM_XOR_DST_1((AS_UL2(&C)).x, A, &long_state[(C.x & E2I_MASK) >> 3], tweak);
|
||||
|
||||
j = (A.x & E2I_MASK) >> 3;
|
||||
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &B);
|
||||
store_variant2(&long_state[j], C ^ B);
|
||||
MUL_SUM_XOR_DST_1((AS_UL2(&B)).x, A, &long_state[(B.x & E2I_MASK) >> 3], tweak);
|
||||
}
|
||||
if (bfactor) {
|
||||
AS_UINT4(ctx_a) = A;
|
||||
AS_UINT4(ctx_b) = B;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
__global__
|
||||
void cryptonight_gpu_phase3(const uint32_t threads, const uint32_t * __restrict__ d_long_state,
|
||||
uint32_t * __restrict__ d_ctx_state, const uint32_t * __restrict__ d_ctx_key2)
|
||||
{
|
||||
__shared__ uint32_t sharedMemory[1024];
|
||||
|
||||
cn_aes_gpu_init(sharedMemory);
|
||||
__syncthreads();
|
||||
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3;
|
||||
|
||||
if(thread < threads)
|
||||
{
|
||||
const int sub = (threadIdx.x & 7) << 2;
|
||||
const uint32_t *longstate = &d_long_state[(thread << LONG_SHL32) + sub];
|
||||
uint32_t key[40], text[4];
|
||||
MEMCPY8(key, d_ctx_key2 + thread * 40, 20);
|
||||
MEMCPY8(text, d_ctx_state + thread * 50 + sub + 16, 2);
|
||||
|
||||
for(int i = 0; i < LONG_LOOPS32; i += 32)
|
||||
{
|
||||
#pragma unroll
|
||||
for(int j = 0; j < 4; ++j)
|
||||
text[j] ^= longstate[i + j];
|
||||
|
||||
cn_aes_pseudo_round_mut(sharedMemory, text, key);
|
||||
}
|
||||
|
||||
MEMCPY8(d_ctx_state + thread * 50 + sub + 16, text, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
extern int device_bfactor[MAX_GPUS];
|
||||
|
||||
__host__
|
||||
void cryptonight_core_cuda(int thr_id, uint32_t blocks, uint32_t threads, uint64_t *d_long_state, uint32_t *d_ctx_state,
|
||||
uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak)
|
||||
{
|
||||
dim3 grid(blocks);
|
||||
dim3 block(threads);
|
||||
dim3 block4(threads << 2);
|
||||
dim3 block8(threads << 3);
|
||||
|
||||
const uint16_t bfactor = (uint16_t) device_bfactor[thr_id];
|
||||
const uint32_t partcount = 1U << bfactor;
|
||||
const uint32_t throughput = (uint32_t) (blocks*threads);
|
||||
|
||||
const int bsleep = bfactor ? 100 : 0;
|
||||
const int dev_id = device_map[thr_id];
|
||||
|
||||
cryptonight_gpu_phase1 <<<grid, block8>>> (throughput, (uint32_t*) d_long_state, d_ctx_state, d_ctx_key1);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
if(partcount > 1) usleep(bsleep);
|
||||
|
||||
for (uint32_t i = 0; i < partcount; i++)
|
||||
{
|
||||
dim3 b = device_sm[dev_id] >= 300 ? block4 : block;
|
||||
if (variant == 0)
|
||||
cryptonight_gpu_phase2 <<<grid, b>>> (throughput, bfactor, i, d_long_state, d_ctx_a, d_ctx_b);
|
||||
else if (variant == 1 || cryptonight_fork == 8)
|
||||
monero_gpu_phase2 <<<grid, b>>> (throughput, bfactor, i, d_long_state, d_ctx_a, d_ctx_b, d_ctx_tweak);
|
||||
else if (variant == 2 && cryptonight_fork == 3)
|
||||
stellite_gpu_phase2 <<<grid, b>>> (throughput, bfactor, i, d_long_state, d_ctx_a, d_ctx_b, d_ctx_tweak);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
if(partcount > 1) usleep(bsleep);
|
||||
}
|
||||
//cudaDeviceSynchronize();
|
||||
//exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cryptonight_gpu_phase3 <<<grid, block8>>> (throughput, (uint32_t*) d_long_state, d_ctx_state, d_ctx_key2);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
}
|
||||
@@ -1,269 +0,0 @@
|
||||
#include <miner.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "oaes_lib.h"
|
||||
#include "cryptonight.h"
|
||||
|
||||
extern "C" {
|
||||
#include <sph/sph_blake.h>
|
||||
#include <sph/sph_groestl.h>
|
||||
#include <sph/sph_jh.h>
|
||||
#include <sph/sph_skein.h>
|
||||
#include "cpu/c_keccak.h"
|
||||
}
|
||||
|
||||
struct cryptonight_ctx {
|
||||
uint8_t long_state[MEMORY];
|
||||
union cn_slow_hash_state state;
|
||||
uint8_t text[INIT_SIZE_BYTE];
|
||||
uint8_t a[AES_BLOCK_SIZE];
|
||||
uint8_t b[AES_BLOCK_SIZE];
|
||||
uint8_t c[AES_BLOCK_SIZE];
|
||||
oaes_ctx* aes_ctx;
|
||||
};
|
||||
|
||||
static void do_blake_hash(const void* input, size_t len, void* output)
|
||||
{
|
||||
uchar hash[32];
|
||||
sph_blake256_context ctx;
|
||||
sph_blake256_set_rounds(14);
|
||||
sph_blake256_init(&ctx);
|
||||
sph_blake256(&ctx, input, len);
|
||||
sph_blake256_close(&ctx, hash);
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
static void do_groestl_hash(const void* input, size_t len, void* output)
|
||||
{
|
||||
uchar hash[32];
|
||||
sph_groestl256_context ctx;
|
||||
sph_groestl256_init(&ctx);
|
||||
sph_groestl256(&ctx, input, len);
|
||||
sph_groestl256_close(&ctx, hash);
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
static void do_jh_hash(const void* input, size_t len, void* output)
|
||||
{
|
||||
uchar hash[64];
|
||||
sph_jh256_context ctx;
|
||||
sph_jh256_init(&ctx);
|
||||
sph_jh256(&ctx, input, len);
|
||||
sph_jh256_close(&ctx, hash);
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
static void do_skein_hash(const void* input, size_t len, void* output)
|
||||
{
|
||||
uchar hash[32];
|
||||
sph_skein256_context ctx;
|
||||
sph_skein256_init(&ctx);
|
||||
sph_skein256(&ctx, input, len);
|
||||
sph_skein256_close(&ctx, hash);
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
// todo: use sph if possible
|
||||
static void keccak_hash_permutation(union hash_state *state) {
|
||||
keccakf((uint64_t*)state, 24);
|
||||
}
|
||||
|
||||
static void keccak_hash_process(union hash_state *state, const uint8_t *buf, size_t count) {
|
||||
keccak1600(buf, (int)count, (uint8_t*)state);
|
||||
}
|
||||
|
||||
extern "C" int fast_aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
|
||||
extern "C" int aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
|
||||
extern "C" int aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey);
|
||||
extern "C" int fast_aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey);
|
||||
|
||||
static void (* const extra_hashes[4])(const void*, size_t, void *) = {
|
||||
do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash
|
||||
};
|
||||
|
||||
static uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi)
|
||||
{
|
||||
// multiplier = ab = a * 2^32 + b
|
||||
// multiplicand = cd = c * 2^32 + d
|
||||
// ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d
|
||||
uint64_t a = hi_dword(multiplier);
|
||||
uint64_t b = lo_dword(multiplier);
|
||||
uint64_t c = hi_dword(multiplicand);
|
||||
uint64_t d = lo_dword(multiplicand);
|
||||
|
||||
uint64_t ac = a * c;
|
||||
uint64_t ad = a * d;
|
||||
uint64_t bc = b * c;
|
||||
uint64_t bd = b * d;
|
||||
|
||||
uint64_t adbc = ad + bc;
|
||||
uint64_t adbc_carry = adbc < ad ? 1 : 0;
|
||||
|
||||
// multiplier * multiplicand = product_hi * 2^64 + product_lo
|
||||
uint64_t product_lo = bd + (adbc << 32);
|
||||
uint64_t product_lo_carry = product_lo < bd ? 1 : 0;
|
||||
*product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry;
|
||||
|
||||
return product_lo;
|
||||
}
|
||||
|
||||
static size_t e2i(const uint8_t* a) {
|
||||
return (*((uint64_t*) a) / AES_BLOCK_SIZE) & (MEMORY / AES_BLOCK_SIZE - 1);
|
||||
}
|
||||
|
||||
static void mul(const uint8_t* a, const uint8_t* b, uint8_t* res) {
|
||||
((uint64_t*) res)[1] = mul128(((uint64_t*) a)[0], ((uint64_t*) b)[0], (uint64_t*) res);
|
||||
}
|
||||
|
||||
static void sum_half_blocks(uint8_t* a, const uint8_t* b) {
|
||||
((uint64_t*) a)[0] += ((uint64_t*) b)[0];
|
||||
((uint64_t*) a)[1] += ((uint64_t*) b)[1];
|
||||
}
|
||||
|
||||
static void sum_half_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) {
|
||||
((uint64_t*) dst)[0] = ((uint64_t*) a)[0] + ((uint64_t*) b)[0];
|
||||
((uint64_t*) dst)[1] = ((uint64_t*) a)[1] + ((uint64_t*) b)[1];
|
||||
}
|
||||
|
||||
static void mul_sum_dst(const uint8_t* a, const uint8_t* b, const uint8_t* c, uint8_t* dst) {
|
||||
((uint64_t*) dst)[1] = mul128(((uint64_t*) a)[0], ((uint64_t*) b)[0], (uint64_t*) dst) + ((uint64_t*) c)[1];
|
||||
((uint64_t*) dst)[0] += ((uint64_t*) c)[0];
|
||||
}
|
||||
|
||||
static void mul_sum_xor_dst(const uint8_t* a, uint8_t* c, uint8_t* dst, const int variant, const uint64_t tweak) {
|
||||
uint64_t hi, lo = mul128(((uint64_t*) a)[0], ((uint64_t*) dst)[0], &hi) + ((uint64_t*) c)[1];
|
||||
hi += ((uint64_t*) c)[0];
|
||||
|
||||
((uint64_t*) c)[0] = ((uint64_t*) dst)[0] ^ hi;
|
||||
((uint64_t*) c)[1] = ((uint64_t*) dst)[1] ^ lo;
|
||||
((uint64_t*) dst)[0] = hi;
|
||||
((uint64_t*) dst)[1] = variant ? lo ^ tweak : lo;
|
||||
}
|
||||
|
||||
static void copy_block(uint8_t* dst, const uint8_t* src) {
|
||||
((uint64_t*) dst)[0] = ((uint64_t*) src)[0];
|
||||
((uint64_t*) dst)[1] = ((uint64_t*) src)[1];
|
||||
}
|
||||
|
||||
static void xor_blocks(uint8_t* a, const uint8_t* b) {
|
||||
((uint64_t*) a)[0] ^= ((uint64_t*) b)[0];
|
||||
((uint64_t*) a)[1] ^= ((uint64_t*) b)[1];
|
||||
}
|
||||
|
||||
static void xor_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) {
|
||||
((uint64_t*) dst)[0] = ((uint64_t*) a)[0] ^ ((uint64_t*) b)[0];
|
||||
((uint64_t*) dst)[1] = ((uint64_t*) a)[1] ^ ((uint64_t*) b)[1];
|
||||
}
|
||||
|
||||
static void cryptonight_store_variant(void* state, int variant) {
|
||||
if (variant == 1 || cryptonight_fork == 8) {
|
||||
// monero and graft
|
||||
const uint8_t tmp = ((const uint8_t*)(state))[11];
|
||||
const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1;
|
||||
((uint8_t*)(state))[11] = tmp ^ ((0x75310 >> index) & 0x30);
|
||||
} else if (variant == 2 && cryptonight_fork == 3) {
|
||||
// stellite
|
||||
const uint8_t tmp = ((const uint8_t*)(state))[11];
|
||||
const uint8_t index = (((tmp >> 4) & 6) | (tmp & 1)) << 1;
|
||||
((uint8_t*)(state))[11] = tmp ^ ((0x75312 >> index) & 0x30);
|
||||
}
|
||||
}
|
||||
|
||||
static void cryptonight_hash_ctx(void* output, const void* input, const size_t len, struct cryptonight_ctx* ctx, const int variant)
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
keccak_hash_process(&ctx->state.hs, (const uint8_t*) input, len);
|
||||
ctx->aes_ctx = (oaes_ctx*) oaes_alloc();
|
||||
memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
|
||||
|
||||
const uint64_t tweak = variant ? *((uint64_t*) (((uint8_t*)input) + 35)) ^ ctx->state.hs.w[24] : 0;
|
||||
|
||||
oaes_key_import_data(ctx->aes_ctx, ctx->state.hs.b, AES_KEY_SIZE);
|
||||
for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) {
|
||||
#undef RND
|
||||
#define RND(p) aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * p], ctx->aes_ctx->key->exp_data);
|
||||
RND(0);
|
||||
RND(1);
|
||||
RND(2);
|
||||
RND(3);
|
||||
RND(4);
|
||||
RND(5);
|
||||
RND(6);
|
||||
RND(7);
|
||||
memcpy(&ctx->long_state[i], ctx->text, INIT_SIZE_BYTE);
|
||||
}
|
||||
|
||||
xor_blocks_dst(&ctx->state.k[0], &ctx->state.k[32], ctx->a);
|
||||
xor_blocks_dst(&ctx->state.k[16], &ctx->state.k[48], ctx->b);
|
||||
|
||||
for (i = 0; likely(i < ITER / 4); ++i) {
|
||||
j = e2i(ctx->a) * AES_BLOCK_SIZE;
|
||||
aesb_single_round(&ctx->long_state[j], ctx->c, ctx->a);
|
||||
xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]);
|
||||
cryptonight_store_variant(&ctx->long_state[j], variant);
|
||||
mul_sum_xor_dst(ctx->c, ctx->a, &ctx->long_state[e2i(ctx->c) * AES_BLOCK_SIZE], variant, tweak);
|
||||
|
||||
j = e2i(ctx->a) * AES_BLOCK_SIZE;
|
||||
aesb_single_round(&ctx->long_state[j], ctx->b, ctx->a);
|
||||
xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]);
|
||||
cryptonight_store_variant(&ctx->long_state[j], variant);
|
||||
mul_sum_xor_dst(ctx->b, ctx->a, &ctx->long_state[e2i(ctx->b) * AES_BLOCK_SIZE], variant, tweak);
|
||||
}
|
||||
|
||||
memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
|
||||
oaes_key_import_data(ctx->aes_ctx, &ctx->state.hs.b[32], AES_KEY_SIZE);
|
||||
for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) {
|
||||
#undef RND
|
||||
#define RND(p) xor_blocks(&ctx->text[p * AES_BLOCK_SIZE], &ctx->long_state[i + p * AES_BLOCK_SIZE]); \
|
||||
aesb_pseudo_round_mut(&ctx->text[p * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data);
|
||||
RND(0);
|
||||
RND(1);
|
||||
RND(2);
|
||||
RND(3);
|
||||
RND(4);
|
||||
RND(5);
|
||||
RND(6);
|
||||
RND(7);
|
||||
}
|
||||
memcpy(ctx->state.init, ctx->text, INIT_SIZE_BYTE);
|
||||
keccak_hash_permutation(&ctx->state.hs);
|
||||
|
||||
int extra_algo = ctx->state.hs.b[0] & 3;
|
||||
extra_hashes[extra_algo](&ctx->state, 200, output);
|
||||
if (opt_debug) applog(LOG_DEBUG, "extra algo=%d", extra_algo);
|
||||
|
||||
oaes_free((OAES_CTX **) &ctx->aes_ctx);
|
||||
}
|
||||
|
||||
void cryptonight_hash_variant(void* output, const void* input, size_t len, int variant)
|
||||
{
|
||||
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));
|
||||
cryptonight_hash_ctx(output, input, len, ctx, variant);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
void cryptonight_hash(void* output, const void* input)
|
||||
{
|
||||
cryptonight_fork = 1;
|
||||
cryptonight_hash_variant(output, input, 76, 0);
|
||||
}
|
||||
|
||||
void graft_hash(void* output, const void* input)
|
||||
{
|
||||
cryptonight_fork = 8;
|
||||
cryptonight_hash_variant(output, input, 76, 1);
|
||||
}
|
||||
|
||||
void monero_hash(void* output, const void* input)
|
||||
{
|
||||
cryptonight_fork = 7;
|
||||
cryptonight_hash_variant(output, input, 76, 1);
|
||||
}
|
||||
|
||||
void stellite_hash(void* output, const void* input)
|
||||
{
|
||||
cryptonight_fork = 3;
|
||||
cryptonight_hash_variant(output, input, 76, 2);
|
||||
}
|
||||
|
||||
@@ -1,212 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <miner.h>
|
||||
#include <cuda_helper.h>
|
||||
|
||||
#include "cryptonight.h"
|
||||
|
||||
static uint32_t *d_input[MAX_GPUS];
|
||||
static uint32_t *d_target[MAX_GPUS];
|
||||
static uint32_t *d_result[MAX_GPUS];
|
||||
|
||||
typedef uint8_t BitSequence;
|
||||
typedef uint32_t DataLength;
|
||||
#include "cn_keccak.cuh"
|
||||
#include "cn_blake.cuh"
|
||||
#include "cn_groestl.cuh"
|
||||
#include "cn_jh.cuh"
|
||||
#include "cn_skein.cuh"
|
||||
|
||||
__constant__ uint8_t d_sub_byte[16][16] = {
|
||||
{0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76},
|
||||
{0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0},
|
||||
{0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15},
|
||||
{0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75},
|
||||
{0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84},
|
||||
{0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf},
|
||||
{0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8},
|
||||
{0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2},
|
||||
{0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73},
|
||||
{0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb},
|
||||
{0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79},
|
||||
{0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08},
|
||||
{0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a},
|
||||
{0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e},
|
||||
{0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf},
|
||||
{0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16}
|
||||
};
|
||||
|
||||
__device__ __forceinline__
|
||||
void cryptonight_aes_set_key(uint32_t * __restrict__ key, const uint32_t * __restrict__ data)
|
||||
{
|
||||
const uint32_t aes_gf[10] = {
|
||||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
|
||||
};
|
||||
|
||||
MEMCPY4(key, data, 8);
|
||||
#pragma unroll
|
||||
for(int i = 8; i < 40; i++)
|
||||
{
|
||||
uint8_t temp[4];
|
||||
*(uint32_t *)temp = key[i - 1];
|
||||
|
||||
if(i % 8 == 0) {
|
||||
*(uint32_t *)temp = ROTR32(*(uint32_t *)temp, 8);
|
||||
for(int j = 0; j < 4; j++)
|
||||
temp[j] = d_sub_byte[(temp[j] >> 4) & 0x0f][temp[j] & 0x0f];
|
||||
*(uint32_t *)temp ^= aes_gf[i / 8 - 1];
|
||||
}
|
||||
else if(i % 8 == 4) {
|
||||
#pragma unroll
|
||||
for(int j = 0; j < 4; j++)
|
||||
temp[j] = d_sub_byte[(temp[j] >> 4) & 0x0f][temp[j] & 0x0f];
|
||||
}
|
||||
|
||||
key[i] = key[(i - 8)] ^ *(uint32_t *)temp;
|
||||
}
|
||||
}
|
||||
|
||||
__global__
|
||||
void cryptonight_extra_gpu_prepare(const uint32_t threads, const uint32_t * __restrict__ d_input, uint32_t startNonce,
|
||||
uint32_t * __restrict__ d_ctx_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b,
|
||||
uint32_t * __restrict__ d_ctx_key1, uint32_t * __restrict__ d_ctx_key2, int variant, uint64_t * d_ctx_tweak)
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if(thread < threads)
|
||||
{
|
||||
uint64_t ctx_state[25];
|
||||
uint32_t ctx_a[4];
|
||||
uint32_t ctx_b[4];
|
||||
uint32_t ctx_key1[40];
|
||||
uint32_t ctx_key2[40];
|
||||
uint32_t input[19];
|
||||
|
||||
MEMCPY4(input, d_input, 19);
|
||||
|
||||
uint32_t nonce = startNonce + thread;
|
||||
*(((uint8_t *)input) + 39) = nonce & 0xff;
|
||||
*(((uint8_t *)input) + 40) = (nonce >> 8) & 0xff;
|
||||
*(((uint8_t *)input) + 41) = (nonce >> 16) & 0xff;
|
||||
*(((uint8_t *)input) + 42) = (nonce >> 24) & 0xff;
|
||||
|
||||
cn_keccak(input, ctx_state);
|
||||
MEMCPY4(&d_ctx_state[thread * 50U], ctx_state, 50);
|
||||
|
||||
cryptonight_aes_set_key(ctx_key1, (uint32_t*)(&ctx_state[0]));
|
||||
cryptonight_aes_set_key(ctx_key2, (uint32_t*)(&ctx_state[4]));
|
||||
MEMCPY4(&d_ctx_key1[thread * 40U], ctx_key1, 40);
|
||||
MEMCPY4(&d_ctx_key2[thread * 40U], ctx_key2, 40);
|
||||
|
||||
XOR_BLOCKS_DST(&ctx_state[0], &ctx_state[4], ctx_a);
|
||||
XOR_BLOCKS_DST(&ctx_state[2], &ctx_state[6], ctx_b);
|
||||
MEMCPY4(&d_ctx_a[thread * 4U], ctx_a, 4);
|
||||
MEMCPY4(&d_ctx_b[thread * 4U], ctx_b, 4);
|
||||
|
||||
if (variant) {
|
||||
uint2 tweak = AS_UINT2(&ctx_state[24]);
|
||||
//tweak.x ^= (input[8] >> 24) | (input[9] << 8);
|
||||
tweak.x ^= __byte_perm(input[8], input[ 9], 0x6543);
|
||||
tweak.y ^= __byte_perm(input[9], input[10], 0x6543);
|
||||
MEMCPY4(&d_ctx_tweak[thread], &tweak, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__global__
|
||||
void cryptonight_extra_gpu_final(const uint32_t threads, uint32_t startNonce, const uint32_t * __restrict__ d_target,
|
||||
uint32_t * __restrict__ resNonces, uint32_t * __restrict__ d_ctx_state)
|
||||
{
|
||||
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
if(thread < threads)
|
||||
{
|
||||
uint32_t *ctx_state = &d_ctx_state[thread * 50U];
|
||||
uint32_t hash[8];
|
||||
uint32_t state[50];
|
||||
|
||||
#pragma unroll 25
|
||||
for(int i = 0; i < 50; i+=2)
|
||||
AS_UINT2(&state[i]) = AS_UINT2(&ctx_state[i]);
|
||||
|
||||
cn_keccakf2((uint64_t *)state);
|
||||
|
||||
int branch = ((uint8_t *)state)[0] & 0x03;
|
||||
if(branch == 0)
|
||||
cn_blake((const uint8_t *)state, 200, hash);
|
||||
if(branch == 1)
|
||||
cn_groestl((const uint8_t *)state, 200, hash);
|
||||
if(branch == 2)
|
||||
cn_jh((const uint8_t *)state, 200, hash);
|
||||
if(branch == 3)
|
||||
cn_skein((const uint8_t *)state, 200, hash);
|
||||
|
||||
if(hash[7] <= d_target[1] && hash[6] <= d_target[0])
|
||||
{
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
uint32_t tmp = atomicExch(resNonces, nonce);
|
||||
if(tmp != UINT32_MAX)
|
||||
resNonces[1] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void cryptonight_extra_setData(int thr_id, const void *data, const void *ptarget)
|
||||
{
|
||||
uint32_t *pTargetIn = (uint32_t*) ptarget;
|
||||
cudaMemcpy(d_input[thr_id], data, 20 * sizeof(uint32_t), cudaMemcpyHostToDevice);
|
||||
cudaMemcpy(d_target[thr_id], &pTargetIn[6], 2 * sizeof(uint32_t), cudaMemcpyHostToDevice);
|
||||
cudaMemset(d_result[thr_id], 0xFF, 2 * sizeof(uint32_t));
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
__host__
|
||||
void cryptonight_extra_init(int thr_id)
|
||||
{
|
||||
cudaMalloc(&d_input[thr_id], 20 * sizeof(uint32_t));
|
||||
cudaMalloc(&d_target[thr_id], 2 * sizeof(uint32_t));
|
||||
cudaMalloc(&d_result[thr_id], 2 * sizeof(uint32_t));
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
__host__
|
||||
void cryptonight_extra_prepare(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak)
|
||||
{
|
||||
uint32_t threadsperblock = 128;
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
cryptonight_extra_gpu_prepare <<<grid, block>>> (threads, d_input[thr_id], startNonce, d_ctx_state, d_ctx_a, d_ctx_b, d_ctx_key1, d_ctx_key2, variant, d_ctx_tweak);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
__host__
|
||||
void cryptonight_extra_final(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *resNonces, uint32_t *d_ctx_state)
|
||||
{
|
||||
uint32_t threadsperblock = 128;
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cryptonight_extra_gpu_final <<<grid, block>>> (threads, startNonce, d_target[thr_id], d_result[thr_id], d_ctx_state);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMemcpy(resNonces, d_result[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
__host__
|
||||
void cryptonight_extra_free(int thr_id)
|
||||
{
|
||||
if (d_input[thr_id]) {
|
||||
cudaFree(d_input[thr_id]);
|
||||
cudaFree(d_target[thr_id]);
|
||||
cudaFree(d_result[thr_id]);
|
||||
d_input[thr_id] = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
|
||||
#include "cryptonight.h"
|
||||
|
||||
extern char *device_config[MAX_GPUS]; // -l 32x16
|
||||
|
||||
static __thread uint32_t cn_blocks;
|
||||
static __thread uint32_t cn_threads;
|
||||
|
||||
// used for gpu intensity on algo init
|
||||
static __thread bool gpu_init_shown = false;
|
||||
#define gpulog_init(p,thr,fmt, ...) if (!gpu_init_shown) \
|
||||
gpulog(p, thr, fmt, ##__VA_ARGS__)
|
||||
|
||||
static uint64_t *d_long_state[MAX_GPUS];
|
||||
static uint32_t *d_ctx_state[MAX_GPUS];
|
||||
static uint32_t *d_ctx_key1[MAX_GPUS];
|
||||
static uint32_t *d_ctx_key2[MAX_GPUS];
|
||||
static uint32_t *d_ctx_text[MAX_GPUS];
|
||||
static uint64_t *d_ctx_tweak[MAX_GPUS];
|
||||
static uint32_t *d_ctx_a[MAX_GPUS];
|
||||
static uint32_t *d_ctx_b[MAX_GPUS];
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_cryptonight(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, int variant)
|
||||
{
|
||||
int res = 0;
|
||||
uint32_t throughput = 0;
|
||||
|
||||
uint32_t *ptarget = work->target;
|
||||
uint8_t *pdata = (uint8_t*) work->data;
|
||||
uint32_t *nonceptr = (uint32_t*) (&pdata[39]);
|
||||
const uint32_t first_nonce = *nonceptr;
|
||||
uint32_t nonce = first_nonce;
|
||||
int dev_id = device_map[thr_id];
|
||||
|
||||
if(opt_benchmark) {
|
||||
ptarget[7] = 0x00ff;
|
||||
}
|
||||
|
||||
if(!init[thr_id])
|
||||
{
|
||||
int mem = cuda_available_memory(thr_id);
|
||||
int mul = device_sm[dev_id] >= 300 ? 4 : 1; // see cryptonight-core.cu
|
||||
cn_threads = device_sm[dev_id] >= 600 ? 16 : 8; // real TPB is x4 on SM3+
|
||||
cn_blocks = device_mpcount[dev_id] * 4;
|
||||
if (cn_blocks*cn_threads*2.2 > mem) cn_blocks = device_mpcount[dev_id] * 2;
|
||||
|
||||
if (!opt_quiet)
|
||||
gpulog_init(LOG_INFO, thr_id, "%s, %d MB available, %hd SMX", device_name[dev_id],
|
||||
mem, device_mpcount[dev_id]);
|
||||
|
||||
if (!device_config[thr_id]) {
|
||||
if(strcmp(device_name[dev_id], "TITAN V") == 0)
|
||||
device_config[thr_id] = strdup("80x24");
|
||||
if(strstr(device_name[dev_id], "V100"))
|
||||
device_config[thr_id] = strdup("80x24");
|
||||
}
|
||||
|
||||
if (device_config[thr_id]) {
|
||||
int res = sscanf(device_config[thr_id], "%ux%u", &cn_blocks, &cn_threads);
|
||||
throughput = cuda_default_throughput(thr_id, cn_blocks*cn_threads);
|
||||
gpulog_init(LOG_INFO, thr_id, "Using %ux%u(x%d) kernel launch config, %u threads",
|
||||
cn_blocks, cn_threads, mul, throughput);
|
||||
} else {
|
||||
throughput = cuda_default_throughput(thr_id, cn_blocks*cn_threads);
|
||||
if (throughput != cn_blocks*cn_threads && cn_threads) {
|
||||
cn_blocks = throughput / cn_threads;
|
||||
throughput = cn_threads * cn_blocks;
|
||||
}
|
||||
gpulog_init(LOG_INFO, thr_id, "%u threads (%g) with %u blocks",// of %ux%d",
|
||||
throughput, throughput2intensity(throughput), cn_blocks);//, cn_threads, mul);
|
||||
}
|
||||
|
||||
if(sizeof(size_t) == 4 && throughput > UINT32_MAX / MEMORY) {
|
||||
gpulog(LOG_ERR, thr_id, "THE 32bit VERSION CAN'T ALLOCATE MORE THAN 4GB OF MEMORY!");
|
||||
gpulog(LOG_ERR, thr_id, "PLEASE REDUCE THE NUMBER OF THREADS OR BLOCKS");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cudaSetDevice(dev_id);
|
||||
if (opt_cudaschedule == -1 && gpu_threads == 1) {
|
||||
cudaDeviceReset();
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
|
||||
const size_t alloc = MEMORY * size_t(throughput);
|
||||
cryptonight_extra_init(thr_id);
|
||||
|
||||
cudaMalloc(&d_long_state[thr_id], alloc);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_state[thr_id], 50 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_key1[thr_id], 40 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_key2[thr_id], 40 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_text[thr_id], 32 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_a[thr_id], 4 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_b[thr_id], 4 * sizeof(uint32_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
|
||||
cudaMalloc(&d_ctx_tweak[thr_id], sizeof(uint64_t) * throughput);
|
||||
exit_if_cudaerror(thr_id, __FILE__, __LINE__);
|
||||
|
||||
gpu_init_shown = true;
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
throughput = cn_blocks*cn_threads;
|
||||
|
||||
do
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t resNonces[2] = { UINT32_MAX, UINT32_MAX };
|
||||
|
||||
cryptonight_extra_setData(thr_id, pdata, ptarget);
|
||||
cryptonight_extra_prepare(thr_id, throughput, nonce, d_ctx_state[thr_id], d_ctx_a[thr_id], d_ctx_b[thr_id], d_ctx_key1[thr_id], d_ctx_key2[thr_id], variant, d_ctx_tweak[thr_id]);
|
||||
cryptonight_core_cuda(thr_id, cn_blocks, cn_threads, d_long_state[thr_id], d_ctx_state[thr_id], d_ctx_a[thr_id], d_ctx_b[thr_id], d_ctx_key1[thr_id], d_ctx_key2[thr_id], variant, d_ctx_tweak[thr_id]);
|
||||
cryptonight_extra_final(thr_id, throughput, nonce, resNonces, d_ctx_state[thr_id]);
|
||||
|
||||
*hashes_done = nonce - first_nonce + throughput;
|
||||
|
||||
if(resNonces[0] != UINT32_MAX)
|
||||
{
|
||||
uint32_t vhash[8];
|
||||
uint32_t tempdata[19];
|
||||
uint32_t *tempnonceptr = (uint32_t*)(((char*)tempdata) + 39);
|
||||
memcpy(tempdata, pdata, 76);
|
||||
*tempnonceptr = resNonces[0];
|
||||
cryptonight_hash_variant(vhash, tempdata, 76, variant);
|
||||
if(vhash[7] <= Htarg && fulltest(vhash, ptarget))
|
||||
{
|
||||
res = 1;
|
||||
work->nonces[0] = resNonces[0];
|
||||
work_set_target_ratio(work, vhash);
|
||||
// second nonce
|
||||
if(resNonces[1] != UINT32_MAX)
|
||||
{
|
||||
*tempnonceptr = resNonces[1];
|
||||
cryptonight_hash_variant(vhash, tempdata, 76, variant);
|
||||
if(vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
|
||||
res++;
|
||||
work->nonces[1] = resNonces[1];
|
||||
} else {
|
||||
gpu_increment_reject(thr_id);
|
||||
}
|
||||
}
|
||||
goto done;
|
||||
} else if (vhash[7] > Htarg) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for nonce %08x does not validate on CPU!", resNonces[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if ((uint64_t) throughput + nonce >= max_nonce - 127) {
|
||||
nonce = max_nonce;
|
||||
break;
|
||||
}
|
||||
|
||||
nonce += throughput;
|
||||
gpulog(LOG_DEBUG, thr_id, "nonce %08x", nonce);
|
||||
|
||||
} while (!work_restart[thr_id].restart && max_nonce > (uint64_t)throughput + nonce);
|
||||
|
||||
done:
|
||||
gpulog(LOG_DEBUG, thr_id, "nonce %08x exit", nonce);
|
||||
work->valid_nonces = res;
|
||||
*nonceptr = nonce;
|
||||
return res;
|
||||
}
|
||||
|
||||
void free_cryptonight(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaFree(d_long_state[thr_id]);
|
||||
cudaFree(d_ctx_state[thr_id]);
|
||||
cudaFree(d_ctx_key1[thr_id]);
|
||||
cudaFree(d_ctx_key2[thr_id]);
|
||||
cudaFree(d_ctx_text[thr_id]);
|
||||
cudaFree(d_ctx_tweak[thr_id]);
|
||||
cudaFree(d_ctx_a[thr_id]);
|
||||
cudaFree(d_ctx_b[thr_id]);
|
||||
|
||||
cryptonight_extra_free(thr_id);
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
|
||||
init[thr_id] = false;
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
#pragma once
|
||||
#include <cuda_runtime.h>
|
||||
#include <miner.h>
|
||||
|
||||
#ifdef __INTELLISENSE__
|
||||
/* avoid red underlining */
|
||||
#define __CUDA_ARCH__ 520
|
||||
struct uint3 {
|
||||
unsigned int x, y, z;
|
||||
};
|
||||
struct uint3 threadIdx;
|
||||
struct uint3 blockIdx;
|
||||
struct uint3 blockDim;
|
||||
#define atomicExch(p,y) (*p) = y
|
||||
#define __funnelshift_r(a,b,c) 1
|
||||
#define __syncthreads()
|
||||
#define __threadfence_block()
|
||||
#define asm(x)
|
||||
#define __shfl(a,b,c) 1
|
||||
#define __umul64hi(a,b) a*b
|
||||
#endif
|
||||
|
||||
#define MEMORY (1U << 21) // 2 MiB / 2097152 B
|
||||
#define ITER (1U << 20) // 1048576
|
||||
#define E2I_MASK 0x1FFFF0u
|
||||
|
||||
#define AES_BLOCK_SIZE 16U
|
||||
#define AES_KEY_SIZE 32
|
||||
#define INIT_SIZE_BLK 8
|
||||
#define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) // 128 B
|
||||
|
||||
#define AES_RKEY_LEN 4
|
||||
#define AES_COL_LEN 4
|
||||
#define AES_ROUND_BASE 7
|
||||
|
||||
#ifndef HASH_SIZE
|
||||
#define HASH_SIZE 32
|
||||
#endif
|
||||
|
||||
#ifndef HASH_DATA_AREA
|
||||
#define HASH_DATA_AREA 136
|
||||
#endif
|
||||
|
||||
#define hi_dword(x) (x >> 32)
|
||||
#define lo_dword(x) (x & 0xFFFFFFFF)
|
||||
|
||||
#define C32(x) ((uint32_t)(x ## U))
|
||||
#define T32(x) ((x) & C32(0xFFFFFFFF))
|
||||
|
||||
#ifndef ROTL64
|
||||
#if __CUDA_ARCH__ >= 350
|
||||
__forceinline__ __device__ uint64_t cuda_ROTL64(const uint64_t value, const int offset) {
|
||||
uint2 result;
|
||||
if(offset >= 32) {
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
|
||||
} else {
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
|
||||
}
|
||||
return __double_as_longlong(__hiloint2double(result.y, result.x));
|
||||
}
|
||||
#define ROTL64(x, n) (cuda_ROTL64(x, n))
|
||||
#else
|
||||
#define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ROTL32
|
||||
#if __CUDA_ARCH__ < 350
|
||||
#define ROTL32(x, n) T32(((x) << (n)) | ((x) >> (32 - (n))))
|
||||
#else
|
||||
#define ROTL32(x, n) __funnelshift_l( (x), (x), (n) )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ROTR32
|
||||
#if __CUDA_ARCH__ < 350
|
||||
#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
|
||||
#else
|
||||
#define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MEMSET8(dst,what,cnt) { \
|
||||
int i_memset8; \
|
||||
uint64_t *out_memset8 = (uint64_t *)(dst); \
|
||||
for( i_memset8 = 0; i_memset8 < cnt; i_memset8++ ) \
|
||||
out_memset8[i_memset8] = (what); }
|
||||
|
||||
#define MEMSET4(dst,what,cnt) { \
|
||||
int i_memset4; \
|
||||
uint32_t *out_memset4 = (uint32_t *)(dst); \
|
||||
for( i_memset4 = 0; i_memset4 < cnt; i_memset4++ ) \
|
||||
out_memset4[i_memset4] = (what); }
|
||||
|
||||
#define MEMCPY8(dst,src,cnt) { \
|
||||
int i_memcpy8; \
|
||||
uint64_t *in_memcpy8 = (uint64_t *)(src); \
|
||||
uint64_t *out_memcpy8 = (uint64_t *)(dst); \
|
||||
for( i_memcpy8 = 0; i_memcpy8 < cnt; i_memcpy8++ ) \
|
||||
out_memcpy8[i_memcpy8] = in_memcpy8[i_memcpy8]; }
|
||||
|
||||
#define MEMCPY4(dst,src,cnt) { \
|
||||
int i_memcpy4; \
|
||||
uint32_t *in_memcpy4 = (uint32_t *)(src); \
|
||||
uint32_t *out_memcpy4 = (uint32_t *)(dst); \
|
||||
for( i_memcpy4 = 0; i_memcpy4 < cnt; i_memcpy4++ ) \
|
||||
out_memcpy4[i_memcpy4] = in_memcpy4[i_memcpy4]; }
|
||||
|
||||
#define XOR_BLOCKS_DST(x,y,z) { \
|
||||
((uint64_t *)z)[0] = ((uint64_t *)(x))[0] ^ ((uint64_t *)(y))[0]; \
|
||||
((uint64_t *)z)[1] = ((uint64_t *)(x))[1] ^ ((uint64_t *)(y))[1]; }
|
||||
|
||||
#define E2I(x) ((size_t)(((*((uint64_t*)(x)) >> 4) & 0x1ffff)))
|
||||
|
||||
union hash_state {
|
||||
uint8_t b[200];
|
||||
uint64_t w[25];
|
||||
};
|
||||
|
||||
union cn_slow_hash_state {
|
||||
union hash_state hs;
|
||||
struct {
|
||||
uint8_t k[64];
|
||||
uint8_t init[INIT_SIZE_BYTE];
|
||||
};
|
||||
};
|
||||
|
||||
static inline void exit_if_cudaerror(int thr_id, const char *src, int line)
|
||||
{
|
||||
cudaError_t err = cudaGetLastError();
|
||||
if(err != cudaSuccess) {
|
||||
gpulog(LOG_ERR, thr_id, "%s %s line %d", cudaGetErrorString(err), src, line);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
void cryptonight_core_cuda(int thr_id, uint32_t blocks, uint32_t threads, uint64_t *d_long_state, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak);
|
||||
|
||||
void cryptonight_extra_setData(int thr_id, const void *data, const void *ptarget);
|
||||
void cryptonight_extra_init(int thr_id);
|
||||
void cryptonight_extra_free(int thr_id);
|
||||
void cryptonight_extra_prepare(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak);
|
||||
void cryptonight_extra_final(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *resnonce, uint32_t *d_ctx_state);
|
||||
@@ -1,573 +0,0 @@
|
||||
#ifndef UINT128_C_H
|
||||
#define UINT128_C_H
|
||||
|
||||
struct __uint128 {
|
||||
uint64_t Hi;
|
||||
uint64_t Lo;
|
||||
};
|
||||
typedef struct __uint128 uint128;
|
||||
|
||||
void Increment(uint128 * N)
|
||||
{
|
||||
uint64_t T = (N->Lo + 1);
|
||||
N->Hi += ((N->Lo ^T) & N->Lo) >> 63;
|
||||
N->Lo = T;
|
||||
}
|
||||
|
||||
void Decrement(uint128 * N)
|
||||
{
|
||||
uint64_t T = (N->Lo - 1);
|
||||
N->Hi -= ((T ^ N->Lo) & T) >> 63;
|
||||
N->Lo = T;
|
||||
}
|
||||
|
||||
void Add(uint128 * Ans, uint128 N, uint128 M)
|
||||
{
|
||||
uint64_t C = (((N.Lo & M.Lo) & 1) + (N.Lo >> 1) + (M.Lo >> 1)) >> 63;
|
||||
Ans->Hi = N.Hi + M.Hi + C;
|
||||
Ans->Lo = N.Lo + M.Lo;
|
||||
}
|
||||
|
||||
void Subtract(uint128 * Ans, uint128 N, uint128 M)
|
||||
{
|
||||
Ans->Lo = N.Lo - M.Lo;
|
||||
uint64_t C = (((Ans->Lo & M.Lo) & 1) + (M.Lo >> 1) + (Ans->Lo >> 1)) >> 63;
|
||||
Ans->Hi = N.Hi - (M.Hi + C);
|
||||
}
|
||||
|
||||
void inc128(uint128 N, uint128* A)
|
||||
{
|
||||
A->Lo = (N.Lo + 1);
|
||||
A->Hi = N.Hi + (((N.Lo ^ A->Lo) & N.Lo) >> 63);
|
||||
}
|
||||
|
||||
void dec128(uint128 N, uint128* A)
|
||||
{
|
||||
A->Lo = N.Lo - 1;
|
||||
A->Hi = N.Hi - (((A->Lo ^ N.Lo) & A->Lo) >> 63);
|
||||
}
|
||||
|
||||
void add128(uint128 N, uint128 M, uint128* A)
|
||||
{
|
||||
uint64_t C = (((N.Lo & M.Lo) & 1) + (N.Lo >> 1) + (M.Lo >> 1)) >> 63;
|
||||
A->Hi = N.Hi + M.Hi + C;
|
||||
A->Lo = N.Lo + M.Lo;
|
||||
}
|
||||
|
||||
void sub128(uint128 N, uint128 M, uint128* A)
|
||||
{
|
||||
A->Lo = N.Lo - M.Lo;
|
||||
uint64_t C = (((A->Lo & M.Lo) & 1) + (M.Lo >> 1) + (A->Lo >> 1)) >> 63;
|
||||
A->Hi = N.Hi - (M.Hi + C);
|
||||
}
|
||||
|
||||
void mult64to128(uint64_t u, uint64_t v, uint64_t * h, uint64_t *l)
|
||||
{
|
||||
uint64_t u1 = (u & 0xffffffff);
|
||||
uint64_t v1 = (v & 0xffffffff);
|
||||
uint64_t t = (u1 * v1);
|
||||
uint64_t w3 = (t & 0xffffffff);
|
||||
uint64_t k = (t >> 32);
|
||||
|
||||
u >>= 32;
|
||||
t = (u * v1) + k;
|
||||
k = (t & 0xffffffff);
|
||||
uint64_t w1 = (t >> 32);
|
||||
|
||||
v >>= 32;
|
||||
t = (u1 * v) + k;
|
||||
k = (t >> 32);
|
||||
|
||||
*h = (u * v) + w1 + k;
|
||||
*l = (t << 32) + w3;
|
||||
}
|
||||
|
||||
void mult128(uint128 N, uint128 M, uint128 * Ans)
|
||||
{
|
||||
mult64to128(N.Lo, M.Lo, &Ans->Hi, &Ans->Lo);
|
||||
Ans->Hi += (N.Hi * M.Lo) + (N.Lo * M.Hi);
|
||||
}
|
||||
|
||||
void mult128to256(uint128 N, uint128 M, uint128 * H, uint128 * L)
|
||||
{
|
||||
mult64to128(N.Hi, M.Hi, &H->Hi, &H->Lo);
|
||||
mult64to128(N.Lo, M.Lo, &L->Hi, &L->Lo);
|
||||
|
||||
uint128 T;
|
||||
mult64to128(N.Hi, M.Lo, &T.Hi, &T.Lo);
|
||||
L->Hi += T.Lo;
|
||||
if(L->Hi < T.Lo) // if L->Hi overflowed
|
||||
{
|
||||
Increment(H);
|
||||
}
|
||||
H->Lo += T.Hi;
|
||||
if(H->Lo < T.Hi) // if H->Lo overflowed
|
||||
{
|
||||
++H->Hi;
|
||||
}
|
||||
|
||||
mult64to128(N.Lo, M.Hi, &T.Hi, &T.Lo);
|
||||
L->Hi += T.Lo;
|
||||
if(L->Hi < T.Lo) // if L->Hi overflowed
|
||||
{
|
||||
Increment(H);
|
||||
}
|
||||
H->Lo += T.Hi;
|
||||
if(H->Lo < T.Hi) // if H->Lo overflowed
|
||||
{
|
||||
++H->Hi;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void sqr64to128(uint64_t r, uint64_t * h, uint64_t *l)
|
||||
{
|
||||
uint64_t r1 = (r & 0xffffffff);
|
||||
uint64_t t = (r1 * r1);
|
||||
uint64_t w3 = (t & 0xffffffff);
|
||||
uint64_t k = (t >> 32);
|
||||
|
||||
r >>= 32;
|
||||
uint64_t m = (r * r1);
|
||||
t = m + k;
|
||||
uint64_t w2 = (t & 0xffffffff);
|
||||
uint64_t w1 = (t >> 32);
|
||||
|
||||
t = m + w2;
|
||||
k = (t >> 32);
|
||||
*h = (r * r) + w1 + k;
|
||||
*l = (t << 32) + w3;
|
||||
}
|
||||
|
||||
void sqr128(uint128 R, uint128 * Ans)
|
||||
{
|
||||
sqr64to128(R.Lo, &Ans->Hi, &Ans->Lo);
|
||||
Ans->Hi += (R.Hi * R.Lo) << 1;
|
||||
}
|
||||
|
||||
void sqr128to256(uint128 R, uint128 * H, uint128 * L)
|
||||
{
|
||||
sqr64to128(R.Hi, &H->Hi, &H->Lo);
|
||||
sqr64to128(R.Lo, &L->Hi, &L->Lo);
|
||||
|
||||
uint128 T;
|
||||
mult64to128(R.Hi, R.Lo, &T.Hi, &T.Lo);
|
||||
|
||||
H->Hi += (T.Hi >> 63);
|
||||
T.Hi = (T.Hi << 1) | (T.Lo >> 63); // Shift Left 1 bit
|
||||
T.Lo <<= 1;
|
||||
|
||||
L->Hi += T.Lo;
|
||||
if(L->Hi < T.Lo) // if L->Hi overflowed
|
||||
{
|
||||
Increment(H);
|
||||
}
|
||||
|
||||
H->Lo += T.Hi;
|
||||
if(H->Lo < T.Hi) // if H->Lo overflowed
|
||||
{
|
||||
++H->Hi;
|
||||
}
|
||||
}
|
||||
|
||||
void shiftleft128(uint128 N, size_t S, uint128 * A)
|
||||
{
|
||||
uint64_t M1, M2;
|
||||
S &= 127;
|
||||
|
||||
M1 = ((((S + 127) | S) & 64) >> 6) - 1llu;
|
||||
M2 = (S >> 6) - 1llu;
|
||||
S &= 63;
|
||||
A->Hi = (N.Lo << S) & (~M2);
|
||||
A->Lo = (N.Lo << S) & M2;
|
||||
A->Hi |= ((N.Hi << S) | ((N.Lo >> (64 - S)) & M1)) & M2;
|
||||
|
||||
/*
|
||||
S &= 127;
|
||||
|
||||
if(S != 0)
|
||||
{
|
||||
if(S > 64)
|
||||
{
|
||||
A.Hi = N.Lo << (S - 64);
|
||||
A.Lo = 0;
|
||||
}
|
||||
else if(S < 64)
|
||||
{
|
||||
A.Hi = (N.Hi << S) | (N.Lo >> (64 - S));
|
||||
A.Lo = N.Lo << S;
|
||||
}
|
||||
else
|
||||
{
|
||||
A.Hi = N.Lo;
|
||||
A.Lo = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
A.Hi = N.Hi;
|
||||
A.Lo = N.Lo;
|
||||
}
|
||||
//*/
|
||||
}
|
||||
|
||||
void shiftright128(uint128 N, size_t S, uint128 * A)
|
||||
{
|
||||
uint64_t M1, M2;
|
||||
S &= 127;
|
||||
|
||||
M1 = ((((S + 127) | S) & 64) >> 6) - 1llu;
|
||||
M2 = (S >> 6) - 1llu;
|
||||
S &= 63;
|
||||
A->Lo = (N.Hi >> S) & (~M2);
|
||||
A->Hi = (N.Hi >> S) & M2;
|
||||
A->Lo |= ((N.Lo >> S) | ((N.Hi << (64 - S)) & M1)) & M2;
|
||||
|
||||
/*
|
||||
S &= 127;
|
||||
|
||||
if(S != 0)
|
||||
{
|
||||
if(S > 64)
|
||||
{
|
||||
A.Hi = N.Hi >> (S - 64);
|
||||
A.Lo = 0;
|
||||
}
|
||||
else if(S < 64)
|
||||
{
|
||||
A.Lo = (N.Lo >> S) | (N.Hi << (64 - S));
|
||||
A.Hi = N.Hi >> S;
|
||||
}
|
||||
else
|
||||
{
|
||||
A.Lo = N.Hi;
|
||||
A.Hi = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
A.Hi = N.Hi;
|
||||
A.Lo = N.Lo;
|
||||
}
|
||||
//*/
|
||||
}
|
||||
|
||||
|
||||
void not128(uint128 N, uint128 * A)
|
||||
{
|
||||
A->Hi = ~N.Hi;
|
||||
A->Lo = ~N.Lo;
|
||||
}
|
||||
|
||||
void or128(uint128 N1, uint128 N2, uint128 * A)
|
||||
{
|
||||
A->Hi = N1.Hi | N2.Hi;
|
||||
A->Lo = N1.Lo | N2.Lo;
|
||||
}
|
||||
|
||||
void and128(uint128 N1, uint128 N2, uint128 * A)
|
||||
{
|
||||
A->Hi = N1.Hi & N2.Hi;
|
||||
A->Lo = N1.Lo & N2.Lo;
|
||||
}
|
||||
|
||||
void xor128(uint128 N1, uint128 N2, uint128 * A)
|
||||
{
|
||||
A->Hi = N1.Hi ^ N2.Hi;
|
||||
A->Lo = N1.Lo ^ N2.Lo;
|
||||
}
|
||||
|
||||
size_t nlz64(uint64_t N)
|
||||
{
|
||||
uint64_t I;
|
||||
size_t C;
|
||||
|
||||
I = ~N;
|
||||
C = ((I ^ (I + 1)) & I) >> 63;
|
||||
|
||||
I = (N >> 32) + 0xffffffff;
|
||||
I = ((I & 0x100000000) ^ 0x100000000) >> 27;
|
||||
C += I; N <<= I;
|
||||
|
||||
I = (N >> 48) + 0xffff;
|
||||
I = ((I & 0x10000) ^ 0x10000) >> 12;
|
||||
C += I; N <<= I;
|
||||
|
||||
I = (N >> 56) + 0xff;
|
||||
I = ((I & 0x100) ^ 0x100) >> 5;
|
||||
C += I; N <<= I;
|
||||
|
||||
I = (N >> 60) + 0xf;
|
||||
I = ((I & 0x10) ^ 0x10) >> 2;
|
||||
C += I; N <<= I;
|
||||
|
||||
I = (N >> 62) + 3;
|
||||
I = ((I & 4) ^ 4) >> 1;
|
||||
C += I; N <<= I;
|
||||
|
||||
C += (N >> 63) ^ 1;
|
||||
|
||||
return C;
|
||||
}
|
||||
|
||||
size_t ntz64(uint64_t N)
|
||||
{
|
||||
uint64_t I = ~N;
|
||||
size_t C = ((I ^ (I + 1)) & I) >> 63;
|
||||
|
||||
I = (N & 0xffffffff) + 0xffffffff;
|
||||
I = ((I & 0x100000000) ^ 0x100000000) >> 27;
|
||||
C += I; N >>= I;
|
||||
|
||||
I = (N & 0xffff) + 0xffff;
|
||||
I = ((I & 0x10000) ^ 0x10000) >> 12;
|
||||
C += I; N >>= I;
|
||||
|
||||
I = (N & 0xff) + 0xff;
|
||||
I = ((I & 0x100) ^ 0x100) >> 5;
|
||||
C += I; N >>= I;
|
||||
|
||||
I = (N & 0xf) + 0xf;
|
||||
I = ((I & 0x10) ^ 0x10) >> 2;
|
||||
C += I; N >>= I;
|
||||
|
||||
I = (N & 3) + 3;
|
||||
I = ((I & 4) ^ 4) >> 1;
|
||||
C += I; N >>= I;
|
||||
|
||||
C += ((N & 1) ^ 1);
|
||||
|
||||
return C;
|
||||
}
|
||||
|
||||
size_t popcnt64(uint64_t V)
|
||||
{
|
||||
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
||||
V -= ((V >> 1) & 0x5555555555555555);
|
||||
V = (V & 0x3333333333333333) + ((V >> 2) & 0x3333333333333333);
|
||||
return ((V + (V >> 4) & 0xF0F0F0F0F0F0F0F) * 0x101010101010101) >> 56;
|
||||
}
|
||||
|
||||
size_t popcnt128(uint128 N)
|
||||
{
|
||||
return popcnt64(N.Hi) + popcnt64(N.Lo);
|
||||
}
|
||||
|
||||
|
||||
size_t nlz128(uint128 N)
|
||||
{
|
||||
return (N.Hi == 0) ? nlz64(N.Lo) + 64 : nlz64(N.Hi);
|
||||
}
|
||||
|
||||
size_t ntz128(uint128 N)
|
||||
{
|
||||
return (N.Lo == 0) ? ntz64(N.Hi) + 64 : ntz64(N.Lo);
|
||||
}
|
||||
int compare128(uint128 N1, uint128 N2)
|
||||
{
|
||||
return (((N1.Hi > N2.Hi) || ((N1.Hi == N2.Hi) && (N1.Lo > N2.Lo))) ? 1 : 0)
|
||||
- (((N1.Hi < N2.Hi) || ((N1.Hi == N2.Hi) && (N1.Lo < N2.Lo))) ? 1 : 0);
|
||||
}
|
||||
|
||||
void bindivmod128(uint128 M, uint128 N, uint128 * Q, uint128 *R)
|
||||
{
|
||||
Q->Hi = Q->Lo = 0;
|
||||
size_t Shift = nlz128(N) - nlz128(M);
|
||||
shiftleft128(N, Shift, &N);
|
||||
|
||||
do
|
||||
{
|
||||
shiftleft128(*Q, (size_t)1, Q);
|
||||
if(compare128(M, N) >= 0)
|
||||
{
|
||||
sub128(M, N, &M);
|
||||
Q->Lo |= 1;
|
||||
}
|
||||
|
||||
shiftright128(N, 1, &N);
|
||||
}while(Shift-- != 0);
|
||||
|
||||
R->Hi = M.Hi;
|
||||
R->Lo = M.Lo;
|
||||
}
|
||||
|
||||
void divmod128by64(const uint64_t u1, const uint64_t u0, uint64_t v, uint64_t * q, uint64_t * r)
|
||||
{
|
||||
const uint64_t b = 1ll << 32;
|
||||
uint64_t un1, un0, vn1, vn0, q1, q0, un32, un21, un10, rhat, left, right;
|
||||
size_t s;
|
||||
|
||||
s = nlz64(v);
|
||||
v <<= s;
|
||||
vn1 = v >> 32;
|
||||
vn0 = v & 0xffffffff;
|
||||
|
||||
if (s > 0)
|
||||
{
|
||||
un32 = (u1 << s) | (u0 >> (64 - s));
|
||||
un10 = u0 << s;
|
||||
}
|
||||
else
|
||||
{
|
||||
un32 = u1;
|
||||
un10 = u0;
|
||||
}
|
||||
|
||||
un1 = un10 >> 32;
|
||||
un0 = un10 & 0xffffffff;
|
||||
|
||||
q1 = un32 / vn1;
|
||||
rhat = un32 % vn1;
|
||||
|
||||
left = q1 * vn0;
|
||||
right = (rhat << 32) + un1;
|
||||
again1:
|
||||
if ((q1 >= b) || (left > right))
|
||||
{
|
||||
--q1;
|
||||
rhat += vn1;
|
||||
if (rhat < b)
|
||||
{
|
||||
left -= vn0;
|
||||
right = (rhat << 32) | un1;
|
||||
goto again1;
|
||||
}
|
||||
}
|
||||
|
||||
un21 = (un32 << 32) + (un1 - (q1 * v));
|
||||
|
||||
q0 = un21 / vn1;
|
||||
rhat = un21 % vn1;
|
||||
|
||||
left = q0 * vn0;
|
||||
right = (rhat << 32) | un0;
|
||||
again2:
|
||||
if ((q0 >= b) || (left > right))
|
||||
{
|
||||
--q0;
|
||||
rhat += vn1;
|
||||
if (rhat < b)
|
||||
{
|
||||
left -= vn0;
|
||||
right = (rhat << 32) | un0;
|
||||
goto again2;
|
||||
}
|
||||
}
|
||||
|
||||
*r = ((un21 << 32) + (un0 - (q0 * v))) >> s;
|
||||
*q = (q1 << 32) | q0;
|
||||
}
|
||||
|
||||
static void divmod128by128(uint128 M, uint128 N, uint128 * Q, uint128 * R)
|
||||
{
|
||||
if (N.Hi == 0)
|
||||
{
|
||||
if (M.Hi < N.Lo)
|
||||
{
|
||||
divmod128by64(M.Hi, M.Lo, N.Lo, &Q->Lo, &R->Lo);
|
||||
Q->Hi = 0;
|
||||
R->Hi = 0;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Q->Hi = M.Hi / N.Lo;
|
||||
R->Hi = M.Hi % N.Lo;
|
||||
divmod128by64(R->Hi, M.Lo, N.Lo, &Q->Lo, &R->Lo);
|
||||
R->Hi = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t n = nlz64(N.Hi);
|
||||
|
||||
uint128 v1;
|
||||
shiftleft128(N, n, &v1);
|
||||
|
||||
uint128 u1;
|
||||
shiftright128(M, 1, &u1);
|
||||
|
||||
uint128 q1;
|
||||
divmod128by64(u1.Hi, u1.Lo, v1.Hi, &q1.Hi, &q1.Lo);
|
||||
q1.Hi = 0;
|
||||
shiftright128(q1, 63 - n, &q1);
|
||||
|
||||
if ((q1.Hi | q1.Lo) != 0)
|
||||
{
|
||||
dec128(q1, &q1);
|
||||
}
|
||||
|
||||
Q->Hi = q1.Hi;
|
||||
Q->Lo = q1.Lo;
|
||||
mult128(q1, N, &q1);
|
||||
sub128(M, q1, R);
|
||||
|
||||
if (compare128(*R, N) >= 0)
|
||||
{
|
||||
inc128(*Q, Q);
|
||||
sub128(*R, N, R);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void divmod128(uint128 M, uint128 N, uint128 * Q, uint128 * R)
|
||||
{
|
||||
size_t Nlz, Mlz, Ntz;
|
||||
int C;
|
||||
|
||||
Nlz = nlz128(N);
|
||||
Mlz = nlz128(M);
|
||||
Ntz = ntz128(N);
|
||||
|
||||
if(Nlz == 128)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if((M.Hi | N.Hi) == 0)
|
||||
{
|
||||
Q->Hi = R->Hi = 0;
|
||||
Q->Lo = M.Lo / N.Lo;
|
||||
R->Lo = M.Lo % N.Lo;
|
||||
return;
|
||||
}
|
||||
else if(Nlz == 127)
|
||||
{
|
||||
*Q = M;
|
||||
R->Hi = R->Lo = 0;
|
||||
return;
|
||||
}
|
||||
else if((Ntz + Nlz) == 127)
|
||||
{
|
||||
shiftright128(M, Ntz, Q);
|
||||
dec128(N, &N);
|
||||
and128(N, M, R);
|
||||
return;
|
||||
}
|
||||
|
||||
C = compare128(M, N);
|
||||
if(C < 0)
|
||||
{
|
||||
Q->Hi = Q->Lo = 0;
|
||||
*R = M;
|
||||
return;
|
||||
}
|
||||
else if(C == 0)
|
||||
{
|
||||
Q->Hi = R->Hi = R->Lo = 0;
|
||||
Q->Lo = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if((Nlz - Mlz) > 5)
|
||||
{
|
||||
divmod128by128(M, N, Q, R);
|
||||
}
|
||||
else
|
||||
{
|
||||
bindivmod128(M, N, Q, R);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
-180
@@ -1,180 +0,0 @@
|
||||
|
||||
#include <windows.h>
|
||||
#include <errno.h>
|
||||
#include <io.h>
|
||||
|
||||
#include "mman.h"
|
||||
|
||||
#ifndef FILE_MAP_EXECUTE
|
||||
#define FILE_MAP_EXECUTE 0x0020
|
||||
#endif /* FILE_MAP_EXECUTE */
|
||||
|
||||
static int __map_mman_error(const DWORD err, const int deferr)
|
||||
{
|
||||
if (err == 0)
|
||||
return 0;
|
||||
//TODO: implement
|
||||
return err;
|
||||
}
|
||||
|
||||
static DWORD __map_mmap_prot_page(const int prot)
|
||||
{
|
||||
DWORD protect = 0;
|
||||
|
||||
if (prot == PROT_NONE)
|
||||
return protect;
|
||||
|
||||
if ((prot & PROT_EXEC) != 0)
|
||||
{
|
||||
protect = ((prot & PROT_WRITE) != 0) ?
|
||||
PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ;
|
||||
}
|
||||
else
|
||||
{
|
||||
protect = ((prot & PROT_WRITE) != 0) ?
|
||||
PAGE_READWRITE : PAGE_READONLY;
|
||||
}
|
||||
|
||||
return protect;
|
||||
}
|
||||
|
||||
static DWORD __map_mmap_prot_file(const int prot)
|
||||
{
|
||||
DWORD desiredAccess = 0;
|
||||
|
||||
if (prot == PROT_NONE)
|
||||
return desiredAccess;
|
||||
|
||||
if ((prot & PROT_READ) != 0)
|
||||
desiredAccess |= FILE_MAP_READ;
|
||||
if ((prot & PROT_WRITE) != 0)
|
||||
desiredAccess |= FILE_MAP_WRITE;
|
||||
if ((prot & PROT_EXEC) != 0)
|
||||
desiredAccess |= FILE_MAP_EXECUTE;
|
||||
|
||||
return desiredAccess;
|
||||
}
|
||||
|
||||
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, OffsetType off)
|
||||
{
|
||||
HANDLE fm, h;
|
||||
|
||||
void * map = MAP_FAILED;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4293)
|
||||
#endif
|
||||
|
||||
const DWORD dwFileOffsetLow = (sizeof(OffsetType) <= sizeof(DWORD)) ?
|
||||
(DWORD)off : (DWORD)(off & 0xFFFFFFFFL);
|
||||
const DWORD dwFileOffsetHigh = (sizeof(OffsetType) <= sizeof(DWORD)) ?
|
||||
(DWORD)0 : (DWORD)((off >> 32) & 0xFFFFFFFFL);
|
||||
const DWORD protect = __map_mmap_prot_page(prot);
|
||||
const DWORD desiredAccess = __map_mmap_prot_file(prot);
|
||||
|
||||
const OffsetType maxSize = off + (OffsetType)len;
|
||||
|
||||
const DWORD dwMaxSizeLow = (sizeof(OffsetType) <= sizeof(DWORD)) ?
|
||||
(DWORD)maxSize : (DWORD)(maxSize & 0xFFFFFFFFL);
|
||||
const DWORD dwMaxSizeHigh = (sizeof(OffsetType) <= sizeof(DWORD)) ?
|
||||
(DWORD)0 : (DWORD)((maxSize >> 32) & 0xFFFFFFFFL);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
errno = 0;
|
||||
|
||||
if (len == 0
|
||||
/* Unsupported flag combinations */
|
||||
|| (flags & MAP_FIXED) != 0
|
||||
/* Usupported protection combinations */
|
||||
|| prot == PROT_EXEC)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
h = ((flags & MAP_ANONYMOUS) == 0) ?
|
||||
(HANDLE)_get_osfhandle(fildes) : INVALID_HANDLE_VALUE;
|
||||
|
||||
if ((flags & MAP_ANONYMOUS) == 0 && h == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
errno = EBADF;
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
fm = CreateFileMapping(h, NULL, protect, dwMaxSizeHigh, dwMaxSizeLow, NULL);
|
||||
|
||||
if (fm == NULL)
|
||||
{
|
||||
errno = __map_mman_error(GetLastError(), EPERM);
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
map = MapViewOfFile(fm, desiredAccess, dwFileOffsetHigh, dwFileOffsetLow, len);
|
||||
|
||||
CloseHandle(fm);
|
||||
|
||||
if (map == NULL)
|
||||
{
|
||||
errno = __map_mman_error(GetLastError(), EPERM);
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
int munmap(void *addr, size_t len)
|
||||
{
|
||||
if (UnmapViewOfFile(addr))
|
||||
return 0;
|
||||
|
||||
errno = __map_mman_error(GetLastError(), EPERM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _mprotect(void *addr, size_t len, int prot)
|
||||
{
|
||||
DWORD newProtect = __map_mmap_prot_page(prot);
|
||||
DWORD oldProtect = 0;
|
||||
|
||||
if (VirtualProtect(addr, len, newProtect, &oldProtect))
|
||||
return 0;
|
||||
|
||||
errno = __map_mman_error(GetLastError(), EPERM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int msync(void *addr, size_t len, int flags)
|
||||
{
|
||||
if (FlushViewOfFile(addr, len))
|
||||
return 0;
|
||||
|
||||
errno = __map_mman_error(GetLastError(), EPERM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mlock(const void *addr, size_t len)
|
||||
{
|
||||
if (VirtualLock((LPVOID)addr, len))
|
||||
return 0;
|
||||
|
||||
errno = __map_mman_error(GetLastError(), EPERM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int munlock(const void *addr, size_t len)
|
||||
{
|
||||
if (VirtualUnlock((LPVOID)addr, len))
|
||||
return 0;
|
||||
|
||||
errno = __map_mman_error(GetLastError(), EPERM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* sys/mman.h
|
||||
* mman-win32
|
||||
*/
|
||||
|
||||
#ifndef _SYS_MMAN_H_
|
||||
#define _SYS_MMAN_H_
|
||||
|
||||
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
|
||||
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
|
||||
#endif
|
||||
|
||||
/* All the headers include this file. */
|
||||
#ifndef _MSC_VER
|
||||
#include <_mingw.h>
|
||||
#endif
|
||||
|
||||
/* Determine offset type */
|
||||
#include <stdint.h>
|
||||
#if defined(_WIN64)
|
||||
typedef int64_t OffsetType;
|
||||
#else
|
||||
typedef uint32_t OffsetType;
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PROT_NONE 0
|
||||
#define PROT_READ 1
|
||||
#define PROT_WRITE 2
|
||||
#define PROT_EXEC 4
|
||||
|
||||
#define MAP_FILE 0
|
||||
#define MAP_SHARED 1
|
||||
#define MAP_PRIVATE 2
|
||||
#define MAP_TYPE 0xf
|
||||
#define MAP_FIXED 0x10
|
||||
#define MAP_ANONYMOUS 0x20
|
||||
#define MAP_ANON MAP_ANONYMOUS
|
||||
|
||||
#define MAP_FAILED ((void *)-1)
|
||||
|
||||
/* Flags for msync. */
|
||||
#define MS_ASYNC 1
|
||||
#define MS_SYNC 2
|
||||
#define MS_INVALIDATE 4
|
||||
|
||||
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, OffsetType off);
|
||||
int munmap(void *addr, size_t len);
|
||||
int _mprotect(void *addr, size_t len, int prot);
|
||||
int msync(void *addr, size_t len, int flags);
|
||||
int mlock(const void *addr, size_t len);
|
||||
int munlock(const void *addr, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_MMAN_H_ */
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* ---------------------------------------------------------------------------
|
||||
* OpenAES License
|
||||
* ---------------------------------------------------------------------------
|
||||
* Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef _OAES_CONFIG_H
|
||||
#define _OAES_CONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//#ifndef OAES_HAVE_ISAAC
|
||||
//#define OAES_HAVE_ISAAC 1
|
||||
//#endif // OAES_HAVE_ISAAC
|
||||
|
||||
//#ifndef OAES_DEBUG
|
||||
//#define OAES_DEBUG 0
|
||||
//#endif // OAES_DEBUG
|
||||
//#define OAES_DEBUG 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _OAES_CONFIG_H
|
||||
-1447
File diff suppressed because it is too large.
Load diff
@@ -1,214 +0,0 @@
|
||||
/*
|
||||
* ---------------------------------------------------------------------------
|
||||
* OpenAES License
|
||||
* ---------------------------------------------------------------------------
|
||||
* Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef _OAES_LIB_H
|
||||
#define _OAES_LIB_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifdef OAES_SHARED
|
||||
# ifdef oaes_lib_EXPORTS
|
||||
# define OAES_API __declspec(dllexport)
|
||||
# else
|
||||
# define OAES_API __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define OAES_API
|
||||
# endif
|
||||
#else
|
||||
# define OAES_API
|
||||
#endif // WIN32
|
||||
|
||||
#define OAES_VERSION "0.8.1"
|
||||
#define OAES_BLOCK_SIZE 16
|
||||
|
||||
typedef void OAES_CTX;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OAES_RET_FIRST = 0,
|
||||
OAES_RET_SUCCESS = 0,
|
||||
OAES_RET_UNKNOWN,
|
||||
OAES_RET_ARG1,
|
||||
OAES_RET_ARG2,
|
||||
OAES_RET_ARG3,
|
||||
OAES_RET_ARG4,
|
||||
OAES_RET_ARG5,
|
||||
OAES_RET_NOKEY,
|
||||
OAES_RET_MEM,
|
||||
OAES_RET_BUF,
|
||||
OAES_RET_HEADER,
|
||||
OAES_RET_COUNT
|
||||
} OAES_RET;
|
||||
|
||||
/*
|
||||
* oaes_set_option() takes one of these values for its [option] parameter
|
||||
* some options accept either an optional or a required [value] parameter
|
||||
*/
|
||||
// no option
|
||||
#define OAES_OPTION_NONE 0
|
||||
// enable ECB mode, disable CBC mode
|
||||
#define OAES_OPTION_ECB 1
|
||||
// enable CBC mode, disable ECB mode
|
||||
// value is optional, may pass uint8_t iv[OAES_BLOCK_SIZE] to specify
|
||||
// the value of the initialization vector, iv
|
||||
#define OAES_OPTION_CBC 2
|
||||
|
||||
#ifdef OAES_DEBUG
|
||||
typedef int ( * oaes_step_cb ) (
|
||||
const uint8_t state[OAES_BLOCK_SIZE],
|
||||
const char * step_name,
|
||||
int step_count,
|
||||
void * user_data );
|
||||
// enable state stepping mode
|
||||
// value is required, must pass oaes_step_cb to receive the state at each step
|
||||
#define OAES_OPTION_STEP_ON 4
|
||||
// disable state stepping mode
|
||||
#define OAES_OPTION_STEP_OFF 8
|
||||
#endif // OAES_DEBUG
|
||||
|
||||
typedef uint16_t OAES_OPTION;
|
||||
|
||||
typedef struct _oaes_key
|
||||
{
|
||||
size_t data_len;
|
||||
uint8_t *data;
|
||||
size_t exp_data_len;
|
||||
uint8_t *exp_data;
|
||||
size_t num_keys;
|
||||
size_t key_base;
|
||||
} oaes_key;
|
||||
|
||||
typedef struct _oaes_ctx
|
||||
{
|
||||
#ifdef OAES_HAVE_ISAAC
|
||||
randctx * rctx;
|
||||
#endif // OAES_HAVE_ISAAC
|
||||
|
||||
#ifdef OAES_DEBUG
|
||||
oaes_step_cb step_cb;
|
||||
#endif // OAES_DEBUG
|
||||
|
||||
oaes_key * key;
|
||||
OAES_OPTION options;
|
||||
uint8_t iv[OAES_BLOCK_SIZE];
|
||||
} oaes_ctx;
|
||||
/*
|
||||
* // usage:
|
||||
*
|
||||
* OAES_CTX * ctx = oaes_alloc();
|
||||
* .
|
||||
* .
|
||||
* .
|
||||
* {
|
||||
* oaes_gen_key_xxx( ctx );
|
||||
* {
|
||||
* oaes_key_export( ctx, _buf, &_buf_len );
|
||||
* // or
|
||||
* oaes_key_export_data( ctx, _buf, &_buf_len );\
|
||||
* }
|
||||
* }
|
||||
* // or
|
||||
* {
|
||||
* oaes_key_import( ctx, _buf, _buf_len );
|
||||
* // or
|
||||
* oaes_key_import_data( ctx, _buf, _buf_len );
|
||||
* }
|
||||
* .
|
||||
* .
|
||||
* .
|
||||
* oaes_encrypt( ctx, m, m_len, c, &c_len );
|
||||
* .
|
||||
* .
|
||||
* .
|
||||
* oaes_decrypt( ctx, c, c_len, m, &m_len );
|
||||
* .
|
||||
* .
|
||||
* .
|
||||
* oaes_free( &ctx );
|
||||
*/
|
||||
|
||||
OAES_API OAES_CTX * oaes_alloc(void);
|
||||
|
||||
OAES_API OAES_RET oaes_free( OAES_CTX ** ctx );
|
||||
|
||||
OAES_API OAES_RET oaes_set_option( OAES_CTX * ctx,
|
||||
OAES_OPTION option, const void * value );
|
||||
|
||||
OAES_API OAES_RET oaes_key_gen_128( OAES_CTX * ctx );
|
||||
|
||||
OAES_API OAES_RET oaes_key_gen_192( OAES_CTX * ctx );
|
||||
|
||||
OAES_API OAES_RET oaes_key_gen_256( OAES_CTX * ctx );
|
||||
|
||||
// export key with header information
|
||||
// set data == NULL to get the required data_len
|
||||
OAES_API OAES_RET oaes_key_export( OAES_CTX * ctx,
|
||||
uint8_t * data, size_t * data_len );
|
||||
|
||||
// directly export the data from key
|
||||
// set data == NULL to get the required data_len
|
||||
OAES_API OAES_RET oaes_key_export_data( OAES_CTX * ctx,
|
||||
uint8_t * data, size_t * data_len );
|
||||
|
||||
// import key with header information
|
||||
OAES_API OAES_RET oaes_key_import( OAES_CTX * ctx,
|
||||
const uint8_t * data, size_t data_len );
|
||||
|
||||
// directly import data into key
|
||||
OAES_API OAES_RET oaes_key_import_data( OAES_CTX * ctx,
|
||||
const uint8_t * data, size_t data_len );
|
||||
|
||||
// set c == NULL to get the required c_len
|
||||
OAES_API OAES_RET oaes_encrypt( OAES_CTX * ctx,
|
||||
const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len );
|
||||
|
||||
// set m == NULL to get the required m_len
|
||||
OAES_API OAES_RET oaes_decrypt( OAES_CTX * ctx,
|
||||
const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len );
|
||||
|
||||
// set buf == NULL to get the required buf_len
|
||||
OAES_API OAES_RET oaes_sprintf(
|
||||
char * buf, size_t * buf_len, const uint8_t * data, size_t data_len );
|
||||
|
||||
OAES_API OAES_RET oaes_encryption_round( const uint8_t * key, uint8_t * c );
|
||||
|
||||
OAES_API OAES_RET oaes_pseudo_encrypt_ecb( OAES_CTX * ctx, uint8_t * c );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _OAES_LIB_H
|
||||
@@ -1,376 +0,0 @@
|
||||
// Memory-hard extension of keccak for PoW
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Copyright (c) 2014 The Boolberry developers
|
||||
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
// Modified for CPUminer by Lucas Jones
|
||||
// Adapted for ccminer by Tanguy Pruvot - 2016
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <emmintrin.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
#include "compat/bignum_ssl10.hpp"
|
||||
#else
|
||||
#include "bignum.hpp"
|
||||
#endif
|
||||
#include "int128_c.h"
|
||||
#else
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
|
||||
#include <miner.h>
|
||||
|
||||
#include "xmr-rpc.h"
|
||||
|
||||
extern uint64_t* pscratchpad_buff;
|
||||
|
||||
struct reciprocal_value64 {
|
||||
uint64_t m;
|
||||
uint8_t sh1, sh2;
|
||||
};
|
||||
|
||||
static inline int fls64(uint64_t x)
|
||||
{
|
||||
#if defined(_WIN64)
|
||||
unsigned long bitpos = 0;
|
||||
_BitScanReverse64(&bitpos, x);
|
||||
return (int) (bitpos + 1);
|
||||
#elif defined(WIN32)
|
||||
unsigned long hipos = 0, bitpos = 0;
|
||||
uint32_t hi = x >> 32;
|
||||
_BitScanReverse(&hipos, hi);
|
||||
if (!hipos) {
|
||||
_BitScanReverse(&bitpos, (uint32_t) x);
|
||||
}
|
||||
return (int) hipos ? hipos + 33 : bitpos + 1;
|
||||
#else
|
||||
/*
|
||||
* AMD64 says BSRQ won't clobber the dest reg if x==0; Intel64 says the
|
||||
* dest reg is undefined if x==0, but their CPU architect says its
|
||||
* value is written to set it to the same as before.
|
||||
*/
|
||||
register long bitpos = -1;
|
||||
asm("bsrq %1,%0" : "+r" (bitpos) : "rm" (x));
|
||||
return bitpos + 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline struct reciprocal_value64 reciprocal_val64(uint64_t d)
|
||||
{
|
||||
struct reciprocal_value64 R;
|
||||
int l;
|
||||
|
||||
l = fls64(d - 1);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
uint128 v1;
|
||||
v1.Lo = (1ULL << l) - d;v1.Hi=0;
|
||||
uint128 v2;
|
||||
v2.Hi = 1; v2.Lo = 0;
|
||||
|
||||
uint128 v;
|
||||
mult128(v1,v2,&v);
|
||||
divmod128by64(v.Hi,v.Lo,d,&v.Hi,&v.Lo);
|
||||
Increment(&v);
|
||||
R.m = (uint64_t)v.Hi;
|
||||
#else
|
||||
__uint128_t m;
|
||||
m = (((__uint128_t)1 << 64) * ((1ULL << l) - d));
|
||||
m /= d;
|
||||
++m;
|
||||
R.m = (uint64_t)m;
|
||||
#endif
|
||||
|
||||
R.sh1 = min(l, 1);
|
||||
R.sh2 = max(l - 1, 0);
|
||||
|
||||
return R;
|
||||
}
|
||||
|
||||
static inline uint64_t reciprocal_divide64(uint64_t a, struct reciprocal_value64 R)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
uint128 v;
|
||||
mult64to128(a,R.m,&v.Hi,&v.Lo);
|
||||
uint64_t t = v.Hi;
|
||||
#else
|
||||
uint64_t t = (uint64_t)(((__uint128_t)a * R.m) >> 64);
|
||||
#endif
|
||||
return (t + ((a - t) >> R.sh1)) >> R.sh2;
|
||||
}
|
||||
|
||||
static inline uint64_t reciprocal_remainder64(uint64_t A, uint64_t B, struct reciprocal_value64 R)
|
||||
{
|
||||
uint64_t div, mod;
|
||||
|
||||
div = reciprocal_divide64(A, R);
|
||||
mod = A - (uint64_t) (div * B);
|
||||
if (mod >= B) mod -= B;
|
||||
return mod;
|
||||
}
|
||||
|
||||
//#define UNROLL_SCR_MIX
|
||||
|
||||
static inline uint64_t rotl641(uint64_t x) { return((x << 1) | (x >> 63)); }
|
||||
static inline uint64_t rotl64_1(uint64_t x, uint64_t y) { return((x << y) | (x >> (64 - y))); }
|
||||
static inline uint64_t rotl64_2(uint64_t x, uint64_t y) { return(rotl64_1((x >> 32) | (x << 32), y)); }
|
||||
static inline uint64_t bitselect(uint64_t a, uint64_t b, uint64_t c) { return(a ^ (c & (b ^ a))); }
|
||||
|
||||
static inline void keccakf_mul(uint64_t *s)
|
||||
{
|
||||
uint64_t bc[5], t[5];
|
||||
uint64_t tmp1, tmp2;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 5; i++)
|
||||
t[i] = s[i + 0] ^ s[i + 5] ^ s[i + 10] * s[i + 15] * s[i + 20];
|
||||
|
||||
bc[0] = t[0] ^ rotl641(t[2]);
|
||||
bc[1] = t[1] ^ rotl641(t[3]);
|
||||
bc[2] = t[2] ^ rotl641(t[4]);
|
||||
bc[3] = t[3] ^ rotl641(t[0]);
|
||||
bc[4] = t[4] ^ rotl641(t[1]);
|
||||
|
||||
tmp1 = s[1] ^ bc[0];
|
||||
|
||||
s[ 0] ^= bc[4];
|
||||
s[ 1] = rotl64_1(s[ 6] ^ bc[0], 44);
|
||||
s[ 6] = rotl64_1(s[ 9] ^ bc[3], 20);
|
||||
s[ 9] = rotl64_1(s[22] ^ bc[1], 61);
|
||||
s[22] = rotl64_1(s[14] ^ bc[3], 39);
|
||||
s[14] = rotl64_1(s[20] ^ bc[4], 18);
|
||||
s[20] = rotl64_1(s[ 2] ^ bc[1], 62);
|
||||
s[ 2] = rotl64_1(s[12] ^ bc[1], 43);
|
||||
s[12] = rotl64_1(s[13] ^ bc[2], 25);
|
||||
s[13] = rotl64_1(s[19] ^ bc[3], 8);
|
||||
s[19] = rotl64_1(s[23] ^ bc[2], 56);
|
||||
s[23] = rotl64_1(s[15] ^ bc[4], 41);
|
||||
s[15] = rotl64_1(s[ 4] ^ bc[3], 27);
|
||||
s[ 4] = rotl64_1(s[24] ^ bc[3], 14);
|
||||
s[24] = rotl64_1(s[21] ^ bc[0], 2);
|
||||
s[21] = rotl64_1(s[ 8] ^ bc[2], 55);
|
||||
s[ 8] = rotl64_1(s[16] ^ bc[0], 45);
|
||||
s[16] = rotl64_1(s[ 5] ^ bc[4], 36);
|
||||
s[ 5] = rotl64_1(s[ 3] ^ bc[2], 28);
|
||||
s[ 3] = rotl64_1(s[18] ^ bc[2], 21);
|
||||
s[18] = rotl64_1(s[17] ^ bc[1], 15);
|
||||
s[17] = rotl64_1(s[11] ^ bc[0], 10);
|
||||
s[11] = rotl64_1(s[ 7] ^ bc[1], 6);
|
||||
s[ 7] = rotl64_1(s[10] ^ bc[4], 3);
|
||||
s[10] = rotl64_1(tmp1, 1);
|
||||
|
||||
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1);
|
||||
tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1);
|
||||
tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1);
|
||||
tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1);
|
||||
tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1);
|
||||
|
||||
s[0] ^= 0x0000000000000001ULL;
|
||||
}
|
||||
|
||||
static inline void keccakf_mul_last(uint64_t *s)
|
||||
{
|
||||
uint64_t bc[5], xormul[5];
|
||||
uint64_t tmp1, tmp2;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 5; i++)
|
||||
xormul[i] = s[i + 0] ^ s[i + 5] ^ s[i + 10] * s[i + 15] * s[i + 20];
|
||||
|
||||
bc[0] = xormul[0] ^ rotl641(xormul[2]);
|
||||
bc[1] = xormul[1] ^ rotl641(xormul[3]);
|
||||
bc[2] = xormul[2] ^ rotl641(xormul[4]);
|
||||
bc[3] = xormul[3] ^ rotl641(xormul[0]);
|
||||
bc[4] = xormul[4] ^ rotl641(xormul[1]);
|
||||
|
||||
s[0] ^= bc[4];
|
||||
s[1] = rotl64_2(s[6] ^ bc[0], 12);
|
||||
s[2] = rotl64_2(s[12] ^ bc[1], 11);
|
||||
s[4] = rotl64_1(s[24] ^ bc[3], 14);
|
||||
s[3] = rotl64_1(s[18] ^ bc[2], 21);
|
||||
|
||||
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]);
|
||||
s[0] ^= 0x0000000000000001ULL;
|
||||
}
|
||||
|
||||
struct reciprocal_value64 cached_recip;
|
||||
static uint64_t cached_scr_size = 0;
|
||||
|
||||
static inline void scr_mix(uint64_t *st, uint64_t scr_size, struct reciprocal_value64 recip)
|
||||
{
|
||||
#define KK_MIXIN_SIZE 24
|
||||
uint64_t _ALIGN(128) idx[KK_MIXIN_SIZE];
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define pscr pscratchpad_buff
|
||||
int x;
|
||||
|
||||
// non-optimized 64bit operations
|
||||
for (x = 0; x < KK_MIXIN_SIZE; x++) {
|
||||
idx[x] = reciprocal_remainder64(st[x], scr_size, recip) << 2;
|
||||
}
|
||||
if (idx[7] > scr_size*4) {
|
||||
applog(LOG_WARNING, "Wrong remainder64 returned by the cpu hash %016llx > %016llx",
|
||||
(unsigned long long) idx[7], (unsigned long long) scr_size*4);
|
||||
return;
|
||||
}
|
||||
for(x = 0; x < KK_MIXIN_SIZE; x += 4) {
|
||||
st[x + 0] ^= pscr[idx[x] + 0] ^ pscr[idx[x + 1] + 0] ^ pscr[idx[x + 2] + 0] ^ pscr[idx[x + 3] + 0];
|
||||
st[x + 1] ^= pscr[idx[x] + 1] ^ pscr[idx[x + 1] + 1] ^ pscr[idx[x + 2] + 1] ^ pscr[idx[x + 3] + 1];
|
||||
st[x + 2] ^= pscr[idx[x] + 2] ^ pscr[idx[x + 1] + 2] ^ pscr[idx[x + 2] + 2] ^ pscr[idx[x + 3] + 2];
|
||||
st[x + 3] ^= pscr[idx[x] + 3] ^ pscr[idx[x + 1] + 3] ^ pscr[idx[x + 2] + 3] ^ pscr[idx[x + 3] + 3];
|
||||
}
|
||||
return;
|
||||
|
||||
#elif !defined(UNROLL_SCR_MIX)
|
||||
|
||||
#pragma GCC ivdep
|
||||
for(int x = 0; x < 3; ++x)
|
||||
{
|
||||
__m128i *st0, *st1, *st2, *st3;
|
||||
|
||||
idx[0] = reciprocal_remainder64(st[(x << 3) + 0], scr_size, recip) << 2;
|
||||
idx[1] = reciprocal_remainder64(st[(x << 3) + 1], scr_size, recip) << 2;
|
||||
idx[2] = reciprocal_remainder64(st[(x << 3) + 2], scr_size, recip) << 2;
|
||||
idx[3] = reciprocal_remainder64(st[(x << 3) + 3], scr_size, recip) << 2;
|
||||
idx[4] = reciprocal_remainder64(st[(x << 3) + 4], scr_size, recip) << 2;
|
||||
idx[5] = reciprocal_remainder64(st[(x << 3) + 5], scr_size, recip) << 2;
|
||||
idx[6] = reciprocal_remainder64(st[(x << 3) + 6], scr_size, recip) << 2;
|
||||
idx[7] = reciprocal_remainder64(st[(x << 3) + 7], scr_size, recip) << 2;
|
||||
|
||||
for(int y = 0; y < 8; y++) _mm_prefetch((const char*) (&pscratchpad_buff[idx[y]]), _MM_HINT_T1);
|
||||
|
||||
st0 = (__m128i *)&st[(x << 3) + 0];
|
||||
st1 = (__m128i *)&st[(x << 3) + 2];
|
||||
st2 = (__m128i *)&st[(x << 3) + 4];
|
||||
st3 = (__m128i *)&st[(x << 3) + 6];
|
||||
|
||||
*st0 = _mm_xor_si128(*st0, *((__m128i *)&pscratchpad_buff[idx[0]]));
|
||||
*st0 = _mm_xor_si128(*st0, *((__m128i *)&pscratchpad_buff[idx[1]]));
|
||||
*st0 = _mm_xor_si128(*st0, *((__m128i *)&pscratchpad_buff[idx[2]]));
|
||||
*st0 = _mm_xor_si128(*st0, *((__m128i *)&pscratchpad_buff[idx[3]]));
|
||||
|
||||
*st1 = _mm_xor_si128(*st1, *((__m128i *)&pscratchpad_buff[idx[0] + 2]));
|
||||
*st1 = _mm_xor_si128(*st1, *((__m128i *)&pscratchpad_buff[idx[1] + 2]));
|
||||
*st1 = _mm_xor_si128(*st1, *((__m128i *)&pscratchpad_buff[idx[2] + 2]));
|
||||
*st1 = _mm_xor_si128(*st1, *((__m128i *)&pscratchpad_buff[idx[3] + 2]));
|
||||
|
||||
*st2 = _mm_xor_si128(*st2, *((__m128i *)&pscratchpad_buff[idx[4]]));
|
||||
*st2 = _mm_xor_si128(*st2, *((__m128i *)&pscratchpad_buff[idx[5]]));
|
||||
*st2 = _mm_xor_si128(*st2, *((__m128i *)&pscratchpad_buff[idx[6]]));
|
||||
*st2 = _mm_xor_si128(*st2, *((__m128i *)&pscratchpad_buff[idx[7]]));
|
||||
|
||||
*st3 = _mm_xor_si128(*st3, *((__m128i *)&pscratchpad_buff[idx[4] + 2]));
|
||||
*st3 = _mm_xor_si128(*st3, *((__m128i *)&pscratchpad_buff[idx[5] + 2]));
|
||||
*st3 = _mm_xor_si128(*st3, *((__m128i *)&pscratchpad_buff[idx[6] + 2]));
|
||||
*st3 = _mm_xor_si128(*st3, *((__m128i *)&pscratchpad_buff[idx[7] + 2]));
|
||||
}
|
||||
|
||||
#else
|
||||
#warning using AVX2 optimizations
|
||||
|
||||
idx[ 0] = reciprocal_remainder64(st[0], scr_size, recip) << 2;
|
||||
idx[ 1] = reciprocal_remainder64(st[1], scr_size, recip) << 2;
|
||||
idx[ 2] = reciprocal_remainder64(st[2], scr_size, recip) << 2;
|
||||
idx[ 3] = reciprocal_remainder64(st[3], scr_size, recip) << 2;
|
||||
idx[ 4] = reciprocal_remainder64(st[4], scr_size, recip) << 2;
|
||||
idx[ 5] = reciprocal_remainder64(st[5], scr_size, recip) << 2;
|
||||
idx[ 6] = reciprocal_remainder64(st[6], scr_size, recip) << 2;
|
||||
idx[ 7] = reciprocal_remainder64(st[7], scr_size, recip) << 2;
|
||||
|
||||
for(int y = 0; y < 8; y++) _mm_prefetch(&pscratchpad_buff[idx[y]], _MM_HINT_T1);
|
||||
|
||||
idx[ 8] = reciprocal_remainder64(st[8], scr_size, recip) << 2;
|
||||
idx[ 9] = reciprocal_remainder64(st[9], scr_size, recip) << 2;
|
||||
idx[10] = reciprocal_remainder64(st[10], scr_size, recip) << 2;
|
||||
idx[11] = reciprocal_remainder64(st[11], scr_size, recip) << 2;
|
||||
idx[12] = reciprocal_remainder64(st[12], scr_size, recip) << 2;
|
||||
idx[13] = reciprocal_remainder64(st[13], scr_size, recip) << 2;
|
||||
idx[14] = reciprocal_remainder64(st[14], scr_size, recip) << 2;
|
||||
idx[15] = reciprocal_remainder64(st[15], scr_size, recip) << 2;
|
||||
|
||||
for(int y = 8; y < 16; ++y) _mm_prefetch(&pscratchpad_buff[idx[y]], _MM_HINT_T1);
|
||||
|
||||
idx[16] = reciprocal_remainder64(st[16], scr_size, recip) << 2;
|
||||
idx[17] = reciprocal_remainder64(st[17], scr_size, recip) << 2;
|
||||
idx[18] = reciprocal_remainder64(st[18], scr_size, recip) << 2;
|
||||
idx[19] = reciprocal_remainder64(st[19], scr_size, recip) << 2;
|
||||
idx[20] = reciprocal_remainder64(st[20], scr_size, recip) << 2;
|
||||
idx[21] = reciprocal_remainder64(st[21], scr_size, recip) << 2;
|
||||
idx[22] = reciprocal_remainder64(st[22], scr_size, recip) << 2;
|
||||
idx[23] = reciprocal_remainder64(st[23], scr_size, recip) << 2;
|
||||
|
||||
for(int y = 16; y < 24; ++y) _mm_prefetch(&pscratchpad_buff[idx[y]], _MM_HINT_T1);
|
||||
|
||||
__m256i *st0 = (__m256i *)&st[0];
|
||||
|
||||
for(int x = 0; x < 6; ++x)
|
||||
{
|
||||
*st0 = _mm256_xor_si256(*st0, *((__m256i *)&pscratchpad_buff[idx[(x << 2) + 0]]));
|
||||
*st0 = _mm256_xor_si256(*st0, *((__m256i *)&pscratchpad_buff[idx[(x << 2) + 1]]));
|
||||
*st0 = _mm256_xor_si256(*st0, *((__m256i *)&pscratchpad_buff[idx[(x << 2) + 2]]));
|
||||
*st0 = _mm256_xor_si256(*st0, *((__m256i *)&pscratchpad_buff[idx[(x << 2) + 3]]));
|
||||
++st0;
|
||||
}
|
||||
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
static void wild_keccak_hash_dbl(uint8_t * __restrict md, const uint8_t * __restrict in)
|
||||
{
|
||||
uint64_t _ALIGN(32) st[25];
|
||||
uint64_t scr_size, i;
|
||||
struct reciprocal_value64 recip;
|
||||
|
||||
scr_size = scratchpad_size >> 2;
|
||||
if (scr_size == cached_scr_size)
|
||||
recip = cached_recip;
|
||||
else {
|
||||
cached_recip = recip = reciprocal_val64(scr_size);
|
||||
cached_scr_size = scr_size;
|
||||
}
|
||||
|
||||
// Wild Keccak #1
|
||||
memcpy(st, in, 88);
|
||||
st[10] = (st[10] & 0x00000000000000FFULL) | 0x0000000000000100ULL;
|
||||
memset(&st[11], 0, 112);
|
||||
st[16] |= 0x8000000000000000ULL;
|
||||
|
||||
for(i = 0; i < 23; i++) {
|
||||
keccakf_mul(st);
|
||||
scr_mix(st, scr_size, recip);
|
||||
}
|
||||
|
||||
keccakf_mul_last(st);
|
||||
|
||||
// Wild Keccak #2
|
||||
memset(&st[4], 0x00, 168);
|
||||
st[ 4] = 0x0000000000000001ULL;
|
||||
st[16] = 0x8000000000000000ULL;
|
||||
|
||||
for(i = 0; i < 23; i++) {
|
||||
keccakf_mul(st);
|
||||
scr_mix(st, scr_size, recip);
|
||||
}
|
||||
|
||||
keccakf_mul_last(st);
|
||||
|
||||
memcpy(md, st, 32);
|
||||
return;
|
||||
}
|
||||
|
||||
void wildkeccak_hash(void* output, const void* input, uint64_t* scratchpad, uint64_t ssize)
|
||||
{
|
||||
if (scratchpad) pscratchpad_buff = scratchpad;
|
||||
if (!scratchpad_size) scratchpad_size = ssize;
|
||||
wild_keccak_hash_dbl((uint8_t*)output, (uint8_t*)input);
|
||||
}
|
||||
@@ -1,381 +0,0 @@
|
||||
// WildKeccak CUDA Kernel, Code based on Linux Wolf0 bbr-miner implementation from 2014
|
||||
// Adapted to ccminer 2.0 - tpruvot 2016-2017
|
||||
//
|
||||
// NOTE FOR SP: this ccminer version is licensed under GPLv3 Licence
|
||||
|
||||
extern "C" {
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
}
|
||||
|
||||
#include <miner.h>
|
||||
#include <cuda_helper.h>
|
||||
#include <cuda_vector_uint2x4.h> // todo
|
||||
|
||||
#include "wildkeccak.h"
|
||||
|
||||
extern char *device_config[MAX_GPUS]; // -l
|
||||
extern uint64_t* pscratchpad_buff;
|
||||
|
||||
static uint64_t* d_input[MAX_GPUS];
|
||||
static uint32_t* d_retnonce[MAX_GPUS];
|
||||
static ulonglong4* d_scratchpad[MAX_GPUS];
|
||||
|
||||
static uint64_t* h_scratchpad[MAX_GPUS] = { 0 };
|
||||
static cudaStream_t bufpad_stream[MAX_GPUS] = { 0 };
|
||||
static cudaStream_t kernel_stream[MAX_GPUS] = { 0 };
|
||||
|
||||
uint64_t scratchpad_size = 0;
|
||||
|
||||
uint32_t WK_CUDABlocks = 64;
|
||||
uint32_t WK_CUDAThreads = 256;
|
||||
|
||||
#define st0 vst0.x
|
||||
#define st1 vst0.y
|
||||
#define st2 vst0.z
|
||||
#define st3 vst0.w
|
||||
|
||||
#define st4 vst4.x
|
||||
#define st5 vst4.y
|
||||
#define st6 vst4.z
|
||||
#define st7 vst4.w
|
||||
|
||||
#define st8 vst8.x
|
||||
#define st9 vst8.y
|
||||
#define st10 vst8.z
|
||||
#define st11 vst8.w
|
||||
|
||||
#define st12 vst12.x
|
||||
#define st13 vst12.y
|
||||
#define st14 vst12.z
|
||||
#define st15 vst12.w
|
||||
|
||||
#define st16 vst16.x
|
||||
#define st17 vst16.y
|
||||
#define st18 vst16.z
|
||||
#define st19 vst16.w
|
||||
|
||||
#define st20 vst20.x
|
||||
#define st21 vst20.y
|
||||
#define st22 vst20.z
|
||||
#define st23 vst20.w
|
||||
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
|
||||
__device__ __forceinline__ uint64_t cuda_rotl641(const uint64_t value)
|
||||
{
|
||||
uint2 result;
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, 1U;" : "=r"(result.x)
|
||||
: "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, 1U;" : "=r"(result.y)
|
||||
: "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))));
|
||||
return __double_as_longlong(__hiloint2double(result.y, result.x));
|
||||
}
|
||||
|
||||
#else
|
||||
__noinline__ __device__ uint64_t cuda_rotl641(const uint64_t x) { return((x << 1) | (x >> 63)); }
|
||||
#endif
|
||||
|
||||
__noinline__ __device__ uint64_t bitselect(const uint64_t a, const uint64_t b, const uint64_t c) { return(a ^ (c & (b ^ a))); }
|
||||
|
||||
#define ROTL641(x) (cuda_rotl641(x))
|
||||
|
||||
#define RND() \
|
||||
bc[0] = st0 ^ st5 ^ st10 * st15 * st20 ^ ROTL641(st2 ^ st7 ^ st12 * st17 * st22); \
|
||||
bc[1] = st1 ^ st6 ^ st11 * st16 * st21 ^ ROTL641(st3 ^ st8 ^ st13 * st18 * st23); \
|
||||
bc[2] = st2 ^ st7 ^ st12 * st17 * st22 ^ ROTL641(st4 ^ st9 ^ st14 * st19 * st24); \
|
||||
bc[3] = st3 ^ st8 ^ st13 * st18 * st23 ^ ROTL641(st0 ^ st5 ^ st10 * st15 * st20); \
|
||||
bc[4] = st4 ^ st9 ^ st14 * st19 * st24 ^ ROTL641(st1 ^ st6 ^ st11 * st16 * st21); \
|
||||
tmp1 = st1 ^ bc[0]; \
|
||||
\
|
||||
st0 ^= bc[4]; \
|
||||
st1 = ROTL64(st6 ^ bc[0], 44); \
|
||||
st6 = ROTL64(st9 ^ bc[3], 20); \
|
||||
st9 = ROTL64(st22 ^ bc[1], 61); \
|
||||
st22 = ROTL64(st14 ^ bc[3], 39); \
|
||||
st14 = ROTL64(st20 ^ bc[4], 18); \
|
||||
st20 = ROTL64(st2 ^ bc[1], 62); \
|
||||
st2 = ROTL64(st12 ^ bc[1], 43); \
|
||||
st12 = ROTL64(st13 ^ bc[2], 25); \
|
||||
st13 = ROTL64(st19 ^ bc[3], 8); \
|
||||
st19 = ROTL64(st23 ^ bc[2], 56); \
|
||||
st23 = ROTL64(st15 ^ bc[4], 41); \
|
||||
st15 = ROTL64(st4 ^ bc[3], 27); \
|
||||
st4 = ROTL64(st24 ^ bc[3], 14); \
|
||||
st24 = ROTL64(st21 ^ bc[0], 2); \
|
||||
st21 = ROTL64(st8 ^ bc[2], 55); \
|
||||
st8 = ROTL64(st16 ^ bc[0], 45); \
|
||||
st16 = ROTL64(st5 ^ bc[4], 36); \
|
||||
st5 = ROTL64(st3 ^ bc[2], 28); \
|
||||
st3 = ROTL64(st18 ^ bc[2], 21); \
|
||||
st18 = ROTL64(st17 ^ bc[1], 15); \
|
||||
st17 = ROTL64(st11 ^ bc[0], 10); \
|
||||
st11 = ROTL64(st7 ^ bc[1], 6); \
|
||||
st7 = ROTL64(st10 ^ bc[4], 3); \
|
||||
st10 = ROTL641(tmp1); \
|
||||
\
|
||||
tmp1 = st0; tmp2 = st1; st0 = bitselect(st0 ^ st2, st0, st1); st1 = bitselect(st1 ^ st3, st1, st2); \
|
||||
st2 = bitselect(st2 ^ st4, st2, st3); st3 = bitselect(st3 ^ tmp1, st3, st4); st4 = bitselect(st4 ^ tmp2, st4, tmp1); \
|
||||
tmp1 = st5; tmp2 = st6; st5 = bitselect(st5 ^ st7, st5, st6); st6 = bitselect(st6 ^ st8, st6, st7); \
|
||||
st7 = bitselect(st7 ^ st9, st7, st8); st8 = bitselect(st8 ^ tmp1, st8, st9); st9 = bitselect(st9 ^ tmp2, st9, tmp1); \
|
||||
tmp1 = st10; tmp2 = st11; st10 = bitselect(st10 ^ st12, st10, st11); st11 = bitselect(st11 ^ st13, st11, st12); \
|
||||
st12 = bitselect(st12 ^ st14, st12, st13); st13 = bitselect(st13 ^ tmp1, st13, st14); st14 = bitselect(st14 ^ tmp2, st14, tmp1); \
|
||||
tmp1 = st15; tmp2 = st16; st15 = bitselect(st15 ^ st17, st15, st16); st16 = bitselect(st16 ^ st18, st16, st17); \
|
||||
st17 = bitselect(st17 ^ st19, st17, st18); st18 = bitselect(st18 ^ tmp1, st18, st19); st19 = bitselect(st19 ^ tmp2, st19, tmp1); \
|
||||
tmp1 = st20; tmp2 = st21; st20 = bitselect(st20 ^ st22, st20, st21); st21 = bitselect(st21 ^ st23, st21, st22); \
|
||||
st22 = bitselect(st22 ^ st24, st22, st23); st23 = bitselect(st23 ^ tmp1, st23, st24); st24 = bitselect(st24 ^ tmp2, st24, tmp1); \
|
||||
st0 ^= 1;
|
||||
|
||||
#define LASTRND1() \
|
||||
bc[0] = st0 ^ st5 ^ st10 * st15 * st20 ^ ROTL64(st2 ^ st7 ^ st12 * st17 * st22, 1); \
|
||||
bc[1] = st1 ^ st6 ^ st11 * st16 * st21 ^ ROTL64(st3 ^ st8 ^ st13 * st18 * st23, 1); \
|
||||
bc[2] = st2 ^ st7 ^ st12 * st17 * st22 ^ ROTL64(st4 ^ st9 ^ st14 * st19 * st24, 1); \
|
||||
bc[3] = st3 ^ st8 ^ st13 * st18 * st23 ^ ROTL64(st0 ^ st5 ^ st10 * st15 * st20, 1); \
|
||||
bc[4] = st4 ^ st9 ^ st14 * st19 * st24 ^ ROTL64(st1 ^ st6 ^ st11 * st16 * st21, 1); \
|
||||
\
|
||||
st0 ^= bc[4]; \
|
||||
st1 = ROTL64(st6 ^ bc[0], 44); \
|
||||
st2 = ROTL64(st12 ^ bc[1], 43); \
|
||||
st4 = ROTL64(st24 ^ bc[3], 14); \
|
||||
st3 = ROTL64(st18 ^ bc[2], 21); \
|
||||
\
|
||||
tmp1 = st0; st0 = bitselect(st0 ^ st2, st0, st1); st1 = bitselect(st1 ^ st3, st1, st2); st2 = bitselect(st2 ^ st4, st2, st3); st3 = bitselect(st3 ^ tmp1, st3, st4); \
|
||||
st0 ^= 1;
|
||||
|
||||
#define LASTRND2() \
|
||||
bc[2] = st2 ^ st7 ^ st12 * st17 * st22 ^ ROTL64(st4 ^ st9 ^ st14 * st19 * st24, 1); \
|
||||
bc[3] = st3 ^ st8 ^ st13 * st18 * st23 ^ ROTL64(st0 ^ st5 ^ st10 * st15 * st20, 1); \
|
||||
bc[4] = st4 ^ st9 ^ st14 * st19 * st24 ^ ROTL64(st1 ^ st6 ^ st11 * st16 * st21, 1); \
|
||||
\
|
||||
st0 ^= bc[4]; \
|
||||
st4 = ROTL64(st24 ^ bc[3], 14); \
|
||||
st3 = ROTL64(st18 ^ bc[2], 21); \
|
||||
st3 = bitselect(st3 ^ st0, st3, st4);
|
||||
|
||||
__device__ ulonglong4 operator^(const ulonglong4 &a, const ulonglong4 &b)
|
||||
{
|
||||
return(make_ulonglong4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w));
|
||||
}
|
||||
|
||||
#define MIX(vst) vst = vst ^ scratchpad[vst.x % scr_size] ^ scratchpad[vst.y % scr_size] ^ scratchpad[vst.z % scr_size] ^ scratchpad[vst.w % scr_size];
|
||||
|
||||
#define MIX_ALL MIX(vst0); MIX(vst4); MIX(vst8); MIX(vst12); MIX(vst16); MIX(vst20);
|
||||
|
||||
__global__
|
||||
void wk(uint32_t* __restrict__ retnonce, const uint64_t* __restrict__ input, const ulonglong4* __restrict__ scratchpad,
|
||||
const uint32_t scr_size, const uint32_t target, uint64_t startNonce)
|
||||
{
|
||||
ulonglong4 vst0, vst4, vst8, vst12, vst16, vst20;
|
||||
uint64_t bc[5];
|
||||
uint64_t st24, tmp1, tmp2;
|
||||
|
||||
const uint64_t nonce = startNonce + (blockDim.x * blockIdx.x) + threadIdx.x;
|
||||
vst0 = make_ulonglong4((nonce << 8) + (input[0] & 0xFF), input[1] & 0xFFFFFFFFFFFFFF00ULL, input[2], input[3]);
|
||||
vst4 = make_ulonglong4(input[4], input[5], input[6], input[7]);
|
||||
vst8 = make_ulonglong4(input[8], input[9], (input[10] & 0xFF) | 0x100, 0);
|
||||
vst12 = make_ulonglong4(0, 0, 0, 0);
|
||||
vst16 = make_ulonglong4(0x8000000000000000ULL, 0, 0, 0);
|
||||
vst20 = make_ulonglong4(0, 0, 0, 0);
|
||||
st24 = 0;
|
||||
|
||||
RND();
|
||||
MIX_ALL;
|
||||
|
||||
for(int i = 0; i < 22; i++) {
|
||||
RND();
|
||||
MIX_ALL;
|
||||
}
|
||||
|
||||
LASTRND1();
|
||||
|
||||
vst4 = make_ulonglong4(1, 0, 0, 0);
|
||||
vst8 = make_ulonglong4(0, 0, 0, 0);
|
||||
vst12 = make_ulonglong4(0, 0, 0, 0);
|
||||
vst16 = make_ulonglong4(0x8000000000000000ULL, 0, 0, 0);
|
||||
vst20 = make_ulonglong4(0, 0, 0, 0);
|
||||
st24 = 0;
|
||||
|
||||
RND();
|
||||
MIX_ALL;
|
||||
|
||||
#pragma unroll
|
||||
for(int i = 0; i < 22; i++) {
|
||||
RND();
|
||||
MIX_ALL;
|
||||
}
|
||||
|
||||
LASTRND2();
|
||||
|
||||
if((st3 >> 32) <= target) {
|
||||
retnonce[0] = (uint32_t) nonce;
|
||||
retnonce[1] = retnonce[0];
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void wildkeccak_kernel(const int thr_id, const uint32_t threads, const uint32_t startNounce, const uint2 target, uint32_t *resNonces)
|
||||
{
|
||||
CUDA_SAFE_CALL(cudaMemsetAsync(d_retnonce[thr_id], 0xff, 2 * sizeof(uint32_t), kernel_stream[thr_id]));
|
||||
|
||||
const uint32_t threadsperblock = WK_CUDAThreads;
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
wk <<<grid, block, 0, kernel_stream[thr_id]>>> (d_retnonce[thr_id], d_input[thr_id], d_scratchpad[thr_id],
|
||||
(uint32_t)(scratchpad_size >> 2), target.y, startNounce);
|
||||
|
||||
cudaMemcpyAsync(resNonces, d_retnonce[thr_id], 2*sizeof(uint32_t), cudaMemcpyDeviceToHost, kernel_stream[thr_id]);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_wildkeccak(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *ptarget = work->target;
|
||||
uint32_t throughput = 0;
|
||||
uint64_t n, nonce, first;
|
||||
uint8_t *pdata = (uint8_t*) work->data;
|
||||
memcpy(&first, &pdata[1], 8);
|
||||
n = nonce = first;
|
||||
|
||||
if (!scratchpad_size || !h_scratchpad[thr_id]) {
|
||||
if (h_scratchpad[thr_id])
|
||||
applog(LOG_ERR, "Scratchpad size is not set!");
|
||||
work->data[0] = 0; // invalidate
|
||||
sleep(1);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
if (!init[thr_id]) {
|
||||
|
||||
if (device_config[thr_id]) {
|
||||
sscanf(device_config[thr_id], "%ux%u", &WK_CUDABlocks, &WK_CUDAThreads);
|
||||
gpulog(LOG_INFO, thr_id, "Using %u x %u kernel launch config, %u threads",
|
||||
WK_CUDABlocks, WK_CUDAThreads, throughput);
|
||||
} else {
|
||||
throughput = cuda_default_throughput(thr_id, WK_CUDABlocks*WK_CUDAThreads);
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
}
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
if (opt_cudaschedule == -1 && gpu_threads == 1) {
|
||||
cudaDeviceReset();
|
||||
// reduce cpu usage (linux)
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_input[thr_id], 88));
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_retnonce[thr_id], 2*sizeof(uint32_t)));
|
||||
|
||||
int status = (int) cudaMalloc(&d_scratchpad[thr_id], WILD_KECCAK_SCRATCHPAD_BUFFSIZE);
|
||||
if (status != cudaSuccess) {
|
||||
gpulog(LOG_ERR, thr_id, "Unable to allocate device memory, %u MB, err %d",
|
||||
(uint32_t) (WILD_KECCAK_SCRATCHPAD_BUFFSIZE/(1024*1024)), status);
|
||||
exit(-ENOMEM);
|
||||
}
|
||||
|
||||
cudaStreamCreate(&bufpad_stream[thr_id]);
|
||||
cudaStreamCreate(&kernel_stream[thr_id]);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMemcpyAsync(d_scratchpad[thr_id], h_scratchpad[thr_id], scratchpad_size << 3, cudaMemcpyHostToDevice, bufpad_stream[thr_id]));
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
throughput = WK_CUDABlocks * WK_CUDAThreads;
|
||||
|
||||
cudaMemcpy(d_input[thr_id], pdata, 88, cudaMemcpyHostToDevice);
|
||||
// cudaMemset(d_retnonce[thr_id], 0xFF, 2*sizeof(uint32_t));
|
||||
|
||||
if (h_scratchpad[thr_id]) {
|
||||
cudaStreamSynchronize(bufpad_stream[thr_id]);
|
||||
}
|
||||
|
||||
do {
|
||||
// const uint32_t blocks = WK_CUDABlocks, threads = WK_CUDAThreads;
|
||||
// const dim3 block(blocks);
|
||||
// const dim3 thread(threads);
|
||||
uint32_t h_retnonce[2] = { UINT32_MAX, UINT32_MAX };
|
||||
uint2 target = make_uint2(ptarget[6], ptarget[7]);
|
||||
|
||||
wildkeccak_kernel(thr_id, throughput, (uint32_t) nonce, target, h_retnonce);
|
||||
/*
|
||||
wk <<<block, thread, 0, kernel_stream[thr_id]>>> (d_retnonce[thr_id], d_input[thr_id], d_scratchpad[thr_id],
|
||||
(uint32_t)(scratchpad_size >> 2), nonce, ptarget[7]);
|
||||
*/
|
||||
|
||||
*hashes_done = (unsigned long) (n - first + throughput);
|
||||
|
||||
cudaStreamSynchronize(kernel_stream[thr_id]);
|
||||
if(h_retnonce[0] != UINT32_MAX) {
|
||||
uint8_t _ALIGN(64) cpuhash[32];
|
||||
uint32_t* vhash = (uint32_t*) cpuhash;
|
||||
uint64_t nonce64;
|
||||
memcpy(&pdata[1], &h_retnonce[0], sizeof(uint32_t));
|
||||
memcpy(&nonce64, &pdata[1], 8);
|
||||
wildkeccak_hash(cpuhash, pdata, pscratchpad_buff, scratchpad_size);
|
||||
if (!cpuhash[31] && vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
work_set_target_ratio(work, vhash);
|
||||
//applog_hex(pdata, 84);
|
||||
//applog_hex(cpuhash, 32);
|
||||
//applog_hex(ptarget, 32);
|
||||
memcpy(work->nonces, &nonce64, 8);
|
||||
if (n + throughput > max_nonce) {
|
||||
*hashes_done = (unsigned long) (max_nonce - first);
|
||||
}
|
||||
work->valid_nonces = 1;
|
||||
return 1;
|
||||
} else if (vhash[7] > ptarget[7]) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for nonce %08x does not validate on CPU!", h_retnonce[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (n + throughput >= max_nonce) {
|
||||
n = max_nonce;
|
||||
break;
|
||||
}
|
||||
|
||||
n += throughput;
|
||||
nonce += throughput;
|
||||
|
||||
} while(!work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = (unsigned long) (n - first + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wildkeccak_scratchpad_need_update(uint64_t* pscratchpad_buff)
|
||||
{
|
||||
for(int i = 0; i < opt_n_threads; i++) {
|
||||
h_scratchpad[i] = pscratchpad_buff;
|
||||
if (init[i]) {
|
||||
gpulog(LOG_DEBUG, i, "Starting scratchpad update...");
|
||||
cudaMemcpyAsync(d_scratchpad[i], h_scratchpad[i], scratchpad_size << 3, cudaMemcpyHostToDevice, bufpad_stream[i]);
|
||||
work_restart[i].restart = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void free_wildkeccak(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaThreadSynchronize();
|
||||
|
||||
cudaFree(d_scratchpad[thr_id]);
|
||||
cudaFree(d_input[thr_id]);
|
||||
cudaFree(d_retnonce[thr_id]);
|
||||
|
||||
cudaStreamDestroy(bufpad_stream[thr_id]);
|
||||
cudaStreamDestroy(kernel_stream[thr_id]);
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
|
||||
init[thr_id] = false;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
#define WILD_KECCAK_SCRATCHPAD_BUFFSIZE 1ULL << 29
|
||||
#define WILD_KECCAK_ADDENDUMS_ARRAY_SIZE 10
|
||||
|
||||
extern uint64_t scratchpad_size;
|
||||
|
||||
extern uint32_t WK_CUDABlocks, WK_CUDAThreads;
|
||||
|
||||
void wildkeccak_scratchpad_need_update(uint64_t* pscratchpad_buff);
|
||||
|
||||
-1337
File diff suppressed because it is too large.
Load diff
@@ -1,41 +0,0 @@
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#include "wildkeccak.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define _PACKED _ALIGN(4)
|
||||
#else
|
||||
#define _PACKED __attribute__((__packed__))
|
||||
#endif
|
||||
|
||||
struct _PACKED scratchpad_hi {
|
||||
unsigned char prevhash[32];
|
||||
uint64_t height;
|
||||
};
|
||||
|
||||
struct _PACKED addendums_array_entry {
|
||||
struct scratchpad_hi prev_hi;
|
||||
uint64_t add_size;
|
||||
};
|
||||
|
||||
|
||||
struct _PACKED scratchpad_file_header {
|
||||
struct scratchpad_hi current_hi;
|
||||
struct addendums_array_entry add_arr[WILD_KECCAK_ADDENDUMS_ARRAY_SIZE];
|
||||
uint64_t scratchpad_size;
|
||||
};
|
||||
|
||||
|
||||
bool rpc2_job_decode(const json_t *job, struct work *work);
|
||||
bool rpc2_stratum_job(struct stratum_ctx *sctx, json_t *id, json_t *params);
|
||||
bool rpc2_stratum_gen_work(struct stratum_ctx *sctx, struct work *work);
|
||||
bool rpc2_stratum_submit(struct pool_infos *pool, struct work *work);
|
||||
|
||||
int rpc2_stratum_thread_stuff(struct pool_infos* pool);
|
||||
|
||||
bool rpc2_login_decode(const json_t *val);
|
||||
|
||||
void rpc2_init();
|
||||
|
||||
void GetScratchpad();
|
||||
@@ -27,21 +27,25 @@ extern "C" {
|
||||
// CUDA Devices on the System
|
||||
int cuda_num_devices()
|
||||
{
|
||||
int version = 0, GPU_N = 0;
|
||||
int version;
|
||||
cudaError_t err = cudaDriverGetVersion(&version);
|
||||
if (err != cudaSuccess) {
|
||||
if (err != cudaSuccess)
|
||||
{
|
||||
applog(LOG_ERR, "Unable to query CUDA driver version! Is an nVidia driver installed?");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (version < CUDART_VERSION) {
|
||||
applog(LOG_ERR, "Your system does not support CUDA %d.%d API!",
|
||||
CUDART_VERSION / 1000, (CUDART_VERSION % 1000) / 10);
|
||||
int maj = version / 1000, min = version % 100; // same as in deviceQuery sample
|
||||
if (maj < 5 || (maj == 5 && min < 5))
|
||||
{
|
||||
applog(LOG_ERR, "Driver does not support CUDA %d.%d API! Update your nVidia driver!", 5, 5);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int GPU_N;
|
||||
err = cudaGetDeviceCount(&GPU_N);
|
||||
if (err != cudaSuccess) {
|
||||
if (err != cudaSuccess)
|
||||
{
|
||||
applog(LOG_ERR, "Unable to query number of CUDA devices! Is an nVidia driver installed?");
|
||||
exit(1);
|
||||
}
|
||||
@@ -74,7 +78,6 @@ void cuda_devicenames()
|
||||
cudaGetDeviceProperties(&props, dev_id);
|
||||
|
||||
device_sm[dev_id] = (props.major * 100 + props.minor * 10);
|
||||
device_mpcount[dev_id] = (short) props.multiProcessorCount;
|
||||
|
||||
if (device_name[dev_id]) {
|
||||
free(device_name[dev_id]);
|
||||
@@ -102,28 +105,14 @@ void cuda_print_devices()
|
||||
cudaDeviceProp props;
|
||||
cudaGetDeviceProperties(&props, dev_id);
|
||||
if (!opt_n_threads || n < opt_n_threads) {
|
||||
fprintf(stderr, "GPU #%d: SM %d.%d %s @ %.0f MHz (MEM %.0f)\n", dev_id,
|
||||
props.major, props.minor, device_name[dev_id],
|
||||
(double) props.clockRate/1000,
|
||||
(double) props.memoryClockRate/1000);
|
||||
#ifdef USE_WRAPNVML
|
||||
if (opt_debug) nvml_print_device_info(dev_id);
|
||||
#ifdef WIN32
|
||||
if (opt_debug) {
|
||||
unsigned int devNum = nvapi_devnum(dev_id);
|
||||
nvapi_pstateinfo(devNum);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
fprintf(stderr, "GPU #%d: SM %d.%d %s\n", dev_id, props.major, props.minor, device_name[dev_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cuda_shutdown()
|
||||
{
|
||||
// require gpu init first
|
||||
//if (thr_info != NULL)
|
||||
// cudaDeviceSynchronize();
|
||||
cudaDeviceSynchronize();
|
||||
cudaDeviceReset();
|
||||
}
|
||||
|
||||
@@ -173,21 +162,6 @@ uint32_t cuda_default_throughput(int thr_id, uint32_t defcount)
|
||||
return throughput;
|
||||
}
|
||||
|
||||
// since 1.8.3
|
||||
double throughput2intensity(uint32_t throughput)
|
||||
{
|
||||
double intensity = 0.;
|
||||
uint32_t ws = throughput;
|
||||
uint8_t i = 0;
|
||||
while (ws > 1 && i++ < 32)
|
||||
ws = ws >> 1;
|
||||
intensity = (double) i;
|
||||
if (i && ((1U << i) < throughput)) {
|
||||
intensity += ((double) (throughput-(1U << i)) / (1U << i));
|
||||
}
|
||||
return intensity;
|
||||
}
|
||||
|
||||
// if we use 2 threads on the same gpu, we need to reinit the threads
|
||||
void cuda_reset_device(int thr_id, bool *init)
|
||||
{
|
||||
@@ -219,18 +193,10 @@ void cuda_reset_device(int thr_id, bool *init)
|
||||
int cuda_available_memory(int thr_id)
|
||||
{
|
||||
int dev_id = device_map[thr_id % MAX_GPUS];
|
||||
#if defined(_WIN32) && defined(USE_WRAPNVML)
|
||||
uint64_t tot64 = 0, free64 = 0;
|
||||
// cuda (6.5) one can crash on pascal and dont handle 8GB
|
||||
nvapiMemGetInfo(dev_id, &free64, &tot64);
|
||||
return (int) (free64 / (1024));
|
||||
#else
|
||||
size_t mtotal = 0, mfree = 0;
|
||||
size_t mtotal, mfree = 0;
|
||||
cudaSetDevice(dev_id);
|
||||
cudaDeviceSynchronize();
|
||||
cudaMemGetInfo(&mfree, &mtotal);
|
||||
return (int) (mfree / (1024 * 1024));
|
||||
#endif
|
||||
}
|
||||
|
||||
// Check (and reset) last cuda error, and report it in logs
|
||||
@@ -251,18 +217,13 @@ void cuda_clear_lasterror()
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
int cuda_gpu_info(struct cgpu_info *gpu)
|
||||
int cuda_gpu_clocks(struct cgpu_info *gpu)
|
||||
{
|
||||
cudaDeviceProp props;
|
||||
if (cudaGetDeviceProperties(&props, gpu->gpu_id) == cudaSuccess) {
|
||||
gpu->gpu_clock = (uint32_t) props.clockRate;
|
||||
gpu->gpu_memclock = (uint32_t) props.memoryClockRate;
|
||||
gpu->gpu_mem = (uint64_t) (props.totalGlobalMem / 1024); // kB
|
||||
#if defined(_WIN32) && defined(USE_WRAPNVML)
|
||||
// required to get mem size > 4GB (size_t too small for bytes on 32bit)
|
||||
nvapiMemGetInfo(gpu->gpu_id, &gpu->gpu_memfree, &gpu->gpu_mem); // kB
|
||||
#endif
|
||||
gpu->gpu_mem = gpu->gpu_mem / 1024; // MB
|
||||
gpu->gpu_clock = props.clockRate;
|
||||
gpu->gpu_memclock = props.memoryClockRate;
|
||||
gpu->gpu_mem = props.totalGlobalMem;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
|
||||
+19
-15
@@ -5,11 +5,6 @@
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#ifdef __INTELLISENSE__
|
||||
#define __CUDA_ARCH__ 500
|
||||
#define __byte_perm(x,y,n) x
|
||||
#endif
|
||||
|
||||
#include "miner.h"
|
||||
|
||||
__constant__ uint32_t pTarget[8]; // Single GPU
|
||||
@@ -90,8 +85,9 @@ void groestlcoin_gpu_hash_quad(uint32_t threads, uint32_t startNounce, uint32_t
|
||||
}
|
||||
}
|
||||
|
||||
if(rc && resNounce[0] > nounce)
|
||||
resNounce[0] = nounce;
|
||||
if(rc == true)
|
||||
if(resNounce[0] > nounce)
|
||||
resNounce[0] = nounce;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -115,8 +111,9 @@ void groestlcoin_cpu_free(int thr_id)
|
||||
__host__
|
||||
void groestlcoin_cpu_setBlock(int thr_id, void *data, void *pTargetIn)
|
||||
{
|
||||
uint32_t msgBlock[32] = { 0 };
|
||||
uint32_t msgBlock[32];
|
||||
|
||||
memset(msgBlock, 0, sizeof(uint32_t) * 32);
|
||||
memcpy(&msgBlock[0], data, 80);
|
||||
|
||||
// Erweitere die Nachricht auf den Nachrichtenblock (padding)
|
||||
@@ -128,14 +125,18 @@ void groestlcoin_cpu_setBlock(int thr_id, void *data, void *pTargetIn)
|
||||
// auf der GPU ausgeführt)
|
||||
|
||||
// Blockheader setzen (korrekte Nonce und Hefty Hash fehlen da drin noch)
|
||||
cudaMemcpyToSymbol(groestlcoin_gpu_msg, msgBlock, 128);
|
||||
cudaMemcpyToSymbol( groestlcoin_gpu_msg,
|
||||
msgBlock,
|
||||
128);
|
||||
|
||||
cudaMemset(d_resultNonce[thr_id], 0xFF, sizeof(uint32_t));
|
||||
cudaMemcpyToSymbol(pTarget, pTargetIn, 32);
|
||||
cudaMemcpyToSymbol( pTarget,
|
||||
pTargetIn,
|
||||
sizeof(uint32_t) * 8 );
|
||||
}
|
||||
|
||||
__host__
|
||||
void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *resNonce)
|
||||
void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outputHashes, uint32_t *nounce)
|
||||
{
|
||||
uint32_t threadsperblock = 256;
|
||||
|
||||
@@ -143,10 +144,13 @@ void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, ui
|
||||
// mit den Quad Funktionen brauchen wir jetzt 4 threads pro Hash, daher Faktor 4 bei der Blockzahl
|
||||
int factor = 4;
|
||||
|
||||
// berechne wie viele Thread Blocks wir brauchen
|
||||
// berechne wie viele Thread Blocks wir brauchen
|
||||
dim3 grid(factor*((threads + threadsperblock-1)/threadsperblock));
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
// Größe des dynamischen Shared Memory Bereichs
|
||||
size_t shared_size = 0;
|
||||
|
||||
int dev_id = device_map[thr_id];
|
||||
if (device_sm[dev_id] < 300 || cuda_arch[dev_id] < 300) {
|
||||
gpulog(LOG_ERR, thr_id, "Sorry, This algo is not supported by this GPU arch (SM 3.0 required)");
|
||||
@@ -154,10 +158,10 @@ void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, ui
|
||||
}
|
||||
|
||||
cudaMemset(d_resultNonce[thr_id], 0xFF, sizeof(uint32_t));
|
||||
groestlcoin_gpu_hash_quad <<<grid, block>>> (threads, startNounce, d_resultNonce[thr_id]);
|
||||
groestlcoin_gpu_hash_quad<<<grid, block, shared_size>>>(threads, startNounce, d_resultNonce[thr_id]);
|
||||
|
||||
// Strategisches Sleep Kommando zur Senkung der CPU Last
|
||||
// MyStreamSynchronize(NULL, 0, thr_id);
|
||||
MyStreamSynchronize(NULL, 0, thr_id);
|
||||
|
||||
cudaMemcpy(resNonce, d_resultNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
cudaMemcpy(nounce, d_resultNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
}
|
||||
+1
-1
@@ -4,6 +4,6 @@
|
||||
void groestlcoin_cpu_init(int thr_id, uint32_t threads);
|
||||
void groestlcoin_cpu_free(int thr_id);
|
||||
void groestlcoin_cpu_setBlock(int thr_id, void *data, void *pTargetIn);
|
||||
void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *resNonce);
|
||||
void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outputHashes, uint32_t *nounce);
|
||||
|
||||
#endif
|
||||
+43
-28
@@ -25,7 +25,7 @@
|
||||
|
||||
extern "C" short device_map[MAX_GPUS];
|
||||
extern "C" long device_sm[MAX_GPUS];
|
||||
extern "C" short device_mpcount[MAX_GPUS];
|
||||
|
||||
extern int cuda_arch[MAX_GPUS];
|
||||
|
||||
// common functions
|
||||
@@ -77,12 +77,6 @@ extern const uint3 threadIdx;
|
||||
#define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
|
||||
#endif
|
||||
|
||||
#define AS_U32(addr) *((uint32_t*)(addr))
|
||||
#define AS_U64(addr) *((uint64_t*)(addr))
|
||||
#define AS_UINT2(addr) *((uint2*)(addr))
|
||||
#define AS_UINT4(addr) *((uint4*)(addr))
|
||||
#define AS_UL2(addr) *((ulonglong2*)(addr))
|
||||
|
||||
__device__ __forceinline__ uint64_t MAKE_ULONGLONG(uint32_t LO, uint32_t HI)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 130
|
||||
@@ -102,7 +96,6 @@ __device__ __forceinline__ uint64_t REPLACE_LODWORD(const uint64_t &x, const uin
|
||||
return (x & 0xFFFFFFFF00000000ULL) | ((uint64_t)y);
|
||||
}
|
||||
|
||||
// Endian Drehung für 32 Bit Typen
|
||||
#ifdef __CUDA_ARCH__
|
||||
__device__ __forceinline__ uint32_t cuda_swab32(uint32_t x)
|
||||
{
|
||||
@@ -477,6 +470,15 @@ static __host__ __device__ __forceinline__ uint64_t devectorize(uint2 v) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint2 eorswap32(uint2 u, uint2 v)
|
||||
{
|
||||
uint2 result;
|
||||
result.y = u.x ^ v.x;
|
||||
result.x = u.y ^ v.y;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* uint2 direct ops by c++ operator definitions
|
||||
*/
|
||||
@@ -487,12 +489,31 @@ static __device__ __forceinline__ uint2 operator~ (uint2 a) { return make_uint2(
|
||||
static __device__ __forceinline__ void operator^= (uint2 &a, uint2 b) { a = a ^ b; }
|
||||
|
||||
static __device__ __forceinline__ uint2 operator+ (uint2 a, uint2 b) {
|
||||
#ifdef __CUDA_ARCH__
|
||||
uint2 result;
|
||||
asm("{ // uint2 a+b \n\t"
|
||||
"add.cc.u32 %0, %2, %4; \n\t"
|
||||
"addc.u32 %1, %3, %5; \n\t"
|
||||
"}\n" : "=r"(result.x), "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(b.x), "r"(b.y));
|
||||
return result;
|
||||
#else
|
||||
return vectorize(devectorize(a) + devectorize(b));
|
||||
#endif
|
||||
}
|
||||
static __device__ __forceinline__ void operator+= (uint2 &a, uint2 b) { a = a + b; }
|
||||
|
||||
|
||||
static __device__ __forceinline__ uint2 operator- (uint2 a, uint2 b) {
|
||||
#if defined(__CUDA_ARCH__) && CUDA_VERSION < 7000
|
||||
uint2 result;
|
||||
asm("{ // uint2 a-b \n\t"
|
||||
"sub.cc.u32 %0, %2, %4; \n\t"
|
||||
"subc.u32 %1, %3, %5; \n\t"
|
||||
"}\n" : "=r"(result.x), "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(b.x), "r"(b.y));
|
||||
return result;
|
||||
#else
|
||||
return vectorize(devectorize(a) - devectorize(b));
|
||||
#endif
|
||||
}
|
||||
static __device__ __forceinline__ void operator-= (uint2 &a, uint2 b) { a = a - b; }
|
||||
|
||||
@@ -548,11 +569,9 @@ uint2 ROR2(const uint2 a, const int offset)
|
||||
return result;
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
uint2 ROL2(const uint2 a, const int offset)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 350
|
||||
__inline__ __device__ uint2 ROL2(const uint2 a, const int offset) {
|
||||
uint2 result;
|
||||
#if __CUDA_ARCH__ > 300
|
||||
if (offset >= 32) {
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(a.x), "r"(a.y), "r"(offset));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(a.y), "r"(a.x), "r"(offset));
|
||||
@@ -561,14 +580,20 @@ uint2 ROL2(const uint2 a, const int offset)
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(a.y), "r"(a.x), "r"(offset));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(offset));
|
||||
}
|
||||
#else
|
||||
if (!offset)
|
||||
result = a;
|
||||
else
|
||||
result = ROR2(a, 64 - offset);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
__inline__ __device__ uint2 ROL2(const uint2 v, const int n)
|
||||
{
|
||||
uint2 result;
|
||||
if (!n)
|
||||
result = v;
|
||||
else
|
||||
result = ROR2(v, 64 - n);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
__device__ __forceinline__
|
||||
uint2 SWAPUINT2(uint2 value)
|
||||
@@ -669,14 +694,4 @@ static uint2 SHR2(uint2 a, int offset)
|
||||
#endif
|
||||
}
|
||||
|
||||
// CUDA 9+ deprecated functions warnings (new mask param)
|
||||
#if CUDA_VERSION >= 9000 && __CUDA_ARCH__ >= 300
|
||||
#undef __shfl
|
||||
#define __shfl(var, srcLane, width) __shfl_sync(0xFFFFFFFFu, var, srcLane, width)
|
||||
#undef __shfl_up
|
||||
#define __shfl_up(var, delta, width) __shfl_up_sync(0xFFFFFFFF, var, delta, width)
|
||||
#undef __any
|
||||
#define __any(p) __any_sync(0xFFFFFFFFu, p)
|
||||
#endif
|
||||
|
||||
#endif // #ifndef CUDA_HELPER_H
|
||||
+293
-258
@@ -5,12 +5,6 @@
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#ifdef __INTELLISENSE__
|
||||
#define __CUDA_ARCH__ 500
|
||||
#define __funnelshift_r(x,y,n) (x >> n)
|
||||
#define atomicExch(p,x) x
|
||||
#endif
|
||||
|
||||
#if __CUDA_ARCH__ >= 300
|
||||
// 64 Registers Variant for Compute 3.0
|
||||
#include "quark/groestl_functions_quad.h"
|
||||
@@ -18,276 +12,290 @@
|
||||
#endif
|
||||
|
||||
// globaler Speicher für alle HeftyHashes aller Threads
|
||||
static uint32_t *d_outputHashes[MAX_GPUS];
|
||||
static uint32_t *d_resultNonces[MAX_GPUS];
|
||||
__constant__ uint32_t pTarget[8]; // Single GPU
|
||||
uint32_t *d_outputHashes[MAX_GPUS];
|
||||
static uint32_t *d_resultNonce[MAX_GPUS];
|
||||
|
||||
__constant__ uint32_t pTarget[2]; // Same for all GPU
|
||||
__constant__ uint32_t myriadgroestl_gpu_msg[32];
|
||||
|
||||
// muss expandiert werden
|
||||
__constant__ uint32_t myr_sha256_gpu_constantTable[64];
|
||||
__constant__ uint32_t myr_sha256_gpu_constantTable2[64];
|
||||
__constant__ uint32_t myr_sha256_gpu_hashTable[8];
|
||||
|
||||
const uint32_t myr_sha256_cpu_constantTable[] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
||||
uint32_t myr_sha256_cpu_hashTable[] = {
|
||||
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
|
||||
uint32_t myr_sha256_cpu_constantTable[] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
||||
};
|
||||
|
||||
const uint32_t myr_sha256_cpu_w2Table[] = {
|
||||
0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000200,
|
||||
0x80000000, 0x01400000, 0x00205000, 0x00005088, 0x22000800, 0x22550014, 0x05089742, 0xa0000020,
|
||||
0x5a880000, 0x005c9400, 0x0016d49d, 0xfa801f00, 0xd33225d0, 0x11675959, 0xf6e6bfda, 0xb30c1549,
|
||||
0x08b2b050, 0x9d7c4c27, 0x0ce2a393, 0x88e6e1ea, 0xa52b4335, 0x67a16f49, 0xd732016f, 0x4eeb2e91,
|
||||
0x5dbf55e5, 0x8eee2335, 0xe2bc5ec2, 0xa83f4394, 0x45ad78f7, 0x36f3d0cd, 0xd99c05e8, 0xb0511dc7,
|
||||
0x69bc7ac4, 0xbd11375b, 0xe3ba71e5, 0x3b209ff2, 0x18feee17, 0xe25ad9e7, 0x13375046, 0x0515089d,
|
||||
0x4f0d0f04, 0x2627484e, 0x310128d2, 0xc668b434, 0x420841cc, 0x62d311b8, 0xe59ba771, 0x85a7a484
|
||||
};
|
||||
uint32_t myr_sha256_cpu_w2Table[] = {
|
||||
0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000200,
|
||||
0x80000000, 0x01400000, 0x00205000, 0x00005088, 0x22000800, 0x22550014, 0x05089742, 0xa0000020,
|
||||
0x5a880000, 0x005c9400, 0x0016d49d, 0xfa801f00, 0xd33225d0, 0x11675959, 0xf6e6bfda, 0xb30c1549,
|
||||
0x08b2b050, 0x9d7c4c27, 0x0ce2a393, 0x88e6e1ea, 0xa52b4335, 0x67a16f49, 0xd732016f, 0x4eeb2e91,
|
||||
0x5dbf55e5, 0x8eee2335, 0xe2bc5ec2, 0xa83f4394, 0x45ad78f7, 0x36f3d0cd, 0xd99c05e8, 0xb0511dc7,
|
||||
0x69bc7ac4, 0xbd11375b, 0xe3ba71e5, 0x3b209ff2, 0x18feee17, 0xe25ad9e7, 0x13375046, 0x0515089d,
|
||||
0x4f0d0f04, 0x2627484e, 0x310128d2, 0xc668b434, 0x420841cc, 0x62d311b8, 0xe59ba771, 0x85a7a484 };
|
||||
|
||||
#define SWAB32(x) cuda_swab32(x)
|
||||
#define SWAB32(x) ( ((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8) | ((x & 0x00FF0000) >> 8) | ((x & 0xFF000000) >> 24) )
|
||||
|
||||
#if __CUDA_ARCH__ < 320
|
||||
// Kepler (Compute 3.0)
|
||||
#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
|
||||
// Kepler (Compute 3.0)
|
||||
#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
|
||||
#else
|
||||
// Kepler (Compute 3.5)
|
||||
#define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
|
||||
// Kepler (Compute 3.5)
|
||||
#define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
|
||||
#endif
|
||||
|
||||
#define R(x, n) ((x) >> (n))
|
||||
#define Ch(x, y, z) ((x & (y ^ z)) ^ z)
|
||||
#define R(x, n) ((x) >> (n))
|
||||
#define Ch(x, y, z) ((x & (y ^ z)) ^ z)
|
||||
#define Maj(x, y, z) ((x & (y | z)) | (y & z))
|
||||
#define S0(x) (ROTR32(x, 2) ^ ROTR32(x, 13) ^ ROTR32(x, 22))
|
||||
#define S1(x) (ROTR32(x, 6) ^ ROTR32(x, 11) ^ ROTR32(x, 25))
|
||||
#define s0(x) (ROTR32(x, 7) ^ ROTR32(x, 18) ^ R(x, 3))
|
||||
#define s1(x) (ROTR32(x, 17) ^ ROTR32(x, 19) ^ R(x, 10))
|
||||
#define S0(x) (ROTR32(x, 2) ^ ROTR32(x, 13) ^ ROTR32(x, 22))
|
||||
#define S1(x) (ROTR32(x, 6) ^ ROTR32(x, 11) ^ ROTR32(x, 25))
|
||||
#define s0(x) (ROTR32(x, 7) ^ ROTR32(x, 18) ^ R(x, 3))
|
||||
#define s1(x) (ROTR32(x, 17) ^ ROTR32(x, 19) ^ R(x, 10))
|
||||
|
||||
__device__ __forceinline__
|
||||
void myriadgroestl_gpu_sha256(uint32_t *message)
|
||||
__device__ void myriadgroestl_gpu_sha256(uint32_t *message)
|
||||
{
|
||||
uint32_t W1[16];
|
||||
#pragma unroll
|
||||
for(int k=0; k<16; k++)
|
||||
W1[k] = SWAB32(message[k]);
|
||||
uint32_t W1[16];
|
||||
uint32_t W2[16];
|
||||
|
||||
uint32_t regs[8] = {
|
||||
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
||||
};
|
||||
// Initialisiere die register a bis h mit der Hash-Tabelle
|
||||
uint32_t regs[8];
|
||||
uint32_t hash[8];
|
||||
|
||||
// Progress W1
|
||||
#pragma unroll
|
||||
for(int j=0; j<16; j++)
|
||||
{
|
||||
uint32_t T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j] + W1[j];
|
||||
uint32_t T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
|
||||
// pre
|
||||
#pragma unroll 8
|
||||
for (int k=0; k < 8; k++)
|
||||
{
|
||||
regs[k] = myr_sha256_gpu_hashTable[k];
|
||||
hash[k] = regs[k];
|
||||
}
|
||||
|
||||
#pragma unroll 7
|
||||
for (int k=6; k >= 0; k--) regs[k+1] = regs[k];
|
||||
regs[0] = T1 + T2;
|
||||
regs[4] += T1;
|
||||
}
|
||||
#pragma unroll 16
|
||||
for(int k=0;k<16;k++)
|
||||
W1[k] = SWAB32(message[k]);
|
||||
|
||||
// Progress W2...W3
|
||||
uint32_t W2[16];
|
||||
// Progress W1
|
||||
#pragma unroll 16
|
||||
for(int j=0;j<16;j++)
|
||||
{
|
||||
uint32_t T1, T2;
|
||||
T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j] + W1[j];
|
||||
T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
|
||||
|
||||
////// PART 1
|
||||
#pragma unroll
|
||||
for(int j=0; j<2; j++)
|
||||
W2[j] = s1(W1[14+j]) + W1[9+j] + s0(W1[1+j]) + W1[j];
|
||||
#pragma unroll 7
|
||||
for (int k=6; k >= 0; k--) regs[k+1] = regs[k];
|
||||
regs[0] = T1 + T2;
|
||||
regs[4] += T1;
|
||||
}
|
||||
|
||||
#pragma unroll 5
|
||||
for(int j=2; j<7;j++)
|
||||
W2[j] = s1(W2[j-2]) + W1[9+j] + s0(W1[1+j]) + W1[j];
|
||||
// Progress W2...W3
|
||||
////// PART 1
|
||||
#pragma unroll 2
|
||||
for(int j=0;j<2;j++)
|
||||
W2[j] = s1(W1[14+j]) + W1[9+j] + s0(W1[1+j]) + W1[j];
|
||||
#pragma unroll 5
|
||||
for(int j=2;j<7;j++)
|
||||
W2[j] = s1(W2[j-2]) + W1[9+j] + s0(W1[1+j]) + W1[j];
|
||||
|
||||
#pragma unroll
|
||||
for(int j=7; j<15; j++)
|
||||
W2[j] = s1(W2[j-2]) + W2[j-7] + s0(W1[1+j]) + W1[j];
|
||||
#pragma unroll 8
|
||||
for(int j=7;j<15;j++)
|
||||
W2[j] = s1(W2[j-2]) + W2[j-7] + s0(W1[1+j]) + W1[j];
|
||||
|
||||
W2[15] = s1(W2[13]) + W2[8] + s0(W2[0]) + W1[15];
|
||||
W2[15] = s1(W2[13]) + W2[8] + s0(W2[0]) + W1[15];
|
||||
|
||||
// Round function
|
||||
#pragma unroll
|
||||
for(int j=0; j<16; j++)
|
||||
{
|
||||
uint32_t T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 16] + W2[j];
|
||||
uint32_t T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
|
||||
// Rundenfunktion
|
||||
#pragma unroll 16
|
||||
for(int j=0;j<16;j++)
|
||||
{
|
||||
uint32_t T1, T2;
|
||||
T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 16] + W2[j];
|
||||
T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
|
||||
|
||||
#pragma unroll 7
|
||||
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
|
||||
regs[0] = T1 + T2;
|
||||
regs[4] += T1;
|
||||
}
|
||||
#pragma unroll 7
|
||||
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
|
||||
regs[0] = T1 + T2;
|
||||
regs[4] += T1;
|
||||
}
|
||||
|
||||
////// PART 2
|
||||
#pragma unroll
|
||||
for(int j=0; j<2; j++)
|
||||
W1[j] = s1(W2[14+j]) + W2[9+j] + s0(W2[1+j]) + W2[j];
|
||||
#pragma unroll 5
|
||||
for(int j=2; j<7; j++)
|
||||
W1[j] = s1(W1[j-2]) + W2[9+j] + s0(W2[1+j]) + W2[j];
|
||||
////// PART 2
|
||||
#pragma unroll 2
|
||||
for(int j=0;j<2;j++)
|
||||
W1[j] = s1(W2[14+j]) + W2[9+j] + s0(W2[1+j]) + W2[j];
|
||||
#pragma unroll 5
|
||||
for(int j=2;j<7;j++)
|
||||
W1[j] = s1(W1[j-2]) + W2[9+j] + s0(W2[1+j]) + W2[j];
|
||||
|
||||
#pragma unroll
|
||||
for(int j=7; j<15; j++)
|
||||
W1[j] = s1(W1[j-2]) + W1[j-7] + s0(W2[1+j]) + W2[j];
|
||||
#pragma unroll 8
|
||||
for(int j=7;j<15;j++)
|
||||
W1[j] = s1(W1[j-2]) + W1[j-7] + s0(W2[1+j]) + W2[j];
|
||||
|
||||
W1[15] = s1(W1[13]) + W1[8] + s0(W1[0]) + W2[15];
|
||||
W1[15] = s1(W1[13]) + W1[8] + s0(W1[0]) + W2[15];
|
||||
|
||||
// Round function
|
||||
#pragma unroll
|
||||
for(int j=0; j<16; j++)
|
||||
{
|
||||
uint32_t T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 32] + W1[j];
|
||||
uint32_t T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
|
||||
// Rundenfunktion
|
||||
#pragma unroll 16
|
||||
for(int j=0;j<16;j++)
|
||||
{
|
||||
uint32_t T1, T2;
|
||||
T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 32] + W1[j];
|
||||
T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
|
||||
|
||||
#pragma unroll 7
|
||||
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
|
||||
regs[0] = T1 + T2;
|
||||
regs[4] += T1;
|
||||
}
|
||||
#pragma unroll 7
|
||||
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
|
||||
regs[0] = T1 + T2;
|
||||
regs[4] += T1;
|
||||
}
|
||||
|
||||
////// PART 3
|
||||
#pragma unroll
|
||||
for(int j=0; j<2; j++)
|
||||
W2[j] = s1(W1[14+j]) + W1[9+j] + s0(W1[1+j]) + W1[j];
|
||||
////// PART 3
|
||||
#pragma unroll 2
|
||||
for(int j=0;j<2;j++)
|
||||
W2[j] = s1(W1[14+j]) + W1[9+j] + s0(W1[1+j]) + W1[j];
|
||||
#pragma unroll 5
|
||||
for(int j=2;j<7;j++)
|
||||
W2[j] = s1(W2[j-2]) + W1[9+j] + s0(W1[1+j]) + W1[j];
|
||||
|
||||
#pragma unroll 5
|
||||
for(int j=2; j<7; j++)
|
||||
W2[j] = s1(W2[j-2]) + W1[9+j] + s0(W1[1+j]) + W1[j];
|
||||
#pragma unroll 8
|
||||
for(int j=7;j<15;j++)
|
||||
W2[j] = s1(W2[j-2]) + W2[j-7] + s0(W1[1+j]) + W1[j];
|
||||
|
||||
#pragma unroll
|
||||
for(int j=7; j<15; j++)
|
||||
W2[j] = s1(W2[j-2]) + W2[j-7] + s0(W1[1+j]) + W1[j];
|
||||
W2[15] = s1(W2[13]) + W2[8] + s0(W2[0]) + W1[15];
|
||||
|
||||
W2[15] = s1(W2[13]) + W2[8] + s0(W2[0]) + W1[15];
|
||||
// Rundenfunktion
|
||||
#pragma unroll 16
|
||||
for(int j=0;j<16;j++)
|
||||
{
|
||||
uint32_t T1, T2;
|
||||
T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 48] + W2[j];
|
||||
T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
|
||||
|
||||
// Round function
|
||||
#pragma unroll
|
||||
for(int j=0; j<16; j++)
|
||||
{
|
||||
uint32_t T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 48] + W2[j];
|
||||
uint32_t T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
|
||||
#pragma unroll 7
|
||||
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
|
||||
regs[0] = T1 + T2;
|
||||
regs[4] += T1;
|
||||
}
|
||||
|
||||
#pragma unroll 7
|
||||
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
|
||||
regs[0] = T1 + T2;
|
||||
regs[4] += T1;
|
||||
}
|
||||
#pragma unroll 8
|
||||
for(int k=0;k<8;k++)
|
||||
hash[k] += regs[k];
|
||||
|
||||
uint32_t hash[8] = {
|
||||
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
||||
};
|
||||
/////
|
||||
///// Zweite Runde (wegen Msg-Padding)
|
||||
/////
|
||||
#pragma unroll 8
|
||||
for(int k=0;k<8;k++)
|
||||
regs[k] = hash[k];
|
||||
|
||||
#pragma unroll 8
|
||||
for(int k=0; k<8; k++)
|
||||
hash[k] += regs[k];
|
||||
// Progress W1
|
||||
#pragma unroll 64
|
||||
for(int j=0;j<64;j++)
|
||||
{
|
||||
uint32_t T1, T2;
|
||||
T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable2[j];
|
||||
T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
|
||||
|
||||
/////
|
||||
///// 2nd Round (wegen Msg-Padding)
|
||||
/////
|
||||
#pragma unroll
|
||||
for(int k=0; k<8; k++)
|
||||
regs[k] = hash[k];
|
||||
#pragma unroll 7
|
||||
for (int k=6; k >= 0; k--) regs[k+1] = regs[k];
|
||||
regs[0] = T1 + T2;
|
||||
regs[4] += T1;
|
||||
}
|
||||
|
||||
// Progress W1
|
||||
#pragma unroll
|
||||
for(int j=0; j<64; j++)
|
||||
{
|
||||
uint32_t T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable2[j];
|
||||
uint32_t T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
|
||||
#pragma unroll 8
|
||||
for(int k=0;k<8;k++)
|
||||
hash[k] += regs[k];
|
||||
|
||||
#pragma unroll 7
|
||||
for (int k=6; k >= 0; k--) regs[k+1] = regs[k];
|
||||
regs[0] = T1 + T2;
|
||||
regs[4] += T1;
|
||||
}
|
||||
//// FERTIG
|
||||
|
||||
#if 0
|
||||
// Full sha hash
|
||||
#pragma unroll
|
||||
for(int k=0; k<8; k++)
|
||||
hash[k] += regs[k];
|
||||
#pragma unroll 8
|
||||
for(int k=0;k<8;k++)
|
||||
message[k] = SWAB32(hash[k]);
|
||||
}
|
||||
|
||||
#pragma unroll
|
||||
for(int k=0; k<8; k++)
|
||||
message[k] = SWAB32(hash[k]);
|
||||
#else
|
||||
message[6] = SWAB32(hash[6] + regs[6]);
|
||||
message[7] = SWAB32(hash[7] + regs[7]);
|
||||
__global__ void __launch_bounds__(256, 4)
|
||||
myriadgroestl_gpu_hash_quad(uint32_t threads, uint32_t startNounce, uint32_t *hashBuffer)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 300
|
||||
// durch 4 dividieren, weil jeweils 4 Threads zusammen ein Hash berechnen
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x) / 4;
|
||||
if (thread < threads)
|
||||
{
|
||||
// GROESTL
|
||||
uint32_t paddedInput[8];
|
||||
#pragma unroll 8
|
||||
for(int k=0;k<8;k++) paddedInput[k] = myriadgroestl_gpu_msg[4*k+threadIdx.x%4];
|
||||
|
||||
uint32_t nounce = startNounce + thread;
|
||||
if ((threadIdx.x % 4) == 3)
|
||||
paddedInput[4] = SWAB32(nounce); // 4*4+3 = 19
|
||||
|
||||
uint32_t msgBitsliced[8];
|
||||
to_bitslice_quad(paddedInput, msgBitsliced);
|
||||
|
||||
uint32_t state[8];
|
||||
|
||||
groestl512_progressMessage_quad(state, msgBitsliced);
|
||||
|
||||
uint32_t out_state[16];
|
||||
from_bitslice_quad(state, out_state);
|
||||
|
||||
if ((threadIdx.x & 0x03) == 0)
|
||||
{
|
||||
uint32_t *outpHash = &hashBuffer[16 * thread];
|
||||
#pragma unroll 16
|
||||
for(int k=0;k<16;k++) outpHash[k] = out_state[k];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
__global__
|
||||
//__launch_bounds__(256, 6) // we want <= 40 regs
|
||||
void myriadgroestl_gpu_hash_sha(uint32_t threads, uint32_t startNounce, uint32_t *hashBuffer, uint32_t *resNonces)
|
||||
__global__ void
|
||||
myriadgroestl_gpu_hash_quad2(uint32_t threads, uint32_t startNounce, uint32_t *resNounce, uint32_t *hashBuffer)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 300
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
const uint32_t nonce = startNounce + thread;
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t nounce = startNounce + thread;
|
||||
|
||||
uint32_t out_state[16];
|
||||
uint32_t *inpHash = &hashBuffer[16 * thread];
|
||||
uint32_t out_state[16];
|
||||
uint32_t *inpHash = &hashBuffer[16 * thread];
|
||||
#pragma unroll 16
|
||||
for (int i=0; i < 16; i++)
|
||||
out_state[i] = inpHash[i];
|
||||
|
||||
#pragma unroll 16
|
||||
for (int i=0; i < 16; i++)
|
||||
out_state[i] = inpHash[i];
|
||||
myriadgroestl_gpu_sha256(out_state);
|
||||
|
||||
myriadgroestl_gpu_sha256(out_state);
|
||||
int i, position = -1;
|
||||
bool rc = true;
|
||||
|
||||
if (out_state[7] <= pTarget[1] && out_state[6] <= pTarget[0])
|
||||
{
|
||||
uint32_t tmp = atomicExch(&resNonces[0], nonce);
|
||||
if (tmp != UINT32_MAX)
|
||||
resNonces[1] = tmp;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#pragma unroll 8
|
||||
for (i = 7; i >= 0; i--) {
|
||||
if (out_state[i] > pTarget[i]) {
|
||||
if(position < i) {
|
||||
position = i;
|
||||
rc = false;
|
||||
}
|
||||
}
|
||||
if (out_state[i] < pTarget[i]) {
|
||||
if(position < i) {
|
||||
position = i;
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__global__
|
||||
__launch_bounds__(256, 4)
|
||||
void myriadgroestl_gpu_hash_quad(uint32_t threads, uint32_t startNounce, uint32_t *hashBuffer)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 300
|
||||
// durch 4 dividieren, weil jeweils 4 Threads zusammen ein Hash berechnen
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x) / 4;
|
||||
if (thread < threads)
|
||||
{
|
||||
// GROESTL
|
||||
uint32_t paddedInput[8];
|
||||
#pragma unroll 8
|
||||
for(int k=0; k<8; k++)
|
||||
paddedInput[k] = myriadgroestl_gpu_msg[4*k+threadIdx.x%4];
|
||||
|
||||
uint32_t nounce = startNounce + thread;
|
||||
if ((threadIdx.x % 4) == 3)
|
||||
paddedInput[4] = SWAB32(nounce); // 4*4+3 = 19
|
||||
|
||||
uint32_t msgBitsliced[8];
|
||||
to_bitslice_quad(paddedInput, msgBitsliced);
|
||||
|
||||
uint32_t state[8];
|
||||
groestl512_progressMessage_quad(state, msgBitsliced);
|
||||
|
||||
uint32_t out_state[16];
|
||||
from_bitslice_quad(state, out_state);
|
||||
|
||||
if ((threadIdx.x & 0x03) == 0)
|
||||
{
|
||||
uint32_t *outpHash = &hashBuffer[16 * thread];
|
||||
#pragma unroll 16
|
||||
for(int k=0; k<16; k++) outpHash[k] = out_state[k];
|
||||
}
|
||||
}
|
||||
if(rc == true)
|
||||
if(resNounce[0] > nounce)
|
||||
resNounce[0] = nounce;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -295,66 +303,93 @@ void myriadgroestl_gpu_hash_quad(uint32_t threads, uint32_t startNounce, uint32_
|
||||
__host__
|
||||
void myriadgroestl_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
uint32_t temp[64];
|
||||
for(int i=0; i<64; i++)
|
||||
temp[i] = myr_sha256_cpu_w2Table[i] + myr_sha256_cpu_constantTable[i];
|
||||
cudaMemcpyToSymbol( myr_sha256_gpu_hashTable,
|
||||
myr_sha256_cpu_hashTable,
|
||||
sizeof(uint32_t) * 8 );
|
||||
|
||||
cudaMemcpyToSymbol( myr_sha256_gpu_constantTable2, temp, sizeof(uint32_t) * 64 );
|
||||
cudaMemcpyToSymbol( myr_sha256_gpu_constantTable,
|
||||
myr_sha256_cpu_constantTable,
|
||||
sizeof(uint32_t) * 64 );
|
||||
|
||||
cudaMemcpyToSymbol( myr_sha256_gpu_constantTable,
|
||||
myr_sha256_cpu_constantTable,
|
||||
sizeof(uint32_t) * 64 );
|
||||
// zweite CPU-Tabelle bauen und auf die GPU laden
|
||||
uint32_t temp[64];
|
||||
for(int i=0;i<64;i++)
|
||||
temp[i] = myr_sha256_cpu_w2Table[i] + myr_sha256_cpu_constantTable[i];
|
||||
|
||||
// to check if the binary supports SM3+
|
||||
cuda_get_arch(thr_id);
|
||||
cudaMemcpyToSymbol( myr_sha256_gpu_constantTable2,
|
||||
temp,
|
||||
sizeof(uint32_t) * 64 );
|
||||
|
||||
cudaMalloc(&d_outputHashes[thr_id], (size_t) 64 * threads);
|
||||
cudaMalloc(&d_resultNonces[thr_id], 2 * sizeof(uint32_t));
|
||||
// Speicher für Gewinner-Nonce belegen
|
||||
cudaMalloc(&d_resultNonce[thr_id], sizeof(uint32_t));
|
||||
|
||||
// Speicher für temporäreHashes
|
||||
cudaMalloc(&d_outputHashes[thr_id], 16*sizeof(uint32_t)*threads);
|
||||
}
|
||||
|
||||
__host__
|
||||
void myriadgroestl_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_outputHashes[thr_id]);
|
||||
cudaFree(d_resultNonces[thr_id]);
|
||||
cudaFree(d_resultNonce[thr_id]);
|
||||
cudaFree(d_outputHashes[thr_id]);
|
||||
}
|
||||
|
||||
__host__
|
||||
void myriadgroestl_cpu_setBlock(int thr_id, void *data, uint32_t *pTargetIn)
|
||||
void myriadgroestl_cpu_setBlock(int thr_id, void *data, void *pTargetIn)
|
||||
{
|
||||
uint32_t msgBlock[32] = { 0 };
|
||||
memcpy(&msgBlock[0], data, 80);
|
||||
msgBlock[20] = 0x80;
|
||||
msgBlock[31] = 0x01000000;
|
||||
// Nachricht expandieren und setzen
|
||||
uint32_t msgBlock[32];
|
||||
|
||||
cudaMemcpyToSymbol(myriadgroestl_gpu_msg, msgBlock, 128);
|
||||
cudaMemcpyToSymbol(pTarget, &pTargetIn[6], 2 * sizeof(uint32_t));
|
||||
memset(msgBlock, 0, sizeof(uint32_t) * 32);
|
||||
memcpy(&msgBlock[0], data, 80);
|
||||
|
||||
// Erweitere die Nachricht auf den Nachrichtenblock (padding)
|
||||
// Unsere Nachricht hat 80 Byte
|
||||
msgBlock[20] = 0x80;
|
||||
msgBlock[31] = 0x01000000;
|
||||
|
||||
// groestl512 braucht hierfür keinen CPU-Code (die einzige Runde wird
|
||||
// auf der GPU ausgeführt)
|
||||
|
||||
// Blockheader setzen (korrekte Nonce und Hefty Hash fehlen da drin noch)
|
||||
cudaMemcpyToSymbol( myriadgroestl_gpu_msg,
|
||||
msgBlock,
|
||||
128);
|
||||
|
||||
cudaMemset(d_resultNonce[thr_id], 0xFF, sizeof(uint32_t));
|
||||
cudaMemcpyToSymbol( pTarget,
|
||||
pTargetIn,
|
||||
sizeof(uint32_t) * 8 );
|
||||
}
|
||||
|
||||
__host__
|
||||
void myriadgroestl_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *resNounce)
|
||||
void myriadgroestl_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outputHashes, uint32_t *nounce)
|
||||
{
|
||||
uint32_t threadsperblock = 256;
|
||||
uint32_t threadsperblock = 256;
|
||||
|
||||
cudaMemset(d_resultNonces[thr_id], 0xFF, 2 * sizeof(uint32_t));
|
||||
// Compute 3.0 benutzt die registeroptimierte Quad Variante mit Warp Shuffle
|
||||
// mit den Quad Funktionen brauchen wir jetzt 4 threads pro Hash, daher Faktor 4 bei der Blockzahl
|
||||
const int factor=4;
|
||||
|
||||
// Compute 3.0 benutzt die registeroptimierte Quad Variante mit Warp Shuffle
|
||||
// mit den Quad Funktionen brauchen wir jetzt 4 threads pro Hash, daher Faktor 4 bei der Blockzahl
|
||||
const int factor = 4;
|
||||
// Größe des dynamischen Shared Memory Bereichs
|
||||
size_t shared_size = 0;
|
||||
|
||||
dim3 grid(factor*((threads + threadsperblock-1)/threadsperblock));
|
||||
dim3 block(threadsperblock);
|
||||
cudaMemset(d_resultNonce[thr_id], 0xFF, sizeof(uint32_t));
|
||||
// berechne wie viele Thread Blocks wir brauchen
|
||||
dim3 grid(factor*((threads + threadsperblock-1)/threadsperblock));
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
int dev_id = device_map[thr_id];
|
||||
if (device_sm[dev_id] < 300 || cuda_arch[dev_id] < 300) {
|
||||
printf("Sorry, This algo is not supported by this GPU arch (SM 3.0 required)");
|
||||
return;
|
||||
}
|
||||
if (device_sm[device_map[thr_id]] < 300) {
|
||||
printf("Sorry, This algo is not supported by this GPU arch (SM 3.0 required)");
|
||||
return;
|
||||
}
|
||||
|
||||
myriadgroestl_gpu_hash_quad <<< grid, block >>> (threads, startNounce, d_outputHashes[thr_id]);
|
||||
myriadgroestl_gpu_hash_quad<<<grid, block, shared_size>>>(threads, startNounce, d_outputHashes[thr_id]);
|
||||
dim3 grid2((threads + threadsperblock-1)/threadsperblock);
|
||||
myriadgroestl_gpu_hash_quad2<<<grid2, block, shared_size>>>(threads, startNounce, d_resultNonce[thr_id], d_outputHashes[thr_id]);
|
||||
|
||||
dim3 grid2((threads + threadsperblock-1)/threadsperblock);
|
||||
myriadgroestl_gpu_hash_sha <<< grid2, block >>> (threads, startNounce, d_outputHashes[thr_id], d_resultNonces[thr_id]);
|
||||
// Strategisches Sleep Kommando zur Senkung der CPU Last
|
||||
MyStreamSynchronize(NULL, 0, thr_id);
|
||||
|
||||
cudaMemcpy(resNounce, d_resultNonces[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
cudaMemcpy(nounce, d_resultNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
}
|
||||
@@ -22,13 +22,13 @@ extern "C" void nist5hash(void *state, const void *input)
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_skein512_context ctx_skein;
|
||||
|
||||
|
||||
uint8_t hash[64];
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, 80);
|
||||
sph_blake512_close(&ctx_blake, (void*) hash);
|
||||
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, (const void*) hash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, (void*) hash);
|
||||
@@ -56,6 +56,7 @@ extern "C" int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce,
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
int res = 0;
|
||||
|
||||
uint32_t throughput = cuda_default_throughput(thr_id, 1 << 20); // 256*256*16
|
||||
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
|
||||
@@ -65,14 +66,8 @@ extern "C" int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce,
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaDeviceSynchronize();
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
if (opt_cudaschedule == -1 && gpu_threads == 1) {
|
||||
cudaDeviceReset();
|
||||
// reduce cpu usage
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
CUDA_LOG_ERROR();
|
||||
}
|
||||
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
|
||||
|
||||
// Constants copy/init (no device alloc in these algos)
|
||||
quark_blake512_cpu_init(thr_id, throughput);
|
||||
@@ -100,8 +95,6 @@ extern "C" int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce,
|
||||
quark_blake512_cpu_setBlock_80(thr_id, endiandata);
|
||||
cuda_check_cpu_setTarget(ptarget);
|
||||
|
||||
work->valid_nonces = 0;
|
||||
|
||||
do {
|
||||
int order = 0;
|
||||
|
||||
@@ -114,35 +107,31 @@ extern "C" int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce,
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
work->nonces[0] = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (work->nonces[0] != UINT32_MAX)
|
||||
uint32_t foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t _ALIGN(64) vhash[8];
|
||||
be32enc(&endiandata[19], work->nonces[0]);
|
||||
nist5hash(vhash, endiandata);
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
nist5hash(vhash64, endiandata);
|
||||
|
||||
if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
|
||||
work->valid_nonces = 1;
|
||||
work_set_target_ratio(work, vhash);
|
||||
work->nonces[1] = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
if (work->nonces[1] != 0) {
|
||||
be32enc(&endiandata[19], work->nonces[1]);
|
||||
nist5hash(vhash, endiandata);
|
||||
bn_set_target_ratio(work, vhash, 1);
|
||||
work->valid_nonces++;
|
||||
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
|
||||
} else {
|
||||
pdata[19] = work->nonces[0] + 1; // cursor
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
work_set_target_ratio(work, vhash64);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
nist5hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
work_set_target_ratio(work, vhash64);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
pdata[19] = foundNonce;
|
||||
goto out;
|
||||
}
|
||||
else if (vhash[7] > Htarg) {
|
||||
gpu_increment_reject(thr_id);
|
||||
if (!opt_quiet)
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
|
||||
pdata[19] = work->nonces[0] + 1;
|
||||
continue;
|
||||
else {
|
||||
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,13 +145,13 @@ extern "C" int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce,
|
||||
} while (!work_restart[thr_id].restart);
|
||||
|
||||
out:
|
||||
// *hashes_done = pdata[19] - first_nonce;
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
#ifdef USE_STREAMS
|
||||
for (int i = 0; i < 5; i++)
|
||||
cudaStreamDestroy(stream[i]);
|
||||
#endif
|
||||
|
||||
return work->valid_nonces;
|
||||
return res;
|
||||
}
|
||||
|
||||
// ressources cleanup
|
||||
@@ -1,47 +0,0 @@
|
||||
#include "cuda_helper.h"
|
||||
|
||||
/* Macros for uint2 operations (used by skein) */
|
||||
|
||||
__device__ __forceinline__
|
||||
uint2 ROR8(const uint2 a) {
|
||||
uint2 result;
|
||||
result.x = __byte_perm(a.x, a.y, 0x4321);
|
||||
result.y = __byte_perm(a.y, a.x, 0x4321);
|
||||
return result;
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
uint2 ROL24(const uint2 a) {
|
||||
uint2 result;
|
||||
result.x = __byte_perm(a.x, a.y, 0x0765);
|
||||
result.y = __byte_perm(a.y, a.x, 0x0765);
|
||||
return result;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint2 operator+ (const uint2 a, const uint32_t b)
|
||||
{
|
||||
#if 0 && defined(__CUDA_ARCH__) && CUDA_VERSION < 7000
|
||||
uint2 result;
|
||||
asm(
|
||||
"add.cc.u32 %0,%2,%4; \n\t"
|
||||
"addc.u32 %1,%3,%5; \n\t"
|
||||
: "=r"(result.x), "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(b), "r"(0));
|
||||
return result;
|
||||
#else
|
||||
return vectorize(devectorize(a) + b);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* whirlpool ones */
|
||||
#ifdef __CUDA_ARCH__
|
||||
__device__ __forceinline__
|
||||
uint2 ROL16(const uint2 a) {
|
||||
uint2 result;
|
||||
result.x = __byte_perm(a.x, a.y, 0x1076);
|
||||
result.y = __byte_perm(a.y, a.x, 0x1076);
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
#define ROL16(a) make_uint2(a.x, a.y) /* bad, just to define it */
|
||||
#endif
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - optimized C implementations
|
||||
|
||||
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef __BLAKE2_CONFIG_H__
|
||||
#define __BLAKE2_CONFIG_H__
|
||||
|
||||
// These don't work everywhere
|
||||
#if (defined(__SSE2__) || defined(_M_AMD_64) || defined(_M_X64))
|
||||
#define HAVE_SSE2
|
||||
#endif
|
||||
|
||||
#if defined(__SSSE3__)
|
||||
#define HAVE_SSSE3
|
||||
#endif
|
||||
|
||||
#if defined(__SSE4_1__)
|
||||
#define HAVE_SSE41
|
||||
#endif
|
||||
|
||||
#if defined(__AVX__)
|
||||
#define HAVE_AVX
|
||||
#endif
|
||||
|
||||
#if defined(__XOP__)
|
||||
#define HAVE_XOP
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_AVX2
|
||||
#ifndef HAVE_AVX
|
||||
#define HAVE_AVX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_XOP
|
||||
#ifndef HAVE_AVX
|
||||
#define HAVE_AVX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AVX
|
||||
#ifndef HAVE_SSE41
|
||||
#define HAVE_SSE41
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SSE41
|
||||
#ifndef HAVE_SSSE3
|
||||
#define HAVE_SSSE3
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SSSE3
|
||||
#define HAVE_SSE2
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SSE2)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// enforce required stuff for now
|
||||
#define HAVE_SSE2
|
||||
//#define HAVE_SSSE3
|
||||
#define HAVE_SSE41
|
||||
#else
|
||||
# error "This code requires at least SSE 4.1"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - optimized C implementations
|
||||
|
||||
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef __BLAKE2_IMPL_H__
|
||||
#define __BLAKE2_IMPL_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static inline uint32_t load32( const void *src )
|
||||
{
|
||||
#if defined(NATIVE_LITTLE_ENDIAN)
|
||||
uint32_t w;
|
||||
memcpy(&w, src, sizeof w);
|
||||
return w;
|
||||
#else
|
||||
const uint8_t *p = ( const uint8_t * )src;
|
||||
uint32_t w = *p++;
|
||||
w |= ( uint32_t )( *p++ ) << 8;
|
||||
w |= ( uint32_t )( *p++ ) << 16;
|
||||
w |= ( uint32_t )( *p++ ) << 24;
|
||||
return w;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint64_t load64( const void *src )
|
||||
{
|
||||
#if defined(NATIVE_LITTLE_ENDIAN)
|
||||
uint64_t w;
|
||||
memcpy(&w, src, sizeof w);
|
||||
return w;
|
||||
#else
|
||||
const uint8_t *p = ( const uint8_t * )src;
|
||||
uint64_t w = *p++;
|
||||
w |= ( uint64_t )( *p++ ) << 8;
|
||||
w |= ( uint64_t )( *p++ ) << 16;
|
||||
w |= ( uint64_t )( *p++ ) << 24;
|
||||
w |= ( uint64_t )( *p++ ) << 32;
|
||||
w |= ( uint64_t )( *p++ ) << 40;
|
||||
w |= ( uint64_t )( *p++ ) << 48;
|
||||
w |= ( uint64_t )( *p++ ) << 56;
|
||||
return w;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void store32( void *dst, uint32_t w )
|
||||
{
|
||||
#if defined(NATIVE_LITTLE_ENDIAN)
|
||||
memcpy(dst, &w, sizeof w);
|
||||
#else
|
||||
uint8_t *p = ( uint8_t * )dst;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void store64( void *dst, uint64_t w )
|
||||
{
|
||||
#if defined(NATIVE_LITTLE_ENDIAN)
|
||||
memcpy(dst, &w, sizeof w);
|
||||
#else
|
||||
uint8_t *p = ( uint8_t * )dst;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint64_t load48( const void *src )
|
||||
{
|
||||
const uint8_t *p = ( const uint8_t * )src;
|
||||
uint64_t w = *p++;
|
||||
w |= ( uint64_t )( *p++ ) << 8;
|
||||
w |= ( uint64_t )( *p++ ) << 16;
|
||||
w |= ( uint64_t )( *p++ ) << 24;
|
||||
w |= ( uint64_t )( *p++ ) << 32;
|
||||
w |= ( uint64_t )( *p++ ) << 40;
|
||||
return w;
|
||||
}
|
||||
|
||||
static inline void store48( void *dst, uint64_t w )
|
||||
{
|
||||
uint8_t *p = ( uint8_t * )dst;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w; w >>= 8;
|
||||
*p++ = ( uint8_t )w;
|
||||
}
|
||||
|
||||
static inline uint32_t rotl32( const uint32_t w, const unsigned c )
|
||||
{
|
||||
return ( w << c ) | ( w >> ( 32 - c ) );
|
||||
}
|
||||
|
||||
static inline uint64_t rotl64( const uint64_t w, const unsigned c )
|
||||
{
|
||||
return ( w << c ) | ( w >> ( 64 - c ) );
|
||||
}
|
||||
|
||||
static inline uint32_t rotr32( const uint32_t w, const unsigned c )
|
||||
{
|
||||
return ( w >> c ) | ( w << ( 32 - c ) );
|
||||
}
|
||||
|
||||
static inline uint64_t rotr64( const uint64_t w, const unsigned c )
|
||||
{
|
||||
return ( w >> c ) | ( w << ( 64 - c ) );
|
||||
}
|
||||
|
||||
/* prevents compiler optimizing out memset() */
|
||||
static inline void secure_zero_memory( void *v, size_t n )
|
||||
{
|
||||
volatile uint8_t *p = ( volatile uint8_t * )v;
|
||||
while( n-- ) *p++ = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
#define _mm_roti_epi64(x, c) \
|
||||
(-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \
|
||||
: (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \
|
||||
: (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \
|
||||
: (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \
|
||||
: _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c))))
|
||||
|
||||
#define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \
|
||||
row1l = _mm_add_epi64(row1l, row2l); \
|
||||
row1h = _mm_add_epi64(row1h, 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, -24); \
|
||||
row2h = _mm_roti_epi64(row2h, -24); \
|
||||
|
||||
#define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \
|
||||
row1l = _mm_add_epi64(row1l, row2l); \
|
||||
row1h = _mm_add_epi64(row1h, 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, -63); \
|
||||
row2h = _mm_roti_epi64(row2h, -63); \
|
||||
|
||||
#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 BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \
|
||||
G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
|
||||
G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
|
||||
\
|
||||
DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
|
||||
\
|
||||
G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
|
||||
G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \
|
||||
\
|
||||
UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h);
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - optimized C implementations
|
||||
|
||||
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef __BLAKE2_H__
|
||||
#define __BLAKE2_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define ALIGN(x) __declspec(align(x))
|
||||
#else
|
||||
#define ALIGN(x) __attribute__ ((__aligned__(x)))
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum blake2b_constant
|
||||
{
|
||||
BLAKE2B_BLOCKBYTES = 128,
|
||||
BLAKE2B_OUTBYTES = 64,
|
||||
BLAKE2B_KEYBYTES = 64,
|
||||
BLAKE2B_SALTBYTES = 16,
|
||||
BLAKE2B_PERSONALBYTES = 16
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct __blake2b_param
|
||||
{
|
||||
uint8_t digest_length; // 1
|
||||
uint8_t key_length; // 2
|
||||
uint8_t fanout; // 3
|
||||
uint8_t depth; // 4
|
||||
uint32_t leaf_length; // 8
|
||||
uint64_t node_offset; // 16
|
||||
uint8_t node_depth; // 17
|
||||
uint8_t inner_length; // 18
|
||||
uint8_t reserved[14]; // 32
|
||||
uint8_t salt[BLAKE2B_SALTBYTES]; // 48
|
||||
uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64
|
||||
} blake2b_param;
|
||||
|
||||
ALIGN( 64 ) typedef struct __blake2b_state
|
||||
{
|
||||
uint64_t h[8];
|
||||
uint8_t buf[BLAKE2B_BLOCKBYTES];
|
||||
uint16_t counter;
|
||||
uint8_t buflen;
|
||||
uint8_t lastblock;
|
||||
} blake2b_state;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
int eq_blake2b_init( blake2b_state *S, const uint8_t outlen );
|
||||
int eq_blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen );
|
||||
int eq_blake2b_init_param( blake2b_state *S, const blake2b_param *P );
|
||||
int eq_blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen );
|
||||
int eq_blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen );
|
||||
|
||||
// Simple API
|
||||
int eq_blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen );
|
||||
|
||||
static inline int eq_blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen )
|
||||
{
|
||||
return eq_blake2b( out, in, key, outlen, inlen, keylen );
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - optimized C implementations
|
||||
|
||||
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef __BLAKE2B_LOAD_SSE2_H__
|
||||
#define __BLAKE2B_LOAD_SSE2_H__
|
||||
|
||||
#define LOAD_MSG_0_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4)
|
||||
#define LOAD_MSG_0_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5)
|
||||
#define LOAD_MSG_0_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12)
|
||||
#define LOAD_MSG_0_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13)
|
||||
#define LOAD_MSG_1_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9)
|
||||
#define LOAD_MSG_1_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15)
|
||||
#define LOAD_MSG_1_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11)
|
||||
#define LOAD_MSG_1_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7)
|
||||
#define LOAD_MSG_2_1(b0, b1) b0 = _mm_set_epi64x(m12, m11); b1 = _mm_set_epi64x(m15, m5)
|
||||
#define LOAD_MSG_2_2(b0, b1) b0 = _mm_set_epi64x(m0, m8); b1 = _mm_set_epi64x(m13, m2)
|
||||
#define LOAD_MSG_2_3(b0, b1) b0 = _mm_set_epi64x(m3, m10); b1 = _mm_set_epi64x(m9, m7)
|
||||
#define LOAD_MSG_2_4(b0, b1) b0 = _mm_set_epi64x(m6, m14); b1 = _mm_set_epi64x(m4, m1)
|
||||
#define LOAD_MSG_3_1(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m13)
|
||||
#define LOAD_MSG_3_2(b0, b1) b0 = _mm_set_epi64x(m1, m9); b1 = _mm_set_epi64x(m14, m12)
|
||||
#define LOAD_MSG_3_3(b0, b1) b0 = _mm_set_epi64x(m5, m2); b1 = _mm_set_epi64x(m15, m4)
|
||||
#define LOAD_MSG_3_4(b0, b1) b0 = _mm_set_epi64x(m10, m6); b1 = _mm_set_epi64x(m8, m0)
|
||||
#define LOAD_MSG_4_1(b0, b1) b0 = _mm_set_epi64x(m5, m9); b1 = _mm_set_epi64x(m10, m2)
|
||||
#define LOAD_MSG_4_2(b0, b1) b0 = _mm_set_epi64x(m7, m0); b1 = _mm_set_epi64x(m15, m4)
|
||||
#define LOAD_MSG_4_3(b0, b1) b0 = _mm_set_epi64x(m11, m14); b1 = _mm_set_epi64x(m3, m6)
|
||||
#define LOAD_MSG_4_4(b0, b1) b0 = _mm_set_epi64x(m12, m1); b1 = _mm_set_epi64x(m13, m8)
|
||||
#define LOAD_MSG_5_1(b0, b1) b0 = _mm_set_epi64x(m6, m2); b1 = _mm_set_epi64x(m8, m0)
|
||||
#define LOAD_MSG_5_2(b0, b1) b0 = _mm_set_epi64x(m10, m12); b1 = _mm_set_epi64x(m3, m11)
|
||||
#define LOAD_MSG_5_3(b0, b1) b0 = _mm_set_epi64x(m7, m4); b1 = _mm_set_epi64x(m1, m15)
|
||||
#define LOAD_MSG_5_4(b0, b1) b0 = _mm_set_epi64x(m5, m13); b1 = _mm_set_epi64x(m9, m14)
|
||||
#define LOAD_MSG_6_1(b0, b1) b0 = _mm_set_epi64x(m1, m12); b1 = _mm_set_epi64x(m4, m14)
|
||||
#define LOAD_MSG_6_2(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m10, m13)
|
||||
#define LOAD_MSG_6_3(b0, b1) b0 = _mm_set_epi64x(m6, m0); b1 = _mm_set_epi64x(m8, m9)
|
||||
#define LOAD_MSG_6_4(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m2)
|
||||
#define LOAD_MSG_7_1(b0, b1) b0 = _mm_set_epi64x(m7, m13); b1 = _mm_set_epi64x(m3, m12)
|
||||
#define LOAD_MSG_7_2(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m9, m1)
|
||||
#define LOAD_MSG_7_3(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m2, m8)
|
||||
#define LOAD_MSG_7_4(b0, b1) b0 = _mm_set_epi64x(m4, m0); b1 = _mm_set_epi64x(m10, m6)
|
||||
#define LOAD_MSG_8_1(b0, b1) b0 = _mm_set_epi64x(m14, m6); b1 = _mm_set_epi64x(m0, m11)
|
||||
#define LOAD_MSG_8_2(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m8, m3)
|
||||
#define LOAD_MSG_8_3(b0, b1) b0 = _mm_set_epi64x(m13, m12); b1 = _mm_set_epi64x(m10, m1)
|
||||
#define LOAD_MSG_8_4(b0, b1) b0 = _mm_set_epi64x(m7, m2); b1 = _mm_set_epi64x(m5, m4)
|
||||
#define LOAD_MSG_9_1(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m1, m7)
|
||||
#define LOAD_MSG_9_2(b0, b1) b0 = _mm_set_epi64x(m4, m2); b1 = _mm_set_epi64x(m5, m6)
|
||||
#define LOAD_MSG_9_3(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m13, m3)
|
||||
#define LOAD_MSG_9_4(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m0, m12)
|
||||
#define LOAD_MSG_10_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4)
|
||||
#define LOAD_MSG_10_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5)
|
||||
#define LOAD_MSG_10_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12)
|
||||
#define LOAD_MSG_10_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13)
|
||||
#define LOAD_MSG_11_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9)
|
||||
#define LOAD_MSG_11_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15)
|
||||
#define LOAD_MSG_11_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11)
|
||||
#define LOAD_MSG_11_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,402 +0,0 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - optimized C implementations
|
||||
|
||||
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef __BLAKE2B_LOAD_SSE41_H__
|
||||
#define __BLAKE2B_LOAD_SSE41_H__
|
||||
|
||||
#define LOAD_MSG_0_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m0, m1); \
|
||||
b1 = _mm_unpacklo_epi64(m2, m3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_0_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m0, m1); \
|
||||
b1 = _mm_unpackhi_epi64(m2, m3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_0_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m4, m5); \
|
||||
b1 = _mm_unpacklo_epi64(m6, m7); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_0_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m4, m5); \
|
||||
b1 = _mm_unpackhi_epi64(m6, m7); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_1_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m7, m2); \
|
||||
b1 = _mm_unpackhi_epi64(m4, m6); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_1_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m5, m4); \
|
||||
b1 = _mm_alignr_epi8(m3, m7, 8); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_1_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_shuffle_epi32(m0, _MM_SHUFFLE(1,0,3,2)); \
|
||||
b1 = _mm_unpackhi_epi64(m5, m2); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_1_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m6, m1); \
|
||||
b1 = _mm_unpackhi_epi64(m3, m1); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_2_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_alignr_epi8(m6, m5, 8); \
|
||||
b1 = _mm_unpackhi_epi64(m2, m7); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_2_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m4, m0); \
|
||||
b1 = _mm_blend_epi16(m1, m6, 0xF0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_2_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_blend_epi16(m5, m1, 0xF0); \
|
||||
b1 = _mm_unpackhi_epi64(m3, m4); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_2_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m7, m3); \
|
||||
b1 = _mm_alignr_epi8(m2, m0, 8); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_3_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m3, m1); \
|
||||
b1 = _mm_unpackhi_epi64(m6, m5); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_3_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m4, m0); \
|
||||
b1 = _mm_unpacklo_epi64(m6, m7); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_3_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_blend_epi16(m1, m2, 0xF0); \
|
||||
b1 = _mm_blend_epi16(m2, m7, 0xF0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_3_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m3, m5); \
|
||||
b1 = _mm_unpacklo_epi64(m0, m4); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_4_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m4, m2); \
|
||||
b1 = _mm_unpacklo_epi64(m1, m5); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_4_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_blend_epi16(m0, m3, 0xF0); \
|
||||
b1 = _mm_blend_epi16(m2, m7, 0xF0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_4_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_blend_epi16(m7, m5, 0xF0); \
|
||||
b1 = _mm_blend_epi16(m3, m1, 0xF0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_4_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_alignr_epi8(m6, m0, 8); \
|
||||
b1 = _mm_blend_epi16(m4, m6, 0xF0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_5_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m1, m3); \
|
||||
b1 = _mm_unpacklo_epi64(m0, m4); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_5_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m6, m5); \
|
||||
b1 = _mm_unpackhi_epi64(m5, m1); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_5_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_blend_epi16(m2, m3, 0xF0); \
|
||||
b1 = _mm_unpackhi_epi64(m7, m0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_5_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m6, m2); \
|
||||
b1 = _mm_blend_epi16(m7, m4, 0xF0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_6_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_blend_epi16(m6, m0, 0xF0); \
|
||||
b1 = _mm_unpacklo_epi64(m7, m2); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_6_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m2, m7); \
|
||||
b1 = _mm_alignr_epi8(m5, m6, 8); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_6_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m0, m3); \
|
||||
b1 = _mm_shuffle_epi32(m4, _MM_SHUFFLE(1,0,3,2)); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_6_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m3, m1); \
|
||||
b1 = _mm_blend_epi16(m1, m5, 0xF0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_7_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m6, m3); \
|
||||
b1 = _mm_blend_epi16(m6, m1, 0xF0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_7_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_alignr_epi8(m7, m5, 8); \
|
||||
b1 = _mm_unpackhi_epi64(m0, m4); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_7_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m2, m7); \
|
||||
b1 = _mm_unpacklo_epi64(m4, m1); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_7_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m0, m2); \
|
||||
b1 = _mm_unpacklo_epi64(m3, m5); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_8_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m3, m7); \
|
||||
b1 = _mm_alignr_epi8(m0, m5, 8); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_8_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m7, m4); \
|
||||
b1 = _mm_alignr_epi8(m4, m1, 8); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_8_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = m6; \
|
||||
b1 = _mm_alignr_epi8(m5, m0, 8); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_8_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_blend_epi16(m1, m3, 0xF0); \
|
||||
b1 = m2; \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_9_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m5, m4); \
|
||||
b1 = _mm_unpackhi_epi64(m3, m0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_9_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m1, m2); \
|
||||
b1 = _mm_blend_epi16(m3, m2, 0xF0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_9_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m7, m4); \
|
||||
b1 = _mm_unpackhi_epi64(m1, m6); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_9_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_alignr_epi8(m7, m5, 8); \
|
||||
b1 = _mm_unpacklo_epi64(m6, m0); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_10_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m0, m1); \
|
||||
b1 = _mm_unpacklo_epi64(m2, m3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_10_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m0, m1); \
|
||||
b1 = _mm_unpackhi_epi64(m2, m3); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_10_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m4, m5); \
|
||||
b1 = _mm_unpacklo_epi64(m6, m7); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_10_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpackhi_epi64(m4, m5); \
|
||||
b1 = _mm_unpackhi_epi64(m6, m7); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_11_1(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m7, m2); \
|
||||
b1 = _mm_unpackhi_epi64(m4, m6); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_11_2(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m5, m4); \
|
||||
b1 = _mm_alignr_epi8(m3, m7, 8); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_11_3(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_shuffle_epi32(m0, _MM_SHUFFLE(1,0,3,2)); \
|
||||
b1 = _mm_unpackhi_epi64(m5, m2); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define LOAD_MSG_11_4(b0, b1) \
|
||||
do \
|
||||
{ \
|
||||
b0 = _mm_unpacklo_epi64(m6, m1); \
|
||||
b1 = _mm_unpackhi_epi64(m3, m1); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - optimized C implementations
|
||||
|
||||
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef __BLAKE2B_ROUND_H__
|
||||
#define __BLAKE2B_ROUND_H__
|
||||
|
||||
#define LOAD(p) _mm_load_si128( (const __m128i *)(p) )
|
||||
#define STORE(p,r) _mm_store_si128((__m128i *)(p), r)
|
||||
|
||||
#define LOADU(p) _mm_loadu_si128( (const __m128i *)(p) )
|
||||
#define STOREU(p,r) _mm_storeu_si128((__m128i *)(p), r)
|
||||
|
||||
#define TOF(reg) _mm_castsi128_ps((reg))
|
||||
#define TOI(reg) _mm_castps_si128((reg))
|
||||
|
||||
#define LIKELY(x) __builtin_expect((x),1)
|
||||
|
||||
|
||||
/* Microarchitecture-specific macros */
|
||||
#ifndef HAVE_XOP
|
||||
#ifdef HAVE_SSSE3
|
||||
#define _mm_roti_epi64(x, c) \
|
||||
(-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \
|
||||
: (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \
|
||||
: (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \
|
||||
: (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \
|
||||
: _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c))))
|
||||
#else
|
||||
#define _mm_roti_epi64(r, c) _mm_xor_si128(_mm_srli_epi64( (r), -(c) ),_mm_slli_epi64( (r), 64-(-c) ))
|
||||
#endif
|
||||
#else
|
||||
/* ... */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#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, (-24)); \
|
||||
row2h = _mm_roti_epi64(row2h, (-24)); \
|
||||
|
||||
#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, (-63)); \
|
||||
row2h = _mm_roti_epi64(row2h, (-63)); \
|
||||
|
||||
#if defined(HAVE_SSSE3)
|
||||
#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;
|
||||
#else
|
||||
|
||||
#define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \
|
||||
t0 = row4l;\
|
||||
t1 = row2l;\
|
||||
row4l = row3l;\
|
||||
row3l = row3h;\
|
||||
row3h = row4l;\
|
||||
row4l = _mm_unpackhi_epi64(row4h, _mm_unpacklo_epi64(t0, t0)); \
|
||||
row4h = _mm_unpackhi_epi64(t0, _mm_unpacklo_epi64(row4h, row4h)); \
|
||||
row2l = _mm_unpackhi_epi64(row2l, _mm_unpacklo_epi64(row2h, row2h)); \
|
||||
row2h = _mm_unpackhi_epi64(row2h, _mm_unpacklo_epi64(t1, t1))
|
||||
|
||||
#define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \
|
||||
t0 = row3l;\
|
||||
row3l = row3h;\
|
||||
row3h = t0;\
|
||||
t0 = row2l;\
|
||||
t1 = row4l;\
|
||||
row2l = _mm_unpackhi_epi64(row2h, _mm_unpacklo_epi64(row2l, row2l)); \
|
||||
row2h = _mm_unpackhi_epi64(t0, _mm_unpacklo_epi64(row2h, row2h)); \
|
||||
row4l = _mm_unpackhi_epi64(row4l, _mm_unpacklo_epi64(row4h, row4h)); \
|
||||
row4h = _mm_unpackhi_epi64(row4h, _mm_unpacklo_epi64(t1, t1))
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SSE41)
|
||||
#include "blake2b-load-sse41.h"
|
||||
#else
|
||||
#include "blake2b-load-sse2.h"
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#define BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \
|
||||
G1(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \
|
||||
G2(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \
|
||||
\
|
||||
DIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \
|
||||
\
|
||||
G1(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \
|
||||
G2(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \
|
||||
\
|
||||
UNDIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h);
|
||||
@@ -1,262 +0,0 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - optimized C implementations
|
||||
|
||||
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "blake2.h"
|
||||
#include "blake2-impl.h"
|
||||
|
||||
#include "blake2-config.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
#include <emmintrin.h>
|
||||
#if defined(HAVE_SSSE3)
|
||||
#include <tmmintrin.h>
|
||||
#endif
|
||||
#if defined(HAVE_SSE41)
|
||||
#include <smmintrin.h>
|
||||
#endif
|
||||
#if defined(HAVE_AVX)
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
#if defined(HAVE_XOP)
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
|
||||
#include "blake2b-round.h"
|
||||
|
||||
ALIGN(64) static const uint64_t blake2b_IV[8] = {
|
||||
0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
|
||||
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
|
||||
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
|
||||
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
|
||||
};
|
||||
|
||||
/* init xors IV with input parameter block */
|
||||
int eq_blake2b_init_param(blake2b_state *S, const blake2b_param *P)
|
||||
{
|
||||
//blake2b_init0( S );
|
||||
const uint8_t * v = (const uint8_t *)(blake2b_IV);
|
||||
const uint8_t * p = (const uint8_t *)(P);
|
||||
uint8_t * h = (uint8_t *)(S->h);
|
||||
/* IV XOR ParamBlock */
|
||||
memset(S, 0, sizeof(blake2b_state));
|
||||
|
||||
for (int i = 0; i < BLAKE2B_OUTBYTES; ++i) h[i] = v[i] ^ p[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Some sort of default parameter block initialization, for sequential blake2b */
|
||||
int eq_blake2b_init(blake2b_state *S, const uint8_t outlen)
|
||||
{
|
||||
if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) return -1;
|
||||
|
||||
const blake2b_param P =
|
||||
{
|
||||
outlen,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
{ 0 },
|
||||
{ 0 },
|
||||
{ 0 }
|
||||
};
|
||||
return eq_blake2b_init_param(S, &P);
|
||||
}
|
||||
|
||||
int eq_blake2b_init_key(blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen)
|
||||
{
|
||||
if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) return -1;
|
||||
|
||||
if ((!keylen) || keylen > BLAKE2B_KEYBYTES) return -1;
|
||||
|
||||
const blake2b_param P =
|
||||
{
|
||||
outlen,
|
||||
keylen,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
{ 0 },
|
||||
{ 0 },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
if (eq_blake2b_init_param(S, &P) < 0)
|
||||
return 0;
|
||||
|
||||
{
|
||||
uint8_t block[BLAKE2B_BLOCKBYTES];
|
||||
memset(block, 0, BLAKE2B_BLOCKBYTES);
|
||||
memcpy(block, key, keylen);
|
||||
eq_blake2b_update(S, block, BLAKE2B_BLOCKBYTES);
|
||||
secure_zero_memory(block, BLAKE2B_BLOCKBYTES); /* Burn the key from stack */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int blake2b_compress(blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES])
|
||||
{
|
||||
__m128i row1l, row1h;
|
||||
__m128i row2l, row2h;
|
||||
__m128i row3l, row3h;
|
||||
__m128i row4l, row4h;
|
||||
__m128i b0, b1;
|
||||
__m128i t0, t1;
|
||||
#if defined(HAVE_SSSE3) && !defined(HAVE_XOP)
|
||||
const __m128i r16 = _mm_setr_epi8(2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9);
|
||||
const __m128i r24 = _mm_setr_epi8(3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10);
|
||||
#endif
|
||||
#if defined(HAVE_SSE41)
|
||||
const __m128i m0 = LOADU(block + 00);
|
||||
const __m128i m1 = LOADU(block + 16);
|
||||
const __m128i m2 = LOADU(block + 32);
|
||||
const __m128i m3 = LOADU(block + 48);
|
||||
const __m128i m4 = LOADU(block + 64);
|
||||
const __m128i m5 = LOADU(block + 80);
|
||||
const __m128i m6 = LOADU(block + 96);
|
||||
const __m128i m7 = LOADU(block + 112);
|
||||
#else
|
||||
const uint64_t m0 = ( ( uint64_t * )block )[ 0];
|
||||
const uint64_t m1 = ( ( uint64_t * )block )[ 1];
|
||||
const uint64_t m2 = ( ( uint64_t * )block )[ 2];
|
||||
const uint64_t m3 = ( ( uint64_t * )block )[ 3];
|
||||
const uint64_t m4 = ( ( uint64_t * )block )[ 4];
|
||||
const uint64_t m5 = ( ( uint64_t * )block )[ 5];
|
||||
const uint64_t m6 = ( ( uint64_t * )block )[ 6];
|
||||
const uint64_t m7 = ( ( uint64_t * )block )[ 7];
|
||||
const uint64_t m8 = ( ( uint64_t * )block )[ 8];
|
||||
const uint64_t m9 = ( ( uint64_t * )block )[ 9];
|
||||
const uint64_t m10 = ( ( uint64_t * )block )[10];
|
||||
const uint64_t m11 = ( ( uint64_t * )block )[11];
|
||||
const uint64_t m12 = ( ( uint64_t * )block )[12];
|
||||
const uint64_t m13 = ( ( uint64_t * )block )[13];
|
||||
const uint64_t m14 = ( ( uint64_t * )block )[14];
|
||||
const uint64_t m15 = ( ( uint64_t * )block )[15];
|
||||
#endif
|
||||
row1l = LOADU(&S->h[0]);
|
||||
row1h = LOADU(&S->h[2]);
|
||||
row2l = LOADU(&S->h[4]);
|
||||
row2h = LOADU(&S->h[6]);
|
||||
row3l = LOADU(&blake2b_IV[0]);
|
||||
row3h = LOADU(&blake2b_IV[2]);
|
||||
row4l = _mm_xor_si128(LOADU(&blake2b_IV[4]), _mm_set_epi32(0, 0, 0, S->counter));
|
||||
row4h = _mm_xor_si128(LOADU(&blake2b_IV[6]), _mm_set_epi32(0, 0, 0L - S->lastblock, 0L - S->lastblock));
|
||||
ROUND(0);
|
||||
ROUND(1);
|
||||
ROUND(2);
|
||||
ROUND(3);
|
||||
ROUND(4);
|
||||
ROUND(5);
|
||||
ROUND(6);
|
||||
ROUND(7);
|
||||
ROUND(8);
|
||||
ROUND(9);
|
||||
ROUND(10);
|
||||
ROUND(11);
|
||||
row1l = _mm_xor_si128(row3l, row1l);
|
||||
row1h = _mm_xor_si128(row3h, row1h);
|
||||
STOREU(&S->h[0], _mm_xor_si128(LOADU(&S->h[0]), row1l));
|
||||
STOREU(&S->h[2], _mm_xor_si128(LOADU(&S->h[2]), row1h));
|
||||
row2l = _mm_xor_si128(row4l, row2l);
|
||||
row2h = _mm_xor_si128(row4h, row2h);
|
||||
STOREU(&S->h[4], _mm_xor_si128(LOADU(&S->h[4]), row2l));
|
||||
STOREU(&S->h[6], _mm_xor_si128(LOADU(&S->h[6]), row2h));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int eq_blake2b_update(blake2b_state *S, const uint8_t *in, uint64_t inlen)
|
||||
{
|
||||
while (inlen > 0)
|
||||
{
|
||||
size_t left = S->buflen;
|
||||
size_t fill = BLAKE2B_BLOCKBYTES - left;
|
||||
|
||||
if (inlen > fill)
|
||||
{
|
||||
memcpy(S->buf + left, in, fill); // Fill buffer
|
||||
in += fill;
|
||||
inlen -= fill;
|
||||
S->counter += BLAKE2B_BLOCKBYTES;
|
||||
blake2b_compress(S, S->buf); // Compress
|
||||
S->buflen = 0;
|
||||
}
|
||||
else // inlen <= fill
|
||||
{
|
||||
memcpy(S->buf + left, in, inlen);
|
||||
S->buflen += (uint8_t) inlen; // not enough to compress
|
||||
in += inlen;
|
||||
inlen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int eq_blake2b_final(blake2b_state *S, uint8_t *out, uint8_t outlen)
|
||||
{
|
||||
if (outlen > BLAKE2B_OUTBYTES)
|
||||
return -1;
|
||||
|
||||
if (S->buflen > BLAKE2B_BLOCKBYTES)
|
||||
{
|
||||
S->counter += BLAKE2B_BLOCKBYTES;
|
||||
blake2b_compress(S, S->buf);
|
||||
S->buflen -= BLAKE2B_BLOCKBYTES;
|
||||
memcpy(S->buf, S->buf + BLAKE2B_BLOCKBYTES, S->buflen);
|
||||
}
|
||||
|
||||
S->counter += S->buflen;
|
||||
S->lastblock = 1;
|
||||
memset(S->buf + S->buflen, 0, BLAKE2B_BLOCKBYTES - S->buflen); /* Padding */
|
||||
blake2b_compress(S, S->buf);
|
||||
memcpy(out, &S->h[0], outlen);
|
||||
S->lastblock = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int eq_blake2b(uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen)
|
||||
{
|
||||
blake2b_state S[1];
|
||||
|
||||
/* Verify parameters */
|
||||
if (!in || !out) return -1;
|
||||
if (NULL == key) keylen = 0;
|
||||
|
||||
if (keylen)
|
||||
{
|
||||
if (eq_blake2b_init_key(S, outlen, key, keylen) < 0) return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (eq_blake2b_init(S, outlen) < 0) return -1;
|
||||
}
|
||||
|
||||
eq_blake2b_update(S, (const uint8_t *)in, inlen);
|
||||
eq_blake2b_final(S, out, outlen);
|
||||
return 0;
|
||||
}
|
||||
-2130
File diff suppressed because it is too large.
Load diff
-136
@@ -1,136 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
#include <device_launch_parameters.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#define _SNPRINTF _snprintf
|
||||
#else
|
||||
#define _SNPRINTF snprintf
|
||||
#endif
|
||||
|
||||
#ifndef nullptr
|
||||
#define nullptr NULL
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define rt_error std::runtime_error
|
||||
#else
|
||||
class rt_error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit rt_error(const std::string& str) : std::runtime_error(str) {}
|
||||
};
|
||||
#endif
|
||||
|
||||
#define checkCudaErrors(call) \
|
||||
do { \
|
||||
cudaError_t err = call; \
|
||||
if (cudaSuccess != err) { \
|
||||
char errorBuff[512]; \
|
||||
_SNPRINTF(errorBuff, sizeof(errorBuff) - 1, \
|
||||
"CUDA error '%s' in func '%s' line %d", \
|
||||
cudaGetErrorString(err), __FUNCTION__, __LINE__); \
|
||||
throw rt_error(errorBuff); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define checkCudaDriverErrors(call) \
|
||||
do { \
|
||||
CUresult err = call; \
|
||||
if (CUDA_SUCCESS != err) { \
|
||||
char errorBuff[512]; \
|
||||
_SNPRINTF(errorBuff, sizeof(errorBuff) - 1, \
|
||||
"CUDA error DRIVER: '%d' in func '%s' line %d", \
|
||||
err, __FUNCTION__, __LINE__); \
|
||||
throw rt_error(errorBuff); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef uint64_t u64;
|
||||
typedef uint32_t u32;
|
||||
typedef uint16_t u16;
|
||||
typedef uint8_t u8;
|
||||
typedef unsigned char uchar;
|
||||
|
||||
struct packer_default;
|
||||
struct packer_cantor;
|
||||
|
||||
#define MAXREALSOLS 9
|
||||
|
||||
struct scontainerreal {
|
||||
u32 sols[MAXREALSOLS][512];
|
||||
u32 nsols;
|
||||
};
|
||||
|
||||
#if 0
|
||||
#include <functional>
|
||||
#define fn_solution std::function<void(int thr_id, const std::vector<uint32_t>&, size_t, const unsigned char*)>
|
||||
#define fn_hashdone std::function<void(int thr_id)>
|
||||
#define fn_cancel std::function<bool(int thr_id)>
|
||||
#else
|
||||
typedef void (*fn_solution)(int thr_id, const std::vector<uint32_t>&, size_t, const unsigned char*);
|
||||
typedef void (*fn_hashdone)(int thr_id);
|
||||
typedef bool (*fn_cancel)(int thr_id);
|
||||
#endif
|
||||
|
||||
template <u32 RB, u32 SM> struct equi;
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------
|
||||
|
||||
struct eq_cuda_context_interface
|
||||
{
|
||||
//virtual ~eq_cuda_context_interface();
|
||||
|
||||
virtual void solve(const char *tequihash_header,
|
||||
unsigned int tequihash_header_len,
|
||||
const char* nonce,
|
||||
unsigned int nonce_len,
|
||||
fn_cancel cancelf,
|
||||
fn_solution solutionf,
|
||||
fn_hashdone hashdonef);
|
||||
|
||||
public:
|
||||
int thread_id;
|
||||
int device_id;
|
||||
int throughput;
|
||||
int totalblocks;
|
||||
int threadsperblock;
|
||||
int threadsperblock_digits;
|
||||
size_t equi_mem_sz;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------
|
||||
|
||||
template <u32 RB, u32 SM, u32 SSM, u32 THREADS, typename PACKER>
|
||||
class eq_cuda_context : public eq_cuda_context_interface
|
||||
{
|
||||
equi<RB, SM>* device_eq;
|
||||
scontainerreal* solutions;
|
||||
CUcontext pctx;
|
||||
|
||||
void solve(const char *tequihash_header,
|
||||
unsigned int tequihash_header_len,
|
||||
const char* nonce,
|
||||
unsigned int nonce_len,
|
||||
fn_cancel cancelf,
|
||||
fn_solution solutionf,
|
||||
fn_hashdone hashdonef);
|
||||
public:
|
||||
eq_cuda_context(int thr_id, int dev_id);
|
||||
void freemem();
|
||||
~eq_cuda_context();
|
||||
};
|
||||
|
||||
// RB, SM, SSM, TPB, PACKER... but any change only here will fail..
|
||||
#define CONFIG_MODE_1 9, 1248, 12, 640, packer_cantor
|
||||
//#define CONFIG_MODE_2 8, 640, 12, 512, packer_default
|
||||
@@ -1,275 +0,0 @@
|
||||
/**
|
||||
* Equihash specific stratum protocol
|
||||
* tpruvot@github - 2017 - Part under GPLv3 Licence
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <miner.h>
|
||||
|
||||
#include "equihash.h"
|
||||
|
||||
extern struct stratum_ctx stratum;
|
||||
extern pthread_mutex_t stratum_work_lock;
|
||||
|
||||
// ZEC uses a different scale to compute diff...
|
||||
// sample targets to diff (stored in the reverse byte order in work->target)
|
||||
// 0007fff800000000000000000000000000000000000000000000000000000000 is stratum diff 32
|
||||
// 003fffc000000000000000000000000000000000000000000000000000000000 is stratum diff 4
|
||||
// 00ffff0000000000000000000000000000000000000000000000000000000000 is stratum diff 1
|
||||
double target_to_diff_equi(uint32_t* target)
|
||||
{
|
||||
uchar* tgt = (uchar*) target;
|
||||
uint64_t m =
|
||||
(uint64_t)tgt[30] << 24 |
|
||||
(uint64_t)tgt[29] << 16 |
|
||||
(uint64_t)tgt[28] << 8 |
|
||||
(uint64_t)tgt[27] << 0;
|
||||
|
||||
if (!m)
|
||||
return 0.;
|
||||
else
|
||||
return (double)0xffff0000UL/m;
|
||||
}
|
||||
|
||||
void diff_to_target_equi(uint32_t *target, double diff)
|
||||
{
|
||||
uint64_t m;
|
||||
int k;
|
||||
|
||||
for (k = 6; k > 0 && diff > 1.0; k--)
|
||||
diff /= 4294967296.0;
|
||||
m = (uint64_t)(4294901760.0 / diff);
|
||||
if (m == 0 && k == 6)
|
||||
memset(target, 0xff, 32);
|
||||
else {
|
||||
memset(target, 0, 32);
|
||||
target[k + 1] = (uint32_t)(m >> 8);
|
||||
target[k + 2] = (uint32_t)(m >> 40);
|
||||
//memset(target, 0xff, 6*sizeof(uint32_t));
|
||||
for (k = 0; k < 28 && ((uint8_t*)target)[k] == 0; k++)
|
||||
((uint8_t*)target)[k] = 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
/* compute nbits to get the network diff */
|
||||
double equi_network_diff(struct work *work)
|
||||
{
|
||||
//KMD bits: "1e 015971",
|
||||
//KMD target: "00 00 015971000000000000000000000000000000000000000000000000000000",
|
||||
//KMD bits: "1d 686aaf",
|
||||
//KMD target: "00 0000 686aaf0000000000000000000000000000000000000000000000000000",
|
||||
uint32_t nbits = work->data[26];
|
||||
uint32_t bits = (nbits & 0xffffff);
|
||||
int16_t shift = (swab32(nbits) & 0xff);
|
||||
shift = (31 - shift) * 8; // 8 bits shift for 0x1e, 16 for 0x1d
|
||||
uint64_t tgt64 = swab32(bits);
|
||||
tgt64 = tgt64 << shift;
|
||||
// applog_hex(&tgt64, 8);
|
||||
uint8_t net_target[32] = { 0 };
|
||||
for (int b=0; b<8; b++)
|
||||
net_target[31-b] = ((uint8_t*)&tgt64)[b];
|
||||
// applog_hex(net_target, 32);
|
||||
double d = target_to_diff_equi((uint32_t*)net_target);
|
||||
return d;
|
||||
}
|
||||
|
||||
void equi_work_set_target(struct work* work, double diff)
|
||||
{
|
||||
// target is given as data by the equihash stratum
|
||||
// memcpy(work->target, stratum.job.claim, 32); // claim field is only used for lbry
|
||||
diff_to_target_equi(work->target, diff);
|
||||
//applog(LOG_BLUE, "diff %f to target :", diff);
|
||||
//applog_hex(work->target, 32);
|
||||
work->targetdiff = diff;
|
||||
}
|
||||
|
||||
bool equi_stratum_set_target(struct stratum_ctx *sctx, json_t *params)
|
||||
{
|
||||
uint8_t target_bin[32], target_be[32];
|
||||
|
||||
const char *target_hex = json_string_value(json_array_get(params, 0));
|
||||
if (!target_hex || strlen(target_hex) == 0)
|
||||
return false;
|
||||
|
||||
hex2bin(target_bin, target_hex, 32);
|
||||
memset(target_be, 0xff, 32);
|
||||
int filled = 0;
|
||||
for (int i=0; i<32; i++) {
|
||||
if (filled == 3) break;
|
||||
target_be[31-i] = target_bin[i];
|
||||
if (target_bin[i]) filled++;
|
||||
}
|
||||
memcpy(sctx->job.extra, target_be, 32);
|
||||
|
||||
pthread_mutex_lock(&stratum_work_lock);
|
||||
sctx->next_diff = target_to_diff_equi((uint32_t*) &target_be);
|
||||
pthread_mutex_unlock(&stratum_work_lock);
|
||||
|
||||
//applog(LOG_BLUE, "low diff %f", sctx->next_diff);
|
||||
//applog_hex(target_be, 32);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool equi_stratum_notify(struct stratum_ctx *sctx, json_t *params)
|
||||
{
|
||||
const char *job_id, *version, *prevhash, *coinb1, *coinb2, *nbits, *stime;
|
||||
size_t coinb1_size, coinb2_size;
|
||||
bool clean, ret = false;
|
||||
int ntime, i, p=0;
|
||||
job_id = json_string_value(json_array_get(params, p++));
|
||||
version = json_string_value(json_array_get(params, p++));
|
||||
prevhash = json_string_value(json_array_get(params, p++));
|
||||
coinb1 = json_string_value(json_array_get(params, p++)); //merkle
|
||||
coinb2 = json_string_value(json_array_get(params, p++)); //blank (reserved)
|
||||
stime = json_string_value(json_array_get(params, p++));
|
||||
nbits = json_string_value(json_array_get(params, p++));
|
||||
clean = json_is_true(json_array_get(params, p)); p++;
|
||||
|
||||
if (!job_id || !prevhash || !coinb1 || !coinb2 || !version || !nbits || !stime ||
|
||||
strlen(prevhash) != 64 || strlen(version) != 8 ||
|
||||
strlen(coinb1) != 64 || strlen(coinb2) != 64 ||
|
||||
strlen(nbits) != 8 || strlen(stime) != 8) {
|
||||
applog(LOG_ERR, "Stratum notify: invalid parameters");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* store stratum server time diff */
|
||||
hex2bin((uchar *)&ntime, stime, 4);
|
||||
ntime = ntime - (int) time(0);
|
||||
if (ntime > sctx->srvtime_diff) {
|
||||
sctx->srvtime_diff = ntime;
|
||||
if (opt_protocol && ntime > 20)
|
||||
applog(LOG_DEBUG, "stratum time is at least %ds in the future", ntime);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&stratum_work_lock);
|
||||
hex2bin(sctx->job.version, version, 4);
|
||||
hex2bin(sctx->job.prevhash, prevhash, 32);
|
||||
|
||||
coinb1_size = strlen(coinb1) / 2;
|
||||
coinb2_size = strlen(coinb2) / 2;
|
||||
sctx->job.coinbase_size = coinb1_size + coinb2_size + // merkle + reserved
|
||||
sctx->xnonce1_size + sctx->xnonce2_size; // extranonce and...
|
||||
|
||||
sctx->job.coinbase = (uchar*) realloc(sctx->job.coinbase, sctx->job.coinbase_size);
|
||||
hex2bin(sctx->job.coinbase, coinb1, coinb1_size);
|
||||
hex2bin(sctx->job.coinbase + coinb1_size, coinb2, coinb2_size);
|
||||
|
||||
sctx->job.xnonce2 = sctx->job.coinbase + coinb1_size + coinb2_size + sctx->xnonce1_size;
|
||||
if (!sctx->job.job_id || strcmp(sctx->job.job_id, job_id))
|
||||
memset(sctx->job.xnonce2, 0, sctx->xnonce2_size);
|
||||
memcpy(sctx->job.coinbase + coinb1_size + coinb2_size, sctx->xnonce1, sctx->xnonce1_size);
|
||||
|
||||
for (i = 0; i < sctx->job.merkle_count; i++)
|
||||
free(sctx->job.merkle[i]);
|
||||
free(sctx->job.merkle);
|
||||
sctx->job.merkle = NULL;
|
||||
sctx->job.merkle_count = 0;
|
||||
|
||||
free(sctx->job.job_id);
|
||||
sctx->job.job_id = strdup(job_id);
|
||||
|
||||
hex2bin(sctx->job.nbits, nbits, 4);
|
||||
hex2bin(sctx->job.ntime, stime, 4);
|
||||
sctx->job.clean = clean;
|
||||
|
||||
sctx->job.diff = sctx->next_diff;
|
||||
pthread_mutex_unlock(&stratum_work_lock);
|
||||
|
||||
ret = true;
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
// equihash stratum protocol is not standard, use client.show_message to pass block height
|
||||
bool equi_stratum_show_message(struct stratum_ctx *sctx, json_t *id, json_t *params)
|
||||
{
|
||||
char *s;
|
||||
json_t *val;
|
||||
bool ret;
|
||||
|
||||
val = json_array_get(params, 0);
|
||||
if (val) {
|
||||
const char* data = json_string_value(val);
|
||||
if (data && strlen(data)) {
|
||||
char symbol[32] = { 0 };
|
||||
uint32_t height = 0;
|
||||
int ss = sscanf(data, "equihash %s block %u", symbol, &height);
|
||||
if (height && ss > 1) sctx->job.height = height;
|
||||
if (opt_debug && ss > 1) applog(LOG_DEBUG, "%s", data);
|
||||
}
|
||||
}
|
||||
|
||||
if (!id || json_is_null(id))
|
||||
return true;
|
||||
|
||||
val = json_object();
|
||||
json_object_set(val, "id", id);
|
||||
json_object_set_new(val, "error", json_null());
|
||||
json_object_set_new(val, "result", json_true());
|
||||
s = json_dumps(val, 0);
|
||||
ret = stratum_send_line(sctx, s);
|
||||
json_decref(val);
|
||||
free(s);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void equi_store_work_solution(struct work* work, uint32_t* hash, void* sol_data)
|
||||
{
|
||||
int nonce = work->valid_nonces-1;
|
||||
memcpy(work->extra, sol_data, 1347);
|
||||
bn_store_hash_target_ratio(hash, work->target, work, nonce);
|
||||
//work->sharediff[nonce] = target_to_diff_equi(hash);
|
||||
}
|
||||
|
||||
#define JSON_SUBMIT_BUF_LEN (4*1024)
|
||||
// called by submit_upstream_work()
|
||||
bool equi_stratum_submit(struct pool_infos *pool, struct work *work)
|
||||
{
|
||||
char _ALIGN(64) s[JSON_SUBMIT_BUF_LEN];
|
||||
char _ALIGN(64) timehex[16] = { 0 };
|
||||
char *jobid, *noncestr, *solhex;
|
||||
int idnonce = work->submit_nonce_id;
|
||||
|
||||
// scanned nonce
|
||||
work->data[EQNONCE_OFFSET] = work->nonces[idnonce];
|
||||
unsigned char * nonce = (unsigned char*) (&work->data[27]);
|
||||
size_t nonce_len = 32 - stratum.xnonce1_size;
|
||||
// long nonce without pool prefix (extranonce)
|
||||
noncestr = bin2hex(&nonce[stratum.xnonce1_size], nonce_len);
|
||||
|
||||
solhex = (char*) calloc(1, 1344*2 + 64);
|
||||
if (!solhex || !noncestr) {
|
||||
applog(LOG_ERR, "unable to alloc share memory");
|
||||
return false;
|
||||
}
|
||||
cbin2hex(solhex, (const char*) work->extra, 1347);
|
||||
|
||||
jobid = work->job_id + 8;
|
||||
sprintf(timehex, "%08x", swab32(work->data[25]));
|
||||
|
||||
snprintf(s, sizeof(s), "{\"method\":\"mining.submit\",\"params\":"
|
||||
"[\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"], \"id\":%u}",
|
||||
pool->user, jobid, timehex, noncestr, solhex,
|
||||
stratum.job.shares_count + 10);
|
||||
|
||||
free(solhex);
|
||||
free(noncestr);
|
||||
|
||||
gettimeofday(&stratum.tv_submit, NULL);
|
||||
|
||||
if(!stratum_send_line(&stratum, s)) {
|
||||
applog(LOG_ERR, "%s stratum_send_line failed", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
stratum.sharediff = work->sharediff[idnonce];
|
||||
stratum.job.shares_count++;
|
||||
|
||||
return true;
|
||||
}
|
||||
-171
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
* Port to Generic C of C++ implementation of the Equihash Proof-of-Work
|
||||
* algorithm from zcashd.
|
||||
*
|
||||
* Copyright (c) 2016 abc at openwall dot com
|
||||
* Copyright (c) 2016 Jack Grigg
|
||||
* Copyright (c) 2016 The Zcash developers
|
||||
* Copyright (c) 2017 tpruvot
|
||||
*
|
||||
* Distributed under the MIT software license, see the accompanying
|
||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "equihash.h"
|
||||
|
||||
//#define USE_LIBSODIUM
|
||||
|
||||
#ifdef USE_LIBSODIUM
|
||||
#include "sodium.h"
|
||||
#define blake2b_state crypto_generichash_blake2b_state
|
||||
#else
|
||||
#include "blake2/blake2.h"
|
||||
#define be32toh(x) swab32(x)
|
||||
#define htole32(x) (x)
|
||||
#define HASHOUT 50
|
||||
#endif
|
||||
|
||||
#include <miner.h>
|
||||
|
||||
static void digestInit(blake2b_state *S, const uint32_t n, const uint32_t k)
|
||||
{
|
||||
uint32_t le_N = htole32(n);
|
||||
uint32_t le_K = htole32(k);
|
||||
#ifdef USE_LIBSODIUM
|
||||
uint8_t personalization[crypto_generichash_blake2b_PERSONALBYTES] = { 0 };
|
||||
|
||||
memcpy(personalization, "ZcashPoW", 8);
|
||||
memcpy(personalization + 8, &le_N, 4);
|
||||
memcpy(personalization + 12, &le_K, 4);
|
||||
|
||||
crypto_generichash_blake2b_init_salt_personal(S,
|
||||
NULL, 0, (512 / n) * n / 8, NULL, personalization);
|
||||
#else
|
||||
unsigned char personal[] = "ZcashPoW01230123";
|
||||
memcpy(personal + 8, &le_N, 4);
|
||||
memcpy(personal + 12, &le_K, 4);
|
||||
blake2b_param P[1];
|
||||
P->digest_length = HASHOUT;
|
||||
P->key_length = 0;
|
||||
P->fanout = 1;
|
||||
P->depth = 1;
|
||||
P->leaf_length = 0;
|
||||
P->node_offset = 0;
|
||||
P->node_depth = 0;
|
||||
P->inner_length = 0;
|
||||
memset(P->reserved, 0, sizeof(P->reserved));
|
||||
memset(P->salt, 0, sizeof(P->salt));
|
||||
memcpy(P->personal, (const uint8_t *)personal, 16);
|
||||
eq_blake2b_init_param(S, P);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void expandArray(const unsigned char *in, const uint32_t in_len,
|
||||
unsigned char *out, const uint32_t out_len,
|
||||
const uint32_t bit_len, const uint32_t byte_pad)
|
||||
{
|
||||
assert(bit_len >= 8);
|
||||
assert(8 * sizeof(uint32_t) >= 7 + bit_len);
|
||||
|
||||
const uint32_t out_width = (bit_len + 7) / 8 + byte_pad;
|
||||
assert(out_len == 8 * out_width * in_len / bit_len);
|
||||
|
||||
const uint32_t bit_len_mask = ((uint32_t)1 << bit_len) - 1;
|
||||
|
||||
// The acc_bits least-significant bits of acc_value represent a bit sequence
|
||||
// in big-endian order.
|
||||
uint32_t acc_bits = 0;
|
||||
uint32_t acc_value = 0;
|
||||
uint32_t j = 0;
|
||||
|
||||
for (uint32_t i = 0; i < in_len; i++)
|
||||
{
|
||||
acc_value = (acc_value << 8) | in[i];
|
||||
acc_bits += 8;
|
||||
|
||||
// When we have bit_len or more bits in the accumulator, write the next
|
||||
// output element.
|
||||
if (acc_bits >= bit_len) {
|
||||
acc_bits -= bit_len;
|
||||
for (uint32_t x = 0; x < byte_pad; x++) {
|
||||
out[j + x] = 0;
|
||||
}
|
||||
for (uint32_t x = byte_pad; x < out_width; x++) {
|
||||
out[j + x] = (
|
||||
// Big-endian
|
||||
acc_value >> (acc_bits + (8 * (out_width - x - 1)))
|
||||
) & (
|
||||
// Apply bit_len_mask across byte boundaries
|
||||
(bit_len_mask >> (8 * (out_width - x - 1))) & 0xFF
|
||||
);
|
||||
}
|
||||
j += out_width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void generateHash(blake2b_state *S, const uint32_t g, uint8_t *hash, const size_t hashLen)
|
||||
{
|
||||
const uint32_t le_g = htole32(g);
|
||||
blake2b_state digest = *S; /* copy */
|
||||
#ifdef USE_LIBSODIUM
|
||||
crypto_generichash_blake2b_update(&digest, (uint8_t *)&le_g, sizeof(le_g));
|
||||
crypto_generichash_blake2b_final(&digest, hash, hashLen);
|
||||
#else
|
||||
eq_blake2b_update(&digest, (const uint8_t*) &le_g, sizeof(le_g));
|
||||
eq_blake2b_final(&digest, hash, (uint8_t) (hashLen & 0xFF));
|
||||
#endif
|
||||
}
|
||||
|
||||
static int isZero(const uint8_t *hash, size_t len)
|
||||
{
|
||||
// This doesn't need to be constant time.
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (hash[i] != 0) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// hdr -> header including nonce (140 bytes)
|
||||
// soln -> equihash solution (excluding 3 bytes with size, so 1344 bytes length)
|
||||
bool equi_verify(uint8_t* const hdr, uint8_t* const soln)
|
||||
{
|
||||
const uint32_t n = WN; // 200
|
||||
const uint32_t k = WK; // 9
|
||||
const uint32_t collisionBitLength = n / (k + 1);
|
||||
const uint32_t collisionByteLength = (collisionBitLength + 7) / 8;
|
||||
const uint32_t hashLength = (k + 1) * collisionByteLength;
|
||||
const uint32_t indicesPerHashOutput = 512 / n;
|
||||
const uint32_t hashOutput = indicesPerHashOutput * n / 8;
|
||||
const uint32_t equihashSolutionSize = (1 << k) * (n / (k + 1) + 1) / 8;
|
||||
const uint32_t solnr = 1 << k;
|
||||
|
||||
uint32_t indices[512] = { 0 };
|
||||
uint8_t vHash[hashLength] = { 0 };
|
||||
|
||||
blake2b_state state;
|
||||
digestInit(&state, n, k);
|
||||
#ifdef USE_LIBSODIUM
|
||||
crypto_generichash_blake2b_update(&state, hdr, 140);
|
||||
#else
|
||||
eq_blake2b_update(&state, hdr, 140);
|
||||
#endif
|
||||
|
||||
expandArray(soln, equihashSolutionSize, (uint8_t*) &indices, sizeof(indices), collisionBitLength + 1, 1);
|
||||
|
||||
for (uint32_t j = 0; j < solnr; j++) {
|
||||
uint8_t tmpHash[hashOutput];
|
||||
uint8_t hash[hashLength];
|
||||
uint32_t i = be32toh(indices[j]);
|
||||
generateHash(&state, i / indicesPerHashOutput, tmpHash, hashOutput);
|
||||
expandArray(tmpHash + (i % indicesPerHashOutput * n / 8), n / 8, hash, hashLength, collisionBitLength, 0);
|
||||
for (uint32_t k = 0; k < hashLength; k++)
|
||||
vHash[k] ^= hash[k];
|
||||
}
|
||||
return isZero(vHash, sizeof(vHash));
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
/**
|
||||
* Equihash solver interface for ccminer (compatible with linux and windows)
|
||||
* Solver taken from nheqminer, by djeZo (and NiceHash)
|
||||
* tpruvot - 2017 (GPL v3)
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include <sph/sph_sha2.h>
|
||||
|
||||
#include "eqcuda.hpp"
|
||||
#include "equihash.h" // equi_verify()
|
||||
|
||||
#include <miner.h>
|
||||
|
||||
// All solutions (BLOCK_HEADER_LEN + SOLSIZE_LEN + SOL_LEN) sha256d should be under the target
|
||||
extern "C" void equi_hash(const void* input, void* output, int len)
|
||||
{
|
||||
uint8_t _ALIGN(64) hash0[32], hash1[32];
|
||||
|
||||
sph_sha256_context ctx_sha256;
|
||||
|
||||
sph_sha256_init(&ctx_sha256);
|
||||
sph_sha256(&ctx_sha256, input, len);
|
||||
sph_sha256_close(&ctx_sha256, hash0);
|
||||
sph_sha256(&ctx_sha256, hash0, 32);
|
||||
sph_sha256_close(&ctx_sha256, hash1);
|
||||
|
||||
memcpy(output, hash1, 32);
|
||||
}
|
||||
|
||||
// input here is 140 for the header and 1344 for the solution (equi.cpp)
|
||||
extern "C" int equi_verify_sol(void * const hdr, void * const sol)
|
||||
{
|
||||
bool res = equi_verify((uint8_t*) hdr, (uint8_t*) sol);
|
||||
|
||||
//applog_hex((void*)hdr, 140);
|
||||
//applog_hex((void*)sol, 1344);
|
||||
|
||||
return res ? 1 : 0;
|
||||
}
|
||||
|
||||
#include <cuda_helper.h>
|
||||
|
||||
//#define EQNONCE_OFFSET 30 /* 27:34 */
|
||||
#define NONCE_OFT EQNONCE_OFFSET
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
static int valid_sols[MAX_GPUS] = { 0 };
|
||||
static uint8_t _ALIGN(64) data_sols[MAX_GPUS][MAXREALSOLS][1536] = { 0 }; // 140+3+1344 required
|
||||
static eq_cuda_context_interface* solvers[MAX_GPUS] = { NULL };
|
||||
|
||||
static void CompressArray(const unsigned char* in, size_t in_len,
|
||||
unsigned char* out, size_t out_len, size_t bit_len, size_t byte_pad)
|
||||
{
|
||||
assert(bit_len >= 8);
|
||||
assert(8 * sizeof(uint32_t) >= 7 + bit_len);
|
||||
|
||||
size_t in_width = (bit_len + 7) / 8 + byte_pad;
|
||||
assert(out_len == bit_len*in_len / (8 * in_width));
|
||||
|
||||
uint32_t bit_len_mask = (1UL << bit_len) - 1;
|
||||
|
||||
// The acc_bits least-significant bits of acc_value represent a bit sequence
|
||||
// in big-endian order.
|
||||
size_t acc_bits = 0;
|
||||
uint32_t acc_value = 0;
|
||||
|
||||
size_t j = 0;
|
||||
for (size_t i = 0; i < out_len; i++) {
|
||||
// When we have fewer than 8 bits left in the accumulator, read the next
|
||||
// input element.
|
||||
if (acc_bits < 8) {
|
||||
acc_value = acc_value << bit_len;
|
||||
for (size_t x = byte_pad; x < in_width; x++) {
|
||||
acc_value = acc_value | (
|
||||
(
|
||||
// Apply bit_len_mask across byte boundaries
|
||||
in[j + x] & ((bit_len_mask >> (8 * (in_width - x - 1))) & 0xFF)
|
||||
) << (8 * (in_width - x - 1))); // Big-endian
|
||||
}
|
||||
j += in_width;
|
||||
acc_bits += bit_len;
|
||||
}
|
||||
|
||||
acc_bits -= 8;
|
||||
out[i] = (acc_value >> acc_bits) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef htobe32
|
||||
#define htobe32(x) swab32(x)
|
||||
#endif
|
||||
|
||||
static void EhIndexToArray(const u32 i, unsigned char* arr)
|
||||
{
|
||||
u32 bei = htobe32(i);
|
||||
memcpy(arr, &bei, sizeof(u32));
|
||||
}
|
||||
|
||||
static std::vector<unsigned char> GetMinimalFromIndices(std::vector<u32> indices, size_t cBitLen)
|
||||
{
|
||||
assert(((cBitLen + 1) + 7) / 8 <= sizeof(u32));
|
||||
size_t lenIndices = indices.size()*sizeof(u32);
|
||||
size_t minLen = (cBitLen + 1)*lenIndices / (8 * sizeof(u32));
|
||||
size_t bytePad = sizeof(u32) - ((cBitLen + 1) + 7) / 8;
|
||||
std::vector<unsigned char> array(lenIndices);
|
||||
for (size_t i = 0; i < indices.size(); i++) {
|
||||
EhIndexToArray(indices[i], array.data() + (i*sizeof(u32)));
|
||||
}
|
||||
std::vector<unsigned char> ret(minLen);
|
||||
CompressArray(array.data(), lenIndices, ret.data(), minLen, cBitLen + 1, bytePad);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// solver callbacks
|
||||
static void cb_solution(int thr_id, const std::vector<uint32_t>& solutions, size_t cbitlen, const unsigned char *compressed_sol)
|
||||
{
|
||||
std::vector<unsigned char> nSolution;
|
||||
if (!compressed_sol) {
|
||||
nSolution = GetMinimalFromIndices(solutions, cbitlen);
|
||||
} else {
|
||||
gpulog(LOG_INFO, thr_id, "compressed_sol");
|
||||
nSolution = std::vector<unsigned char>(1344);
|
||||
for (size_t i = 0; i < cbitlen; i++)
|
||||
nSolution[i] = compressed_sol[i];
|
||||
}
|
||||
int nsol = valid_sols[thr_id];
|
||||
if (nsol < 0) nsol = 0;
|
||||
if(nSolution.size() == 1344) {
|
||||
// todo, only store solution data here...
|
||||
le32enc(&data_sols[thr_id][nsol][140], 0x000540fd); // sol sz header
|
||||
memcpy(&data_sols[thr_id][nsol][143], nSolution.data(), 1344);
|
||||
valid_sols[thr_id] = nsol + 1;
|
||||
}
|
||||
}
|
||||
static void cb_hashdone(int thr_id) {
|
||||
if (!valid_sols[thr_id]) valid_sols[thr_id] = -1;
|
||||
}
|
||||
static bool cb_cancel(int thr_id) {
|
||||
if (work_restart[thr_id].restart)
|
||||
valid_sols[thr_id] = -1;
|
||||
return work_restart[thr_id].restart;
|
||||
}
|
||||
|
||||
extern "C" int scanhash_equihash(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[35];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[NONCE_OFT];
|
||||
uint32_t nonce_increment = rand() & 0xFF; // nonce randomizer
|
||||
struct timeval tv_start, tv_end, diff;
|
||||
double secs, solps;
|
||||
uint32_t soluce_count = 0;
|
||||
|
||||
if (opt_benchmark)
|
||||
ptarget[7] = 0xfffff;
|
||||
|
||||
if (!init[thr_id]) {
|
||||
try {
|
||||
int mode = 1;
|
||||
switch (mode) {
|
||||
case 1:
|
||||
solvers[thr_id] = new eq_cuda_context<CONFIG_MODE_1>(thr_id, device_map[thr_id]);
|
||||
break;
|
||||
#ifdef CONFIG_MODE_2
|
||||
case 2:
|
||||
solvers[thr_id] = new eq_cuda_context<CONFIG_MODE_2>(thr_id, device_map[thr_id]);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_MODE_3
|
||||
case 3:
|
||||
solvers[thr_id] = new eq_cuda_context<CONFIG_MODE_3>(thr_id, device_map[thr_id]);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
proper_exit(EXIT_CODE_SW_INIT_ERROR);
|
||||
return -1;
|
||||
}
|
||||
size_t memSz = solvers[thr_id]->equi_mem_sz / (1024*1024);
|
||||
api_set_throughput(thr_id, (uint32_t) solvers[thr_id]->throughput);
|
||||
gpulog(LOG_DEBUG, thr_id, "Allocated %u MB of context memory", (u32) memSz);
|
||||
cuda_get_arch(thr_id);
|
||||
init[thr_id] = true;
|
||||
} catch (const std::exception & e) {
|
||||
CUDA_LOG_ERROR();
|
||||
gpulog(LOG_ERR, thr_id, "init: %s", e.what());
|
||||
proper_exit(EXIT_CODE_CUDA_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
memcpy(endiandata, pdata, 140);
|
||||
work->valid_nonces = 0;
|
||||
|
||||
do {
|
||||
|
||||
try {
|
||||
|
||||
valid_sols[thr_id] = 0;
|
||||
solvers[thr_id]->solve(
|
||||
(const char *) endiandata, (unsigned int) (140 - 32),
|
||||
(const char *) &endiandata[27], (unsigned int) 32,
|
||||
&cb_cancel, &cb_solution, &cb_hashdone
|
||||
);
|
||||
|
||||
*hashes_done = soluce_count;
|
||||
|
||||
} catch (const std::exception & e) {
|
||||
gpulog(LOG_WARNING, thr_id, "solver: %s", e.what());
|
||||
free_equihash(thr_id);
|
||||
sleep(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (valid_sols[thr_id] > 0)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t _ALIGN(64) vhash[8];
|
||||
uint8_t _ALIGN(64) full_data[140+3+1344] = { 0 };
|
||||
uint8_t* sol_data = &full_data[140];
|
||||
|
||||
soluce_count += valid_sols[thr_id];
|
||||
|
||||
for (int nsol=0; nsol < valid_sols[thr_id]; nsol++)
|
||||
{
|
||||
memcpy(full_data, endiandata, 140);
|
||||
memcpy(sol_data, &data_sols[thr_id][nsol][140], 1347);
|
||||
equi_hash(full_data, vhash, 140+3+1344);
|
||||
|
||||
if (vhash[7] <= Htarg && fulltest(vhash, ptarget))
|
||||
{
|
||||
bool valid = equi_verify_sol(endiandata, &sol_data[3]);
|
||||
if (valid && work->valid_nonces < MAX_NONCES) {
|
||||
work->valid_nonces++;
|
||||
memcpy(work->data, endiandata, 140);
|
||||
equi_store_work_solution(work, vhash, sol_data);
|
||||
work->nonces[work->valid_nonces-1] = endiandata[NONCE_OFT];
|
||||
pdata[NONCE_OFT] = endiandata[NONCE_OFT] + 1;
|
||||
//applog_hex(vhash, 32);
|
||||
//applog_hex(&work->data[27], 32);
|
||||
goto out; // second solution storage not handled..
|
||||
}
|
||||
}
|
||||
if (work->valid_nonces == MAX_NONCES) goto out;
|
||||
}
|
||||
if (work->valid_nonces)
|
||||
goto out;
|
||||
|
||||
valid_sols[thr_id] = 0;
|
||||
}
|
||||
|
||||
endiandata[NONCE_OFT] += nonce_increment;
|
||||
|
||||
} while (!work_restart[thr_id].restart);
|
||||
|
||||
out:
|
||||
gettimeofday(&tv_end, NULL);
|
||||
timeval_subtract(&diff, &tv_end, &tv_start);
|
||||
secs = (1.0 * diff.tv_sec) + (0.000001 * diff.tv_usec);
|
||||
solps = (double)soluce_count / secs;
|
||||
gpulog(LOG_DEBUG, thr_id, "%d solutions in %.2f s (%.2f Sol/s)", soluce_count, secs, solps);
|
||||
|
||||
// H/s
|
||||
*hashes_done = soluce_count;
|
||||
|
||||
pdata[NONCE_OFT] = endiandata[NONCE_OFT] + 1;
|
||||
|
||||
return work->valid_nonces;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
void free_equihash(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
// assume config 1 was used... interface destructor seems bad
|
||||
eq_cuda_context<CONFIG_MODE_1>* ptr = dynamic_cast<eq_cuda_context<CONFIG_MODE_1>*>(solvers[thr_id]);
|
||||
ptr->freemem();
|
||||
ptr = NULL;
|
||||
|
||||
solvers[thr_id] = NULL;
|
||||
|
||||
init[thr_id] = false;
|
||||
}
|
||||
|
||||
// mmm... viva c++ junk
|
||||
void eq_cuda_context_interface::solve(const char *tequihash_header, unsigned int tequihash_header_len,
|
||||
const char* nonce, unsigned int nonce_len,
|
||||
fn_cancel cancelf, fn_solution solutionf, fn_hashdone hashdonef) { }
|
||||
Loaded 100 of 247 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user