Browse Source

keccak: Adapt for BFGMiner

Luke Dashjr 11 years ago
parent
commit
cba871e59e
5 changed files with 44 additions and 14 deletions
  1. 4 0
      Makefile.am
  2. 1 0
      README
  3. 1 0
      configure.ac
  4. 35 14
      malgo/keccak.c
  5. 3 0
      miner.h

+ 4 - 0
Makefile.am

@@ -148,6 +148,10 @@ endif
 endif
 endif
 
 
 
 
+if USE_KECCAK
+bfgminer_SOURCES += malgo/keccak.c
+endif
+
 if USE_SHA256D
 if USE_SHA256D
 bfgminer_SOURCES += malgo/sha256d.c
 bfgminer_SOURCES += malgo/sha256d.c
 
 

+ 1 - 0
README

@@ -182,6 +182,7 @@ BFGMiner driver configuration options:
 	--disable-ztex          Compile support for ZTEX (default enabled)
 	--disable-ztex          Compile support for ZTEX (default enabled)
 
 
 BFGMiner algorithm configuration option:
 BFGMiner algorithm configuration option:
+	--enable-keccak         Compile support for Keccak (default disabled)
 	--disable-sha256d       Compile support for SHA256d (default enabled)
 	--disable-sha256d       Compile support for SHA256d (default enabled)
 	--enable-scrypt         Compile support for scrypt (default disabled)
 	--enable-scrypt         Compile support for scrypt (default disabled)
 
 

+ 1 - 0
configure.ac

@@ -361,6 +361,7 @@ AM_CONDITIONAL([USE_UDEVRULES_GROUP], [$use_udevrules_group])
 AC_SUBST([UDEVRULES_GROUP], [$udevrules_group])
 AC_SUBST([UDEVRULES_GROUP], [$udevrules_group])
 
 
 
 
+BFG_ALGO(Keccak,no)
 BFG_ALGO(SHA256d,yes)
 BFG_ALGO(SHA256d,yes)
 BFG_ALGO(scrypt,no)
 BFG_ALGO(scrypt,no)
 
 

+ 35 - 14
malgo/keccak.c

@@ -1,3 +1,14 @@
+/*
+ * Copyright 2013-2014 Ronny Van Keer (released as CC0)
+ * Copyright 2014 Luke Mitchell
+ * Copyright 2014 Luke Dashjr
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.  See COPYING for more details.
+ */
+
 #include "config.h"
 #include "config.h"
 #include "miner.h"
 #include "miner.h"
 
 
@@ -7,8 +18,7 @@
 
 
 #include <stdio.h>
 #include <stdio.h>
 
 
-#define CL_SET_BLKARG(blkvar) status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->blkvar)
-#define CL_SET_ARG(var) status |= clSetKernelArg(*kernel, num++, sizeof(var), (void *)&var)
+#include <uthash.h>
 
 
 struct uint256 {
 struct uint256 {
 	unsigned char v[32];
 	unsigned char v[32];
@@ -53,6 +63,7 @@ struct bin32 {
 	UINT64 v3;
 	UINT64 v3;
 };
 };
 
 
+static
 void keccak1(unsigned char *out, const unsigned char *inraw, unsigned inrawlen)
 void keccak1(unsigned char *out, const unsigned char *inraw, unsigned inrawlen)
 {
 {
 	unsigned char temp[136];
 	unsigned char temp[136];
@@ -305,24 +316,34 @@ void keccak1(unsigned char *out, const unsigned char *inraw, unsigned inrawlen)
 	}
 	}
 }
 }
 
 
-void keccak_regenhash(struct work *work)
+static
+void keccak_hash_data(void * const digest, const void * const pdata)
 {
 {
 	uint256 result;
 	uint256 result;
 	
 	
-	unsigned int data[20], datacopy[20]; // aligned for flip80
-	memcpy(datacopy, work->data, 80);
-	flip80(data, datacopy); 
+	unsigned int data[20], datacopy[20]; // aligned for swap32yes
+	memcpy(datacopy, pdata, 80);
+	swap32yes(data, datacopy, 20);
 	keccak1((unsigned char*)&result, (unsigned char*)data, 80);
 	keccak1((unsigned char*)&result, (unsigned char*)data, 80);
 	
 	
-	memcpy(work->hash, &result, 32);
+	memcpy(digest, &result, 0x20);
 }
 }
 
 
-bool keccak_prepare_work(struct thr_info __maybe_unused *thr, struct work *work)
+static struct mining_algorithm malgo_keccak = {
+	.name = "Keccak",
+	.aliases = "Keccak",
+	
+	.algo = POW_KECCAK,
+	.ui_skip_hash_bytes = 4,
+	.worktime_skip_prevblk_u32 = 1,
+	.reasonable_low_nonce_diff = 1.,
+	
+	.hash_data_f = keccak_hash_data,
+};
+
+static
+__attribute__((constructor))
+void init_keccak(void)
 {
 {
-	unsigned int src[20], dst[20]; // aligned for flip80
-	int i;
-	memcpy(src, work->data, 80);
-	flip80(dst, src);
-	memcpy(work->blk.keccak_data, dst, 80);
-	return true;
+    LL_APPEND(mining_algorithms, (&malgo_keccak));
 }
 }

+ 3 - 0
miner.h

@@ -277,6 +277,9 @@ struct gpu_adl {
 #endif
 #endif
 
 
 enum pow_algorithm {
 enum pow_algorithm {
+#ifdef USE_KECCAK
+	POW_KECCAK,
+#endif
 #ifdef USE_SHA256D
 #ifdef USE_SHA256D
 	POW_SHA256D,
 	POW_SHA256D,
 #endif
 #endif