mirror of https://github.com/GOSTSec/sgminer
Paul Sheppard
13 years ago
39 changed files with 4770 additions and 574 deletions
@ -0,0 +1,143 @@
@@ -0,0 +1,143 @@
|
||||
If you wish to donate to the author, Con Kolivas, in LTC, please submit your |
||||
donations to: |
||||
|
||||
Lc8TWMiKM7gRUrG8VB8pPNP1Yvt1SGZnoH |
||||
|
||||
Otherwise, please donate in BTC as per the main README. |
||||
|
||||
--- |
||||
|
||||
|
||||
Scrypt mining, AKA litecoin mining, for GPU is completely different to sha256 |
||||
used for bitcoin mining. The algorithm was originally developed in a manner |
||||
that it was anticipated would make it suitable for mining on CPU but NOT GPU. |
||||
Thanks to some innovative work by Artforz and mtrlt, this was proven to be |
||||
wrong. However, it has very different requirements to bitcoin mining and is a |
||||
lot more complicated to get working well. Note that it is a ram dependent |
||||
workload, and requires you to have enough system ram as well as fast enough |
||||
GPU ram. If you have less system ram than your GPU has, it may not be possible |
||||
to mine at any reasonable rate. |
||||
|
||||
There are 5 main parameters to tuning scrypt, 2 of which you MUST set, and |
||||
the others are optional for further fine tuning. When you start scrypt mining |
||||
with the --scrypt option, cgminer will fail IN RANDOM WAYS. They are all due |
||||
to parameters being outside what the GPU can cope with. Not giving cgminer a |
||||
hint as to your GPU type, it will hardly ever perform well. |
||||
|
||||
NOTE that if it does not fail at startup, the presence of hardware errors (HW) |
||||
are a sure sign that you have set the parameters too high. |
||||
|
||||
|
||||
Step 1 on linux: |
||||
export GPU_MAX_ALLOC_PERCENT=100 |
||||
If you do not do this, you may find it impossible to scrypt mine. You may find |
||||
a value of 40 is enough and increasing this further has little effect. |
||||
|
||||
export GPU_USE_SYNC_OBJECTS=1 |
||||
may help CPU usage a little as well. |
||||
|
||||
--shaders XXX |
||||
|
||||
is a new option where you tell cgminer how many shaders your GPU has. This |
||||
helps cgminer try to choose some meaningful baseline parameters. Use this table |
||||
below to determine how many shaders your GPU has, and note that there are some |
||||
variants of these cards, and nvidia shaders are much much lower and virtually |
||||
pointless trying to mine on. |
||||
|
||||
GPU Shaders |
||||
7750 512 |
||||
7770 640 |
||||
7850 1024 |
||||
7870 1280 |
||||
7950 1792 |
||||
7970 2048 |
||||
|
||||
6850 960 |
||||
6870 1120 |
||||
6950 1408 |
||||
6970 1536 |
||||
6990 (6970x2) |
||||
|
||||
6570 480 |
||||
6670 480 |
||||
6790 800 |
||||
|
||||
6450 160 |
||||
|
||||
5670 400 |
||||
5750 720 |
||||
5770 800 |
||||
5830 1120 |
||||
5850 1440 |
||||
5870 1600 |
||||
5970 (5870x2) |
||||
|
||||
These are only used as a rough guide for cgminer, and it is rare that this is |
||||
all you will need to set. |
||||
|
||||
|
||||
--intensity XX |
||||
|
||||
Just like in bitcoin mining, scrypt mining takes an intensity, however the |
||||
scale goes from 0 to 20 to mimic the "Aggression" used in mtrlt's reaper. The |
||||
reason this is crucial is that too high an intensity can actually be |
||||
disastrous with scrypt because it CAN run out of ram. Intensities over 13 |
||||
start writing over the same ram and it is highly dependent on the GPU, but they |
||||
can start actually DECREASING your hashrate, or even worse, start producing |
||||
garbage with HW errors skyrocketing. The low level detail is that intensity is |
||||
only guaranteed up to the power of 2 that most closely matches the thread |
||||
concurrency. i.e. a thread concurrency of 6144 has 8192 as the nearest power |
||||
of two above it, thus as 2^13=8192, that is an intensity of 13. |
||||
|
||||
|
||||
Optional parameters to tune: |
||||
-g, --thread-concurrency, --lookup-gap |
||||
|
||||
-g: |
||||
Once you have found the optimal shaders and intensity, you can start increasing |
||||
the -g value till cgminer fails to start. Rarely will you be able to go over |
||||
about -g 4 and each increase in -g only increases hashrate slightly. |
||||
|
||||
--thread-concurrency: |
||||
This tunes the optimal size of work that scrypt can do. It is internally tuned |
||||
by cgminer to be the highest reasonable multiple of shaders that it can |
||||
allocate on your GPU. Ideally it should be a multiple of your shader count. |
||||
vliw5 architecture (R5XXX) would be best at 5x shaders, while VLIW4 (R6xxx and |
||||
R7xxx) are best at 4x. Setting thread concurrency overrides anything you put |
||||
into --shaders. |
||||
|
||||
--lookup-gap |
||||
This tunes a compromise between ram usage and performance. Performance peaks |
||||
at a gap of 2, but increasing the gap can save you some GPU ram, but almost |
||||
always at the cost of significant loss of hashrate. Setting lookup gap |
||||
overrides the default of 2, but cgminer will use the --shaders value to choose |
||||
a thread-concurrency if you haven't chosen one. |
||||
|
||||
|
||||
Overclocking for scrypt mining: |
||||
First of all, do not underclock your memory initially. Scrypt mining requires |
||||
memory speed and on most, but not all, GPUs, lowering memory speed lowers |
||||
mining performance. |
||||
|
||||
Second, absolute engine clock speeds do NOT correlate with hashrate. The ratio |
||||
of engine clock speed to memory matters, so if you set your memory to the |
||||
default value, and then start overclocking as you are running it, you should |
||||
find a sweet spot where the hashrate peaks and then it might actually drop if |
||||
you increase the engine clock speed further. Unless you wish to run with a |
||||
dynamic intensity, do not go over 13 without testing it while it's running to |
||||
see that it increases hashrate AND utility WITHOUT increasing your HW errors. |
||||
|
||||
|
||||
Suggested values for 7970 for example: |
||||
export GPU_MAX_ALLOC_PERCENT=100 |
||||
--thread-concurrency 8192 -g 4 --gpu-engine 1135 --gpu-memclock 1375 |
||||
|
||||
|
||||
--- |
||||
|
||||
If you wish to donate to the author, Con Kolivas, in LTC, please submit your |
||||
donations to: |
||||
|
||||
Lc8TWMiKM7gRUrG8VB8pPNP1Yvt1SGZnoH |
||||
|
||||
Otherwise, please donate in BTC as per the main README. |
@ -1,12 +1,17 @@
@@ -1,12 +1,17 @@
|
||||
#!/bin/sh |
||||
cwd="$PWD" |
||||
bs_dir="$(dirname $(readlink -f $0))" |
||||
rm -rf "${bs_dir}"/autom4te.cache |
||||
rm -f "${bs_dir}"/aclocal.m4 "${bs_dir}"/ltmain.sh |
||||
|
||||
# You need autoconf 2.5x, preferably 2.57 or later |
||||
# You need automake 1.7 or later. 1.6 might work. |
||||
|
||||
set -e |
||||
|
||||
aclocal -I m4 |
||||
autoheader |
||||
automake --add-missing --copy |
||||
autoconf |
||||
|
||||
echo 'Running autoreconf -if...' |
||||
autoreconf -if || exit 1 |
||||
if test -z "$NOCONFIGURE" ; then |
||||
echo 'Configuring...' |
||||
cd "${bs_dir}" &> /dev/null |
||||
test "$?" = "0" || e=1 |
||||
test "$cwd" != "$bs_dir" && cd "$bs_dir" &> /dev/null |
||||
./configure $@ |
||||
test "$e" = "1" && exit 1 |
||||
cd "$cwd" |
||||
fi |
||||
|
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
v2.4.1 |
||||
v2.4.2 |
||||
v2.6.2 |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,466 @@
@@ -0,0 +1,466 @@
|
||||
/*-
|
||||
* Copyright 2009 Colin Percival, 2011 ArtForz |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. 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 AUTHOR 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 AUTHOR 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. |
||||
* |
||||
* This file was originally written by Colin Percival as part of the Tarsnap |
||||
* online backup system. |
||||
*/ |
||||
|
||||
#include "config.h" |
||||
#include "miner.h" |
||||
|
||||
#include <stdlib.h> |
||||
#include <stdint.h> |
||||
#include <string.h> |
||||
|
||||
#define byteswap(x) ((((x) << 24) & 0xff000000u) | (((x) << 8) & 0x00ff0000u) | (((x) >> 8) & 0x0000ff00u) | (((x) >> 24) & 0x000000ffu)) |
||||
|
||||
typedef struct SHA256Context { |
||||
uint32_t state[8]; |
||||
uint32_t buf[16]; |
||||
} SHA256_CTX; |
||||
|
||||
/*
|
||||
* Encode a length len/4 vector of (uint32_t) into a length len vector of |
||||
* (unsigned char) in big-endian form. Assumes len is a multiple of 4. |
||||
*/ |
||||
static inline void |
||||
be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len) |
||||
{ |
||||
uint32_t i; |
||||
|
||||
for (i = 0; i < len; i++) |
||||
dst[i] = byteswap(src[i]); |
||||
} |
||||
|
||||
/* Elementary functions used by SHA256 */ |
||||
#define Ch(x, y, z) ((x & (y ^ z)) ^ z) |
||||
#define Maj(x, y, z) ((x & (y | z)) | (y & z)) |
||||
#define SHR(x, n) (x >> n) |
||||
#define ROTR(x, n) ((x >> n) | (x << (32 - n))) |
||||
#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) |
||||
#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) |
||||
#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) |
||||
#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) |
||||
|
||||
/* SHA256 round function */ |
||||
#define RND(a, b, c, d, e, f, g, h, k) \ |
||||
t0 = h + S1(e) + Ch(e, f, g) + k; \ |
||||
t1 = S0(a) + Maj(a, b, c); \ |
||||
d += t0; \ |
||||
h = t0 + t1; |
||||
|
||||
/* Adjusted round function for rotating state */ |
||||
#define RNDr(S, W, i, k) \ |
||||
RND(S[(64 - i) % 8], S[(65 - i) % 8], \ |
||||
S[(66 - i) % 8], S[(67 - i) % 8], \ |
||||
S[(68 - i) % 8], S[(69 - i) % 8], \ |
||||
S[(70 - i) % 8], S[(71 - i) % 8], \ |
||||
W[i] + k) |
||||
|
||||
/*
|
||||
* SHA256 block compression function. The 256-bit state is transformed via |
||||
* the 512-bit input block to produce a new state. |
||||
*/ |
||||
static void |
||||
SHA256_Transform(uint32_t * state, const uint32_t block[16], int swap) |
||||
{ |
||||
uint32_t W[64]; |
||||
uint32_t S[8]; |
||||
uint32_t t0, t1; |
||||
int i; |
||||
|
||||
/* 1. Prepare message schedule W. */ |
||||
if(swap) |
||||
for (i = 0; i < 16; i++) |
||||
W[i] = byteswap(block[i]); |
||||
else |
||||
memcpy(W, block, 64); |
||||
for (i = 16; i < 64; i += 2) { |
||||
W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; |
||||
W[i+1] = s1(W[i - 1]) + W[i - 6] + s0(W[i - 14]) + W[i - 15]; |
||||
} |
||||
|
||||
/* 2. Initialize working variables. */ |
||||
memcpy(S, state, 32); |
||||
|
||||
/* 3. Mix. */ |
||||
RNDr(S, W, 0, 0x428a2f98); |
||||
RNDr(S, W, 1, 0x71374491); |
||||
RNDr(S, W, 2, 0xb5c0fbcf); |
||||
RNDr(S, W, 3, 0xe9b5dba5); |
||||
RNDr(S, W, 4, 0x3956c25b); |
||||
RNDr(S, W, 5, 0x59f111f1); |
||||
RNDr(S, W, 6, 0x923f82a4); |
||||
RNDr(S, W, 7, 0xab1c5ed5); |
||||
RNDr(S, W, 8, 0xd807aa98); |
||||
RNDr(S, W, 9, 0x12835b01); |
||||
RNDr(S, W, 10, 0x243185be); |
||||
RNDr(S, W, 11, 0x550c7dc3); |
||||
RNDr(S, W, 12, 0x72be5d74); |
||||
RNDr(S, W, 13, 0x80deb1fe); |
||||
RNDr(S, W, 14, 0x9bdc06a7); |
||||
RNDr(S, W, 15, 0xc19bf174); |
||||
RNDr(S, W, 16, 0xe49b69c1); |
||||
RNDr(S, W, 17, 0xefbe4786); |
||||
RNDr(S, W, 18, 0x0fc19dc6); |
||||
RNDr(S, W, 19, 0x240ca1cc); |
||||
RNDr(S, W, 20, 0x2de92c6f); |
||||
RNDr(S, W, 21, 0x4a7484aa); |
||||
RNDr(S, W, 22, 0x5cb0a9dc); |
||||
RNDr(S, W, 23, 0x76f988da); |
||||
RNDr(S, W, 24, 0x983e5152); |
||||
RNDr(S, W, 25, 0xa831c66d); |
||||
RNDr(S, W, 26, 0xb00327c8); |
||||
RNDr(S, W, 27, 0xbf597fc7); |
||||
RNDr(S, W, 28, 0xc6e00bf3); |
||||
RNDr(S, W, 29, 0xd5a79147); |
||||
RNDr(S, W, 30, 0x06ca6351); |
||||
RNDr(S, W, 31, 0x14292967); |
||||
RNDr(S, W, 32, 0x27b70a85); |
||||
RNDr(S, W, 33, 0x2e1b2138); |
||||
RNDr(S, W, 34, 0x4d2c6dfc); |
||||
RNDr(S, W, 35, 0x53380d13); |
||||
RNDr(S, W, 36, 0x650a7354); |
||||
RNDr(S, W, 37, 0x766a0abb); |
||||
RNDr(S, W, 38, 0x81c2c92e); |
||||
RNDr(S, W, 39, 0x92722c85); |
||||
RNDr(S, W, 40, 0xa2bfe8a1); |
||||
RNDr(S, W, 41, 0xa81a664b); |
||||
RNDr(S, W, 42, 0xc24b8b70); |
||||
RNDr(S, W, 43, 0xc76c51a3); |
||||
RNDr(S, W, 44, 0xd192e819); |
||||
RNDr(S, W, 45, 0xd6990624); |
||||
RNDr(S, W, 46, 0xf40e3585); |
||||
RNDr(S, W, 47, 0x106aa070); |
||||
RNDr(S, W, 48, 0x19a4c116); |
||||
RNDr(S, W, 49, 0x1e376c08); |
||||
RNDr(S, W, 50, 0x2748774c); |
||||
RNDr(S, W, 51, 0x34b0bcb5); |
||||
RNDr(S, W, 52, 0x391c0cb3); |
||||
RNDr(S, W, 53, 0x4ed8aa4a); |
||||
RNDr(S, W, 54, 0x5b9cca4f); |
||||
RNDr(S, W, 55, 0x682e6ff3); |
||||
RNDr(S, W, 56, 0x748f82ee); |
||||
RNDr(S, W, 57, 0x78a5636f); |
||||
RNDr(S, W, 58, 0x84c87814); |
||||
RNDr(S, W, 59, 0x8cc70208); |
||||
RNDr(S, W, 60, 0x90befffa); |
||||
RNDr(S, W, 61, 0xa4506ceb); |
||||
RNDr(S, W, 62, 0xbef9a3f7); |
||||
RNDr(S, W, 63, 0xc67178f2); |
||||
|
||||
/* 4. Mix local working variables into global state */ |
||||
for (i = 0; i < 8; i++) |
||||
state[i] += S[i]; |
||||
} |
||||
|
||||
static inline void |
||||
SHA256_InitState(uint32_t * state) |
||||
{ |
||||
/* Magic initialization constants */ |
||||
state[0] = 0x6A09E667; |
||||
state[1] = 0xBB67AE85; |
||||
state[2] = 0x3C6EF372; |
||||
state[3] = 0xA54FF53A; |
||||
state[4] = 0x510E527F; |
||||
state[5] = 0x9B05688C; |
||||
state[6] = 0x1F83D9AB; |
||||
state[7] = 0x5BE0CD19; |
||||
} |
||||
|
||||
static const uint32_t passwdpad[12] = {0x00000080, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80020000}; |
||||
static const uint32_t outerpad[8] = {0x80000000, 0, 0, 0, 0, 0, 0, 0x00000300}; |
||||
|
||||
/**
|
||||
* PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): |
||||
* Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and |
||||
* write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). |
||||
*/ |
||||
static inline void |
||||
PBKDF2_SHA256_80_128(const uint32_t * passwd, uint32_t * buf) |
||||
{ |
||||
SHA256_CTX PShictx, PShoctx; |
||||
uint32_t tstate[8]; |
||||
uint32_t ihash[8]; |
||||
uint32_t i; |
||||
uint32_t pad[16]; |
||||
|
||||
static const uint32_t innerpad[11] = {0x00000080, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xa0040000}; |
||||
|
||||
/* If Klen > 64, the key is really SHA256(K). */ |
||||
SHA256_InitState(tstate); |
||||
SHA256_Transform(tstate, passwd, 1); |
||||
memcpy(pad, passwd+16, 16); |
||||
memcpy(pad+4, passwdpad, 48); |
||||
SHA256_Transform(tstate, pad, 1); |
||||
memcpy(ihash, tstate, 32); |
||||
|
||||
SHA256_InitState(PShictx.state); |
||||
for (i = 0; i < 8; i++) |
||||
pad[i] = ihash[i] ^ 0x36363636; |
||||
for (; i < 16; i++) |
||||
pad[i] = 0x36363636; |
||||
SHA256_Transform(PShictx.state, pad, 0); |
||||
SHA256_Transform(PShictx.state, passwd, 1); |
||||
be32enc_vect(PShictx.buf, passwd+16, 4); |
||||
be32enc_vect(PShictx.buf+5, innerpad, 11); |
||||
|
||||
SHA256_InitState(PShoctx.state); |
||||
for (i = 0; i < 8; i++) |
||||
pad[i] = ihash[i] ^ 0x5c5c5c5c; |
||||
for (; i < 16; i++) |
||||
pad[i] = 0x5c5c5c5c; |
||||
SHA256_Transform(PShoctx.state, pad, 0); |
||||
memcpy(PShoctx.buf+8, outerpad, 32); |
||||
|
||||
/* Iterate through the blocks. */ |
||||
for (i = 0; i < 4; i++) { |
||||
uint32_t istate[8]; |
||||
uint32_t ostate[8]; |
||||
|
||||
memcpy(istate, PShictx.state, 32); |
||||
PShictx.buf[4] = i + 1; |
||||
SHA256_Transform(istate, PShictx.buf, 0); |
||||
memcpy(PShoctx.buf, istate, 32); |
||||
|
||||
memcpy(ostate, PShoctx.state, 32); |
||||
SHA256_Transform(ostate, PShoctx.buf, 0); |
||||
be32enc_vect(buf+i*8, ostate, 8); |
||||
} |
||||
} |
||||
|
||||
|
||||
static inline uint32_t |
||||
PBKDF2_SHA256_80_128_32(const uint32_t * passwd, const uint32_t * salt) |
||||
{ |
||||
uint32_t tstate[8]; |
||||
uint32_t ostate[8]; |
||||
uint32_t ihash[8]; |
||||
uint32_t i; |
||||
|
||||
/* Compute HMAC state after processing P and S. */ |
||||
uint32_t pad[16]; |
||||
|
||||
static const uint32_t ihash_finalblk[16] = {0x00000001,0x80000000,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0x00000620}; |
||||
|
||||
/* If Klen > 64, the key is really SHA256(K). */ |
||||
SHA256_InitState(tstate); |
||||
SHA256_Transform(tstate, passwd, 1); |
||||
memcpy(pad, passwd+16, 16); |
||||
memcpy(pad+4, passwdpad, 48); |
||||
SHA256_Transform(tstate, pad, 1); |
||||
memcpy(ihash, tstate, 32); |
||||
|
||||
SHA256_InitState(ostate); |
||||
for (i = 0; i < 8; i++) |
||||
pad[i] = ihash[i] ^ 0x5c5c5c5c; |
||||
for (; i < 16; i++) |
||||
pad[i] = 0x5c5c5c5c; |
||||
SHA256_Transform(ostate, pad, 0); |
||||
|
||||
SHA256_InitState(tstate); |
||||
for (i = 0; i < 8; i++) |
||||
pad[i] = ihash[i] ^ 0x36363636; |
||||
for (; i < 16; i++) |
||||
pad[i] = 0x36363636; |
||||
SHA256_Transform(tstate, pad, 0); |
||||
SHA256_Transform(tstate, salt, 1); |
||||
SHA256_Transform(tstate, salt+16, 1); |
||||
SHA256_Transform(tstate, ihash_finalblk, 0); |
||||
memcpy(pad, tstate, 32); |
||||
memcpy(pad+8, outerpad, 32); |
||||
|
||||
/* Feed the inner hash to the outer SHA256 operation. */ |
||||
SHA256_Transform(ostate, pad, 0); |
||||
/* Finish the outer SHA256 operation. */ |
||||
return byteswap(ostate[7]); |
||||
} |
||||
|
||||
|
||||
/**
|
||||
* salsa20_8(B): |
||||
* Apply the salsa20/8 core to the provided block. |
||||
*/ |
||||
static inline void |
||||
salsa20_8(uint32_t B[16], const uint32_t Bx[16]) |
||||
{ |
||||
uint32_t x00,x01,x02,x03,x04,x05,x06,x07,x08,x09,x10,x11,x12,x13,x14,x15; |
||||
size_t i; |
||||
|
||||
x00 = (B[ 0] ^= Bx[ 0]); |
||||
x01 = (B[ 1] ^= Bx[ 1]); |
||||
x02 = (B[ 2] ^= Bx[ 2]); |
||||
x03 = (B[ 3] ^= Bx[ 3]); |
||||
x04 = (B[ 4] ^= Bx[ 4]); |
||||
x05 = (B[ 5] ^= Bx[ 5]); |
||||
x06 = (B[ 6] ^= Bx[ 6]); |
||||
x07 = (B[ 7] ^= Bx[ 7]); |
||||
x08 = (B[ 8] ^= Bx[ 8]); |
||||
x09 = (B[ 9] ^= Bx[ 9]); |
||||
x10 = (B[10] ^= Bx[10]); |
||||
x11 = (B[11] ^= Bx[11]); |
||||
x12 = (B[12] ^= Bx[12]); |
||||
x13 = (B[13] ^= Bx[13]); |
||||
x14 = (B[14] ^= Bx[14]); |
||||
x15 = (B[15] ^= Bx[15]); |
||||
for (i = 0; i < 8; i += 2) { |
||||
#define R(a,b) (((a) << (b)) | ((a) >> (32 - (b)))) |
||||
/* Operate on columns. */ |
||||
x04 ^= R(x00+x12, 7); x09 ^= R(x05+x01, 7); x14 ^= R(x10+x06, 7); x03 ^= R(x15+x11, 7); |
||||
x08 ^= R(x04+x00, 9); x13 ^= R(x09+x05, 9); x02 ^= R(x14+x10, 9); x07 ^= R(x03+x15, 9); |
||||
x12 ^= R(x08+x04,13); x01 ^= R(x13+x09,13); x06 ^= R(x02+x14,13); x11 ^= R(x07+x03,13); |
||||
x00 ^= R(x12+x08,18); x05 ^= R(x01+x13,18); x10 ^= R(x06+x02,18); x15 ^= R(x11+x07,18); |
||||
|
||||
/* Operate on rows. */ |
||||
x01 ^= R(x00+x03, 7); x06 ^= R(x05+x04, 7); x11 ^= R(x10+x09, 7); x12 ^= R(x15+x14, 7); |
||||
x02 ^= R(x01+x00, 9); x07 ^= R(x06+x05, 9); x08 ^= R(x11+x10, 9); x13 ^= R(x12+x15, 9); |
||||
x03 ^= R(x02+x01,13); x04 ^= R(x07+x06,13); x09 ^= R(x08+x11,13); x14 ^= R(x13+x12,13); |
||||
x00 ^= R(x03+x02,18); x05 ^= R(x04+x07,18); x10 ^= R(x09+x08,18); x15 ^= R(x14+x13,18); |
||||
#undef R |
||||
} |
||||
B[ 0] += x00; |
||||
B[ 1] += x01; |
||||
B[ 2] += x02; |
||||
B[ 3] += x03; |
||||
B[ 4] += x04; |
||||
B[ 5] += x05; |
||||
B[ 6] += x06; |
||||
B[ 7] += x07; |
||||
B[ 8] += x08; |
||||
B[ 9] += x09; |
||||
B[10] += x10; |
||||
B[11] += x11; |
||||
B[12] += x12; |
||||
B[13] += x13; |
||||
B[14] += x14; |
||||
B[15] += x15; |
||||
} |
||||
|
||||
/* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output
|
||||
scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes |
||||
*/ |
||||
static uint32_t scrypt_1024_1_1_256_sp(const uint32_t* input, char* scratchpad) |
||||
{ |
||||
uint32_t * V; |
||||
uint32_t X[32]; |
||||
uint32_t i; |
||||
uint32_t j; |
||||
uint32_t k; |
||||
uint64_t *p1, *p2; |
||||
|
||||
p1 = (uint64_t *)X; |
||||
V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63)); |
||||
|
||||
PBKDF2_SHA256_80_128(input, X); |
||||
|
||||
for (i = 0; i < 1024; i += 2) { |
||||
memcpy(&V[i * 32], X, 128); |
||||
|
||||
salsa20_8(&X[0], &X[16]); |
||||
salsa20_8(&X[16], &X[0]); |
||||
|
||||
memcpy(&V[(i + 1) * 32], X, 128); |
||||
|
||||
salsa20_8(&X[0], &X[16]); |
||||
salsa20_8(&X[16], &X[0]); |
||||
} |
||||
for (i = 0; i < 1024; i += 2) { |
||||
j = X[16] & 1023; |
||||
p2 = (uint64_t *)(&V[j * 32]); |
||||
for(k = 0; k < 16; k++) |
||||
p1[k] ^= p2[k]; |
||||
|
||||
salsa20_8(&X[0], &X[16]); |
||||
salsa20_8(&X[16], &X[0]); |
||||
|
||||
j = X[16] & 1023; |
||||
p2 = (uint64_t *)(&V[j * 32]); |
||||
for(k = 0; k < 16; k++) |
||||
p1[k] ^= p2[k]; |
||||
|
||||
salsa20_8(&X[0], &X[16]); |
||||
salsa20_8(&X[16], &X[0]); |
||||
} |
||||
|
||||
return PBKDF2_SHA256_80_128_32(input, X); |
||||
} |
||||
|
||||
/* Used externally as confirmation of correct OCL code */ |
||||
bool scrypt_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce) |
||||
{ |
||||
uint32_t tmp_hash7, Htarg = ((const uint32_t *)ptarget)[7]; |
||||
char *scratchbuf; |
||||
uint32_t data[20]; |
||||
|
||||
be32enc_vect(data, (const uint32_t *)pdata, 19); |
||||
data[19] = byteswap(nonce); |
||||
scratchbuf = alloca(131584); |
||||
tmp_hash7 = scrypt_1024_1_1_256_sp(data, scratchbuf); |
||||
|
||||
return (tmp_hash7 <= Htarg); |
||||
} |
||||
|
||||
bool scanhash_scrypt(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate, |
||||
unsigned char *pdata, unsigned char __maybe_unused *phash1, |
||||
unsigned char __maybe_unused *phash, const unsigned char *ptarget, |
||||
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n) |
||||
{ |
||||
uint32_t *nonce = (uint32_t *)(pdata + 76); |
||||
char *scratchbuf; |
||||
uint32_t data[20]; |
||||
uint32_t tmp_hash7; |
||||
uint32_t Htarg = ((const uint32_t *)ptarget)[7]; |
||||
bool ret = false; |
||||
|
||||
be32enc_vect(data, (const uint32_t *)pdata, 19); |
||||
|
||||
scratchbuf = malloc(131583); |
||||
if (unlikely(!scratchbuf)) { |
||||
applog(LOG_ERR, "Failed to malloc scratchbuf in scanhash_scrypt"); |
||||
return ret; |
||||
} |
||||
|
||||
while(1) { |
||||
*nonce = ++n; |
||||
data[19] = n; |
||||
tmp_hash7 = scrypt_1024_1_1_256_sp(data, scratchbuf); |
||||
|
||||
if (unlikely(tmp_hash7 <= Htarg)) { |
||||
((uint32_t *)pdata)[19] = byteswap(n); |
||||
*last_nonce = n; |
||||
ret = true; |
||||
break; |
||||
} |
||||
|
||||
if (unlikely((n >= max_nonce) || thr->work_restart)) { |
||||
*last_nonce = n; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
free(scratchbuf);; |
||||
return ret; |
||||
} |
||||
|
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
#ifndef SCRYPT_H |
||||
#define SCRYPT_H |
||||
|
||||
#ifdef USE_SCRYPT |
||||
extern bool scrypt_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce); |
||||
#else /* USE_SCRYPT */ |
||||
static inline bool scrypt_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce) |
||||
{ |
||||
return false; |
||||
} |
||||
#endif /* USE_SCRYPT */ |
||||
|
||||
#endif /* SCRYPT_H */ |
@ -0,0 +1,757 @@
@@ -0,0 +1,757 @@
|
||||
#define rotl(x,y) rotate(x,y) |
||||
#define Ch(x,y,z) bitselect(z,y,x) |
||||
#define Maj(x,y,z) Ch((x^z),y,z) |
||||
|
||||
#define EndianSwap(n) (rotl(n&0x00FF00FF,24U)|rotl(n&0xFF00FF00,8U)) |
||||
|
||||
#define Tr2(x) (rotl(x, 30U) ^ rotl(x, 19U) ^ rotl(x, 10U)) |
||||
#define Tr1(x) (rotl(x, 26U) ^ rotl(x, 21U) ^ rotl(x, 7U)) |
||||
#define Wr2(x) (rotl(x, 25U) ^ rotl(x, 14U) ^ (x>>3U)) |
||||
#define Wr1(x) (rotl(x, 15U) ^ rotl(x, 13U) ^ (x>>10U)) |
||||
|
||||
#define RND(a, b, c, d, e, f, g, h, k) \ |
||||
h += Tr1(e) + Ch(e, f, g) + k; \ |
||||
d += h; \ |
||||
h += Tr2(a) + Maj(a, b, c); |
||||
|
||||
void SHA256(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) |
||||
{ |
||||
uint4 S0 = *state0; |
||||
uint4 S1 = *state1; |
||||
|
||||
#define A S0.x |
||||
#define B S0.y |
||||
#define C S0.z |
||||
#define D S0.w |
||||
#define E S1.x |
||||
#define F S1.y |
||||
#define G S1.z |
||||
#define H S1.w |
||||
|
||||
uint4 W[4]; |
||||
|
||||
W[ 0].x = block0.x; |
||||
RND(A,B,C,D,E,F,G,H, W[0].x+0x428a2f98U); |
||||
W[ 0].y = block0.y; |
||||
RND(H,A,B,C,D,E,F,G, W[0].y+0x71374491U); |
||||
W[ 0].z = block0.z; |
||||
RND(G,H,A,B,C,D,E,F, W[0].z+0xb5c0fbcfU); |
||||
W[ 0].w = block0.w; |
||||
RND(F,G,H,A,B,C,D,E, W[0].w+0xe9b5dba5U); |
||||
|
||||
W[ 1].x = block1.x; |
||||
RND(E,F,G,H,A,B,C,D, W[1].x+0x3956c25bU); |
||||
W[ 1].y = block1.y; |
||||
RND(D,E,F,G,H,A,B,C, W[1].y+0x59f111f1U); |
||||
W[ 1].z = block1.z; |
||||
RND(C,D,E,F,G,H,A,B, W[1].z+0x923f82a4U); |
||||
W[ 1].w = block1.w; |
||||
RND(B,C,D,E,F,G,H,A, W[1].w+0xab1c5ed5U); |
||||
|
||||
W[ 2].x = block2.x; |
||||
RND(A,B,C,D,E,F,G,H, W[2].x+0xd807aa98U); |
||||
W[ 2].y = block2.y; |
||||
RND(H,A,B,C,D,E,F,G, W[2].y+0x12835b01U); |
||||
W[ 2].z = block2.z; |
||||
RND(G,H,A,B,C,D,E,F, W[2].z+0x243185beU); |
||||
W[ 2].w = block2.w; |
||||
RND(F,G,H,A,B,C,D,E, W[2].w+0x550c7dc3U); |
||||
|
||||
W[ 3].x = block3.x; |
||||
RND(E,F,G,H,A,B,C,D, W[3].x+0x72be5d74U); |
||||
W[ 3].y = block3.y; |
||||
RND(D,E,F,G,H,A,B,C, W[3].y+0x80deb1feU); |
||||
W[ 3].z = block3.z; |
||||
RND(C,D,E,F,G,H,A,B, W[3].z+0x9bdc06a7U); |
||||
W[ 3].w = block3.w; |
||||
RND(B,C,D,E,F,G,H,A, W[3].w+0xc19bf174U); |
||||
|
||||
W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); |
||||
RND(A,B,C,D,E,F,G,H, W[0].x+0xe49b69c1U); |
||||
|
||||
W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); |
||||
RND(H,A,B,C,D,E,F,G, W[0].y+0xefbe4786U); |
||||
|
||||
W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); |
||||
RND(G,H,A,B,C,D,E,F, W[0].z+0x0fc19dc6U); |
||||
|
||||
W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); |
||||
RND(F,G,H,A,B,C,D,E, W[0].w+0x240ca1ccU); |
||||
|
||||
W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); |
||||
RND(E,F,G,H,A,B,C,D, W[1].x+0x2de92c6fU); |
||||
|
||||
W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); |
||||
RND(D,E,F,G,H,A,B,C, W[1].y+0x4a7484aaU); |
||||
|
||||
W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); |
||||
RND(C,D,E,F,G,H,A,B, W[1].z+0x5cb0a9dcU); |
||||
|
||||
W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); |
||||
RND(B,C,D,E,F,G,H,A, W[1].w+0x76f988daU); |
||||
|
||||
W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); |
||||
RND(A,B,C,D,E,F,G,H, W[2].x+0x983e5152U); |
||||
|
||||
W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); |
||||
RND(H,A,B,C,D,E,F,G, W[2].y+0xa831c66dU); |
||||
|
||||
W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); |
||||
RND(G,H,A,B,C,D,E,F, W[2].z+0xb00327c8U); |
||||
|
||||
W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); |
||||
RND(F,G,H,A,B,C,D,E, W[2].w+0xbf597fc7U); |
||||
|
||||
W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); |
||||
RND(E,F,G,H,A,B,C,D, W[3].x+0xc6e00bf3U); |
||||
|
||||
W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); |
||||
RND(D,E,F,G,H,A,B,C, W[3].y+0xd5a79147U); |
||||
|
||||
W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); |
||||
RND(C,D,E,F,G,H,A,B, W[3].z+0x06ca6351U); |
||||
|
||||
W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); |
||||
RND(B,C,D,E,F,G,H,A, W[3].w+0x14292967U); |
||||
|
||||
W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); |
||||
RND(A,B,C,D,E,F,G,H, W[0].x+0x27b70a85U); |
||||
|
||||
W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); |
||||
RND(H,A,B,C,D,E,F,G, W[0].y+0x2e1b2138U); |
||||
|
||||
W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); |
||||
RND(G,H,A,B,C,D,E,F, W[0].z+0x4d2c6dfcU); |
||||
|
||||
W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); |
||||
RND(F,G,H,A,B,C,D,E, W[0].w+0x53380d13U); |
||||
|
||||
W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); |
||||
RND(E,F,G,H,A,B,C,D, W[1].x+0x650a7354U); |
||||
|
||||
W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); |
||||
RND(D,E,F,G,H,A,B,C, W[1].y+0x766a0abbU); |
||||
|
||||
W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); |
||||
RND(C,D,E,F,G,H,A,B, W[1].z+0x81c2c92eU); |
||||
|
||||
W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); |
||||
RND(B,C,D,E,F,G,H,A, W[1].w+0x92722c85U); |
||||
|
||||
W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); |
||||
RND(A,B,C,D,E,F,G,H, W[2].x+0xa2bfe8a1U); |
||||
|
||||
W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); |
||||
RND(H,A,B,C,D,E,F,G, W[2].y+0xa81a664bU); |
||||
|
||||
W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); |
||||
RND(G,H,A,B,C,D,E,F, W[2].z+0xc24b8b70U); |
||||
|
||||
W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); |
||||
RND(F,G,H,A,B,C,D,E, W[2].w+0xc76c51a3U); |
||||
|
||||
W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); |
||||
RND(E,F,G,H,A,B,C,D, W[3].x+0xd192e819U); |
||||
|
||||
W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); |
||||
RND(D,E,F,G,H,A,B,C, W[3].y+0xd6990624U); |
||||
|
||||
W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); |
||||
RND(C,D,E,F,G,H,A,B, W[3].z+0xf40e3585U); |
||||
|
||||
W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); |
||||
RND(B,C,D,E,F,G,H,A, W[3].w+0x106aa070U); |
||||
|
||||
W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); |
||||
RND(A,B,C,D,E,F,G,H, W[0].x+0x19a4c116U); |
||||
|
||||
W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); |
||||
RND(H,A,B,C,D,E,F,G, W[0].y+0x1e376c08U); |
||||
|
||||
W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); |
||||
RND(G,H,A,B,C,D,E,F, W[0].z+0x2748774cU); |
||||
|
||||
W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); |
||||
RND(F,G,H,A,B,C,D,E, W[0].w+0x34b0bcb5U); |
||||
|
||||
W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); |
||||
RND(E,F,G,H,A,B,C,D, W[1].x+0x391c0cb3U); |
||||
|
||||
W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); |
||||
RND(D,E,F,G,H,A,B,C, W[1].y+0x4ed8aa4aU); |
||||
|
||||
W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); |
||||
RND(C,D,E,F,G,H,A,B, W[1].z+0x5b9cca4fU); |
||||
|
||||
W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); |
||||
RND(B,C,D,E,F,G,H,A, W[1].w+0x682e6ff3U); |
||||
|
||||
W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); |
||||
RND(A,B,C,D,E,F,G,H, W[2].x+0x748f82eeU); |
||||
|
||||
W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); |
||||
RND(H,A,B,C,D,E,F,G, W[2].y+0x78a5636fU); |
||||
|
||||
W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); |
||||
RND(G,H,A,B,C,D,E,F, W[2].z+0x84c87814U); |
||||
|
||||
W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); |
||||
RND(F,G,H,A,B,C,D,E, W[2].w+0x8cc70208U); |
||||
|
||||
W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); |
||||
RND(E,F,G,H,A,B,C,D, W[3].x+0x90befffaU); |
||||
|
||||
W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); |
||||
RND(D,E,F,G,H,A,B,C, W[3].y+0xa4506cebU); |
||||
|
||||
W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); |
||||
RND(C,D,E,F,G,H,A,B, W[3].z+0xbef9a3f7U); |
||||
|
||||
W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); |
||||
RND(B,C,D,E,F,G,H,A, W[3].w+0xc67178f2U); |
||||
|
||||
#undef A |
||||
#undef B |
||||
#undef C |
||||
#undef D |
||||
#undef E |
||||
#undef F |
||||
#undef G |
||||
#undef H |
||||
|
||||
*state0 += S0; |
||||
*state1 += S1; |
||||
} |
||||
|
||||
void SHA256_fresh(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) |
||||
{ |
||||
#define A (*state0).x |
||||
#define B (*state0).y |
||||
#define C (*state0).z |
||||
#define D (*state0).w |
||||
#define E (*state1).x |
||||
#define F (*state1).y |
||||
#define G (*state1).z |
||||
#define H (*state1).w |
||||
|
||||
uint4 W[4]; |
||||
|
||||
W[0].x = block0.x; |
||||
D=0x98c7e2a2U+W[0].x; |
||||
H=0xfc08884dU+W[0].x; |
||||
|
||||
W[0].y = block0.y; |
||||
C=0xcd2a11aeU+Tr1(D)+Ch(D,0x510e527fU,0x9b05688cU)+W[0].y; |
||||
G=0xC3910C8EU+C+Tr2(H)+Ch(H,0xfb6feee7U,0x2a01a605U); |
||||
|
||||
W[0].z = block0.z; |
||||
B=0x0c2e12e0U+Tr1(C)+Ch(C,D,0x510e527fU)+W[0].z; |
||||
F=0x4498517BU+B+Tr2(G)+Maj(G,H,0x6a09e667U); |
||||
|
||||
W[0].w = block0.w; |
||||
A=0xa4ce148bU+Tr1(B)+Ch(B,C,D)+W[0].w; |
||||
E=0x95F61999U+A+Tr2(F)+Maj(F,G,H); |
||||
|
||||
W[1].x = block1.x; |
||||
RND(E,F,G,H,A,B,C,D, W[1].x+0x3956c25bU); |
||||
W[1].y = block1.y; |
||||
RND(D,E,F,G,H,A,B,C, W[1].y+0x59f111f1U); |
||||
W[1].z = block1.z; |
||||
RND(C,D,E,F,G,H,A,B, W[1].z+0x923f82a4U); |
||||
W[1].w = block1.w; |
||||
RND(B,C,D,E,F,G,H,A, W[1].w+0xab1c5ed5U); |
||||
|
||||
W[2].x = block2.x; |
||||
RND(A,B,C,D,E,F,G,H, W[2].x+0xd807aa98U); |
||||
W[2].y = block2.y; |
||||
RND(H,A,B,C,D,E,F,G, W[2].y+0x12835b01U); |
||||
W[2].z = block2.z; |
||||
RND(G,H,A,B,C,D,E,F, W[2].z+0x243185beU); |
||||
W[2].w = block2.w; |
||||
RND(F,G,H,A,B,C,D,E, W[2].w+0x550c7dc3U); |
||||
|
||||
W[3].x = block3.x; |
||||
RND(E,F,G,H,A,B,C,D, W[3].x+0x72be5d74U); |
||||
W[3].y = block3.y; |
||||
RND(D,E,F,G,H,A,B,C, W[3].y+0x80deb1feU); |
||||
W[3].z = block3.z; |
||||
RND(C,D,E,F,G,H,A,B, W[3].z+0x9bdc06a7U); |
||||
W[3].w = block3.w; |
||||
RND(B,C,D,E,F,G,H,A, W[3].w+0xc19bf174U); |
||||
|
||||
W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); |
||||
RND(A,B,C,D,E,F,G,H, W[0].x+0xe49b69c1U); |
||||
|
||||
W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); |
||||
RND(H,A,B,C,D,E,F,G, W[0].y+0xefbe4786U); |
||||
|
||||
W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); |
||||
RND(G,H,A,B,C,D,E,F, W[0].z+0x0fc19dc6U); |
||||
|
||||
W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); |
||||
RND(F,G,H,A,B,C,D,E, W[0].w+0x240ca1ccU); |
||||
|
||||
W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); |
||||
RND(E,F,G,H,A,B,C,D, W[1].x+0x2de92c6fU); |
||||
|
||||
W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); |
||||
RND(D,E,F,G,H,A,B,C, W[1].y+0x4a7484aaU); |
||||
|
||||
W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); |
||||
RND(C,D,E,F,G,H,A,B, W[1].z+0x5cb0a9dcU); |
||||
|
||||
W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); |
||||
RND(B,C,D,E,F,G,H,A, W[1].w+0x76f988daU); |
||||
|
||||
W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); |
||||
RND(A,B,C,D,E,F,G,H, W[2].x+0x983e5152U); |
||||
|
||||
W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); |
||||
RND(H,A,B,C,D,E,F,G, W[2].y+0xa831c66dU); |
||||
|
||||
W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); |
||||
RND(G,H,A,B,C,D,E,F, W[2].z+0xb00327c8U); |
||||
|
||||
W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); |
||||
RND(F,G,H,A,B,C,D,E, W[2].w+0xbf597fc7U); |
||||
|
||||
W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); |
||||
RND(E,F,G,H,A,B,C,D, W[3].x+0xc6e00bf3U); |
||||
|
||||
W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); |
||||
RND(D,E,F,G,H,A,B,C, W[3].y+0xd5a79147U); |
||||
|
||||
W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); |
||||
RND(C,D,E,F,G,H,A,B, W[3].z+0x06ca6351U); |
||||
|
||||
W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); |
||||
RND(B,C,D,E,F,G,H,A, W[3].w+0x14292967U); |
||||
|
||||
W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); |
||||
RND(A,B,C,D,E,F,G,H, W[0].x+0x27b70a85U); |
||||
|
||||
W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); |
||||
RND(H,A,B,C,D,E,F,G, W[0].y+0x2e1b2138U); |
||||
|
||||
W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); |
||||
RND(G,H,A,B,C,D,E,F, W[0].z+0x4d2c6dfcU); |
||||
|
||||
W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); |
||||
RND(F,G,H,A,B,C,D,E, W[0].w+0x53380d13U); |
||||
|
||||
W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); |
||||
RND(E,F,G,H,A,B,C,D, W[1].x+0x650a7354U); |
||||
|
||||
W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); |
||||
RND(D,E,F,G,H,A,B,C, W[1].y+0x766a0abbU); |
||||
|
||||
W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); |
||||
RND(C,D,E,F,G,H,A,B, W[1].z+0x81c2c92eU); |
||||
|
||||
W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); |
||||
RND(B,C,D,E,F,G,H,A, W[1].w+0x92722c85U); |
||||
|
||||
W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); |
||||
RND(A,B,C,D,E,F,G,H, W[2].x+0xa2bfe8a1U); |
||||
|
||||
W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); |
||||
RND(H,A,B,C,D,E,F,G, W[2].y+0xa81a664bU); |
||||
|
||||
W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); |
||||
RND(G,H,A,B,C,D,E,F, W[2].z+0xc24b8b70U); |
||||
|
||||
W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); |
||||
RND(F,G,H,A,B,C,D,E, W[2].w+0xc76c51a3U); |
||||
|
||||
W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); |
||||
RND(E,F,G,H,A,B,C,D, W[3].x+0xd192e819U); |
||||
|
||||
W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); |
||||
RND(D,E,F,G,H,A,B,C, W[3].y+0xd6990624U); |
||||
|
||||
W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); |
||||
RND(C,D,E,F,G,H,A,B, W[3].z+0xf40e3585U); |
||||
|
||||
W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); |
||||
RND(B,C,D,E,F,G,H,A, W[3].w+0x106aa070U); |
||||
|
||||
W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); |
||||
RND(A,B,C,D,E,F,G,H, W[0].x+0x19a4c116U); |
||||
|
||||
W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); |
||||
RND(H,A,B,C,D,E,F,G, W[0].y+0x1e376c08U); |
||||
|
||||
W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); |
||||
RND(G,H,A,B,C,D,E,F, W[0].z+0x2748774cU); |
||||
|
||||
W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); |
||||
RND(F,G,H,A,B,C,D,E, W[0].w+0x34b0bcb5U); |
||||
|
||||
W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); |
||||
RND(E,F,G,H,A,B,C,D, W[1].x+0x391c0cb3U); |
||||
|
||||
W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); |
||||
RND(D,E,F,G,H,A,B,C, W[1].y+0x4ed8aa4aU); |
||||
|
||||
W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); |
||||
RND(C,D,E,F,G,H,A,B, W[1].z+0x5b9cca4fU); |
||||
|
||||
W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); |
||||
RND(B,C,D,E,F,G,H,A, W[1].w+0x682e6ff3U); |
||||
|
||||
W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); |
||||
RND(A,B,C,D,E,F,G,H, W[2].x+0x748f82eeU); |
||||
|
||||
W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); |
||||
RND(H,A,B,C,D,E,F,G, W[2].y+0x78a5636fU); |
||||
|
||||
W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); |
||||
RND(G,H,A,B,C,D,E,F, W[2].z+0x84c87814U); |
||||
|
||||
W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); |
||||
RND(F,G,H,A,B,C,D,E, W[2].w+0x8cc70208U); |
||||
|
||||
W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); |
||||
RND(E,F,G,H,A,B,C,D, W[3].x+0x90befffaU); |
||||
|
||||
W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); |
||||
RND(D,E,F,G,H,A,B,C, W[3].y+0xa4506cebU); |
||||
|
||||
W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); |
||||
RND(C,D,E,F,G,H,A,B, W[3].z+0xbef9a3f7U); |
||||
|
||||
W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); |
||||
RND(B,C,D,E,F,G,H,A, W[3].w+0xc67178f2U); |
||||
|
||||
#undef A |
||||
#undef B |
||||
#undef C |
||||
#undef D |
||||
#undef E |
||||
#undef F |
||||
#undef G |
||||
#undef H |
||||
|
||||
*state0 += (uint4)(0x6A09E667U,0xBB67AE85U,0x3C6EF372U,0xA54FF53AU); |
||||
*state1 += (uint4)(0x510E527FU,0x9B05688CU,0x1F83D9ABU,0x5BE0CD19U); |
||||
} |
||||
|
||||
__constant uint fixedW[64] = |
||||
{ |
||||
0x428a2f99,0xf1374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, |
||||
0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf794, |
||||
0xf59b89c2,0x73924787,0x23c6886e,0xa42ca65c,0x15ed3627,0x4d6edcbf,0xe28217fc,0xef02488f, |
||||
0xb707775c,0x0468c23f,0xe7e72b4c,0x49e1f1a2,0x4b99c816,0x926d1570,0xaa0fc072,0xadb36e2c, |
||||
0xad87a3ea,0xbcb1d3a3,0x7b993186,0x562b9420,0xbff3ca0c,0xda4b0c23,0x6cd8711a,0x8f337caa, |
||||
0xc91b1417,0xc359dce1,0xa83253a7,0x3b13c12d,0x9d3d725d,0xd9031a84,0xb1a03340,0x16f58012, |
||||
0xe64fb6a2,0xe84d923a,0xe93a5730,0x09837686,0x078ff753,0x29833341,0xd5de0b7e,0x6948ccf4, |
||||
0xe0a1adbe,0x7c728e11,0x511c78e4,0x315b45bd,0xfca71413,0xea28f96a,0x79703128,0x4e1ef848, |
||||
}; |
||||
|
||||
void SHA256_fixed(uint4*restrict state0,uint4*restrict state1) |
||||
{ |
||||
uint4 S0 = *state0; |
||||
uint4 S1 = *state1; |
||||
|
||||
#define A S0.x |
||||
#define B S0.y |
||||
#define C S0.z |
||||
#define D S0.w |
||||
#define E S1.x |
||||
#define F S1.y |
||||
#define G S1.z |
||||
#define H S1.w |
||||
|
||||
RND(A,B,C,D,E,F,G,H, fixedW[0]); |
||||
RND(H,A,B,C,D,E,F,G, fixedW[1]); |
||||
RND(G,H,A,B,C,D,E,F, fixedW[2]); |
||||
RND(F,G,H,A,B,C,D,E, fixedW[3]); |
||||
RND(E,F,G,H,A,B,C,D, fixedW[4]); |
||||
RND(D,E,F,G,H,A,B,C, fixedW[5]); |
||||
RND(C,D,E,F,G,H,A,B, fixedW[6]); |
||||
RND(B,C,D,E,F,G,H,A, fixedW[7]); |
||||
RND(A,B,C,D,E,F,G,H, fixedW[8]); |
||||
RND(H,A,B,C,D,E,F,G, fixedW[9]); |
||||
RND(G,H,A,B,C,D,E,F, fixedW[10]); |
||||
RND(F,G,H,A,B,C,D,E, fixedW[11]); |
||||
RND(E,F,G,H,A,B,C,D, fixedW[12]); |
||||
RND(D,E,F,G,H,A,B,C, fixedW[13]); |
||||
RND(C,D,E,F,G,H,A,B, fixedW[14]); |
||||
RND(B,C,D,E,F,G,H,A, fixedW[15]); |
||||
RND(A,B,C,D,E,F,G,H, fixedW[16]); |
||||
RND(H,A,B,C,D,E,F,G, fixedW[17]); |
||||
RND(G,H,A,B,C,D,E,F, fixedW[18]); |
||||
RND(F,G,H,A,B,C,D,E, fixedW[19]); |
||||
RND(E,F,G,H,A,B,C,D, fixedW[20]); |
||||
RND(D,E,F,G,H,A,B,C, fixedW[21]); |
||||
RND(C,D,E,F,G,H,A,B, fixedW[22]); |
||||
RND(B,C,D,E,F,G,H,A, fixedW[23]); |
||||
RND(A,B,C,D,E,F,G,H, fixedW[24]); |
||||
RND(H,A,B,C,D,E,F,G, fixedW[25]); |
||||
RND(G,H,A,B,C,D,E,F, fixedW[26]); |
||||
RND(F,G,H,A,B,C,D,E, fixedW[27]); |
||||
RND(E,F,G,H,A,B,C,D, fixedW[28]); |
||||
RND(D,E,F,G,H,A,B,C, fixedW[29]); |
||||
RND(C,D,E,F,G,H,A,B, fixedW[30]); |
||||
RND(B,C,D,E,F,G,H,A, fixedW[31]); |
||||
RND(A,B,C,D,E,F,G,H, fixedW[32]); |
||||
RND(H,A,B,C,D,E,F,G, fixedW[33]); |
||||
RND(G,H,A,B,C,D,E,F, fixedW[34]); |
||||
RND(F,G,H,A,B,C,D,E, fixedW[35]); |
||||
RND(E,F,G,H,A,B,C,D, fixedW[36]); |
||||
RND(D,E,F,G,H,A,B,C, fixedW[37]); |
||||
RND(C,D,E,F,G,H,A,B, fixedW[38]); |
||||
RND(B,C,D,E,F,G,H,A, fixedW[39]); |
||||
RND(A,B,C,D,E,F,G,H, fixedW[40]); |
||||
RND(H,A,B,C,D,E,F,G, fixedW[41]); |
||||
RND(G,H,A,B,C,D,E,F, fixedW[42]); |
||||
RND(F,G,H,A,B,C,D,E, fixedW[43]); |
||||
RND(E,F,G,H,A,B,C,D, fixedW[44]); |
||||
RND(D,E,F,G,H,A,B,C, fixedW[45]); |
||||
RND(C,D,E,F,G,H,A,B, fixedW[46]); |
||||
RND(B,C,D,E,F,G,H,A, fixedW[47]); |
||||
RND(A,B,C,D,E,F,G,H, fixedW[48]); |
||||
RND(H,A,B,C,D,E,F,G, fixedW[49]); |
||||
RND(G,H,A,B,C,D,E,F, fixedW[50]); |
||||
RND(F,G,H,A,B,C,D,E, fixedW[51]); |
||||
RND(E,F,G,H,A,B,C,D, fixedW[52]); |
||||
RND(D,E,F,G,H,A,B,C, fixedW[53]); |
||||
RND(C,D,E,F,G,H,A,B, fixedW[54]); |
||||
RND(B,C,D,E,F,G,H,A, fixedW[55]); |
||||
RND(A,B,C,D,E,F,G,H, fixedW[56]); |
||||
RND(H,A,B,C,D,E,F,G, fixedW[57]); |
||||
RND(G,H,A,B,C,D,E,F, fixedW[58]); |
||||
RND(F,G,H,A,B,C,D,E, fixedW[59]); |
||||
RND(E,F,G,H,A,B,C,D, fixedW[60]); |
||||
RND(D,E,F,G,H,A,B,C, fixedW[61]); |
||||
RND(C,D,E,F,G,H,A,B, fixedW[62]); |
||||
RND(B,C,D,E,F,G,H,A, fixedW[63]); |
||||
|
||||
#undef A |
||||
#undef B |
||||
#undef C |
||||
#undef D |
||||
#undef E |
||||
#undef F |
||||
#undef G |
||||
#undef H |
||||
*state0 += S0; |
||||
*state1 += S1; |
||||
} |
||||
|
||||
void shittify(uint4 B[8]) |
||||
{ |
||||
uint4 tmp[4]; |
||||
tmp[0] = (uint4)(B[1].x,B[2].y,B[3].z,B[0].w); |
||||
tmp[1] = (uint4)(B[2].x,B[3].y,B[0].z,B[1].w); |
||||
tmp[2] = (uint4)(B[3].x,B[0].y,B[1].z,B[2].w); |
||||
tmp[3] = (uint4)(B[0].x,B[1].y,B[2].z,B[3].w); |
||||
|
||||
#pragma unroll |
||||
for(uint i=0; i<4; ++i) |
||||
B[i] = EndianSwap(tmp[i]); |
||||
|
||||
tmp[0] = (uint4)(B[5].x,B[6].y,B[7].z,B[4].w); |
||||
tmp[1] = (uint4)(B[6].x,B[7].y,B[4].z,B[5].w); |
||||
tmp[2] = (uint4)(B[7].x,B[4].y,B[5].z,B[6].w); |
||||
tmp[3] = (uint4)(B[4].x,B[5].y,B[6].z,B[7].w); |
||||
|
||||
#pragma unroll |
||||
for(uint i=0; i<4; ++i) |
||||
B[i+4] = EndianSwap(tmp[i]); |
||||
} |
||||
|
||||
void unshittify(uint4 B[8]) |
||||
{ |
||||
uint4 tmp[4]; |
||||
tmp[0] = (uint4)(B[3].x,B[2].y,B[1].z,B[0].w); |
||||
tmp[1] = (uint4)(B[0].x,B[3].y,B[2].z,B[1].w); |
||||
tmp[2] = (uint4)(B[1].x,B[0].y,B[3].z,B[2].w); |
||||
tmp[3] = (uint4)(B[2].x,B[1].y,B[0].z,B[3].w); |
||||
|
||||
#pragma unroll |
||||
for(uint i=0; i<4; ++i) |
||||
B[i] = EndianSwap(tmp[i]); |
||||
|
||||
tmp[0] = (uint4)(B[7].x,B[6].y,B[5].z,B[4].w); |
||||
tmp[1] = (uint4)(B[4].x,B[7].y,B[6].z,B[5].w); |
||||
tmp[2] = (uint4)(B[5].x,B[4].y,B[7].z,B[6].w); |
||||
tmp[3] = (uint4)(B[6].x,B[5].y,B[4].z,B[7].w); |
||||
|
||||
#pragma unroll |
||||
for(uint i=0; i<4; ++i) |
||||
B[i+4] = EndianSwap(tmp[i]); |
||||
} |
||||
|
||||
void salsa(uint4 B[8]) |
||||
{ |
||||
uint4 w[4]; |
||||
|
||||
#pragma unroll |
||||
for(uint i=0; i<4; ++i) |
||||
w[i] = (B[i]^=B[i+4]); |
||||
|
||||
#pragma unroll |
||||
for(uint i=0; i<4; ++i) |
||||
{ |
||||
w[0] ^= rotl(w[3] +w[2] , 7U); |
||||
w[1] ^= rotl(w[0] +w[3] , 9U); |
||||
w[2] ^= rotl(w[1] +w[0] ,13U); |
||||
w[3] ^= rotl(w[2] +w[1] ,18U); |
||||
w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); |
||||
w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); |
||||
w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); |
||||
w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); |
||||
} |
||||
|
||||
#pragma unroll |
||||
for(uint i=0; i<4; ++i) |
||||
w[i] = (B[i+4]^=(B[i]+=w[i])); |
||||
|
||||
#pragma unroll |
||||
for(uint i=0; i<4; ++i) |
||||
{ |
||||
w[0] ^= rotl(w[3] +w[2] , 7U); |
||||
w[1] ^= rotl(w[0] +w[3] , 9U); |
||||
w[2] ^= rotl(w[1] +w[0] ,13U); |
||||
w[3] ^= rotl(w[2] +w[1] ,18U); |
||||
w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); |
||||
w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); |
||||
w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); |
||||
w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); |
||||
} |
||||
|
||||
#pragma unroll |
||||
for(uint i=0; i<4; ++i) |
||||
B[i+4] += w[i]; |
||||
} |
||||
|
||||
#define Coord(x,y,z) x+y*(x ## SIZE)+z*(y ## SIZE)*(x ## SIZE) |
||||
#define CO Coord(z,x,y) |
||||
|
||||
void scrypt_core(uint4 X[8], __global uint4*restrict lookup) |
||||
{ |
||||
shittify(X); |
||||
const uint zSIZE = 8; |
||||
const uint ySIZE = (1024/LOOKUP_GAP+(1024%LOOKUP_GAP>0)); |
||||
const uint xSIZE = CONCURRENT_THREADS; |
||||
uint x = get_global_id(0)%xSIZE; |
||||
|
||||
for(uint y=0; y<1024/LOOKUP_GAP; ++y) |
||||
{ |
||||
#pragma unroll |
||||
for(uint z=0; z<zSIZE; ++z) |
||||
lookup[CO] = X[z]; |
||||
for(uint i=0; i<LOOKUP_GAP; ++i) |
||||
salsa(X); |
||||
} |
||||
#if (LOOKUP_GAP != 1) && (LOOKUP_GAP != 2) && (LOOKUP_GAP != 4) && (LOOKUP_GAP != 8) |
||||
{ |
||||
uint y = (1024/LOOKUP_GAP); |
||||
#pragma unroll |
||||
for(uint z=0; z<zSIZE; ++z) |
||||
lookup[CO] = X[z]; |
||||
for(uint i=0; i<1024%LOOKUP_GAP; ++i) |
||||
salsa(X); |
||||
} |
||||
#endif |
||||
for (uint i=0; i<1024; ++i) |
||||
{ |
||||
uint4 V[8]; |
||||
uint j = X[7].x & 0x3FF; |
||||
uint y = (j/LOOKUP_GAP); |
||||
#pragma unroll |
||||
for(uint z=0; z<zSIZE; ++z) |
||||
V[z] = lookup[CO]; |
||||
|
||||
#if (LOOKUP_GAP == 1) |
||||
#elif (LOOKUP_GAP == 2) |
||||
if (j&1) |
||||
salsa(V); |
||||
#else |
||||
uint val = j%LOOKUP_GAP; |
||||
for (uint z=0; z<val; ++z) |
||||
salsa(V); |
||||
#endif |
||||
|
||||
#pragma unroll |
||||
for(uint z=0; z<zSIZE; ++z) |
||||
X[z] ^= V[z]; |
||||
salsa(X); |
||||
} |
||||
unshittify(X); |
||||
} |
||||
|
||||
#define FOUND (0x800) |
||||
#define NFLAG (0x7FF) |
||||
|
||||
__attribute__((reqd_work_group_size(WORKSIZE, 1, 1))) |
||||
__kernel void search(__global const uint4 * restrict input, |
||||
__global uint*restrict output, __global uint4*restrict padcache, |
||||
const uint4 midstate0, const uint4 midstate16, const uint target) |
||||
{ |
||||
uint gid = get_global_id(0); |
||||
uint4 X[8]; |
||||
uint4 tstate0, tstate1, ostate0, ostate1, tmp0, tmp1; |
||||
uint4 data = (uint4)(input[4].x,input[4].y,input[4].z,gid); |
||||
uint4 pad0 = midstate0, pad1 = midstate16; |
||||
|
||||
SHA256(&pad0,&pad1, data, (uint4)(0x80000000U,0,0,0), (uint4)(0,0,0,0), (uint4)(0,0,0,0x280)); |
||||
SHA256_fresh(&ostate0,&ostate1, pad0^0x5C5C5C5CU, pad1^0x5C5C5C5CU, 0x5C5C5C5CU, 0x5C5C5C5CU); |
||||
SHA256_fresh(&tstate0,&tstate1, pad0^0x36363636U, pad1^0x36363636U, 0x36363636U, 0x36363636U); |
||||
|
||||
tmp0 = tstate0; |
||||
tmp1 = tstate1; |
||||
SHA256(&tstate0, &tstate1, input[0],input[1],input[2],input[3]); |
||||
|
||||
#pragma unroll |
||||
for (uint i=0; i<4; i++) |
||||
{ |
||||
pad0 = tstate0; |
||||
pad1 = tstate1; |
||||
X[i*2 ] = ostate0; |
||||
X[i*2+1] = ostate1; |
||||
|
||||
SHA256(&pad0,&pad1, data, (uint4)(i+1,0x80000000U,0,0), (uint4)(0,0,0,0), (uint4)(0,0,0,0x4a0U)); |
||||
SHA256(X+i*2,X+i*2+1, pad0, pad1, (uint4)(0x80000000U, 0U, 0U, 0U), (uint4)(0U, 0U, 0U, 0x300U)); |
||||
} |
||||
scrypt_core(X,padcache); |
||||
SHA256(&tmp0,&tmp1, X[0], X[1], X[2], X[3]); |
||||
SHA256(&tmp0,&tmp1, X[4], X[5], X[6], X[7]); |
||||
SHA256_fixed(&tmp0,&tmp1); |
||||
SHA256(&ostate0,&ostate1, tmp0, tmp1, (uint4)(0x80000000U, 0U, 0U, 0U), (uint4)(0U, 0U, 0U, 0x300U)); |
||||
|
||||
bool found = (EndianSwap(ostate1.w) <= target); |
||||
if (found) |
||||
output[FOUND] = output[NFLAG & gid] = gid; |
||||
} |
||||
|
||||
/*- |
||||
* Copyright 2009 Colin Percival, 2011 ArtForz, 2011 pooler, 2012 mtrlt, |
||||
* 2012 Con Kolivas. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. 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 AUTHOR 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 AUTHOR 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. |
||||
* |
||||
* This file was originally written by Colin Percival as part of the Tarsnap |
||||
* online backup system. |
||||
*/ |
Loading…
Reference in new issue