]> Git Repo - cpuminer-multi.git/blame - algo/skein.c
update build.sh
[cpuminer-multi.git] / algo / skein.c
CommitLineData
e68cb6e4
LJ
1#include "miner.h"
2
3#include <string.h>
4#include <stdint.h>
5
6#include <openssl/sha.h>
7
8#include "sha3/sph_skein.h"
9
588f5d90 10void skeinhash(void *state, const void *input)
e68cb6e4 11{
d5b6dd52
TP
12 sph_skein512_context ctx_skein;
13 SHA256_CTX sha256;
e68cb6e4 14
d5b6dd52 15 uint32_t hash[16];
f7c584dc 16
d5b6dd52
TP
17 sph_skein512_init(&ctx_skein);
18 sph_skein512(&ctx_skein, input, 80);
19 sph_skein512_close(&ctx_skein, hash);
e68cb6e4 20
d5b6dd52
TP
21 SHA256_Init(&sha256);
22 SHA256_Update(&sha256, hash, 64);
23 SHA256_Final((unsigned char*) hash, &sha256);
e68cb6e4 24
d5b6dd52 25 memcpy(state, hash, 32);
e68cb6e4
LJ
26}
27
f7c584dc 28int scanhash_skein(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
e68cb6e4 29{
f7c584dc
TP
30 uint32_t _ALIGN(128) hash32[8];
31 uint32_t _ALIGN(128) endiandata[20];
32 uint32_t *pdata = work->data;
33 uint32_t *ptarget = work->target;
d5b6dd52
TP
34
35 const uint32_t Htarg = ptarget[7];
e68cb6e4 36 const uint32_t first_nonce = pdata[19];
e68cb6e4 37
d5b6dd52 38 uint32_t n = first_nonce;
f7c584dc 39
d5b6dd52
TP
40 for (int i=0; i < 19; i++) {
41 be32enc(&endiandata[i], pdata[i]);
e68cb6e4
LJ
42 };
43
44 do {
f7c584dc
TP
45 be32enc(&endiandata[19], n);
46 skeinhash(hash32, endiandata);
47 if (hash32[7] < Htarg && fulltest(hash32, ptarget)) {
48 work_set_target_ratio(work, hash32);
d5b6dd52
TP
49 *hashes_done = n - first_nonce + 1;
50 pdata[19] = n;
e68cb6e4
LJ
51 return true;
52 }
d5b6dd52
TP
53 n++;
54
e68cb6e4 55 } while (n < max_nonce && !work_restart[thr_id].restart);
d5b6dd52 56
e68cb6e4
LJ
57 *hashes_done = n - first_nonce + 1;
58 pdata[19] = n;
d5b6dd52 59
e68cb6e4 60 return 0;
df0c0adb 61}
This page took 0.038085 seconds and 4 git commands to generate.