├── cpuminer-source ├── compat │ ├── jansson │ │ ├── .gitignore │ │ ├── util.h │ │ ├── Makefile.am │ │ ├── utf.h │ │ ├── strbuffer.h │ │ ├── LICENSE │ │ ├── jansson_private.h │ │ ├── config.h │ │ ├── strbuffer.c │ │ ├── utf.c │ │ ├── jansson.h │ │ └── hashtable.h │ └── Makefile.am ├── ChangeLog ├── AUTHORS ├── LICENSE ├── build.sh ├── autogen.sh ├── example-cfg.json ├── .gitignore ├── compat.h ├── README ├── Dockerfile ├── Makefile.am ├── nomacro.pl └── configure.ac ├── cpuminer-newalgorithms ├── compat │ ├── jansson │ │ ├── .gitignore │ │ ├── util.h │ │ ├── Makefile.am │ │ ├── utf.h │ │ ├── strbuffer.h │ │ ├── LICENSE │ │ ├── jansson_private.h │ │ ├── config.h │ │ ├── strbuffer.c │ │ ├── utf.c │ │ ├── jansson.h │ │ └── hashtable.h │ └── Makefile.am ├── ChangeLog ├── LICENSE ├── crypto │ ├── hash.h │ ├── c_keccak.h │ ├── c_jh.h │ ├── hash.c │ ├── aesb-x86-impl.c │ ├── c_blake256.h │ ├── c_groestl.h │ ├── hash-ops.h │ ├── c_skein.h │ ├── oaes_config.h │ ├── c_keccak.c │ ├── groestl_tables.h │ ├── int-util.h │ ├── oaes_lib.h │ └── skein_port.h ├── build.sh ├── AUTHORS ├── autogen.sh ├── example-cfg.json ├── compat.h ├── aesb-arm.S ├── aesb-x86.S ├── scryptjane │ ├── scrypt-jane-romix.h │ ├── scrypt-jane-mix_chacha.h │ ├── scrypt-jane-mix_salsa.h │ ├── scrypt-jane-hash.h │ ├── scrypt-jane-romix-basic.h │ ├── scrypt-jane-salsa.h │ ├── scrypt-jane-romix-template.h │ ├── scrypt-jane-pbkdf2.h │ ├── scrypt-jane-chacha.h │ ├── scrypt-jane-hash_sha256.h │ └── scrypt-jane-hash_keccak.h ├── nomacro.pl ├── keccak.c ├── aesb-x64.S ├── Makefile.am ├── sha3 │ ├── sph_fugue.h │ ├── sph_hefty1.h │ └── sph_whirlpool.h ├── skein.c ├── fresh.c ├── heavy.c ├── configure.ac ├── ink.c ├── blake.c ├── x13.c ├── x14.c ├── x15.c ├── README.md └── x11.c ├── minerd ├── minerd-multi ├── minerd.tar.bz2 ├── minerd.tar.gz ├── minerd-multi.tar.gz └── README.md /cpuminer-source/compat/jansson/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | libjansson.a 3 | 4 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | libjansson.a 3 | 4 | -------------------------------------------------------------------------------- /cpuminer-source/ChangeLog: -------------------------------------------------------------------------------- 1 | See git repository ('git log') for full changelog. 2 | -------------------------------------------------------------------------------- /minerd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demogorgonz/RaspberryPi-CPUMiner/HEAD/minerd -------------------------------------------------------------------------------- /cpuminer-newalgorithms/ChangeLog: -------------------------------------------------------------------------------- 1 | See git repository ('git log') for full changelog. 2 | -------------------------------------------------------------------------------- /minerd-multi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demogorgonz/RaspberryPi-CPUMiner/HEAD/minerd-multi -------------------------------------------------------------------------------- /minerd.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demogorgonz/RaspberryPi-CPUMiner/HEAD/minerd.tar.bz2 -------------------------------------------------------------------------------- /minerd.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demogorgonz/RaspberryPi-CPUMiner/HEAD/minerd.tar.gz -------------------------------------------------------------------------------- /minerd-multi.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demogorgonz/RaspberryPi-CPUMiner/HEAD/minerd-multi.tar.gz -------------------------------------------------------------------------------- /cpuminer-source/AUTHORS: -------------------------------------------------------------------------------- 1 | Jeff Garzik 2 | 3 | ArtForz 4 | 5 | pooler 6 | -------------------------------------------------------------------------------- /cpuminer-source/compat/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if WANT_JANSSON 3 | SUBDIRS = jansson 4 | else 5 | SUBDIRS = 6 | endif 7 | 8 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if WANT_JANSSON 3 | SUBDIRS = jansson 4 | else 5 | SUBDIRS = 6 | endif 7 | 8 | -------------------------------------------------------------------------------- /cpuminer-source/LICENSE: -------------------------------------------------------------------------------- 1 | cpuminer is available under the terms of the GNU Public License version 2. 2 | 3 | See COPYING for details. 4 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/LICENSE: -------------------------------------------------------------------------------- 1 | cpuminer is available under the terms of the GNU Public License version 2. 2 | 3 | See COPYING for details. 4 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef unsigned char BitSequence; 4 | typedef unsigned long long DataLength; 5 | typedef enum {SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2} HashReturn; 6 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt-get install autoconf libcurl4-openssl-dev libjansson-dev openssl libssl-dev gcc gawk 3 | ./autogen.sh 4 | ./configure 5 | make 6 | 7 | echo "run ./minerd --help" 8 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/AUTHORS: -------------------------------------------------------------------------------- 1 | Jeff Garzik 2 | 3 | ArtForz 4 | 5 | pooler 6 | 7 | BlueDragon747 8 | 9 | 1gh 10 | 11 | Neisklar 12 | 13 | prettyhatemachine 14 | 15 | LucasJones 16 | -------------------------------------------------------------------------------- /cpuminer-source/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt-get update -y 3 | sudo apt-get install libusb-1.0-0-dev libusb-1.0-0 libcurl4-openssl-dev libncurses5-dev libudev-dev make automake autoconf -y 4 | sudo ./autogen.sh 5 | sudo ./configure CFLAGS="-O3" 6 | sudo make 7 | -------------------------------------------------------------------------------- /cpuminer-source/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # You need autoconf 2.5x, preferably 2.57 or later 4 | # You need automake 1.7 or later. 1.6 might work. 5 | 6 | set -e 7 | 8 | aclocal 9 | autoheader 10 | automake --gnu --add-missing --copy 11 | autoconf 12 | 13 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # You need autoconf 2.5x, preferably 2.57 or later 4 | # You need automake 1.7 or later. 1.6 might work. 5 | 6 | set -e 7 | 8 | aclocal 9 | autoheader 10 | automake --gnu --add-missing --copy 11 | autoconf 12 | 13 | -------------------------------------------------------------------------------- /cpuminer-source/example-cfg.json: -------------------------------------------------------------------------------- 1 | { 2 | "_comment1" : "Any long-format command line argument ", 3 | "_comment2" : "may be used in this JSON configuration file", 4 | 5 | "url" : "http://127.0.0.1:9332/", 6 | "user" : "rpcuser", 7 | "pass" : "rpcpass", 8 | 9 | "algo" : "scrypt", 10 | "threads" : "4", 11 | 12 | "quiet" : true 13 | } 14 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/example-cfg.json: -------------------------------------------------------------------------------- 1 | { 2 | "_comment1" : "Any long-format command line argument ", 3 | "_comment2" : "may be used in this JSON configuration file", 4 | 5 | "url" : "http://127.0.0.1:9332/", 6 | "user" : "rpcuser", 7 | "pass" : "rpcpass", 8 | 9 | "algo" : "scrypt", 10 | "threads" : "4", 11 | 12 | "quiet" : true 13 | } 14 | -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTIL_H 9 | #define UTIL_H 10 | 11 | #define max(a, b) ((a) > (b) ? (a) : (b)) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTIL_H 9 | #define UTIL_H 10 | 11 | #define max(a, b) ((a) > (b) ? (a) : (b)) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_LIBRARIES = libjansson.a 3 | 4 | libjansson_a_SOURCES = \ 5 | config.h \ 6 | dump.c \ 7 | hashtable.c \ 8 | hashtable.h \ 9 | jansson.h \ 10 | jansson_private.h \ 11 | load.c \ 12 | strbuffer.c \ 13 | strbuffer.h \ 14 | utf.c \ 15 | utf.h \ 16 | util.h \ 17 | value.c 18 | 19 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_LIBRARIES = libjansson.a 3 | 4 | libjansson_a_SOURCES = \ 5 | config.h \ 6 | dump.c \ 7 | hashtable.c \ 8 | hashtable.h \ 9 | jansson.h \ 10 | jansson_private.h \ 11 | load.c \ 12 | strbuffer.c \ 13 | strbuffer.h \ 14 | utf.c \ 15 | utf.h \ 16 | util.h \ 17 | value.c 18 | 19 | -------------------------------------------------------------------------------- /cpuminer-source/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | minerd 3 | minerd.exe 4 | *.o 5 | 6 | autom4te.cache 7 | .deps 8 | 9 | Makefile 10 | Makefile.in 11 | INSTALL 12 | aclocal.m4 13 | configure 14 | configure.lineno 15 | depcomp 16 | missing 17 | install-sh 18 | stamp-h1 19 | cpuminer-config.h* 20 | compile 21 | config.log 22 | config.status 23 | config.status.lineno 24 | config.guess 25 | config.sub 26 | 27 | mingw32-config.cache 28 | 29 | -------------------------------------------------------------------------------- /cpuminer-source/compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPAT_H__ 2 | #define __COMPAT_H__ 3 | 4 | #ifdef WIN32 5 | 6 | #include 7 | 8 | #define sleep(secs) Sleep((secs) * 1000) 9 | 10 | enum { 11 | PRIO_PROCESS = 0, 12 | }; 13 | 14 | static inline int setpriority(int which, int who, int prio) 15 | { 16 | return -!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE); 17 | } 18 | 19 | #endif /* WIN32 */ 20 | 21 | #endif /* __COMPAT_H__ */ 22 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPAT_H__ 2 | #define __COMPAT_H__ 3 | 4 | #ifdef WIN32 5 | 6 | #include 7 | 8 | #define sleep(secs) Sleep((secs) * 1000) 9 | 10 | enum { 11 | PRIO_PROCESS = 0, 12 | }; 13 | 14 | static inline int setpriority(int which, int who, int prio) 15 | { 16 | return -!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE); 17 | } 18 | 19 | #endif /* WIN32 */ 20 | 21 | #endif /* __COMPAT_H__ */ 22 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/aesb-arm.S: -------------------------------------------------------------------------------- 1 | #include "cpuminer-config.h" 2 | 3 | #if defined(__linux__) && defined(__ELF__) 4 | .section .note.GNU-stack,"",%progbits 5 | #endif 6 | 7 | .text 8 | .p2align 6 9 | .globl fast_aesb_single_round 10 | .globl _fast_aesb_single_round 11 | fast_aesb_single_round: 12 | _fast_aesb_single_round: 13 | 14 | .text 15 | .p2align 6 16 | .globl fast_aesb_pseudo_round_mut 17 | .globl _fast_aesb_pseudo_round_mut 18 | fast_aesb_pseudo_round_mut: 19 | _fast_aesb_pseudo_round_mut: 20 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/aesb-x86.S: -------------------------------------------------------------------------------- 1 | #include "cpuminer-config.h" 2 | 3 | #if defined(__linux__) && defined(__ELF__) 4 | .section .note.GNU-stack,"",%progbits 5 | #endif 6 | 7 | .text 8 | .p2align 6 9 | .globl fast_aesb_single_round 10 | .globl _fast_aesb_single_round 11 | fast_aesb_single_round: 12 | _fast_aesb_single_round: 13 | ret 14 | 15 | .text 16 | .p2align 6 17 | .globl fast_aesb_pseudo_round_mut 18 | .globl _fast_aesb_pseudo_round_mut 19 | fast_aesb_pseudo_round_mut: 20 | _fast_aesb_pseudo_round_mut: 21 | ret 22 | -------------------------------------------------------------------------------- /cpuminer-source/README: -------------------------------------------------------------------------------- 1 | Build instructions: 2 | ./build.sh # this script will install dependencies and build the miner for you. 3 | 4 | 5 | Usage instructions: Run "minerd --help" to see options. 6 | 7 | Connecting through a proxy: Use the --proxy option. 8 | To use a SOCKS proxy, add a socks4:// or socks5:// prefix to the proxy host. 9 | Protocols socks4a and socks5h, allowing remote name resolving, are also 10 | available since libcurl 7.18.0. 11 | If no protocol is specified, the proxy is assumed to be a HTTP proxy. 12 | When the --proxy option is not used, the program honors the http_proxy 13 | and all_proxy environment variables. -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/c_keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | 4 | #ifndef KECCAK_H 5 | #define KECCAK_H 6 | 7 | #include 8 | #include 9 | 10 | #ifndef KECCAK_ROUNDS 11 | #define KECCAK_ROUNDS 24 12 | #endif 13 | 14 | #ifndef ROTL64 15 | #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) 16 | #endif 17 | 18 | // compute a keccak hash (md) of given byte length from "in" 19 | int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen); 20 | 21 | // update the state 22 | void keccakf(uint64_t st[25], int norounds); 23 | 24 | void keccak1600(const uint8_t *in, int inlen, uint8_t *md); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /cpuminer-source/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # Dockerfile for cpuminer 3 | # usage: docker run creack/cpuminer --url xxxx --user xxxx --pass xxxx 4 | # ex: docker run creack/cpuminer --url stratum+tcp://ltc.pool.com:80 --user creack.worker1 --pass abcdef 5 | # 6 | # 7 | 8 | FROM ubuntu:14.04 9 | MAINTAINER Guillaume J. Charmes 10 | 11 | RUN apt-get update -qq && \ 12 | apt-get install -qqy automake libcurl4-openssl-dev git make 13 | 14 | RUN git clone https://github.com/pooler/cpuminer 15 | 16 | RUN cd cpuminer && \ 17 | ./autogen.sh && \ 18 | ./configure CFLAGS="-O3" && \ 19 | make 20 | 21 | WORKDIR /cpuminer 22 | ENTRYPOINT ["./minerd"] 23 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/c_jh.h: -------------------------------------------------------------------------------- 1 | /*This program gives the 64-bit optimized bitslice implementation of JH using ANSI C 2 | 3 | -------------------------------- 4 | Performance 5 | 6 | Microprocessor: Intel CORE 2 processor (Core 2 Duo Mobile T6600 2.2GHz) 7 | Operating System: 64-bit Ubuntu 10.04 (Linux kernel 2.6.32-22-generic) 8 | Speed for long message: 9 | 1) 45.8 cycles/byte compiler: Intel C++ Compiler 11.1 compilation option: icc -O2 10 | 2) 56.8 cycles/byte compiler: gcc 4.4.3 compilation option: gcc -O3 11 | 12 | -------------------------------- 13 | Last Modified: January 16, 2011 14 | */ 15 | #pragma once 16 | 17 | #include "hash.h" 18 | 19 | HashReturn jh_hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval); 20 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/hash.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "hash-ops.h" 10 | #include "c_keccak.h" 11 | 12 | void hash_permutation(union hash_state *state) { 13 | keccakf((uint64_t*)state, 24); 14 | } 15 | 16 | void hash_process(union hash_state *state, const uint8_t *buf, size_t count) { 17 | keccak1600(buf, count, (uint8_t*)state); 18 | } 19 | 20 | void cn_fast_hash(const void *data, size_t length, char *hash) { 21 | union hash_state state; 22 | hash_process(&state, data, length); 23 | memcpy(hash, &state, HASH_SIZE); 24 | } 25 | -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/utf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTF_H 9 | #define UTF_H 10 | 11 | #include 12 | 13 | #ifdef HAVE_INTTYPES_H 14 | /* inttypes.h includes stdint.h in a standard environment, so there's 15 | no need to include stdint.h separately. If inttypes.h doesn't define 16 | int32_t, it's defined in config.h. */ 17 | #include 18 | #endif 19 | 20 | int utf8_encode(int codepoint, char *buffer, int *size); 21 | 22 | int utf8_check_first(char byte); 23 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint); 24 | const char *utf8_iterate(const char *buffer, int32_t *codepoint); 25 | 26 | int utf8_check_string(const char *string, int length); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/utf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTF_H 9 | #define UTF_H 10 | 11 | #include 12 | 13 | #ifdef HAVE_INTTYPES_H 14 | /* inttypes.h includes stdint.h in a standard environment, so there's 15 | no need to include stdint.h separately. If inttypes.h doesn't define 16 | int32_t, it's defined in config.h. */ 17 | #include 18 | #endif 19 | 20 | int utf8_encode(int codepoint, char *buffer, int *size); 21 | 22 | int utf8_check_first(char byte); 23 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint); 24 | const char *utf8_iterate(const char *buffer, int32_t *codepoint); 25 | 26 | int utf8_check_string(const char *string, int length); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /cpuminer-source/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if WANT_JANSSON 3 | JANSSON_INCLUDES= -I$(top_srcdir)/compat/jansson 4 | else 5 | JANSSON_INCLUDES= 6 | endif 7 | 8 | EXTRA_DIST = example-cfg.json nomacro.pl 9 | 10 | SUBDIRS = compat 11 | 12 | INCLUDES = $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) 13 | 14 | bin_PROGRAMS = minerd 15 | 16 | dist_man_MANS = minerd.1 17 | 18 | minerd_SOURCES = elist.h miner.h compat.h \ 19 | cpu-miner.c util.c \ 20 | sha2.c scrypt.c 21 | if USE_ASM 22 | if ARCH_x86 23 | minerd_SOURCES += sha2-x86.S scrypt-x86.S 24 | endif 25 | if ARCH_x86_64 26 | minerd_SOURCES += sha2-x64.S scrypt-x64.S 27 | endif 28 | if ARCH_ARM 29 | minerd_SOURCES += sha2-arm.S scrypt-arm.S 30 | endif 31 | if ARCH_PPC 32 | minerd_SOURCES += sha2-ppc.S scrypt-ppc.S 33 | endif 34 | endif 35 | minerd_LDFLAGS = $(PTHREAD_FLAGS) 36 | minerd_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ 37 | minerd_CPPFLAGS = @LIBCURL_CPPFLAGS@ 38 | 39 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/aesb-x86-impl.c: -------------------------------------------------------------------------------- 1 | #include "int-util.h" 2 | #include 3 | 4 | uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi) { 5 | // multiplier = ab = a * 2^32 + b 6 | // multiplicand = cd = c * 2^32 + d 7 | // ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d 8 | uint64_t a = hi_dword(multiplier); 9 | uint64_t b = lo_dword(multiplier); 10 | uint64_t c = hi_dword(multiplicand); 11 | uint64_t d = lo_dword(multiplicand); 12 | 13 | uint64_t ac = a * c; 14 | uint64_t ad = a * d; 15 | uint64_t bc = b * c; 16 | uint64_t bd = b * d; 17 | 18 | uint64_t adbc = ad + bc; 19 | uint64_t adbc_carry = adbc < ad ? 1 : 0; 20 | 21 | // multiplier * multiplicand = product_hi * 2^64 + product_lo 22 | uint64_t product_lo = bd + (adbc << 32); 23 | uint64_t product_lo_carry = product_lo < bd ? 1 : 0; 24 | *product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry; 25 | 26 | return product_lo; 27 | } 28 | -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/strbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef STRBUFFER_H 9 | #define STRBUFFER_H 10 | 11 | typedef struct { 12 | char *value; 13 | int length; /* bytes used */ 14 | int size; /* bytes allocated */ 15 | } strbuffer_t; 16 | 17 | int strbuffer_init(strbuffer_t *strbuff); 18 | void strbuffer_close(strbuffer_t *strbuff); 19 | 20 | void strbuffer_clear(strbuffer_t *strbuff); 21 | 22 | const char *strbuffer_value(const strbuffer_t *strbuff); 23 | char *strbuffer_steal_value(strbuffer_t *strbuff); 24 | 25 | int strbuffer_append(strbuffer_t *strbuff, const char *string); 26 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte); 27 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size); 28 | 29 | char strbuffer_pop(strbuffer_t *strbuff); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/strbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef STRBUFFER_H 9 | #define STRBUFFER_H 10 | 11 | typedef struct { 12 | char *value; 13 | int length; /* bytes used */ 14 | int size; /* bytes allocated */ 15 | } strbuffer_t; 16 | 17 | int strbuffer_init(strbuffer_t *strbuff); 18 | void strbuffer_close(strbuffer_t *strbuff); 19 | 20 | void strbuffer_clear(strbuffer_t *strbuff); 21 | 22 | const char *strbuffer_value(const strbuffer_t *strbuff); 23 | char *strbuffer_steal_value(strbuffer_t *strbuff); 24 | 25 | int strbuffer_append(strbuffer_t *strbuff, const char *string); 26 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte); 27 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size); 28 | 29 | char strbuffer_pop(strbuffer_t *strbuff); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009, 2010 Petri Lehtinen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009, 2010 Petri Lehtinen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-romix.h: -------------------------------------------------------------------------------- 1 | #if defined(SCRYPT_CHACHA) 2 | #include "scrypt-jane-chacha.h" 3 | #elif defined(SCRYPT_SALSA) 4 | #include "scrypt-jane-salsa.h" 5 | #elif defined(SCRYPT_SALSA64) 6 | #include "scrypt-jane-salsa64.h" 7 | #else 8 | #define SCRYPT_MIX_BASE "ERROR" 9 | typedef uint32_t scrypt_mix_word_t; 10 | #define SCRYPT_WORDTO8_LE U32TO8_LE 11 | #define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP 12 | #define SCRYPT_BLOCK_BYTES 64 13 | #define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t)) 14 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 15 | static void FASTCALL scrypt_ROMix_error(scrypt_mix_word_t *X/*[chunkWords]*/, scrypt_mix_word_t *Y/*[chunkWords]*/, scrypt_mix_word_t *V/*[chunkWords * N]*/, uint32_t N, uint32_t r) {} 16 | static scrypt_ROMixfn scrypt_getROMix() { return scrypt_ROMix_error; } 17 | #else 18 | static void FASTCALL scrypt_ROMix(scrypt_mix_word_t *X, scrypt_mix_word_t *Y, scrypt_mix_word_t *V, uint32_t N, uint32_t r) {} 19 | #endif 20 | static int scrypt_test_mix() { return 0; } 21 | #error must define a mix function! 22 | #endif 23 | 24 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 25 | #undef SCRYPT_MIX 26 | #define SCRYPT_MIX SCRYPT_MIX_BASE 27 | #endif 28 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/nomacro.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Copyright 2012 pooler@litecoinpool.org 3 | # 4 | # This program is free software; you can redistribute it and/or modify it 5 | # under the terms of the GNU General Public License as published by the Free 6 | # Software Foundation; either version 2 of the License, or (at your option) 7 | # any later version. See COPYING for more details. 8 | # 9 | # nomacro.pl - convert assembler macros to C preprocessor macros. 10 | 11 | use strict; 12 | 13 | foreach my $f (<*.S>) { 14 | rename $f, "$f.orig"; 15 | open FIN, "$f.orig"; 16 | open FOUT, ">$f"; 17 | my $inmacro = 0; 18 | my %macros = (); 19 | while () { 20 | if (m/^\.macro\s+([_0-9A-Z]+)(?:\s*)(.*)$/i) { 21 | print FOUT "#define $1($2) \\\n"; 22 | $macros{$1} = 1; 23 | $inmacro = 1; 24 | next; 25 | } 26 | if (m/^\.endm/) { 27 | print FOUT "\n"; 28 | $inmacro = 0; 29 | next; 30 | } 31 | for my $m (keys %macros) { 32 | s/^([ \t]*)($m)(?:[ \t]+([^#\n]*))?([;\n])/\1\2(\3)\4/; 33 | } 34 | if ($inmacro) { 35 | if (m/^\s*#if/) { 36 | $_ = while (!m/^\s*#endif/); 37 | next; 38 | } 39 | next if (m/^\s*$/); 40 | s/\\//g; 41 | s/$/; \\/; 42 | } 43 | print FOUT; 44 | } 45 | close FOUT; 46 | close FIN; 47 | } 48 | -------------------------------------------------------------------------------- /cpuminer-source/nomacro.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Copyright 2012, 2015 pooler@litecoinpool.org 3 | # 4 | # This program is free software; you can redistribute it and/or modify it 5 | # under the terms of the GNU General Public License as published by the Free 6 | # Software Foundation; either version 2 of the License, or (at your option) 7 | # any later version. See COPYING for more details. 8 | # 9 | # nomacro.pl - expand assembler macros. 10 | 11 | use strict; 12 | 13 | foreach my $f (<*.S>) { 14 | rename $f, "$f.orig" unless -e "$f.orig"; 15 | open FIN, "$f.orig"; 16 | open FOUT, ">$f"; 17 | my %macros = (); 18 | my %m = (); 19 | while () { 20 | if (m/^\.macro\s+(\w+)\s*(.*)$/) { 21 | $m{name} = $1; 22 | @m{args} = [split /\s*,\s*/, $2]; 23 | $m{body} = ""; 24 | next; 25 | } 26 | if (m/^\.endm/) { 27 | $macros{$m{name}} = {%m}; 28 | %m = (); 29 | next; 30 | } 31 | for my $n (keys %macros) { 32 | if (m/^\s*$n\b\s*(.*)$/) { 33 | my @a = split /\s*,\s*/, $1; 34 | $_ = $macros{$n}{body}; 35 | for my $i (0 .. $#{$macros{$n}{args}}) { 36 | s/\\$macros{$n}{args}[$i]\b/$a[$i]/g; 37 | } 38 | last; 39 | } 40 | } 41 | if (%m) { 42 | $m{body} .= $_; 43 | next; 44 | } 45 | print FOUT; 46 | } 47 | close FOUT; 48 | close FIN; 49 | } 50 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/keccak.c: -------------------------------------------------------------------------------- 1 | #include "cpuminer-config.h" 2 | #include "miner.h" 3 | 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_keccak.h" 8 | 9 | static void keccakhash(void *state, const void *input) 10 | { 11 | sph_keccak256_context ctx_keccak; 12 | uint32_t hash[32]; 13 | 14 | sph_keccak256_init(&ctx_keccak); 15 | sph_keccak256 (&ctx_keccak,input, 80); 16 | sph_keccak256_close(&ctx_keccak, hash); 17 | 18 | memcpy(state, hash, 32); 19 | } 20 | 21 | int scanhash_keccak(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 22 | uint32_t max_nonce, uint64_t *hashes_done) 23 | { 24 | uint32_t n = pdata[19] - 1; 25 | const uint32_t first_nonce = pdata[19]; 26 | const uint32_t Htarg = ptarget[7]; 27 | 28 | uint32_t hash64[8] __attribute__((aligned(32))); 29 | uint32_t endiandata[32]; 30 | 31 | int kk=0; 32 | for (; kk < 32; kk++) 33 | { 34 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 35 | }; 36 | 37 | do { 38 | 39 | pdata[19] = ++n; 40 | be32enc(&endiandata[19], n); 41 | keccakhash(hash64, &endiandata); 42 | if (((hash64[7]&0xFFFFFF00)==0) && 43 | fulltest(hash64, ptarget)) { 44 | *hashes_done = n - first_nonce + 1; 45 | return true; 46 | } 47 | } while (n < max_nonce && !work_restart[thr_id].restart); 48 | 49 | *hashes_done = n - first_nonce + 1; 50 | pdata[19] = n; 51 | return 0; 52 | } -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/c_blake256.h: -------------------------------------------------------------------------------- 1 | #ifndef _BLAKE256_H_ 2 | #define _BLAKE256_H_ 3 | 4 | #include 5 | 6 | typedef struct { 7 | uint32_t h[8], s[4], t[2]; 8 | int buflen, nullt; 9 | uint8_t buf[64]; 10 | } state; 11 | 12 | typedef struct { 13 | state inner; 14 | state outer; 15 | } hmac_state; 16 | 17 | void blake256_init(state *); 18 | void blake224_init(state *); 19 | 20 | void blake256_update(state *, const uint8_t *, uint64_t); 21 | void blake224_update(state *, const uint8_t *, uint64_t); 22 | 23 | void blake256_final(state *, uint8_t *); 24 | void blake224_final(state *, uint8_t *); 25 | 26 | void blake256_hash(uint8_t *, const uint8_t *, uint64_t); 27 | void blake224_hash(uint8_t *, const uint8_t *, uint64_t); 28 | 29 | /* HMAC functions: */ 30 | 31 | void hmac_blake256_init(hmac_state *, const uint8_t *, uint64_t); 32 | void hmac_blake224_init(hmac_state *, const uint8_t *, uint64_t); 33 | 34 | void hmac_blake256_update(hmac_state *, const uint8_t *, uint64_t); 35 | void hmac_blake224_update(hmac_state *, const uint8_t *, uint64_t); 36 | 37 | void hmac_blake256_final(hmac_state *, uint8_t *); 38 | void hmac_blake224_final(hmac_state *, uint8_t *); 39 | 40 | void hmac_blake256_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 41 | void hmac_blake224_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 42 | 43 | #endif /* _BLAKE256_H_ */ 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RaspberryPi-CPUMiner + CPUMiner with new algorithms (check bellow) 2 | CPUMiner for RaspberryPi Zero, Pi 3, Pi 2, B+, A+. 3 | 4 | 5 | Clone of: [pooler](https://github.com/pooler/cpuminer) 6 | 7 | # Instructions for PiZero: 8 | Download minerd to your PiZero, make it executable & run: 9 | 10 | **# wget https://github.com/demogorgonz/RaspberryPi-CPUMiner/raw/master/minerd** 11 | 12 | **# chmod +x minerd** 13 | 14 | **# ./minerd -h** 15 | 16 | # Or 17 | 18 | Download minerd.tar.bz2 archive, extract & run: 19 | 20 | **# wget https://github.com/demogorgonz/RaspberryPi-CPUMiner/releases/download/v.1.0/minerd.tar.bz2** 21 | 22 | **# tar xjf minerd.tar.bz2** 23 | 24 | **# ./minerd -h** 25 | 26 | 27 | # Build it yourself for Pi 3, Pi 2, B+, A+ : 28 | There is auto build script which will install dependencies to your Raspberry and build "minerd" - see "cpuminer-source" folder and locate build.sh file. 29 | 30 | **cd cpuminer-source/** 31 | 32 | **sudo bash build.sh** 33 | 34 | _____________________________________________________ 35 | 36 | # CPUMiner with new algorithms (EXPERIMENTAL) 37 | 38 | clone of [lucasjones](https://github.com/lucasjones/cpuminer-multi) 39 | 40 | Download page: [Releases v1.1](https://github.com/demogorgonz/RaspberryPi-CPUMiner/releases/tag/v.1.1) 41 | 42 | # Build it yourself for Pi 3, Pi 2, B+, A+ : 43 | 44 | **cd cpuminer-newalgorithms** 45 | 46 | **sudo bash build.sh** 47 | 48 | # Donate: 49 | 50 | **Bitcoin: 1KWVA9qBfTHmzPMvDw4ociqnk71FoLm1mp** 51 | 52 | ![btc](http://i.imgur.com/FeRpxAb.png) 53 | -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/jansson_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef JANSSON_PRIVATE_H 9 | #define JANSSON_PRIVATE_H 10 | 11 | #include "jansson.h" 12 | #include "hashtable.h" 13 | 14 | #define container_of(ptr_, type_, member_) \ 15 | ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_)) 16 | 17 | typedef struct { 18 | json_t json; 19 | hashtable_t hashtable; 20 | unsigned long serial; 21 | int visited; 22 | } json_object_t; 23 | 24 | typedef struct { 25 | json_t json; 26 | unsigned int size; 27 | unsigned int entries; 28 | json_t **table; 29 | int visited; 30 | } json_array_t; 31 | 32 | typedef struct { 33 | json_t json; 34 | char *value; 35 | } json_string_t; 36 | 37 | typedef struct { 38 | json_t json; 39 | double value; 40 | } json_real_t; 41 | 42 | typedef struct { 43 | json_t json; 44 | int value; 45 | } json_integer_t; 46 | 47 | #define json_to_object(json_) container_of(json_, json_object_t, json) 48 | #define json_to_array(json_) container_of(json_, json_array_t, json) 49 | #define json_to_string(json_) container_of(json_, json_string_t, json) 50 | #define json_to_real(json_) container_of(json_, json_real_t, json) 51 | #define json_to_integer(json_) container_of(json_, json_integer_t, json) 52 | 53 | typedef struct { 54 | unsigned long serial; 55 | char key[]; 56 | } object_key_t; 57 | 58 | const object_key_t *jsonp_object_iter_fullkey(void *iter); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/aesb-x64.S: -------------------------------------------------------------------------------- 1 | #include "cpuminer-config.h" 2 | 3 | #if defined(__linux__) && defined(__ELF__) 4 | .section .note.GNU-stack,"",%progbits 5 | #endif 6 | 7 | .text 8 | .p2align 6 9 | .globl fast_aesb_single_round 10 | .globl _fast_aesb_single_round 11 | fast_aesb_single_round: 12 | _fast_aesb_single_round: 13 | #if defined(_WIN64) || defined(__CYGWIN__) 14 | movdqa (%rcx), %xmm1 15 | aesenc (%r8), %xmm1 16 | movdqa %xmm1, (%rdx) 17 | #else 18 | movdqa (%rdi), %xmm1 19 | aesenc (%rdx), %xmm1 20 | movdqa %xmm1, (%rsi) 21 | #endif 22 | ret 23 | 24 | .text 25 | .p2align 6 26 | .globl fast_aesb_pseudo_round_mut 27 | .globl _fast_aesb_pseudo_round_mut 28 | fast_aesb_pseudo_round_mut: 29 | _fast_aesb_pseudo_round_mut: 30 | #if defined(_WIN64) || defined(__CYGWIN__) 31 | mov %rdx, %r9 32 | add $0xA0, %r9 33 | movdqa (%rcx), %xmm1 34 | 35 | .LOOP: 36 | aesenc (%rdx), %xmm1 37 | add $0x10, %rdx 38 | cmp %r9, %rdx 39 | jl .LOOP 40 | 41 | movdqa %xmm1, (%rcx) 42 | #else 43 | mov %rsi, %r9 44 | add $0xA0, %r9 45 | movdqa (%rdi), %xmm1 46 | 47 | .LOOP: 48 | aesenc (%rsi), %xmm1 49 | add $0x10, %rsi 50 | cmp %r9, %rsi 51 | jl .LOOP 52 | 53 | movdqa %xmm1, (%rdi) 54 | #endif 55 | ret 56 | 57 | .text 58 | .globl mul128 59 | .globl _mul128 60 | mul128: 61 | _mul128: 62 | #if defined(_WIN64) || defined(__CYGWIN__) 63 | mov %rcx, %rax 64 | mul %rdx 65 | mov %rdx, (%r8) 66 | #else 67 | mov %rdx, %r8 68 | mov %rdi, %rax 69 | mul %rsi 70 | mov %rdx, (%r8) 71 | #endif 72 | ret 73 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/jansson_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef JANSSON_PRIVATE_H 9 | #define JANSSON_PRIVATE_H 10 | 11 | #include "jansson.h" 12 | #include "hashtable.h" 13 | 14 | #define container_of(ptr_, type_, member_) \ 15 | ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_)) 16 | 17 | typedef struct { 18 | json_t json; 19 | hashtable_t hashtable; 20 | unsigned long serial; 21 | int visited; 22 | } json_object_t; 23 | 24 | typedef struct { 25 | json_t json; 26 | unsigned int size; 27 | unsigned int entries; 28 | json_t **table; 29 | int visited; 30 | } json_array_t; 31 | 32 | typedef struct { 33 | json_t json; 34 | char *value; 35 | } json_string_t; 36 | 37 | typedef struct { 38 | json_t json; 39 | double value; 40 | } json_real_t; 41 | 42 | typedef struct { 43 | json_t json; 44 | int value; 45 | } json_integer_t; 46 | 47 | #define json_to_object(json_) container_of(json_, json_object_t, json) 48 | #define json_to_array(json_) container_of(json_, json_array_t, json) 49 | #define json_to_string(json_) container_of(json_, json_string_t, json) 50 | #define json_to_real(json_) container_of(json_, json_real_t, json) 51 | #define json_to_integer(json_) container_of(json_, json_integer_t, json) 52 | 53 | typedef struct { 54 | unsigned long serial; 55 | char key[]; 56 | } object_key_t; 57 | 58 | const object_key_t *jsonp_object_iter_fullkey(void *iter); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-mix_chacha.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_CHACHA_INCLUDED) 2 | 3 | #undef SCRYPT_MIX 4 | #define SCRYPT_MIX "ChaCha20/8 Ref" 5 | 6 | #undef SCRYPT_CHACHA_INCLUDED 7 | #define SCRYPT_CHACHA_INCLUDED 8 | #define SCRYPT_CHACHA_BASIC 9 | 10 | static void 11 | chacha_core_basic(uint32_t state[16]) { 12 | size_t rounds = 8; 13 | uint32_t x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,t; 14 | 15 | x0 = state[0]; 16 | x1 = state[1]; 17 | x2 = state[2]; 18 | x3 = state[3]; 19 | x4 = state[4]; 20 | x5 = state[5]; 21 | x6 = state[6]; 22 | x7 = state[7]; 23 | x8 = state[8]; 24 | x9 = state[9]; 25 | x10 = state[10]; 26 | x11 = state[11]; 27 | x12 = state[12]; 28 | x13 = state[13]; 29 | x14 = state[14]; 30 | x15 = state[15]; 31 | 32 | #define quarter(a,b,c,d) \ 33 | a += b; t = d^a; d = ROTL32(t,16); \ 34 | c += d; t = b^c; b = ROTL32(t,12); \ 35 | a += b; t = d^a; d = ROTL32(t, 8); \ 36 | c += d; t = b^c; b = ROTL32(t, 7); 37 | 38 | for (; rounds; rounds -= 2) { 39 | quarter( x0, x4, x8,x12) 40 | quarter( x1, x5, x9,x13) 41 | quarter( x2, x6,x10,x14) 42 | quarter( x3, x7,x11,x15) 43 | quarter( x0, x5,x10,x15) 44 | quarter( x1, x6,x11,x12) 45 | quarter( x2, x7, x8,x13) 46 | quarter( x3, x4, x9,x14) 47 | } 48 | 49 | state[0] += x0; 50 | state[1] += x1; 51 | state[2] += x2; 52 | state[3] += x3; 53 | state[4] += x4; 54 | state[5] += x5; 55 | state[6] += x6; 56 | state[7] += x7; 57 | state[8] += x8; 58 | state[9] += x9; 59 | state[10] += x10; 60 | state[11] += x11; 61 | state[12] += x12; 62 | state[13] += x13; 63 | state[14] += x14; 64 | state[15] += x15; 65 | 66 | #undef quarter 67 | } 68 | 69 | #endif -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-mix_salsa.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_SALSA_INCLUDED) 2 | 3 | #undef SCRYPT_MIX 4 | #define SCRYPT_MIX "Salsa20/8 Ref" 5 | 6 | #undef SCRYPT_SALSA_INCLUDED 7 | #define SCRYPT_SALSA_INCLUDED 8 | #define SCRYPT_SALSA_BASIC 9 | 10 | static void 11 | salsa_core_basic(uint32_t state[16]) { 12 | size_t rounds = 8; 13 | uint32_t x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,t; 14 | 15 | x0 = state[0]; 16 | x1 = state[1]; 17 | x2 = state[2]; 18 | x3 = state[3]; 19 | x4 = state[4]; 20 | x5 = state[5]; 21 | x6 = state[6]; 22 | x7 = state[7]; 23 | x8 = state[8]; 24 | x9 = state[9]; 25 | x10 = state[10]; 26 | x11 = state[11]; 27 | x12 = state[12]; 28 | x13 = state[13]; 29 | x14 = state[14]; 30 | x15 = state[15]; 31 | 32 | #define quarter(a,b,c,d) \ 33 | t = a+d; t = ROTL32(t, 7); b ^= t; \ 34 | t = b+a; t = ROTL32(t, 9); c ^= t; \ 35 | t = c+b; t = ROTL32(t, 13); d ^= t; \ 36 | t = d+c; t = ROTL32(t, 18); a ^= t; \ 37 | 38 | for (; rounds; rounds -= 2) { 39 | quarter( x0, x4, x8,x12) 40 | quarter( x5, x9,x13, x1) 41 | quarter(x10,x14, x2, x6) 42 | quarter(x15, x3, x7,x11) 43 | quarter( x0, x1, x2, x3) 44 | quarter( x5, x6, x7, x4) 45 | quarter(x10,x11, x8, x9) 46 | quarter(x15,x12,x13,x14) 47 | } 48 | 49 | state[0] += x0; 50 | state[1] += x1; 51 | state[2] += x2; 52 | state[3] += x3; 53 | state[4] += x4; 54 | state[5] += x5; 55 | state[6] += x6; 56 | state[7] += x7; 57 | state[8] += x8; 58 | state[9] += x9; 59 | state[10] += x10; 60 | state[11] += x11; 61 | state[12] += x12; 62 | state[13] += x13; 63 | state[14] += x14; 64 | state[15] += x15; 65 | 66 | #undef quarter 67 | } 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/c_groestl.h: -------------------------------------------------------------------------------- 1 | #ifndef __hash_h 2 | #define __hash_h 3 | /* 4 | #include "crypto_uint8.h" 5 | #include "crypto_uint32.h" 6 | #include "crypto_uint64.h" 7 | #include "crypto_hash.h" 8 | 9 | typedef crypto_uint8 uint8_t; 10 | typedef crypto_uint32 uint32_t; 11 | typedef crypto_uint64 uint64_t; 12 | */ 13 | #include 14 | 15 | #include "hash.h" 16 | 17 | /* some sizes (number of bytes) */ 18 | #define ROWS 8 19 | #define LENGTHFIELDLEN ROWS 20 | #define COLS512 8 21 | 22 | #define SIZE512 (ROWS*COLS512) 23 | 24 | #define ROUNDS512 10 25 | #define HASH_BIT_LEN 256 26 | 27 | #define ROTL32(v, n) ((((v)<<(n))|((v)>>(32-(n))))&li_32(ffffffff)) 28 | 29 | 30 | #define li_32(h) 0x##h##u 31 | #define EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n))) 32 | #define u32BIG(a) \ 33 | ((ROTL32(a,8) & li_32(00FF00FF)) | \ 34 | (ROTL32(a,24) & li_32(FF00FF00))) 35 | 36 | 37 | /* NIST API begin */ 38 | typedef struct { 39 | uint32_t chaining[SIZE512/sizeof(uint32_t)]; /* actual state */ 40 | uint32_t block_counter1, 41 | block_counter2; /* message block counter(s) */ 42 | BitSequence buffer[SIZE512]; /* data buffer */ 43 | int buf_ptr; /* data buffer pointer */ 44 | int bits_in_last_byte; /* no. of message bits in last byte of 45 | data buffer */ 46 | } groestlHashState; 47 | 48 | /*void Init(hashState*); 49 | void Update(hashState*, const BitSequence*, DataLength); 50 | void Final(hashState*, BitSequence*); */ 51 | void groestl(const BitSequence*, DataLength, BitSequence*); 52 | /* NIST API end */ 53 | 54 | /* 55 | int crypto_hash(unsigned char *out, 56 | const unsigned char *in, 57 | unsigned long long len); 58 | */ 59 | 60 | #endif /* __hash_h */ 61 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/hash-ops.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #pragma once 6 | 7 | #if !defined(__cplusplus) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "int-util.h" 15 | 16 | static inline void *padd(void *p, size_t i) { 17 | return (char *) p + i; 18 | } 19 | 20 | static inline const void *cpadd(const void *p, size_t i) { 21 | return (const char *) p + i; 22 | } 23 | 24 | static inline void place_length(uint8_t *buffer, size_t bufsize, size_t length) { 25 | if (sizeof(size_t) == 4) { 26 | *(uint32_t *) padd(buffer, bufsize - 4) = swap32be(length); 27 | } else { 28 | *(uint64_t *) padd(buffer, bufsize - 8) = swap64be(length); 29 | } 30 | } 31 | 32 | #pragma pack(push, 1) 33 | union hash_state { 34 | uint8_t b[200]; 35 | uint64_t w[25]; 36 | }; 37 | #pragma pack(pop) 38 | 39 | void hash_permutation(union hash_state *state); 40 | void hash_process(union hash_state *state, const uint8_t *buf, size_t count); 41 | 42 | #endif 43 | 44 | enum { 45 | HASH_SIZE = 32, 46 | HASH_DATA_AREA = 136 47 | }; 48 | 49 | void cn_fast_hash(const void *data, size_t length, char *hash); 50 | void cn_slow_hash(const void *data, size_t length, char *hash); 51 | 52 | void hash_extra_blake(const void *data, size_t length, char *hash); 53 | void hash_extra_groestl(const void *data, size_t length, char *hash); 54 | void hash_extra_jh(const void *data, size_t length, char *hash); 55 | void hash_extra_skein(const void *data, size_t length, char *hash); 56 | 57 | void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash); 58 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-hash.h: -------------------------------------------------------------------------------- 1 | #if defined(SCRYPT_BLAKE512) 2 | #include "scrypt-jane-hash_blake512.h" 3 | #elif defined(SCRYPT_BLAKE256) 4 | #include "scrypt-jane-hash_blake256.h" 5 | #elif defined(SCRYPT_SHA512) 6 | #include "scrypt-jane-hash_sha512.h" 7 | #elif defined(SCRYPT_SHA256) 8 | #include "scrypt-jane-hash_sha256.h" 9 | #elif defined(SCRYPT_SKEIN512) 10 | #include "scrypt-jane-hash_skein512.h" 11 | #elif defined(SCRYPT_KECCAK512) || defined(SCRYPT_KECCAK256) 12 | #include "scrypt-jane-hash_keccak.h" 13 | #else 14 | #define SCRYPT_HASH "ERROR" 15 | #define SCRYPT_HASH_BLOCK_SIZE 64 16 | #define SCRYPT_HASH_DIGEST_SIZE 64 17 | typedef struct scrypt_hash_state_t { size_t dummy; } scrypt_hash_state; 18 | typedef uint8_t scrypt_hash_digest[SCRYPT_HASH_DIGEST_SIZE]; 19 | static void scrypt_hash_init(scrypt_hash_state *S) {} 20 | static void scrypt_hash_update(scrypt_hash_state *S, const uint8_t *in, size_t inlen) {} 21 | static void scrypt_hash_finish(scrypt_hash_state *S, uint8_t *hash) {} 22 | static const uint8_t scrypt_test_hash_expected[SCRYPT_HASH_DIGEST_SIZE] = {0}; 23 | #error must define a hash function! 24 | #endif 25 | 26 | #include "scrypt-jane-pbkdf2.h" 27 | 28 | #define SCRYPT_TEST_HASH_LEN 257 /* (2 * largest block size) + 1 */ 29 | 30 | static int 31 | scrypt_test_hash() { 32 | scrypt_hash_state st; 33 | scrypt_hash_digest hash, final; 34 | uint8_t msg[SCRYPT_TEST_HASH_LEN]; 35 | size_t i; 36 | 37 | for (i = 0; i < SCRYPT_TEST_HASH_LEN; i++) 38 | msg[i] = (uint8_t)i; 39 | 40 | scrypt_hash_init(&st); 41 | for (i = 0; i < SCRYPT_TEST_HASH_LEN + 1; i++) { 42 | scrypt_hash(hash, msg, i); 43 | scrypt_hash_update(&st, hash, sizeof(hash)); 44 | } 45 | scrypt_hash_finish(&st, final); 46 | return scrypt_verify(final, scrypt_test_hash_expected, SCRYPT_HASH_DIGEST_SIZE); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if WANT_JANSSON 3 | JANSSON_INCLUDES= -I$(top_srcdir)/compat/jansson 4 | else 5 | JANSSON_INCLUDES= 6 | endif 7 | 8 | EXTRA_DIST = example-cfg.json nomacro.pl 9 | 10 | SUBDIRS = compat 11 | 12 | INCLUDES = $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) 13 | 14 | bin_PROGRAMS = minerd 15 | 16 | dist_man_MANS = minerd.1 17 | 18 | minerd_SOURCES = elist.h \ 19 | miner.h \ 20 | compat.h \ 21 | cpu-miner.c \ 22 | util.c \ 23 | sha2.c \ 24 | scrypt.c \ 25 | keccak.c \ 26 | heavy.c \ 27 | quark.c \ 28 | skein.c \ 29 | ink.c \ 30 | blake.c \ 31 | cryptonight.c \ 32 | fresh.c \ 33 | x11.c \ 34 | x13.c \ 35 | x14.c \ 36 | x15.c \ 37 | sha3/sph_keccak.c \ 38 | sha3/sph_hefty1.c \ 39 | sha3/sph_groestl.c \ 40 | sha3/sph_skein.c \ 41 | sha3/sph_bmw.c \ 42 | sha3/sph_jh.c \ 43 | sha3/sph_shavite.c \ 44 | sha3/sph_blake.c \ 45 | sha3/sph_luffa.c \ 46 | sha3/sph_cubehash.c \ 47 | sha3/sph_simd.c \ 48 | sha3/sph_echo.c \ 49 | sha3/sph_hamsi.c \ 50 | sha3/sph_fugue.c \ 51 | sha3/sph_shabal.c \ 52 | sha3/sph_whirlpool.c \ 53 | crypto/oaes_lib.c \ 54 | crypto/c_keccak.c \ 55 | crypto/c_groestl.c \ 56 | crypto/c_blake256.c \ 57 | crypto/c_jh.c \ 58 | crypto/c_skein.c \ 59 | crypto/hash.c \ 60 | crypto/aesb.c 61 | if USE_ASM 62 | if ARCH_x86 63 | minerd_SOURCES += sha2-x86.S scrypt-x86.S aesb-x86.S crypto/aesb-x86-impl.c 64 | endif 65 | if ARCH_x86_64 66 | minerd_SOURCES += sha2-x64.S scrypt-x64.S aesb-x64.S 67 | endif 68 | if ARCH_ARM 69 | minerd_SOURCES += sha2-arm.S scrypt-arm.S aesb-arm.S crypto/aesb-x86-impl.c 70 | endif 71 | endif 72 | 73 | minerd_LDFLAGS = $(PTHREAD_FLAGS) 74 | minerd_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ 75 | minerd_CPPFLAGS = @LIBCURL_CPPFLAGS@ 76 | minerd_CFLAGS = -Ofast -flto -fuse-linker-plugin 77 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/sha3/sph_fugue.h: -------------------------------------------------------------------------------- 1 | #ifndef SPH_FUGUE_H__ 2 | #define SPH_FUGUE_H__ 3 | 4 | #include 5 | #include "sph_types.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C"{ 9 | #endif 10 | 11 | #define SPH_SIZE_fugue224 224 12 | 13 | #define SPH_SIZE_fugue256 256 14 | 15 | #define SPH_SIZE_fugue384 384 16 | 17 | #define SPH_SIZE_fugue512 512 18 | 19 | typedef struct { 20 | #ifndef DOXYGEN_IGNORE 21 | sph_u32 partial; 22 | unsigned partial_len; 23 | unsigned round_shift; 24 | sph_u32 S[36]; 25 | #if SPH_64 26 | sph_u64 bit_count; 27 | #else 28 | sph_u32 bit_count_high, bit_count_low; 29 | #endif 30 | #endif 31 | } sph_fugue_context; 32 | 33 | typedef sph_fugue_context sph_fugue224_context; 34 | 35 | typedef sph_fugue_context sph_fugue256_context; 36 | 37 | typedef sph_fugue_context sph_fugue384_context; 38 | 39 | typedef sph_fugue_context sph_fugue512_context; 40 | 41 | void sph_fugue224_init(void *cc); 42 | 43 | void sph_fugue224(void *cc, const void *data, size_t len); 44 | 45 | void sph_fugue224_close(void *cc, void *dst); 46 | 47 | void sph_fugue224_addbits_and_close( 48 | void *cc, unsigned ub, unsigned n, void *dst); 49 | 50 | void sph_fugue256_init(void *cc); 51 | 52 | void sph_fugue256(void *cc, const void *data, size_t len); 53 | 54 | void sph_fugue256_close(void *cc, void *dst); 55 | 56 | void sph_fugue256_addbits_and_close( 57 | void *cc, unsigned ub, unsigned n, void *dst); 58 | 59 | void sph_fugue384_init(void *cc); 60 | 61 | void sph_fugue384(void *cc, const void *data, size_t len); 62 | 63 | void sph_fugue384_close(void *cc, void *dst); 64 | 65 | void sph_fugue384_addbits_and_close( 66 | void *cc, unsigned ub, unsigned n, void *dst); 67 | 68 | void sph_fugue512_init(void *cc); 69 | 70 | void sph_fugue512(void *cc, const void *data, size_t len); 71 | 72 | void sph_fugue512_close(void *cc, void *dst); 73 | 74 | void sph_fugue512_addbits_and_close( 75 | void *cc, unsigned ub, unsigned n, void *dst); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/c_skein.h: -------------------------------------------------------------------------------- 1 | #ifndef _SKEIN_H_ 2 | #define _SKEIN_H_ 1 3 | /************************************************************************** 4 | ** 5 | ** Interface declarations and internal definitions for Skein hashing. 6 | ** 7 | ** Source code author: Doug Whiting, 2008. 8 | ** 9 | ** This algorithm and source code is released to the public domain. 10 | ** 11 | *************************************************************************** 12 | ** 13 | ** The following compile-time switches may be defined to control some 14 | ** tradeoffs between speed, code size, error checking, and security. 15 | ** 16 | ** The "default" note explains what happens when the switch is not defined. 17 | ** 18 | ** SKEIN_DEBUG -- make callouts from inside Skein code 19 | ** to examine/display intermediate values. 20 | ** [default: no callouts (no overhead)] 21 | ** 22 | ** SKEIN_ERR_CHECK -- how error checking is handled inside Skein 23 | ** code. If not defined, most error checking 24 | ** is disabled (for performance). Otherwise, 25 | ** the switch value is interpreted as: 26 | ** 0: use assert() to flag errors 27 | ** 1: return SKEIN_FAIL to flag errors 28 | ** 29 | ***************************************************************************/ 30 | #include "skein_port.h" /* get platform-specific definitions */ 31 | 32 | typedef enum 33 | { 34 | SKEIN_SUCCESS = 0, /* return codes from Skein calls */ 35 | SKEIN_FAIL = 1, 36 | SKEIN_BAD_HASHLEN = 2 37 | } 38 | SkeinHashReturn; 39 | 40 | typedef size_t SkeinDataLength; /* bit count type */ 41 | typedef u08b_t SkeinBitSequence; /* bit stream type */ 42 | 43 | /* "all-in-one" call */ 44 | SkeinHashReturn skein_hash(int hashbitlen, const SkeinBitSequence *data, 45 | SkeinDataLength databitlen, SkeinBitSequence *hashval); 46 | 47 | #endif /* ifndef _SKEIN_H_ */ 48 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/oaes_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_CONFIG_H 32 | #define _OAES_CONFIG_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | //#ifndef OAES_HAVE_ISAAC 39 | //#define OAES_HAVE_ISAAC 1 40 | //#endif // OAES_HAVE_ISAAC 41 | 42 | //#ifndef OAES_DEBUG 43 | //#define OAES_DEBUG 0 44 | //#endif // OAES_DEBUG 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif // _OAES_CONFIG_H 51 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/skein.c: -------------------------------------------------------------------------------- 1 | #include "cpuminer-config.h" 2 | #include "miner.h" 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "sha3/sph_skein.h" 10 | 11 | static void skeinhash(void *state, const void *input) 12 | { 13 | sph_skein512_context ctx_skein; 14 | static unsigned char pblank[1]; 15 | 16 | uint32_t mask = 8; 17 | uint32_t zero = 0; 18 | 19 | //these uint512 in the c++ source of the client are backed by an array of uint32 20 | uint32_t hashA[16], hashB[16]; 21 | 22 | sph_skein512_init(&ctx_skein); 23 | sph_skein512 (&ctx_skein, input, 80); //6 24 | sph_skein512_close(&ctx_skein, hashA); //7 25 | 26 | SHA256_CTX sha256; 27 | SHA256_Init(&sha256); 28 | SHA256_Update(&sha256, hashA, 64); 29 | SHA256_Final((unsigned char*) hashB, &sha256); 30 | 31 | memcpy(state, hashB, 32); 32 | 33 | 34 | /* int ii; 35 | printf("result: "); 36 | for (ii=0; ii < 32; ii++) 37 | { 38 | printf ("%.2x",((uint8_t*)state)[ii]); 39 | }; 40 | printf ("\n"); 41 | */ 42 | } 43 | 44 | int scanhash_skein(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 45 | uint32_t max_nonce, uint64_t *hashes_done) 46 | { 47 | uint32_t n = pdata[19] - 1; 48 | const uint32_t first_nonce = pdata[19]; 49 | const uint32_t Htarg = ptarget[7]; 50 | 51 | uint32_t hash64[8] __attribute__((aligned(32))); 52 | uint32_t endiandata[32]; 53 | 54 | //char testdata[] = {"\x70\x00\x00\x00\x5d\x38\x5b\xa1\x14\xd0\x79\x97\x0b\x29\xa9\x41\x8f\xd0\x54\x9e\x7d\x68\xa9\x5c\x7f\x16\x86\x21\xa3\x14\x20\x10\x00\x00\x00\x00\x57\x85\x86\xd1\x49\xfd\x07\xb2\x2f\x3a\x8a\x34\x7c\x51\x6d\xe7\x05\x2f\x03\x4d\x2b\x76\xff\x68\xe0\xd6\xec\xff\x9b\x77\xa4\x54\x89\xe3\xfd\x51\x17\x32\x01\x1d\xf0\x73\x10\x00"}; 55 | 56 | //we need bigendian data... 57 | //lessons learned: do NOT endianchange directly in pdata, this will all proof-of-works be considered as stale from minerd.... 58 | int kk=0; 59 | for (; kk < 32; kk++) 60 | { 61 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 62 | }; 63 | 64 | do { 65 | pdata[19] = ++n; 66 | be32enc(&endiandata[19], n); 67 | skeinhash(hash64, &endiandata); 68 | if (((hash64[7]&0xFFFFFF00)==0) && 69 | fulltest(hash64, ptarget)) { 70 | *hashes_done = n - first_nonce + 1; 71 | return true; 72 | } 73 | } while (n < max_nonce && !work_restart[thr_id].restart); 74 | 75 | *hashes_done = n - first_nonce + 1; 76 | pdata[19] = n; 77 | return 0; 78 | } -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_DLFCN_H 1 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #define HAVE_INTTYPES_H 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_MEMORY_H 1 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_STDINT_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_STDLIB_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_STRINGS_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_STRING_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_SYS_STAT_H 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_SYS_TYPES_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_UNISTD_H 1 33 | 34 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 35 | */ 36 | #define LT_OBJDIR ".libs/" 37 | 38 | /* Name of package */ 39 | #define PACKAGE "jansson" 40 | 41 | /* Define to the address where bug reports for this package should be sent. */ 42 | #define PACKAGE_BUGREPORT "petri@digip.org" 43 | 44 | /* Define to the full name of this package. */ 45 | #define PACKAGE_NAME "jansson" 46 | 47 | /* Define to the full name and version of this package. */ 48 | #define PACKAGE_STRING "jansson 1.3" 49 | 50 | /* Define to the one symbol short name of this package. */ 51 | #define PACKAGE_TARNAME "jansson" 52 | 53 | /* Define to the home page for this package. */ 54 | #define PACKAGE_URL "" 55 | 56 | /* Define to the version of this package. */ 57 | #define PACKAGE_VERSION "1.3" 58 | 59 | /* Define to 1 if you have the ANSI C header files. */ 60 | #define STDC_HEADERS 1 61 | 62 | /* Version number of package */ 63 | #define VERSION "1.3" 64 | 65 | /* Define to `__inline__' or `__inline' if that's what the C compiler 66 | calls it, or to nothing if 'inline' is not supported under any name. */ 67 | #ifndef __cplusplus 68 | /* #undef inline */ 69 | #endif 70 | 71 | /* Define to the type of a signed integer type of width exactly 32 bits if 72 | such a type exists and the standard includes do not define it. */ 73 | /* #undef int32_t */ 74 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_DLFCN_H 1 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #define HAVE_INTTYPES_H 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_MEMORY_H 1 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_STDINT_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_STDLIB_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_STRINGS_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_STRING_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_SYS_STAT_H 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_SYS_TYPES_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_UNISTD_H 1 33 | 34 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 35 | */ 36 | #define LT_OBJDIR ".libs/" 37 | 38 | /* Name of package */ 39 | #define PACKAGE "jansson" 40 | 41 | /* Define to the address where bug reports for this package should be sent. */ 42 | #define PACKAGE_BUGREPORT "petri@digip.org" 43 | 44 | /* Define to the full name of this package. */ 45 | #define PACKAGE_NAME "jansson" 46 | 47 | /* Define to the full name and version of this package. */ 48 | #define PACKAGE_STRING "jansson 1.3" 49 | 50 | /* Define to the one symbol short name of this package. */ 51 | #define PACKAGE_TARNAME "jansson" 52 | 53 | /* Define to the home page for this package. */ 54 | #define PACKAGE_URL "" 55 | 56 | /* Define to the version of this package. */ 57 | #define PACKAGE_VERSION "1.3" 58 | 59 | /* Define to 1 if you have the ANSI C header files. */ 60 | #define STDC_HEADERS 1 61 | 62 | /* Version number of package */ 63 | #define VERSION "1.3" 64 | 65 | /* Define to `__inline__' or `__inline' if that's what the C compiler 66 | calls it, or to nothing if 'inline' is not supported under any name. */ 67 | #ifndef __cplusplus 68 | /* #undef inline */ 69 | #endif 70 | 71 | /* Define to the type of a signed integer type of width exactly 32 bits if 72 | such a type exists and the standard includes do not define it. */ 73 | /* #undef int32_t */ 74 | -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/strbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #define _GNU_SOURCE 9 | #include 10 | #include 11 | #include "strbuffer.h" 12 | #include "util.h" 13 | 14 | #define STRBUFFER_MIN_SIZE 16 15 | #define STRBUFFER_FACTOR 2 16 | 17 | int strbuffer_init(strbuffer_t *strbuff) 18 | { 19 | strbuff->size = STRBUFFER_MIN_SIZE; 20 | strbuff->length = 0; 21 | 22 | strbuff->value = malloc(strbuff->size); 23 | if(!strbuff->value) 24 | return -1; 25 | 26 | /* initialize to empty */ 27 | strbuff->value[0] = '\0'; 28 | return 0; 29 | } 30 | 31 | void strbuffer_close(strbuffer_t *strbuff) 32 | { 33 | free(strbuff->value); 34 | strbuff->size = 0; 35 | strbuff->length = 0; 36 | strbuff->value = NULL; 37 | } 38 | 39 | void strbuffer_clear(strbuffer_t *strbuff) 40 | { 41 | strbuff->length = 0; 42 | strbuff->value[0] = '\0'; 43 | } 44 | 45 | const char *strbuffer_value(const strbuffer_t *strbuff) 46 | { 47 | return strbuff->value; 48 | } 49 | 50 | char *strbuffer_steal_value(strbuffer_t *strbuff) 51 | { 52 | char *result = strbuff->value; 53 | strbuffer_init(strbuff); 54 | return result; 55 | } 56 | 57 | int strbuffer_append(strbuffer_t *strbuff, const char *string) 58 | { 59 | return strbuffer_append_bytes(strbuff, string, strlen(string)); 60 | } 61 | 62 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte) 63 | { 64 | return strbuffer_append_bytes(strbuff, &byte, 1); 65 | } 66 | 67 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size) 68 | { 69 | if(strbuff->length + size >= strbuff->size) 70 | { 71 | strbuff->size = max(strbuff->size * STRBUFFER_FACTOR, 72 | strbuff->length + size + 1); 73 | 74 | strbuff->value = realloc(strbuff->value, strbuff->size); 75 | if(!strbuff->value) 76 | return -1; 77 | } 78 | 79 | memcpy(strbuff->value + strbuff->length, data, size); 80 | strbuff->length += size; 81 | strbuff->value[strbuff->length] = '\0'; 82 | 83 | return 0; 84 | } 85 | 86 | char strbuffer_pop(strbuffer_t *strbuff) 87 | { 88 | if(strbuff->length > 0) { 89 | char c = strbuff->value[--strbuff->length]; 90 | strbuff->value[strbuff->length] = '\0'; 91 | return c; 92 | } 93 | else 94 | return '\0'; 95 | } 96 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/strbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #define _GNU_SOURCE 9 | #include 10 | #include 11 | #include "strbuffer.h" 12 | #include "util.h" 13 | 14 | #define STRBUFFER_MIN_SIZE 16 15 | #define STRBUFFER_FACTOR 2 16 | 17 | int strbuffer_init(strbuffer_t *strbuff) 18 | { 19 | strbuff->size = STRBUFFER_MIN_SIZE; 20 | strbuff->length = 0; 21 | 22 | strbuff->value = malloc(strbuff->size); 23 | if(!strbuff->value) 24 | return -1; 25 | 26 | /* initialize to empty */ 27 | strbuff->value[0] = '\0'; 28 | return 0; 29 | } 30 | 31 | void strbuffer_close(strbuffer_t *strbuff) 32 | { 33 | free(strbuff->value); 34 | strbuff->size = 0; 35 | strbuff->length = 0; 36 | strbuff->value = NULL; 37 | } 38 | 39 | void strbuffer_clear(strbuffer_t *strbuff) 40 | { 41 | strbuff->length = 0; 42 | strbuff->value[0] = '\0'; 43 | } 44 | 45 | const char *strbuffer_value(const strbuffer_t *strbuff) 46 | { 47 | return strbuff->value; 48 | } 49 | 50 | char *strbuffer_steal_value(strbuffer_t *strbuff) 51 | { 52 | char *result = strbuff->value; 53 | strbuffer_init(strbuff); 54 | return result; 55 | } 56 | 57 | int strbuffer_append(strbuffer_t *strbuff, const char *string) 58 | { 59 | return strbuffer_append_bytes(strbuff, string, strlen(string)); 60 | } 61 | 62 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte) 63 | { 64 | return strbuffer_append_bytes(strbuff, &byte, 1); 65 | } 66 | 67 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size) 68 | { 69 | if(strbuff->length + size >= strbuff->size) 70 | { 71 | strbuff->size = max(strbuff->size * STRBUFFER_FACTOR, 72 | strbuff->length + size + 1); 73 | 74 | strbuff->value = realloc(strbuff->value, strbuff->size); 75 | if(!strbuff->value) 76 | return -1; 77 | } 78 | 79 | memcpy(strbuff->value + strbuff->length, data, size); 80 | strbuff->length += size; 81 | strbuff->value[strbuff->length] = '\0'; 82 | 83 | return 0; 84 | } 85 | 86 | char strbuffer_pop(strbuffer_t *strbuff) 87 | { 88 | if(strbuff->length > 0) { 89 | char c = strbuff->value[--strbuff->length]; 90 | strbuff->value[strbuff->length] = '\0'; 91 | return c; 92 | } 93 | else 94 | return '\0'; 95 | } 96 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-romix-basic.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 2 | /* function type returned by scrypt_getROMix, used with cpu detection */ 3 | typedef void (FASTCALL *scrypt_ROMixfn)(scrypt_mix_word_t *X/*[chunkWords]*/, scrypt_mix_word_t *Y/*[chunkWords]*/, scrypt_mix_word_t *V/*[chunkWords * N]*/, uint32_t N, uint32_t r); 4 | #endif 5 | 6 | /* romix pre/post nop function */ 7 | static void STDCALL 8 | scrypt_romix_nop(scrypt_mix_word_t *blocks, size_t nblocks) { 9 | } 10 | 11 | /* romix pre/post endian conversion function */ 12 | static void STDCALL 13 | scrypt_romix_convert_endian(scrypt_mix_word_t *blocks, size_t nblocks) { 14 | #if !defined(CPU_LE) 15 | static const union { uint8_t b[2]; uint16_t w; } endian_test = {{1,0}}; 16 | size_t i; 17 | if (endian_test.w == 0x100) { 18 | nblocks *= SCRYPT_BLOCK_WORDS; 19 | for (i = 0; i < nblocks; i++) { 20 | SCRYPT_WORD_ENDIAN_SWAP(blocks[i]); 21 | } 22 | } 23 | #endif 24 | } 25 | 26 | /* chunkmix test function */ 27 | typedef void (STDCALL *chunkmixfn)(scrypt_mix_word_t *Bout/*[chunkWords]*/, scrypt_mix_word_t *Bin/*[chunkWords]*/, scrypt_mix_word_t *Bxor/*[chunkWords]*/, uint32_t r); 28 | typedef void (STDCALL *blockfixfn)(scrypt_mix_word_t *blocks, size_t nblocks); 29 | 30 | static int 31 | scrypt_test_mix_instance(chunkmixfn mixfn, blockfixfn prefn, blockfixfn postfn, const uint8_t expected[16]) { 32 | /* r = 2, (2 * r) = 4 blocks in a chunk, 4 * SCRYPT_BLOCK_WORDS total */ 33 | const uint32_t r = 2, blocks = 2 * r, words = blocks * SCRYPT_BLOCK_WORDS; 34 | scrypt_mix_word_t MM16 chunk[2][4 * SCRYPT_BLOCK_WORDS], v; 35 | uint8_t final[16]; 36 | size_t i; 37 | 38 | for (i = 0; i < words; i++) { 39 | v = (scrypt_mix_word_t)i; 40 | v = (v << 8) | v; 41 | v = (v << 16) | v; 42 | chunk[0][i] = v; 43 | } 44 | 45 | prefn(chunk[0], blocks); 46 | mixfn(chunk[1], chunk[0], NULL, r); 47 | postfn(chunk[1], blocks); 48 | 49 | /* grab the last 16 bytes of the final block */ 50 | for (i = 0; i < 16; i += sizeof(scrypt_mix_word_t)) { 51 | SCRYPT_WORDTO8_LE(final + i, chunk[1][words - (16 / sizeof(scrypt_mix_word_t)) + (i / sizeof(scrypt_mix_word_t))]); 52 | } 53 | 54 | return scrypt_verify(expected, final, 16); 55 | } 56 | 57 | /* returns a pointer to item i, where item is len scrypt_mix_word_t's long */ 58 | static scrypt_mix_word_t * 59 | scrypt_item(scrypt_mix_word_t *base, scrypt_mix_word_t i, scrypt_mix_word_t len) { 60 | return base + (i * len); 61 | } 62 | 63 | /* returns a pointer to block i */ 64 | static scrypt_mix_word_t * 65 | scrypt_block(scrypt_mix_word_t *base, scrypt_mix_word_t i) { 66 | return base + (i * SCRYPT_BLOCK_WORDS); 67 | } 68 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/sha3/sph_hefty1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HEFTY1 cryptographic hash function 3 | * 4 | * Copyright (c) 2014, dbcc14 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | * 27 | * The views and conclusions contained in the software and documentation are those 28 | * of the authors and should not be interpreted as representing official policies, 29 | * either expressed or implied, of the FreeBSD Project. 30 | */ 31 | 32 | #ifndef __HEFTY1_H__ 33 | #define __HEFTY1_H__ 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #ifndef WIN32 40 | #include 41 | #endif 42 | 43 | #include 44 | 45 | #define HEFTY1_DIGEST_BYTES 32 46 | #define HEFTY1_BLOCK_BYTES 64 47 | #define HEFTY1_STATE_WORDS 8 48 | #define HEFTY1_SPONGE_WORDS 4 49 | 50 | typedef struct HEFTY1_CTX { 51 | uint32_t h[HEFTY1_STATE_WORDS]; 52 | uint8_t block[HEFTY1_BLOCK_BYTES]; 53 | uint64_t written; 54 | uint32_t sponge[HEFTY1_SPONGE_WORDS]; 55 | } HEFTY1_CTX; 56 | 57 | void HEFTY1_Init(HEFTY1_CTX *cxt); 58 | void HEFTY1_Update(HEFTY1_CTX *cxt, const void *data, size_t len); 59 | void HEFTY1_Final(unsigned char *digest, HEFTY1_CTX *cxt); 60 | unsigned char* HEFTY1(const unsigned char *data, size_t len, unsigned char *digest); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* __HEFTY1_H__ */ -------------------------------------------------------------------------------- /cpuminer-newalgorithms/fresh.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_shavite.h" 9 | #include "sha3/sph_simd.h" 10 | #include "sha3/sph_echo.h" 11 | 12 | //#define DEBUG_ALGO 13 | 14 | inline void freshhash(void* output, const void* input, uint32_t len) 15 | { 16 | unsigned char hash[128]; // uint32_t hashA[16], hashB[16]; 17 | #define hashA hash 18 | #define hashB hash+64 19 | 20 | memset(hash, 0, 128); 21 | sph_shavite512_context ctx_shavite1; 22 | sph_simd512_context ctx_simd1; 23 | sph_echo512_context ctx_echo1; 24 | 25 | sph_shavite512_init(&ctx_shavite1); 26 | sph_shavite512(&ctx_shavite1, input, len); 27 | sph_shavite512_close(&ctx_shavite1, hashA); 28 | 29 | sph_simd512_init(&ctx_simd1); 30 | sph_simd512(&ctx_simd1, hashA, 64); 31 | sph_simd512_close(&ctx_simd1, hashB); 32 | 33 | sph_shavite512_init(&ctx_shavite1); 34 | sph_shavite512(&ctx_shavite1, hashB, 64); 35 | sph_shavite512_close(&ctx_shavite1, hashA); 36 | 37 | sph_simd512_init(&ctx_simd1); 38 | sph_simd512(&ctx_simd1, hashA, 64); 39 | sph_simd512_close(&ctx_simd1, hashB); 40 | 41 | sph_echo512_init(&ctx_echo1); 42 | sph_echo512(&ctx_echo1, hashB, 64); 43 | sph_echo512_close(&ctx_echo1, hashA); 44 | 45 | memcpy(output, hash, 32); 46 | } 47 | 48 | int scanhash_fresh(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 49 | uint32_t max_nonce, uint64_t *hashes_done) 50 | { 51 | uint32_t len = 80; 52 | 53 | uint32_t n = pdata[19] - 1; 54 | const uint32_t first_nonce = pdata[19]; 55 | const uint32_t Htarg = ptarget[7]; 56 | 57 | uint32_t hash64[8] __attribute__((aligned(32))); 58 | uint32_t endiandata[32]; 59 | 60 | uint64_t htmax[] = { 61 | 0, 62 | 0xF, 63 | 0xFF, 64 | 0xFFF, 65 | 0xFFFF, 66 | 0x10000000 67 | }; 68 | uint32_t masks[] = { 69 | 0xFFFFFFFF, 70 | 0xFFFFFFF0, 71 | 0xFFFFFF00, 72 | 0xFFFFF000, 73 | 0xFFFF0000, 74 | 0 75 | }; 76 | 77 | // we need bigendian data... 78 | for (int kk=0; kk < 32; kk++) { 79 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 80 | }; 81 | #ifdef DEBUG_ALGO 82 | if (Htarg != 0) 83 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 84 | #endif 85 | for (int m=0; m < sizeof(masks); m++) { 86 | if (Htarg <= htmax[m]) { 87 | uint32_t mask = masks[m]; 88 | do { 89 | pdata[19] = ++n; 90 | be32enc(&endiandata[19], n); 91 | freshhash(hash64, &endiandata, len); 92 | #ifndef DEBUG_ALGO 93 | if ((!(hash64[7] & mask)) && fulltest(hash64, ptarget)) { 94 | *hashes_done = n - first_nonce + 1; 95 | return true; 96 | } 97 | #else 98 | if (!(n % 0x1000) && !thr_id) printf("."); 99 | if (!(hash64[7] & mask)) { 100 | printf("[%d]",thr_id); 101 | if (fulltest(hash64, ptarget)) { 102 | *hashes_done = n - first_nonce + 1; 103 | return true; 104 | } 105 | } 106 | #endif 107 | } while (n < max_nonce && !work_restart[thr_id].restart); 108 | // see blake.c if else to understand the loop on htmax => mask 109 | break; 110 | } 111 | } 112 | 113 | *hashes_done = n - first_nonce + 1; 114 | pdata[19] = n; 115 | return 0; 116 | } 117 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-salsa.h: -------------------------------------------------------------------------------- 1 | #define SCRYPT_MIX_BASE "Salsa20/8" 2 | 3 | typedef uint32_t scrypt_mix_word_t; 4 | 5 | #define SCRYPT_WORDTO8_LE U32TO8_LE 6 | #define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP 7 | 8 | #define SCRYPT_BLOCK_BYTES 64 9 | #define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t)) 10 | 11 | /* must have these here in case block bytes is ever != 64 */ 12 | #include "scrypt-jane-romix-basic.h" 13 | 14 | #include "scrypt-jane-mix_salsa-avx.h" 15 | #include "scrypt-jane-mix_salsa-sse2.h" 16 | #include "scrypt-jane-mix_salsa.h" 17 | 18 | #if defined(SCRYPT_SALSA_AVX) 19 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx 20 | #define SCRYPT_ROMIX_FN scrypt_ROMix_avx 21 | #define SCRYPT_ROMIX_TANGLE_FN salsa_core_tangle_sse2 22 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa_core_tangle_sse2 23 | #include "scrypt-jane-romix-template.h" 24 | #endif 25 | 26 | #if defined(SCRYPT_SALSA_SSE2) 27 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse2 28 | #define SCRYPT_ROMIX_FN scrypt_ROMix_sse2 29 | #define SCRYPT_MIX_FN salsa_core_sse2 30 | #define SCRYPT_ROMIX_TANGLE_FN salsa_core_tangle_sse2 31 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa_core_tangle_sse2 32 | #include "scrypt-jane-romix-template.h" 33 | #endif 34 | 35 | /* cpu agnostic */ 36 | #define SCRYPT_ROMIX_FN scrypt_ROMix_basic 37 | #define SCRYPT_MIX_FN salsa_core_basic 38 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian 39 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian 40 | #include "scrypt-jane-romix-template.h" 41 | 42 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 43 | static scrypt_ROMixfn 44 | scrypt_getROMix() { 45 | size_t cpuflags = detect_cpu(); 46 | 47 | #if defined(SCRYPT_SALSA_AVX) 48 | if (cpuflags & cpu_avx) 49 | return scrypt_ROMix_avx; 50 | else 51 | #endif 52 | 53 | #if defined(SCRYPT_SALSA_SSE2) 54 | if (cpuflags & cpu_sse2) 55 | return scrypt_ROMix_sse2; 56 | else 57 | #endif 58 | 59 | return scrypt_ROMix_basic; 60 | } 61 | #endif 62 | 63 | 64 | #if defined(SCRYPT_TEST_SPEED) 65 | static size_t 66 | available_implementations() { 67 | size_t flags = 0; 68 | 69 | #if defined(SCRYPT_SALSA_AVX) 70 | flags |= cpu_avx; 71 | #endif 72 | 73 | #if defined(SCRYPT_SALSA_SSE2) 74 | flags |= cpu_sse2; 75 | #endif 76 | 77 | return flags; 78 | } 79 | #endif 80 | 81 | 82 | static int 83 | scrypt_test_mix() { 84 | static const uint8_t expected[16] = { 85 | 0x41,0x1f,0x2e,0xa3,0xab,0xa3,0x1a,0x34,0x87,0x1d,0x8a,0x1c,0x76,0xa0,0x27,0x66, 86 | }; 87 | 88 | int ret = 1; 89 | size_t cpuflags = detect_cpu(); 90 | 91 | #if defined(SCRYPT_SALSA_AVX) 92 | if (cpuflags & cpu_avx) 93 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, salsa_core_tangle_sse2, salsa_core_tangle_sse2, expected); 94 | #endif 95 | 96 | #if defined(SCRYPT_SALSA_SSE2) 97 | if (cpuflags & cpu_sse2) 98 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, salsa_core_tangle_sse2, salsa_core_tangle_sse2, expected); 99 | #endif 100 | 101 | #if defined(SCRYPT_SALSA_BASIC) 102 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected); 103 | #endif 104 | 105 | return ret; 106 | } 107 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-romix-template.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_HAVE_ROMIX) 2 | 3 | #if defined(SCRYPT_CHOOSE_COMPILETIME) 4 | #undef SCRYPT_ROMIX_FN 5 | #define SCRYPT_ROMIX_FN scrypt_ROMix 6 | #endif 7 | 8 | #undef SCRYPT_HAVE_ROMIX 9 | #define SCRYPT_HAVE_ROMIX 10 | 11 | #if !defined(SCRYPT_CHUNKMIX_FN) 12 | 13 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_basic 14 | 15 | /* 16 | Bout = ChunkMix(Bin) 17 | 18 | 2*r: number of blocks in the chunk 19 | */ 20 | static void STDCALL 21 | SCRYPT_CHUNKMIX_FN(scrypt_mix_word_t *Bout/*[chunkWords]*/, scrypt_mix_word_t *Bin/*[chunkWords]*/, scrypt_mix_word_t *Bxor/*[chunkWords]*/, uint32_t r) { 22 | scrypt_mix_word_t MM16 X[SCRYPT_BLOCK_WORDS], *block; 23 | uint32_t i, j, blocksPerChunk = r * 2, half = 0; 24 | 25 | /* 1: X = B_{2r - 1} */ 26 | block = scrypt_block(Bin, blocksPerChunk - 1); 27 | for (i = 0; i < SCRYPT_BLOCK_WORDS; i++) 28 | X[i] = block[i]; 29 | 30 | if (Bxor) { 31 | block = scrypt_block(Bxor, blocksPerChunk - 1); 32 | for (i = 0; i < SCRYPT_BLOCK_WORDS; i++) 33 | X[i] ^= block[i]; 34 | } 35 | 36 | /* 2: for i = 0 to 2r - 1 do */ 37 | for (i = 0; i < blocksPerChunk; i++, half ^= r) { 38 | /* 3: X = H(X ^ B_i) */ 39 | block = scrypt_block(Bin, i); 40 | for (j = 0; j < SCRYPT_BLOCK_WORDS; j++) 41 | X[j] ^= block[j]; 42 | 43 | if (Bxor) { 44 | block = scrypt_block(Bxor, i); 45 | for (j = 0; j < SCRYPT_BLOCK_WORDS; j++) 46 | X[j] ^= block[j]; 47 | } 48 | SCRYPT_MIX_FN(X); 49 | 50 | /* 4: Y_i = X */ 51 | /* 6: B'[0..r-1] = Y_even */ 52 | /* 6: B'[r..2r-1] = Y_odd */ 53 | block = scrypt_block(Bout, (i / 2) + half); 54 | for (j = 0; j < SCRYPT_BLOCK_WORDS; j++) 55 | block[j] = X[j]; 56 | } 57 | } 58 | #endif 59 | 60 | /* 61 | X = ROMix(X) 62 | 63 | X: chunk to mix 64 | Y: scratch chunk 65 | N: number of rounds 66 | V[N]: array of chunks to randomly index in to 67 | 2*r: number of blocks in a chunk 68 | */ 69 | 70 | static void NOINLINE FASTCALL 71 | SCRYPT_ROMIX_FN(scrypt_mix_word_t *X/*[chunkWords]*/, scrypt_mix_word_t *Y/*[chunkWords]*/, scrypt_mix_word_t *V/*[N * chunkWords]*/, uint32_t N, uint32_t r) { 72 | uint32_t i, j, chunkWords = SCRYPT_BLOCK_WORDS * r * 2; 73 | scrypt_mix_word_t *block = V; 74 | 75 | SCRYPT_ROMIX_TANGLE_FN(X, r * 2); 76 | 77 | /* 1: X = B */ 78 | /* implicit */ 79 | 80 | /* 2: for i = 0 to N - 1 do */ 81 | memcpy(block, X, chunkWords * sizeof(scrypt_mix_word_t)); 82 | for (i = 0; i < N - 1; i++, block += chunkWords) { 83 | /* 3: V_i = X */ 84 | /* 4: X = H(X) */ 85 | SCRYPT_CHUNKMIX_FN(block + chunkWords, block, NULL, r); 86 | } 87 | SCRYPT_CHUNKMIX_FN(X, block, NULL, r); 88 | 89 | /* 6: for i = 0 to N - 1 do */ 90 | for (i = 0; i < N; i += 2) { 91 | /* 7: j = Integerify(X) % N */ 92 | j = X[chunkWords - SCRYPT_BLOCK_WORDS] & (N - 1); 93 | 94 | /* 8: X = H(Y ^ V_j) */ 95 | SCRYPT_CHUNKMIX_FN(Y, X, scrypt_item(V, j, chunkWords), r); 96 | 97 | /* 7: j = Integerify(Y) % N */ 98 | j = Y[chunkWords - SCRYPT_BLOCK_WORDS] & (N - 1); 99 | 100 | /* 8: X = H(Y ^ V_j) */ 101 | SCRYPT_CHUNKMIX_FN(X, Y, scrypt_item(V, j, chunkWords), r); 102 | } 103 | 104 | /* 10: B' = X */ 105 | /* implicit */ 106 | 107 | SCRYPT_ROMIX_UNTANGLE_FN(X, r * 2); 108 | } 109 | 110 | #endif /* !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_HAVE_ROMIX) */ 111 | 112 | 113 | #undef SCRYPT_CHUNKMIX_FN 114 | #undef SCRYPT_ROMIX_FN 115 | #undef SCRYPT_MIX_FN 116 | #undef SCRYPT_ROMIX_TANGLE_FN 117 | #undef SCRYPT_ROMIX_UNTANGLE_FN 118 | 119 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/heavy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "miner.h" 6 | #include "sha3/sph_hefty1.h" 7 | #include "sha3/sph_keccak.h" 8 | #include "sha3/sph_blake.h" 9 | #include "sha3/sph_groestl.h" 10 | 11 | /* Combines top 64-bits from each hash into a single hash */ 12 | static void combine_hashes(uint32_t *out, uint32_t *hash1, uint32_t *hash2, uint32_t *hash3, uint32_t *hash4) 13 | { 14 | uint32_t *hash[4] = { hash1, hash2, hash3, hash4 }; 15 | 16 | /* Transpose first 64 bits of each hash into out */ 17 | memset(out, 0, 32); 18 | int bits = 0; 19 | for (unsigned int i = 7; i >= 6; i--) { 20 | for (uint32_t mask = 0x80000000; mask; mask >>= 1) { 21 | for (unsigned int k = 0; k < 4; k++) { 22 | out[(255 - bits)/32] <<= 1; 23 | if ((hash[k][i] & mask) != 0) 24 | out[(255 - bits)/32] |= 1; 25 | bits++; 26 | } 27 | } 28 | } 29 | } 30 | 31 | 32 | 33 | void heavycoin_hash(unsigned char* output, const unsigned char* input, int len) 34 | { 35 | unsigned char hash1[32]; 36 | HEFTY1(input, len, hash1); 37 | 38 | /* HEFTY1 is new, so take an extra security measure to eliminate 39 | * the possiblity of collisions: 40 | * 41 | * Hash(x) = SHA256(x + HEFTY1(x)) 42 | * 43 | * N.B. '+' is concatenation. 44 | */ 45 | unsigned char hash2[32];; 46 | SHA256_CTX ctx; 47 | SHA256_Init(&ctx); 48 | SHA256_Update(&ctx, input, len); 49 | SHA256_Update(&ctx, hash1, sizeof(hash1)); 50 | SHA256_Final(hash2, &ctx); 51 | 52 | /* Additional security: Do not rely on a single cryptographic hash 53 | * function. Instead, combine the outputs of 4 of the most secure 54 | * cryptographic hash functions-- SHA256, KECCAK512, GROESTL512 55 | * and BLAKE512. 56 | */ 57 | 58 | uint32_t hash3[16]; 59 | sph_keccak512_context keccakCtx; 60 | sph_keccak512_init(&keccakCtx); 61 | sph_keccak512(&keccakCtx, input, len); 62 | sph_keccak512(&keccakCtx, hash1, sizeof(hash1)); 63 | sph_keccak512_close(&keccakCtx, (void *)&hash3); 64 | 65 | uint32_t hash4[16]; 66 | sph_groestl512_context groestlCtx; 67 | sph_groestl512_init(&groestlCtx); 68 | sph_groestl512(&groestlCtx, input, len); 69 | sph_groestl512(&groestlCtx, hash1, sizeof(hash1)); 70 | sph_groestl512_close(&groestlCtx, (void *)&hash4); 71 | 72 | uint32_t hash5[16]; 73 | sph_blake512_context blakeCtx; 74 | sph_blake512_init(&blakeCtx); 75 | sph_blake512(&blakeCtx, input, len); 76 | sph_blake512(&blakeCtx, (unsigned char *)&hash1, sizeof(hash1)); 77 | sph_blake512_close(&blakeCtx, (void *)&hash5); 78 | 79 | uint32_t *final = (uint32_t *)output; 80 | combine_hashes(final, (uint32_t *)hash2, hash3, hash4, hash5); 81 | } 82 | 83 | int scanhash_heavy(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 84 | uint32_t max_nonce, uint64_t *hashes_done) 85 | { 86 | uint32_t hash[8]; 87 | uint32_t start_nonce = pdata[19]; 88 | 89 | do { 90 | heavycoin_hash((unsigned char *)hash, (unsigned char *)pdata, 80); 91 | 92 | if (hash[7] <= ptarget[7]) { 93 | if (fulltest(hash, ptarget)) { 94 | *hashes_done = pdata[19] - start_nonce; 95 | return 1; 96 | break; 97 | } 98 | } 99 | pdata[19]++; 100 | } while (pdata[19] < max_nonce && !work_restart[thr_id].restart); 101 | *hashes_done = pdata[19] - start_nonce; 102 | return 0; 103 | } -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-pbkdf2.h: -------------------------------------------------------------------------------- 1 | typedef struct scrypt_hmac_state_t { 2 | scrypt_hash_state inner, outer; 3 | } scrypt_hmac_state; 4 | 5 | 6 | static void 7 | scrypt_hash(scrypt_hash_digest hash, const uint8_t *m, size_t mlen) { 8 | scrypt_hash_state st; 9 | scrypt_hash_init(&st); 10 | scrypt_hash_update(&st, m, mlen); 11 | scrypt_hash_finish(&st, hash); 12 | } 13 | 14 | /* hmac */ 15 | static void 16 | scrypt_hmac_init(scrypt_hmac_state *st, const uint8_t *key, size_t keylen) { 17 | uint8_t pad[SCRYPT_HASH_BLOCK_SIZE] = {0}; 18 | size_t i; 19 | 20 | scrypt_hash_init(&st->inner); 21 | scrypt_hash_init(&st->outer); 22 | 23 | if (keylen <= SCRYPT_HASH_BLOCK_SIZE) { 24 | /* use the key directly if it's <= blocksize bytes */ 25 | memcpy(pad, key, keylen); 26 | } else { 27 | /* if it's > blocksize bytes, hash it */ 28 | scrypt_hash(pad, key, keylen); 29 | } 30 | 31 | /* inner = (key ^ 0x36) */ 32 | /* h(inner || ...) */ 33 | for (i = 0; i < SCRYPT_HASH_BLOCK_SIZE; i++) 34 | pad[i] ^= 0x36; 35 | scrypt_hash_update(&st->inner, pad, SCRYPT_HASH_BLOCK_SIZE); 36 | 37 | /* outer = (key ^ 0x5c) */ 38 | /* h(outer || ...) */ 39 | for (i = 0; i < SCRYPT_HASH_BLOCK_SIZE; i++) 40 | pad[i] ^= (0x5c ^ 0x36); 41 | scrypt_hash_update(&st->outer, pad, SCRYPT_HASH_BLOCK_SIZE); 42 | 43 | scrypt_ensure_zero(pad, sizeof(pad)); 44 | } 45 | 46 | static void 47 | scrypt_hmac_update(scrypt_hmac_state *st, const uint8_t *m, size_t mlen) { 48 | /* h(inner || m...) */ 49 | scrypt_hash_update(&st->inner, m, mlen); 50 | } 51 | 52 | static void 53 | scrypt_hmac_finish(scrypt_hmac_state *st, scrypt_hash_digest mac) { 54 | /* h(inner || m) */ 55 | scrypt_hash_digest innerhash; 56 | scrypt_hash_finish(&st->inner, innerhash); 57 | 58 | /* h(outer || h(inner || m)) */ 59 | scrypt_hash_update(&st->outer, innerhash, sizeof(innerhash)); 60 | scrypt_hash_finish(&st->outer, mac); 61 | 62 | scrypt_ensure_zero(st, sizeof(*st)); 63 | } 64 | 65 | static void 66 | scrypt_pbkdf2(const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint64_t N, uint8_t *out, size_t bytes) { 67 | scrypt_hmac_state hmac_pw, hmac_pw_salt, work; 68 | scrypt_hash_digest ti, u; 69 | uint8_t be[4]; 70 | uint32_t i, j, blocks; 71 | uint64_t c; 72 | 73 | /* bytes must be <= (0xffffffff - (SCRYPT_HASH_DIGEST_SIZE - 1)), which they will always be under scrypt */ 74 | 75 | /* hmac(password, ...) */ 76 | scrypt_hmac_init(&hmac_pw, password, password_len); 77 | 78 | /* hmac(password, salt...) */ 79 | hmac_pw_salt = hmac_pw; 80 | scrypt_hmac_update(&hmac_pw_salt, salt, salt_len); 81 | 82 | blocks = ((uint32_t)bytes + (SCRYPT_HASH_DIGEST_SIZE - 1)) / SCRYPT_HASH_DIGEST_SIZE; 83 | for (i = 1; i <= blocks; i++) { 84 | /* U1 = hmac(password, salt || be(i)) */ 85 | U32TO8_BE(be, i); 86 | work = hmac_pw_salt; 87 | scrypt_hmac_update(&work, be, 4); 88 | scrypt_hmac_finish(&work, ti); 89 | memcpy(u, ti, sizeof(u)); 90 | 91 | /* T[i] = U1 ^ U2 ^ U3... */ 92 | for (c = 0; c < N - 1; c++) { 93 | /* UX = hmac(password, U{X-1}) */ 94 | work = hmac_pw; 95 | scrypt_hmac_update(&work, u, SCRYPT_HASH_DIGEST_SIZE); 96 | scrypt_hmac_finish(&work, u); 97 | 98 | /* T[i] ^= UX */ 99 | for (j = 0; j < sizeof(u); j++) 100 | ti[j] ^= u[j]; 101 | } 102 | 103 | memcpy(out, ti, (bytes > SCRYPT_HASH_DIGEST_SIZE) ? SCRYPT_HASH_DIGEST_SIZE : bytes); 104 | out += SCRYPT_HASH_DIGEST_SIZE; 105 | bytes -= SCRYPT_HASH_DIGEST_SIZE; 106 | } 107 | 108 | scrypt_ensure_zero(ti, sizeof(ti)); 109 | scrypt_ensure_zero(u, sizeof(u)); 110 | scrypt_ensure_zero(&hmac_pw, sizeof(hmac_pw)); 111 | scrypt_ensure_zero(&hmac_pw_salt, sizeof(hmac_pw_salt)); 112 | } 113 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/c_keccak.c: -------------------------------------------------------------------------------- 1 | // keccak.c 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | // A baseline Keccak (3rd round) implementation. 4 | 5 | #include "hash-ops.h" 6 | #include "c_keccak.h" 7 | 8 | const uint64_t keccakf_rndc[24] = 9 | { 10 | 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 11 | 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 12 | 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 13 | 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 14 | 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 15 | 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 16 | 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 17 | 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 18 | }; 19 | 20 | const int keccakf_rotc[24] = 21 | { 22 | 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 23 | 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 24 | }; 25 | 26 | const int keccakf_piln[24] = 27 | { 28 | 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 29 | 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 30 | }; 31 | 32 | // update the state with given number of rounds 33 | 34 | void keccakf(uint64_t st[25], int rounds) 35 | { 36 | int i, j, round; 37 | uint64_t t, bc[5]; 38 | 39 | for (round = 0; round < rounds; ++round) { 40 | 41 | // Theta 42 | bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20]; 43 | bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21]; 44 | bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22]; 45 | bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23]; 46 | bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24]; 47 | 48 | for (i = 0; i < 5; ++i) { 49 | t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); 50 | st[i ] ^= t; 51 | st[i + 5] ^= t; 52 | st[i + 10] ^= t; 53 | st[i + 15] ^= t; 54 | st[i + 20] ^= t; 55 | } 56 | 57 | // Rho Pi 58 | t = st[1]; 59 | for (i = 0; i < 24; ++i) { 60 | bc[0] = st[keccakf_piln[i]]; 61 | st[keccakf_piln[i]] = ROTL64(t, keccakf_rotc[i]); 62 | t = bc[0]; 63 | } 64 | 65 | // Chi 66 | for (j = 0; j < 25; j += 5) { 67 | bc[0] = st[j ]; 68 | bc[1] = st[j + 1]; 69 | bc[2] = st[j + 2]; 70 | bc[3] = st[j + 3]; 71 | bc[4] = st[j + 4]; 72 | st[j ] ^= (~bc[1]) & bc[2]; 73 | st[j + 1] ^= (~bc[2]) & bc[3]; 74 | st[j + 2] ^= (~bc[3]) & bc[4]; 75 | st[j + 3] ^= (~bc[4]) & bc[0]; 76 | st[j + 4] ^= (~bc[0]) & bc[1]; 77 | } 78 | 79 | // Iota 80 | st[0] ^= keccakf_rndc[round]; 81 | } 82 | } 83 | 84 | // compute a keccak hash (md) of given byte length from "in" 85 | typedef uint64_t state_t[25]; 86 | 87 | int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen) 88 | { 89 | state_t st; 90 | uint8_t temp[144]; 91 | int i, rsiz, rsizw; 92 | 93 | rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; 94 | rsizw = rsiz / 8; 95 | 96 | memset(st, 0, sizeof(st)); 97 | 98 | for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { 99 | for (i = 0; i < rsizw; i++) 100 | st[i] ^= ((uint64_t *) in)[i]; 101 | keccakf(st, KECCAK_ROUNDS); 102 | } 103 | 104 | // last block and padding 105 | memcpy(temp, in, inlen); 106 | temp[inlen++] = 1; 107 | memset(temp + inlen, 0, rsiz - inlen); 108 | temp[rsiz - 1] |= 0x80; 109 | 110 | for (i = 0; i < rsizw; i++) 111 | st[i] ^= ((uint64_t *) temp)[i]; 112 | 113 | keccakf(st, KECCAK_ROUNDS); 114 | 115 | memcpy(md, st, mdlen); 116 | 117 | return 0; 118 | } 119 | 120 | void keccak1600(const uint8_t *in, int inlen, uint8_t *md) 121 | { 122 | keccak(in, inlen, md, sizeof(state_t)); 123 | } 124 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-chacha.h: -------------------------------------------------------------------------------- 1 | #define SCRYPT_MIX_BASE "ChaCha20/8" 2 | 3 | typedef uint32_t scrypt_mix_word_t; 4 | 5 | #define SCRYPT_WORDTO8_LE U32TO8_LE 6 | #define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP 7 | 8 | #define SCRYPT_BLOCK_BYTES 64 9 | #define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t)) 10 | 11 | /* must have these here in case block bytes is ever != 64 */ 12 | #include "scrypt-jane-romix-basic.h" 13 | 14 | #include "scrypt-jane-mix_chacha-avx.h" 15 | #include "scrypt-jane-mix_chacha-ssse3.h" 16 | #include "scrypt-jane-mix_chacha-sse2.h" 17 | #include "scrypt-jane-mix_chacha.h" 18 | 19 | #if defined(SCRYPT_CHACHA_AVX) 20 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx 21 | #define SCRYPT_ROMIX_FN scrypt_ROMix_avx 22 | #define SCRYPT_MIX_FN chacha_core_avx 23 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop 24 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop 25 | #include "scrypt-jane-romix-template.h" 26 | #endif 27 | 28 | #if defined(SCRYPT_CHACHA_SSSE3) 29 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_ssse3 30 | #define SCRYPT_ROMIX_FN scrypt_ROMix_ssse3 31 | #define SCRYPT_MIX_FN chacha_core_ssse3 32 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop 33 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop 34 | #include "scrypt-jane-romix-template.h" 35 | #endif 36 | 37 | #if defined(SCRYPT_CHACHA_SSE2) 38 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse2 39 | #define SCRYPT_ROMIX_FN scrypt_ROMix_sse2 40 | #define SCRYPT_MIX_FN chacha_core_sse2 41 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop 42 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop 43 | #include "scrypt-jane-romix-template.h" 44 | #endif 45 | 46 | /* cpu agnostic */ 47 | #define SCRYPT_ROMIX_FN scrypt_ROMix_basic 48 | #define SCRYPT_MIX_FN chacha_core_basic 49 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian 50 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian 51 | #include "scrypt-jane-romix-template.h" 52 | 53 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 54 | static scrypt_ROMixfn 55 | scrypt_getROMix() { 56 | size_t cpuflags = detect_cpu(); 57 | 58 | #if defined(SCRYPT_CHACHA_AVX) 59 | if (cpuflags & cpu_avx) 60 | return scrypt_ROMix_avx; 61 | else 62 | #endif 63 | 64 | #if defined(SCRYPT_CHACHA_SSSE3) 65 | if (cpuflags & cpu_ssse3) 66 | return scrypt_ROMix_ssse3; 67 | else 68 | #endif 69 | 70 | #if defined(SCRYPT_CHACHA_SSE2) 71 | if (cpuflags & cpu_sse2) 72 | return scrypt_ROMix_sse2; 73 | else 74 | #endif 75 | 76 | return scrypt_ROMix_basic; 77 | } 78 | #endif 79 | 80 | 81 | #if defined(SCRYPT_TEST_SPEED) 82 | static size_t 83 | available_implementations() { 84 | size_t flags = 0; 85 | 86 | #if defined(SCRYPT_CHACHA_AVX) 87 | flags |= cpu_avx; 88 | #endif 89 | 90 | #if defined(SCRYPT_CHACHA_SSSE3) 91 | flags |= cpu_ssse3; 92 | #endif 93 | 94 | #if defined(SCRYPT_CHACHA_SSE2) 95 | flags |= cpu_sse2; 96 | #endif 97 | 98 | return flags; 99 | } 100 | #endif 101 | 102 | static int 103 | scrypt_test_mix() { 104 | static const uint8_t expected[16] = { 105 | 0x48,0x2b,0x2d,0xb8,0xa1,0x33,0x22,0x73,0xcd,0x16,0xc4,0xb4,0xb0,0x7f,0xb1,0x8a, 106 | }; 107 | 108 | int ret = 1; 109 | size_t cpuflags = detect_cpu(); 110 | 111 | #if defined(SCRYPT_CHACHA_AVX) 112 | if (cpuflags & cpu_avx) 113 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, scrypt_romix_nop, scrypt_romix_nop, expected); 114 | #endif 115 | 116 | #if defined(SCRYPT_CHACHA_SSSE3) 117 | if (cpuflags & cpu_ssse3) 118 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_ssse3, scrypt_romix_nop, scrypt_romix_nop, expected); 119 | #endif 120 | 121 | #if defined(SCRYPT_CHACHA_SSE2) 122 | if (cpuflags & cpu_sse2) 123 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, scrypt_romix_nop, scrypt_romix_nop, expected); 124 | #endif 125 | 126 | #if defined(SCRYPT_CHACHA_BASIC) 127 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected); 128 | #endif 129 | 130 | return ret; 131 | } 132 | 133 | -------------------------------------------------------------------------------- /cpuminer-source/configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([cpuminer], [2.4.5]) 2 | 3 | AC_PREREQ([2.59c]) 4 | AC_CANONICAL_SYSTEM 5 | AC_CONFIG_SRCDIR([cpu-miner.c]) 6 | AM_INIT_AUTOMAKE([gnu]) 7 | AC_CONFIG_HEADERS([cpuminer-config.h]) 8 | 9 | dnl Make sure anyone changing configure.ac/Makefile.am has a clue 10 | AM_MAINTAINER_MODE 11 | 12 | dnl Checks for programs 13 | AC_PROG_CC_C99 14 | AC_PROG_GCC_TRADITIONAL 15 | AM_PROG_CC_C_O 16 | AM_PROG_AS 17 | AC_PROG_RANLIB 18 | 19 | dnl Checks for header files 20 | AC_HEADER_STDC 21 | AC_CHECK_HEADERS([sys/endian.h sys/param.h syslog.h]) 22 | # sys/sysctl.h requires sys/types.h on FreeBSD 23 | # sys/sysctl.h requires sys/param.h on OpenBSD 24 | AC_CHECK_HEADERS([sys/sysctl.h], [], [], 25 | [#include 26 | #ifdef HAVE_SYS_PARAM_H 27 | #include 28 | #endif 29 | ]) 30 | 31 | AC_CHECK_DECLS([be32dec, le32dec, be32enc, le32enc], [], [], 32 | [AC_INCLUDES_DEFAULT 33 | #ifdef HAVE_SYS_ENDIAN_H 34 | #include 35 | #endif 36 | ]) 37 | 38 | AC_FUNC_ALLOCA 39 | AC_CHECK_FUNCS([getopt_long]) 40 | 41 | case $target in 42 | i*86-*-*) 43 | have_x86=true 44 | ;; 45 | x86_64-*-*|amd64-*-*) 46 | have_x86_64=true 47 | ;; 48 | arm*-*-*) 49 | have_arm=true 50 | ;; 51 | powerpc*-*-*) 52 | have_ppc=true 53 | ;; 54 | esac 55 | 56 | PTHREAD_FLAGS="-pthread" 57 | WS2_LIBS="" 58 | 59 | case $target in 60 | *-*-mingw*) 61 | have_win32=true 62 | PTHREAD_FLAGS="" 63 | WS2_LIBS="-lws2_32" 64 | ;; 65 | esac 66 | 67 | AC_ARG_ENABLE([assembly], 68 | AS_HELP_STRING([--disable-assembly], [disable assembly-language routines])) 69 | if test x$enable_assembly != xno; then 70 | AC_DEFINE([USE_ASM], [1], [Define to 1 if assembly routines are wanted.]) 71 | fi 72 | 73 | if test x$enable_assembly != xno -a x$have_x86_64 = xtrue 74 | then 75 | AC_MSG_CHECKING(whether we can compile AVX code) 76 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("vmovdqa %ymm0, %ymm1");])], 77 | AC_DEFINE(USE_AVX, 1, [Define to 1 if AVX assembly is available.]) 78 | AC_MSG_RESULT(yes) 79 | AC_MSG_CHECKING(whether we can compile XOP code) 80 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("vprotd \$7, %xmm0, %xmm1");])], 81 | AC_DEFINE(USE_XOP, 1, [Define to 1 if XOP assembly is available.]) 82 | AC_MSG_RESULT(yes) 83 | , 84 | AC_MSG_RESULT(no) 85 | AC_MSG_WARN([The assembler does not support the XOP instruction set.]) 86 | ) 87 | AC_MSG_CHECKING(whether we can compile AVX2 code) 88 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("vpaddd %ymm0, %ymm1, %ymm2");])], 89 | AC_DEFINE(USE_AVX2, 1, [Define to 1 if AVX2 assembly is available.]) 90 | AC_MSG_RESULT(yes) 91 | , 92 | AC_MSG_RESULT(no) 93 | AC_MSG_WARN([The assembler does not support the AVX2 instruction set.]) 94 | ) 95 | , 96 | AC_MSG_RESULT(no) 97 | AC_MSG_WARN([The assembler does not support the AVX instruction set.]) 98 | ) 99 | fi 100 | 101 | AC_CHECK_LIB(jansson, json_loads, request_jansson=false, request_jansson=true) 102 | AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS="-lpthread", 103 | AC_CHECK_LIB([pthreadGC2], [pthread_create], PTHREAD_LIBS="-lpthreadGC2", 104 | AC_CHECK_LIB([pthreadGC1], [pthread_create], PTHREAD_LIBS="-lpthreadGC1", 105 | AC_CHECK_LIB([pthreadGC], [pthread_create], PTHREAD_LIBS="-lpthreadGC" 106 | )))) 107 | 108 | AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue]) 109 | AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue]) 110 | AM_CONDITIONAL([USE_ASM], [test x$enable_assembly != xno]) 111 | AM_CONDITIONAL([ARCH_x86], [test x$have_x86 = xtrue]) 112 | AM_CONDITIONAL([ARCH_x86_64], [test x$have_x86_64 = xtrue]) 113 | AM_CONDITIONAL([ARCH_ARM], [test x$have_arm = xtrue]) 114 | AM_CONDITIONAL([ARCH_PPC], [test x$have_ppc = xtrue]) 115 | 116 | if test x$request_jansson = xtrue 117 | then 118 | JANSSON_LIBS="compat/jansson/libjansson.a" 119 | else 120 | JANSSON_LIBS=-ljansson 121 | fi 122 | 123 | LIBCURL_CHECK_CONFIG(, 7.15.2, , 124 | [AC_MSG_ERROR([Missing required libcurl >= 7.15.2])]) 125 | 126 | AC_SUBST(JANSSON_LIBS) 127 | AC_SUBST(PTHREAD_FLAGS) 128 | AC_SUBST(PTHREAD_LIBS) 129 | AC_SUBST(WS2_LIBS) 130 | 131 | AC_CONFIG_FILES([ 132 | Makefile 133 | compat/Makefile 134 | compat/jansson/Makefile 135 | ]) 136 | AC_OUTPUT 137 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([cpuminer], [1.0.4]) 2 | 3 | AC_PREREQ([2.59c]) 4 | AC_CANONICAL_SYSTEM 5 | AC_CONFIG_SRCDIR([cpu-miner.c]) 6 | AM_INIT_AUTOMAKE([foreign subdir-objects]) 7 | AC_CONFIG_HEADERS([cpuminer-config.h]) 8 | 9 | dnl Make sure anyone changing configure.ac/Makefile.am has a clue 10 | AM_MAINTAINER_MODE 11 | 12 | dnl Checks for programs 13 | AC_PROG_CC_C99 14 | AC_PROG_GCC_TRADITIONAL 15 | AM_PROG_CC_C_O 16 | AM_PROG_AS 17 | AC_PROG_RANLIB 18 | 19 | dnl Checks for header files 20 | AC_HEADER_STDC 21 | AC_CHECK_HEADERS([sys/endian.h sys/param.h syslog.h]) 22 | # sys/sysctl.h requires sys/types.h on FreeBSD 23 | # sys/sysctl.h requires sys/param.h on OpenBSD 24 | AC_CHECK_HEADERS([sys/sysctl.h], [], [], 25 | [#include 26 | #ifdef HAVE_SYS_PARAM_H 27 | #include 28 | #endif 29 | ]) 30 | 31 | AC_CHECK_DECLS([be32dec, le32dec, be32enc, le32enc], [], [], 32 | [AC_INCLUDES_DEFAULT 33 | #ifdef HAVE_SYS_ENDIAN_H 34 | #include 35 | #endif 36 | ]) 37 | 38 | AC_FUNC_ALLOCA 39 | AC_CHECK_FUNCS([getopt_long]) 40 | 41 | case $target in 42 | i*86-*-*) 43 | have_x86=true 44 | ;; 45 | x86_64-*-*|amd64-*-*) 46 | have_x86_64=true 47 | ;; 48 | arm*-*-*) 49 | have_arm=true 50 | ;; 51 | esac 52 | 53 | PTHREAD_FLAGS="-pthread" 54 | WS2_LIBS="" 55 | 56 | case $target in 57 | *-*-mingw*) 58 | have_win32=true 59 | PTHREAD_FLAGS="" 60 | WS2_LIBS="-lws2_32" 61 | ;; 62 | esac 63 | 64 | AC_ARG_ENABLE([assembly], 65 | AS_HELP_STRING([--disable-assembly], [disable assembly-language routines])) 66 | if test x$enable_assembly != xno; then 67 | AC_DEFINE([USE_ASM], [1], [Define to 1 if assembly routines are wanted.]) 68 | fi 69 | 70 | if test x$enable_assembly != xno -a x$have_x86_64 = xtrue 71 | then 72 | AC_MSG_CHECKING(whether we can compile AVX code) 73 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("vmovdqa %ymm0, %ymm1");])], 74 | AC_DEFINE(USE_AVX, 1, [Define to 1 if AVX assembly is available.]) 75 | AC_MSG_RESULT(yes) 76 | AC_MSG_CHECKING(whether we can compile XOP code) 77 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("vprotd \$7, %xmm0, %xmm1");])], 78 | AC_DEFINE(USE_XOP, 1, [Define to 1 if XOP assembly is available.]) 79 | AC_MSG_RESULT(yes) 80 | , 81 | AC_MSG_RESULT(no) 82 | AC_MSG_WARN([The assembler does not support the XOP instruction set.]) 83 | ) 84 | AC_MSG_CHECKING(whether we can compile AVX2 code) 85 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("vpaddd %ymm0, %ymm1, %ymm2");])], 86 | AC_DEFINE(USE_AVX2, 1, [Define to 1 if AVX2 assembly is available.]) 87 | AC_MSG_RESULT(yes) 88 | , 89 | AC_MSG_RESULT(no) 90 | AC_MSG_WARN([The assembler does not support the AVX2 instruction set.]) 91 | ) 92 | , 93 | AC_MSG_RESULT(no) 94 | AC_MSG_WARN([The assembler does not support the AVX instruction set.]) 95 | ) 96 | fi 97 | 98 | AC_CHECK_LIB(jansson, json_loads, request_jansson=false, request_jansson=true) 99 | AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS="-lpthread", 100 | AC_CHECK_LIB([pthreadGC2], [pthread_create], PTHREAD_LIBS="-lpthreadGC2", 101 | AC_CHECK_LIB([pthreadGC1], [pthread_create], PTHREAD_LIBS="-lpthreadGC1", 102 | AC_CHECK_LIB([pthreadGC], [pthread_create], PTHREAD_LIBS="-lpthreadGC" 103 | )))) 104 | 105 | AC_CHECK_LIB([crypto], [OPENSSL_init], [], [AC_MSG_FAILURE([could not find crypto])]) 106 | 107 | AC_MSG_CHECKING(whether __uint128_t is supported) 108 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([static __uint128_t i = 100;])], 109 | AC_DEFINE(USE_INT128, 1, [Define if __uint128_t is available]) 110 | AC_MSG_RESULT(yes) 111 | , 112 | AC_MSG_RESULT(no) 113 | ) 114 | 115 | AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue]) 116 | AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue]) 117 | AM_CONDITIONAL([USE_ASM], [test x$enable_assembly != xno]) 118 | AM_CONDITIONAL([ARCH_x86], [test x$have_x86 = xtrue]) 119 | AM_CONDITIONAL([ARCH_x86_64], [test x$have_x86_64 = xtrue]) 120 | AM_CONDITIONAL([ARCH_ARM], [test x$have_arm = xtrue]) 121 | 122 | if test x$request_jansson = xtrue 123 | then 124 | JANSSON_LIBS="compat/jansson/libjansson.a" 125 | else 126 | JANSSON_LIBS=-ljansson 127 | fi 128 | 129 | LIBCURL_CHECK_CONFIG(, 7.15.2, , 130 | [AC_MSG_ERROR([Missing required libcurl >= 7.15.2])]) 131 | 132 | AC_SUBST(JANSSON_LIBS) 133 | AC_SUBST(PTHREAD_FLAGS) 134 | AC_SUBST(PTHREAD_LIBS) 135 | AC_SUBST(WS2_LIBS) 136 | 137 | AC_CONFIG_FILES([ 138 | Makefile 139 | compat/Makefile 140 | compat/jansson/Makefile 141 | ]) 142 | AC_OUTPUT 143 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/ink.c: -------------------------------------------------------------------------------- 1 | #include "cpuminer-config.h" 2 | #include "miner.h" 3 | 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_shavite.h" 8 | 9 | static void inkhash(void *state, const void *input) 10 | { 11 | sph_shavite512_context ctx_shavite; 12 | uint32_t hash[16]; 13 | 14 | sph_shavite512_init(&ctx_shavite); 15 | sph_shavite512 (&ctx_shavite, (const void*) input, 80); 16 | sph_shavite512_close(&ctx_shavite, (void*) hash); 17 | 18 | sph_shavite512_init(&ctx_shavite); 19 | sph_shavite512(&ctx_shavite, (const void*) hash, 64); 20 | sph_shavite512_close(&ctx_shavite, (void*) hash); 21 | 22 | memcpy(state, hash, 32); 23 | 24 | /* 25 | int ii; 26 | printf("result: "); 27 | for (ii=0; ii < 32; ii++) 28 | { 29 | printf ("%.2x",((uint8_t*)state)[ii]); 30 | }; 31 | printf ("\n"); 32 | */ 33 | } 34 | 35 | int scanhash_ink(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 36 | uint32_t max_nonce, uint64_t *hashes_done) 37 | { 38 | uint32_t n = pdata[19] - 1; 39 | const uint32_t first_nonce = pdata[19]; 40 | const uint32_t Htarg = ptarget[7]; 41 | 42 | uint32_t hash64[8] __attribute__((aligned(32))); 43 | uint32_t endiandata[32]; 44 | 45 | //char testdata[] = {"\x70\x00\x00\x00\x5d\x38\x5b\xa1\x14\xd0\x79\x97\x0b\x29\xa9\x41\x8f\xd0\x54\x9e\x7d\x68\xa9\x5c\x7f\x16\x86\x21\xa3\x14\x20\x10\x00\x00\x00\x00\x57\x85\x86\xd1\x49\xfd\x07\xb2\x2f\x3a\x8a\x34\x7c\x51\x6d\xe7\x05\x2f\x03\x4d\x2b\x76\xff\x68\xe0\xd6\xec\xff\x9b\x77\xa4\x54\x89\xe3\xfd\x51\x17\x32\x01\x1d\xf0\x73\x10\x00"}; 46 | 47 | //we need bigendian data... 48 | //lessons learned: do NOT endianchange directly in pdata, this will all proof-of-works be considered as stale from minerd.... 49 | int kk=0; 50 | for (; kk < 32; kk++) 51 | { 52 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 53 | }; 54 | 55 | // if (opt_debug) 56 | // { 57 | // applog(LOG_DEBUG, "Thr: %02d, firstN: %08x, maxN: %08x, ToDo: %d", thr_id, first_nonce, max_nonce, max_nonce-first_nonce); 58 | // } 59 | 60 | /* I'm to lazy to put the loop in an inline function... so dirty copy'n'paste.... */ 61 | /* i know that i could set a variable, but i don't know how the compiler will optimize it, not that then the cpu needs to load the value *everytime* in a register */ 62 | if (ptarget[7]==0) { 63 | do { 64 | pdata[19] = ++n; 65 | be32enc(&endiandata[19], n); 66 | inkhash(hash64, &endiandata); 67 | if (((hash64[7]&0xFFFFFFFF)==0) && 68 | fulltest(hash64, ptarget)) { 69 | *hashes_done = n - first_nonce + 1; 70 | return true; 71 | } 72 | } while (n < max_nonce && !work_restart[thr_id].restart); 73 | } 74 | else if (ptarget[7]<=0xF) 75 | { 76 | do { 77 | pdata[19] = ++n; 78 | be32enc(&endiandata[19], n); 79 | inkhash(hash64, &endiandata); 80 | if (((hash64[7]&0xFFFFFFF0)==0) && 81 | fulltest(hash64, ptarget)) { 82 | *hashes_done = n - first_nonce + 1; 83 | return true; 84 | } 85 | } while (n < max_nonce && !work_restart[thr_id].restart); 86 | } 87 | else if (ptarget[7]<=0xFF) 88 | { 89 | do { 90 | pdata[19] = ++n; 91 | be32enc(&endiandata[19], n); 92 | inkhash(hash64, &endiandata); 93 | if (((hash64[7]&0xFFFFFF00)==0) && 94 | fulltest(hash64, ptarget)) { 95 | *hashes_done = n - first_nonce + 1; 96 | return true; 97 | } 98 | } while (n < max_nonce && !work_restart[thr_id].restart); 99 | } 100 | else if (ptarget[7]<=0xFFF) 101 | { 102 | do { 103 | pdata[19] = ++n; 104 | be32enc(&endiandata[19], n); 105 | inkhash(hash64, &endiandata); 106 | if (((hash64[7]&0xFFFFF000)==0) && 107 | fulltest(hash64, ptarget)) { 108 | *hashes_done = n - first_nonce + 1; 109 | return true; 110 | } 111 | } while (n < max_nonce && !work_restart[thr_id].restart); 112 | 113 | } 114 | else if (ptarget[7]<=0xFFFF) 115 | { 116 | do { 117 | pdata[19] = ++n; 118 | be32enc(&endiandata[19], n); 119 | inkhash(hash64, &endiandata); 120 | if (((hash64[7]&0xFFFF0000)==0) && 121 | fulltest(hash64, ptarget)) { 122 | *hashes_done = n - first_nonce + 1; 123 | return true; 124 | } 125 | } while (n < max_nonce && !work_restart[thr_id].restart); 126 | 127 | } 128 | else 129 | { 130 | do { 131 | pdata[19] = ++n; 132 | be32enc(&endiandata[19], n); 133 | inkhash(hash64, &endiandata); 134 | if (fulltest(hash64, ptarget)) { 135 | *hashes_done = n - first_nonce + 1; 136 | return true; 137 | } 138 | } while (n < max_nonce && !work_restart[thr_id].restart); 139 | } 140 | 141 | 142 | *hashes_done = n - first_nonce + 1; 143 | pdata[19] = n; 144 | return 0; 145 | } -------------------------------------------------------------------------------- /cpuminer-newalgorithms/blake.c: -------------------------------------------------------------------------------- 1 | #include "cpuminer-config.h" 2 | #include "miner.h" 3 | 4 | #include 5 | #include 6 | 7 | #include "sha3/sph_blake.h" 8 | 9 | /* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */ 10 | typedef struct { 11 | sph_blake256_context blake1; 12 | } blakehash_context_holder; 13 | 14 | static blakehash_context_holder base_contexts; 15 | 16 | void init_blakehash_contexts() 17 | { 18 | sph_blake256_init(&base_contexts.blake1); 19 | } 20 | 21 | static void blakehash(void *state, const void *input) 22 | { 23 | blakehash_context_holder ctx; 24 | //an array of uint32 25 | uint32_t hashA[8]; 26 | 27 | 28 | //do one memcopy to get fresh contexts, its faster even with a larger block then issuing 9 memcopies 29 | memcpy(&ctx, &base_contexts, sizeof(base_contexts)); 30 | 31 | sph_blake256 (&ctx.blake1, input, 80); 32 | sph_blake256_close (&ctx.blake1, hashA); //0 33 | memcpy(state, hashA, 32); 34 | 35 | } 36 | 37 | int scanhash_blake(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 38 | uint32_t max_nonce, uint64_t *hashes_done) 39 | { 40 | uint32_t n = pdata[19] - 1; 41 | const uint32_t first_nonce = pdata[19]; 42 | const uint32_t Htarg = ptarget[7]; 43 | uint32_t hash64[8] __attribute__((aligned(32))); 44 | uint32_t endiandata[32]; 45 | 46 | //char testdata[] = {"\x70\x00\x00\x00\x5d\x38\x5b\xa1\x14\xd0\x79\x97\x0b\x29\xa9\x41\x8f\xd0\x54\x9e\x7d\x68\xa9\x5c\x7f\x16\x86\x21\xa3\x14\x20\x10\x00\x00\x00\x00\x57\x85\x86\xd1\x49\xfd\x07\xb2\x2f\x3a\x8a\x34\x7c\x51\x6d\xe7\x05\x2f\x03\x4d\x2b\x76\xff\x68\xe0\xd6\xec\xff\x9b\x77\xa4\x54\x89\xe3\xfd\x51\x17\x32\x01\x1d\xf0\x73\x10\x00"}; 47 | 48 | //we need bigendian data... 49 | //lessons learned: do NOT endianchange directly in pdata, this will all proof-of-works be considered as stale from minerd.... 50 | int kk=0; 51 | for (; kk < 32; kk++) 52 | { 53 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 54 | }; 55 | 56 | // if (opt_debug) 57 | // { 58 | // applog(LOG_DEBUG, "Thr: %02d, firstN: %08x, maxN: %08x, ToDo: %d", thr_id, first_nonce, max_nonce, max_nonce-first_nonce); 59 | // } 60 | 61 | /* I'm to lazy to put the loop in an inline function... so dirty copy'n'paste.... */ 62 | /* i know that i could set a variable, but i don't know how the compiler will optimize it, not that then the cpu needs to load the value *everytime* in a register */ 63 | if (ptarget[7]==0) { 64 | do { 65 | pdata[19] = ++n; 66 | be32enc(&endiandata[19], n); 67 | blakehash(hash64, &endiandata); 68 | if (((hash64[7]&0xFFFFFFFF)==0) && 69 | fulltest(hash64, ptarget)) { 70 | *hashes_done = n - first_nonce + 1; 71 | return true; 72 | } 73 | } while (n < max_nonce && !work_restart[thr_id].restart); 74 | } 75 | else if (ptarget[7]<=0xF) 76 | { 77 | do { 78 | pdata[19] = ++n; 79 | be32enc(&endiandata[19], n); 80 | blakehash(hash64, &endiandata); 81 | if (((hash64[7]&0xFFFFFFF0)==0) && 82 | fulltest(hash64, ptarget)) { 83 | *hashes_done = n - first_nonce + 1; 84 | return true; 85 | } 86 | } while (n < max_nonce && !work_restart[thr_id].restart); 87 | } 88 | else if (ptarget[7]<=0xFF) 89 | { 90 | do { 91 | pdata[19] = ++n; 92 | be32enc(&endiandata[19], n); 93 | blakehash(hash64, &endiandata); 94 | if (((hash64[7]&0xFFFFFF00)==0) && 95 | fulltest(hash64, ptarget)) { 96 | *hashes_done = n - first_nonce + 1; 97 | return true; 98 | } 99 | } while (n < max_nonce && !work_restart[thr_id].restart); 100 | } 101 | else if (ptarget[7]<=0xFFF) 102 | { 103 | do { 104 | pdata[19] = ++n; 105 | be32enc(&endiandata[19], n); 106 | blakehash(hash64, &endiandata); 107 | if (((hash64[7]&0xFFFFF000)==0) && 108 | fulltest(hash64, ptarget)) { 109 | *hashes_done = n - first_nonce + 1; 110 | return true; 111 | } 112 | } while (n < max_nonce && !work_restart[thr_id].restart); 113 | 114 | } 115 | else if (ptarget[7]<=0xFFFF) 116 | { 117 | do { 118 | pdata[19] = ++n; 119 | be32enc(&endiandata[19], n); 120 | blakehash(hash64, &endiandata); 121 | if (((hash64[7]&0xFFFF0000)==0) && 122 | fulltest(hash64, ptarget)) { 123 | *hashes_done = n - first_nonce + 1; 124 | return true; 125 | } 126 | } while (n < max_nonce && !work_restart[thr_id].restart); 127 | 128 | } 129 | else 130 | { 131 | do { 132 | pdata[19] = ++n; 133 | be32enc(&endiandata[19], n); 134 | blakehash(hash64, &endiandata); 135 | if (fulltest(hash64, ptarget)) { 136 | *hashes_done = n - first_nonce + 1; 137 | return true; 138 | } 139 | } while (n < max_nonce && !work_restart[thr_id].restart); 140 | } 141 | 142 | 143 | *hashes_done = n - first_nonce + 1; 144 | pdata[19] = n; 145 | return 0; 146 | } 147 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/x13.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_blake.h" 9 | #include "sha3/sph_bmw.h" 10 | #include "sha3/sph_groestl.h" 11 | #include "sha3/sph_jh.h" 12 | #include "sha3/sph_keccak.h" 13 | #include "sha3/sph_skein.h" 14 | #include "sha3/sph_luffa.h" 15 | #include "sha3/sph_cubehash.h" 16 | #include "sha3/sph_shavite.h" 17 | #include "sha3/sph_simd.h" 18 | #include "sha3/sph_echo.h" 19 | #include "sha3/sph_hamsi.h" 20 | #include "sha3/sph_fugue.h" 21 | 22 | static void x13hash(void *output, const void *input) 23 | { 24 | unsigned char hash[128]; // uint32_t hashA[16], hashB[16]; 25 | #define hashB hash+64 26 | 27 | memset(hash, 0, 128); 28 | 29 | sph_blake512_context ctx_blake; 30 | sph_bmw512_context ctx_bmw; 31 | sph_groestl512_context ctx_groestl; 32 | sph_jh512_context ctx_jh; 33 | sph_keccak512_context ctx_keccak; 34 | sph_skein512_context ctx_skein; 35 | sph_luffa512_context ctx_luffa; 36 | sph_cubehash512_context ctx_cubehash; 37 | sph_shavite512_context ctx_shavite; 38 | sph_simd512_context ctx_simd; 39 | sph_echo512_context ctx_echo; 40 | sph_hamsi512_context ctx_hamsi; 41 | sph_fugue512_context ctx_fugue; 42 | 43 | sph_blake512_init(&ctx_blake); 44 | sph_blake512(&ctx_blake, input, 80); 45 | sph_blake512_close(&ctx_blake, hash); 46 | 47 | sph_bmw512_init(&ctx_bmw); 48 | sph_bmw512(&ctx_bmw, hash, 64); 49 | sph_bmw512_close(&ctx_bmw, hashB); 50 | 51 | sph_groestl512_init(&ctx_groestl); 52 | sph_groestl512(&ctx_groestl, hashB, 64); 53 | sph_groestl512_close(&ctx_groestl, hash); 54 | 55 | sph_skein512_init(&ctx_skein); 56 | sph_skein512(&ctx_skein, hash, 64); 57 | sph_skein512_close(&ctx_skein, hashB); 58 | 59 | sph_jh512_init(&ctx_jh); 60 | sph_jh512(&ctx_jh, hashB, 64); 61 | sph_jh512_close(&ctx_jh, hash); 62 | 63 | sph_keccak512_init(&ctx_keccak); 64 | sph_keccak512(&ctx_keccak, hash, 64); 65 | sph_keccak512_close(&ctx_keccak, hashB); 66 | 67 | sph_luffa512_init(&ctx_luffa); 68 | sph_luffa512(&ctx_luffa, hashB, 64); 69 | sph_luffa512_close(&ctx_luffa, hash); 70 | 71 | sph_cubehash512_init(&ctx_cubehash); 72 | sph_cubehash512(&ctx_cubehash, hash, 64); 73 | sph_cubehash512_close(&ctx_cubehash, hashB); 74 | 75 | sph_shavite512_init(&ctx_shavite); 76 | sph_shavite512(&ctx_shavite, hashB, 64); 77 | sph_shavite512_close(&ctx_shavite, hash); 78 | 79 | sph_simd512_init(&ctx_simd); 80 | sph_simd512(&ctx_simd, hash, 64); 81 | sph_simd512_close(&ctx_simd, hashB); 82 | 83 | sph_echo512_init(&ctx_echo); 84 | sph_echo512(&ctx_echo, hashB, 64); 85 | sph_echo512_close(&ctx_echo, hash); 86 | 87 | sph_hamsi512_init(&ctx_hamsi); 88 | sph_hamsi512(&ctx_hamsi, hash, 64); 89 | sph_hamsi512_close(&ctx_hamsi, hashB); 90 | 91 | sph_fugue512_init(&ctx_fugue); 92 | sph_fugue512(&ctx_fugue, hashB, 64); 93 | sph_fugue512_close(&ctx_fugue, hash); 94 | 95 | memcpy(output, hash, 32); 96 | } 97 | 98 | int scanhash_x13(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 99 | uint32_t max_nonce, uint64_t *hashes_done) 100 | { 101 | uint32_t n = pdata[19] - 1; 102 | const uint32_t first_nonce = pdata[19]; 103 | const uint32_t Htarg = ptarget[7]; 104 | 105 | uint32_t hash64[8] __attribute__((aligned(32))); 106 | uint32_t endiandata[32]; 107 | 108 | 109 | uint64_t htmax[] = { 110 | 0, 111 | 0xF, 112 | 0xFF, 113 | 0xFFF, 114 | 0xFFFF, 115 | 0x10000000 116 | }; 117 | uint32_t masks[] = { 118 | 0xFFFFFFFF, 119 | 0xFFFFFFF0, 120 | 0xFFFFFF00, 121 | 0xFFFFF000, 122 | 0xFFFF0000, 123 | 0 124 | }; 125 | 126 | // we need bigendian data... 127 | for (int kk=0; kk < 32; kk++) { 128 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 129 | }; 130 | #ifdef DEBUG_ALGO 131 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 132 | #endif 133 | for (int m=0; m < sizeof(masks); m++) { 134 | if (Htarg <= htmax[m]) { 135 | uint32_t mask = masks[m]; 136 | do { 137 | pdata[19] = ++n; 138 | be32enc(&endiandata[19], n); 139 | x13hash(hash64, &endiandata); 140 | #ifndef DEBUG_ALGO 141 | if ((!(hash64[7] & mask)) && fulltest(hash64, ptarget)) { 142 | *hashes_done = n - first_nonce + 1; 143 | return true; 144 | } 145 | #else 146 | if (!(n % 0x1000) && !thr_id) printf("."); 147 | if (!(hash64[7] & mask)) { 148 | printf("[%d]",thr_id); 149 | if (fulltest(hash64, ptarget)) { 150 | *hashes_done = n - first_nonce + 1; 151 | return true; 152 | } 153 | } 154 | #endif 155 | } while (n < max_nonce && !work_restart[thr_id].restart); 156 | // see blake.c if else to understand the loop on htmax => mask 157 | break; 158 | } 159 | } 160 | 161 | *hashes_done = n - first_nonce + 1; 162 | pdata[19] = n; 163 | return 0; 164 | } 165 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-hash_sha256.h: -------------------------------------------------------------------------------- 1 | #define SCRYPT_HASH "SHA-2-256" 2 | #define SCRYPT_HASH_BLOCK_SIZE 64 3 | #define SCRYPT_HASH_DIGEST_SIZE 32 4 | 5 | typedef uint8_t scrypt_hash_digest[SCRYPT_HASH_DIGEST_SIZE]; 6 | 7 | typedef struct scrypt_hash_state_t { 8 | uint32_t H[8]; 9 | uint64_t T; 10 | uint32_t leftover; 11 | uint8_t buffer[SCRYPT_HASH_BLOCK_SIZE]; 12 | } scrypt_hash_state; 13 | 14 | static const uint32_t sha256_constants[64] = { 15 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 16 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 17 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 18 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 19 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 20 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 21 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 22 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 23 | }; 24 | 25 | #define Ch(x,y,z) (z ^ (x & (y ^ z))) 26 | #define Maj(x,y,z) (((x | y) & z) | (x & y)) 27 | #define S0(x) (ROTR32(x, 2) ^ ROTR32(x, 13) ^ ROTR32(x, 22)) 28 | #define S1(x) (ROTR32(x, 6) ^ ROTR32(x, 11) ^ ROTR32(x, 25)) 29 | #define G0(x) (ROTR32(x, 7) ^ ROTR32(x, 18) ^ (x >> 3)) 30 | #define G1(x) (ROTR32(x, 17) ^ ROTR32(x, 19) ^ (x >> 10)) 31 | #define W0(in,i) (U8TO32_BE(&in[i * 4])) 32 | #define W1(i) (G1(w[i - 2]) + w[i - 7] + G0(w[i - 15]) + w[i - 16]) 33 | #define STEP(i) \ 34 | t1 = S0(r[0]) + Maj(r[0], r[1], r[2]); \ 35 | t0 = r[7] + S1(r[4]) + Ch(r[4], r[5], r[6]) + sha256_constants[i] + w[i]; \ 36 | r[7] = r[6]; \ 37 | r[6] = r[5]; \ 38 | r[5] = r[4]; \ 39 | r[4] = r[3] + t0; \ 40 | r[3] = r[2]; \ 41 | r[2] = r[1]; \ 42 | r[1] = r[0]; \ 43 | r[0] = t0 + t1; 44 | 45 | static void 46 | sha256_blocks(scrypt_hash_state *S, const uint8_t *in, size_t blocks) { 47 | uint32_t r[8], w[64], t0, t1; 48 | size_t i; 49 | 50 | for (i = 0; i < 8; i++) r[i] = S->H[i]; 51 | 52 | while (blocks--) { 53 | for (i = 0; i < 16; i++) { w[i] = W0(in, i); } 54 | for (i = 16; i < 64; i++) { w[i] = W1(i); } 55 | for (i = 0; i < 64; i++) { STEP(i); } 56 | for (i = 0; i < 8; i++) { r[i] += S->H[i]; S->H[i] = r[i]; } 57 | S->T += SCRYPT_HASH_BLOCK_SIZE * 8; 58 | in += SCRYPT_HASH_BLOCK_SIZE; 59 | } 60 | } 61 | 62 | static void 63 | scrypt_hash_init(scrypt_hash_state *S) { 64 | S->H[0] = 0x6a09e667; 65 | S->H[1] = 0xbb67ae85; 66 | S->H[2] = 0x3c6ef372; 67 | S->H[3] = 0xa54ff53a; 68 | S->H[4] = 0x510e527f; 69 | S->H[5] = 0x9b05688c; 70 | S->H[6] = 0x1f83d9ab; 71 | S->H[7] = 0x5be0cd19; 72 | S->T = 0; 73 | S->leftover = 0; 74 | } 75 | 76 | static void 77 | scrypt_hash_update(scrypt_hash_state *S, const uint8_t *in, size_t inlen) { 78 | size_t blocks, want; 79 | 80 | /* handle the previous data */ 81 | if (S->leftover) { 82 | want = (SCRYPT_HASH_BLOCK_SIZE - S->leftover); 83 | want = (want < inlen) ? want : inlen; 84 | memcpy(S->buffer + S->leftover, in, want); 85 | S->leftover += (uint32_t)want; 86 | if (S->leftover < SCRYPT_HASH_BLOCK_SIZE) 87 | return; 88 | in += want; 89 | inlen -= want; 90 | sha256_blocks(S, S->buffer, 1); 91 | } 92 | 93 | /* handle the current data */ 94 | blocks = (inlen & ~(SCRYPT_HASH_BLOCK_SIZE - 1)); 95 | S->leftover = (uint32_t)(inlen - blocks); 96 | if (blocks) { 97 | sha256_blocks(S, in, blocks / SCRYPT_HASH_BLOCK_SIZE); 98 | in += blocks; 99 | } 100 | 101 | /* handle leftover data */ 102 | if (S->leftover) 103 | memcpy(S->buffer, in, S->leftover); 104 | } 105 | 106 | static void 107 | scrypt_hash_finish(scrypt_hash_state *S, uint8_t *hash) { 108 | uint64_t t = S->T + (S->leftover * 8); 109 | 110 | S->buffer[S->leftover] = 0x80; 111 | if (S->leftover <= 55) { 112 | memset(S->buffer + S->leftover + 1, 0, 55 - S->leftover); 113 | } else { 114 | memset(S->buffer + S->leftover + 1, 0, 63 - S->leftover); 115 | sha256_blocks(S, S->buffer, 1); 116 | memset(S->buffer, 0, 56); 117 | } 118 | 119 | U64TO8_BE(S->buffer + 56, t); 120 | sha256_blocks(S, S->buffer, 1); 121 | 122 | U32TO8_BE(&hash[ 0], S->H[0]); 123 | U32TO8_BE(&hash[ 4], S->H[1]); 124 | U32TO8_BE(&hash[ 8], S->H[2]); 125 | U32TO8_BE(&hash[12], S->H[3]); 126 | U32TO8_BE(&hash[16], S->H[4]); 127 | U32TO8_BE(&hash[20], S->H[5]); 128 | U32TO8_BE(&hash[24], S->H[6]); 129 | U32TO8_BE(&hash[28], S->H[7]); 130 | } 131 | 132 | static const uint8_t scrypt_test_hash_expected[SCRYPT_HASH_DIGEST_SIZE] = { 133 | 0xee,0x36,0xae,0xa6,0x65,0xf0,0x28,0x7d,0xc9,0xde,0xd8,0xad,0x48,0x33,0x7d,0xbf, 134 | 0xcb,0xc0,0x48,0xfa,0x5f,0x92,0xfd,0x0a,0x95,0x6f,0x34,0x8e,0x8c,0x1e,0x73,0xad, 135 | }; 136 | -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/utf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include 9 | #include "utf.h" 10 | 11 | int utf8_encode(int32_t codepoint, char *buffer, int *size) 12 | { 13 | if(codepoint < 0) 14 | return -1; 15 | else if(codepoint < 0x80) 16 | { 17 | buffer[0] = (char)codepoint; 18 | *size = 1; 19 | } 20 | else if(codepoint < 0x800) 21 | { 22 | buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6); 23 | buffer[1] = 0x80 + ((codepoint & 0x03F)); 24 | *size = 2; 25 | } 26 | else if(codepoint < 0x10000) 27 | { 28 | buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12); 29 | buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6); 30 | buffer[2] = 0x80 + ((codepoint & 0x003F)); 31 | *size = 3; 32 | } 33 | else if(codepoint <= 0x10FFFF) 34 | { 35 | buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18); 36 | buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12); 37 | buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6); 38 | buffer[3] = 0x80 + ((codepoint & 0x00003F)); 39 | *size = 4; 40 | } 41 | else 42 | return -1; 43 | 44 | return 0; 45 | } 46 | 47 | int utf8_check_first(char byte) 48 | { 49 | unsigned char u = (unsigned char)byte; 50 | 51 | if(u < 0x80) 52 | return 1; 53 | 54 | if(0x80 <= u && u <= 0xBF) { 55 | /* second, third or fourth byte of a multi-byte 56 | sequence, i.e. a "continuation byte" */ 57 | return 0; 58 | } 59 | else if(u == 0xC0 || u == 0xC1) { 60 | /* overlong encoding of an ASCII byte */ 61 | return 0; 62 | } 63 | else if(0xC2 <= u && u <= 0xDF) { 64 | /* 2-byte sequence */ 65 | return 2; 66 | } 67 | 68 | else if(0xE0 <= u && u <= 0xEF) { 69 | /* 3-byte sequence */ 70 | return 3; 71 | } 72 | else if(0xF0 <= u && u <= 0xF4) { 73 | /* 4-byte sequence */ 74 | return 4; 75 | } 76 | else { /* u >= 0xF5 */ 77 | /* Restricted (start of 4-, 5- or 6-byte sequence) or invalid 78 | UTF-8 */ 79 | return 0; 80 | } 81 | } 82 | 83 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint) 84 | { 85 | int i; 86 | int32_t value = 0; 87 | unsigned char u = (unsigned char)buffer[0]; 88 | 89 | if(size == 2) 90 | { 91 | value = u & 0x1F; 92 | } 93 | else if(size == 3) 94 | { 95 | value = u & 0xF; 96 | } 97 | else if(size == 4) 98 | { 99 | value = u & 0x7; 100 | } 101 | else 102 | return 0; 103 | 104 | for(i = 1; i < size; i++) 105 | { 106 | u = (unsigned char)buffer[i]; 107 | 108 | if(u < 0x80 || u > 0xBF) { 109 | /* not a continuation byte */ 110 | return 0; 111 | } 112 | 113 | value = (value << 6) + (u & 0x3F); 114 | } 115 | 116 | if(value > 0x10FFFF) { 117 | /* not in Unicode range */ 118 | return 0; 119 | } 120 | 121 | else if(0xD800 <= value && value <= 0xDFFF) { 122 | /* invalid code point (UTF-16 surrogate halves) */ 123 | return 0; 124 | } 125 | 126 | else if((size == 2 && value < 0x80) || 127 | (size == 3 && value < 0x800) || 128 | (size == 4 && value < 0x10000)) { 129 | /* overlong encoding */ 130 | return 0; 131 | } 132 | 133 | if(codepoint) 134 | *codepoint = value; 135 | 136 | return 1; 137 | } 138 | 139 | const char *utf8_iterate(const char *buffer, int32_t *codepoint) 140 | { 141 | int count; 142 | int32_t value; 143 | 144 | if(!*buffer) 145 | return buffer; 146 | 147 | count = utf8_check_first(buffer[0]); 148 | if(count <= 0) 149 | return NULL; 150 | 151 | if(count == 1) 152 | value = (unsigned char)buffer[0]; 153 | else 154 | { 155 | if(!utf8_check_full(buffer, count, &value)) 156 | return NULL; 157 | } 158 | 159 | if(codepoint) 160 | *codepoint = value; 161 | 162 | return buffer + count; 163 | } 164 | 165 | int utf8_check_string(const char *string, int length) 166 | { 167 | int i; 168 | 169 | if(length == -1) 170 | length = strlen(string); 171 | 172 | for(i = 0; i < length; i++) 173 | { 174 | int count = utf8_check_first(string[i]); 175 | if(count == 0) 176 | return 0; 177 | else if(count > 1) 178 | { 179 | if(i + count > length) 180 | return 0; 181 | 182 | if(!utf8_check_full(&string[i], count, NULL)) 183 | return 0; 184 | 185 | i += count - 1; 186 | } 187 | } 188 | 189 | return 1; 190 | } 191 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/utf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include 9 | #include "utf.h" 10 | 11 | int utf8_encode(int32_t codepoint, char *buffer, int *size) 12 | { 13 | if(codepoint < 0) 14 | return -1; 15 | else if(codepoint < 0x80) 16 | { 17 | buffer[0] = (char)codepoint; 18 | *size = 1; 19 | } 20 | else if(codepoint < 0x800) 21 | { 22 | buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6); 23 | buffer[1] = 0x80 + ((codepoint & 0x03F)); 24 | *size = 2; 25 | } 26 | else if(codepoint < 0x10000) 27 | { 28 | buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12); 29 | buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6); 30 | buffer[2] = 0x80 + ((codepoint & 0x003F)); 31 | *size = 3; 32 | } 33 | else if(codepoint <= 0x10FFFF) 34 | { 35 | buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18); 36 | buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12); 37 | buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6); 38 | buffer[3] = 0x80 + ((codepoint & 0x00003F)); 39 | *size = 4; 40 | } 41 | else 42 | return -1; 43 | 44 | return 0; 45 | } 46 | 47 | int utf8_check_first(char byte) 48 | { 49 | unsigned char u = (unsigned char)byte; 50 | 51 | if(u < 0x80) 52 | return 1; 53 | 54 | if(0x80 <= u && u <= 0xBF) { 55 | /* second, third or fourth byte of a multi-byte 56 | sequence, i.e. a "continuation byte" */ 57 | return 0; 58 | } 59 | else if(u == 0xC0 || u == 0xC1) { 60 | /* overlong encoding of an ASCII byte */ 61 | return 0; 62 | } 63 | else if(0xC2 <= u && u <= 0xDF) { 64 | /* 2-byte sequence */ 65 | return 2; 66 | } 67 | 68 | else if(0xE0 <= u && u <= 0xEF) { 69 | /* 3-byte sequence */ 70 | return 3; 71 | } 72 | else if(0xF0 <= u && u <= 0xF4) { 73 | /* 4-byte sequence */ 74 | return 4; 75 | } 76 | else { /* u >= 0xF5 */ 77 | /* Restricted (start of 4-, 5- or 6-byte sequence) or invalid 78 | UTF-8 */ 79 | return 0; 80 | } 81 | } 82 | 83 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint) 84 | { 85 | int i; 86 | int32_t value = 0; 87 | unsigned char u = (unsigned char)buffer[0]; 88 | 89 | if(size == 2) 90 | { 91 | value = u & 0x1F; 92 | } 93 | else if(size == 3) 94 | { 95 | value = u & 0xF; 96 | } 97 | else if(size == 4) 98 | { 99 | value = u & 0x7; 100 | } 101 | else 102 | return 0; 103 | 104 | for(i = 1; i < size; i++) 105 | { 106 | u = (unsigned char)buffer[i]; 107 | 108 | if(u < 0x80 || u > 0xBF) { 109 | /* not a continuation byte */ 110 | return 0; 111 | } 112 | 113 | value = (value << 6) + (u & 0x3F); 114 | } 115 | 116 | if(value > 0x10FFFF) { 117 | /* not in Unicode range */ 118 | return 0; 119 | } 120 | 121 | else if(0xD800 <= value && value <= 0xDFFF) { 122 | /* invalid code point (UTF-16 surrogate halves) */ 123 | return 0; 124 | } 125 | 126 | else if((size == 2 && value < 0x80) || 127 | (size == 3 && value < 0x800) || 128 | (size == 4 && value < 0x10000)) { 129 | /* overlong encoding */ 130 | return 0; 131 | } 132 | 133 | if(codepoint) 134 | *codepoint = value; 135 | 136 | return 1; 137 | } 138 | 139 | const char *utf8_iterate(const char *buffer, int32_t *codepoint) 140 | { 141 | int count; 142 | int32_t value; 143 | 144 | if(!*buffer) 145 | return buffer; 146 | 147 | count = utf8_check_first(buffer[0]); 148 | if(count <= 0) 149 | return NULL; 150 | 151 | if(count == 1) 152 | value = (unsigned char)buffer[0]; 153 | else 154 | { 155 | if(!utf8_check_full(buffer, count, &value)) 156 | return NULL; 157 | } 158 | 159 | if(codepoint) 160 | *codepoint = value; 161 | 162 | return buffer + count; 163 | } 164 | 165 | int utf8_check_string(const char *string, int length) 166 | { 167 | int i; 168 | 169 | if(length == -1) 170 | length = strlen(string); 171 | 172 | for(i = 0; i < length; i++) 173 | { 174 | int count = utf8_check_first(string[i]); 175 | if(count == 0) 176 | return 0; 177 | else if(count > 1) 178 | { 179 | if(i + count > length) 180 | return 0; 181 | 182 | if(!utf8_check_full(&string[i], count, NULL)) 183 | return 0; 184 | 185 | i += count - 1; 186 | } 187 | } 188 | 189 | return 1; 190 | } 191 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/x14.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_blake.h" 9 | #include "sha3/sph_bmw.h" 10 | #include "sha3/sph_groestl.h" 11 | #include "sha3/sph_jh.h" 12 | #include "sha3/sph_keccak.h" 13 | #include "sha3/sph_skein.h" 14 | #include "sha3/sph_luffa.h" 15 | #include "sha3/sph_cubehash.h" 16 | #include "sha3/sph_shavite.h" 17 | #include "sha3/sph_simd.h" 18 | #include "sha3/sph_echo.h" 19 | #include "sha3/sph_hamsi.h" 20 | #include "sha3/sph_fugue.h" 21 | #include "sha3/sph_shabal.h" 22 | 23 | //#define DEBUG_ALGO 24 | 25 | static void x14hash(void *output, const void *input) 26 | { 27 | unsigned char hash[128]; // uint32_t hashA[16], hashB[16]; 28 | #define hashB hash+64 29 | 30 | memset(hash, 0, 128); 31 | 32 | sph_blake512_context ctx_blake; 33 | sph_bmw512_context ctx_bmw; 34 | sph_groestl512_context ctx_groestl; 35 | sph_jh512_context ctx_jh; 36 | sph_keccak512_context ctx_keccak; 37 | sph_skein512_context ctx_skein; 38 | sph_luffa512_context ctx_luffa; 39 | sph_cubehash512_context ctx_cubehash; 40 | sph_shavite512_context ctx_shavite; 41 | sph_simd512_context ctx_simd; 42 | sph_echo512_context ctx_echo; 43 | sph_hamsi512_context ctx_hamsi; 44 | sph_fugue512_context ctx_fugue; 45 | sph_shabal512_context ctx_shabal; 46 | 47 | sph_blake512_init(&ctx_blake); 48 | sph_blake512(&ctx_blake, input, 80); 49 | sph_blake512_close(&ctx_blake, hash); 50 | 51 | sph_bmw512_init(&ctx_bmw); 52 | sph_bmw512(&ctx_bmw, hash, 64); 53 | sph_bmw512_close(&ctx_bmw, hashB); 54 | 55 | sph_groestl512_init(&ctx_groestl); 56 | sph_groestl512(&ctx_groestl, hashB, 64); 57 | sph_groestl512_close(&ctx_groestl, hash); 58 | 59 | sph_skein512_init(&ctx_skein); 60 | sph_skein512(&ctx_skein, hash, 64); 61 | sph_skein512_close(&ctx_skein, hashB); 62 | 63 | sph_jh512_init(&ctx_jh); 64 | sph_jh512(&ctx_jh, hashB, 64); 65 | sph_jh512_close(&ctx_jh, hash); 66 | 67 | sph_keccak512_init(&ctx_keccak); 68 | sph_keccak512(&ctx_keccak, hash, 64); 69 | sph_keccak512_close(&ctx_keccak, hashB); 70 | 71 | sph_luffa512_init(&ctx_luffa); 72 | sph_luffa512(&ctx_luffa, hashB, 64); 73 | sph_luffa512_close(&ctx_luffa, hash); 74 | 75 | sph_cubehash512_init(&ctx_cubehash); 76 | sph_cubehash512(&ctx_cubehash, hash, 64); 77 | sph_cubehash512_close(&ctx_cubehash, hashB); 78 | 79 | sph_shavite512_init(&ctx_shavite); 80 | sph_shavite512(&ctx_shavite, hashB, 64); 81 | sph_shavite512_close(&ctx_shavite, hash); 82 | 83 | sph_simd512_init(&ctx_simd); 84 | sph_simd512(&ctx_simd, hash, 64); 85 | sph_simd512_close(&ctx_simd, hashB); 86 | 87 | sph_echo512_init(&ctx_echo); 88 | sph_echo512(&ctx_echo, hashB, 64); 89 | sph_echo512_close(&ctx_echo, hash); 90 | 91 | sph_hamsi512_init(&ctx_hamsi); 92 | sph_hamsi512(&ctx_hamsi, hash, 64); 93 | sph_hamsi512_close(&ctx_hamsi, hashB); 94 | 95 | sph_fugue512_init(&ctx_fugue); 96 | sph_fugue512(&ctx_fugue, hashB, 64); 97 | sph_fugue512_close(&ctx_fugue, hash); 98 | 99 | sph_shabal512_init(&ctx_shabal); 100 | sph_shabal512(&ctx_shabal, hash, 64); 101 | sph_shabal512_close(&ctx_shabal, hash); 102 | 103 | memcpy(output, hash, 32); 104 | } 105 | 106 | int scanhash_x14(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 107 | uint32_t max_nonce, uint64_t *hashes_done) 108 | { 109 | uint32_t n = pdata[19] - 1; 110 | const uint32_t first_nonce = pdata[19]; 111 | const uint32_t Htarg = ptarget[7]; 112 | 113 | uint32_t hash64[8] __attribute__((aligned(32))); 114 | uint32_t endiandata[32]; 115 | 116 | uint64_t htmax[] = { 117 | 0, 118 | 0xF, 119 | 0xFF, 120 | 0xFFF, 121 | 0xFFFF, 122 | 0x10000000 123 | }; 124 | uint32_t masks[] = { 125 | 0xFFFFFFFF, 126 | 0xFFFFFFF0, 127 | 0xFFFFFF00, 128 | 0xFFFFF000, 129 | 0xFFFF0000, 130 | 0 131 | }; 132 | 133 | // we need bigendian data... 134 | for (int kk=0; kk < 32; kk++) { 135 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 136 | }; 137 | #ifdef DEBUG_ALGO 138 | if (Htarg != 0) 139 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 140 | #endif 141 | for (int m=0; m < sizeof(masks); m++) { 142 | if (Htarg <= htmax[m]) { 143 | uint32_t mask = masks[m]; 144 | do { 145 | pdata[19] = ++n; 146 | be32enc(&endiandata[19], n); 147 | x14hash(hash64, &endiandata); 148 | #ifndef DEBUG_ALGO 149 | if ((!(hash64[7] & mask)) && fulltest(hash64, ptarget)) { 150 | *hashes_done = n - first_nonce + 1; 151 | return true; 152 | } 153 | #else 154 | if (!(n % 0x1000) && !thr_id) printf("."); 155 | if (!(hash64[7] & mask)) { 156 | printf("[%d]",thr_id); 157 | if (fulltest(hash64, ptarget)) { 158 | *hashes_done = n - first_nonce + 1; 159 | return true; 160 | } 161 | } 162 | #endif 163 | } while (n < max_nonce && !work_restart[thr_id].restart); 164 | // see blake.c if else to understand the loop on htmax => mask 165 | break; 166 | } 167 | } 168 | 169 | *hashes_done = n - first_nonce + 1; 170 | pdata[19] = n; 171 | return 0; 172 | } 173 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/x15.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_blake.h" 9 | #include "sha3/sph_bmw.h" 10 | #include "sha3/sph_groestl.h" 11 | #include "sha3/sph_jh.h" 12 | #include "sha3/sph_keccak.h" 13 | #include "sha3/sph_skein.h" 14 | #include "sha3/sph_luffa.h" 15 | #include "sha3/sph_cubehash.h" 16 | #include "sha3/sph_shavite.h" 17 | #include "sha3/sph_simd.h" 18 | #include "sha3/sph_echo.h" 19 | #include "sha3/sph_hamsi.h" 20 | #include "sha3/sph_fugue.h" 21 | #include "sha3/sph_shabal.h" 22 | #include "sha3/sph_whirlpool.h" 23 | 24 | //#define DEBUG_ALGO 25 | 26 | static void x15hash(void *output, const void *input) 27 | { 28 | unsigned char hash[128]; // uint32_t hashA[16], hashB[16]; 29 | #define hashB hash+64 30 | 31 | memset(hash, 0, 128); 32 | 33 | sph_blake512_context ctx_blake; 34 | sph_bmw512_context ctx_bmw; 35 | sph_groestl512_context ctx_groestl; 36 | sph_jh512_context ctx_jh; 37 | sph_keccak512_context ctx_keccak; 38 | sph_skein512_context ctx_skein; 39 | sph_luffa512_context ctx_luffa; 40 | sph_cubehash512_context ctx_cubehash; 41 | sph_shavite512_context ctx_shavite; 42 | sph_simd512_context ctx_simd; 43 | sph_echo512_context ctx_echo; 44 | sph_hamsi512_context ctx_hamsi; 45 | sph_fugue512_context ctx_fugue; 46 | sph_shabal512_context ctx_shabal; 47 | sph_whirlpool_context ctx_whirlpool; 48 | 49 | sph_blake512_init(&ctx_blake); 50 | sph_blake512(&ctx_blake, input, 80); 51 | sph_blake512_close(&ctx_blake, hash); 52 | 53 | sph_bmw512_init(&ctx_bmw); 54 | sph_bmw512(&ctx_bmw, hash, 64); 55 | sph_bmw512_close(&ctx_bmw, hashB); 56 | 57 | sph_groestl512_init(&ctx_groestl); 58 | sph_groestl512(&ctx_groestl, hashB, 64); 59 | sph_groestl512_close(&ctx_groestl, hash); 60 | 61 | sph_skein512_init(&ctx_skein); 62 | sph_skein512(&ctx_skein, hash, 64); 63 | sph_skein512_close(&ctx_skein, hashB); 64 | 65 | sph_jh512_init(&ctx_jh); 66 | sph_jh512(&ctx_jh, hashB, 64); 67 | sph_jh512_close(&ctx_jh, hash); 68 | 69 | sph_keccak512_init(&ctx_keccak); 70 | sph_keccak512(&ctx_keccak, hash, 64); 71 | sph_keccak512_close(&ctx_keccak, hashB); 72 | 73 | sph_luffa512_init(&ctx_luffa); 74 | sph_luffa512(&ctx_luffa, hashB, 64); 75 | sph_luffa512_close(&ctx_luffa, hash); 76 | 77 | sph_cubehash512_init(&ctx_cubehash); 78 | sph_cubehash512(&ctx_cubehash, hash, 64); 79 | sph_cubehash512_close(&ctx_cubehash, hashB); 80 | 81 | sph_shavite512_init(&ctx_shavite); 82 | sph_shavite512(&ctx_shavite, hashB, 64); 83 | sph_shavite512_close(&ctx_shavite, hash); 84 | 85 | sph_simd512_init(&ctx_simd); 86 | sph_simd512(&ctx_simd, hash, 64); 87 | sph_simd512_close(&ctx_simd, hashB); 88 | 89 | sph_echo512_init(&ctx_echo); 90 | sph_echo512(&ctx_echo, hashB, 64); 91 | sph_echo512_close(&ctx_echo, hash); 92 | 93 | sph_hamsi512_init(&ctx_hamsi); 94 | sph_hamsi512(&ctx_hamsi, hash, 64); 95 | sph_hamsi512_close(&ctx_hamsi, hashB); 96 | 97 | sph_fugue512_init(&ctx_fugue); 98 | sph_fugue512(&ctx_fugue, hashB, 64); 99 | sph_fugue512_close(&ctx_fugue, hash); 100 | 101 | sph_shabal512_init(&ctx_shabal); 102 | sph_shabal512(&ctx_shabal, hash, 64); 103 | sph_shabal512_close(&ctx_shabal, hashB); 104 | 105 | sph_whirlpool_init(&ctx_whirlpool); 106 | sph_whirlpool(&ctx_whirlpool, hashB, 64); 107 | sph_whirlpool_close(&ctx_whirlpool, hash); 108 | 109 | memcpy(output, hash, 32); 110 | } 111 | 112 | int scanhash_x15(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 113 | uint32_t max_nonce, uint64_t *hashes_done) 114 | { 115 | uint32_t n = pdata[19] - 1; 116 | const uint32_t first_nonce = pdata[19]; 117 | const uint32_t Htarg = ptarget[7]; 118 | 119 | uint32_t hash64[8] __attribute__((aligned(32))); 120 | uint32_t endiandata[32]; 121 | 122 | uint64_t htmax[] = { 123 | 0, 124 | 0xF, 125 | 0xFF, 126 | 0xFFF, 127 | 0xFFFF, 128 | 0x10000000 129 | }; 130 | uint32_t masks[] = { 131 | 0xFFFFFFFF, 132 | 0xFFFFFFF0, 133 | 0xFFFFFF00, 134 | 0xFFFFF000, 135 | 0xFFFF0000, 136 | 0 137 | }; 138 | 139 | // we need bigendian data... 140 | for (int kk=0; kk < 32; kk++) { 141 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 142 | }; 143 | #ifdef DEBUG_ALGO 144 | if (Htarg != 0) 145 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 146 | #endif 147 | for (int m=0; m < sizeof(masks); m++) { 148 | if (Htarg <= htmax[m]) { 149 | uint32_t mask = masks[m]; 150 | do { 151 | pdata[19] = ++n; 152 | be32enc(&endiandata[19], n); 153 | x15hash(hash64, &endiandata); 154 | #ifndef DEBUG_ALGO 155 | if ((!(hash64[7] & mask)) && fulltest(hash64, ptarget)) { 156 | *hashes_done = n - first_nonce + 1; 157 | return true; 158 | } 159 | #else 160 | if (!(n % 0x1000) && !thr_id) printf("."); 161 | if (!(hash64[7] & mask)) { 162 | printf("[%d]",thr_id); 163 | if (fulltest(hash64, ptarget)) { 164 | *hashes_done = n - first_nonce + 1; 165 | return true; 166 | } 167 | } 168 | #endif 169 | } while (n < max_nonce && !work_restart[thr_id].restart); 170 | // see blake.c if else to understand the loop on htmax => mask 171 | break; 172 | } 173 | } 174 | 175 | *hashes_done = n - first_nonce + 1; 176 | pdata[19] = n; 177 | return 0; 178 | } 179 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/README.md: -------------------------------------------------------------------------------- 1 | CPUMiner-Multi 2 | ============== 3 | 4 | [![Build Status](https://travis-ci.org/lucasjones/cpuminer-multi.svg?branch=master)](https://travis-ci.org/lucasjones/cpuminer-multi) 5 | 6 | This is a multi-threaded CPU miner, 7 | fork of [pooler](//github.com/pooler)'s cpuminer (see AUTHORS for list of contributors). 8 | 9 | #### Table of contents 10 | 11 | * [Algorithms](#algorithms) 12 | * [Dependencies](#dependencies) 13 | * [Download](#download) 14 | * [Build](#build) 15 | * [Usage instructions](#usage-instructions) 16 | * [Donations](#donations) 17 | * [Credits](#credits) 18 | * [License](#license) 19 | 20 | Algorithms 21 | ========== 22 | #### Currently supported 23 | * ✓ __scrypt__ (Litecoin, Dogecoin, Feathercoin, etc..) 24 | * ✓ __scrypt:N__ (Vertcoin [VTC]) 25 | * ✓ __sha256d__ (Bitcoin, Freicoin, Peercoin/PPCoin, Terracoin, etc..) 26 | * ✓ __x11__ (Darkcoin [DRK], Hirocoin, Limecoin) 27 | * ✓ __x13__ (Sherlockcoin, [ACE], [B2B], [GRC], [XHC], etc..) 28 | * ✓ __x14__ (X14, Webcoin [WEB]) 29 | * ✓ __x15__ (RadianceCoin [RCE]) 30 | * ✓ __cryptonight__ (Bytecoin [BCN], Monero) 31 | * ✓ __fresh__ (FreshCoin) 32 | 33 | #### Implemented, but untested 34 | * ? keccak (Maxcoin HelixCoin, CryptoMeth, Galleon, 365coin, Slothcoin, BitcointalkCoin) 35 | * ? hefty1 (Heavycoin) 36 | * ? quark (Quarkcoin) 37 | * ? skein (Skeincoin, Myriadcoin) 38 | * ? shavite3 (INKcoin) 39 | * ? blake (Blakecoin) 40 | 41 | #### Planned support for 42 | * *scrypt-jane* (YaCoin, CopperBars, Pennies, Tickets, etc..) 43 | * *qubit* (Qubitcoin, Myriadcoin) 44 | * *groestl* (Groestlcoin) 45 | 46 | Dependencies 47 | ============ 48 | * libcurl http://curl.haxx.se/libcurl/ 49 | * jansson http://www.digip.org/jansson/ (jansson is included in-tree) 50 | * openssl https://www.openssl.org/ 51 | 52 | Download 53 | ======== 54 | * Binary releases: https://github.com/LucasJones/cpuminer-multi/releases 55 | * Git tree: https://github.com/LucasJones/cpuminer-multi 56 | * Clone with `git clone https://github.com/LucasJones/cpuminer-multi` 57 | 58 | Build 59 | ===== 60 | 61 | #### Basic *nix build instructions: 62 | * ./autogen.sh # only needed if building from git repo 63 | * ./nomacro.pl # only needed if building on Mac OS X or with Clang 64 | * ./configure CFLAGS="*-march=native*" 65 | * # Use -march=native if building for a single machine 66 | * make 67 | 68 | #### Notes for AIX users: 69 | * To build a 64-bit binary, export OBJECT_MODE=64 70 | * GNU-style long options are not supported, but are accessible via configuration file 71 | 72 | #### Basic Windows build instructions, using MinGW: 73 | * Install MinGW and the MSYS Developer Tool Kit (http://www.mingw.org/) 74 | * Make sure you have mstcpip.h in MinGW\include 75 | * If using MinGW-w64, install pthreads-w64 76 | * Install libcurl devel (http://curl.haxx.se/download.html) 77 | * Make sure you have libcurl.m4 in MinGW\share\aclocal 78 | * Make sure you have curl-config in MinGW\bin 79 | * Install openssl devel (https://www.openssl.org/related/binaries.html) 80 | * In the MSYS shell, run: 81 | * ./autogen.sh # only needed if building from git repo 82 | * LIBCURL="-lcurldll" ./configure CFLAGS="*-march=native*" 83 | * # Use -march=native if building for a single machine 84 | * make 85 | 86 | #### Architecture-specific notes: 87 | * ARM: 88 | * No runtime CPU detection. The miner can take advantage of some instructions specific to ARMv5E and later processors, but the decision whether to use them is made at compile time, based on compiler-defined macros. 89 | * To use NEON instructions, add "-mfpu=neon" to CFLAGS. 90 | * x86: 91 | * The miner checks for SSE2 instructions support at runtime, and uses them if they are available. 92 | * x86-64: 93 | * The miner can take advantage of AVX, AVX2 and XOP instructions, but only if both the CPU and the operating system support them. 94 | * Linux supports AVX starting from kernel version 2.6.30. 95 | * FreeBSD supports AVX starting with 9.1-RELEASE. 96 | * Mac OS X added AVX support in the 10.6.8 update. 97 | * Windows supports AVX starting from Windows 7 SP1 and Windows Server 2008 R2 SP1. 98 | * The configure script outputs a warning if the assembler doesn't support some instruction sets. In that case, the miner can still be built, but unavailable optimizations are left off. 99 | 100 | Usage instructions 101 | ================== 102 | Run "minerd --help" to see options. 103 | 104 | ### Connecting through a proxy 105 | 106 | Use the --proxy option. 107 | 108 | To use a SOCKS proxy, add a socks4:// or socks5:// prefix to the proxy host 109 | Protocols socks4a and socks5h, allowing remote name resolving, are also available since libcurl 7.18.0. 110 | 111 | If no protocol is specified, the proxy is assumed to be a HTTP proxy. 112 | When the --proxy option is not used, the program honors the http_proxy and all_proxy environment variables. 113 | 114 | Donations 115 | ========= 116 | Donations for the work done in this fork are accepted at 117 | * MRO: `472haywQKoxFzf7asaQ4XKBc2foAY4ezk8HiN63ifW4iAbJiLnfmJfhHSR9XmVKw2WYPnszJV9MEHj9Z5WMK9VCNHaGLDmJ` 118 | * BTC: `139QWoktddChHsZMWZFxmBva4FM96X2dhE` 119 | 120 | Credits 121 | ======= 122 | CPUMiner-multi was forked from pooler's CPUMiner, and has been developed by Lucas Jones. 123 | * [tpruvot](https://github.com/tpruvot) added some features and recent SHA3 based algorythmns 124 | * [Wolf9466](https://github.com/wolf9466) helped with Intel AES-NI support for CryptoNight 125 | 126 | License 127 | ======= 128 | GPLv2. See COPYING for details. 129 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/groestl_tables.h: -------------------------------------------------------------------------------- 1 | #ifndef __tables_h 2 | #define __tables_h 3 | 4 | 5 | const uint32_t T[512] = {0xa5f432c6, 0xc6a597f4, 0x84976ff8, 0xf884eb97, 0x99b05eee, 0xee99c7b0, 0x8d8c7af6, 0xf68df78c, 0xd17e8ff, 0xff0de517, 0xbddc0ad6, 0xd6bdb7dc, 0xb1c816de, 0xdeb1a7c8, 0x54fc6d91, 0x915439fc 6 | , 0x50f09060, 0x6050c0f0, 0x3050702, 0x2030405, 0xa9e02ece, 0xcea987e0, 0x7d87d156, 0x567dac87, 0x192bcce7, 0xe719d52b, 0x62a613b5, 0xb56271a6, 0xe6317c4d, 0x4de69a31, 0x9ab559ec, 0xec9ac3b5 7 | , 0x45cf408f, 0x8f4505cf, 0x9dbca31f, 0x1f9d3ebc, 0x40c04989, 0x894009c0, 0x879268fa, 0xfa87ef92, 0x153fd0ef, 0xef15c53f, 0xeb2694b2, 0xb2eb7f26, 0xc940ce8e, 0x8ec90740, 0xb1de6fb, 0xfb0bed1d 8 | , 0xec2f6e41, 0x41ec822f, 0x67a91ab3, 0xb3677da9, 0xfd1c435f, 0x5ffdbe1c, 0xea256045, 0x45ea8a25, 0xbfdaf923, 0x23bf46da, 0xf7025153, 0x53f7a602, 0x96a145e4, 0xe496d3a1, 0x5bed769b, 0x9b5b2ded 9 | , 0xc25d2875, 0x75c2ea5d, 0x1c24c5e1, 0xe11cd924, 0xaee9d43d, 0x3dae7ae9, 0x6abef24c, 0x4c6a98be, 0x5aee826c, 0x6c5ad8ee, 0x41c3bd7e, 0x7e41fcc3, 0x206f3f5, 0xf502f106, 0x4fd15283, 0x834f1dd1 10 | , 0x5ce48c68, 0x685cd0e4, 0xf4075651, 0x51f4a207, 0x345c8dd1, 0xd134b95c, 0x818e1f9, 0xf908e918, 0x93ae4ce2, 0xe293dfae, 0x73953eab, 0xab734d95, 0x53f59762, 0x6253c4f5, 0x3f416b2a, 0x2a3f5441 11 | , 0xc141c08, 0x80c1014, 0x52f66395, 0x955231f6, 0x65afe946, 0x46658caf, 0x5ee27f9d, 0x9d5e21e2, 0x28784830, 0x30286078, 0xa1f8cf37, 0x37a16ef8, 0xf111b0a, 0xa0f1411, 0xb5c4eb2f, 0x2fb55ec4 12 | , 0x91b150e, 0xe091c1b, 0x365a7e24, 0x2436485a, 0x9bb6ad1b, 0x1b9b36b6, 0x3d4798df, 0xdf3da547, 0x266aa7cd, 0xcd26816a, 0x69bbf54e, 0x4e699cbb, 0xcd4c337f, 0x7fcdfe4c, 0x9fba50ea, 0xea9fcfba 13 | , 0x1b2d3f12, 0x121b242d, 0x9eb9a41d, 0x1d9e3ab9, 0x749cc458, 0x5874b09c, 0x2e724634, 0x342e6872, 0x2d774136, 0x362d6c77, 0xb2cd11dc, 0xdcb2a3cd, 0xee299db4, 0xb4ee7329, 0xfb164d5b, 0x5bfbb616 14 | , 0xf601a5a4, 0xa4f65301, 0x4dd7a176, 0x764decd7, 0x61a314b7, 0xb76175a3, 0xce49347d, 0x7dcefa49, 0x7b8ddf52, 0x527ba48d, 0x3e429fdd, 0xdd3ea142, 0x7193cd5e, 0x5e71bc93, 0x97a2b113, 0x139726a2 15 | , 0xf504a2a6, 0xa6f55704, 0x68b801b9, 0xb96869b8, 0x0, 0x0, 0x2c74b5c1, 0xc12c9974, 0x60a0e040, 0x406080a0, 0x1f21c2e3, 0xe31fdd21, 0xc8433a79, 0x79c8f243, 0xed2c9ab6, 0xb6ed772c 16 | , 0xbed90dd4, 0xd4beb3d9, 0x46ca478d, 0x8d4601ca, 0xd9701767, 0x67d9ce70, 0x4bddaf72, 0x724be4dd, 0xde79ed94, 0x94de3379, 0xd467ff98, 0x98d42b67, 0xe82393b0, 0xb0e87b23, 0x4ade5b85, 0x854a11de 17 | , 0x6bbd06bb, 0xbb6b6dbd, 0x2a7ebbc5, 0xc52a917e, 0xe5347b4f, 0x4fe59e34, 0x163ad7ed, 0xed16c13a, 0xc554d286, 0x86c51754, 0xd762f89a, 0x9ad72f62, 0x55ff9966, 0x6655ccff, 0x94a7b611, 0x119422a7 18 | , 0xcf4ac08a, 0x8acf0f4a, 0x1030d9e9, 0xe910c930, 0x60a0e04, 0x406080a, 0x819866fe, 0xfe81e798, 0xf00baba0, 0xa0f05b0b, 0x44ccb478, 0x7844f0cc, 0xbad5f025, 0x25ba4ad5, 0xe33e754b, 0x4be3963e 19 | , 0xf30eaca2, 0xa2f35f0e, 0xfe19445d, 0x5dfeba19, 0xc05bdb80, 0x80c01b5b, 0x8a858005, 0x58a0a85, 0xadecd33f, 0x3fad7eec, 0xbcdffe21, 0x21bc42df, 0x48d8a870, 0x7048e0d8, 0x40cfdf1, 0xf104f90c 20 | , 0xdf7a1963, 0x63dfc67a, 0xc1582f77, 0x77c1ee58, 0x759f30af, 0xaf75459f, 0x63a5e742, 0x426384a5, 0x30507020, 0x20304050, 0x1a2ecbe5, 0xe51ad12e, 0xe12effd, 0xfd0ee112, 0x6db708bf, 0xbf6d65b7 21 | , 0x4cd45581, 0x814c19d4, 0x143c2418, 0x1814303c, 0x355f7926, 0x26354c5f, 0x2f71b2c3, 0xc32f9d71, 0xe13886be, 0xbee16738, 0xa2fdc835, 0x35a26afd, 0xcc4fc788, 0x88cc0b4f, 0x394b652e, 0x2e395c4b 22 | , 0x57f96a93, 0x93573df9, 0xf20d5855, 0x55f2aa0d, 0x829d61fc, 0xfc82e39d, 0x47c9b37a, 0x7a47f4c9, 0xacef27c8, 0xc8ac8bef, 0xe73288ba, 0xbae76f32, 0x2b7d4f32, 0x322b647d, 0x95a442e6, 0xe695d7a4 23 | , 0xa0fb3bc0, 0xc0a09bfb, 0x98b3aa19, 0x199832b3, 0xd168f69e, 0x9ed12768, 0x7f8122a3, 0xa37f5d81, 0x66aaee44, 0x446688aa, 0x7e82d654, 0x547ea882, 0xabe6dd3b, 0x3bab76e6, 0x839e950b, 0xb83169e 24 | , 0xca45c98c, 0x8cca0345, 0x297bbcc7, 0xc729957b, 0xd36e056b, 0x6bd3d66e, 0x3c446c28, 0x283c5044, 0x798b2ca7, 0xa779558b, 0xe23d81bc, 0xbce2633d, 0x1d273116, 0x161d2c27, 0x769a37ad, 0xad76419a 25 | , 0x3b4d96db, 0xdb3bad4d, 0x56fa9e64, 0x6456c8fa, 0x4ed2a674, 0x744ee8d2, 0x1e223614, 0x141e2822, 0xdb76e492, 0x92db3f76, 0xa1e120c, 0xc0a181e, 0x6cb4fc48, 0x486c90b4, 0xe4378fb8, 0xb8e46b37 26 | , 0x5de7789f, 0x9f5d25e7, 0x6eb20fbd, 0xbd6e61b2, 0xef2a6943, 0x43ef862a, 0xa6f135c4, 0xc4a693f1, 0xa8e3da39, 0x39a872e3, 0xa4f7c631, 0x31a462f7, 0x37598ad3, 0xd337bd59, 0x8b8674f2, 0xf28bff86 27 | , 0x325683d5, 0xd532b156, 0x43c54e8b, 0x8b430dc5, 0x59eb856e, 0x6e59dceb, 0xb7c218da, 0xdab7afc2, 0x8c8f8e01, 0x18c028f, 0x64ac1db1, 0xb16479ac, 0xd26df19c, 0x9cd2236d, 0xe03b7249, 0x49e0923b 28 | , 0xb4c71fd8, 0xd8b4abc7, 0xfa15b9ac, 0xacfa4315, 0x709faf3, 0xf307fd09, 0x256fa0cf, 0xcf25856f, 0xafea20ca, 0xcaaf8fea, 0x8e897df4, 0xf48ef389, 0xe9206747, 0x47e98e20, 0x18283810, 0x10182028 29 | , 0xd5640b6f, 0x6fd5de64, 0x888373f0, 0xf088fb83, 0x6fb1fb4a, 0x4a6f94b1, 0x7296ca5c, 0x5c72b896, 0x246c5438, 0x3824706c, 0xf1085f57, 0x57f1ae08, 0xc7522173, 0x73c7e652, 0x51f36497, 0x975135f3 30 | , 0x2365aecb, 0xcb238d65, 0x7c8425a1, 0xa17c5984, 0x9cbf57e8, 0xe89ccbbf, 0x21635d3e, 0x3e217c63, 0xdd7cea96, 0x96dd377c, 0xdc7f1e61, 0x61dcc27f, 0x86919c0d, 0xd861a91, 0x85949b0f, 0xf851e94 31 | , 0x90ab4be0, 0xe090dbab, 0x42c6ba7c, 0x7c42f8c6, 0xc4572671, 0x71c4e257, 0xaae529cc, 0xccaa83e5, 0xd873e390, 0x90d83b73, 0x50f0906, 0x6050c0f, 0x103f4f7, 0xf701f503, 0x12362a1c, 0x1c123836 32 | , 0xa3fe3cc2, 0xc2a39ffe, 0x5fe18b6a, 0x6a5fd4e1, 0xf910beae, 0xaef94710, 0xd06b0269, 0x69d0d26b, 0x91a8bf17, 0x17912ea8, 0x58e87199, 0x995829e8, 0x2769533a, 0x3a277469, 0xb9d0f727, 0x27b94ed0 33 | , 0x384891d9, 0xd938a948, 0x1335deeb, 0xeb13cd35, 0xb3cee52b, 0x2bb356ce, 0x33557722, 0x22334455, 0xbbd604d2, 0xd2bbbfd6, 0x709039a9, 0xa9704990, 0x89808707, 0x7890e80, 0xa7f2c133, 0x33a766f2 34 | , 0xb6c1ec2d, 0x2db65ac1, 0x22665a3c, 0x3c227866, 0x92adb815, 0x15922aad, 0x2060a9c9, 0xc9208960, 0x49db5c87, 0x874915db, 0xff1ab0aa, 0xaaff4f1a, 0x7888d850, 0x5078a088, 0x7a8e2ba5, 0xa57a518e 35 | , 0x8f8a8903, 0x38f068a, 0xf8134a59, 0x59f8b213, 0x809b9209, 0x980129b, 0x1739231a, 0x1a173439, 0xda751065, 0x65daca75, 0x315384d7, 0xd731b553, 0xc651d584, 0x84c61351, 0xb8d303d0, 0xd0b8bbd3 36 | , 0xc35edc82, 0x82c31f5e, 0xb0cbe229, 0x29b052cb, 0x7799c35a, 0x5a77b499, 0x11332d1e, 0x1e113c33, 0xcb463d7b, 0x7bcbf646, 0xfc1fb7a8, 0xa8fc4b1f, 0xd6610c6d, 0x6dd6da61, 0x3a4e622c, 0x2c3a584e}; 37 | 38 | #endif /* __tables_h */ 39 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/int-util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #if defined(_MSC_VER) 14 | #include 15 | 16 | static inline uint32_t rol32(uint32_t x, int r) { 17 | static_assert(sizeof(uint32_t) == sizeof(unsigned int), "this code assumes 32-bit integers"); 18 | return _rotl(x, r); 19 | } 20 | 21 | static inline uint64_t rol64(uint64_t x, int r) { 22 | return _rotl64(x, r); 23 | } 24 | 25 | #else 26 | 27 | static inline uint32_t rol32(uint32_t x, int r) { 28 | return (x << (r & 31)) | (x >> (-r & 31)); 29 | } 30 | 31 | static inline uint64_t rol64(uint64_t x, int r) { 32 | return (x << (r & 63)) | (x >> (-r & 63)); 33 | } 34 | 35 | #endif 36 | 37 | static inline uint64_t hi_dword(uint64_t val) { 38 | return val >> 32; 39 | } 40 | 41 | static inline uint64_t lo_dword(uint64_t val) { 42 | return val & 0xFFFFFFFF; 43 | } 44 | 45 | extern uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi); 46 | 47 | static inline uint64_t div_with_reminder(uint64_t dividend, uint32_t divisor, uint32_t* remainder) { 48 | dividend |= ((uint64_t)*remainder) << 32; 49 | *remainder = dividend % divisor; 50 | return dividend / divisor; 51 | } 52 | 53 | // Long division with 2^32 base 54 | static inline uint32_t div128_32(uint64_t dividend_hi, uint64_t dividend_lo, uint32_t divisor, uint64_t* quotient_hi, uint64_t* quotient_lo) { 55 | uint64_t dividend_dwords[4]; 56 | uint32_t remainder = 0; 57 | 58 | dividend_dwords[3] = hi_dword(dividend_hi); 59 | dividend_dwords[2] = lo_dword(dividend_hi); 60 | dividend_dwords[1] = hi_dword(dividend_lo); 61 | dividend_dwords[0] = lo_dword(dividend_lo); 62 | 63 | *quotient_hi = div_with_reminder(dividend_dwords[3], divisor, &remainder) << 32; 64 | *quotient_hi |= div_with_reminder(dividend_dwords[2], divisor, &remainder); 65 | *quotient_lo = div_with_reminder(dividend_dwords[1], divisor, &remainder) << 32; 66 | *quotient_lo |= div_with_reminder(dividend_dwords[0], divisor, &remainder); 67 | 68 | return remainder; 69 | } 70 | 71 | #define IDENT32(x) ((uint32_t) (x)) 72 | #define IDENT64(x) ((uint64_t) (x)) 73 | 74 | #define SWAP32(x) ((((uint32_t) (x) & 0x000000ff) << 24) | \ 75 | (((uint32_t) (x) & 0x0000ff00) << 8) | \ 76 | (((uint32_t) (x) & 0x00ff0000) >> 8) | \ 77 | (((uint32_t) (x) & 0xff000000) >> 24)) 78 | #define SWAP64(x) ((((uint64_t) (x) & 0x00000000000000ff) << 56) | \ 79 | (((uint64_t) (x) & 0x000000000000ff00) << 40) | \ 80 | (((uint64_t) (x) & 0x0000000000ff0000) << 24) | \ 81 | (((uint64_t) (x) & 0x00000000ff000000) << 8) | \ 82 | (((uint64_t) (x) & 0x000000ff00000000) >> 8) | \ 83 | (((uint64_t) (x) & 0x0000ff0000000000) >> 24) | \ 84 | (((uint64_t) (x) & 0x00ff000000000000) >> 40) | \ 85 | (((uint64_t) (x) & 0xff00000000000000) >> 56)) 86 | 87 | static inline uint32_t ident32(uint32_t x) { return x; } 88 | static inline uint64_t ident64(uint64_t x) { return x; } 89 | 90 | static inline uint32_t swap32(uint32_t x) { 91 | x = ((x & 0x00ff00ff) << 8) | ((x & 0xff00ff00) >> 8); 92 | return (x << 16) | (x >> 16); 93 | } 94 | static inline uint64_t swap64(uint64_t x) { 95 | x = ((x & 0x00ff00ff00ff00ff) << 8) | ((x & 0xff00ff00ff00ff00) >> 8); 96 | x = ((x & 0x0000ffff0000ffff) << 16) | ((x & 0xffff0000ffff0000) >> 16); 97 | return (x << 32) | (x >> 32); 98 | } 99 | 100 | #if defined(__GNUC__) 101 | #define UNUSED __attribute__((unused)) 102 | #else 103 | #define UNUSED 104 | #endif 105 | static inline void mem_inplace_ident(void *mem UNUSED, size_t n UNUSED) { } 106 | #undef UNUSED 107 | 108 | static inline void mem_inplace_swap32(void *mem, size_t n) { 109 | size_t i; 110 | for (i = 0; i < n; i++) { 111 | ((uint32_t *) mem)[i] = swap32(((const uint32_t *) mem)[i]); 112 | } 113 | } 114 | static inline void mem_inplace_swap64(void *mem, size_t n) { 115 | size_t i; 116 | for (i = 0; i < n; i++) { 117 | ((uint64_t *) mem)[i] = swap64(((const uint64_t *) mem)[i]); 118 | } 119 | } 120 | 121 | static inline void memcpy_ident32(void *dst, const void *src, size_t n) { 122 | memcpy(dst, src, 4 * n); 123 | } 124 | static inline void memcpy_ident64(void *dst, const void *src, size_t n) { 125 | memcpy(dst, src, 8 * n); 126 | } 127 | 128 | static inline void memcpy_swap32(void *dst, const void *src, size_t n) { 129 | size_t i; 130 | for (i = 0; i < n; i++) { 131 | ((uint32_t *) dst)[i] = swap32(((const uint32_t *) src)[i]); 132 | } 133 | } 134 | static inline void memcpy_swap64(void *dst, const void *src, size_t n) { 135 | size_t i; 136 | for (i = 0; i < n; i++) { 137 | ((uint64_t *) dst)[i] = swap64(((const uint64_t *) src)[i]); 138 | } 139 | } 140 | 141 | #if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN) 142 | static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not enabled"); 143 | #endif 144 | 145 | #if BYTE_ORDER == LITTLE_ENDIAN 146 | #define SWAP32LE IDENT32 147 | #define SWAP32BE SWAP32 148 | #define swap32le ident32 149 | #define swap32be swap32 150 | #define mem_inplace_swap32le mem_inplace_ident 151 | #define mem_inplace_swap32be mem_inplace_swap32 152 | #define memcpy_swap32le memcpy_ident32 153 | #define memcpy_swap32be memcpy_swap32 154 | #define SWAP64LE IDENT64 155 | #define SWAP64BE SWAP64 156 | #define swap64le ident64 157 | #define swap64be swap64 158 | #define mem_inplace_swap64le mem_inplace_ident 159 | #define mem_inplace_swap64be mem_inplace_swap64 160 | #define memcpy_swap64le memcpy_ident64 161 | #define memcpy_swap64be memcpy_swap64 162 | #endif 163 | 164 | #if BYTE_ORDER == BIG_ENDIAN 165 | #define SWAP32BE IDENT32 166 | #define SWAP32LE SWAP32 167 | #define swap32be ident32 168 | #define swap32le swap32 169 | #define mem_inplace_swap32be mem_inplace_ident 170 | #define mem_inplace_swap32le mem_inplace_swap32 171 | #define memcpy_swap32be memcpy_ident32 172 | #define memcpy_swap32le memcpy_swap32 173 | #define SWAP64BE IDENT64 174 | #define SWAP64LE SWAP64 175 | #define swap64be ident64 176 | #define swap64le swap64 177 | #define mem_inplace_swap64be mem_inplace_ident 178 | #define mem_inplace_swap64le mem_inplace_swap64 179 | #define memcpy_swap64be memcpy_ident64 180 | #define memcpy_swap64le memcpy_swap64 181 | #endif 182 | -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/jansson.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef JANSSON_H 9 | #define JANSSON_H 10 | 11 | #include 12 | 13 | #ifndef __cplusplus 14 | #define JSON_INLINE inline 15 | #else 16 | #define JSON_INLINE inline 17 | extern "C" { 18 | #endif 19 | 20 | /* types */ 21 | 22 | typedef enum { 23 | JSON_OBJECT, 24 | JSON_ARRAY, 25 | JSON_STRING, 26 | JSON_INTEGER, 27 | JSON_REAL, 28 | JSON_TRUE, 29 | JSON_FALSE, 30 | JSON_NULL 31 | } json_type; 32 | 33 | typedef struct { 34 | json_type type; 35 | unsigned long refcount; 36 | } json_t; 37 | 38 | #define json_typeof(json) ((json)->type) 39 | #define json_is_object(json) (json && json_typeof(json) == JSON_OBJECT) 40 | #define json_is_array(json) (json && json_typeof(json) == JSON_ARRAY) 41 | #define json_is_string(json) (json && json_typeof(json) == JSON_STRING) 42 | #define json_is_integer(json) (json && json_typeof(json) == JSON_INTEGER) 43 | #define json_is_real(json) (json && json_typeof(json) == JSON_REAL) 44 | #define json_is_number(json) (json_is_integer(json) || json_is_real(json)) 45 | #define json_is_true(json) (json && json_typeof(json) == JSON_TRUE) 46 | #define json_is_false(json) (json && json_typeof(json) == JSON_FALSE) 47 | #define json_is_boolean(json) (json_is_true(json) || json_is_false(json)) 48 | #define json_is_null(json) (json && json_typeof(json) == JSON_NULL) 49 | 50 | /* construction, destruction, reference counting */ 51 | 52 | json_t *json_object(void); 53 | json_t *json_array(void); 54 | json_t *json_string(const char *value); 55 | json_t *json_string_nocheck(const char *value); 56 | json_t *json_integer(int value); 57 | json_t *json_real(double value); 58 | json_t *json_true(void); 59 | json_t *json_false(void); 60 | json_t *json_null(void); 61 | 62 | static JSON_INLINE 63 | json_t *json_incref(json_t *json) 64 | { 65 | if(json && json->refcount != (unsigned int)-1) 66 | ++json->refcount; 67 | return json; 68 | } 69 | 70 | /* do not call json_delete directly */ 71 | void json_delete(json_t *json); 72 | 73 | static JSON_INLINE 74 | void json_decref(json_t *json) 75 | { 76 | if(json && json->refcount != (unsigned int)-1 && --json->refcount == 0) 77 | json_delete(json); 78 | } 79 | 80 | 81 | /* getters, setters, manipulation */ 82 | 83 | unsigned int json_object_size(const json_t *object); 84 | json_t *json_object_get(const json_t *object, const char *key); 85 | int json_object_set_new(json_t *object, const char *key, json_t *value); 86 | int json_object_set_new_nocheck(json_t *object, const char *key, json_t *value); 87 | int json_object_del(json_t *object, const char *key); 88 | int json_object_clear(json_t *object); 89 | int json_object_update(json_t *object, json_t *other); 90 | void *json_object_iter(json_t *object); 91 | void *json_object_iter_at(json_t *object, const char *key); 92 | void *json_object_iter_next(json_t *object, void *iter); 93 | const char *json_object_iter_key(void *iter); 94 | json_t *json_object_iter_value(void *iter); 95 | int json_object_iter_set_new(json_t *object, void *iter, json_t *value); 96 | 97 | static JSON_INLINE 98 | int json_object_set(json_t *object, const char *key, json_t *value) 99 | { 100 | return json_object_set_new(object, key, json_incref(value)); 101 | } 102 | 103 | static JSON_INLINE 104 | int json_object_set_nocheck(json_t *object, const char *key, json_t *value) 105 | { 106 | return json_object_set_new_nocheck(object, key, json_incref(value)); 107 | } 108 | 109 | static inline 110 | int json_object_iter_set(json_t *object, void *iter, json_t *value) 111 | { 112 | return json_object_iter_set_new(object, iter, json_incref(value)); 113 | } 114 | 115 | unsigned int json_array_size(const json_t *array); 116 | json_t *json_array_get(const json_t *array, unsigned int index); 117 | int json_array_set_new(json_t *array, unsigned int index, json_t *value); 118 | int json_array_append_new(json_t *array, json_t *value); 119 | int json_array_insert_new(json_t *array, unsigned int index, json_t *value); 120 | int json_array_remove(json_t *array, unsigned int index); 121 | int json_array_clear(json_t *array); 122 | int json_array_extend(json_t *array, json_t *other); 123 | 124 | static JSON_INLINE 125 | int json_array_set(json_t *array, unsigned int index, json_t *value) 126 | { 127 | return json_array_set_new(array, index, json_incref(value)); 128 | } 129 | 130 | static JSON_INLINE 131 | int json_array_append(json_t *array, json_t *value) 132 | { 133 | return json_array_append_new(array, json_incref(value)); 134 | } 135 | 136 | static JSON_INLINE 137 | int json_array_insert(json_t *array, unsigned int index, json_t *value) 138 | { 139 | return json_array_insert_new(array, index, json_incref(value)); 140 | } 141 | 142 | const char *json_string_value(const json_t *string); 143 | int json_integer_value(const json_t *integer); 144 | double json_real_value(const json_t *real); 145 | double json_number_value(const json_t *json); 146 | 147 | int json_string_set(json_t *string, const char *value); 148 | int json_string_set_nocheck(json_t *string, const char *value); 149 | int json_integer_set(json_t *integer, int value); 150 | int json_real_set(json_t *real, double value); 151 | 152 | 153 | /* equality */ 154 | 155 | int json_equal(json_t *value1, json_t *value2); 156 | 157 | 158 | /* copying */ 159 | 160 | json_t *json_copy(json_t *value); 161 | json_t *json_deep_copy(json_t *value); 162 | 163 | 164 | /* loading, printing */ 165 | 166 | #define JSON_ERROR_TEXT_LENGTH 160 167 | 168 | typedef struct { 169 | char text[JSON_ERROR_TEXT_LENGTH]; 170 | int line; 171 | } json_error_t; 172 | 173 | json_t *json_loads(const char *input, json_error_t *error); 174 | json_t *json_loadf(FILE *input, json_error_t *error); 175 | json_t *json_load_file(const char *path, json_error_t *error); 176 | 177 | #define JSON_INDENT(n) (n & 0xFF) 178 | #define JSON_COMPACT 0x100 179 | #define JSON_ENSURE_ASCII 0x200 180 | #define JSON_SORT_KEYS 0x400 181 | #define JSON_PRESERVE_ORDER 0x800 182 | 183 | char *json_dumps(const json_t *json, unsigned long flags); 184 | int json_dumpf(const json_t *json, FILE *output, unsigned long flags); 185 | int json_dump_file(const json_t *json, const char *path, unsigned long flags); 186 | 187 | #ifdef __cplusplus 188 | } 189 | #endif 190 | 191 | #endif 192 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/jansson.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef JANSSON_H 9 | #define JANSSON_H 10 | 11 | #include 12 | 13 | #ifndef __cplusplus 14 | #define JSON_INLINE inline 15 | #else 16 | #define JSON_INLINE inline 17 | extern "C" { 18 | #endif 19 | 20 | /* types */ 21 | 22 | typedef enum { 23 | JSON_OBJECT, 24 | JSON_ARRAY, 25 | JSON_STRING, 26 | JSON_INTEGER, 27 | JSON_REAL, 28 | JSON_TRUE, 29 | JSON_FALSE, 30 | JSON_NULL 31 | } json_type; 32 | 33 | typedef struct { 34 | json_type type; 35 | unsigned long refcount; 36 | } json_t; 37 | 38 | #define json_typeof(json) ((json)->type) 39 | #define json_is_object(json) (json && json_typeof(json) == JSON_OBJECT) 40 | #define json_is_array(json) (json && json_typeof(json) == JSON_ARRAY) 41 | #define json_is_string(json) (json && json_typeof(json) == JSON_STRING) 42 | #define json_is_integer(json) (json && json_typeof(json) == JSON_INTEGER) 43 | #define json_is_real(json) (json && json_typeof(json) == JSON_REAL) 44 | #define json_is_number(json) (json_is_integer(json) || json_is_real(json)) 45 | #define json_is_true(json) (json && json_typeof(json) == JSON_TRUE) 46 | #define json_is_false(json) (json && json_typeof(json) == JSON_FALSE) 47 | #define json_is_boolean(json) (json_is_true(json) || json_is_false(json)) 48 | #define json_is_null(json) (json && json_typeof(json) == JSON_NULL) 49 | 50 | /* construction, destruction, reference counting */ 51 | 52 | json_t *json_object(void); 53 | json_t *json_array(void); 54 | json_t *json_string(const char *value); 55 | json_t *json_string_nocheck(const char *value); 56 | json_t *json_integer(int value); 57 | json_t *json_real(double value); 58 | json_t *json_true(void); 59 | json_t *json_false(void); 60 | json_t *json_null(void); 61 | 62 | static JSON_INLINE 63 | json_t *json_incref(json_t *json) 64 | { 65 | if(json && json->refcount != (unsigned int)-1) 66 | ++json->refcount; 67 | return json; 68 | } 69 | 70 | /* do not call json_delete directly */ 71 | void json_delete(json_t *json); 72 | 73 | static JSON_INLINE 74 | void json_decref(json_t *json) 75 | { 76 | if(json && json->refcount != (unsigned int)-1 && --json->refcount == 0) 77 | json_delete(json); 78 | } 79 | 80 | 81 | /* getters, setters, manipulation */ 82 | 83 | unsigned int json_object_size(const json_t *object); 84 | json_t *json_object_get(const json_t *object, const char *key); 85 | int json_object_set_new(json_t *object, const char *key, json_t *value); 86 | int json_object_set_new_nocheck(json_t *object, const char *key, json_t *value); 87 | int json_object_del(json_t *object, const char *key); 88 | int json_object_clear(json_t *object); 89 | int json_object_update(json_t *object, json_t *other); 90 | void *json_object_iter(json_t *object); 91 | void *json_object_iter_at(json_t *object, const char *key); 92 | void *json_object_iter_next(json_t *object, void *iter); 93 | const char *json_object_iter_key(void *iter); 94 | json_t *json_object_iter_value(void *iter); 95 | int json_object_iter_set_new(json_t *object, void *iter, json_t *value); 96 | 97 | static JSON_INLINE 98 | int json_object_set(json_t *object, const char *key, json_t *value) 99 | { 100 | return json_object_set_new(object, key, json_incref(value)); 101 | } 102 | 103 | static JSON_INLINE 104 | int json_object_set_nocheck(json_t *object, const char *key, json_t *value) 105 | { 106 | return json_object_set_new_nocheck(object, key, json_incref(value)); 107 | } 108 | 109 | static inline 110 | int json_object_iter_set(json_t *object, void *iter, json_t *value) 111 | { 112 | return json_object_iter_set_new(object, iter, json_incref(value)); 113 | } 114 | 115 | unsigned int json_array_size(const json_t *array); 116 | json_t *json_array_get(const json_t *array, unsigned int index); 117 | int json_array_set_new(json_t *array, unsigned int index, json_t *value); 118 | int json_array_append_new(json_t *array, json_t *value); 119 | int json_array_insert_new(json_t *array, unsigned int index, json_t *value); 120 | int json_array_remove(json_t *array, unsigned int index); 121 | int json_array_clear(json_t *array); 122 | int json_array_extend(json_t *array, json_t *other); 123 | 124 | static JSON_INLINE 125 | int json_array_set(json_t *array, unsigned int index, json_t *value) 126 | { 127 | return json_array_set_new(array, index, json_incref(value)); 128 | } 129 | 130 | static JSON_INLINE 131 | int json_array_append(json_t *array, json_t *value) 132 | { 133 | return json_array_append_new(array, json_incref(value)); 134 | } 135 | 136 | static JSON_INLINE 137 | int json_array_insert(json_t *array, unsigned int index, json_t *value) 138 | { 139 | return json_array_insert_new(array, index, json_incref(value)); 140 | } 141 | 142 | const char *json_string_value(const json_t *string); 143 | int json_integer_value(const json_t *integer); 144 | double json_real_value(const json_t *real); 145 | double json_number_value(const json_t *json); 146 | 147 | int json_string_set(json_t *string, const char *value); 148 | int json_string_set_nocheck(json_t *string, const char *value); 149 | int json_integer_set(json_t *integer, int value); 150 | int json_real_set(json_t *real, double value); 151 | 152 | 153 | /* equality */ 154 | 155 | int json_equal(json_t *value1, json_t *value2); 156 | 157 | 158 | /* copying */ 159 | 160 | json_t *json_copy(json_t *value); 161 | json_t *json_deep_copy(json_t *value); 162 | 163 | 164 | /* loading, printing */ 165 | 166 | #define JSON_ERROR_TEXT_LENGTH 160 167 | 168 | typedef struct { 169 | char text[JSON_ERROR_TEXT_LENGTH]; 170 | int line; 171 | } json_error_t; 172 | 173 | json_t *json_loads(const char *input, json_error_t *error); 174 | json_t *json_loadf(FILE *input, json_error_t *error); 175 | json_t *json_load_file(const char *path, json_error_t *error); 176 | 177 | #define JSON_INDENT(n) (n & 0xFF) 178 | #define JSON_COMPACT 0x100 179 | #define JSON_ENSURE_ASCII 0x200 180 | #define JSON_SORT_KEYS 0x400 181 | #define JSON_PRESERVE_ORDER 0x800 182 | 183 | char *json_dumps(const json_t *json, unsigned long flags); 184 | int json_dumpf(const json_t *json, FILE *output, unsigned long flags); 185 | int json_dump_file(const json_t *json, const char *path, unsigned long flags); 186 | 187 | #ifdef __cplusplus 188 | } 189 | #endif 190 | 191 | #endif 192 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/scryptjane/scrypt-jane-hash_keccak.h: -------------------------------------------------------------------------------- 1 | #if defined(SCRYPT_KECCAK256) 2 | #define SCRYPT_HASH "Keccak-256" 3 | #define SCRYPT_HASH_DIGEST_SIZE 32 4 | #else 5 | #define SCRYPT_HASH "Keccak-512" 6 | #define SCRYPT_HASH_DIGEST_SIZE 64 7 | #endif 8 | #define SCRYPT_KECCAK_F 1600 9 | #define SCRYPT_KECCAK_C (SCRYPT_HASH_DIGEST_SIZE * 8 * 2) /* 256=512, 512=1024 */ 10 | #define SCRYPT_KECCAK_R (SCRYPT_KECCAK_F - SCRYPT_KECCAK_C) /* 256=1088, 512=576 */ 11 | #define SCRYPT_HASH_BLOCK_SIZE (SCRYPT_KECCAK_R / 8) 12 | 13 | typedef uint8_t scrypt_hash_digest[SCRYPT_HASH_DIGEST_SIZE]; 14 | 15 | typedef struct scrypt_hash_state_t { 16 | uint64_t state[SCRYPT_KECCAK_F / 64]; 17 | uint32_t leftover; 18 | uint8_t buffer[SCRYPT_HASH_BLOCK_SIZE]; 19 | } scrypt_hash_state; 20 | 21 | static const uint64_t keccak_round_constants[24] = { 22 | 0x0000000000000001ull, 0x0000000000008082ull, 23 | 0x800000000000808aull, 0x8000000080008000ull, 24 | 0x000000000000808bull, 0x0000000080000001ull, 25 | 0x8000000080008081ull, 0x8000000000008009ull, 26 | 0x000000000000008aull, 0x0000000000000088ull, 27 | 0x0000000080008009ull, 0x000000008000000aull, 28 | 0x000000008000808bull, 0x800000000000008bull, 29 | 0x8000000000008089ull, 0x8000000000008003ull, 30 | 0x8000000000008002ull, 0x8000000000000080ull, 31 | 0x000000000000800aull, 0x800000008000000aull, 32 | 0x8000000080008081ull, 0x8000000000008080ull, 33 | 0x0000000080000001ull, 0x8000000080008008ull 34 | }; 35 | 36 | static void 37 | keccak_block(scrypt_hash_state *S, const uint8_t *in) { 38 | size_t i; 39 | uint64_t *s = S->state, t[5], u[5], v, w; 40 | 41 | /* absorb input */ 42 | for (i = 0; i < SCRYPT_HASH_BLOCK_SIZE / 8; i++, in += 8) 43 | s[i] ^= U8TO64_LE(in); 44 | 45 | for (i = 0; i < 24; i++) { 46 | /* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */ 47 | t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20]; 48 | t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21]; 49 | t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22]; 50 | t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23]; 51 | t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24]; 52 | 53 | /* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */ 54 | u[0] = t[4] ^ ROTL64(t[1], 1); 55 | u[1] = t[0] ^ ROTL64(t[2], 1); 56 | u[2] = t[1] ^ ROTL64(t[3], 1); 57 | u[3] = t[2] ^ ROTL64(t[4], 1); 58 | u[4] = t[3] ^ ROTL64(t[0], 1); 59 | 60 | /* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */ 61 | s[0] ^= u[0]; s[5] ^= u[0]; s[10] ^= u[0]; s[15] ^= u[0]; s[20] ^= u[0]; 62 | s[1] ^= u[1]; s[6] ^= u[1]; s[11] ^= u[1]; s[16] ^= u[1]; s[21] ^= u[1]; 63 | s[2] ^= u[2]; s[7] ^= u[2]; s[12] ^= u[2]; s[17] ^= u[2]; s[22] ^= u[2]; 64 | s[3] ^= u[3]; s[8] ^= u[3]; s[13] ^= u[3]; s[18] ^= u[3]; s[23] ^= u[3]; 65 | s[4] ^= u[4]; s[9] ^= u[4]; s[14] ^= u[4]; s[19] ^= u[4]; s[24] ^= u[4]; 66 | 67 | /* rho pi: b[..] = rotl(a[..], ..) */ 68 | v = s[ 1]; 69 | s[ 1] = ROTL64(s[ 6], 44); 70 | s[ 6] = ROTL64(s[ 9], 20); 71 | s[ 9] = ROTL64(s[22], 61); 72 | s[22] = ROTL64(s[14], 39); 73 | s[14] = ROTL64(s[20], 18); 74 | s[20] = ROTL64(s[ 2], 62); 75 | s[ 2] = ROTL64(s[12], 43); 76 | s[12] = ROTL64(s[13], 25); 77 | s[13] = ROTL64(s[19], 8); 78 | s[19] = ROTL64(s[23], 56); 79 | s[23] = ROTL64(s[15], 41); 80 | s[15] = ROTL64(s[ 4], 27); 81 | s[ 4] = ROTL64(s[24], 14); 82 | s[24] = ROTL64(s[21], 2); 83 | s[21] = ROTL64(s[ 8], 55); 84 | s[ 8] = ROTL64(s[16], 45); 85 | s[16] = ROTL64(s[ 5], 36); 86 | s[ 5] = ROTL64(s[ 3], 28); 87 | s[ 3] = ROTL64(s[18], 21); 88 | s[18] = ROTL64(s[17], 15); 89 | s[17] = ROTL64(s[11], 10); 90 | s[11] = ROTL64(s[ 7], 6); 91 | s[ 7] = ROTL64(s[10], 3); 92 | s[10] = ROTL64( v, 1); 93 | 94 | /* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */ 95 | v = s[ 0]; w = s[ 1]; s[ 0] ^= (~w) & s[ 2]; s[ 1] ^= (~s[ 2]) & s[ 3]; s[ 2] ^= (~s[ 3]) & s[ 4]; s[ 3] ^= (~s[ 4]) & v; s[ 4] ^= (~v) & w; 96 | v = s[ 5]; w = s[ 6]; s[ 5] ^= (~w) & s[ 7]; s[ 6] ^= (~s[ 7]) & s[ 8]; s[ 7] ^= (~s[ 8]) & s[ 9]; s[ 8] ^= (~s[ 9]) & v; s[ 9] ^= (~v) & w; 97 | v = s[10]; w = s[11]; s[10] ^= (~w) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & v; s[14] ^= (~v) & w; 98 | v = s[15]; w = s[16]; s[15] ^= (~w) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & v; s[19] ^= (~v) & w; 99 | v = s[20]; w = s[21]; s[20] ^= (~w) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & v; s[24] ^= (~v) & w; 100 | 101 | /* iota: a[0,0] ^= round constant */ 102 | s[0] ^= keccak_round_constants[i]; 103 | } 104 | } 105 | 106 | static void 107 | scrypt_hash_init(scrypt_hash_state *S) { 108 | memset(S, 0, sizeof(*S)); 109 | } 110 | 111 | static void 112 | scrypt_hash_update(scrypt_hash_state *S, const uint8_t *in, size_t inlen) { 113 | size_t want; 114 | 115 | /* handle the previous data */ 116 | if (S->leftover) { 117 | want = (SCRYPT_HASH_BLOCK_SIZE - S->leftover); 118 | want = (want < inlen) ? want : inlen; 119 | memcpy(S->buffer + S->leftover, in, want); 120 | S->leftover += (uint32_t)want; 121 | if (S->leftover < SCRYPT_HASH_BLOCK_SIZE) 122 | return; 123 | in += want; 124 | inlen -= want; 125 | keccak_block(S, S->buffer); 126 | } 127 | 128 | /* handle the current data */ 129 | while (inlen >= SCRYPT_HASH_BLOCK_SIZE) { 130 | keccak_block(S, in); 131 | in += SCRYPT_HASH_BLOCK_SIZE; 132 | inlen -= SCRYPT_HASH_BLOCK_SIZE; 133 | } 134 | 135 | /* handle leftover data */ 136 | S->leftover = (uint32_t)inlen; 137 | if (S->leftover) 138 | memcpy(S->buffer, in, S->leftover); 139 | } 140 | 141 | static void 142 | scrypt_hash_finish(scrypt_hash_state *S, uint8_t *hash) { 143 | size_t i; 144 | 145 | S->buffer[S->leftover] = 0x01; 146 | memset(S->buffer + (S->leftover + 1), 0, SCRYPT_HASH_BLOCK_SIZE - (S->leftover + 1)); 147 | S->buffer[SCRYPT_HASH_BLOCK_SIZE - 1] |= 0x80; 148 | keccak_block(S, S->buffer); 149 | 150 | for (i = 0; i < SCRYPT_HASH_DIGEST_SIZE; i += 8) { 151 | U64TO8_LE(&hash[i], S->state[i / 8]); 152 | } 153 | } 154 | 155 | #if defined(SCRYPT_KECCAK256) 156 | static const uint8_t scrypt_test_hash_expected[SCRYPT_HASH_DIGEST_SIZE] = { 157 | 0x26,0xb7,0x10,0xb3,0x66,0xb1,0xd1,0xb1,0x25,0xfc,0x3e,0xe3,0x1e,0x33,0x1d,0x19, 158 | 0x94,0xaa,0x63,0x7a,0xd5,0x77,0x29,0xb4,0x27,0xe9,0xe0,0xf4,0x19,0xba,0x68,0xea, 159 | }; 160 | #else 161 | static const uint8_t scrypt_test_hash_expected[SCRYPT_HASH_DIGEST_SIZE] = { 162 | 0x17,0xc7,0x8c,0xa0,0xd9,0x08,0x1d,0xba,0x8a,0xc8,0x3e,0x07,0x90,0xda,0x91,0x88, 163 | 0x25,0xbd,0xd3,0xf8,0x78,0x4a,0x8d,0x5e,0xe4,0x96,0x9c,0x01,0xf3,0xeb,0xdc,0x12, 164 | 0xea,0x35,0x57,0xba,0x94,0xb8,0xe9,0xb9,0x27,0x45,0x0a,0x48,0x5c,0x3d,0x69,0xf0, 165 | 0xdb,0x22,0x38,0xb5,0x52,0x22,0x29,0xea,0x7a,0xb2,0xe6,0x07,0xaa,0x37,0x4d,0xe6, 166 | }; 167 | #endif 168 | 169 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/x11.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_blake.h" 9 | #include "sha3/sph_bmw.h" 10 | #include "sha3/sph_groestl.h" 11 | #include "sha3/sph_jh.h" 12 | #include "sha3/sph_keccak.h" 13 | #include "sha3/sph_skein.h" 14 | #include "sha3/sph_luffa.h" 15 | #include "sha3/sph_cubehash.h" 16 | #include "sha3/sph_shavite.h" 17 | #include "sha3/sph_simd.h" 18 | #include "sha3/sph_echo.h" 19 | 20 | 21 | void x11_hash(char* output, const char* input) 22 | { 23 | sph_blake512_context ctx_blake; 24 | sph_bmw512_context ctx_bmw; 25 | sph_groestl512_context ctx_groestl; 26 | sph_skein512_context ctx_skein; 27 | sph_jh512_context ctx_jh; 28 | sph_keccak512_context ctx_keccak; 29 | 30 | sph_luffa512_context ctx_luffa1; 31 | sph_cubehash512_context ctx_cubehash1; 32 | sph_shavite512_context ctx_shavite1; 33 | sph_simd512_context ctx_simd1; 34 | sph_echo512_context ctx_echo1; 35 | 36 | //these uint512 in the c++ source of the client are backed by an array of uint32 37 | uint32_t hashA[16], hashB[16]; 38 | 39 | sph_blake512_init(&ctx_blake); 40 | sph_blake512 (&ctx_blake, input, 80); 41 | sph_blake512_close (&ctx_blake, hashA); 42 | 43 | sph_bmw512_init(&ctx_bmw); 44 | sph_bmw512 (&ctx_bmw, hashA, 64); 45 | sph_bmw512_close(&ctx_bmw, hashB); 46 | 47 | sph_groestl512_init(&ctx_groestl); 48 | sph_groestl512 (&ctx_groestl, hashB, 64); 49 | sph_groestl512_close(&ctx_groestl, hashA); 50 | 51 | sph_skein512_init(&ctx_skein); 52 | sph_skein512 (&ctx_skein, hashA, 64); 53 | sph_skein512_close (&ctx_skein, hashB); 54 | 55 | sph_jh512_init(&ctx_jh); 56 | sph_jh512 (&ctx_jh, hashB, 64); 57 | sph_jh512_close(&ctx_jh, hashA); 58 | 59 | sph_keccak512_init(&ctx_keccak); 60 | sph_keccak512 (&ctx_keccak, hashA, 64); 61 | sph_keccak512_close(&ctx_keccak, hashB); 62 | 63 | sph_luffa512_init (&ctx_luffa1); 64 | sph_luffa512 (&ctx_luffa1, hashB, 64); 65 | sph_luffa512_close (&ctx_luffa1, hashA); 66 | 67 | sph_cubehash512_init (&ctx_cubehash1); 68 | sph_cubehash512 (&ctx_cubehash1, hashA, 64); 69 | sph_cubehash512_close(&ctx_cubehash1, hashB); 70 | 71 | sph_shavite512_init (&ctx_shavite1); 72 | sph_shavite512 (&ctx_shavite1, hashB, 64); 73 | sph_shavite512_close(&ctx_shavite1, hashA); 74 | 75 | sph_simd512_init (&ctx_simd1); 76 | sph_simd512 (&ctx_simd1, hashA, 64); 77 | sph_simd512_close(&ctx_simd1, hashB); 78 | 79 | sph_echo512_init (&ctx_echo1); 80 | sph_echo512 (&ctx_echo1, hashB, 64); 81 | sph_echo512_close(&ctx_echo1, hashA); 82 | 83 | memcpy(output, hashA, 32); 84 | } 85 | 86 | int scanhash_x11(int thr_id, uint32_t *pdata, const uint32_t *ptarget, 87 | uint32_t max_nonce, uint64_t *hashes_done) 88 | { 89 | uint32_t n = pdata[19] - 1; 90 | const uint32_t first_nonce = pdata[19]; 91 | const uint32_t Htarg = ptarget[7]; 92 | 93 | uint32_t hash64[8] __attribute__((aligned(32))); 94 | uint32_t endiandata[32]; 95 | 96 | //char testdata[] = {"\x70\x00\x00\x00\x5d\x38\x5b\xa1\x14\xd0\x79\x97\x0b\x29\xa9\x41\x8f\xd0\x54\x9e\x7d\x68\xa9\x5c\x7f\x16\x86\x21\xa3\x14\x20\x10\x00\x00\x00\x00\x57\x85\x86\xd1\x49\xfd\x07\xb2\x2f\x3a\x8a\x34\x7c\x51\x6d\xe7\x05\x2f\x03\x4d\x2b\x76\xff\x68\xe0\xd6\xec\xff\x9b\x77\xa4\x54\x89\xe3\xfd\x51\x17\x32\x01\x1d\xf0\x73\x10\x00"}; 97 | 98 | //we need bigendian data... 99 | //lessons learned: do NOT endianchange directly in pdata, this will all proof-of-works be considered as stale from minerd.... 100 | int kk=0; 101 | for (; kk < 32; kk++) 102 | { 103 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 104 | }; 105 | 106 | // if (opt_debug) 107 | // { 108 | // applog(LOG_DEBUG, "Thr: %02d, firstN: %08x, maxN: %08x, ToDo: %d", thr_id, first_nonce, max_nonce, max_nonce-first_nonce); 109 | // } 110 | 111 | /* I'm to lazy to put the loop in an inline function... so dirty copy'n'paste.... */ 112 | /* i know that i could set a variable, but i don't know how the compiler will optimize it, not that then the cpu needs to load the value *everytime* in a register */ 113 | if (ptarget[7]==0) { 114 | do { 115 | pdata[19] = ++n; 116 | be32enc(&endiandata[19], n); 117 | x11_hash((char*) hash64, (const char*) endiandata); 118 | if (((hash64[7]&0xFFFFFFFF)==0) && 119 | fulltest(hash64, ptarget)) { 120 | *hashes_done = n - first_nonce + 1; 121 | return true; 122 | } 123 | } while (n < max_nonce && !work_restart[thr_id].restart); 124 | } 125 | else if (ptarget[7]<=0xF) 126 | { 127 | do { 128 | pdata[19] = ++n; 129 | be32enc(&endiandata[19], n); 130 | x11_hash((char*) hash64, (const char*) endiandata); 131 | if (((hash64[7]&0xFFFFFFF0)==0) && 132 | fulltest(hash64, ptarget)) { 133 | *hashes_done = n - first_nonce + 1; 134 | return true; 135 | } 136 | } while (n < max_nonce && !work_restart[thr_id].restart); 137 | } 138 | else if (ptarget[7]<=0xFF) 139 | { 140 | do { 141 | pdata[19] = ++n; 142 | be32enc(&endiandata[19], n); 143 | x11_hash((char*) hash64, (const char*) endiandata); 144 | if (((hash64[7]&0xFFFFFF00)==0) && 145 | fulltest(hash64, ptarget)) { 146 | *hashes_done = n - first_nonce + 1; 147 | return true; 148 | } 149 | } while (n < max_nonce && !work_restart[thr_id].restart); 150 | } 151 | else if (ptarget[7]<=0xFFF) 152 | { 153 | do { 154 | pdata[19] = ++n; 155 | be32enc(&endiandata[19], n); 156 | x11_hash((char*) hash64, (const char*) endiandata); 157 | if (((hash64[7]&0xFFFFF000)==0) && 158 | fulltest(hash64, ptarget)) { 159 | *hashes_done = n - first_nonce + 1; 160 | return true; 161 | } 162 | } while (n < max_nonce && !work_restart[thr_id].restart); 163 | 164 | } 165 | else if (ptarget[7]<=0xFFFF) 166 | { 167 | do { 168 | pdata[19] = ++n; 169 | be32enc(&endiandata[19], n); 170 | x11_hash((char*) hash64, (const char*) endiandata); 171 | if (((hash64[7]&0xFFFF0000)==0) && 172 | fulltest(hash64, ptarget)) { 173 | *hashes_done = n - first_nonce + 1; 174 | return true; 175 | } 176 | } while (n < max_nonce && !work_restart[thr_id].restart); 177 | 178 | } 179 | else 180 | { 181 | do { 182 | pdata[19] = ++n; 183 | be32enc(&endiandata[19], n); 184 | x11_hash((char*) hash64, (const char*) endiandata); 185 | if (fulltest(hash64, ptarget)) { 186 | *hashes_done = n - first_nonce + 1; 187 | return true; 188 | } 189 | } while (n < max_nonce && !work_restart[thr_id].restart); 190 | } 191 | 192 | 193 | *hashes_done = n - first_nonce + 1; 194 | pdata[19] = n; 195 | return 0; 196 | } 197 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/oaes_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_LIB_H 32 | #define _OAES_LIB_H 33 | 34 | #include 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #ifdef _WIN32 41 | # ifdef OAES_SHARED 42 | # ifdef oaes_lib_EXPORTS 43 | # define OAES_API __declspec(dllexport) 44 | # else 45 | # define OAES_API __declspec(dllimport) 46 | # endif 47 | # else 48 | # define OAES_API 49 | # endif 50 | #else 51 | # define OAES_API 52 | #endif // WIN32 53 | 54 | #define OAES_VERSION "0.8.1" 55 | #define OAES_BLOCK_SIZE 16 56 | 57 | typedef void OAES_CTX; 58 | 59 | typedef enum 60 | { 61 | OAES_RET_FIRST = 0, 62 | OAES_RET_SUCCESS = 0, 63 | OAES_RET_UNKNOWN, 64 | OAES_RET_ARG1, 65 | OAES_RET_ARG2, 66 | OAES_RET_ARG3, 67 | OAES_RET_ARG4, 68 | OAES_RET_ARG5, 69 | OAES_RET_NOKEY, 70 | OAES_RET_MEM, 71 | OAES_RET_BUF, 72 | OAES_RET_HEADER, 73 | OAES_RET_COUNT 74 | } OAES_RET; 75 | 76 | /* 77 | * oaes_set_option() takes one of these values for its [option] parameter 78 | * some options accept either an optional or a required [value] parameter 79 | */ 80 | // no option 81 | #define OAES_OPTION_NONE 0 82 | // enable ECB mode, disable CBC mode 83 | #define OAES_OPTION_ECB 1 84 | // enable CBC mode, disable ECB mode 85 | // value is optional, may pass uint8_t iv[OAES_BLOCK_SIZE] to specify 86 | // the value of the initialization vector, iv 87 | #define OAES_OPTION_CBC 2 88 | 89 | #ifdef OAES_DEBUG 90 | typedef int ( * oaes_step_cb ) ( 91 | const uint8_t state[OAES_BLOCK_SIZE], 92 | const char * step_name, 93 | int step_count, 94 | void * user_data ); 95 | // enable state stepping mode 96 | // value is required, must pass oaes_step_cb to receive the state at each step 97 | #define OAES_OPTION_STEP_ON 4 98 | // disable state stepping mode 99 | #define OAES_OPTION_STEP_OFF 8 100 | #endif // OAES_DEBUG 101 | 102 | typedef uint16_t OAES_OPTION; 103 | 104 | typedef struct _oaes_key 105 | { 106 | size_t data_len; 107 | uint8_t *data; 108 | size_t exp_data_len; 109 | uint8_t *exp_data; 110 | size_t num_keys; 111 | size_t key_base; 112 | } oaes_key; 113 | 114 | typedef struct _oaes_ctx 115 | { 116 | #ifdef OAES_HAVE_ISAAC 117 | randctx * rctx; 118 | #endif // OAES_HAVE_ISAAC 119 | 120 | #ifdef OAES_DEBUG 121 | oaes_step_cb step_cb; 122 | #endif // OAES_DEBUG 123 | 124 | oaes_key * key; 125 | OAES_OPTION options; 126 | uint8_t iv[OAES_BLOCK_SIZE]; 127 | } oaes_ctx; 128 | /* 129 | * // usage: 130 | * 131 | * OAES_CTX * ctx = oaes_alloc(); 132 | * . 133 | * . 134 | * . 135 | * { 136 | * oaes_gen_key_xxx( ctx ); 137 | * { 138 | * oaes_key_export( ctx, _buf, &_buf_len ); 139 | * // or 140 | * oaes_key_export_data( ctx, _buf, &_buf_len );\ 141 | * } 142 | * } 143 | * // or 144 | * { 145 | * oaes_key_import( ctx, _buf, _buf_len ); 146 | * // or 147 | * oaes_key_import_data( ctx, _buf, _buf_len ); 148 | * } 149 | * . 150 | * . 151 | * . 152 | * oaes_encrypt( ctx, m, m_len, c, &c_len ); 153 | * . 154 | * . 155 | * . 156 | * oaes_decrypt( ctx, c, c_len, m, &m_len ); 157 | * . 158 | * . 159 | * . 160 | * oaes_free( &ctx ); 161 | */ 162 | 163 | OAES_API OAES_CTX * oaes_alloc(void); 164 | 165 | OAES_API OAES_RET oaes_free( OAES_CTX ** ctx ); 166 | 167 | OAES_API OAES_RET oaes_set_option( OAES_CTX * ctx, 168 | OAES_OPTION option, const void * value ); 169 | 170 | OAES_API OAES_RET oaes_key_gen_128( OAES_CTX * ctx ); 171 | 172 | OAES_API OAES_RET oaes_key_gen_192( OAES_CTX * ctx ); 173 | 174 | OAES_API OAES_RET oaes_key_gen_256( OAES_CTX * ctx ); 175 | 176 | // export key with header information 177 | // set data == NULL to get the required data_len 178 | OAES_API OAES_RET oaes_key_export( OAES_CTX * ctx, 179 | uint8_t * data, size_t * data_len ); 180 | 181 | // directly export the data from key 182 | // set data == NULL to get the required data_len 183 | OAES_API OAES_RET oaes_key_export_data( OAES_CTX * ctx, 184 | uint8_t * data, size_t * data_len ); 185 | 186 | // import key with header information 187 | OAES_API OAES_RET oaes_key_import( OAES_CTX * ctx, 188 | const uint8_t * data, size_t data_len ); 189 | 190 | // directly import data into key 191 | OAES_API OAES_RET oaes_key_import_data( OAES_CTX * ctx, 192 | const uint8_t * data, size_t data_len ); 193 | 194 | // set c == NULL to get the required c_len 195 | OAES_API OAES_RET oaes_encrypt( OAES_CTX * ctx, 196 | const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len ); 197 | 198 | // set m == NULL to get the required m_len 199 | OAES_API OAES_RET oaes_decrypt( OAES_CTX * ctx, 200 | const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len ); 201 | 202 | // set buf == NULL to get the required buf_len 203 | OAES_API OAES_RET oaes_sprintf( 204 | char * buf, size_t * buf_len, const uint8_t * data, size_t data_len ); 205 | 206 | OAES_API OAES_RET oaes_encryption_round( const uint8_t * key, uint8_t * c ); 207 | 208 | OAES_API OAES_RET oaes_pseudo_encrypt_ecb( OAES_CTX * ctx, uint8_t * c ); 209 | 210 | #ifdef __cplusplus 211 | } 212 | #endif 213 | 214 | #endif // _OAES_LIB_H 215 | -------------------------------------------------------------------------------- /cpuminer-source/compat/jansson/hashtable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * This library is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef HASHTABLE_H 9 | #define HASHTABLE_H 10 | 11 | typedef unsigned int (*key_hash_fn)(const void *key); 12 | typedef int (*key_cmp_fn)(const void *key1, const void *key2); 13 | typedef void (*free_fn)(void *key); 14 | 15 | struct hashtable_list { 16 | struct hashtable_list *prev; 17 | struct hashtable_list *next; 18 | }; 19 | 20 | struct hashtable_pair { 21 | void *key; 22 | void *value; 23 | unsigned int hash; 24 | struct hashtable_list list; 25 | }; 26 | 27 | struct hashtable_bucket { 28 | struct hashtable_list *first; 29 | struct hashtable_list *last; 30 | }; 31 | 32 | typedef struct hashtable { 33 | unsigned int size; 34 | struct hashtable_bucket *buckets; 35 | unsigned int num_buckets; /* index to primes[] */ 36 | struct hashtable_list list; 37 | 38 | key_hash_fn hash_key; 39 | key_cmp_fn cmp_keys; /* returns non-zero for equal keys */ 40 | free_fn free_key; 41 | free_fn free_value; 42 | } hashtable_t; 43 | 44 | /** 45 | * hashtable_create - Create a hashtable object 46 | * 47 | * @hash_key: The key hashing function 48 | * @cmp_keys: The key compare function. Returns non-zero for equal and 49 | * zero for unequal unequal keys 50 | * @free_key: If non-NULL, called for a key that is no longer referenced. 51 | * @free_value: If non-NULL, called for a value that is no longer referenced. 52 | * 53 | * Returns a new hashtable object that should be freed with 54 | * hashtable_destroy when it's no longer used, or NULL on failure (out 55 | * of memory). 56 | */ 57 | hashtable_t *hashtable_create(key_hash_fn hash_key, key_cmp_fn cmp_keys, 58 | free_fn free_key, free_fn free_value); 59 | 60 | /** 61 | * hashtable_destroy - Destroy a hashtable object 62 | * 63 | * @hashtable: The hashtable 64 | * 65 | * Destroys a hashtable created with hashtable_create(). 66 | */ 67 | void hashtable_destroy(hashtable_t *hashtable); 68 | 69 | /** 70 | * hashtable_init - Initialize a hashtable object 71 | * 72 | * @hashtable: The (statically allocated) hashtable object 73 | * @hash_key: The key hashing function 74 | * @cmp_keys: The key compare function. Returns non-zero for equal and 75 | * zero for unequal unequal keys 76 | * @free_key: If non-NULL, called for a key that is no longer referenced. 77 | * @free_value: If non-NULL, called for a value that is no longer referenced. 78 | * 79 | * Initializes a statically allocated hashtable object. The object 80 | * should be cleared with hashtable_close when it's no longer used. 81 | * 82 | * Returns 0 on success, -1 on error (out of memory). 83 | */ 84 | int hashtable_init(hashtable_t *hashtable, 85 | key_hash_fn hash_key, key_cmp_fn cmp_keys, 86 | free_fn free_key, free_fn free_value); 87 | 88 | /** 89 | * hashtable_close - Release all resources used by a hashtable object 90 | * 91 | * @hashtable: The hashtable 92 | * 93 | * Destroys a statically allocated hashtable object. 94 | */ 95 | void hashtable_close(hashtable_t *hashtable); 96 | 97 | /** 98 | * hashtable_set - Add/modify value in hashtable 99 | * 100 | * @hashtable: The hashtable object 101 | * @key: The key 102 | * @value: The value 103 | * 104 | * If a value with the given key already exists, its value is replaced 105 | * with the new value. 106 | * 107 | * Key and value are "stealed" in the sense that hashtable frees them 108 | * automatically when they are no longer used. The freeing is 109 | * accomplished by calling free_key and free_value functions that were 110 | * supplied to hashtable_new. In case one or both of the free 111 | * functions is NULL, the corresponding item is not "stealed". 112 | * 113 | * Returns 0 on success, -1 on failure (out of memory). 114 | */ 115 | int hashtable_set(hashtable_t *hashtable, void *key, void *value); 116 | 117 | /** 118 | * hashtable_get - Get a value associated with a key 119 | * 120 | * @hashtable: The hashtable object 121 | * @key: The key 122 | * 123 | * Returns value if it is found, or NULL otherwise. 124 | */ 125 | void *hashtable_get(hashtable_t *hashtable, const void *key); 126 | 127 | /** 128 | * hashtable_del - Remove a value from the hashtable 129 | * 130 | * @hashtable: The hashtable object 131 | * @key: The key 132 | * 133 | * Returns 0 on success, or -1 if the key was not found. 134 | */ 135 | int hashtable_del(hashtable_t *hashtable, const void *key); 136 | 137 | /** 138 | * hashtable_clear - Clear hashtable 139 | * 140 | * @hashtable: The hashtable object 141 | * 142 | * Removes all items from the hashtable. 143 | */ 144 | void hashtable_clear(hashtable_t *hashtable); 145 | 146 | /** 147 | * hashtable_iter - Iterate over hashtable 148 | * 149 | * @hashtable: The hashtable object 150 | * 151 | * Returns an opaque iterator to the first element in the hashtable. 152 | * The iterator should be passed to hashtable_iter_* functions. 153 | * The hashtable items are not iterated over in any particular order. 154 | * 155 | * There's no need to free the iterator in any way. The iterator is 156 | * valid as long as the item that is referenced by the iterator is not 157 | * deleted. Other values may be added or deleted. In particular, 158 | * hashtable_iter_next() may be called on an iterator, and after that 159 | * the key/value pair pointed by the old iterator may be deleted. 160 | */ 161 | void *hashtable_iter(hashtable_t *hashtable); 162 | 163 | /** 164 | * hashtable_iter_at - Return an iterator at a specific key 165 | * 166 | * @hashtable: The hashtable object 167 | * @key: The key that the iterator should point to 168 | * 169 | * Like hashtable_iter() but returns an iterator pointing to a 170 | * specific key. 171 | */ 172 | void *hashtable_iter_at(hashtable_t *hashtable, const void *key); 173 | 174 | /** 175 | * hashtable_iter_next - Advance an iterator 176 | * 177 | * @hashtable: The hashtable object 178 | * @iter: The iterator 179 | * 180 | * Returns a new iterator pointing to the next element in the 181 | * hashtable or NULL if the whole hastable has been iterated over. 182 | */ 183 | void *hashtable_iter_next(hashtable_t *hashtable, void *iter); 184 | 185 | /** 186 | * hashtable_iter_key - Retrieve the key pointed by an iterator 187 | * 188 | * @iter: The iterator 189 | */ 190 | void *hashtable_iter_key(void *iter); 191 | 192 | /** 193 | * hashtable_iter_value - Retrieve the value pointed by an iterator 194 | * 195 | * @iter: The iterator 196 | */ 197 | void *hashtable_iter_value(void *iter); 198 | 199 | /** 200 | * hashtable_iter_set - Set the value pointed by an iterator 201 | * 202 | * @iter: The iterator 203 | * @value: The value to set 204 | */ 205 | void hashtable_iter_set(hashtable_t *hashtable, void *iter, void *value); 206 | 207 | #endif 208 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/compat/jansson/hashtable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * This library is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef HASHTABLE_H 9 | #define HASHTABLE_H 10 | 11 | typedef unsigned int (*key_hash_fn)(const void *key); 12 | typedef int (*key_cmp_fn)(const void *key1, const void *key2); 13 | typedef void (*free_fn)(void *key); 14 | 15 | struct hashtable_list { 16 | struct hashtable_list *prev; 17 | struct hashtable_list *next; 18 | }; 19 | 20 | struct hashtable_pair { 21 | void *key; 22 | void *value; 23 | unsigned int hash; 24 | struct hashtable_list list; 25 | }; 26 | 27 | struct hashtable_bucket { 28 | struct hashtable_list *first; 29 | struct hashtable_list *last; 30 | }; 31 | 32 | typedef struct hashtable { 33 | unsigned int size; 34 | struct hashtable_bucket *buckets; 35 | unsigned int num_buckets; /* index to primes[] */ 36 | struct hashtable_list list; 37 | 38 | key_hash_fn hash_key; 39 | key_cmp_fn cmp_keys; /* returns non-zero for equal keys */ 40 | free_fn free_key; 41 | free_fn free_value; 42 | } hashtable_t; 43 | 44 | /** 45 | * hashtable_create - Create a hashtable object 46 | * 47 | * @hash_key: The key hashing function 48 | * @cmp_keys: The key compare function. Returns non-zero for equal and 49 | * zero for unequal unequal keys 50 | * @free_key: If non-NULL, called for a key that is no longer referenced. 51 | * @free_value: If non-NULL, called for a value that is no longer referenced. 52 | * 53 | * Returns a new hashtable object that should be freed with 54 | * hashtable_destroy when it's no longer used, or NULL on failure (out 55 | * of memory). 56 | */ 57 | hashtable_t *hashtable_create(key_hash_fn hash_key, key_cmp_fn cmp_keys, 58 | free_fn free_key, free_fn free_value); 59 | 60 | /** 61 | * hashtable_destroy - Destroy a hashtable object 62 | * 63 | * @hashtable: The hashtable 64 | * 65 | * Destroys a hashtable created with hashtable_create(). 66 | */ 67 | void hashtable_destroy(hashtable_t *hashtable); 68 | 69 | /** 70 | * hashtable_init - Initialize a hashtable object 71 | * 72 | * @hashtable: The (statically allocated) hashtable object 73 | * @hash_key: The key hashing function 74 | * @cmp_keys: The key compare function. Returns non-zero for equal and 75 | * zero for unequal unequal keys 76 | * @free_key: If non-NULL, called for a key that is no longer referenced. 77 | * @free_value: If non-NULL, called for a value that is no longer referenced. 78 | * 79 | * Initializes a statically allocated hashtable object. The object 80 | * should be cleared with hashtable_close when it's no longer used. 81 | * 82 | * Returns 0 on success, -1 on error (out of memory). 83 | */ 84 | int hashtable_init(hashtable_t *hashtable, 85 | key_hash_fn hash_key, key_cmp_fn cmp_keys, 86 | free_fn free_key, free_fn free_value); 87 | 88 | /** 89 | * hashtable_close - Release all resources used by a hashtable object 90 | * 91 | * @hashtable: The hashtable 92 | * 93 | * Destroys a statically allocated hashtable object. 94 | */ 95 | void hashtable_close(hashtable_t *hashtable); 96 | 97 | /** 98 | * hashtable_set - Add/modify value in hashtable 99 | * 100 | * @hashtable: The hashtable object 101 | * @key: The key 102 | * @value: The value 103 | * 104 | * If a value with the given key already exists, its value is replaced 105 | * with the new value. 106 | * 107 | * Key and value are "stealed" in the sense that hashtable frees them 108 | * automatically when they are no longer used. The freeing is 109 | * accomplished by calling free_key and free_value functions that were 110 | * supplied to hashtable_new. In case one or both of the free 111 | * functions is NULL, the corresponding item is not "stealed". 112 | * 113 | * Returns 0 on success, -1 on failure (out of memory). 114 | */ 115 | int hashtable_set(hashtable_t *hashtable, void *key, void *value); 116 | 117 | /** 118 | * hashtable_get - Get a value associated with a key 119 | * 120 | * @hashtable: The hashtable object 121 | * @key: The key 122 | * 123 | * Returns value if it is found, or NULL otherwise. 124 | */ 125 | void *hashtable_get(hashtable_t *hashtable, const void *key); 126 | 127 | /** 128 | * hashtable_del - Remove a value from the hashtable 129 | * 130 | * @hashtable: The hashtable object 131 | * @key: The key 132 | * 133 | * Returns 0 on success, or -1 if the key was not found. 134 | */ 135 | int hashtable_del(hashtable_t *hashtable, const void *key); 136 | 137 | /** 138 | * hashtable_clear - Clear hashtable 139 | * 140 | * @hashtable: The hashtable object 141 | * 142 | * Removes all items from the hashtable. 143 | */ 144 | void hashtable_clear(hashtable_t *hashtable); 145 | 146 | /** 147 | * hashtable_iter - Iterate over hashtable 148 | * 149 | * @hashtable: The hashtable object 150 | * 151 | * Returns an opaque iterator to the first element in the hashtable. 152 | * The iterator should be passed to hashtable_iter_* functions. 153 | * The hashtable items are not iterated over in any particular order. 154 | * 155 | * There's no need to free the iterator in any way. The iterator is 156 | * valid as long as the item that is referenced by the iterator is not 157 | * deleted. Other values may be added or deleted. In particular, 158 | * hashtable_iter_next() may be called on an iterator, and after that 159 | * the key/value pair pointed by the old iterator may be deleted. 160 | */ 161 | void *hashtable_iter(hashtable_t *hashtable); 162 | 163 | /** 164 | * hashtable_iter_at - Return an iterator at a specific key 165 | * 166 | * @hashtable: The hashtable object 167 | * @key: The key that the iterator should point to 168 | * 169 | * Like hashtable_iter() but returns an iterator pointing to a 170 | * specific key. 171 | */ 172 | void *hashtable_iter_at(hashtable_t *hashtable, const void *key); 173 | 174 | /** 175 | * hashtable_iter_next - Advance an iterator 176 | * 177 | * @hashtable: The hashtable object 178 | * @iter: The iterator 179 | * 180 | * Returns a new iterator pointing to the next element in the 181 | * hashtable or NULL if the whole hastable has been iterated over. 182 | */ 183 | void *hashtable_iter_next(hashtable_t *hashtable, void *iter); 184 | 185 | /** 186 | * hashtable_iter_key - Retrieve the key pointed by an iterator 187 | * 188 | * @iter: The iterator 189 | */ 190 | void *hashtable_iter_key(void *iter); 191 | 192 | /** 193 | * hashtable_iter_value - Retrieve the value pointed by an iterator 194 | * 195 | * @iter: The iterator 196 | */ 197 | void *hashtable_iter_value(void *iter); 198 | 199 | /** 200 | * hashtable_iter_set - Set the value pointed by an iterator 201 | * 202 | * @iter: The iterator 203 | * @value: The value to set 204 | */ 205 | void hashtable_iter_set(hashtable_t *hashtable, void *iter, void *value); 206 | 207 | #endif 208 | -------------------------------------------------------------------------------- /cpuminer-newalgorithms/sha3/sph_whirlpool.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_whirlpool.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * WHIRLPOOL interface. 4 | * 5 | * WHIRLPOOL knows three variants, dubbed "WHIRLPOOL-0" (original 6 | * version, published in 2000, studied by NESSIE), "WHIRLPOOL-1" 7 | * (first revision, 2001, with a new S-box) and "WHIRLPOOL" (current 8 | * version, 2003, with a new diffusion matrix, also described as "plain 9 | * WHIRLPOOL"). All three variants are implemented here. 10 | * 11 | * The original WHIRLPOOL (i.e. WHIRLPOOL-0) was published in: P. S. L. 12 | * M. Barreto, V. Rijmen, "The Whirlpool Hashing Function", First open 13 | * NESSIE Workshop, Leuven, Belgium, November 13--14, 2000. 14 | * 15 | * The current WHIRLPOOL specification and a reference implementation 16 | * can be found on the WHIRLPOOL web page: 17 | * http://paginas.terra.com.br/informatica/paulobarreto/WhirlpoolPage.html 18 | * 19 | * ==========================(LICENSE BEGIN)============================ 20 | * 21 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 22 | * 23 | * Permission is hereby granted, free of charge, to any person obtaining 24 | * a copy of this software and associated documentation files (the 25 | * "Software"), to deal in the Software without restriction, including 26 | * without limitation the rights to use, copy, modify, merge, publish, 27 | * distribute, sublicense, and/or sell copies of the Software, and to 28 | * permit persons to whom the Software is furnished to do so, subject to 29 | * the following conditions: 30 | * 31 | * The above copyright notice and this permission notice shall be 32 | * included in all copies or substantial portions of the Software. 33 | * 34 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 35 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 36 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 37 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 38 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 39 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 40 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 41 | * 42 | * ===========================(LICENSE END)============================= 43 | * 44 | * @file sph_whirlpool.h 45 | * @author Thomas Pornin 46 | */ 47 | 48 | #ifndef SPH_WHIRLPOOL_H__ 49 | #define SPH_WHIRLPOOL_H__ 50 | 51 | #include 52 | #include "sph_types.h" 53 | 54 | #if SPH_64 55 | 56 | /** 57 | * Output size (in bits) for WHIRLPOOL. 58 | */ 59 | #define SPH_SIZE_whirlpool 512 60 | 61 | /** 62 | * Output size (in bits) for WHIRLPOOL-0. 63 | */ 64 | #define SPH_SIZE_whirlpool0 512 65 | 66 | /** 67 | * Output size (in bits) for WHIRLPOOL-1. 68 | */ 69 | #define SPH_SIZE_whirlpool1 512 70 | 71 | /** 72 | * This structure is a context for WHIRLPOOL computations: it contains the 73 | * intermediate values and some data from the last entered block. Once 74 | * a WHIRLPOOL computation has been performed, the context can be reused for 75 | * another computation. 76 | * 77 | * The contents of this structure are private. A running WHIRLPOOL computation 78 | * can be cloned by copying the context (e.g. with a simple 79 | * memcpy()). 80 | */ 81 | typedef struct { 82 | #ifndef DOXYGEN_IGNORE 83 | unsigned char buf[64]; /* first field, for alignment */ 84 | sph_u64 state[8]; 85 | #if SPH_64 86 | sph_u64 count; 87 | #else 88 | sph_u32 count_high, count_low; 89 | #endif 90 | #endif 91 | } sph_whirlpool_context; 92 | 93 | /** 94 | * Initialize a WHIRLPOOL context. This process performs no memory allocation. 95 | * 96 | * @param cc the WHIRLPOOL context (pointer to a 97 | * sph_whirlpool_context) 98 | */ 99 | void sph_whirlpool_init(void *cc); 100 | 101 | /** 102 | * Process some data bytes. It is acceptable that len is zero 103 | * (in which case this function does nothing). This function applies the 104 | * plain WHIRLPOOL algorithm. 105 | * 106 | * @param cc the WHIRLPOOL context 107 | * @param data the input data 108 | * @param len the input data length (in bytes) 109 | */ 110 | void sph_whirlpool(void *cc, const void *data, size_t len); 111 | 112 | /** 113 | * Terminate the current WHIRLPOOL computation and output the result into the 114 | * provided buffer. The destination buffer must be wide enough to 115 | * accomodate the result (64 bytes). The context is automatically 116 | * reinitialized. 117 | * 118 | * @param cc the WHIRLPOOL context 119 | * @param dst the destination buffer 120 | */ 121 | void sph_whirlpool_close(void *cc, void *dst); 122 | 123 | /** 124 | * WHIRLPOOL-0 uses the same structure than plain WHIRLPOOL. 125 | */ 126 | typedef sph_whirlpool_context sph_whirlpool0_context; 127 | 128 | #ifdef DOXYGEN_IGNORE 129 | /** 130 | * Initialize a WHIRLPOOL-0 context. This function is identical to 131 | * sph_whirlpool_init(). 132 | * 133 | * @param cc the WHIRLPOOL context (pointer to a 134 | * sph_whirlpool0_context) 135 | */ 136 | void sph_whirlpool0_init(void *cc); 137 | #endif 138 | 139 | #ifndef DOXYGEN_IGNORE 140 | #define sph_whirlpool0_init sph_whirlpool_init 141 | #endif 142 | 143 | /** 144 | * Process some data bytes. It is acceptable that len is zero 145 | * (in which case this function does nothing). This function applies the 146 | * WHIRLPOOL-0 algorithm. 147 | * 148 | * @param cc the WHIRLPOOL context 149 | * @param data the input data 150 | * @param len the input data length (in bytes) 151 | */ 152 | void sph_whirlpool0(void *cc, const void *data, size_t len); 153 | 154 | /** 155 | * Terminate the current WHIRLPOOL-0 computation and output the result into the 156 | * provided buffer. The destination buffer must be wide enough to 157 | * accomodate the result (64 bytes). The context is automatically 158 | * reinitialized. 159 | * 160 | * @param cc the WHIRLPOOL-0 context 161 | * @param dst the destination buffer 162 | */ 163 | void sph_whirlpool0_close(void *cc, void *dst); 164 | 165 | /** 166 | * WHIRLPOOL-1 uses the same structure than plain WHIRLPOOL. 167 | */ 168 | typedef sph_whirlpool_context sph_whirlpool1_context; 169 | 170 | #ifdef DOXYGEN_IGNORE 171 | /** 172 | * Initialize a WHIRLPOOL-1 context. This function is identical to 173 | * sph_whirlpool_init(). 174 | * 175 | * @param cc the WHIRLPOOL context (pointer to a 176 | * sph_whirlpool1_context) 177 | */ 178 | void sph_whirlpool1_init(void *cc); 179 | #endif 180 | 181 | #ifndef DOXYGEN_IGNORE 182 | #define sph_whirlpool1_init sph_whirlpool_init 183 | #endif 184 | 185 | /** 186 | * Process some data bytes. It is acceptable that len is zero 187 | * (in which case this function does nothing). This function applies the 188 | * WHIRLPOOL-1 algorithm. 189 | * 190 | * @param cc the WHIRLPOOL context 191 | * @param data the input data 192 | * @param len the input data length (in bytes) 193 | */ 194 | void sph_whirlpool1(void *cc, const void *data, size_t len); 195 | 196 | /** 197 | * Terminate the current WHIRLPOOL-1 computation and output the result into the 198 | * provided buffer. The destination buffer must be wide enough to 199 | * accomodate the result (64 bytes). The context is automatically 200 | * reinitialized. 201 | * 202 | * @param cc the WHIRLPOOL-1 context 203 | * @param dst the destination buffer 204 | */ 205 | void sph_whirlpool1_close(void *cc, void *dst); 206 | 207 | #endif 208 | 209 | #endif -------------------------------------------------------------------------------- /cpuminer-newalgorithms/crypto/skein_port.h: -------------------------------------------------------------------------------- 1 | #ifndef _SKEIN_PORT_H_ 2 | #define _SKEIN_PORT_H_ 3 | 4 | #include 5 | #include 6 | 7 | #ifndef RETURN_VALUES 8 | # define RETURN_VALUES 9 | # if defined( DLL_EXPORT ) 10 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 11 | # define VOID_RETURN __declspec( dllexport ) void __stdcall 12 | # define INT_RETURN __declspec( dllexport ) int __stdcall 13 | # elif defined( __GNUC__ ) 14 | # define VOID_RETURN __declspec( __dllexport__ ) void 15 | # define INT_RETURN __declspec( __dllexport__ ) int 16 | # else 17 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 18 | # endif 19 | # elif defined( DLL_IMPORT ) 20 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 21 | # define VOID_RETURN __declspec( dllimport ) void __stdcall 22 | # define INT_RETURN __declspec( dllimport ) int __stdcall 23 | # elif defined( __GNUC__ ) 24 | # define VOID_RETURN __declspec( __dllimport__ ) void 25 | # define INT_RETURN __declspec( __dllimport__ ) int 26 | # else 27 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 28 | # endif 29 | # elif defined( __WATCOMC__ ) 30 | # define VOID_RETURN void __cdecl 31 | # define INT_RETURN int __cdecl 32 | # else 33 | # define VOID_RETURN void 34 | # define INT_RETURN int 35 | # endif 36 | #endif 37 | 38 | /* These defines are used to declare buffers in a way that allows 39 | faster operations on longer variables to be used. In all these 40 | defines 'size' must be a power of 2 and >= 8 41 | 42 | dec_unit_type(size,x) declares a variable 'x' of length 43 | 'size' bits 44 | 45 | dec_bufr_type(size,bsize,x) declares a buffer 'x' of length 'bsize' 46 | bytes defined as an array of variables 47 | each of 'size' bits (bsize must be a 48 | multiple of size / 8) 49 | 50 | ptr_cast(x,size) casts a pointer to a pointer to a 51 | varaiable of length 'size' bits 52 | */ 53 | 54 | #define ui_type(size) uint##size##_t 55 | #define dec_unit_type(size,x) typedef ui_type(size) x 56 | #define dec_bufr_type(size,bsize,x) typedef ui_type(size) x[bsize / (size >> 3)] 57 | #define ptr_cast(x,size) ((ui_type(size)*)(x)) 58 | 59 | typedef unsigned int uint_t; /* native unsigned integer */ 60 | typedef uint8_t u08b_t; /* 8-bit unsigned integer */ 61 | typedef uint64_t u64b_t; /* 64-bit unsigned integer */ 62 | 63 | #ifndef RotL_64 64 | #define RotL_64(x,N) (((x) << (N)) | ((x) >> (64-(N)))) 65 | #endif 66 | 67 | /* 68 | * Skein is "natively" little-endian (unlike SHA-xxx), for optimal 69 | * performance on x86 CPUs. The Skein code requires the following 70 | * definitions for dealing with endianness: 71 | * 72 | * SKEIN_NEED_SWAP: 0 for little-endian, 1 for big-endian 73 | * Skein_Put64_LSB_First 74 | * Skein_Get64_LSB_First 75 | * Skein_Swap64 76 | * 77 | * If SKEIN_NEED_SWAP is defined at compile time, it is used here 78 | * along with the portable versions of Put64/Get64/Swap64, which 79 | * are slow in general. 80 | * 81 | * Otherwise, an "auto-detect" of endianness is attempted below. 82 | * If the default handling doesn't work well, the user may insert 83 | * platform-specific code instead (e.g., for big-endian CPUs). 84 | * 85 | */ 86 | #ifndef SKEIN_NEED_SWAP /* compile-time "override" for endianness? */ 87 | 88 | 89 | #include "int-util.h" 90 | 91 | #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ 92 | #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ 93 | 94 | #if BYTE_ORDER == LITTLE_ENDIAN 95 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 96 | #endif 97 | 98 | #if BYTE_ORDER == BIG_ENDIAN 99 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 100 | #endif 101 | 102 | /* special handler for IA64, which may be either endianness (?) */ 103 | /* here we assume little-endian, but this may need to be changed */ 104 | #if defined(__ia64) || defined(__ia64__) || defined(_M_IA64) 105 | # define PLATFORM_MUST_ALIGN (1) 106 | #ifndef PLATFORM_BYTE_ORDER 107 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 108 | #endif 109 | #endif 110 | 111 | #ifndef PLATFORM_MUST_ALIGN 112 | # define PLATFORM_MUST_ALIGN (0) 113 | #endif 114 | 115 | 116 | #if PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN 117 | /* here for big-endian CPUs */ 118 | #define SKEIN_NEED_SWAP (1) 119 | #elif PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN 120 | /* here for x86 and x86-64 CPUs (and other detected little-endian CPUs) */ 121 | #define SKEIN_NEED_SWAP (0) 122 | #if PLATFORM_MUST_ALIGN == 0 /* ok to use "fast" versions? */ 123 | #define Skein_Put64_LSB_First(dst08,src64,bCnt) memcpy(dst08,src64,bCnt) 124 | #define Skein_Get64_LSB_First(dst64,src08,wCnt) memcpy(dst64,src08,8*(wCnt)) 125 | #endif 126 | #else 127 | #error "Skein needs endianness setting!" 128 | #endif 129 | 130 | #endif /* ifndef SKEIN_NEED_SWAP */ 131 | 132 | /* 133 | ****************************************************************** 134 | * Provide any definitions still needed. 135 | ****************************************************************** 136 | */ 137 | #ifndef Skein_Swap64 /* swap for big-endian, nop for little-endian */ 138 | #if SKEIN_NEED_SWAP 139 | #define Skein_Swap64(w64) \ 140 | ( (( ((u64b_t)(w64)) & 0xFF) << 56) | \ 141 | (((((u64b_t)(w64)) >> 8) & 0xFF) << 48) | \ 142 | (((((u64b_t)(w64)) >>16) & 0xFF) << 40) | \ 143 | (((((u64b_t)(w64)) >>24) & 0xFF) << 32) | \ 144 | (((((u64b_t)(w64)) >>32) & 0xFF) << 24) | \ 145 | (((((u64b_t)(w64)) >>40) & 0xFF) << 16) | \ 146 | (((((u64b_t)(w64)) >>48) & 0xFF) << 8) | \ 147 | (((((u64b_t)(w64)) >>56) & 0xFF) ) ) 148 | #else 149 | #define Skein_Swap64(w64) (w64) 150 | #endif 151 | #endif /* ifndef Skein_Swap64 */ 152 | 153 | 154 | #ifndef Skein_Put64_LSB_First 155 | void Skein_Put64_LSB_First(u08b_t *dst,const u64b_t *src,size_t bCnt) 156 | #ifdef SKEIN_PORT_CODE /* instantiate the function code here? */ 157 | { /* this version is fully portable (big-endian or little-endian), but slow */ 158 | size_t n; 159 | 160 | for (n=0;n>3] >> (8*(n&7))); 162 | } 163 | #else 164 | ; /* output only the function prototype */ 165 | #endif 166 | #endif /* ifndef Skein_Put64_LSB_First */ 167 | 168 | 169 | #ifndef Skein_Get64_LSB_First 170 | void Skein_Get64_LSB_First(u64b_t *dst,const u08b_t *src,size_t wCnt) 171 | #ifdef SKEIN_PORT_CODE /* instantiate the function code here? */ 172 | { /* this version is fully portable (big-endian or little-endian), but slow */ 173 | size_t n; 174 | 175 | for (n=0;n<8*wCnt;n+=8) 176 | dst[n/8] = (((u64b_t) src[n ]) ) + 177 | (((u64b_t) src[n+1]) << 8) + 178 | (((u64b_t) src[n+2]) << 16) + 179 | (((u64b_t) src[n+3]) << 24) + 180 | (((u64b_t) src[n+4]) << 32) + 181 | (((u64b_t) src[n+5]) << 40) + 182 | (((u64b_t) src[n+6]) << 48) + 183 | (((u64b_t) src[n+7]) << 56) ; 184 | } 185 | #else 186 | ; /* output only the function prototype */ 187 | #endif 188 | #endif /* ifndef Skein_Get64_LSB_First */ 189 | 190 | #endif /* ifndef _SKEIN_PORT_H_ */ 191 | --------------------------------------------------------------------------------