├── cryptoport-miner.xcodeproj ├── xcuserdata │ └── uraymeiviar.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ ├── release.xcscheme │ │ └── cryptoport-miner.xcscheme ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcuserdata │ │ └── uraymeiviar.xcuserdatad │ │ │ ├── UserInterfaceState.xcuserstate │ │ │ └── xcdebugger │ │ │ └── Expressions.xcexplist │ └── xcshareddata │ │ └── cryptoport-miner.xccheckout └── project.pbxproj ├── bin └── mining.conf ├── src ├── MinerLogger.cpp ├── MinerLogger.h ├── MinerShabal.h ├── rapidjson │ ├── internal │ │ ├── strfunc.h │ │ ├── stack.h │ │ └── pow10.h │ ├── filestream.h │ ├── stringbuffer.h │ ├── prettywriter.h │ ├── writer.h │ ├── rapidjson.h │ └── reader.h ├── MinerShabal.cpp ├── nxt │ ├── nxt_address.h │ └── nxt_address.cpp ├── MinerUtil.h ├── PlotReader.h ├── MinerConfig.h ├── MinerProtocol.h ├── main.cpp ├── Miner.h ├── MinerUtil.cpp ├── Miner.cpp ├── MinerConfig.cpp ├── MinerProtocol.cpp ├── PlotReader.cpp └── sphlib │ ├── sph_shabal.h │ └── sph_shabal.cpp ├── README.md ├── Makefile ├── burst-miner.sln ├── burst-miner.vcxproj.filters └── burst-miner.vcxproj /cryptoport-miner.xcodeproj/xcuserdata/uraymeiviar.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /cryptoport-miner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /cryptoport-miner.xcodeproj/project.xcworkspace/xcuserdata/uraymeiviar.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uraymeiviar/burst-miner/HEAD/cryptoport-miner.xcodeproj/project.xcworkspace/xcuserdata/uraymeiviar.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /bin/mining.conf: -------------------------------------------------------------------------------- 1 | { 2 | "poolUrl" : "burst-pool.cryptoport.io", 3 | "submissionMaxDelay" : 30, 4 | "submissionMaxRetry" : 3, 5 | "socketTimeout" : 60, 6 | "maxBufferSizeMB" : 128, 7 | "plots" : 8 | [ 9 | "/Users/uraymeiviar/plots", 10 | "/Users/uraymeiviar/Documents/plots" 11 | ] 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/MinerLogger.cpp: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #include "Miner.h" 10 | 11 | void Burst::MinerLogger::write(const std::string text) 12 | { 13 | std::lock_guard lock(MinerLogger::getInstance()->consoleMutex); 14 | std::cout << text << std::endl; 15 | } 16 | 17 | Burst::MinerLogger* Burst::MinerLogger::getInstance() 18 | { 19 | static Burst::MinerLogger instance; 20 | return &instance; 21 | } -------------------------------------------------------------------------------- /src/MinerLogger.h: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #ifndef cryptoport_MinerLogger_h 10 | #define cryptoport_MinerLogger_h 11 | #include "Miner.h" 12 | 13 | namespace Burst 14 | { 15 | class MinerLogger 16 | { 17 | public: 18 | static void write(const std::string text); 19 | static MinerLogger* getInstance(); 20 | std::mutex consoleMutex; 21 | private: 22 | }; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /cryptoport-miner.xcodeproj/xcuserdata/uraymeiviar.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | cryptoport-miner.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 1495546B19C6C76100DC6D79 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/MinerShabal.h: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #ifndef cryptoport_MinerShabal_h 10 | #define cryptoport_MinerShabal_h 11 | #include "Miner.h" 12 | 13 | namespace Burst 14 | { 15 | class Shabal256 16 | { 17 | public : 18 | Shabal256(); 19 | void update(const void* data, size_t length); 20 | void update(const uint64_t data); 21 | void close(void* outData); 22 | private : 23 | sph_shabal256_context context; 24 | }; 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | burst-miner 2 | =========== 3 | 4 | native burstcoin miner, its fast, its multithreaded, low memory usage, multi-account and multi-plot 5 | you can specity plot directory or files inside mining.conf file 6 | 7 | contact : uray meiviar [ uraymeiviar@gmail.com ] 8 | 9 | please donate to support developments : 10 | 11 | + [ Burst ] `BURST-8E8K-WQ2F-ZDZ5-FQWHX` 12 | + [ Bitcoin ] `1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b` 13 | 14 | ## compilation : 15 | tested on OSX and Linux using GCC 4.8.x 16 | 17 | + for linux, just do "make", binary will be in "bin" directory and then edit "mining.conf" file 18 | + for windows, compilation is tested using Visual Studio Express 2013 (Desktop) 19 | + for OSX, compilation is tested using XCode 5 20 | -------------------------------------------------------------------------------- /src/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 2 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 3 | 4 | namespace rapidjson { 5 | namespace internal { 6 | 7 | //! Custom strlen() which works on different character types. 8 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 9 | \param s Null-terminated input string. 10 | \return Number of characters in the string. 11 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 12 | */ 13 | template 14 | inline SizeType StrLen(const Ch* s) { 15 | const Ch* p = s; 16 | while (*p != '\0') 17 | ++p; 18 | return SizeType(p - s); 19 | } 20 | 21 | } // namespace internal 22 | } // namespace rapidjson 23 | 24 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 25 | -------------------------------------------------------------------------------- /src/MinerShabal.cpp: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #include "Miner.h" 10 | 11 | Burst::Shabal256::Shabal256() 12 | { 13 | sph_shabal256_init(&this->context); 14 | } 15 | 16 | void Burst::Shabal256::update(const void* data, size_t length) 17 | { 18 | sph_shabal256(&this->context,data,length); 19 | } 20 | 21 | void Burst::Shabal256::update(const uint64_t data) 22 | { 23 | uint64_t result = __builtin_bswap64(data); 24 | this->update(&result, sizeof(uint64_t)); 25 | } 26 | 27 | void Burst::Shabal256::close(void* outData) 28 | { 29 | sph_shabal256_close(&this->context,outData); 30 | } 31 | -------------------------------------------------------------------------------- /src/nxt/nxt_address.h: -------------------------------------------------------------------------------- 1 | /* 2 | Basic NXT address (without error correction). 3 | 4 | More info: http://wiki.nxtcrypto.org/wiki/New_Address_Format 5 | 6 | Version: 1.0, license: Public Domain, coder: NxtChg (admin@nxtchg.com). 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | class NxtAddress 16 | { 17 | public: 18 | NxtAddress(uint64_t id); 19 | static char alphabet[33]; 20 | char* account_id(); 21 | bool set(char *adr); 22 | char* c_str(bool prefix = false); 23 | std::string to_string(); 24 | operator uint64_t(); 25 | void operator=(uint64_t acc); 26 | 27 | private: 28 | char codeword[17]; 29 | char syndrome[5]; 30 | static int gexp[32]; 31 | static int glog[32]; 32 | int gmult(int a, int b); 33 | void encode(); 34 | bool ok(); 35 | }; 36 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS := -O3 -march=native -std=c++11 -Wall -D_REENTRANT 2 | CC := g++ $(CFLAGS) 3 | LD := g++ -pthread 4 | 5 | MODULES := rapidjson sphlib nxt 6 | SRC_DIR := $(addprefix src/,$(MODULES)) src 7 | BUILD_DIR := $(addprefix bin/,$(MODULES)) bin 8 | 9 | SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp)) 10 | OBJ := $(patsubst src/%.cpp,bin/%.o,$(SRC)) 11 | INCLUDES := $(addprefix -I,$(SRC_DIR)) 12 | 13 | EXECUTABLE:= burstminer 14 | 15 | vpath %.cpp $(SRC_DIR) 16 | 17 | define make-goal 18 | $1/%.o: %.cpp 19 | $(CC) $(INCLUDES) -c $$< -o $$@ 20 | endef 21 | 22 | .PHONY: all checkdirs clean 23 | 24 | all: checkdirs bin/$(EXECUTABLE) 25 | 26 | bin/$(EXECUTABLE): $(OBJ) 27 | $(LD) $^ -o $@ 28 | 29 | checkdirs: $(BUILD_DIR) 30 | 31 | $(BUILD_DIR): 32 | @mkdir -p $@ 33 | 34 | clean: 35 | @rm -rf $(BUILD_DIR) 36 | 37 | $(foreach bdir,$(BUILD_DIR),$(eval $(call make-goal,$(bdir)))) 38 | -------------------------------------------------------------------------------- /burst-miner.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2013 for Windows Desktop 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "burst-miner", "burst-miner.vcxproj", "{0FBF38FD-4EE5-4E43-ADFB-C808DE6154F1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0FBF38FD-4EE5-4E43-ADFB-C808DE6154F1}.Debug|x64.ActiveCfg = Debug|x64 15 | {0FBF38FD-4EE5-4E43-ADFB-C808DE6154F1}.Debug|x64.Build.0 = Debug|x64 16 | {0FBF38FD-4EE5-4E43-ADFB-C808DE6154F1}.Release|x64.ActiveCfg = Release|x64 17 | {0FBF38FD-4EE5-4E43-ADFB-C808DE6154F1}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /src/rapidjson/filestream.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_FILESTREAM_H_ 2 | #define RAPIDJSON_FILESTREAM_H_ 3 | 4 | #include 5 | 6 | namespace rapidjson { 7 | 8 | //! Wrapper of C file stream for input or output. 9 | /*! 10 | This simple wrapper does not check the validity of the stream. 11 | \implements Stream 12 | */ 13 | class FileStream { 14 | public: 15 | typedef char Ch; //!< Character type. Only support char. 16 | 17 | FileStream(FILE* fp) : fp_(fp), count_(0) { Read(); } 18 | char Peek() const { return current_; } 19 | char Take() { char c = current_; Read(); return c; } 20 | size_t Tell() const { return count_; } 21 | void Put(char c) { fputc(c, fp_); } 22 | 23 | // Not implemented 24 | char* PutBegin() { return 0; } 25 | size_t PutEnd(char*) { return 0; } 26 | 27 | private: 28 | void Read() { 29 | RAPIDJSON_ASSERT(fp_ != 0); 30 | int c = fgetc(fp_); 31 | if (c != EOF) { 32 | current_ = (char)c; 33 | count_++; 34 | } 35 | else 36 | current_ = '\0'; 37 | } 38 | 39 | FILE* fp_; 40 | char current_; 41 | size_t count_; 42 | }; 43 | 44 | } // namespace rapidjson 45 | 46 | #endif // RAPIDJSON_FILESTREAM_H_ 47 | -------------------------------------------------------------------------------- /src/MinerUtil.h: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #ifndef cryptoport_MinerUtil_h 10 | #define cryptoport_MinerUtil_h 11 | #include "Miner.h" 12 | 13 | namespace Burst 14 | { 15 | template 16 | std::string byteArrayToStr(const std::array& arr) 17 | { 18 | std::stringstream stream; 19 | for(size_t i=0 ; i &splitStr(const std::string &s, char delim, std::vector &elems); 29 | std::vector splitStr(const std::string &s, char delim); 30 | bool isValidPlotFile(const std::string filePath); 31 | std::string getAccountIdFromPlotFile(const std::string path); 32 | std::string getStartNonceFromPlotFile(const std::string path); 33 | std::string getNonceCountFromPlotFile(const std::string path); 34 | std::string getStaggerSizeFromPlotFile(const std::string path); 35 | std::string deadlineFormat(uint64_t seconds); 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/PlotReader.h: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #ifndef cryptoport_PlotReader_h 10 | #define cryptoport_PlotReader_h 11 | #include "Miner.h" 12 | 13 | namespace Burst 14 | { 15 | class PlotReader 16 | { 17 | public: 18 | PlotReader(Miner* miner); 19 | ~PlotReader(); 20 | 21 | void read(const std::string path); 22 | void stop(); 23 | bool isDone() const; 24 | 25 | private: 26 | void readerThread(); 27 | void verifierThread(); 28 | 29 | size_t nonceStart; 30 | size_t scoopNum; 31 | size_t nonceCount; 32 | size_t nonceOffset; 33 | size_t nonceRead; 34 | size_t staggerSize; 35 | uint64_t accountId; 36 | GensigData gensig; 37 | 38 | bool done; 39 | bool runVerify; 40 | std::string inputPath; 41 | 42 | Miner* miner; 43 | std::thread readerThreadObj; 44 | 45 | std::vector buffer[2]; 46 | 47 | Shabal256 hash; 48 | bool verifySignaled; 49 | std::mutex verifyMutex; 50 | std::condition_variable verifySignal; 51 | std::vector* readBuffer; 52 | std::vector* writeBuffer; 53 | }; 54 | } 55 | #endif 56 | -------------------------------------------------------------------------------- /src/rapidjson/stringbuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_STRINGBUFFER_H_ 2 | #define RAPIDJSON_STRINGBUFFER_H_ 3 | 4 | #include "rapidjson.h" 5 | #include "internal/stack.h" 6 | 7 | namespace rapidjson { 8 | 9 | //! Represents an in-memory output stream. 10 | /*! 11 | \tparam Encoding Encoding of the stream. 12 | \tparam Allocator type for allocating memory buffer. 13 | \implements Stream 14 | */ 15 | template 16 | struct GenericStringBuffer { 17 | typedef typename Encoding::Ch Ch; 18 | 19 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 20 | 21 | void Put(Ch c) { *stack_.template Push() = c; } 22 | 23 | void Clear() { stack_.Clear(); } 24 | 25 | const char* GetString() const { 26 | // Push and pop a null terminator. This is safe. 27 | *stack_.template Push() = '\0'; 28 | stack_.template Pop(1); 29 | 30 | return stack_.template Bottom(); 31 | } 32 | 33 | size_t Size() const { return stack_.GetSize(); } 34 | 35 | static const size_t kDefaultCapacity = 256; 36 | mutable internal::Stack stack_; 37 | }; 38 | 39 | typedef GenericStringBuffer > StringBuffer; 40 | 41 | //! Implement specialized version of PutN() with memset() for better performance. 42 | template<> 43 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 44 | memset(stream.stack_.Push(n), c, n * sizeof(c)); 45 | } 46 | 47 | } // namespace rapidjson 48 | 49 | #endif // RAPIDJSON_STRINGBUFFER_H_ 50 | -------------------------------------------------------------------------------- /src/MinerConfig.h: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #ifndef cryptoport_MinerConfig_h 10 | #define cryptoport_MinerConfig_h 11 | #include "Miner.h" 12 | 13 | /* 14 | { 15 | poolUrl : "burst-pool.cryptoport.io:80", 16 | submissionMaxDelay : 60000, 17 | submissionMaxRetry : 3, 18 | plots : [ 19 | "/mnt/sda/plots/", 20 | "/mnt/sdb/plots/" 21 | ] 22 | } 23 | */ 24 | 25 | namespace Burst 26 | { 27 | class MinerConfig 28 | { 29 | public: 30 | bool readConfigFile(const std::string configPath); 31 | void rescan(); 32 | 33 | size_t submissionMaxDelay = 60; 34 | size_t submissionMaxRetry = 5; 35 | std::string poolHost = "burst-pool.cryptoport.io"; 36 | size_t poolPort = 80; 37 | size_t socketTimeout = 30; 38 | size_t maxBufferSizeMB = 64; 39 | std::string configPath; 40 | std::vector plotList; 41 | 42 | static const size_t hashSize = 32; 43 | static const size_t scoopPerPlot = 4096; 44 | static const size_t hashPerScoop = 2; 45 | static const size_t scoopSize = hashPerScoop * hashSize; // 64 Bytes 46 | static const size_t plotSize = scoopPerPlot * scoopSize; // 256KB = 262144 Bytes 47 | static const size_t plotScoopSize = scoopSize + hashSize; // 64 + 32 bytes 48 | private : 49 | bool addPlotLocation(const std::string fileOrPath); 50 | bool addPlotFile( std::string file); 51 | }; 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /cryptoport-miner.xcodeproj/project.xcworkspace/xcshareddata/cryptoport-miner.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 54E49234-074E-4CB2-9E27-7CF69CC8134C 9 | IDESourceControlProjectName 10 | cryptoport-miner 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 56C38A96-19B0-4BDF-89AE-8429140D9C14 14 | https://github.com/uraymeiviar/burst-miner.git 15 | 16 | IDESourceControlProjectPath 17 | cryptoport-miner.xcodeproj/project.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 56C38A96-19B0-4BDF-89AE-8429140D9C14 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/uraymeiviar/burst-miner.git 25 | IDESourceControlProjectVersion 26 | 110 27 | IDESourceControlProjectWCCIdentifier 28 | 56C38A96-19B0-4BDF-89AE-8429140D9C14 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 56C38A96-19B0-4BDF-89AE-8429140D9C14 36 | IDESourceControlWCCName 37 | burst-miner 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/MinerProtocol.h: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #ifndef cryptoport_MinerProtocol_h 10 | #define cryptoport_MinerProtocol_h 11 | #include "Miner.h" 12 | 13 | namespace Burst 14 | { 15 | class MinerSocket 16 | { 17 | public: 18 | void setRemote(const std::string ip, size_t port,size_t defaultTimeout = 60); 19 | std::string httpPost(const std::string url, const std::string body); 20 | std::string httpGet(const std::string url); 21 | void httpPostAsync(const std::string url, const std::string body,std::function< void ( std::string ) > responseCallback); 22 | void httpGetAsync(const std::string url,std::function< void ( std::string ) > responseCallback); 23 | private: 24 | std::string httpRequest(const std::string method, const std::string url, 25 | const std::string body, const std::string header); 26 | void httpRequestAsync(const std::string method, const std::string url, 27 | const std::string body, const std::string header, 28 | std::function< void ( std::string ) > responseCallback ); 29 | static const size_t readBufferSize = 2048; 30 | char readBuffer[readBufferSize]; 31 | struct sockaddr_in remoteAddr; 32 | struct timeval socketTimeout; 33 | }; 34 | 35 | class MinerProtocol 36 | { 37 | public: 38 | MinerProtocol(); 39 | ~MinerProtocol(); 40 | 41 | bool run(Miner* miner); 42 | void stop(); 43 | uint64_t submitNonce(uint64_t nonce, uint64_t accountId); 44 | static std::string resolveHostname(const std::string host); 45 | private: 46 | Miner* miner; 47 | bool running; 48 | void getMiningInfo(); 49 | uint64_t currentBlockHeight; 50 | uint64_t currentBaseTarget; 51 | std::string gensig; 52 | 53 | MinerSocket miningInfoSocket; 54 | MinerSocket nonceSubmitterSocket; 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /cryptoport-miner.xcodeproj/project.xcworkspace/xcuserdata/uraymeiviar.xcuserdatad/xcdebugger/Expressions.xcexplist: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 11 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | 23 | 24 | 26 | 27 | 29 | 30 | 31 | 32 | 34 | 35 | 37 | 38 | 39 | 40 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #include "Miner.h" 10 | 11 | int main(int argc, const char* argv[]) 12 | { 13 | Burst::MinerLogger::write("Burst cryptoport Miners"); 14 | Burst::MinerLogger::write("-----------------------"); 15 | Burst::MinerLogger::write("http://github.com/uraymeiviar/burst-miner"); 16 | Burst::MinerLogger::write("author : uray meiviar [ uraymeiviar@gmail.com ]"); 17 | Burst::MinerLogger::write("please donate to support developments :"); 18 | Burst::MinerLogger::write(" [ Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX"); 19 | Burst::MinerLogger::write(" [ Bitcoin ] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b"); 20 | Burst::MinerLogger::write(" "); 21 | 22 | #ifdef WIN32 23 | WSADATA wsadata; 24 | if (WSAStartup(MAKEWORD(2, 2), &wsadata) != 0) 25 | { 26 | Burst::MinerLogger::write("failed to initalize networking system"); 27 | } 28 | #endif 29 | 30 | std::string configFile = "mining.conf"; 31 | if(argc > 1) 32 | { 33 | if(argv[1][0] == '-') 34 | { 35 | Burst::MinerLogger::write("usage : burstminer "); 36 | Burst::MinerLogger::write("if no config-file specified, program will look for mining.conf file inside current directory"); 37 | } 38 | configFile = std::string(argv[1]); 39 | } 40 | Burst::MinerLogger::write("using config file : "+configFile); 41 | 42 | Burst::MinerConfig config; 43 | if( config.readConfigFile(configFile) ) 44 | { 45 | Burst::MinerLogger::write("Submission Max Delay : "+ std::to_string(config.submissionMaxDelay)); 46 | Burst::MinerLogger::write("Submission Max Retry : "+ std::to_string(config.submissionMaxRetry)); 47 | Burst::MinerLogger::write("Buffer Size : "+ std::to_string(config.maxBufferSizeMB)+"MB"); 48 | Burst::MinerLogger::write("Pool Host : "+config.poolHost+" port "+ std::to_string(config.poolPort)); 49 | 50 | Burst::Miner miner(config); 51 | miner.run(); 52 | } 53 | else 54 | { 55 | Burst::MinerLogger::write("Aborting program due to invalid configuration"); 56 | } 57 | 58 | #ifdef WIN32 59 | WSACleanup(); 60 | #endif 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/rapidjson/internal/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_INTERNAL_STACK_H_ 2 | #define RAPIDJSON_INTERNAL_STACK_H_ 3 | 4 | namespace rapidjson { 5 | namespace internal { 6 | 7 | /////////////////////////////////////////////////////////////////////////////// 8 | // Stack 9 | 10 | //! A type-unsafe stack for storing different types of data. 11 | /*! \tparam Allocator Allocator for allocating stack memory. 12 | */ 13 | template 14 | class Stack { 15 | public: 16 | Stack(Allocator* allocator, size_t stack_capacity) : allocator_(allocator), own_allocator_(0), stack_(0), stack_top_(0), stack_end_(0), stack_capacity_(stack_capacity) { 17 | RAPIDJSON_ASSERT(stack_capacity_ > 0); 18 | if (!allocator_) 19 | own_allocator_ = allocator_ = new Allocator(); 20 | stack_top_ = stack_ = (char*)allocator_->Malloc(stack_capacity_); 21 | stack_end_ = stack_ + stack_capacity_; 22 | } 23 | 24 | ~Stack() { 25 | Allocator::Free(stack_); 26 | delete own_allocator_; // Only delete if it is owned by the stack 27 | } 28 | 29 | void Clear() { /*stack_top_ = 0;*/ stack_top_ = stack_; } 30 | 31 | template 32 | T* Push(size_t count = 1) { 33 | // Expand the stack if needed 34 | if (stack_top_ + sizeof(T) * count >= stack_end_) { 35 | size_t new_capacity = stack_capacity_ * 2; 36 | size_t size = GetSize(); 37 | size_t new_size = GetSize() + sizeof(T) * count; 38 | if (new_capacity < new_size) 39 | new_capacity = new_size; 40 | stack_ = (char*)allocator_->Realloc(stack_, stack_capacity_, new_capacity); 41 | stack_capacity_ = new_capacity; 42 | stack_top_ = stack_ + size; 43 | stack_end_ = stack_ + stack_capacity_; 44 | } 45 | T* ret = (T*)stack_top_; 46 | stack_top_ += sizeof(T) * count; 47 | return ret; 48 | } 49 | 50 | template 51 | T* Pop(size_t count) { 52 | RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T)); 53 | stack_top_ -= count * sizeof(T); 54 | return (T*)stack_top_; 55 | } 56 | 57 | template 58 | T* Top() { 59 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 60 | return (T*)(stack_top_ - sizeof(T)); 61 | } 62 | 63 | template 64 | T* Bottom() { return (T*)stack_; } 65 | 66 | Allocator& GetAllocator() { return *allocator_; } 67 | size_t GetSize() const { return stack_top_ - stack_; } 68 | size_t GetCapacity() const { return stack_capacity_; } 69 | 70 | private: 71 | Allocator* allocator_; 72 | Allocator* own_allocator_; 73 | char *stack_; 74 | char *stack_top_; 75 | char *stack_end_; 76 | size_t stack_capacity_; 77 | }; 78 | 79 | } // namespace internal 80 | } // namespace rapidjson 81 | 82 | #endif // RAPIDJSON_STACK_H_ 83 | -------------------------------------------------------------------------------- /burst-miner.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | nxt 14 | 15 | 16 | sphlib 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | rapidjson 29 | 30 | 31 | rapidjson 32 | 33 | 34 | rapidjson 35 | 36 | 37 | rapidjson 38 | 39 | 40 | rapidjson 41 | 42 | 43 | rapidjson 44 | 45 | 46 | rapidjson 47 | 48 | 49 | nxt 50 | 51 | 52 | sphlib 53 | 54 | 55 | sphlib 56 | 57 | 58 | 59 | 60 | {531922ef-2cd8-4350-b951-76cbc096b866} 61 | 62 | 63 | {42eb2a1b-d1fb-4180-8563-9545d4df189e} 64 | 65 | 66 | {242f4f66-14f5-4d5c-8fad-1da976a482d7} 67 | 68 | 69 | -------------------------------------------------------------------------------- /cryptoport-miner.xcodeproj/xcuserdata/uraymeiviar.xcuserdatad/xcschemes/release.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /cryptoport-miner.xcodeproj/xcuserdata/uraymeiviar.xcuserdatad/xcschemes/cryptoport-miner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /src/Miner.h: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #ifndef cryptoport_Miner_h 10 | #define cryptoport_Miner_h 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #include "rapidjson/document.h" 37 | 38 | #ifndef WIN32 39 | # include 40 | # include 41 | # include 42 | # include 43 | # include "unistd.h" 44 | # include 45 | # ifndef MSG_NOSIGNAL 46 | # define MSG_NOSIGNAL SO_NOSIGPIPE 47 | # endif 48 | # define closesocket close 49 | # define SOCKET int 50 | # define PATH_SEPARATOR '/' 51 | #else 52 | # define MSG_NOSIGNAL 0 53 | # include "win/dirent.h" 54 | # include 55 | # include 56 | # include 57 | # define strcasecmp _stricmp 58 | # define strncasecmp _strnicmp 59 | # define SHUT_RDWR SD_BOTH 60 | # define SHUT_RD SD_RECEIVE 61 | # define SHUT_WR SD_SEND 62 | # define __builtin_bswap64 _byteswap_uint64 63 | # define PATH_SEPARATOR '\\' 64 | #endif 65 | 66 | #include "nxt/nxt_address.h" 67 | #include "MinerConfig.h" 68 | 69 | namespace Burst 70 | { 71 | class MinerShabal; 72 | class Miner; 73 | class MinerLogger; 74 | class MinerConfig; 75 | class MinerProtocol; 76 | class PlotReader; 77 | 78 | template 79 | using BytesArray = std::array; 80 | using ScoopData = BytesArray; 81 | using GensigData = BytesArray; 82 | using HashData = BytesArray; 83 | } 84 | 85 | #include "sphlib/sph_types.h" 86 | #include "sphlib/sph_shabal.h" 87 | #include "MinerShabal.h" 88 | #include "MinerUtil.h" 89 | #include "MinerLogger.h" 90 | #include "MinerProtocol.h" 91 | #include "PlotReader.h" 92 | 93 | namespace Burst 94 | { 95 | class Miner 96 | { 97 | public: 98 | Miner(MinerConfig& config); 99 | void run(); 100 | size_t getScoopNum() const; 101 | uint64_t getBaseTarget() const; 102 | const GensigData& getGensig() const; 103 | const MinerConfig* getConfig() const; 104 | void updateGensig(const std::string gensigStr, uint64_t blockHeight, uint64_t baseTarget); 105 | void submitNonce(uint64_t nonce, uint64_t accountId, uint64_t deadline); 106 | void nonceSubmitReport(uint64_t nonce, uint64_t accountId, uint64_t deadline); 107 | private: 108 | void nonceSubmitterThread(); 109 | bool running; 110 | MinerConfig* config; 111 | size_t scoopNum; 112 | uint64_t baseTarget; 113 | uint64_t blockHeight; 114 | std::string gensigStr; 115 | MinerProtocol protocol; 116 | Shabal256 hash; 117 | GensigData gensig; 118 | std::vector> plotReaders; 119 | std::map bestDeadline; 120 | std::map bestNonce; 121 | std::map bestDeadlineConfirmed; 122 | std::mutex accountLock; 123 | std::chrono::system_clock::time_point nextNonceSubmission; 124 | }; 125 | } 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /src/nxt/nxt_address.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // nxt_address.cpp 3 | // cryptoport-miner 4 | // 5 | // Created by Uray Meiviar on 9/19/14. 6 | // Copyright (c) 2014 Miner. All rights reserved. 7 | // 8 | 9 | #include "nxt_address.h" 10 | 11 | #ifdef WIN32 12 | # define strcasecmp _stricmp 13 | # define strncasecmp _strnicmp 14 | #endif 15 | 16 | char NxtAddress::alphabet[33] = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"; 17 | char cwmap[17] = { 3, 2, 1, 0, 7, 6, 5, 4, 13, 14, 15, 16, 12, 8, 9, 10, 11, }; 18 | int NxtAddress::gexp[32] = { 1, 2, 4, 8, 16, 5, 10, 20, 13, 26, 17, 7, 14, 28, 29, 31, 27, 19, 3, 6, 12, 24, 21, 15, 30, 25, 23, 11, 22, 9, 18, 1 }; 19 | int NxtAddress::glog[32] = { 0, 0, 1, 18, 2, 5, 19, 11, 3, 29, 6, 27, 20, 8, 12, 23, 4, 10, 30, 17, 7, 22, 28, 26, 21, 25, 9, 16, 13, 14, 24, 15 }; 20 | 21 | NxtAddress::NxtAddress(uint64_t id) 22 | { 23 | for(int i = 0; i < 13; i++) 24 | { 25 | codeword[i] = (id >> (5 * i)) & 31; 26 | } 27 | 28 | encode(); 29 | } 30 | 31 | NxtAddress::operator uint64_t() 32 | { 33 | uint64_t acc = 0; 34 | 35 | for(int i = 0; i < 13; i++) 36 | { 37 | acc |= uint64_t(codeword[i] & 31) << (5 * i); 38 | } 39 | 40 | return acc; 41 | } 42 | 43 | void NxtAddress::operator=(uint64_t acc) 44 | { 45 | for(int i = 0; i < 13; i++) 46 | { 47 | codeword[i] = (acc >> (5 * i)) & 31; 48 | } 49 | 50 | encode(); 51 | } 52 | 53 | char* NxtAddress::c_str(bool prefix) 54 | { 55 | static char out[32]; int pos = 0; 56 | 57 | if(prefix){ strcpy(out, "BURST-"); pos = 4; } 58 | 59 | for(int i = 0; i < 17; i++) 60 | { 61 | out[pos++] = alphabet[(int)codeword[(int)cwmap[i]]]; 62 | 63 | if((i & 3) == 3 && i < 13) out[pos++] = '-'; 64 | } 65 | 66 | out[pos] = 0; 67 | 68 | return out; 69 | } 70 | 71 | std::string NxtAddress::to_string() 72 | { 73 | return std::string(this->c_str()); 74 | } 75 | 76 | char* NxtAddress::account_id() 77 | { 78 | static char out[21]; 79 | 80 | sprintf(out, "%llu", (unsigned long long)(*this)); 81 | 82 | return out; 83 | } 84 | 85 | bool NxtAddress::set(char *adr) 86 | { 87 | int len = 0; memset(codeword, 1, 17); 88 | 89 | if(!strncasecmp(adr, "BURST-", 4)) adr += 4; 90 | 91 | size_t digits = strspn(adr, "0123456789 \t"); 92 | 93 | if(adr[digits] == 0) // account id 94 | { 95 | if(digits > 5 && digits < 21) 96 | { 97 | uint64_t acc; 98 | 99 | if(digits == 20 && *adr != '1') return false; 100 | 101 | if(sscanf(adr, "%llu", (unsigned long long*)&acc) == 1) 102 | { 103 | *this = acc; return true; 104 | } 105 | } 106 | } 107 | else // address 108 | { 109 | while(*adr) 110 | { 111 | char c = *adr++; 112 | 113 | if(c >= 'a' && c <= 'z') c -= 'a'-'A'; 114 | 115 | char *p = strchr(alphabet, c); if(!p) continue; 116 | 117 | if(len > 16) return false; 118 | 119 | codeword[(int)cwmap[len++]] = (char)(p - alphabet); 120 | } 121 | } 122 | 123 | return (len == 17 ? ok() : false); 124 | } 125 | 126 | int NxtAddress::gmult(int a, int b) 127 | { 128 | if(a == 0 || b == 0) return 0; 129 | 130 | int idx = (glog[a] + glog[b]) % 31; 131 | 132 | return gexp[idx]; 133 | } 134 | 135 | void NxtAddress::encode() 136 | { 137 | char *p = codeword + 13; 138 | 139 | p[3] = p[2] = p[1] = p[0] = 0; 140 | 141 | for(int i = 12; i >= 0; i--) 142 | { 143 | int fb = codeword[i] ^ p[3]; 144 | 145 | p[3] = p[2] ^ gmult(30, fb); 146 | p[2] = p[1] ^ gmult( 6, fb); 147 | p[1] = p[0] ^ gmult( 9, fb); 148 | p[0] = gmult(17, fb); 149 | } 150 | } 151 | 152 | bool NxtAddress::ok() 153 | { 154 | int sum = 0; 155 | int t = 0; 156 | 157 | for(int i = 1; i < 5; i++) 158 | { 159 | t = 0; 160 | for(int j = 0; j < 31; j++) 161 | { 162 | if(j > 12 && j < 27) continue; 163 | 164 | int pos = j; if(j > 26) pos -= 14; 165 | 166 | t ^= gmult(codeword[pos], gexp[(i*j)%31]); 167 | } 168 | 169 | sum |= t; 170 | syndrome[i] = t; 171 | } 172 | 173 | return (sum == 0); 174 | } 175 | -------------------------------------------------------------------------------- /src/rapidjson/internal/pow10.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_POW10_ 2 | #define RAPIDJSON_POW10_ 3 | 4 | namespace rapidjson { 5 | namespace internal { 6 | 7 | //! Computes integer powers of 10 in double (10.0^n). 8 | /*! This function uses lookup table for fast and accurate results. 9 | \param n positive/negative exponent. Must <= 308. 10 | \return 10.0^n 11 | */ 12 | inline double Pow10(int n) { 13 | static const double e[] = { // 1e-308...1e308: 617 * 8 bytes = 4936 bytes 14 | 1e-308,1e-307,1e-306,1e-305,1e-304,1e-303,1e-302,1e-301,1e-300, 15 | 1e-299,1e-298,1e-297,1e-296,1e-295,1e-294,1e-293,1e-292,1e-291,1e-290,1e-289,1e-288,1e-287,1e-286,1e-285,1e-284,1e-283,1e-282,1e-281,1e-280, 16 | 1e-279,1e-278,1e-277,1e-276,1e-275,1e-274,1e-273,1e-272,1e-271,1e-270,1e-269,1e-268,1e-267,1e-266,1e-265,1e-264,1e-263,1e-262,1e-261,1e-260, 17 | 1e-259,1e-258,1e-257,1e-256,1e-255,1e-254,1e-253,1e-252,1e-251,1e-250,1e-249,1e-248,1e-247,1e-246,1e-245,1e-244,1e-243,1e-242,1e-241,1e-240, 18 | 1e-239,1e-238,1e-237,1e-236,1e-235,1e-234,1e-233,1e-232,1e-231,1e-230,1e-229,1e-228,1e-227,1e-226,1e-225,1e-224,1e-223,1e-222,1e-221,1e-220, 19 | 1e-219,1e-218,1e-217,1e-216,1e-215,1e-214,1e-213,1e-212,1e-211,1e-210,1e-209,1e-208,1e-207,1e-206,1e-205,1e-204,1e-203,1e-202,1e-201,1e-200, 20 | 1e-199,1e-198,1e-197,1e-196,1e-195,1e-194,1e-193,1e-192,1e-191,1e-190,1e-189,1e-188,1e-187,1e-186,1e-185,1e-184,1e-183,1e-182,1e-181,1e-180, 21 | 1e-179,1e-178,1e-177,1e-176,1e-175,1e-174,1e-173,1e-172,1e-171,1e-170,1e-169,1e-168,1e-167,1e-166,1e-165,1e-164,1e-163,1e-162,1e-161,1e-160, 22 | 1e-159,1e-158,1e-157,1e-156,1e-155,1e-154,1e-153,1e-152,1e-151,1e-150,1e-149,1e-148,1e-147,1e-146,1e-145,1e-144,1e-143,1e-142,1e-141,1e-140, 23 | 1e-139,1e-138,1e-137,1e-136,1e-135,1e-134,1e-133,1e-132,1e-131,1e-130,1e-129,1e-128,1e-127,1e-126,1e-125,1e-124,1e-123,1e-122,1e-121,1e-120, 24 | 1e-119,1e-118,1e-117,1e-116,1e-115,1e-114,1e-113,1e-112,1e-111,1e-110,1e-109,1e-108,1e-107,1e-106,1e-105,1e-104,1e-103,1e-102,1e-101,1e-100, 25 | 1e-99, 1e-98, 1e-97, 1e-96, 1e-95, 1e-94, 1e-93, 1e-92, 1e-91, 1e-90, 1e-89, 1e-88, 1e-87, 1e-86, 1e-85, 1e-84, 1e-83, 1e-82, 1e-81, 1e-80, 26 | 1e-79, 1e-78, 1e-77, 1e-76, 1e-75, 1e-74, 1e-73, 1e-72, 1e-71, 1e-70, 1e-69, 1e-68, 1e-67, 1e-66, 1e-65, 1e-64, 1e-63, 1e-62, 1e-61, 1e-60, 27 | 1e-59, 1e-58, 1e-57, 1e-56, 1e-55, 1e-54, 1e-53, 1e-52, 1e-51, 1e-50, 1e-49, 1e-48, 1e-47, 1e-46, 1e-45, 1e-44, 1e-43, 1e-42, 1e-41, 1e-40, 28 | 1e-39, 1e-38, 1e-37, 1e-36, 1e-35, 1e-34, 1e-33, 1e-32, 1e-31, 1e-30, 1e-29, 1e-28, 1e-27, 1e-26, 1e-25, 1e-24, 1e-23, 1e-22, 1e-21, 1e-20, 29 | 1e-19, 1e-18, 1e-17, 1e-16, 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, 1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e+0, 30 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 31 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, 32 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, 33 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, 34 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, 35 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, 36 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, 37 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, 38 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, 39 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, 40 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, 41 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, 42 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, 43 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, 44 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, 45 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 46 | }; 47 | RAPIDJSON_ASSERT(n <= 308); 48 | return n < -308 ? 0.0 : e[n + 308]; 49 | } 50 | 51 | } // namespace internal 52 | } // namespace rapidjson 53 | 54 | #endif // RAPIDJSON_POW10_ 55 | -------------------------------------------------------------------------------- /src/MinerUtil.cpp: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #include "Miner.h" 10 | 11 | bool Burst::isNumberStr(const std::string &str) 12 | { 13 | return std::all_of(str.begin(), str.end(), ::isdigit); 14 | } 15 | 16 | std::string Burst::getFileNameFromPath(const std::string& strPath) 17 | { 18 | size_t iLastSeparator = 0; 19 | return strPath.substr((iLastSeparator = strPath.find_last_of("/\\")) != std::string::npos ? iLastSeparator + 1 : 0, strPath.size() - strPath.find_last_of(".")); 20 | } 21 | 22 | std::vector Burst::splitStr(const std::string &s, char delim) 23 | { 24 | std::vector elems; 25 | splitStr(s, delim, elems); 26 | return elems; 27 | } 28 | 29 | std::vector& Burst::splitStr(const std::string &s, char delim, std::vector &elems) 30 | { 31 | std::stringstream ss(s); 32 | std::string item; 33 | while (std::getline(ss, item, delim)) 34 | { 35 | elems.push_back(item); 36 | } 37 | return elems; 38 | } 39 | 40 | bool Burst::isValidPlotFile(const std::string filePath) 41 | { 42 | bool result = false; 43 | std::string fileName = getFileNameFromPath(filePath); 44 | if(getAccountIdFromPlotFile(fileName) != "" && 45 | getStartNonceFromPlotFile(fileName) != "") 46 | { 47 | //struct stat info; 48 | //int statResult = stat( filePath.c_str(), &info ); 49 | 50 | //if( statResult >= 0) 51 | //{ 52 | // if( (info.st_mode & S_IFDIR) == 0) 53 | // { 54 | std::ifstream testRead(filePath); 55 | if(testRead.good()) 56 | { 57 | result = true; 58 | } 59 | testRead.close(); 60 | // } 61 | //} 62 | } 63 | 64 | return result; 65 | } 66 | 67 | std::string Burst::getAccountIdFromPlotFile(const std::string path) 68 | { 69 | size_t filenamePos = path.find_last_of("/\\"); 70 | if(filenamePos == std::string::npos) 71 | { 72 | filenamePos = 0; 73 | } 74 | std::vector fileNamePart = splitStr(path.substr(filenamePos+1,path.length()-(filenamePos+1)),'_'); 75 | if(fileNamePart.size() > 3) 76 | { 77 | std::string accountIdPart = fileNamePart[0]; 78 | if(isNumberStr(accountIdPart)) 79 | { 80 | return accountIdPart; 81 | } 82 | } 83 | return ""; 84 | } 85 | 86 | std::string Burst::getNonceCountFromPlotFile(const std::string path) 87 | { 88 | size_t filenamePos = path.find_last_of("/\\"); 89 | if(filenamePos == std::string::npos) 90 | { 91 | filenamePos = 0; 92 | } 93 | std::vector fileNamePart = splitStr(path.substr(filenamePos+1,path.length()-(filenamePos+1)),'_'); 94 | if(fileNamePart.size() > 3) 95 | { 96 | std::string nonceCountPart = fileNamePart[2]; 97 | if(isNumberStr(nonceCountPart)) 98 | { 99 | return nonceCountPart; 100 | } 101 | } 102 | return ""; 103 | } 104 | 105 | std::string Burst::getStaggerSizeFromPlotFile(const std::string path) 106 | { 107 | size_t filenamePos = path.find_last_of("/\\"); 108 | if(filenamePos == std::string::npos) 109 | { 110 | filenamePos = 0; 111 | } 112 | std::vector fileNamePart = splitStr(path.substr(filenamePos+1,path.length()-(filenamePos+1)),'_'); 113 | if(fileNamePart.size() > 3) 114 | { 115 | std::string staggerPart = fileNamePart[3]; 116 | if(isNumberStr(staggerPart)) 117 | { 118 | return staggerPart; 119 | } 120 | } 121 | return ""; 122 | } 123 | 124 | std::string Burst::getStartNonceFromPlotFile(const std::string path) 125 | { 126 | size_t filenamePos = path.find_last_of("/\\"); 127 | if(filenamePos == std::string::npos) 128 | { 129 | filenamePos = 0; 130 | } 131 | std::vector fileNamePart = splitStr(path.substr(filenamePos+1,path.length()-(filenamePos+1)),'_'); 132 | if(fileNamePart.size() > 3) 133 | { 134 | std::string nonceStartPart = fileNamePart[1]; 135 | if(isNumberStr(nonceStartPart)) 136 | { 137 | return nonceStartPart; 138 | } 139 | } 140 | return ""; 141 | } 142 | 143 | std::string Burst::deadlineFormat(uint64_t seconds) 144 | { 145 | size_t secs = seconds; 146 | size_t min = 0; 147 | size_t hour = 0; 148 | size_t day = 0; 149 | 150 | if(secs > 59) 151 | { 152 | min = secs/60; 153 | secs = secs - min*60; 154 | } 155 | 156 | if(min > 59) 157 | { 158 | hour = min/60; 159 | min = min - hour*60; 160 | } 161 | 162 | if(hour > 23) 163 | { 164 | day = hour/24; 165 | hour = hour - day*24; 166 | } 167 | 168 | std::string hourStr = std::to_string(hour); 169 | if(hour < 10) 170 | { 171 | hourStr = "0"+hourStr; 172 | } 173 | 174 | std::string minStr = std::to_string(min); 175 | if(min < 10) 176 | { 177 | minStr = "0"+minStr; 178 | } 179 | 180 | std::string secStr = std::to_string(secs); 181 | if(secs < 10) 182 | { 183 | secStr = "0"+secStr; 184 | } 185 | 186 | return std::to_string(day)+" days "+hourStr+":"+minStr+":"+secStr; 187 | } -------------------------------------------------------------------------------- /src/rapidjson/prettywriter.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_PRETTYWRITER_H_ 2 | #define RAPIDJSON_PRETTYWRITER_H_ 3 | 4 | #include "writer.h" 5 | 6 | namespace rapidjson { 7 | 8 | //! Writer with indentation and spacing. 9 | /*! 10 | \tparam Stream Type of ouptut stream. 11 | \tparam Encoding Encoding of both source strings and output. 12 | \tparam Allocator Type of allocator for allocating memory of stack. 13 | */ 14 | template, typename Allocator = MemoryPoolAllocator<> > 15 | class PrettyWriter : public Writer { 16 | public: 17 | typedef Writer Base; 18 | typedef typename Base::Ch Ch; 19 | 20 | //! Constructor 21 | /*! \param stream Output stream. 22 | \param allocator User supplied allocator. If it is null, it will create a private one. 23 | \param levelDepth Initial capacity of 24 | */ 25 | PrettyWriter(Stream& stream, Allocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) : 26 | Base(stream, allocator, levelDepth), indentChar_(' '), indentCharCount_(4) {} 27 | 28 | //! Set custom indentation. 29 | /*! \param indentChar Character for indentation. Must be whitespace character (' ', '\t', '\n', '\r'). 30 | \param indentCharCount Number of indent characters for each indentation level. 31 | \note The default indentation is 4 spaces. 32 | */ 33 | PrettyWriter& SetIndent(Ch indentChar, unsigned indentCharCount) { 34 | RAPIDJSON_ASSERT(indentChar == ' ' || indentChar == '\t' || indentChar == '\n' || indentChar == '\r'); 35 | indentChar_ = indentChar; 36 | indentCharCount_ = indentCharCount; 37 | return *this; 38 | } 39 | 40 | //@name Implementation of Handler. 41 | //@{ 42 | 43 | PrettyWriter& Null() { PrettyPrefix(kNullType); Base::WriteNull(); return *this; } 44 | PrettyWriter& Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); Base::WriteBool(b); return *this; } 45 | PrettyWriter& Int(int i) { PrettyPrefix(kNumberType); Base::WriteInt(i); return *this; } 46 | PrettyWriter& Uint(unsigned u) { PrettyPrefix(kNumberType); Base::WriteUint(u); return *this; } 47 | PrettyWriter& Int64(int64_t i64) { PrettyPrefix(kNumberType); Base::WriteInt64(i64); return *this; } 48 | PrettyWriter& Uint64(uint64_t u64) { PrettyPrefix(kNumberType); Base::WriteUint64(u64); return *this; } 49 | PrettyWriter& Double(double d) { PrettyPrefix(kNumberType); Base::WriteDouble(d); return *this; } 50 | 51 | PrettyWriter& String(const Ch* str, SizeType length, bool copy = false) { 52 | (void)copy; 53 | PrettyPrefix(kStringType); 54 | Base::WriteString(str, length); 55 | return *this; 56 | } 57 | 58 | PrettyWriter& StartObject() { 59 | PrettyPrefix(kObjectType); 60 | new (Base::level_stack_.template Push()) typename Base::Level(false); 61 | Base::WriteStartObject(); 62 | return *this; 63 | } 64 | 65 | PrettyWriter& EndObject(SizeType memberCount = 0) { 66 | (void)memberCount; 67 | RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); 68 | RAPIDJSON_ASSERT(!Base::level_stack_.template Top()->inArray); 69 | bool empty = Base::level_stack_.template Pop(1)->valueCount == 0; 70 | 71 | if (!empty) { 72 | Base::stream_.Put('\n'); 73 | WriteIndent(); 74 | } 75 | Base::WriteEndObject(); 76 | return *this; 77 | } 78 | 79 | PrettyWriter& StartArray() { 80 | PrettyPrefix(kArrayType); 81 | new (Base::level_stack_.template Push()) typename Base::Level(true); 82 | Base::WriteStartArray(); 83 | return *this; 84 | } 85 | 86 | PrettyWriter& EndArray(SizeType memberCount = 0) { 87 | (void)memberCount; 88 | RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); 89 | RAPIDJSON_ASSERT(Base::level_stack_.template Top()->inArray); 90 | bool empty = Base::level_stack_.template Pop(1)->valueCount == 0; 91 | 92 | if (!empty) { 93 | Base::stream_.Put('\n'); 94 | WriteIndent(); 95 | } 96 | Base::WriteEndArray(); 97 | return *this; 98 | } 99 | 100 | //@} 101 | 102 | //! Simpler but slower overload. 103 | PrettyWriter& String(const Ch* str) { return String(str, internal::StrLen(str)); } 104 | 105 | protected: 106 | void PrettyPrefix(Type type) { 107 | (void)type; 108 | if (Base::level_stack_.GetSize() != 0) { // this value is not at root 109 | typename Base::Level* level = Base::level_stack_.template Top(); 110 | 111 | if (level->inArray) { 112 | if (level->valueCount > 0) { 113 | Base::stream_.Put(','); // add comma if it is not the first element in array 114 | Base::stream_.Put('\n'); 115 | } 116 | else 117 | Base::stream_.Put('\n'); 118 | WriteIndent(); 119 | } 120 | else { // in object 121 | if (level->valueCount > 0) { 122 | if (level->valueCount % 2 == 0) { 123 | Base::stream_.Put(','); 124 | Base::stream_.Put('\n'); 125 | } 126 | else { 127 | Base::stream_.Put(':'); 128 | Base::stream_.Put(' '); 129 | } 130 | } 131 | else 132 | Base::stream_.Put('\n'); 133 | 134 | if (level->valueCount % 2 == 0) 135 | WriteIndent(); 136 | } 137 | if (!level->inArray && level->valueCount % 2 == 0) 138 | RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name 139 | level->valueCount++; 140 | } 141 | else 142 | RAPIDJSON_ASSERT(type == kObjectType || type == kArrayType); 143 | } 144 | 145 | void WriteIndent() { 146 | size_t count = (Base::level_stack_.GetSize() / sizeof(typename Base::Level)) * indentCharCount_; 147 | PutN(Base::stream_, indentChar_, count); 148 | } 149 | 150 | Ch indentChar_; 151 | unsigned indentCharCount_; 152 | }; 153 | 154 | } // namespace rapidjson 155 | 156 | #endif // RAPIDJSON_RAPIDJSON_H_ 157 | -------------------------------------------------------------------------------- /src/Miner.cpp: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #include "Miner.h" 10 | 11 | Burst::Miner::Miner(MinerConfig& config) 12 | { 13 | this->config = &config; 14 | this->running = false; 15 | } 16 | 17 | void Burst::Miner::run() 18 | { 19 | this->running = true; 20 | std::thread submitter(&Miner::nonceSubmitterThread,this); 21 | if(!this->protocol.run(this)) 22 | { 23 | MinerLogger::write("Mining networking failed"); 24 | } 25 | this->running = false; 26 | submitter.join(); 27 | } 28 | 29 | const Burst::MinerConfig* Burst::Miner::getConfig() const 30 | { 31 | return this->config; 32 | } 33 | 34 | void Burst::Miner::updateGensig(const std::string gensigStr, uint64_t blockHeight, uint64_t baseTarget) 35 | { 36 | this->gensigStr = gensigStr; 37 | this->blockHeight = blockHeight; 38 | this->baseTarget = baseTarget; 39 | for(size_t i=0 ; i<32 ; i++) 40 | { 41 | std::string byteStr = gensigStr.substr(i*2,2); 42 | this->gensig[i] = (uint8_t)std::stoi(byteStr,0,16); 43 | } 44 | 45 | GensigData newGenSig; 46 | this->hash.update(&this->gensig[0],this->gensig.size()); 47 | this->hash.update(blockHeight); 48 | this->hash.close(&newGenSig[0]); 49 | this->scoopNum = ((int)(newGenSig[newGenSig.size()-2] & 0x0F) << 8) | (int)newGenSig[newGenSig.size()-1]; 50 | 51 | MinerLogger::write("block#" + std::to_string(blockHeight) + " s#:" + std::to_string(this->scoopNum)+" bt:"+std::to_string(this->baseTarget)+" "+this->gensigStr); 52 | 53 | this->bestDeadline.clear(); 54 | this->config->rescan(); 55 | 56 | this->plotReaders.clear(); 57 | for(const std::string path : this->config->plotList) 58 | { 59 | std::shared_ptr reader = std::shared_ptr(new PlotReader(this)); 60 | reader->read(path); 61 | this->plotReaders.push_back(reader); 62 | } 63 | 64 | std::random_device rd; 65 | std::default_random_engine randomizer(rd()); 66 | std::uniform_int_distribution dist(0, this->config->submissionMaxDelay); 67 | size_t delay = dist(randomizer); 68 | this->nextNonceSubmission = std::chrono::system_clock::now() + 69 | std::chrono::seconds(delay); 70 | 71 | std::lock_guard mutex(this->accountLock); 72 | this->bestDeadline.clear(); 73 | this->bestNonce.clear(); 74 | this->bestDeadlineConfirmed.clear(); 75 | } 76 | 77 | const Burst::GensigData& Burst::Miner::getGensig() const 78 | { 79 | return this->gensig; 80 | } 81 | 82 | uint64_t Burst::Miner::getBaseTarget() const 83 | { 84 | return this->baseTarget; 85 | } 86 | 87 | size_t Burst::Miner::getScoopNum() const 88 | { 89 | return this->scoopNum; 90 | } 91 | 92 | void Burst::Miner::nonceSubmitterThread() 93 | { 94 | std::deque> submitList; 95 | std::unique_lock mutex(this->accountLock); 96 | mutex.unlock(); 97 | while(this->running) 98 | { 99 | if(std::chrono::system_clock::now() > this->nextNonceSubmission) 100 | { 101 | mutex.lock(); 102 | for (auto& kv : this->bestDeadline) 103 | { 104 | uint64_t accountId = kv.first; 105 | uint64_t deadline = kv.second; 106 | uint64_t nonce = this->bestNonce[accountId]; 107 | bool firstSubmit = this->bestDeadlineConfirmed.find(accountId) == this->bestDeadlineConfirmed.end(); 108 | if (!firstSubmit) 109 | { 110 | firstSubmit = deadline < this->bestDeadlineConfirmed[accountId]; 111 | } 112 | if( firstSubmit ) 113 | { 114 | bool exist = false; 115 | for (size_t i = 0; i < submitList.size(); i++) 116 | { 117 | if (submitList.at(i).first == nonce && 118 | submitList.at(i).second == accountId) 119 | { 120 | exist = true; 121 | break; 122 | } 123 | } 124 | if (!exist) 125 | { 126 | submitList.push_back(std::make_pair(nonce, accountId)); 127 | } 128 | } 129 | } 130 | mutex.unlock(); 131 | 132 | std::random_device rd; 133 | std::default_random_engine randomizer(rd()); 134 | std::uniform_int_distribution dist(0, this->config->submissionMaxDelay); 135 | this->nextNonceSubmission = std::chrono::system_clock::now() + 136 | std::chrono::seconds(dist(randomizer)); 137 | 138 | if(submitList.size() > 0) 139 | { 140 | mutex.lock(); 141 | 142 | auto submitData = submitList.front(); 143 | submitList.pop_front(); 144 | 145 | mutex.unlock(); 146 | 147 | uint64_t confirmedDeadline = this->protocol.submitNonce(submitData.first, submitData.second); 148 | 149 | if(confirmedDeadline != (uint64_t)(-1)) 150 | { 151 | this->nonceSubmitReport(submitData.first, submitData.second, confirmedDeadline); 152 | } 153 | } 154 | } 155 | std::this_thread::sleep_for(std::chrono::seconds(1)); 156 | } 157 | } 158 | 159 | void Burst::Miner::submitNonce(uint64_t nonce, uint64_t accountId, uint64_t deadline) 160 | { 161 | std::lock_guard mutex(this->accountLock); 162 | NxtAddress addr(accountId); 163 | if(this->bestDeadline.find(accountId) != this->bestDeadline.end()) 164 | { 165 | if(deadline < this->bestDeadline[accountId]) 166 | { 167 | this->bestDeadline[accountId] = deadline; 168 | this->bestNonce[accountId] = nonce; 169 | 170 | MinerLogger::write(addr.to_string()+" dl:"+Burst::deadlineFormat(deadline)+" n:"+std::to_string(nonce)); 171 | } 172 | } 173 | else 174 | { 175 | this->bestDeadline.insert(std::make_pair(accountId, deadline)); 176 | this->bestNonce.insert(std::make_pair(accountId, nonce)); 177 | MinerLogger::write(addr.to_string() + " dl:" + Burst::deadlineFormat(deadline) + " n:" + std::to_string(nonce)); 178 | } 179 | } 180 | 181 | void Burst::Miner::nonceSubmitReport(uint64_t nonce, uint64_t accountId, uint64_t deadline) 182 | { 183 | std::lock_guard mutex(this->accountLock); 184 | NxtAddress addr(accountId); 185 | if(this->bestDeadlineConfirmed.find(accountId) != this->bestDeadlineConfirmed.end()) 186 | { 187 | if(deadline < this->bestDeadlineConfirmed[accountId]) 188 | { 189 | this->bestDeadlineConfirmed[accountId] = deadline; 190 | MinerLogger::write("confirmed dl. for " + addr.to_string() + " : " + Burst::deadlineFormat(deadline)); 191 | } 192 | } 193 | else 194 | { 195 | this->bestDeadlineConfirmed.insert(std::make_pair(accountId, deadline)); 196 | MinerLogger::write("confirmed dl. for " + addr.to_string() + " : " + Burst::deadlineFormat(deadline)); 197 | } 198 | } -------------------------------------------------------------------------------- /src/MinerConfig.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // MinerConfig.cpp 3 | // cryptoport-miner 4 | // 5 | // Created by Uray Meiviar on 9/15/14. 6 | // Copyright (c) 2014 Miner. All rights reserved. 7 | // 8 | 9 | #include "Miner.h" 10 | 11 | void Burst::MinerConfig::rescan() 12 | { 13 | this->readConfigFile(this->configPath); 14 | } 15 | 16 | bool Burst::MinerConfig::readConfigFile(const std::string configPath) 17 | { 18 | this->configPath = configPath; 19 | std::ifstream inputFileStream; 20 | 21 | std::ios_base::iostate exceptionMask = inputFileStream.exceptions() | std::ios::failbit; 22 | inputFileStream.exceptions(exceptionMask); 23 | 24 | try { 25 | inputFileStream.open(configPath); 26 | } 27 | catch (...) 28 | { 29 | MinerLogger::write("unable to open file "+configPath); 30 | return false; 31 | } 32 | 33 | std::stringstream configContent; 34 | configContent << inputFileStream.rdbuf(); 35 | inputFileStream.close(); 36 | std::string configContentStr = configContent.str(); 37 | 38 | rapidjson::Document configDoc; 39 | configDoc.Parse<0>(configContentStr.c_str()); 40 | 41 | if(configDoc.GetParseError() != nullptr) 42 | { 43 | std::string parseError = configDoc.GetParseError(); 44 | size_t parseErrorLoc = configDoc.GetErrorOffset(); 45 | MinerLogger::write("Parsing Error : "+parseError); 46 | size_t sampleLen = 16; 47 | if(configContentStr.length() - parseErrorLoc < 16) 48 | { 49 | sampleLen = configContentStr.length() - parseErrorLoc; 50 | } 51 | MinerLogger::write("--> "+configContentStr.substr(parseErrorLoc,sampleLen)+"..."); 52 | return false; 53 | } 54 | 55 | if(configDoc.HasMember("poolUrl")) 56 | { 57 | std::string poolUrl = configDoc["poolUrl"].GetString(); 58 | size_t startPos = poolUrl.find("//"); 59 | if(startPos == std::string::npos) 60 | { 61 | startPos = 0; 62 | } 63 | size_t hostEnd = poolUrl.find(":",startPos); 64 | if(hostEnd == std::string::npos) 65 | { 66 | this->poolPort = 80; 67 | this->poolHost = poolUrl.substr(startPos,poolUrl.length()-startPos); 68 | } 69 | else 70 | { 71 | this->poolHost = poolUrl.substr(startPos,hostEnd-startPos); 72 | std::string poolPortStr = poolUrl.substr(hostEnd+1,poolUrl.length() - (hostEnd+1) ); 73 | try { 74 | this->poolPort = std::stoul(poolPortStr); 75 | } catch (...) { 76 | this->poolPort = 80; 77 | } 78 | } 79 | } 80 | else 81 | { 82 | MinerLogger::write("No poolUrl is defined in config file "+configPath); 83 | return false; 84 | } 85 | 86 | if(configDoc.HasMember("plots")) 87 | { 88 | if(configDoc["plots"].IsArray()) 89 | { 90 | for (auto itr = configDoc["plots"].Begin(); itr != configDoc["plots"].End(); ++itr) 91 | { 92 | this->addPlotLocation(itr->GetString()); 93 | } 94 | } 95 | else if(configDoc["plots"].IsString()) 96 | { 97 | this->addPlotLocation(configDoc["plots"].GetString()); 98 | } 99 | else 100 | { 101 | MinerLogger::write("Invalid plot file or directory in config file "+configPath); 102 | return false; 103 | } 104 | } 105 | else 106 | { 107 | MinerLogger::write("No plot file or directory defined in config file "+configPath); 108 | return false; 109 | } 110 | 111 | if(this->plotList.empty()) 112 | { 113 | MinerLogger::write("No valid plot file or directory in config file "+configPath); 114 | return false; 115 | } 116 | 117 | if(configDoc.HasMember("submissionMaxDelay")) 118 | { 119 | if( configDoc["submissionMaxDelay"].IsNumber() ) 120 | { 121 | this->submissionMaxDelay = configDoc["submissionMaxDelay"].GetInt(); 122 | } 123 | else 124 | { 125 | std::string maxDelayStr = configDoc["submissionMaxDelay"].GetString(); 126 | try { 127 | this->submissionMaxDelay = std::stoul(maxDelayStr); 128 | } catch (...) { 129 | this->submissionMaxDelay = 60; 130 | } 131 | } 132 | } 133 | 134 | if(configDoc.HasMember("submissionMaxRetry")) 135 | { 136 | if( configDoc["submissionMaxRetry"].IsNumber() ) 137 | { 138 | this->submissionMaxRetry = configDoc["submissionMaxRetry"].GetInt(); 139 | } 140 | else 141 | { 142 | std::string submissionMaxRetryStr = configDoc["submissionMaxRetry"].GetString(); 143 | try { 144 | this->submissionMaxRetry = std::stoul(submissionMaxRetryStr); 145 | } catch (...) { 146 | this->submissionMaxRetry = 3; 147 | } 148 | } 149 | } 150 | 151 | if(configDoc.HasMember("maxBufferSizeMB")) 152 | { 153 | if( configDoc["maxBufferSizeMB"].IsNumber() ) 154 | { 155 | this->maxBufferSizeMB = configDoc["maxBufferSizeMB"].GetInt(); 156 | } 157 | else 158 | { 159 | std::string maxBufferSizeMBStr = configDoc["maxBufferSizeMB"].GetString(); 160 | try { 161 | this->maxBufferSizeMB = std::stoul(maxBufferSizeMBStr); 162 | } catch (...) { 163 | this->maxBufferSizeMB = 64; 164 | } 165 | } 166 | 167 | if (this->maxBufferSizeMB < 1) { 168 | this->maxBufferSizeMB = 1; 169 | } 170 | } 171 | 172 | return true; 173 | } 174 | 175 | bool Burst::MinerConfig::addPlotLocation(const std::string fileOrPath) 176 | { 177 | struct stat info; 178 | int statResult = stat( fileOrPath.c_str(), &info ); 179 | 180 | if( statResult != 0 ) 181 | { 182 | MinerLogger::write(fileOrPath+" does not exist or can not be read"); 183 | return false; 184 | } 185 | else if( info.st_mode & S_IFDIR ) 186 | { 187 | std::string dirPath = fileOrPath; 188 | if (dirPath[dirPath.length() - 1] != PATH_SEPARATOR) 189 | { 190 | dirPath += PATH_SEPARATOR; 191 | } 192 | 193 | DIR *dir; 194 | struct dirent *ent; 195 | if ((dir = opendir(dirPath.c_str())) != NULL) 196 | { 197 | while ((ent = readdir (dir)) != NULL) 198 | { 199 | this->addPlotFile(dirPath+std::string(ent->d_name)); 200 | } 201 | closedir (dir); 202 | } 203 | else 204 | { 205 | MinerLogger::write("failed reading file or directory "+fileOrPath); 206 | closedir (dir); 207 | return false; 208 | } 209 | } 210 | else 211 | { 212 | this->addPlotFile(fileOrPath); 213 | } 214 | return true; 215 | } 216 | 217 | bool Burst::MinerConfig::addPlotFile(std::string file) 218 | { 219 | if(Burst::isValidPlotFile(file)) 220 | { 221 | for(size_t i=0 ; iplotList.size() ; i++) 222 | { 223 | if(this->plotList[i] == file) 224 | { 225 | return true; 226 | } 227 | } 228 | this->plotList.push_back(file); 229 | MinerLogger::write("Plot "+std::to_string(this->plotList.size())+": "+file); 230 | return true; 231 | } 232 | return false; 233 | } 234 | -------------------------------------------------------------------------------- /src/rapidjson/writer.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_WRITER_H_ 2 | #define RAPIDJSON_WRITER_H_ 3 | 4 | #include "rapidjson.h" 5 | #include "internal/stack.h" 6 | #include "internal/strfunc.h" 7 | #include // snprintf() or _sprintf_s() 8 | #include // placement new 9 | 10 | #ifdef _MSC_VER 11 | #pragma warning(push) 12 | #pragma warning(disable : 4127) // conditional expression is constant 13 | #endif 14 | 15 | namespace rapidjson { 16 | 17 | //! JSON writer 18 | /*! Writer implements the concept Handler. 19 | It generates JSON text by events to an output stream. 20 | 21 | User may programmatically calls the functions of a writer to generate JSON text. 22 | 23 | On the other side, a writer can also be passed to objects that generates events, 24 | 25 | for example Reader::Parse() and Document::Accept(). 26 | 27 | \tparam Stream Type of ouptut stream. 28 | \tparam Encoding Encoding of both source strings and output. 29 | \implements Handler 30 | */ 31 | template, typename Allocator = MemoryPoolAllocator<> > 32 | class Writer { 33 | public: 34 | typedef typename Encoding::Ch Ch; 35 | 36 | Writer(Stream& stream, Allocator* allocator = 0, size_t levelDepth = kDefaultLevelDepth) : 37 | stream_(stream), level_stack_(allocator, levelDepth * sizeof(Level)) {} 38 | 39 | //@name Implementation of Handler 40 | //@{ 41 | Writer& Null() { Prefix(kNullType); WriteNull(); return *this; } 42 | Writer& Bool(bool b) { Prefix(b ? kTrueType : kFalseType); WriteBool(b); return *this; } 43 | Writer& Int(int i) { Prefix(kNumberType); WriteInt(i); return *this; } 44 | Writer& Uint(unsigned u) { Prefix(kNumberType); WriteUint(u); return *this; } 45 | Writer& Int64(int64_t i64) { Prefix(kNumberType); WriteInt64(i64); return *this; } 46 | Writer& Uint64(uint64_t u64) { Prefix(kNumberType); WriteUint64(u64); return *this; } 47 | Writer& Double(double d) { Prefix(kNumberType); WriteDouble(d); return *this; } 48 | 49 | Writer& String(const Ch* str, SizeType length, bool copy = false) { 50 | (void)copy; 51 | Prefix(kStringType); 52 | WriteString(str, length); 53 | return *this; 54 | } 55 | 56 | Writer& StartObject() { 57 | Prefix(kObjectType); 58 | new (level_stack_.template Push()) Level(false); 59 | WriteStartObject(); 60 | return *this; 61 | } 62 | 63 | Writer& EndObject(SizeType memberCount = 0) { 64 | (void)memberCount; 65 | RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); 66 | RAPIDJSON_ASSERT(!level_stack_.template Top()->inArray); 67 | level_stack_.template Pop(1); 68 | WriteEndObject(); 69 | return *this; 70 | } 71 | 72 | Writer& StartArray() { 73 | Prefix(kArrayType); 74 | new (level_stack_.template Push()) Level(true); 75 | WriteStartArray(); 76 | return *this; 77 | } 78 | 79 | Writer& EndArray(SizeType elementCount = 0) { 80 | (void)elementCount; 81 | RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); 82 | RAPIDJSON_ASSERT(level_stack_.template Top()->inArray); 83 | level_stack_.template Pop(1); 84 | WriteEndArray(); 85 | return *this; 86 | } 87 | //@} 88 | 89 | //! Simpler but slower overload. 90 | Writer& String(const Ch* str) { return String(str, internal::StrLen(str)); } 91 | 92 | protected: 93 | //! Information for each nested level 94 | struct Level { 95 | Level(bool inArray_) : inArray(inArray_), valueCount(0) {} 96 | bool inArray; //!< true if in array, otherwise in object 97 | size_t valueCount; //!< number of values in this level 98 | }; 99 | 100 | static const size_t kDefaultLevelDepth = 32; 101 | 102 | void WriteNull() { 103 | stream_.Put('n'); stream_.Put('u'); stream_.Put('l'); stream_.Put('l'); 104 | } 105 | 106 | void WriteBool(bool b) { 107 | if (b) { 108 | stream_.Put('t'); stream_.Put('r'); stream_.Put('u'); stream_.Put('e'); 109 | } 110 | else { 111 | stream_.Put('f'); stream_.Put('a'); stream_.Put('l'); stream_.Put('s'); stream_.Put('e'); 112 | } 113 | } 114 | 115 | void WriteInt(int i) { 116 | if (i < 0) { 117 | stream_.Put('-'); 118 | i = -i; 119 | } 120 | WriteUint((unsigned)i); 121 | } 122 | 123 | void WriteUint(unsigned u) { 124 | char buffer[10]; 125 | char *p = buffer; 126 | do { 127 | *p++ = (u % 10) + '0'; 128 | u /= 10; 129 | } while (u > 0); 130 | 131 | do { 132 | --p; 133 | stream_.Put(*p); 134 | } while (p != buffer); 135 | } 136 | 137 | void WriteInt64(int64_t i64) { 138 | if (i64 < 0) { 139 | stream_.Put('-'); 140 | i64 = -i64; 141 | } 142 | WriteUint64((uint64_t)i64); 143 | } 144 | 145 | void WriteUint64(uint64_t u64) { 146 | char buffer[20]; 147 | char *p = buffer; 148 | do { 149 | *p++ = char(u64 % 10) + '0'; 150 | u64 /= 10; 151 | } while (u64 > 0); 152 | 153 | do { 154 | --p; 155 | stream_.Put(*p); 156 | } while (p != buffer); 157 | } 158 | 159 | //! \todo Optimization with custom double-to-string converter. 160 | void WriteDouble(double d) { 161 | char buffer[100]; 162 | #if _MSC_VER 163 | int ret = sprintf_s(buffer, sizeof(buffer), "%g", d); 164 | #else 165 | int ret = snprintf(buffer, sizeof(buffer), "%g", d); 166 | #endif 167 | RAPIDJSON_ASSERT(ret >= 1); 168 | for (int i = 0; i < ret; i++) 169 | stream_.Put(buffer[i]); 170 | } 171 | 172 | void WriteString(const Ch* str, SizeType length) { 173 | static const char hexDigits[] = "0123456789ABCDEF"; 174 | static const char escape[256] = { 175 | #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 176 | //0 1 2 3 4 5 6 7 8 9 A B C D E F 177 | 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00 178 | 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10 179 | 0, 0, '"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20 180 | Z16, Z16, // 30~4F 181 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, // 50 182 | Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 // 60~FF 183 | #undef Z16 184 | }; 185 | 186 | stream_.Put('\"'); 187 | for (const Ch* p = str; p != str + length; ++p) { 188 | if ((sizeof(Ch) == 1 || *p < 256) && escape[(unsigned char)*p]) { 189 | stream_.Put('\\'); 190 | stream_.Put(escape[(unsigned char)*p]); 191 | if (escape[(unsigned char)*p] == 'u') { 192 | stream_.Put('0'); 193 | stream_.Put('0'); 194 | stream_.Put(hexDigits[(*p) >> 4]); 195 | stream_.Put(hexDigits[(*p) & 0xF]); 196 | } 197 | } 198 | else 199 | stream_.Put(*p); 200 | } 201 | stream_.Put('\"'); 202 | } 203 | 204 | void WriteStartObject() { stream_.Put('{'); } 205 | void WriteEndObject() { stream_.Put('}'); } 206 | void WriteStartArray() { stream_.Put('['); } 207 | void WriteEndArray() { stream_.Put(']'); } 208 | 209 | void Prefix(Type type) { 210 | (void)type; 211 | if (level_stack_.GetSize() != 0) { // this value is not at root 212 | Level* level = level_stack_.template Top(); 213 | if (level->valueCount > 0) { 214 | if (level->inArray) 215 | stream_.Put(','); // add comma if it is not the first element in array 216 | else // in object 217 | stream_.Put((level->valueCount % 2 == 0) ? ',' : ':'); 218 | } 219 | if (!level->inArray && level->valueCount % 2 == 0) 220 | RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name 221 | level->valueCount++; 222 | } 223 | else 224 | RAPIDJSON_ASSERT(type == kObjectType || type == kArrayType); 225 | } 226 | 227 | Stream& stream_; 228 | internal::Stack level_stack_; 229 | 230 | private: 231 | // Prohibit assignment for VC C4512 warning 232 | Writer& operator=(const Writer& w); 233 | }; 234 | 235 | } // namespace rapidjson 236 | 237 | #ifdef _MSC_VER 238 | #pragma warning(pop) 239 | #endif 240 | 241 | #endif // RAPIDJSON_RAPIDJSON_H_ 242 | -------------------------------------------------------------------------------- /src/MinerProtocol.cpp: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #include "Miner.h" 10 | 11 | void Burst::MinerSocket::setRemote(const std::string ip, size_t port,size_t defaultTimeout) 12 | { 13 | inet_pton(AF_INET, ip.c_str(), &this->remoteAddr.sin_addr); 14 | this->remoteAddr.sin_family = AF_INET; 15 | this->remoteAddr.sin_port = htons( (u_short)port ); 16 | 17 | this->socketTimeout.tv_sec = (long)defaultTimeout; 18 | this->socketTimeout.tv_usec = (long)defaultTimeout*1000; 19 | } 20 | 21 | std::string Burst::MinerSocket::httpRequest(const std::string method, 22 | const std::string url, 23 | const std::string body, 24 | const std::string header) 25 | { 26 | std::string response = ""; 27 | memset((void*)this->readBuffer,0,readBufferSize); 28 | SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 29 | #ifdef WIN32 30 | setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&this->socketTimeout.tv_usec, sizeof(this->socketTimeout.tv_usec)); 31 | #else 32 | setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&this->socketTimeout, sizeof(struct timeval)); 33 | #endif 34 | if(connect(sock, (struct sockaddr*)&this->remoteAddr, sizeof(struct sockaddr_in)) == -1) 35 | { 36 | MinerLogger::write("unable to connect to remote host"); 37 | } 38 | else 39 | { 40 | std::string request = method+" "; 41 | request += url+" HTTP/1.0\r\n"; 42 | request += header+"\r\n\r\n"; 43 | request += body; 44 | 45 | if(send(sock, request.c_str(), (int)request.length(),MSG_NOSIGNAL) > 0) 46 | { 47 | //shutdown(sock,SHUT_WR); 48 | 49 | 50 | int totalBytesRead = 0; 51 | int bytesRead = 0; 52 | do 53 | { 54 | bytesRead = (int)recv(sock, &this->readBuffer[totalBytesRead], 55 | readBufferSize-totalBytesRead-1,0); 56 | if(bytesRead > 0) 57 | { 58 | totalBytesRead+=bytesRead; 59 | this->readBuffer[totalBytesRead] = 0; 60 | response = std::string((char*)this->readBuffer); 61 | totalBytesRead = 0; 62 | this->readBuffer[totalBytesRead] = 0; 63 | } 64 | }while( (bytesRead > 0) && (totalBytesRead < (int)readBufferSize-1) ); 65 | 66 | shutdown(sock,SHUT_RDWR); 67 | closesocket(sock); 68 | sock = 0; 69 | 70 | if(response.length() > 0) 71 | { 72 | size_t httpBodyPos = response.find("\r\n\r\n"); 73 | response = response.substr(httpBodyPos+4,response.length()-(httpBodyPos+4)); 74 | } 75 | } 76 | } 77 | 78 | return response; 79 | } 80 | 81 | std::string Burst::MinerSocket::httpPost(const std::string url, const std::string body) 82 | { 83 | std::string //header = "Content-Type: application/x-www-form-urlencoded\r\n"; 84 | //header = "Content-Length: "+std::to_string(body.length())+"\r\n"; 85 | header = "Connection: close"; 86 | return this->httpRequest("POST",url,body,header); 87 | } 88 | 89 | void Burst::MinerSocket::httpRequestAsync(const std::string method, 90 | const std::string url, 91 | const std::string body, 92 | const std::string header, 93 | std::function< void ( std::string ) > responseCallback ) 94 | { 95 | std::string response = httpRequest(method, url, body, header); 96 | responseCallback(response); 97 | } 98 | 99 | void Burst::MinerSocket::httpPostAsync(const std::string url, const std::string body, 100 | std::function< void ( std::string ) > responseCallback) 101 | { 102 | std::string //header = "Content-Type: application/x-www-form-urlencoded\r\n"; 103 | //header = "Content-Length: "+std::to_string(body.length())+"\r\n"; 104 | header = "Connection: close"; 105 | std::thread requestThread(&MinerSocket::httpRequestAsync,this,"POST",url,body,header,responseCallback); 106 | requestThread.detach(); 107 | } 108 | 109 | void Burst::MinerSocket::httpGetAsync(const std::string url, 110 | std::function< void ( std::string ) > responseCallback) 111 | { 112 | std::string header = "Connection: close"; 113 | std::thread requestThread(&MinerSocket::httpRequestAsync,this,"GET",url,"",header,responseCallback); 114 | requestThread.detach(); 115 | } 116 | 117 | std::string Burst::MinerSocket::httpGet(const std::string url) 118 | { 119 | std::string header = "Connection: close"; 120 | return httpRequest("GET", url, "", header); 121 | } 122 | 123 | Burst::MinerProtocol::MinerProtocol() 124 | { 125 | this->running = false; 126 | this->currentBaseTarget = 0; 127 | this->currentBlockHeight = 0; 128 | } 129 | 130 | Burst::MinerProtocol::~MinerProtocol() 131 | { 132 | this->stop(); 133 | } 134 | 135 | void Burst::MinerProtocol::stop() 136 | { 137 | this->running = false; 138 | } 139 | 140 | bool Burst::MinerProtocol::run(Miner* miner) 141 | { 142 | const MinerConfig* config = miner->getConfig(); 143 | this->miner = miner; 144 | std::string remoteIP = MinerProtocol::resolveHostname(config->poolHost); 145 | if(remoteIP != "") 146 | { 147 | this->running = true; 148 | this->miningInfoSocket.setRemote(remoteIP, config->poolPort); 149 | this->nonceSubmitterSocket.setRemote(remoteIP, config->poolPort); 150 | while(this->running) 151 | { 152 | this->getMiningInfo(); 153 | std::this_thread::sleep_for(std::chrono::seconds(3)); 154 | } 155 | } 156 | return false; 157 | } 158 | 159 | uint64_t Burst::MinerProtocol::submitNonce(uint64_t nonce, uint64_t accountId) 160 | { 161 | NxtAddress addr(accountId); 162 | MinerLogger::write("submitting nonce "+std::to_string(nonce)+" for "+addr.to_string()); 163 | std::string request = "requestType=submitNonce&nonce="+std::to_string(nonce)+"&accountId="+std::to_string(accountId)+"&secretPhrase=cryptoport"; 164 | std::string url = "/burst?"+request; 165 | 166 | size_t tryCount = 0; 167 | std::string response = ""; 168 | do{ 169 | response = this->nonceSubmitterSocket.httpPost(url,""); 170 | tryCount++; 171 | } 172 | while(response.empty() && tryCount < this->miner->getConfig()->submissionMaxRetry); 173 | 174 | MinerLogger::write(response); 175 | rapidjson::Document body; 176 | body.Parse<0>(response.c_str()); 177 | 178 | if(body.GetParseError() == nullptr) 179 | { 180 | if(body.HasMember("deadline")) 181 | { 182 | return body["deadline"].GetUint64(); 183 | } 184 | } 185 | return (uint64_t)(-1); 186 | } 187 | 188 | void Burst::MinerProtocol::getMiningInfo() 189 | { 190 | std::string response = this->miningInfoSocket.httpPost("/burst?requestType=getMiningInfo",""); 191 | 192 | if(response.length() > 0) 193 | { 194 | rapidjson::Document body; 195 | body.Parse<0>(response.c_str()); 196 | 197 | if(body.GetParseError() == nullptr) 198 | { 199 | if(body.HasMember("baseTarget")) 200 | { 201 | std::string baseTargetStr = body["baseTarget"].GetString(); 202 | this->currentBaseTarget = std::stoull(baseTargetStr); 203 | } 204 | 205 | if(body.HasMember("generationSignature")) 206 | { 207 | this->gensig = body["generationSignature"].GetString(); 208 | } 209 | 210 | if(body.HasMember("height")) 211 | { 212 | std::string newBlockHeightStr = body["height"].GetString(); 213 | uint64_t newBlockHeight = std::stoull(newBlockHeightStr); 214 | if(newBlockHeight > this->currentBlockHeight) 215 | { 216 | this->miner->updateGensig(this->gensig, newBlockHeight, this->currentBaseTarget); 217 | } 218 | this->currentBlockHeight = newBlockHeight; 219 | } 220 | } 221 | } 222 | } 223 | 224 | std::string Burst::MinerProtocol::resolveHostname(const std::string host) 225 | { 226 | struct hostent *he; 227 | struct in_addr **addr_list; 228 | int i; 229 | 230 | MinerLogger::write("resolving hostname "+host); 231 | 232 | if ( (he = gethostbyname( host.c_str() ) ) == NULL) 233 | { 234 | MinerLogger::write("error while resolving hostname"); 235 | return ""; 236 | } 237 | 238 | addr_list = (struct in_addr **) he->h_addr_list; 239 | 240 | char inetAddrStr[64]; 241 | for(i = 0; addr_list[i] != NULL; i++) 242 | { 243 | std::string ip = std::string(inet_ntop(AF_INET, addr_list[i], inetAddrStr,64)); 244 | MinerLogger::write("Remote IP "+ip); 245 | return ip; 246 | } 247 | 248 | MinerLogger::write("can not resolve hostname "+host); 249 | return ""; 250 | } -------------------------------------------------------------------------------- /burst-miner.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {0FBF38FD-4EE5-4E43-ADFB-C808DE6154F1} 23 | Win32Proj 24 | burstminer 25 | 26 | 27 | 28 | Application 29 | true 30 | v120 31 | Unicode 32 | 33 | 34 | Application 35 | true 36 | v120 37 | NotSet 38 | 39 | 40 | Application 41 | false 42 | v120 43 | true 44 | Unicode 45 | 46 | 47 | Application 48 | false 49 | v120 50 | true 51 | Unicode 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | true 71 | 72 | 73 | true 74 | $(SolutionDir)bin\$(Configuration)\ 75 | $(SolutionDir)obj\$(Configuration)\$(Configuration)\ 76 | 77 | 78 | false 79 | 80 | 81 | false 82 | $(SolutionDir)bin\$(Configuration)\ 83 | $(SolutionDir)obj\$(Configuration)\$(Configuration)\ 84 | 85 | 86 | 87 | 88 | 89 | Level3 90 | Disabled 91 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 92 | 93 | 94 | Console 95 | true 96 | 97 | 98 | 99 | 100 | 101 | 102 | Level3 103 | Disabled 104 | WIN32;_CRT_SECURE_NO_WARNINGS;VC_EXTRALEAN;WIN32_LEAN_AND_MEAN;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 105 | $(SolutionDir)src;%(AdditionalIncludeDirectories) 106 | true 107 | false 108 | false 109 | false 110 | true 111 | 112 | 113 | Console 114 | true 115 | $(IntDir)$(TargetName).pdb 116 | true 117 | ws2_32.lib;%(AdditionalDependencies) 118 | 119 | 120 | 121 | 122 | Level3 123 | 124 | 125 | MaxSpeed 126 | true 127 | true 128 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 129 | 130 | 131 | Console 132 | true 133 | true 134 | true 135 | 136 | 137 | 138 | 139 | Level3 140 | 141 | 142 | Full 143 | true 144 | true 145 | WIN32;_CRT_SECURE_NO_WARNINGS;VC_EXTRALEAN;WIN32_LEAN_AND_MEAN;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 146 | $(SolutionDir)src;%(AdditionalIncludeDirectories) 147 | true 148 | false 149 | false 150 | false 151 | true 152 | AnySuitable 153 | Speed 154 | true 155 | true 156 | MultiThreaded 157 | 16Bytes 158 | false 159 | true 160 | StreamingSIMDExtensions2 161 | Fast 162 | 163 | 164 | Console 165 | false 166 | true 167 | true 168 | $(IntDir)$(TargetName).pdb 169 | true 170 | ws2_32.lib;%(AdditionalDependencies) 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | -------------------------------------------------------------------------------- /src/PlotReader.cpp: -------------------------------------------------------------------------------- 1 | // cryptoport.io Burst Pool Miner 2 | // 3 | // Created by Uray Meiviar < uraymeiviar@gmail.com > 2014 4 | // donation : 5 | // 6 | // [Burst ] BURST-8E8K-WQ2F-ZDZ5-FQWHX 7 | // [Bitcoin] 1UrayjqRjSJjuouhJnkczy5AuMqJGRK4b 8 | 9 | #include "Miner.h" 10 | 11 | Burst::PlotReader::PlotReader(Miner* miner) 12 | { 13 | this->done = true; 14 | this->miner = miner; 15 | } 16 | 17 | Burst::PlotReader::~PlotReader() 18 | { 19 | this->stop(); 20 | } 21 | 22 | void Burst::PlotReader::stop() 23 | { 24 | this->done = true; 25 | if(readerThreadObj.joinable()) 26 | { 27 | readerThreadObj.join(); 28 | } 29 | } 30 | 31 | bool Burst::PlotReader::isDone() const 32 | { 33 | return this->done; 34 | } 35 | 36 | void Burst::PlotReader::read(const std::string path) 37 | { 38 | this->stop(); 39 | this->accountId = std::stoull(getAccountIdFromPlotFile(path)); 40 | this->nonceStart = std::stoull(Burst::getStartNonceFromPlotFile(path)); 41 | this->nonceCount = std::stoull(Burst::getNonceCountFromPlotFile(path)); 42 | this->staggerSize = std::stoull(Burst::getStaggerSizeFromPlotFile(path)); 43 | this->scoopNum = this->miner->getScoopNum(); 44 | this->gensig = miner->getGensig(); 45 | this->done = false; 46 | this->inputPath = path; 47 | this->readerThreadObj = std::thread(&PlotReader::readerThread,this); 48 | } 49 | 50 | void Burst::PlotReader::readerThread() 51 | { 52 | std::ifstream inputStream(this->inputPath, std::ifstream::binary); 53 | if(inputStream.good()) 54 | { 55 | /* 56 | inputStream.clear(); 57 | this->runVerify = true; 58 | std::unique_lock verifyLock(this->readLock); 59 | verifyLock.unlock(); 60 | std::thread verifierThreadObj(&PlotReader::verifierThread,this); 61 | 62 | size_t readlimit = this->miner->getConfig()->maxBufferSizeMB / 32; 63 | size_t scoopBufferCount = this->staggerSize / readlimit; 64 | size_t scoopBufferSize = readlimit; 65 | size_t scoopDoneRead = 0; 66 | while(scoopDoneRead <= scoopBufferCount) 67 | { 68 | size_t staggerOffset = this->scoopNum * MinerConfig::scoopSize * scoopDoneRead * scoopBufferSize; 69 | if(scoopBufferSize > (this->staggerSize - (scoopDoneRead * scoopBufferSize))) 70 | { 71 | scoopBufferSize = this->staggerSize - (scoopDoneRead * scoopBufferSize); 72 | } 73 | 74 | this->buffer[0].resize(scoopBufferSize); 75 | this->buffer[1].resize(scoopBufferSize); 76 | this->readBuffer = &this->buffer[0]; 77 | this->writeBuffer = &this->buffer[1]; 78 | 79 | size_t bufferSize = scoopBufferSize * MinerConfig::scoopSize; 80 | size_t startByte = this->scoopNum * MinerConfig::scoopSize * scoopBufferSize + staggerOffset; 81 | size_t chunkNum = 0; 82 | size_t totalChunk = this->nonceCount / scoopBufferSize; 83 | this->nonceOffset = 0; 84 | 85 | while(!this->done && inputStream.good() && chunkNum <= totalChunk) 86 | { 87 | inputStream.seekg(startByte + chunkNum*scoopBufferSize*MinerConfig::plotSize); 88 | char* scoopData = (char*)&(*this->writeBuffer)[0]; 89 | inputStream.read(scoopData, bufferSize); 90 | 91 | verifyLock.lock(); 92 | std::vector* temp = this->readBuffer; 93 | this->readBuffer = this->writeBuffer; 94 | this->writeBuffer = temp; 95 | this->nonceOffset = chunkNum*scoopBufferSize; 96 | verifyLock.unlock(); 97 | this->readSignal.notify_all(); 98 | 99 | chunkNum++; 100 | } 101 | 102 | scoopDoneRead++; 103 | } 104 | */ 105 | 106 | /* 107 | this->buffer[0].resize(this->staggerSize); 108 | this->buffer[1].resize(this->staggerSize); 109 | this->readBuffer = &this->buffer[0]; 110 | this->writeBuffer = &this->buffer[1]; 111 | 112 | size_t bufferSize = this->staggerSize * MinerConfig::scoopSize; 113 | size_t startByte = scoopNum * MinerConfig::scoopSize * this->staggerSize; 114 | size_t chunkNum = 0; 115 | size_t totalChunk = this->nonceCount / this->staggerSize; 116 | this->nonceOffset = 0; 117 | 118 | this->runVerify = true; 119 | std::unique_lock verifyLock(this->readLock); 120 | verifyLock.unlock(); 121 | std::thread verifierThreadObj(&PlotReader::verifierThread,this); 122 | 123 | while(!this->done && inputStream.good() && chunkNum <= totalChunk) 124 | { 125 | inputStream.seekg(startByte + chunkNum*this->staggerSize*MinerConfig::plotSize); 126 | char* scoopData = (char*)&(*this->writeBuffer)[0]; 127 | inputStream.read(scoopData, bufferSize); 128 | 129 | verifyLock.lock(); 130 | std::vector* temp = this->readBuffer; 131 | this->readBuffer = this->writeBuffer; 132 | this->writeBuffer = temp; 133 | this->nonceOffset = chunkNum*this->staggerSize; 134 | verifyLock.unlock(); 135 | this->readSignal.notify_all(); 136 | 137 | chunkNum++; 138 | } 139 | */ 140 | 141 | this->runVerify = true; 142 | std::thread verifierThreadObj(&PlotReader::verifierThread,this); 143 | 144 | size_t chunkNum = 0; 145 | size_t totalChunk = (size_t)std::ceil((double)this->nonceCount / (double)this->staggerSize); 146 | this->nonceOffset = 0; 147 | this->nonceRead = 0; 148 | this->verifySignaled = false; 149 | 150 | this->readBuffer = &this->buffer[0]; 151 | this->writeBuffer = &this->buffer[1]; 152 | 153 | while(!this->done && inputStream.good() && chunkNum <= totalChunk) 154 | { 155 | size_t scoopBufferSize = this->miner->getConfig()->maxBufferSizeMB*1024*1024 / (64*2); 156 | size_t scoopBufferCount = (size_t)std::ceil((float)(this->staggerSize*MinerConfig::scoopSize) / (float)(scoopBufferSize)); 157 | size_t startByte = this->scoopNum * MinerConfig::scoopSize*this->staggerSize + chunkNum*this->staggerSize*MinerConfig::plotSize; 158 | size_t scoopDoneRead = 0; 159 | size_t staggerOffset = 0; 160 | 161 | while(!this->done && inputStream.good() && scoopDoneRead <= scoopBufferCount) 162 | { 163 | this->writeBuffer->resize(scoopBufferSize / MinerConfig::scoopSize); 164 | staggerOffset = scoopDoneRead * scoopBufferSize; 165 | if(scoopBufferSize > (this->staggerSize*MinerConfig::scoopSize - (scoopDoneRead * scoopBufferSize))) 166 | { 167 | scoopBufferSize = this->staggerSize*MinerConfig::scoopSize - (scoopDoneRead * scoopBufferSize); 168 | if(scoopBufferSize > MinerConfig::scoopSize) 169 | { 170 | this->writeBuffer->resize(scoopBufferSize / MinerConfig::scoopSize); 171 | } 172 | } 173 | 174 | if(scoopBufferSize > MinerConfig::scoopSize) 175 | { 176 | inputStream.seekg(startByte + staggerOffset); 177 | char* scoopData = (char*)&(*this->writeBuffer)[0]; 178 | inputStream.read(scoopData, scoopBufferSize); 179 | 180 | 181 | std::unique_lock verifyLock(this->verifyMutex); 182 | 183 | //MinerLogger::write("chunk "+std::to_string(chunkNum)+" offset "+std::to_string(startByte + staggerOffset)+" read "+std::to_string(scoopBufferSize)+" nonce offset "+std::to_string(this->nonceOffset)+" nonceRead "+std::to_string(this->nonceRead)); 184 | 185 | std::vector* temp = this->readBuffer; 186 | this->readBuffer = this->writeBuffer; 187 | this->writeBuffer = temp; 188 | this->nonceOffset = chunkNum*this->staggerSize + scoopDoneRead*(scoopBufferSize / MinerConfig::scoopSize); 189 | this->verifySignaled = true; 190 | this->verifySignal.notify_one(); 191 | verifyLock.unlock(); 192 | 193 | while(this->verifySignaled) 194 | { 195 | //MinerLogger::write("stupid"); 196 | std::this_thread::sleep_for(std::chrono::microseconds(1)); 197 | this->verifySignal.notify_one(); 198 | }; 199 | 200 | } 201 | /* 202 | else 203 | { 204 | MinerLogger::write("scoop buffer ="+std::to_string(scoopBufferSize)); 205 | } 206 | */ 207 | scoopDoneRead++; 208 | } 209 | 210 | chunkNum++; 211 | } 212 | 213 | inputStream.close(); 214 | 215 | 216 | std::unique_lock verifyLock(this->verifyMutex); 217 | this->runVerify = false; 218 | this->readBuffer->clear(); 219 | this->writeBuffer->clear(); 220 | this->verifySignaled = true; 221 | this->verifySignal.notify_all(); 222 | verifyLock.unlock(); 223 | 224 | verifierThreadObj.join(); 225 | 226 | this->done = true; 227 | MinerLogger::write("plot read done. "+Burst::getFileNameFromPath(this->inputPath)+" = "+std::to_string(this->nonceRead)+" nonces "); 228 | } 229 | } 230 | 231 | void Burst::PlotReader::verifierThread() 232 | { 233 | std::unique_lock verifyLock(this->verifyMutex); 234 | 235 | while(this->runVerify) 236 | { 237 | do { 238 | this->verifySignal.wait(verifyLock); 239 | } 240 | while(!this->verifySignaled); 241 | this->verifySignaled = false; 242 | 243 | for(size_t i=0 ; ireadBuffer->size() ; i++) 244 | { 245 | HashData target; 246 | char* test = (char*)&((*this->readBuffer)[i]); 247 | this->hash.update(&this->gensig[0], MinerConfig::hashSize); 248 | this->hash.update(test,MinerConfig::scoopSize); 249 | this->hash.close(&target[0]); 250 | 251 | uint64_t targetResult = 0; 252 | memcpy(&targetResult,&target[0],sizeof(uint64_t)); 253 | uint64_t deadline = targetResult / this->miner->getBaseTarget(); 254 | 255 | uint64_t nonceNum = this->nonceStart + this->nonceOffset + i; 256 | this->miner->submitNonce(nonceNum, this->accountId, deadline); 257 | this->nonceRead++; 258 | } 259 | //MinerLogger::write("verifier processed "+std::to_string(this->nonceRead)+" readsize "+std::to_string(this->readBuffer->size())); 260 | } 261 | //MinerLogger::write("plot read done. "+std::to_string(this->nonceRead)+" nonces "); 262 | } 263 | -------------------------------------------------------------------------------- /src/sphlib/sph_shabal.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_shabal.h 175 2010-05-07 16:03:20Z tp $ */ 2 | /** 3 | * Shabal interface. Shabal is a family of functions which differ by 4 | * their output size; this implementation defines Shabal for output 5 | * sizes 192, 224, 256, 384 and 512 bits. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @file sph_shabal.h 33 | * @author Thomas Pornin 34 | */ 35 | 36 | #ifndef SPH_SHABAL_H__ 37 | #define SPH_SHABAL_H__ 38 | 39 | #include 40 | #include "sph_types.h" 41 | 42 | /** 43 | * Output size (in bits) for Shabal-192. 44 | */ 45 | #define SPH_SIZE_shabal192 192 46 | 47 | /** 48 | * Output size (in bits) for Shabal-224. 49 | */ 50 | #define SPH_SIZE_shabal224 224 51 | 52 | /** 53 | * Output size (in bits) for Shabal-256. 54 | */ 55 | #define SPH_SIZE_shabal256 256 56 | 57 | /** 58 | * Output size (in bits) for Shabal-384. 59 | */ 60 | #define SPH_SIZE_shabal384 384 61 | 62 | /** 63 | * Output size (in bits) for Shabal-512. 64 | */ 65 | #define SPH_SIZE_shabal512 512 66 | 67 | /** 68 | * This structure is a context for Shabal computations: it contains the 69 | * intermediate values and some data from the last entered block. Once 70 | * a Shabal computation has been performed, the context can be reused for 71 | * another computation. 72 | * 73 | * The contents of this structure are private. A running Shabal computation 74 | * can be cloned by copying the context (e.g. with a simple 75 | * memcpy()). 76 | */ 77 | typedef struct { 78 | #ifndef DOXYGEN_IGNORE 79 | unsigned char buf[64]; /* first field, for alignment */ 80 | size_t ptr; 81 | sph_u32 A[12], B[16], C[16]; 82 | sph_u32 Whigh, Wlow; 83 | #endif 84 | } sph_shabal_context; 85 | 86 | /** 87 | * Type for a Shabal-192 context (identical to the common context). 88 | */ 89 | typedef sph_shabal_context sph_shabal192_context; 90 | 91 | /** 92 | * Type for a Shabal-224 context (identical to the common context). 93 | */ 94 | typedef sph_shabal_context sph_shabal224_context; 95 | 96 | /** 97 | * Type for a Shabal-256 context (identical to the common context). 98 | */ 99 | typedef sph_shabal_context sph_shabal256_context; 100 | 101 | /** 102 | * Type for a Shabal-384 context (identical to the common context). 103 | */ 104 | typedef sph_shabal_context sph_shabal384_context; 105 | 106 | /** 107 | * Type for a Shabal-512 context (identical to the common context). 108 | */ 109 | typedef sph_shabal_context sph_shabal512_context; 110 | 111 | /** 112 | * Initialize a Shabal-192 context. This process performs no memory allocation. 113 | * 114 | * @param cc the Shabal-192 context (pointer to a 115 | * sph_shabal192_context) 116 | */ 117 | void sph_shabal192_init(void *cc); 118 | 119 | /** 120 | * Process some data bytes. It is acceptable that len is zero 121 | * (in which case this function does nothing). 122 | * 123 | * @param cc the Shabal-192 context 124 | * @param data the input data 125 | * @param len the input data length (in bytes) 126 | */ 127 | void sph_shabal192(void *cc, const void *data, size_t len); 128 | 129 | /** 130 | * Terminate the current Shabal-192 computation and output the result into 131 | * the provided buffer. The destination buffer must be wide enough to 132 | * accomodate the result (24 bytes). The context is automatically 133 | * reinitialized. 134 | * 135 | * @param cc the Shabal-192 context 136 | * @param dst the destination buffer 137 | */ 138 | void sph_shabal192_close(void *cc, void *dst); 139 | 140 | /** 141 | * Add a few additional bits (0 to 7) to the current computation, then 142 | * terminate it and output the result in the provided buffer, which must 143 | * be wide enough to accomodate the result (24 bytes). If bit number i 144 | * in ub has value 2^i, then the extra bits are those 145 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 146 | * level). The context is automatically reinitialized. 147 | * 148 | * @param cc the Shabal-192 context 149 | * @param ub the extra bits 150 | * @param n the number of extra bits (0 to 7) 151 | * @param dst the destination buffer 152 | */ 153 | void sph_shabal192_addbits_and_close( 154 | void *cc, unsigned ub, unsigned n, void *dst); 155 | 156 | /** 157 | * Initialize a Shabal-224 context. This process performs no memory allocation. 158 | * 159 | * @param cc the Shabal-224 context (pointer to a 160 | * sph_shabal224_context) 161 | */ 162 | void sph_shabal224_init(void *cc); 163 | 164 | /** 165 | * Process some data bytes. It is acceptable that len is zero 166 | * (in which case this function does nothing). 167 | * 168 | * @param cc the Shabal-224 context 169 | * @param data the input data 170 | * @param len the input data length (in bytes) 171 | */ 172 | void sph_shabal224(void *cc, const void *data, size_t len); 173 | 174 | /** 175 | * Terminate the current Shabal-224 computation and output the result into 176 | * the provided buffer. The destination buffer must be wide enough to 177 | * accomodate the result (28 bytes). The context is automatically 178 | * reinitialized. 179 | * 180 | * @param cc the Shabal-224 context 181 | * @param dst the destination buffer 182 | */ 183 | void sph_shabal224_close(void *cc, void *dst); 184 | 185 | /** 186 | * Add a few additional bits (0 to 7) to the current computation, then 187 | * terminate it and output the result in the provided buffer, which must 188 | * be wide enough to accomodate the result (28 bytes). If bit number i 189 | * in ub has value 2^i, then the extra bits are those 190 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 191 | * level). The context is automatically reinitialized. 192 | * 193 | * @param cc the Shabal-224 context 194 | * @param ub the extra bits 195 | * @param n the number of extra bits (0 to 7) 196 | * @param dst the destination buffer 197 | */ 198 | void sph_shabal224_addbits_and_close( 199 | void *cc, unsigned ub, unsigned n, void *dst); 200 | 201 | /** 202 | * Initialize a Shabal-256 context. This process performs no memory allocation. 203 | * 204 | * @param cc the Shabal-256 context (pointer to a 205 | * sph_shabal256_context) 206 | */ 207 | void sph_shabal256_init(void *cc); 208 | 209 | /** 210 | * Process some data bytes. It is acceptable that len is zero 211 | * (in which case this function does nothing). 212 | * 213 | * @param cc the Shabal-256 context 214 | * @param data the input data 215 | * @param len the input data length (in bytes) 216 | */ 217 | void sph_shabal256(void *cc, const void *data, size_t len); 218 | 219 | /** 220 | * Terminate the current Shabal-256 computation and output the result into 221 | * the provided buffer. The destination buffer must be wide enough to 222 | * accomodate the result (32 bytes). The context is automatically 223 | * reinitialized. 224 | * 225 | * @param cc the Shabal-256 context 226 | * @param dst the destination buffer 227 | */ 228 | void sph_shabal256_close(void *cc, void *dst); 229 | 230 | /** 231 | * Add a few additional bits (0 to 7) to the current computation, then 232 | * terminate it and output the result in the provided buffer, which must 233 | * be wide enough to accomodate the result (32 bytes). If bit number i 234 | * in ub has value 2^i, then the extra bits are those 235 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 236 | * level). The context is automatically reinitialized. 237 | * 238 | * @param cc the Shabal-256 context 239 | * @param ub the extra bits 240 | * @param n the number of extra bits (0 to 7) 241 | * @param dst the destination buffer 242 | */ 243 | void sph_shabal256_addbits_and_close( 244 | void *cc, unsigned ub, unsigned n, void *dst); 245 | 246 | /** 247 | * Initialize a Shabal-384 context. This process performs no memory allocation. 248 | * 249 | * @param cc the Shabal-384 context (pointer to a 250 | * sph_shabal384_context) 251 | */ 252 | void sph_shabal384_init(void *cc); 253 | 254 | /** 255 | * Process some data bytes. It is acceptable that len is zero 256 | * (in which case this function does nothing). 257 | * 258 | * @param cc the Shabal-384 context 259 | * @param data the input data 260 | * @param len the input data length (in bytes) 261 | */ 262 | void sph_shabal384(void *cc, const void *data, size_t len); 263 | 264 | /** 265 | * Terminate the current Shabal-384 computation and output the result into 266 | * the provided buffer. The destination buffer must be wide enough to 267 | * accomodate the result (48 bytes). The context is automatically 268 | * reinitialized. 269 | * 270 | * @param cc the Shabal-384 context 271 | * @param dst the destination buffer 272 | */ 273 | void sph_shabal384_close(void *cc, void *dst); 274 | 275 | /** 276 | * Add a few additional bits (0 to 7) to the current computation, then 277 | * terminate it and output the result in the provided buffer, which must 278 | * be wide enough to accomodate the result (48 bytes). If bit number i 279 | * in ub has value 2^i, then the extra bits are those 280 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 281 | * level). The context is automatically reinitialized. 282 | * 283 | * @param cc the Shabal-384 context 284 | * @param ub the extra bits 285 | * @param n the number of extra bits (0 to 7) 286 | * @param dst the destination buffer 287 | */ 288 | void sph_shabal384_addbits_and_close( 289 | void *cc, unsigned ub, unsigned n, void *dst); 290 | 291 | /** 292 | * Initialize a Shabal-512 context. This process performs no memory allocation. 293 | * 294 | * @param cc the Shabal-512 context (pointer to a 295 | * sph_shabal512_context) 296 | */ 297 | void sph_shabal512_init(void *cc); 298 | 299 | /** 300 | * Process some data bytes. It is acceptable that len is zero 301 | * (in which case this function does nothing). 302 | * 303 | * @param cc the Shabal-512 context 304 | * @param data the input data 305 | * @param len the input data length (in bytes) 306 | */ 307 | void sph_shabal512(void *cc, const void *data, size_t len); 308 | 309 | /** 310 | * Terminate the current Shabal-512 computation and output the result into 311 | * the provided buffer. The destination buffer must be wide enough to 312 | * accomodate the result (64 bytes). The context is automatically 313 | * reinitialized. 314 | * 315 | * @param cc the Shabal-512 context 316 | * @param dst the destination buffer 317 | */ 318 | void sph_shabal512_close(void *cc, void *dst); 319 | 320 | /** 321 | * Add a few additional bits (0 to 7) to the current computation, then 322 | * terminate it and output the result in the provided buffer, which must 323 | * be wide enough to accomodate the result (64 bytes). If bit number i 324 | * in ub has value 2^i, then the extra bits are those 325 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 326 | * level). The context is automatically reinitialized. 327 | * 328 | * @param cc the Shabal-512 context 329 | * @param ub the extra bits 330 | * @param n the number of extra bits (0 to 7) 331 | * @param dst the destination buffer 332 | */ 333 | void sph_shabal512_addbits_and_close( 334 | void *cc, unsigned ub, unsigned n, void *dst); 335 | 336 | #endif 337 | -------------------------------------------------------------------------------- /cryptoport-miner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 14C1B22419CB414B00E26D42 /* Makefile in Sources */ = {isa = PBXBuildFile; fileRef = 14C1B22319CB414B00E26D42 /* Makefile */; }; 11 | 14DA79FE19CB4CCE004EB96F /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA79DF19CB4CCE004EB96F /* main.cpp */; }; 12 | 14DA79FF19CB4CCE004EB96F /* Miner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA79E019CB4CCE004EB96F /* Miner.cpp */; }; 13 | 14DA7A0019CB4CCE004EB96F /* MinerConfig.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA79E219CB4CCE004EB96F /* MinerConfig.cpp */; }; 14 | 14DA7A0119CB4CCE004EB96F /* MinerLogger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA79E419CB4CCE004EB96F /* MinerLogger.cpp */; }; 15 | 14DA7A0219CB4CCE004EB96F /* MinerProtocol.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA79E619CB4CCE004EB96F /* MinerProtocol.cpp */; }; 16 | 14DA7A0319CB4CCE004EB96F /* MinerShabal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA79E819CB4CCE004EB96F /* MinerShabal.cpp */; }; 17 | 14DA7A0419CB4CCE004EB96F /* MinerUtil.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA79EA19CB4CCE004EB96F /* MinerUtil.cpp */; }; 18 | 14DA7A0519CB4CCE004EB96F /* PlotReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA79EC19CB4CCE004EB96F /* PlotReader.cpp */; }; 19 | 14DA7A0619CB4CCE004EB96F /* sph_shabal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA79FB19CB4CCE004EB96F /* sph_shabal.cpp */; }; 20 | 14DA7A0B19CB5A0E004EB96F /* nxt_address.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA7A0A19CB5A0E004EB96F /* nxt_address.cpp */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXCopyFilesBuildPhase section */ 24 | 1495546A19C6C76100DC6D79 /* CopyFiles */ = { 25 | isa = PBXCopyFilesBuildPhase; 26 | buildActionMask = 2147483647; 27 | dstPath = /usr/share/man/man1/; 28 | dstSubfolderSpec = 0; 29 | files = ( 30 | ); 31 | runOnlyForDeploymentPostprocessing = 1; 32 | }; 33 | /* End PBXCopyFilesBuildPhase section */ 34 | 35 | /* Begin PBXFileReference section */ 36 | 1495546C19C6C76100DC6D79 /* cryptoport-miner */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cryptoport-miner"; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 14C1B22319CB414B00E26D42 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = ""; }; 38 | 14DA79DF19CB4CCE004EB96F /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 39 | 14DA79E019CB4CCE004EB96F /* Miner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Miner.cpp; sourceTree = ""; }; 40 | 14DA79E119CB4CCE004EB96F /* Miner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Miner.h; sourceTree = ""; }; 41 | 14DA79E219CB4CCE004EB96F /* MinerConfig.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MinerConfig.cpp; sourceTree = ""; }; 42 | 14DA79E319CB4CCE004EB96F /* MinerConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MinerConfig.h; sourceTree = ""; }; 43 | 14DA79E419CB4CCE004EB96F /* MinerLogger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MinerLogger.cpp; sourceTree = ""; }; 44 | 14DA79E519CB4CCE004EB96F /* MinerLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MinerLogger.h; sourceTree = ""; }; 45 | 14DA79E619CB4CCE004EB96F /* MinerProtocol.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MinerProtocol.cpp; sourceTree = ""; }; 46 | 14DA79E719CB4CCE004EB96F /* MinerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MinerProtocol.h; sourceTree = ""; }; 47 | 14DA79E819CB4CCE004EB96F /* MinerShabal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MinerShabal.cpp; sourceTree = ""; }; 48 | 14DA79E919CB4CCE004EB96F /* MinerShabal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MinerShabal.h; sourceTree = ""; }; 49 | 14DA79EA19CB4CCE004EB96F /* MinerUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MinerUtil.cpp; sourceTree = ""; }; 50 | 14DA79EB19CB4CCE004EB96F /* MinerUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MinerUtil.h; sourceTree = ""; }; 51 | 14DA79EC19CB4CCE004EB96F /* PlotReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlotReader.cpp; sourceTree = ""; }; 52 | 14DA79ED19CB4CCE004EB96F /* PlotReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlotReader.h; sourceTree = ""; }; 53 | 14DA79EF19CB4CCE004EB96F /* document.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = document.h; sourceTree = ""; }; 54 | 14DA79F019CB4CCE004EB96F /* filestream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = filestream.h; sourceTree = ""; }; 55 | 14DA79F219CB4CCE004EB96F /* pow10.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pow10.h; sourceTree = ""; }; 56 | 14DA79F319CB4CCE004EB96F /* stack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stack.h; sourceTree = ""; }; 57 | 14DA79F419CB4CCE004EB96F /* strfunc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = strfunc.h; sourceTree = ""; }; 58 | 14DA79F519CB4CCE004EB96F /* prettywriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = prettywriter.h; sourceTree = ""; }; 59 | 14DA79F619CB4CCE004EB96F /* rapidjson.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rapidjson.h; sourceTree = ""; }; 60 | 14DA79F719CB4CCE004EB96F /* reader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reader.h; sourceTree = ""; }; 61 | 14DA79F819CB4CCE004EB96F /* stringbuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stringbuffer.h; sourceTree = ""; }; 62 | 14DA79F919CB4CCE004EB96F /* writer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = writer.h; sourceTree = ""; }; 63 | 14DA79FB19CB4CCE004EB96F /* sph_shabal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sph_shabal.cpp; sourceTree = ""; }; 64 | 14DA79FC19CB4CCE004EB96F /* sph_shabal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sph_shabal.h; sourceTree = ""; }; 65 | 14DA79FD19CB4CCE004EB96F /* sph_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sph_types.h; sourceTree = ""; }; 66 | 14DA7A0819CB5801004EB96F /* nxt_address.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nxt_address.h; sourceTree = ""; }; 67 | 14DA7A0A19CB5A0E004EB96F /* nxt_address.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = nxt_address.cpp; sourceTree = ""; }; 68 | /* End PBXFileReference section */ 69 | 70 | /* Begin PBXFrameworksBuildPhase section */ 71 | 1495546919C6C76100DC6D79 /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | ); 76 | runOnlyForDeploymentPostprocessing = 0; 77 | }; 78 | /* End PBXFrameworksBuildPhase section */ 79 | 80 | /* Begin PBXGroup section */ 81 | 1495546319C6C76100DC6D79 = { 82 | isa = PBXGroup; 83 | children = ( 84 | 14DA79DE19CB4CCE004EB96F /* src */, 85 | 14C1B22319CB414B00E26D42 /* Makefile */, 86 | 1495546D19C6C76100DC6D79 /* Products */, 87 | ); 88 | sourceTree = ""; 89 | }; 90 | 1495546D19C6C76100DC6D79 /* Products */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 1495546C19C6C76100DC6D79 /* cryptoport-miner */, 94 | ); 95 | name = Products; 96 | sourceTree = ""; 97 | }; 98 | 14DA79DE19CB4CCE004EB96F /* src */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 14DA7A0719CB5801004EB96F /* nxt */, 102 | 14DA79DF19CB4CCE004EB96F /* main.cpp */, 103 | 14DA79E019CB4CCE004EB96F /* Miner.cpp */, 104 | 14DA79E119CB4CCE004EB96F /* Miner.h */, 105 | 14DA79E219CB4CCE004EB96F /* MinerConfig.cpp */, 106 | 14DA79E319CB4CCE004EB96F /* MinerConfig.h */, 107 | 14DA79E419CB4CCE004EB96F /* MinerLogger.cpp */, 108 | 14DA79E519CB4CCE004EB96F /* MinerLogger.h */, 109 | 14DA79E619CB4CCE004EB96F /* MinerProtocol.cpp */, 110 | 14DA79E719CB4CCE004EB96F /* MinerProtocol.h */, 111 | 14DA79E819CB4CCE004EB96F /* MinerShabal.cpp */, 112 | 14DA79E919CB4CCE004EB96F /* MinerShabal.h */, 113 | 14DA79EA19CB4CCE004EB96F /* MinerUtil.cpp */, 114 | 14DA79EB19CB4CCE004EB96F /* MinerUtil.h */, 115 | 14DA79EC19CB4CCE004EB96F /* PlotReader.cpp */, 116 | 14DA79ED19CB4CCE004EB96F /* PlotReader.h */, 117 | 14DA79EE19CB4CCE004EB96F /* rapidjson */, 118 | 14DA79FA19CB4CCE004EB96F /* sphlib */, 119 | ); 120 | path = src; 121 | sourceTree = ""; 122 | }; 123 | 14DA79EE19CB4CCE004EB96F /* rapidjson */ = { 124 | isa = PBXGroup; 125 | children = ( 126 | 14DA79EF19CB4CCE004EB96F /* document.h */, 127 | 14DA79F019CB4CCE004EB96F /* filestream.h */, 128 | 14DA79F119CB4CCE004EB96F /* internal */, 129 | 14DA79F519CB4CCE004EB96F /* prettywriter.h */, 130 | 14DA79F619CB4CCE004EB96F /* rapidjson.h */, 131 | 14DA79F719CB4CCE004EB96F /* reader.h */, 132 | 14DA79F819CB4CCE004EB96F /* stringbuffer.h */, 133 | 14DA79F919CB4CCE004EB96F /* writer.h */, 134 | ); 135 | path = rapidjson; 136 | sourceTree = ""; 137 | }; 138 | 14DA79F119CB4CCE004EB96F /* internal */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | 14DA79F219CB4CCE004EB96F /* pow10.h */, 142 | 14DA79F319CB4CCE004EB96F /* stack.h */, 143 | 14DA79F419CB4CCE004EB96F /* strfunc.h */, 144 | ); 145 | path = internal; 146 | sourceTree = ""; 147 | }; 148 | 14DA79FA19CB4CCE004EB96F /* sphlib */ = { 149 | isa = PBXGroup; 150 | children = ( 151 | 14DA79FB19CB4CCE004EB96F /* sph_shabal.cpp */, 152 | 14DA79FC19CB4CCE004EB96F /* sph_shabal.h */, 153 | 14DA79FD19CB4CCE004EB96F /* sph_types.h */, 154 | ); 155 | path = sphlib; 156 | sourceTree = ""; 157 | }; 158 | 14DA7A0719CB5801004EB96F /* nxt */ = { 159 | isa = PBXGroup; 160 | children = ( 161 | 14DA7A0819CB5801004EB96F /* nxt_address.h */, 162 | 14DA7A0A19CB5A0E004EB96F /* nxt_address.cpp */, 163 | ); 164 | path = nxt; 165 | sourceTree = ""; 166 | }; 167 | /* End PBXGroup section */ 168 | 169 | /* Begin PBXNativeTarget section */ 170 | 1495546B19C6C76100DC6D79 /* cryptoport-miner */ = { 171 | isa = PBXNativeTarget; 172 | buildConfigurationList = 1495547519C6C76100DC6D79 /* Build configuration list for PBXNativeTarget "cryptoport-miner" */; 173 | buildPhases = ( 174 | 1495546819C6C76100DC6D79 /* Sources */, 175 | 1495546919C6C76100DC6D79 /* Frameworks */, 176 | 1495546A19C6C76100DC6D79 /* CopyFiles */, 177 | ); 178 | buildRules = ( 179 | ); 180 | dependencies = ( 181 | ); 182 | name = "cryptoport-miner"; 183 | productName = "cryptoport-miner"; 184 | productReference = 1495546C19C6C76100DC6D79 /* cryptoport-miner */; 185 | productType = "com.apple.product-type.tool"; 186 | }; 187 | /* End PBXNativeTarget section */ 188 | 189 | /* Begin PBXProject section */ 190 | 1495546419C6C76100DC6D79 /* Project object */ = { 191 | isa = PBXProject; 192 | attributes = { 193 | LastUpgradeCheck = 0510; 194 | ORGANIZATIONNAME = Miner; 195 | }; 196 | buildConfigurationList = 1495546719C6C76100DC6D79 /* Build configuration list for PBXProject "cryptoport-miner" */; 197 | compatibilityVersion = "Xcode 3.2"; 198 | developmentRegion = English; 199 | hasScannedForEncodings = 0; 200 | knownRegions = ( 201 | en, 202 | ); 203 | mainGroup = 1495546319C6C76100DC6D79; 204 | productRefGroup = 1495546D19C6C76100DC6D79 /* Products */; 205 | projectDirPath = ""; 206 | projectRoot = ""; 207 | targets = ( 208 | 1495546B19C6C76100DC6D79 /* cryptoport-miner */, 209 | ); 210 | }; 211 | /* End PBXProject section */ 212 | 213 | /* Begin PBXSourcesBuildPhase section */ 214 | 1495546819C6C76100DC6D79 /* Sources */ = { 215 | isa = PBXSourcesBuildPhase; 216 | buildActionMask = 2147483647; 217 | files = ( 218 | 14C1B22419CB414B00E26D42 /* Makefile in Sources */, 219 | 14DA7A0B19CB5A0E004EB96F /* nxt_address.cpp in Sources */, 220 | 14DA79FE19CB4CCE004EB96F /* main.cpp in Sources */, 221 | 14DA7A0119CB4CCE004EB96F /* MinerLogger.cpp in Sources */, 222 | 14DA7A0319CB4CCE004EB96F /* MinerShabal.cpp in Sources */, 223 | 14DA7A0419CB4CCE004EB96F /* MinerUtil.cpp in Sources */, 224 | 14DA7A0619CB4CCE004EB96F /* sph_shabal.cpp in Sources */, 225 | 14DA79FF19CB4CCE004EB96F /* Miner.cpp in Sources */, 226 | 14DA7A0219CB4CCE004EB96F /* MinerProtocol.cpp in Sources */, 227 | 14DA7A0019CB4CCE004EB96F /* MinerConfig.cpp in Sources */, 228 | 14DA7A0519CB4CCE004EB96F /* PlotReader.cpp in Sources */, 229 | ); 230 | runOnlyForDeploymentPostprocessing = 0; 231 | }; 232 | /* End PBXSourcesBuildPhase section */ 233 | 234 | /* Begin XCBuildConfiguration section */ 235 | 1495547319C6C76100DC6D79 /* Debug */ = { 236 | isa = XCBuildConfiguration; 237 | buildSettings = { 238 | ALWAYS_SEARCH_USER_PATHS = NO; 239 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 240 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 241 | CLANG_CXX_LIBRARY = "libc++"; 242 | CLANG_ENABLE_MODULES = YES; 243 | CLANG_ENABLE_OBJC_ARC = YES; 244 | CLANG_STATIC_ANALYZER_MODE = deep; 245 | CLANG_WARN_BOOL_CONVERSION = YES; 246 | CLANG_WARN_CONSTANT_CONVERSION = YES; 247 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 248 | CLANG_WARN_EMPTY_BODY = YES; 249 | CLANG_WARN_ENUM_CONVERSION = YES; 250 | CLANG_WARN_INT_CONVERSION = YES; 251 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 252 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 253 | CLANG_X86_VECTOR_INSTRUCTIONS = default; 254 | COPY_PHASE_STRIP = NO; 255 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 256 | GCC_C_LANGUAGE_STANDARD = gnu11; 257 | GCC_DYNAMIC_NO_PIC = NO; 258 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 259 | GCC_OPTIMIZATION_LEVEL = 0; 260 | GCC_PREPROCESSOR_DEFINITIONS = ( 261 | "DEBUG=1", 262 | "$(inherited)", 263 | ); 264 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 265 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 266 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 267 | GCC_WARN_UNDECLARED_SELECTOR = YES; 268 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 269 | GCC_WARN_UNUSED_FUNCTION = YES; 270 | GCC_WARN_UNUSED_VARIABLE = YES; 271 | MACOSX_DEPLOYMENT_TARGET = 10.8; 272 | ONLY_ACTIVE_ARCH = YES; 273 | SDKROOT = macosx10.8; 274 | VALID_ARCHS = x86_64; 275 | }; 276 | name = Debug; 277 | }; 278 | 1495547419C6C76100DC6D79 /* Release */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | ALWAYS_SEARCH_USER_PATHS = NO; 282 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 283 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 284 | CLANG_CXX_LIBRARY = "libc++"; 285 | CLANG_ENABLE_MODULES = YES; 286 | CLANG_ENABLE_OBJC_ARC = YES; 287 | CLANG_STATIC_ANALYZER_MODE = deep; 288 | CLANG_WARN_BOOL_CONVERSION = YES; 289 | CLANG_WARN_CONSTANT_CONVERSION = YES; 290 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 291 | CLANG_WARN_EMPTY_BODY = YES; 292 | CLANG_WARN_ENUM_CONVERSION = YES; 293 | CLANG_WARN_INT_CONVERSION = YES; 294 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 295 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 296 | CLANG_X86_VECTOR_INSTRUCTIONS = sse4.2; 297 | CODE_SIGN_IDENTITY = ""; 298 | COPY_PHASE_STRIP = YES; 299 | DEBUG_INFORMATION_FORMAT = dwarf; 300 | ENABLE_NS_ASSERTIONS = NO; 301 | GCC_C_LANGUAGE_STANDARD = gnu11; 302 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 303 | GCC_GENERATE_DEBUGGING_SYMBOLS = NO; 304 | GCC_OPTIMIZATION_LEVEL = fast; 305 | GCC_SYMBOLS_PRIVATE_EXTERN = YES; 306 | GCC_UNROLL_LOOPS = YES; 307 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 308 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 309 | GCC_WARN_UNDECLARED_SELECTOR = YES; 310 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 311 | GCC_WARN_UNUSED_FUNCTION = YES; 312 | GCC_WARN_UNUSED_VARIABLE = YES; 313 | LLVM_LTO = YES; 314 | MACOSX_DEPLOYMENT_TARGET = 10.8; 315 | ONLY_ACTIVE_ARCH = YES; 316 | SDKROOT = macosx10.8; 317 | VALID_ARCHS = x86_64; 318 | }; 319 | name = Release; 320 | }; 321 | 1495547619C6C76100DC6D79 /* Debug */ = { 322 | isa = XCBuildConfiguration; 323 | buildSettings = { 324 | PRODUCT_NAME = "$(TARGET_NAME)"; 325 | }; 326 | name = Debug; 327 | }; 328 | 1495547719C6C76100DC6D79 /* Release */ = { 329 | isa = XCBuildConfiguration; 330 | buildSettings = { 331 | PRODUCT_NAME = "$(TARGET_NAME)"; 332 | }; 333 | name = Release; 334 | }; 335 | /* End XCBuildConfiguration section */ 336 | 337 | /* Begin XCConfigurationList section */ 338 | 1495546719C6C76100DC6D79 /* Build configuration list for PBXProject "cryptoport-miner" */ = { 339 | isa = XCConfigurationList; 340 | buildConfigurations = ( 341 | 1495547319C6C76100DC6D79 /* Debug */, 342 | 1495547419C6C76100DC6D79 /* Release */, 343 | ); 344 | defaultConfigurationIsVisible = 0; 345 | defaultConfigurationName = Release; 346 | }; 347 | 1495547519C6C76100DC6D79 /* Build configuration list for PBXNativeTarget "cryptoport-miner" */ = { 348 | isa = XCConfigurationList; 349 | buildConfigurations = ( 350 | 1495547619C6C76100DC6D79 /* Debug */, 351 | 1495547719C6C76100DC6D79 /* Release */, 352 | ); 353 | defaultConfigurationIsVisible = 0; 354 | defaultConfigurationName = Release; 355 | }; 356 | /* End XCConfigurationList section */ 357 | }; 358 | rootObject = 1495546419C6C76100DC6D79 /* Project object */; 359 | } 360 | -------------------------------------------------------------------------------- /src/rapidjson/rapidjson.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_RAPIDJSON_H_ 2 | #define RAPIDJSON_RAPIDJSON_H_ 3 | 4 | // Copyright (c) 2011-2012 Milo Yip (miloyip@gmail.com) 5 | // Version 0.11 6 | 7 | #include // malloc(), realloc(), free() 8 | #include // memcpy() 9 | 10 | /////////////////////////////////////////////////////////////////////////////// 11 | // RAPIDJSON_NO_INT64DEFINE 12 | 13 | // Here defines int64_t and uint64_t types in global namespace. 14 | // If user have their own definition, can define RAPIDJSON_NO_INT64DEFINE to disable this. 15 | #ifndef RAPIDJSON_NO_INT64DEFINE 16 | #ifdef _MSC_VER 17 | typedef __int64 int64_t; 18 | typedef unsigned __int64 uint64_t; 19 | #else 20 | #include 21 | #endif 22 | #endif // RAPIDJSON_NO_INT64TYPEDEF 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // RAPIDJSON_ENDIAN 26 | #define RAPIDJSON_LITTLEENDIAN 0 //!< Little endian machine 27 | #define RAPIDJSON_BIGENDIAN 1 //!< Big endian machine 28 | 29 | //! Endianness of the machine. 30 | /*! GCC provided macro for detecting endianness of the target machine. But other 31 | compilers may not have this. User can define RAPIDJSON_ENDIAN to either 32 | RAPIDJSON_LITTLEENDIAN or RAPIDJSON_BIGENDIAN. 33 | */ 34 | #ifndef RAPIDJSON_ENDIAN 35 | #ifdef __BYTE_ORDER__ 36 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 37 | #define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN 38 | #else 39 | #define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN 40 | #endif // __BYTE_ORDER__ 41 | #else 42 | #define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN // Assumes little endian otherwise. 43 | #endif 44 | #endif // RAPIDJSON_ENDIAN 45 | 46 | /////////////////////////////////////////////////////////////////////////////// 47 | // RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_SIMD 48 | 49 | // Enable SSE2 optimization. 50 | //#define RAPIDJSON_SSE2 51 | 52 | // Enable SSE4.2 optimization. 53 | //#define RAPIDJSON_SSE42 54 | 55 | #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) 56 | #define RAPIDJSON_SIMD 57 | #endif 58 | 59 | /////////////////////////////////////////////////////////////////////////////// 60 | // RAPIDJSON_NO_SIZETYPEDEFINE 61 | 62 | #ifndef RAPIDJSON_NO_SIZETYPEDEFINE 63 | namespace rapidjson { 64 | //! Use 32-bit array/string indices even for 64-bit platform, instead of using size_t. 65 | /*! User may override the SizeType by defining RAPIDJSON_NO_SIZETYPEDEFINE. 66 | */ 67 | typedef unsigned SizeType; 68 | } // namespace rapidjson 69 | #endif 70 | 71 | /////////////////////////////////////////////////////////////////////////////// 72 | // RAPIDJSON_ASSERT 73 | 74 | //! Assertion. 75 | /*! By default, rapidjson uses C assert() for assertion. 76 | User can override it by defining RAPIDJSON_ASSERT(x) macro. 77 | */ 78 | #ifndef RAPIDJSON_ASSERT 79 | #include 80 | #define RAPIDJSON_ASSERT(x) assert(x) 81 | #endif // RAPIDJSON_ASSERT 82 | 83 | /////////////////////////////////////////////////////////////////////////////// 84 | // Helpers 85 | 86 | #define RAPIDJSON_MULTILINEMACRO_BEGIN do { 87 | #define RAPIDJSON_MULTILINEMACRO_END \ 88 | } while((void)0, 0) 89 | 90 | namespace rapidjson { 91 | 92 | /////////////////////////////////////////////////////////////////////////////// 93 | // Allocator 94 | 95 | /*! \class rapidjson::Allocator 96 | \brief Concept for allocating, resizing and freeing memory block. 97 | 98 | Note that Malloc() and Realloc() are non-static but Free() is static. 99 | 100 | So if an allocator need to support Free(), it needs to put its pointer in 101 | the header of memory block. 102 | 103 | \code 104 | concept Allocator { 105 | static const bool kNeedFree; //!< Whether this allocator needs to call Free(). 106 | 107 | // Allocate a memory block. 108 | // \param size of the memory block in bytes. 109 | // \returns pointer to the memory block. 110 | void* Malloc(size_t size); 111 | 112 | // Resize a memory block. 113 | // \param originalPtr The pointer to current memory block. Null pointer is permitted. 114 | // \param originalSize The current size in bytes. (Design issue: since some allocator may not book-keep this, explicitly pass to it can save memory.) 115 | // \param newSize the new size in bytes. 116 | void* Realloc(void* originalPtr, size_t originalSize, size_t newSize); 117 | 118 | // Free a memory block. 119 | // \param pointer to the memory block. Null pointer is permitted. 120 | static void Free(void *ptr); 121 | }; 122 | \endcode 123 | */ 124 | 125 | /////////////////////////////////////////////////////////////////////////////// 126 | // CrtAllocator 127 | 128 | //! C-runtime library allocator. 129 | /*! This class is just wrapper for standard C library memory routines. 130 | \implements Allocator 131 | */ 132 | class CrtAllocator { 133 | public: 134 | static const bool kNeedFree = true; 135 | void* Malloc(size_t size) { return malloc(size); } 136 | void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { (void)originalSize; return realloc(originalPtr, newSize); } 137 | static void Free(void *ptr) { free(ptr); } 138 | }; 139 | 140 | /////////////////////////////////////////////////////////////////////////////// 141 | // MemoryPoolAllocator 142 | 143 | //! Default memory allocator used by the parser and DOM. 144 | /*! This allocator allocate memory blocks from pre-allocated memory chunks. 145 | 146 | It does not free memory blocks. And Realloc() only allocate new memory. 147 | 148 | The memory chunks are allocated by BaseAllocator, which is CrtAllocator by default. 149 | 150 | User may also supply a buffer as the first chunk. 151 | 152 | If the user-buffer is full then additional chunks are allocated by BaseAllocator. 153 | 154 | The user-buffer is not deallocated by this allocator. 155 | 156 | \tparam BaseAllocator the allocator type for allocating memory chunks. Default is CrtAllocator. 157 | \implements Allocator 158 | */ 159 | template 160 | class MemoryPoolAllocator { 161 | public: 162 | static const bool kNeedFree = false; //!< Tell users that no need to call Free() with this allocator. (concept Allocator) 163 | 164 | //! Constructor with chunkSize. 165 | /*! \param chunkSize The size of memory chunk. The default is kDefaultChunkSize. 166 | \param baseAllocator The allocator for allocating memory chunks. 167 | */ 168 | MemoryPoolAllocator(size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : 169 | chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(0), baseAllocator_(baseAllocator), ownBaseAllocator_(0) 170 | { 171 | if (!baseAllocator_) 172 | ownBaseAllocator_ = baseAllocator_ = new BaseAllocator(); 173 | AddChunk(chunk_capacity_); 174 | } 175 | 176 | //! Constructor with user-supplied buffer. 177 | /*! The user buffer will be used firstly. When it is full, memory pool allocates new chunk with chunk size. 178 | 179 | The user buffer will not be deallocated when this allocator is destructed. 180 | 181 | \param buffer User supplied buffer. 182 | \param size Size of the buffer in bytes. It must at least larger than sizeof(ChunkHeader). 183 | \param chunkSize The size of memory chunk. The default is kDefaultChunkSize. 184 | \param baseAllocator The allocator for allocating memory chunks. 185 | */ 186 | MemoryPoolAllocator(char *buffer, size_t size, size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : 187 | chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(buffer), baseAllocator_(baseAllocator), ownBaseAllocator_(0) 188 | { 189 | RAPIDJSON_ASSERT(buffer != 0); 190 | RAPIDJSON_ASSERT(size > sizeof(ChunkHeader)); 191 | chunkHead_ = (ChunkHeader*)buffer; 192 | chunkHead_->capacity = size - sizeof(ChunkHeader); 193 | chunkHead_->size = 0; 194 | chunkHead_->next = 0; 195 | } 196 | 197 | //! Destructor. 198 | /*! This deallocates all memory chunks, excluding the user-supplied buffer. 199 | */ 200 | ~MemoryPoolAllocator() { 201 | Clear(); 202 | delete ownBaseAllocator_; 203 | } 204 | 205 | //! Deallocates all memory chunks, excluding the user-supplied buffer. 206 | void Clear() { 207 | while(chunkHead_ != 0 && chunkHead_ != (ChunkHeader *)userBuffer_) { 208 | ChunkHeader* next = chunkHead_->next; 209 | baseAllocator_->Free(chunkHead_); 210 | chunkHead_ = next; 211 | } 212 | } 213 | 214 | //! Computes the total capacity of allocated memory chunks. 215 | /*! \return total capacity in bytes. 216 | */ 217 | size_t Capacity() { 218 | size_t capacity = 0; 219 | for (ChunkHeader* c = chunkHead_; c != 0; c = c->next) 220 | capacity += c->capacity; 221 | return capacity; 222 | } 223 | 224 | //! Computes the memory blocks allocated. 225 | /*! \return total used bytes. 226 | */ 227 | size_t Size() { 228 | size_t size = 0; 229 | for (ChunkHeader* c = chunkHead_; c != 0; c = c->next) 230 | size += c->size; 231 | return size; 232 | } 233 | 234 | //! Allocates a memory block. (concept Allocator) 235 | void* Malloc(size_t size) { 236 | size = (size + 3) & ~3; // Force aligning size to 4 237 | 238 | if (chunkHead_->size + size > chunkHead_->capacity) 239 | AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size); 240 | 241 | char *buffer = (char *)(chunkHead_ + 1) + chunkHead_->size; 242 | RAPIDJSON_ASSERT(((uintptr_t)buffer & 3) == 0); // returned buffer is aligned to 4 243 | chunkHead_->size += size; 244 | 245 | return buffer; 246 | } 247 | 248 | //! Resizes a memory block (concept Allocator) 249 | void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { 250 | if (originalPtr == 0) 251 | return Malloc(newSize); 252 | 253 | // Do not shrink if new size is smaller than original 254 | if (originalSize >= newSize) 255 | return originalPtr; 256 | 257 | // Simply expand it if it is the last allocation and there is sufficient space 258 | if (originalPtr == (char *)(chunkHead_ + 1) + chunkHead_->size - originalSize) { 259 | size_t increment = newSize - originalSize; 260 | increment = (increment + 3) & ~3; // Force aligning size to 4 261 | if (chunkHead_->size + increment <= chunkHead_->capacity) { 262 | chunkHead_->size += increment; 263 | RAPIDJSON_ASSERT(((uintptr_t)originalPtr & 3) == 0); // returned buffer is aligned to 4 264 | return originalPtr; 265 | } 266 | } 267 | 268 | // Realloc process: allocate and copy memory, do not free original buffer. 269 | void* newBuffer = Malloc(newSize); 270 | RAPIDJSON_ASSERT(newBuffer != 0); // Do not handle out-of-memory explicitly. 271 | return memcpy(newBuffer, originalPtr, originalSize); 272 | } 273 | 274 | //! Frees a memory block (concept Allocator) 275 | static void Free(void *) {} // Do nothing 276 | 277 | private: 278 | //! Creates a new chunk. 279 | /*! \param capacity Capacity of the chunk in bytes. 280 | */ 281 | void AddChunk(size_t capacity) { 282 | ChunkHeader* chunk = (ChunkHeader*)baseAllocator_->Malloc(sizeof(ChunkHeader) + capacity); 283 | chunk->capacity = capacity; 284 | chunk->size = 0; 285 | chunk->next = chunkHead_; 286 | chunkHead_ = chunk; 287 | } 288 | 289 | static const int kDefaultChunkCapacity = 64 * 1024; //!< Default chunk capacity. 290 | 291 | //! Chunk header for perpending to each chunk. 292 | /*! Chunks are stored as a singly linked list. 293 | */ 294 | struct ChunkHeader { 295 | size_t capacity; //!< Capacity of the chunk in bytes (excluding the header itself). 296 | size_t size; //!< Current size of allocated memory in bytes. 297 | ChunkHeader *next; //!< Next chunk in the linked list. 298 | }; 299 | 300 | ChunkHeader *chunkHead_; //!< Head of the chunk linked-list. Only the head chunk serves allocation. 301 | size_t chunk_capacity_; //!< The minimum capacity of chunk when they are allocated. 302 | char *userBuffer_; //!< User supplied buffer. 303 | BaseAllocator* baseAllocator_; //!< base allocator for allocating memory chunks. 304 | BaseAllocator* ownBaseAllocator_; //!< base allocator created by this object. 305 | }; 306 | 307 | /////////////////////////////////////////////////////////////////////////////// 308 | // Encoding 309 | 310 | /*! \class rapidjson::Encoding 311 | \brief Concept for encoding of Unicode characters. 312 | 313 | \code 314 | concept Encoding { 315 | typename Ch; //! Type of character. 316 | 317 | //! \brief Encode a Unicode codepoint to a buffer. 318 | //! \param buffer pointer to destination buffer to store the result. It should have sufficient size of encoding one character. 319 | //! \param codepoint An unicode codepoint, ranging from 0x0 to 0x10FFFF inclusively. 320 | //! \returns the pointer to the next character after the encoded data. 321 | static Ch* Encode(Ch *buffer, unsigned codepoint); 322 | }; 323 | \endcode 324 | */ 325 | 326 | /////////////////////////////////////////////////////////////////////////////// 327 | // UTF8 328 | 329 | //! UTF-8 encoding. 330 | /*! http://en.wikipedia.org/wiki/UTF-8 331 | \tparam CharType Type for storing 8-bit UTF-8 data. Default is char. 332 | \implements Encoding 333 | */ 334 | template 335 | struct UTF8 { 336 | typedef CharType Ch; 337 | 338 | static Ch* Encode(Ch *buffer, unsigned codepoint) { 339 | if (codepoint <= 0x7F) 340 | *buffer++ = codepoint & 0xFF; 341 | else if (codepoint <= 0x7FF) { 342 | *buffer++ = 0xC0 | ((codepoint >> 6) & 0xFF); 343 | *buffer++ = 0x80 | ((codepoint & 0x3F)); 344 | } 345 | else if (codepoint <= 0xFFFF) { 346 | *buffer++ = 0xE0 | ((codepoint >> 12) & 0xFF); 347 | *buffer++ = 0x80 | ((codepoint >> 6) & 0x3F); 348 | *buffer++ = 0x80 | (codepoint & 0x3F); 349 | } 350 | else { 351 | RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); 352 | *buffer++ = 0xF0 | ((codepoint >> 18) & 0xFF); 353 | *buffer++ = 0x80 | ((codepoint >> 12) & 0x3F); 354 | *buffer++ = 0x80 | ((codepoint >> 6) & 0x3F); 355 | *buffer++ = 0x80 | (codepoint & 0x3F); 356 | } 357 | return buffer; 358 | } 359 | }; 360 | 361 | /////////////////////////////////////////////////////////////////////////////// 362 | // UTF16 363 | 364 | //! UTF-16 encoding. 365 | /*! http://en.wikipedia.org/wiki/UTF-16 366 | \tparam CharType Type for storing 16-bit UTF-16 data. Default is wchar_t. C++11 may use char16_t instead. 367 | \implements Encoding 368 | */ 369 | template 370 | struct UTF16 { 371 | typedef CharType Ch; 372 | 373 | static Ch* Encode(Ch* buffer, unsigned codepoint) { 374 | if (codepoint <= 0xFFFF) { 375 | RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair 376 | *buffer++ = static_cast(codepoint); 377 | } 378 | else { 379 | RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); 380 | unsigned v = codepoint - 0x10000; 381 | *buffer++ = static_cast((v >> 10) + 0xD800); 382 | *buffer++ = (v & 0x3FF) + 0xDC00; 383 | } 384 | return buffer; 385 | } 386 | }; 387 | 388 | /////////////////////////////////////////////////////////////////////////////// 389 | // UTF32 390 | 391 | //! UTF-32 encoding. 392 | /*! http://en.wikipedia.org/wiki/UTF-32 393 | \tparam Ch Type for storing 32-bit UTF-32 data. Default is unsigned. C++11 may use char32_t instead. 394 | \implements Encoding 395 | */ 396 | template 397 | struct UTF32 { 398 | typedef CharType Ch; 399 | 400 | static Ch *Encode(Ch* buffer, unsigned codepoint) { 401 | RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); 402 | *buffer++ = codepoint; 403 | return buffer; 404 | } 405 | }; 406 | 407 | /////////////////////////////////////////////////////////////////////////////// 408 | // Stream 409 | 410 | /*! \class rapidjson::Stream 411 | \brief Concept for reading and writing characters. 412 | 413 | For read-only stream, no need to implement PutBegin(), Put() and PutEnd(). 414 | 415 | For write-only stream, only need to implement Put(). 416 | 417 | \code 418 | concept Stream { 419 | typename Ch; //!< Character type of the stream. 420 | 421 | //! Read the current character from stream without moving the read cursor. 422 | Ch Peek() const; 423 | 424 | //! Read the current character from stream and moving the read cursor to next character. 425 | Ch Take(); 426 | 427 | //! Get the current read cursor. 428 | //! \return Number of characters read from start. 429 | size_t Tell(); 430 | 431 | //! Begin writing operation at the current read pointer. 432 | //! \return The begin writer pointer. 433 | Ch* PutBegin(); 434 | 435 | //! Write a character. 436 | void Put(Ch c); 437 | 438 | //! End the writing operation. 439 | //! \param begin The begin write pointer returned by PutBegin(). 440 | //! \return Number of characters written. 441 | size_t PutEnd(Ch* begin); 442 | } 443 | \endcode 444 | */ 445 | 446 | //! Put N copies of a character to a stream. 447 | template 448 | inline void PutN(Stream& stream, Ch c, size_t n) { 449 | for (size_t i = 0; i < n; i++) 450 | stream.Put(c); 451 | } 452 | 453 | /////////////////////////////////////////////////////////////////////////////// 454 | // StringStream 455 | 456 | //! Read-only string stream. 457 | /*! \implements Stream 458 | */ 459 | template 460 | struct GenericStringStream { 461 | typedef typename Encoding::Ch Ch; 462 | 463 | GenericStringStream(const Ch *src) : src_(src), head_(src) {} 464 | 465 | Ch Peek() const { return *src_; } 466 | Ch Take() { return *src_++; } 467 | size_t Tell() const { return src_ - head_; } 468 | 469 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 470 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 471 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 472 | 473 | const Ch* src_; //!< Current read position. 474 | const Ch* head_; //!< Original head of the string. 475 | }; 476 | 477 | typedef GenericStringStream > StringStream; 478 | 479 | /////////////////////////////////////////////////////////////////////////////// 480 | // InsituStringStream 481 | 482 | //! A read-write string stream. 483 | /*! This string stream is particularly designed for in-situ parsing. 484 | \implements Stream 485 | */ 486 | template 487 | struct GenericInsituStringStream { 488 | typedef typename Encoding::Ch Ch; 489 | 490 | GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {} 491 | 492 | // Read 493 | Ch Peek() { return *src_; } 494 | Ch Take() { return *src_++; } 495 | size_t Tell() { return src_ - head_; } 496 | 497 | // Write 498 | Ch* PutBegin() { return dst_ = src_; } 499 | void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; } 500 | size_t PutEnd(Ch* begin) { return dst_ - begin; } 501 | 502 | Ch* src_; 503 | Ch* dst_; 504 | Ch* head_; 505 | }; 506 | 507 | typedef GenericInsituStringStream > InsituStringStream; 508 | 509 | /////////////////////////////////////////////////////////////////////////////// 510 | // Type 511 | 512 | //! Type of JSON value 513 | enum Type { 514 | kNullType = 0, //!< null 515 | kFalseType = 1, //!< false 516 | kTrueType = 2, //!< true 517 | kObjectType = 3, //!< object 518 | kArrayType = 4, //!< array 519 | kStringType = 5, //!< string 520 | kNumberType = 6, //!< number 521 | }; 522 | 523 | } // namespace rapidjson 524 | 525 | #endif // RAPIDJSON_RAPIDJSON_H_ 526 | -------------------------------------------------------------------------------- /src/rapidjson/reader.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_READER_H_ 2 | #define RAPIDJSON_READER_H_ 3 | 4 | // Copyright (c) 2011 Milo Yip (miloyip@gmail.com) 5 | // Version 0.1 6 | 7 | #include "rapidjson.h" 8 | #include "internal/pow10.h" 9 | #include "internal/stack.h" 10 | #include 11 | 12 | #ifdef RAPIDJSON_SSE42 13 | #include 14 | #elif defined(RAPIDJSON_SSE2) 15 | #include 16 | #endif 17 | 18 | #ifdef _MSC_VER 19 | #pragma warning(push) 20 | #pragma warning(disable : 4127) // conditional expression is constant 21 | #endif 22 | 23 | #ifndef RAPIDJSON_PARSE_ERROR 24 | #define RAPIDJSON_PARSE_ERROR(msg, offset) \ 25 | RAPIDJSON_MULTILINEMACRO_BEGIN \ 26 | parseError_ = msg; \ 27 | errorOffset_ = offset; \ 28 | longjmp(jmpbuf_, 1); \ 29 | RAPIDJSON_MULTILINEMACRO_END 30 | #endif 31 | 32 | namespace rapidjson { 33 | 34 | /////////////////////////////////////////////////////////////////////////////// 35 | // ParseFlag 36 | 37 | //! Combination of parseFlags 38 | enum ParseFlag { 39 | kParseDefaultFlags = 0, //!< Default parse flags. Non-destructive parsing. Text strings are decoded into allocated buffer. 40 | kParseInsituFlag = 1 //!< In-situ(destructive) parsing. 41 | }; 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | // Handler 45 | 46 | /*! \class rapidjson::Handler 47 | \brief Concept for receiving events from GenericReader upon parsing. 48 | \code 49 | concept Handler { 50 | typename Ch; 51 | 52 | void Null(); 53 | void Bool(bool b); 54 | void Int(int i); 55 | void Uint(unsigned i); 56 | void Int64(int64_t i); 57 | void Uint64(uint64_t i); 58 | void Double(double d); 59 | void String(const Ch* str, SizeType length, bool copy); 60 | void StartObject(); 61 | void EndObject(SizeType memberCount); 62 | void StartArray(); 63 | void EndArray(SizeType elementCount); 64 | }; 65 | \endcode 66 | */ 67 | /////////////////////////////////////////////////////////////////////////////// 68 | // BaseReaderHandler 69 | 70 | //! Default implementation of Handler. 71 | /*! This can be used as base class of any reader handler. 72 | \implements Handler 73 | */ 74 | template > 75 | struct BaseReaderHandler { 76 | typedef typename Encoding::Ch Ch; 77 | 78 | void Default() {} 79 | void Null() { Default(); } 80 | void Bool(bool) { Default(); } 81 | void Int(int) { Default(); } 82 | void Uint(unsigned) { Default(); } 83 | void Int64(int64_t) { Default(); } 84 | void Uint64(uint64_t) { Default(); } 85 | void Double(double) { Default(); } 86 | void String(const Ch*, SizeType, bool) { Default(); } 87 | void StartObject() { Default(); } 88 | void EndObject(SizeType) { Default(); } 89 | void StartArray() { Default(); } 90 | void EndArray(SizeType) { Default(); } 91 | }; 92 | 93 | /////////////////////////////////////////////////////////////////////////////// 94 | // SkipWhitespace 95 | 96 | //! Skip the JSON white spaces in a stream. 97 | /*! \param stream A input stream for skipping white spaces. 98 | \note This function has SSE2/SSE4.2 specialization. 99 | */ 100 | template 101 | void SkipWhitespace(Stream& stream) { 102 | Stream s = stream; // Use a local copy for optimization 103 | while (s.Peek() == ' ' || s.Peek() == '\n' || s.Peek() == '\r' || s.Peek() == '\t') 104 | s.Take(); 105 | stream = s; 106 | } 107 | 108 | #ifdef RAPIDJSON_SSE42 109 | //! Skip whitespace with SSE 4.2 pcmpistrm instruction, testing 16 8-byte characters at once. 110 | inline const char *SkipWhitespace_SIMD(const char* p) { 111 | static const char whitespace[16] = " \n\r\t"; 112 | __m128i w = _mm_loadu_si128((const __m128i *)&whitespace[0]); 113 | 114 | for (;;) { 115 | __m128i s = _mm_loadu_si128((const __m128i *)p); 116 | unsigned r = _mm_cvtsi128_si32(_mm_cmpistrm(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK | _SIDD_NEGATIVE_POLARITY)); 117 | if (r == 0) // all 16 characters are whitespace 118 | p += 16; 119 | else { // some of characters may be non-whitespace 120 | #ifdef _MSC_VER // Find the index of first non-whitespace 121 | unsigned long offset; 122 | if (_BitScanForward(&offset, r)) 123 | return p + offset; 124 | #else 125 | if (r != 0) 126 | return p + __builtin_ffs(r) - 1; 127 | #endif 128 | } 129 | } 130 | } 131 | 132 | #elif defined(RAPIDJSON_SSE2) 133 | 134 | //! Skip whitespace with SSE2 instructions, testing 16 8-byte characters at once. 135 | inline const char *SkipWhitespace_SIMD(const char* p) { 136 | static const char whitespaces[4][17] = { 137 | " ", 138 | "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", 139 | "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r", 140 | "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"}; 141 | 142 | __m128i w0 = _mm_loadu_si128((const __m128i *)&whitespaces[0][0]); 143 | __m128i w1 = _mm_loadu_si128((const __m128i *)&whitespaces[1][0]); 144 | __m128i w2 = _mm_loadu_si128((const __m128i *)&whitespaces[2][0]); 145 | __m128i w3 = _mm_loadu_si128((const __m128i *)&whitespaces[3][0]); 146 | 147 | for (;;) { 148 | __m128i s = _mm_loadu_si128((const __m128i *)p); 149 | __m128i x = _mm_cmpeq_epi8(s, w0); 150 | x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1)); 151 | x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2)); 152 | x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3)); 153 | unsigned short r = ~_mm_movemask_epi8(x); 154 | if (r == 0) // all 16 characters are whitespace 155 | p += 16; 156 | else { // some of characters may be non-whitespace 157 | #ifdef _MSC_VER // Find the index of first non-whitespace 158 | unsigned long offset; 159 | if (_BitScanForward(&offset, r)) 160 | return p + offset; 161 | #else 162 | if (r != 0) 163 | return p + __builtin_ffs(r) - 1; 164 | #endif 165 | } 166 | } 167 | } 168 | 169 | #endif // RAPIDJSON_SSE2 170 | 171 | #ifdef RAPIDJSON_SIMD 172 | //! Template function specialization for InsituStringStream 173 | template<> inline void SkipWhitespace(InsituStringStream& stream) { 174 | stream.src_ = const_cast(SkipWhitespace_SIMD(stream.src_)); 175 | } 176 | 177 | //! Template function specialization for StringStream 178 | template<> inline void SkipWhitespace(StringStream& stream) { 179 | stream.src_ = SkipWhitespace_SIMD(stream.src_); 180 | } 181 | #endif // RAPIDJSON_SIMD 182 | 183 | /////////////////////////////////////////////////////////////////////////////// 184 | // GenericReader 185 | 186 | //! SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator. 187 | /*! GenericReader parses JSON text from a stream, and send events synchronously to an 188 | object implementing Handler concept. 189 | 190 | It needs to allocate a stack for storing a single decoded string during 191 | non-destructive parsing. 192 | 193 | For in-situ parsing, the decoded string is directly written to the source 194 | text string, no temporary buffer is required. 195 | 196 | A GenericReader object can be reused for parsing multiple JSON text. 197 | 198 | \tparam Encoding Encoding of both the stream and the parse output. 199 | \tparam Allocator Allocator type for stack. 200 | */ 201 | template > 202 | class GenericReader { 203 | public: 204 | typedef typename Encoding::Ch Ch; 205 | 206 | //! Constructor. 207 | /*! \param allocator Optional allocator for allocating stack memory. (Only use for non-destructive parsing) 208 | \param stackCapacity stack capacity in bytes for storing a single decoded string. (Only use for non-destructive parsing) 209 | */ 210 | GenericReader(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity) : stack_(allocator, stackCapacity), parseError_(0), errorOffset_(0) {} 211 | 212 | //! Parse JSON text. 213 | /*! \tparam parseFlags Combination of ParseFlag. 214 | \tparam Stream Type of input stream. 215 | \tparam Handler Type of handler which must implement Handler concept. 216 | \param stream Input stream to be parsed. 217 | \param handler The handler to receive events. 218 | \return Whether the parsing is successful. 219 | */ 220 | template 221 | bool Parse(Stream& stream, Handler& handler) { 222 | parseError_ = 0; 223 | errorOffset_ = 0; 224 | 225 | #ifdef _MSC_VER 226 | #pragma warning(push) 227 | #pragma warning(disable : 4611) // interaction between '_setjmp' and C++ object destruction is non-portable 228 | #endif 229 | if (setjmp(jmpbuf_)) { 230 | #ifdef _MSC_VER 231 | #pragma warning(pop) 232 | #endif 233 | stack_.Clear(); 234 | return false; 235 | } 236 | 237 | SkipWhitespace(stream); 238 | 239 | if (stream.Peek() == '\0') 240 | RAPIDJSON_PARSE_ERROR("Text only contains white space(s)", stream.Tell()); 241 | else { 242 | switch (stream.Peek()) { 243 | case '{': ParseObject(stream, handler); break; 244 | case '[': ParseArray(stream, handler); break; 245 | default: RAPIDJSON_PARSE_ERROR("Expect either an object or array at root", stream.Tell()); 246 | } 247 | SkipWhitespace(stream); 248 | 249 | if (stream.Peek() != '\0') 250 | RAPIDJSON_PARSE_ERROR("Nothing should follow the root object or array.", stream.Tell()); 251 | } 252 | 253 | return true; 254 | } 255 | 256 | bool HasParseError() const { return parseError_ != 0; } 257 | const char* GetParseError() const { return parseError_; } 258 | size_t GetErrorOffset() const { return errorOffset_; } 259 | 260 | private: 261 | // Parse object: { string : value, ... } 262 | template 263 | void ParseObject(Stream& stream, Handler& handler) { 264 | RAPIDJSON_ASSERT(stream.Peek() == '{'); 265 | stream.Take(); // Skip '{' 266 | handler.StartObject(); 267 | SkipWhitespace(stream); 268 | 269 | if (stream.Peek() == '}') { 270 | stream.Take(); 271 | handler.EndObject(0); // empty object 272 | return; 273 | } 274 | 275 | for (SizeType memberCount = 0;;) { 276 | if (stream.Peek() != '"') { 277 | RAPIDJSON_PARSE_ERROR("Name of an object member must be a string", stream.Tell()); 278 | break; 279 | } 280 | 281 | ParseString(stream, handler); 282 | SkipWhitespace(stream); 283 | 284 | if (stream.Take() != ':') { 285 | RAPIDJSON_PARSE_ERROR("There must be a colon after the name of object member", stream.Tell()); 286 | break; 287 | } 288 | SkipWhitespace(stream); 289 | 290 | ParseValue(stream, handler); 291 | SkipWhitespace(stream); 292 | 293 | ++memberCount; 294 | 295 | switch(stream.Take()) { 296 | case ',': SkipWhitespace(stream); break; 297 | case '}': handler.EndObject(memberCount); return; 298 | default: RAPIDJSON_PARSE_ERROR("Must be a comma or '}' after an object member", stream.Tell()); 299 | } 300 | } 301 | } 302 | 303 | // Parse array: [ value, ... ] 304 | template 305 | void ParseArray(Stream& stream, Handler& handler) { 306 | RAPIDJSON_ASSERT(stream.Peek() == '['); 307 | stream.Take(); // Skip '[' 308 | handler.StartArray(); 309 | SkipWhitespace(stream); 310 | 311 | if (stream.Peek() == ']') { 312 | stream.Take(); 313 | handler.EndArray(0); // empty array 314 | return; 315 | } 316 | 317 | for (SizeType elementCount = 0;;) { 318 | ParseValue(stream, handler); 319 | ++elementCount; 320 | SkipWhitespace(stream); 321 | 322 | switch (stream.Take()) { 323 | case ',': SkipWhitespace(stream); break; 324 | case ']': handler.EndArray(elementCount); return; 325 | default: RAPIDJSON_PARSE_ERROR("Must be a comma or ']' after an array element.", stream.Tell()); 326 | } 327 | } 328 | } 329 | 330 | template 331 | void ParseNull(Stream& stream, Handler& handler) { 332 | RAPIDJSON_ASSERT(stream.Peek() == 'n'); 333 | stream.Take(); 334 | 335 | if (stream.Take() == 'u' && stream.Take() == 'l' && stream.Take() == 'l') 336 | handler.Null(); 337 | else 338 | RAPIDJSON_PARSE_ERROR("Invalid value", stream.Tell() - 1); 339 | } 340 | 341 | template 342 | void ParseTrue(Stream& stream, Handler& handler) { 343 | RAPIDJSON_ASSERT(stream.Peek() == 't'); 344 | stream.Take(); 345 | 346 | if (stream.Take() == 'r' && stream.Take() == 'u' && stream.Take() == 'e') 347 | handler.Bool(true); 348 | else 349 | RAPIDJSON_PARSE_ERROR("Invalid value", stream.Tell()); 350 | } 351 | 352 | template 353 | void ParseFalse(Stream& stream, Handler& handler) { 354 | RAPIDJSON_ASSERT(stream.Peek() == 'f'); 355 | stream.Take(); 356 | 357 | if (stream.Take() == 'a' && stream.Take() == 'l' && stream.Take() == 's' && stream.Take() == 'e') 358 | handler.Bool(false); 359 | else 360 | RAPIDJSON_PARSE_ERROR("Invalid value", stream.Tell() - 1); 361 | } 362 | 363 | // Helper function to parse four hexidecimal digits in \uXXXX in ParseString(). 364 | template 365 | unsigned ParseHex4(Stream& stream) { 366 | Stream s = stream; // Use a local copy for optimization 367 | unsigned codepoint = 0; 368 | for (int i = 0; i < 4; i++) { 369 | Ch c = s.Take(); 370 | codepoint <<= 4; 371 | codepoint += c; 372 | if (c >= '0' && c <= '9') 373 | codepoint -= '0'; 374 | else if (c >= 'A' && c <= 'F') 375 | codepoint -= 'A' - 10; 376 | else if (c >= 'a' && c <= 'f') 377 | codepoint -= 'a' - 10; 378 | else 379 | RAPIDJSON_PARSE_ERROR("Incorrect hex digit after \\u escape", s.Tell() - 1); 380 | } 381 | stream = s; // Restore stream 382 | return codepoint; 383 | } 384 | 385 | // Parse string, handling the prefix and suffix double quotes and escaping. 386 | template 387 | void ParseString(Stream& stream, Handler& handler) { 388 | #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 389 | static const Ch escape[256] = { 390 | Z16, Z16, 0, 0,'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'/', 391 | Z16, Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, 392 | 0, 0,'\b', 0, 0, 0,'\f', 0, 0, 0, 0, 0, 0, 0,'\n', 0, 393 | 0, 0,'\r', 0,'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 394 | Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 395 | }; 396 | #undef Z16 397 | 398 | Stream s = stream; // Use a local copy for optimization 399 | RAPIDJSON_ASSERT(s.Peek() == '\"'); 400 | s.Take(); // Skip '\"' 401 | Ch *head; 402 | SizeType len; 403 | if (parseFlags & kParseInsituFlag) 404 | head = s.PutBegin(); 405 | else 406 | len = 0; 407 | 408 | #define RAPIDJSON_PUT(x) \ 409 | do { \ 410 | if (parseFlags & kParseInsituFlag) \ 411 | s.Put(x); \ 412 | else { \ 413 | *stack_.template Push() = x; \ 414 | ++len; \ 415 | } \ 416 | } while(false) 417 | 418 | for (;;) { 419 | Ch c = s.Take(); 420 | if (c == '\\') { // Escape 421 | Ch e = s.Take(); 422 | if ((sizeof(Ch) == 1 || e < 256) && escape[(unsigned char)e]) 423 | RAPIDJSON_PUT(escape[(unsigned char)e]); 424 | else if (e == 'u') { // Unicode 425 | unsigned codepoint = ParseHex4(s); 426 | if (codepoint >= 0xD800 && codepoint <= 0xDBFF) { // Handle UTF-16 surrogate pair 427 | if (s.Take() != '\\' || s.Take() != 'u') { 428 | RAPIDJSON_PARSE_ERROR("Missing the second \\u in surrogate pair", s.Tell() - 2); 429 | return; 430 | } 431 | unsigned codepoint2 = ParseHex4(s); 432 | if (codepoint2 < 0xDC00 || codepoint2 > 0xDFFF) { 433 | RAPIDJSON_PARSE_ERROR("The second \\u in surrogate pair is invalid", s.Tell() - 2); 434 | return; 435 | } 436 | codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000; 437 | } 438 | 439 | Ch buffer[4]; 440 | SizeType count = SizeType(Encoding::Encode(buffer, codepoint) - &buffer[0]); 441 | 442 | if (parseFlags & kParseInsituFlag) 443 | for (SizeType i = 0; i < count; i++) 444 | s.Put(buffer[i]); 445 | else { 446 | memcpy(stack_.template Push(count), buffer, count * sizeof(Ch)); 447 | len += count; 448 | } 449 | } 450 | else { 451 | RAPIDJSON_PARSE_ERROR("Unknown escape character", stream.Tell() - 1); 452 | return; 453 | } 454 | } 455 | else if (c == '"') { // Closing double quote 456 | if (parseFlags & kParseInsituFlag) { 457 | size_t length = s.PutEnd(head); 458 | RAPIDJSON_ASSERT(length <= 0xFFFFFFFF); 459 | RAPIDJSON_PUT('\0'); // null-terminate the string 460 | handler.String(head, SizeType(length), false); 461 | } 462 | else { 463 | RAPIDJSON_PUT('\0'); 464 | handler.String(stack_.template Pop(len), len - 1, true); 465 | } 466 | stream = s; // restore stream 467 | return; 468 | } 469 | else if (c == '\0') { 470 | RAPIDJSON_PARSE_ERROR("lacks ending quotation before the end of string", stream.Tell() - 1); 471 | return; 472 | } 473 | else if ((unsigned)c < 0x20) { // RFC 4627: unescaped = %x20-21 / %x23-5B / %x5D-10FFFF 474 | RAPIDJSON_PARSE_ERROR("Incorrect unescaped character in string", stream.Tell() - 1); 475 | return; 476 | } 477 | else 478 | RAPIDJSON_PUT(c); // Normal character, just copy 479 | } 480 | #undef RAPIDJSON_PUT 481 | } 482 | 483 | template 484 | void ParseNumber(Stream& stream, Handler& handler) { 485 | Stream s = stream; // Local copy for optimization 486 | // Parse minus 487 | bool minus = false; 488 | if (s.Peek() == '-') { 489 | minus = true; 490 | s.Take(); 491 | } 492 | 493 | // Parse int: zero / ( digit1-9 *DIGIT ) 494 | unsigned i; 495 | bool try64bit = false; 496 | if (s.Peek() == '0') { 497 | i = 0; 498 | s.Take(); 499 | } 500 | else if (s.Peek() >= '1' && s.Peek() <= '9') { 501 | i = s.Take() - '0'; 502 | 503 | if (minus) 504 | while (s.Peek() >= '0' && s.Peek() <= '9') { 505 | if (i >= 214748364) { // 2^31 = 2147483648 506 | if (i != 214748364 || s.Peek() > '8') { 507 | try64bit = true; 508 | break; 509 | } 510 | } 511 | i = i * 10 + (s.Take() - '0'); 512 | } 513 | else 514 | while (s.Peek() >= '0' && s.Peek() <= '9') { 515 | if (i >= 429496729) { // 2^32 - 1 = 4294967295 516 | if (i != 429496729 || s.Peek() > '5') { 517 | try64bit = true; 518 | break; 519 | } 520 | } 521 | i = i * 10 + (s.Take() - '0'); 522 | } 523 | } 524 | else { 525 | RAPIDJSON_PARSE_ERROR("Expect a value here.", stream.Tell()); 526 | return; 527 | } 528 | 529 | // Parse 64bit int 530 | uint64_t i64 = 0; 531 | bool useDouble = false; 532 | if (try64bit) { 533 | i64 = i; 534 | if (minus) 535 | while (s.Peek() >= '0' && s.Peek() <= '9') { 536 | if (i64 >= 922337203685477580uLL) // 2^63 = 9223372036854775808 537 | if (i64 != 922337203685477580uLL || s.Peek() > '8') { 538 | useDouble = true; 539 | break; 540 | } 541 | i64 = i64 * 10 + (s.Take() - '0'); 542 | } 543 | else 544 | while (s.Peek() >= '0' && s.Peek() <= '9') { 545 | if (i64 >= 1844674407370955161uLL) // 2^64 - 1 = 18446744073709551615 546 | if (i64 != 1844674407370955161uLL || s.Peek() > '5') { 547 | useDouble = true; 548 | break; 549 | } 550 | i64 = i64 * 10 + (s.Take() - '0'); 551 | } 552 | } 553 | 554 | // Force double for big integer 555 | double d = 0.0; 556 | if (useDouble) { 557 | d = (double)i64; 558 | while (s.Peek() >= '0' && s.Peek() <= '9') { 559 | if (d >= 1E307) { 560 | RAPIDJSON_PARSE_ERROR("Number too big to store in double", stream.Tell()); 561 | return; 562 | } 563 | d = d * 10 + (s.Take() - '0'); 564 | } 565 | } 566 | 567 | // Parse frac = decimal-point 1*DIGIT 568 | int expFrac = 0; 569 | if (s.Peek() == '.') { 570 | if (!useDouble) { 571 | d = try64bit ? (double)i64 : (double)i; 572 | useDouble = true; 573 | } 574 | s.Take(); 575 | 576 | if (s.Peek() >= '0' && s.Peek() <= '9') { 577 | d = d * 10 + (s.Take() - '0'); 578 | --expFrac; 579 | } 580 | else { 581 | RAPIDJSON_PARSE_ERROR("At least one digit in fraction part", stream.Tell()); 582 | return; 583 | } 584 | 585 | while (s.Peek() >= '0' && s.Peek() <= '9') { 586 | if (expFrac > -16) { 587 | d = d * 10 + (s.Peek() - '0'); 588 | --expFrac; 589 | } 590 | s.Take(); 591 | } 592 | } 593 | 594 | // Parse exp = e [ minus / plus ] 1*DIGIT 595 | int exp = 0; 596 | if (s.Peek() == 'e' || s.Peek() == 'E') { 597 | if (!useDouble) { 598 | d = try64bit ? (double)i64 : (double)i; 599 | useDouble = true; 600 | } 601 | s.Take(); 602 | 603 | bool expMinus = false; 604 | if (s.Peek() == '+') 605 | s.Take(); 606 | else if (s.Peek() == '-') { 607 | s.Take(); 608 | expMinus = true; 609 | } 610 | 611 | if (s.Peek() >= '0' && s.Peek() <= '9') { 612 | exp = s.Take() - '0'; 613 | while (s.Peek() >= '0' && s.Peek() <= '9') { 614 | exp = exp * 10 + (s.Take() - '0'); 615 | if (exp > 308) { 616 | RAPIDJSON_PARSE_ERROR("Number too big to store in double", stream.Tell()); 617 | return; 618 | } 619 | } 620 | } 621 | else { 622 | RAPIDJSON_PARSE_ERROR("At least one digit in exponent", s.Tell()); 623 | return; 624 | } 625 | 626 | if (expMinus) 627 | exp = -exp; 628 | } 629 | 630 | // Finish parsing, call event according to the type of number. 631 | if (useDouble) { 632 | d *= internal::Pow10(exp + expFrac); 633 | handler.Double(minus ? -d : d); 634 | } 635 | else { 636 | if (try64bit) { 637 | if (minus) 638 | handler.Int64(-(int64_t)i64); 639 | else 640 | handler.Uint64(i64); 641 | } 642 | else { 643 | if (minus) 644 | handler.Int(-(int)i); 645 | else 646 | handler.Uint(i); 647 | } 648 | } 649 | 650 | stream = s; // restore stream 651 | } 652 | 653 | // Parse any JSON value 654 | template 655 | void ParseValue(Stream& stream, Handler& handler) { 656 | switch (stream.Peek()) { 657 | case 'n': ParseNull (stream, handler); break; 658 | case 't': ParseTrue (stream, handler); break; 659 | case 'f': ParseFalse (stream, handler); break; 660 | case '"': ParseString(stream, handler); break; 661 | case '{': ParseObject(stream, handler); break; 662 | case '[': ParseArray (stream, handler); break; 663 | default : ParseNumber(stream, handler); 664 | } 665 | } 666 | 667 | static const size_t kDefaultStackCapacity = 256; //!< Default stack capacity in bytes for storing a single decoded string. 668 | internal::Stack stack_; //!< A stack for storing decoded string temporarily during non-destructive parsing. 669 | jmp_buf jmpbuf_; //!< setjmp buffer for fast exit from nested parsing function calls. 670 | const char* parseError_; 671 | size_t errorOffset_; 672 | }; // class GenericReader 673 | 674 | //! Reader with UTF8 encoding and default allocator. 675 | typedef GenericReader > Reader; 676 | 677 | } // namespace rapidjson 678 | 679 | #ifdef _MSC_VER 680 | #pragma warning(pop) 681 | #endif 682 | 683 | #endif // RAPIDJSON_READER_H_ 684 | -------------------------------------------------------------------------------- /src/sphlib/sph_shabal.cpp: -------------------------------------------------------------------------------- 1 | /* $Id: shabal.c 175 2010-05-07 16:03:20Z tp $ */ 2 | /* 3 | * Shabal implementation. 4 | * 5 | * ==========================(LICENSE BEGIN)============================ 6 | * 7 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining 10 | * a copy of this software and associated documentation files (the 11 | * "Software"), to deal in the Software without restriction, including 12 | * without limitation the rights to use, copy, modify, merge, publish, 13 | * distribute, sublicense, and/or sell copies of the Software, and to 14 | * permit persons to whom the Software is furnished to do so, subject to 15 | * the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * ===========================(LICENSE END)============================= 29 | * 30 | * @author Thomas Pornin 31 | */ 32 | 33 | #include 34 | #include 35 | 36 | #include "sph_shabal.h" 37 | 38 | #ifdef _MSC_VER 39 | #pragma warning (disable: 4146) 40 | #endif 41 | 42 | /* 43 | * Part of this code was automatically generated (the part between 44 | * the "BEGIN" and "END" markers). 45 | */ 46 | 47 | #define sM 16 48 | 49 | #define C32 SPH_C32 50 | #define T32 SPH_T32 51 | 52 | #define O1 13 53 | #define O2 9 54 | #define O3 6 55 | 56 | /* 57 | * We copy the state into local variables, so that the compiler knows 58 | * that it can optimize them at will. 59 | */ 60 | 61 | /* BEGIN -- automatically generated code. */ 62 | 63 | #define DECL_STATE \ 64 | sph_u32 A00, A01, A02, A03, A04, A05, A06, A07, \ 65 | A08, A09, A0A, A0B; \ 66 | sph_u32 B0, B1, B2, B3, B4, B5, B6, B7, \ 67 | B8, B9, BA, BB, BC, BD, BE, BF; \ 68 | sph_u32 C0, C1, C2, C3, C4, C5, C6, C7, \ 69 | C8, C9, CA, CB, CC, CD, CE, CF; \ 70 | sph_u32 M0, M1, M2, M3, M4, M5, M6, M7, \ 71 | M8, M9, MA, MB, MC, MD, ME, MF; \ 72 | sph_u32 Wlow, Whigh; 73 | 74 | #define READ_STATE(state) do { \ 75 | A00 = (state)->A[0]; \ 76 | A01 = (state)->A[1]; \ 77 | A02 = (state)->A[2]; \ 78 | A03 = (state)->A[3]; \ 79 | A04 = (state)->A[4]; \ 80 | A05 = (state)->A[5]; \ 81 | A06 = (state)->A[6]; \ 82 | A07 = (state)->A[7]; \ 83 | A08 = (state)->A[8]; \ 84 | A09 = (state)->A[9]; \ 85 | A0A = (state)->A[10]; \ 86 | A0B = (state)->A[11]; \ 87 | B0 = (state)->B[0]; \ 88 | B1 = (state)->B[1]; \ 89 | B2 = (state)->B[2]; \ 90 | B3 = (state)->B[3]; \ 91 | B4 = (state)->B[4]; \ 92 | B5 = (state)->B[5]; \ 93 | B6 = (state)->B[6]; \ 94 | B7 = (state)->B[7]; \ 95 | B8 = (state)->B[8]; \ 96 | B9 = (state)->B[9]; \ 97 | BA = (state)->B[10]; \ 98 | BB = (state)->B[11]; \ 99 | BC = (state)->B[12]; \ 100 | BD = (state)->B[13]; \ 101 | BE = (state)->B[14]; \ 102 | BF = (state)->B[15]; \ 103 | C0 = (state)->C[0]; \ 104 | C1 = (state)->C[1]; \ 105 | C2 = (state)->C[2]; \ 106 | C3 = (state)->C[3]; \ 107 | C4 = (state)->C[4]; \ 108 | C5 = (state)->C[5]; \ 109 | C6 = (state)->C[6]; \ 110 | C7 = (state)->C[7]; \ 111 | C8 = (state)->C[8]; \ 112 | C9 = (state)->C[9]; \ 113 | CA = (state)->C[10]; \ 114 | CB = (state)->C[11]; \ 115 | CC = (state)->C[12]; \ 116 | CD = (state)->C[13]; \ 117 | CE = (state)->C[14]; \ 118 | CF = (state)->C[15]; \ 119 | Wlow = (state)->Wlow; \ 120 | Whigh = (state)->Whigh; \ 121 | } while (0) 122 | 123 | #define WRITE_STATE(state) do { \ 124 | (state)->A[0] = A00; \ 125 | (state)->A[1] = A01; \ 126 | (state)->A[2] = A02; \ 127 | (state)->A[3] = A03; \ 128 | (state)->A[4] = A04; \ 129 | (state)->A[5] = A05; \ 130 | (state)->A[6] = A06; \ 131 | (state)->A[7] = A07; \ 132 | (state)->A[8] = A08; \ 133 | (state)->A[9] = A09; \ 134 | (state)->A[10] = A0A; \ 135 | (state)->A[11] = A0B; \ 136 | (state)->B[0] = B0; \ 137 | (state)->B[1] = B1; \ 138 | (state)->B[2] = B2; \ 139 | (state)->B[3] = B3; \ 140 | (state)->B[4] = B4; \ 141 | (state)->B[5] = B5; \ 142 | (state)->B[6] = B6; \ 143 | (state)->B[7] = B7; \ 144 | (state)->B[8] = B8; \ 145 | (state)->B[9] = B9; \ 146 | (state)->B[10] = BA; \ 147 | (state)->B[11] = BB; \ 148 | (state)->B[12] = BC; \ 149 | (state)->B[13] = BD; \ 150 | (state)->B[14] = BE; \ 151 | (state)->B[15] = BF; \ 152 | (state)->C[0] = C0; \ 153 | (state)->C[1] = C1; \ 154 | (state)->C[2] = C2; \ 155 | (state)->C[3] = C3; \ 156 | (state)->C[4] = C4; \ 157 | (state)->C[5] = C5; \ 158 | (state)->C[6] = C6; \ 159 | (state)->C[7] = C7; \ 160 | (state)->C[8] = C8; \ 161 | (state)->C[9] = C9; \ 162 | (state)->C[10] = CA; \ 163 | (state)->C[11] = CB; \ 164 | (state)->C[12] = CC; \ 165 | (state)->C[13] = CD; \ 166 | (state)->C[14] = CE; \ 167 | (state)->C[15] = CF; \ 168 | (state)->Wlow = Wlow; \ 169 | (state)->Whigh = Whigh; \ 170 | } while (0) 171 | 172 | #define DECODE_BLOCK do { \ 173 | M0 = sph_dec32le_aligned(buf + 0); \ 174 | M1 = sph_dec32le_aligned(buf + 4); \ 175 | M2 = sph_dec32le_aligned(buf + 8); \ 176 | M3 = sph_dec32le_aligned(buf + 12); \ 177 | M4 = sph_dec32le_aligned(buf + 16); \ 178 | M5 = sph_dec32le_aligned(buf + 20); \ 179 | M6 = sph_dec32le_aligned(buf + 24); \ 180 | M7 = sph_dec32le_aligned(buf + 28); \ 181 | M8 = sph_dec32le_aligned(buf + 32); \ 182 | M9 = sph_dec32le_aligned(buf + 36); \ 183 | MA = sph_dec32le_aligned(buf + 40); \ 184 | MB = sph_dec32le_aligned(buf + 44); \ 185 | MC = sph_dec32le_aligned(buf + 48); \ 186 | MD = sph_dec32le_aligned(buf + 52); \ 187 | ME = sph_dec32le_aligned(buf + 56); \ 188 | MF = sph_dec32le_aligned(buf + 60); \ 189 | } while (0) 190 | 191 | #define INPUT_BLOCK_ADD do { \ 192 | B0 = T32(B0 + M0); \ 193 | B1 = T32(B1 + M1); \ 194 | B2 = T32(B2 + M2); \ 195 | B3 = T32(B3 + M3); \ 196 | B4 = T32(B4 + M4); \ 197 | B5 = T32(B5 + M5); \ 198 | B6 = T32(B6 + M6); \ 199 | B7 = T32(B7 + M7); \ 200 | B8 = T32(B8 + M8); \ 201 | B9 = T32(B9 + M9); \ 202 | BA = T32(BA + MA); \ 203 | BB = T32(BB + MB); \ 204 | BC = T32(BC + MC); \ 205 | BD = T32(BD + MD); \ 206 | BE = T32(BE + ME); \ 207 | BF = T32(BF + MF); \ 208 | } while (0) 209 | 210 | #define INPUT_BLOCK_SUB do { \ 211 | C0 = T32(C0 - M0); \ 212 | C1 = T32(C1 - M1); \ 213 | C2 = T32(C2 - M2); \ 214 | C3 = T32(C3 - M3); \ 215 | C4 = T32(C4 - M4); \ 216 | C5 = T32(C5 - M5); \ 217 | C6 = T32(C6 - M6); \ 218 | C7 = T32(C7 - M7); \ 219 | C8 = T32(C8 - M8); \ 220 | C9 = T32(C9 - M9); \ 221 | CA = T32(CA - MA); \ 222 | CB = T32(CB - MB); \ 223 | CC = T32(CC - MC); \ 224 | CD = T32(CD - MD); \ 225 | CE = T32(CE - ME); \ 226 | CF = T32(CF - MF); \ 227 | } while (0) 228 | 229 | #define XOR_W do { \ 230 | A00 ^= Wlow; \ 231 | A01 ^= Whigh; \ 232 | } while (0) 233 | 234 | #define SWAP(v1, v2) do { \ 235 | sph_u32 tmp = (v1); \ 236 | (v1) = (v2); \ 237 | (v2) = tmp; \ 238 | } while (0) 239 | 240 | #define SWAP_BC do { \ 241 | SWAP(B0, C0); \ 242 | SWAP(B1, C1); \ 243 | SWAP(B2, C2); \ 244 | SWAP(B3, C3); \ 245 | SWAP(B4, C4); \ 246 | SWAP(B5, C5); \ 247 | SWAP(B6, C6); \ 248 | SWAP(B7, C7); \ 249 | SWAP(B8, C8); \ 250 | SWAP(B9, C9); \ 251 | SWAP(BA, CA); \ 252 | SWAP(BB, CB); \ 253 | SWAP(BC, CC); \ 254 | SWAP(BD, CD); \ 255 | SWAP(BE, CE); \ 256 | SWAP(BF, CF); \ 257 | } while (0) 258 | 259 | #define PERM_ELT(xa0, xa1, xb0, xb1, xb2, xb3, xc, xm) do { \ 260 | xa0 = T32((xa0 \ 261 | ^ (((xa1 << 15) | (xa1 >> 17)) * 5U) \ 262 | ^ xc) * 3U) \ 263 | ^ xb1 ^ (xb2 & ~xb3) ^ xm; \ 264 | xb0 = T32(~(((xb0 << 1) | (xb0 >> 31)) ^ xa0)); \ 265 | } while (0) 266 | 267 | #define PERM_STEP_0 do { \ 268 | PERM_ELT(A00, A0B, B0, BD, B9, B6, C8, M0); \ 269 | PERM_ELT(A01, A00, B1, BE, BA, B7, C7, M1); \ 270 | PERM_ELT(A02, A01, B2, BF, BB, B8, C6, M2); \ 271 | PERM_ELT(A03, A02, B3, B0, BC, B9, C5, M3); \ 272 | PERM_ELT(A04, A03, B4, B1, BD, BA, C4, M4); \ 273 | PERM_ELT(A05, A04, B5, B2, BE, BB, C3, M5); \ 274 | PERM_ELT(A06, A05, B6, B3, BF, BC, C2, M6); \ 275 | PERM_ELT(A07, A06, B7, B4, B0, BD, C1, M7); \ 276 | PERM_ELT(A08, A07, B8, B5, B1, BE, C0, M8); \ 277 | PERM_ELT(A09, A08, B9, B6, B2, BF, CF, M9); \ 278 | PERM_ELT(A0A, A09, BA, B7, B3, B0, CE, MA); \ 279 | PERM_ELT(A0B, A0A, BB, B8, B4, B1, CD, MB); \ 280 | PERM_ELT(A00, A0B, BC, B9, B5, B2, CC, MC); \ 281 | PERM_ELT(A01, A00, BD, BA, B6, B3, CB, MD); \ 282 | PERM_ELT(A02, A01, BE, BB, B7, B4, CA, ME); \ 283 | PERM_ELT(A03, A02, BF, BC, B8, B5, C9, MF); \ 284 | } while (0) 285 | 286 | #define PERM_STEP_1 do { \ 287 | PERM_ELT(A04, A03, B0, BD, B9, B6, C8, M0); \ 288 | PERM_ELT(A05, A04, B1, BE, BA, B7, C7, M1); \ 289 | PERM_ELT(A06, A05, B2, BF, BB, B8, C6, M2); \ 290 | PERM_ELT(A07, A06, B3, B0, BC, B9, C5, M3); \ 291 | PERM_ELT(A08, A07, B4, B1, BD, BA, C4, M4); \ 292 | PERM_ELT(A09, A08, B5, B2, BE, BB, C3, M5); \ 293 | PERM_ELT(A0A, A09, B6, B3, BF, BC, C2, M6); \ 294 | PERM_ELT(A0B, A0A, B7, B4, B0, BD, C1, M7); \ 295 | PERM_ELT(A00, A0B, B8, B5, B1, BE, C0, M8); \ 296 | PERM_ELT(A01, A00, B9, B6, B2, BF, CF, M9); \ 297 | PERM_ELT(A02, A01, BA, B7, B3, B0, CE, MA); \ 298 | PERM_ELT(A03, A02, BB, B8, B4, B1, CD, MB); \ 299 | PERM_ELT(A04, A03, BC, B9, B5, B2, CC, MC); \ 300 | PERM_ELT(A05, A04, BD, BA, B6, B3, CB, MD); \ 301 | PERM_ELT(A06, A05, BE, BB, B7, B4, CA, ME); \ 302 | PERM_ELT(A07, A06, BF, BC, B8, B5, C9, MF); \ 303 | } while (0) 304 | 305 | #define PERM_STEP_2 do { \ 306 | PERM_ELT(A08, A07, B0, BD, B9, B6, C8, M0); \ 307 | PERM_ELT(A09, A08, B1, BE, BA, B7, C7, M1); \ 308 | PERM_ELT(A0A, A09, B2, BF, BB, B8, C6, M2); \ 309 | PERM_ELT(A0B, A0A, B3, B0, BC, B9, C5, M3); \ 310 | PERM_ELT(A00, A0B, B4, B1, BD, BA, C4, M4); \ 311 | PERM_ELT(A01, A00, B5, B2, BE, BB, C3, M5); \ 312 | PERM_ELT(A02, A01, B6, B3, BF, BC, C2, M6); \ 313 | PERM_ELT(A03, A02, B7, B4, B0, BD, C1, M7); \ 314 | PERM_ELT(A04, A03, B8, B5, B1, BE, C0, M8); \ 315 | PERM_ELT(A05, A04, B9, B6, B2, BF, CF, M9); \ 316 | PERM_ELT(A06, A05, BA, B7, B3, B0, CE, MA); \ 317 | PERM_ELT(A07, A06, BB, B8, B4, B1, CD, MB); \ 318 | PERM_ELT(A08, A07, BC, B9, B5, B2, CC, MC); \ 319 | PERM_ELT(A09, A08, BD, BA, B6, B3, CB, MD); \ 320 | PERM_ELT(A0A, A09, BE, BB, B7, B4, CA, ME); \ 321 | PERM_ELT(A0B, A0A, BF, BC, B8, B5, C9, MF); \ 322 | } while (0) 323 | 324 | #define APPLY_P do { \ 325 | B0 = T32(B0 << 17) | (B0 >> 15); \ 326 | B1 = T32(B1 << 17) | (B1 >> 15); \ 327 | B2 = T32(B2 << 17) | (B2 >> 15); \ 328 | B3 = T32(B3 << 17) | (B3 >> 15); \ 329 | B4 = T32(B4 << 17) | (B4 >> 15); \ 330 | B5 = T32(B5 << 17) | (B5 >> 15); \ 331 | B6 = T32(B6 << 17) | (B6 >> 15); \ 332 | B7 = T32(B7 << 17) | (B7 >> 15); \ 333 | B8 = T32(B8 << 17) | (B8 >> 15); \ 334 | B9 = T32(B9 << 17) | (B9 >> 15); \ 335 | BA = T32(BA << 17) | (BA >> 15); \ 336 | BB = T32(BB << 17) | (BB >> 15); \ 337 | BC = T32(BC << 17) | (BC >> 15); \ 338 | BD = T32(BD << 17) | (BD >> 15); \ 339 | BE = T32(BE << 17) | (BE >> 15); \ 340 | BF = T32(BF << 17) | (BF >> 15); \ 341 | PERM_STEP_0; \ 342 | PERM_STEP_1; \ 343 | PERM_STEP_2; \ 344 | A0B = T32(A0B + C6); \ 345 | A0A = T32(A0A + C5); \ 346 | A09 = T32(A09 + C4); \ 347 | A08 = T32(A08 + C3); \ 348 | A07 = T32(A07 + C2); \ 349 | A06 = T32(A06 + C1); \ 350 | A05 = T32(A05 + C0); \ 351 | A04 = T32(A04 + CF); \ 352 | A03 = T32(A03 + CE); \ 353 | A02 = T32(A02 + CD); \ 354 | A01 = T32(A01 + CC); \ 355 | A00 = T32(A00 + CB); \ 356 | A0B = T32(A0B + CA); \ 357 | A0A = T32(A0A + C9); \ 358 | A09 = T32(A09 + C8); \ 359 | A08 = T32(A08 + C7); \ 360 | A07 = T32(A07 + C6); \ 361 | A06 = T32(A06 + C5); \ 362 | A05 = T32(A05 + C4); \ 363 | A04 = T32(A04 + C3); \ 364 | A03 = T32(A03 + C2); \ 365 | A02 = T32(A02 + C1); \ 366 | A01 = T32(A01 + C0); \ 367 | A00 = T32(A00 + CF); \ 368 | A0B = T32(A0B + CE); \ 369 | A0A = T32(A0A + CD); \ 370 | A09 = T32(A09 + CC); \ 371 | A08 = T32(A08 + CB); \ 372 | A07 = T32(A07 + CA); \ 373 | A06 = T32(A06 + C9); \ 374 | A05 = T32(A05 + C8); \ 375 | A04 = T32(A04 + C7); \ 376 | A03 = T32(A03 + C6); \ 377 | A02 = T32(A02 + C5); \ 378 | A01 = T32(A01 + C4); \ 379 | A00 = T32(A00 + C3); \ 380 | } while (0) 381 | 382 | #define INCR_W do { \ 383 | if ((Wlow = T32(Wlow + 1)) == 0) \ 384 | Whigh = T32(Whigh + 1); \ 385 | } while (0) 386 | 387 | static const sph_u32 A_init_192[] = { 388 | C32(0xFD749ED4), C32(0xB798E530), C32(0x33904B6F), C32(0x46BDA85E), 389 | C32(0x076934B4), C32(0x454B4058), C32(0x77F74527), C32(0xFB4CF465), 390 | C32(0x62931DA9), C32(0xE778C8DB), C32(0x22B3998E), C32(0xAC15CFB9) 391 | }; 392 | 393 | static const sph_u32 B_init_192[] = { 394 | C32(0x58BCBAC4), C32(0xEC47A08E), C32(0xAEE933B2), C32(0xDFCBC824), 395 | C32(0xA7944804), C32(0xBF65BDB0), C32(0x5A9D4502), C32(0x59979AF7), 396 | C32(0xC5CEA54E), C32(0x4B6B8150), C32(0x16E71909), C32(0x7D632319), 397 | C32(0x930573A0), C32(0xF34C63D1), C32(0xCAF914B4), C32(0xFDD6612C) 398 | }; 399 | 400 | static const sph_u32 C_init_192[] = { 401 | C32(0x61550878), C32(0x89EF2B75), C32(0xA1660C46), C32(0x7EF3855B), 402 | C32(0x7297B58C), C32(0x1BC67793), C32(0x7FB1C723), C32(0xB66FC640), 403 | C32(0x1A48B71C), C32(0xF0976D17), C32(0x088CE80A), C32(0xA454EDF3), 404 | C32(0x1C096BF4), C32(0xAC76224B), C32(0x5215781C), C32(0xCD5D2669) 405 | }; 406 | 407 | static const sph_u32 A_init_224[] = { 408 | C32(0xA5201467), C32(0xA9B8D94A), C32(0xD4CED997), C32(0x68379D7B), 409 | C32(0xA7FC73BA), C32(0xF1A2546B), C32(0x606782BF), C32(0xE0BCFD0F), 410 | C32(0x2F25374E), C32(0x069A149F), C32(0x5E2DFF25), C32(0xFAECF061) 411 | }; 412 | 413 | static const sph_u32 B_init_224[] = { 414 | C32(0xEC9905D8), C32(0xF21850CF), C32(0xC0A746C8), C32(0x21DAD498), 415 | C32(0x35156EEB), C32(0x088C97F2), C32(0x26303E40), C32(0x8A2D4FB5), 416 | C32(0xFEEE44B6), C32(0x8A1E9573), C32(0x7B81111A), C32(0xCBC139F0), 417 | C32(0xA3513861), C32(0x1D2C362E), C32(0x918C580E), C32(0xB58E1B9C) 418 | }; 419 | 420 | static const sph_u32 C_init_224[] = { 421 | C32(0xE4B573A1), C32(0x4C1A0880), C32(0x1E907C51), C32(0x04807EFD), 422 | C32(0x3AD8CDE5), C32(0x16B21302), C32(0x02512C53), C32(0x2204CB18), 423 | C32(0x99405F2D), C32(0xE5B648A1), C32(0x70AB1D43), C32(0xA10C25C2), 424 | C32(0x16F1AC05), C32(0x38BBEB56), C32(0x9B01DC60), C32(0xB1096D83) 425 | }; 426 | 427 | static const sph_u32 A_init_256[] = { 428 | C32(0x52F84552), C32(0xE54B7999), C32(0x2D8EE3EC), C32(0xB9645191), 429 | C32(0xE0078B86), C32(0xBB7C44C9), C32(0xD2B5C1CA), C32(0xB0D2EB8C), 430 | C32(0x14CE5A45), C32(0x22AF50DC), C32(0xEFFDBC6B), C32(0xEB21B74A) 431 | }; 432 | 433 | static const sph_u32 B_init_256[] = { 434 | C32(0xB555C6EE), C32(0x3E710596), C32(0xA72A652F), C32(0x9301515F), 435 | C32(0xDA28C1FA), C32(0x696FD868), C32(0x9CB6BF72), C32(0x0AFE4002), 436 | C32(0xA6E03615), C32(0x5138C1D4), C32(0xBE216306), C32(0xB38B8890), 437 | C32(0x3EA8B96B), C32(0x3299ACE4), C32(0x30924DD4), C32(0x55CB34A5) 438 | }; 439 | 440 | static const sph_u32 C_init_256[] = { 441 | C32(0xB405F031), C32(0xC4233EBA), C32(0xB3733979), C32(0xC0DD9D55), 442 | C32(0xC51C28AE), C32(0xA327B8E1), C32(0x56C56167), C32(0xED614433), 443 | C32(0x88B59D60), C32(0x60E2CEBA), C32(0x758B4B8B), C32(0x83E82A7F), 444 | C32(0xBC968828), C32(0xE6E00BF7), C32(0xBA839E55), C32(0x9B491C60) 445 | }; 446 | 447 | static const sph_u32 A_init_384[] = { 448 | C32(0xC8FCA331), C32(0xE55C504E), C32(0x003EBF26), C32(0xBB6B8D83), 449 | C32(0x7B0448C1), C32(0x41B82789), C32(0x0A7C9601), C32(0x8D659CFF), 450 | C32(0xB6E2673E), C32(0xCA54C77B), C32(0x1460FD7E), C32(0x3FCB8F2D) 451 | }; 452 | 453 | static const sph_u32 B_init_384[] = { 454 | C32(0x527291FC), C32(0x2A16455F), C32(0x78E627E5), C32(0x944F169F), 455 | C32(0x1CA6F016), C32(0xA854EA25), C32(0x8DB98ABE), C32(0xF2C62641), 456 | C32(0x30117DCB), C32(0xCF5C4309), C32(0x93711A25), C32(0xF9F671B8), 457 | C32(0xB01D2116), C32(0x333F4B89), C32(0xB285D165), C32(0x86829B36) 458 | }; 459 | 460 | static const sph_u32 C_init_384[] = { 461 | C32(0xF764B11A), C32(0x76172146), C32(0xCEF6934D), C32(0xC6D28399), 462 | C32(0xFE095F61), C32(0x5E6018B4), C32(0x5048ECF5), C32(0x51353261), 463 | C32(0x6E6E36DC), C32(0x63130DAD), C32(0xA9C69BD6), C32(0x1E90EA0C), 464 | C32(0x7C35073B), C32(0x28D95E6D), C32(0xAA340E0D), C32(0xCB3DEE70) 465 | }; 466 | 467 | static const sph_u32 A_init_512[] = { 468 | C32(0x20728DFD), C32(0x46C0BD53), C32(0xE782B699), C32(0x55304632), 469 | C32(0x71B4EF90), C32(0x0EA9E82C), C32(0xDBB930F1), C32(0xFAD06B8B), 470 | C32(0xBE0CAE40), C32(0x8BD14410), C32(0x76D2ADAC), C32(0x28ACAB7F) 471 | }; 472 | 473 | static const sph_u32 B_init_512[] = { 474 | C32(0xC1099CB7), C32(0x07B385F3), C32(0xE7442C26), C32(0xCC8AD640), 475 | C32(0xEB6F56C7), C32(0x1EA81AA9), C32(0x73B9D314), C32(0x1DE85D08), 476 | C32(0x48910A5A), C32(0x893B22DB), C32(0xC5A0DF44), C32(0xBBC4324E), 477 | C32(0x72D2F240), C32(0x75941D99), C32(0x6D8BDE82), C32(0xA1A7502B) 478 | }; 479 | 480 | static const sph_u32 C_init_512[] = { 481 | C32(0xD9BF68D1), C32(0x58BAD750), C32(0x56028CB2), C32(0x8134F359), 482 | C32(0xB5D469D8), C32(0x941A8CC2), C32(0x418B2A6E), C32(0x04052780), 483 | C32(0x7F07D787), C32(0x5194358F), C32(0x3C60D665), C32(0xBE97D79A), 484 | C32(0x950C3434), C32(0xAED9A06D), C32(0x2537DC8D), C32(0x7CDB5969) 485 | }; 486 | 487 | /* END -- automatically generated code. */ 488 | 489 | void shabal_init(void *cc, unsigned size) 490 | { 491 | /* 492 | * We have precomputed initial states for all the supported 493 | * output bit lengths. 494 | */ 495 | const sph_u32 *A_init, *B_init, *C_init; 496 | sph_shabal_context *sc; 497 | 498 | switch (size) { 499 | case 192: 500 | A_init = A_init_192; 501 | B_init = B_init_192; 502 | C_init = C_init_192; 503 | break; 504 | case 224: 505 | A_init = A_init_224; 506 | B_init = B_init_224; 507 | C_init = C_init_224; 508 | break; 509 | case 256: 510 | A_init = A_init_256; 511 | B_init = B_init_256; 512 | C_init = C_init_256; 513 | break; 514 | case 384: 515 | A_init = A_init_384; 516 | B_init = B_init_384; 517 | C_init = C_init_384; 518 | break; 519 | case 512: 520 | A_init = A_init_512; 521 | B_init = B_init_512; 522 | C_init = C_init_512; 523 | break; 524 | default: 525 | return; 526 | } 527 | sc = (sph_shabal_context *)cc; 528 | memcpy(sc->A, A_init, sizeof sc->A); 529 | memcpy(sc->B, B_init, sizeof sc->B); 530 | memcpy(sc->C, C_init, sizeof sc->C); 531 | sc->Wlow = 1; 532 | sc->Whigh = 0; 533 | sc->ptr = 0; 534 | } 535 | 536 | void shabal_core(void *cc, const unsigned char *data, size_t len) 537 | { 538 | sph_shabal_context *sc; 539 | unsigned char *buf; 540 | size_t ptr; 541 | DECL_STATE 542 | 543 | sc = (sph_shabal_context *)cc; 544 | buf = sc->buf; 545 | ptr = sc->ptr; 546 | 547 | /* 548 | * We do not want to copy the state to local variables if the 549 | * amount of data is less than what is needed to complete the 550 | * current block. Note that it is anyway suboptimal to call 551 | * this method many times for small chunks of data. 552 | */ 553 | if (len < (sizeof sc->buf) - ptr) { 554 | memcpy(buf + ptr, data, len); 555 | ptr += len; 556 | sc->ptr = ptr; 557 | return; 558 | } 559 | 560 | READ_STATE(sc); 561 | while (len > 0) { 562 | size_t clen; 563 | 564 | clen = (sizeof sc->buf) - ptr; 565 | if (clen > len) 566 | clen = len; 567 | memcpy(buf + ptr, data, clen); 568 | ptr += clen; 569 | data += clen; 570 | len -= clen; 571 | if (ptr == sizeof sc->buf) { 572 | DECODE_BLOCK; 573 | INPUT_BLOCK_ADD; 574 | XOR_W; 575 | APPLY_P; 576 | INPUT_BLOCK_SUB; 577 | SWAP_BC; 578 | INCR_W; 579 | ptr = 0; 580 | } 581 | } 582 | WRITE_STATE(sc); 583 | sc->ptr = ptr; 584 | } 585 | 586 | static void 587 | shabal_close(void *cc, unsigned ub, unsigned n, void *dst, unsigned size_words) 588 | { 589 | sph_shabal_context *sc; 590 | unsigned char *buf; 591 | size_t ptr; 592 | int i; 593 | unsigned z; 594 | union { 595 | unsigned char tmp_out[64]; 596 | sph_u32 dummy; 597 | } u; 598 | size_t out_len; 599 | DECL_STATE 600 | 601 | sc = (sph_shabal_context *)cc; 602 | buf = sc->buf; 603 | ptr = sc->ptr; 604 | z = 0x80 >> n; 605 | buf[ptr] = ((ub & -z) | z) & 0xFF; 606 | memset(buf + ptr + 1, 0, (sizeof sc->buf) - (ptr + 1)); 607 | READ_STATE(sc); 608 | DECODE_BLOCK; 609 | INPUT_BLOCK_ADD; 610 | XOR_W; 611 | APPLY_P; 612 | for (i = 0; i < 3; i ++) { 613 | SWAP_BC; 614 | XOR_W; 615 | APPLY_P; 616 | } 617 | 618 | /* 619 | * We just use our local variables; no need to go through 620 | * the state structure. In order to share some code, we 621 | * emit the relevant words into a temporary buffer, which 622 | * we finally copy into the destination array. 623 | */ 624 | switch (size_words) { 625 | case 16: 626 | sph_enc32le_aligned(u.tmp_out + 0, B0); 627 | sph_enc32le_aligned(u.tmp_out + 4, B1); 628 | sph_enc32le_aligned(u.tmp_out + 8, B2); 629 | sph_enc32le_aligned(u.tmp_out + 12, B3); 630 | /* fall through */ 631 | case 12: 632 | sph_enc32le_aligned(u.tmp_out + 16, B4); 633 | sph_enc32le_aligned(u.tmp_out + 20, B5); 634 | sph_enc32le_aligned(u.tmp_out + 24, B6); 635 | sph_enc32le_aligned(u.tmp_out + 28, B7); 636 | /* fall through */ 637 | case 8: 638 | sph_enc32le_aligned(u.tmp_out + 32, B8); 639 | /* fall through */ 640 | case 7: 641 | sph_enc32le_aligned(u.tmp_out + 36, B9); 642 | /* fall through */ 643 | case 6: 644 | sph_enc32le_aligned(u.tmp_out + 40, BA); 645 | sph_enc32le_aligned(u.tmp_out + 44, BB); 646 | sph_enc32le_aligned(u.tmp_out + 48, BC); 647 | sph_enc32le_aligned(u.tmp_out + 52, BD); 648 | sph_enc32le_aligned(u.tmp_out + 56, BE); 649 | sph_enc32le_aligned(u.tmp_out + 60, BF); 650 | break; 651 | default: 652 | return; 653 | } 654 | out_len = size_words << 2; 655 | memcpy(dst, u.tmp_out + (sizeof u.tmp_out) - out_len, out_len); 656 | shabal_init(sc, size_words << 5); 657 | } 658 | 659 | /* see sph_shabal.h */ 660 | void 661 | sph_shabal192_init(void *cc) 662 | { 663 | shabal_init(cc, 192); 664 | } 665 | 666 | /* see sph_shabal.h */ 667 | void 668 | sph_shabal192(void *cc, const void *data, size_t len) 669 | { 670 | shabal_core(cc, (const unsigned char *)data, len); 671 | } 672 | 673 | /* see sph_shabal.h */ 674 | void 675 | sph_shabal192_close(void *cc, void *dst) 676 | { 677 | shabal_close(cc, 0, 0, dst, 6); 678 | } 679 | 680 | /* see sph_shabal.h */ 681 | void 682 | sph_shabal192_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst) 683 | { 684 | shabal_close(cc, ub, n, dst, 6); 685 | } 686 | 687 | /* see sph_shabal.h */ 688 | void 689 | sph_shabal224_init(void *cc) 690 | { 691 | shabal_init(cc, 224); 692 | } 693 | 694 | /* see sph_shabal.h */ 695 | void 696 | sph_shabal224(void *cc, const void *data, size_t len) 697 | { 698 | shabal_core(cc, (const unsigned char *)data, len); 699 | } 700 | 701 | /* see sph_shabal.h */ 702 | void 703 | sph_shabal224_close(void *cc, void *dst) 704 | { 705 | shabal_close(cc, 0, 0, dst, 7); 706 | } 707 | 708 | /* see sph_shabal.h */ 709 | void 710 | sph_shabal224_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst) 711 | { 712 | shabal_close(cc, ub, n, dst, 7); 713 | } 714 | 715 | /* see sph_shabal.h */ 716 | void 717 | sph_shabal256_init(void *cc) 718 | { 719 | shabal_init(cc, 256); 720 | } 721 | 722 | /* see sph_shabal.h */ 723 | void 724 | sph_shabal256(void *cc, const void *data, size_t len) 725 | { 726 | shabal_core(cc, (const unsigned char *)data, len); 727 | } 728 | 729 | /* see sph_shabal.h */ 730 | void 731 | sph_shabal256_close(void *cc, void *dst) 732 | { 733 | shabal_close(cc, 0, 0, dst, 8); 734 | } 735 | 736 | /* see sph_shabal.h */ 737 | void 738 | sph_shabal256_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst) 739 | { 740 | shabal_close(cc, ub, n, dst, 8); 741 | } 742 | 743 | /* see sph_shabal.h */ 744 | void 745 | sph_shabal384_init(void *cc) 746 | { 747 | shabal_init(cc, 384); 748 | } 749 | 750 | /* see sph_shabal.h */ 751 | void 752 | sph_shabal384(void *cc, const void *data, size_t len) 753 | { 754 | shabal_core(cc, (const unsigned char *)data, len); 755 | } 756 | 757 | /* see sph_shabal.h */ 758 | void 759 | sph_shabal384_close(void *cc, void *dst) 760 | { 761 | shabal_close(cc, 0, 0, dst, 12); 762 | } 763 | 764 | /* see sph_shabal.h */ 765 | void 766 | sph_shabal384_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst) 767 | { 768 | shabal_close(cc, ub, n, dst, 12); 769 | } 770 | 771 | /* see sph_shabal.h */ 772 | void 773 | sph_shabal512_init(void *cc) 774 | { 775 | shabal_init(cc, 512); 776 | } 777 | 778 | /* see sph_shabal.h */ 779 | void 780 | sph_shabal512(void *cc, const void *data, size_t len) 781 | { 782 | shabal_core(cc, (const unsigned char *)data, len); 783 | } 784 | 785 | /* see sph_shabal.h */ 786 | void 787 | sph_shabal512_close(void *cc, void *dst) 788 | { 789 | shabal_close(cc, 0, 0, dst, 16); 790 | } 791 | 792 | /* see sph_shabal.h */ 793 | void 794 | sph_shabal512_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst) 795 | { 796 | shabal_close(cc, ub, n, dst, 16); 797 | } 798 | --------------------------------------------------------------------------------