Skip to content

Commit

Permalink
Added Dallar kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
Allar committed Jan 3, 2018
1 parent 41cb8b0 commit 7f85a0b
Show file tree
Hide file tree
Showing 11 changed files with 555 additions and 19 deletions.
2 changes: 2 additions & 0 deletions algorithm.c
Expand Up @@ -22,6 +22,7 @@
#include "algorithm/myriadcoin-groestl.h"
#include "algorithm/fuguecoin.h"
#include "algorithm/groestlcoin.h"
#include "algorithm/dallar.h"
#include "algorithm/twecoin.h"
#include "algorithm/marucoin.h"
#include "algorithm/maxcoin.h"
Expand Down Expand Up @@ -800,6 +801,7 @@ static algorithm_settings_t algos[] = {
{ a, ALGO_FUGUE, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, c, NULL }
A_FUGUE("fuguecoin", fuguecoin_regenhash, sha256),
A_FUGUE("groestlcoin", groestlcoin_regenhash, sha256),
A_FUGUE("dallar", dallar_regenhash, sha256),
A_FUGUE("diamond", groestlcoin_regenhash, gen_hash),
#undef A_FUGUE

Expand Down
155 changes: 155 additions & 0 deletions algorithm/dallar.c
@@ -0,0 +1,155 @@
/*-
* Copyright 2009 Colin Percival, 2014 phm
* 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_groestl.h"
#include "sph/sph_sha2.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]);
}


#ifdef __APPLE_CC__
static
#endif
inline void throestlhash(void *state, const void *input)
{
sph_groestl512_context ctx_groestl;

uint32_t hash[16];

sph_groestl512_init(&ctx_groestl);
sph_groestl512(&ctx_groestl, input, 80);
sph_groestl512_close(&ctx_groestl, (void*) hash);

sph_groestl512_init(&ctx_groestl);
sph_groestl512(&ctx_groestl, hash, 64);
sph_groestl512_close(&ctx_groestl, (void*) hash);

sph_groestl512_init(&ctx_groestl);
sph_groestl512(&ctx_groestl, hash, 64);
sph_groestl512_close(&ctx_groestl, (void*)hash);

memcpy(state, hash, 32);
}

static const uint32_t diff1targ = 0x0000ffff;


/* Used externally as confirmation of correct OCL code */
int dallar_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);
throestlhash(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 dallar_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);
throestlhash(ohash, data);
}

bool scanhash_dallar(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);
throestlhash(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;
}



10 changes: 10 additions & 0 deletions algorithm/dallar.h
@@ -0,0 +1,10 @@
#ifndef DALLAR_H
#define DALLAR_H

#include "miner.h"

extern int dallar_test(unsigned char *pdata, const unsigned char *ptarget,
uint32_t nonce);
extern void dallar_regenhash(struct work *work);

#endif /* DALLAR_H */

0 comments on commit 7f85a0b

Please sign in to comment.