]> Git Repo - cpuminer-multi.git/blame - algo/nist5.c
cryptonight: handle rpc 2.0 pools and clean the crypto-rpc-code
[cpuminer-multi.git] / algo / nist5.c
CommitLineData
9f3083cd
TP
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#include "sha3/sph_groestl.h"
10#include "sha3/sph_skein.h"
11#include "sha3/sph_jh.h"
12#include "sha3/sph_keccak.h"
13
14void nist5hash(void *output, const void *input)
15{
16 sph_blake512_context ctx_blake;
17 sph_groestl512_context ctx_groestl;
18 sph_jh512_context ctx_jh;
19 sph_keccak512_context ctx_keccak;
20 sph_skein512_context ctx_skein;
21
22 uint8_t hash[64];
23
24 sph_blake512_init(&ctx_blake);
25 sph_blake512(&ctx_blake, input, 80);
26 sph_blake512_close(&ctx_blake, (void*) hash);
27
28 sph_groestl512_init(&ctx_groestl);
29 sph_groestl512(&ctx_groestl, (const void*) hash, 64);
30 sph_groestl512_close(&ctx_groestl, (void*) hash);
31
32 sph_jh512_init(&ctx_jh);
33 sph_jh512(&ctx_jh, (const void*) hash, 64);
34 sph_jh512_close(&ctx_jh, (void*) hash);
35
36 sph_keccak512_init(&ctx_keccak);
37 sph_keccak512(&ctx_keccak, (const void*) hash, 64);
38 sph_keccak512_close(&ctx_keccak, (void*) hash);
39
40 sph_skein512_init(&ctx_skein);
41 sph_skein512(&ctx_skein, (const void*) hash, 64);
42 sph_skein512_close(&ctx_skein, (void*) hash);
43
44 memcpy(output, hash, 32);
45}
46
47int scanhash_nist5(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
48 uint32_t max_nonce, uint64_t *hashes_done)
49{
50 uint32_t n = pdata[19] - 1;
51 const uint32_t first_nonce = pdata[19];
52 const uint32_t Htarg = ptarget[7];
53
54 uint32_t _ALIGN(32) hash64[8];
55 uint32_t endiandata[32];
56
57
58 uint64_t htmax[] = {
59 0,
60 0xF,
61 0xFF,
62 0xFFF,
63 0xFFFF,
64 0x10000000
65 };
66 uint32_t masks[] = {
67 0xFFFFFFFF,
68 0xFFFFFFF0,
69 0xFFFFFF00,
70 0xFFFFF000,
71 0xFFFF0000,
72 0
73 };
74
75 // we need bigendian data...
76 for (int kk=0; kk < 32; kk++) {
77 be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
78 };
79#ifdef DEBUG_ALGO
80 printf("[%d] Htarg=%X\n", thr_id, Htarg);
81#endif
82 for (int m=0; m < 6; m++) {
83 if (Htarg <= htmax[m]) {
84 uint32_t mask = masks[m];
85 do {
86 pdata[19] = ++n;
87 be32enc(&endiandata[19], n);
88 nist5hash(hash64, endiandata);
89#ifndef DEBUG_ALGO
90 if ((!(hash64[7] & mask)) && fulltest(hash64, ptarget)) {
91 *hashes_done = n - first_nonce + 1;
92 return true;
93 }
94#else
95 if (!(n % 0x1000) && !thr_id) printf(".");
96 if (!(hash64[7] & mask)) {
97 printf("[%d]",thr_id);
98 if (fulltest(hash64, ptarget)) {
99 *hashes_done = n - first_nonce + 1;
100 return true;
101 }
102 }
103#endif
104 } while (n < max_nonce && !work_restart[thr_id].restart);
105 // see blake.c if else to understand the loop on htmax => mask
106 break;
107 }
108 }
109
110 *hashes_done = n - first_nonce + 1;
111 pdata[19] = n;
112 return 0;
113}
This page took 0.031724 seconds and 4 git commands to generate.