├── Makefile ├── test.txt ├── doc ├── CHANGES └── LICENSE ├── lib ├── OpenCL64.def └── OpenCL.def ├── src ├── gaussFilter.c ├── Makefile ├── gaussCombinator.c ├── md5.c ├── OpenCL.c ├── oclGaussCrack.cl └── oclGaussCrack.c └── README.md /Makefile: -------------------------------------------------------------------------------- 1 | include src/Makefile 2 | -------------------------------------------------------------------------------- /test.txt: -------------------------------------------------------------------------------- 1 | C:\Documents and Settings\john\Local Settings\Application Data\Google\Chrome\Application~dir1 -------------------------------------------------------------------------------- /doc/CHANGES: -------------------------------------------------------------------------------- 1 | v1.4 -> v1.x 2 | 3 | o Update Makefile to simplify compilation process 4 | o Set OpenCL version to use before loading OpenCL headers 5 | 6 | v1.3 -> v1.4 7 | 8 | o Move the project to GitHub 9 | o Update Makefile to use official Khronos OpenCL Headers 10 | o Update Makefile to fix an issue related to _mkgmtime32 11 | o Fix a bug where global_work_size[0] results in a wrong value 12 | o Allow the use of deprecated OpenCL API function calls 13 | 14 | v1.2 -> v1.3 15 | 16 | o Added two support utilities: gaussFilter and gaussCombinator, see README for details 17 | o Added check for \r\n LFs not just \n 18 | o Implemented Trac #47: Full verification of all 4 known hashes 19 | o Implemented Trac #48: Saving the cracked hashes to a "pot" file 20 | o Fixed buf: In utf16 unicode there is a zero-byte following the \n, skip it 21 | 22 | v1.1 -> v1.2 23 | 24 | o Added two optional parameters to pick a range of candidates to test - useful in distributed / resume. 25 | o Reduced required host memory 26 | o Cleaned code to make it more readable 27 | o Changed maximum line length from BUFSIZ to configurable MAX_LINELEN 28 | o Changed GPU kernel to more precise checks 29 | o Changed GPU runtime in status display 30 | o Fixed bug: Add extra buffer space for salt and padding 31 | o Fixed bug: VECT_SIZE was handled incorrectly 32 | o Fixed bug: kernel source terminator byte was set incorrectly 33 | o Fixed bug: cracked display showed more data than neccessary 34 | 35 | v1.0 -> v1.1 36 | 37 | o Added windows precompiled binaries 38 | o Added dedicated 32/64 bit precompiled binaries 39 | o Added real Gauss-Virus hash to kernel 40 | o Test vector hash is just commented out, simply uncomment it for test 41 | o Removed OpenSSL depency 42 | o Fixed documentation 43 | -------------------------------------------------------------------------------- /lib/OpenCL64.def: -------------------------------------------------------------------------------- 1 | ; 2 | ; Definition file of OpenCL.dll 3 | ; Automatic generated by gendef 4 | ; written by Kai Tietz 2008 5 | ; 6 | LIBRARY "OpenCL.dll" 7 | EXPORTS 8 | clBuildProgram 9 | clCreateBuffer 10 | clCreateCommandQueue 11 | clCreateContext 12 | clCreateContextFromType 13 | clCreateFromGLBuffer 14 | clCreateFromGLRenderbuffer 15 | clCreateFromGLTexture2D 16 | clCreateFromGLTexture3D 17 | clCreateImage2D 18 | clCreateImage3D 19 | clCreateKernel 20 | clCreateKernelsInProgram 21 | clCreateProgramWithBinary 22 | clCreateProgramWithSource 23 | clCreateSampler 24 | clEnqueueAcquireGLObjects 25 | clEnqueueBarrier 26 | clEnqueueCopyBuffer 27 | clEnqueueCopyBufferToImage 28 | clEnqueueCopyImage 29 | clEnqueueCopyImageToBuffer 30 | clEnqueueMapBuffer 31 | clEnqueueMapImage 32 | clEnqueueMarker 33 | clEnqueueNDRangeKernel 34 | clEnqueueNativeKernel 35 | clEnqueueReadBuffer 36 | clEnqueueReadImage 37 | clEnqueueReleaseGLObjects 38 | clEnqueueTask 39 | clEnqueueUnmapMemObject 40 | clEnqueueWaitForEvents 41 | clEnqueueWriteBuffer 42 | clEnqueueWriteImage 43 | clFinish 44 | clFlush 45 | clGetCommandQueueInfo 46 | clGetContextInfo 47 | clGetDeviceIDs 48 | clGetDeviceInfo 49 | clGetEventInfo 50 | clGetEventProfilingInfo 51 | clGetExtensionFunctionAddress 52 | clGetGLObjectInfo 53 | clGetGLTextureInfo 54 | clGetImageInfo 55 | clGetKernelInfo 56 | clGetKernelWorkGroupInfo 57 | clGetMemObjectInfo 58 | clGetPlatformIDs 59 | clGetPlatformInfo 60 | clGetProgramBuildInfo 61 | clGetProgramInfo 62 | clGetSamplerInfo 63 | clGetSupportedImageFormats 64 | clReleaseCommandQueue 65 | clReleaseContext 66 | clReleaseEvent 67 | clReleaseKernel 68 | clReleaseMemObject 69 | clReleaseProgram 70 | clReleaseSampler 71 | clRetainCommandQueue 72 | clRetainContext 73 | clRetainEvent 74 | clRetainKernel 75 | clRetainMemObject 76 | clRetainProgram 77 | clRetainSampler 78 | clSetCommandQueueProperty 79 | clSetKernelArg 80 | clUnloadCompiler 81 | clWaitForEvents 82 | -------------------------------------------------------------------------------- /lib/OpenCL.def: -------------------------------------------------------------------------------- 1 | LIBRARY "OpenCL.dll" 2 | EXPORTS 3 | clBuildProgram@24 4 | clCreateBuffer@24 5 | clCreateCommandQueue@20 6 | clCreateContext@24 7 | clCreateContextFromType@24 8 | clCreateFromD3D10Buffer@20 9 | clCreateFromD3D9Buffer@24 10 | clCreateFromGLBuffer@20 11 | clCreateFromGLRenderbuffer@20 12 | clCreateFromGLTexture2D@28 13 | clCreateFromGLTexture3D@28 14 | clCreateImage2D@36 15 | clCreateImage3D@44 16 | clCreateImageFromD3D10Resource@20 17 | clCreateImageFromD3D9Resource@24 18 | clCreateKernel@12 19 | clCreateKernelsInProgram@16 20 | clCreateProgramWithBinary@28 21 | clCreateProgramWithSource@20 22 | clCreateSampler@20 23 | clEnqueueAcquireExternalObjects@24 24 | clEnqueueAcquireGLObjects@24 25 | clEnqueueBarrier@4 26 | clEnqueueCopyBuffer@36 27 | clEnqueueCopyBufferToImage@36 28 | clEnqueueCopyImage@36 29 | clEnqueueCopyImageToBuffer@36 30 | clEnqueueMapBuffer@44 31 | clEnqueueMapImage@52 32 | clEnqueueMarker@8 33 | clEnqueueNDRangeKernel@36 34 | clEnqueueNativeKernel@40 35 | clEnqueueReadBuffer@36 36 | clEnqueueReadImage@44 37 | clEnqueueReleaseExternalObjects@24 38 | clEnqueueReleaseGLObjects@24 39 | clEnqueueTask@20 40 | clEnqueueUnmapMemObject@24 41 | clEnqueueWaitForEvents@12 42 | clEnqueueWriteBuffer@36 43 | clEnqueueWriteImage@44 44 | clFinish@4 45 | clFlush@4 46 | clGetCommandQueueInfo@20 47 | clGetContextInfo@20 48 | clGetDeviceIDs@24 49 | clGetDeviceInfo@20 50 | clGetEventInfo@20 51 | clGetEventProfilingInfo@20 52 | clGetExtensionFunctionAddress@4 53 | clGetGLObjectInfo@12 54 | clGetGLTextureInfo@20 55 | clGetImageInfo@20 56 | clGetKernelInfo@20 57 | clGetKernelWorkGroupInfo@24 58 | clGetMemObjectInfo@20 59 | clGetPlatformIDs@12 60 | clGetPlatformInfo@20 61 | clGetProgramBuildInfo@24 62 | clGetProgramInfo@20 63 | clGetSamplerInfo@20 64 | clGetSupportedImageFormats@28 65 | clReleaseCommandQueue@4 66 | clReleaseContext@4 67 | clReleaseEvent@4 68 | clReleaseKernel@4 69 | clReleaseMemObject@4 70 | clReleaseProgram@4 71 | clReleaseSampler@4 72 | clRetainCommandQueue@4 73 | clRetainContext@4 74 | clRetainEvent@4 75 | clRetainKernel@4 76 | clRetainMemObject@4 77 | clRetainProgram@4 78 | clRetainSampler@4 79 | clSetCommandQueueProperty@20 80 | clSetKernelArg@16 81 | clUnloadCompiler@0 82 | clWaitForEvents@8 83 | -------------------------------------------------------------------------------- /src/gaussFilter.c: -------------------------------------------------------------------------------- 1 | /* 2 | * oclGaussCrack - OpenCL accelerated Gauss hash validator 3 | * 4 | * Copyright (C) 2012 Jens Steube 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * 20 | */ 21 | 22 | #define _GNU_SOURCE 23 | #define _FILE_OFFSET_BITS 64 24 | #define __MSVCRT_VERSION__ 0x0700 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | // NOTE! iconv your input file before using it 35 | // 36 | // iconv -c -f utf8 -t utf16le < in.txt > out.txt 37 | 38 | int main (int argc, char *argv[]) 39 | { 40 | FILE *fd; 41 | 42 | if (argc != 2) 43 | { 44 | fprintf (stderr, "usage: %s file\n", argv[0]); 45 | 46 | return (-1); 47 | } 48 | 49 | if ((fd = fopen (argv[1], "rb")) == NULL) 50 | { 51 | fprintf (stderr, "%s: %s\n", argv[1], strerror (errno)); 52 | 53 | return (-1); 54 | } 55 | 56 | while (!feof (fd)) 57 | { 58 | /* Get new password candidate from stdin */ 59 | 60 | uint16_t line_buf[BUFSIZ]; 61 | 62 | int line_len = 0; 63 | 64 | int i; 65 | 66 | for (i = 0; i < BUFSIZ - 1; i++) 67 | { 68 | int c1 = fgetc (fd); 69 | 70 | if (c1 == EOF) break; 71 | 72 | int c2 = fgetc (fd); 73 | 74 | if (c2 == EOF) break; 75 | 76 | uint16_t c = (c1 << 0) | (c2 << 8); 77 | 78 | line_buf[line_len] = c; 79 | 80 | line_len++; 81 | 82 | if (c == '\n') break; 83 | } 84 | 85 | if (line_len == 0) continue; 86 | 87 | if (line_buf[0] <= 0x7a) continue; 88 | 89 | fwrite ((char *) line_buf, sizeof (uint16_t), line_len, stdout); 90 | } 91 | 92 | fclose (fd); 93 | 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | ## Simply clone this from https://github.com/KhronosGroup/OpenCL-Headers and add a symlink inside: ln -s . CL 2 | 3 | OCL := OpenCL-Headers 4 | 5 | ## 6 | ## Compiler paths 7 | ## 8 | 9 | BIN := . 10 | 11 | CPP_LINUX_32 := gcc 12 | CPP_LINUX_64 := gcc 13 | 14 | CPP_WIN_32 := i686-w64-mingw32-gcc 15 | CPP_WIN_64 := x86_64-w64-mingw32-gcc 16 | 17 | DLL_WIN_32 := /usr/bin/i686-w64-mingw32-dlltool 18 | DLL_WIN_64 := /usr/bin/x86_64-w64-mingw32-dlltool 19 | 20 | ## 21 | ## Compiler flags 22 | ## 23 | 24 | CFLAGS := -O2 -s -pipe -W -Wall -pedantic -std=c99 -I$(OCL) 25 | 26 | CFLAGS_32 := -m32 27 | CFLAGS_64 := -m64 28 | 29 | CFLAGS_LINUX := -DLINUX 30 | CFLAGS_WIN := -DWIN -D__MSVCRT__ -D__USE_MINGW_ANSI_STDIO=1 31 | 32 | LFLAGS_LINUX := 33 | LFLAGS_WIN := -static-libgcc -L. -lpsapi 34 | 35 | ## 36 | ## Targets 37 | ## 38 | 39 | all: linux win 40 | 41 | clean: 42 | rm -f $(BIN)/*.bin $(BIN)/*.exe $(BIN)/*.a 43 | 44 | linux: oclGaussCrack32.bin oclGaussCrack64.bin gaussCombinator32.bin gaussCombinator64.bin gaussFilter32.bin gaussFilter64.bin 45 | win: libOpenCL.a libOpenCL64.a oclGaussCrack32.exe oclGaussCrack64.exe gaussCombinator32.exe gaussCombinator64.exe gaussFilter32.exe gaussFilter64.exe 46 | 47 | libOpenCL.a: 48 | ${DLL_WIN_32} -A -k -l libOpenCL.a -d lib/OpenCL.def 49 | 50 | libOpenCL64.a: 51 | ${DLL_WIN_64} -A -k -l libOpenCL64.a -d lib/OpenCL64.def 52 | 53 | oclGaussCrack32.bin: src/oclGaussCrack.c 54 | $(CPP_LINUX_32) $(CFLAGS) $(CFLAGS_32) $(CFLAGS_LINUX) -o $@ $^ $(LFLAGS_LINUX) -lOpenCL 55 | 56 | oclGaussCrack64.bin: src/oclGaussCrack.c 57 | $(CPP_LINUX_64) $(CFLAGS) $(CFLAGS_64) $(CFLAGS_LINUX) -o $@ $^ $(LFLAGS_LINUX) -lOpenCL 58 | 59 | oclGaussCrack32.exe: src/oclGaussCrack.c 60 | $(CPP_WIN_32) $(CFLAGS) $(CFLAGS_32) $(CFLAGS_WIN) -o $@ $^ $(LFLAGS_WIN) -lOpenCL 61 | 62 | oclGaussCrack64.exe: src/oclGaussCrack.c 63 | $(CPP_WIN_64) $(CFLAGS) $(CFLAGS_64) $(CFLAGS_WIN) -o $@ $^ $(LFLAGS_WIN) -lOpenCL64 64 | 65 | gaussCombinator32.bin: src/gaussCombinator.c 66 | $(CPP_LINUX_32) $(CFLAGS) $(CFLAGS_32) $(CFLAGS_LINUX) -o $@ $^ $(LFLAGS_LINUX) 67 | 68 | gaussCombinator64.bin: src/gaussCombinator.c 69 | $(CPP_LINUX_64) $(CFLAGS) $(CFLAGS_64) $(CFLAGS_LINUX) -o $@ $^ $(LFLAGS_LINUX) 70 | 71 | gaussCombinator32.exe: src/gaussCombinator.c 72 | $(CPP_WIN_32) $(CFLAGS) $(CFLAGS_32) $(CFLAGS_WIN) -o $@ $^ $(LFLAGS_WIN) 73 | 74 | gaussCombinator64.exe: src/gaussCombinator.c 75 | $(CPP_WIN_64) $(CFLAGS) $(CFLAGS_64) $(CFLAGS_WIN) -o $@ $^ $(LFLAGS_WIN) 76 | 77 | gaussFilter32.bin: src/gaussFilter.c 78 | $(CPP_LINUX_32) $(CFLAGS) $(CFLAGS_32) $(CFLAGS_LINUX) -o $@ $^ $(LFLAGS_LINUX) 79 | 80 | gaussFilter64.bin: src/gaussFilter.c 81 | $(CPP_LINUX_64) $(CFLAGS) $(CFLAGS_64) $(CFLAGS_LINUX) -o $@ $^ $(LFLAGS_LINUX) 82 | 83 | gaussFilter32.exe: src/gaussFilter.c 84 | $(CPP_WIN_32) $(CFLAGS) $(CFLAGS_32) $(CFLAGS_WIN) -o $@ $^ $(LFLAGS_WIN) 85 | 86 | gaussFilter64.exe: src/gaussFilter.c 87 | $(CPP_WIN_64) $(CFLAGS) $(CFLAGS_64) $(CFLAGS_WIN) -o $@ $^ $(LFLAGS_WIN) 88 | -------------------------------------------------------------------------------- /src/gaussCombinator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * oclGaussCrack - OpenCL accelerated Gauss hash validator 3 | * 4 | * Copyright (C) 2012 Jens Steube 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * 20 | */ 21 | 22 | #define _GNU_SOURCE 23 | #define _FILE_OFFSET_BITS 64 24 | #define __MSVCRT_VERSION__ 0x0700 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | // NOTE! iconv your input file before using it 35 | // 36 | // iconv -c -f utf8 -t utf16le < in.txt > out.txt 37 | 38 | int main (int argc, char *argv[]) 39 | { 40 | FILE *fd1; 41 | FILE *fd2; 42 | 43 | uint16_t buf1[BUFSIZ]; 44 | uint16_t buf2[BUFSIZ]; 45 | 46 | size_t len1; 47 | size_t len2; 48 | 49 | uint16_t out[BUFSIZ]; 50 | 51 | uint16_t *out1 = out; 52 | uint16_t *out2 = NULL; 53 | 54 | if (argc != 3) 55 | { 56 | fprintf (stderr, "usage: %s file1 file2\n", argv[0]); 57 | 58 | return (-1); 59 | } 60 | 61 | if ((fd1 = fopen (argv[1], "rb")) == NULL) 62 | { 63 | fprintf (stderr, "%s: %s\n", argv[1], strerror (errno)); 64 | 65 | return (-1); 66 | } 67 | 68 | if ((fd2 = fopen (argv[2], "rb")) == NULL) 69 | { 70 | fprintf (stderr, "%s: %s\n", argv[1], strerror (errno)); 71 | 72 | return (-1); 73 | } 74 | 75 | while (!feof (fd1)) 76 | { 77 | int i; 78 | 79 | for (i = 0, len1 = 0; i < BUFSIZ - 1; i++) 80 | { 81 | int c1 = fgetc (fd1); 82 | 83 | if (c1 == EOF) break; 84 | 85 | int c2 = fgetc (fd1); 86 | 87 | if (c2 == EOF) break; 88 | 89 | uint16_t c = (c1 << 0) | (c2 << 8); 90 | 91 | if (c == '\n') break; 92 | 93 | buf1[len1] = c; 94 | 95 | len1++; 96 | } 97 | 98 | memcpy (out1, buf1, len1 * sizeof (uint16_t)); 99 | 100 | out2 = out1 + len1; 101 | 102 | while (!feof (fd2)) 103 | { 104 | for (i = 0, len2 = 0; i < BUFSIZ - 1; i++) 105 | { 106 | int c1 = fgetc (fd2); 107 | 108 | if (c1 == EOF) break; 109 | 110 | int c2 = fgetc (fd2); 111 | 112 | if (c2 == EOF) break; 113 | 114 | uint16_t c = (c1 << 0) | (c2 << 8); 115 | 116 | if (c == '\n') break; 117 | 118 | buf2[len2] = c; 119 | 120 | len2++; 121 | } 122 | 123 | memcpy (out2, buf2, len2 * sizeof (uint16_t)); 124 | 125 | fwrite ((char *) out, sizeof (uint16_t), len1 + len2, stdout); 126 | 127 | fputc ('\n', stdout); 128 | fputc ('\0', stdout); 129 | } 130 | 131 | rewind (fd2); 132 | } 133 | 134 | fclose (fd2); 135 | fclose (fd1); 136 | 137 | return 0; 138 | } 139 | -------------------------------------------------------------------------------- /src/md5.c: -------------------------------------------------------------------------------- 1 | /* 2 | * oclGaussCrack - OpenCL accelerated Gauss hash validator 3 | * 4 | * Copyright (C) 2012 Jens Steube 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * 20 | */ 21 | 22 | #define MD5M_A 0x67452301u 23 | #define MD5M_B 0xefcdab89u 24 | #define MD5M_C 0x98badcfeu 25 | #define MD5M_D 0x10325476u 26 | 27 | #define MD5S00 7u 28 | #define MD5S01 12u 29 | #define MD5S02 17u 30 | #define MD5S03 22u 31 | #define MD5S10 5u 32 | #define MD5S11 9u 33 | #define MD5S12 14u 34 | #define MD5S13 20u 35 | #define MD5S20 4u 36 | #define MD5S21 11u 37 | #define MD5S22 16u 38 | #define MD5S23 23u 39 | #define MD5S30 6u 40 | #define MD5S31 10u 41 | #define MD5S32 15u 42 | #define MD5S33 21u 43 | 44 | #define MD5C00 0xd76aa478u 45 | #define MD5C01 0xe8c7b756u 46 | #define MD5C02 0x242070dbu 47 | #define MD5C03 0xc1bdceeeu 48 | #define MD5C04 0xf57c0fafu 49 | #define MD5C05 0x4787c62au 50 | #define MD5C06 0xa8304613u 51 | #define MD5C07 0xfd469501u 52 | #define MD5C08 0x698098d8u 53 | #define MD5C09 0x8b44f7afu 54 | #define MD5C0a 0xffff5bb1u 55 | #define MD5C0b 0x895cd7beu 56 | #define MD5C0c 0x6b901122u 57 | #define MD5C0d 0xfd987193u 58 | #define MD5C0e 0xa679438eu 59 | #define MD5C0f 0x49b40821u 60 | #define MD5C10 0xf61e2562u 61 | #define MD5C11 0xc040b340u 62 | #define MD5C12 0x265e5a51u 63 | #define MD5C13 0xe9b6c7aau 64 | #define MD5C14 0xd62f105du 65 | #define MD5C15 0x02441453u 66 | #define MD5C16 0xd8a1e681u 67 | #define MD5C17 0xe7d3fbc8u 68 | #define MD5C18 0x21e1cde6u 69 | #define MD5C19 0xc33707d6u 70 | #define MD5C1a 0xf4d50d87u 71 | #define MD5C1b 0x455a14edu 72 | #define MD5C1c 0xa9e3e905u 73 | #define MD5C1d 0xfcefa3f8u 74 | #define MD5C1e 0x676f02d9u 75 | #define MD5C1f 0x8d2a4c8au 76 | #define MD5C20 0xfffa3942u 77 | #define MD5C21 0x8771f681u 78 | #define MD5C22 0x6d9d6122u 79 | #define MD5C23 0xfde5380cu 80 | #define MD5C24 0xa4beea44u 81 | #define MD5C25 0x4bdecfa9u 82 | #define MD5C26 0xf6bb4b60u 83 | #define MD5C27 0xbebfbc70u 84 | #define MD5C28 0x289b7ec6u 85 | #define MD5C29 0xeaa127fau 86 | #define MD5C2a 0xd4ef3085u 87 | #define MD5C2b 0x04881d05u 88 | #define MD5C2c 0xd9d4d039u 89 | #define MD5C2d 0xe6db99e5u 90 | #define MD5C2e 0x1fa27cf8u 91 | #define MD5C2f 0xc4ac5665u 92 | #define MD5C30 0xf4292244u 93 | #define MD5C31 0x432aff97u 94 | #define MD5C32 0xab9423a7u 95 | #define MD5C33 0xfc93a039u 96 | #define MD5C34 0x655b59c3u 97 | #define MD5C35 0x8f0ccc92u 98 | #define MD5C36 0xffeff47du 99 | #define MD5C37 0x85845dd1u 100 | #define MD5C38 0x6fa87e4fu 101 | #define MD5C39 0xfe2ce6e0u 102 | #define MD5C3a 0xa3014314u 103 | #define MD5C3b 0x4e0811a1u 104 | #define MD5C3c 0xf7537e82u 105 | #define MD5C3d 0xbd3af235u 106 | #define MD5C3e 0x2ad7d2bbu 107 | #define MD5C3f 0xeb86d391u 108 | 109 | #define MD5_F(x,y,z) z ^ (x & (y ^ z)) 110 | #define MD5_G(x,y,z) y ^ (z & (x ^ y)) 111 | #define MD5_H1(x,y,z) (tmp2 = (x ^ y)) ^ z 112 | #define MD5_H2(x,y,z) x ^ tmp2 113 | #define MD5_I(x,y,z) y ^ (x | ~z) 114 | 115 | #define MD5_Fo(x,y,z) bitselect (z, y, x) 116 | #define MD5_Go(x,y,z) bitselect (y, x, z) 117 | 118 | #define ROTL(a,n) rotate (a, n) 119 | 120 | #define MD5_STEP(f,a,b,c,d,x,K,s) \ 121 | { \ 122 | a += K; \ 123 | a += x; \ 124 | a += f (b, c, d); \ 125 | a = ROTL (a, s); \ 126 | a += b; \ 127 | } 128 | 129 | #define MD5_STEP0(f,a,b,c,d,K,s) \ 130 | { \ 131 | a += K; \ 132 | a += f (b, c, d); \ 133 | a = ROTL (a, s); \ 134 | a += b; \ 135 | } 136 | 137 | #define MD5_STEPZ(f,a,b,c,d,x,K,s) \ 138 | { \ 139 | a += x; \ 140 | a = ROTL (a, s); \ 141 | a += b; \ 142 | } 143 | 144 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | oclGaussCrack 2 | ============= 3 | 4 | Crack the verification hash of the encrypted payload of the Gauss Virus 5 | 6 | * Name....: oclGaussCrack 7 | * Version.: v1.4 8 | * Autor...: Jens Steube 9 | * License.: GPLv2 10 | * Language: C, OpenCL 11 | 12 | Why 13 | ------------- 14 | 15 | The goal of the program is to Crack the verification hash of the encrypted payload of the Gauss Virus as described here: https://www.securelist.com/en/blog/208193781/The_Mystery_of_the_Encrypted_Gauss_Payload 16 | 17 | * Uses OpenCL to accelerate the 10k MD5 loop 18 | * Uses optimizations also used in oclHashcat-plus for maximum performance 19 | * Able to handle multi-GPU setups (of the same type) 20 | * VCL (Virtual CL) v1.17 compatible 21 | * Open Source 22 | * Supports integration into distributed computing environments 23 | * Supports resume 24 | 25 | Install 26 | ------------- 27 | 28 | Make sure you have OpenCL enabled driver installed 29 | 30 | If you want to compile it from sources: 31 | 32 | Make sure to have an OpenCL SDK installed 33 | Just run "make" to compile 34 | 35 | Performance 36 | ------------- 37 | 38 | AMD Radeon HD 7970 (GPU) 489k c/s 39 | AMD Radeon HD 6990 (GPU) 670k c/s 40 | AMD FX 8120 (CPU) 14k c/s 41 | AMD FX 6100 (CPU) 11k c/s 42 | NVIDIA GeForce GTX 470 (GPU) 94k c/s 43 | NVIDIA GeForce GTX 560Ti (GPU) 86k c/s 44 | 45 | Intel CPU supporting OpenCL should work as well. 46 | 47 | You can increase the performance slightly by increasing the workload GPU_ACCEL in oclGaussCrack.c. 48 | To enable CPU mode change DEV_TYPE to CL_DEVICE_TYPE_CPU. 49 | 50 | How to use 51 | ------------- 52 | 53 | * The program waits for any arbitrary input data on stdin. This is your password / path / the unknown key. 54 | * It then appends the fixed salt to the input and processes the first MD5 on CPU. 55 | * The resulting digest is used as input for the 10k MD5 loops which is done on the GPU. 56 | * The hashes are compared on GPU. If they match, the GID which matched is stored in the result buffer. 57 | * The host program reads the result buffer and if the hash was cracked it uses the GID to lookup the original plaintext used. 58 | 59 | Example 60 | ------------- 61 | 62 | This is the official Kaspersky test-vector! 63 | 64 | NOTE: To enable "test mode", go to src/oclGaussCrack.cl and uncomment the target hash for the test vector in lines 31 - 37. 65 | 66 | $ ./oclGaussCrack64.bin < test.txt 67 | 68 | This should output: 69 | 70 | Loading Kernel... 71 | Initializing OpenCL... 72 | Found new device # 0: Tahiti, 32 compute units 73 | Initialization done, accepting candidates from stdin... 74 | 75 | 76 | GPU # 0: ALARM! Candidate number 0 cracked the hash! Hex dump following: 77 | 78 | 43 00 3a 00 5c 00 44 00 79 | 6f 00 63 00 75 00 6d 00 80 | 65 00 6e 00 74 00 73 00 81 | 20 00 61 00 6e 00 64 00 82 | 20 00 53 00 65 00 74 00 83 | 74 00 69 00 6e 00 67 00 84 | 73 00 5c 00 6a 00 6f 00 85 | 68 00 6e 00 5c 00 4c 00 86 | 6f 00 63 00 61 00 6c 00 87 | 20 00 53 00 65 00 74 00 88 | 74 00 69 00 6e 00 67 00 89 | 73 00 5c 00 41 00 70 00 90 | 70 00 6c 00 69 00 63 00 91 | 61 00 74 00 69 00 6f 00 92 | 6e 00 20 00 44 00 61 00 93 | 74 00 61 00 5c 00 47 00 94 | 6f 00 6f 00 67 00 6c 00 95 | 65 00 5c 00 43 00 68 00 96 | 72 00 6f 00 6d 00 65 00 97 | 5c 00 41 00 70 00 70 00 98 | 6c 00 69 00 63 00 61 00 99 | 74 00 69 00 6f 00 6e 00 100 | 7e 00 64 00 69 00 72 00 101 | 31 00 102 | 103 | 104 | This is how the test.txt file has been generated: 105 | 106 | $ echo -n "C:\Documents and Settings\john\Local Settings\Application Data\Google\Chrome\Application~dir1" | iconv -f utf8 -t utf16le > test.txt 107 | 108 | Parameters 109 | ------------- 110 | 111 | oclGaussCrack supports two optional parameters since v1.2. 112 | 113 | * The first one sets an offset that defines how many entries from input data to skip. 114 | * The second one sets an limitation that defines how many entries from input data to process. 115 | 116 | By doing this, you can pick a range of the workload coming on stdin. 117 | This is required to integrate oclGaussCrack into distributed computing services, like boinc or so. 118 | It is also useful if you want to continue your work at a specific point after it stopped for whatever reason. 119 | 120 | Both parameters are just numbers. You can set the first one without setting the second one but not vice versa. 121 | 122 | Limitations 123 | ------------- 124 | 125 | * Maximum input length of the string can be configured by changing MAX_LINELEN in program header. 126 | * Maximum number of GPUs suported can be configured by changing MAX_GPU in the program header. 127 | 128 | gaussFilter 129 | ------------- 130 | 131 | This tool simply skips all lines from a given input which must be encoded in utf16 in case the first character value <= 0x007a. 132 | It is useful since gauss filters all inputs from "%PROGRAMFILES%\*" where cFileName[0] > 0x007A (UNICODE 'z') 133 | By applying this filter we can reduce the keyspace to search a lot. 134 | 135 | Example usage: 136 | 137 | ./gaussFilter64.bin PROGRAMFILES.dict > PROGRAMFILES_filtered.dict 138 | 139 | gaussCombinator 140 | ------------- 141 | 142 | This tool simply concatinates two input sources encoded in utf16 in memory. 143 | It is useful since there are two input sources used in gauss to generate the key. 144 | 145 | Example usage: 146 | 147 | ./gaussCombinator64.bin GetEnvironmentVariableW.dict PROGRAMFILES_filtered.dict | ./gaussCrack64.bin 148 | 149 | 150 | -- 151 | 152 | USE AT YOUR OWN RISK. This software is provided 'AS IS' without any express or implied warranty of any kind. 153 | 154 | Copyright (c) 2012-2017, Jens Steube 155 | -------------------------------------------------------------------------------- /src/OpenCL.c: -------------------------------------------------------------------------------- 1 | void gc_clEnqueueNDRangeKernel (cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) 2 | { 3 | cl_int CL_err = clEnqueueNDRangeKernel (command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event); 4 | 5 | if (CL_err != CL_SUCCESS) 6 | { 7 | fprintf (stderr, "ERROR: %s %d\n", "clEnqueueNDRangeKernel()", CL_err); 8 | 9 | exit (-1); 10 | } 11 | } 12 | 13 | void gc_clFlush (cl_command_queue command_queue) 14 | { 15 | cl_int CL_err = clFlush (command_queue); 16 | 17 | if (CL_err != CL_SUCCESS) 18 | { 19 | fprintf (stderr, "ERROR: %s %d\n", "clFlush()", CL_err); 20 | 21 | exit (-1); 22 | } 23 | } 24 | 25 | void gc_clFinish (cl_command_queue command_queue) 26 | { 27 | cl_int CL_err = clFinish (command_queue); 28 | 29 | if (CL_err != CL_SUCCESS) 30 | { 31 | fprintf (stderr, "ERROR: %s %d\n", "clFinish()", CL_err); 32 | 33 | exit (-1); 34 | } 35 | } 36 | 37 | void gc_clSetKernelArg (cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value) 38 | { 39 | cl_int CL_err = clSetKernelArg (kernel, arg_index, arg_size, arg_value); 40 | 41 | if (CL_err != CL_SUCCESS) 42 | { 43 | fprintf (stderr, "ERROR: %s %d\n", "clSetKernelArg()", CL_err); 44 | 45 | exit (-1); 46 | } 47 | } 48 | 49 | void gc_clEnqueueWriteBuffer (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t cb, const void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) 50 | { 51 | cl_int CL_err = clEnqueueWriteBuffer (command_queue, buffer, blocking_write, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event); 52 | 53 | if (CL_err != CL_SUCCESS) 54 | { 55 | fprintf (stderr, "ERROR: %s %d\n", "clEnqueueWriteBuffer()", CL_err); 56 | 57 | exit (-1); 58 | } 59 | } 60 | 61 | void gc_clEnqueueReadBuffer (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t cb, void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) 62 | { 63 | cl_int CL_err = clEnqueueReadBuffer (command_queue, buffer, blocking_read, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event); 64 | 65 | if (CL_err != CL_SUCCESS) 66 | { 67 | fprintf (stderr, "ERROR: %s %d\n", "clEnqueueReadBuffer()", CL_err); 68 | 69 | exit (-1); 70 | } 71 | } 72 | 73 | void gc_clGetPlatformIDs (cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms) 74 | { 75 | cl_int CL_err = clGetPlatformIDs (num_entries, platforms, num_platforms); 76 | 77 | if (CL_err != CL_SUCCESS) 78 | { 79 | fprintf (stderr, "ERROR: %s %d\n", "clGetPlatformIDs()", CL_err); 80 | 81 | exit (-1); 82 | } 83 | } 84 | 85 | void gc_clGetPlatformInfo (cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) 86 | { 87 | cl_int CL_err = clGetPlatformInfo (platform, param_name, param_value_size, param_value, param_value_size_ret); 88 | 89 | if (CL_err != CL_SUCCESS) 90 | { 91 | fprintf (stderr, "ERROR: %s %d\n", "clGetPlatformInfo()", CL_err); 92 | 93 | exit (-1); 94 | } 95 | } 96 | 97 | void gc_clGetDeviceIDs (cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices) 98 | { 99 | cl_int CL_err = clGetDeviceIDs (platform, device_type, num_entries, devices, num_devices); 100 | 101 | if (CL_err != CL_SUCCESS) 102 | { 103 | fprintf (stderr, "ERROR: %s %d\n", "clGetDeviceIDs()", CL_err); 104 | 105 | exit (-1); 106 | } 107 | } 108 | 109 | void gc_clGetDeviceInfo (cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) 110 | { 111 | cl_int CL_err = clGetDeviceInfo (device, param_name, param_value_size, param_value, param_value_size_ret); 112 | 113 | if (CL_err != CL_SUCCESS) 114 | { 115 | fprintf (stderr, "ERROR: %s %d\n", "clGetDeviceInfo()", CL_err); 116 | 117 | exit (-1); 118 | } 119 | } 120 | 121 | cl_context gc_clCreateContext (cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, void (CL_CALLBACK *pfn_notify) (const char *, const void *, size_t, void *), void *user_data) 122 | { 123 | cl_int CL_err; 124 | 125 | cl_context context = clCreateContext (properties, num_devices, devices, pfn_notify, user_data, &CL_err); 126 | 127 | if (CL_err != CL_SUCCESS) 128 | { 129 | fprintf (stderr, "ERROR: %s %d\n", "clCreateContext()", CL_err); 130 | 131 | exit (-1); 132 | } 133 | 134 | return (context); 135 | } 136 | 137 | cl_command_queue gc_clCreateCommandQueue (cl_context context, cl_device_id device, cl_command_queue_properties properties) 138 | { 139 | cl_int CL_err; 140 | 141 | cl_command_queue command_queue = clCreateCommandQueue (context, device, properties, &CL_err); 142 | 143 | if (CL_err != CL_SUCCESS) 144 | { 145 | fprintf (stderr, "ERROR: %s %d\n", "clCreateCommandQueue()", CL_err); 146 | 147 | exit (-1); 148 | } 149 | 150 | return (command_queue); 151 | } 152 | 153 | cl_mem gc_clCreateBuffer (cl_context context, cl_mem_flags flags, size_t size, void *host_ptr) 154 | { 155 | cl_int CL_err; 156 | 157 | cl_mem mem = clCreateBuffer (context, flags, size, host_ptr, &CL_err); 158 | 159 | if (CL_err != CL_SUCCESS) 160 | { 161 | fprintf (stderr, "ERROR: %s %d\n", "clCreateBuffer()", CL_err); 162 | 163 | exit (-1); 164 | } 165 | 166 | return (mem); 167 | } 168 | 169 | cl_program gc_clCreateProgramWithSource (cl_context context, cl_uint count, const char **strings, const size_t *lengths) 170 | { 171 | cl_int CL_err; 172 | 173 | cl_program program = clCreateProgramWithSource (context, count, strings, lengths, &CL_err); 174 | 175 | if (CL_err != CL_SUCCESS) 176 | { 177 | fprintf (stderr, "ERROR: %s %d\n", "clCreateProgramWithSource()", CL_err); 178 | 179 | exit (-1); 180 | } 181 | 182 | return (program); 183 | } 184 | 185 | void gc_clBuildProgram (cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data) 186 | { 187 | cl_int CL_err = clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data); 188 | 189 | if (CL_err != CL_SUCCESS) 190 | { 191 | fprintf (stderr, "ERROR: %s %d\n", "clBuildProgram()", CL_err); 192 | 193 | exit (-1); 194 | } 195 | } 196 | 197 | cl_kernel gc_clCreateKernel (cl_program program, const char *kernel_name) 198 | { 199 | cl_int CL_err; 200 | 201 | cl_kernel kernel = clCreateKernel (program, kernel_name, &CL_err); 202 | 203 | if (CL_err != CL_SUCCESS) 204 | { 205 | fprintf (stderr, "ERROR: %s %d\n", "clCreateKernel()", CL_err); 206 | 207 | exit (-1); 208 | } 209 | 210 | return (kernel); 211 | } 212 | -------------------------------------------------------------------------------- /src/oclGaussCrack.cl: -------------------------------------------------------------------------------- 1 | /* 2 | * oclGaussCrack - OpenCL accelerated Gauss hash validator 3 | * 4 | * Copyright (C) 2012 Jens Steube 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * 20 | */ 21 | 22 | __constant uint TARGETS[4][4] = 23 | { 24 | { 0x9aa08e75, 0xcacb7d14, 0x8b55bdd6, 0xde7407e3 }, 25 | { 0x23172feb, 0xd91e2698, 0x21058d4c, 0x9b915066 }, 26 | { 0x6b4ddd52, 0xc4842d79, 0x8ea0e622, 0xb8ac7242 }, 27 | { 0xeafab353, 0x901bcc53, 0xcf5f2caa, 0xe2f91e83 }, 28 | }; 29 | 30 | /* 31 | __constant uint TARGETS[4][4] = 32 | { 33 | { 0xe75c4076, 0x355ee7f4, 0xd9d41c2c, 0x41beb6ae }, 34 | { 0, 0, 0, 0 }, 35 | { 0, 0, 0, 0 }, 36 | { 0, 0, 0, 0 }, 37 | }; 38 | */ 39 | 40 | #include "md5.c" 41 | 42 | #define ITERATIONS 10000 43 | 44 | typedef struct __block 45 | { 46 | uint4 buf[4]; 47 | 48 | } block_t; 49 | 50 | __kernel void oclGaussCrack (const __global block_t *blocks, __global uint *results) 51 | { 52 | const int gid = get_global_id (0); 53 | const int lid = get_local_id (0); 54 | 55 | uint4 W[4]; 56 | 57 | W[0] = blocks[gid].buf[0]; 58 | W[1] = blocks[gid].buf[1]; 59 | W[2] = blocks[gid].buf[2]; 60 | W[3] = blocks[gid].buf[3]; 61 | 62 | const uint W04 = 0x80; 63 | const uint W14 = 16 * 8; 64 | 65 | uint az = MD5M_A; 66 | uint bz = MD5M_B; 67 | uint cz = MD5M_C; 68 | uint dz = MD5M_D; 69 | 70 | az = az + MD5C00 + MD5_Fo (bz, cz, dz); 71 | 72 | for (int i = 0; i < ITERATIONS; i++) 73 | { 74 | uint4 tmp2; 75 | 76 | uint4 a = az; 77 | uint4 b = bz; 78 | uint4 c = cz; 79 | uint4 d = dz; 80 | 81 | MD5_STEPZ(MD5_Fo, a, b, c, d, W[0], MD5C00, MD5S00); 82 | MD5_STEP (MD5_Fo, d, a, b, c, W[1], MD5C01, MD5S01); 83 | MD5_STEP (MD5_Fo, c, d, a, b, W[2], MD5C02, MD5S02); 84 | MD5_STEP (MD5_Fo, b, c, d, a, W[3], MD5C03, MD5S03); 85 | MD5_STEP (MD5_Fo, a, b, c, d, W04, MD5C04, MD5S00); 86 | MD5_STEP0(MD5_Fo, d, a, b, c, MD5C05, MD5S01); 87 | MD5_STEP0(MD5_Fo, c, d, a, b, MD5C06, MD5S02); 88 | MD5_STEP0(MD5_Fo, b, c, d, a, MD5C07, MD5S03); 89 | MD5_STEP0(MD5_Fo, a, b, c, d, MD5C08, MD5S00); 90 | MD5_STEP0(MD5_Fo, d, a, b, c, MD5C09, MD5S01); 91 | MD5_STEP0(MD5_Fo, c, d, a, b, MD5C0a, MD5S02); 92 | MD5_STEP0(MD5_Fo, b, c, d, a, MD5C0b, MD5S03); 93 | MD5_STEP0(MD5_Fo, a, b, c, d, MD5C0c, MD5S00); 94 | MD5_STEP0(MD5_Fo, d, a, b, c, MD5C0d, MD5S01); 95 | MD5_STEP (MD5_Fo, c, d, a, b, W14, MD5C0e, MD5S02); 96 | MD5_STEP0(MD5_Fo, b, c, d, a, MD5C0f, MD5S03); 97 | 98 | MD5_STEP (MD5_Go, a, b, c, d, W[1], MD5C10, MD5S10); 99 | MD5_STEP0(MD5_Go, d, a, b, c, MD5C11, MD5S11); 100 | MD5_STEP0(MD5_Go, c, d, a, b, MD5C12, MD5S12); 101 | MD5_STEP (MD5_Go, b, c, d, a, W[0], MD5C13, MD5S13); 102 | MD5_STEP0(MD5_Go, a, b, c, d, MD5C14, MD5S10); 103 | MD5_STEP0(MD5_Go, d, a, b, c, MD5C15, MD5S11); 104 | MD5_STEP0(MD5_Go, c, d, a, b, MD5C16, MD5S12); 105 | MD5_STEP (MD5_Go, b, c, d, a, W04, MD5C17, MD5S13); 106 | MD5_STEP0(MD5_Go, a, b, c, d, MD5C18, MD5S10); 107 | MD5_STEP (MD5_Go, d, a, b, c, W14, MD5C19, MD5S11); 108 | MD5_STEP (MD5_Go, c, d, a, b, W[3], MD5C1a, MD5S12); 109 | MD5_STEP0(MD5_Go, b, c, d, a, MD5C1b, MD5S13); 110 | MD5_STEP0(MD5_Go, a, b, c, d, MD5C1c, MD5S10); 111 | MD5_STEP (MD5_Go, d, a, b, c, W[2], MD5C1d, MD5S11); 112 | MD5_STEP0(MD5_Go, c, d, a, b, MD5C1e, MD5S12); 113 | MD5_STEP0(MD5_Go, b, c, d, a, MD5C1f, MD5S13); 114 | 115 | MD5_STEP0(MD5_H1, a, b, c, d, MD5C20, MD5S20); 116 | MD5_STEP0(MD5_H2, d, a, b, c, MD5C21, MD5S21); 117 | MD5_STEP0(MD5_H1, c, d, a, b, MD5C22, MD5S22); 118 | MD5_STEP (MD5_H2, b, c, d, a, W14, MD5C23, MD5S23); 119 | MD5_STEP (MD5_H1, a, b, c, d, W[1], MD5C24, MD5S20); 120 | MD5_STEP (MD5_H2, d, a, b, c, W04, MD5C25, MD5S21); 121 | MD5_STEP0(MD5_H1, c, d, a, b, MD5C26, MD5S22); 122 | MD5_STEP0(MD5_H2, b, c, d, a, MD5C27, MD5S23); 123 | MD5_STEP0(MD5_H1, a, b, c, d, MD5C28, MD5S20); 124 | MD5_STEP (MD5_H2, d, a, b, c, W[0], MD5C29, MD5S21); 125 | MD5_STEP (MD5_H1, c, d, a, b, W[3], MD5C2a, MD5S22); 126 | MD5_STEP0(MD5_H2, b, c, d, a, MD5C2b, MD5S23); 127 | MD5_STEP0(MD5_H1, a, b, c, d, MD5C2c, MD5S20); 128 | MD5_STEP0(MD5_H2, d, a, b, c, MD5C2d, MD5S21); 129 | MD5_STEP0(MD5_H1, c, d, a, b, MD5C2e, MD5S22); 130 | MD5_STEP (MD5_H2, b, c, d, a, W[2], MD5C2f, MD5S23); 131 | 132 | MD5_STEP (MD5_I , a, b, c, d, W[0], MD5C30, MD5S30); 133 | MD5_STEP0(MD5_I , d, a, b, c, MD5C31, MD5S31); 134 | MD5_STEP (MD5_I , c, d, a, b, W14, MD5C32, MD5S32); 135 | MD5_STEP0(MD5_I , b, c, d, a, MD5C33, MD5S33); 136 | MD5_STEP0(MD5_I , a, b, c, d, MD5C34, MD5S30); 137 | MD5_STEP (MD5_I , d, a, b, c, W[3], MD5C35, MD5S31); 138 | MD5_STEP0(MD5_I , c, d, a, b, MD5C36, MD5S32); 139 | MD5_STEP (MD5_I , b, c, d, a, W[1], MD5C37, MD5S33); 140 | MD5_STEP0(MD5_I , a, b, c, d, MD5C38, MD5S30); 141 | MD5_STEP0(MD5_I , d, a, b, c, MD5C39, MD5S31); 142 | MD5_STEP0(MD5_I , c, d, a, b, MD5C3a, MD5S32); 143 | MD5_STEP0(MD5_I , b, c, d, a, MD5C3b, MD5S33); 144 | MD5_STEP (MD5_I , a, b, c, d, W04, MD5C3c, MD5S30); 145 | MD5_STEP0(MD5_I , d, a, b, c, MD5C3d, MD5S31); 146 | MD5_STEP (MD5_I , c, d, a, b, W[2], MD5C3e, MD5S32); 147 | MD5_STEP0(MD5_I , b, c, d, a, MD5C3f, MD5S33); 148 | 149 | W[0] = a + MD5M_A; 150 | W[1] = b + MD5M_B; 151 | W[2] = c + MD5M_C; 152 | W[3] = d + MD5M_D; 153 | } 154 | 155 | for (int i = 0; i < 4; i++) 156 | { 157 | const uint target_a = TARGETS[i][0]; 158 | const uint target_b = TARGETS[i][1]; 159 | const uint target_c = TARGETS[i][2]; 160 | const uint target_d = TARGETS[i][3]; 161 | 162 | if (all (W[0] != target_a)) continue; 163 | if (all (W[1] != target_b)) continue; 164 | if (all (W[2] != target_c)) continue; 165 | if (all (W[3] != target_d)) continue; 166 | 167 | const int gid4 = gid * 4; 168 | 169 | if ((W[0].s0 == target_a) 170 | && (W[1].s0 == target_b) 171 | && (W[2].s0 == target_c) 172 | && (W[3].s0 == target_d)) results[lid] = gid4 + 0; 173 | 174 | if ((W[0].s1 == target_a) 175 | && (W[1].s1 == target_b) 176 | && (W[2].s1 == target_c) 177 | && (W[3].s1 == target_d)) results[lid] = gid4 + 1; 178 | 179 | if ((W[0].s2 == target_a) 180 | && (W[1].s2 == target_b) 181 | && (W[2].s2 == target_c) 182 | && (W[3].s2 == target_d)) results[lid] = gid4 + 2; 183 | 184 | if ((W[0].s3 == target_a) 185 | && (W[1].s3 == target_b) 186 | && (W[2].s3 == target_c) 187 | && (W[3].s3 == target_d)) results[lid] = gid4 + 3; 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /doc/LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /src/oclGaussCrack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * oclGaussCrack - OpenCL accelerated Gauss hash validator 3 | * 4 | * Copyright (C) 2012 Jens Steube 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * 20 | */ 21 | 22 | #define CL_TARGET_OPENCL_VERSION 120 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "md5.c" 39 | #include "OpenCL.c" 40 | 41 | #define KERNEL_SRC "src/oclGaussCrack.cl" 42 | #define KERNEL_NAME "oclGaussCrack" 43 | #define POTFILE "oclGaussCrack.pot" 44 | #define BUILD_OPTS "-I . -I src" 45 | #define DEV_TYPE CL_DEVICE_TYPE_GPU 46 | #define MAX_LINELEN 256 + 100 47 | #define MAX_PLATFORM 16 48 | #define MAX_GPU 16 49 | #define VECT_SIZE 4 // must be power of 2 50 | #define GPU_THREADS 64 // must be power of 2 51 | #define GPU_ACCEL 32 52 | 53 | #define rotate(x,n) (x << n) | (x >> (32 - n)) 54 | 55 | #define timer_set(a) gettimeofday (a, NULL) 56 | 57 | #define timer_get(a,r) \ 58 | { \ 59 | struct timeval hr_tmp; \ 60 | timer_set (&hr_tmp); \ 61 | r = ((hr_tmp.tv_sec - a.tv_sec) * 1000) \ 62 | + ((hr_tmp.tv_usec - a.tv_usec) / 1000); \ 63 | } 64 | 65 | typedef struct __block 66 | { 67 | /* it is using uint4 in kernel thats why this looks a bit weird */ 68 | 69 | cl_uint A[4]; 70 | cl_uint B[4]; 71 | cl_uint C[4]; 72 | cl_uint D[4]; 73 | 74 | } block_t; 75 | 76 | typedef struct 77 | { 78 | cl_context context; 79 | cl_program program; 80 | cl_kernel kernel; 81 | cl_command_queue command_queue; 82 | 83 | cl_uint max_compute_units; 84 | uint32_t num_threads; 85 | uint32_t num_elements; 86 | uint32_t num_cached; 87 | uint32_t num_work; 88 | 89 | uint8_t **plains_buf; 90 | size_t *plains_len; 91 | 92 | cl_mem d_block; 93 | cl_mem d_results; 94 | block_t *h_block; 95 | uint32_t *h_results; 96 | 97 | struct timeval timer; 98 | 99 | } gpu_ctx_t; 100 | 101 | static void dump_hex (FILE *fd, const uint8_t *s, const size_t sz) 102 | { 103 | for (size_t i = 0; i < sz; i += 8) 104 | { 105 | for (size_t j = 0; j < 8; j += 1) 106 | { 107 | const size_t pos = i + j; 108 | 109 | if (pos == sz) break; 110 | 111 | fprintf (fd, "%02x ", s[pos]); 112 | } 113 | 114 | fprintf (fd, "\n"); 115 | } 116 | 117 | fprintf (fd, "\n"); 118 | } 119 | 120 | static void calc_work (const cl_uint num_devices, gpu_ctx_t *gpu_ctxs) 121 | { 122 | for (cl_uint device_id = 0; device_id < num_devices; device_id++) 123 | { 124 | gpu_ctx_t *gpu_ctx = &gpu_ctxs[device_id]; 125 | 126 | if (gpu_ctx->num_cached == 0) continue; 127 | 128 | gpu_ctx->num_work = ((gpu_ctx->num_cached + (VECT_SIZE - 1)) & ~(VECT_SIZE - 1)) / VECT_SIZE; 129 | } 130 | } 131 | 132 | static void launch_kernel (const cl_uint num_devices, gpu_ctx_t *gpu_ctxs) 133 | { 134 | for (cl_uint device_id = 0; device_id < num_devices; device_id++) 135 | { 136 | gpu_ctx_t *gpu_ctx = &gpu_ctxs[device_id]; 137 | 138 | if (gpu_ctx->num_work == 0) continue; 139 | 140 | timer_set (&gpu_ctx->timer); 141 | 142 | const size_t size_block = gpu_ctx->num_work * sizeof (block_t); 143 | 144 | gc_clEnqueueWriteBuffer (gpu_ctx->command_queue, gpu_ctx->d_block, CL_FALSE, 0, size_block, gpu_ctx->h_block, 0, NULL, NULL); 145 | 146 | size_t global_work_size[3] = { gpu_ctx->num_work, 1, 1 }; 147 | size_t local_work_size[3] = { gpu_ctx->num_threads, 1, 1 }; 148 | 149 | while (global_work_size[0] % local_work_size[0]) global_work_size[0]++; 150 | 151 | gc_clEnqueueNDRangeKernel (gpu_ctx->command_queue, gpu_ctx->kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); 152 | 153 | gc_clFlush (gpu_ctx->command_queue); 154 | } 155 | } 156 | 157 | static void check_results (const cl_uint num_devices, gpu_ctx_t *gpu_ctxs) 158 | { 159 | static uint64_t total = 0; 160 | 161 | for (cl_uint device_id = 0; device_id < num_devices; device_id++) 162 | { 163 | gpu_ctx_t *gpu_ctx = &gpu_ctxs[device_id]; 164 | 165 | if (gpu_ctx->num_cached == 0) continue; 166 | 167 | const size_t size_results = gpu_ctx->num_threads * sizeof (uint32_t); 168 | 169 | gc_clEnqueueReadBuffer (gpu_ctx->command_queue, gpu_ctx->d_results, CL_TRUE, 0, size_results, gpu_ctx->h_results, 0, NULL, NULL); 170 | 171 | for (uint32_t thread = 0; thread < gpu_ctx->num_threads; thread++) 172 | { 173 | if (gpu_ctx->h_results[thread] != 0xffffffff) 174 | { 175 | uint32_t gid = gpu_ctx->h_results[thread]; 176 | 177 | fprintf (stdout, "\nGPU #%2d: ALARM! Candidate number %u cracked the hash! Hex dump following:\n\n", device_id, gid); 178 | 179 | dump_hex (stdout, gpu_ctx->plains_buf[gid], gpu_ctx->plains_len[gid]); 180 | 181 | FILE *fd = fopen (POTFILE, "ab"); 182 | 183 | if (fd) // ignore error 184 | { 185 | fprintf (fd, "\nGPU #%2d: ALARM! Candidate number %u cracked the hash! Hex dump following:\n\n", device_id, gid); 186 | 187 | dump_hex (fd, gpu_ctx->plains_buf[gid], gpu_ctx->plains_len[gid]); 188 | 189 | fclose (fd); 190 | } 191 | 192 | exit (0); 193 | } 194 | } 195 | 196 | const uint32_t num_cached = gpu_ctx->num_cached; 197 | 198 | total += num_cached; 199 | 200 | float ms; 201 | 202 | timer_get (gpu_ctx->timer, ms); 203 | 204 | if (ms == 0) continue; 205 | 206 | float speed = (num_cached / ms) * 1000; 207 | 208 | printf ("GPU #%2d: %u candidates in %u ms [%u/s] - Total = %llu...\n", device_id, num_cached, (uint32_t) ms, (uint32_t) speed, (long long unsigned int) total); 209 | } 210 | } 211 | 212 | static void md5_transform (uint32_t *W, const uint32_t len, uint32_t digest[4]) 213 | { 214 | // prepare some stuff 215 | 216 | digest[0] = MD5M_A; 217 | digest[1] = MD5M_B; 218 | digest[2] = MD5M_C; 219 | digest[3] = MD5M_D; 220 | 221 | uint32_t len_pad = (len + 0x3f) & ~0x3f; 222 | 223 | uint8_t *ptr = (uint8_t *) W; 224 | 225 | memset (ptr + len, 0, len_pad - len); 226 | 227 | ptr[len] = 0x80; 228 | 229 | W[((len_pad - 64) / 4) + 14] = len * 8; 230 | 231 | // loop that 232 | 233 | for (uint32_t i = len_pad; i >= 55; i -= 64, W += 16) 234 | { 235 | uint32_t a = digest[0]; 236 | uint32_t b = digest[1]; 237 | uint32_t c = digest[2]; 238 | uint32_t d = digest[3]; 239 | 240 | uint32_t tmp2; 241 | 242 | MD5_STEP (MD5_F , a, b, c, d, W[ 0], MD5C00, MD5S00); 243 | MD5_STEP (MD5_F , d, a, b, c, W[ 1], MD5C01, MD5S01); 244 | MD5_STEP (MD5_F , c, d, a, b, W[ 2], MD5C02, MD5S02); 245 | MD5_STEP (MD5_F , b, c, d, a, W[ 3], MD5C03, MD5S03); 246 | MD5_STEP (MD5_F , a, b, c, d, W[ 4], MD5C04, MD5S00); 247 | MD5_STEP (MD5_F , d, a, b, c, W[ 5], MD5C05, MD5S01); 248 | MD5_STEP (MD5_F , c, d, a, b, W[ 6], MD5C06, MD5S02); 249 | MD5_STEP (MD5_F , b, c, d, a, W[ 7], MD5C07, MD5S03); 250 | MD5_STEP (MD5_F , a, b, c, d, W[ 8], MD5C08, MD5S00); 251 | MD5_STEP (MD5_F , d, a, b, c, W[ 9], MD5C09, MD5S01); 252 | MD5_STEP (MD5_F , c, d, a, b, W[10], MD5C0a, MD5S02); 253 | MD5_STEP (MD5_F , b, c, d, a, W[11], MD5C0b, MD5S03); 254 | MD5_STEP (MD5_F , a, b, c, d, W[12], MD5C0c, MD5S00); 255 | MD5_STEP (MD5_F , d, a, b, c, W[13], MD5C0d, MD5S01); 256 | MD5_STEP (MD5_F , c, d, a, b, W[14], MD5C0e, MD5S02); 257 | MD5_STEP (MD5_F , b, c, d, a, W[15], MD5C0f, MD5S03); 258 | 259 | MD5_STEP (MD5_G , a, b, c, d, W[ 1], MD5C10, MD5S10); 260 | MD5_STEP (MD5_G , d, a, b, c, W[ 6], MD5C11, MD5S11); 261 | MD5_STEP (MD5_G , c, d, a, b, W[11], MD5C12, MD5S12); 262 | MD5_STEP (MD5_G , b, c, d, a, W[ 0], MD5C13, MD5S13); 263 | MD5_STEP (MD5_G , a, b, c, d, W[ 5], MD5C14, MD5S10); 264 | MD5_STEP (MD5_G , d, a, b, c, W[10], MD5C15, MD5S11); 265 | MD5_STEP (MD5_G , c, d, a, b, W[15], MD5C16, MD5S12); 266 | MD5_STEP (MD5_G , b, c, d, a, W[ 4], MD5C17, MD5S13); 267 | MD5_STEP (MD5_G , a, b, c, d, W[ 9], MD5C18, MD5S10); 268 | MD5_STEP (MD5_G , d, a, b, c, W[14], MD5C19, MD5S11); 269 | MD5_STEP (MD5_G , c, d, a, b, W[ 3], MD5C1a, MD5S12); 270 | MD5_STEP (MD5_G , b, c, d, a, W[ 8], MD5C1b, MD5S13); 271 | MD5_STEP (MD5_G , a, b, c, d, W[13], MD5C1c, MD5S10); 272 | MD5_STEP (MD5_G , d, a, b, c, W[ 2], MD5C1d, MD5S11); 273 | MD5_STEP (MD5_G , c, d, a, b, W[ 7], MD5C1e, MD5S12); 274 | MD5_STEP (MD5_G , b, c, d, a, W[12], MD5C1f, MD5S13); 275 | 276 | MD5_STEP (MD5_H1, a, b, c, d, W[ 5], MD5C20, MD5S20); 277 | MD5_STEP (MD5_H2, d, a, b, c, W[ 8], MD5C21, MD5S21); 278 | MD5_STEP (MD5_H1, c, d, a, b, W[11], MD5C22, MD5S22); 279 | MD5_STEP (MD5_H2, b, c, d, a, W[14], MD5C23, MD5S23); 280 | MD5_STEP (MD5_H1, a, b, c, d, W[ 1], MD5C24, MD5S20); 281 | MD5_STEP (MD5_H2, d, a, b, c, W[ 4], MD5C25, MD5S21); 282 | MD5_STEP (MD5_H1, c, d, a, b, W[ 7], MD5C26, MD5S22); 283 | MD5_STEP (MD5_H2, b, c, d, a, W[10], MD5C27, MD5S23); 284 | MD5_STEP (MD5_H1, a, b, c, d, W[13], MD5C28, MD5S20); 285 | MD5_STEP (MD5_H2, d, a, b, c, W[ 0], MD5C29, MD5S21); 286 | MD5_STEP (MD5_H1, c, d, a, b, W[ 3], MD5C2a, MD5S22); 287 | MD5_STEP (MD5_H2, b, c, d, a, W[ 6], MD5C2b, MD5S23); 288 | MD5_STEP (MD5_H1, a, b, c, d, W[ 9], MD5C2c, MD5S20); 289 | MD5_STEP (MD5_H2, d, a, b, c, W[12], MD5C2d, MD5S21); 290 | MD5_STEP (MD5_H1, c, d, a, b, W[15], MD5C2e, MD5S22); 291 | MD5_STEP (MD5_H2, b, c, d, a, W[ 2], MD5C2f, MD5S23); 292 | 293 | MD5_STEP (MD5_I , a, b, c, d, W[ 0], MD5C30, MD5S30); 294 | MD5_STEP (MD5_I , d, a, b, c, W[ 7], MD5C31, MD5S31); 295 | MD5_STEP (MD5_I , c, d, a, b, W[14], MD5C32, MD5S32); 296 | MD5_STEP (MD5_I , b, c, d, a, W[ 5], MD5C33, MD5S33); 297 | MD5_STEP (MD5_I , a, b, c, d, W[12], MD5C34, MD5S30); 298 | MD5_STEP (MD5_I , d, a, b, c, W[ 3], MD5C35, MD5S31); 299 | MD5_STEP (MD5_I , c, d, a, b, W[10], MD5C36, MD5S32); 300 | MD5_STEP (MD5_I , b, c, d, a, W[ 1], MD5C37, MD5S33); 301 | MD5_STEP (MD5_I , a, b, c, d, W[ 8], MD5C38, MD5S30); 302 | MD5_STEP (MD5_I , d, a, b, c, W[15], MD5C39, MD5S31); 303 | MD5_STEP (MD5_I , c, d, a, b, W[ 6], MD5C3a, MD5S32); 304 | MD5_STEP (MD5_I , b, c, d, a, W[13], MD5C3b, MD5S33); 305 | MD5_STEP (MD5_I , a, b, c, d, W[ 4], MD5C3c, MD5S30); 306 | MD5_STEP (MD5_I , d, a, b, c, W[11], MD5C3d, MD5S31); 307 | MD5_STEP (MD5_I , c, d, a, b, W[ 2], MD5C3e, MD5S32); 308 | MD5_STEP (MD5_I , b, c, d, a, W[ 9], MD5C3f, MD5S33); 309 | 310 | digest[0] += a; 311 | digest[1] += b; 312 | digest[2] += c; 313 | digest[3] += d; 314 | } 315 | } 316 | 317 | int main (int argc, char *argv[]) 318 | { 319 | uint64_t skip = 0; 320 | uint64_t left = -1; 321 | 322 | if (argc >= 2) skip = atoll (argv[1]); 323 | if (argc >= 3) left = atoll (argv[2]); 324 | 325 | printf ("Loading Kernel...\n"); 326 | 327 | const char *filename = KERNEL_SRC; 328 | 329 | struct stat s; 330 | 331 | if (stat (filename, &s) == -1) 332 | { 333 | fprintf (stderr, "%s: %s in line %d\n", filename, strerror (errno), __LINE__); 334 | 335 | return (-1); 336 | } 337 | 338 | FILE *fp = fopen (filename, "rb"); 339 | 340 | if (fp == NULL) 341 | { 342 | fprintf (stderr, "%s: %s in line %d\n", filename, strerror (errno), __LINE__); 343 | 344 | return (-1); 345 | } 346 | 347 | char *source_buf = (char *) malloc (s.st_size + 1); 348 | 349 | if (!fread (source_buf, sizeof (char), s.st_size, fp)) 350 | { 351 | fprintf (stderr, "%s: %s in line %d\n", filename, strerror (errno), __LINE__); 352 | 353 | return (-1); 354 | } 355 | 356 | source_buf[s.st_size] = 0; 357 | 358 | fclose (fp); 359 | 360 | const char *sourceBuf[] = { source_buf }; 361 | 362 | const size_t sourceLen[] = { s.st_size + 1 }; 363 | 364 | printf ("Initializing OpenCL...\n"); 365 | 366 | cl_platform_id platform; 367 | 368 | cl_uint num_devices = 0; 369 | 370 | cl_device_id devices[MAX_PLATFORM]; 371 | 372 | gc_clGetPlatformIDs (1, &platform, NULL); 373 | 374 | gc_clGetDeviceIDs (platform, DEV_TYPE, MAX_PLATFORM, devices, &num_devices); 375 | 376 | gpu_ctx_t gpu_ctxs[MAX_GPU]; 377 | 378 | memset (gpu_ctxs, 0, sizeof (gpu_ctxs)); 379 | 380 | for (cl_uint device_id = 0; device_id < num_devices; device_id++) 381 | { 382 | cl_device_id device = devices[device_id]; 383 | 384 | cl_context context = gc_clCreateContext (NULL, 1, &device, NULL, NULL); 385 | 386 | cl_program program = gc_clCreateProgramWithSource (context, 1, sourceBuf, sourceLen); 387 | 388 | gc_clBuildProgram (program, 1, &device, BUILD_OPTS, NULL, NULL); 389 | 390 | cl_kernel kernel = gc_clCreateKernel (program, KERNEL_NAME); 391 | 392 | cl_command_queue command_queue = gc_clCreateCommandQueue (context, device, 0); 393 | 394 | cl_uint max_compute_units; 395 | 396 | gc_clGetDeviceInfo (device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof (max_compute_units), &max_compute_units, NULL); 397 | 398 | char device_name[BUFSIZ]; 399 | 400 | memset (device_name, 0, sizeof (device_name)); 401 | 402 | gc_clGetDeviceInfo (device, CL_DEVICE_NAME, sizeof (device_name), &device_name, NULL); 403 | 404 | printf ("Found new device #%2d: %s, %u compute units\n", device_id, device_name, max_compute_units); 405 | 406 | const int num_threads = GPU_THREADS; 407 | const int num_elements = max_compute_units * num_threads * GPU_ACCEL; 408 | 409 | /** 410 | * GPU memory 411 | */ 412 | 413 | const size_t size_block = num_elements * sizeof (block_t); 414 | const size_t size_results = num_threads * sizeof (uint32_t); 415 | 416 | cl_mem d_block = gc_clCreateBuffer (context, CL_MEM_READ_ONLY, size_block, NULL); 417 | 418 | cl_mem d_results = gc_clCreateBuffer (context, CL_MEM_WRITE_ONLY, size_results, NULL); 419 | 420 | gc_clSetKernelArg (kernel, 0, sizeof (cl_mem), (void *) &d_block); 421 | gc_clSetKernelArg (kernel, 1, sizeof (cl_mem), (void *) &d_results); 422 | 423 | /** 424 | * Host memory 425 | */ 426 | 427 | block_t *h_block = (block_t *) malloc (size_block); 428 | 429 | uint32_t *h_results = (uint32_t *) malloc (size_results); 430 | 431 | memset (h_results, 0xff, size_results); 432 | 433 | gc_clEnqueueWriteBuffer (command_queue, d_results, CL_TRUE, 0, size_results, h_results, 0, NULL, NULL); 434 | 435 | /** 436 | * Buffers for candidates 437 | */ 438 | 439 | uint8_t **plains_buf = (uint8_t **) calloc (num_elements * VECT_SIZE, sizeof (uint8_t *)); 440 | 441 | for (int i = 0; i < num_elements * VECT_SIZE; i++) 442 | { 443 | /* Agreed, this is not nice. But who cares nowadays? */ 444 | 445 | plains_buf[i] = (uint8_t *) malloc (MAX_LINELEN); 446 | } 447 | 448 | size_t *plains_len = (size_t *) calloc (num_elements * VECT_SIZE, sizeof (size_t)); 449 | 450 | gpu_ctx_t *gpu_ctx = &gpu_ctxs[device_id]; 451 | 452 | gpu_ctx->context = context; 453 | gpu_ctx->program = program; 454 | gpu_ctx->kernel = kernel; 455 | gpu_ctx->command_queue = command_queue; 456 | gpu_ctx->max_compute_units = max_compute_units; 457 | gpu_ctx->d_block = d_block; 458 | gpu_ctx->d_results = d_results; 459 | gpu_ctx->h_block = h_block; 460 | gpu_ctx->h_results = h_results; 461 | gpu_ctx->num_threads = num_threads; 462 | gpu_ctx->num_elements = num_elements; 463 | gpu_ctx->plains_buf = plains_buf; 464 | gpu_ctx->plains_len = plains_len; 465 | } 466 | 467 | /* static salt */ 468 | 469 | const uint8_t salt_buf[16] = 470 | { 471 | 0x97, 0x48, 0x6C, 0xAA, 472 | 0x22, 0x5F, 0xE8, 0x77, 473 | 0xC0, 0x35, 0xCC, 0x03, 474 | 0x73, 0x23, 0x6D, 0x51 475 | }; 476 | 477 | const size_t salt_len = sizeof (salt_buf); 478 | 479 | /* main loop */ 480 | 481 | printf ("Initialization done, accepting candidates from stdin...\n\n"); 482 | 483 | cl_uint cur_device_id = 0; 484 | 485 | while (!feof (stdin)) 486 | { 487 | /* Get new password candidate from stdin */ 488 | 489 | uint8_t line_buf[MAX_LINELEN]; 490 | 491 | int cur_c = 0; 492 | 493 | int prev_c = 0; 494 | 495 | size_t line_len = 0; 496 | 497 | for (size_t i = 0; i < MAX_LINELEN - 100; i++) // - 100 = we need some space for salt and padding 498 | { 499 | cur_c = getchar (); 500 | 501 | if (cur_c == EOF) break; 502 | 503 | if ((prev_c == '\n') && (cur_c == '\0')) 504 | { 505 | line_len--; 506 | 507 | break; 508 | } 509 | 510 | line_buf[line_len] = cur_c; 511 | 512 | line_len++; 513 | 514 | prev_c = cur_c; 515 | } 516 | 517 | /* chop \r if it exists for some reason (in case user used a dictionary) */ 518 | 519 | if (line_len >= 2) 520 | { 521 | if ((prev_c == '\r') && (cur_c == '\0')) line_len -= 2; 522 | } 523 | 524 | /* skip empty lines */ 525 | 526 | if (line_len == 0) continue; 527 | 528 | /* The following enables distributed computing / resume work */ 529 | 530 | if (skip) 531 | { 532 | skip--; 533 | 534 | continue; 535 | } 536 | 537 | if (left) 538 | { 539 | left--; 540 | } 541 | else 542 | { 543 | break; 544 | } 545 | 546 | /* Append constant salt */ 547 | 548 | memcpy (line_buf + line_len, salt_buf, salt_len); 549 | 550 | line_len += salt_len; 551 | 552 | /* Generate digest out of it */ 553 | 554 | uint32_t digest[4]; 555 | 556 | md5_transform ((uint32_t *) line_buf, (uint32_t) line_len, digest); 557 | 558 | /* Next garanteed free GPU */ 559 | 560 | gpu_ctx_t *gpu_ctx = &gpu_ctxs[cur_device_id]; 561 | 562 | /* Save original buffer in case it cracks it */ 563 | 564 | memcpy (gpu_ctx->plains_buf[gpu_ctx->num_cached], line_buf, line_len - salt_len); 565 | 566 | gpu_ctx->plains_len[gpu_ctx->num_cached] = line_len - salt_len; 567 | 568 | /* Next garanteed free memory element on that GPU */ 569 | 570 | const uint32_t element_div = gpu_ctx->num_cached / 4; 571 | const uint32_t element_mod = gpu_ctx->num_cached % 4; 572 | 573 | /* Copy new digest */ 574 | 575 | gpu_ctx->h_block[element_div].A[element_mod] = digest[0]; 576 | gpu_ctx->h_block[element_div].B[element_mod] = digest[1]; 577 | gpu_ctx->h_block[element_div].C[element_mod] = digest[2]; 578 | gpu_ctx->h_block[element_div].D[element_mod] = digest[3]; 579 | 580 | gpu_ctx->num_cached++; 581 | 582 | /* If memory elements on that GPU are full, switch to the next GPU */ 583 | 584 | if ((gpu_ctx->num_cached / VECT_SIZE) < gpu_ctx->num_elements) continue; 585 | 586 | cur_device_id++; 587 | 588 | /* If there is no more GPU left, run the calculation */ 589 | 590 | if (cur_device_id < num_devices) continue; 591 | 592 | /* Fire! */ 593 | 594 | calc_work (num_devices, gpu_ctxs); 595 | 596 | launch_kernel (num_devices, gpu_ctxs); 597 | 598 | /* Collecting data has a blocking effect */ 599 | 600 | check_results (num_devices, gpu_ctxs); 601 | 602 | /* Reset buffer state */ 603 | 604 | for (cl_uint device_id = 0; device_id < num_devices; device_id++) 605 | { 606 | gpu_ctx_t *gpu_ctx = &gpu_ctxs[device_id]; 607 | 608 | gpu_ctx->num_cached = 0; 609 | } 610 | 611 | cur_device_id = 0; 612 | } 613 | 614 | /* Final calculation of leftovers */ 615 | 616 | calc_work (num_devices, gpu_ctxs); 617 | 618 | launch_kernel (num_devices, gpu_ctxs); 619 | 620 | check_results (num_devices, gpu_ctxs); 621 | 622 | return -1; 623 | } 624 | --------------------------------------------------------------------------------