├── hash_cn ├── libhash │ ├── libhash.so │ ├── slow-hash.h │ ├── Makefile │ ├── keccak.h │ ├── jh.h │ ├── main.c │ ├── random.h │ ├── hash-extra-blake.c │ ├── hash-extra-groestl.c │ ├── hash-extra-skein.c │ ├── skein.h │ ├── hash-extra-jh.c │ ├── oaes_config.h │ ├── hash.c │ ├── generic-ops.h │ ├── initializer.h │ ├── blake256.h │ ├── groestl.h │ ├── hash-ops.h │ ├── hash.h │ ├── keccak.c │ ├── chacha.h │ ├── random.c │ ├── tree-hash.c │ ├── crypto-ops.h │ └── chacha.c ├── webassembly │ ├── blake.h │ ├── skein.h │ ├── groestl.h │ ├── jh.h │ ├── cryptonight.h │ ├── keccak.h │ ├── Makefile │ ├── main.c │ ├── license.txt │ ├── oaes_config.h │ ├── keccak.c │ ├── groestl_tables.h │ ├── base64.h │ └── oaes_lib.h └── correct_hashes.txt ├── server ├── build ├── Server.sln ├── Server │ ├── Extensions.cs │ ├── Fleck │ │ ├── Interfaces │ │ │ ├── IWebSocketServer.cs │ │ │ ├── IHandler.cs │ │ │ ├── IWebSocketConnectionInfo.cs │ │ │ ├── IWebSocketConnection.cs │ │ │ └── ISocket.cs │ │ ├── Helpers │ │ │ └── MonoHelper.cs │ │ ├── FrameType.cs │ │ ├── HandshakeException.cs │ │ ├── SubProtocolNegotiationFailureException.cs │ │ ├── ReadState.cs │ │ ├── ConnectionNotAvailableException.cs │ │ ├── SubProtocolNegotiator.cs │ │ ├── WebSocketException.cs │ │ ├── Handlers │ │ │ ├── FlashSocketPolicyRequestHandler.cs │ │ │ ├── ComposableHandler.cs │ │ │ └── Draft76Handler.cs │ │ ├── FleckLog.cs │ │ ├── WebSocketStatusCodes.cs │ │ ├── IntExtensions.cs │ │ ├── WebSocketHttpRequest.cs │ │ ├── BufferPool.cs │ │ ├── HandlerFactory.cs │ │ ├── RequestParser.cs │ │ └── WebSocketConnectionInfo.cs │ ├── DevDonation.cs │ ├── Random2.cs │ ├── Helper.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── DataStructures.cs │ ├── AlgorithmHelper.cs │ ├── CConsole.cs │ ├── PoolList.cs │ ├── Firewall.cs │ ├── Server.csproj │ └── EmptyWebsocket.cs └── pools.json └── SDK ├── other ├── getpools.html ├── getuserstats.html └── register.html ├── miner_raw ├── mine.html └── miner │ ├── worker.js │ └── miner.js └── miner_compressed └── mine.html /hash_cn/libhash/libhash.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cryptonoter/webminerpool/HEAD/hash_cn/libhash/libhash.so -------------------------------------------------------------------------------- /hash_cn/libhash/slow-hash.h: -------------------------------------------------------------------------------- 1 | #ifndef __slow_hash_h 2 | #define __slow_hash_h 3 | 4 | void cn_slow_hash(const void *data, size_t length, char *hash, int light, int variant, int prehashed); 5 | 6 | #endif -------------------------------------------------------------------------------- /hash_cn/webassembly/blake.h: -------------------------------------------------------------------------------- 1 | #ifndef BLAKE_H 2 | #define BLAKE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void blake(const uint8_t *input, uint64_t len, uint8_t *output); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /hash_cn/webassembly/skein.h: -------------------------------------------------------------------------------- 1 | #ifndef SKEIN_H 2 | #define SKEIN_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern int skein(int hashbitlen, const unsigned char *input, 9 | size_t input_len, unsigned char *output); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /hash_cn/webassembly/groestl.h: -------------------------------------------------------------------------------- 1 | #ifndef GROESTL_H 2 | #define GROESTL_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern void groestl(const unsigned char *input, 9 | unsigned long long len, 10 | unsigned char *output); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /hash_cn/webassembly/jh.h: -------------------------------------------------------------------------------- 1 | #ifndef JH_H 2 | #define JH_H 3 | #include 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void jh(unsigned bit_len, const uint8_t input[], 10 | size_t input_bit_length, uint8_t output[]); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /hash_cn/webassembly/cryptonight.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTONIGHT_H 2 | #define CRYPTONIGHT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void cryptonight(void *output, const void *input, size_t len, int lite, int variant); 9 | struct cryptonight_ctx; 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /hash_cn/webassembly/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 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | void keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen); 14 | 15 | void keccakf(uint64_t st[25], int norounds); 16 | 17 | void keccak1600(const uint8_t *in, int inlen, uint8_t *md); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /hash_cn/libhash/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = prog 2 | LIBS = -lm 3 | CC = gcc -O3 -shared -fPIC -pthread 4 | CFLAGS = -g -Wall -std=gnu99 -maes 5 | 6 | .PHONY: default all clean 7 | 8 | default: $(TARGET) 9 | all: default 10 | 11 | OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) 12 | HEADERS = $(wildcard *.h) 13 | 14 | %.o: %.c $(HEADERS) $(CC) $(CFLAGS) -c $< -o $@ 15 | 16 | .PRECIOUS: $(TARGET) $(OBJECTS) 17 | 18 | $(TARGET): $(OBJECTS) 19 | $(CC) $(OBJECTS) -Wall $(LIBS) -o libhash.so 20 | 21 | clean: 22 | -rm -f *.o 23 | -rm -f $(TARGET) 24 | -------------------------------------------------------------------------------- /server/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "" 4 | echo "This is a simple helper to compile the C# server on Linux with msbuild." 5 | echo "You should install the latest mono version (including msbuild) from" 6 | echo "http://www.mono-project.com/download/stable/" 7 | echo "" 8 | echo "At least version 4.8.0 of mono is required. Your version is" 9 | mono --version | grep version 10 | echo "" 11 | echo "Your msbuild version is" 12 | msbuild /version | grep version 13 | echo "" 14 | 15 | read -p "Press enter to continue" 16 | msbuild Server.sln /p:Configuration=Release_Server /p:Platform="any CPU" 17 | -------------------------------------------------------------------------------- /hash_cn/libhash/keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | 4 | #ifndef KECCAK_H 5 | #define KECCAK_H 6 | 7 | #include 8 | #include 9 | 10 | #ifndef KECCAK_ROUNDS 11 | #define KECCAK_ROUNDS 24 12 | #endif 13 | 14 | #ifndef ROTL64 15 | #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) 16 | #endif 17 | 18 | // compute a keccak hash (md) of given byte length from "in" 19 | void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen); 20 | 21 | // update the state 22 | void keccakf(uint64_t st[25], int norounds); 23 | 24 | void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /hash_cn/webassembly/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = prog 2 | LIBS = -lm 3 | CC = emcc -O3 -s SINGLE_FILE=1 -s NO_FILESYSTEM=1 -s 'EXTRA_EXPORTED_RUNTIME_METHODS=["ccall", "cwrap"]' --llvm-lto 1 -s TOTAL_MEMORY=67108864 -s WASM=1 -s "BINARYEN_TRAP_MODE='allow'" -s EXPORTED_FUNCTIONS="['_hash_cn']" --shell-file html_template/shell_minimal.html 4 | CFLAGS = -Wall -msse2 5 | 6 | 7 | # SINGLE_FILE=1 8 | 9 | # -s ASSERTIONS=1 10 | # -s SINGLE_FILE=1 11 | .PHONY: default all clean 12 | 13 | default: $(TARGET) 14 | all: default 15 | 16 | OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) 17 | HEADERS = $(wildcard *.h) 18 | 19 | %.o: %.c $(HEADERS) $(CC) $(CFLAGS) -c $< -o $@ 20 | 21 | .PRECIOUS: $(TARGET) $(OBJECTS) 22 | 23 | $(TARGET): $(OBJECTS) 24 | $(CC) $(OBJECTS) -Wall $(LIBS) -o cn.html 25 | 26 | clean: 27 | -rm -f *.o 28 | -rm -f $(TARGET) 29 | -------------------------------------------------------------------------------- /hash_cn/libhash/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 | typedef unsigned char BitSequence; 18 | typedef unsigned long long DataLength; 19 | typedef enum {SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2} HashReturn; 20 | 21 | HashReturn jh_hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval); 22 | -------------------------------------------------------------------------------- /SDK/other/getpools.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 | 10 | 11 |
12 | 13 |
14 | 15 | 16 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /hash_cn/libhash/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "slow-hash.h" 9 | 10 | char *hash_cn(char *hex, int lite, int variant) 11 | { 12 | char *output = (char *)malloc((64 + 1) * sizeof(char)); 13 | 14 | int len = strlen(hex) / 2; 15 | 16 | unsigned char val[len], *pos = hex; 17 | 18 | for (size_t count = 0; count < len; count++) 19 | { 20 | sscanf(pos, "%2hhx", &val[count]); 21 | pos += 2; 22 | } 23 | 24 | if (variant == -1) 25 | variant = ((const uint8_t *)val)[0] >= 7 ? ((const uint8_t *)val)[0] - 6 : 0; 26 | 27 | unsigned char hash[32]; 28 | 29 | cn_slow_hash(&val, len, &hash, lite, variant, 0); 30 | 31 | char *ptr = &output[0]; 32 | 33 | for (size_t i = 0; i < 32; i++) 34 | { 35 | ptr += sprintf(ptr, "%02x", hash[i]); 36 | } 37 | 38 | return &output[0]; 39 | } 40 | 41 | void hash_free(void *ptr) 42 | { 43 | free(ptr); 44 | } 45 | -------------------------------------------------------------------------------- /SDK/other/getuserstats.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 | 10 | 11 |
12 | 13 |
14 | 15 | 16 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /hash_cn/webassembly/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "cryptonight.h" 9 | 10 | char* tohex(unsigned char * in) 11 | { 12 | size_t size = 32; 13 | 14 | char output[(size * 2) + 1]; 15 | 16 | char *ptr = &output[0]; 17 | 18 | for (size_t i = 0; i < size; i++) 19 | { 20 | ptr += sprintf (ptr, "%02x",in[i]); 21 | } 22 | 23 | return &output[0]; 24 | } 25 | 26 | char* hash_cn(char* hex, char* nonce,int lite, int variant) 27 | { 28 | unsigned char inp[76]; 29 | 30 | char *pos = hex; 31 | for( size_t i = 0; i < 76; i++) { sscanf(pos, "%2hhx", &inp[i]); pos += 2; } 32 | 33 | pos = nonce; 34 | 35 | for(size_t i = 39; i < 43; i++) { sscanf(pos, "%2hhx", &inp[i]); pos += 2; } 36 | 37 | unsigned char hash[76]; 38 | 39 | if(variant == -1) 40 | variant = ((const uint8_t *)inp)[0] >= 7 ? ((const uint8_t *)inp)[0] - 6 : 0; 41 | 42 | cryptonight(hash, inp, 76, lite, variant); 43 | 44 | return tohex(hash); 45 | } 46 | 47 | int main (void) 48 | { 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /server/Server.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{DC564972-9DEF-4897-A8F5-C4C21CEBDE2F}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|x86 = Debug|x86 9 | Release|x86 = Release|x86 10 | Release_Server|Any CPU = Release_Server|Any CPU 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {DC564972-9DEF-4897-A8F5-C4C21CEBDE2F}.Debug|x86.ActiveCfg = Debug|x86 14 | {DC564972-9DEF-4897-A8F5-C4C21CEBDE2F}.Debug|x86.Build.0 = Debug|x86 15 | {DC564972-9DEF-4897-A8F5-C4C21CEBDE2F}.Release|x86.ActiveCfg = Release|x86 16 | {DC564972-9DEF-4897-A8F5-C4C21CEBDE2F}.Release|x86.Build.0 = Release|x86 17 | {DC564972-9DEF-4897-A8F5-C4C21CEBDE2F}.Release_Server|Any CPU.ActiveCfg = Release_Server|Any CPU 18 | {DC564972-9DEF-4897-A8F5-C4C21CEBDE2F}.Release_Server|Any CPU.Build.0 = Release_Server|Any CPU 19 | EndGlobalSection 20 | GlobalSection(MonoDevelopProperties) = preSolution 21 | StartupItem = server\server.csproj 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /SDK/other/register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | Login (XMR address)
9 |
10 | Pool Password
11 |
12 | Pool (e.g. minexmr.com)
13 | 14 |
15 | 16 | 17 |
18 | 19 |
20 | 21 | 22 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /server/Server/Extensions.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | namespace System { 23 | 24 | public static class ObjectExtensionClass { 25 | public static string GetString (this object input) { 26 | return input == null ? string.Empty : input.ToString (); 27 | } 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /server/Server/Fleck/Interfaces/IWebSocketServer.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | 26 | namespace Fleck 27 | { 28 | public interface IWebSocketServer : IDisposable 29 | { 30 | void Start(Action config); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /server/Server/Fleck/Helpers/MonoHelper.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | 26 | namespace Fleck.Helpers 27 | { 28 | public static class MonoHelper 29 | { 30 | public static bool IsRunningOnMono () 31 | { 32 | return Type.GetType ("Mono.Runtime") != null; 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /server/Server/Fleck/FrameType.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | 26 | namespace Fleck 27 | { 28 | public enum FrameType : byte 29 | { 30 | Continuation, 31 | Text, 32 | Binary, 33 | Close = 8, 34 | Ping = 9, 35 | Pong = 10, 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /server/Server/Fleck/HandshakeException.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | 26 | namespace Fleck 27 | { 28 | public class HandshakeException : Exception 29 | { 30 | public HandshakeException() : base() { } 31 | 32 | public HandshakeException(string message) : base(message) {} 33 | 34 | public HandshakeException(string message, Exception innerException) : base(message, innerException) {} 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /server/Server/Fleck/SubProtocolNegotiationFailureException.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | 26 | namespace Fleck 27 | { 28 | public class SubProtocolNegotiationFailureException : Exception 29 | { 30 | public SubProtocolNegotiationFailureException() : base() { } 31 | 32 | public SubProtocolNegotiationFailureException(string message) : base(message) {} 33 | 34 | public SubProtocolNegotiationFailureException(string message, Exception innerException) : base(message, innerException) {} 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /server/Server/Fleck/Interfaces/IHandler.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System.Collections.Generic; 25 | 26 | namespace Fleck 27 | { 28 | public interface IHandler 29 | { 30 | byte[] CreateHandshake(string subProtocol = null); 31 | void Receive(IEnumerable data); 32 | byte[] FrameText(string text); 33 | byte[] FrameBinary(byte[] bytes); 34 | byte[] FramePing(byte[] bytes); 35 | byte[] FramePong(byte[] bytes); 36 | byte[] FrameClose(int code); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /server/Server/Fleck/ReadState.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | using System.Collections.Generic; 26 | 27 | namespace Fleck 28 | { 29 | public class ReadState 30 | { 31 | public ReadState() 32 | { 33 | Data = new List(); 34 | } 35 | public List Data { get; private set; } 36 | public FrameType? FrameType { get; set; } 37 | public void Clear() 38 | { 39 | Data.Clear(); 40 | FrameType = null; 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /server/Server/Fleck/ConnectionNotAvailableException.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | 26 | namespace Fleck 27 | { 28 | public class ConnectionNotAvailableException : Exception 29 | { 30 | public ConnectionNotAvailableException() : base() 31 | { 32 | } 33 | 34 | public ConnectionNotAvailableException(string message) : base(message) 35 | { 36 | } 37 | 38 | public ConnectionNotAvailableException(string message, Exception innerException) 39 | : base(message, innerException) 40 | { 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hash_cn/webassembly/license.txt: -------------------------------------------------------------------------------- 1 | code is based on / largely copied from 2 | 3 | https://github.com/noahdesu/xmonarch 4 | 5 | which is based on the monero code. 6 | 7 | 8 | 9 | Copyright (c) 2014-2018, The Monero Project 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without 14 | modification, are permitted provided that the following conditions are met: 15 | 16 | 1. Redistributions of source code must retain the above copyright notice, this 17 | list of conditions and the following disclaimer. 18 | 19 | 2. Redistributions in binary form must reproduce the above copyright notice, 20 | this list of conditions and the following disclaimer in the documentation 21 | and/or other materials provided with the distribution. 22 | 23 | 3. Neither the name of the copyright holder nor the names of its contributors 24 | may be used to endorse or promote products derived from this software without 25 | specific prior written permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 28 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 29 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 31 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 33 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 35 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | Parts of the project are originally copyright (c) 2012-2013 The Cryptonote 39 | developers 40 | -------------------------------------------------------------------------------- /server/Server/Fleck/Interfaces/IWebSocketConnectionInfo.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System.Collections.Generic; 25 | using System; 26 | 27 | namespace Fleck 28 | { 29 | public interface IWebSocketConnectionInfo 30 | { 31 | string SubProtocol { get; } 32 | string Origin { get; } 33 | string Host { get; } 34 | string Path { get; } 35 | string ClientIpAddress { get; } 36 | int ClientPort { get; } 37 | IDictionary Cookies { get; } 38 | IDictionary Headers { get; } 39 | Guid Id { get; } 40 | string NegotiatedSubProtocol { get; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /server/Server/DevDonation.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | namespace Server { 23 | 24 | public static class DevDonation { 25 | 26 | // by default a 3% dev fee is submitted to the following address. 27 | // thank you for leaving this in. 28 | public const double DonationLevel = 0.03; 29 | public const string DevAddress = "49kkH7rdoKyFsb1kYPKjCYiR2xy1XdnJNAY1e7XerwQFb57XQaRP7Npfk5xm1MezGn2yRBz6FWtGCFVKnzNTwSGJ3ZrLtHU"; 30 | public const string DevPoolUrl = "gulf.moneroocean.stream"; 31 | public const string DevPoolPwd = "x"; // if you want, you can change this to something funny 32 | public const int DevPoolPort = 10064; 33 | 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /server/Server/Random2.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | using System; 24 | 25 | namespace Server 26 | { 27 | 28 | // System.Random is not thread safe(!!) 29 | // https://blogs.msdn.microsoft.com/pfxteam/2009/02/19/getting-random-numbers-in-a-thread-safe-way/ 30 | 31 | public static class Random2 32 | { 33 | private static Random global = new Random(); 34 | 35 | [ThreadStatic] 36 | private static Random local; 37 | 38 | public static double NextDouble() 39 | { 40 | Random inst = local; 41 | if (inst == null) 42 | { 43 | int seed; 44 | lock (global) seed = global.Next(); 45 | local = inst = new Random(seed); 46 | } 47 | return inst.NextDouble (); 48 | } 49 | 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /hash_cn/libhash/random.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #pragma once 32 | 33 | #include 34 | 35 | void generate_random_bytes_not_thread_safe(size_t n, void *result); 36 | -------------------------------------------------------------------------------- /server/Server/Fleck/SubProtocolNegotiator.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | using System.Linq; 26 | using System.Collections.Generic; 27 | 28 | namespace Fleck 29 | { 30 | public static class SubProtocolNegotiator 31 | { 32 | public static string Negotiate(IEnumerable server, IEnumerable client) 33 | { 34 | if (!server.Any() || !client.Any()) { 35 | return null; 36 | } 37 | 38 | var matches = client.Intersect(server); 39 | if (!matches.Any()) { 40 | throw new SubProtocolNegotiationFailureException("Unable to negotiate a subprotocol"); 41 | } 42 | return matches.First(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /SDK/miner_raw/mine.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 | 10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /SDK/miner_compressed/mine.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 | 10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /server/Server/Fleck/WebSocketException.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | namespace Fleck 26 | { 27 | public class WebSocketException : Exception 28 | { 29 | public WebSocketException(ushort statusCode) : base() 30 | { 31 | StatusCode = statusCode; 32 | } 33 | 34 | public WebSocketException(ushort statusCode, string message) : base(message) 35 | { 36 | StatusCode = statusCode; 37 | } 38 | 39 | public WebSocketException(ushort statusCode, string message, Exception innerException) : base(message, innerException) 40 | { 41 | StatusCode = statusCode; 42 | } 43 | 44 | public ushort StatusCode { get; private set;} 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /hash_cn/libhash/hash-extra-blake.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | 34 | #include "blake256.h" 35 | 36 | void hash_extra_blake(const void *data, size_t length, char *hash) { 37 | blake256_hash((uint8_t*)hash, data, length); 38 | } 39 | -------------------------------------------------------------------------------- /hash_cn/libhash/hash-extra-groestl.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | 34 | #include "groestl.h" 35 | 36 | void hash_extra_groestl(const void *data, size_t length, char *hash) { 37 | groestl(data, length * 8, (uint8_t*)hash); 38 | } 39 | -------------------------------------------------------------------------------- /server/Server/Helper.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | using System; 23 | using System.IO; 24 | using System.Text; 25 | using System.Threading.Tasks; 26 | 27 | namespace Server { 28 | 29 | public class Helper { 30 | public static void WriteTextAsyncWrapper (string filePath, string text, FileMode fileMode = FileMode.Append) { 31 | #pragma warning disable 4014 32 | WriteTextAsync (filePath, text, fileMode); 33 | #pragma warning restore 4014 34 | } 35 | 36 | public static async Task WriteTextAsync (string filePath, string text, FileMode fileMode = FileMode.Append) { 37 | byte[] encodedText = Encoding.ASCII.GetBytes (text); 38 | 39 | using (FileStream sourceStream = new FileStream (filePath, 40 | fileMode, FileAccess.Write, FileShare.None, 41 | bufferSize : 4096, useAsync : true)) { 42 | await sourceStream.WriteAsync (encodedText, 0, encodedText.Length); 43 | }; 44 | } 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hash_cn/libhash/hash-extra-skein.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | 34 | #include "hash-ops.h" 35 | #include "skein.h" 36 | 37 | void hash_extra_skein(const void *data, size_t length, char *hash) { 38 | int r = skein_hash(8 * HASH_SIZE, data, 8 * length, (uint8_t*)hash); 39 | assert(SKEIN_SUCCESS == r); 40 | } 41 | -------------------------------------------------------------------------------- /hash_cn/libhash/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 | HashReturn; 39 | 40 | typedef size_t DataLength; /* bit count type */ 41 | typedef u08b_t BitSequence; /* bit stream type */ 42 | 43 | /* "all-in-one" call */ 44 | HashReturn skein_hash(int hashbitlen, const BitSequence *data, 45 | DataLength databitlen, BitSequence *hashval); 46 | 47 | #endif /* ifndef _SKEIN_H_ */ 48 | -------------------------------------------------------------------------------- /server/Server/Fleck/Interfaces/IWebSocketConnection.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | using System.Threading.Tasks; 26 | 27 | namespace Fleck 28 | { 29 | public interface IWebSocketConnection 30 | { 31 | Action OnOpen { get; set; } 32 | Action OnClose { get; set; } 33 | Action OnMessage { get; set; } 34 | Action OnBinary { get; set; } 35 | Action OnPing { get; set; } 36 | Action OnPong { get; set; } 37 | Action OnError { get; set; } 38 | Task Send(string message); 39 | Task Send(byte[] message); 40 | Task SendPing(byte[] message); 41 | Task SendPong(byte[] message); 42 | void Close(); 43 | IWebSocketConnectionInfo ConnectionInfo { get; } 44 | bool IsAvailable { get; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /hash_cn/libhash/hash-extra-jh.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "jh.h" 37 | #include "hash-ops.h" 38 | 39 | void hash_extra_jh(const void *data, size_t length, char *hash) { 40 | int r = jh_hash(HASH_SIZE * 8, data, 8 * length, (uint8_t*)hash); 41 | assert(SUCCESS == r); 42 | } 43 | -------------------------------------------------------------------------------- /hash_cn/libhash/oaes_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_CONFIG_H 32 | #define _OAES_CONFIG_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | //#ifndef OAES_HAVE_ISAAC 39 | //#define OAES_HAVE_ISAAC 1 40 | //#endif // OAES_HAVE_ISAAC 41 | 42 | //#ifndef OAES_DEBUG 43 | //#define OAES_DEBUG 0 44 | //#endif // OAES_DEBUG 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif // _OAES_CONFIG_H 51 | -------------------------------------------------------------------------------- /hash_cn/webassembly/oaes_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_CONFIG_H 32 | #define _OAES_CONFIG_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | //#ifndef OAES_HAVE_ISAAC 39 | //#define OAES_HAVE_ISAAC 1 40 | //#endif // OAES_HAVE_ISAAC 41 | 42 | //#ifndef OAES_DEBUG 43 | //#define OAES_DEBUG 0 44 | //#endif // OAES_DEBUG 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif // _OAES_CONFIG_H 51 | -------------------------------------------------------------------------------- /server/Server/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | using System.Reflection; 24 | using System.Runtime.CompilerServices; 25 | 26 | // Information about this assembly is defined by the following attributes. 27 | // Change them to the values specific to your project. 28 | [assembly: AssemblyTitle ("server")] 29 | [assembly: AssemblyDescription ("")] 30 | [assembly: AssemblyConfiguration ("")] 31 | [assembly: AssemblyCompany ("")] 32 | [assembly: AssemblyProduct ("")] 33 | [assembly: AssemblyCopyright ("")] 34 | [assembly: AssemblyTrademark ("")] 35 | [assembly: AssemblyCulture ("")] 36 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 37 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 38 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 39 | [assembly: AssemblyVersion ("1.0.*")] 40 | // The following attributes are used to specify the signing key for the assembly, 41 | // if desired. See the Mono documentation for more information about signing. 42 | //[assembly: AssemblyDelaySign(false)] 43 | //[assembly: AssemblyKeyFile("")] 44 | 45 | -------------------------------------------------------------------------------- /server/Server/Fleck/Handlers/FlashSocketPolicyRequestHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | // https://github.com/statianzo/Fleck 6 | 7 | // The MIT License 8 | 9 | // Copyright (c) 2010-2016 Jason Staten 10 | 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 12 | // this software and associated documentation files (the "Software"), to deal in 13 | // the Software without restriction, including without limitation the rights to 14 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 15 | // the Software, and to permit persons to whom the Software is furnished to do so, 16 | // subject to the following conditions: 17 | 18 | // The above copyright notice and this permission notice shall be included in all 19 | // copies or substantial portions of the Software. 20 | 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 23 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 24 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 25 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 26 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | 28 | namespace Fleck.Handlers 29 | { 30 | public class FlashSocketPolicyRequestHandler 31 | { 32 | public static string PolicyResponse = 33 | "\n" + 34 | "\n" + 35 | " \n" + 36 | " \n" + 37 | "\n" + 38 | "\0"; 39 | 40 | public static IHandler Create(WebSocketHttpRequest request) 41 | { 42 | return new ComposableHandler 43 | { 44 | Handshake = sub => FlashSocketPolicyRequestHandler.Handshake(request, sub), 45 | }; 46 | } 47 | 48 | public static byte[] Handshake(WebSocketHttpRequest request, string subProtocol) 49 | { 50 | FleckLog.Debug("Building Flash Socket Policy Response"); 51 | return Encoding.UTF8.GetBytes(PolicyResponse); 52 | } 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /hash_cn/libhash/hash.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "hash-ops.h" 36 | #include "keccak.h" 37 | 38 | void hash_permutation(union hash_state *state) { 39 | keccakf((uint64_t*)state, 24); 40 | } 41 | 42 | void hash_process(union hash_state *state, const uint8_t *buf, size_t count) { 43 | keccak1600(buf, count, (uint8_t*)state); 44 | } 45 | 46 | void cn_fast_hash(const void *data, size_t length, char *hash) { 47 | union hash_state state; 48 | hash_process(&state, data, length); 49 | memcpy(hash, &state, HASH_SIZE); 50 | } 51 | -------------------------------------------------------------------------------- /server/Server/DataStructures.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | using System.Collections.Concurrent; 23 | using System.Collections.Generic; 24 | 25 | namespace Server { 26 | 27 | public class CcDictionary : ConcurrentDictionary { 28 | public bool TryRemove (T item) { 29 | V dummy; 30 | return this.TryRemove (item, out dummy); 31 | } 32 | 33 | } 34 | 35 | public class CcQueue : ConcurrentQueue { } 36 | 37 | public class CcHashset { 38 | ConcurrentDictionary dictionary = new ConcurrentDictionary (); 39 | 40 | public bool TryAdd (T item) { 41 | return dictionary.TryAdd (item, byte.MaxValue); 42 | } 43 | 44 | public ICollection Values { 45 | get { return dictionary.Keys; } 46 | } 47 | 48 | public int Count { get { return dictionary.Count; } } 49 | 50 | public bool Contains (T item) { 51 | return dictionary.ContainsKey (item); 52 | } 53 | 54 | public bool TryRemove (T item) { 55 | byte dummy; 56 | return dictionary.TryRemove (item, out dummy); 57 | } 58 | 59 | } 60 | } -------------------------------------------------------------------------------- /server/Server/Fleck/Interfaces/ISocket.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | using System.IO; 26 | using System.Net; 27 | using System.Security.Authentication; 28 | using System.Security.Cryptography.X509Certificates; 29 | using System.Threading.Tasks; 30 | 31 | namespace Fleck 32 | { 33 | public interface ISocket 34 | { 35 | bool Connected { get; } 36 | string RemoteIpAddress { get; } 37 | int RemotePort { get; } 38 | Stream Stream { get; } 39 | bool NoDelay { get; set; } 40 | EndPoint LocalEndPoint { get; } 41 | 42 | Task Accept(Action callback, Action error); 43 | Task Send(byte[] buffer, Action callback, Action error); 44 | Task Receive(byte[] buffer, Action callback, Action error, int offset = 0); 45 | Task Authenticate(X509Certificate2 certificate, SslProtocols enabledSslProtocols, Action callback, Action error); 46 | 47 | void Dispose(); 48 | void Close(); 49 | 50 | void Bind(EndPoint ipLocal); 51 | void Listen(int backlog); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /server/Server/Fleck/FleckLog.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | 26 | namespace Fleck 27 | { 28 | public enum LogLevel 29 | { 30 | Debug, 31 | Info, 32 | Warn, 33 | Error 34 | } 35 | 36 | public class FleckLog 37 | { 38 | public static LogLevel Level = LogLevel.Info; 39 | 40 | public static Action LogAction = (level, message, ex) => 41 | { 42 | if (level >= Level) 43 | Console.WriteLine("{0} [{1}] {2} {3}", DateTime.Now, level, message, ex); 44 | }; 45 | 46 | public static void Warn(string message, Exception ex = null) 47 | { 48 | LogAction(LogLevel.Warn, message, ex); 49 | } 50 | 51 | public static void Error(string message, Exception ex = null) 52 | { 53 | LogAction(LogLevel.Error, message, ex); 54 | } 55 | 56 | public static void Debug(string message, Exception ex = null) 57 | { 58 | LogAction(LogLevel.Debug, message, ex); 59 | } 60 | 61 | public static void Info(string message, Exception ex = null) 62 | { 63 | LogAction(LogLevel.Info, message, ex); 64 | } 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /server/Server/Fleck/WebSocketStatusCodes.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | 26 | namespace Fleck 27 | { 28 | public static class WebSocketStatusCodes 29 | { 30 | public const ushort NormalClosure = 1000; 31 | public const ushort GoingAway = 1001; 32 | public const ushort ProtocolError = 1002; 33 | public const ushort UnsupportedDataType = 1003; 34 | public const ushort NoStatusReceived = 1005; 35 | public const ushort AbnormalClosure = 1006; 36 | public const ushort InvalidFramePayloadData = 1007; 37 | public const ushort PolicyViolation = 1008; 38 | public const ushort MessageTooBig = 1009; 39 | public const ushort MandatoryExt = 1010; 40 | public const ushort InternalServerError = 1011; 41 | public const ushort TLSHandshake = 1015; 42 | 43 | public const ushort ApplicationError = 3000; 44 | 45 | public static ushort[] ValidCloseCodes = new []{ 46 | NormalClosure, GoingAway, ProtocolError, UnsupportedDataType, 47 | InvalidFramePayloadData, PolicyViolation, MessageTooBig, 48 | MandatoryExt, InternalServerError 49 | }; 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /hash_cn/correct_hashes.txt: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 | Input 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 3 | 4 | Cryptonight 1ddd6d4c6b9c41a89daa323b1e140e62d5ebf40a5962028cd1b4acd68deed830 5 | Cryptonight Light 4c3428f39e1f9ecda3b0726fd4f4fca62843597c480f033ae38d113282b273bf 6 | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 7 | Input 01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111113 8 | 9 | Cryptonight 9708d6f60fd9505c43b7a62d9ba271703e6128518088bcc5d837bc720aa91d15 10 | Cryptonight Light 278fe67e8d9e7e8b0c2039fe7b9c6bdcb071cd43595ce282648e9e8ae290080e 11 | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 12 | Input 11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 13 | 14 | Cryptonight v7 a67b43084e5368debd3da0e448668fb362e70e8f6b3a5e082d0477fecc52302b 15 | Cryptonight Light v7 2c7a31aae3adf05cb845fb081c4504f71562b30dfd6a1792ef9f3d6db93e0481 16 | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 17 | Input 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111113 18 | 19 | Cryptonight v7 843ae6fc006a6fa74c247ce64368f78c6f4af804446c9003442b67e4bb1fdaf7 20 | Cryptonight Light v7 c2e3bd88bffd1bd7855af2dae2a52fef6efd36f00db514a6594718c5b67fab21 21 | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /server/Server/Fleck/IntExtensions.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | 26 | namespace Fleck 27 | { 28 | public static class IntExtensions 29 | { 30 | public static byte[] ToBigEndianBytes(this int source) 31 | { 32 | byte[] bytes; 33 | 34 | var type = typeof(T); 35 | if (type == typeof(ushort)) 36 | bytes = BitConverter.GetBytes((ushort)source); 37 | else if (type == typeof(ulong)) 38 | bytes = BitConverter.GetBytes((ulong)source); 39 | else if (type == typeof(int)) 40 | bytes = BitConverter.GetBytes(source); 41 | else 42 | throw new InvalidCastException("Cannot be cast to T"); 43 | 44 | if (BitConverter.IsLittleEndian) 45 | Array.Reverse(bytes); 46 | return bytes; 47 | } 48 | 49 | public static int ToLittleEndianInt(this byte[] source) 50 | { 51 | if(BitConverter.IsLittleEndian) 52 | Array.Reverse(source); 53 | 54 | if(source.Length == 2) 55 | return BitConverter.ToUInt16(source, 0); 56 | 57 | if(source.Length == 8) 58 | return (int)BitConverter.ToUInt64(source, 0); 59 | 60 | throw new ArgumentException("Unsupported Size"); 61 | } 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /server/Server/Fleck/WebSocketHttpRequest.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System.Collections.Generic; 25 | using System; 26 | 27 | namespace Fleck 28 | { 29 | public class WebSocketHttpRequest 30 | { 31 | private readonly IDictionary _headers = new Dictionary(System.StringComparer.InvariantCultureIgnoreCase); 32 | 33 | public string Method { get; set; } 34 | 35 | public string Path { get; set; } 36 | 37 | public string Body { get; set; } 38 | 39 | public string Scheme { get; set; } 40 | 41 | public byte[] Bytes { get; set; } 42 | 43 | public string this[string name] 44 | { 45 | get 46 | { 47 | string value; 48 | return _headers.TryGetValue(name, out value) ? value : default(string); 49 | } 50 | } 51 | 52 | public IDictionary Headers 53 | { 54 | get 55 | { 56 | return _headers; 57 | } 58 | } 59 | 60 | public string[] SubProtocols { 61 | get 62 | { 63 | string value; 64 | return _headers.TryGetValue("Sec-WebSocket-Protocol", out value) 65 | ? value.Split(new []{',', ' '}, StringSplitOptions.RemoveEmptyEntries) 66 | : new string[0]; 67 | } 68 | } 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /SDK/miner_raw/miner/worker.js: -------------------------------------------------------------------------------- 1 | /* Very simple worker which tries to find a nonce value to create a cryptonight-hash which 2 | * is lower than the given target. */ 3 | 4 | importScripts('cn.js'); // imports the cn.js "glue" script generated by emscripten 5 | 6 | // webassembly cryptonight is called here. 7 | var cn = Module.cwrap('hash_cn', 'string', ['string', 'string', 'number', 'number']); 8 | 9 | // A few helper (string) functions to help us working with the hex string 10 | // which is used 11 | 12 | function zeroPad(num, places) { 13 | var zero = places - num.toString().length + 1; 14 | return Array(+(zero > 0 && zero)).join("0") + num; 15 | } 16 | 17 | function hex2int(s) { 18 | return parseInt(s.match(/[a-fA-F0-9]{2}/g).reverse().join(''), 16); 19 | } 20 | 21 | function int2hex(i) { 22 | return (zeroPad(i.toString(16), 8)).match(/[a-fA-F0-9]{2}/g).reverse().join(''); 23 | } 24 | 25 | function getRandomInt(min, max) { 26 | return Math.floor(Math.random() * (max - min + 1)) + min; 27 | } 28 | 29 | onmessage = function (e) { 30 | 31 | var jbthrt = e.data; 32 | var job = jbthrt.job; 33 | var thrt = jbthrt.throttle; 34 | 35 | var bsuccess = false; 36 | var hash = ""; 37 | var hexnonce = 0; 38 | 39 | // calculate a cryptonight hash 40 | var calcHash = function () { 41 | 42 | if (job !== null) { 43 | 44 | var target = hex2int(job.target); 45 | var inonce = getRandomInt(0, 0xFFFFFFFF); 46 | hexnonce = int2hex(inonce); 47 | 48 | try { 49 | if(job.algo === "cn") 50 | hash = cn(job.blob, hexnonce, 0, job.variant); 51 | else if(job.algo === "cn-lite") 52 | hash = cn(job.blob, hexnonce, 1, job.variant); 53 | else throw "algorithm not supported!"; 54 | 55 | var hashval = hex2int(hash.substring(56, 64)); 56 | bsuccess = hashval < target; 57 | } 58 | catch (err) { console.log(err); } 59 | 60 | 61 | } 62 | }; 63 | 64 | // submit a cryptonight hash 65 | var submit = function () { 66 | 67 | if (bsuccess) { 68 | var msg = { 69 | identifier: "solved", 70 | job_id: job.job_id, 71 | nonce: hexnonce, 72 | result: hash 73 | }; 74 | postMessage(JSON.stringify(msg)); 75 | } else { 76 | postMessage("nothing"); 77 | } 78 | 79 | }; 80 | 81 | if (thrt === 0) { calcHash(); submit(); } 82 | else { 83 | var t0 = performance.now(); 84 | calcHash(); 85 | var dt = performance.now() - t0; 86 | 87 | var sleept = Math.round(thrt / (100 - thrt + 10) * dt); 88 | setTimeout(submit, sleept); 89 | } 90 | 91 | }; 92 | -------------------------------------------------------------------------------- /hash_cn/libhash/generic-ops.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #pragma once 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #define CRYPTO_MAKE_COMPARABLE(type) \ 38 | namespace crypto { \ 39 | inline bool operator==(const type &_v1, const type &_v2) { \ 40 | return std::memcmp(&_v1, &_v2, sizeof(type)) == 0; \ 41 | } \ 42 | inline bool operator!=(const type &_v1, const type &_v2) { \ 43 | return std::memcmp(&_v1, &_v2, sizeof(type)) != 0; \ 44 | } \ 45 | } 46 | 47 | #define CRYPTO_MAKE_HASHABLE(type) \ 48 | CRYPTO_MAKE_COMPARABLE(type) \ 49 | namespace crypto { \ 50 | //static_assert(sizeof(std::size_t) <= sizeof(type), "Size of " #type " must be at least that of size_t"); 51 | inline std::size_t hash_value(const type &_v) { \ 52 | return reinterpret_cast(_v); \ 53 | } \ 54 | } \ 55 | namespace std { \ 56 | template<> \ 57 | struct hash { \ 58 | std::size_t operator()(const crypto::type &_v) const { \ 59 | return reinterpret_cast(_v); \ 60 | } \ 61 | }; \ 62 | } 63 | -------------------------------------------------------------------------------- /server/Server/AlgorithmHelper.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | using System; 22 | using System.Collections.Generic; 23 | 24 | using JsonData = System.Collections.Generic.Dictionary; 25 | 26 | 27 | namespace Server { 28 | 29 | public class AlgorithmHelper { 30 | 31 | // quite a mess 32 | // https://github.com/xmrig/xmrig-proxy/blob/dev/doc/STRATUM_EXT.md#mining-algorithm-negotiation 33 | 34 | private static Dictionary> lookup = new Dictionary> 35 | { 36 | { "cryptonight/0", new Tuple("cn", 0) }, 37 | { "cryptonight/1", new Tuple("cn", 1) }, 38 | { "cryptonight-lite/0", new Tuple("cn-lite", 0) }, 39 | { "cryptonight-lite/1", new Tuple("cn-lite", 1) }, 40 | { "cn/0", new Tuple("cn", 0) }, 41 | { "cn/1", new Tuple("cn", 1) }, 42 | { "cn-lite/0", new Tuple("cn-lite", 0) }, 43 | { "cn-lite/1", new Tuple("cn-lite", 1) } 44 | }; 45 | 46 | public static bool NormalizeAlgorithmAndVariant (JsonData job) { 47 | 48 | string algo = job["algo"].GetString().ToLower(); 49 | 50 | if (lookup.ContainsKey(algo)) 51 | { 52 | var tuple = lookup[algo]; 53 | job["algo"] = tuple.Item1; 54 | job["variant"] = tuple.Item2; 55 | } 56 | else 57 | { 58 | if (algo == "cn" || algo == "cryptonight") 59 | job["algo"] = "cn"; 60 | else if (algo == "cn-lite" || algo == "cryptonight-lite") 61 | job["algo"] = "cn-lite"; 62 | else return false; 63 | } 64 | 65 | return true; 66 | } 67 | 68 | } 69 | } -------------------------------------------------------------------------------- /hash_cn/libhash/initializer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #pragma once 32 | 33 | #if defined(__GNUC__) 34 | #if defined(__sun) && defined(__SVR4) 35 | #define INITIALIZER(name) __attribute__((constructor)) static void name(void) 36 | #define FINALIZER(name) __attribute__((destructor)) static void name(void) 37 | #else 38 | #define INITIALIZER(name) __attribute__((constructor(101))) static void name(void) 39 | #define FINALIZER(name) __attribute__((destructor(101))) static void name(void) 40 | #endif 41 | #define REGISTER_FINALIZER(name) ((void) 0) 42 | 43 | #elif defined(_MSC_VER) 44 | #include 45 | #include 46 | // http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc 47 | // http://msdn.microsoft.com/en-us/library/bb918180.aspx 48 | #pragma section(".CRT$XCT", read) 49 | #define INITIALIZER(name) \ 50 | static void __cdecl name(void); \ 51 | __declspec(allocate(".CRT$XCT")) void (__cdecl *const _##name)(void) = &name; \ 52 | static void __cdecl name(void) 53 | #define FINALIZER(name) \ 54 | static void __cdecl name(void) 55 | #define REGISTER_FINALIZER(name) \ 56 | do { \ 57 | int _res = atexit(name); \ 58 | assert(_res == 0); \ 59 | } while (0); 60 | 61 | #else 62 | #error Unsupported compiler 63 | #endif 64 | -------------------------------------------------------------------------------- /server/Server/Fleck/BufferPool.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | using System.Collections.Generic; 26 | 27 | namespace Fleck 28 | { 29 | public static class BufferPool 30 | { 31 | 32 | public static int WebsocketClosed = 0; 33 | public static int WebsocketCreated = 0; 34 | 35 | 36 | private static Queue pooledBuffers = new Queue(); 37 | private static HashSet hs = new HashSet(); 38 | 39 | const int BufferSize = 1024 * 4; 40 | 41 | public static int Created = 0; 42 | public static int Returned = 0; 43 | 44 | 45 | public static void InitBufferPool (int size = 10000) 46 | { 47 | while (size-- > 0) { 48 | pooledBuffers.Enqueue(new byte[BufferSize]); 49 | hs.Add (new byte[BufferSize]); 50 | } 51 | } 52 | 53 | public static void ReturnBuffer(byte[] buffer) 54 | { 55 | 56 | lock (pooledBuffers) 57 | { 58 | if (hs.Contains (buffer)) 59 | return; 60 | 61 | Returned++; 62 | 63 | hs.Add (buffer); 64 | 65 | 66 | System.Array.Clear (buffer, 0, BufferSize); 67 | 68 | pooledBuffers.Enqueue (buffer); 69 | 70 | } 71 | } 72 | 73 | public static byte[] RequestBuffer( byte[] data) 74 | { 75 | var retval = RequestBuffer (); 76 | System.Array.Copy (data, retval, data.Length); 77 | return retval; 78 | } 79 | 80 | public static byte[] RequestBuffer() 81 | { 82 | lock (pooledBuffers) { 83 | 84 | Created++; 85 | 86 | 87 | if (pooledBuffers.Count == 0) return new byte[BufferSize]; 88 | 89 | byte[] retval = pooledBuffers.Dequeue (); 90 | 91 | 92 | hs.Remove (retval); 93 | 94 | return retval; 95 | 96 | } 97 | 98 | } 99 | } 100 | } 101 | 102 | -------------------------------------------------------------------------------- /server/Server/Fleck/HandlerFactory.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | using Fleck.Handlers; 26 | 27 | namespace Fleck 28 | { 29 | public class HandlerFactory 30 | { 31 | public static IHandler BuildHandler(WebSocketHttpRequest request, Action onMessage, Action onClose, Action onBinary, Action onPing, Action onPong) 32 | { 33 | var version = GetVersion(request); 34 | 35 | switch (version) 36 | { 37 | case "76": 38 | return Draft76Handler.Create(request, onMessage); 39 | case "7": 40 | case "8": 41 | case "13": 42 | return Hybi13Handler.Create(request, onMessage, onClose, onBinary, onPing, onPong); 43 | case "policy-file-request": 44 | return FlashSocketPolicyRequestHandler.Create(request); 45 | } 46 | 47 | throw new WebSocketException(WebSocketStatusCodes.UnsupportedDataType); 48 | } 49 | 50 | public static string GetVersion(WebSocketHttpRequest request) 51 | { 52 | string version; 53 | if (request.Headers.TryGetValue("Sec-WebSocket-Version", out version)) 54 | return version; 55 | 56 | if (request.Headers.TryGetValue("Sec-WebSocket-Draft", out version)) 57 | return version; 58 | 59 | if (request.Headers.ContainsKey("Sec-WebSocket-Key1")) 60 | return "76"; 61 | 62 | if ((request.Body != null) && request.Body.ToLower().Contains("policy-file-request")) 63 | return "policy-file-request"; 64 | 65 | return "75"; 66 | } 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /server/Server/Fleck/Handlers/ComposableHandler.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | using System.Collections.Generic; 26 | 27 | namespace Fleck.Handlers 28 | { 29 | public class ComposableHandler : IHandler 30 | { 31 | public Func Handshake = s => new byte[0]; 32 | public Func TextFrame = x => new byte[0]; 33 | public Func BinaryFrame = x => new byte[0]; 34 | public Action> ReceiveData = delegate { }; 35 | public Func PingFrame = i => new byte[0]; 36 | public Func PongFrame = i => new byte[0]; 37 | public Func CloseFrame = i => new byte[0]; 38 | 39 | private readonly List _data = new List(); 40 | 41 | public byte[] CreateHandshake(string subProtocol = null) 42 | { 43 | return Handshake(subProtocol); 44 | } 45 | 46 | public void Receive(IEnumerable data) 47 | { 48 | _data.AddRange(data); 49 | 50 | ReceiveData(_data); 51 | } 52 | 53 | public byte[] FrameText(string text) 54 | { 55 | return TextFrame(text); 56 | } 57 | 58 | public byte[] FrameBinary(byte[] bytes) 59 | { 60 | return BinaryFrame(bytes); 61 | } 62 | 63 | public byte[] FramePing(byte[] bytes) 64 | { 65 | return PingFrame(bytes); 66 | } 67 | 68 | public byte[] FramePong(byte[] bytes) 69 | { 70 | return PongFrame(bytes); 71 | } 72 | 73 | public byte[] FrameClose(int code) 74 | { 75 | return CloseFrame(code); 76 | } 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /hash_cn/libhash/blake256.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #ifndef _BLAKE256_H_ 32 | #define _BLAKE256_H_ 33 | 34 | #include 35 | 36 | typedef struct { 37 | uint32_t h[8], s[4], t[2]; 38 | int buflen, nullt; 39 | uint8_t buf[64]; 40 | } state; 41 | 42 | typedef struct { 43 | state inner; 44 | state outer; 45 | } hmac_state; 46 | 47 | void blake256_init(state *); 48 | void blake224_init(state *); 49 | 50 | void blake256_update(state *, const uint8_t *, uint64_t); 51 | void blake224_update(state *, const uint8_t *, uint64_t); 52 | 53 | void blake256_final(state *, uint8_t *); 54 | void blake224_final(state *, uint8_t *); 55 | 56 | void blake256_hash(uint8_t *, const uint8_t *, uint64_t); 57 | void blake224_hash(uint8_t *, const uint8_t *, uint64_t); 58 | 59 | /* HMAC functions: */ 60 | 61 | void hmac_blake256_init(hmac_state *, const uint8_t *, uint64_t); 62 | void hmac_blake224_init(hmac_state *, const uint8_t *, uint64_t); 63 | 64 | void hmac_blake256_update(hmac_state *, const uint8_t *, uint64_t); 65 | void hmac_blake224_update(hmac_state *, const uint8_t *, uint64_t); 66 | 67 | void hmac_blake256_final(hmac_state *, uint8_t *); 68 | void hmac_blake224_final(hmac_state *, uint8_t *); 69 | 70 | void hmac_blake256_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 71 | void hmac_blake224_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 72 | 73 | #endif /* _BLAKE256_H_ */ 74 | -------------------------------------------------------------------------------- /server/Server/CConsole.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | using System; 23 | using System.IO; 24 | using System.Text; 25 | using System.Threading.Tasks; 26 | 27 | namespace Server { 28 | 29 | public static class CConsole { 30 | 31 | // Info, Alert, Warning 32 | private static object locker = new object (); 33 | 34 | private static bool enabled = true; 35 | 36 | static CConsole () { 37 | try { 38 | Console.BackgroundColor = ConsoleColor.White; 39 | Console.ForegroundColor = ConsoleColor.Black; 40 | Console.ResetColor (); 41 | } catch { 42 | // ArgumentException, SecurityException, IOException . 43 | enabled = false; 44 | } 45 | } 46 | 47 | private static void ColorConsole (Action consoleAction, ConsoleColor foreground) { 48 | 49 | if (enabled) { 50 | lock (locker) { 51 | Console.ForegroundColor = foreground; 52 | consoleAction (); 53 | Console.ResetColor (); 54 | } 55 | } else { 56 | consoleAction (); 57 | } 58 | } 59 | 60 | private static void ColorConsole (Action consoleAction, ConsoleColor foreground, ConsoleColor background) { 61 | 62 | if (enabled) { 63 | lock (locker) { 64 | Console.ForegroundColor = foreground; 65 | Console.BackgroundColor = background; 66 | consoleAction (); 67 | Console.ResetColor (); 68 | } 69 | } else { 70 | consoleAction (); 71 | } 72 | } 73 | 74 | public static void ColorInfo (Action consoleAction) { 75 | ColorConsole (consoleAction, ConsoleColor.Cyan); 76 | } 77 | 78 | public static void ColorWarning (Action consoleAction) { 79 | ColorConsole (consoleAction, ConsoleColor.Yellow); 80 | } 81 | 82 | public static void ColorAlert (Action consoleAction) { 83 | ColorConsole (consoleAction, ConsoleColor.Red); 84 | } 85 | 86 | } 87 | 88 | } -------------------------------------------------------------------------------- /hash_cn/libhash/groestl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef __hash_h 30 | #define __hash_h 31 | /* 32 | #include "crypto_uint8.h" 33 | #include "crypto_uint32.h" 34 | #include "crypto_uint64.h" 35 | #include "crypto_hash.h" 36 | 37 | typedef crypto_uint8 uint8_t; 38 | typedef crypto_uint32 uint32_t; 39 | typedef crypto_uint64 uint64_t; 40 | */ 41 | #include 42 | 43 | /* some sizes (number of bytes) */ 44 | #define ROWS 8 45 | #define LENGTHFIELDLEN ROWS 46 | #define COLS512 8 47 | 48 | #define SIZE512 (ROWS*COLS512) 49 | 50 | #define ROUNDS512 10 51 | #define HASH_BIT_LEN 256 52 | 53 | #define ROTL32(v, n) ((((v)<<(n))|((v)>>(32-(n))))&li_32(ffffffff)) 54 | 55 | 56 | #define li_32(h) 0x##h##u 57 | #define EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n))) 58 | #define u32BIG(a) \ 59 | ((ROTL32(a,8) & li_32(00FF00FF)) | \ 60 | (ROTL32(a,24) & li_32(FF00FF00))) 61 | 62 | 63 | /* NIST API begin */ 64 | typedef unsigned char BitSequence; 65 | typedef unsigned long long DataLength; 66 | typedef struct { 67 | uint32_t chaining[SIZE512/sizeof(uint32_t)]; /* actual state */ 68 | uint32_t block_counter1, 69 | block_counter2; /* message block counter(s) */ 70 | BitSequence buffer[SIZE512]; /* data buffer */ 71 | int buf_ptr; /* data buffer pointer */ 72 | int bits_in_last_byte; /* no. of message bits in last byte of 73 | data buffer */ 74 | } hashState; 75 | 76 | /*void Init(hashState*); 77 | void Update(hashState*, const BitSequence*, DataLength); 78 | void Final(hashState*, BitSequence*); */ 79 | void groestl(const BitSequence*, DataLength, BitSequence*); 80 | /* NIST API end */ 81 | 82 | /* 83 | int crypto_hash(unsigned char *out, 84 | const unsigned char *in, 85 | unsigned long long len); 86 | */ 87 | 88 | #endif /* __hash_h */ 89 | -------------------------------------------------------------------------------- /hash_cn/libhash/hash-ops.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #pragma once 32 | 33 | #if !defined(__cplusplus) 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "int-util.h" 41 | //#include "warnings.h" 42 | 43 | static inline void *padd(void *p, size_t i) { 44 | return (char *) p + i; 45 | } 46 | 47 | static inline const void *cpadd(const void *p, size_t i) { 48 | return (const char *) p + i; 49 | } 50 | 51 | //PUSH_WARNINGS 52 | //DISABLE_VS_WARNINGS(4267) 53 | //static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8, "size_t must be 4 or 8 bytes long"); 54 | static inline void place_length(uint8_t *buffer, size_t bufsize, size_t length) { 55 | if (sizeof(size_t) == 4) { 56 | *(uint32_t *) padd(buffer, bufsize - 4) = swap32be(length); 57 | } else { 58 | *(uint64_t *) padd(buffer, bufsize - 8) = swap64be(length); 59 | } 60 | } 61 | //POP_WARNINGS 62 | 63 | #pragma pack(push, 1) 64 | union hash_state { 65 | uint8_t b[200]; 66 | uint64_t w[25]; 67 | }; 68 | #pragma pack(pop) 69 | //static_assert(sizeof(union hash_state) == 200, "Invalid structure size"); 70 | 71 | void hash_permutation(union hash_state *state); 72 | void hash_process(union hash_state *state, const uint8_t *buf, size_t count); 73 | 74 | #endif 75 | 76 | enum { 77 | HASH_SIZE = 32, 78 | HASH_DATA_AREA = 136 79 | }; 80 | 81 | void cn_fast_hash(const void *data, size_t length, char *hash); 82 | void cn_slow_hash(const void *data, size_t length, char *hash, int light, int variant, int prehashed); 83 | 84 | void hash_extra_blake(const void *data, size_t length, char *hash); 85 | void hash_extra_groestl(const void *data, size_t length, char *hash); 86 | void hash_extra_jh(const void *data, size_t length, char *hash); 87 | void hash_extra_skein(const void *data, size_t length, char *hash); 88 | 89 | void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash); 90 | -------------------------------------------------------------------------------- /server/Server/PoolList.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | using System; 23 | using System.Collections.Generic; 24 | using System.IO; 25 | using System.Text; 26 | using System.Threading.Tasks; 27 | using TinyJson; 28 | 29 | using JsonData = System.Collections.Generic.Dictionary; 30 | 31 | namespace Server { 32 | 33 | public struct PoolInfo { 34 | public int Port; 35 | public string Url; 36 | // some pools require a non-empty password 37 | public string EmptyPassword; 38 | public string DefaultAlgorithm; 39 | public int DefaultVariant; 40 | 41 | public PoolInfo (string url, int port, string emptypw = "", string algo = "cn", int variant = -1) { Port = port; Url = url; EmptyPassword = emptypw; DefaultAlgorithm = algo; DefaultVariant = variant; } 42 | } 43 | 44 | public class PoolList { 45 | 46 | private Dictionary pools; 47 | private PoolList () { } 48 | 49 | public string JsonPools { private set; get; } 50 | 51 | public bool TryGetPool (string pool, out PoolInfo info) { 52 | return pools.TryGetValue (pool, out info); 53 | } 54 | 55 | public int Count { get { return pools.Count; } } 56 | 57 | public static PoolList LoadFromFile (string filename) { 58 | PoolList pl = new PoolList (); 59 | pl.pools = new Dictionary (); 60 | 61 | string json = File.ReadAllText (filename); 62 | 63 | JsonData data = json.FromJson (); 64 | 65 | foreach (string pool in data.Keys) { 66 | 67 | JsonData jinfo = data[pool] as JsonData; 68 | PoolInfo pi = new PoolInfo (); 69 | 70 | if (!(jinfo.ContainsKey ("url") && jinfo.ContainsKey ("port") && 71 | jinfo.ContainsKey ("emptypassword") && jinfo.ContainsKey ("algorithm") && 72 | jinfo.ContainsKey ("variant"))) 73 | throw new Exception ("Invalid entry."); 74 | 75 | pi.Url = jinfo["url"].GetString (); 76 | pi.EmptyPassword = jinfo["emptypassword"].GetString (); 77 | pi.DefaultAlgorithm = jinfo["algorithm"].GetString (); 78 | pi.DefaultVariant = int.Parse (jinfo["variant"].GetString ()); 79 | pi.Port = int.Parse (jinfo["port"].GetString ()); 80 | 81 | pl.pools.Add (pool, pi); 82 | 83 | } 84 | 85 | int counter = 0; 86 | 87 | pl.JsonPools = "{\"identifier\":\"" + "poolinfo"; 88 | 89 | foreach (string pool in pl.pools.Keys) { 90 | counter++; 91 | pl.JsonPools += "\",\"pool" + counter.ToString () + "\":\"" + pool; 92 | } 93 | 94 | pl.JsonPools += "\"}\n"; 95 | 96 | return pl; 97 | } 98 | 99 | } 100 | 101 | } -------------------------------------------------------------------------------- /hash_cn/webassembly/keccak.c: -------------------------------------------------------------------------------- 1 | // keccak.c 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | // A baseline Keccak (3rd round) implementation. 4 | 5 | #include 6 | #include 7 | #include "keccak.h" 8 | 9 | #define HASH_DATA_AREA 136 10 | #define KECCAK_ROUNDS 24 11 | 12 | #ifndef ROTL64 13 | #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) 14 | #endif 15 | 16 | const uint64_t keccakf_rndc[24] = 17 | { 18 | 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 19 | 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 20 | 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 21 | 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 22 | 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 23 | 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 24 | 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 25 | 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 26 | }; 27 | 28 | const int keccakf_rotc[24] = 29 | { 30 | 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 31 | 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 32 | }; 33 | 34 | const int keccakf_piln[24] = 35 | { 36 | 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 37 | 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 38 | }; 39 | 40 | // update the state with given number of rounds 41 | 42 | void keccakf(uint64_t st[25], int rounds) 43 | { 44 | int i, j, round; 45 | uint64_t t, bc[5]; 46 | 47 | for (round = 0; round < rounds; ++round) { 48 | 49 | // Theta 50 | bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20]; 51 | bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21]; 52 | bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22]; 53 | bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23]; 54 | bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24]; 55 | 56 | for (i = 0; i < 5; ++i) { 57 | t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); 58 | st[i ] ^= t; 59 | st[i + 5] ^= t; 60 | st[i + 10] ^= t; 61 | st[i + 15] ^= t; 62 | st[i + 20] ^= t; 63 | } 64 | 65 | // Rho Pi 66 | t = st[1]; 67 | for (i = 0; i < 24; ++i) { 68 | bc[0] = st[keccakf_piln[i]]; 69 | st[keccakf_piln[i]] = ROTL64(t, keccakf_rotc[i]); 70 | t = bc[0]; 71 | } 72 | 73 | // Chi 74 | for (j = 0; j < 25; j += 5) { 75 | bc[0] = st[j ]; 76 | bc[1] = st[j + 1]; 77 | bc[2] = st[j + 2]; 78 | bc[3] = st[j + 3]; 79 | bc[4] = st[j + 4]; 80 | st[j ] ^= (~bc[1]) & bc[2]; 81 | st[j + 1] ^= (~bc[2]) & bc[3]; 82 | st[j + 2] ^= (~bc[3]) & bc[4]; 83 | st[j + 3] ^= (~bc[4]) & bc[0]; 84 | st[j + 4] ^= (~bc[0]) & bc[1]; 85 | } 86 | 87 | // Iota 88 | st[0] ^= keccakf_rndc[round]; 89 | } 90 | } 91 | 92 | // compute a keccak hash (md) of given byte length from "in" 93 | typedef uint64_t state_t[25]; 94 | 95 | void keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen) 96 | { 97 | state_t st; 98 | uint8_t temp[144]; 99 | int i, rsiz, rsizw; 100 | 101 | rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; 102 | rsizw = rsiz / 8; 103 | 104 | memset(st, 0, sizeof(st)); 105 | 106 | for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { 107 | for (i = 0; i < rsizw; i++) 108 | st[i] ^= ((uint64_t *) in)[i]; 109 | keccakf(st, KECCAK_ROUNDS); 110 | } 111 | 112 | // last block and padding 113 | memcpy(temp, in, inlen); 114 | temp[inlen++] = 1; 115 | memset(temp + inlen, 0, rsiz - inlen); 116 | temp[rsiz - 1] |= 0x80; 117 | 118 | for (i = 0; i < rsizw; i++) 119 | st[i] ^= ((uint64_t *) temp)[i]; 120 | 121 | keccakf(st, KECCAK_ROUNDS); 122 | 123 | memcpy(md, st, mdlen); 124 | } 125 | 126 | void keccak1600(const uint8_t *in, int inlen, uint8_t *md) 127 | { 128 | keccak(in, inlen, md, sizeof(state_t)); 129 | } 130 | -------------------------------------------------------------------------------- /server/Server/Fleck/RequestParser.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System.Text; 25 | using System.Text.RegularExpressions; 26 | 27 | namespace Fleck 28 | { 29 | public class RequestParser 30 | { 31 | const string pattern = @"^(?[^\s]+)\s(?[^\s]+)\sHTTP\/1\.1\r\n" + // request line 32 | @"((?[^:\r\n]+):(?([^\r\n])\s)*(?[^\r\n]*)\r\n)+" + //headers 33 | @"\r\n" + //newline 34 | @"(?.+)?"; 35 | const string FlashSocketPolicyRequestPattern = @"^[<]policy-file-request\s*[/][>]"; 36 | 37 | private static readonly Regex _regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); 38 | private static readonly Regex _FlashSocketPolicyRequestRegex = new Regex(FlashSocketPolicyRequestPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); 39 | 40 | public static WebSocketHttpRequest Parse(byte[] bytes) 41 | { 42 | return Parse(bytes, "ws"); 43 | } 44 | 45 | public static WebSocketHttpRequest Parse(byte[] bytes, string scheme) 46 | { 47 | // Check for websocket request header 48 | var body = Encoding.UTF8.GetString(bytes); 49 | Match match = _regex.Match(body); 50 | 51 | if (!match.Success) 52 | { 53 | // No websocket request header found, check for a flash socket policy request 54 | match = _FlashSocketPolicyRequestRegex.Match(body); 55 | if (match.Success) 56 | { 57 | // It's a flash socket policy request, so return 58 | return new WebSocketHttpRequest 59 | { 60 | Body = body, 61 | Bytes = bytes 62 | }; 63 | } 64 | else 65 | { 66 | return null; 67 | } 68 | } 69 | 70 | var request = new WebSocketHttpRequest 71 | { 72 | Method = match.Groups["method"].Value, 73 | Path = match.Groups["path"].Value, 74 | Body = match.Groups["body"].Value, 75 | Bytes = bytes, 76 | Scheme = scheme 77 | }; 78 | 79 | var fields = match.Groups["field_name"].Captures; 80 | var values = match.Groups["field_value"].Captures; 81 | for (var i = 0; i < fields.Count; i++) 82 | { 83 | var name = fields[i].ToString(); 84 | var value = values[i].ToString(); 85 | request.Headers[name] = value; 86 | } 87 | 88 | return request; 89 | } 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /hash_cn/libhash/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #pragma once 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "common/pod-class.h" 38 | #include "generic-ops.h" 39 | #include "hex.h" 40 | #include "span.h" 41 | 42 | namespace crypto { 43 | 44 | extern "C" { 45 | #include "hash-ops.h" 46 | } 47 | 48 | #pragma pack(push, 1) 49 | POD_CLASS hash { 50 | char data[HASH_SIZE]; 51 | }; 52 | POD_CLASS hash8 { 53 | char data[8]; 54 | }; 55 | #pragma pack(pop) 56 | 57 | //static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size"); 58 | //static_assert(sizeof(hash8) == 8, "Invalid structure size"); 59 | 60 | /* 61 | Cryptonight hash functions 62 | */ 63 | 64 | inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) { 65 | cn_fast_hash(data, length, reinterpret_cast(&hash)); 66 | } 67 | 68 | inline hash cn_fast_hash(const void *data, std::size_t length) { 69 | hash h; 70 | cn_fast_hash(data, length, reinterpret_cast(&h)); 71 | return h; 72 | } 73 | 74 | inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int light = 0, int variant = 0) { 75 | cn_slow_hash(data, length, reinterpret_cast(&hash), light, variant, 0/*prehashed*/); 76 | } 77 | 78 | inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int light = 0, int variant = 0) { 79 | cn_slow_hash(data, length, reinterpret_cast(&hash), light, variant, 1/*prehashed*/); 80 | } 81 | 82 | inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) { 83 | tree_hash(reinterpret_cast(hashes), count, reinterpret_cast(&root_hash)); 84 | } 85 | 86 | inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) { 87 | epee::to_hex::formatted(o, epee::as_byte_span(v)); return o; 88 | } 89 | inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) { 90 | epee::to_hex::formatted(o, epee::as_byte_span(v)); return o; 91 | } 92 | 93 | const static crypto::hash null_hash = boost::value_initialized(); 94 | const static crypto::hash8 null_hash8 = boost::value_initialized(); 95 | } 96 | 97 | CRYPTO_MAKE_HASHABLE(hash) 98 | CRYPTO_MAKE_COMPARABLE(hash8) 99 | -------------------------------------------------------------------------------- /server/Server/Fleck/WebSocketConnectionInfo.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | using System.Collections.Generic; 26 | using System.Linq; 27 | using System.Text.RegularExpressions; 28 | 29 | namespace Fleck 30 | { 31 | public class WebSocketConnectionInfo : IWebSocketConnectionInfo 32 | { 33 | const string CookiePattern = @"((;)*(\s)*(?[^=]+)=(?[^\;]+))+"; 34 | private static readonly Regex CookieRegex = new Regex(CookiePattern, RegexOptions.Compiled); 35 | 36 | public static WebSocketConnectionInfo Create(WebSocketHttpRequest request, string clientIp, int clientPort, string negotiatedSubprotocol) 37 | { 38 | var info = new WebSocketConnectionInfo 39 | { 40 | Origin = request["Origin"] ?? request["Sec-WebSocket-Origin"], 41 | Host = request["Host"], 42 | SubProtocol = request["Sec-WebSocket-Protocol"], 43 | Path = request.Path, 44 | ClientIpAddress = clientIp, 45 | ClientPort = clientPort, 46 | NegotiatedSubProtocol = negotiatedSubprotocol, 47 | Headers = new Dictionary(request.Headers, System.StringComparer.InvariantCultureIgnoreCase) 48 | }; 49 | var cookieHeader = request["Cookie"]; 50 | 51 | if (cookieHeader != null) 52 | { 53 | var match = CookieRegex.Match(cookieHeader); 54 | var fields = match.Groups["cookie_name"].Captures; 55 | var values = match.Groups["cookie_value"].Captures; 56 | for (var i = 0; i < fields.Count; i++) 57 | { 58 | var name = fields[i].ToString(); 59 | var value = values[i].ToString(); 60 | info.Cookies[name] = value; 61 | } 62 | } 63 | 64 | return info; 65 | } 66 | 67 | 68 | WebSocketConnectionInfo() 69 | { 70 | Cookies = new Dictionary(); 71 | Id = Guid.NewGuid(); 72 | } 73 | 74 | public string NegotiatedSubProtocol { get; private set; } 75 | public string SubProtocol { get; private set; } 76 | public string Origin { get; private set; } 77 | public string Host { get; private set; } 78 | public string Path { get; private set; } 79 | public string ClientIpAddress { get; set; } 80 | public int ClientPort { get; set; } 81 | public Guid Id { get; set; } 82 | 83 | public IDictionary Cookies { get; private set; } 84 | public IDictionary Headers { get; private set; } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /hash_cn/libhash/keccak.c: -------------------------------------------------------------------------------- 1 | // keccak.c 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | // A baseline Keccak (3rd round) implementation. 4 | 5 | #include 6 | #include 7 | #include 8 | #include "hash-ops.h" 9 | #include "keccak.h" 10 | 11 | static void local_abort(const char *msg) 12 | { 13 | fprintf(stderr, "%s\n", msg); 14 | #ifdef NDEBUG 15 | _exit(1); 16 | #else 17 | abort(); 18 | #endif 19 | } 20 | 21 | const uint64_t keccakf_rndc[24] = 22 | { 23 | 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 24 | 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 25 | 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 26 | 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 27 | 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 28 | 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 29 | 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 30 | 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 31 | }; 32 | 33 | const int keccakf_rotc[24] = 34 | { 35 | 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 36 | 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 37 | }; 38 | 39 | const int keccakf_piln[24] = 40 | { 41 | 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 42 | 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 43 | }; 44 | 45 | // update the state with given number of rounds 46 | 47 | void keccakf(uint64_t st[25], int rounds) 48 | { 49 | int i, j, round; 50 | uint64_t t, bc[5]; 51 | 52 | for (round = 0; round < rounds; round++) { 53 | 54 | // Theta 55 | for (i = 0; i < 5; i++) 56 | bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20]; 57 | 58 | for (i = 0; i < 5; i++) { 59 | t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); 60 | for (j = 0; j < 25; j += 5) 61 | st[j + i] ^= t; 62 | } 63 | 64 | // Rho Pi 65 | t = st[1]; 66 | for (i = 0; i < 24; i++) { 67 | j = keccakf_piln[i]; 68 | bc[0] = st[j]; 69 | st[j] = ROTL64(t, keccakf_rotc[i]); 70 | t = bc[0]; 71 | } 72 | 73 | // Chi 74 | for (j = 0; j < 25; j += 5) { 75 | for (i = 0; i < 5; i++) 76 | bc[i] = st[j + i]; 77 | for (i = 0; i < 5; i++) 78 | st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; 79 | } 80 | 81 | // Iota 82 | st[0] ^= keccakf_rndc[round]; 83 | } 84 | } 85 | 86 | // compute a keccak hash (md) of given byte length from "in" 87 | typedef uint64_t state_t[25]; 88 | 89 | void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen) 90 | { 91 | state_t st; 92 | uint8_t temp[144]; 93 | size_t i, rsiz, rsizw; 94 | 95 | //static_assert(HASH_DATA_AREA <= sizeof(temp), "Bad keccak preconditions"); 96 | if (mdlen <= 0 || (mdlen > 100 && sizeof(st) != (size_t)mdlen)) 97 | { 98 | local_abort("Bad keccak use"); 99 | } 100 | 101 | rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; 102 | rsizw = rsiz / 8; 103 | 104 | memset(st, 0, sizeof(st)); 105 | 106 | for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { 107 | for (i = 0; i < rsizw; i++) 108 | st[i] ^= ((uint64_t *) in)[i]; 109 | keccakf(st, KECCAK_ROUNDS); 110 | } 111 | 112 | // last block and padding 113 | if (inlen + 1 >= sizeof(temp) || inlen > rsiz || rsiz - inlen + inlen + 1 >= sizeof(temp) || rsiz == 0 || rsiz - 1 >= sizeof(temp) || rsizw * 8 > sizeof(temp)) 114 | { 115 | local_abort("Bad keccak use"); 116 | } 117 | 118 | memcpy(temp, in, inlen); 119 | temp[inlen++] = 1; 120 | memset(temp + inlen, 0, rsiz - inlen); 121 | temp[rsiz - 1] |= 0x80; 122 | 123 | for (i = 0; i < rsizw; i++) 124 | st[i] ^= ((uint64_t *) temp)[i]; 125 | 126 | keccakf(st, KECCAK_ROUNDS); 127 | 128 | memcpy(md, st, mdlen); 129 | } 130 | 131 | void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md) 132 | { 133 | keccak(in, inlen, md, sizeof(state_t)); 134 | } 135 | -------------------------------------------------------------------------------- /server/Server/Firewall.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | using System; 23 | using System.Collections.Concurrent; 24 | using System.Collections.Generic; 25 | using System.IO; 26 | using System.Text; 27 | using System.Threading.Tasks; 28 | 29 | namespace Server { 30 | public static class Firewall { 31 | 32 | public enum UpdateEntry { 33 | SolvedJob, 34 | AuthSuccess, 35 | AuthFailure, 36 | WrongHash, 37 | Handshake 38 | } 39 | 40 | private class Entry { 41 | public string Address; 42 | 43 | public Entry (string adr) { 44 | Address = adr; 45 | } 46 | 47 | public int SolvedJobs = 0; 48 | public int WrongHash = 0; 49 | public int AuthSuccess = 0; 50 | public int AuthFailure = 0; 51 | public int Handshake = 0; 52 | 53 | public DateTime FirstSeen = DateTime.Now; 54 | } 55 | 56 | private static CcDictionary entries = new CcDictionary (); 57 | 58 | public const int CheckTimeInHeartbeats = 6 * 10; // every 10min 59 | 60 | private static void AddToIpTables (Entry entry, int rule) { 61 | Helper.WriteTextAsyncWrapper ("ip_list", entry.Address + Environment.NewLine); 62 | CConsole.ColorWarning(() => Console.WriteLine ("Added {0} to ip_list (rule #{1})", entry.Address, rule.ToString ())); 63 | entries.TryRemove (entry.Address); 64 | } 65 | 66 | public static void Update (string ip, UpdateEntry update) { 67 | Entry entry = null; 68 | if (entries.TryGetValue (ip, out entry)) { 69 | 70 | if (update == UpdateEntry.SolvedJob) 71 | entry.SolvedJobs++; 72 | else if (update == UpdateEntry.AuthFailure) 73 | entry.AuthFailure++; 74 | else if (update == UpdateEntry.AuthSuccess) 75 | entry.AuthSuccess++; 76 | else if (update == UpdateEntry.WrongHash) 77 | entry.WrongHash++; 78 | else if (update == UpdateEntry.Handshake) 79 | entry.Handshake++; 80 | } else { 81 | entries.TryAdd (ip, new Entry (ip)); 82 | } 83 | 84 | } 85 | 86 | public static void Heartbeat (int heartBeats) { 87 | 88 | List entrylst = new List (entries.Values); 89 | 90 | foreach (Entry entry in entrylst) { 91 | // decide here... 92 | if (entry.AuthSuccess == 0 && entry.SolvedJobs == 0 && 93 | entry.AuthFailure > 20) { 94 | AddToIpTables (entry, 1); 95 | } else if (entry.AuthFailure > 500 && entry.AuthSuccess < 500) { 96 | AddToIpTables (entry, 2); 97 | } else if (entry.AuthSuccess + entry.AuthFailure > 1000 && entry.SolvedJobs < 3) { 98 | AddToIpTables (entry, 3); 99 | } else if (entry.AuthSuccess + entry.AuthFailure > 4000) { 100 | AddToIpTables (entry, 4); 101 | } else if (entry.WrongHash > 0 && entry.AuthSuccess < 5) { 102 | AddToIpTables (entry, 5); 103 | } else if (entry.AuthSuccess + entry.AuthFailure > 2000 && entry.Handshake < 1) { 104 | AddToIpTables (entry, 6); 105 | } 106 | } 107 | 108 | if ((heartBeats % CheckTimeInHeartbeats) == 0) { 109 | entries.Clear (); 110 | } 111 | } 112 | 113 | } 114 | } -------------------------------------------------------------------------------- /hash_cn/libhash/chacha.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #pragma once 32 | 33 | #include 34 | #include 35 | 36 | #define CHACHA_KEY_SIZE 32 37 | #define CHACHA_IV_SIZE 8 38 | 39 | #if defined(__cplusplus) 40 | #include 41 | 42 | #include "memwipe.h" 43 | #include "hash.h" 44 | 45 | namespace crypto { 46 | extern "C" { 47 | #endif 48 | void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher); 49 | void chacha20(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher); 50 | #if defined(__cplusplus) 51 | } 52 | 53 | using chacha_key = tools::scrubbed_arr; 54 | 55 | #pragma pack(push, 1) 56 | // MS VC 2012 doesn't interpret `class chacha_iv` as POD in spite of [9.0.10], so it is a struct 57 | struct chacha_iv { 58 | uint8_t data[CHACHA_IV_SIZE]; 59 | }; 60 | #pragma pack(pop) 61 | 62 | //static_assert(sizeof(chacha_key) == CHACHA_KEY_SIZE && sizeof(chacha_iv) == CHACHA_IV_SIZE, "Invalid structure size"); 63 | 64 | inline void chacha8(const void* data, std::size_t length, const chacha_key& key, const chacha_iv& iv, char* cipher) { 65 | chacha8(data, length, key.data(), reinterpret_cast(&iv), cipher); 66 | } 67 | 68 | inline void chacha20(const void* data, std::size_t length, const chacha_key& key, const chacha_iv& iv, char* cipher) { 69 | chacha20(data, length, key.data(), reinterpret_cast(&iv), cipher); 70 | } 71 | 72 | inline void generate_chacha_key(const void *data, size_t size, chacha_key& key) { 73 | //static_assert(sizeof(chacha_key) <= sizeof(hash), "Size of hash must be at least that of chacha_key"); 74 | tools::scrubbed_arr pwd_hash; 75 | crypto::cn_slow_hash(data, size, pwd_hash.data(), 0/*light*/, 0/*variant*/, 0/*prehashed*/); 76 | memcpy(&key, pwd_hash.data(), sizeof(key)); 77 | } 78 | 79 | inline void generate_chacha_key_prehashed(const void *data, size_t size, chacha_key& key) { 80 | //static_assert(sizeof(chacha_key) <= sizeof(hash), "Size of hash must be at least that of chacha_key"); 81 | tools::scrubbed_arr pwd_hash; 82 | crypto::cn_slow_hash(data, size, pwd_hash.data(), 0/*light*/, 0/*variant*/, 1/*prehashed*/); 83 | memcpy(&key, pwd_hash.data(), sizeof(key)); 84 | } 85 | 86 | inline void generate_chacha_key(std::string password, chacha_key& key) { 87 | return generate_chacha_key(password.data(), password.size(), key); 88 | } 89 | } 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /server/Server/Server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {DC564972-9DEF-4897-A8F5-C4C21CEBDE2F} 9 | Exe 10 | Server 11 | server 12 | v4.5 13 | 14 | 15 | true 16 | full 17 | false 18 | bin\Debug 19 | DEBUG; 20 | prompt 21 | 4 22 | true 23 | x86 24 | 25 | 26 | true 27 | bin\Release 28 | prompt 29 | 4 30 | true 31 | x86 32 | 33 | 34 | true 35 | bin\Release_Server 36 | 4 37 | true 38 | none 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | pools.json 92 | Always 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /server/Server/EmptyWebsocket.cs: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2018 - the webminerpool developer 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | using System; 23 | using System.Collections.Generic; 24 | using Fleck; 25 | 26 | namespace Server { 27 | 28 | public class EmptyConnectionInfo : IWebSocketConnectionInfo { 29 | #region IWebSocketConnectionInfo implementation 30 | public string SubProtocol { 31 | get { 32 | throw new NotImplementedException (); 33 | } 34 | } 35 | public string Origin { 36 | get { 37 | throw new NotImplementedException (); 38 | } 39 | } 40 | public string Host { 41 | get { 42 | throw new NotImplementedException (); 43 | } 44 | } 45 | public string Path { 46 | get { 47 | throw new NotImplementedException (); 48 | } 49 | } 50 | public string ClientIpAddress { 51 | get { 52 | return "127.0.0.1"; 53 | } 54 | } 55 | public int ClientPort { 56 | get { 57 | throw new NotImplementedException (); 58 | } 59 | } 60 | public IDictionary Cookies { 61 | get { 62 | throw new NotImplementedException (); 63 | } 64 | } 65 | public IDictionary Headers { 66 | get { 67 | throw new NotImplementedException (); 68 | } 69 | } 70 | public Guid Id { 71 | get { 72 | return Guid.Empty; 73 | } 74 | } 75 | public string NegotiatedSubProtocol { 76 | get { 77 | throw new NotImplementedException (); 78 | } 79 | } 80 | #endregion 81 | } 82 | 83 | public class EmptyWebsocket : IWebSocketConnection { 84 | private static EmptyConnectionInfo eci = 85 | new EmptyConnectionInfo (); 86 | 87 | #region IWebSocketConnection implementation 88 | public System.Threading.Tasks.Task Send (string message) { 89 | //throw new NotImplementedException (); 90 | return null; 91 | } 92 | public System.Threading.Tasks.Task Send (byte[] message) { 93 | throw new NotImplementedException (); 94 | } 95 | public System.Threading.Tasks.Task SendPing (byte[] message) { 96 | throw new NotImplementedException (); 97 | } 98 | public System.Threading.Tasks.Task SendPong (byte[] message) { 99 | throw new NotImplementedException (); 100 | } 101 | public void Close () { 102 | 103 | } 104 | public Action OnOpen { 105 | get { 106 | throw new NotImplementedException (); 107 | } 108 | set { 109 | throw new NotImplementedException (); 110 | } 111 | } 112 | public Action OnClose { 113 | get { 114 | throw new NotImplementedException (); 115 | } 116 | set { 117 | throw new NotImplementedException (); 118 | } 119 | } 120 | public Action OnMessage { 121 | get { 122 | throw new NotImplementedException (); 123 | } 124 | set { 125 | throw new NotImplementedException (); 126 | } 127 | } 128 | public Action OnBinary { 129 | get { 130 | throw new NotImplementedException (); 131 | } 132 | set { 133 | throw new NotImplementedException (); 134 | } 135 | } 136 | public Action OnPing { 137 | get { 138 | throw new NotImplementedException (); 139 | } 140 | set { 141 | throw new NotImplementedException (); 142 | } 143 | } 144 | public Action OnPong { 145 | get { 146 | throw new NotImplementedException (); 147 | } 148 | set { 149 | throw new NotImplementedException (); 150 | } 151 | } 152 | public Action OnError { 153 | get { 154 | throw new NotImplementedException (); 155 | } 156 | set { 157 | throw new NotImplementedException (); 158 | } 159 | } 160 | public IWebSocketConnectionInfo ConnectionInfo { 161 | get { 162 | return EmptyWebsocket.eci; 163 | } 164 | } 165 | public bool IsAvailable { 166 | get { 167 | return false; 168 | } 169 | } 170 | #endregion 171 | } 172 | 173 | } -------------------------------------------------------------------------------- /hash_cn/libhash/random.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "hash-ops.h" 36 | #include "initializer.h" 37 | #include "random.h" 38 | 39 | static void generate_system_random_bytes(size_t n, void *result); 40 | 41 | #if defined(_WIN32) 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | static void generate_system_random_bytes(size_t n, void *result) { 48 | HCRYPTPROV prov; 49 | #ifdef NDEBUG 50 | #define must_succeed(x) do if (!(x)) { fprintf(stderr, "Failed: " #x); _exit(1); } while (0) 51 | #else 52 | #define must_succeed(x) do if (!(x)) abort(); while (0) 53 | #endif 54 | must_succeed(CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)); 55 | must_succeed(CryptGenRandom(prov, (DWORD)n, result)); 56 | must_succeed(CryptReleaseContext(prov, 0)); 57 | #undef must_succeed 58 | } 59 | 60 | #else 61 | 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | 70 | static void generate_system_random_bytes(size_t n, void *result) { 71 | int fd; 72 | if ((fd = open("/dev/urandom", O_RDONLY | O_NOCTTY | O_CLOEXEC)) < 0) { 73 | err(EXIT_FAILURE, "open /dev/urandom"); 74 | } 75 | for (;;) { 76 | ssize_t res = read(fd, result, n); 77 | if ((size_t) res == n) { 78 | break; 79 | } 80 | if (res < 0) { 81 | if (errno != EINTR) { 82 | err(EXIT_FAILURE, "read /dev/urandom"); 83 | } 84 | } else if (res == 0) { 85 | errx(EXIT_FAILURE, "read /dev/urandom: end of file"); 86 | } else { 87 | result = padd(result, (size_t) res); 88 | n -= (size_t) res; 89 | } 90 | } 91 | if (close(fd) < 0) { 92 | err(EXIT_FAILURE, "close /dev/urandom"); 93 | } 94 | } 95 | 96 | #endif 97 | 98 | static union hash_state state; 99 | 100 | #if !defined(NDEBUG) 101 | static volatile int curstate; /* To catch thread safety problems. */ 102 | #endif 103 | 104 | FINALIZER(deinit_random) { 105 | #if !defined(NDEBUG) 106 | assert(curstate == 1); 107 | curstate = 0; 108 | #endif 109 | memset(&state, 0, sizeof(union hash_state)); 110 | } 111 | 112 | INITIALIZER(init_random) { 113 | generate_system_random_bytes(32, &state); 114 | REGISTER_FINALIZER(deinit_random); 115 | #if !defined(NDEBUG) 116 | assert(curstate == 0); 117 | curstate = 1; 118 | #endif 119 | } 120 | 121 | void generate_random_bytes_not_thread_safe(size_t n, void *result) { 122 | #if !defined(NDEBUG) 123 | assert(curstate == 1); 124 | curstate = 2; 125 | #endif 126 | if (n == 0) { 127 | #if !defined(NDEBUG) 128 | assert(curstate == 2); 129 | curstate = 1; 130 | #endif 131 | return; 132 | } 133 | for (;;) { 134 | hash_permutation(&state); 135 | if (n <= HASH_DATA_AREA) { 136 | memcpy(result, &state, n); 137 | #if !defined(NDEBUG) 138 | assert(curstate == 2); 139 | curstate = 1; 140 | #endif 141 | return; 142 | } else { 143 | memcpy(result, &state, HASH_DATA_AREA); 144 | result = padd(result, HASH_DATA_AREA); 145 | n -= HASH_DATA_AREA; 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /hash_cn/libhash/tree-hash.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "hash-ops.h" 36 | 37 | #ifdef _MSC_VER 38 | #include 39 | #elif !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__) 40 | #include 41 | #else 42 | #include 43 | #endif 44 | 45 | /*** 46 | * Round to power of two, for count>=3 and for count being not too large (as reasonable for tree hash calculations) 47 | */ 48 | size_t tree_hash_cnt(size_t count) { 49 | // This algo has some bad history but all we are doing is 1 << floor(log2(count)) 50 | // There are _many_ ways to do log2, for some reason the one selected was the most obscure one, 51 | // and fixing it made it even more obscure. 52 | // 53 | // Iterative method implemented below aims for clarity over speed, if performance is needed 54 | // then my advice is to use the BSR instruction on x86 55 | // 56 | // All the paranoid asserts have been removed since it is trivial to mathematically prove that 57 | // the return will always be a power of 2. 58 | // Problem space has been defined as 3 <= count <= 2^28. Of course quarter of a billion transactions 59 | // is not a sane upper limit for a block, so there will be tighter limits in other parts of the code 60 | 61 | assert( count >= 3 ); // cases for 0,1,2 are handled elsewhere 62 | assert( count <= 0x10000000 ); // sanity limit to 2^28, MSB=1 will cause an inf loop 63 | 64 | size_t pow = 2; 65 | while(pow < count) pow <<= 1; 66 | return pow >> 1; 67 | } 68 | 69 | void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash) { 70 | // The blockchain block at height 202612 http://monerochain.info/block/bbd604d2ba11ba27935e006ed39c9bfdd99b76bf4a50654bc1e1e61217962698 71 | // contained 514 transactions, that triggered bad calculation of variable "cnt" in the original version of this function 72 | // as from CryptoNote code. 73 | // 74 | // This bug applies to all CN altcoins. 75 | // 76 | // Mathematical bug here was first published on 14:45:34 (GMT+2) 2014-09-04 by Rafal Freeman 77 | // https://github.com/rfree2monero/bitmonero/commit/b417abfb7a297d09f1bbb6de29030f8de9952ac8 78 | // and soon also applied to CryptoNote (15:10 GMT+2), and BoolBerry used not fully correct work around: 79 | // the work around of sizeof(size_t)*8 or <<3 as used before in 2 coins and in BBL later was blocking 80 | // exploitation on normal platforms, how ever we strongly recommend the following fix because it removes 81 | // mistake in mathematical formula. 82 | 83 | assert(count > 0); 84 | if (count == 1) { 85 | memcpy(root_hash, hashes, HASH_SIZE); 86 | } else if (count == 2) { 87 | cn_fast_hash(hashes, 2 * HASH_SIZE, root_hash); 88 | } else { 89 | size_t i, j; 90 | 91 | size_t cnt = tree_hash_cnt( count ); 92 | 93 | char (*ints)[HASH_SIZE]; 94 | size_t ints_size = cnt * HASH_SIZE; 95 | ints = alloca(ints_size); memset( ints , 0 , ints_size); // allocate, and zero out as extra protection for using uninitialized mem 96 | 97 | memcpy(ints, hashes, (2 * cnt - count) * HASH_SIZE); 98 | 99 | for (i = 2 * cnt - count, j = 2 * cnt - count; j < cnt; i += 2, ++j) { 100 | cn_fast_hash(hashes[i], 64, ints[j]); 101 | } 102 | assert(i == count); 103 | 104 | while (cnt > 2) { 105 | cnt >>= 1; 106 | for (i = 0, j = 0; j < cnt; i += 2, ++j) { 107 | cn_fast_hash(ints[i], 64, ints[j]); 108 | } 109 | } 110 | 111 | cn_fast_hash(ints[0], 64, root_hash); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /hash_cn/libhash/crypto-ops.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #pragma once 32 | 33 | /* From fe.h */ 34 | 35 | typedef int32_t fe[10]; 36 | 37 | /* From ge.h */ 38 | 39 | typedef struct { 40 | fe X; 41 | fe Y; 42 | fe Z; 43 | } ge_p2; 44 | 45 | typedef struct { 46 | fe X; 47 | fe Y; 48 | fe Z; 49 | fe T; 50 | } ge_p3; 51 | 52 | typedef struct { 53 | fe X; 54 | fe Y; 55 | fe Z; 56 | fe T; 57 | } ge_p1p1; 58 | 59 | typedef struct { 60 | fe yplusx; 61 | fe yminusx; 62 | fe xy2d; 63 | } ge_precomp; 64 | 65 | typedef struct { 66 | fe YplusX; 67 | fe YminusX; 68 | fe Z; 69 | fe T2d; 70 | } ge_cached; 71 | 72 | /* From ge_add.c */ 73 | 74 | void ge_add(ge_p1p1 *, const ge_p3 *, const ge_cached *); 75 | 76 | /* From ge_double_scalarmult.c, modified */ 77 | 78 | typedef ge_cached ge_dsmp[8]; 79 | extern const ge_precomp ge_Bi[8]; 80 | void ge_dsm_precomp(ge_dsmp r, const ge_p3 *s); 81 | void ge_double_scalarmult_base_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *); 82 | void ge_double_scalarmult_base_vartime_p3(ge_p3 *, const unsigned char *, const ge_p3 *, const unsigned char *); 83 | 84 | /* From ge_frombytes.c, modified */ 85 | 86 | extern const fe fe_sqrtm1; 87 | extern const fe fe_d; 88 | int ge_frombytes_vartime(ge_p3 *, const unsigned char *); 89 | 90 | /* From ge_p1p1_to_p2.c */ 91 | 92 | void ge_p1p1_to_p2(ge_p2 *, const ge_p1p1 *); 93 | 94 | /* From ge_p1p1_to_p3.c */ 95 | 96 | void ge_p1p1_to_p3(ge_p3 *, const ge_p1p1 *); 97 | 98 | /* From ge_p2_dbl.c */ 99 | 100 | void ge_p2_dbl(ge_p1p1 *, const ge_p2 *); 101 | 102 | /* From ge_p3_to_cached.c */ 103 | 104 | extern const fe fe_d2; 105 | void ge_p3_to_cached(ge_cached *, const ge_p3 *); 106 | 107 | /* From ge_p3_to_p2.c */ 108 | 109 | void ge_p3_to_p2(ge_p2 *, const ge_p3 *); 110 | 111 | /* From ge_p3_tobytes.c */ 112 | 113 | void ge_p3_tobytes(unsigned char *, const ge_p3 *); 114 | 115 | /* From ge_scalarmult_base.c */ 116 | 117 | extern const ge_precomp ge_base[32][8]; 118 | void ge_scalarmult_base(ge_p3 *, const unsigned char *); 119 | 120 | /* From ge_tobytes.c */ 121 | 122 | void ge_tobytes(unsigned char *, const ge_p2 *); 123 | 124 | /* From sc_reduce.c */ 125 | 126 | void sc_reduce(unsigned char *); 127 | 128 | /* New code */ 129 | 130 | void ge_scalarmult(ge_p2 *, const unsigned char *, const ge_p3 *); 131 | void ge_scalarmult_p3(ge_p3 *, const unsigned char *, const ge_p3 *); 132 | void ge_double_scalarmult_precomp_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *, const ge_dsmp); 133 | void ge_double_scalarmult_precomp_vartime2(ge_p2 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp); 134 | void ge_double_scalarmult_precomp_vartime2_p3(ge_p3 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp); 135 | void ge_mul8(ge_p1p1 *, const ge_p2 *); 136 | extern const fe fe_ma2; 137 | extern const fe fe_ma; 138 | extern const fe fe_fffb1; 139 | extern const fe fe_fffb2; 140 | extern const fe fe_fffb3; 141 | extern const fe fe_fffb4; 142 | extern const ge_p3 ge_p3_identity; 143 | void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *); 144 | void sc_0(unsigned char *); 145 | void sc_reduce32(unsigned char *); 146 | void sc_add(unsigned char *, const unsigned char *, const unsigned char *); 147 | void sc_sub(unsigned char *, const unsigned char *, const unsigned char *); 148 | void sc_mulsub(unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *); 149 | void sc_mul(unsigned char *, const unsigned char *, const unsigned char *); 150 | void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c); 151 | int sc_check(const unsigned char *); 152 | int sc_isnonzero(const unsigned char *); /* Doesn't normalize */ 153 | 154 | // internal 155 | uint64_t load_3(const unsigned char *in); 156 | uint64_t load_4(const unsigned char *in); 157 | void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q); 158 | void fe_add(fe h, const fe f, const fe g); 159 | void fe_tobytes(unsigned char *, const fe); 160 | void fe_invert(fe out, const fe z); 161 | -------------------------------------------------------------------------------- /hash_cn/libhash/chacha.c: -------------------------------------------------------------------------------- 1 | /* 2 | chacha-merged.c version 20080118 3 | D. J. Bernstein 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #ifndef _MSC_VER 10 | #include 11 | #endif 12 | 13 | #include "chacha.h" 14 | #include "int-util.h" 15 | //#include "warnings.h" 16 | 17 | /* 18 | * The following macros are used to obtain exact-width results. 19 | */ 20 | #define U8V(v) ((uint8_t)(v) & UINT8_C(0xFF)) 21 | #define U32V(v) ((uint32_t)(v) & UINT32_C(0xFFFFFFFF)) 22 | 23 | /* 24 | * The following macros load words from an array of bytes with 25 | * different types of endianness, and vice versa. 26 | */ 27 | #define U8TO32_LITTLE(p) SWAP32LE(((uint32_t*)(p))[0]) 28 | #define U32TO8_LITTLE(p, v) (((uint32_t*)(p))[0] = SWAP32LE(v)) 29 | 30 | #define ROTATE(v,c) (rol32(v,c)) 31 | #define XOR(v,w) ((v) ^ (w)) 32 | #define PLUS(v,w) (U32V((v) + (w))) 33 | #define PLUSONE(v) (PLUS((v),1)) 34 | 35 | #define QUARTERROUND(a,b,c,d) \ 36 | a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \ 37 | c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \ 38 | a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \ 39 | c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); 40 | 41 | static const char sigma[] = "expand 32-byte k"; 42 | 43 | //DISABLE_GCC_AND_CLANG_WARNING(strict-aliasing) 44 | 45 | static void chacha(unsigned rounds, const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher) { 46 | uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; 47 | uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15; 48 | char* ctarget = 0; 49 | char tmp[64]; 50 | int i; 51 | 52 | if (!length) return; 53 | 54 | j0 = U8TO32_LITTLE(sigma + 0); 55 | j1 = U8TO32_LITTLE(sigma + 4); 56 | j2 = U8TO32_LITTLE(sigma + 8); 57 | j3 = U8TO32_LITTLE(sigma + 12); 58 | j4 = U8TO32_LITTLE(key + 0); 59 | j5 = U8TO32_LITTLE(key + 4); 60 | j6 = U8TO32_LITTLE(key + 8); 61 | j7 = U8TO32_LITTLE(key + 12); 62 | j8 = U8TO32_LITTLE(key + 16); 63 | j9 = U8TO32_LITTLE(key + 20); 64 | j10 = U8TO32_LITTLE(key + 24); 65 | j11 = U8TO32_LITTLE(key + 28); 66 | j12 = 0; 67 | j13 = 0; 68 | j14 = U8TO32_LITTLE(iv + 0); 69 | j15 = U8TO32_LITTLE(iv + 4); 70 | 71 | for (;;) { 72 | if (length < 64) { 73 | memcpy(tmp, data, length); 74 | data = tmp; 75 | ctarget = cipher; 76 | cipher = tmp; 77 | } 78 | x0 = j0; 79 | x1 = j1; 80 | x2 = j2; 81 | x3 = j3; 82 | x4 = j4; 83 | x5 = j5; 84 | x6 = j6; 85 | x7 = j7; 86 | x8 = j8; 87 | x9 = j9; 88 | x10 = j10; 89 | x11 = j11; 90 | x12 = j12; 91 | x13 = j13; 92 | x14 = j14; 93 | x15 = j15; 94 | for (i = rounds;i > 0;i -= 2) { 95 | QUARTERROUND( x0, x4, x8,x12) 96 | QUARTERROUND( x1, x5, x9,x13) 97 | QUARTERROUND( x2, x6,x10,x14) 98 | QUARTERROUND( x3, x7,x11,x15) 99 | QUARTERROUND( x0, x5,x10,x15) 100 | QUARTERROUND( x1, x6,x11,x12) 101 | QUARTERROUND( x2, x7, x8,x13) 102 | QUARTERROUND( x3, x4, x9,x14) 103 | } 104 | x0 = PLUS( x0, j0); 105 | x1 = PLUS( x1, j1); 106 | x2 = PLUS( x2, j2); 107 | x3 = PLUS( x3, j3); 108 | x4 = PLUS( x4, j4); 109 | x5 = PLUS( x5, j5); 110 | x6 = PLUS( x6, j6); 111 | x7 = PLUS( x7, j7); 112 | x8 = PLUS( x8, j8); 113 | x9 = PLUS( x9, j9); 114 | x10 = PLUS(x10,j10); 115 | x11 = PLUS(x11,j11); 116 | x12 = PLUS(x12,j12); 117 | x13 = PLUS(x13,j13); 118 | x14 = PLUS(x14,j14); 119 | x15 = PLUS(x15,j15); 120 | 121 | x0 = XOR( x0,U8TO32_LITTLE((uint8_t*)data + 0)); 122 | x1 = XOR( x1,U8TO32_LITTLE((uint8_t*)data + 4)); 123 | x2 = XOR( x2,U8TO32_LITTLE((uint8_t*)data + 8)); 124 | x3 = XOR( x3,U8TO32_LITTLE((uint8_t*)data + 12)); 125 | x4 = XOR( x4,U8TO32_LITTLE((uint8_t*)data + 16)); 126 | x5 = XOR( x5,U8TO32_LITTLE((uint8_t*)data + 20)); 127 | x6 = XOR( x6,U8TO32_LITTLE((uint8_t*)data + 24)); 128 | x7 = XOR( x7,U8TO32_LITTLE((uint8_t*)data + 28)); 129 | x8 = XOR( x8,U8TO32_LITTLE((uint8_t*)data + 32)); 130 | x9 = XOR( x9,U8TO32_LITTLE((uint8_t*)data + 36)); 131 | x10 = XOR(x10,U8TO32_LITTLE((uint8_t*)data + 40)); 132 | x11 = XOR(x11,U8TO32_LITTLE((uint8_t*)data + 44)); 133 | x12 = XOR(x12,U8TO32_LITTLE((uint8_t*)data + 48)); 134 | x13 = XOR(x13,U8TO32_LITTLE((uint8_t*)data + 52)); 135 | x14 = XOR(x14,U8TO32_LITTLE((uint8_t*)data + 56)); 136 | x15 = XOR(x15,U8TO32_LITTLE((uint8_t*)data + 60)); 137 | 138 | j12 = PLUSONE(j12); 139 | if (!j12) 140 | { 141 | j13 = PLUSONE(j13); 142 | /* stopping at 2^70 bytes per iv is user's responsibility */ 143 | } 144 | 145 | U32TO8_LITTLE(cipher + 0,x0); 146 | U32TO8_LITTLE(cipher + 4,x1); 147 | U32TO8_LITTLE(cipher + 8,x2); 148 | U32TO8_LITTLE(cipher + 12,x3); 149 | U32TO8_LITTLE(cipher + 16,x4); 150 | U32TO8_LITTLE(cipher + 20,x5); 151 | U32TO8_LITTLE(cipher + 24,x6); 152 | U32TO8_LITTLE(cipher + 28,x7); 153 | U32TO8_LITTLE(cipher + 32,x8); 154 | U32TO8_LITTLE(cipher + 36,x9); 155 | U32TO8_LITTLE(cipher + 40,x10); 156 | U32TO8_LITTLE(cipher + 44,x11); 157 | U32TO8_LITTLE(cipher + 48,x12); 158 | U32TO8_LITTLE(cipher + 52,x13); 159 | U32TO8_LITTLE(cipher + 56,x14); 160 | U32TO8_LITTLE(cipher + 60,x15); 161 | 162 | if (length <= 64) { 163 | if (length < 64) { 164 | memcpy(ctarget, cipher, length); 165 | } 166 | return; 167 | } 168 | length -= 64; 169 | cipher += 64; 170 | data = (uint8_t*)data + 64; 171 | } 172 | } 173 | 174 | void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher) 175 | { 176 | chacha(8, data, length, key, iv, cipher); 177 | } 178 | 179 | void chacha20(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher) 180 | { 181 | chacha(20, data, length, key, iv, cipher); 182 | } 183 | -------------------------------------------------------------------------------- /server/pools.json: -------------------------------------------------------------------------------- 1 | { 2 | "xmrpool.eu" : { "url" : "xmrpool.eu", "port" : 3333, "emptypassword" : "", "algorithm" : "cn", "variant" : -1 }, 3 | "moneropool.com" : { "url" : "mine.moneropool.com", "port" : 3333, "emptypassword" : "", "algorithm" : "cn", "variant" : -1 }, 4 | "monero.crypto-pool.fr" : { "url" : "xmr.crypto-pool.fr", "port" : 3333, "emptypassword" : "", "algorithm" : "cn", "variant" : -1 }, 5 | "monerohash.com" : { "url" : "monerohash.com", "port" : 3333, "emptypassword" : "", "algorithm" : "cn", "variant" : -1 }, 6 | "minexmr.com" : { "url" : "pool.minexmr.com", "port" : 4444, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 7 | "usxmrpool.com" : { "url" : "pool.usxmrpool.com", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 8 | "supportxmr.com" : { "url" : "pool.supportxmr.com", "port" : 5555, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 9 | "moneroocean.stream:100" : { "url" : "gulf.moneroocean.stream", "port" : 80, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 10 | "moneroocean.stream" : { "url" : "gulf.moneroocean.stream", "port" : 10001, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 11 | "poolmining.org" : { "url" : "xmr.poolmining.org", "port" : 3032, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 12 | "minemonero.pro" : { "url" : "pool.minemonero.pro", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 13 | "xmr.prohash.net" : { "url" : "xmr.prohash.net", "port" : 1111, "emptypassword" : "", "algorithm" : "cn", "variant" : -1 }, 14 | "minercircle.com" : { "url" : "xmr.minercircle.com", "port" : 3333, "emptypassword" : "", "algorithm" : "cn", "variant" : -1 }, 15 | "xmr.nanopool.org" : { "url" : "xmr-eu1.nanopool.org", "port" : 14444, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 16 | "xmrminerpro.com" : { "url" : "xmrminerpro.com", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 17 | "clawde.xyz" : { "url" : "clawde.xyz", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 18 | "dwarfpool.com" : { "url" : "xmr-eu.dwarfpool.com", "port" : 8005, "emptypassword" : "", "algorithm" : "cn", "variant" : -1 }, 19 | "xmrpool.net" : { "url" : "mine.xmrpool.net", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 20 | "monero.hashvault.pro" : { "url" : "pool.monero.hashvault.pro", "port" : 5555, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 21 | "osiamining.com" : { "url" : "osiamining.com", "port" : 4545, "emptypassword" : "", "algorithm" : "cn", "variant" : -1 }, 22 | "killallasics" : { "url" : "killallasics.moneroworld.com", "port" : 3333, "emptypassword" : "", "algorithm" : "cn", "variant" : -1 }, 23 | "arhash.xyz" : { "url" : "arhash.xyz", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 24 | 25 | "aeon-pool.com" : { "url" : "mine.aeon-pool.com", "port" : 5555, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : -1 }, 26 | "minereasy.com" : { "url" : "aeon.minereasy.com", "port" : 3333, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : -1 }, 27 | "aeon.sumominer.com" : { "url" : "aeon.sumominer.com", "port" : 3333, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : -1 }, 28 | "aeon.rupool.tk" : { "url" : "aeon.rupool.tk", "port" : 4444, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : -1 }, 29 | "aeon.hashvault.pro" : { "url" : "pool.aeon.hashvault.pro", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn-lite", "variant" : -1 }, 30 | "aeon.n-engine.com" : { "url" : "aeon.n-engine.com", "port" : 7333, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : -1 }, 31 | "aeonpool.xyz" : { "url" : "mine.aeonpool.xyz", "port" : 3333, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : -1 }, 32 | "aeonpool.dreamitsystems.com" : { "url" : "aeonpool.dreamitsystems.com", "port" : 13333, "emptypassword" : "x", "algorithm" : "cn-lite", "variant" : -1 }, 33 | "aeonminingpool.com" : { "url" : "pool.aeonminingpool.com", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn-lite", "variant" : -1 }, 34 | "aeonhash.com" : { "url" : "pool.aeonhash.com", "port" : 3333, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : -1 }, 35 | "durinsmine.com" : { "url" : "mine.durinsmine.com", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn-lite", "variant" : -1 }, 36 | "aeon.uax.io" : { "url" : "mine.uax.io", "port" : 4446, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : -1 }, 37 | "aeon-pool.sytes.net" : { "url" : "aeon-pool.sytes.net", "port" : 3333, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : -1 }, 38 | "aeonpool.net" : { "url" : "pool.aeonpool.net", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn-lite", "variant" : -1 }, 39 | "supportaeon.com" : { "url" : "pool.supportaeon.com", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn-lite", "variant" : -1 }, 40 | "pooltupi.com" : { "url" : "pooltupi.com", "port" : 8080, "emptypassword" : "x", "algorithm" : "cn-lite", "variant" : -1 }, 41 | "aeon.semipool.com" : { "url" : "pool.aeon.semipool.com", "port" : 3333, "emptypassword" : "x", "algorithm" : "cn-lite", "variant" : -1 }, 42 | 43 | "slowandsteady.fun" : { "url" : "slowandsteady.fun", "port" : 3333, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : 1 }, 44 | "trtl.flashpool.club" : { "url" : "trtl.flashpool.club", "port" : 3333, "emptypassword" : "", "algorithm" : "cn-lite", "variant" : 1 }, 45 | 46 | "etn.poolmining.org" : { "url" : "etn.poolmining.org", "port" : 3102, "emptypassword" : "", "algorithm" : "cn", "variant" : -1 }, 47 | "etn.nanopool.org" : { "url" : "etn.nanopool.org", "port" : 13333, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 }, 48 | "etn.hashvault.pro" : { "url" : "etn.hashvault.pro", "port" : 80, "emptypassword" : "x", "algorithm" : "cn", "variant" : -1 } 49 | } 50 | -------------------------------------------------------------------------------- /SDK/miner_raw/miner/miner.js: -------------------------------------------------------------------------------- 1 | /* very simple monero miner which connects to 2 | * webminerpool.com. */ 3 | 4 | const wasmSupported = (() => { 5 | try { 6 | if (typeof WebAssembly === "object" 7 | && typeof WebAssembly.instantiate === "function") { 8 | const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)); 9 | if (module instanceof WebAssembly.Module) 10 | return new WebAssembly.Instance(module) instanceof WebAssembly.Instance; 11 | } 12 | } catch (e) { 13 | } 14 | return false; 15 | })(); 16 | 17 | var server="wss://ws1.server1:80/;wss://ws2.server2:80/;wss://ws3.server3:80/" // the webminerpool servers 18 | 19 | var job = null; // remember last job we got from the server 20 | var workers = []; // keep track of our workers 21 | var ws; // the websocket we use 22 | 23 | /* state variables */ 24 | 25 | var receiveStack = []; // everything we get from the server 26 | var sendStack = []; // everything we send to the server 27 | var totalhashes = 0; // number of hashes calculated 28 | var connected = 0; // 0->disconnected, 1->connected, 2->disconnected (error), 3->disconnect (on purpose) 29 | var reconnector = 0; // regular check if the WebSocket is still connected 30 | var attempts = 1; 31 | 32 | var throttleMiner = 0; // percentage of miner throttling. If you set this to 20, the 33 | // cpu workload will be approx. 80% (for 1 thread / CPU). 34 | // setting this value to 100 will not fully disable the miner but still 35 | // calculate hashes with 10% CPU load. See worker.js for details. 36 | 37 | var handshake = null; 38 | 39 | 40 | function addWorkers(numThreads) { 41 | logicalProcessors = numThreads; 42 | 43 | if (numThreads == -1) { 44 | 45 | /* try to find a good value */ 46 | 47 | try { 48 | logicalProcessors = window.navigator.hardwareConcurrency; 49 | } catch (err) { 50 | logicalProcessors = 4; 51 | } 52 | 53 | if (!((logicalProcessors > 0) && (logicalProcessors < 40))) 54 | logicalProcessors = 4; 55 | } 56 | 57 | 58 | while (logicalProcessors-- > 0) addWorker(); 59 | } 60 | 61 | var openWebSocket = function () { 62 | 63 | if (ws != null) { 64 | ws.close(); 65 | } 66 | 67 | var splitted = server.split(";") 68 | var chosen = splitted[Math.floor(Math.random() * Math.floor(splitted.length))]; 69 | 70 | ws = new WebSocket(chosen); 71 | 72 | ws.onmessage = on_servermsg; 73 | ws.onerror = function (event) { 74 | if (connected < 2) connected = 2; 75 | job = null; 76 | } 77 | ws.onclose = function () { 78 | if (connected < 2) connected = 2; 79 | job = null; 80 | } 81 | 82 | ws.onopen = function () { 83 | ws.send((JSON.stringify(handshake))); 84 | attempts = 1; 85 | connected = 1; 86 | } 87 | 88 | 89 | }; 90 | 91 | reconnector = function () { 92 | if (connected !== 3 && (ws == null || (ws.readyState !== 0 && ws.readyState !== 1))) { 93 | //console.log("The WebSocket is not connected. Trying to connect."); 94 | attempts++; 95 | openWebSocket(); 96 | } 97 | 98 | if (connected !== 3) 99 | setTimeout(reconnector, 10000 * attempts); 100 | }; 101 | 102 | // starts mining 103 | function startMiningWithId(loginid, numThreads = -1, userid = "") { 104 | 105 | if(!wasmSupported) return; 106 | 107 | stopMining(); 108 | connected = 0; 109 | 110 | handshake = { 111 | identifier: "handshake", 112 | loginid: loginid, 113 | userid: userid, 114 | version : 5 115 | }; 116 | 117 | addWorkers(numThreads); 118 | reconnector(); 119 | } 120 | 121 | // starts mining 122 | function startMining(pool, login, password = "", numThreads = -1, userid = "") { 123 | 124 | if(!wasmSupported) return; 125 | 126 | stopMining(); 127 | connected = 0; 128 | 129 | handshake = { 130 | identifier: "handshake", 131 | pool: pool, 132 | login: login, 133 | password: password, 134 | userid: userid, 135 | version : 5 136 | }; 137 | 138 | addWorkers(numThreads); 139 | reconnector(); 140 | } 141 | 142 | // stop mining 143 | function stopMining() { 144 | connected = 3; 145 | 146 | if (ws != null) ws.close(); 147 | deleteAllWorkers(); 148 | job = null; 149 | } 150 | 151 | // add one worker 152 | function addWorker() { 153 | var newWorker = new Worker("miner/worker.js"); 154 | workers.push(newWorker); 155 | 156 | newWorker.onmessage = on_workermsg; 157 | 158 | setTimeout(function () { 159 | informWorker(newWorker); 160 | }, 2000); 161 | } 162 | 163 | // remove one worker 164 | function removeWorker() { 165 | if (workers.length < 1) return; 166 | var wrk = workers.shift(); 167 | wrk.terminate(); 168 | } 169 | 170 | /* "internal" functions */ 171 | 172 | function deleteAllWorkers() { 173 | for (i = 0; i < workers.length; i++) { 174 | workers[i].terminate(); 175 | } 176 | workers = []; 177 | } 178 | 179 | function informWorker(wrk) { 180 | var evt = { 181 | data: "wakeup", 182 | target: wrk 183 | }; 184 | on_workermsg(evt); 185 | } 186 | 187 | function on_servermsg(e) { 188 | var obj = JSON.parse(e.data); 189 | 190 | receiveStack.push(obj); 191 | 192 | if (obj.identifier == "job") job = obj; 193 | } 194 | 195 | function on_workermsg(e) { 196 | var wrk = e.target; 197 | 198 | if (connected != 1) { 199 | setTimeout(function () { 200 | informWorker(wrk); 201 | }, 2000); 202 | return; 203 | } 204 | 205 | if ((e.data) != "nothing" && (e.data) != "wakeup") { 206 | // we solved a hash. forward it to the server. 207 | var obj = JSON.parse(e.data); 208 | ws.send(e.data); 209 | sendStack.push(obj); 210 | } 211 | 212 | if (job === null) { 213 | setTimeout(function () { 214 | informWorker(wrk); 215 | }, 2000); 216 | return; 217 | } 218 | 219 | var jbthrt = { 220 | job: job, 221 | throttle: Math.max(0, Math.min(throttleMiner, 100)) 222 | }; 223 | wrk.postMessage(jbthrt); 224 | 225 | if ((e.data) != "wakeup") totalhashes += 1; 226 | } 227 | -------------------------------------------------------------------------------- /hash_cn/webassembly/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 | -------------------------------------------------------------------------------- /server/Server/Fleck/Handlers/Draft76Handler.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/statianzo/Fleck 2 | 3 | // The MIT License 4 | 5 | // Copyright (c) 2010-2016 Jason Staten 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | using System; 25 | using System.Collections.Generic; 26 | using System.Linq; 27 | using System.Security.Cryptography; 28 | using System.Text; 29 | 30 | namespace Fleck.Handlers 31 | { 32 | public static class Draft76Handler 33 | { 34 | private const byte End = 255; 35 | private const byte Start = 0; 36 | private const int MaxSize = 1024 * 1024 * 5; 37 | 38 | public static IHandler Create(WebSocketHttpRequest request, Action onMessage) 39 | { 40 | return new ComposableHandler 41 | { 42 | TextFrame = Draft76Handler.FrameText, 43 | Handshake = sub => Draft76Handler.Handshake(request, sub), 44 | ReceiveData = data => ReceiveData(onMessage, data) 45 | }; 46 | } 47 | 48 | public static void ReceiveData(Action onMessage, List data) 49 | { 50 | while (data.Count > 0) 51 | { 52 | if (data[0] != Start) 53 | throw new WebSocketException(WebSocketStatusCodes.InvalidFramePayloadData); 54 | 55 | var endIndex = data.IndexOf(End); 56 | if (endIndex < 0) 57 | return; 58 | 59 | if (endIndex > MaxSize) 60 | throw new WebSocketException(WebSocketStatusCodes.MessageTooBig); 61 | 62 | var bytes = data.Skip(1).Take(endIndex - 1).ToArray(); 63 | 64 | data.RemoveRange(0, endIndex + 1); 65 | 66 | var message = Encoding.UTF8.GetString(bytes); 67 | 68 | onMessage(message); 69 | } 70 | } 71 | 72 | public static byte[] FrameText(string data) 73 | { 74 | byte[] bytes = Encoding.UTF8.GetBytes(data); 75 | // wrap the array with the wrapper bytes 76 | var wrappedBytes = new byte[bytes.Length + 2]; 77 | wrappedBytes[0] = Start; 78 | wrappedBytes[wrappedBytes.Length - 1] = End; 79 | Array.Copy(bytes, 0, wrappedBytes, 1, bytes.Length); 80 | return wrappedBytes; 81 | } 82 | 83 | public static byte[] Handshake(WebSocketHttpRequest request, string subProtocol) 84 | { 85 | FleckLog.Debug("Building Draft76 Response"); 86 | 87 | var builder = new StringBuilder(); 88 | builder.Append("HTTP/1.1 101 WebSocket Protocol Handshake\r\n"); 89 | builder.Append("Upgrade: WebSocket\r\n"); 90 | builder.Append("Connection: Upgrade\r\n"); 91 | builder.AppendFormat("Sec-WebSocket-Origin: {0}\r\n", request["Origin"]); 92 | builder.AppendFormat("Sec-WebSocket-Location: {0}://{1}{2}\r\n", request.Scheme, request["Host"], request.Path); 93 | 94 | if (subProtocol != null) 95 | builder.AppendFormat("Sec-WebSocket-Protocol: {0}\r\n", subProtocol); 96 | 97 | builder.Append("\r\n"); 98 | 99 | var key1 = request["Sec-WebSocket-Key1"]; 100 | var key2 = request["Sec-WebSocket-Key2"]; 101 | var challenge = new ArraySegment(request.Bytes, request.Bytes.Length - 8, 8); 102 | 103 | var answerBytes = CalculateAnswerBytes(key1, key2, challenge); 104 | 105 | byte[] byteResponse = Encoding.ASCII.GetBytes(builder.ToString()); 106 | int byteResponseLength = byteResponse.Length; 107 | Array.Resize(ref byteResponse, byteResponseLength + answerBytes.Length); 108 | Array.Copy(answerBytes, 0, byteResponse, byteResponseLength, answerBytes.Length); 109 | 110 | return byteResponse; 111 | } 112 | 113 | public static byte[] CalculateAnswerBytes(string key1, string key2, ArraySegment challenge) 114 | { 115 | byte[] result1Bytes = ParseKey(key1); 116 | byte[] result2Bytes = ParseKey(key2); 117 | 118 | var rawAnswer = new byte[16]; 119 | Array.Copy(result1Bytes, 0, rawAnswer, 0, 4); 120 | Array.Copy(result2Bytes, 0, rawAnswer, 4, 4); 121 | Array.Copy(challenge.Array, challenge.Offset, rawAnswer, 8, 8); 122 | 123 | return MD5.Create().ComputeHash(rawAnswer); 124 | } 125 | 126 | private static byte[] ParseKey(string key) 127 | { 128 | int spaces = key.Count(x => x == ' '); 129 | var digits = new String(key.Where(Char.IsDigit).ToArray()); 130 | 131 | var value = (Int32)(Int64.Parse(digits) / spaces); 132 | 133 | byte[] result = BitConverter.GetBytes(value); 134 | if (BitConverter.IsLittleEndian) 135 | Array.Reverse(result); 136 | return result; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /hash_cn/webassembly/base64.h: -------------------------------------------------------------------------------- 1 | // https://github.com/tkislan/base64 2 | 3 | #ifndef BASE64_H 4 | #define BASE64_H 5 | 6 | #include 7 | 8 | const char kBase64Alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 9 | "abcdefghijklmnopqrstuvwxyz" 10 | "0123456789+/"; 11 | 12 | class Base64 { 13 | public: 14 | static bool Encode(const std::string &in, std::string *out) { 15 | int i = 0, j = 0; 16 | size_t enc_len = 0; 17 | unsigned char a3[3]; 18 | unsigned char a4[4]; 19 | 20 | out->resize(EncodedLength(in)); 21 | 22 | int input_len = in.size(); 23 | std::string::const_iterator input = in.begin(); 24 | 25 | while (input_len--) { 26 | a3[i++] = *(input++); 27 | if (i == 3) { 28 | a3_to_a4(a4, a3); 29 | 30 | for (i = 0; i < 4; i++) { 31 | (*out)[enc_len++] = kBase64Alphabet[a4[i]]; 32 | } 33 | 34 | i = 0; 35 | } 36 | } 37 | 38 | if (i) { 39 | for (j = i; j < 3; j++) { 40 | a3[j] = '\0'; 41 | } 42 | 43 | a3_to_a4(a4, a3); 44 | 45 | for (j = 0; j < i + 1; j++) { 46 | (*out)[enc_len++] = kBase64Alphabet[a4[j]]; 47 | } 48 | 49 | while ((i++ < 3)) { 50 | (*out)[enc_len++] = '='; 51 | } 52 | } 53 | 54 | return (enc_len == out->size()); 55 | } 56 | 57 | static bool Encode(const char *input, size_t input_length, char *out, size_t out_length) { 58 | int i = 0, j = 0; 59 | char *out_begin = out; 60 | unsigned char a3[3]; 61 | unsigned char a4[4]; 62 | 63 | size_t encoded_length = EncodedLength(input_length); 64 | 65 | if (out_length < encoded_length) return false; 66 | 67 | while (input_length--) { 68 | a3[i++] = *input++; 69 | if (i == 3) { 70 | a3_to_a4(a4, a3); 71 | 72 | for (i = 0; i < 4; i++) { 73 | *out++ = kBase64Alphabet[a4[i]]; 74 | } 75 | 76 | i = 0; 77 | } 78 | } 79 | 80 | if (i) { 81 | for (j = i; j < 3; j++) { 82 | a3[j] = '\0'; 83 | } 84 | 85 | a3_to_a4(a4, a3); 86 | 87 | for (j = 0; j < i + 1; j++) { 88 | *out++ = kBase64Alphabet[a4[j]]; 89 | } 90 | 91 | while ((i++ < 3)) { 92 | *out++ = '='; 93 | } 94 | } 95 | 96 | return (out == (out_begin + encoded_length)); 97 | } 98 | 99 | static bool Decode(const std::string &in, std::string *out) { 100 | int i = 0, j = 0; 101 | size_t dec_len = 0; 102 | unsigned char a3[3]; 103 | unsigned char a4[4]; 104 | 105 | int input_len = in.size(); 106 | std::string::const_iterator input = in.begin(); 107 | 108 | out->resize(DecodedLength(in)); 109 | 110 | while (input_len--) { 111 | if (*input == '=') { 112 | break; 113 | } 114 | 115 | a4[i++] = *(input++); 116 | if (i == 4) { 117 | for (i = 0; i <4; i++) { 118 | a4[i] = b64_lookup(a4[i]); 119 | } 120 | 121 | a4_to_a3(a3,a4); 122 | 123 | for (i = 0; i < 3; i++) { 124 | (*out)[dec_len++] = a3[i]; 125 | } 126 | 127 | i = 0; 128 | } 129 | } 130 | 131 | if (i) { 132 | for (j = i; j < 4; j++) { 133 | a4[j] = '\0'; 134 | } 135 | 136 | for (j = 0; j < 4; j++) { 137 | a4[j] = b64_lookup(a4[j]); 138 | } 139 | 140 | a4_to_a3(a3,a4); 141 | 142 | for (j = 0; j < i - 1; j++) { 143 | (*out)[dec_len++] = a3[j]; 144 | } 145 | } 146 | 147 | return (dec_len == out->size()); 148 | } 149 | 150 | static bool Decode(const char *input, size_t input_length, char *out, size_t out_length) { 151 | int i = 0, j = 0; 152 | char *out_begin = out; 153 | unsigned char a3[3]; 154 | unsigned char a4[4]; 155 | 156 | size_t decoded_length = DecodedLength(input, input_length); 157 | 158 | if (out_length < decoded_length) return false; 159 | 160 | while (input_length--) { 161 | if (*input == '=') { 162 | break; 163 | } 164 | 165 | a4[i++] = *(input++); 166 | if (i == 4) { 167 | for (i = 0; i <4; i++) { 168 | a4[i] = b64_lookup(a4[i]); 169 | } 170 | 171 | a4_to_a3(a3,a4); 172 | 173 | for (i = 0; i < 3; i++) { 174 | *out++ = a3[i]; 175 | } 176 | 177 | i = 0; 178 | } 179 | } 180 | 181 | if (i) { 182 | for (j = i; j < 4; j++) { 183 | a4[j] = '\0'; 184 | } 185 | 186 | for (j = 0; j < 4; j++) { 187 | a4[j] = b64_lookup(a4[j]); 188 | } 189 | 190 | a4_to_a3(a3,a4); 191 | 192 | for (j = 0; j < i - 1; j++) { 193 | *out++ = a3[j]; 194 | } 195 | } 196 | 197 | return (out == (out_begin + decoded_length)); 198 | } 199 | 200 | static int DecodedLength(const char *in, size_t in_length) { 201 | int numEq = 0; 202 | 203 | const char *in_end = in + in_length; 204 | while (*--in_end == '=') ++numEq; 205 | 206 | return ((6 * in_length) / 8) - numEq; 207 | } 208 | 209 | static int DecodedLength(const std::string &in) { 210 | int numEq = 0; 211 | int n = in.size(); 212 | 213 | for (std::string::const_reverse_iterator it = in.rbegin(); *it == '='; ++it) { 214 | ++numEq; 215 | } 216 | 217 | return ((6 * n) / 8) - numEq; 218 | } 219 | 220 | inline static int EncodedLength(size_t length) { 221 | return (length + 2 - ((length + 2) % 3)) / 3 * 4; 222 | } 223 | 224 | inline static int EncodedLength(const std::string &in) { 225 | return EncodedLength(in.length()); 226 | } 227 | 228 | inline static void StripPadding(std::string *in) { 229 | while (!in->empty() && *(in->rbegin()) == '=') in->resize(in->size() - 1); 230 | } 231 | 232 | private: 233 | static inline void a3_to_a4(unsigned char * a4, unsigned char * a3) { 234 | a4[0] = (a3[0] & 0xfc) >> 2; 235 | a4[1] = ((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4); 236 | a4[2] = ((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6); 237 | a4[3] = (a3[2] & 0x3f); 238 | } 239 | 240 | static inline void a4_to_a3(unsigned char * a3, unsigned char * a4) { 241 | a3[0] = (a4[0] << 2) + ((a4[1] & 0x30) >> 4); 242 | a3[1] = ((a4[1] & 0xf) << 4) + ((a4[2] & 0x3c) >> 2); 243 | a3[2] = ((a4[2] & 0x3) << 6) + a4[3]; 244 | } 245 | 246 | static inline unsigned char b64_lookup(unsigned char c) { 247 | if(c >='A' && c <='Z') return c - 'A'; 248 | if(c >='a' && c <='z') return c - 71; 249 | if(c >='0' && c <='9') return c + 4; 250 | if(c == '+') return 62; 251 | if(c == '/') return 63; 252 | return 255; 253 | } 254 | }; 255 | 256 | 257 | 258 | #endif // BASE64_H 259 | -------------------------------------------------------------------------------- /hash_cn/webassembly/oaes_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_LIB_H 32 | #define _OAES_LIB_H 33 | 34 | #include 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #ifdef _WIN32 41 | # ifdef OAES_SHARED 42 | # ifdef oaes_lib_EXPORTS 43 | # define OAES_API __declspec(dllexport) 44 | # else 45 | # define OAES_API __declspec(dllimport) 46 | # endif 47 | # else 48 | # define OAES_API 49 | # endif 50 | #else 51 | # define OAES_API 52 | #endif // WIN32 53 | 54 | #define OAES_VERSION "0.8.1" 55 | #define OAES_BLOCK_SIZE 16 56 | 57 | typedef void OAES_CTX; 58 | 59 | typedef enum 60 | { 61 | OAES_RET_FIRST = 0, 62 | OAES_RET_SUCCESS = 0, 63 | OAES_RET_UNKNOWN, 64 | OAES_RET_ARG1, 65 | OAES_RET_ARG2, 66 | OAES_RET_ARG3, 67 | OAES_RET_ARG4, 68 | OAES_RET_ARG5, 69 | OAES_RET_NOKEY, 70 | OAES_RET_MEM, 71 | OAES_RET_BUF, 72 | OAES_RET_HEADER, 73 | OAES_RET_COUNT 74 | } OAES_RET; 75 | 76 | /* 77 | * oaes_set_option() takes one of these values for its [option] parameter 78 | * some options accept either an optional or a required [value] parameter 79 | */ 80 | // no option 81 | #define OAES_OPTION_NONE 0 82 | // enable ECB mode, disable CBC mode 83 | #define OAES_OPTION_ECB 1 84 | // enable CBC mode, disable ECB mode 85 | // value is optional, may pass uint8_t iv[OAES_BLOCK_SIZE] to specify 86 | // the value of the initialization vector, iv 87 | #define OAES_OPTION_CBC 2 88 | 89 | #ifdef OAES_DEBUG 90 | typedef int ( * oaes_step_cb ) ( 91 | const uint8_t state[OAES_BLOCK_SIZE], 92 | const char * step_name, 93 | int step_count, 94 | void * user_data ); 95 | // enable state stepping mode 96 | // value is required, must pass oaes_step_cb to receive the state at each step 97 | #define OAES_OPTION_STEP_ON 4 98 | // disable state stepping mode 99 | #define OAES_OPTION_STEP_OFF 8 100 | #endif // OAES_DEBUG 101 | 102 | typedef uint16_t OAES_OPTION; 103 | 104 | typedef struct _oaes_key 105 | { 106 | size_t data_len; 107 | uint8_t *data; 108 | size_t exp_data_len; 109 | uint8_t *exp_data; 110 | size_t num_keys; 111 | size_t key_base; 112 | } oaes_key; 113 | 114 | typedef struct _oaes_ctx 115 | { 116 | #ifdef OAES_HAVE_ISAAC 117 | randctx * rctx; 118 | #endif // OAES_HAVE_ISAAC 119 | 120 | #ifdef OAES_DEBUG 121 | oaes_step_cb step_cb; 122 | #endif // OAES_DEBUG 123 | 124 | oaes_key * key; 125 | OAES_OPTION options; 126 | uint8_t iv[OAES_BLOCK_SIZE]; 127 | } oaes_ctx; 128 | /* 129 | * // usage: 130 | * 131 | * OAES_CTX * ctx = oaes_alloc(); 132 | * . 133 | * . 134 | * . 135 | * { 136 | * oaes_gen_key_xxx( ctx ); 137 | * { 138 | * oaes_key_export( ctx, _buf, &_buf_len ); 139 | * // or 140 | * oaes_key_export_data( ctx, _buf, &_buf_len );\ 141 | * } 142 | * } 143 | * // or 144 | * { 145 | * oaes_key_import( ctx, _buf, _buf_len ); 146 | * // or 147 | * oaes_key_import_data( ctx, _buf, _buf_len ); 148 | * } 149 | * . 150 | * . 151 | * . 152 | * oaes_encrypt( ctx, m, m_len, c, &c_len ); 153 | * . 154 | * . 155 | * . 156 | * oaes_decrypt( ctx, c, c_len, m, &m_len ); 157 | * . 158 | * . 159 | * . 160 | * oaes_free( &ctx ); 161 | */ 162 | 163 | OAES_API OAES_CTX * oaes_alloc(void); 164 | 165 | OAES_API OAES_RET oaes_free( OAES_CTX ** ctx ); 166 | 167 | OAES_API OAES_RET oaes_set_option( OAES_CTX * ctx, 168 | OAES_OPTION option, const void * value ); 169 | 170 | OAES_API OAES_RET oaes_key_gen_128( OAES_CTX * ctx ); 171 | 172 | OAES_API OAES_RET oaes_key_gen_192( OAES_CTX * ctx ); 173 | 174 | OAES_API OAES_RET oaes_key_gen_256( OAES_CTX * ctx ); 175 | 176 | // export key with header information 177 | // set data == NULL to get the required data_len 178 | OAES_API OAES_RET oaes_key_export( OAES_CTX * ctx, 179 | uint8_t * data, size_t * data_len ); 180 | 181 | // directly export the data from key 182 | // set data == NULL to get the required data_len 183 | OAES_API OAES_RET oaes_key_export_data( OAES_CTX * ctx, 184 | uint8_t * data, size_t * data_len ); 185 | 186 | // import key with header information 187 | OAES_API OAES_RET oaes_key_import( OAES_CTX * ctx, 188 | const uint8_t * data, size_t data_len ); 189 | 190 | // directly import data into key 191 | OAES_API OAES_RET oaes_key_import_data( OAES_CTX * ctx, 192 | const uint8_t * data, size_t data_len ); 193 | 194 | // set c == NULL to get the required c_len 195 | OAES_API OAES_RET oaes_encrypt( OAES_CTX * ctx, 196 | const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len ); 197 | 198 | // set m == NULL to get the required m_len 199 | OAES_API OAES_RET oaes_decrypt( OAES_CTX * ctx, 200 | const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len ); 201 | 202 | // set buf == NULL to get the required buf_len 203 | OAES_API OAES_RET oaes_sprintf( 204 | char * buf, size_t * buf_len, const uint8_t * data, size_t data_len ); 205 | 206 | OAES_API OAES_RET oaes_encryption_round( const uint8_t * key, uint8_t * c ); 207 | 208 | OAES_API OAES_RET oaes_pseudo_encrypt_ecb( OAES_CTX * ctx, uint8_t * c ); 209 | 210 | #ifdef __cplusplus 211 | } 212 | #endif 213 | 214 | #endif // _OAES_LIB_H 215 | --------------------------------------------------------------------------------