Skip to content

Commit 89c380a

Browse files
committed
Added WhirlpoolX algorithm
1 parent f27f8dd commit 89c380a

10 files changed

+1491
-10
lines changed

AUTHORS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
* Jan Berdajs <mrbrdo at mrbrdo dot net> 15bULC8snaKAMeFb3xBmmhbWj1xyTmBUfm
66
* Noel Maersk <veox at wemakethings dot net> 12jF1VExtmmMu8D36vo4Y4CYqLK5yCtLC4
7-
* troky <troky2001 at yahoo dot com> 15hMFjU8xQhiFzQ19JSaX2y7SV2GAoTuXs
7+
* troky <troky2001 at yahoo dot com> 1DqHeJdVy4kQX1jHaaVxef9Bgii14pwEbg
88
* Yann St.Arnaud <ystarnaud at gmail dot com> 1SLixz2vRvjdpzZTep4Tiqs82Jc28tc6J
99
* lasybear <**FIXME**>
1010
* Luke Dashjr <luke-jr+cgminer @at@ utopios .dot. org> 1QATWksNFGeUJCWBrN4g6hGM178Lovm7Wh
@@ -52,6 +52,7 @@ updated by many others.
5252
* tonobitc <tonobitc>
5353
* Perry Huang <perryh>
5454
* Joseph Bruggeman <jbruggeman>
55+
* Badman74 <badman74>
5556

5657
...and many others. See:
5758

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ sgminer_SOURCES += algorithm/x14.c algorithm/x14.h
6868
sgminer_SOURCES += algorithm/fresh.c algorithm/fresh.h
6969
sgminer_SOURCES += algorithm/whirlcoin.c algorithm/whirlcoin.h
7070
sgminer_SOURCES += algorithm/neoscrypt.c algorithm/neoscrypt.h
71+
sgminer_SOURCES += algorithm/whirlpoolx.c algorithm/whirlpoolx.h
7172

