├── .gitattributes ├── .gitignore ├── AddrGen ├── AddrGen.vcxproj ├── Makefile └── main.cpp ├── AddressUtil ├── AddressUtil.h ├── AddressUtil.vcxproj ├── Base58.cpp ├── Makefile └── hash.cpp ├── BitCrack.props ├── BitCrack.sln ├── CLKeySearchDevice ├── CLKeySearchDevice.cpp ├── CLKeySearchDevice.h ├── CLKeySearchDevice.vcxproj ├── Makefile ├── bitcrack.cl └── keysearch.cl ├── CLUnitTests ├── CLUnitTests.vcxproj ├── Makefile ├── main.cpp └── secp256k1test.cl ├── CmdParse ├── CmdParse.cpp ├── CmdParse.h ├── CmdParse.vcxproj └── Makefile ├── CryptoUtil ├── CryptoUtil.h ├── CryptoUtil.vcxproj ├── Makefile ├── Rng.cpp ├── checksum.cpp ├── hash.cpp ├── ripemd160.cpp └── sha256.cpp ├── CudaKeySearchDevice ├── CudaAtomicList.cu ├── CudaAtomicList.cuh ├── CudaAtomicList.h ├── CudaDeviceKeys.cu ├── CudaDeviceKeys.cuh ├── CudaDeviceKeys.h ├── CudaHashLookup.cu ├── CudaHashLookup.cuh ├── CudaHashLookup.h ├── CudaKeySearchDevice.cpp ├── CudaKeySearchDevice.cu ├── CudaKeySearchDevice.h ├── CudaKeySearchDevice.vcxproj ├── Makefile ├── cudabridge.cu └── cudabridge.h ├── KeyFinder ├── ConfigFile.cpp ├── ConfigFile.h ├── DeviceManager.cpp ├── DeviceManager.h ├── KeyFinder.vcxproj ├── Makefile └── main.cpp ├── KeyFinderLib ├── KeyFinder.cpp ├── KeyFinder.h ├── KeyFinderLib.vcxproj ├── KeyFinderShared.h ├── KeySearchDevice.h ├── KeySearchTypes.h └── Makefile ├── LICENSE.MIT ├── Logger ├── Logger.cpp ├── Logger.h ├── Logger.vcxproj └── Makefile ├── Makefile ├── README.md ├── clKeyFinder └── clKeyFinder.vcxproj ├── clMath ├── clMath.vcxproj ├── ripemd160.cl ├── secp256k1.cl └── sha256.cl ├── clUtil ├── Makefile ├── clContext.cpp ├── clContext.h ├── clUtil.cpp ├── clUtil.vcxproj ├── clerrors.cpp └── clutil.h ├── cudaInfo ├── Makefile ├── cudaInfo.vcxproj └── main.cpp ├── cudaMath ├── cudaMath.vcxproj ├── ptx.cuh ├── ripemd160.cuh ├── secp256k1.cuh └── sha256.cuh ├── cudaUtil ├── Makefile ├── cudaUtil.cpp ├── cudaUtil.h └── cudaUtil.vcxproj ├── embedcl ├── Makefile ├── embedcl.vcxproj └── main.cpp ├── secp256k1lib ├── Makefile ├── secp256k1.cpp ├── secp256k1.h └── secp256k1lib.vcxproj ├── tools └── embedcl.exe └── util ├── Makefile ├── util.cpp ├── util.h └── util.vcxproj /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # These files are auto-generated during building and do 7 | # not need to be checked in 8 | CLKeySearchDevice/bitcrack.cl 9 | CLKeySearchDevice/bitcrack_cl.cpp 10 | CLUnitTests/test.cpp 11 | CLUnitTests/test.cl 12 | 13 | # Linux build results 14 | *.o 15 | 16 | # CUDA build results 17 | *.cuo 18 | 19 | # User-specific files 20 | *.suo 21 | *.user 22 | *.userosscache 23 | *.sln.docstates 24 | *.vcxproj.filters 25 | 26 | # User-specific files (MonoDevelop/Xamarin Studio) 27 | *.userprefs 28 | 29 | # Build results 30 | [Dd]ebug/ 31 | [Dd]ebugPublic/ 32 | [Rr]elease/ 33 | [Rr]eleases/ 34 | x64/ 35 | x86/ 36 | bld/ 37 | [Bb]in/ 38 | [Oo]bj/ 39 | [Ll]og/ 40 | 41 | # Visual Studio 2015 cache/options directory 42 | .vs/ 43 | # Uncomment if you have tasks that create the project's static files in wwwroot 44 | #wwwroot/ 45 | 46 | # MSTest test Results 47 | [Tt]est[Rr]esult*/ 48 | [Bb]uild[Ll]og.* 49 | 50 | # NUNIT 51 | *.VisualState.xml 52 | TestResult.xml 53 | 54 | # Build Results of an ATL Project 55 | [Dd]ebugPS/ 56 | [Rr]eleasePS/ 57 | dlldata.c 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | **/Properties/launchSettings.json 64 | 65 | *_i.c 66 | *_p.c 67 | *_i.h 68 | *.ilk 69 | *.meta 70 | *.obj 71 | *.pch 72 | *.pdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *.log 83 | *.vspscc 84 | *.vssscc 85 | .builds 86 | *.pidb 87 | *.svclog 88 | *.scc 89 | 90 | # Chutzpah Test files 91 | _Chutzpah* 92 | 93 | # Visual C++ cache files 94 | ipch/ 95 | *.aps 96 | *.ncb 97 | *.opendb 98 | *.opensdf 99 | *.sdf 100 | *.cachefile 101 | *.VC.db 102 | *.VC.VC.opendb 103 | 104 | # Visual Studio profiler 105 | *.psess 106 | *.vsp 107 | *.vspx 108 | *.sap 109 | 110 | # TFS 2012 Local Workspace 111 | $tf/ 112 | 113 | # Guidance Automation Toolkit 114 | *.gpState 115 | 116 | # ReSharper is a .NET coding add-in 117 | _ReSharper*/ 118 | *.[Rr]e[Ss]harper 119 | *.DotSettings.user 120 | 121 | # JustCode is a .NET coding add-in 122 | .JustCode 123 | 124 | # TeamCity is a build add-in 125 | _TeamCity* 126 | 127 | # DotCover is a Code Coverage Tool 128 | *.dotCover 129 | 130 | # Visual Studio code coverage results 131 | *.coverage 132 | *.coveragexml 133 | 134 | # NCrunch 135 | _NCrunch_* 136 | .*crunch*.local.xml 137 | nCrunchTemp_* 138 | 139 | # MightyMoose 140 | *.mm.* 141 | AutoTest.Net/ 142 | 143 | # Web workbench (sass) 144 | .sass-cache/ 145 | 146 | # Installshield output folder 147 | [Ee]xpress/ 148 | 149 | # DocProject is a documentation generator add-in 150 | DocProject/buildhelp/ 151 | DocProject/Help/*.HxT 152 | DocProject/Help/*.HxC 153 | DocProject/Help/*.hhc 154 | DocProject/Help/*.hhk 155 | DocProject/Help/*.hhp 156 | DocProject/Help/Html2 157 | DocProject/Help/html 158 | 159 | # Click-Once directory 160 | publish/ 161 | 162 | # Publish Web Output 163 | *.[Pp]ublish.xml 164 | *.azurePubxml 165 | # TODO: Comment the next line if you want to checkin your web deploy settings 166 | # but database connection strings (with potential passwords) will be unencrypted 167 | *.pubxml 168 | *.publishproj 169 | 170 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 171 | # checkin your Azure Web App publish settings, but sensitive information contained 172 | # in these scripts will be unencrypted 173 | PublishScripts/ 174 | 175 | # NuGet Packages 176 | *.nupkg 177 | # The packages folder can be ignored because of Package Restore 178 | **/packages/* 179 | # except build/, which is used as an MSBuild target. 180 | !**/packages/build/ 181 | # Uncomment if necessary however generally it will be regenerated when needed 182 | #!**/packages/repositories.config 183 | # NuGet v3's project.json files produces more ignoreable files 184 | *.nuget.props 185 | *.nuget.targets 186 | 187 | # Microsoft Azure Build Output 188 | csx/ 189 | *.build.csdef 190 | 191 | # Microsoft Azure Emulator 192 | ecf/ 193 | rcf/ 194 | 195 | # Windows Store app package directories and files 196 | AppPackages/ 197 | BundleArtifacts/ 198 | Package.StoreAssociation.xml 199 | _pkginfo.txt 200 | 201 | # Visual Studio cache files 202 | # files ending in .cache can be ignored 203 | *.[Cc]ache 204 | # but keep track of directories ending in .cache 205 | !*.[Cc]ache/ 206 | 207 | # Others 208 | ClientBin/ 209 | ~$* 210 | *~ 211 | *.dbmdl 212 | *.dbproj.schemaview 213 | *.jfm 214 | *.pfx 215 | *.publishsettings 216 | node_modules/ 217 | orleans.codegen.cs 218 | 219 | # Since there are multiple workflows, uncomment next line to ignore bower_components 220 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 221 | #bower_components/ 222 | 223 | # RIA/Silverlight projects 224 | Generated_Code/ 225 | 226 | # Backup & report files from converting an old project file 227 | # to a newer Visual Studio version. Backup files are not needed, 228 | # because we have git ;-) 229 | _UpgradeReport_Files/ 230 | Backup*/ 231 | UpgradeLog*.XML 232 | UpgradeLog*.htm 233 | 234 | # SQL Server files 235 | *.mdf 236 | *.ldf 237 | 238 | # Business Intelligence projects 239 | *.rdl.data 240 | *.bim.layout 241 | *.bim_*.settings 242 | 243 | # Microsoft Fakes 244 | FakesAssemblies/ 245 | 246 | # GhostDoc plugin setting file 247 | *.GhostDoc.xml 248 | 249 | # Node.js Tools for Visual Studio 250 | .ntvs_analysis.dat 251 | 252 | # Visual Studio 6 build log 253 | *.plg 254 | 255 | # Visual Studio 6 workspace options file 256 | *.opt 257 | 258 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 259 | *.vbw 260 | 261 | # Visual Studio LightSwitch build output 262 | **/*.HTMLClient/GeneratedArtifacts 263 | **/*.DesktopClient/GeneratedArtifacts 264 | **/*.DesktopClient/ModelManifest.xml 265 | **/*.Server/GeneratedArtifacts 266 | **/*.Server/ModelManifest.xml 267 | _Pvt_Extensions 268 | 269 | # Paket dependency manager 270 | .paket/paket.exe 271 | paket-files/ 272 | 273 | # FAKE - F# Make 274 | .fake/ 275 | 276 | # JetBrains Rider 277 | .idea/ 278 | *.sln.iml 279 | 280 | # CodeRush 281 | .cr/ 282 | 283 | # Python Tools for Visual Studio (PTVS) 284 | __pycache__/ 285 | *.pyc 286 | 287 | # Cake - Uncomment if you are using it 288 | # tools/ 289 | 290 | TestData/ 291 | -------------------------------------------------------------------------------- /AddrGen/Makefile: -------------------------------------------------------------------------------- 1 | CPPSRC:=$(wildcard *.cpp) 2 | 3 | all: 4 | ${CXX} -o addrgen.bin ${CPPSRC} ${INCLUDE} -I${CUDA_INCLUDE} ${CXXFLAGS} ${LIBS} -laddressutil -lsecp256k1 -lcryptoutil -lsecp256k1 -lutil -lcmdparse 5 | mkdir -p $(BINDIR) 6 | cp addrgen.bin $(BINDIR)/addrgen 7 | 8 | 9 | clean: 10 | rm -rf addrgen.bin 11 | -------------------------------------------------------------------------------- /AddrGen/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "secp256k1.h" 4 | #include "util.h" 5 | #include "AddressUtil.h" 6 | #include "CmdParse.h" 7 | 8 | int main(int argc, char **argv) 9 | { 10 | std::vector keys; 11 | 12 | bool compressed = true; 13 | bool printPrivate = false; 14 | bool printPublic = false; 15 | bool printAddr = false; 16 | bool printAll = true; 17 | int count = 1; 18 | 19 | secp256k1::uint256 k; 20 | 21 | k = secp256k1::generatePrivateKey(); 22 | 23 | CmdParse parser; 24 | 25 | parser.add("-c", "--compressed", false); 26 | parser.add("-u", "--uncompressed", false); 27 | parser.add("-p", "--pub", false); 28 | parser.add("-k", "--priv", false); 29 | parser.add("-a", "--addr", false); 30 | parser.add("-n", true); 31 | 32 | parser.parse(argc, argv); 33 | 34 | std::vector args = parser.getArgs(); 35 | 36 | for(unsigned int i = 0; i < args.size(); i++) { 37 | OptArg arg = args[i]; 38 | 39 | if(arg.equals("-c", "--compressed")) { 40 | compressed = true; 41 | } else if(arg.equals("-u", "--uncompressed")) { 42 | compressed = false; 43 | } else if(arg.equals("-k", "--priv")) { 44 | printAll = false; 45 | printPrivate = true; 46 | } else if(arg.equals("-p", "--pub")) { 47 | printAll = false; 48 | printPublic = true; 49 | } else if(arg.equals("-a", "--addr")) { 50 | printAll = false; 51 | printAddr = true; 52 | } else if(arg.equals("-n")) { 53 | count = (int)util::parseUInt32(arg.arg); 54 | } 55 | } 56 | 57 | std::vector operands = parser.getOperands(); 58 | 59 | if(operands.size() > 0) { 60 | for(int i = 0; i < operands.size(); i++) { 61 | try { 62 | keys.push_back(secp256k1::uint256(operands[i])); 63 | } catch(std::string err) { 64 | printf("Error parsing private key: %s\n", err.c_str()); 65 | return 1; 66 | } 67 | } 68 | } else { 69 | for(int i = 0; i < count; i++) { 70 | keys.push_back(secp256k1::generatePrivateKey()); 71 | } 72 | } 73 | 74 | for(int i = 0; i < keys.size(); i++) { 75 | secp256k1::uint256 k = keys[i]; 76 | 77 | if(k.isZero() || k.cmp(secp256k1::N) >= 0) 78 | { 79 | printf("Error parsing private key: Private key is out of range\n"); 80 | 81 | return 1; 82 | } 83 | 84 | secp256k1::ecpoint p = secp256k1::multiplyPoint(k, secp256k1::G()); 85 | std::string address = Address::fromPublicKey(p, compressed); 86 | 87 | if(printAll || printPrivate) { 88 | std::cout << k.toString() << std::endl; 89 | } 90 | if(printAll || printPublic) { 91 | std::cout << p.toString() << std::endl; 92 | } 93 | if(printAll || printAddr) { 94 | std::cout << address << std::endl; 95 | } 96 | } 97 | 98 | return 0; 99 | } -------------------------------------------------------------------------------- /AddressUtil/AddressUtil.h: -------------------------------------------------------------------------------- 1 | #ifndef _ADDRESS_UTIL_H 2 | #define _ADDRESS_UTIL_H 3 | 4 | #include "secp256k1.h" 5 | 6 | namespace Address { 7 | std::string fromPublicKey(const secp256k1::ecpoint &p, bool compressed = false); 8 | bool verifyAddress(std::string address); 9 | }; 10 | 11 | namespace Base58 { 12 | std::string toBase58(const secp256k1::uint256 &x); 13 | secp256k1::uint256 toBigInt(const std::string &s); 14 | void getMinMaxFromPrefix(const std::string &prefix, secp256k1::uint256 &minValueOut, secp256k1::uint256 &maxValueOut); 15 | 16 | void toHash160(const std::string &s, unsigned int hash[5]); 17 | 18 | bool isBase58(std::string s); 19 | }; 20 | 21 | 22 | 23 | namespace Hash { 24 | 25 | 26 | void hashPublicKey(const secp256k1::ecpoint &p, unsigned int *digest); 27 | void hashPublicKeyCompressed(const secp256k1::ecpoint &p, unsigned int *digest); 28 | 29 | void hashPublicKey(const unsigned int *x, const unsigned int *y, unsigned int *digest); 30 | void hashPublicKeyCompressed(const unsigned int *x, const unsigned int *y, unsigned int *digest); 31 | 32 | }; 33 | 34 | 35 | #endif -------------------------------------------------------------------------------- /AddressUtil/AddressUtil.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {ca46856a-1d1e-4f6f-a69c-6707d540bf36} 31 | 32 | 33 | {bff4b5fe-c2c5-4384-8941-cd6cb29e78c6} 34 | 35 | 36 | 37 | {34042455-D274-432D-9134-C9EA41FD1B54} 38 | Win32Proj 39 | AddressUtil 40 | 10.0 41 | 42 | 43 | 44 | StaticLibrary 45 | true 46 | v141 47 | Unicode 48 | 49 | 50 | StaticLibrary 51 | false 52 | v141 53 | true 54 | Unicode 55 | 56 | 57 | StaticLibrary 58 | true 59 | v142 60 | Unicode 61 | 62 | 63 | StaticLibrary 64 | false 65 | v142 66 | true 67 | Unicode 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | Level3 97 | Disabled 98 | _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 99 | $(SolutionDir)secp256k1lib;$(SolutionDir)CryptoUtil;%(AdditionalIncludeDirectories) 100 | 101 | 102 | Windows 103 | 104 | 105 | 106 | 107 | NotUsing 108 | Level3 109 | Disabled 110 | _CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) 111 | $(SolutionDir)secp256k1lib;$(SolutionDir)CryptoUtil;%(AdditionalIncludeDirectories) 112 | 113 | 114 | Windows 115 | 116 | 117 | 118 | 119 | Level3 120 | 121 | 122 | MaxSpeed 123 | true 124 | true 125 | _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 126 | $(SolutionDir)secp256k1lib;$(SolutionDir)CryptoUtil;%(AdditionalIncludeDirectories) 127 | 128 | 129 | Windows 130 | true 131 | true 132 | 133 | 134 | 135 | 136 | Level3 137 | NotUsing 138 | MaxSpeed 139 | true 140 | true 141 | _CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;%(PreprocessorDefinitions) 142 | $(SolutionDir)secp256k1lib;$(SolutionDir)CryptoUtil;%(AdditionalIncludeDirectories) 143 | 144 | 145 | Windows 146 | true 147 | true 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /AddressUtil/Base58.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CryptoUtil.h" 3 | 4 | #include "AddressUtil.h" 5 | 6 | 7 | static const std::string BASE58_STRING = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; 8 | 9 | struct Base58Map { 10 | static std::map createBase58Map() 11 | { 12 | std::map m; 13 | for(int i = 0; i < 58; i++) { 14 | m[BASE58_STRING[i]] = i; 15 | } 16 | 17 | return m; 18 | } 19 | 20 | static std::map myMap; 21 | }; 22 | 23 | std::map Base58Map::myMap = Base58Map::createBase58Map(); 24 | 25 | 26 | 27 | /** 28 | * Converts a base58 string to uint256 29 | */ 30 | secp256k1::uint256 Base58::toBigInt(const std::string &s) 31 | { 32 | secp256k1::uint256 value; 33 | 34 | for(unsigned int i = 0; i < s.length(); i++) { 35 | value = value.mul(58); 36 | 37 | int c = Base58Map::myMap[s[i]]; 38 | value = value.add(c); 39 | } 40 | 41 | return value; 42 | } 43 | 44 | void Base58::toHash160(const std::string &s, unsigned int hash[5]) 45 | { 46 | secp256k1::uint256 value = toBigInt(s); 47 | unsigned int words[6]; 48 | 49 | value.exportWords(words, 6, secp256k1::uint256::BigEndian); 50 | 51 | // Extract words, ignore checksum 52 | for(int i = 0; i < 5; i++) { 53 | hash[i] = words[i]; 54 | } 55 | } 56 | 57 | bool Base58::isBase58(std::string s) 58 | { 59 | for(unsigned int i = 0; i < s.length(); i++) { 60 | if(BASE58_STRING.find(s[i]) < 0) { 61 | return false; 62 | } 63 | } 64 | 65 | return true; 66 | } 67 | 68 | std::string Base58::toBase58(const secp256k1::uint256 &x) 69 | { 70 | std::string s; 71 | 72 | secp256k1::uint256 value = x; 73 | 74 | while(!value.isZero()) { 75 | secp256k1::uint256 digit = value.mod(58); 76 | int digitInt = digit.toInt32(); 77 | 78 | s = BASE58_STRING[digitInt] + s; 79 | 80 | value = value.div(58); 81 | } 82 | 83 | return s; 84 | } 85 | 86 | void Base58::getMinMaxFromPrefix(const std::string &prefix, secp256k1::uint256 &minValueOut, secp256k1::uint256 &maxValueOut) 87 | { 88 | secp256k1::uint256 minValue = toBigInt(prefix); 89 | secp256k1::uint256 maxValue = minValue; 90 | int exponent = 1; 91 | 92 | // 2^192 93 | unsigned int expWords[] = { 0, 0, 0, 0, 0, 0, 1, 0 }; 94 | 95 | secp256k1::uint256 exp(expWords); 96 | 97 | // Find the smallest 192-bit number that starts with the prefix. That is, the prefix multiplied 98 | // by some power of 58 99 | secp256k1::uint256 nextValue = minValue.mul(58); 100 | 101 | while(nextValue.cmp(exp) < 0) { 102 | exponent++; 103 | minValue = nextValue; 104 | nextValue = nextValue.mul(58); 105 | } 106 | 107 | secp256k1::uint256 diff = secp256k1::uint256(58).pow(exponent - 1).sub(1); 108 | 109 | maxValue = minValue.add(diff); 110 | 111 | if(maxValue.cmp(exp) > 0) { 112 | maxValue = exp.sub(1); 113 | } 114 | 115 | minValueOut = minValue; 116 | maxValueOut = maxValue; 117 | } -------------------------------------------------------------------------------- /AddressUtil/Makefile: -------------------------------------------------------------------------------- 1 | NAME=addressutil 2 | SRC=$(wildcard *.cpp) 3 | 4 | all: ${SRC} 5 | for file in ${SRC} ; do\ 6 | ${CXX} -c $$file ${INCLUDE} ${CXXFLAGS};\ 7 | done 8 | mkdir -p ${LIBDIR} 9 | ar rvs ${LIBDIR}/lib$(NAME).a *.o 10 | 11 | clean: 12 | rm -rf *.o 13 | -------------------------------------------------------------------------------- /AddressUtil/hash.cpp: -------------------------------------------------------------------------------- 1 | #include "AddressUtil.h" 2 | #include "CryptoUtil.h" 3 | 4 | #include 5 | #include 6 | 7 | static unsigned int endian(unsigned int x) 8 | { 9 | return (x << 24) | ((x << 8) & 0x00ff0000) | ((x >> 8) & 0x0000ff00) | (x >> 24); 10 | } 11 | 12 | bool Address::verifyAddress(std::string address) 13 | { 14 | // Check length 15 | if(address.length() > 34) { 16 | false; 17 | } 18 | 19 | // Check encoding 20 | if(!Base58::isBase58(address)) { 21 | return false; 22 | } 23 | 24 | std::string noPrefix = address.substr(1); 25 | 26 | secp256k1::uint256 value = Base58::toBigInt(noPrefix); 27 | unsigned int words[6]; 28 | unsigned int hash[5]; 29 | unsigned int checksum; 30 | 31 | value.exportWords(words, 6, secp256k1::uint256::BigEndian); 32 | memcpy(hash, words, sizeof(unsigned int) * 5); 33 | checksum = words[5]; 34 | 35 | return crypto::checksum(hash) == checksum; 36 | } 37 | 38 | std::string Address::fromPublicKey(const secp256k1::ecpoint &p, bool compressed) 39 | { 40 | unsigned int xWords[8] = { 0 }; 41 | unsigned int yWords[8] = { 0 }; 42 | 43 | p.x.exportWords(xWords, 8, secp256k1::uint256::BigEndian); 44 | p.y.exportWords(yWords, 8, secp256k1::uint256::BigEndian); 45 | 46 | unsigned int digest[5]; 47 | 48 | if(compressed) { 49 | Hash::hashPublicKeyCompressed(xWords, yWords, digest); 50 | } else { 51 | Hash::hashPublicKey(xWords, yWords, digest); 52 | } 53 | 54 | unsigned int checksum = crypto::checksum(digest); 55 | 56 | unsigned int addressWords[8] = { 0 }; 57 | for(int i = 0; i < 5; i++) { 58 | addressWords[2 + i] = digest[i]; 59 | } 60 | addressWords[7] = checksum; 61 | 62 | secp256k1::uint256 addressBigInt(addressWords, secp256k1::uint256::BigEndian); 63 | 64 | return "1" + Base58::toBase58(addressBigInt); 65 | } 66 | 67 | void Hash::hashPublicKey(const secp256k1::ecpoint &p, unsigned int *digest) 68 | { 69 | unsigned int xWords[8]; 70 | unsigned int yWords[8]; 71 | 72 | p.x.exportWords(xWords, 8, secp256k1::uint256::BigEndian); 73 | p.y.exportWords(yWords, 8, secp256k1::uint256::BigEndian); 74 | 75 | hashPublicKey(xWords, yWords, digest); 76 | } 77 | 78 | 79 | void Hash::hashPublicKeyCompressed(const secp256k1::ecpoint &p, unsigned int *digest) 80 | { 81 | unsigned int xWords[8]; 82 | unsigned int yWords[8]; 83 | 84 | p.x.exportWords(xWords, 8, secp256k1::uint256::BigEndian); 85 | p.y.exportWords(yWords, 8, secp256k1::uint256::BigEndian); 86 | 87 | hashPublicKeyCompressed(xWords, yWords, digest); 88 | } 89 | 90 | void Hash::hashPublicKey(const unsigned int *x, const unsigned int *y, unsigned int *digest) 91 | { 92 | unsigned int msg[16]; 93 | unsigned int sha256Digest[8]; 94 | 95 | // 0x04 || x || y 96 | msg[15] = (y[7] >> 8) | (y[6] << 24); 97 | msg[14] = (y[6] >> 8) | (y[5] << 24); 98 | msg[13] = (y[5] >> 8) | (y[4] << 24); 99 | msg[12] = (y[4] >> 8) | (y[3] << 24); 100 | msg[11] = (y[3] >> 8) | (y[2] << 24); 101 | msg[10] = (y[2] >> 8) | (y[1] << 24); 102 | msg[9] = (y[1] >> 8) | (y[0] << 24); 103 | msg[8] = (y[0] >> 8) | (x[7] << 24); 104 | msg[7] = (x[7] >> 8) | (x[6] << 24); 105 | msg[6] = (x[6] >> 8) | (x[5] << 24); 106 | msg[5] = (x[5] >> 8) | (x[4] << 24); 107 | msg[4] = (x[4] >> 8) | (x[3] << 24); 108 | msg[3] = (x[3] >> 8) | (x[2] << 24); 109 | msg[2] = (x[2] >> 8) | (x[1] << 24); 110 | msg[1] = (x[1] >> 8) | (x[0] << 24); 111 | msg[0] = (x[0] >> 8) | 0x04000000; 112 | 113 | 114 | crypto::sha256Init(sha256Digest); 115 | crypto::sha256(msg, sha256Digest); 116 | 117 | // Zero out the message 118 | for(int i = 0; i < 16; i++) { 119 | msg[i] = 0; 120 | } 121 | 122 | // Set first byte, padding, and length 123 | msg[0] = (y[7] << 24) | 0x00800000; 124 | msg[15] = 65 * 8; 125 | 126 | crypto::sha256(msg, sha256Digest); 127 | 128 | for(int i = 0; i < 16; i++) { 129 | msg[i] = 0; 130 | } 131 | 132 | // Swap to little-endian 133 | for(int i = 0; i < 8; i++) { 134 | msg[i] = endian(sha256Digest[i]); 135 | } 136 | 137 | // Message length, little endian 138 | msg[8] = 0x00000080; 139 | msg[14] = 256; 140 | msg[15] = 0; 141 | 142 | crypto::ripemd160(msg, digest); 143 | } 144 | 145 | 146 | 147 | void Hash::hashPublicKeyCompressed(const unsigned int *x, const unsigned int *y, unsigned int *digest) 148 | { 149 | unsigned int msg[16] = { 0 }; 150 | unsigned int sha256Digest[8]; 151 | 152 | // Compressed public key format 153 | msg[15] = 33 * 8; 154 | 155 | msg[8] = (x[7] << 24) | 0x00800000; 156 | msg[7] = (x[7] >> 8) | (x[6] << 24); 157 | msg[6] = (x[6] >> 8) | (x[5] << 24); 158 | msg[5] = (x[5] >> 8) | (x[4] << 24); 159 | msg[4] = (x[4] >> 8) | (x[3] << 24); 160 | msg[3] = (x[3] >> 8) | (x[2] << 24); 161 | msg[2] = (x[2] >> 8) | (x[1] << 24); 162 | msg[1] = (x[1] >> 8) | (x[0] << 24); 163 | 164 | if(y[7] & 0x01) { 165 | msg[0] = (x[0] >> 8) | 0x03000000; 166 | } else { 167 | msg[0] = (x[0] >> 8) | 0x02000000; 168 | } 169 | 170 | crypto::sha256Init(sha256Digest); 171 | crypto::sha256(msg, sha256Digest); 172 | 173 | for(int i = 0; i < 16; i++) { 174 | msg[i] = 0; 175 | } 176 | 177 | // Swap to little-endian 178 | for(int i = 0; i < 8; i++) { 179 | msg[i] = endian(sha256Digest[i]); 180 | } 181 | 182 | // Message length, little endian 183 | msg[8] = 0x00000080; 184 | msg[14] = 256; 185 | msg[15] = 0; 186 | 187 | crypto::ripemd160(msg, digest); 188 | } -------------------------------------------------------------------------------- /BitCrack.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include 6 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64 7 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include 8 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64 9 | 10 | 11 | 12 | 13 | 14 | $(OPENCL_INCLUDE) 15 | true 16 | 17 | 18 | $(OPENCL_LIB) 19 | true 20 | 21 | 22 | $(CUDA_INCLUDE) 23 | true 24 | 25 | 26 | $(CUDA_LIB) 27 | true 28 | 29 | 30 | -------------------------------------------------------------------------------- /CLKeySearchDevice/CLKeySearchDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef _CL_KEYSEARCH_DEVICE_H 2 | #define _CL_KEYSEARCH_DEVICE_H 3 | 4 | #include "KeySearchDevice.h" 5 | #include "clContext.h" 6 | 7 | typedef struct CLTargetList_ 8 | { 9 | cl_ulong mask = 0; 10 | cl_ulong size = 0; 11 | cl_mem ptr = 0; 12 | }CLTargetList; 13 | 14 | class CLKeySearchDevice : public KeySearchDevice { 15 | 16 | private: 17 | cl::CLContext *_clContext = NULL; 18 | cl::CLProgram *_clProgram = NULL; 19 | cl::CLKernel *_initKeysKernel = NULL; 20 | cl::CLKernel *_stepKernel = NULL; 21 | cl::CLKernel *_stepKernelWithDouble = NULL; 22 | 23 | uint64_t _globalMemSize = 0; 24 | uint64_t _pointsMemSize = 0; 25 | uint64_t _targetMemSize = 0; 26 | 27 | CLTargetList _deviceTargetList; 28 | 29 | secp256k1::uint256 _start; 30 | 31 | std::vector _targetList; 32 | 33 | std::vector _results; 34 | 35 | int _blocks; 36 | 37 | int _threads; 38 | 39 | int _points; 40 | 41 | cl_device_id _device; 42 | 43 | int _compression = PointCompressionType::COMPRESSED; 44 | 45 | uint64_t _iterations = 0; 46 | 47 | secp256k1::uint256 _stride = 1; 48 | 49 | std::string _deviceName; 50 | 51 | // Device memory pointers 52 | cl_mem _chain = NULL; 53 | 54 | cl_mem _x = NULL; 55 | 56 | cl_mem _y = NULL; 57 | 58 | cl_mem _xInc = NULL; 59 | 60 | cl_mem _yInc = NULL; 61 | 62 | cl_mem _privateKeys = NULL; 63 | 64 | cl_mem _xTable = NULL; 65 | 66 | cl_mem _yTable = NULL; 67 | 68 | cl_mem _deviceResults = NULL; 69 | 70 | cl_mem _deviceResultsCount = NULL; 71 | 72 | cl_mem _targets = NULL; 73 | 74 | void generateStartingPoints(); 75 | 76 | void setIncrementor(secp256k1::ecpoint &p); 77 | 78 | void splatBigInt(secp256k1::uint256 &k, unsigned int *ptr); 79 | 80 | void allocateBuffers(); 81 | 82 | void initializeBasePoints(); 83 | 84 | int getIndex(int block, int thread, int idx); 85 | 86 | void splatBigInt(unsigned int *dest, int block, int thread, int idx, const secp256k1::uint256 &i); 87 | void splatBigInt(unsigned int *dest, int idx, secp256k1::uint256 &k); 88 | secp256k1::uint256 readBigInt(unsigned int *src, int idx); 89 | 90 | void selfTest(); 91 | 92 | bool _useBloomFilter = false; 93 | 94 | void setTargetsInternal(); 95 | void setTargetsList(); 96 | void setBloomFilter(); 97 | 98 | void getResultsInternal(); 99 | 100 | bool isTargetInList(const unsigned int hash[5]); 101 | 102 | void removeTargetFromList(const unsigned int hash[5]); 103 | 104 | uint32_t getPrivateKeyOffset(int thread, int block, int idx); 105 | 106 | void initializeBloomFilter(const std::vector &targets, uint64_t mask); 107 | 108 | uint64_t getOptimalBloomFilterMask(double p, size_t n); 109 | 110 | public: 111 | 112 | CLKeySearchDevice(uint64_t device, int threads, int pointsPerThread, int blocks = 0); 113 | ~CLKeySearchDevice(); 114 | 115 | 116 | // Initialize the device 117 | virtual void init(const secp256k1::uint256 &start, int compression, const secp256k1::uint256 &stride); 118 | 119 | // Perform one iteration 120 | virtual void doStep(); 121 | 122 | // Tell the device which addresses to search for 123 | virtual void setTargets(const std::set &targets); 124 | 125 | // Get the private keys that have been found so far 126 | virtual size_t getResults(std::vector &results); 127 | 128 | // The number of keys searched at each step 129 | virtual uint64_t keysPerStep(); 130 | 131 | // The name of the device 132 | virtual std::string getDeviceName(); 133 | 134 | // Memory information for this device 135 | virtual void getMemoryInfo(uint64_t &freeMem, uint64_t &totalMem); 136 | 137 | virtual secp256k1::uint256 getNextKey(); 138 | }; 139 | 140 | #endif 141 | 142 | -------------------------------------------------------------------------------- /CLKeySearchDevice/Makefile: -------------------------------------------------------------------------------- 1 | NAME=CLKeySearchDevice 2 | CPPSRC:=$(wildcard *.cpp) 3 | 4 | all: 5 | cat ../clMath/sha256.cl ../clMath/secp256k1.cl ../clMath/ripemd160.cl keysearch.cl > bitcrack.cl 6 | ${BINDIR}/embedcl bitcrack.cl bitcrack_cl.cpp _bitcrack_cl 7 | 8 | for file in ${CPPSRC} bitcrack_cl.cpp; do\ 9 | ${CXX} -c $$file ${INCLUDE} -I${OPENCL_INCLUDE} ${CXXFLAGS};\ 10 | done 11 | 12 | ar rvs ${LIBDIR}/lib$(NAME).a *.o 13 | 14 | clean: 15 | rm -rf *.a *.o bitcrack.cl bitcrack_cl.cpp 16 | -------------------------------------------------------------------------------- /CLUnitTests/CLUnitTests.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {146C79F4-2CA1-43B8-A8FE-C86C4E9F6C63} 24 | CLUnitTests 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v141 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v141 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v142 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | Level3 78 | MaxSpeed 79 | true 80 | true 81 | true 82 | true 83 | $(SolutionDir)clUtil;$(OPENCL_INCLUDE);%(AdditionalIncludeDirectories) 84 | 85 | 86 | true 87 | true 88 | OpenCL.lib;%(AdditionalDependencies) 89 | $(OPENCL_LIB);%(AdditionalLibraryDirectories) 90 | 91 | 92 | type $(SolutionDir)clMath\secp256k1.cl secp256k1test.cl > test.cl 93 | $(SolutionDir)\tools\embedcl.exe test.cl test.cpp _secp256k1_test_cl 94 | 95 | 96 | 97 | 98 | Level3 99 | Disabled 100 | true 101 | true 102 | 103 | 104 | OpenCL.lib;%(AdditionalDependencies) 105 | $(OPENCL_LIB);%(AdditionalLibraryDirectories) 106 | 107 | 108 | 109 | 110 | Level3 111 | Disabled 112 | true 113 | true 114 | $(SolutionDir)clUtil;$(OPENCL_INCLUDE);%(AdditionalIncludeDirectories) 115 | 116 | 117 | type $(SolutionDir)clMath\secp256k1.cl secp256k1test.cl > test.cl 118 | $(SolutionDir)\tools\embedcl.exe test.cl test.cpp _secp256k1_test_cl 119 | 120 | 121 | OpenCL.lib;%(AdditionalDependencies) 122 | $(OPENCL_LIB);%(AdditionalLibraryDirectories) 123 | 124 | 125 | 126 | 127 | Level3 128 | MaxSpeed 129 | true 130 | true 131 | true 132 | true 133 | 134 | 135 | true 136 | true 137 | OpenCL.lib;%(AdditionalDependencies) 138 | $(OPENCL_LIB);%(AdditionalLibraryDirectories) 139 | 140 | 141 | 142 | 143 | Document 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | {d9a5823d-c472-40ac-b23a-21b1586ceeb0} 153 | 154 | 155 | {93b89bf6-32b9-4eba-aa44-bcfec4836b76} 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /CLUnitTests/Makefile: -------------------------------------------------------------------------------- 1 | NAME=CLUnitTests 2 | CPPSRC:=$(wildcard *.cpp) 3 | 4 | all: 5 | cat ../clMath/secp256k1.cl secp256k1test.cl > cltest.cl 6 | ${BINDIR}/embedcl cltest.cl cltest.cpp _secp256k1_test_cl 7 | 8 | ${CXX} -o clunittest.bin ${CPPSRC} ${INCLUDE} -I${OPENCL_INCLUDE} ${CXXFLAGS} ${LIBS} -L${OPENCL_LIB} -lclutil -lutil -lOpenCL 9 | mkdir -p $(BINDIR) 10 | 11 | cp clunittest.bin $(BINDIR)/clunittest 12 | 13 | 14 | 15 | clean: 16 | rm -rf *.a *.o clunittest.bin cltest.cl cltest.cpp 17 | -------------------------------------------------------------------------------- /CLUnitTests/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "clutil.h" 5 | #include "clContext.h" 6 | 7 | #define SECTION_ADD 0 8 | #define SECTION_MULTIPLY 1 9 | #define SECTION_INVERSE 2 10 | 11 | std::string _sections[] = { 12 | "Addition", 13 | "Multiplication", 14 | "Inverse" }; 15 | 16 | typedef struct { 17 | int section; 18 | }CLErrorInfo; 19 | 20 | extern char _secp256k1_test_cl[]; 21 | 22 | int runTest(cl_device_id deviceId) 23 | { 24 | bool pass = true; 25 | 26 | cl::CLContext ctx(deviceId); 27 | cl::CLProgram prog(ctx, _secp256k1_test_cl); 28 | cl::CLKernel k(prog, "secp256k1_test"); 29 | 30 | cl_mem devNumErrors = ctx.malloc(sizeof(unsigned int)); 31 | cl_mem devErrors = ctx.malloc(sizeof(CLErrorInfo) * 1000); 32 | 33 | std::cout << "Running test kernel..." << std::endl; 34 | 35 | k.set_args(devErrors, devNumErrors); 36 | k.call(1, 1); 37 | 38 | unsigned int numErrors = 0; 39 | std::vector errors; 40 | 41 | ctx.copyDeviceToHost(devNumErrors, &numErrors, sizeof(unsigned int)); 42 | 43 | std::cout << numErrors << " errors" << std::endl; 44 | 45 | if(numErrors > 0) { 46 | errors.resize(numErrors); 47 | 48 | ctx.copyDeviceToHost(devErrors, errors.data(), sizeof(CLErrorInfo) * numErrors); 49 | 50 | for(int i = 0; i < numErrors; i++) { 51 | std::cout << _sections[errors[i].section] << " test failed" << std::endl; 52 | } 53 | 54 | pass = false; 55 | } 56 | 57 | ctx.free(devNumErrors); 58 | ctx.free(devErrors); 59 | 60 | return numErrors; 61 | } 62 | 63 | int main(int argc, char **argv) 64 | { 65 | std::vector devices; 66 | 67 | try { 68 | devices = cl::getDevices(); 69 | }catch(cl::CLException ex) { 70 | std::cout << "Error: " << ex.msg << std::endl; 71 | return 1; 72 | } 73 | 74 | std::cout << "Found " << devices.size() << " devices" << std::endl; 75 | 76 | if(devices.size() == 0) { 77 | std::cout << "No OpenCL devices found" << std::endl; 78 | return 0; 79 | } 80 | 81 | int numErrors = 0; 82 | 83 | for(int i = 0; i < devices.size(); i++) { 84 | try { 85 | std::cout << "Testing device " << devices[i].name << std::endl; 86 | numErrors += runTest(devices[i].id); 87 | } 88 | catch(cl::CLException ex) { 89 | std::cout << "Error " << ex.msg << std::endl; 90 | } 91 | } 92 | 93 | std::cout << std::endl; 94 | 95 | if(!numErrors) { 96 | std::cout << "PASS" << std::endl; 97 | } 98 | else { 99 | std::cout << "FAIL" << std::endl; 100 | } 101 | 102 | return 0; 103 | } -------------------------------------------------------------------------------- /CLUnitTests/secp256k1test.cl: -------------------------------------------------------------------------------- 1 | 2 | #define SECTION_ADD 0 3 | #define SECTION_MULTIPLY 1 4 | #define SECTION_INVERSE 2 5 | 6 | typedef struct { 7 | int section; 8 | }CLErrorInfo; 9 | 10 | 11 | bool addTest() 12 | { 13 | unsigned int x[8] = { 0xa4aea9b8, 0x6fe248f5, 0x1fc74965, 0xe9493264, 0x4e2dff0c, 0x009f7c9c, 0x832fa59b, 0x3361f837 }; 14 | unsigned int y[8] = { 0x537c13eb, 0xec1bf1f8, 0x7c25b4cf, 0xa57084ac, 0x245a823e, 0x624d20ee, 0x066cffaf, 0x4a0538f3 }; 15 | unsigned int z[8] = { 0xf82abda4, 0x5bfe3aed, 0x9becfe35, 0x8eb9b710, 0x7288814a, 0x62ec9d8a, 0x899ca54a, 0x7d67312a }; 16 | unsigned int k[8]; 17 | 18 | addModP(x, y, k); 19 | 20 | return equal(z, k); 21 | } 22 | 23 | bool multiplyTest() 24 | { 25 | unsigned int x[8] = { 0xa4aea9b8, 0x6fe248f5, 0x1fc74965, 0xe9493264, 0x4e2dff0c, 0x009f7c9c, 0x832fa59b, 0x3361f837 }; 26 | unsigned int y[8] = { 0x537c13eb, 0xec1bf1f8, 0x7c25b4cf, 0xa57084ac, 0x245a823e, 0x624d20ee, 0x066cffaf, 0x4a0538f3 }; 27 | unsigned int z[8] = { 0x4e0ce587, 0x119dd71e, 0x797c3d8c, 0x218d8631, 0x2535962b, 0xd61c1d6d, 0x01f40664, 0x3367edcb }; 28 | unsigned int k[8]; 29 | 30 | mulModP(x, y, k); 31 | 32 | return equal(z, k); 33 | } 34 | 35 | bool inverseTest() 36 | { 37 | unsigned int x[8] = { 0xa4aea9b8, 0x6fe248f5, 0x1fc74965, 0xe9493264, 0x4e2dff0c, 0x009f7c9c, 0x832fa59b, 0x3361f837 }; 38 | unsigned int k[8]; 39 | unsigned int z[8] = { 0x22a595b4, 0x5a57167e, 0x1b9426be, 0x2c9b13e1, 0x8ca6f21c, 0x1765b9a9, 0xb378bbb3, 0x9a7f38e5 }; 40 | 41 | for(int i = 0; i < 8; i++) { 42 | k[i] = x[i]; 43 | } 44 | 45 | invModP(k); 46 | 47 | return equal(z, k); 48 | } 49 | 50 | void addError(__global CLErrorInfo *errInfo, __global unsigned int *numErrors, int section) 51 | { 52 | unsigned int idx = atomic_add(numErrors, 1); 53 | 54 | CLErrorInfo info; 55 | info.section = section; 56 | 57 | errInfo[idx] = info; 58 | 59 | } 60 | 61 | __kernel void secp256k1_test(__global CLErrorInfo *errInfo, __global unsigned int *numErrors) 62 | { 63 | if(!addTest()) { 64 | addError(errInfo, numErrors, SECTION_ADD); 65 | } 66 | 67 | if(!multiplyTest()) { 68 | addError(errInfo, numErrors, SECTION_MULTIPLY); 69 | } 70 | 71 | if(!inverseTest()) { 72 | addError(errInfo, numErrors, SECTION_INVERSE); 73 | } 74 | } -------------------------------------------------------------------------------- /CmdParse/CmdParse.cpp: -------------------------------------------------------------------------------- 1 | #include "CmdParse.h" 2 | 3 | CmdParse::CmdParse() 4 | { 5 | 6 | } 7 | 8 | void CmdParse::add(const std::string shortForm, bool hasArg) 9 | { 10 | this->add(shortForm, "", hasArg); 11 | } 12 | 13 | void CmdParse::add(const std::string shortForm, const std::string longForm, bool hasArg) 14 | { 15 | ArgType arg; 16 | arg.shortForm = shortForm; 17 | arg.longForm = longForm; 18 | arg.hasArg = hasArg; 19 | 20 | _argType.push_back(arg); 21 | } 22 | 23 | bool CmdParse::get(const std::string opt, ArgType &t) 24 | { 25 | for(unsigned int i = 0; i < _argType.size(); i++) { 26 | if(_argType[i].shortForm == opt || _argType[i].longForm == opt) { 27 | t = _argType[i]; 28 | return true; 29 | } 30 | } 31 | 32 | return false; 33 | } 34 | 35 | void CmdParse::parse(int argc, char **argv) 36 | { 37 | for(int i = 1; i < argc; i++) { 38 | std::string arg(argv[i]); 39 | 40 | ArgType t; 41 | if(get(arg, t)) { 42 | // It is an option 43 | 44 | OptArg a; 45 | 46 | if(t.hasArg) { 47 | // It requires an argument 48 | 49 | if(i == argc - 1) { 50 | throw std::string("'" + arg + "' requires an argument"); 51 | } 52 | 53 | std::string optArg(argv[i + 1]); 54 | i++; 55 | a.option = arg; 56 | a.arg = optArg; 57 | 58 | } else { 59 | // It does not require an argument 60 | 61 | a.option = arg; 62 | a.arg = ""; 63 | } 64 | 65 | _optArgs.push_back(a); 66 | 67 | } else { 68 | // It is an operand 69 | 70 | _operands.push_back(arg); 71 | } 72 | } 73 | } 74 | 75 | std::vector CmdParse::getArgs() 76 | { 77 | return _optArgs; 78 | } 79 | 80 | std::vector CmdParse::getOperands() 81 | { 82 | return _operands; 83 | } -------------------------------------------------------------------------------- /CmdParse/CmdParse.h: -------------------------------------------------------------------------------- 1 | #ifndef _CMD_PARSE 2 | #define _CMD_PARSE 3 | 4 | #include 5 | #include 6 | 7 | class OptArg { 8 | 9 | public: 10 | 11 | std::string option; 12 | std::string arg; 13 | 14 | bool equals(std::string shortForm, std::string longForm = "") 15 | { 16 | return (shortForm.length() > 0 && option == shortForm) || option == longForm; 17 | } 18 | }; 19 | 20 | class ArgType { 21 | 22 | public: 23 | std::string shortForm; 24 | std::string longForm; 25 | bool hasArg; 26 | 27 | }; 28 | 29 | class CmdParse { 30 | 31 | private: 32 | 33 | std::vector _argType; 34 | 35 | std::vector _optArgs; 36 | 37 | std::vector _operands; 38 | 39 | bool get(const std::string opt, ArgType &t); 40 | 41 | public: 42 | 43 | CmdParse(); 44 | 45 | void parse(int argc, char **argv); 46 | 47 | void add(const std::string shortForm, const std::string longForm, bool hasArg); 48 | 49 | void add(const std::string shortForm, bool hasArg); 50 | 51 | std::vector getArgs(); 52 | 53 | std::vector getOperands(); 54 | }; 55 | 56 | #endif -------------------------------------------------------------------------------- /CmdParse/CmdParse.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | {F7037134-28C5-4EB9-BE5D-587E79A40628} 29 | Win32Proj 30 | CmdParse 31 | 10.0 32 | 33 | 34 | 35 | StaticLibrary 36 | true 37 | v141 38 | Unicode 39 | 40 | 41 | StaticLibrary 42 | false 43 | v141 44 | true 45 | Unicode 46 | 47 | 48 | StaticLibrary 49 | true 50 | v142 51 | Unicode 52 | 53 | 54 | StaticLibrary 55 | false 56 | v142 57 | true 58 | Unicode 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | Level3 88 | Disabled 89 | _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 90 | 91 | 92 | Windows 93 | 94 | 95 | 96 | 97 | NotUsing 98 | Level3 99 | Disabled 100 | _CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) 101 | 102 | 103 | Windows 104 | 105 | 106 | 107 | 108 | Level3 109 | 110 | 111 | MaxSpeed 112 | true 113 | true 114 | _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 115 | 116 | 117 | Windows 118 | true 119 | true 120 | 121 | 122 | 123 | 124 | Level3 125 | NotUsing 126 | MaxSpeed 127 | true 128 | true 129 | _CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;%(PreprocessorDefinitions) 130 | 131 | 132 | Windows 133 | true 134 | true 135 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /CmdParse/Makefile: -------------------------------------------------------------------------------- 1 | NAME=cmdparse 2 | SRC=$(wildcard *.cpp) 3 | OBJS=$(SRC:.cpp=.o) 4 | 5 | all: ${SRC} 6 | for file in ${SRC} ; do\ 7 | ${CXX} -c $$file ${INCLUDE} ${CXXFLAGS};\ 8 | done 9 | mkdir -p ${LIBDIR} 10 | ar rvs ${LIBDIR}/lib$(NAME).a ${OBJS} 11 | 12 | clean: 13 | rm -rf *.o -------------------------------------------------------------------------------- /CryptoUtil/CryptoUtil.h: -------------------------------------------------------------------------------- 1 | #ifndef _CRYPTO_UTIL_H 2 | 3 | namespace crypto { 4 | 5 | class Rng { 6 | unsigned int _state[16]; 7 | unsigned int _counter; 8 | 9 | void reseed(); 10 | 11 | public: 12 | Rng(); 13 | void get(unsigned char *buf, int len); 14 | }; 15 | 16 | 17 | void ripemd160(unsigned int *msg, unsigned int *digest); 18 | 19 | void sha256Init(unsigned int *digest); 20 | void sha256(unsigned int *msg, unsigned int *digest); 21 | 22 | unsigned int checksum(const unsigned int *hash); 23 | }; 24 | 25 | #endif -------------------------------------------------------------------------------- /CryptoUtil/CryptoUtil.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | {CA46856A-1D1E-4F6F-A69C-6707D540BF36} 32 | Win32Proj 33 | CryptoUtil 34 | 10.0 35 | 36 | 37 | 38 | StaticLibrary 39 | true 40 | v141 41 | Unicode 42 | 43 | 44 | StaticLibrary 45 | false 46 | v141 47 | true 48 | Unicode 49 | 50 | 51 | StaticLibrary 52 | true 53 | v142 54 | Unicode 55 | 56 | 57 | StaticLibrary 58 | false 59 | v142 60 | true 61 | Unicode 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | Level3 91 | Disabled 92 | _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 93 | 94 | 95 | Windows 96 | 97 | 98 | 99 | 100 | NotUsing 101 | Level3 102 | Disabled 103 | _CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) 104 | 105 | 106 | Windows 107 | 108 | 109 | 110 | 111 | Level3 112 | 113 | 114 | MaxSpeed 115 | true 116 | true 117 | _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 118 | 119 | 120 | Windows 121 | true 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | NotUsing 129 | MaxSpeed 130 | true 131 | true 132 | _CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;%(PreprocessorDefinitions) 133 | 134 | 135 | Windows 136 | true 137 | true 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /CryptoUtil/Makefile: -------------------------------------------------------------------------------- 1 | NAME=cryptoutil 2 | SRC=$(wildcard *.cpp) 3 | 4 | all: ${SRC} 5 | for file in ${SRC} ; do\ 6 | ${CXX} -c $$file ${INCLUDE} ${CXXFLAGS};\ 7 | done 8 | mkdir -p ${LIBDIR} 9 | ar rvs ${LIBDIR}/lib$(NAME).a *.o 10 | 11 | clean: 12 | rm -rf *.o 13 | -------------------------------------------------------------------------------- /CryptoUtil/Rng.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "CryptoUtil.h" 5 | 6 | #ifdef _WIN32 7 | #include 8 | #include 9 | 10 | static void secureRandom(unsigned char *buf, unsigned int count) 11 | { 12 | BCRYPT_ALG_HANDLE h; 13 | BCryptOpenAlgorithmProvider(&h, BCRYPT_RNG_ALGORITHM, NULL, 0); 14 | BCryptGenRandom(h, buf, count, 0); 15 | } 16 | #else 17 | static void secureRandom(unsigned char *buf, unsigned int count) 18 | { 19 | // Read from /dev/urandom 20 | FILE *fp = fopen("/dev/urandom", "rb"); 21 | 22 | if(fp == NULL) { 23 | throw std::string("Fatal error: Cannot open /dev/urandom for reading"); 24 | } 25 | 26 | if(fread(buf, 1, count, fp) != count) { 27 | throw std::string("Fatal error: Not enough entropy available in /dev/urandom"); 28 | } 29 | 30 | fclose(fp); 31 | } 32 | #endif 33 | 34 | 35 | crypto::Rng::Rng() 36 | { 37 | reseed(); 38 | } 39 | 40 | void crypto::Rng::reseed() 41 | { 42 | _counter = 0; 43 | 44 | memset(_state, 0, sizeof(_state)); 45 | 46 | secureRandom((unsigned char *)_state, 32); 47 | } 48 | 49 | void crypto::Rng::get(unsigned char *buf, int len) 50 | { 51 | int i = 0; 52 | while(len > 0) { 53 | if(_counter++ == 0xffffffff) { 54 | reseed(); 55 | } 56 | 57 | _state[15] = _counter; 58 | 59 | unsigned int digest[8]; 60 | sha256Init(digest); 61 | sha256(_state, digest); 62 | 63 | if(len >= 32) { 64 | memcpy(&buf[i], (const void *)digest, 32); 65 | i += 32; 66 | len -= 32; 67 | } else { 68 | memcpy(&buf[i], (const void *)digest, len); 69 | i += len; 70 | len -= len; 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /CryptoUtil/checksum.cpp: -------------------------------------------------------------------------------- 1 | #include "CryptoUtil.h" 2 | #include 3 | #include 4 | 5 | static unsigned int endian(unsigned int x) 6 | { 7 | return (x << 24) | ((x << 8) & 0x00ff0000) | ((x >> 8) & 0x0000ff00) | (x >> 24); 8 | } 9 | 10 | unsigned int crypto::checksum(const unsigned int *hash) 11 | { 12 | unsigned int msg[16] = { 0 }; 13 | unsigned int digest[8] = { 0 }; 14 | 15 | // Insert network byte, shift everything right 1 byte 16 | msg[0] = 0x00; // main network 17 | msg[0] |= hash[0] >> 8; 18 | msg[1] = (hash[0] << 24) | (hash[1] >> 8); 19 | msg[2] = (hash[1] << 24) | (hash[2] >> 8); 20 | msg[3] = (hash[2] << 24) | (hash[3] >> 8); 21 | msg[4] = (hash[3] << 24) | (hash[4] >> 8); 22 | msg[5] = (hash[4] << 24) | 0x00800000; 23 | 24 | // Padding and length 25 | msg[15] = 168; 26 | 27 | // Hash address 28 | sha256Init(digest); 29 | sha256(msg, digest); 30 | 31 | // Prepare to make a hash of the digest 32 | memset(msg, 0, 16 * sizeof(unsigned int)); 33 | for(int i = 0; i < 8; i++) { 34 | msg[i] = digest[i]; 35 | } 36 | 37 | msg[8] = 0x80000000; 38 | msg[15] = 256; 39 | 40 | 41 | sha256Init(digest); 42 | sha256(msg, digest); 43 | 44 | return digest[0]; 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /CryptoUtil/hash.cpp: -------------------------------------------------------------------------------- 1 | #include"CryptoUtil.h" 2 | #include 3 | #include 4 | 5 | static unsigned int endian(unsigned int x) 6 | { 7 | return (x << 24) | ((x << 8) & 0x00ff0000) | ((x >> 8) & 0x0000ff00) | (x >> 24); 8 | } 9 | 10 | unsigned int crypto::checksum(const unsigned int *hash) 11 | { 12 | unsigned int msg[16] = { 0 }; 13 | unsigned int digest[8] = { 0 }; 14 | 15 | // Insert network byte, shift everything right 1 byte 16 | msg[0] = 0x00; // main network 17 | msg[0] |= hash[0] >> 8; 18 | msg[1] = (hash[0] << 24) | (hash[1] >> 8); 19 | msg[2] = (hash[1] << 24) | (hash[2] >> 8); 20 | msg[3] = (hash[2] << 24) | (hash[3] >> 8); 21 | msg[4] = (hash[3] << 24) | (hash[4] >> 8); 22 | msg[5] = (hash[4] << 24) | 0x00800000; 23 | 24 | // Padding and length 25 | msg[15] = 168; 26 | 27 | // Hash address 28 | sha256Init(digest); 29 | sha256(msg, digest); 30 | 31 | // Prepare to make a hash of the digest 32 | memset(msg, 0, 16 * sizeof(unsigned int)); 33 | for(int i = 0; i < 8; i++) { 34 | msg[i] = digest[i]; 35 | } 36 | 37 | msg[8] = 0x80000000; 38 | msg[15] = 256; 39 | 40 | 41 | sha256Init(digest); 42 | sha256(msg, digest); 43 | 44 | return digest[0]; 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /CryptoUtil/sha256.cpp: -------------------------------------------------------------------------------- 1 | #include "CryptoUtil.h" 2 | 3 | static const unsigned int _K[64] = { 4 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 5 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 6 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 7 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 8 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 9 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 10 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 11 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 12 | }; 13 | 14 | static const unsigned int _IV[8] = { 15 | 0x6a09e667, 16 | 0xbb67ae85, 17 | 0x3c6ef372, 18 | 0xa54ff53a, 19 | 0x510e527f, 20 | 0x9b05688c, 21 | 0x1f83d9ab, 22 | 0x5be0cd19 23 | }; 24 | 25 | static unsigned int rotr(unsigned int x, int n) 26 | { 27 | return (x >> n) | (x << (32 - n)); 28 | } 29 | 30 | static unsigned int MAJ(unsigned int a, unsigned int b, unsigned int c) 31 | { 32 | return (a & b) ^ (a & c) ^ (b & c); 33 | } 34 | 35 | static unsigned int CH(unsigned int e, unsigned int f, unsigned int g) 36 | { 37 | return (e & f) ^ (~e & g); 38 | } 39 | 40 | 41 | static void round(unsigned int a, unsigned int b, unsigned int c, unsigned int &d, unsigned e, unsigned int f, unsigned int g, unsigned int &h, unsigned int m, unsigned int k) 42 | { 43 | unsigned int s = CH(e, f, g) + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + k + m; 44 | 45 | d += s + h; 46 | 47 | h += s + MAJ(a, b, c) + (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)); 48 | } 49 | 50 | 51 | void crypto::sha256Init(unsigned int *digest) 52 | { 53 | for(int i = 0; i < 8; i++) { 54 | digest[i] = _IV[i]; 55 | } 56 | } 57 | 58 | void crypto::sha256(unsigned int *msg, unsigned int *digest) 59 | { 60 | unsigned int a, b, c, d, e, f, g, h; 61 | unsigned int s0, s1; 62 | 63 | a = digest[0]; 64 | b = digest[1]; 65 | c = digest[2]; 66 | d = digest[3]; 67 | e = digest[4]; 68 | f = digest[5]; 69 | g = digest[6]; 70 | h = digest[7]; 71 | 72 | unsigned int w[80] = { 0 }; 73 | for(int i = 0; i < 16; i++) { 74 | w[i] = msg[i]; 75 | } 76 | 77 | // Expand 16 words to 64 words 78 | for(int i = 16; i < 64; i++) { 79 | unsigned int x = w[i - 15]; 80 | unsigned int y = w[i - 2]; 81 | 82 | s0 = rotr(x, 7) ^ rotr(x, 18) ^ (x >> 3); 83 | s1 = rotr(y, 17) ^ rotr(y, 19) ^ (y >> 10); 84 | w[i] = w[i - 16] + s0 + w[i - 7] + s1; 85 | } 86 | 87 | for(int i = 0; i < 64; i += 8) { 88 | round(a, b, c, d, e, f, g, h, w[i], _K[i]); 89 | round(h, a, b, c, d, e, f, g, w[i + 1], _K[i + 1]); 90 | round(g, h, a, b, c, d, e, f, w[i + 2], _K[i + 2]); 91 | round(f, g, h, a, b, c, d, e, w[i + 3], _K[i + 3]); 92 | round(e, f, g, h, a, b, c, d, w[i + 4], _K[i + 4]); 93 | round(d, e, f, g, h, a, b, c, w[i + 5], _K[i + 5]); 94 | round(c, d, e, f, g, h, a, b, w[i + 6], _K[i + 6]); 95 | round(b, c, d, e, f, g, h, a, w[i + 7], _K[i + 7]); 96 | } 97 | 98 | digest[0] += a; 99 | digest[1] += b; 100 | digest[2] += c; 101 | digest[3] += d; 102 | digest[4] += e; 103 | digest[5] += f; 104 | digest[6] += g; 105 | digest[7] += h; 106 | } -------------------------------------------------------------------------------- /CudaKeySearchDevice/CudaAtomicList.cu: -------------------------------------------------------------------------------- 1 | #include "CudaAtomicList.h" 2 | #include "CudaAtomicList.cuh" 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | static __constant__ void *_LIST_BUF[1]; 10 | static __constant__ unsigned int *_LIST_SIZE[1]; 11 | 12 | 13 | __device__ void atomicListAdd(void *info, unsigned int size) 14 | { 15 | unsigned int count = atomicAdd(_LIST_SIZE[0], 1); 16 | 17 | unsigned char *ptr = (unsigned char *)(_LIST_BUF[0]) + count * size; 18 | 19 | memcpy(ptr, info, size); 20 | } 21 | 22 | static cudaError_t setListPtr(void *ptr, unsigned int *numResults) 23 | { 24 | cudaError_t err = cudaMemcpyToSymbol(_LIST_BUF, &ptr, sizeof(void *)); 25 | 26 | if(err) { 27 | return err; 28 | } 29 | 30 | err = cudaMemcpyToSymbol(_LIST_SIZE, &numResults, sizeof(unsigned int *)); 31 | 32 | return err; 33 | } 34 | 35 | 36 | cudaError_t CudaAtomicList::init(unsigned int itemSize, unsigned int maxItems) 37 | { 38 | _itemSize = itemSize; 39 | 40 | // The number of results found in the most recent kernel run 41 | _countHostPtr = NULL; 42 | cudaError_t err = cudaHostAlloc(&_countHostPtr, sizeof(unsigned int), cudaHostAllocMapped); 43 | if(err) { 44 | goto end; 45 | } 46 | 47 | // Number of items in the list 48 | _countDevPtr = NULL; 49 | err = cudaHostGetDevicePointer(&_countDevPtr, _countHostPtr, 0); 50 | if(err) { 51 | goto end; 52 | } 53 | *_countHostPtr = 0; 54 | 55 | // Storage for results data 56 | _hostPtr = NULL; 57 | err = cudaHostAlloc(&_hostPtr, itemSize * maxItems, cudaHostAllocMapped); 58 | if(err) { 59 | goto end; 60 | } 61 | 62 | // Storage for results data (device to host pointer) 63 | _devPtr = NULL; 64 | err = cudaHostGetDevicePointer(&_devPtr, _hostPtr, 0); 65 | 66 | if(err) { 67 | goto end; 68 | } 69 | 70 | err = setListPtr(_devPtr, _countDevPtr); 71 | 72 | end: 73 | if(err) { 74 | cudaFreeHost(_countHostPtr); 75 | 76 | cudaFree(_countDevPtr); 77 | 78 | cudaFreeHost(_hostPtr); 79 | 80 | cudaFree(_devPtr); 81 | } 82 | 83 | return err; 84 | } 85 | 86 | unsigned int CudaAtomicList::size() 87 | { 88 | return *_countHostPtr; 89 | } 90 | 91 | void CudaAtomicList::clear() 92 | { 93 | *_countHostPtr = 0; 94 | } 95 | 96 | unsigned int CudaAtomicList::read(void *ptr, unsigned int count) 97 | { 98 | if(count >= *_countHostPtr) { 99 | count = *_countHostPtr; 100 | } 101 | 102 | memcpy(ptr, _hostPtr, count * _itemSize); 103 | 104 | return count; 105 | } 106 | 107 | void CudaAtomicList::cleanup() 108 | { 109 | cudaFreeHost(_countHostPtr); 110 | 111 | cudaFree(_countDevPtr); 112 | 113 | cudaFreeHost(_hostPtr); 114 | 115 | cudaFree(_devPtr); 116 | } -------------------------------------------------------------------------------- /CudaKeySearchDevice/CudaAtomicList.cuh: -------------------------------------------------------------------------------- 1 | #ifndef _ATOMIC_LIST_CUH 2 | #define _ATOMIC_LIST_CUH 3 | 4 | #include 5 | 6 | __device__ void atomicListAdd(void *info, unsigned int size); 7 | 8 | #endif -------------------------------------------------------------------------------- /CudaKeySearchDevice/CudaAtomicList.h: -------------------------------------------------------------------------------- 1 | #ifndef _ATOMIC_LIST_HOST_H 2 | #define _ATOMIC_LIST_HOST_H 3 | 4 | #include 5 | 6 | /** 7 | A list that multiple device threads can append items to. Items can be 8 | read and removed by the host 9 | */ 10 | class CudaAtomicList { 11 | 12 | private: 13 | void *_devPtr; 14 | 15 | void *_hostPtr; 16 | 17 | unsigned int *_countHostPtr; 18 | 19 | unsigned int *_countDevPtr; 20 | 21 | unsigned int _maxSize; 22 | 23 | unsigned int _itemSize; 24 | 25 | public: 26 | 27 | CudaAtomicList() 28 | { 29 | _devPtr = NULL; 30 | _hostPtr = NULL; 31 | _countHostPtr = NULL; 32 | _countDevPtr = NULL; 33 | _maxSize = 0; 34 | _itemSize = 0; 35 | } 36 | 37 | ~CudaAtomicList() 38 | { 39 | cleanup(); 40 | } 41 | 42 | cudaError_t init(unsigned int itemSize, unsigned int maxItems); 43 | 44 | unsigned int read(void *dest, unsigned int count); 45 | 46 | unsigned int size(); 47 | 48 | void clear(); 49 | 50 | void cleanup(); 51 | 52 | }; 53 | 54 | #endif -------------------------------------------------------------------------------- /CudaKeySearchDevice/CudaDeviceKeys.cuh: -------------------------------------------------------------------------------- 1 | #ifndef _EC_CUH 2 | #define _EC_CUH 3 | 4 | #include 5 | 6 | namespace ec { 7 | __device__ unsigned int *getXPtr(); 8 | 9 | __device__ unsigned int *getYPtr(); 10 | } 11 | 12 | #endif -------------------------------------------------------------------------------- /CudaKeySearchDevice/CudaDeviceKeys.h: -------------------------------------------------------------------------------- 1 | #ifndef _EC_H 2 | #define _EC_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include "secp256k1.h" 9 | 10 | 11 | class CudaDeviceKeys { 12 | 13 | private: 14 | int _blocks; 15 | 16 | int _threads; 17 | 18 | int _pointsPerThread; 19 | 20 | unsigned int _numKeys; 21 | 22 | unsigned int *_devX; 23 | 24 | unsigned int *_devY; 25 | 26 | unsigned int *_devPrivate; 27 | 28 | unsigned int *_devChain; 29 | 30 | unsigned int *_devBasePointX; 31 | 32 | unsigned int *_devBasePointY; 33 | 34 | int _step; 35 | 36 | int getIndex(int block, int thread, int idx); 37 | 38 | void splatBigInt(unsigned int *dest, int block, int thread, int idx, const secp256k1::uint256 &i); 39 | 40 | secp256k1::uint256 readBigInt(unsigned int *src, int block, int thread, int idx); 41 | 42 | cudaError_t allocateChainBuf(unsigned int count); 43 | 44 | cudaError_t initializePublicKeys(size_t count); 45 | 46 | cudaError_t initializeBasePoints(); 47 | 48 | 49 | public: 50 | 51 | CudaDeviceKeys() 52 | { 53 | _numKeys = 0; 54 | _devX = NULL; 55 | _devY = NULL; 56 | _devPrivate = NULL; 57 | _devChain = NULL; 58 | _devBasePointX = NULL; 59 | _devBasePointY = NULL; 60 | _step = 0; 61 | } 62 | 63 | ~CudaDeviceKeys() 64 | { 65 | clearPublicKeys(); 66 | clearPrivateKeys(); 67 | } 68 | 69 | cudaError_t init(int blocks, int threads, int pointsPerThread, const std::vector &privateKeys); 70 | 71 | bool selfTest(const std::vector &privateKeys); 72 | 73 | cudaError_t doStep(); 74 | 75 | void clearPrivateKeys(); 76 | 77 | void clearPublicKeys(); 78 | 79 | }; 80 | 81 | #endif -------------------------------------------------------------------------------- /CudaKeySearchDevice/CudaHashLookup.cuh: -------------------------------------------------------------------------------- 1 | #ifndef _ADDRESS_LOOKUP_CUH 2 | #define _ADDRESS_LOOKUP_CUH 3 | 4 | __device__ bool checkHash(const unsigned int hash[5]); 5 | 6 | #endif -------------------------------------------------------------------------------- /CudaKeySearchDevice/CudaHashLookup.h: -------------------------------------------------------------------------------- 1 | #ifndef _HASH_LOOKUP_HOST_H 2 | #define _HASH_LOOKUP_HOST_H 3 | 4 | #include 5 | 6 | class CudaHashLookup { 7 | 8 | private: 9 | unsigned int *_bloomFilterPtr; 10 | 11 | cudaError_t setTargetBloomFilter(const std::vector &targets); 12 | 13 | cudaError_t setTargetConstantMemory(const std::vector &targets); 14 | 15 | unsigned int getOptimalBloomFilterBits(double p, size_t n); 16 | 17 | void cleanup(); 18 | 19 | void initializeBloomFilter(const std::vector &targets, unsigned int *filter, unsigned int mask); 20 | 21 | void initializeBloomFilter64(const std::vector &targets, unsigned int *filter, unsigned long long mask); 22 | 23 | public: 24 | 25 | CudaHashLookup() 26 | { 27 | _bloomFilterPtr = NULL; 28 | } 29 | 30 | ~CudaHashLookup() 31 | { 32 | cleanup(); 33 | } 34 | 35 | cudaError_t setTargets(const std::vector &targets); 36 | }; 37 | 38 | #endif -------------------------------------------------------------------------------- /CudaKeySearchDevice/CudaKeySearchDevice.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "KeySearchTypes.h" 5 | #include "CudaKeySearchDevice.h" 6 | #include "ptx.cuh" 7 | #include "secp256k1.cuh" 8 | 9 | #include "sha256.cuh" 10 | #include "ripemd160.cuh" 11 | 12 | #include "secp256k1.h" 13 | 14 | #include "CudaHashLookup.cuh" 15 | #include "CudaAtomicList.cuh" 16 | #include "CudaDeviceKeys.cuh" 17 | 18 | __constant__ unsigned int _INC_X[8]; 19 | 20 | __constant__ unsigned int _INC_Y[8]; 21 | 22 | __constant__ unsigned int *_CHAIN[1]; 23 | 24 | static unsigned int *_chainBufferPtr = NULL; 25 | 26 | 27 | __device__ void doRMD160FinalRound(const unsigned int hIn[5], unsigned int hOut[5]) 28 | { 29 | const unsigned int iv[5] = { 30 | 0x67452301, 31 | 0xefcdab89, 32 | 0x98badcfe, 33 | 0x10325476, 34 | 0xc3d2e1f0 35 | }; 36 | 37 | for(int i = 0; i < 5; i++) { 38 | hOut[i] = endian(hIn[i] + iv[(i + 1) % 5]); 39 | } 40 | } 41 | 42 | 43 | /** 44 | * Allocates device memory for storing the multiplication chain used in 45 | the batch inversion operation 46 | */ 47 | cudaError_t allocateChainBuf(unsigned int count) 48 | { 49 | cudaError_t err = cudaMalloc(&_chainBufferPtr, count * sizeof(unsigned int) * 8); 50 | 51 | if(err) { 52 | return err; 53 | } 54 | 55 | err = cudaMemcpyToSymbol(_CHAIN, &_chainBufferPtr, sizeof(unsigned int *)); 56 | if(err) { 57 | cudaFree(_chainBufferPtr); 58 | } 59 | 60 | return err; 61 | } 62 | 63 | void cleanupChainBuf() 64 | { 65 | if(_chainBufferPtr != NULL) { 66 | cudaFree(_chainBufferPtr); 67 | _chainBufferPtr = NULL; 68 | } 69 | } 70 | 71 | /** 72 | *Sets the EC point which all points will be incremented by 73 | */ 74 | cudaError_t setIncrementorPoint(const secp256k1::uint256 &x, const secp256k1::uint256 &y) 75 | { 76 | unsigned int xWords[8]; 77 | unsigned int yWords[8]; 78 | 79 | x.exportWords(xWords, 8, secp256k1::uint256::BigEndian); 80 | y.exportWords(yWords, 8, secp256k1::uint256::BigEndian); 81 | 82 | cudaError_t err = cudaMemcpyToSymbol(_INC_X, xWords, sizeof(unsigned int) * 8); 83 | if(err) { 84 | return err; 85 | } 86 | 87 | return cudaMemcpyToSymbol(_INC_Y, yWords, sizeof(unsigned int) * 8); 88 | } 89 | 90 | 91 | 92 | __device__ void hashPublicKey(const unsigned int *x, const unsigned int *y, unsigned int *digestOut) 93 | { 94 | unsigned int hash[8]; 95 | 96 | sha256PublicKey(x, y, hash); 97 | 98 | // Swap to little-endian 99 | for(int i = 0; i < 8; i++) { 100 | hash[i] = endian(hash[i]); 101 | } 102 | 103 | ripemd160sha256NoFinal(hash, digestOut); 104 | } 105 | 106 | __device__ void hashPublicKeyCompressed(const unsigned int *x, unsigned int yParity, unsigned int *digestOut) 107 | { 108 | unsigned int hash[8]; 109 | 110 | sha256PublicKeyCompressed(x, yParity, hash); 111 | 112 | // Swap to little-endian 113 | for(int i = 0; i < 8; i++) { 114 | hash[i] = endian(hash[i]); 115 | } 116 | 117 | ripemd160sha256NoFinal(hash, digestOut); 118 | } 119 | 120 | 121 | __device__ void setResultFound(int idx, bool compressed, unsigned int x[8], unsigned int y[8], unsigned int digest[5]) 122 | { 123 | CudaDeviceResult r; 124 | 125 | r.block = blockIdx.x; 126 | r.thread = threadIdx.x; 127 | r.idx = idx; 128 | r.compressed = compressed; 129 | 130 | for(int i = 0; i < 8; i++) { 131 | r.x[i] = x[i]; 132 | r.y[i] = y[i]; 133 | } 134 | 135 | doRMD160FinalRound(digest, r.digest); 136 | 137 | atomicListAdd(&r, sizeof(r)); 138 | } 139 | 140 | __device__ void doIteration(int pointsPerThread, int compression) 141 | { 142 | unsigned int *chain = _CHAIN[0]; 143 | unsigned int *xPtr = ec::getXPtr(); 144 | unsigned int *yPtr = ec::getYPtr(); 145 | 146 | // Multiply together all (_Gx - x) and then invert 147 | unsigned int inverse[8] = {0,0,0,0,0,0,0,1}; 148 | for(int i = 0; i < pointsPerThread; i++) { 149 | unsigned int x[8]; 150 | 151 | unsigned int digest[5]; 152 | 153 | readInt(xPtr, i, x); 154 | 155 | if(compression == PointCompressionType::UNCOMPRESSED || compression == PointCompressionType::BOTH) { 156 | unsigned int y[8]; 157 | readInt(yPtr, i, y); 158 | 159 | hashPublicKey(x, y, digest); 160 | 161 | if(checkHash(digest)) { 162 | setResultFound(i, false, x, y, digest); 163 | } 164 | } 165 | 166 | if(compression == PointCompressionType::COMPRESSED || compression == PointCompressionType::BOTH) { 167 | hashPublicKeyCompressed(x, readIntLSW(yPtr, i), digest); 168 | 169 | if(checkHash(digest)) { 170 | unsigned int y[8]; 171 | readInt(yPtr, i, y); 172 | setResultFound(i, true, x, y, digest); 173 | } 174 | } 175 | 176 | beginBatchAdd(_INC_X, x, chain, i, i, inverse); 177 | } 178 | 179 | doBatchInverse(inverse); 180 | 181 | for(int i = pointsPerThread - 1; i >= 0; i--) { 182 | 183 | unsigned int newX[8]; 184 | unsigned int newY[8]; 185 | 186 | completeBatchAdd(_INC_X, _INC_Y, xPtr, yPtr, i, i, chain, inverse, newX, newY); 187 | 188 | writeInt(xPtr, i, newX); 189 | writeInt(yPtr, i, newY); 190 | } 191 | } 192 | 193 | __device__ void doIterationWithDouble(int pointsPerThread, int compression) 194 | { 195 | unsigned int *chain = _CHAIN[0]; 196 | unsigned int *xPtr = ec::getXPtr(); 197 | unsigned int *yPtr = ec::getYPtr(); 198 | 199 | // Multiply together all (_Gx - x) and then invert 200 | unsigned int inverse[8] = {0,0,0,0,0,0,0,1}; 201 | for(int i = 0; i < pointsPerThread; i++) { 202 | unsigned int x[8]; 203 | 204 | unsigned int digest[5]; 205 | 206 | readInt(xPtr, i, x); 207 | 208 | // uncompressed 209 | if(compression == PointCompressionType::UNCOMPRESSED || compression == PointCompressionType::BOTH) { 210 | unsigned int y[8]; 211 | readInt(yPtr, i, y); 212 | hashPublicKey(x, y, digest); 213 | 214 | if(checkHash(digest)) { 215 | setResultFound(i, false, x, y, digest); 216 | } 217 | } 218 | 219 | // compressed 220 | if(compression == PointCompressionType::COMPRESSED || compression == PointCompressionType::BOTH) { 221 | 222 | hashPublicKeyCompressed(x, readIntLSW(yPtr, i), digest); 223 | 224 | if(checkHash(digest)) { 225 | 226 | unsigned int y[8]; 227 | readInt(yPtr, i, y); 228 | 229 | setResultFound(i, true, x, y, digest); 230 | } 231 | } 232 | 233 | beginBatchAddWithDouble(_INC_X, _INC_Y, xPtr, chain, i, i, inverse); 234 | } 235 | 236 | doBatchInverse(inverse); 237 | 238 | for(int i = pointsPerThread - 1; i >= 0; i--) { 239 | 240 | unsigned int newX[8]; 241 | unsigned int newY[8]; 242 | 243 | completeBatchAddWithDouble(_INC_X, _INC_Y, xPtr, yPtr, i, i, chain, inverse, newX, newY); 244 | 245 | writeInt(xPtr, i, newX); 246 | writeInt(yPtr, i, newY); 247 | } 248 | } 249 | 250 | /** 251 | * Performs a single iteration 252 | */ 253 | __global__ void keyFinderKernel(int points, int compression) 254 | { 255 | doIteration(points, compression); 256 | } 257 | 258 | __global__ void keyFinderKernelWithDouble(int points, int compression) 259 | { 260 | doIterationWithDouble(points, compression); 261 | } -------------------------------------------------------------------------------- /CudaKeySearchDevice/CudaKeySearchDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef _CUDA_KEY_SEARCH_DEVICE 2 | #define _CUDA_KEY_SEARCH_DEVICE 3 | 4 | #include "KeySearchDevice.h" 5 | #include 6 | #include 7 | #include "secp256k1.h" 8 | #include "CudaDeviceKeys.h" 9 | #include "CudaHashLookup.h" 10 | #include "CudaAtomicList.h" 11 | #include "cudaUtil.h" 12 | 13 | // Structures that exist on both host and device side 14 | struct CudaDeviceResult { 15 | int thread; 16 | int block; 17 | int idx; 18 | bool compressed; 19 | unsigned int x[8]; 20 | unsigned int y[8]; 21 | unsigned int digest[5]; 22 | }; 23 | 24 | class CudaKeySearchDevice : public KeySearchDevice { 25 | 26 | private: 27 | 28 | int _device; 29 | 30 | int _blocks; 31 | 32 | int _threads; 33 | 34 | int _pointsPerThread; 35 | 36 | int _compression; 37 | 38 | std::vector _results; 39 | 40 | std::string _deviceName; 41 | 42 | secp256k1::uint256 _startExponent; 43 | 44 | uint64_t _iterations; 45 | 46 | void cudaCall(cudaError_t err); 47 | 48 | void generateStartingPoints(); 49 | 50 | CudaDeviceKeys _deviceKeys; 51 | 52 | CudaAtomicList _resultList; 53 | 54 | CudaHashLookup _targetLookup; 55 | 56 | void getResultsInternal(); 57 | 58 | std::vector _targets; 59 | 60 | bool isTargetInList(const unsigned int hash[5]); 61 | 62 | void removeTargetFromList(const unsigned int hash[5]); 63 | 64 | uint32_t getPrivateKeyOffset(int thread, int block, int point); 65 | 66 | secp256k1::uint256 _stride; 67 | 68 | bool verifyKey(const secp256k1::uint256 &privateKey, const secp256k1::ecpoint &publicKey, const unsigned int hash[5], bool compressed); 69 | 70 | public: 71 | 72 | CudaKeySearchDevice(int device, int threads, int pointsPerThread, int blocks = 0); 73 | 74 | virtual void init(const secp256k1::uint256 &start, int compression, const secp256k1::uint256 &stride); 75 | 76 | virtual void doStep(); 77 | 78 | virtual void setTargets(const std::set &targets); 79 | 80 | virtual size_t getResults(std::vector &results); 81 | 82 | virtual uint64_t keysPerStep(); 83 | 84 | virtual std::string getDeviceName(); 85 | 86 | virtual void getMemoryInfo(uint64_t &freeMem, uint64_t &totalMem); 87 | 88 | virtual secp256k1::uint256 getNextKey(); 89 | }; 90 | 91 | #endif -------------------------------------------------------------------------------- /CudaKeySearchDevice/CudaKeySearchDevice.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | {150af404-1f80-4a13-855b-4383c4a3326f} 36 | 37 | 38 | 39 | {CCA3D02C-5E5A-4A24-B34B-5961DFA93946} 40 | CudaKeySearchDevice 41 | 10.0 42 | 43 | 44 | 45 | StaticLibrary 46 | true 47 | MultiByte 48 | v142 49 | 50 | 51 | StaticLibrary 52 | false 53 | true 54 | MultiByte 55 | v142 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | true 72 | 73 | 74 | 75 | Level4 76 | Disabled 77 | WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 78 | %(AdditionalUsingDirectories) 79 | $(SolutionDir)\secp256k1lib;$(SolutionDir)\KeyFinderLib;$(SolutionDir)\Logger;$(SolutionDir)\Util;$(SolutionDir)\CudaMath;$(SolutionDir)\cudaUtil;$(SolutionDir)\AddressUtil;$(CUDA_INCLUDE) 80 | 81 | 82 | true 83 | Console 84 | cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 85 | 86 | 87 | 64 88 | true 89 | %(CodeGeneration) 90 | 91 | 92 | 93 | 94 | Level4 95 | MaxSpeed 96 | true 97 | true 98 | WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 99 | %(AdditionalUsingDirectories) 100 | $(SolutionDir)\secp256k1lib;$(SolutionDir)\KeyFinderLib;$(SolutionDir)\Logger;$(SolutionDir)\Util;$(SolutionDir)\CudaMath;$(SolutionDir)\cudaUtil;$(SolutionDir)\AddressUtil;$(CUDA_INCLUDE) 101 | 102 | 103 | true 104 | true 105 | true 106 | Console 107 | cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 108 | 109 | 110 | 64 111 | true 112 | %(CodeGeneration) 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /CudaKeySearchDevice/Makefile: -------------------------------------------------------------------------------- 1 | NAME=CudaKeySearchDevice 2 | CPPSRC:=$(wildcard *.cpp) 3 | CUSRC:=$(wildcard *.cu) 4 | 5 | all: cuda 6 | 7 | cuda: 8 | for file in ${CPPSRC} ; do\ 9 | ${CXX} -c $$file ${INCLUDE} -I${CUDA_INCLUDE} ${CXXFLAGS};\ 10 | done 11 | 12 | for file in ${CUSRC} ; do\ 13 | ${NVCC} -c $$file -o $$file".o" ${NVCCFLAGS} -rdc=true ${INCLUDE} -I${CUDA_INCLUDE} -I${CUDA_MATH};\ 14 | done 15 | 16 | ${NVCC} -dlink -o cuda_libs.o *.cu.o -lcudadevrt -lcudart 17 | 18 | ar rvs ${LIBDIR}/lib$(NAME).a *.o 19 | 20 | clean: 21 | rm -f *.o *.cu.o 22 | rm -f *.a -------------------------------------------------------------------------------- /CudaKeySearchDevice/cudabridge.cu: -------------------------------------------------------------------------------- 1 | #include "cudabridge.h" 2 | 3 | 4 | __global__ void keyFinderKernel(int points, int compression); 5 | __global__ void keyFinderKernelWithDouble(int points, int compression); 6 | 7 | void callKeyFinderKernel(int blocks, int threads, int points, bool useDouble, int compression) 8 | { 9 | if(useDouble) { 10 | keyFinderKernelWithDouble <<>>(points, compression); 11 | } else { 12 | keyFinderKernel <<>> (points, compression); 13 | } 14 | waitForKernel(); 15 | } 16 | 17 | 18 | void waitForKernel() 19 | { 20 | // Check for kernel launch error 21 | cudaError_t err = cudaGetLastError(); 22 | 23 | if(err != cudaSuccess) { 24 | throw cuda::CudaException(err); 25 | } 26 | 27 | // Wait for kernel to complete 28 | err = cudaDeviceSynchronize(); 29 | fflush(stdout); 30 | if(err != cudaSuccess) { 31 | throw cuda::CudaException(err); 32 | } 33 | } -------------------------------------------------------------------------------- /CudaKeySearchDevice/cudabridge.h: -------------------------------------------------------------------------------- 1 | #ifndef _BRIDGE_H 2 | #define _BRIDGE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "cudaUtil.h" 8 | #include "secp256k1.h" 9 | 10 | 11 | void callKeyFinderKernel(int blocks, int threads, int points, bool useDouble, int compression); 12 | 13 | void waitForKernel(); 14 | 15 | cudaError_t setIncrementorPoint(const secp256k1::uint256 &x, const secp256k1::uint256 &y); 16 | cudaError_t allocateChainBuf(unsigned int count); 17 | void cleanupChainBuf(); 18 | 19 | #endif -------------------------------------------------------------------------------- /KeyFinder/ConfigFile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ConfigFile.h" 3 | #include "util.h" 4 | 5 | 6 | ConfigFileReader::ConfigFileReader(const std::string &path) 7 | { 8 | _path = path; 9 | } 10 | 11 | bool ConfigFileReader::exists() 12 | { 13 | std::ifstream f(_path); 14 | return f.good(); 15 | } 16 | 17 | ConfigFileEntry ConfigFileReader::readEntry(const std::string &line) 18 | { 19 | size_t eqPos = line.find('='); 20 | 21 | if(eqPos == std::string::npos) { 22 | throw std::string("Invalid syntax"); 23 | } 24 | 25 | std::string leftSide = util::trim(line.substr(0, eqPos), ' '); 26 | 27 | std::string rightSide = util::trim(line.substr(eqPos + 1), ' '); 28 | 29 | return ConfigFileEntry(leftSide, rightSide); 30 | } 31 | 32 | std::map ConfigFileReader::read() 33 | { 34 | std::vector lines; 35 | std::map entries; 36 | 37 | util::readLinesFromStream(_path, lines); 38 | 39 | for(int i = 0; i < lines.size(); i++) { 40 | ConfigFileEntry e = readEntry(lines[i]); 41 | std::string k = util::toLower(e.key); 42 | entries[k] = e; 43 | } 44 | 45 | return entries; 46 | } -------------------------------------------------------------------------------- /KeyFinder/ConfigFile.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_FILE_H 2 | #define _CONFIG_FILE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class ConfigFileEntry { 10 | 11 | public: 12 | std::string key = ""; 13 | std::string value = ""; 14 | 15 | ConfigFileEntry() {} 16 | 17 | ConfigFileEntry(std::string k, std::string v) : key(k), value(v) 18 | { 19 | } 20 | 21 | }; 22 | 23 | class ConfigFileReader { 24 | 25 | private: 26 | std::string _path; 27 | 28 | ConfigFileEntry readEntry(const std::string &line); 29 | 30 | public: 31 | ConfigFileReader(const std::string &path); 32 | 33 | bool exists(); 34 | std::map read(); 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /KeyFinder/DeviceManager.cpp: -------------------------------------------------------------------------------- 1 | #include "DeviceManager.h" 2 | 3 | #ifdef BUILD_CUDA 4 | #include "cudaUtil.h" 5 | #endif 6 | 7 | #ifdef BUILD_OPENCL 8 | #include "clutil.h" 9 | #endif 10 | 11 | std::vector DeviceManager::getDevices() 12 | { 13 | int deviceId = 0; 14 | 15 | std::vector devices; 16 | 17 | #ifdef BUILD_CUDA 18 | // Get CUDA devices 19 | try { 20 | std::vector cudaDevices = cuda::getDevices(); 21 | 22 | for(int i = 0; i < cudaDevices.size(); i++) { 23 | DeviceManager::DeviceInfo device; 24 | device.name = cudaDevices[i].name; 25 | device.type = DeviceType::CUDA; 26 | device.id = deviceId; 27 | device.physicalId = cudaDevices[i].id; 28 | device.memory = cudaDevices[i].mem; 29 | device.computeUnits = cudaDevices[i].mpCount; 30 | devices.push_back(device); 31 | 32 | deviceId++; 33 | } 34 | } catch(cuda::CudaException ex) { 35 | throw DeviceManager::DeviceManagerException(ex.msg); 36 | } 37 | #endif 38 | 39 | #ifdef BUILD_OPENCL 40 | // Get OpenCL devices 41 | try { 42 | std::vector clDevices = cl::getDevices(); 43 | 44 | for(int i = 0; i < clDevices.size(); i++) { 45 | DeviceManager::DeviceInfo device; 46 | device.name = clDevices[i].name; 47 | device.type = DeviceType::OpenCL; 48 | device.id = deviceId; 49 | device.physicalId = (uint64_t)clDevices[i].id; 50 | device.memory = clDevices[i].mem; 51 | device.computeUnits = clDevices[i].cores; 52 | devices.push_back(device); 53 | deviceId++; 54 | } 55 | } catch(cl::CLException ex) { 56 | throw DeviceManager::DeviceManagerException(ex.msg); 57 | } 58 | #endif 59 | 60 | return devices; 61 | } -------------------------------------------------------------------------------- /KeyFinder/DeviceManager.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEVICE_MANAGER_H 2 | #define _DEVICE_MANAGER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace DeviceManager { 9 | 10 | class DeviceManagerException { 11 | 12 | public: 13 | std::string msg; 14 | 15 | DeviceManagerException(const std::string &msg) 16 | { 17 | this->msg = msg; 18 | } 19 | }; 20 | 21 | class DeviceType { 22 | public: 23 | enum { 24 | CUDA = 0, 25 | OpenCL 26 | }; 27 | }; 28 | 29 | 30 | typedef struct { 31 | int type; 32 | int id; 33 | 34 | // General device info 35 | uint64_t physicalId; 36 | std::string name; 37 | uint64_t memory; 38 | int computeUnits; 39 | 40 | // CUDA device info 41 | int cudaMajor; 42 | int cudaMinor; 43 | int cudaCores; 44 | }DeviceInfo; 45 | 46 | std::vector getDevices(); 47 | 48 | } 49 | 50 | 51 | #endif -------------------------------------------------------------------------------- /KeyFinder/Makefile: -------------------------------------------------------------------------------- 1 | CPPSRC:=$(wildcard *.cpp) 2 | 3 | all: 4 | ifeq ($(BUILD_CUDA), 1) 5 | ${CXX} -DBUILD_CUDA -o cuKeyFinder.bin ${CPPSRC} ${INCLUDE} -I${CUDA_INCLUDE} ${CXXFLAGS} ${LIBS} -L${CUDA_LIB} -lkeyfinder -laddressutil -lsecp256k1 -lcryptoutil -lsecp256k1 -lcudautil -llogger -lutil -lCudaKeySearchDevice -lcudadevrt -lcudart -lcmdparse 6 | mkdir -p $(BINDIR) 7 | cp cuKeyFinder.bin $(BINDIR)/cuBitCrack 8 | endif 9 | ifeq ($(BUILD_OPENCL),1) 10 | ${CXX} -DBUILD_OPENCL -o clKeyFinder.bin ${CPPSRC} ${INCLUDE} -I${OPENCL_INCLUDE} ${CXXFLAGS} ${LIBS} -L${OPENCL_LIB} -lkeyfinder -laddressutil -lsecp256k1 -lcryptoutil -lsecp256k1 -lCLKeySearchDevice -lclutil -lOpenCL -llogger -lutil -lcmdparse 11 | mkdir -p $(BINDIR) 12 | cp clKeyFinder.bin $(BINDIR)/clBitCrack 13 | endif 14 | 15 | clean: 16 | rm -rf cuKeyFinder.bin 17 | rm -rf clKeyFinder.bin 18 | -------------------------------------------------------------------------------- /KeyFinderLib/KeyFinder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "KeyFinder.h" 5 | #include "util.h" 6 | #include "AddressUtil.h" 7 | 8 | #include "Logger.h" 9 | 10 | 11 | void KeyFinder::defaultResultCallback(KeySearchResult result) 12 | { 13 | // Do nothing 14 | } 15 | 16 | void KeyFinder::defaultStatusCallback(KeySearchStatus status) 17 | { 18 | // Do nothing 19 | } 20 | 21 | KeyFinder::KeyFinder(const secp256k1::uint256 &startKey, const secp256k1::uint256 &endKey, int compression, KeySearchDevice* device, const secp256k1::uint256 &stride) 22 | { 23 | _total = 0; 24 | _statusInterval = 1000; 25 | _device = device; 26 | 27 | _compression = compression; 28 | 29 | _startKey = startKey; 30 | 31 | _endKey = endKey; 32 | 33 | _statusCallback = NULL; 34 | 35 | _resultCallback = NULL; 36 | 37 | _iterCount = 0; 38 | 39 | _stride = stride; 40 | } 41 | 42 | KeyFinder::~KeyFinder() 43 | { 44 | } 45 | 46 | void KeyFinder::setTargets(std::vector &targets) 47 | { 48 | if(targets.size() == 0) { 49 | throw KeySearchException("Requires at least 1 target"); 50 | } 51 | 52 | _targets.clear(); 53 | 54 | // Convert each address from base58 encoded form to a 160-bit integer 55 | for(unsigned int i = 0; i < targets.size(); i++) { 56 | 57 | if(!Address::verifyAddress(targets[i])) { 58 | throw KeySearchException("Invalid address '" + targets[i] + "'"); 59 | } 60 | 61 | KeySearchTarget t; 62 | 63 | Base58::toHash160(targets[i], t.value); 64 | 65 | _targets.insert(t); 66 | } 67 | 68 | _device->setTargets(_targets); 69 | } 70 | 71 | void KeyFinder::setTargets(std::string targetsFile) 72 | { 73 | std::ifstream inFile(targetsFile.c_str()); 74 | 75 | if(!inFile.is_open()) { 76 | Logger::log(LogLevel::Error, "Unable to open '" + targetsFile + "'"); 77 | throw KeySearchException(); 78 | } 79 | 80 | _targets.clear(); 81 | 82 | std::string line; 83 | Logger::log(LogLevel::Info, "Loading addresses from '" + targetsFile + "'"); 84 | while(std::getline(inFile, line)) { 85 | util::removeNewline(line); 86 | line = util::trim(line); 87 | 88 | if(line.length() > 0) { 89 | if(!Address::verifyAddress(line)) { 90 | Logger::log(LogLevel::Error, "Invalid address '" + line + "'"); 91 | throw KeySearchException(); 92 | } 93 | 94 | KeySearchTarget t; 95 | 96 | Base58::toHash160(line, t.value); 97 | 98 | _targets.insert(t); 99 | } 100 | } 101 | Logger::log(LogLevel::Info, util::formatThousands(_targets.size()) + " addresses loaded (" 102 | + util::format("%.1f", (double)(sizeof(KeySearchTarget) * _targets.size()) / (double)(1024 * 1024)) + "MB)"); 103 | 104 | _device->setTargets(_targets); 105 | } 106 | 107 | 108 | void KeyFinder::setResultCallback(void(*callback)(KeySearchResult)) 109 | { 110 | _resultCallback = callback; 111 | } 112 | 113 | void KeyFinder::setStatusCallback(void(*callback)(KeySearchStatus)) 114 | { 115 | _statusCallback = callback; 116 | } 117 | 118 | void KeyFinder::setStatusInterval(uint64_t interval) 119 | { 120 | _statusInterval = interval; 121 | } 122 | 123 | void KeyFinder::setTargetsOnDevice() 124 | { 125 | // Set the target in constant memory 126 | std::vector targets; 127 | 128 | for(std::set::iterator i = _targets.begin(); i != _targets.end(); ++i) { 129 | targets.push_back(hash160((*i).value)); 130 | } 131 | 132 | _device->setTargets(_targets); 133 | } 134 | 135 | void KeyFinder::init() 136 | { 137 | Logger::log(LogLevel::Info, "Initializing " + _device->getDeviceName()); 138 | 139 | _device->init(_startKey, _compression, _stride); 140 | } 141 | 142 | 143 | void KeyFinder::stop() 144 | { 145 | _running = false; 146 | } 147 | 148 | void KeyFinder::removeTargetFromList(const unsigned int hash[5]) 149 | { 150 | KeySearchTarget t(hash); 151 | 152 | _targets.erase(t); 153 | } 154 | 155 | bool KeyFinder::isTargetInList(const unsigned int hash[5]) 156 | { 157 | KeySearchTarget t(hash); 158 | return _targets.find(t) != _targets.end(); 159 | } 160 | 161 | 162 | void KeyFinder::run() 163 | { 164 | uint64_t pointsPerIteration = _device->keysPerStep(); 165 | 166 | _running = true; 167 | 168 | util::Timer timer; 169 | 170 | timer.start(); 171 | 172 | uint64_t prevIterCount = 0; 173 | 174 | _totalTime = 0; 175 | 176 | while(_running) { 177 | 178 | _device->doStep(); 179 | _iterCount++; 180 | 181 | // Update status 182 | uint64_t t = timer.getTime(); 183 | 184 | if(t >= _statusInterval) { 185 | 186 | KeySearchStatus info; 187 | 188 | uint64_t count = (_iterCount - prevIterCount) * pointsPerIteration; 189 | 190 | _total += count; 191 | 192 | double seconds = (double)t / 1000.0; 193 | 194 | info.speed = (double)((double)count / seconds) / 1000000.0; 195 | 196 | info.total = _total; 197 | 198 | info.totalTime = _totalTime; 199 | 200 | uint64_t freeMem = 0; 201 | 202 | uint64_t totalMem = 0; 203 | 204 | _device->getMemoryInfo(freeMem, totalMem); 205 | 206 | info.freeMemory = freeMem; 207 | info.deviceMemory = totalMem; 208 | info.deviceName = _device->getDeviceName(); 209 | info.targets = _targets.size(); 210 | info.nextKey = getNextKey(); 211 | 212 | _statusCallback(info); 213 | 214 | timer.start(); 215 | prevIterCount = _iterCount; 216 | _totalTime += t; 217 | } 218 | 219 | std::vector results; 220 | 221 | if(_device->getResults(results) > 0) { 222 | 223 | for(unsigned int i = 0; i < results.size(); i++) { 224 | 225 | KeySearchResult info; 226 | info.privateKey = results[i].privateKey; 227 | info.publicKey = results[i].publicKey; 228 | info.compressed = results[i].compressed; 229 | info.address = Address::fromPublicKey(results[i].publicKey, results[i].compressed); 230 | 231 | _resultCallback(info); 232 | } 233 | 234 | // Remove the hashes that were found 235 | for(unsigned int i = 0; i < results.size(); i++) { 236 | removeTargetFromList(results[i].hash); 237 | } 238 | } 239 | 240 | // Stop if there are no keys left 241 | if(_targets.size() == 0) { 242 | Logger::log(LogLevel::Info, "No targets remaining"); 243 | _running = false; 244 | } 245 | 246 | // Stop if we searched the entire range 247 | if(_device->getNextKey().cmp(_endKey) >= 0 || _device->getNextKey().cmp(_startKey) < 0) { 248 | Logger::log(LogLevel::Info, "Reached end of keyspace"); 249 | _running = false; 250 | } 251 | } 252 | } 253 | 254 | secp256k1::uint256 KeyFinder::getNextKey() 255 | { 256 | return _device->getNextKey(); 257 | } -------------------------------------------------------------------------------- /KeyFinderLib/KeyFinder.h: -------------------------------------------------------------------------------- 1 | #ifndef _KEY_FINDER_H 2 | #define _KEY_FINDER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "secp256k1.h" 8 | #include "KeySearchTypes.h" 9 | #include "KeySearchDevice.h" 10 | 11 | 12 | class KeyFinder { 13 | 14 | private: 15 | 16 | KeySearchDevice *_device; 17 | 18 | unsigned int _compression; 19 | 20 | std::set _targets; 21 | 22 | uint64_t _statusInterval; 23 | 24 | secp256k1::uint256 _stride = 1; 25 | uint64_t _iterCount; 26 | uint64_t _total; 27 | uint64_t _totalTime; 28 | 29 | secp256k1::uint256 _startKey; 30 | secp256k1::uint256 _endKey; 31 | 32 | // Each index of each thread gets a flag to indicate if it found a valid hash 33 | bool _running; 34 | 35 | void(*_resultCallback)(KeySearchResult); 36 | void(*_statusCallback)(KeySearchStatus); 37 | 38 | 39 | static void defaultResultCallback(KeySearchResult result); 40 | static void defaultStatusCallback(KeySearchStatus status); 41 | 42 | void removeTargetFromList(const unsigned int value[5]); 43 | bool isTargetInList(const unsigned int value[5]); 44 | void setTargetsOnDevice(); 45 | 46 | public: 47 | 48 | KeyFinder(const secp256k1::uint256 &startKey, const secp256k1::uint256 &endKey, int compression, KeySearchDevice* device, const secp256k1::uint256 &stride); 49 | 50 | ~KeyFinder(); 51 | 52 | void init(); 53 | void run(); 54 | void stop(); 55 | 56 | void setResultCallback(void(*callback)(KeySearchResult)); 57 | void setStatusCallback(void(*callback)(KeySearchStatus)); 58 | void setStatusInterval(uint64_t interval); 59 | 60 | void setTargets(std::string targetFile); 61 | void setTargets(std::vector &targets); 62 | 63 | secp256k1::uint256 getNextKey(); 64 | }; 65 | 66 | #endif -------------------------------------------------------------------------------- /KeyFinderLib/KeyFinderLib.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {53EE0C03-4419-4767-A91B-7FC7D4B3D2AA} 15 | KeyFinderLib 16 | 10.0 17 | 18 | 19 | 20 | StaticLibrary 21 | true 22 | MultiByte 23 | v142 24 | 25 | 26 | StaticLibrary 27 | false 28 | true 29 | MultiByte 30 | v142 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | true 46 | 47 | 48 | 49 | Level4 50 | Disabled 51 | WIN32;WIN64;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 52 | $(SolutionDir)secp256k1lib;$(SolutionDir)AddressUtil;$(SolutionDir)Logger;$(SolutionDir)util;$(SolutionDir)KeySearchDevice;$(SolutionDir)clUtil;%(AdditionalIncludeDirectories) 53 | 54 | 55 | true 56 | Console 57 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 58 | 59 | 60 | 61 | 62 | Level4 63 | MaxSpeed 64 | true 65 | true 66 | WIN32;WIN64;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 67 | $(SolutionDir)secp256k1lib;$(SolutionDir)AddressUtil;$(SolutionDir)Logger;$(SolutionDir)util;$(SolutionDir)KeySearchDevice;$(SolutionDir)clUtil;%(AdditionalIncludeDirectories) 68 | 69 | 70 | true 71 | true 72 | true 73 | Console 74 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /KeyFinderLib/KeyFinderShared.h: -------------------------------------------------------------------------------- 1 | #ifndef _KEY_FINDER_SHARED_H 2 | #define _KEY_FINDER_SHARED_H 3 | 4 | namespace PointCompressionType { 5 | enum Value { 6 | COMPRESSED = 0, 7 | UNCOMPRESSED = 1, 8 | BOTH = 2 9 | }; 10 | } 11 | 12 | // Structures that exist on both host and device side 13 | struct KeyFinderDeviceResult { 14 | int thread; 15 | int block; 16 | int idx; 17 | bool compressed; 18 | unsigned int x[8]; 19 | unsigned int y[8]; 20 | unsigned int digest[5]; 21 | }; 22 | 23 | //typedef struct hash160 { 24 | // 25 | // unsigned int h[5]; 26 | // 27 | // hash160(const unsigned int hash[5]) 28 | // { 29 | // memcpy(h, hash, sizeof(unsigned int) * 5); 30 | // } 31 | //}hash160; 32 | 33 | #endif -------------------------------------------------------------------------------- /KeyFinderLib/KeySearchDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef _KEY_SEARCH_DEVICE_H 2 | #define _KEY_SEARCH_DEVICE_H 3 | 4 | #include 5 | #include 6 | #include "secp256k1.h" 7 | #include "KeySearchTypes.h" 8 | 9 | 10 | class KeySearchException { 11 | 12 | public: 13 | 14 | KeySearchException() 15 | { 16 | 17 | } 18 | 19 | KeySearchException(const std::string &msg) 20 | { 21 | this->msg = msg; 22 | } 23 | 24 | std::string msg; 25 | }; 26 | 27 | 28 | typedef struct { 29 | std::string address; 30 | secp256k1::ecpoint publicKey; 31 | secp256k1::uint256 privateKey; 32 | unsigned int hash[5]; 33 | bool compressed; 34 | }KeySearchResult; 35 | 36 | // Pure virtual class representing a device that performs a key search 37 | class KeySearchDevice { 38 | 39 | public: 40 | 41 | // Initialize the device 42 | virtual void init(const secp256k1::uint256 &start, int compression, const secp256k1::uint256 &stride) = 0; 43 | 44 | // Perform one iteration 45 | virtual void doStep() = 0; 46 | 47 | // Tell the device which addresses to search for 48 | virtual void setTargets(const std::set &targets) = 0; 49 | 50 | // Get the private keys that have been found so far 51 | virtual size_t getResults(std::vector &results) = 0; 52 | 53 | // The number of keys searched at each step 54 | virtual uint64_t keysPerStep() = 0; 55 | 56 | // The name of the device 57 | virtual std::string getDeviceName() = 0; 58 | 59 | // Memory information for this device 60 | virtual void getMemoryInfo(uint64_t &freeMem, uint64_t &totalMem) = 0; 61 | 62 | virtual secp256k1::uint256 getNextKey() = 0; 63 | }; 64 | 65 | #endif -------------------------------------------------------------------------------- /KeyFinderLib/KeySearchTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef _KEY_FINDER_TYPES 2 | #define _KEY_FINDER_TYPES 3 | 4 | #include 5 | #include 6 | #include "secp256k1.h" 7 | 8 | namespace PointCompressionType { 9 | enum Value { 10 | COMPRESSED = 0, 11 | UNCOMPRESSED = 1, 12 | BOTH = 2 13 | }; 14 | } 15 | 16 | typedef struct hash160 { 17 | 18 | unsigned int h[5]; 19 | 20 | hash160(const unsigned int hash[5]) 21 | { 22 | memcpy(h, hash, sizeof(unsigned int) * 5); 23 | } 24 | }hash160; 25 | 26 | 27 | typedef struct { 28 | int device; 29 | double speed; 30 | uint64_t total; 31 | uint64_t totalTime; 32 | std::string deviceName; 33 | uint64_t freeMemory; 34 | uint64_t deviceMemory; 35 | uint64_t targets; 36 | secp256k1::uint256 nextKey; 37 | }KeySearchStatus; 38 | 39 | 40 | class KeySearchTarget { 41 | 42 | public: 43 | unsigned int value[5]; 44 | 45 | KeySearchTarget() 46 | { 47 | memset(value, 0, sizeof(value)); 48 | } 49 | 50 | KeySearchTarget(const unsigned int h[5]) 51 | { 52 | for(int i = 0; i < 5; i++) { 53 | value[i] = h[i]; 54 | } 55 | } 56 | 57 | 58 | bool operator==(const KeySearchTarget &t) const 59 | { 60 | for(int i = 0; i < 5; i++) { 61 | if(value[i] != t.value[i]) { 62 | return false; 63 | } 64 | } 65 | 66 | return true; 67 | } 68 | 69 | bool operator<(const KeySearchTarget &t) const 70 | { 71 | for(int i = 0; i < 5; i++) { 72 | if(value[i] < t.value[i]) { 73 | return true; 74 | } else if(value[i] > t.value[i]) { 75 | return false; 76 | } 77 | } 78 | 79 | return false; 80 | } 81 | 82 | bool operator>(const KeySearchTarget &t) const 83 | { 84 | for(int i = 0; i < 5; i++) { 85 | if(value[i] > t.value[i]) { 86 | return true; 87 | } else if(value[i] < t.value[i]) { 88 | return false; 89 | } 90 | } 91 | 92 | return false; 93 | } 94 | }; 95 | 96 | #endif -------------------------------------------------------------------------------- /KeyFinderLib/Makefile: -------------------------------------------------------------------------------- 1 | NAME=keyfinder 2 | CPPSRC:=$(wildcard *.cpp) 3 | 4 | all: cuda 5 | 6 | cuda: 7 | for file in ${CPPSRC} ; do\ 8 | ${CXX} -c $$file ${INCLUDE} -I${CUDA_INCLUDE} ${CXXFLAGS};\ 9 | done 10 | 11 | ar rvs ${LIBDIR}/lib$(NAME).a *.o 12 | 13 | clean: 14 | rm -f *.o *.cu.o 15 | rm -f *.a 16 | -------------------------------------------------------------------------------- /LICENSE.MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Ben Richard https://github.com/brichard19 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /Logger/Logger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Logger.h" 5 | #include "util.h" 6 | 7 | bool LogLevel::isValid(int level) 8 | { 9 | switch(level) { 10 | case Info: 11 | case Error: 12 | case Debug: 13 | return true; 14 | default: 15 | return false; 16 | } 17 | } 18 | 19 | std::string LogLevel::toString(int level) 20 | { 21 | switch(level) { 22 | case Info: 23 | return "Info"; 24 | case Error: 25 | return "Error"; 26 | case Debug: 27 | return "Debug"; 28 | case Warning: 29 | return "Warning"; 30 | } 31 | 32 | return ""; 33 | } 34 | 35 | std::string Logger::getDateTimeString() 36 | { 37 | time_t now = time(0); 38 | struct tm tstruct; 39 | char buf[80]; 40 | tstruct = *localtime(&now); 41 | 42 | strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct); 43 | 44 | return std::string(buf); 45 | } 46 | 47 | std::string Logger::formatLog(int logLevel, std::string msg) 48 | { 49 | std::string dateTime = getDateTimeString(); 50 | 51 | std::string prefix = "[" + dateTime + "] [" + LogLevel::toString(logLevel) + "] "; 52 | 53 | size_t prefixLen = prefix.length(); 54 | 55 | std::string padding(prefixLen, ' '); 56 | 57 | if(msg.find('\n', 0) != std::string::npos) { 58 | size_t pos = 0; 59 | size_t prev = 0; 60 | 61 | while((pos = msg.find('\n', prev)) != std::string::npos) { 62 | prefix += msg.substr(prev, pos - prev) + "\n" + padding; 63 | prev = pos + 1; 64 | } 65 | 66 | prefix += msg.substr(prev); 67 | } else { 68 | prefix += msg; 69 | } 70 | 71 | return prefix; 72 | } 73 | 74 | 75 | void Logger::log(int logLevel, std::string msg) 76 | { 77 | std::string str = formatLog(logLevel, msg); 78 | 79 | fprintf(stderr, "%s\n", str.c_str()); 80 | } 81 | 82 | void Logger::setLogFile(std::string path) 83 | { 84 | 85 | } 86 | -------------------------------------------------------------------------------- /Logger/Logger.h: -------------------------------------------------------------------------------- 1 | #ifndef _LOGGER_H 2 | #define _LOGGER_H 3 | 4 | #include 5 | 6 | 7 | namespace LogLevel { 8 | enum Level { 9 | Info = 1, 10 | Error = 2, 11 | Debug = 4, 12 | Warning = 8 13 | }; 14 | 15 | bool isValid(int level); 16 | 17 | std::string toString(int level); 18 | }; 19 | 20 | 21 | class Logger { 22 | 23 | private: 24 | static std::string _logFile; 25 | 26 | static std::string formatLog(int logLevel, std::string msg); 27 | 28 | static std::string getDateTimeString(); 29 | 30 | public: 31 | 32 | Logger() 33 | { 34 | } 35 | 36 | static void log(int logLevel, std::string msg); 37 | 38 | static void setLogFile(std::string path); 39 | }; 40 | 41 | #endif -------------------------------------------------------------------------------- /Logger/Logger.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | {93b89bf6-32b9-4eba-aa44-bcfec4836b76} 30 | 31 | 32 | 33 | {150AF404-1F80-4A13-855B-4383C4A3326F} 34 | Win32Proj 35 | Logger 36 | 10.0 37 | 38 | 39 | 40 | StaticLibrary 41 | true 42 | v141 43 | Unicode 44 | 45 | 46 | StaticLibrary 47 | false 48 | v141 49 | true 50 | Unicode 51 | 52 | 53 | StaticLibrary 54 | true 55 | v142 56 | Unicode 57 | 58 | 59 | StaticLibrary 60 | false 61 | v142 62 | true 63 | Unicode 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | Level3 93 | Disabled 94 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 95 | $(SolutionDir)Util;%(AdditionalIncludeDirectories) 96 | 97 | 98 | Windows 99 | 100 | 101 | 102 | 103 | NotUsing 104 | Level3 105 | Disabled 106 | _DEBUG;_LIB;%(PreprocessorDefinitions) 107 | $(SolutionDir)Util;%(AdditionalIncludeDirectories) 108 | 109 | 110 | Windows 111 | 112 | 113 | 114 | 115 | Level3 116 | 117 | 118 | MaxSpeed 119 | true 120 | true 121 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 122 | $(SolutionDir)Util;%(AdditionalIncludeDirectories) 123 | 124 | 125 | Windows 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | NotUsing 134 | MaxSpeed 135 | true 136 | true 137 | NDEBUG;_LIB;%(PreprocessorDefinitions) 138 | $(SolutionDir)Util;%(AdditionalIncludeDirectories) 139 | 140 | 141 | Windows 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /Logger/Makefile: -------------------------------------------------------------------------------- 1 | NAME=logger 2 | SRC=$(wildcard *.cpp) 3 | OBJS=$(SRC:.cpp=.o) 4 | 5 | all: ${SRC} 6 | for file in ${SRC} ; do\ 7 | ${CXX} -c $$file ${INCLUDE} ${CXXFLAGS};\ 8 | done 9 | mkdir -p ${LIBDIR} 10 | ar rvs ${LIBDIR}/lib$(NAME).a ${OBJS} 11 | 12 | clean: 13 | rm -rf *.o 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | CUR_DIR=$(shell pwd) 3 | DIRS=util AddressUtil CmdParse CryptoUtil KeyFinderLib CLKeySearchDevice CudaKeySearchDevice cudaMath clUtil cudaUtil secp256k1lib Logger embedcl 4 | 5 | INCLUDE = $(foreach d, $(DIRS), -I$(CUR_DIR)/$d) 6 | 7 | LIBDIR=$(CUR_DIR)/lib 8 | BINDIR=$(CUR_DIR)/bin 9 | LIBS+=-L$(LIBDIR) 10 | 11 | # C++ options 12 | CXX=g++ 13 | CXXFLAGS=-O2 -std=c++11 14 | 15 | # CUDA variables 16 | COMPUTE_CAP=30 17 | NVCC=nvcc 18 | NVCCFLAGS=-std=c++11 -gencode=arch=compute_${COMPUTE_CAP},code=\"sm_${COMPUTE_CAP}\" -Xptxas="-v" -Xcompiler "${CXXFLAGS}" 19 | CUDA_HOME=/usr/local/cuda 20 | CUDA_LIB=${CUDA_HOME}/lib64 21 | CUDA_INCLUDE=${CUDA_HOME}/include 22 | CUDA_MATH=$(CUR_DIR)/cudaMath 23 | 24 | # OpenCL variables 25 | OPENCL_LIB=${CUDA_LIB} 26 | OPENCL_INCLUDE=${CUDA_INCLUDE} 27 | OPENCL_VERSION=110 28 | 29 | export INCLUDE 30 | export LIBDIR 31 | export BINDIR 32 | export NVCC 33 | export NVCCFLAGS 34 | export LIBS 35 | export CXX 36 | export CXXFLAGS 37 | export CUDA_LIB 38 | export CUDA_INCLUDE 39 | export CUDA_MATH 40 | export OPENCL_LIB 41 | export OPENCL_INCLUDE 42 | export BUILD_OPENCL 43 | export BUILD_CUDA 44 | 45 | TARGETS=dir_addressutil dir_cmdparse dir_cryptoutil dir_keyfinderlib dir_keyfinder dir_secp256k1lib dir_util dir_logger dir_addrgen 46 | 47 | ifeq ($(BUILD_CUDA),1) 48 | TARGETS:=${TARGETS} dir_cudaKeySearchDevice dir_cudautil 49 | endif 50 | 51 | ifeq ($(BUILD_OPENCL),1) 52 | TARGETS:=${TARGETS} dir_embedcl dir_clKeySearchDevice dir_clutil dir_clunittest 53 | CXXFLAGS:=${CXXFLAGS} -DCL_TARGET_OPENCL_VERSION=${OPENCL_VERSION} 54 | endif 55 | 56 | all: ${TARGETS} 57 | 58 | dir_cudaKeySearchDevice: dir_keyfinderlib dir_cudautil dir_logger 59 | make --directory CudaKeySearchDevice 60 | 61 | dir_clKeySearchDevice: dir_embedcl dir_keyfinderlib dir_clutil dir_logger 62 | make --directory CLKeySearchDevice 63 | 64 | dir_embedcl: 65 | make --directory embedcl 66 | 67 | dir_addressutil: dir_util dir_secp256k1lib dir_cryptoutil 68 | make --directory AddressUtil 69 | 70 | dir_cmdparse: 71 | make --directory CmdParse 72 | 73 | dir_cryptoutil: 74 | make --directory CryptoUtil 75 | 76 | dir_keyfinderlib: dir_util dir_secp256k1lib dir_cryptoutil dir_addressutil dir_logger 77 | make --directory KeyFinderLib 78 | 79 | KEYFINDER_DEPS=dir_keyfinderlib 80 | 81 | ifeq ($(BUILD_CUDA), 1) 82 | KEYFINDER_DEPS:=$(KEYFINDER_DEPS) dir_cudaKeySearchDevice 83 | endif 84 | 85 | ifeq ($(BUILD_OPENCL),1) 86 | KEYFINDER_DEPS:=$(KEYFINDER_DEPS) dir_clKeySearchDevice 87 | endif 88 | 89 | dir_keyfinder: $(KEYFINDER_DEPS) 90 | make --directory KeyFinder 91 | 92 | dir_cudautil: 93 | make --directory cudaUtil 94 | 95 | dir_clutil: 96 | make --directory clUtil 97 | 98 | dir_secp256k1lib: dir_cryptoutil 99 | make --directory secp256k1lib 100 | 101 | dir_util: 102 | make --directory util 103 | 104 | dir_cudainfo: 105 | make --directory cudaInfo 106 | 107 | dir_logger: 108 | make --directory Logger 109 | 110 | dir_addrgen: dir_cmdparse dir_addressutil dir_secp256k1lib 111 | make --directory AddrGen 112 | dir_clunittest: dir_clutil 113 | make --directory CLUnitTests 114 | 115 | clean: 116 | make --directory AddressUtil clean 117 | make --directory CmdParse clean 118 | make --directory CryptoUtil clean 119 | make --directory KeyFinderLib clean 120 | make --directory KeyFinder clean 121 | make --directory cudaUtil clean 122 | make --directory secp256k1lib clean 123 | make --directory util clean 124 | make --directory cudaInfo clean 125 | make --directory Logger clean 126 | make --directory clUtil clean 127 | make --directory CLKeySearchDevice clean 128 | make --directory CudaKeySearchDevice clean 129 | make --directory embedcl clean 130 | make --directory CLUnitTests clean 131 | rm -rf ${LIBDIR} 132 | rm -rf ${BINDIR} 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BitCrack 2 | 3 | A tool for brute-forcing Bitcoin private keys. The main purpose of this project is to contribute to the effort of solving the [Bitcoin puzzle transaction](https://blockchain.info/tx/08389f34c98c606322740c0be6a7125d9860bb8d5cb182c02f98461e5fa6cd15): A transaction with 32 addresses that become increasingly difficult to crack. 4 | 5 | 6 | ### Using BitCrack 7 | 8 | #### Usage 9 | 10 | 11 | Use `cuBitCrack.exe` for CUDA devices and `clBitCrack.exe` for OpenCL devices. 12 | 13 | ### Note: **clBitCrack.exe is still EXPERIMENTAL**, as users have reported critial bugs when running on some AMD and Intel devices. 14 | 15 | **Note for Intel users:** 16 | 17 | There is bug in Intel's OpenCL implementation which affects BitCrack. Details here: https://github.com/brichard19/BitCrack/issues/123 18 | 19 | 20 | ``` 21 | xxBitCrack.exe [OPTIONS] [TARGETS] 22 | 23 | Where [TARGETS] are one or more Bitcoin address 24 | 25 | Options: 26 | 27 | -i, --in FILE 28 | Read addresses from FILE, one address per line. If FILE is "-" then stdin is read 29 | 30 | -o, --out FILE 31 | Append private keys to FILE, one per line 32 | 33 | -d, --device N 34 | Use device with ID equal to N 35 | 36 | -b, --blocks BLOCKS 37 | The number of CUDA blocks 38 | 39 | -t, --threads THREADS 40 | Threads per block 41 | 42 | -p, --points NUMBER 43 | Each thread will process NUMBER keys at a time 44 | 45 | --keyspace KEYSPACE 46 | Specify the range of keys to search, where KEYSPACE is in the format, 47 | 48 | START:END start at key START, end at key END 49 | START:+COUNT start at key START and end at key START + COUNT 50 | :END start at key 1 and end at key END 51 | :+COUNT start at key 1 and end at key 1 + COUNT 52 | 53 | -c, --compressed 54 | Search for compressed keys (default). Can be used with -u to also search uncompressed keys 55 | 56 | -u, --uncompressed 57 | Search for uncompressed keys, can be used with -c to search compressed keys 58 | 59 | --compression MODE 60 | Specify the compression mode, where MODE is 'compressed' or 'uncompressed' or 'both' 61 | 62 | --list-devices 63 | List available devices 64 | 65 | --stride NUMBER 66 | Increment by NUMBER 67 | 68 | --share M/N 69 | Divide the keyspace into N equal sized shares, process the Mth share 70 | 71 | --continue FILE 72 | Save/load progress from FILE 73 | ``` 74 | 75 | #### Examples 76 | 77 | The simplest usage, the keyspace will begin at 0, and the CUDA parameters will be chosen automatically 78 | ``` 79 | xxBitCrack.exe 1FshYsUh3mqgsG29XpZ23eLjWV8Ur3VwH 80 | ``` 81 | 82 | Multiple keys can be searched at once with minimal impact to performance. Provide the keys on the command line, or in a file with one address per line 83 | ``` 84 | xxBitCrack.exe 1FshYsUh3mqgsG29XpZ23eLjWV8Ur3VwH 15JhYXn6Mx3oF4Y7PcTAv2wVVAuCFFQNiP 19EEC52krRUK1RkUAEZmQdjTyHT7Gp1TYT 85 | ``` 86 | 87 | To start the search at a specific private key, use the `--keyspace` option: 88 | 89 | ``` 90 | xxBitCrack.exe --keyspace 766519C977831678F0000000000 1FshYsUh3mqgsG29XpZ23eLjWV8Ur3VwH 91 | ``` 92 | 93 | The `--keyspace` option can also be used to search a specific range: 94 | 95 | ``` 96 | xxBitCrack.exe --keyspace 80000000:ffffffff 1FshYsUh3mqgsG29XpZ23eLjWV8Ur3VwH 97 | ``` 98 | 99 | To periodically save progress, the `--continue` option can be used. This is useful for recovering 100 | after an unexpected interruption: 101 | 102 | ``` 103 | xxBitCrack.exe --keyspace 80000000:ffffffff 1FshYsUh3mqgsG29XpZ23eLjWV8Ur3VwH 104 | ... 105 | GeForce GT 640 224/1024MB | 1 target 10.33 MKey/s (1,244,659,712 total) [00:01:58] 106 | ^C 107 | xxBitCrack.exe --keyspace 80000000:ffffffff 1FshYsUh3mqgsG29XpZ23eLjWV8Ur3VwH 108 | ... 109 | GeForce GT 640 224/1024MB | 1 target 10.33 MKey/s (1,357,905,920 total) [00:02:12] 110 | ``` 111 | 112 | 113 | Use the `-b,` `-t` and `-p` options to specify the number of blocks, threads per block, and keys per thread. 114 | ``` 115 | xxBitCrack.exe -b 32 -t 256 -p 16 1FshYsUh3mqgsG29XpZ23eLjWV8Ur3VwH 116 | ``` 117 | 118 | ### Choosing the right parameters for your device 119 | 120 | GPUs have many cores. Work for the cores is divided into blocks. Each block contains threads. 121 | 122 | There are 3 parameters that affect performance: blocks, threads per block, and keys per thread. 123 | 124 | 125 | `blocks:` Should be a multiple of the number of compute units on the device. The default is 32. 126 | 127 | `threads:` The number of threads in a block. This must be a multiple of 32. The default is 256. 128 | 129 | `Keys per thread:` The number of keys each thread will process. The performance (keys per second) 130 | increases asymptotically with this value. The default is256. Increasing this value will cause the 131 | kernel to run longer, but more keys will be processed. 132 | 133 | 134 | ### Build dependencies 135 | 136 | Visual Studio 2019 (if on Windows) 137 | 138 | For CUDA: CUDA Toolkit 10.1 139 | 140 | For OpenCL: An OpenCL SDK (The CUDA toolkit contains an OpenCL SDK). 141 | 142 | 143 | ### Building in Windows 144 | 145 | Open the Visual Studio solution. 146 | 147 | Build the `clKeyFinder` project for an OpenCL build. 148 | 149 | Build the `cuKeyFinder` project for a CUDA build. 150 | 151 | Note: By default the NVIDIA OpenCL headers are used. You can set the header and library path for 152 | OpenCL in the `BitCrack.props` property sheet. 153 | 154 | ### Building in Linux 155 | 156 | Using `make`: 157 | 158 | Build CUDA: 159 | ``` 160 | make BUILD_CUDA=1 161 | ``` 162 | 163 | Build OpenCL: 164 | ``` 165 | make BUILD_OPENCL=1 166 | ``` 167 | 168 | Or build both: 169 | ``` 170 | make BUILD_CUDA=1 BUILD_OPENCL=1 171 | ``` 172 | 173 | ### Supporting this project 174 | 175 | If you find this project useful and would like to support it, consider making a donation. Your support is greatly appreciated! 176 | 177 | **BTC**: `1LqJ9cHPKxPXDRia4tteTJdLXnisnfHsof` 178 | 179 | **LTC**: `LfwqkJY7YDYQWqgR26cg2T1F38YyojD67J` 180 | 181 | **ETH**: `0xd28082CD48E1B279425346E8f6C651C45A9023c5` 182 | 183 | ### Contact 184 | 185 | Send any questions or comments to bitcrack.project@gmail.com 186 | -------------------------------------------------------------------------------- /clMath/clMath.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {83327841-C283-4D46-A873-97AC674C68AC} 24 | clMath 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v141 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v141 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v142 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Level3 76 | MaxSpeed 77 | true 78 | true 79 | true 80 | true 81 | 82 | 83 | true 84 | true 85 | 86 | 87 | 88 | 89 | Level3 90 | Disabled 91 | true 92 | true 93 | 94 | 95 | 96 | 97 | Level3 98 | Disabled 99 | true 100 | true 101 | 102 | 103 | 104 | 105 | Level3 106 | MaxSpeed 107 | true 108 | true 109 | true 110 | true 111 | 112 | 113 | true 114 | true 115 | 116 | 117 | 118 | 119 | Document 120 | 121 | 122 | Document 123 | 124 | 125 | Document 126 | 127 | 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /clUtil/Makefile: -------------------------------------------------------------------------------- 1 | NAME=clutil 2 | SRC=$(wildcard *.cpp) 3 | OBJS=$(SRC:.cpp=.o) 4 | 5 | all: ${SRC} 6 | for file in ${SRC} ; do\ 7 | ${CXX} -c $$file ${INCLUDE} -I${OPENCL_INCLUDE} ${CXXFLAGS};\ 8 | done 9 | mkdir -p ${LIBDIR} 10 | ar rvs ${LIBDIR}/lib$(NAME).a ${OBJS} 11 | 12 | clean: 13 | rm -rf *.o -------------------------------------------------------------------------------- /clUtil/clContext.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "clContext.h" 8 | #include "util.h" 9 | 10 | cl::CLContext::CLContext(cl_device_id device) 11 | { 12 | _device = device; 13 | 14 | cl_int err; 15 | _ctx = clCreateContext(0, 1, &_device, NULL, NULL, &err); 16 | clCall(err); 17 | 18 | _queue = clCreateCommandQueue(_ctx, _device, 0, &err); 19 | clCall(err); 20 | } 21 | 22 | cl::CLContext::~CLContext() 23 | { 24 | clReleaseCommandQueue(_queue); 25 | clReleaseContext(_ctx); 26 | } 27 | 28 | cl_device_id cl::CLContext::getDevice() 29 | { 30 | return _device; 31 | } 32 | 33 | cl_command_queue cl::CLContext::getQueue() 34 | { 35 | return _queue; 36 | } 37 | 38 | cl_context cl::CLContext::getContext() 39 | { 40 | return _ctx; 41 | } 42 | 43 | cl_mem cl::CLContext::malloc(size_t size, cl_mem_flags flags) 44 | { 45 | cl_int err = 0; 46 | cl_mem ptr = clCreateBuffer(_ctx, flags, size, NULL, &err); 47 | clCall(err); 48 | this->memset(ptr, 0, size); 49 | return ptr; 50 | } 51 | 52 | void cl::CLContext::free(cl_mem mem) 53 | { 54 | clReleaseMemObject(mem); 55 | } 56 | 57 | void cl::CLContext::copyHostToDevice(const void *hostPtr, cl_mem devicePtr, size_t size) 58 | { 59 | clCall(clEnqueueWriteBuffer(_queue, devicePtr, CL_TRUE, 0, size, hostPtr, 0, NULL, NULL)); 60 | } 61 | 62 | void cl::CLContext::copyHostToDevice(const void *hostPtr, cl_mem devicePtr, size_t offset, size_t size) 63 | { 64 | clCall(clEnqueueWriteBuffer(_queue, devicePtr, CL_TRUE, offset, size, hostPtr, 0, NULL, NULL)); 65 | } 66 | 67 | void cl::CLContext::copyDeviceToHost(cl_mem devicePtr, void *hostPtr, size_t size) 68 | { 69 | clCall(clEnqueueReadBuffer(_queue, devicePtr, CL_TRUE, 0, size, hostPtr, 0, NULL, NULL)); 70 | } 71 | 72 | void cl::CLContext::copyBuffer(cl_mem src_buffer, size_t src_offset, cl_mem dst_buffer, size_t dst_offset, size_t size) 73 | { 74 | clCall(clEnqueueCopyBuffer(_queue, src_buffer, dst_buffer, src_offset, dst_offset, size, NULL, NULL, NULL)); 75 | } 76 | 77 | void cl::CLContext::memset(cl_mem devicePtr, unsigned char value, size_t size) 78 | { 79 | #if CL_TARGET_OPENCL_VERSION >= 120 80 | clCall(clEnqueueFillBuffer(_queue, devicePtr, &value, sizeof(unsigned char), 0, size, NULL, NULL, NULL)); 81 | #else 82 | unsigned char *ptr = new unsigned char[size]; 83 | std::memset(ptr, value, size); 84 | copyHostToDevice(ptr, devicePtr, 0, size); 85 | delete[] ptr; 86 | #endif 87 | } 88 | 89 | cl::CLProgram::CLProgram(cl::CLContext &ctx, std::string srcFile, std::string options) : _ctx(ctx) 90 | { 91 | std::string src = loadSource(srcFile); 92 | const char *ptr = src.c_str(); 93 | size_t len = src.length(); 94 | cl_int err; 95 | 96 | if(util::toLower(_ctx.getDeviceVendor()).find("intel") != std::string::npos) { 97 | options += "-DDEVICE_VENDOR_INTEL"; 98 | } 99 | 100 | _prog = clCreateProgramWithSource(ctx.getContext(), 1, &ptr, &len, &err); 101 | clCall(err); 102 | 103 | err = clBuildProgram(_prog, 0, NULL, options.c_str(), NULL, NULL); 104 | 105 | if(err == CL_BUILD_PROGRAM_FAILURE) { 106 | size_t logSize; 107 | clGetProgramBuildInfo(_prog, ctx.getDevice(), CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize); 108 | 109 | char *log = new char[logSize]; 110 | clGetProgramBuildInfo(_prog, ctx.getDevice(), CL_PROGRAM_BUILD_LOG, logSize, log, NULL); 111 | 112 | _buildLog = std::string(log, logSize); 113 | delete[] log; 114 | 115 | throw CLException(err, _buildLog); 116 | } 117 | clCall(err); 118 | } 119 | 120 | cl::CLProgram::CLProgram(cl::CLContext &ctx, const char *src, std::string options) : _ctx(ctx) 121 | { 122 | size_t len = strlen(src); 123 | cl_int err; 124 | 125 | if(util::toLower(_ctx.getDeviceVendor()).find("intel") != std::string::npos) { 126 | options += " -DDEVICE_VENDOR_INTEL"; 127 | } 128 | 129 | _prog = clCreateProgramWithSource(ctx.getContext(), 1, &src, &len, &err); 130 | clCall(err); 131 | 132 | err = clBuildProgram(_prog, 0, NULL, options.c_str(), NULL, NULL); 133 | 134 | if(err == CL_BUILD_PROGRAM_FAILURE) { 135 | size_t logSize; 136 | clGetProgramBuildInfo(_prog, ctx.getDevice(), CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize); 137 | 138 | char *log = new char[logSize]; 139 | clGetProgramBuildInfo(_prog, ctx.getDevice(), CL_PROGRAM_BUILD_LOG, logSize, log, NULL); 140 | 141 | _buildLog = std::string(log, logSize); 142 | delete[] log; 143 | 144 | throw CLException(err, _buildLog); 145 | } 146 | clCall(err); 147 | } 148 | 149 | std::string cl::CLProgram::loadSource(std::string srcFile) 150 | { 151 | std::ifstream f(srcFile); 152 | if(!f.good()) { 153 | throw CLException(CL_BUILD_PROGRAM_FAILURE, "'" + srcFile + "' not found"); 154 | } 155 | 156 | std::stringstream buf; 157 | buf << f.rdbuf(); 158 | 159 | return buf.str(); 160 | } 161 | 162 | cl_program cl::CLProgram::getProgram() 163 | { 164 | return _prog; 165 | } 166 | 167 | cl::CLContext& cl::CLProgram::getContext() 168 | { 169 | return _ctx; 170 | } 171 | 172 | uint64_t cl::CLContext::getGlobalMemorySize() 173 | { 174 | cl_ulong mem; 175 | clCall(clGetDeviceInfo(_device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(mem), &mem, NULL)); 176 | 177 | return mem; 178 | } 179 | 180 | std::string cl::CLContext::getDeviceName() 181 | { 182 | char name[128] = {0}; 183 | 184 | clCall(clGetDeviceInfo(_device, CL_DEVICE_NAME, sizeof(name), name, NULL)); 185 | 186 | return std::string(name); 187 | } 188 | 189 | std::string cl::CLContext::getDeviceVendor() 190 | { 191 | char name[128] = { 0 }; 192 | 193 | clCall(clGetDeviceInfo(_device, CL_DEVICE_VENDOR, sizeof(name), name, NULL)); 194 | 195 | return std::string(name); 196 | } 197 | 198 | int cl::CLContext::get_mp_count() 199 | { 200 | size_t count = 1; 201 | 202 | clCall(clGetDeviceInfo(_device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(count), &count, NULL)); 203 | 204 | return (int)count; 205 | } 206 | 207 | // TODO: This is for 1 dimension only 208 | int cl::CLContext::get_max_block_size() 209 | { 210 | size_t count[3] = { 1,1,1 }; 211 | size_t max_items = 1; 212 | 213 | clCall(clGetDeviceInfo(_device, CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(count), &count, NULL)); 214 | 215 | clCall(clGetDeviceInfo(_device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(max_items), &max_items, NULL)); 216 | 217 | return (int)std::min(count[0], max_items); 218 | } 219 | 220 | cl::CLProgram::~CLProgram() 221 | { 222 | clReleaseProgram(_prog); 223 | } 224 | 225 | 226 | cl::CLKernel::CLKernel(cl::CLProgram &prog, std::string entry) : _prog(prog) 227 | { 228 | _entry = entry; 229 | const char *ptr = entry.c_str(); 230 | cl_int err; 231 | _kernel = clCreateKernel(_prog.getProgram(), ptr, &err); 232 | clCall(err); 233 | } 234 | 235 | size_t cl::CLKernel::getWorkGroupSize() 236 | { 237 | size_t size = 0; 238 | 239 | cl_int err = clGetKernelWorkGroupInfo(_kernel, _prog.getContext().getDevice(), CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &size, NULL); 240 | 241 | clCall(err); 242 | 243 | return size; 244 | } 245 | 246 | cl::CLKernel::~CLKernel() 247 | { 248 | clReleaseKernel(_kernel); 249 | } -------------------------------------------------------------------------------- /clUtil/clUtil.cpp: -------------------------------------------------------------------------------- 1 | #include "clutil.h" 2 | 3 | 4 | void cl::clCall(cl_int err) 5 | { 6 | if(err != CL_SUCCESS) { 7 | throw cl::CLException(err); 8 | } 9 | } 10 | 11 | 12 | std::vector cl::getDevices() 13 | { 14 | std::vector deviceList; 15 | 16 | cl_uint platformCount = 0; 17 | 18 | clCall(clGetPlatformIDs(0, NULL, &platformCount)); 19 | 20 | if(platformCount == 0) { 21 | return deviceList; 22 | } 23 | 24 | cl_platform_id* platforms = new cl_platform_id[platformCount]; 25 | 26 | clCall(clGetPlatformIDs(platformCount, platforms, NULL)); 27 | 28 | for(cl_uint i = 0; i < platformCount; i++) { 29 | 30 | cl_uint deviceCount = 0; 31 | clCall(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount)); 32 | 33 | if(deviceCount == 0) { 34 | continue; 35 | } 36 | 37 | cl_device_id* devices = new cl_device_id[deviceCount]; 38 | clCall(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL)); 39 | 40 | for(cl_uint j = 0; j < deviceCount; j++) { 41 | char buf[256] = {0}; 42 | 43 | cl::CLDeviceInfo info; 44 | size_t size; 45 | // Get device name 46 | clCall(clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(buf), buf, &size)); 47 | 48 | info.name = std::string(buf, size); 49 | 50 | int cores = 0; 51 | clCall(clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cores), &cores, NULL)); 52 | 53 | info.cores = cores; 54 | 55 | cl_ulong mem; 56 | clCall(clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(mem), &mem, NULL)); 57 | 58 | info.mem = (uint64_t)mem; 59 | info.id = devices[j]; 60 | deviceList.push_back(info); 61 | } 62 | 63 | delete devices; 64 | } 65 | 66 | delete platforms; 67 | 68 | return deviceList; 69 | } -------------------------------------------------------------------------------- /clUtil/clUtil.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {D9A5823D-C472-40AC-B23A-21B1586CEEB0} 24 | clUtil 25 | 10.0 26 | 27 | 28 | 29 | StaticLibrary 30 | true 31 | v141 32 | MultiByte 33 | 34 | 35 | StaticLibrary 36 | false 37 | v141 38 | true 39 | MultiByte 40 | 41 | 42 | StaticLibrary 43 | true 44 | v142 45 | MultiByte 46 | 47 | 48 | StaticLibrary 49 | false 50 | v142 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | Level3 80 | MaxSpeed 81 | true 82 | true 83 | true 84 | true 85 | $(OPENCL_INCLUDE);$(SolutionDir)\util;%(AdditionalIncludeDirectories) 86 | 87 | 88 | true 89 | true 90 | 91 | 92 | 93 | 94 | Level3 95 | Disabled 96 | true 97 | true 98 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\include;%(AdditionalIncludeDirectories) 99 | 100 | 101 | 102 | 103 | Level3 104 | Disabled 105 | true 106 | true 107 | $(OPENCL_INCLUDE);$(SolutionDir)\util;%(AdditionalIncludeDirectories) 108 | 109 | 110 | 111 | 112 | Level3 113 | MaxSpeed 114 | true 115 | true 116 | true 117 | true 118 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\include;%(AdditionalIncludeDirectories) 119 | 120 | 121 | true 122 | true 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /clUtil/clerrors.cpp: -------------------------------------------------------------------------------- 1 | #include "clutil.h" 2 | 3 | 4 | std::string cl::getErrorString(cl_int err) 5 | { 6 | switch(err) { 7 | case 0: return "CL_SUCCESS"; 8 | case -1: return "CL_DEVICE_NOT_FOUND"; 9 | case -2: return "CL_DEVICE_NOT_AVAILABLE"; 10 | case -3: return "CL_COMPILER_NOT_AVAILABLE"; 11 | case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE"; 12 | case -5: return "CL_OUT_OF_RESOURCES"; 13 | case -6: return "CL_OUT_OF_HOST_MEMORY"; 14 | case -7: return "CL_PROFILING_INFO_NOT_AVAILABLE"; 15 | case -8: return "CL_MEM_COPY_OVERLAP"; 16 | case -9: return "CL_IMAGE_FORMAT_MISMATCH"; 17 | case -10: return "CL_IMAGE_FORMAT_NOT_SUPPORTED"; 18 | case -11: return "CL_BUILD_PROGRAM_FAILURE"; 19 | case -12: return "CL_MAP_FAILURE"; 20 | case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET"; 21 | case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST"; 22 | case -15: return "CL_COMPILE_PROGRAM_FAILURE"; 23 | case -16: return "CL_LINKER_NOT_AVAILABLE"; 24 | case -17: return "CL_LINK_PROGRAM_FAILURE"; 25 | case -18: return "CL_DEVICE_PARTITION_FAILED"; 26 | case -19: return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE"; 27 | case -30: return "CL_INVALID_VALUE"; 28 | case -31: return "CL_INVALID_DEVICE_TYPE"; 29 | case -32: return "CL_INVALID_PLATFORM"; 30 | case -33: return "CL_INVALID_DEVICE"; 31 | case -34: return "CL_INVALID_CONTEXT"; 32 | case -35: return "CL_INVALID_QUEUE_PROPERTIES"; 33 | case -36: return "CL_INVALID_COMMAND_QUEUE"; 34 | case -37: return "CL_INVALID_HOST_PTR"; 35 | case -38: return "CL_INVALID_MEM_OBJECT"; 36 | case -39: return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR"; 37 | case -40: return "CL_INVALID_IMAGE_SIZE"; 38 | case -41: return "CL_INVALID_SAMPLER"; 39 | case -42: return "CL_INVALID_BINARY"; 40 | case -43: return "CL_INVALID_BUILD_OPTIONS"; 41 | case -44: return "CL_INVALID_PROGRAM"; 42 | case -45: return "CL_INVALID_PROGRAM_EXECUTABLE"; 43 | case -46: return "CL_INVALID_KERNEL_NAME"; 44 | case -47: return "CL_INVALID_KERNEL_DEFINITION"; 45 | case -48: return "CL_INVALID_KERNEL"; 46 | case -49: return "CL_INVALID_ARG_INDEX"; 47 | case -50: return "CL_INVALID_ARG_VALUE"; 48 | case -51: return "CL_INVALID_ARG_SIZE"; 49 | case -52: return "CL_INVALID_KERNEL_ARGS"; 50 | case -53: return "CL_INVALID_WORK_DIMENSION"; 51 | case -54: return "CL_INVALID_WORK_GROUP_SIZE"; 52 | case -55: return "CL_INVALID_WORK_ITEM_SIZE"; 53 | case -56: return "CL_INVALID_GLOBAL_OFFSET"; 54 | case -57: return "CL_INVALID_EVENT_WAIT_LIST"; 55 | case -58: return "CL_INVALID_EVENT"; 56 | case -59: return "CL_INVALID_OPERATION"; 57 | case -60: return "CL_INVALID_GL_OBJECT"; 58 | case -61: return "CL_INVALID_BUFFER_SIZE"; 59 | case -62: return "CL_INVALID_MIP_LEVEL"; 60 | case -63: return "CL_INVALID_GLOBAL_WORK_SIZE"; 61 | case -64: return "CL_INVALID_PROPERTY"; 62 | case -65: return "CL_INVALID_IMAGE_DESCRIPTOR"; 63 | case -66: return "CL_INVALID_COMPILER_OPTIONS"; 64 | case -67: return "CL_INVALID_LINKER_OPTIONS"; 65 | case -68: return "CL_INVALID_DEVICE_PARTITION_COUNT"; 66 | default: return "CL_UNKNOWN_ERROR"; 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /clUtil/clutil.h: -------------------------------------------------------------------------------- 1 | #ifndef _CL_UTIL_H 2 | #define _CL_UTIL_H 3 | 4 | #ifdef __APPLE__ 5 | #define CL_SILENCE_DEPRECATION 6 | #include 7 | #else 8 | #include 9 | #endif 10 | 11 | #include 12 | #include 13 | 14 | namespace cl { 15 | std::string getErrorString(cl_int err); 16 | 17 | typedef struct { 18 | cl_device_id id; 19 | int cores; 20 | uint64_t mem; 21 | std::string name; 22 | 23 | }CLDeviceInfo; 24 | 25 | class CLException { 26 | public: 27 | int error; 28 | std::string msg; 29 | 30 | CLException(cl_int err) 31 | { 32 | this->error = err; 33 | this->msg = getErrorString(err); 34 | } 35 | 36 | CLException(cl_int err, std::string msg) 37 | { 38 | this->error = err; 39 | this->msg = msg; 40 | } 41 | }; 42 | 43 | CLDeviceInfo getDeviceInfo(int device); 44 | 45 | std::vector getDevices(); 46 | 47 | int getDeviceCount(); 48 | 49 | void clCall(cl_int err); 50 | 51 | } 52 | 53 | #endif -------------------------------------------------------------------------------- /cudaInfo/Makefile: -------------------------------------------------------------------------------- 1 | CPPSRC:=$(wildcard *.cpp) 2 | 3 | all: 4 | ${CXX} -o cudainfo.bin ${CPPSRC} ${INCLUDE} -I${CUDA_INCLUDE} ${CXXFLAGS} ${LIBS} -L${CUDA_LIB} -lcudautil -lcudart 5 | mkdir -p $(BINDIR) 6 | cp cudainfo.bin $(BINDIR)/cudainfo 7 | 8 | clean: 9 | rm -rf cudainfo.bin -------------------------------------------------------------------------------- /cudaInfo/cudaInfo.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | {eadaaa54-e304-4656-8263-e5e688ff323d} 19 | 20 | 21 | 22 | {9E8ECC85-AF9F-4F17-9397-633CA2FEE94E} 23 | cudaInfo 24 | 10.0 25 | 26 | 27 | 28 | Application 29 | true 30 | MultiByte 31 | v142 32 | 33 | 34 | Application 35 | false 36 | true 37 | MultiByte 38 | v142 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | true 53 | 54 | 55 | 56 | Level3 57 | Disabled 58 | WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 59 | $(SolutionDir)cudaUtil;%(AdditionalIncludeDirectories) 60 | 61 | 62 | true 63 | Console 64 | cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 65 | 66 | 67 | 64 68 | 69 | 70 | 71 | 72 | Level3 73 | MaxSpeed 74 | true 75 | true 76 | WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 77 | $(SolutionDir)cudaUtil;%(AdditionalIncludeDirectories) 78 | 79 | 80 | true 81 | true 82 | true 83 | Console 84 | cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 85 | 86 | 87 | 64 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /cudaInfo/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include"cudaUtil.h" 5 | 6 | void printDeviceInfo(const cuda::CudaDeviceInfo &info) 7 | { 8 | printf("ID: %d\n", info.id); 9 | printf("Name: %s\n", info.name.c_str()); 10 | printf("Capability: %d.%d\n", info.major, info.minor); 11 | printf("MP: %d\n", info.mpCount); 12 | printf("Cores: %d (%d per MP)\n", info.mpCount * info.cores, info.cores); 13 | printf("Memory: %dMB\n", (int)(info.mem / (1024 * 1024))); 14 | } 15 | 16 | int main(int argc, char **argv) 17 | { 18 | try { 19 | std::vector devices = cuda::getDevices(); 20 | 21 | printf("Found %d devices\n\n", (int)devices.size()); 22 | 23 | for(int i = 0; i < (int)devices.size(); i++) { 24 | printDeviceInfo(devices[i]); 25 | printf("\n"); 26 | } 27 | } catch(cuda::CudaException &ex) { 28 | printf("Error querying devices: %s\n", ex.msg.c_str()); 29 | 30 | return 1; 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /cudaMath/cudaMath.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {E1BDB205-8994-4E49-8B35-172A84E7118C} 15 | cudaMath 16 | 10.0 17 | 18 | 19 | 20 | Application 21 | true 22 | MultiByte 23 | v142 24 | 25 | 26 | Application 27 | false 28 | true 29 | MultiByte 30 | v142 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | true 45 | 46 | 47 | 48 | Level3 49 | Disabled 50 | WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 51 | 52 | 53 | true 54 | Console 55 | cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 56 | 57 | 58 | 64 59 | 60 | 61 | 62 | 63 | Level3 64 | MaxSpeed 65 | true 66 | true 67 | WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 68 | 69 | 70 | true 71 | true 72 | true 73 | Console 74 | cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 75 | 76 | 77 | 64 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /cudaMath/ptx.cuh: -------------------------------------------------------------------------------- 1 | #ifndef _PTX_H 2 | #define _PTX_H 3 | 4 | #include 5 | 6 | #define madc_hi(dest, a, x, b) asm volatile("madc.hi.u32 %0, %1, %2, %3;\n\t" : "=r"(dest) : "r"(a), "r"(x), "r"(b)) 7 | #define madc_hi_cc(dest, a, x, b) asm volatile("madc.hi.cc.u32 %0, %1, %2, %3;\n\t" : "=r"(dest) : "r"(a), "r"(x), "r"(b)) 8 | #define mad_hi_cc(dest, a, x, b) asm volatile("mad.hi.cc.u32 %0, %1, %2, %3;\n\t" : "=r"(dest) : "r"(a), "r"(x), "r"(b)) 9 | 10 | #define mad_lo_cc(dest, a, x, b) asm volatile("mad.lo.cc.u32 %0, %1, %2, %3;\n\t" : "=r"(dest) : "r"(a), "r"(x), "r"(b)) 11 | #define madc_lo(dest, a, x, b) asm volatile("madc.lo.u32 %0, %1, %2, %3;\n\t" : "=r"(dest) : "r"(a), "r"(x), "r"(b)) 12 | #define madc_lo_cc(dest, a, x, b) asm volatile("madc.lo.cc.u32 %0, %1, %2, %3;\n\t" : "=r"(dest) : "r"(a), "r"(x),"r"(b)) 13 | 14 | #define addc(dest, a, b) asm volatile("addc.u32 %0, %1, %2;\n\t" : "=r"(dest) : "r"(a), "r"(b)) 15 | #define add_cc(dest, a, b) asm volatile("add.cc.u32 %0, %1, %2;\n\t" : "=r"(dest) : "r"(a), "r"(b)) 16 | #define addc_cc(dest, a, b) asm volatile("addc.cc.u32 %0, %1, %2;\n\t" : "=r"(dest) : "r"(a), "r"(b)) 17 | 18 | #define sub_cc(dest, a, b) asm volatile("sub.cc.u32 %0, %1, %2;\n\t" : "=r"(dest) : "r"(a), "r"(b)) 19 | #define subc_cc(dest, a, b) asm volatile("subc.cc.u32 %0, %1, %2;\n\t" : "=r"(dest) : "r"(a), "r"(b)) 20 | #define subc(dest, a, b) asm volatile("subc.u32 %0, %1, %2;\n\t" : "=r"(dest) : "r"(a), "r"(b)) 21 | 22 | #define set_eq(dest,a,b) asm volatile("set.eq.u32.u32 %0, %1, %2;\n\t" : "=r"(dest) : "r"(a), "r"(b)) 23 | 24 | #define lsbpos(x) (__ffs((x))) 25 | 26 | 27 | __device__ __forceinline__ unsigned int endian(unsigned int x) 28 | { 29 | return (x << 24) | ((x << 8) & 0x00ff0000) | ((x >> 8) & 0x0000ff00) | (x >> 24); 30 | } 31 | 32 | #endif -------------------------------------------------------------------------------- /cudaUtil/Makefile: -------------------------------------------------------------------------------- 1 | NAME=cudautil 2 | SRC=$(wildcard *.cpp) 3 | OBJS=$(SRC:.cpp=.o) 4 | 5 | all: ${SRC} 6 | for file in ${SRC} ; do\ 7 | ${CXX} -c $$file ${INCLUDE} -I${CUDA_INCLUDE} ${CXXFLAGS};\ 8 | done 9 | mkdir -p ${LIBDIR} 10 | ar rvs ${LIBDIR}/lib$(NAME).a ${OBJS} 11 | 12 | clean: 13 | rm -rf *.o 14 | -------------------------------------------------------------------------------- /cudaUtil/cudaUtil.cpp: -------------------------------------------------------------------------------- 1 | #include "cudaUtil.h" 2 | 3 | 4 | cuda::CudaDeviceInfo cuda::getDeviceInfo(int device) 5 | { 6 | cuda::CudaDeviceInfo devInfo; 7 | 8 | cudaDeviceProp properties; 9 | cudaError_t err = cudaSuccess; 10 | 11 | err = cudaSetDevice(device); 12 | 13 | if(err) { 14 | throw cuda::CudaException(err); 15 | } 16 | 17 | err = cudaGetDeviceProperties(&properties, device); 18 | 19 | if(err) { 20 | throw cuda::CudaException(err); 21 | } 22 | 23 | devInfo.id = device; 24 | devInfo.major = properties.major; 25 | devInfo.minor = properties.minor; 26 | devInfo.mpCount = properties.multiProcessorCount; 27 | devInfo.mem = properties.totalGlobalMem; 28 | devInfo.name = std::string(properties.name); 29 | 30 | int cores = 0; 31 | switch(devInfo.major) { 32 | case 1: 33 | cores = 8; 34 | break; 35 | case 2: 36 | if(devInfo.minor == 0) { 37 | cores = 32; 38 | } else { 39 | cores = 48; 40 | } 41 | break; 42 | case 3: 43 | cores = 192; 44 | break; 45 | case 5: 46 | cores = 128; 47 | break; 48 | case 6: 49 | if(devInfo.minor == 1 || devInfo.minor == 2) { 50 | cores = 128; 51 | } else { 52 | cores = 64; 53 | } 54 | break; 55 | case 7: 56 | cores = 64; 57 | break; 58 | default: 59 | cores = 8; 60 | break; 61 | } 62 | devInfo.cores = cores; 63 | 64 | return devInfo; 65 | } 66 | 67 | 68 | std::vector cuda::getDevices() 69 | { 70 | int count = getDeviceCount(); 71 | 72 | std::vector devList; 73 | 74 | for(int device = 0; device < count; device++) { 75 | devList.push_back(getDeviceInfo(device)); 76 | } 77 | 78 | return devList; 79 | } 80 | 81 | int cuda::getDeviceCount() 82 | { 83 | int count = 0; 84 | 85 | cudaError_t err = cudaGetDeviceCount(&count); 86 | 87 | if(err) { 88 | throw cuda::CudaException(err); 89 | } 90 | 91 | return count; 92 | } -------------------------------------------------------------------------------- /cudaUtil/cudaUtil.h: -------------------------------------------------------------------------------- 1 | #ifndef _CUDA_UTIL_H 2 | #define _CUDA_UTIL_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace cuda { 11 | typedef struct { 12 | 13 | int id; 14 | int major; 15 | int minor; 16 | int mpCount; 17 | int cores; 18 | uint64_t mem; 19 | std::string name; 20 | 21 | }CudaDeviceInfo; 22 | 23 | class CudaException 24 | { 25 | public: 26 | cudaError_t error; 27 | std::string msg; 28 | 29 | CudaException(cudaError_t err) 30 | { 31 | this->error = err; 32 | this->msg = std::string(cudaGetErrorString(err)); 33 | } 34 | }; 35 | 36 | CudaDeviceInfo getDeviceInfo(int device); 37 | 38 | std::vector getDevices(); 39 | 40 | int getDeviceCount(); 41 | } 42 | #endif -------------------------------------------------------------------------------- /embedcl/Makefile: -------------------------------------------------------------------------------- 1 | CPPSRC:=$(wildcard *.cpp) 2 | NAME=embedcl 3 | 4 | all: 5 | ${CXX} -o ${NAME} ${CPPSRC} ${INCLUDE} ${CXXFLAGS} 6 | mkdir -p $(BINDIR) 7 | cp ${NAME} $(BINDIR)/${NAME} 8 | 9 | clean: 10 | rm -rf ${NAME} -------------------------------------------------------------------------------- /embedcl/embedcl.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {8DA841AA-42FF-40AA-8F12-BC654DF39FEF} 24 | embedcl 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v141 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v141 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v142 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Level3 76 | MaxSpeed 77 | true 78 | true 79 | true 80 | true 81 | _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 82 | 83 | 84 | true 85 | true 86 | 87 | 88 | 89 | 90 | Level3 91 | Disabled 92 | true 93 | true 94 | _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 95 | 96 | 97 | 98 | 99 | Level3 100 | Disabled 101 | true 102 | true 103 | _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 104 | 105 | 106 | 107 | 108 | Level3 109 | MaxSpeed 110 | true 111 | true 112 | true 113 | true 114 | _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 115 | 116 | 117 | true 118 | true 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /embedcl/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | bool create(char *inputFile, char *outputFile, char *symbol) 5 | { 6 | char buf[1024]; 7 | 8 | FILE *fpIn = fopen(inputFile, "rb"); 9 | 10 | if(fpIn == NULL) { 11 | printf("Error opening '%s' for reading\n", inputFile); 12 | return false; 13 | } 14 | 15 | FILE *fpOut = fopen(outputFile, "w"); 16 | 17 | if(fpOut == NULL) { 18 | printf("Error opening '%s' for writing\n", outputFile); 19 | fclose(fpIn); 20 | return false; 21 | } 22 | 23 | fprintf(fpOut, "char %s[] = {", symbol); 24 | 25 | size_t bytesRead = 0; 26 | while((bytesRead = fread(buf, 1, sizeof(buf), fpIn))) { 27 | for(int i = 0; i < bytesRead; i++) { 28 | fprintf(fpOut, "0x%x,", buf[i]); 29 | } 30 | } 31 | fprintf(fpOut, "0x00};\n"); 32 | 33 | fclose(fpIn); 34 | fclose(fpOut); 35 | 36 | return true; 37 | } 38 | 39 | void usage() 40 | { 41 | printf("Usage:\n"); 42 | printf(" \n"); 43 | } 44 | 45 | int main(int argc, char **argv) 46 | { 47 | if(argc != 4) { 48 | usage(); 49 | 50 | return 1; 51 | } 52 | 53 | if(create(argv[1], argv[2], argv[3])) { 54 | return 0; 55 | } else { 56 | return 1; 57 | } 58 | } -------------------------------------------------------------------------------- /secp256k1lib/Makefile: -------------------------------------------------------------------------------- 1 | NAME=secp256k1 2 | SRC=$(wildcard *.cpp) 3 | OBJS=$(SRC:.cpp=.o) 4 | 5 | all: ${SRC} 6 | for file in ${SRC} ; do\ 7 | ${CXX} -c $$file ${INCLUDE} ${CXXFLAGS} ${LIBS} -lcryptoutil;\ 8 | done 9 | mkdir -p ${LIBDIR} 10 | ar rvs ${LIBDIR}/lib$(NAME).a ${OBJS} 11 | 12 | clean: 13 | rm -rf *.o 14 | -------------------------------------------------------------------------------- /secp256k1lib/secp256k1lib.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | {ca46856a-1d1e-4f6f-a69c-6707d540bf36} 30 | 31 | 32 | 33 | {BFF4B5FE-C2C5-4384-8941-CD6CB29E78C6} 34 | Win32Proj 35 | secp256k1lib 36 | 10.0 37 | 38 | 39 | 40 | StaticLibrary 41 | true 42 | v141 43 | Unicode 44 | 45 | 46 | StaticLibrary 47 | false 48 | v141 49 | true 50 | Unicode 51 | 52 | 53 | StaticLibrary 54 | true 55 | v142 56 | NotSet 57 | 58 | 59 | StaticLibrary 60 | false 61 | v142 62 | true 63 | NotSet 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | Level3 93 | Disabled 94 | _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 95 | $(SolutionDir)CryptoUtil;%(AdditionalIncludeDirectories) 96 | 97 | 98 | Windows 99 | 100 | 101 | 102 | 103 | NotUsing 104 | Level3 105 | Disabled 106 | _CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) 107 | $(SolutionDir)CryptoUtil;%(AdditionalIncludeDirectories) 108 | 109 | 110 | Windows 111 | 112 | 113 | 114 | 115 | Level3 116 | 117 | 118 | MaxSpeed 119 | true 120 | true 121 | _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 122 | $(SolutionDir)CryptoUtil;%(AdditionalIncludeDirectories) 123 | 124 | 125 | Windows 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | NotUsing 134 | MaxSpeed 135 | true 136 | true 137 | _CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;%(PreprocessorDefinitions) 138 | $(SolutionDir)CryptoUtil;%(AdditionalIncludeDirectories) 139 | 140 | 141 | Windows 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /tools/embedcl.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brichard19/BitCrack/6bf8059ef075eb1622298395866b0bd02375e1d9/tools/embedcl.exe -------------------------------------------------------------------------------- /util/Makefile: -------------------------------------------------------------------------------- 1 | NAME=util 2 | SRC=$(wildcard *.cpp) 3 | OBJS=$(SRC:.cpp=.o) 4 | 5 | all: ${SRC} 6 | for file in ${SRC} ; do\ 7 | ${CXX} -c $$file ${INCLUDE} ${CXXFLAGS};\ 8 | done 9 | mkdir -p ${LIBDIR} 10 | ar rvs ${LIBDIR}/lib$(NAME).a ${OBJS} 11 | 12 | clean: 13 | rm -rf *.o 14 | -------------------------------------------------------------------------------- /util/util.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include"util.h" 9 | 10 | #ifdef _WIN32 11 | #include 12 | #else 13 | #include 14 | #include 15 | #include 16 | #include 17 | #endif 18 | 19 | namespace util { 20 | 21 | uint64_t getSystemTime() 22 | { 23 | #ifdef _WIN32 24 | return GetTickCount64(); 25 | #else 26 | struct timeval t; 27 | gettimeofday(&t, NULL); 28 | return (uint64_t)t.tv_sec * 1000 + t.tv_usec / 1000; 29 | #endif 30 | } 31 | 32 | Timer::Timer() 33 | { 34 | _startTime = 0; 35 | } 36 | 37 | void Timer::start() 38 | { 39 | _startTime = getSystemTime(); 40 | } 41 | 42 | uint64_t Timer::getTime() 43 | { 44 | return getSystemTime() - _startTime; 45 | } 46 | 47 | void sleep(int seconds) 48 | { 49 | #ifdef _WIN32 50 | Sleep(seconds * 1000); 51 | #else 52 | sleep(seconds); 53 | #endif 54 | } 55 | 56 | std::string formatThousands(uint64_t x) 57 | { 58 | char buf[32] = ""; 59 | 60 | sprintf(buf, "%lld", x); 61 | 62 | std::string s(buf); 63 | 64 | int len = (int)s.length(); 65 | 66 | int numCommas = (len - 1) / 3; 67 | 68 | if(numCommas == 0) { 69 | return s; 70 | } 71 | 72 | std::string result = ""; 73 | 74 | int count = ((len % 3) == 0) ? 0 : (3 - (len % 3)); 75 | 76 | for(int i = 0; i < len; i++) { 77 | result += s[i]; 78 | 79 | if(count++ == 2 && i < len - 1) { 80 | result += ","; 81 | count = 0; 82 | } 83 | } 84 | 85 | return result; 86 | } 87 | 88 | uint32_t parseUInt32(std::string s) 89 | { 90 | return (uint32_t)parseUInt64(s); 91 | } 92 | 93 | uint64_t parseUInt64(std::string s) 94 | { 95 | uint64_t val = 0; 96 | bool isHex = false; 97 | 98 | if(s[0] == '0' && s[1] == 'x') { 99 | isHex = true; 100 | s = s.substr(2); 101 | } 102 | 103 | if(s[s.length() - 1] == 'h') { 104 | isHex = true; 105 | s = s.substr(0, s.length() - 1); 106 | } 107 | 108 | if(isHex) { 109 | if(sscanf(s.c_str(), "%llx", &val) != 1) { 110 | throw std::string("Expected an integer"); 111 | } 112 | } else { 113 | if(sscanf(s.c_str(), "%lld", &val) != 1) { 114 | throw std::string("Expected an integer"); 115 | } 116 | } 117 | 118 | return val; 119 | } 120 | 121 | bool isHex(const std::string &s) 122 | { 123 | int len = 0; 124 | 125 | for(int i = 0; i < len; i++) { 126 | char c = s[i]; 127 | 128 | if(!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { 129 | return false; 130 | } 131 | } 132 | 133 | return true; 134 | } 135 | 136 | std::string formatSeconds(unsigned int seconds) 137 | { 138 | char s[128] = { 0 }; 139 | 140 | unsigned int days = seconds / 86400; 141 | unsigned int hours = (seconds % 86400) / 3600; 142 | unsigned int minutes = (seconds % 3600) / 60; 143 | unsigned int sec = seconds % 60; 144 | 145 | if(days > 0) { 146 | sprintf(s, "%d:%02d:%02d:%02d", days, hours, minutes, sec); 147 | } else { 148 | sprintf(s, "%02d:%02d:%02d", hours, minutes, sec); 149 | } 150 | 151 | 152 | return std::string(s); 153 | } 154 | 155 | long getFileSize(const std::string &fileName) 156 | { 157 | FILE *fp = fopen(fileName.c_str(), "rb"); 158 | if(fp == NULL) { 159 | return -1; 160 | } 161 | 162 | fseek(fp, 0, SEEK_END); 163 | 164 | long pos = ftell(fp); 165 | 166 | fclose(fp); 167 | 168 | return pos; 169 | } 170 | 171 | bool readLinesFromStream(const std::string &fileName, std::vector &lines) 172 | { 173 | std::ifstream inFile(fileName.c_str()); 174 | 175 | if(!inFile.is_open()) { 176 | return false; 177 | } 178 | 179 | return readLinesFromStream(inFile, lines); 180 | } 181 | 182 | bool readLinesFromStream(std::istream &in, std::vector &lines) 183 | { 184 | std::string line; 185 | 186 | while(std::getline(in, line)) { 187 | if(line.length() > 0) { 188 | lines.push_back(line); 189 | } 190 | } 191 | 192 | return true; 193 | } 194 | 195 | bool appendToFile(const std::string &fileName, const std::string &s) 196 | { 197 | std::ofstream outFile; 198 | bool newline = false; 199 | 200 | if(getFileSize(fileName) > 0) { 201 | newline = true; 202 | } 203 | 204 | outFile.open(fileName.c_str(), std::ios::app); 205 | 206 | if(!outFile.is_open()) { 207 | return false; 208 | } 209 | 210 | // Add newline following previous line 211 | if(newline) { 212 | outFile << std::endl; 213 | } 214 | 215 | outFile << s; 216 | 217 | return true; 218 | } 219 | 220 | std::string format(const char *formatStr, double value) 221 | { 222 | char buf[100] = { 0 }; 223 | 224 | sprintf(buf, formatStr, value); 225 | 226 | return std::string(buf); 227 | } 228 | 229 | std::string format(uint32_t value) 230 | { 231 | char buf[100] = { 0 }; 232 | 233 | sprintf(buf, "%u", value); 234 | 235 | return std::string(buf); 236 | } 237 | 238 | std::string format(uint64_t value) 239 | { 240 | char buf[100] = { 0 }; 241 | 242 | sprintf(buf, "%lld", (uint64_t)value); 243 | 244 | return std::string(buf); 245 | } 246 | 247 | std::string format(int value) 248 | { 249 | char buf[100] = { 0 }; 250 | 251 | sprintf(buf, "%d", value); 252 | 253 | return std::string(buf); 254 | } 255 | 256 | void removeNewline(std::string &s) 257 | { 258 | size_t len = s.length(); 259 | 260 | int toRemove = 0; 261 | 262 | if(len >= 2) { 263 | if(s[len - 2] == '\r' || s[len - 2] == '\n') { 264 | toRemove++; 265 | } 266 | } 267 | if(len >= 1) { 268 | if(s[len - 1] == '\r' || s[len - 1] == '\n') { 269 | toRemove++; 270 | } 271 | } 272 | 273 | if(toRemove) { 274 | s.erase(len - toRemove); 275 | } 276 | } 277 | 278 | unsigned int endian(unsigned int x) 279 | { 280 | return (x << 24) | ((x << 8) & 0x00ff0000) | ((x >> 8) & 0x0000ff00) | (x >> 24); 281 | } 282 | 283 | std::string toLower(const std::string &s) 284 | { 285 | std::string lowerCase = s; 286 | std::transform(lowerCase.begin(), lowerCase.end(), lowerCase.begin(), ::tolower); 287 | 288 | return lowerCase; 289 | } 290 | 291 | std::string trim(const std::string &s, char c) 292 | { 293 | size_t left = s.find_first_not_of(c); 294 | size_t right = s.find_last_not_of(c); 295 | 296 | return s.substr(left, right - left + 1); 297 | } 298 | } -------------------------------------------------------------------------------- /util/util.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIL_H 2 | #define _UTIL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace util { 9 | 10 | class Timer { 11 | 12 | private: 13 | uint64_t _startTime; 14 | 15 | public: 16 | Timer(); 17 | void start(); 18 | uint64_t getTime(); 19 | }; 20 | 21 | uint64_t getSystemTime(); 22 | void sleep(int seconds); 23 | 24 | std::string formatThousands(uint64_t x); 25 | std::string formatSeconds(unsigned int seconds); 26 | 27 | uint32_t parseUInt32(std::string s); 28 | uint64_t parseUInt64(std::string s); 29 | bool isHex(const std::string &s); 30 | bool appendToFile(const std::string &fileName, const std::string &s); 31 | bool readLinesFromStream(std::istream &in, std::vector &lines); 32 | bool readLinesFromStream(const std::string &fileName, std::vector &lines); 33 | 34 | std::string format(const char *formatStr, double value); 35 | std::string format(uint32_t value); 36 | std::string format(uint64_t value); 37 | std::string format(int value); 38 | void removeNewline(std::string &s); 39 | unsigned int endian(unsigned int x); 40 | 41 | std::string toLower(const std::string &s); 42 | std::string trim(const std::string &s, char c=' '); 43 | 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /util/util.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | {93B89BF6-32B9-4EBA-AA44-BCFEC4836B76} 29 | Win32Proj 30 | util 31 | 10.0 32 | 33 | 34 | 35 | StaticLibrary 36 | true 37 | v141 38 | Unicode 39 | 40 | 41 | StaticLibrary 42 | false 43 | v141 44 | true 45 | Unicode 46 | 47 | 48 | StaticLibrary 49 | true 50 | v142 51 | Unicode 52 | 53 | 54 | StaticLibrary 55 | false 56 | v142 57 | true 58 | Unicode 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | Level3 88 | Disabled 89 | _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 90 | 91 | 92 | Windows 93 | 94 | 95 | 96 | 97 | NotUsing 98 | Level3 99 | Disabled 100 | _CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) 101 | 102 | 103 | Windows 104 | 105 | 106 | 107 | 108 | Level3 109 | 110 | 111 | MaxSpeed 112 | true 113 | true 114 | _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 115 | 116 | 117 | Windows 118 | true 119 | true 120 | 121 | 122 | 123 | 124 | Level3 125 | NotUsing 126 | MaxSpeed 127 | true 128 | true 129 | _CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;%(PreprocessorDefinitions) 130 | 131 | 132 | Windows 133 | true 134 | true 135 | 136 | 137 | 138 | 139 | 140 | --------------------------------------------------------------------------------