Skip to content

Commit

Permalink
Add SHA256 and SHA256ET10 algos.
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni Lukkaroinen committed Jan 12, 2025
1 parent 5f02105 commit 0c484ca
Show file tree
Hide file tree
Showing 19 changed files with 99,583 additions and 10,469 deletions.
922 changes: 564 additions & 358 deletions cpu-miner.c

Large diffs are not rendered by default.

90 changes: 50 additions & 40 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define __MINER_H__

#include "cpuminer-config.h"

#include <stdbool.h>
#include <inttypes.h>
#include <sys/time.h>
Expand All @@ -11,35 +10,37 @@
#include <curl/curl.h>

#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#endif
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#include <alloca.h>
#elif !defined alloca
# ifdef __GNUC__
# define alloca __builtin_alloca
# elif defined _AIX
# define alloca __alloca
# elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
# elif !defined HAVE_ALLOCA
# ifdef __cplusplus
#ifdef __GNUC__
#define alloca __builtin_alloca
#elif defined _AIX
#define alloca __alloca
#elif defined _MSC_VER
#include <malloc.h>
#define alloca _alloca
#elif !defined HAVE_ALLOCA
#ifdef __cplusplus
extern "C"
# endif
void *alloca (size_t);
# endif
#endif
void *
alloca(size_t);
#endif
#endif

#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#else
enum {
enum
{
LOG_ERR,
LOG_WARNING,
LOG_NOTICE,
Expand All @@ -65,8 +66,7 @@ enum {
#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
#define WANT_BUILTIN_BSWAP
#else
#define bswap_32(x) ((((x) << 24) & 0xff000000u) | (((x) << 8) & 0x00ff0000u) \
| (((x) >> 8) & 0x0000ff00u) | (((x) >> 24) & 0x000000ffu))
#define bswap_32(x) ((((x) << 24) & 0xff000000u) | (((x) << 8) & 0x00ff0000u) | (((x) >> 8) & 0x0000ff00u) | (((x) >> 24) & 0x000000ffu))
#endif

static inline uint32_t swab32(uint32_t v)
Expand All @@ -87,7 +87,7 @@ static inline uint32_t be32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
}
#endif

Expand All @@ -96,7 +96,7 @@ static inline uint32_t le32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
}
#endif

Expand Down Expand Up @@ -152,22 +152,30 @@ void sha256_transform_8way(uint32_t *state, const uint32_t *block, int swap);
#endif

extern int scanhash_sha256d(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);

extern int scanhash_sha256(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);

extern int scanhash_sha256ET10(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);

extern unsigned char *scrypt_buffer_alloc(int N);
extern int scanhash_scrypt(int thr_id, uint32_t *pdata,
unsigned char *scratchbuf, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done, int N);
unsigned char *scratchbuf, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done, int N);

struct thr_info {
int id;
pthread_t pth;
struct thread_q *q;
struct thr_info
{
int id;
pthread_t pth;
struct thread_q *q;
};

struct work_restart {
volatile unsigned long restart;
char padding[128 - sizeof(unsigned long)];
struct work_restart
{
volatile unsigned long restart;
char padding[128 - sizeof(unsigned long)];
};

extern bool opt_debug;
Expand All @@ -190,24 +198,25 @@ extern int longpoll_thr_id;
extern int stratum_thr_id;
extern struct work_restart *work_restart;

#define JSON_RPC_LONGPOLL (1 << 0)
#define JSON_RPC_QUIET_404 (1 << 1)
#define JSON_RPC_LONGPOLL (1 << 0)
#define JSON_RPC_QUIET_404 (1 << 1)

extern void applog(int prio, const char *fmt, ...);
extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
const char *rpc_req, int *curl_err, int flags);
const char *rpc_req, int *curl_err, int flags);
void memrev(unsigned char *p, size_t len);
extern void bin2hex(char *s, const unsigned char *p, size_t len);
extern char *abin2hex(const unsigned char *p, size_t len);
extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
extern int varint_encode(unsigned char *p, uint64_t n);
extern size_t address_to_script(unsigned char *out, size_t outsz, const char *addr);
extern int timeval_subtract(struct timeval *result, struct timeval *x,
struct timeval *y);
struct timeval *y);
extern bool fulltest(const uint32_t *hash, const uint32_t *target);
extern void diff_to_target(uint32_t *target, double diff);

struct stratum_job {
struct stratum_job
{
char *job_id;
unsigned char prevhash[32];
size_t coinbase_size;
Expand All @@ -222,7 +231,8 @@ struct stratum_job {
double diff;
};

struct stratum_ctx {
struct stratum_ctx
{
char *url;

CURL *curl;
Expand Down
Loading

0 comments on commit 0c484ca

Please sign in to comment.