7273
bin_SCRIPTS = $(top_srcdir)/kernel/*.cl
7374

algorithm.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "algorithm/fresh.h"
3232
#include "algorithm/whirlcoin.h"
3333
#include "algorithm/neoscrypt.h"
34+
#include "algorithm/whirlpoolx.h"
3435

3536
#include "compat.h"
3637

@@ -52,7 +53,8 @@ const char *algorithm_type_str[] = {
5253
"NIST",
5354
"Fresh",
5455
"Whirlcoin",
55-
"Neoscrypt"
56+
"Neoscrypt",
57+
"WhirlpoolX"
5658
};
5759

5860
void sha256(const unsigned char *message, unsigned int len, unsigned char *digest)
@@ -630,6 +632,27 @@ static cl_int queue_whirlcoin_kernel(struct __clState *clState, struct _dev_blk_
630632
return status;
631633
}
632634

635+
static cl_int queue_whirlpoolx_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
636+
{
637+
cl_kernel *kernel;
638+
cl_ulong le_target;
639+
cl_int status = 0;
640+
641+
le_target = *(cl_ulong *)(blk->work->device_target + 24);
642+
flip80(clState->cldata, blk->work->data);
643+
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL,NULL);
644+
645+
//clbuffer, hashes
646+
kernel = &clState->kernel;
647+
CL_SET_ARG_N(0,clState->CLbuffer0);
648+
CL_SET_ARG_N(1,clState->padbuffer8);
649+
650+
CL_SET_ARG_N(2,clState->outputBuffer);
651+
CL_SET_ARG_N(3,le_target);
652+
653+
return status;
654+
}
655+
633656
typedef struct _algorithm_settings_t {
634657
const char *name; /* Human-readable identifier */
635658
algorithm_type_t type; //common algorithm type
@@ -715,6 +738,8 @@ static algorithm_settings_t algos[] = {
715738

716739
{ "whirlcoin", ALGO_WHIRL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 3, 8 * 16 * 4194304, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, whirlcoin_regenhash, queue_whirlcoin_kernel, sha256, NULL},
717740

741+
{ "whirlpoolx", ALGO_WHIRL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, 0, whirlpoolx_regenhash, queue_sph_kernel, gen_hash, NULL },
742+
718743
// Terminator (do not remove)
719744
{ NULL, ALGO_UNK, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL}
720745
};
@@ -786,6 +811,7 @@ static const char *lookup_algorithm_alias(const char *lookup_alias, uint8_t *nfa
786811
ALGO_ALIAS("nist5", "talkcoin-mod");
787812
ALGO_ALIAS("keccak", "maxcoin");
788813
ALGO_ALIAS("whirlpool", "whirlcoin");
814+
ALGO_ALIAS("whirlpoolx", "whirlpoolx");
789815

790816
#undef ALGO_ALIAS
791817
#undef ALGO_ALIAS_NF

algorithm/whirlcoin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef W_H
2-
#define W_H
1+
#ifndef WHIRLCOIN_H
2+
#define WHIRLCOIN_H
33

44
#include "miner.h"
55

algorithm/whirlpoolx.c

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*-
2+
* Copyright 2009 Colin Percival, 2011 ArtForz
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24+
* SUCH DAMAGE.
25+
*
26+
* This file was originally written by Colin Percival as part of the Tarsnap
27+
* online backup system.
28+
*/
29+
30+
#include "config.h"
31+
#include "miner.h"
32+
33+
#include <stdlib.h>
34+
#include <stdint.h>
35+
#include <string.h>
36+
37+
#include "sph/sph_whirlpool.h"
38+
39+
/*
40+
* Encode a length len/4 vector of (uint32_t) into a length len vector of
41+
* (unsigned char) in big-endian form. Assumes len is a multiple of 4.
42+
*/
43+
static inline void
44+
be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len)
45+
{
46+
uint32_t i;
47+
48+
for (i = 0; i < len; i++)
49+
dst[i] = htobe32(src[i]);
50+
}
51+
52+
inline void whirlpoolx_hash(void *state, const void *input)
53+
{
54+
sph_whirlpool1_context ctx;
55+
56+
sph_whirlpool1_init(&ctx);
57+
58+
uint8_t digest[64];
59+
60+
sph_whirlpool(&ctx, input, 80);
61+
sph_whirlpool_close(&ctx, digest);
62+
63+
((uint8_t *)state)[0] = digest[0] ^ digest[16];
64+
((uint8_t *)state)[1] = digest[1] ^ digest[17];
65+
((uint8_t *)state)[2] = digest[2] ^ digest[18];
66+
((uint8_t *)state)[3] = digest[3] ^ digest[19];
67+
((uint8_t *)state)[4] = digest[4] ^ digest[20];
68+
((uint8_t *)state)[5] = digest[5] ^ digest[21];
69+
((uint8_t *)state)[6] = digest[6] ^ digest[22];
70+
((uint8_t *)state)[7] = digest[7] ^ digest[23];
71+
((uint8_t *)state)[8] = digest[8] ^ digest[24];
72+
((uint8_t *)state)[9] = digest[9] ^ digest[25];
73+
((uint8_t *)state)[10] = digest[10] ^ digest[26];
74+
((uint8_t *)state)[11] = digest[11] ^ digest[27];
75+
((uint8_t *)state)[12] = digest[12] ^ digest[28];
76+
((uint8_t *)state)[13] = digest[13] ^ digest[29];
77+
((uint8_t *)state)[14] = digest[14] ^ digest[30];
78+
((uint8_t *)state)[15] = digest[15] ^ digest[31];
79+
((uint8_t *)state)[16] = digest[16] ^ digest[32];
80+
((uint8_t *)state)[17] = digest[17] ^ digest[33];
81+
((uint8_t *)state)[18] = digest[18] ^ digest[34];
82+
((uint8_t *)state)[19] = digest[19] ^ digest[35];
83+
((uint8_t *)state)[20] = digest[20] ^ digest[36];
84+
((uint8_t *)state)[21] = digest[21] ^ digest[37];
85+
((uint8_t *)state)[22] = digest[22] ^ digest[38];
86+
((uint8_t *)state)[23] = digest[23] ^ digest[39];
87+
((uint8_t *)state)[24] = digest[24] ^ digest[40];
88+
((uint8_t *)state)[25] = digest[25] ^ digest[41];
89+
((uint8_t *)state)[26] = digest[26] ^ digest[42];
90+
((uint8_t *)state)[27] = digest[27] ^ digest[43];
91+
((uint8_t *)state)[28] = digest[28] ^ digest[44];
92+
((uint8_t *)state)[29] = digest[29] ^ digest[45];
93+
((uint8_t *)state)[30] = digest[30] ^ digest[46];
94+
((uint8_t *)state)[31] = digest[31] ^ digest[47];
95+
}
96+
97+
static const uint32_t diff1targ = 0x0000ffff;
98+
99+
100+
/* Used externally as confirmation of correct OCL code */
101+
int whirlpoolx_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
102+
{
103+
uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]);
104+
uint32_t data[20], ohash[8];
105+
106+
be32enc_vect(data, (const uint32_t *)pdata, 19);
107+
data[19] = htobe32(nonce);
108+
109+
whirlpoolx_hash(ohash, data);
110+
tmp_hash7 = be32toh(ohash[7]);
111+
112+
applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx",
113+
(long unsigned int)Htarg,
114+
(long unsigned int)diff1targ,
115+
(long unsigned int)tmp_hash7);
116+
if (tmp_hash7 > diff1targ)
117+
return -1;
118+
if (tmp_hash7 > Htarg)
119+
return 0;
120+
return 1;
121+
}
122+
123+
void whirlpoolx_regenhash(struct work *work)
124+
{
125+
uint32_t data[20];
126+
uint32_t *nonce = (uint32_t *)(work->data + 76);
127+
uint32_t *ohash = (uint32_t *)(work->hash);
128+
129+
be32enc_vect(data, (const uint32_t *)work->data, 19);
130+
data[19] = htobe32(*nonce);
131+
whirlpoolx_hash(ohash, data);
132+
}
133+
134+
bool scanhash_whirlpoolx(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
135+
unsigned char *pdata, unsigned char __maybe_unused *phash1,
136+
unsigned char __maybe_unused *phash, const unsigned char *ptarget,
137+
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
138+
{
139+
uint32_t *nonce = (uint32_t *)(pdata + 76);
140+
uint32_t data[20];
141+
uint32_t tmp_hash7;
142+
uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
143+
bool ret = false;
144+
145+
be32enc_vect(data, (const uint32_t *)pdata, 19);
146+
147+
while(1) {
148+
uint32_t ostate[8];
149+
150+
*nonce = ++n;
151+
data[19] = (n);
152+
whirlpoolx_hash(ostate, data);
153+
tmp_hash7 = (ostate[7]);
154+
155+
applog(LOG_INFO, "data7 %08lx",
156+
(long unsigned int)data[7]);
157+
158+
if (unlikely(tmp_hash7 <= Htarg)) {
159+
((uint32_t *)pdata)[19] = htobe32(n);
160+
*last_nonce = n;
161+
ret = true;
162+
break;
163+
}
164+
165+
if (unlikely((n >= max_nonce) || thr->work_restart)) {
166+
*last_nonce = n;
167+
break;
168+
}
169+
}
170+
171+
return ret;
172+
}

algorithm/whirlpoolx.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef WHIRLPOOLX_H
2+
#define WHIRLPOOLX_H
3+
4+
#include "miner.h"
5+
6+
extern int whirlpoolx_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce);
7+
extern void whirlpoolx_regenhash(struct work *work);
8+
9+
#endif /* W_H */

0 commit comments

Comments
 (0)