Browse Source

Added WhirlpoolX algorithm

windows
troky 9 years ago
parent
commit
89c380a4ac
  1. 3
      AUTHORS.md
  2. 1
      Makefile.am
  3. 28
      algorithm.c
  4. 4
      algorithm/whirlcoin.h
  5. 172
      algorithm/whirlpoolx.c
  6. 9
      algorithm/whirlpoolx.h
  7. 1264
      kernel/whirlpoolx.cl
  8. 8
      winbuild/README.txt
  9. 4
      winbuild/sgminer.vcxproj
  10. 8
      winbuild/sgminer.vcxproj.filters

3
AUTHORS.md

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

1
Makefile.am

@ -68,6 +68,7 @@ sgminer_SOURCES += algorithm/x14.c algorithm/x14.h @@ -68,6 +68,7 @@ sgminer_SOURCES += algorithm/x14.c algorithm/x14.h
sgminer_SOURCES += algorithm/fresh.c algorithm/fresh.h
sgminer_SOURCES += algorithm/whirlcoin.c algorithm/whirlcoin.h
sgminer_SOURCES += algorithm/neoscrypt.c algorithm/neoscrypt.h
sgminer_SOURCES += algorithm/whirlpoolx.c algorithm/whirlpoolx.h
bin_SCRIPTS = $(top_srcdir)/kernel/*.cl

28
algorithm.c

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include "algorithm/fresh.h"
#include "algorithm/whirlcoin.h"
#include "algorithm/neoscrypt.h"
#include "algorithm/whirlpoolx.h"
#include "compat.h"
@ -52,7 +53,8 @@ const char *algorithm_type_str[] = { @@ -52,7 +53,8 @@ const char *algorithm_type_str[] = {
"NIST",
"Fresh",
"Whirlcoin",
"Neoscrypt"
"Neoscrypt",
"WhirlpoolX"
};
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_ @@ -630,6 +632,27 @@ static cl_int queue_whirlcoin_kernel(struct __clState *clState, struct _dev_blk_
return status;
}
static cl_int queue_whirlpoolx_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL,NULL);
//clbuffer, hashes
kernel = &clState->kernel;
CL_SET_ARG_N(0,clState->CLbuffer0);
CL_SET_ARG_N(1,clState->padbuffer8);
CL_SET_ARG_N(2,clState->outputBuffer);
CL_SET_ARG_N(3,le_target);
return status;
}
typedef struct _algorithm_settings_t {
const char *name; /* Human-readable identifier */
algorithm_type_t type; //common algorithm type
@ -715,6 +738,8 @@ static algorithm_settings_t algos[] = { @@ -715,6 +738,8 @@ static algorithm_settings_t algos[] = {
{ "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},
{ "whirlpoolx", ALGO_WHIRL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, 0, whirlpoolx_regenhash, queue_sph_kernel, gen_hash, NULL },
// Terminator (do not remove)
{ NULL, ALGO_UNK, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL}
};
@ -786,6 +811,7 @@ static const char *lookup_algorithm_alias(const char *lookup_alias, uint8_t *nfa @@ -786,6 +811,7 @@ static const char *lookup_algorithm_alias(const char *lookup_alias, uint8_t *nfa
ALGO_ALIAS("nist5", "talkcoin-mod");
ALGO_ALIAS("keccak", "maxcoin");
ALGO_ALIAS("whirlpool", "whirlcoin");
ALGO_ALIAS("whirlpoolx", "whirlpoolx");
#undef ALGO_ALIAS
#undef ALGO_ALIAS_NF

4
algorithm/whirlcoin.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
#ifndef W_H
#define W_H
#ifndef WHIRLCOIN_H
#define WHIRLCOIN_H
#include "miner.h"

172
algorithm/whirlpoolx.c

@ -0,0 +1,172 @@ @@ -0,0 +1,172 @@
/*-
* Copyright 2009 Colin Percival, 2011 ArtForz
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file was originally written by Colin Percival as part of the Tarsnap
* online backup system.
*/
#include "config.h"
#include "miner.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "sph/sph_whirlpool.h"
/*
* Encode a length len/4 vector of (uint32_t) into a length len vector of
* (unsigned char) in big-endian form. Assumes len is a multiple of 4.
*/
static inline void
be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len)
{
uint32_t i;
for (i = 0; i < len; i++)
dst[i] = htobe32(src[i]);
}
inline void whirlpoolx_hash(void *state, const void *input)
{
sph_whirlpool1_context ctx;
sph_whirlpool1_init(&ctx);
uint8_t digest[64];
sph_whirlpool(&ctx, input, 80);
sph_whirlpool_close(&ctx, digest);
((uint8_t *)state)[0] = digest[0] ^ digest[16];
((uint8_t *)state)[1] = digest[1] ^ digest[17];
((uint8_t *)state)[2] = digest[2] ^ digest[18];
((uint8_t *)state)[3] = digest[3] ^ digest[19];
((uint8_t *)state)[4] = digest[4] ^ digest[20];
((uint8_t *)state)[5] = digest[5] ^ digest[21];
((uint8_t *)state)[6] = digest[6] ^ digest[22];
((uint8_t *)state)[7] = digest[7] ^ digest[23];
((uint8_t *)state)[8] = digest[8] ^ digest[24];
((uint8_t *)state)[9] = digest[9] ^ digest[25];
((uint8_t *)state)[10] = digest[10] ^ digest[26];
((uint8_t *)state)[11] = digest[11] ^ digest[27];
((uint8_t *)state)[12] = digest[12] ^ digest[28];
((uint8_t *)state)[13] = digest[13] ^ digest[29];
((uint8_t *)state)[14] = digest[14] ^ digest[30];
((uint8_t *)state)[15] = digest[15] ^ digest[31];
((uint8_t *)state)[16] = digest[16] ^ digest[32];
((uint8_t *)state)[17] = digest[17] ^ digest[33];
((uint8_t *)state)[18] = digest[18] ^ digest[34];
((uint8_t *)state)[19] = digest[19] ^ digest[35];
((uint8_t *)state)[20] = digest[20] ^ digest[36];
((uint8_t *)state)[21] = digest[21] ^ digest[37];
((uint8_t *)state)[22] = digest[22] ^ digest[38];
((uint8_t *)state)[23] = digest[23] ^ digest[39];
((uint8_t *)state)[24] = digest[24] ^ digest[40];
((uint8_t *)state)[25] = digest[25] ^ digest[41];
((uint8_t *)state)[26] = digest[26] ^ digest[42];
((uint8_t *)state)[27] = digest[27] ^ digest[43];
((uint8_t *)state)[28] = digest[28] ^ digest[44];
((uint8_t *)state)[29] = digest[29] ^ digest[45];
((uint8_t *)state)[30] = digest[30] ^ digest[46];
((uint8_t *)state)[31] = digest[31] ^ digest[47];
}
static const uint32_t diff1targ = 0x0000ffff;
/* Used externally as confirmation of correct OCL code */
int whirlpoolx_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
{
uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]);
uint32_t data[20], ohash[8];
be32enc_vect(data, (const uint32_t *)pdata, 19);
data[19] = htobe32(nonce);
whirlpoolx_hash(ohash, data);
tmp_hash7 = be32toh(ohash[7]);
applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx",
(long unsigned int)Htarg,
(long unsigned int)diff1targ,
(long unsigned int)tmp_hash7);
if (tmp_hash7 > diff1targ)
return -1;
if (tmp_hash7 > Htarg)
return 0;
return 1;
}
void whirlpoolx_regenhash(struct work *work)
{
uint32_t data[20];
uint32_t *nonce = (uint32_t *)(work->data + 76);
uint32_t *ohash = (uint32_t *)(work->hash);
be32enc_vect(data, (const uint32_t *)work->data, 19);
data[19] = htobe32(*nonce);
whirlpoolx_hash(ohash, data);
}
bool scanhash_whirlpoolx(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
unsigned char *pdata, unsigned char __maybe_unused *phash1,
unsigned char __maybe_unused *phash, const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
{
uint32_t *nonce = (uint32_t *)(pdata + 76);
uint32_t data[20];
uint32_t tmp_hash7;
uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
bool ret = false;
be32enc_vect(data, (const uint32_t *)pdata, 19);
while(1) {
uint32_t ostate[8];
*nonce = ++n;
data[19] = (n);
whirlpoolx_hash(ostate, data);
tmp_hash7 = (ostate[7]);
applog(LOG_INFO, "data7 %08lx",
(long unsigned int)data[7]);
if (unlikely(tmp_hash7 <= Htarg)) {
((uint32_t *)pdata)[19] = htobe32(n);
*last_nonce = n;
ret = true;
break;
}
if (unlikely((n >= max_nonce) || thr->work_restart)) {
*last_nonce = n;
break;
}
}
return ret;
}

9
algorithm/whirlpoolx.h

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
#ifndef WHIRLPOOLX_H
#define WHIRLPOOLX_H
#include "miner.h"
extern int whirlpoolx_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce);
extern void whirlpoolx_regenhash(struct work *work);
#endif /* W_H */

