├── .gitattributes ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── LICENSE ├── LICENSE.txt ├── Makefile.am ├── NEWS ├── README ├── README.md ├── README.txt ├── autogen.sh ├── ccminer.sln ├── ccminer.vcxproj ├── ccminer.vcxproj.filters ├── compat.h ├── compat ├── Makefile.am ├── Makefile.in ├── getopt │ ├── getopt.h │ └── getopt_long.c ├── gettimeofday.c ├── includes │ ├── curl │ │ ├── curl.h │ │ ├── curlbuild.h │ │ ├── curlrules.h │ │ ├── curlver.h │ │ ├── easy.h │ │ ├── mprintf.h │ │ ├── multi.h │ │ ├── stdcheaders.h │ │ ├── system.h │ │ └── typecheck-gcc.h │ ├── openssl │ │ ├── e_os2.h │ │ ├── opensslconf.h │ │ └── sha.h │ ├── pthreads │ │ ├── pthread.h │ │ └── sched.h │ └── zlib │ │ ├── zconf.h │ │ └── zlib.h ├── inttypes.h ├── jansson │ ├── Makefile.am │ ├── config.h │ ├── dump.c │ ├── error.c │ ├── hashtable.c │ ├── hashtable.h │ ├── jansson.h │ ├── jansson_config.h │ ├── jansson_private.h │ ├── jansson_private_config.h │ ├── load.c │ ├── memory.c │ ├── pack_unpack.c │ ├── strbuffer.c │ ├── strbuffer.h │ ├── strconv.c │ ├── utf.c │ ├── utf.h │ ├── util.h │ └── value.c ├── libs │ ├── x64 │ │ ├── libcrypto.lib │ │ ├── libcurl.lib │ │ ├── pthreadVC2.lib │ │ └── zlibstat.lib │ └── x86 │ │ ├── libcrypto.lib │ │ ├── libcurl.lib │ │ ├── pthreadVC2.lib │ │ └── zlibstat.lib ├── stdbool.h ├── sys │ └── time.h └── unistd.h ├── compile ├── config.guess ├── config.sub ├── configure.ac ├── configure.sh ├── cpu-miner.cpp ├── cpuminer-config-win.h ├── crypto ├── aesb.cpp ├── c_blake256.cpp ├── c_blake256.h ├── c_groestl.cpp ├── c_groestl.h ├── c_jh.cpp ├── c_jh.h ├── c_keccak.cpp ├── c_keccak.h ├── c_skein.cpp ├── c_skein.h ├── groestl_tables.h ├── hash.h ├── oaes_config.h ├── oaes_lib.cpp ├── oaes_lib.h └── skein_port.h ├── cryptonight-cpu.cpp ├── cryptonight.h ├── cryptonight ├── cryptonight.cu ├── cuda_cryptonight_aes.cu ├── cuda_cryptonight_blake.cu ├── cuda_cryptonight_core.cu ├── cuda_cryptonight_extra.cu ├── cuda_cryptonight_groestl.cu ├── cuda_cryptonight_jh.cu ├── cuda_cryptonight_keccak.cu └── cuda_cryptonight_skein.cu ├── cuda_helper.h ├── depcomp ├── elist.h ├── install-sh ├── miner.h ├── sha2.cpp └── util.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.am text eol=lf 4 | *.in text eol=lf 5 | *.sh text eol=lf 6 | *.ac text eol=lf 7 | *.txt text eol=crlf 8 | *.vcxproj text eol=crlf 9 | *.sln text eol=crlf 10 | 11 | *.cu diff=cpp 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cpuminer-config.h 2 | *.m4 3 | *.in 4 | compat/*.in 5 | compat/jansson/*.in 6 | configure 7 | #ignore thumbnails created by windows 8 | Thumbs.db 9 | #Ignore files build by Visual Studio 10 | *.obj 11 | *.exe 12 | *.pdb 13 | *.user 14 | *.aps 15 | *.pch 16 | *.vspscc 17 | *_i.c 18 | *_p.c 19 | *.ncb 20 | *.suo 21 | *.tlb 22 | *.tlh 23 | *.bak 24 | *.cache 25 | *.ilk 26 | *.log 27 | *.sdf 28 | *.opensdf 29 | [Dd]ebug*/ 30 | *.sbr 31 | obj/ 32 | [Rr]elease*/ 33 | *.db 34 | *.opendb 35 | .deps/ccminer-cpu-miner.Po 36 | .deps/ccminer-cryptonight.Po 37 | .deps/ccminer-sha2.Po 38 | .deps/ccminer-util.Po 39 | ccminer-cpu-miner.o 40 | ccminer-sha2.o 41 | ccminer-util.o 42 | compat/jansson/.deps/dump.Po 43 | compat/jansson/.deps/error.Po 44 | compat/jansson/.deps/hashtable.Po 45 | compat/jansson/.deps/load.Po 46 | compat/jansson/.deps/memory.Po 47 | compat/jansson/.deps/pack_unpack.Po 48 | compat/jansson/.deps/strbuffer.Po 49 | compat/jansson/.deps/utf.Po 50 | compat/jansson/.deps/value.Po 51 | compat/jansson/dump.o 52 | compat/jansson/error.o 53 | compat/jansson/hashtable.o 54 | compat/jansson/jansson_private_config.h 55 | compat/jansson/libjansson.a 56 | compat/jansson/load.o 57 | compat/jansson/Makefile 58 | compat/jansson/memory.o 59 | compat/jansson/pack_unpack.o 60 | compat/jansson/strbuffer.o 61 | compat/jansson/utf.o 62 | compat/jansson/value.o 63 | compat/Makefile 64 | compat/Makefile.in 65 | config.status 66 | cpuminer-config.h 67 | crypto/.deps/ccminer-aesb.Po 68 | crypto/.deps/ccminer-c_blake256.Po 69 | crypto/.deps/ccminer-c_groestl.Po 70 | crypto/.deps/ccminer-c_jh.Po 71 | crypto/.deps/ccminer-c_keccak.Po 72 | crypto/.deps/ccminer-c_skein.Po 73 | crypto/.deps/ccminer-oaes_lib.Po 74 | cryptonight/.deps/.dirstamp 75 | cryptonight/.dirstamp 76 | Makefile 77 | missing 78 | stamp-h1 79 | compat/Makefile.in 80 | cpuminer-config.h 81 | /.vs 82 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | See README.txt 2 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | See LICENSE.txt 2 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | See README.txt 2 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | It is advised to run ./autogen.sh before ./configure (autoconf and automake 2 | need to be installed on your system for autogen.sh to work) 3 | 4 | ./configure has an option named --with-cuda that allows you to specify 5 | where your CUDA 5.5 toolkit is installed (usually /usr/local/cuda-5.5, 6 | but some distros may have a different default location). 7 | 8 | On Ubuntu Xenial (16 LTS), here's the rough installation process using cuda 9.0: 9 | 10 | # wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb 11 | # sudo dpkg -i cuda-repo-ubuntu1604_9.1.85-1_amd64.deb 12 | # sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub 13 | # sudo apt-get update 14 | # sudo apt install build-essential automake pkg-config libssl-dev libcurl4-openssl-dev cuda-9-0 nvidia-opencl-dev nvidia-cuda-toolkit 15 | 16 | For cuda-9-1, you also need the cuda-nvcc-9-1 package. 17 | 18 | # ./autogen.sh 19 | # ./configure --with-cuda=/usr/local/cuda 20 | # make clean 21 | # make 22 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = subdir-objects 2 | 3 | if WANT_JANSSON 4 | JANSSON_INCLUDES= -I$(top_srcdir)/compat/jansson 5 | else 6 | JANSSON_INCLUDES= 7 | endif 8 | 9 | EXTRA_DIST = autogen.sh README.txt LICENSE.txt \ 10 | cudaminer.sln cudaminer.vcxproj cudaminer.vcxproj.filters \ 11 | compat/gettimeofday.c compat/getopt/getopt_long.c cpuminer-config.h.in 12 | 13 | SUBDIRS = compat 14 | 15 | bin_PROGRAMS = ccminer 16 | 17 | ccminer_SOURCES = elist.h miner.h compat.h \ 18 | compat/inttypes.h compat/stdbool.h compat/unistd.h \ 19 | compat/sys/time.h compat/getopt/getopt.h \ 20 | cpu-miner.cpp util.cpp sha2.cpp \ 21 | cryptonight/cryptonight.cu cryptonight/cuda_cryptonight_core.cu cryptonight/cuda_cryptonight_extra.cu \ 22 | cryptonight-cpu.cpp \ 23 | crypto/oaes_lib.cpp \ 24 | crypto/c_keccak.cpp \ 25 | crypto/c_groestl.cpp \ 26 | crypto/c_blake256.cpp \ 27 | crypto/c_jh.cpp \ 28 | crypto/c_skein.cpp \ 29 | crypto/aesb.cpp 30 | 31 | 32 | ccminer_LDFLAGS = $(PTHREAD_FLAGS) @CUDA_LDFLAGS@ 33 | ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @OPENMP_CFLAGS@ @LIBS@ 34 | ccminer_CPPFLAGS = $(CUDA_CFLAGS) -msse2 @LIBCURL_CPPFLAGS@ @OPENMP_CFLAGS@ $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) -DSCRYPT_KECCAK512 -DSCRYPT_CHACHA -DSCRYPT_CHOOSE_COMPILETIME 35 | 36 | NVCC_GENCODE = -D_FORCE_INLINES $(CUDA_CFLAGS) -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_37,code=sm_37 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_61,code=sm_61 -gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_75,code=sm_75 37 | 38 | # we're now targeting all major compute architectures within one binary. 39 | .cu.o: 40 | $(NVCC) @CFLAGS@ -I . $(NVCC_GENCODE) --maxrregcount=128 $(JANSSON_INCLUDES) -o $@ -c $< 41 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | A CUDA based miner for Monero and other Cryptonight coins. 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ccminer-cryptonight, a ccminer mod by tsiv and KlausT 2 | 3 | If you find this tool useful and like to support its continued development, 4 | then consider a donation. 5 | 6 | ## KlausT's donation address: 7 | * BTC: 1QHH2dibyYL5iyMDk3UN4PVvFVtrWD8QKp 8 | * BCH: 1AH1u7B4KtDTUBgmT6NrXyahNEgTac3fL7 9 | 10 | ## tsiv's donation adresses: 11 | * BTC: 1JHDKp59t1RhHFXsTw2UQpR3F9BBz3R3cs 12 | * XMR: 42uasNqYPnSaG3TwRtTeVbQ4aRY3n9jY6VXX3mfgerWt4ohDQLVaBPv3cYGKDXasTUVuLvhxetcuS16ynt85czQ48mbSrWX 13 | 14 | Don't forget to support the original ccminer authors 15 | Christian Buchner and Christian H. This mod would not be 16 | here without their work on ccminer: 17 | 18 | * BTC donation address: 16hJF5mceSojnTD3ZTUDqdRhDyPJzoRakM 19 | 20 | ## Introduction 21 | 22 | This is a CUDA accelerated mining application for use with 23 | Monero and other coins based on the Cryptonight algorithm. 24 | 25 | THIS PROGRAM IS PROVIDED "AS-IS", USE IT AT YOUR OWN RISK! 26 | 27 | ## Command Line Options 28 | ` 29 | -a --algo choose between the supported algos: 30 | cryptonight (the old version) 31 | monero (v7) 32 | graft (v8) 33 | stellite (v3) 34 | intense (v4) 35 | electroneum (v6) 36 | -d, --devices gives a comma separated list of CUDA device IDs 37 | to operate on. Device IDs start counting from 0! 38 | Alternatively give string names of your card like 39 | gtx780ti or gt640#2 (matching 2nd gt640 in the PC). 40 | -l, --launch=CONFIG launch config for the Cryptonight kernel. 41 | a comma separated list of values in form of 42 | AxB where A is the number of threads to run in 43 | each thread block and B is the number of thread 44 | blocks to launch. If less values than devices in use 45 | are provided, the last value will be used for 46 | the remaining devices. If you don't need to vary the 47 | value between devices, you can just enter a single 48 | value and it will be used for all devices. 49 | --bfactor=X Enables running the Cryptonight kernel in smaller pieces.\n\ 50 | The kernel will be run in 2^X parts according to bfactor,\n\ 51 | with a small pause between parts, specified by --bsleep.\n\ 52 | This is a per-device setting like the launch config.\n\ 53 | (default: 0 (no splitting) on Linux, 6 (64 parts) on Windows)\n\ 54 | --bsleep=X Insert a delay of X microseconds between kernel launches.\n\ 55 | Use in combination with --bfactor to mitigate the lag\n\ 56 | when running on your primary GPU.\n\ 57 | This is a per-device setting like the launch config.\n\ 58 | -f, --diff Divide difficulty by this factor (std is 1) 59 | -o, --url=URL URL of mining server (default: " DEF_RPC_URL ") 60 | -O, --userpass=U:P username:password pair for mining server 61 | -u, --user=USERNAME username for mining server 62 | -p, --pass=PASSWORD password for mining server 63 | --cert=FILE certificate for mining server using SSL 64 | -x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy 65 | -t, --threads=N number of miner threads 66 | (default: number of nVidia GPUs in your system) 67 | -r, --retries=N number of times to retry if a network call fails 68 | (default: retry indefinitely) 69 | -R, --retry-pause=N time to pause between retries, in seconds (default: 15) 70 | -T, --timeout=N network timeout, in seconds (default: 270) 71 | -k, --keepalive send keepalive requests to avoid a stratum timeout 72 | -s, --scantime=N upper bound on time spent scanning current work when 73 | long polling is unavailable, in seconds (default: 5) 74 | --no-longpoll disable X-Long-Polling support 75 | --no-stratum disable X-Stratum support 76 | -q, --quiet disable per-thread hashmeter output 77 | -D, --debug enable debug output 78 | --color enable color output 79 | -P, --protocol-dump verbose dump of protocol-level activities 80 | -B, --background run the miner in the background (Linux only) 81 | --benchmark run in offline benchmark mode 82 | -c, --config=FILE load a JSON-format configuration file 83 | -V, --version display version information and exit 84 | -h, --help display this help text and exit 85 | ``` 86 | 87 | ## AUTHORS 88 | 89 | Notable contributors to this application are: 90 | KlausT: 91 | - various fixes and optimizations 92 | 93 | tsiv: 94 | - CUDA implementation for the Cryptonight algorithm. 95 | 96 | Christian Buchner, Christian H. (Germany): 97 | - modifying the original pooler-cpuminer for use with CUDA. 98 | 99 | Jeff Garzik, pooler + contributors: 100 | - The original pooler-cpuminer project 101 | 102 | LucasJones: 103 | - JSON-RPC 2.0 handling and the Cryptonight C-code comes 104 | from his cpuminer fork, cpuminer-multi 105 | 106 | Source code is included to satisfy GNU GPL V3 requirements. 107 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | ccminer-cryptonight, a ccminer mod by tsiv and KlausT 2 | ------------------------------------------------------------- 3 | 4 | *************************************************************** 5 | If you find this tool useful and like to support its continued 6 | development, then consider a donation. 7 | 8 | KlausT's BTC donation addresses: 1QDwdLPrPYSoPqS7pB2kGG84YX6hEcQ4JN 9 | bc1qpt7qnvjaqu8t24xqajgyfqan2v00hrdgrut0zq 10 | KlausT's BCH donation addresses: 1AH1u7B4KtDTUBgmT6NrXyahNEgTac3fL7 11 | qpjupzv3nevqzlkyxx5d736xt78jvet7usm479kl73 12 | 13 | tsiv's BTC donation address: 1JHDKp59t1RhHFXsTw2UQpR3F9BBz3R3cs 14 | tsiv's XMR donation address: 42uasNqYPnSaG3TwRtTeVbQ4aRY3n9jY6VXX3mfgerWt4ohDQLVaBPv3cYGKDXasTUVuLvhxetcuS16ynt85czQ48mbSrWX 15 | 16 | Don't forget to support the original ccminer authors 17 | Christian Buchner and Christian H. This mod would not be 18 | here without their work on ccminer: 19 | 20 | BTC donation address: 16hJF5mceSojnTD3ZTUDqdRhDyPJzoRakM 21 | *************************************************************** 22 | 23 | >>> Introduction <<< 24 | 25 | This is a CUDA accelerated mining application for use with 26 | Monero and other coins based on the Cryptonight algorithm. 27 | 28 | THIS PROGRAM IS PROVIDED "AS-IS", USE IT AT YOUR OWN RISK! 29 | 30 | >>> Command Line Interface <<< 31 | 32 | This code is based on the main ccminer branch, that in turn 33 | is based on the pooler cpuminer 2.3.2 release and inherits 34 | most of their command line interface and options. 35 | 36 | -a --algo choose between the supported algos: 37 | cryptonight (the old version) 38 | monero (v7) 39 | graft (v8) 40 | stellite (v3) 41 | intense (v4) 42 | electroneum (v6) 43 | -d, --devices gives a comma separated list of CUDA device IDs 44 | to operate on. Device IDs start counting from 0! 45 | Alternatively give string names of your card like 46 | gtx780ti or gt640#2 (matching 2nd gt640 in the PC). 47 | -l, --launch=CONFIG launch config for the Cryptonight kernel. 48 | a comma separated list of values in form of 49 | AxB where A is the number of threads to run in 50 | each thread block and B is the number of thread 51 | blocks to launch. If less values than devices in use 52 | are provided, the last value will be used for 53 | the remaining devices. If you don't need to vary the 54 | value between devices, you can just enter a single 55 | value and it will be used for all devices. 56 | --bfactor=X Enables running the Cryptonight kernel in smaller pieces.\n\ 57 | The kernel will be run in 2^X parts according to bfactor,\n\ 58 | with a small pause between parts, specified by --bsleep.\n\ 59 | This is a per-device setting like the launch config.\n\ 60 | (default: 0 (no splitting) on Linux, 6 (64 parts) on Windows)\n\ 61 | --bsleep=X Insert a delay of X microseconds between kernel launches.\n\ 62 | Use in combination with --bfactor to mitigate the lag\n\ 63 | when running on your primary GPU.\n\ 64 | This is a per-device setting like the launch config.\n\ 65 | -f, --diff Divide difficulty by this factor (std is 1) 66 | -o, --url=URL URL of mining server (default: " DEF_RPC_URL ") 67 | -O, --userpass=U:P username:password pair for mining server 68 | -u, --user=USERNAME username for mining server 69 | -p, --pass=PASSWORD password for mining server 70 | --cert=FILE certificate for mining server using SSL 71 | -x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy 72 | -t, --threads=N number of miner threads 73 | (default: number of nVidia GPUs in your system) 74 | -r, --retries=N number of times to retry if a network call fails 75 | (default: retry indefinitely) 76 | -R, --retry-pause=N time to pause between retries, in seconds (default: 15) 77 | -T, --timeout=N network timeout, in seconds (default: 270) 78 | -k, --keepalive send keepalive requests to avoid a stratum timeout 79 | -s, --scantime=N upper bound on time spent scanning current work when 80 | long polling is unavailable, in seconds (default: 5) 81 | --no-longpoll disable X-Long-Polling support 82 | --no-stratum disable X-Stratum support 83 | -q, --quiet disable per-thread hashmeter output 84 | -D, --debug enable debug output 85 | --color enable color output 86 | -P, --protocol-dump verbose dump of protocol-level activities 87 | -B, --background run the miner in the background (Linux only) 88 | --benchmark run in offline benchmark mode 89 | -c, --config=FILE load a JSON-format configuration file 90 | -V, --version display version information and exit 91 | -h, --help display this help text and exit 92 | 93 | 94 | >>> AUTHORS <<< 95 | 96 | Notable contributors to this application are: 97 | KlausT: 98 | - various fixes and optimizations 99 | 100 | tsiv: 101 | - CUDA implementation for the Cryptonight algorithm. 102 | 103 | Christian Buchner, Christian H. (Germany): 104 | - modifying the original pooler-cpuminer for use with CUDA. 105 | 106 | Jeff Garzik, pooler + contributors: 107 | - The original pooler-cpuminer project 108 | 109 | LucasJones: 110 | - JSON-RPC 2.0 handling and the Cryptonight C-code comes 111 | from his cpuminer fork, cpuminer-multi 112 | 113 | Source code is included to satisfy GNU GPL V3 requirements. 114 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | aclocal && autoheader && automake --add-missing --gnu --copy && autoconf 2 | -------------------------------------------------------------------------------- /ccminer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ccminer", "ccminer.vcxproj", "{36DC07F9-A4A6-4877-A146-1B960083CF6F}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|Win32.Build.0 = Debug|Win32 16 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|x64.ActiveCfg = Debug|x64 17 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|x64.Build.0 = Debug|x64 18 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|Win32.ActiveCfg = Release|Win32 19 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|Win32.Build.0 = Release|Win32 20 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|x64.ActiveCfg = Release|x64 21 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /ccminer.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {2450a9c7-a97a-49e1-ba19-c8dbc5a4e3e7} 6 | 7 | 8 | {c53ce808-c5c5-4c6c-99a2-3947090c62f1} 9 | 10 | 11 | {5a45c1bf-81d2-4bc6-97b5-714e34f51a82} 12 | 13 | 14 | {431cec61-9376-4de9-aae9-04c4250652e7} 15 | 16 | 17 | {cc8bb259-5332-4a45-ba81-f4840a55b604} 18 | 19 | 20 | {89362bd8-4690-4f0c-a4f7-6b2fa67a1f34} 21 | 22 | 23 | {6c3cd392-b6b8-424c-87d2-10e33dbd4b41} 24 | 25 | 26 | {5a31b6f4-4943-4b22-b69a-230f3cc96269} 27 | 28 | 29 | {a0f072d0-a831-4c23-8d64-7a026521df9c} 30 | 31 | 32 | {fe39ded0-754b-415f-a284-038a15a0aa55} 33 | 34 | 35 | {17b56151-79ec-4a32-bac3-9d94ae7f68fe} 36 | 37 | 38 | {8f1195ec-0869-4fa7-a24a-e56f06cd45fe} 39 | 40 | 41 | 42 | 43 | Source Files\getopt 44 | 45 | 46 | Source Files\gettimeofday 47 | 48 | 49 | Source Files\jansson 50 | 51 | 52 | Source Files\jansson 53 | 54 | 55 | Source Files\jansson 56 | 57 | 58 | Source Files\jansson 59 | 60 | 61 | Source Files\jansson 62 | 63 | 64 | Source Files\jansson 65 | 66 | 67 | Source Files\jansson 68 | 69 | 70 | Source Files\jansson 71 | 72 | 73 | Source Files\jansson 74 | 75 | 76 | Source Files\jansson 77 | 78 | 79 | Source Files 80 | 81 | 82 | Source Files 83 | 84 | 85 | Source Files\code 86 | 87 | 88 | Source Files\code 89 | 90 | 91 | Source Files\code 92 | 93 | 94 | Source Files\code 95 | 96 | 97 | Source Files\code 98 | 99 | 100 | Source Files\code 101 | 102 | 103 | Source Files\code 104 | 105 | 106 | Source Files\code 107 | 108 | 109 | Source Files\code 110 | 111 | 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files\compat\sys 124 | 125 | 126 | Header Files\compat 127 | 128 | 129 | Header Files\compat 130 | 131 | 132 | Header Files\compat\getopt 133 | 134 | 135 | Header Files\compat 136 | 137 | 138 | Header Files 139 | 140 | 141 | Header Files 142 | 143 | 144 | Header Files 145 | 146 | 147 | Header Files 148 | 149 | 150 | Header Files 151 | 152 | 153 | Header Files 154 | 155 | 156 | Header Files 157 | 158 | 159 | Header Files 160 | 161 | 162 | Header Files 163 | 164 | 165 | Header Files 166 | 167 | 168 | Header Files 169 | 170 | 171 | Header Files\compat\jansson 172 | 173 | 174 | Header Files\compat\jansson 175 | 176 | 177 | Header Files\compat\jansson 178 | 179 | 180 | Header Files\compat\jansson 181 | 182 | 183 | Header Files\compat\jansson 184 | 185 | 186 | Header Files\compat\jansson 187 | 188 | 189 | Header Files\compat\jansson 190 | 191 | 192 | Header Files\compat\jansson 193 | 194 | 195 | Header Files\compat\jansson 196 | 197 | 198 | Header Files 199 | 200 | 201 | 202 | 203 | Source Files\CUDA 204 | 205 | 206 | Source Files\CUDA 207 | 208 | 209 | Source Files\CUDA 210 | 211 | 212 | Source Files\CUDA 213 | 214 | 215 | Source Files\CUDA 216 | 217 | 218 | Source Files\CUDA 219 | 220 | 221 | Source Files\CUDA 222 | 223 | 224 | Source Files\CUDA 225 | 226 | 227 | Source Files\CUDA 228 | 229 | 230 | -------------------------------------------------------------------------------- /compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPAT_H__ 2 | #define __COMPAT_H__ 3 | 4 | #ifdef WIN32 5 | 6 | #include 7 | 8 | static __inline void sleep(int secs) 9 | { 10 | Sleep(secs * 1000); 11 | } 12 | 13 | enum { 14 | PRIO_PROCESS = 0, 15 | }; 16 | 17 | static __inline int setpriority(int which, int who, int prio) 18 | { 19 | return -!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE /*THREAD_PRIORITY_TIME_CRITICAL*/); 20 | } 21 | 22 | #endif /* WIN32 */ 23 | 24 | #endif /* __COMPAT_H__ */ 25 | -------------------------------------------------------------------------------- /compat/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if WANT_JANSSON 3 | SUBDIRS = jansson 4 | else 5 | SUBDIRS = 6 | endif 7 | 8 | -------------------------------------------------------------------------------- /compat/getopt/getopt.h: -------------------------------------------------------------------------------- 1 | /* $Id: getopt.h,v 1.1 2009/10/16 19:50:28 rodney Exp rodney $ */ 2 | /* $OpenBSD: getopt.h,v 1.1 2002/12/03 20:24:29 millert Exp $ */ 3 | /* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ 4 | 5 | /*- 6 | * Copyright (c) 2000 The NetBSD Foundation, Inc. 7 | * All rights reserved. 8 | * 9 | * This code is derived from software contributed to The NetBSD Foundation 10 | * by Dieter Baron and Thomas Klausner. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the NetBSD 23 | * Foundation, Inc. and its contributors. 24 | * 4. Neither the name of The NetBSD Foundation nor the names of its 25 | * contributors may be used to endorse or promote products derived 26 | * from this software without specific prior written permission. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 29 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 30 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 32 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef _GETOPT_H_ 42 | #define _GETOPT_H_ 43 | 44 | #if 0 45 | #include 46 | #endif 47 | 48 | /* 49 | * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions 50 | */ 51 | #define no_argument 0 52 | #define required_argument 1 53 | #define optional_argument 2 54 | 55 | struct option { 56 | /* name of long option */ 57 | const char *name; 58 | /* 59 | * one of no_argument, required_argument, and optional_argument: 60 | * whether option takes an argument 61 | */ 62 | int has_arg; 63 | /* if not NULL, set *flag to val when option found */ 64 | int *flag; 65 | /* if flag not NULL, value to set *flag to; else return value */ 66 | int val; 67 | }; 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | int getopt_long(int, char * const *, const char *, 74 | const struct option *, int *); 75 | int getopt_long_only(int, char * const *, const char *, 76 | const struct option *, int *); 77 | #ifndef _GETOPT_DEFINED 78 | #define _GETOPT_DEFINED 79 | int getopt(int, char * const *, const char *); 80 | int getsubopt(char **, char * const *, char **); 81 | 82 | extern char *optarg; /* getopt(3) external variables */ 83 | extern int opterr; 84 | extern int optind; 85 | extern int optopt; 86 | extern int optreset; 87 | extern char *suboptarg; /* getsubopt(3) external variable */ 88 | #endif /* _GETOPT_DEFINED */ 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | #endif /* !_GETOPT_H_ */ 94 | -------------------------------------------------------------------------------- /compat/gettimeofday.c: -------------------------------------------------------------------------------- 1 | #include < time.h > 2 | #include //I've ommited this line. 3 | #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) 4 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 5 | #else 6 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL 7 | #endif 8 | 9 | struct timezone 10 | { 11 | int tz_minuteswest; /* minutes W of Greenwich */ 12 | int tz_dsttime; /* type of dst correction */ 13 | }; 14 | 15 | int gettimeofday(struct timeval *tv, struct timezone *tz) 16 | { 17 | FILETIME ft; 18 | unsigned __int64 tmpres = 0; 19 | static int tzflag; 20 | 21 | if (NULL != tv) 22 | { 23 | GetSystemTimeAsFileTime(&ft); 24 | 25 | tmpres |= ft.dwHighDateTime; 26 | tmpres <<= 32; 27 | tmpres |= ft.dwLowDateTime; 28 | 29 | /*converting file time to unix epoch*/ 30 | tmpres /= 10; /*convert into microseconds*/ 31 | tmpres -= DELTA_EPOCH_IN_MICROSECS; 32 | tv->tv_sec = (long)(tmpres / 1000000UL); 33 | tv->tv_usec = (long)(tmpres % 1000000UL); 34 | } 35 | 36 | if (NULL != tz) 37 | { 38 | if (!tzflag) 39 | { 40 | _tzset(); 41 | tzflag++; 42 | } 43 | tz->tz_minuteswest = _timezone / 60; 44 | tz->tz_dsttime = _daylight; 45 | } 46 | 47 | return 0; 48 | } 49 | 50 | void usleep(__int64 waitTime) 51 | { 52 | if (waitTime > 0) 53 | { 54 | if (waitTime > 100) 55 | { 56 | // use a waitable timer for larger intervals > 0.1ms 57 | 58 | HANDLE timer; 59 | LARGE_INTEGER ft; 60 | 61 | ft.QuadPart = -(10*waitTime); // Convert to 100 nanosecond interval, negative value indicates relative time 62 | 63 | timer = CreateWaitableTimer(NULL, TRUE, NULL); 64 | SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); 65 | WaitForSingleObject(timer, INFINITE); 66 | CloseHandle(timer); 67 | } 68 | else 69 | { 70 | // use a polling loop for short intervals <= 100ms 71 | 72 | LARGE_INTEGER perfCnt, start, now; 73 | __int64 elapsed; 74 | 75 | QueryPerformanceFrequency(&perfCnt); 76 | QueryPerformanceCounter(&start); 77 | do { 78 | QueryPerformanceCounter((LARGE_INTEGER*) &now); 79 | elapsed = (__int64)((now.QuadPart - start.QuadPart) / (float)perfCnt.QuadPart * 1000 * 1000); 80 | } while ( elapsed < waitTime ); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /compat/includes/curl/curlrules.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_CURLRULES_H 2 | #define __CURL_CURLRULES_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | /* ================================================================ */ 26 | /* COMPILE TIME SANITY CHECKS */ 27 | /* ================================================================ */ 28 | 29 | /* 30 | * NOTE 1: 31 | * ------- 32 | * 33 | * All checks done in this file are intentionally placed in a public 34 | * header file which is pulled by curl/curl.h when an application is 35 | * being built using an already built libcurl library. Additionally 36 | * this file is also included and used when building the library. 37 | * 38 | * If compilation fails on this file it is certainly sure that the 39 | * problem is elsewhere. It could be a problem in the curlbuild.h 40 | * header file, or simply that you are using different compilation 41 | * settings than those used to build the library. 42 | * 43 | * Nothing in this file is intended to be modified or adjusted by the 44 | * curl library user nor by the curl library builder. 45 | * 46 | * Do not deactivate any check, these are done to make sure that the 47 | * library is properly built and used. 48 | * 49 | * You can find further help on the libcurl development mailing list: 50 | * https://cool.haxx.se/mailman/listinfo/curl-library/ 51 | * 52 | * NOTE 2 53 | * ------ 54 | * 55 | * Some of the following compile time checks are based on the fact 56 | * that the dimension of a constant array can not be a negative one. 57 | * In this way if the compile time verification fails, the compilation 58 | * will fail issuing an error. The error description wording is compiler 59 | * dependent but it will be quite similar to one of the following: 60 | * 61 | * "negative subscript or subscript is too large" 62 | * "array must have at least one element" 63 | * "-1 is an illegal array size" 64 | * "size of array is negative" 65 | * 66 | * If you are building an application which tries to use an already 67 | * built libcurl library and you are getting this kind of errors on 68 | * this file, it is a clear indication that there is a mismatch between 69 | * how the library was built and how you are trying to use it for your 70 | * application. Your already compiled or binary library provider is the 71 | * only one who can give you the details you need to properly use it. 72 | */ 73 | 74 | /* 75 | * Verify that some macros are actually defined. 76 | */ 77 | 78 | #ifndef CURL_SIZEOF_LONG 79 | # error "CURL_SIZEOF_LONG definition is missing!" 80 | Error Compilation_aborted_CURL_SIZEOF_LONG_is_missing 81 | #endif 82 | 83 | #ifndef CURL_TYPEOF_CURL_SOCKLEN_T 84 | # error "CURL_TYPEOF_CURL_SOCKLEN_T definition is missing!" 85 | Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_is_missing 86 | #endif 87 | 88 | #ifndef CURL_SIZEOF_CURL_SOCKLEN_T 89 | # error "CURL_SIZEOF_CURL_SOCKLEN_T definition is missing!" 90 | Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_is_missing 91 | #endif 92 | 93 | #ifndef CURL_TYPEOF_CURL_OFF_T 94 | # error "CURL_TYPEOF_CURL_OFF_T definition is missing!" 95 | Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_is_missing 96 | #endif 97 | 98 | #ifndef CURL_FORMAT_CURL_OFF_T 99 | # error "CURL_FORMAT_CURL_OFF_T definition is missing!" 100 | Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_is_missing 101 | #endif 102 | 103 | #ifndef CURL_FORMAT_CURL_OFF_TU 104 | # error "CURL_FORMAT_CURL_OFF_TU definition is missing!" 105 | Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_is_missing 106 | #endif 107 | 108 | #ifndef CURL_SIZEOF_CURL_OFF_T 109 | # error "CURL_SIZEOF_CURL_OFF_T definition is missing!" 110 | Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_is_missing 111 | #endif 112 | 113 | #ifndef CURL_SUFFIX_CURL_OFF_T 114 | # error "CURL_SUFFIX_CURL_OFF_T definition is missing!" 115 | Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_is_missing 116 | #endif 117 | 118 | #ifndef CURL_SUFFIX_CURL_OFF_TU 119 | # error "CURL_SUFFIX_CURL_OFF_TU definition is missing!" 120 | Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_is_missing 121 | #endif 122 | 123 | /* 124 | * Macros private to this header file. 125 | */ 126 | 127 | #define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1 128 | 129 | #define CurlchkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1 130 | 131 | /* 132 | * Verify that the size previously defined and expected for long 133 | * is the same as the one reported by sizeof() at compile time. 134 | */ 135 | 136 | typedef char 137 | __curl_rule_01__ 138 | [CurlchkszEQ(long, CURL_SIZEOF_LONG)]; 139 | 140 | /* 141 | * Verify that the size previously defined and expected for 142 | * curl_off_t is actually the the same as the one reported 143 | * by sizeof() at compile time. 144 | */ 145 | 146 | typedef char 147 | __curl_rule_02__ 148 | [CurlchkszEQ(curl_off_t, CURL_SIZEOF_CURL_OFF_T)]; 149 | 150 | /* 151 | * Verify at compile time that the size of curl_off_t as reported 152 | * by sizeof() is greater or equal than the one reported for long 153 | * for the current compilation. 154 | */ 155 | 156 | typedef char 157 | __curl_rule_03__ 158 | [CurlchkszGE(curl_off_t, long)]; 159 | 160 | /* 161 | * Verify that the size previously defined and expected for 162 | * curl_socklen_t is actually the the same as the one reported 163 | * by sizeof() at compile time. 164 | */ 165 | 166 | typedef char 167 | __curl_rule_04__ 168 | [CurlchkszEQ(curl_socklen_t, CURL_SIZEOF_CURL_SOCKLEN_T)]; 169 | 170 | /* 171 | * Verify at compile time that the size of curl_socklen_t as reported 172 | * by sizeof() is greater or equal than the one reported for int for 173 | * the current compilation. 174 | */ 175 | 176 | typedef char 177 | __curl_rule_05__ 178 | [CurlchkszGE(curl_socklen_t, int)]; 179 | 180 | /* ================================================================ */ 181 | /* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */ 182 | /* ================================================================ */ 183 | 184 | /* 185 | * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow 186 | * these to be visible and exported by the external libcurl interface API, 187 | * while also making them visible to the library internals, simply including 188 | * curl_setup.h, without actually needing to include curl.h internally. 189 | * If some day this section would grow big enough, all this should be moved 190 | * to its own header file. 191 | */ 192 | 193 | /* 194 | * Figure out if we can use the ## preprocessor operator, which is supported 195 | * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__ 196 | * or __cplusplus so we need to carefully check for them too. 197 | */ 198 | 199 | #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \ 200 | defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \ 201 | defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \ 202 | defined(__ILEC400__) 203 | /* This compiler is believed to have an ISO compatible preprocessor */ 204 | #define CURL_ISOCPP 205 | #else 206 | /* This compiler is believed NOT to have an ISO compatible preprocessor */ 207 | #undef CURL_ISOCPP 208 | #endif 209 | 210 | /* 211 | * Macros for minimum-width signed and unsigned curl_off_t integer constants. 212 | */ 213 | 214 | #if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551) 215 | # define __CURL_OFF_T_C_HLPR2(x) x 216 | # define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x) 217 | # define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ 218 | __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T) 219 | # define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ 220 | __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU) 221 | #else 222 | # ifdef CURL_ISOCPP 223 | # define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix 224 | # else 225 | # define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix 226 | # endif 227 | # define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix) 228 | # define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T) 229 | # define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU) 230 | #endif 231 | 232 | /* 233 | * Get rid of macros private to this header file. 234 | */ 235 | 236 | #undef CurlchkszEQ 237 | #undef CurlchkszGE 238 | 239 | #endif /* __CURL_CURLRULES_H */ 240 | -------------------------------------------------------------------------------- /compat/includes/curl/curlver.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_CURLVER_H 2 | #define __CURL_CURLVER_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | /* This header file contains nothing but libcurl version info, generated by 26 | a script at release-time. This was made its own header file in 7.11.2 */ 27 | 28 | /* This is the global package copyright */ 29 | #define LIBCURL_COPYRIGHT "1996 - 2017 Daniel Stenberg, ." 30 | 31 | /* This is the version number of the libcurl package from which this header 32 | file origins: */ 33 | #define LIBCURL_VERSION "7.54.0" 34 | 35 | /* The numeric version number is also available "in parts" by using these 36 | defines: */ 37 | #define LIBCURL_VERSION_MAJOR 7 38 | #define LIBCURL_VERSION_MINOR 54 39 | #define LIBCURL_VERSION_PATCH 0 40 | 41 | /* This is the numeric version of the libcurl version number, meant for easier 42 | parsing and comparions by programs. The LIBCURL_VERSION_NUM define will 43 | always follow this syntax: 44 | 45 | 0xXXYYZZ 46 | 47 | Where XX, YY and ZZ are the main version, release and patch numbers in 48 | hexadecimal (using 8 bits each). All three numbers are always represented 49 | using two digits. 1.2 would appear as "0x010200" while version 9.11.7 50 | appears as "0x090b07". 51 | 52 | This 6-digit (24 bits) hexadecimal number does not show pre-release number, 53 | and it is always a greater number in a more recent release. It makes 54 | comparisons with greater than and less than work. 55 | 56 | Note: This define is the full hex number and _does not_ use the 57 | CURL_VERSION_BITS() macro since curl's own configure script greps for it 58 | and needs it to contain the full number. 59 | */ 60 | #define LIBCURL_VERSION_NUM 0x073600 61 | 62 | /* 63 | * This is the date and time when the full source package was created. The 64 | * timestamp is not stored in git, as the timestamp is properly set in the 65 | * tarballs by the maketgz script. 66 | * 67 | * The format of the date should follow this template: 68 | * 69 | * "Mon Feb 12 11:35:33 UTC 2007" 70 | */ 71 | #define LIBCURL_TIMESTAMP "Wed Apr 19 05:43:55 UTC 2017" 72 | 73 | #define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|z) 74 | #define CURL_AT_LEAST_VERSION(x,y,z) \ 75 | (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z)) 76 | 77 | #endif /* __CURL_CURLVER_H */ 78 | -------------------------------------------------------------------------------- /compat/includes/curl/easy.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_EASY_H 2 | #define __CURL_EASY_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | CURL_EXTERN CURL *curl_easy_init(void); 29 | CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); 30 | CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); 31 | CURL_EXTERN void curl_easy_cleanup(CURL *curl); 32 | 33 | /* 34 | * NAME curl_easy_getinfo() 35 | * 36 | * DESCRIPTION 37 | * 38 | * Request internal information from the curl session with this function. The 39 | * third argument MUST be a pointer to a long, a pointer to a char * or a 40 | * pointer to a double (as the documentation describes elsewhere). The data 41 | * pointed to will be filled in accordingly and can be relied upon only if the 42 | * function returns CURLE_OK. This function is intended to get used *AFTER* a 43 | * performed transfer, all results from this function are undefined until the 44 | * transfer is completed. 45 | */ 46 | CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); 47 | 48 | 49 | /* 50 | * NAME curl_easy_duphandle() 51 | * 52 | * DESCRIPTION 53 | * 54 | * Creates a new curl session handle with the same options set for the handle 55 | * passed in. Duplicating a handle could only be a matter of cloning data and 56 | * options, internal state info and things like persistent connections cannot 57 | * be transferred. It is useful in multithreaded applications when you can run 58 | * curl_easy_duphandle() for each new thread to avoid a series of identical 59 | * curl_easy_setopt() invokes in every thread. 60 | */ 61 | CURL_EXTERN CURL *curl_easy_duphandle(CURL *curl); 62 | 63 | /* 64 | * NAME curl_easy_reset() 65 | * 66 | * DESCRIPTION 67 | * 68 | * Re-initializes a CURL handle to the default values. This puts back the 69 | * handle to the same state as it was in when it was just created. 70 | * 71 | * It does keep: live connections, the Session ID cache, the DNS cache and the 72 | * cookies. 73 | */ 74 | CURL_EXTERN void curl_easy_reset(CURL *curl); 75 | 76 | /* 77 | * NAME curl_easy_recv() 78 | * 79 | * DESCRIPTION 80 | * 81 | * Receives data from the connected socket. Use after successful 82 | * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. 83 | */ 84 | CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, 85 | size_t *n); 86 | 87 | /* 88 | * NAME curl_easy_send() 89 | * 90 | * DESCRIPTION 91 | * 92 | * Sends data over the connected socket. Use after successful 93 | * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. 94 | */ 95 | CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, 96 | size_t buflen, size_t *n); 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /compat/includes/curl/mprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_MPRINTF_H 2 | #define __CURL_MPRINTF_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #include 26 | #include /* needed for FILE */ 27 | #include "curl.h" /* for CURL_EXTERN */ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | CURL_EXTERN int curl_mprintf(const char *format, ...); 34 | CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); 35 | CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); 36 | CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, 37 | const char *format, ...); 38 | CURL_EXTERN int curl_mvprintf(const char *format, va_list args); 39 | CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); 40 | CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); 41 | CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, 42 | const char *format, va_list args); 43 | CURL_EXTERN char *curl_maprintf(const char *format, ...); 44 | CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* __CURL_MPRINTF_H */ 51 | -------------------------------------------------------------------------------- /compat/includes/curl/stdcheaders.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDC_HEADERS_H 2 | #define __STDC_HEADERS_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #include 26 | 27 | size_t fread(void *, size_t, size_t, FILE *); 28 | size_t fwrite(const void *, size_t, size_t, FILE *); 29 | 30 | int strcasecmp(const char *, const char *); 31 | int strncasecmp(const char *, const char *, size_t); 32 | 33 | #endif /* __STDC_HEADERS_H */ 34 | -------------------------------------------------------------------------------- /compat/includes/openssl/opensslconf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WARNING: do not edit! 3 | * Generated by makefile from include\openssl\opensslconf.h.in 4 | * 5 | * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. 6 | * 7 | * Licensed under the OpenSSL license (the "License"). You may not use 8 | * this file except in compliance with the License. You can obtain a copy 9 | * in the file LICENSE in the source distribution or at 10 | * https://www.openssl.org/source/license.html 11 | */ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #ifdef OPENSSL_ALGORITHM_DEFINES 18 | # error OPENSSL_ALGORITHM_DEFINES no longer supported 19 | #endif 20 | 21 | /* 22 | * OpenSSL was configured with the following options: 23 | */ 24 | 25 | #ifndef OPENSSL_SYS_WIN64A 26 | # define OPENSSL_SYS_WIN64A 1 27 | #endif 28 | #ifndef OPENSSL_NO_MD2 29 | # define OPENSSL_NO_MD2 30 | #endif 31 | #ifndef OPENSSL_NO_RC5 32 | # define OPENSSL_NO_RC5 33 | #endif 34 | #ifndef OPENSSL_THREADS 35 | # define OPENSSL_THREADS 36 | #endif 37 | #ifndef OPENSSL_NO_ASAN 38 | # define OPENSSL_NO_ASAN 39 | #endif 40 | #ifndef OPENSSL_NO_CRYPTO_MDEBUG 41 | # define OPENSSL_NO_CRYPTO_MDEBUG 42 | #endif 43 | #ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE 44 | # define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE 45 | #endif 46 | #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 47 | # define OPENSSL_NO_EC_NISTP_64_GCC_128 48 | #endif 49 | #ifndef OPENSSL_NO_EGD 50 | # define OPENSSL_NO_EGD 51 | #endif 52 | #ifndef OPENSSL_NO_FUZZ_AFL 53 | # define OPENSSL_NO_FUZZ_AFL 54 | #endif 55 | #ifndef OPENSSL_NO_FUZZ_LIBFUZZER 56 | # define OPENSSL_NO_FUZZ_LIBFUZZER 57 | #endif 58 | #ifndef OPENSSL_NO_HEARTBEATS 59 | # define OPENSSL_NO_HEARTBEATS 60 | #endif 61 | #ifndef OPENSSL_NO_MSAN 62 | # define OPENSSL_NO_MSAN 63 | #endif 64 | #ifndef OPENSSL_NO_SCTP 65 | # define OPENSSL_NO_SCTP 66 | #endif 67 | #ifndef OPENSSL_NO_SSL_TRACE 68 | # define OPENSSL_NO_SSL_TRACE 69 | #endif 70 | #ifndef OPENSSL_NO_SSL3 71 | # define OPENSSL_NO_SSL3 72 | #endif 73 | #ifndef OPENSSL_NO_SSL3_METHOD 74 | # define OPENSSL_NO_SSL3_METHOD 75 | #endif 76 | #ifndef OPENSSL_NO_UBSAN 77 | # define OPENSSL_NO_UBSAN 78 | #endif 79 | #ifndef OPENSSL_NO_UNIT_TEST 80 | # define OPENSSL_NO_UNIT_TEST 81 | #endif 82 | #ifndef OPENSSL_NO_WEAK_SSL_CIPHERS 83 | # define OPENSSL_NO_WEAK_SSL_CIPHERS 84 | #endif 85 | #ifndef OPENSSL_NO_AFALGENG 86 | # define OPENSSL_NO_AFALGENG 87 | #endif 88 | 89 | 90 | /* 91 | * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers 92 | * don't like that. This will hopefully silence them. 93 | */ 94 | #define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy; 95 | 96 | /* 97 | * Applications should use -DOPENSSL_API_COMPAT= to suppress the 98 | * declarations of functions deprecated in or before . Otherwise, they 99 | * still won't see them if the library has been built to disable deprecated 100 | * functions. 101 | */ 102 | #if defined(OPENSSL_NO_DEPRECATED) 103 | # define DECLARE_DEPRECATED(f) 104 | #elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0) 105 | # define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated)); 106 | #else 107 | # define DECLARE_DEPRECATED(f) f; 108 | #endif 109 | 110 | #ifndef OPENSSL_FILE 111 | # ifdef OPENSSL_NO_FILENAMES 112 | # define OPENSSL_FILE "" 113 | # define OPENSSL_LINE 0 114 | # else 115 | # define OPENSSL_FILE __FILE__ 116 | # define OPENSSL_LINE __LINE__ 117 | # endif 118 | #endif 119 | 120 | #ifndef OPENSSL_MIN_API 121 | # define OPENSSL_MIN_API 0 122 | #endif 123 | 124 | #if !defined(OPENSSL_API_COMPAT) || OPENSSL_API_COMPAT < OPENSSL_MIN_API 125 | # undef OPENSSL_API_COMPAT 126 | # define OPENSSL_API_COMPAT OPENSSL_MIN_API 127 | #endif 128 | 129 | #if OPENSSL_API_COMPAT < 0x10100000L 130 | # define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f) 131 | #else 132 | # define DEPRECATEDIN_1_1_0(f) 133 | #endif 134 | 135 | #if OPENSSL_API_COMPAT < 0x10000000L 136 | # define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f) 137 | #else 138 | # define DEPRECATEDIN_1_0_0(f) 139 | #endif 140 | 141 | #if OPENSSL_API_COMPAT < 0x00908000L 142 | # define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f) 143 | #else 144 | # define DEPRECATEDIN_0_9_8(f) 145 | #endif 146 | 147 | #define OPENSSL_CPUID_OBJ 148 | 149 | /* Generate 80386 code? */ 150 | #undef I386_ONLY 151 | 152 | #undef OPENSSL_UNISTD 153 | #define OPENSSL_UNISTD 154 | 155 | #define OPENSSL_EXPORT_VAR_AS_FUNCTION 156 | 157 | /* 158 | * The following are cipher-specific, but are part of the public API. 159 | */ 160 | #if !defined(OPENSSL_SYS_UEFI) 161 | # undef BN_LLONG 162 | /* Only one for the following should be defined */ 163 | # undef SIXTY_FOUR_BIT_LONG 164 | # define SIXTY_FOUR_BIT 165 | # undef THIRTY_TWO_BIT 166 | #endif 167 | 168 | #define RC4_INT unsigned int 169 | 170 | #ifdef __cplusplus 171 | } 172 | #endif 173 | -------------------------------------------------------------------------------- /compat/includes/openssl/sha.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. 3 | * 4 | * Licensed under the OpenSSL license (the "License"). You may not use 5 | * this file except in compliance with the License. You can obtain a copy 6 | * in the file LICENSE in the source distribution or at 7 | * https://www.openssl.org/source/license.html 8 | */ 9 | 10 | #ifndef HEADER_SHA_H 11 | # define HEADER_SHA_H 12 | 13 | # include 14 | # include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | /*- 21 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 22 | * ! SHA_LONG has to be at least 32 bits wide. ! 23 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 24 | */ 25 | # define SHA_LONG unsigned int 26 | 27 | # define SHA_LBLOCK 16 28 | # define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a 29 | * contiguous array of 32 bit wide 30 | * big-endian values. */ 31 | # define SHA_LAST_BLOCK (SHA_CBLOCK-8) 32 | # define SHA_DIGEST_LENGTH 20 33 | 34 | typedef struct SHAstate_st { 35 | SHA_LONG h0, h1, h2, h3, h4; 36 | SHA_LONG Nl, Nh; 37 | SHA_LONG data[SHA_LBLOCK]; 38 | unsigned int num; 39 | } SHA_CTX; 40 | 41 | int SHA1_Init(SHA_CTX *c); 42 | int SHA1_Update(SHA_CTX *c, const void *data, size_t len); 43 | int SHA1_Final(unsigned char *md, SHA_CTX *c); 44 | unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); 45 | void SHA1_Transform(SHA_CTX *c, const unsigned char *data); 46 | 47 | # define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a 48 | * contiguous array of 32 bit wide 49 | * big-endian values. */ 50 | 51 | typedef struct SHA256state_st { 52 | SHA_LONG h[8]; 53 | SHA_LONG Nl, Nh; 54 | SHA_LONG data[SHA_LBLOCK]; 55 | unsigned int num, md_len; 56 | } SHA256_CTX; 57 | 58 | int SHA224_Init(SHA256_CTX *c); 59 | int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); 60 | int SHA224_Final(unsigned char *md, SHA256_CTX *c); 61 | unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md); 62 | int SHA256_Init(SHA256_CTX *c); 63 | int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); 64 | int SHA256_Final(unsigned char *md, SHA256_CTX *c); 65 | unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md); 66 | void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); 67 | 68 | # define SHA224_DIGEST_LENGTH 28 69 | # define SHA256_DIGEST_LENGTH 32 70 | # define SHA384_DIGEST_LENGTH 48 71 | # define SHA512_DIGEST_LENGTH 64 72 | 73 | /* 74 | * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64 75 | * being exactly 64-bit wide. See Implementation Notes in sha512.c 76 | * for further details. 77 | */ 78 | /* 79 | * SHA-512 treats input data as a 80 | * contiguous array of 64 bit 81 | * wide big-endian values. 82 | */ 83 | # define SHA512_CBLOCK (SHA_LBLOCK*8) 84 | # if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) 85 | # define SHA_LONG64 unsigned __int64 86 | # define U64(C) C##UI64 87 | # elif defined(__arch64__) 88 | # define SHA_LONG64 unsigned long 89 | # define U64(C) C##UL 90 | # else 91 | # define SHA_LONG64 unsigned long long 92 | # define U64(C) C##ULL 93 | # endif 94 | 95 | typedef struct SHA512state_st { 96 | SHA_LONG64 h[8]; 97 | SHA_LONG64 Nl, Nh; 98 | union { 99 | SHA_LONG64 d[SHA_LBLOCK]; 100 | unsigned char p[SHA512_CBLOCK]; 101 | } u; 102 | unsigned int num, md_len; 103 | } SHA512_CTX; 104 | 105 | int SHA384_Init(SHA512_CTX *c); 106 | int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); 107 | int SHA384_Final(unsigned char *md, SHA512_CTX *c); 108 | unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md); 109 | int SHA512_Init(SHA512_CTX *c); 110 | int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); 111 | int SHA512_Final(unsigned char *md, SHA512_CTX *c); 112 | unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md); 113 | void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /compat/includes/pthreads/sched.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Module: sched.h 3 | * 4 | * Purpose: 5 | * Provides an implementation of POSIX realtime extensions 6 | * as defined in 7 | * 8 | * POSIX 1003.1b-1993 (POSIX.1b) 9 | * 10 | * -------------------------------------------------------------------------- 11 | * 12 | * Pthreads-win32 - POSIX Threads Library for Win32 13 | * Copyright(C) 1998 John E. Bossom 14 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 15 | * 16 | * Contact Email: rpj@callisto.canberra.edu.au 17 | * 18 | * The current list of contributors is contained 19 | * in the file CONTRIBUTORS included with the source 20 | * code distribution. The list can also be seen at the 21 | * following World Wide Web location: 22 | * http://sources.redhat.com/pthreads-win32/contributors.html 23 | * 24 | * This library is free software; you can redistribute it and/or 25 | * modify it under the terms of the GNU Lesser General Public 26 | * License as published by the Free Software Foundation; either 27 | * version 2 of the License, or (at your option) any later version. 28 | * 29 | * This library is distributed in the hope that it will be useful, 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 32 | * Lesser General Public License for more details. 33 | * 34 | * You should have received a copy of the GNU Lesser General Public 35 | * License along with this library in the file COPYING.LIB; 36 | * if not, write to the Free Software Foundation, Inc., 37 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 38 | */ 39 | #if !defined(_SCHED_H) 40 | #define _SCHED_H 41 | 42 | #undef PTW32_SCHED_LEVEL 43 | 44 | #if defined(_POSIX_SOURCE) 45 | #define PTW32_SCHED_LEVEL 0 46 | /* Early POSIX */ 47 | #endif 48 | 49 | #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 50 | #undef PTW32_SCHED_LEVEL 51 | #define PTW32_SCHED_LEVEL 1 52 | /* Include 1b, 1c and 1d */ 53 | #endif 54 | 55 | #if defined(INCLUDE_NP) 56 | #undef PTW32_SCHED_LEVEL 57 | #define PTW32_SCHED_LEVEL 2 58 | /* Include Non-Portable extensions */ 59 | #endif 60 | 61 | #define PTW32_SCHED_LEVEL_MAX 3 62 | 63 | #if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_SCHED_LEVEL) 64 | #define PTW32_SCHED_LEVEL PTW32_SCHED_LEVEL_MAX 65 | /* Include everything */ 66 | #endif 67 | 68 | 69 | #if defined(__GNUC__) && !defined(__declspec) 70 | # error Please upgrade your GNU compiler to one that supports __declspec. 71 | #endif 72 | 73 | /* 74 | * When building the library, you should define PTW32_BUILD so that 75 | * the variables/functions are exported correctly. When using the library, 76 | * do NOT define PTW32_BUILD, and then the variables/functions will 77 | * be imported correctly. 78 | */ 79 | #if !defined(PTW32_STATIC_LIB) 80 | # if defined(PTW32_BUILD) 81 | # define PTW32_DLLPORT __declspec (dllexport) 82 | # else 83 | # define PTW32_DLLPORT __declspec (dllimport) 84 | # endif 85 | #else 86 | # define PTW32_DLLPORT 87 | #endif 88 | 89 | /* 90 | * This is a duplicate of what is in the autoconf config.h, 91 | * which is only used when building the pthread-win32 libraries. 92 | */ 93 | 94 | #if !defined(PTW32_CONFIG_H) 95 | # if defined(WINCE) 96 | # define NEED_ERRNO 97 | # define NEED_SEM 98 | # endif 99 | # if defined(__MINGW64__) 100 | # define HAVE_STRUCT_TIMESPEC 101 | # define HAVE_MODE_T 102 | # elif defined(_UWIN) || defined(__MINGW32__) 103 | # define HAVE_MODE_T 104 | # endif 105 | #endif 106 | 107 | /* 108 | * 109 | */ 110 | 111 | #if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX 112 | #if defined(NEED_ERRNO) 113 | #include "need_errno.h" 114 | #else 115 | #include 116 | #endif 117 | #endif /* PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX */ 118 | 119 | #if (defined(__MINGW64__) || defined(__MINGW32__)) || defined(_UWIN) 120 | # if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX 121 | /* For pid_t */ 122 | # include 123 | /* Required by Unix 98 */ 124 | # include 125 | # else 126 | typedef int pid_t; 127 | # endif 128 | #else 129 | typedef int pid_t; 130 | #endif 131 | 132 | /* Thread scheduling policies */ 133 | 134 | enum { 135 | SCHED_OTHER = 0, 136 | SCHED_FIFO, 137 | SCHED_RR, 138 | SCHED_MIN = SCHED_OTHER, 139 | SCHED_MAX = SCHED_RR 140 | }; 141 | 142 | struct sched_param { 143 | int sched_priority; 144 | }; 145 | 146 | #if defined(__cplusplus) 147 | extern "C" 148 | { 149 | #endif /* __cplusplus */ 150 | 151 | PTW32_DLLPORT int __cdecl sched_yield (void); 152 | 153 | PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy); 154 | 155 | PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy); 156 | 157 | PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy); 158 | 159 | PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid); 160 | 161 | /* 162 | * Note that this macro returns ENOTSUP rather than 163 | * ENOSYS as might be expected. However, returning ENOSYS 164 | * should mean that sched_get_priority_{min,max} are 165 | * not implemented as well as sched_rr_get_interval. 166 | * This is not the case, since we just don't support 167 | * round-robin scheduling. Therefore I have chosen to 168 | * return the same value as sched_setscheduler when 169 | * SCHED_RR is passed to it. 170 | */ 171 | #define sched_rr_get_interval(_pid, _interval) \ 172 | ( errno = ENOTSUP, (int) -1 ) 173 | 174 | 175 | #if defined(__cplusplus) 176 | } /* End of extern "C" */ 177 | #endif /* __cplusplus */ 178 | 179 | #undef PTW32_SCHED_LEVEL 180 | #undef PTW32_SCHED_LEVEL_MAX 181 | 182 | #endif /* !_SCHED_H */ 183 | 184 | -------------------------------------------------------------------------------- /compat/inttypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | -------------------------------------------------------------------------------- /compat/jansson/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libjansson.a 2 | 3 | libjansson_a_SOURCES = \ 4 | config.h \ 5 | dump.c \ 6 | error.c \ 7 | hashtable.c \ 8 | hashtable.h \ 9 | jansson.h \ 10 | jansson_config.h \ 11 | jansson_private.h \ 12 | load.c \ 13 | memory.c \ 14 | pack_unpack.c \ 15 | strbuffer.c \ 16 | strbuffer.h \ 17 | strconv.c \ 18 | utf.c \ 19 | utf.h \ 20 | util.h \ 21 | value.c 22 | 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /compat/jansson/error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "jansson_private.h" 3 | 4 | void jsonp_error_init(json_error_t *error, const char *source) 5 | { 6 | if(error) 7 | { 8 | error->text[0] = '\0'; 9 | error->line = -1; 10 | error->column = -1; 11 | error->position = 0; 12 | if(source) 13 | jsonp_error_set_source(error, source); 14 | else 15 | error->source[0] = '\0'; 16 | } 17 | } 18 | 19 | void jsonp_error_set_source(json_error_t *error, const char *source) 20 | { 21 | size_t length; 22 | 23 | if(!error || !source) 24 | return; 25 | 26 | length = strlen(source); 27 | if(length < JSON_ERROR_SOURCE_LENGTH) 28 | strcpy(error->source, source); 29 | else { 30 | size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4; 31 | strcpy(error->source, "..."); 32 | strcpy(error->source + 3, source + extra); 33 | } 34 | } 35 | 36 | void jsonp_error_set(json_error_t *error, int line, int column, 37 | size_t position, const char *msg, ...) 38 | { 39 | va_list ap; 40 | 41 | va_start(ap, msg); 42 | jsonp_error_vset(error, line, column, position, msg, ap); 43 | va_end(ap); 44 | } 45 | 46 | void jsonp_error_vset(json_error_t *error, int line, int column, 47 | size_t position, const char *msg, va_list ap) 48 | { 49 | if(!error) 50 | return; 51 | 52 | if(error->text[0] != '\0') { 53 | /* error already set */ 54 | return; 55 | } 56 | 57 | error->line = line; 58 | error->column = column; 59 | error->position = position; 60 | 61 | vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap); 62 | error->text[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; 63 | } 64 | -------------------------------------------------------------------------------- /compat/jansson/hashtable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 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 | struct hashtable_list { 12 | struct hashtable_list *prev; 13 | struct hashtable_list *next; 14 | }; 15 | 16 | /* "pair" may be a bit confusing a name, but think of it as a 17 | key-value pair. In this case, it just encodes some extra data, 18 | too */ 19 | struct hashtable_pair { 20 | size_t hash; 21 | struct hashtable_list list; 22 | json_t *value; 23 | size_t serial; 24 | char key[1]; 25 | }; 26 | 27 | struct hashtable_bucket { 28 | struct hashtable_list *first; 29 | struct hashtable_list *last; 30 | }; 31 | 32 | typedef struct hashtable { 33 | size_t size; 34 | struct hashtable_bucket *buckets; 35 | size_t num_buckets; /* index to primes[] */ 36 | struct hashtable_list list; 37 | } hashtable_t; 38 | 39 | 40 | #define hashtable_key_to_iter(key_) \ 41 | (&(container_of(key_, struct hashtable_pair, key)->list)) 42 | 43 | /** 44 | * hashtable_init - Initialize a hashtable object 45 | * 46 | * @hashtable: The (statically allocated) hashtable object 47 | * 48 | * Initializes a statically allocated hashtable object. The object 49 | * should be cleared with hashtable_close when it's no longer used. 50 | * 51 | * Returns 0 on success, -1 on error (out of memory). 52 | */ 53 | int hashtable_init(hashtable_t *hashtable); 54 | 55 | /** 56 | * hashtable_close - Release all resources used by a hashtable object 57 | * 58 | * @hashtable: The hashtable 59 | * 60 | * Destroys a statically allocated hashtable object. 61 | */ 62 | void hashtable_close(hashtable_t *hashtable); 63 | 64 | /** 65 | * hashtable_set - Add/modify value in hashtable 66 | * 67 | * @hashtable: The hashtable object 68 | * @key: The key 69 | * @serial: For addition order of keys 70 | * @value: The value 71 | * 72 | * If a value with the given key already exists, its value is replaced 73 | * with the new value. Value is "stealed" in the sense that hashtable 74 | * doesn't increment its refcount but decreases the refcount when the 75 | * value is no longer needed. 76 | * 77 | * Returns 0 on success, -1 on failure (out of memory). 78 | */ 79 | int hashtable_set(hashtable_t *hashtable, 80 | const char *key, size_t serial, 81 | json_t *value); 82 | 83 | /** 84 | * hashtable_get - Get a value associated with a key 85 | * 86 | * @hashtable: The hashtable object 87 | * @key: The key 88 | * 89 | * Returns value if it is found, or NULL otherwise. 90 | */ 91 | void *hashtable_get(hashtable_t *hashtable, const char *key); 92 | 93 | /** 94 | * hashtable_del - Remove a value from the hashtable 95 | * 96 | * @hashtable: The hashtable object 97 | * @key: The key 98 | * 99 | * Returns 0 on success, or -1 if the key was not found. 100 | */ 101 | int hashtable_del(hashtable_t *hashtable, const char *key); 102 | 103 | /** 104 | * hashtable_clear - Clear hashtable 105 | * 106 | * @hashtable: The hashtable object 107 | * 108 | * Removes all items from the hashtable. 109 | */ 110 | void hashtable_clear(hashtable_t *hashtable); 111 | 112 | /** 113 | * hashtable_iter - Iterate over hashtable 114 | * 115 | * @hashtable: The hashtable object 116 | * 117 | * Returns an opaque iterator to the first element in the hashtable. 118 | * The iterator should be passed to hashtable_iter_* functions. 119 | * The hashtable items are not iterated over in any particular order. 120 | * 121 | * There's no need to free the iterator in any way. The iterator is 122 | * valid as long as the item that is referenced by the iterator is not 123 | * deleted. Other values may be added or deleted. In particular, 124 | * hashtable_iter_next() may be called on an iterator, and after that 125 | * the key/value pair pointed by the old iterator may be deleted. 126 | */ 127 | void *hashtable_iter(hashtable_t *hashtable); 128 | 129 | /** 130 | * hashtable_iter_at - Return an iterator at a specific key 131 | * 132 | * @hashtable: The hashtable object 133 | * @key: The key that the iterator should point to 134 | * 135 | * Like hashtable_iter() but returns an iterator pointing to a 136 | * specific key. 137 | */ 138 | void *hashtable_iter_at(hashtable_t *hashtable, const char *key); 139 | 140 | /** 141 | * hashtable_iter_next - Advance an iterator 142 | * 143 | * @hashtable: The hashtable object 144 | * @iter: The iterator 145 | * 146 | * Returns a new iterator pointing to the next element in the 147 | * hashtable or NULL if the whole hastable has been iterated over. 148 | */ 149 | void *hashtable_iter_next(hashtable_t *hashtable, void *iter); 150 | 151 | /** 152 | * hashtable_iter_key - Retrieve the key pointed by an iterator 153 | * 154 | * @iter: The iterator 155 | */ 156 | void *hashtable_iter_key(void *iter); 157 | 158 | /** 159 | * hashtable_iter_serial - Retrieve the serial number pointed to by an iterator 160 | * 161 | * @iter: The iterator 162 | */ 163 | size_t hashtable_iter_serial(void *iter); 164 | 165 | /** 166 | * hashtable_iter_value - Retrieve the value pointed by an iterator 167 | * 168 | * @iter: The iterator 169 | */ 170 | void *hashtable_iter_value(void *iter); 171 | 172 | /** 173 | * hashtable_iter_set - Set the value pointed by an iterator 174 | * 175 | * @iter: The iterator 176 | * @value: The value to set 177 | */ 178 | void hashtable_iter_set(void *iter, json_t *value); 179 | 180 | #endif 181 | -------------------------------------------------------------------------------- /compat/jansson/jansson_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2013 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 | * This file specifies a part of the site-specific configuration for 9 | * Jansson, namely those things that affect the public API in 10 | * jansson.h. 11 | * 12 | * The configure script copies this file to jansson_config.h and 13 | * replaces @var@ substitutions by values that fit your system. If you 14 | * cannot run the configure script, you can do the value substitution 15 | * by hand. 16 | */ 17 | 18 | #ifndef JANSSON_CONFIG_H 19 | #define JANSSON_CONFIG_H 20 | /* If your compiler supports the inline keyword in C, JSON_INLINE is 21 | defined to `inline', otherwise empty. In C++, the inline is always 22 | supported. */ 23 | 24 | #ifdef _MSC_VER 25 | #ifndef __cplusplus 26 | #define inline __inline 27 | #endif 28 | #endif 29 | 30 | #ifdef __cplusplus 31 | #define JSON_INLINE inline 32 | #else 33 | #define JSON_INLINE inline 34 | #endif 35 | 36 | /* If your compiler supports the `long long` type and the strtoll() 37 | library function, JSON_INTEGER_IS_LONG_LONG is defined to 1, 38 | otherwise to 0. */ 39 | #define JSON_INTEGER_IS_LONG_LONG 1 40 | 41 | /* If locale.h and localeconv() are available, define to 1, 42 | otherwise to 0. */ 43 | #define JSON_HAVE_LOCALECONV 1 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /compat/jansson/jansson_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 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 12 | #include "jansson.h" 13 | #include "hashtable.h" 14 | #include "strbuffer.h" 15 | 16 | #define container_of(ptr_, type_, member_) \ 17 | ((type_ *)((char *)ptr_ - offsetof(type_, member_))) 18 | 19 | /* On some platforms, max() may already be defined */ 20 | #ifndef max 21 | #define max(a, b) ((a) > (b) ? (a) : (b)) 22 | #endif 23 | 24 | /* va_copy is a C99 feature. In C89 implementations, it's sometimes 25 | available as __va_copy. If not, memcpy() should do the trick. */ 26 | #ifndef va_copy 27 | #ifdef __va_copy 28 | #define va_copy __va_copy 29 | #else 30 | #define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list)) 31 | #endif 32 | #endif 33 | 34 | typedef struct { 35 | json_t json; 36 | hashtable_t hashtable; 37 | size_t serial; 38 | int visited; 39 | } json_object_t; 40 | 41 | typedef struct { 42 | json_t json; 43 | size_t size; 44 | size_t entries; 45 | json_t **table; 46 | int visited; 47 | } json_array_t; 48 | 49 | typedef struct { 50 | json_t json; 51 | char *value; 52 | } json_string_t; 53 | 54 | typedef struct { 55 | json_t json; 56 | double value; 57 | } json_real_t; 58 | 59 | typedef struct { 60 | json_t json; 61 | json_int_t value; 62 | } json_integer_t; 63 | 64 | #define json_to_object(json_) container_of(json_, json_object_t, json) 65 | #define json_to_array(json_) container_of(json_, json_array_t, json) 66 | #define json_to_string(json_) container_of(json_, json_string_t, json) 67 | #define json_to_real(json_) container_of(json_, json_real_t, json) 68 | #define json_to_integer(json_) container_of(json_, json_integer_t, json) 69 | 70 | void jsonp_error_init(json_error_t *error, const char *source); 71 | void jsonp_error_set_source(json_error_t *error, const char *source); 72 | void jsonp_error_set(json_error_t *error, int line, int column, 73 | size_t position, const char *msg, ...); 74 | void jsonp_error_vset(json_error_t *error, int line, int column, 75 | size_t position, const char *msg, va_list ap); 76 | 77 | /* Locale independent string<->double conversions */ 78 | int jsonp_strtod(strbuffer_t *strbuffer, double *out); 79 | int jsonp_dtostr(char *buffer, size_t size, double value); 80 | 81 | /* Wrappers for custom memory functions */ 82 | void* jsonp_malloc(size_t size); 83 | void jsonp_free(void *ptr); 84 | char *jsonp_strndup(const char *str, size_t length); 85 | char *jsonp_strdup(const char *str); 86 | 87 | /* Windows compatibility */ 88 | #ifdef _WIN32 89 | #define snprintf _snprintf 90 | #define vsnprintf _vsnprintf 91 | #endif 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /compat/jansson/jansson_private_config.h: -------------------------------------------------------------------------------- 1 | /* jansson_private_config.h. Generated from jansson_private_config.h.in by configure. */ 2 | /* jansson_private_config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if gcc's __atomic builtins are available */ 5 | /* #undef HAVE_ATOMIC_BUILTINS */ 6 | 7 | /* Define to 1 if you have the `close' function. */ 8 | #define HAVE_CLOSE 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | /* #undef HAVE_DLFCN_H */ 12 | 13 | /* Define to 1 if you have the header file. */ 14 | /* #undef HAVE_ENDIAN_H */ 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_FCNTL_H 1 18 | 19 | /* Define to 1 if you have the `getpid' function. */ 20 | #define HAVE_GETPID 1 21 | 22 | /* Define to 1 if you have the `gettimeofday' function. */ 23 | #define HAVE_GETTIMEOFDAY 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_INTTYPES_H 1 27 | 28 | /* Define to 1 if you have the `localeconv' function. */ 29 | #define HAVE_LOCALECONV 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_LOCALE_H 1 33 | 34 | /* Define to 1 if the system has the type `long long int'. */ 35 | #define HAVE_LONG_LONG_INT 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_MEMORY_H 1 39 | 40 | /* Define to 1 if you have the `open' function. */ 41 | #define HAVE_OPEN 1 42 | 43 | /* Define to 1 if you have the `read' function. */ 44 | #define HAVE_READ 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_SCHED_H 1 48 | 49 | /* Define to 1 if you have the `sched_yield' function. */ 50 | /* #undef HAVE_SCHED_YIELD */ 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_STDINT_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_STDLIB_H 1 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #define HAVE_STRINGS_H 1 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #define HAVE_STRING_H 1 63 | 64 | /* Define to 1 if you have the `strtoll' function. */ 65 | #define HAVE_STRTOLL 1 66 | 67 | /* Define to 1 if gcc's __sync builtins are available */ 68 | #define HAVE_SYNC_BUILTINS 1 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #define HAVE_SYS_PARAM_H 1 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_SYS_STAT_H 1 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #define HAVE_SYS_TIME_H 1 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #define HAVE_SYS_TYPES_H 1 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #define HAVE_UNISTD_H 1 84 | 85 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 86 | */ 87 | #define LT_OBJDIR ".libs/" 88 | 89 | /* Name of package */ 90 | #define PACKAGE "jansson" 91 | 92 | /* Define to the address where bug reports for this package should be sent. */ 93 | #define PACKAGE_BUGREPORT "petri@digip.org" 94 | 95 | /* Define to the full name of this package. */ 96 | #define PACKAGE_NAME "jansson" 97 | 98 | /* Define to the full name and version of this package. */ 99 | #define PACKAGE_STRING "jansson 2.6" 100 | 101 | /* Define to the one symbol short name of this package. */ 102 | #define PACKAGE_TARNAME "jansson" 103 | 104 | /* Define to the home page for this package. */ 105 | #define PACKAGE_URL "" 106 | 107 | /* Define to the version of this package. */ 108 | #define PACKAGE_VERSION "2.6" 109 | 110 | /* Define to 1 if you have the ANSI C header files. */ 111 | #define STDC_HEADERS 1 112 | 113 | /* Define to 1 if /dev/urandom should be used for seeding the hash function */ 114 | #define USE_URANDOM 1 115 | 116 | /* Define to 1 if CryptGenRandom should be used for seeding the hash function 117 | */ 118 | #define USE_WINDOWS_CRYPTOAPI 1 119 | 120 | /* Version number of package */ 121 | #define VERSION "2.6" 122 | 123 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 124 | , or is not used. If the typedef were allowed, the 125 | #define below would cause a syntax error. */ 126 | /* #undef _UINT32_T */ 127 | 128 | /* Define to `__inline__' or `__inline' if that's what the C compiler 129 | calls it, or to nothing if 'inline' is not supported under any name. */ 130 | #ifndef __cplusplus 131 | /* #undef inline */ 132 | #endif 133 | 134 | /* Define to the type of a signed integer type of width exactly 32 bits if 135 | such a type exists and the standard includes do not define it. */ 136 | /* #undef int32_t */ 137 | 138 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 139 | such a type exists and the standard includes do not define it. */ 140 | /* #undef uint32_t */ 141 | -------------------------------------------------------------------------------- /compat/jansson/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * Copyright (c) 2011-2012 Basile Starynkevitch 4 | * 5 | * Jansson is free software; you can redistribute it and/or modify it 6 | * under the terms of the MIT license. See LICENSE for details. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include "jansson.h" 13 | #include "jansson_private.h" 14 | 15 | /* memory function pointers */ 16 | static json_malloc_t do_malloc = malloc; 17 | static json_free_t do_free = free; 18 | 19 | void *jsonp_malloc(size_t size) 20 | { 21 | if(!size) 22 | return NULL; 23 | 24 | return (*do_malloc)(size); 25 | } 26 | 27 | void jsonp_free(void *ptr) 28 | { 29 | if(!ptr) 30 | return; 31 | 32 | (*do_free)(ptr); 33 | } 34 | 35 | char *jsonp_strdup(const char *str) 36 | { 37 | char *new_str; 38 | size_t len; 39 | 40 | len = strlen(str); 41 | if(len == (size_t)-1) 42 | return NULL; 43 | 44 | new_str = jsonp_malloc(len + 1); 45 | if(!new_str) 46 | return NULL; 47 | 48 | memcpy(new_str, str, len + 1); 49 | return new_str; 50 | } 51 | 52 | void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn) 53 | { 54 | do_malloc = malloc_fn; 55 | do_free = free_fn; 56 | } 57 | -------------------------------------------------------------------------------- /compat/jansson/strbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 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 _GNU_SOURCE 9 | #define _GNU_SOURCE 10 | #endif 11 | 12 | #include 13 | #include 14 | #include "jansson_private.h" 15 | #include "strbuffer.h" 16 | 17 | #define STRBUFFER_MIN_SIZE 16 18 | #define STRBUFFER_FACTOR 2 19 | #define STRBUFFER_SIZE_MAX ((size_t)-1) 20 | 21 | int strbuffer_init(strbuffer_t *strbuff) 22 | { 23 | strbuff->size = STRBUFFER_MIN_SIZE; 24 | strbuff->length = 0; 25 | 26 | strbuff->value = jsonp_malloc(strbuff->size); 27 | if(!strbuff->value) 28 | return -1; 29 | 30 | /* initialize to empty */ 31 | strbuff->value[0] = '\0'; 32 | return 0; 33 | } 34 | 35 | void strbuffer_close(strbuffer_t *strbuff) 36 | { 37 | if(strbuff->value) 38 | jsonp_free(strbuff->value); 39 | 40 | strbuff->size = 0; 41 | strbuff->length = 0; 42 | strbuff->value = NULL; 43 | } 44 | 45 | void strbuffer_clear(strbuffer_t *strbuff) 46 | { 47 | strbuff->length = 0; 48 | strbuff->value[0] = '\0'; 49 | } 50 | 51 | const char *strbuffer_value(const strbuffer_t *strbuff) 52 | { 53 | return strbuff->value; 54 | } 55 | 56 | char *strbuffer_steal_value(strbuffer_t *strbuff) 57 | { 58 | char *result = strbuff->value; 59 | strbuff->value = NULL; 60 | return result; 61 | } 62 | 63 | int strbuffer_append(strbuffer_t *strbuff, const char *string) 64 | { 65 | return strbuffer_append_bytes(strbuff, string, strlen(string)); 66 | } 67 | 68 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte) 69 | { 70 | return strbuffer_append_bytes(strbuff, &byte, 1); 71 | } 72 | 73 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size) 74 | { 75 | if(size >= strbuff->size - strbuff->length) 76 | { 77 | size_t new_size; 78 | char *new_value; 79 | 80 | /* avoid integer overflow */ 81 | if (strbuff->size > STRBUFFER_SIZE_MAX / STRBUFFER_FACTOR 82 | || size > STRBUFFER_SIZE_MAX - 1 83 | || strbuff->length > STRBUFFER_SIZE_MAX - 1 - size) 84 | return -1; 85 | 86 | new_size = max(strbuff->size * STRBUFFER_FACTOR, 87 | strbuff->length + size + 1); 88 | 89 | new_value = jsonp_malloc(new_size); 90 | if(!new_value) 91 | return -1; 92 | 93 | memcpy(new_value, strbuff->value, strbuff->length); 94 | 95 | jsonp_free(strbuff->value); 96 | strbuff->value = new_value; 97 | strbuff->size = new_size; 98 | } 99 | 100 | memcpy(strbuff->value + strbuff->length, data, size); 101 | strbuff->length += size; 102 | strbuff->value[strbuff->length] = '\0'; 103 | 104 | return 0; 105 | } 106 | 107 | char strbuffer_pop(strbuffer_t *strbuff) 108 | { 109 | if(strbuff->length > 0) { 110 | char c = strbuff->value[--strbuff->length]; 111 | strbuff->value[strbuff->length] = '\0'; 112 | return c; 113 | } 114 | else 115 | return '\0'; 116 | } 117 | -------------------------------------------------------------------------------- /compat/jansson/strbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 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 | size_t length; /* bytes used */ 14 | size_t 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 | 24 | /* Steal the value and close the strbuffer */ 25 | char *strbuffer_steal_value(strbuffer_t *strbuff); 26 | 27 | int strbuffer_append(strbuffer_t *strbuff, const char *string); 28 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte); 29 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size); 30 | 31 | char strbuffer_pop(strbuffer_t *strbuff); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /compat/jansson/strconv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "jansson_private.h" 6 | #include "strbuffer.h" 7 | 8 | /* need jansson_private_config.h to get the correct snprintf */ 9 | #ifdef HAVE_CONFIG_H 10 | #include "jansson_private_config.h" 11 | #endif 12 | 13 | #if JSON_HAVE_LOCALECONV 14 | #include 15 | 16 | /* 17 | - This code assumes that the decimal separator is exactly one 18 | character. 19 | 20 | - If setlocale() is called by another thread between the call to 21 | localeconv() and the call to sprintf() or strtod(), the result may 22 | be wrong. setlocale() is not thread-safe and should not be used 23 | this way. Multi-threaded programs should use uselocale() instead. 24 | */ 25 | 26 | static void to_locale(strbuffer_t *strbuffer) 27 | { 28 | const char *point; 29 | char *pos; 30 | 31 | point = localeconv()->decimal_point; 32 | if(*point == '.') { 33 | /* No conversion needed */ 34 | return; 35 | } 36 | 37 | pos = strchr(strbuffer->value, '.'); 38 | if(pos) 39 | *pos = *point; 40 | } 41 | 42 | static void from_locale(char *buffer) 43 | { 44 | const char *point; 45 | char *pos; 46 | 47 | point = localeconv()->decimal_point; 48 | if(*point == '.') { 49 | /* No conversion needed */ 50 | return; 51 | } 52 | 53 | pos = strchr(buffer, *point); 54 | if(pos) 55 | *pos = '.'; 56 | } 57 | #endif 58 | 59 | int jsonp_strtod(strbuffer_t *strbuffer, double *out) 60 | { 61 | double value; 62 | char *end; 63 | 64 | #if JSON_HAVE_LOCALECONV 65 | to_locale(strbuffer); 66 | #endif 67 | 68 | errno = 0; 69 | value = strtod(strbuffer->value, &end); 70 | assert(end == strbuffer->value + strbuffer->length); 71 | 72 | if(errno == ERANGE && value != 0) { 73 | /* Overflow */ 74 | return -1; 75 | } 76 | 77 | *out = value; 78 | return 0; 79 | } 80 | 81 | int jsonp_dtostr(char *buffer, size_t size, double value) 82 | { 83 | int ret; 84 | char *start, *end; 85 | size_t length; 86 | 87 | ret = snprintf(buffer, size, "%.17g", value); 88 | if(ret < 0) 89 | return -1; 90 | 91 | length = (size_t)ret; 92 | if(length >= size) 93 | return -1; 94 | 95 | #if JSON_HAVE_LOCALECONV 96 | from_locale(buffer); 97 | #endif 98 | 99 | /* Make sure there's a dot or 'e' in the output. Otherwise 100 | a real is converted to an integer when decoding */ 101 | if(strchr(buffer, '.') == NULL && 102 | strchr(buffer, 'e') == NULL) 103 | { 104 | if(length + 3 >= size) { 105 | /* No space to append ".0" */ 106 | return -1; 107 | } 108 | buffer[length] = '.'; 109 | buffer[length + 1] = '0'; 110 | buffer[length + 2] = '\0'; 111 | length += 2; 112 | } 113 | 114 | /* Remove leading '+' from positive exponent. Also remove leading 115 | zeros from exponents (added by some printf() implementations) */ 116 | start = strchr(buffer, 'e'); 117 | if(start) { 118 | start++; 119 | end = start + 1; 120 | 121 | if(*start == '-') 122 | start++; 123 | 124 | while(*end == '0') 125 | end++; 126 | 127 | if(end != start) { 128 | memmove(start, end, length - (size_t)(end - buffer)); 129 | length -= (size_t)(end - start); 130 | } 131 | } 132 | 133 | return (int)length; 134 | } 135 | -------------------------------------------------------------------------------- /compat/jansson/utf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 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 | -------------------------------------------------------------------------------- /compat/jansson/utf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 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 | #ifdef HAVE_CONFIG_H 12 | #include "jansson_private_config.h" 13 | 14 | #ifdef HAVE_INTTYPES_H 15 | /* inttypes.h includes stdint.h in a standard environment, so there's 16 | no need to include stdint.h separately. If inttypes.h doesn't define 17 | int32_t, it's defined in config.h. */ 18 | #include 19 | #endif /* HAVE_INTTYPES_H */ 20 | 21 | #else /* !HAVE_CONFIG_H */ 22 | #ifdef _WIN32 23 | typedef int int32_t; 24 | #else /* !_WIN32 */ 25 | /* Assume a standard environment */ 26 | #include 27 | #endif /* _WIN32 */ 28 | 29 | #endif /* HAVE_CONFIG_H */ 30 | 31 | int utf8_encode(int codepoint, char *buffer, int *size); 32 | 33 | int utf8_check_first(char byte); 34 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint); 35 | const char *utf8_iterate(const char *buffer, int32_t *codepoint); 36 | 37 | int utf8_check_string(const char *string, int length); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /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 | #ifndef max 12 | #define max(a, b) ((a) > (b) ? (a) : (b)) 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /compat/libs/x64/libcrypto.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KlausT/ccminer-cryptonight/ce20e2b3b964410019e72c246a4a009a16095016/compat/libs/x64/libcrypto.lib -------------------------------------------------------------------------------- /compat/libs/x64/libcurl.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KlausT/ccminer-cryptonight/ce20e2b3b964410019e72c246a4a009a16095016/compat/libs/x64/libcurl.lib -------------------------------------------------------------------------------- /compat/libs/x64/pthreadVC2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KlausT/ccminer-cryptonight/ce20e2b3b964410019e72c246a4a009a16095016/compat/libs/x64/pthreadVC2.lib -------------------------------------------------------------------------------- /compat/libs/x64/zlibstat.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KlausT/ccminer-cryptonight/ce20e2b3b964410019e72c246a4a009a16095016/compat/libs/x64/zlibstat.lib -------------------------------------------------------------------------------- /compat/libs/x86/libcrypto.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KlausT/ccminer-cryptonight/ce20e2b3b964410019e72c246a4a009a16095016/compat/libs/x86/libcrypto.lib -------------------------------------------------------------------------------- /compat/libs/x86/libcurl.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KlausT/ccminer-cryptonight/ce20e2b3b964410019e72c246a4a009a16095016/compat/libs/x86/libcurl.lib -------------------------------------------------------------------------------- /compat/libs/x86/pthreadVC2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KlausT/ccminer-cryptonight/ce20e2b3b964410019e72c246a4a009a16095016/compat/libs/x86/pthreadVC2.lib -------------------------------------------------------------------------------- /compat/libs/x86/zlibstat.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KlausT/ccminer-cryptonight/ce20e2b3b964410019e72c246a4a009a16095016/compat/libs/x86/zlibstat.lib -------------------------------------------------------------------------------- /compat/stdbool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define false 0 4 | #define true 1 5 | 6 | #define bool int 7 | -------------------------------------------------------------------------------- /compat/sys/time.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifdef __cplusplus 3 | extern "C" 4 | { 5 | #endif 6 | int gettimeofday(struct timeval *tv, struct timezone *tz); 7 | void usleep(__int64 usec); 8 | #ifdef __cplusplus 9 | } 10 | #endif 11 | typedef __int64 useconds_t; 12 | -------------------------------------------------------------------------------- /compat/unistd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "getopt/getopt.h" -------------------------------------------------------------------------------- /compile: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for compilers which do not understand '-c -o'. 3 | 4 | scriptversion=2012-01-04.17; # UTC 5 | 6 | # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free 7 | # Software Foundation, Inc. 8 | # Written by Tom Tromey . 9 | # 10 | # This program is free software; you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation; either version 2, or (at your option) 13 | # any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | # This file is maintained in Automake, please report 29 | # bugs to or send patches to 30 | # . 31 | 32 | nl=' 33 | ' 34 | 35 | # We need space, tab and new line, in precisely that order. Quoting is 36 | # there to prevent tools from complaining about whitespace usage. 37 | IFS=" "" $nl" 38 | 39 | file_conv= 40 | 41 | # func_file_conv build_file lazy 42 | # Convert a $build file to $host form and store it in $file 43 | # Currently only supports Windows hosts. If the determined conversion 44 | # type is listed in (the comma separated) LAZY, no conversion will 45 | # take place. 46 | func_file_conv () 47 | { 48 | file=$1 49 | case $file in 50 | / | /[!/]*) # absolute file, and not a UNC file 51 | if test -z "$file_conv"; then 52 | # lazily determine how to convert abs files 53 | case `uname -s` in 54 | MINGW*) 55 | file_conv=mingw 56 | ;; 57 | CYGWIN*) 58 | file_conv=cygwin 59 | ;; 60 | *) 61 | file_conv=wine 62 | ;; 63 | esac 64 | fi 65 | case $file_conv/,$2, in 66 | *,$file_conv,*) 67 | ;; 68 | mingw/*) 69 | file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 70 | ;; 71 | cygwin/*) 72 | file=`cygpath -m "$file" || echo "$file"` 73 | ;; 74 | wine/*) 75 | file=`winepath -w "$file" || echo "$file"` 76 | ;; 77 | esac 78 | ;; 79 | esac 80 | } 81 | 82 | # func_cl_wrapper cl arg... 83 | # Adjust compile command to suit cl 84 | func_cl_wrapper () 85 | { 86 | # Assume a capable shell 87 | lib_path= 88 | shared=: 89 | linker_opts= 90 | for arg 91 | do 92 | if test -n "$eat"; then 93 | eat= 94 | else 95 | case $1 in 96 | -o) 97 | # configure might choose to run compile as 'compile cc -o foo foo.c'. 98 | eat=1 99 | case $2 in 100 | *.o | *.[oO][bB][jJ]) 101 | func_file_conv "$2" 102 | set x "$@" -Fo"$file" 103 | shift 104 | ;; 105 | *) 106 | func_file_conv "$2" 107 | set x "$@" -Fe"$file" 108 | shift 109 | ;; 110 | esac 111 | ;; 112 | -I*) 113 | func_file_conv "${1#-I}" mingw 114 | set x "$@" -I"$file" 115 | shift 116 | ;; 117 | -l*) 118 | lib=${1#-l} 119 | found=no 120 | save_IFS=$IFS 121 | IFS=';' 122 | for dir in $lib_path $LIB 123 | do 124 | IFS=$save_IFS 125 | if $shared && test -f "$dir/$lib.dll.lib"; then 126 | found=yes 127 | set x "$@" "$dir/$lib.dll.lib" 128 | break 129 | fi 130 | if test -f "$dir/$lib.lib"; then 131 | found=yes 132 | set x "$@" "$dir/$lib.lib" 133 | break 134 | fi 135 | done 136 | IFS=$save_IFS 137 | 138 | test "$found" != yes && set x "$@" "$lib.lib" 139 | shift 140 | ;; 141 | -L*) 142 | func_file_conv "${1#-L}" 143 | if test -z "$lib_path"; then 144 | lib_path=$file 145 | else 146 | lib_path="$lib_path;$file" 147 | fi 148 | linker_opts="$linker_opts -LIBPATH:$file" 149 | ;; 150 | -static) 151 | shared=false 152 | ;; 153 | -Wl,*) 154 | arg=${1#-Wl,} 155 | save_ifs="$IFS"; IFS=',' 156 | for flag in $arg; do 157 | IFS="$save_ifs" 158 | linker_opts="$linker_opts $flag" 159 | done 160 | IFS="$save_ifs" 161 | ;; 162 | -Xlinker) 163 | eat=1 164 | linker_opts="$linker_opts $2" 165 | ;; 166 | -*) 167 | set x "$@" "$1" 168 | shift 169 | ;; 170 | *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 171 | func_file_conv "$1" 172 | set x "$@" -Tp"$file" 173 | shift 174 | ;; 175 | *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 176 | func_file_conv "$1" mingw 177 | set x "$@" "$file" 178 | shift 179 | ;; 180 | *) 181 | set x "$@" "$1" 182 | shift 183 | ;; 184 | esac 185 | fi 186 | shift 187 | done 188 | if test -n "$linker_opts"; then 189 | linker_opts="-link$linker_opts" 190 | fi 191 | exec "$@" $linker_opts 192 | exit 1 193 | } 194 | 195 | eat= 196 | 197 | case $1 in 198 | '') 199 | echo "$0: No command. Try '$0 --help' for more information." 1>&2 200 | exit 1; 201 | ;; 202 | -h | --h*) 203 | cat <<\EOF 204 | Usage: compile [--help] [--version] PROGRAM [ARGS] 205 | 206 | Wrapper for compilers which do not understand '-c -o'. 207 | Remove '-o dest.o' from ARGS, run PROGRAM with the remaining 208 | arguments, and rename the output as expected. 209 | 210 | If you are trying to build a whole package this is not the 211 | right script to run: please start by reading the file 'INSTALL'. 212 | 213 | Report bugs to . 214 | EOF 215 | exit $? 216 | ;; 217 | -v | --v*) 218 | echo "compile $scriptversion" 219 | exit $? 220 | ;; 221 | cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 222 | func_cl_wrapper "$@" # Doesn't return... 223 | ;; 224 | esac 225 | 226 | ofile= 227 | cfile= 228 | 229 | for arg 230 | do 231 | if test -n "$eat"; then 232 | eat= 233 | else 234 | case $1 in 235 | -o) 236 | # configure might choose to run compile as 'compile cc -o foo foo.c'. 237 | # So we strip '-o arg' only if arg is an object. 238 | eat=1 239 | case $2 in 240 | *.o | *.obj) 241 | ofile=$2 242 | ;; 243 | *) 244 | set x "$@" -o "$2" 245 | shift 246 | ;; 247 | esac 248 | ;; 249 | *.c) 250 | cfile=$1 251 | set x "$@" "$1" 252 | shift 253 | ;; 254 | *) 255 | set x "$@" "$1" 256 | shift 257 | ;; 258 | esac 259 | fi 260 | shift 261 | done 262 | 263 | if test -z "$ofile" || test -z "$cfile"; then 264 | # If no '-o' option was seen then we might have been invoked from a 265 | # pattern rule where we don't need one. That is ok -- this is a 266 | # normal compilation that the losing compiler can handle. If no 267 | # '.c' file was seen then we are probably linking. That is also 268 | # ok. 269 | exec "$@" 270 | fi 271 | 272 | # Name of file we expect compiler to create. 273 | cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 274 | 275 | # Create the lock directory. 276 | # Note: use '[/\\:.-]' here to ensure that we don't use the same name 277 | # that we are using for the .o file. Also, base the name on the expected 278 | # object file name, since that is what matters with a parallel build. 279 | lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 280 | while true; do 281 | if mkdir "$lockdir" >/dev/null 2>&1; then 282 | break 283 | fi 284 | sleep 1 285 | done 286 | # FIXME: race condition here if user kills between mkdir and trap. 287 | trap "rmdir '$lockdir'; exit 1" 1 2 15 288 | 289 | # Run the compile. 290 | "$@" 291 | ret=$? 292 | 293 | if test -f "$cofile"; then 294 | test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 295 | elif test -f "${cofile}bj"; then 296 | test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 297 | fi 298 | 299 | rmdir "$lockdir" 300 | exit $ret 301 | 302 | # Local Variables: 303 | # mode: shell-script 304 | # sh-indentation: 2 305 | # eval: (add-hook 'write-file-hooks 'time-stamp) 306 | # time-stamp-start: "scriptversion=" 307 | # time-stamp-format: "%:y-%02m-%02d.%02H" 308 | # time-stamp-time-zone: "UTC" 309 | # time-stamp-end: "; # UTC" 310 | # End: 311 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([ccminer-cryptonight], [3.06]) 2 | 3 | AC_PREREQ([2.59c]) 4 | AC_CANONICAL_SYSTEM 5 | AC_CONFIG_SRCDIR([cpu-miner.cpp]) 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 | AC_PROG_CXX 19 | AC_OPENMP 20 | 21 | dnl Checks for header files 22 | AC_HEADER_STDC 23 | AC_CHECK_HEADERS([sys/endian.h sys/param.h syslog.h]) 24 | # sys/sysctl.h requires sys/types.h on FreeBSD 25 | # sys/sysctl.h requires sys/param.h on OpenBSD 26 | AC_CHECK_HEADERS([sys/sysctl.h], [], [], 27 | [#include 28 | #ifdef HAVE_SYS_PARAM_H 29 | #include 30 | #endif 31 | ]) 32 | 33 | AC_CHECK_DECLS([be32dec, le32dec, be32enc, le32enc], [], [], 34 | [AC_INCLUDES_DEFAULT 35 | #ifdef HAVE_SYS_ENDIAN_H 36 | #include 37 | #endif 38 | ]) 39 | 40 | AC_FUNC_ALLOCA 41 | AC_CHECK_FUNCS([getopt_long]) 42 | 43 | case $target in 44 | i*86-*-*) 45 | have_x86=true 46 | ;; 47 | x86_64-*-*) 48 | have_x86=true 49 | have_x86_64=true 50 | ;; 51 | amd64-*-*) 52 | have_x86=true 53 | have_x86_64=true 54 | ;; 55 | esac 56 | 57 | PTHREAD_FLAGS="-pthread" 58 | WS2_LIBS="" 59 | 60 | case $target in 61 | *-*-mingw*) 62 | have_win32=true 63 | PTHREAD_FLAGS="" 64 | WS2_LIBS="-lws2_32" 65 | ;; 66 | esac 67 | 68 | if test x$have_x86 = xtrue 69 | then 70 | AC_MSG_CHECKING(whether we can compile AVX code) 71 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("vmovdqa %ymm0, %ymm1");])], 72 | AC_DEFINE(USE_AVX, 1, [Define to 1 if AVX assembly is available.]) 73 | AC_MSG_RESULT(yes) 74 | AC_MSG_CHECKING(whether we can compile XOP code) 75 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("vprotd \$7, %xmm0, %xmm1");])], 76 | AC_DEFINE(USE_XOP, 1, [Define to 1 if XOP assembly is available.]) 77 | AC_MSG_RESULT(yes) 78 | , 79 | AC_MSG_RESULT(no) 80 | AC_MSG_WARN([The assembler does not support the XOP instruction set.]) 81 | ) 82 | AC_MSG_CHECKING(whether we can compile AVX2 code) 83 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("vpaddd %ymm0, %ymm1, %ymm2");])], 84 | AC_DEFINE(USE_AVX2, 1, [Define to 1 if AVX2 assembly is available.]) 85 | AC_MSG_RESULT(yes) 86 | , 87 | AC_MSG_RESULT(no) 88 | AC_MSG_WARN([The assembler does not support the AVX2 instruction set.]) 89 | ) 90 | , 91 | AC_MSG_RESULT(no) 92 | AC_MSG_WARN([The assembler does not support the AVX instruction set.]) 93 | ) 94 | fi 95 | 96 | AC_CHECK_LIB(jansson, json_loads, request_jansson=false, request_jansson=true) 97 | AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS="-lpthread", 98 | AC_CHECK_LIB([pthreadGC2], [pthread_create], PTHREAD_LIBS="-lpthreadGC2", 99 | AC_CHECK_LIB([pthreadGC1], [pthread_create], PTHREAD_LIBS="-lpthreadGC1", 100 | AC_CHECK_LIB([pthreadGC], [pthread_create], PTHREAD_LIBS="-lpthreadGC" 101 | )))) 102 | 103 | AC_CHECK_LIB([ssl],[SSL_library_init], [], [AC_MSG_ERROR([OpenSSL library required])]) 104 | AC_CHECK_LIB([crypto],[EVP_DigestFinal_ex], [], [AC_MSG_ERROR([OpenSSL library required])]) 105 | 106 | AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue]) 107 | AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue]) 108 | AM_CONDITIONAL([ARCH_x86], [test x$have_x86 = xtrue]) 109 | AM_CONDITIONAL([ARCH_x86_64], [test x$have_x86_64 = xtrue]) 110 | 111 | if test x$request_jansson = xtrue 112 | then 113 | JANSSON_LIBS="compat/jansson/libjansson.a" 114 | else 115 | JANSSON_LIBS=-ljansson 116 | fi 117 | 118 | LIBCURL_CHECK_CONFIG(, 7.15.2, , 119 | [AC_MSG_ERROR([Missing required libcurl >= 7.15.2])]) 120 | 121 | AC_SUBST(JANSSON_LIBS) 122 | AC_SUBST(PTHREAD_FLAGS) 123 | AC_SUBST(PTHREAD_LIBS) 124 | AC_SUBST(WS2_LIBS) 125 | 126 | AC_CONFIG_FILES([ 127 | Makefile 128 | compat/Makefile 129 | compat/jansson/Makefile 130 | ]) 131 | 132 | dnl find out what version we are running 133 | ARCH=`uname -m` 134 | if [[ $ARCH == "x86_64" ]]; 135 | then 136 | SUFFIX="64" 137 | else 138 | SUFFIX="" 139 | fi 140 | 141 | dnl Setup CUDA paths 142 | AC_ARG_WITH([cuda], 143 | [ --with-cuda=PATH prefix where cuda is installed [default=/usr/local/cuda]]) 144 | 145 | if test -n "$with_cuda" 146 | then 147 | CUDA_CFLAGS="-I$with_cuda/include" 148 | CUDA_LIBS="-lcudart" 149 | CUDA_LDFLAGS="-L$with_cuda/lib$SUFFIX" 150 | NVCC="$with_cuda/bin/nvcc" 151 | else 152 | CUDA_CFLAGS="-I/usr/local/cuda/include" 153 | CUDA_LIBS="-lcudart -static-libstdc++" 154 | CUDA_LDFLAGS="-L/usr/local/cuda/lib$SUFFIX" 155 | NVCC="nvcc" 156 | fi 157 | AC_SUBST(CUDA_CFLAGS) 158 | AC_SUBST(CUDA_LIBS) 159 | AC_SUBST(CUDA_LDFLAGS) 160 | AC_SUBST(NVCC) 161 | 162 | AC_SUBST(OPENMP_CFLAGS) 163 | 164 | AC_OUTPUT 165 | -------------------------------------------------------------------------------- /configure.sh: -------------------------------------------------------------------------------- 1 | ./configure "CFLAGS=-O3" "CXXFLAGS=-O3" --with-cuda=/usr/local/cuda 2 | -------------------------------------------------------------------------------- /cpuminer-config-win.h: -------------------------------------------------------------------------------- 1 | #undef CRAY_STACKSEG_END 2 | 3 | /* Define to 1 if using `alloca.c'. */ 4 | #undef C_ALLOCA 5 | 6 | /* Define to 1 if you have `alloca', as a function or macro. */ 7 | #undef HAVE_ALLOCA 8 | 9 | /* Define to 1 if you have and it should be used (not on Ultrix). 10 | */ 11 | #undef HAVE_ALLOCA_H 12 | 13 | /* Define to 1 if you have the declaration of `be32dec', and to 0 if you 14 | don't. */ 15 | #undef HAVE_DECL_BE32DEC 16 | 17 | /* Define to 1 if you have the declaration of `be32enc', and to 0 if you 18 | don't. */ 19 | #undef HAVE_DECL_BE32ENC 20 | 21 | /* Define to 1 if you have the declaration of `le32dec', and to 0 if you 22 | don't. */ 23 | #undef HAVE_DECL_LE32DEC 24 | 25 | /* Define to 1 if you have the declaration of `le32enc', and to 0 if you 26 | don't. */ 27 | #undef HAVE_DECL_LE32ENC 28 | 29 | /* Define to 1 if you have the `getopt_long' function. */ 30 | #define HAVE_GETOPT_LONG 1 31 | 32 | /* Define to 1 if you have the header file. */ 33 | #undef HAVE_INTTYPES_H 34 | 35 | /* Define to 1 if you have a functional curl library. */ 36 | #define HAVE_LIBCURL 1 37 | 38 | /* Define to 1 if you have the header file. */ 39 | #define HAVE_MEMORY_H 1 40 | 41 | /* Define to 1 if you have the header file. */ 42 | #define HAVE_STDINT_H 1 43 | 44 | /* Define to 1 if you have the header file. */ 45 | #define HAVE_STDLIB_H 1 46 | 47 | /* Define to 1 if you have the header file. */ 48 | #undef HAVE_STRINGS_H 49 | 50 | /* Define to 1 if you have the header file. */ 51 | #undef HAVE_STRING_H 52 | 53 | /* Define to 1 if you have the header file. */ 54 | #undef HAVE_SYSLOG_H 55 | 56 | /* Define to 1 if you have the header file. */ 57 | #undef HAVE_SYS_ENDIAN_H 58 | 59 | /* Define to 1 if you have the header file. */ 60 | #undef HAVE_SYS_PARAM_H 61 | 62 | /* Define to 1 if you have the header file. */ 63 | #undef HAVE_SYS_STAT_H 64 | 65 | /* Define to 1 if you have the header file. */ 66 | #undef HAVE_SYS_SYSCTL_H 67 | 68 | /* Define to 1 if you have the header file. */ 69 | #undef HAVE_SYS_TYPES_H 70 | 71 | /* Define to 1 if you have the header file. */ 72 | #undef HAVE_UNISTD_H 73 | 74 | /* Defined if libcurl supports AsynchDNS */ 75 | #define LIBCURL_FEATURE_ASYNCHDNS 1 76 | 77 | /* Defined if libcurl supports IDN */ 78 | #define LIBCURL_FEATURE_IDN 1 79 | 80 | /* Defined if libcurl supports IPv6 */ 81 | #define LIBCURL_FEATURE_IPV6 1 82 | 83 | /* Defined if libcurl supports KRB4 */ 84 | #undef LIBCURL_FEATURE_KRB4 85 | 86 | /* Defined if libcurl supports libz */ 87 | #undef LIBCURL_FEATURE_LIBZ 88 | 89 | /* Defined if libcurl supports NTLM */ 90 | #undef LIBCURL_FEATURE_NTLM 91 | 92 | /* Defined if libcurl supports SSL */ 93 | #define LIBCURL_FEATURE_SSL 1 94 | 95 | /* Defined if libcurl supports SSPI */ 96 | #undef LIBCURL_FEATURE_SSPI 97 | 98 | /* Defined if libcurl supports DICT */ 99 | #undef LIBCURL_PROTOCOL_DICT 100 | 101 | /* Defined if libcurl supports FILE */ 102 | #undef LIBCURL_PROTOCOL_FILE 103 | 104 | /* Defined if libcurl supports FTP */ 105 | #undef LIBCURL_PROTOCOL_FTP 106 | 107 | /* Defined if libcurl supports FTPS */ 108 | #undef LIBCURL_PROTOCOL_FTPS 109 | 110 | /* Defined if libcurl supports HTTP */ 111 | #define LIBCURL_PROTOCOL_HTTP 1 112 | 113 | /* Defined if libcurl supports HTTPS */ 114 | #define LIBCURL_PROTOCOL_HTTPS 1 115 | 116 | /* Defined if libcurl supports IMAP */ 117 | #undef LIBCURL_PROTOCOL_IMAP 118 | 119 | /* Defined if libcurl supports LDAP */ 120 | #undef LIBCURL_PROTOCOL_LDAP 121 | 122 | /* Defined if libcurl supports POP3 */ 123 | #undef LIBCURL_PROTOCOL_POP3 124 | 125 | /* Defined if libcurl supports RTSP */ 126 | #undef LIBCURL_PROTOCOL_RTSP 127 | 128 | /* Defined if libcurl supports SMTP */ 129 | #undef LIBCURL_PROTOCOL_SMTP 130 | 131 | /* Defined if libcurl supports TELNET */ 132 | #undef LIBCURL_PROTOCOL_TELNET 133 | 134 | /* Defined if libcurl supports TFTP */ 135 | #undef LIBCURL_PROTOCOL_TFTP 136 | 137 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 138 | #undef NO_MINUS_C_MINUS_O 139 | 140 | /* Name of package */ 141 | #undef PACKAGE 142 | 143 | /* Define to the address where bug reports for this package should be sent. */ 144 | #undef PACKAGE_BUGREPORT 145 | 146 | /* Define to the full name of this package. */ 147 | #define PACKAGE_NAME "ccminer-cryptonight" 148 | 149 | /* Define to the full name and version of this package. */ 150 | #define PACKAGE_STRING "ccminer-cryptonight 3.06" 151 | 152 | /* Define to the one symbol short name of this package. */ 153 | #undef PACKAGE_TARNAME 154 | 155 | /* Define to the home page for this package. */ 156 | #undef PACKAGE_URL 157 | 158 | /* Define to the version of this package. */ 159 | #define PACKAGE_VERSION "3.06" 160 | 161 | /* Version number of package */ 162 | #undef VERSION 163 | 164 | /* If using the C implementation of alloca, define if you know the 165 | direction of stack growth for your system; otherwise it will be 166 | automatically deduced at runtime. 167 | STACK_DIRECTION > 0 => grows toward higher addresses 168 | STACK_DIRECTION < 0 => grows toward lower addresses 169 | STACK_DIRECTION = 0 => direction of growth unknown */ 170 | #undef STACK_DIRECTION 171 | 172 | /* Define to 1 if you have the ANSI C header files. */ 173 | #define STDC_HEADERS 1 174 | 175 | /* Define to 1 if AVX assembly is available. */ 176 | #undef USE_AVX 177 | 178 | /* Define to 1 if XOP assembly is available. */ 179 | #undef USE_XOP 180 | 181 | /* Define curl_free() as free() if our version of curl lacks curl_free. */ 182 | #undef curl_free 183 | 184 | /* Define to `unsigned int' if does not define. */ 185 | /*#undef size_t*/ 186 | -------------------------------------------------------------------------------- /crypto/aesb.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | */ 20 | 21 | #include 22 | 23 | #define TABLE_ALIGN 32 24 | #define WPOLY 0x011b 25 | #define N_COLS 4 26 | #define AES_BLOCK_SIZE 16 27 | #define RC_LENGTH (5 * (AES_BLOCK_SIZE / 4 - 2)) 28 | 29 | #if defined(_MSC_VER) 30 | #define ALIGN __declspec(align(TABLE_ALIGN)) 31 | #elif defined(__GNUC__) 32 | #define ALIGN __attribute__ ((aligned(16))) 33 | #else 34 | #define ALIGN 35 | #endif 36 | 37 | #define rf1(r,c) (r) 38 | #define word_in(x,c) (*((uint32_t*)(x)+(c))) 39 | #define word_out(x,c,v) (*((uint32_t*)(x)+(c)) = (v)) 40 | 41 | #define s(x,c) x[c] 42 | #define si(y,x,c) (s(y,c) = word_in(x, c)) 43 | #define so(y,x,c) word_out(y, c, s(x,c)) 44 | #define state_in(y,x) si(y,x,0); si(y,x,1); si(y,x,2); si(y,x,3) 45 | #define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3) 46 | #define round(y,x,k) \ 47 | y[0] = (k)[0] ^ (t_fn[0][x[0] & 0xff] ^ t_fn[1][(x[1] >> 8) & 0xff] ^ t_fn[2][(x[2] >> 16) & 0xff] ^ t_fn[3][x[3] >> 24]); \ 48 | y[1] = (k)[1] ^ (t_fn[0][x[1] & 0xff] ^ t_fn[1][(x[2] >> 8) & 0xff] ^ t_fn[2][(x[3] >> 16) & 0xff] ^ t_fn[3][x[0] >> 24]); \ 49 | y[2] = (k)[2] ^ (t_fn[0][x[2] & 0xff] ^ t_fn[1][(x[3] >> 8) & 0xff] ^ t_fn[2][(x[0] >> 16) & 0xff] ^ t_fn[3][x[1] >> 24]); \ 50 | y[3] = (k)[3] ^ (t_fn[0][x[3] & 0xff] ^ t_fn[1][(x[0] >> 8) & 0xff] ^ t_fn[2][(x[1] >> 16) & 0xff] ^ t_fn[3][x[2] >> 24]); 51 | #define to_byte(x) ((x) & 0xff) 52 | #define bval(x,n) to_byte((x) >> (8 * (n))) 53 | 54 | #define fwd_var(x,r,c)\ 55 | ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\ 56 | : r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\ 57 | : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\ 58 | : ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))) 59 | 60 | #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,n),fwd_var,rf1,c)) 61 | 62 | #define sb_data(w) {\ 63 | w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\ 64 | w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\ 65 | w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\ 66 | w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\ 67 | w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\ 68 | w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\ 69 | w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\ 70 | w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\ 71 | w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\ 72 | w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\ 73 | w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\ 74 | w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\ 75 | w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\ 76 | w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\ 77 | w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\ 78 | w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\ 79 | w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\ 80 | w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\ 81 | w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\ 82 | w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\ 83 | w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\ 84 | w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\ 85 | w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\ 86 | w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\ 87 | w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\ 88 | w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\ 89 | w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\ 90 | w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\ 91 | w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\ 92 | w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\ 93 | w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\ 94 | w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) } 95 | 96 | #define rc_data(w) {\ 97 | w(0x01), w(0x02), w(0x04), w(0x08), w(0x10),w(0x20), w(0x40), w(0x80),\ 98 | w(0x1b), w(0x36) } 99 | 100 | #define bytes2word(b0, b1, b2, b3) (((uint32_t)(b3) << 24) | \ 101 | ((uint32_t)(b2) << 16) | ((uint32_t)(b1) << 8) | (b0)) 102 | 103 | #define h0(x) (x) 104 | #define w0(p) bytes2word(p, 0, 0, 0) 105 | #define w1(p) bytes2word(0, p, 0, 0) 106 | #define w2(p) bytes2word(0, 0, p, 0) 107 | #define w3(p) bytes2word(0, 0, 0, p) 108 | 109 | #define u0(p) bytes2word(f2(p), p, p, f3(p)) 110 | #define u1(p) bytes2word(f3(p), f2(p), p, p) 111 | #define u2(p) bytes2word(p, f3(p), f2(p), p) 112 | #define u3(p) bytes2word(p, p, f3(p), f2(p)) 113 | 114 | #define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p)) 115 | #define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p)) 116 | #define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p)) 117 | #define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p)) 118 | 119 | #define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY)) 120 | #define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY)) 121 | #define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) ^ (((x>>5) & 4) * WPOLY)) 122 | #define f3(x) (f2(x) ^ x) 123 | #define f9(x) (f8(x) ^ x) 124 | #define fb(x) (f8(x) ^ f2(x) ^ x) 125 | #define fd(x) (f8(x) ^ f4(x) ^ x) 126 | #define fe(x) (f8(x) ^ f4(x) ^ f2(x)) 127 | 128 | #define t_dec(m,n) t_##m##n 129 | #define t_set(m,n) t_##m##n 130 | #define t_use(m,n) t_##m##n 131 | 132 | #define d_4(t,n,b,e,f,g,h) ALIGN const t n[4][256] = { b(e), b(f), b(g), b(h) } 133 | 134 | #define four_tables(x,tab,vf,rf,c) \ 135 | (tab[0][bval(vf(x,0,c),rf(0,c))] \ 136 | ^ tab[1][bval(vf(x,1,c),rf(1,c))] \ 137 | ^ tab[2][bval(vf(x,2,c),rf(2,c))] \ 138 | ^ tab[3][bval(vf(x,3,c),rf(3,c))]) 139 | 140 | d_4(uint32_t, t_dec(f,n), sb_data, u0, u1, u2, u3); 141 | 142 | void aesb_single_round(const uint8_t *in, uint8_t *out, uint8_t *expandedKey) 143 | { 144 | round(((uint32_t*) out), ((uint32_t*) in), ((uint32_t*) expandedKey)); 145 | } 146 | 147 | void aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey) 148 | { 149 | uint32_t b1[4]; 150 | round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey)); 151 | round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 1 * N_COLS); 152 | round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 2 * N_COLS); 153 | round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 3 * N_COLS); 154 | round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 4 * N_COLS); 155 | round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 5 * N_COLS); 156 | round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 6 * N_COLS); 157 | round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 7 * N_COLS); 158 | round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 8 * N_COLS); 159 | round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 9 * N_COLS); 160 | } 161 | 162 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /crypto/c_keccak.cpp: -------------------------------------------------------------------------------- 1 | // keccak.c 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | // A baseline Keccak (3rd round) implementation. 4 | 5 | #include "c_keccak.h" 6 | 7 | const uint64_t keccakf_rndc[24] = 8 | { 9 | 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 10 | 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 11 | 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 12 | 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 13 | 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 14 | 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 15 | 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 16 | 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 17 | }; 18 | 19 | const int keccakf_rotc[24] = 20 | { 21 | 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 22 | 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 23 | }; 24 | 25 | const int keccakf_piln[24] = 26 | { 27 | 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 28 | 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 29 | }; 30 | 31 | // update the state with given number of rounds 32 | 33 | void keccakf(uint64_t st[25], int rounds) 34 | { 35 | int i, j, round; 36 | uint64_t t, bc[5]; 37 | 38 | for (round = 0; round < rounds; ++round) { 39 | 40 | // Theta 41 | bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20]; 42 | bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21]; 43 | bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22]; 44 | bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23]; 45 | bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24]; 46 | 47 | for (i = 0; i < 5; ++i) { 48 | t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); 49 | st[i ] ^= t; 50 | st[i + 5] ^= t; 51 | st[i + 10] ^= t; 52 | st[i + 15] ^= t; 53 | st[i + 20] ^= t; 54 | } 55 | 56 | // Rho Pi 57 | t = st[1]; 58 | for (i = 0; i < 24; ++i) { 59 | bc[0] = st[keccakf_piln[i]]; 60 | st[keccakf_piln[i]] = ROTL64(t, keccakf_rotc[i]); 61 | t = bc[0]; 62 | } 63 | 64 | // Chi 65 | for (j = 0; j < 25; j += 5) { 66 | bc[0] = st[j ]; 67 | bc[1] = st[j + 1]; 68 | bc[2] = st[j + 2]; 69 | bc[3] = st[j + 3]; 70 | bc[4] = st[j + 4]; 71 | st[j ] ^= (~bc[1]) & bc[2]; 72 | st[j + 1] ^= (~bc[2]) & bc[3]; 73 | st[j + 2] ^= (~bc[3]) & bc[4]; 74 | st[j + 3] ^= (~bc[4]) & bc[0]; 75 | st[j + 4] ^= (~bc[0]) & bc[1]; 76 | } 77 | 78 | // Iota 79 | st[0] ^= keccakf_rndc[round]; 80 | } 81 | } 82 | 83 | // compute a keccak hash (md) of given byte length from "in" 84 | typedef uint64_t state_t[25]; 85 | 86 | int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen) 87 | { 88 | state_t st; 89 | uint8_t temp[144]; 90 | size_t i, rsiz, rsizw; 91 | 92 | rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; 93 | rsizw = rsiz / 8; 94 | 95 | memset(st, 0, sizeof(st)); 96 | 97 | for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { 98 | for (i = 0; i < rsizw; i++) 99 | st[i] ^= ((uint64_t *) in)[i]; 100 | keccakf(st, KECCAK_ROUNDS); 101 | } 102 | 103 | // last block and padding 104 | memcpy(temp, in, inlen); 105 | temp[inlen++] = 1; 106 | memset(temp + inlen, 0, rsiz - inlen); 107 | temp[rsiz - 1] |= 0x80; 108 | 109 | for (i = 0; i < rsizw; i++) 110 | st[i] ^= ((uint64_t *) temp)[i]; 111 | 112 | keccakf(st, KECCAK_ROUNDS); 113 | 114 | memcpy(md, st, mdlen); 115 | 116 | return 0; 117 | } 118 | 119 | void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md) 120 | { 121 | keccak(in, inlen, md, sizeof(state_t)); 122 | } 123 | -------------------------------------------------------------------------------- /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 | #ifndef HASH_SIZE 19 | #define HASH_SIZE 32 20 | #endif 21 | 22 | #ifndef HASH_DATA_AREA 23 | #define HASH_DATA_AREA 136 24 | #endif 25 | 26 | // compute a keccak hash (md) of given byte length from "in" 27 | int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen); 28 | 29 | // update the state 30 | void keccakf(uint64_t st[25], int norounds); 31 | 32 | void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | //#ifndef OAES_HAVE_ISAAC 35 | //#define OAES_HAVE_ISAAC 1 36 | //#endif // OAES_HAVE_ISAAC 37 | 38 | //#ifndef OAES_DEBUG 39 | //#define OAES_DEBUG 0 40 | //#endif // OAES_DEBUG 41 | //#define OAES_DEBUG 1 42 | 43 | #endif // _OAES_CONFIG_H 44 | -------------------------------------------------------------------------------- /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 | #include 36 | 37 | #ifdef _WIN32 38 | # ifdef OAES_SHARED 39 | # ifdef oaes_lib_EXPORTS 40 | # define OAES_API __declspec(dllexport) 41 | # else 42 | # define OAES_API __declspec(dllimport) 43 | # endif 44 | # else 45 | # define OAES_API 46 | # endif 47 | #else 48 | # define OAES_API 49 | #endif // WIN32 50 | 51 | #define OAES_VERSION "0.8.1" 52 | #define OAES_BLOCK_SIZE 16 53 | 54 | typedef void OAES_CTX; 55 | 56 | typedef enum 57 | { 58 | OAES_RET_FIRST = 0, 59 | OAES_RET_SUCCESS = 0, 60 | OAES_RET_UNKNOWN, 61 | OAES_RET_ARG1, 62 | OAES_RET_ARG2, 63 | OAES_RET_ARG3, 64 | OAES_RET_ARG4, 65 | OAES_RET_ARG5, 66 | OAES_RET_NOKEY, 67 | OAES_RET_MEM, 68 | OAES_RET_BUF, 69 | OAES_RET_HEADER, 70 | OAES_RET_COUNT 71 | } OAES_RET; 72 | 73 | /* 74 | * oaes_set_option() takes one of these values for its [option] parameter 75 | * some options accept either an optional or a required [value] parameter 76 | */ 77 | // no option 78 | #define OAES_OPTION_NONE 0 79 | // enable ECB mode, disable CBC mode 80 | #define OAES_OPTION_ECB 1 81 | // enable CBC mode, disable ECB mode 82 | // value is optional, may pass uint8_t iv[OAES_BLOCK_SIZE] to specify 83 | // the value of the initialization vector, iv 84 | #define OAES_OPTION_CBC 2 85 | 86 | #ifdef OAES_DEBUG 87 | typedef int ( * oaes_step_cb ) ( 88 | const uint8_t state[OAES_BLOCK_SIZE], 89 | const char * step_name, 90 | int step_count, 91 | void * user_data ); 92 | // enable state stepping mode 93 | // value is required, must pass oaes_step_cb to receive the state at each step 94 | #define OAES_OPTION_STEP_ON 4 95 | // disable state stepping mode 96 | #define OAES_OPTION_STEP_OFF 8 97 | #endif // OAES_DEBUG 98 | 99 | typedef uint16_t OAES_OPTION; 100 | 101 | typedef struct _oaes_key 102 | { 103 | size_t data_len; 104 | uint8_t *data; 105 | size_t exp_data_len; 106 | uint8_t *exp_data; 107 | size_t num_keys; 108 | size_t key_base; 109 | } oaes_key; 110 | 111 | typedef struct _oaes_ctx 112 | { 113 | #ifdef OAES_HAVE_ISAAC 114 | randctx * rctx; 115 | #endif // OAES_HAVE_ISAAC 116 | 117 | #ifdef OAES_DEBUG 118 | oaes_step_cb step_cb; 119 | #endif // OAES_DEBUG 120 | 121 | oaes_key * key; 122 | OAES_OPTION options; 123 | uint8_t iv[OAES_BLOCK_SIZE]; 124 | } oaes_ctx; 125 | /* 126 | * // usage: 127 | * 128 | * OAES_CTX * ctx = oaes_alloc(); 129 | * . 130 | * . 131 | * . 132 | * { 133 | * oaes_gen_key_xxx( ctx ); 134 | * { 135 | * oaes_key_export( ctx, _buf, &_buf_len ); 136 | * // or 137 | * oaes_key_export_data( ctx, _buf, &_buf_len );\ 138 | * } 139 | * } 140 | * // or 141 | * { 142 | * oaes_key_import( ctx, _buf, _buf_len ); 143 | * // or 144 | * oaes_key_import_data( ctx, _buf, _buf_len ); 145 | * } 146 | * . 147 | * . 148 | * . 149 | * oaes_encrypt( ctx, m, m_len, c, &c_len ); 150 | * . 151 | * . 152 | * . 153 | * oaes_decrypt( ctx, c, c_len, m, &m_len ); 154 | * . 155 | * . 156 | * . 157 | * oaes_free( &ctx ); 158 | */ 159 | 160 | OAES_API OAES_CTX * oaes_alloc(void); 161 | 162 | OAES_API OAES_RET oaes_free( OAES_CTX ** ctx ); 163 | 164 | OAES_API OAES_RET oaes_set_option( OAES_CTX * ctx, 165 | OAES_OPTION option, const void * value ); 166 | 167 | OAES_API OAES_RET oaes_key_gen_128( OAES_CTX * ctx ); 168 | 169 | OAES_API OAES_RET oaes_key_gen_192( OAES_CTX * ctx ); 170 | 171 | OAES_API OAES_RET oaes_key_gen_256( OAES_CTX * ctx ); 172 | 173 | // export key with header information 174 | // set data == NULL to get the required data_len 175 | OAES_API OAES_RET oaes_key_export( OAES_CTX * ctx, 176 | uint8_t * data, size_t * data_len ); 177 | 178 | // directly export the data from key 179 | // set data == NULL to get the required data_len 180 | OAES_API OAES_RET oaes_key_export_data( OAES_CTX * ctx, 181 | uint8_t * data, size_t * data_len ); 182 | 183 | // import key with header information 184 | OAES_API OAES_RET oaes_key_import( OAES_CTX * ctx, 185 | const uint8_t * data, size_t data_len ); 186 | 187 | // directly import data into key 188 | OAES_API OAES_RET oaes_key_import_data( OAES_CTX * ctx, 189 | const uint8_t * data, size_t data_len ); 190 | 191 | // set c == NULL to get the required c_len 192 | OAES_API OAES_RET oaes_encrypt( OAES_CTX * ctx, 193 | const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len ); 194 | 195 | // set m == NULL to get the required m_len 196 | OAES_API OAES_RET oaes_decrypt( OAES_CTX * ctx, 197 | const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len ); 198 | 199 | // set buf == NULL to get the required buf_len 200 | OAES_API OAES_RET oaes_sprintf( 201 | char * buf, size_t * buf_len, const uint8_t * data, size_t data_len ); 202 | 203 | OAES_API OAES_RET oaes_encryption_round( const uint8_t * key, uint8_t * c ); 204 | 205 | OAES_API OAES_RET oaes_pseudo_encrypt_ecb( OAES_CTX * ctx, uint8_t * c ); 206 | 207 | #endif // _OAES_LIB_H 208 | -------------------------------------------------------------------------------- /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 | #define SKEIN_NEED_SWAP (0) 68 | 69 | /* 70 | ****************************************************************** 71 | * Provide any definitions still needed. 72 | ****************************************************************** 73 | */ 74 | #ifndef Skein_Swap64 /* swap for big-endian, nop for little-endian */ 75 | #if SKEIN_NEED_SWAP 76 | #define Skein_Swap64(w64) \ 77 | ( (( ((u64b_t)(w64)) & 0xFF) << 56) | \ 78 | (((((u64b_t)(w64)) >> 8) & 0xFF) << 48) | \ 79 | (((((u64b_t)(w64)) >>16) & 0xFF) << 40) | \ 80 | (((((u64b_t)(w64)) >>24) & 0xFF) << 32) | \ 81 | (((((u64b_t)(w64)) >>32) & 0xFF) << 24) | \ 82 | (((((u64b_t)(w64)) >>40) & 0xFF) << 16) | \ 83 | (((((u64b_t)(w64)) >>48) & 0xFF) << 8) | \ 84 | (((((u64b_t)(w64)) >>56) & 0xFF) ) ) 85 | #else 86 | #define Skein_Swap64(w64) (w64) 87 | #endif 88 | #endif /* ifndef Skein_Swap64 */ 89 | 90 | 91 | #ifndef Skein_Put64_LSB_First 92 | void Skein_Put64_LSB_First(u08b_t *dst,const u64b_t *src,size_t bCnt) 93 | #ifdef SKEIN_PORT_CODE /* instantiate the function code here? */ 94 | { /* this version is fully portable (big-endian or little-endian), but slow */ 95 | size_t n; 96 | 97 | for (n=0;n>3] >> (8*(n&7))); 99 | } 100 | #else 101 | ; /* output only the function prototype */ 102 | #endif 103 | #endif /* ifndef Skein_Put64_LSB_First */ 104 | 105 | 106 | #ifndef Skein_Get64_LSB_First 107 | void Skein_Get64_LSB_First(u64b_t *dst,const u08b_t *src,size_t wCnt) 108 | #ifdef SKEIN_PORT_CODE /* instantiate the function code here? */ 109 | { /* this version is fully portable (big-endian or little-endian), but slow */ 110 | size_t n; 111 | 112 | for (n=0;n<8*wCnt;n+=8) 113 | dst[n/8] = (((u64b_t) src[n ]) ) + 114 | (((u64b_t) src[n+1]) << 8) + 115 | (((u64b_t) src[n+2]) << 16) + 116 | (((u64b_t) src[n+3]) << 24) + 117 | (((u64b_t) src[n+4]) << 32) + 118 | (((u64b_t) src[n+5]) << 40) + 119 | (((u64b_t) src[n+6]) << 48) + 120 | (((u64b_t) src[n+7]) << 56) ; 121 | } 122 | #else 123 | ; /* output only the function prototype */ 124 | #endif 125 | #endif /* ifndef Skein_Get64_LSB_First */ 126 | 127 | #endif /* ifndef _SKEIN_PORT_H_ */ 128 | -------------------------------------------------------------------------------- /cryptonight-cpu.cpp: -------------------------------------------------------------------------------- 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 | // Modified for CPUminer by Lucas Jones 6 | 7 | #ifdef WIN32 8 | #include "cpuminer-config-win.h" 9 | #else 10 | #include "cpuminer-config.h" 11 | #endif 12 | #include "crypto/oaes_lib.h" 13 | #include "crypto/c_keccak.h" 14 | #include "crypto/c_groestl.h" 15 | #include "crypto/c_blake256.h" 16 | #include "crypto/c_jh.h" 17 | #include "crypto/c_skein.h" 18 | #include "cryptonight.h" 19 | 20 | uint64_t MEMORY = 1ULL << 21; // 2 MiB / 2097152 B 21 | uint32_t ITER = 1 << 20; // 1048576 22 | 23 | struct cryptonight_ctx 24 | { 25 | uint8_t *long_state; 26 | union cn_slow_hash_state state; 27 | uint8_t text[INIT_SIZE_BYTE]; 28 | uint8_t a[AES_BLOCK_SIZE]; 29 | uint8_t b[AES_BLOCK_SIZE]; 30 | uint8_t c[AES_BLOCK_SIZE]; 31 | oaes_ctx* aes_ctx; 32 | }; 33 | 34 | #define VARIANT1_1(p) \ 35 | if (variant == 2 && opt_algo == algo_stellite) \ 36 | { \ 37 | const uint8_t tmp = ((const uint8_t*)(p))[11]; \ 38 | static const uint32_t table = 0x75312; \ 39 | const uint8_t index = (((tmp >> 4) & 6) | (tmp & 1)) << 1; \ 40 | ((uint8_t*)(p))[11] = tmp ^ ((table >> index) & 0x30); \ 41 | } \ 42 | else if(variant > 0){ \ 43 | const uint8_t tmp = ((const uint8_t*)(p))[11]; \ 44 | static const uint32_t table = 0x75310; \ 45 | const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \ 46 | ((uint8_t*)(p))[11] = tmp ^ ((table >> index) & 0x30); \ 47 | } 48 | 49 | #define VARIANT1_INIT() \ 50 | if (variant > 0 && len < 43) \ 51 | { \ 52 | return 0; \ 53 | } \ 54 | const uint64_t tweak1_2 = variant > 0 ? *((const uint64_t*) (((const uint8_t*)input) + 35)) ^ ctx->state.hs.w[24] : 0 55 | 56 | static void do_blake_hash(const void* input, size_t len, char* output) { 57 | blake256_hash((uint8_t*)output, (const uint8_t*)input, len); 58 | } 59 | 60 | void do_groestl_hash(const void* input, size_t len, char* output) { 61 | groestl((const BitSequence*)input, len * 8, (uint8_t*)output); 62 | } 63 | 64 | static void do_jh_hash(const void* input, size_t len, char* output) { 65 | int r = jh_hash(HASH_SIZE * 8, (const BitSequence*)input, 8 * len, (uint8_t*)output); 66 | } 67 | 68 | static void do_skein_hash(const void* input, size_t len, char* output) { 69 | int r = skein_hash(8 * HASH_SIZE, (const SkeinBitSequence*)input, 8 * len, (uint8_t*)output); 70 | } 71 | 72 | void hash_permutation(union hash_state *state) { 73 | keccakf((uint64_t*)state, 24); 74 | } 75 | 76 | void hash_process(union hash_state *state, const uint8_t *buf, size_t count) { 77 | keccak1600(buf, (int)count, (uint8_t*)state); 78 | } 79 | 80 | extern void aesb_single_round(const uint8_t *in, uint8_t*out, uint8_t *expandedKey); 81 | extern void aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey); 82 | 83 | static void (* const extra_hashes[4])(const void *, size_t, char *) = { 84 | do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash 85 | }; 86 | 87 | uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi) { 88 | // multiplier = ab = a * 2^32 + b 89 | // multiplicand = cd = c * 2^32 + d 90 | // ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d 91 | uint64_t a = hi_dword(multiplier); 92 | uint64_t b = lo_dword(multiplier); 93 | uint64_t c = hi_dword(multiplicand); 94 | uint64_t d = lo_dword(multiplicand); 95 | 96 | uint64_t ac = a * c; 97 | uint64_t ad = a * d; 98 | uint64_t bc = b * c; 99 | uint64_t bd = b * d; 100 | 101 | uint64_t adbc = ad + bc; 102 | uint64_t adbc_carry = adbc < ad ? 1 : 0; 103 | 104 | // multiplier * multiplicand = product_hi * 2^64 + product_lo 105 | uint64_t product_lo = bd + (adbc << 32); 106 | uint64_t product_lo_carry = product_lo < bd ? 1 : 0; 107 | *product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry; 108 | 109 | return product_lo; 110 | } 111 | 112 | static size_t e2i(const uint8_t* a) { 113 | return (*((uint64_t*) a) / AES_BLOCK_SIZE) & (MEMORY / AES_BLOCK_SIZE - 1); 114 | } 115 | 116 | static void mul(const uint8_t* a, const uint8_t* b, uint8_t* res) { 117 | ((uint64_t*) res)[1] = mul128(((uint64_t*) a)[0], ((uint64_t*) b)[0], (uint64_t*) res); 118 | } 119 | 120 | static void sum_half_blocks(uint8_t* a, const uint8_t* b) { 121 | ((uint64_t*) a)[0] += ((uint64_t*) b)[0]; 122 | ((uint64_t*) a)[1] += ((uint64_t*) b)[1]; 123 | } 124 | 125 | static void sum_half_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) { 126 | ((uint64_t*) dst)[0] = ((uint64_t*) a)[0] + ((uint64_t*) b)[0]; 127 | ((uint64_t*) dst)[1] = ((uint64_t*) a)[1] + ((uint64_t*) b)[1]; 128 | } 129 | 130 | static void mul_sum_dst(const uint8_t* a, const uint8_t* b, const uint8_t* c, uint8_t* dst) { 131 | ((uint64_t*) dst)[1] = mul128(((uint64_t*) a)[0], ((uint64_t*) b)[0], (uint64_t*) dst) + ((uint64_t*) c)[1]; 132 | ((uint64_t*) dst)[0] += ((uint64_t*) c)[0]; 133 | } 134 | 135 | static void mul_sum_xor_dst(const uint8_t* a, uint8_t* c, uint8_t* dst, const int variant, const uint64_t tweak1_2) { 136 | uint64_t hi, lo = mul128(((uint64_t*) a)[0], ((uint64_t*) dst)[0], &hi) + ((uint64_t*) c)[1]; 137 | hi += ((uint64_t*) c)[0]; 138 | 139 | ((uint64_t*) c)[0] = ((uint64_t*) dst)[0] ^ hi; 140 | ((uint64_t*) c)[1] = ((uint64_t*) dst)[1] ^ lo; 141 | ((uint64_t*) dst)[0] = hi; 142 | ((uint64_t*) dst)[1] = variant > 0 ? lo ^ tweak1_2 : lo; 143 | } 144 | 145 | static void copy_block(uint8_t* dst, const uint8_t* src) { 146 | ((uint64_t*) dst)[0] = ((uint64_t*) src)[0]; 147 | ((uint64_t*) dst)[1] = ((uint64_t*) src)[1]; 148 | } 149 | 150 | static void xor_blocks(uint8_t* a, const uint8_t* b) { 151 | ((uint64_t*) a)[0] ^= ((uint64_t*) b)[0]; 152 | ((uint64_t*) a)[1] ^= ((uint64_t*) b)[1]; 153 | } 154 | 155 | static void xor_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) { 156 | ((uint64_t*) dst)[0] = ((uint64_t*) a)[0] ^ ((uint64_t*) b)[0]; 157 | ((uint64_t*) dst)[1] = ((uint64_t*) a)[1] ^ ((uint64_t*) b)[1]; 158 | } 159 | 160 | int cryptonight_hash_ctx(void* output, const void* input, size_t len, struct cryptonight_ctx* ctx, int variant, algo_t opt_algo) { 161 | size_t i, j; 162 | hash_process(&ctx->state.hs, (const uint8_t*) input, len); 163 | ctx->aes_ctx = (oaes_ctx*) oaes_alloc(); 164 | memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE); 165 | 166 | VARIANT1_INIT(); 167 | 168 | oaes_key_import_data(ctx->aes_ctx, ctx->state.hs.b, AES_KEY_SIZE); 169 | for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) { 170 | #undef RND 171 | #define RND(p) aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * p], ctx->aes_ctx->key->exp_data); 172 | RND(0); 173 | RND(1); 174 | RND(2); 175 | RND(3); 176 | RND(4); 177 | RND(5); 178 | RND(6); 179 | RND(7); 180 | memcpy(&ctx->long_state[i], ctx->text, INIT_SIZE_BYTE); 181 | } 182 | 183 | xor_blocks_dst(&ctx->state.k[0], &ctx->state.k[32], ctx->a); 184 | xor_blocks_dst(&ctx->state.k[16], &ctx->state.k[48], ctx->b); 185 | 186 | for (i = 0; likely(i < ITER / 4); ++i) { 187 | j = e2i(ctx->a) * AES_BLOCK_SIZE; 188 | aesb_single_round(&ctx->long_state[j], ctx->c, ctx->a); 189 | xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]); 190 | VARIANT1_1(&ctx->long_state[j]); 191 | 192 | mul_sum_xor_dst(ctx->c, ctx->a, &ctx->long_state[e2i(ctx->c) * AES_BLOCK_SIZE], variant, tweak1_2); 193 | 194 | j = e2i(ctx->a) * AES_BLOCK_SIZE; 195 | aesb_single_round(&ctx->long_state[j], ctx->b, ctx->a); 196 | xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]); 197 | VARIANT1_1(&ctx->long_state[j]); 198 | 199 | mul_sum_xor_dst(ctx->b, ctx->a, &ctx->long_state[e2i(ctx->b) * AES_BLOCK_SIZE], variant, tweak1_2); 200 | } 201 | 202 | memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE); 203 | oaes_key_import_data(ctx->aes_ctx, &ctx->state.hs.b[32], AES_KEY_SIZE); 204 | for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) { 205 | #undef RND 206 | #define RND(p) xor_blocks(&ctx->text[p * AES_BLOCK_SIZE], &ctx->long_state[i + p * AES_BLOCK_SIZE]); \ 207 | aesb_pseudo_round_mut(&ctx->text[p * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data); 208 | RND(0); 209 | RND(1); 210 | RND(2); 211 | RND(3); 212 | RND(4); 213 | RND(5); 214 | RND(6); 215 | RND(7); 216 | } 217 | memcpy(ctx->state.init, ctx->text, INIT_SIZE_BYTE); 218 | hash_permutation(&ctx->state.hs); 219 | extra_hashes[ctx->state.hs.b[0] & 3](&ctx->state, 200, (char *)output); 220 | oaes_free((OAES_CTX **) &ctx->aes_ctx); 221 | return 1; 222 | } 223 | 224 | extern void proper_exit(int); 225 | 226 | int cryptonight_hash(void* output, const void* input, size_t len, int variant, algo_t opt_algo) 227 | { 228 | struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx)); 229 | if (ctx == NULL) 230 | { 231 | applog(LOG_ERR, "file %s line %d: Out of memory!", __FILE__, __LINE__); 232 | proper_exit(1); 233 | } 234 | ctx->long_state = (uint8_t*)malloc(MEMORY); 235 | if (ctx->long_state == NULL) 236 | { 237 | applog(LOG_ERR, "file %s line %d: Out of memory!", __FILE__, __LINE__); 238 | proper_exit(1); 239 | } 240 | int rc = cryptonight_hash_ctx(output, input, len, ctx, variant, opt_algo); 241 | free(ctx->long_state); 242 | free(ctx); 243 | return rc; 244 | } 245 | -------------------------------------------------------------------------------- /cryptonight.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifdef WIN32 3 | #include "cpuminer-config-win.h" 4 | #else 5 | #include "cpuminer-config.h" 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include "miner.h" 12 | #include 13 | 14 | #ifdef __INTELLISENSE__ 15 | #define __CUDA_ARCH__ 610 16 | /* avoid red underlining */ 17 | 18 | struct uint3 19 | { 20 | unsigned int x, y, z; 21 | }; 22 | 23 | struct uint3 threadIdx; 24 | struct uint3 blockIdx; 25 | struct uint3 blockDim; 26 | #define __funnelshift_r(a,b,c) 1 27 | #define __syncthreads() 28 | #define asm(x) 29 | #define SHFL(a,b,c) 1 30 | #define __umul64hi(x, y) (x*y) 31 | #endif 32 | 33 | #define AES_BLOCK_SIZE 16 34 | #define AES_KEY_SIZE 32 35 | #define INIT_SIZE_BLK 8 36 | #define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) // 128 B 37 | 38 | #define AES_RKEY_LEN 4 39 | #define AES_COL_LEN 4 40 | #define AES_ROUND_BASE 7 41 | 42 | #ifndef HASH_SIZE 43 | #define HASH_SIZE 32 44 | #endif 45 | 46 | #ifndef HASH_DATA_AREA 47 | #define HASH_DATA_AREA 136 48 | #endif 49 | 50 | #define hi_dword(x) (x >> 32) 51 | #define lo_dword(x) (x & 0xFFFFFFFF) 52 | 53 | #define C32(x) ((uint32_t)(x ## U)) 54 | #define T32(x) ((x) & C32(0xFFFFFFFF)) 55 | 56 | #ifndef ROTL64 57 | #if __CUDA_ARCH__ >= 350 58 | __forceinline__ __device__ uint64_t cuda_ROTL64(const uint64_t value, const int offset) { 59 | uint2 result; 60 | if(offset >= 32) { 61 | asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset)); 62 | asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset)); 63 | } else { 64 | asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset)); 65 | asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset)); 66 | } 67 | return __double_as_longlong(__hiloint2double(result.y, result.x)); 68 | } 69 | #define ROTL64(x, n) (cuda_ROTL64(x, n)) 70 | #else 71 | #define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n)))) 72 | #endif 73 | #endif 74 | 75 | #ifndef ROTL32 76 | #if __CUDA_ARCH__ < 350 77 | #define ROTL32(x, n) T32(((x) << (n)) | ((x) >> (32 - (n)))) 78 | #else 79 | #define ROTL32(x, n) __funnelshift_l( (x), (x), (n) ) 80 | #endif 81 | #endif 82 | 83 | #ifndef ROTR32 84 | #if __CUDA_ARCH__ < 350 85 | #define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) 86 | #else 87 | #define ROTR32(x, n) __funnelshift_r( (x), (x), (n) ) 88 | #endif 89 | #endif 90 | 91 | #define MEMSET8(dst,what,cnt) { \ 92 | int i_memset8; \ 93 | uint64_t *out_memset8 = (uint64_t *)(dst); \ 94 | for( i_memset8 = 0; i_memset8 < cnt; i_memset8++ ) \ 95 | out_memset8[i_memset8] = (what); } 96 | 97 | #define MEMSET4(dst,what,cnt) { \ 98 | int i_memset4; \ 99 | uint32_t *out_memset4 = (uint32_t *)(dst); \ 100 | for( i_memset4 = 0; i_memset4 < cnt; i_memset4++ ) \ 101 | out_memset4[i_memset4] = (what); } 102 | 103 | #define MEMCPY8(dst,src,cnt) { \ 104 | int i_memcpy8; \ 105 | uint64_t *in_memcpy8 = (uint64_t *)(src); \ 106 | uint64_t *out_memcpy8 = (uint64_t *)(dst); \ 107 | for( i_memcpy8 = 0; i_memcpy8 < cnt; i_memcpy8++ ) \ 108 | out_memcpy8[i_memcpy8] = in_memcpy8[i_memcpy8]; } 109 | 110 | #define MEMCPY4(dst,src,cnt) { \ 111 | int i_memcpy4; \ 112 | uint32_t *in_memcpy4 = (uint32_t *)(src); \ 113 | uint32_t *out_memcpy4 = (uint32_t *)(dst); \ 114 | for( i_memcpy4 = 0; i_memcpy4 < cnt; i_memcpy4++ ) \ 115 | out_memcpy4[i_memcpy4] = in_memcpy4[i_memcpy4]; } 116 | 117 | #define XOR_BLOCKS(a,b) \ 118 | ((uint64_t *)a)[0] ^= ((uint64_t *)b)[0]; \ 119 | ((uint64_t *)a)[1] ^= ((uint64_t *)b)[1]; 120 | 121 | #define XOR_BLOCKS_DST(x,y,z) \ 122 | ((uint64_t *)(z))[0] = ((uint64_t *)(x))[0] ^ ((uint64_t *)(y))[0]; \ 123 | ((uint64_t *)(z))[1] = ((uint64_t *)(x))[1] ^ ((uint64_t *)(y))[1]; 124 | 125 | #define XOR_BLOCKS_DST2(x,y,z) \ 126 | ((uint64_t *)z)[0] = (x)[0] ^ (y)[0]; \ 127 | ((uint64_t *)z)[1] = (x)[1] ^ (y)[1]; 128 | 129 | #define E2I(x) ((size_t)(((*((uint64_t*)(x)) >> 4) & 0x1ffff))) 130 | 131 | union hash_state { 132 | uint8_t b[200]; 133 | uint64_t w[25]; 134 | }; 135 | 136 | union cn_slow_hash_state { 137 | union hash_state hs; 138 | struct { 139 | uint8_t k[64]; 140 | uint8_t init[INIT_SIZE_BYTE]; 141 | }; 142 | }; 143 | 144 | /* 145 | struct cryptonight_gpu_ctx { 146 | uint32_t state[50]; 147 | uint32_t a[4]; 148 | uint32_t b[4]; 149 | uint32_t key1[40]; 150 | uint32_t key2[40]; 151 | uint32_t text[32]; 152 | }; 153 | */ 154 | 155 | void hash_permutation(union hash_state *state); 156 | void hash_process(union hash_state *state, const uint8_t *buf, size_t count); 157 | -------------------------------------------------------------------------------- /cryptonight/cuda_cryptonight_blake.cu: -------------------------------------------------------------------------------- 1 | 2 | typedef struct { 3 | uint32_t h[8], s[4], t[2]; 4 | int buflen, nullt; 5 | uint8_t buf[64]; 6 | } blake_state; 7 | 8 | #define U8TO32(p) \ 9 | (((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \ 10 | ((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) )) 11 | #define U32TO8(p, v) \ 12 | (p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \ 13 | (p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) ); 14 | #define BLAKE_ROT(x,n) ROTR32(x, n) 15 | #define BLAKE_G(a,b,c,d,e) \ 16 | v[a] += (m[d_blake_sigma[i][e]] ^ d_blake_cst[d_blake_sigma[i][e+1]]) + v[b]; \ 17 | v[d] = BLAKE_ROT(v[d] ^ v[a],16); \ 18 | v[c] += v[d]; \ 19 | v[b] = BLAKE_ROT(v[b] ^ v[c],12); \ 20 | v[a] += (m[d_blake_sigma[i][e+1]] ^ d_blake_cst[d_blake_sigma[i][e]])+v[b]; \ 21 | v[d] = BLAKE_ROT(v[d] ^ v[a], 8); \ 22 | v[c] += v[d]; \ 23 | v[b] = BLAKE_ROT(v[b] ^ v[c], 7); 24 | 25 | __constant__ uint8_t d_blake_sigma[14][16] = 26 | { 27 | {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 28 | {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}, 29 | {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4}, 30 | {7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8}, 31 | {9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13}, 32 | {2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9}, 33 | {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11}, 34 | {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10}, 35 | {6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5}, 36 | {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0}, 37 | {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 38 | {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}, 39 | {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4}, 40 | {7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8} 41 | }; 42 | __constant__ uint32_t d_blake_cst[16] 43 | = { 44 | 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 45 | 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89, 46 | 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C, 47 | 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917 48 | }; 49 | 50 | __device__ void cn_blake_compress(blake_state * __restrict__ S, const uint8_t * __restrict__ block) 51 | { 52 | uint32_t v[16], m[16], i; 53 | 54 | for (i = 0; i < 16; ++i) m[i] = U8TO32(block + i * 4); 55 | for (i = 0; i < 8; ++i) v[i] = S->h[i]; 56 | v[ 8] = S->s[0] ^ 0x243F6A88; 57 | v[ 9] = S->s[1] ^ 0x85A308D3; 58 | v[10] = S->s[2] ^ 0x13198A2E; 59 | v[11] = S->s[3] ^ 0x03707344; 60 | v[12] = 0xA4093822; 61 | v[13] = 0x299F31D0; 62 | v[14] = 0x082EFA98; 63 | v[15] = 0xEC4E6C89; 64 | 65 | if (S->nullt == 0) { 66 | v[12] ^= S->t[0]; 67 | v[13] ^= S->t[0]; 68 | v[14] ^= S->t[1]; 69 | v[15] ^= S->t[1]; 70 | } 71 | 72 | for (i = 0; i < 14; ++i) { 73 | BLAKE_G(0, 4, 8, 12, 0); 74 | BLAKE_G(1, 5, 9, 13, 2); 75 | BLAKE_G(2, 6, 10, 14, 4); 76 | BLAKE_G(3, 7, 11, 15, 6); 77 | BLAKE_G(3, 4, 9, 14, 14); 78 | BLAKE_G(2, 7, 8, 13, 12); 79 | BLAKE_G(0, 5, 10, 15, 8); 80 | BLAKE_G(1, 6, 11, 12, 10); 81 | } 82 | 83 | for (i = 0; i < 16; ++i) S->h[i % 8] ^= v[i]; 84 | for (i = 0; i < 8; ++i) S->h[i] ^= S->s[i % 4]; 85 | } 86 | 87 | __device__ void cn_blake_update(blake_state * __restrict__ S, const uint8_t * __restrict__ data, uint64_t datalen) 88 | { 89 | int left = S->buflen >> 3; 90 | int fill = 64 - left; 91 | 92 | if (left && (((datalen >> 3) & 0x3F) >= (unsigned) fill)) { 93 | memcpy((void *) (S->buf + left), (void *) data, fill); 94 | S->t[0] += 512; 95 | if (S->t[0] == 0) S->t[1]++; 96 | cn_blake_compress(S, S->buf); 97 | data += fill; 98 | datalen -= (fill << 3); 99 | left = 0; 100 | } 101 | 102 | while (datalen >= 512) { 103 | S->t[0] += 512; 104 | if (S->t[0] == 0) S->t[1]++; 105 | cn_blake_compress(S, data); 106 | data += 64; 107 | datalen -= 512; 108 | } 109 | 110 | if (datalen > 0) { 111 | memcpy((void *) (S->buf + left), (void *) data, datalen >> 3); 112 | S->buflen = (left << 3) + datalen; 113 | } else { 114 | S->buflen = 0; 115 | } 116 | } 117 | 118 | __device__ void cn_blake_final(blake_state * __restrict__ S, uint8_t * __restrict__ digest) 119 | { 120 | const uint8_t padding[] = { 121 | 0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 122 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 123 | }; 124 | uint8_t pa = 0x81, pb = 0x01; 125 | uint8_t msglen[8]; 126 | uint32_t lo = S->t[0] + S->buflen, hi = S->t[1]; 127 | if (lo < (unsigned) S->buflen) hi++; 128 | U32TO8(msglen + 0, hi); 129 | U32TO8(msglen + 4, lo); 130 | 131 | if (S->buflen == 440) { 132 | S->t[0] -= 8; 133 | cn_blake_update(S, &pa, 8); 134 | } else { 135 | if (S->buflen < 440) { 136 | if (S->buflen == 0) S->nullt = 1; 137 | S->t[0] -= 440 - S->buflen; 138 | cn_blake_update(S, padding, 440 - S->buflen); 139 | } else { 140 | S->t[0] -= 512 - S->buflen; 141 | cn_blake_update(S, padding, 512 - S->buflen); 142 | S->t[0] -= 440; 143 | cn_blake_update(S, padding + 1, 440); 144 | S->nullt = 1; 145 | } 146 | cn_blake_update(S, &pb, 8); 147 | S->t[0] -= 8; 148 | } 149 | S->t[0] -= 64; 150 | cn_blake_update(S, msglen, 64); 151 | 152 | U32TO8(digest + 0, S->h[0]); 153 | U32TO8(digest + 4, S->h[1]); 154 | U32TO8(digest + 8, S->h[2]); 155 | U32TO8(digest + 12, S->h[3]); 156 | U32TO8(digest + 16, S->h[4]); 157 | U32TO8(digest + 20, S->h[5]); 158 | U32TO8(digest + 24, S->h[6]); 159 | U32TO8(digest + 28, S->h[7]); 160 | } 161 | 162 | __device__ void cn_blake(const uint8_t * __restrict__ in, uint64_t inlen, uint8_t * __restrict__ out) 163 | { 164 | blake_state bs; 165 | blake_state *S = (blake_state *)&bs; 166 | 167 | S->h[0] = 0x6A09E667; S->h[1] = 0xBB67AE85; S->h[2] = 0x3C6EF372; 168 | S->h[3] = 0xA54FF53A; S->h[4] = 0x510E527F; S->h[5] = 0x9B05688C; 169 | S->h[6] = 0x1F83D9AB; S->h[7] = 0x5BE0CD19; 170 | S->t[0] = S->t[1] = S->buflen = S->nullt = 0; 171 | S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0; 172 | 173 | cn_blake_update(S, (uint8_t *)in, inlen * 8); 174 | cn_blake_final(S, (uint8_t *)out); 175 | } 176 | -------------------------------------------------------------------------------- /cryptonight/cuda_cryptonight_core.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "cuda.h" 6 | #include "cuda_runtime.h" 7 | #include "cryptonight.h" 8 | 9 | #ifndef _WIN32 10 | #include 11 | #endif 12 | 13 | extern int device_arch[MAX_GPU][2]; 14 | extern int device_bfactor[MAX_GPU]; 15 | extern int device_bsleep[MAX_GPU]; 16 | 17 | #if !defined SHFL 18 | #if CUDART_VERSION >= 9010 19 | #define SHFL(x, y, z) __shfl_sync(0xffffffff, (x), (y), (z)) 20 | #else 21 | #define SHFL(x, y, z) __shfl((x), (y), (z)) 22 | #endif 23 | #endif 24 | 25 | #include "cuda_cryptonight_aes.cu" 26 | 27 | __device__ __forceinline__ uint64_t cuda_mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi) 28 | { 29 | *product_hi = __umul64hi(multiplier, multiplicand); 30 | return(multiplier * multiplicand); 31 | } 32 | 33 | template< typename T > 34 | __device__ __forceinline__ T loadGlobal64(T * const addr) 35 | { 36 | T x; 37 | asm volatile( 38 | "ld.global.cg.u64 %0, [%1];" : "=l"(x) : "l"(addr) 39 | ); 40 | return x; 41 | } 42 | 43 | template< typename T > 44 | __device__ __forceinline__ T loadGlobal32(T * const addr) 45 | { 46 | T x; 47 | asm volatile( 48 | "ld.global.cg.u32 %0, [%1];" : "=r"(x) : "l"(addr) 49 | ); 50 | return x; 51 | } 52 | 53 | template< typename T > 54 | __device__ __forceinline__ void storeGlobal32(T* addr, T const & val) 55 | { 56 | asm volatile( 57 | "st.global.cg.u32 [%0], %1;" : : "l"(addr), "r"(val) 58 | ); 59 | 60 | } 61 | 62 | __global__ void cryptonight_core_gpu_phase1(int threads, uint32_t * __restrict__ long_state, uint32_t * __restrict__ ctx_state, uint32_t * __restrict__ ctx_key1) 63 | { 64 | __shared__ uint32_t sharedMemory[1024]; 65 | 66 | const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3; 67 | if(thread < threads) 68 | { 69 | cn_aes_gpu_init(sharedMemory); 70 | __syncthreads(); 71 | 72 | const int sub = (threadIdx.x & 7) << 2; 73 | uint32_t *longstate = &long_state[(thread << 19) + sub]; 74 | 75 | uint32_t key[40], text[4]; 76 | 77 | MEMCPY8(key, ctx_key1 + thread * 40, 20); 78 | MEMCPY8(text, ctx_state + thread * 50 + sub + 16, 2); 79 | 80 | for(int i = 0; i < 0x80000; i += 32) 81 | { 82 | cn_aes_pseudo_round_mut(sharedMemory, text, key); 83 | MEMCPY8(&longstate[i], text, 2); 84 | } 85 | } 86 | } 87 | 88 | __device__ __forceinline__ uint32_t variant1_1(int variant, algo_t opt_algo, const uint32_t src) 89 | { 90 | if(variant > 0) 91 | { 92 | const uint8_t tmp = src >> 24; 93 | if(variant == 2 && opt_algo == algo_stellite) 94 | { 95 | const uint32_t table = 0x00075312; 96 | const uint8_t index = (((tmp >> 4) & 6) | (tmp & 1)) << 1; 97 | return (src & 0x00ffffff) | ((tmp ^ ((table >> index) & 0x30)) << 24); 98 | } 99 | else 100 | { 101 | const uint32_t table = 0x00075310; 102 | const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; 103 | return (src & 0x00ffffff) | ((tmp ^ ((table >> index) & 0x30)) << 24); 104 | } 105 | } 106 | return src; 107 | } 108 | 109 | __device__ __forceinline__ void MUL_SUM_XOR_DST(uint64_t a, uint64_t *__restrict__ c, uint64_t *__restrict__ dst) 110 | { 111 | uint64_t hi = __umul64hi(a, dst[0]) + c[0]; 112 | uint64_t lo = a * dst[0] + c[1]; 113 | c[0] = dst[0] ^ hi; 114 | c[1] = dst[1] ^ lo; 115 | dst[0] = hi; 116 | dst[1] = lo; 117 | } 118 | 119 | __global__ void cryptonight_core_gpu_phase2(uint32_t threads, int bfactor, int partidx, uint32_t * __restrict__ d_long_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b, int variant, const uint32_t * d_tweak1_2, algo_t opt_algo) 120 | { 121 | __shared__ uint32_t sharedMemory[1024]; 122 | 123 | cn_aes_gpu_init(sharedMemory); 124 | __syncthreads(); 125 | 126 | const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 2; 127 | if (thread >= threads) 128 | return; 129 | 130 | uint32_t tweak1_2[2]; 131 | if (variant > 0) 132 | { 133 | tweak1_2[0] = d_tweak1_2[thread * 2]; 134 | tweak1_2[1] = d_tweak1_2[thread * 2 + 1]; 135 | } 136 | 137 | const int sub = threadIdx.x & 3; 138 | const int sub2 = threadIdx.x & 2; 139 | 140 | int i, k; 141 | uint32_t j; 142 | const int batchsize = 1<<20 >> (2 + bfactor); 143 | const int start = partidx * batchsize; 144 | const int end = start + batchsize; 145 | uint32_t * long_state = &d_long_state[thread << 19]; 146 | uint32_t * ctx_a = d_ctx_a + thread * 4; 147 | uint32_t * ctx_b = d_ctx_b + thread * 4; 148 | uint32_t a, d[2]; 149 | uint32_t t1[2], t2[2], res; 150 | 151 | a = ctx_a[sub]; 152 | d[1] = ctx_b[sub]; 153 | #pragma unroll 2 154 | for (i = start; i < end; ++i) 155 | { 156 | #pragma unroll 2 157 | for (int x = 0; x < 2; ++x) 158 | { 159 | j = ((SHFL(a, 0, 4) & 0x1FFFF0) >> 2) + sub; 160 | 161 | const uint32_t x_0 = loadGlobal32(long_state + j); 162 | const uint32_t x_1 = SHFL(x_0, sub + 1, 4); 163 | const uint32_t x_2 = SHFL(x_0, sub + 2, 4); 164 | const uint32_t x_3 = SHFL(x_0, sub + 3, 4); 165 | d[x] = a ^ 166 | t_fn0(x_0 & 0xff) ^ 167 | t_fn1((x_1 >> 8) & 0xff) ^ 168 | t_fn2((x_2 >> 16) & 0xff) ^ 169 | t_fn3((x_3 >> 24)); 170 | 171 | 172 | //XOR_BLOCKS_DST(c, b, &long_state[j]); 173 | t1[0] = SHFL(d[x], 0, 4); 174 | //long_state[j] = d[0] ^ d[1]; 175 | const uint32_t z = d[0] ^ d[1]; 176 | storeGlobal32(long_state + j, (variant > 0 && sub == 2) ? variant1_1(variant, opt_algo, z) : z); 177 | 178 | //MUL_SUM_XOR_DST(c, a, &long_state[((uint32_t *)c)[0] & 0x1FFFF0]); 179 | j = ((*t1 & 0x1FFFF0) >> 2) + sub; 180 | 181 | uint32_t yy[2]; 182 | *((uint64_t*)yy) = loadGlobal64(((uint64_t *)long_state) + (j >> 1)); 183 | uint32_t zz[2]; 184 | zz[0] = SHFL(yy[0], 0, 4); 185 | zz[1] = SHFL(yy[1], 0, 4); 186 | 187 | t1[1] = SHFL(d[x], 1, 4); 188 | #pragma unroll 189 | for (k = 0; k < 2; k++) 190 | t2[k] = SHFL(a, k + sub2, 4); 191 | 192 | *((uint64_t *)t2) += sub2 ? (*((uint64_t *)t1) * *((uint64_t*)zz)) : __umul64hi(*((uint64_t *)t1), *((uint64_t*)zz)); 193 | 194 | res = *((uint64_t *)t2) >> (sub & 1 ? 32 : 0); 195 | 196 | storeGlobal32(long_state + j, (variant > 0 && sub2) ? (tweak1_2[sub & 1] ^ res) : res); 197 | a = (sub & 1 ? yy[1] : yy[0]) ^ res; 198 | } 199 | } 200 | 201 | if (bfactor > 0) 202 | { 203 | ctx_a[sub] = a; 204 | ctx_b[sub] = d[1]; 205 | } 206 | } 207 | 208 | __global__ void cryptonight_core_gpu_phase3(int threads, const uint32_t * __restrict__ long_state, uint32_t * __restrict__ d_ctx_state, const uint32_t * __restrict__ d_ctx_key2) 209 | { 210 | __shared__ uint32_t sharedMemory[1024]; 211 | 212 | cn_aes_gpu_init(sharedMemory); 213 | __syncthreads(); 214 | 215 | const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3; 216 | 217 | if(thread < threads) 218 | { 219 | const int sub = (threadIdx.x & 7) << 2; 220 | const uint32_t *longstate = &long_state[(thread << 19) + sub]; 221 | uint32_t key[40], text[4], i, j; 222 | MEMCPY8(key, d_ctx_key2 + thread * 40, 20); 223 | MEMCPY8(text, d_ctx_state + thread * 50 + sub + 16, 2); 224 | 225 | for(i = 0; i < 0x80000; i += 32) 226 | { 227 | #pragma unroll 228 | for(j = 0; j < 4; ++j) 229 | text[j] ^= longstate[i + j]; 230 | 231 | cn_aes_pseudo_round_mut(sharedMemory, text, key); 232 | } 233 | 234 | MEMCPY8(d_ctx_state + thread * 50 + sub + 16, text, 2); 235 | } 236 | } 237 | 238 | __host__ void cryptonight_core_cpu_hash(int thr_id, int blocks, int threads, uint32_t *d_long_state, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint32_t *d_ctx_tweak1_2, algo_t opt_algo) 239 | { 240 | dim3 grid(blocks); 241 | dim3 block(threads); 242 | dim3 block4(threads << 2); 243 | dim3 block8(threads << 3); 244 | 245 | int i, partcount = 1 << device_bfactor[thr_id]; 246 | 247 | cryptonight_core_gpu_phase1 <<< grid, block8 >>>(blocks*threads, d_long_state, d_ctx_state, d_ctx_key1); 248 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 249 | if(partcount > 1) usleep(device_bsleep[thr_id]); 250 | 251 | for(i = 0; i < partcount; i++) 252 | { 253 | cryptonight_core_gpu_phase2 <<< grid, block4 >>>(blocks*threads, device_bfactor[thr_id], i, d_long_state, d_ctx_a, d_ctx_b, variant, d_ctx_tweak1_2, opt_algo); 254 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 255 | cudaDeviceSynchronize(); 256 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 257 | if(partcount > 1) usleep(device_bsleep[thr_id]); 258 | } 259 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 260 | cryptonight_core_gpu_phase3 <<< grid, block8 >>>(blocks*threads, d_long_state, d_ctx_state, d_ctx_key2); 261 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 262 | } 263 | -------------------------------------------------------------------------------- /cryptonight/cuda_cryptonight_extra.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "cuda.h" 5 | #include "cuda_runtime.h" 6 | #include "cryptonight.h" 7 | 8 | #ifndef _WIN32 9 | #include 10 | #endif 11 | 12 | typedef unsigned char BitSequence; 13 | typedef unsigned long long DataLength; 14 | 15 | static uint32_t *d_input[MAX_GPU]; 16 | static uint32_t *d_target[MAX_GPU]; 17 | static uint32_t *d_resultNonce[MAX_GPU]; 18 | 19 | #include "cuda_cryptonight_keccak.cu" 20 | #include "cuda_cryptonight_blake.cu" 21 | #include "cuda_cryptonight_groestl.cu" 22 | #include "cuda_cryptonight_jh.cu" 23 | #include "cuda_cryptonight_skein.cu" 24 | 25 | __constant__ uint8_t d_sub_byte[16][16] = 26 | { 27 | {0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76}, 28 | {0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0}, 29 | {0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15}, 30 | {0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75}, 31 | {0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84}, 32 | {0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf}, 33 | {0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8}, 34 | {0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2}, 35 | {0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73}, 36 | {0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb}, 37 | {0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79}, 38 | {0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08}, 39 | {0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a}, 40 | {0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e}, 41 | {0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf}, 42 | {0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16} 43 | }; 44 | 45 | __device__ __forceinline__ void cryptonight_aes_set_key(uint32_t * __restrict__ key, const uint32_t * __restrict__ data) 46 | { 47 | int i, j; 48 | uint8_t temp[4]; 49 | const uint32_t aes_gf[10] = 50 | { 51 | 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 52 | }; 53 | 54 | MEMCPY4(key, data, 8); 55 | #pragma unroll 56 | for(i = 8; i < 40; i++) 57 | { 58 | *(uint32_t *)temp = key[i - 1]; 59 | if(i % 8 == 0) 60 | { 61 | *(uint32_t *)temp = ROTR32(*(uint32_t *)temp, 8); 62 | for(j = 0; j < 4; j++) 63 | temp[j] = d_sub_byte[(temp[j] >> 4) & 0x0f][temp[j] & 0x0f]; 64 | *(uint32_t *)temp ^= aes_gf[i / 8 - 1]; 65 | } 66 | else 67 | if(i % 8 == 4) 68 | #pragma unroll 69 | for(j = 0; j < 4; j++) 70 | temp[j] = d_sub_byte[(temp[j] >> 4) & 0x0f][temp[j] & 0x0f]; 71 | key[i] = key[(i - 8)] ^ *(uint32_t *)temp; 72 | } 73 | } 74 | 75 | __global__ void cryptonight_extra_gpu_prepare(int threads, const uint32_t * __restrict__ d_input, uint32_t startNonce, uint32_t * __restrict__ d_ctx_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b, uint32_t * __restrict__ d_ctx_key1, uint32_t * __restrict__ d_ctx_key2, int variant, uint32_t * d_ctx_tweak1_2) 76 | { 77 | int thread = (blockDim.x * blockIdx.x + threadIdx.x); 78 | 79 | if(thread < threads) 80 | { 81 | uint64_t ctx_state[25]; 82 | uint32_t ctx_a[4]; 83 | uint32_t ctx_b[4]; 84 | uint32_t ctx_key1[40] = {0}; 85 | uint32_t ctx_key2[40] = {0}; 86 | uint32_t input[19]; 87 | uint32_t tweak1_2[2]; 88 | 89 | MEMCPY4(input, d_input, 19); 90 | 91 | uint32_t nonce = startNonce + thread; 92 | *(((uint8_t *)input) + 39) = nonce & 0xff; 93 | *(((uint8_t *)input) + 40) = (nonce >> 8) & 0xff; 94 | *(((uint8_t *)input) + 41) = (nonce >> 16) & 0xff; 95 | *(((uint8_t *)input) + 42) = (nonce >> 24) & 0xff; 96 | 97 | cn_keccak(input, ctx_state); 98 | cryptonight_aes_set_key(ctx_key1, (uint32_t*)ctx_state); 99 | cryptonight_aes_set_key(ctx_key2, (uint32_t*)(ctx_state + 4)); 100 | XOR_BLOCKS_DST(ctx_state, ctx_state + 4, ctx_a); 101 | XOR_BLOCKS_DST(ctx_state + 2, ctx_state + 6, ctx_b); 102 | 103 | if (variant > 0) 104 | { 105 | tweak1_2[0] = (input[8] >> 24) | (input[9] << 8); 106 | tweak1_2[0] ^= (ctx_state[24] & 0xffffffff); 107 | tweak1_2[1] = (input[9] >> 24) | (input[10] << 8); 108 | tweak1_2[1] ^= (ctx_state[24] >> 32); 109 | MEMCPY4(d_ctx_tweak1_2 + thread * 2, tweak1_2, 2); 110 | } 111 | 112 | MEMCPY4(d_ctx_state + thread * 50, ctx_state, 50); 113 | MEMCPY4(d_ctx_a + thread * 4, ctx_a, 4); 114 | MEMCPY4(d_ctx_b + thread * 4, ctx_b, 4); 115 | MEMCPY4(d_ctx_key1 + thread * 40, ctx_key1, 40); 116 | MEMCPY4(d_ctx_key2 + thread * 40, ctx_key2, 40); 117 | } 118 | } 119 | 120 | __global__ void cryptonight_extra_gpu_final(int threads, uint32_t startNonce, const uint32_t * __restrict__ d_target, uint32_t * __restrict__ resNonce, uint32_t * __restrict__ d_ctx_state) 121 | { 122 | const int thread = blockDim.x * blockIdx.x + threadIdx.x; 123 | 124 | if(thread < threads) 125 | { 126 | int i; 127 | const uint32_t nonce = startNonce + thread; 128 | const uint32_t * __restrict__ ctx_state = d_ctx_state + thread * 50; 129 | uint32_t hash[8]; 130 | uint32_t state[50]; 131 | 132 | #pragma unroll 133 | for(i = 0; i < 50; i++) 134 | state[i] = ctx_state[i]; 135 | 136 | cn_keccakf2((uint64_t *)state); 137 | 138 | int branch = ((uint8_t *)state)[0] & 0x03; 139 | if(branch == 0) 140 | cn_blake((const uint8_t *)state, 200, (uint8_t *)hash); 141 | if(branch == 1) 142 | cn_groestl((const BitSequence *)state, 200, (BitSequence *)hash); 143 | if(branch == 2) 144 | cn_jh((const BitSequence *)state, 200, (BitSequence *)hash); 145 | if(branch == 3) 146 | cn_skein((const BitSequence *)state, 200, (BitSequence *)hash); 147 | 148 | int position = -1; 149 | bool rc = true; 150 | 151 | #pragma unroll 8 152 | for(i = 7; i >= 0; i--) 153 | { 154 | if(hash[i] > d_target[i]) 155 | { 156 | if(position < i) 157 | { 158 | position = i; 159 | rc = false; 160 | } 161 | } 162 | if(hash[i] < d_target[i]) 163 | { 164 | if(position < i) 165 | { 166 | position = i; 167 | rc = true; 168 | } 169 | } 170 | } 171 | 172 | if(rc == true) 173 | { 174 | uint32_t tmp = atomicExch(resNonce, nonce); 175 | if(tmp != 0xffffffff) 176 | resNonce[1] = tmp; 177 | } 178 | } 179 | } 180 | 181 | __host__ void cryptonight_extra_cpu_setData(int thr_id, const void *data, const void *pTargetIn) 182 | { 183 | cudaMemcpy(d_input[thr_id], data, 19 * sizeof(uint32_t), cudaMemcpyHostToDevice); 184 | cudaMemcpy(d_target[thr_id], pTargetIn, 8 * sizeof(uint32_t), cudaMemcpyHostToDevice); 185 | cudaMemset(d_resultNonce[thr_id], 0xFF, 2 * sizeof(uint32_t)); 186 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 187 | } 188 | 189 | __host__ void cryptonight_extra_cpu_init(int thr_id) 190 | { 191 | cudaMalloc(&d_input[thr_id], 19 * sizeof(uint32_t)); 192 | cudaMalloc(&d_target[thr_id], 8 * sizeof(uint32_t)); 193 | cudaMalloc(&d_resultNonce[thr_id], 2*sizeof(uint32_t)); 194 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 195 | } 196 | 197 | __host__ void cryptonight_extra_cpu_prepare(int thr_id, int threads, uint32_t startNonce, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint32_t *d_ctx_tweak1_2) 198 | { 199 | int threadsperblock = 128; 200 | 201 | dim3 grid((threads + threadsperblock - 1) / threadsperblock); 202 | dim3 block(threadsperblock); 203 | 204 | cryptonight_extra_gpu_prepare << > >(threads, d_input[thr_id], startNonce, d_ctx_state, d_ctx_a, d_ctx_b, d_ctx_key1, d_ctx_key2, variant, d_ctx_tweak1_2); 205 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 206 | } 207 | 208 | __host__ void cryptonight_extra_cpu_final(int thr_id, int threads, uint32_t startNonce, uint32_t *resnonce, uint32_t *d_ctx_state) 209 | { 210 | int threadsperblock = 128; 211 | 212 | dim3 grid((threads + threadsperblock - 1) / threadsperblock); 213 | dim3 block(threadsperblock); 214 | 215 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 216 | cryptonight_extra_gpu_final << > >(threads, startNonce, d_target[thr_id], d_resultNonce[thr_id], d_ctx_state); 217 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 218 | cudaMemcpy(resnonce, d_resultNonce[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost); 219 | exit_if_cudaerror(thr_id, __FILE__, __LINE__); 220 | } 221 | -------------------------------------------------------------------------------- /cuda_helper.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KlausT/ccminer-cryptonight/ce20e2b3b964410019e72c246a4a009a16095016/cuda_helper.h -------------------------------------------------------------------------------- /elist.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINUX_LIST_H 2 | #define _LINUX_LIST_H 3 | 4 | /* 5 | * Simple doubly linked list implementation. 6 | * 7 | * Some of the internal functions ("__xxx") are useful when 8 | * manipulating whole lists rather than single entries, as 9 | * sometimes we already know the next/prev entries and we can 10 | * generate better code by using them directly rather than 11 | * using the generic single-entry routines. 12 | */ 13 | 14 | struct list_head { 15 | struct list_head *next, *prev; 16 | }; 17 | 18 | #define LIST_HEAD_INIT(name) { &(name), &(name) } 19 | 20 | #define LIST_HEAD(name) \ 21 | struct list_head name = LIST_HEAD_INIT(name) 22 | 23 | #define INIT_LIST_HEAD(ptr) do { \ 24 | (ptr)->next = (ptr); (ptr)->prev = (ptr); \ 25 | } while (0) 26 | 27 | /* 28 | * Insert a new entry between two known consecutive entries. 29 | * 30 | * This is only for internal list manipulation where we know 31 | * the prev/next entries already! 32 | */ 33 | static __inline void __list_add(struct list_head *lnew, 34 | struct list_head *prev, 35 | struct list_head *next) 36 | { 37 | next->prev = lnew; 38 | lnew->next = next; 39 | lnew->prev = prev; 40 | prev->next = lnew; 41 | } 42 | 43 | /** 44 | * list_add - add a new entry 45 | * @new: new entry to be added 46 | * @head: list head to add it after 47 | * 48 | * Insert a new entry after the specified head. 49 | * This is good for implementing stacks. 50 | */ 51 | static __inline void list_add(struct list_head *lnew, struct list_head *head) 52 | { 53 | __list_add(lnew, head, head->next); 54 | } 55 | 56 | /** 57 | * list_add_tail - add a new entry 58 | * @new: new entry to be added 59 | * @head: list head to add it before 60 | * 61 | * Insert a new entry before the specified head. 62 | * This is useful for implementing queues. 63 | */ 64 | static __inline void list_add_tail(struct list_head *lnew, struct list_head *head) 65 | { 66 | __list_add(lnew, head->prev, head); 67 | } 68 | 69 | /* 70 | * Delete a list entry by making the prev/next entries 71 | * point to each other. 72 | * 73 | * This is only for internal list manipulation where we know 74 | * the prev/next entries already! 75 | */ 76 | static __inline void __list_del(struct list_head *prev, struct list_head *next) 77 | { 78 | next->prev = prev; 79 | prev->next = next; 80 | } 81 | 82 | /** 83 | * list_del - deletes entry from list. 84 | * @entry: the element to delete from the list. 85 | * Note: list_empty on entry does not return true after this, the entry is in an undefined state. 86 | */ 87 | static __inline void list_del(struct list_head *entry) 88 | { 89 | __list_del(entry->prev, entry->next); 90 | entry->next = (struct list_head *) 0; 91 | entry->prev = (struct list_head *) 0; 92 | } 93 | 94 | /** 95 | * list_del_init - deletes entry from list and reinitialize it. 96 | * @entry: the element to delete from the list. 97 | */ 98 | static __inline void list_del_init(struct list_head *entry) 99 | { 100 | __list_del(entry->prev, entry->next); 101 | INIT_LIST_HEAD(entry); 102 | } 103 | 104 | /** 105 | * list_move - delete from one list and add as another's head 106 | * @list: the entry to move 107 | * @head: the head that will precede our entry 108 | */ 109 | static __inline void list_move(struct list_head *list, struct list_head *head) 110 | { 111 | __list_del(list->prev, list->next); 112 | list_add(list, head); 113 | } 114 | 115 | /** 116 | * list_move_tail - delete from one list and add as another's tail 117 | * @list: the entry to move 118 | * @head: the head that will follow our entry 119 | */ 120 | static __inline void list_move_tail(struct list_head *list, 121 | struct list_head *head) 122 | { 123 | __list_del(list->prev, list->next); 124 | list_add_tail(list, head); 125 | } 126 | 127 | /** 128 | * list_empty - tests whether a list is empty 129 | * @head: the list to test. 130 | */ 131 | static __inline int list_empty(struct list_head *head) 132 | { 133 | return head->next == head; 134 | } 135 | 136 | static __inline void __list_splice(struct list_head *list, 137 | struct list_head *head) 138 | { 139 | struct list_head *first = list->next; 140 | struct list_head *last = list->prev; 141 | struct list_head *at = head->next; 142 | 143 | first->prev = head; 144 | head->next = first; 145 | 146 | last->next = at; 147 | at->prev = last; 148 | } 149 | 150 | /** 151 | * list_splice - join two lists 152 | * @list: the new list to add. 153 | * @head: the place to add it in the first list. 154 | */ 155 | static __inline void list_splice(struct list_head *list, struct list_head *head) 156 | { 157 | if (!list_empty(list)) 158 | __list_splice(list, head); 159 | } 160 | 161 | /** 162 | * list_splice_init - join two lists and reinitialise the emptied list. 163 | * @list: the new list to add. 164 | * @head: the place to add it in the first list. 165 | * 166 | * The list at @list is reinitialised 167 | */ 168 | static __inline void list_splice_init(struct list_head *list, 169 | struct list_head *head) 170 | { 171 | if (!list_empty(list)) { 172 | __list_splice(list, head); 173 | INIT_LIST_HEAD(list); 174 | } 175 | } 176 | 177 | /** 178 | * list_entry - get the struct for this entry 179 | * @ptr: the &struct list_head pointer. 180 | * @type: the type of the struct this is embedded in. 181 | * @member: the name of the list_struct within the struct. 182 | */ 183 | #define list_entry(ptr, type, member) \ 184 | ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member))) 185 | 186 | /** 187 | * list_for_each - iterate over a list 188 | * @pos: the &struct list_head to use as a loop counter. 189 | * @head: the head for your list. 190 | */ 191 | #define list_for_each(pos, head) \ 192 | for (pos = (head)->next; pos != (head); \ 193 | pos = pos->next) 194 | /** 195 | * list_for_each_prev - iterate over a list backwards 196 | * @pos: the &struct list_head to use as a loop counter. 197 | * @head: the head for your list. 198 | */ 199 | #define list_for_each_prev(pos, head) \ 200 | for (pos = (head)->prev; pos != (head); \ 201 | pos = pos->prev) 202 | 203 | /** 204 | * list_for_each_safe - iterate over a list safe against removal of list entry 205 | * @pos: the &struct list_head to use as a loop counter. 206 | * @n: another &struct list_head to use as temporary storage 207 | * @head: the head for your list. 208 | */ 209 | #define list_for_each_safe(pos, n, head) \ 210 | for (pos = (head)->next, n = pos->next; pos != (head); \ 211 | pos = n, n = pos->next) 212 | 213 | /** 214 | * list_for_each_entry - iterate over list of given type 215 | * @pos: the type * to use as a loop counter. 216 | * @head: the head for your list. 217 | * @member: the name of the list_struct within the struct. 218 | */ 219 | #define list_for_each_entry(pos, head, member, tpos) \ 220 | for (pos = list_entry((head)->next, tpos, member); \ 221 | &pos->member != (head); \ 222 | pos = list_entry(pos->member.next, tpos, member)) 223 | 224 | /** 225 | * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry 226 | * @pos: the type * to use as a loop counter. 227 | * @n: another type * to use as temporary storage 228 | * @head: the head for your list. 229 | * @member: the name of the list_struct within the struct. 230 | */ 231 | #define list_for_each_entry_safe(pos, n, head, member, tpos, tn) \ 232 | for (pos = list_entry((head)->next, tpos, member), \ 233 | n = list_entry(pos->member.next, tpos, member); \ 234 | &pos->member != (head); \ 235 | pos = n, n = list_entry(n->member.next, tn, member)) 236 | 237 | /** 238 | * list_for_each_entry_continue - iterate over list of given type 239 | * continuing after existing point 240 | * @pos: the type * to use as a loop counter. 241 | * @head: the head for your list. 242 | * @member: the name of the list_struct within the struct. 243 | */ 244 | #define list_for_each_entry_continue(pos, head, member, tpos) \ 245 | for (pos = list_entry(pos->member.next, tpos, member), \ 246 | prefetch(pos->member.next); \ 247 | &pos->member != (head); \ 248 | pos = list_entry(pos->member.next, tpos, member), \ 249 | prefetch(pos->member.next)) 250 | 251 | #endif 252 | -------------------------------------------------------------------------------- /miner.h: -------------------------------------------------------------------------------- 1 | #ifndef __MINER_H__ 2 | #define __MINER_H__ 3 | 4 | #ifdef WIN32 5 | #include "cpuminer-config-win.h" 6 | #else 7 | #include "cpuminer-config.h" 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef WIN32 17 | #define snprintf(...) _snprintf(__VA_ARGS__) 18 | #define strdup(x) _strdup(x) 19 | #define strncasecmp(x,y,z) _strnicmp(x,y,z) 20 | #define strcasecmp(x,y) _stricmp(x,y) 21 | typedef SSIZE_T ssize_t; 22 | #endif 23 | 24 | #ifdef STDC_HEADERS 25 | # include 26 | # include 27 | #else 28 | # ifdef HAVE_STDLIB_H 29 | # include 30 | # endif 31 | #endif 32 | #ifdef HAVE_ALLOCA_H 33 | # include 34 | #elif !defined alloca 35 | # ifdef __GNUC__ 36 | # define alloca __builtin_alloca 37 | # elif defined _AIX 38 | # define alloca __alloca 39 | # elif defined _MSC_VER 40 | # include 41 | # define alloca _alloca 42 | # elif !defined HAVE_ALLOCA 43 | void *alloca (size_t); 44 | # endif 45 | #endif 46 | 47 | #ifdef HAVE_SYSLOG_H 48 | #include 49 | #else 50 | enum { 51 | LOG_ERR, 52 | LOG_WARNING, 53 | LOG_NOTICE, 54 | LOG_INFO, 55 | LOG_DEBUG, 56 | }; 57 | #endif 58 | 59 | #undef unlikely 60 | #undef likely 61 | #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) 62 | #define unlikely(expr) (__builtin_expect(!!(expr), 0)) 63 | #define likely(expr) (__builtin_expect(!!(expr), 1)) 64 | #else 65 | #define unlikely(expr) (expr) 66 | #define likely(expr) (expr) 67 | #endif 68 | 69 | #define MAX_GPU 16 70 | 71 | #ifndef ARRAY_SIZE 72 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 73 | #endif 74 | 75 | #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) 76 | #define WANT_BUILTIN_BSWAP 77 | #else 78 | #define bswap_32(x) ((((x) << 24) & 0xff000000u) | (((x) << 8) & 0x00ff0000u) \ 79 | | (((x) >> 8) & 0x0000ff00u) | (((x) >> 24) & 0x000000ffu)) 80 | #endif 81 | 82 | static inline uint32_t swab32(uint32_t v) 83 | { 84 | #ifdef WANT_BUILTIN_BSWAP 85 | return __builtin_bswap32(v); 86 | #else 87 | return bswap_32(v); 88 | #endif 89 | } 90 | 91 | #ifdef HAVE_SYS_ENDIAN_H 92 | #include 93 | #endif 94 | 95 | #if !HAVE_DECL_BE32DEC 96 | static inline uint32_t be32dec(const void *pp) 97 | { 98 | const uint8_t *p = (uint8_t const *)pp; 99 | return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) + 100 | ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24)); 101 | } 102 | #endif 103 | 104 | #if !HAVE_DECL_LE32DEC 105 | static inline uint32_t le32dec(const void *pp) 106 | { 107 | const uint8_t *p = (uint8_t const *)pp; 108 | return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) + 109 | ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24)); 110 | } 111 | #endif 112 | 113 | #if !HAVE_DECL_BE32ENC 114 | static inline void be32enc(void *pp, uint32_t x) 115 | { 116 | uint8_t *p = (uint8_t *)pp; 117 | p[3] = x & 0xff; 118 | p[2] = (x >> 8) & 0xff; 119 | p[1] = (x >> 16) & 0xff; 120 | p[0] = (x >> 24) & 0xff; 121 | } 122 | #endif 123 | 124 | #if !HAVE_DECL_LE32ENC 125 | static inline void le32enc(void *pp, uint32_t x) 126 | { 127 | uint8_t *p = (uint8_t *)pp; 128 | p[0] = x & 0xff; 129 | p[1] = (x >> 8) & 0xff; 130 | p[2] = (x >> 16) & 0xff; 131 | p[3] = (x >> 24) & 0xff; 132 | } 133 | #endif 134 | 135 | #if !HAVE_DECL_BE16DEC 136 | static inline uint16_t be16dec(const void *pp) 137 | { 138 | const uint8_t *p = (uint8_t const *)pp; 139 | return ((uint16_t)(p[1]) + ((uint16_t)(p[0]) << 8)); 140 | } 141 | #endif 142 | 143 | #if !HAVE_DECL_BE16ENC 144 | static inline void be16enc(void *pp, uint16_t x) 145 | { 146 | uint8_t *p = (uint8_t *)pp; 147 | p[1] = x & 0xff; 148 | p[0] = (x >> 8) & 0xff; 149 | } 150 | #endif 151 | 152 | #if !HAVE_DECL_LE16DEC 153 | static inline uint16_t le16dec(const void *pp) 154 | { 155 | const uint8_t *p = (uint8_t const *)pp; 156 | return ((uint16_t)(p[0]) + ((uint16_t)(p[1]) << 8)); 157 | } 158 | #endif 159 | 160 | #if !HAVE_DECL_LE16ENC 161 | static inline void le16enc(void *pp, uint16_t x) 162 | { 163 | uint8_t *p = (uint8_t *)pp; 164 | p[0] = x & 0xff; 165 | p[1] = (x >> 8) & 0xff; 166 | } 167 | #endif 168 | 169 | #if JANSSON_MAJOR_VERSION >= 2 170 | #define JSON_LOADS(str, err_ptr) json_loads((str), 0, (err_ptr)) 171 | #else 172 | #define JSON_LOADS(str, err_ptr) json_loads((str), (err_ptr)) 173 | #endif 174 | 175 | #define USER_AGENT PACKAGE_NAME "/" PACKAGE_VERSION 176 | 177 | void sha256_init(uint32_t *state); 178 | void sha256_transform(uint32_t *state, const uint32_t *block, int swap); 179 | void sha256d(unsigned char *hash, const unsigned char *data, int len); 180 | 181 | #if defined(__ARM_NEON__) || defined(__i386__) || defined(__x86_64__) 182 | #define HAVE_SHA256_4WAY 0 183 | int sha256_use_4way(); 184 | void sha256_init_4way(uint32_t *state); 185 | void sha256_transform_4way(uint32_t *state, const uint32_t *block, int swap); 186 | #endif 187 | 188 | #if defined(__x86_64__) && defined(USE_AVX2) 189 | #define HAVE_SHA256_8WAY 0 190 | int sha256_use_8way(); 191 | void sha256_init_8way(uint32_t *state); 192 | void sha256_transform_8way(uint32_t *state, const uint32_t *block, int swap); 193 | #endif 194 | 195 | typedef enum __algo_t 196 | { 197 | algo_old, 198 | algo_monero, 199 | algo_graft, 200 | algo_stellite, 201 | algo_intense, 202 | algo_electroneum, 203 | algo_sumokoin 204 | } algo_t; 205 | 206 | extern int scanhash_cryptonight(int thr_id, uint32_t *pdata, 207 | const uint32_t *ptarget, uint32_t max_nonce, 208 | unsigned long *hashes_done, uint32_t *results); 209 | 210 | extern int cryptonight_hash(void* output, const void* input, size_t len, int variant, algo_t opt_algo); 211 | 212 | struct thr_info { 213 | int id; 214 | pthread_t pth; 215 | struct thread_q *q; 216 | }; 217 | 218 | struct work_restart { 219 | volatile unsigned long restart; 220 | char padding[128 - sizeof(unsigned long)]; 221 | }; 222 | 223 | extern bool opt_colors; 224 | extern bool opt_debug; 225 | extern bool opt_protocol; 226 | extern int opt_timeout; 227 | extern bool want_longpoll; 228 | extern bool have_longpoll; 229 | extern bool want_stratum; 230 | extern bool have_stratum; 231 | extern char *opt_cert; 232 | extern char *opt_proxy; 233 | extern long opt_proxy_type; 234 | extern bool use_syslog; 235 | extern pthread_mutex_t applog_lock; 236 | extern struct thr_info *thr_info; 237 | extern int longpoll_thr_id; 238 | extern int stratum_thr_id; 239 | extern struct work_restart *work_restart; 240 | 241 | #define JSON_RPC_LONGPOLL (1 << 0) 242 | #define JSON_RPC_QUIET_404 (1 << 1) 243 | #define JSON_RPC_IGNOREERR (1 << 2) 244 | 245 | void color_init(); 246 | extern void applog(int prio, const char *fmt, ...); 247 | extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass, 248 | const char *rpc_req, bool, bool, int *); 249 | extern char *bin2hex(const unsigned char *p, size_t len); 250 | extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len); 251 | extern int timeval_subtract(struct timeval *result, struct timeval *x, 252 | struct timeval *y); 253 | extern bool fulltest(const uint32_t *hash, const uint32_t *target); 254 | extern void diff_to_target(uint32_t *target, double diff); 255 | void exit_if_cudaerror(int thr_id, const char *file, int line); 256 | 257 | struct work { 258 | uint32_t data[32]; 259 | uint32_t target[8]; 260 | uint32_t maxvote; 261 | 262 | char job_id[128]; 263 | size_t xnonce2_len; 264 | unsigned char xnonce2[32]; 265 | }; 266 | 267 | struct stratum_job { 268 | char *job_id; 269 | unsigned char prevhash[32]; 270 | size_t coinbase_size; 271 | unsigned char *coinbase; 272 | unsigned char *xnonce2; 273 | int merkle_count; 274 | unsigned char **merkle; 275 | unsigned char version[4]; 276 | unsigned char nbits[4]; 277 | unsigned char ntime[4]; 278 | bool clean; 279 | unsigned char nreward[2]; 280 | double diff; 281 | }; 282 | 283 | struct stratum_ctx { 284 | char *url; 285 | 286 | CURL *curl; 287 | char *curl_url; 288 | char curl_err_str[CURL_ERROR_SIZE]; 289 | curl_socket_t sock; 290 | size_t sockbuf_size; 291 | char *sockbuf; 292 | pthread_mutex_t sock_lock; 293 | 294 | double next_diff; 295 | 296 | char *session_id; 297 | size_t xnonce1_size; 298 | unsigned char *xnonce1; 299 | size_t xnonce2_size; 300 | struct stratum_job job; 301 | struct work work; 302 | pthread_mutex_t work_lock; 303 | }; 304 | 305 | bool stratum_keepalived(struct stratum_ctx *sctx , const char *rpc2_id); 306 | bool stratum_socket_full(struct stratum_ctx *sctx, int timeout); 307 | bool stratum_send_line(struct stratum_ctx *sctx, char *s); 308 | char *stratum_recv_line(struct stratum_ctx *sctx); 309 | bool stratum_connect(struct stratum_ctx *sctx, const char *url); 310 | void stratum_disconnect(struct stratum_ctx *sctx); 311 | bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *pass); 312 | bool stratum_handle_method(struct stratum_ctx *sctx, const char *s); 313 | 314 | extern bool rpc2_job_decode(const json_t *job, struct work *work); 315 | extern bool rpc2_login_decode(const json_t *val); 316 | 317 | struct thread_q; 318 | 319 | extern struct thread_q *tq_new(void); 320 | extern void tq_free(struct thread_q *tq); 321 | extern bool tq_push(struct thread_q *tq, void *data); 322 | extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime); 323 | extern void tq_freeze(struct thread_q *tq); 324 | extern void tq_thaw(struct thread_q *tq); 325 | 326 | #endif /* __MINER_H__ */ 327 | --------------------------------------------------------------------------------