]> Git Repo - cpuminer-multi.git/blame - skein.c
Add a configure option to disable assembly code
[cpuminer-multi.git] / skein.c
CommitLineData
e68cb6e4
LJ
1#include "cpuminer-config.h"
2#include "miner.h"
3
4#include <string.h>
5#include <stdint.h>
6
7#include <openssl/sha.h>
8
9#include "sha3/sph_skein.h"
10
11static void skeinhash(void *state, const void *input)
12{
13 sph_skein512_context ctx_skein;
14 static unsigned char pblank[1];
15
16 uint32_t mask = 8;
17 uint32_t zero = 0;
18
19 //these uint512 in the c++ source of the client are backed by an array of uint32
20 uint32_t hashA[16], hashB[16];
21
22 sph_skein512_init(&ctx_skein);
23 sph_skein512 (&ctx_skein, input, 80); //6
24 sph_skein512_close(&ctx_skein, hashA); //7
25
26 SHA256_CTX sha256;
27 SHA256_Init(&sha256);
28 SHA256_Update(&sha256, hashA, 64);
c159bef2 29 SHA256_Final((unsigned char*) hashB, &sha256);
e68cb6e4
LJ
30
31 memcpy(state, hashB, 32);
32
33
34/* int ii;
35 printf("result: ");
36 for (ii=0; ii < 32; ii++)
37 {
38 printf ("%.2x",((uint8_t*)state)[ii]);
39 };
40 printf ("\n");
41*/
42}
43
44int scanhash_skein(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
45 uint32_t max_nonce, unsigned long *hashes_done)
46{
47 uint32_t n = pdata[19] - 1;
48 const uint32_t first_nonce = pdata[19];
49 const uint32_t Htarg = ptarget[7];
50
51 uint32_t hash64[8] __attribute__((aligned(32)));
52 uint32_t endiandata[32];
53
54 //char testdata[] = {"\x70\x00\x00\x00\x5d\x38\x5b\xa1\x14\xd0\x79\x97\x0b\x29\xa9\x41\x8f\xd0\x54\x9e\x7d\x68\xa9\x5c\x7f\x16\x86\x21\xa3\x14\x20\x10\x00\x00\x00\x00\x57\x85\x86\xd1\x49\xfd\x07\xb2\x2f\x3a\x8a\x34\x7c\x51\x6d\xe7\x05\x2f\x03\x4d\x2b\x76\xff\x68\xe0\xd6\xec\xff\x9b\x77\xa4\x54\x89\xe3\xfd\x51\x17\x32\x01\x1d\xf0\x73\x10\x00"};
55
56 //we need bigendian data...
57 //lessons learned: do NOT endianchange directly in pdata, this will all proof-of-works be considered as stale from minerd....
58 int kk=0;
59 for (; kk < 32; kk++)
60 {
61 be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
62 };
63
64 do {
e68cb6e4
LJ
65 pdata[19] = ++n;
66 be32enc(&endiandata[19], n);
67 skeinhash(hash64, &endiandata);
68 if (((hash64[7]&0xFFFFFF00)==0) &&
69 fulltest(hash64, ptarget)) {
70 *hashes_done = n - first_nonce + 1;
71 return true;
72 }
73 } while (n < max_nonce && !work_restart[thr_id].restart);
74
75 *hashes_done = n - first_nonce + 1;
76 pdata[19] = n;
77 return 0;
78}
This page took 0.030194 seconds and 4 git commands to generate.