1264
kernel/whirlpoolx.cl

File diff suppressed because it is too large Load Diff

8
winbuild/README.txt

@ -74,15 +74,15 @@ x86 version: @@ -74,15 +74,15 @@ x86 version:
- open Visual Studio Command Prompt (x86)
- go to winbuild folder and execute:
nmake -f Makefile.vc mode=static VC=13 WITH_DEVEL=C:\OpenSSL-Win32 WITH_SSL=static ENABLE_SSPI=no ENABLE_IPV6=no ENABLE_IDN=no GEN_PDB=no DEBUG=no MACHINE=x86
- copy builds\libcurl-vc10-x86-release-static-ssl-static-spnego\lib\libcurl_a.lib to winbuild\dist\lib\x86
- copy builds \libcurl-vc10-x86-release-static-ssl-static-spnego\include\* winbuild\dist\include\
- copy builds\libcurl-vc13-x86-release-static-ssl-static-spnego\lib\libcurl_a.lib to winbuild\dist\lib\x86
- copy builds \libcurl-vc13-x86-release-static-ssl-static-spnego\include\* winbuild\dist\include\
x64 version:
- open Visual Studio Command Prompt (x64)
- go to winbuild folder and execute:
nmake -f Makefile.vc mode=static VC=13 WITH_DEVEL=C:\OpenSSL-Win64 WITH_SSL=static ENABLE_SSPI=no ENABLE_IPV6=no ENABLE_IDN=no GEN_PDB=no DEBUG=no MACHINE=x64
- copy builds\libcurl-vc10-x64-release-static-ssl-static-spnego\lib\libcurl_a.lib to winbuild\dist\lib\x64
- copy builds\libcurl-vc10-x64-release-static-ssl-static-spnego\include\* winbuild\dist\include\
- copy builds\libcurl-vc13-x64-release-static-ssl-static-spnego\lib\libcurl_a.lib to winbuild\dist\lib\x64
- copy builds\libcurl-vc13-x64-release-static-ssl-static-spnego\include\* winbuild\dist\include\
5. Jansson
----------

