Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/pentablake.c
1201 views
1
#include "miner.h"
2
3
#include <stdlib.h>
4
#include <stdint.h>
5
#include <string.h>
6
#include <stdio.h>
7
8
#include "sha3/sph_blake.h"
9
10
//#define DEBUG_ALGO
11
12
extern void pentablakehash(void *output, const void *input)
13
{
14
unsigned char _ALIGN(32) hash[128];
15
// same as uint32_t hashA[16], hashB[16];
16
#define hashB hash+64
17
18
sph_blake512_context ctx_blake;
19
20
sph_blake512_init(&ctx_blake);
21
sph_blake512(&ctx_blake, input, 80);
22
sph_blake512_close(&ctx_blake, hash);
23
24
sph_blake512(&ctx_blake, hash, 64);
25
sph_blake512_close(&ctx_blake, hashB);
26
27
sph_blake512(&ctx_blake, hashB, 64);
28
sph_blake512_close(&ctx_blake, hash);
29
30
sph_blake512(&ctx_blake, hash, 64);
31
sph_blake512_close(&ctx_blake, hashB);
32
33
sph_blake512(&ctx_blake, hashB, 64);
34
sph_blake512_close(&ctx_blake, hash);
35
36
memcpy(output, hash, 32);
37
}
38
39
int scanhash_pentablake(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
40
{
41
uint32_t _ALIGN(128) hash32[8];
42
uint32_t _ALIGN(128) endiandata[20];
43
uint32_t *pdata = work->data;
44
uint32_t *ptarget = work->target;
45
46
uint32_t n = pdata[19] - 1;
47
const uint32_t first_nonce = pdata[19];
48
const uint32_t Htarg = ptarget[7];
49
50
uint64_t htmax[] = {
51
0,
52
0xF,
53
0xFF,
54
0xFFF,
55
0xFFFF,
56
0x10000000
57
};
58
uint32_t masks[] = {
59
0xFFFFFFFF,
60
0xFFFFFFF0,
61
0xFFFFFF00,
62
0xFFFFF000,
63
0xFFFF0000,
64
0
65
};
66
67
// we need bigendian data...
68
for (int i=0; i < 19; i++) {
69
be32enc(&endiandata[i], pdata[i]);
70
}
71
72
#ifdef DEBUG_ALGO
73
if (Htarg != 0)
74
printf("[%d] Htarg=%X\n", thr_id, Htarg);
75
#endif
76
for (int m=0; m < 6; m++) {
77
if (Htarg <= htmax[m]) {
78
uint32_t mask = masks[m];
79
do {
80
pdata[19] = ++n;
81
be32enc(&endiandata[19], n);
82
pentablakehash(hash32, endiandata);
83
#ifndef DEBUG_ALGO
84
if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) {
85
work_set_target_ratio(work, hash32);
86
*hashes_done = n - first_nonce + 1;
87
return 1;
88
}
89
#else
90
if (!(n % 0x1000) && !thr_id) printf(".");
91
if (!(hash32[7] & mask)) {
92
printf("[%d]",thr_id);
93
if (fulltest(hash32, ptarget)) {
94
work_set_target_ratio(work, hash32);
95
*hashes_done = n - first_nonce + 1;
96
return 1;
97
}
98
}
99
#endif
100
} while (n < max_nonce && !work_restart[thr_id].restart);
101
// see blake.c if else to understand the loop on htmax => mask
102
break;
103
}
104
}
105
106
*hashes_done = n - first_nonce + 1;
107
pdata[19] = n;
108
return 0;
109
}
110
111