aboutsummaryrefslogtreecommitdiff
path: root/cpu-miner.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2010-11-27 04:31:32 -0500
committerJeff Garzik <jgarzik@redhat.com>2010-11-27 04:31:32 -0500
commit339ddf4d757e17687d18d59e8ded57a71f186121 (patch)
tree8bdcd2f8bfee2b5ffdd8ee5c5cb2cd7fa93967b8 /cpu-miner.c
parentad3fda8aba5f3f1f4820a20a925c6387347876f9 (diff)
Move sha256_generic into its own .o build output. Const-ify midstate param.
Diffstat (limited to 'cpu-miner.c')
-rw-r--r--cpu-miner.c58
1 files changed, 2 insertions, 56 deletions
diff --git a/cpu-miner.c b/cpu-miner.c
index 8243718..05766e9 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -119,8 +119,6 @@ struct work {
unsigned char hash[32];
};
-#include "sha256_generic.c"
-
static bool jobj_binary(const json_t *obj, const char *key,
void *buf, size_t buflen)
{
@@ -231,58 +229,6 @@ static void hashmeter(int thr_id, struct timeval *tv_start,
khashes / secs);
}
-static void runhash(void *state, void *input, const void *init)
-{
- memcpy(state, init, 32);
- sha256_transform(state, input);
-}
-
-const uint32_t sha256_init_state[8] = {
- 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
- 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
-};
-
-/* suspiciously similar to ScanHash* from bitcoin */
-static bool scanhash(unsigned char *midstate, unsigned char *data,
- unsigned char *hash1, unsigned char *hash,
- unsigned long *hashes_done)
-{
- uint32_t *hash32 = (uint32_t *) hash;
- uint32_t *nonce = (uint32_t *)(data + 12);
- uint32_t n = 0;
- unsigned long stat_ctr = 0;
-
- while (1) {
- n++;
- *nonce = n;
-
- runhash(hash1, data, midstate);
- runhash(hash, hash1, sha256_init_state);
-
- stat_ctr++;
-
- if (hash32[7] == 0) {
- char *hexstr;
-
- hexstr = bin2hex(hash, 32);
- fprintf(stderr,
- "DBG: found zeroes in hash:\n%s\n",
- hexstr);
- free(hexstr);
-
- *hashes_done = stat_ctr;
- return true;
- }
-
- if ((n & 0xffffff) == 0) {
- if (opt_debug)
- fprintf(stderr, "DBG: end of nonce range\n");
- *hashes_done = stat_ctr;
- return false;
- }
- }
-}
-
static void *miner_thread(void *thr_id_int)
{
int thr_id = (unsigned long) thr_id_int;
@@ -318,8 +264,8 @@ static void *miner_thread(void *thr_id_int)
/* scan nonces for a proof-of-work hash */
switch (opt_algo) {
case ALGO_C:
- rc = scanhash(work.midstate, work.data + 64,
- work.hash1, work.hash, &hashes_done);
+ rc = scanhash_c(work.midstate, work.data + 64,
+ work.hash1, work.hash, &hashes_done);
break;
#ifdef WANT_SSE2_4WAY