]> Git Repo - cpuminer-multi.git/blob - ink.c
windows: fix build with mingw64
[cpuminer-multi.git] / ink.c
1 #include "cpuminer-config.h"
2 #include "miner.h"
3
4 #include <string.h>
5 #include <stdint.h>
6
7 #include "sha3/sph_shavite.h"
8
9 extern void inkhash(void *state, const void *input)
10 {
11     sph_shavite512_context       ctx_shavite;
12     uint32_t hash[16];
13         
14     sph_shavite512_init(&ctx_shavite);
15     sph_shavite512 (&ctx_shavite, (const void*) input, 80);
16     sph_shavite512_close(&ctx_shavite, (void*) hash);
17     
18     sph_shavite512_init(&ctx_shavite);
19     sph_shavite512(&ctx_shavite, (const void*) hash, 64);
20     sph_shavite512_close(&ctx_shavite, (void*) hash);
21
22     memcpy(state, hash, 32);
23
24 /*      
25         int ii;
26         printf("result: ");
27         for (ii=0; ii < 32; ii++)
28         {
29                 printf ("%.2x",((uint8_t*)state)[ii]);
30         };
31         printf ("\n");  
32 */      
33 }
34
35 int scanhash_ink(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
36         uint32_t max_nonce, uint64_t *hashes_done)
37 {
38         uint32_t n = pdata[19] - 1;
39         const uint32_t first_nonce = pdata[19];
40         //const uint32_t Htarg = ptarget[7];
41
42         uint32_t _ALIGN(32) hash64[8];
43         uint32_t endiandata[32];
44         
45         //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"};
46         
47         //we need bigendian data...
48         //lessons learned: do NOT endianchange directly in pdata, this will all proof-of-works be considered as stale from minerd.... 
49         int kk=0;
50         for (; kk < 32; kk++)
51         {
52                 be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
53         };
54
55 //      if (opt_debug) 
56 //      {
57 //              applog(LOG_DEBUG, "Thr: %02d, firstN: %08x, maxN: %08x, ToDo: %d", thr_id, first_nonce, max_nonce, max_nonce-first_nonce);
58 //      }
59         
60         /* I'm to lazy to put the loop in an inline function... so dirty copy'n'paste.... */
61         /* i know that i could set a variable, but i don't know how the compiler will optimize it, not that then the cpu needs to load the value *everytime* in a register */
62         if (ptarget[7]==0) {
63                 do {
64                         pdata[19] = ++n;
65                         be32enc(&endiandata[19], n); 
66                         inkhash(hash64, endiandata);
67                         if (((hash64[7]&0xFFFFFFFF)==0) && 
68                                         fulltest(hash64, ptarget)) {
69                                 *hashes_done = n - first_nonce + 1;
70                                 return true;
71                         }
72                 } while (n < max_nonce && !work_restart[thr_id].restart);       
73         } 
74         else if (ptarget[7]<=0xF) 
75         {
76                 do {
77                         pdata[19] = ++n;
78                         be32enc(&endiandata[19], n); 
79                         inkhash(hash64, endiandata);
80                         if (((hash64[7]&0xFFFFFFF0)==0) && 
81                                         fulltest(hash64, ptarget)) {
82                                 *hashes_done = n - first_nonce + 1;
83                                 return true;
84                         }
85                 } while (n < max_nonce && !work_restart[thr_id].restart);       
86         } 
87         else if (ptarget[7]<=0xFF) 
88         {
89                 do {
90                         pdata[19] = ++n;
91                         be32enc(&endiandata[19], n); 
92                         inkhash(hash64, endiandata);
93                         if (((hash64[7]&0xFFFFFF00)==0) && 
94                                         fulltest(hash64, ptarget)) {
95                                 *hashes_done = n - first_nonce + 1;
96                                 return true;
97                         }
98                 } while (n < max_nonce && !work_restart[thr_id].restart);       
99         } 
100         else if (ptarget[7]<=0xFFF) 
101         {
102                 do {
103                         pdata[19] = ++n;
104                         be32enc(&endiandata[19], n); 
105                         inkhash(hash64, endiandata);
106                         if (((hash64[7]&0xFFFFF000)==0) && 
107                                         fulltest(hash64, ptarget)) {
108                                 *hashes_done = n - first_nonce + 1;
109                                 return true;
110                         }
111                 } while (n < max_nonce && !work_restart[thr_id].restart);       
112
113         } 
114         else if (ptarget[7]<=0xFFFF) 
115         {
116                 do {
117                         pdata[19] = ++n;
118                         be32enc(&endiandata[19], n); 
119                         inkhash(hash64, endiandata);
120                         if (((hash64[7]&0xFFFF0000)==0) && 
121                                         fulltest(hash64, ptarget)) {
122                                 *hashes_done = n - first_nonce + 1;
123                                 return true;
124                         }
125                 } while (n < max_nonce && !work_restart[thr_id].restart);       
126
127         } 
128         else 
129         {
130                 do {
131                         pdata[19] = ++n;
132                         be32enc(&endiandata[19], n); 
133                         inkhash(hash64, endiandata);
134                         if (fulltest(hash64, ptarget)) {
135                                 *hashes_done = n - first_nonce + 1;
136                                 return true;
137                         }
138                 } while (n < max_nonce && !work_restart[thr_id].restart);       
139         }
140         
141         
142         *hashes_done = n - first_nonce + 1;
143         pdata[19] = n;
144         return 0;
145 }
This page took 0.034519 seconds and 4 git commands to generate.