4
winbuild/sgminer.vcxproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@ -265,6 +265,7 @@ @@ -265,6 +265,7 @@
<ClCompile Include="..\algorithm\bitblock.c" />
<ClCompile Include="..\algorithm\neoscrypt.c" />
<ClCompile Include="..\algorithm\talkcoin.c" />
<ClCompile Include="..\algorithm\whirlpoolx.c" />
<ClCompile Include="..\algorithm\x14.c" />
<ClCompile Include="..\algorithm\fresh.c" />
<ClCompile Include="..\algorithm\whirlcoin.c" />
@ -326,6 +327,7 @@ @@ -326,6 +327,7 @@
<ClInclude Include="..\algorithm\bitblock.h" />
<ClInclude Include="..\algorithm\neoscrypt.h" />
<ClInclude Include="..\algorithm\talkcoin.h" />
<ClInclude Include="..\algorithm\whirlpoolx.h" />
<ClInclude Include="..\algorithm\x14.h" />
<ClInclude Include="..\algorithm\fresh.h" />
<ClInclude Include="..\algorithm\whirlcoin.h" />

8
winbuild/sgminer.vcxproj.filters

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
@ -206,6 +206,9 @@ @@ -206,6 +206,9 @@
<ClCompile Include="..\events.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\algorithm\whirlpoolx.c">
<Filter>Source Files\algorithm</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\adl.h">
@ -391,6 +394,9 @@ @@ -391,6 +394,9 @@
<ClInclude Include="..\events.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\algorithm\whirlpoolx.h">
<Filter>Header Files\algorithm</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="README.txt" />

Loading…
Cancel
Save