Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PRODUCT_NAME "CUDA SHA-1 Tripper 0.2.1"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <windows.h>
- #include <search.h>
- // default files
- #define TARGET_FILE "target.txt"
- #define TRIP_FILE "trip.txt"
- char target_file[256], trip_file[256];
- typedef unsigned long DWORD; // 32bit
- typedef unsigned short WORD; // 16bit
- typedef unsigned char BYTE; // 8bit
- struct st_sha1trip{
- unsigned int count;
- BYTE key[10];
- BYTE trip[10];
- };
- // 128 threads per block, each block is divided into 4 warps
- #define BLOCK_SIZE_X 64
- #define BLOCK_SIZE_Y 2
- // max is StreamingMultiprocessor * 8
- // StreamingMultiprocessor consists of 8 StreamingProcessor
- unsigned int blocks;
- // size of array R (BLOCK_SIZE_X * BLOCK_SIZE_Y * blocks * sizeof(st_sha1trip))
- unsigned long R_size;
- // SHA-1 input message block
- __device__ __constant__ BYTE Md[64];
- #define TARGETS_MAX 5000
- char target[TARGETS_MAX][14];
- unsigned int target_num;
- __device__ __constant__ DWORD target_dw[TARGETS_MAX];
- __device__ __constant__ unsigned int target_dw_num;
- const char b64t[] = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
- 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
- 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '/'
- };
- st_sha1trip *R, *Rd;
- FILE *fp_trip;
- // constants and initial values defined in SHA-1
- #define K0 0x5A827999
- #define K1 0x6ED9EBA1
- #define K2 0x8F1BBCDC
- #define K3 0xCA62C1D6
- #define H0 0x67452301
- #define H1 0xEFCDAB89
- #define H2 0x98BADCFE
- #define H3 0x10325476
- #define H4 0xC3D2E1F0
- ////////////////////////////////////////////////////////////////////////////////
- #define ROL32(_val32, _nBits) (((_val32)<<(_nBits))|((_val32)>>(32-(_nBits))))
- #define _R0(v,w,x,y,z,i) { z += ((w&(x^y))^y) + i + K0 + ROL32(v,5); w=ROL32(w,30); }
- #define _R00(v,w,x,y,z) { z += ((w&(x^y))^y) + K0 + ROL32(v,5); w=ROL32(w,30); }
- #define _R2(v,w,x,y,z,i) { z += (w^x^y) + i + K1 + ROL32(v,5); w=ROL32(w,30); }
- #define _R4(v,w,x,y,z,i) { z += (((w|x)&y)|(w&x)) + i + K2 + ROL32(v,5); w=ROL32(w,30); }
- #define _R6(v,w,x,y,z,i) { z += (w^x^y) + i + K3 + ROL32(v,5); w=ROL32(w,30); }
- __device__ __constant__ char b64t_d[] = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
- 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
- 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '/'
- };
- // sha1trip_search
- // R - Result array (BLOCK_SIZE_X * BLOCK_SIZE_Y * blocks array of st_sha1trip)
- __global__ void sha1trip_search(st_sha1trip *R)
- {
- DWORD W0, W1, W2, W3, W4, W5, W6, W7, W8, W9, W10, W11, W12, W13, W14, W15;
- DWORD a, b, c, d, e;
- // 32 * 64 = 2048
- for (unsigned int Npass = 0; Npass < 2048; Npass++){
- __syncthreads();
- a = H0;
- b = H1;
- c = H2;
- d = H3;
- e = H4;
- // copy message block
- W0 = Md[0] << 24 | Md[1] << 16 | Md[2] << 8 | Md[3];
- W1 = Md[4] << 24 | Md[5] << 16 | Md[6] << 8;
- W1 |= b64t_d[(Md[7] + (Npass >> 5)) & 63];
- W2 = b64t_d[(Md[8] + (blockIdx.x >> 6)) & 63] << 24;
- W2 |= b64t_d[(Md[9] + blockIdx.x) & 63] << 16;
- W2 |= b64t_d[(Npass & 31) * BLOCK_SIZE_Y + threadIdx.y] << 8;
- W2 |= b64t_d[threadIdx.x];
- W3 = 0x80000000; // padding
- /*
- W4 = 0;
- W5 = 0;
- W6 = 0;
- W7 = 0;
- W8 = 0;
- W9 = 0;
- W10 = 0;
- W11 = 0;
- W12 = 0;
- W13 = 0;
- W14 = 0;
- */
- W15 = 96; // bits of Message Block (12 bytes * 8 bits)
- // round 0 to 15
- _R0(a, b, c, d, e, W0);
- _R0(e, a, b, c, d, W1);
- _R0(d, e, a, b, c, W2);
- _R0(c, d, e, a, b, W3);
- _R00(b, c, d, e, a); // W4 == 0
- _R00(a, b, c, d, e); // W5 == 0
- _R00(e, a, b, c, d); // W6 == 0
- _R00(d, e, a, b, c); // W7 == 0
- _R00(c, d, e, a, b); // W8 == 0
- _R00(b, c, d, e, a); // W9 == 0
- _R00(a, b, c, d, e); // W10 == 0
- _R00(e, a, b, c, d); // W11 == 0
- _R00(d, e, a, b, c); // W12 == 0
- _R00(c, d, e, a, b); // W13 == 0
- _R00(b, c, d, e, a); // W14 == 0
- _R0(a, b, c, d, e, W15);
- // W[t] = ROL32(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1);
- W0 = ROL32(W2 ^ W0, 1); // (t, W[t-3], W[t-8], W[t-14], W[t-16]) = (16, W13==0, W8==0, W2, W0)
- W1 = ROL32(W3 ^ W1, 1); // 17, W14==0, W9==0, W3, W1
- W2 = ROL32(W15 ^ W2, 1); // 18, W15, W10==0, W4==0, W2
- W3 = ROL32(W0 ^ W3, 1); // 19, W0, W11==0, W5==0, W3
- W4 = ROL32(W1, 1); // 20, W1, W12==0, W6==0, W4==0
- W5 = ROL32(W2, 1); // 21, W2, W13==0, W7==0, W5==0
- W6 = ROL32(W3, 1); // 22, W3, W14==0, W8==0, W6==0
- W7 = ROL32(W4 ^ W15, 1); // 23, W4, W15, W9==0, W7==0
- W8 = ROL32(W5 ^ W0, 1); // 24, W5, W0, W10==0, W8==0
- W9 = ROL32(W6 ^ W1, 1); // 25, W6, W1, W11==0, W9==0
- W10 = ROL32(W7 ^ W2, 1); // 26, W7, W2, W12==0, W10==0
- W11 = ROL32(W8 ^ W3, 1); // 27, W8, W3, W13==0, W11==0
- W12 = ROL32(W9 ^ W4, 1); // 28, W9, W4, W14==0, W12==0
- W13 = ROL32(W10 ^ W5 ^ W15, 1); // 29, W10, W5, W15, W13==0
- W14 = ROL32(W11 ^ W6 ^ W0, 1); // 30, W11, W6, W0, W14==0
- W15 = ROL32(W12 ^ W7 ^ W1 ^ W15, 1); // 31, W12, W7, W1, W15
- // round 16 to 19
- _R0(e, a, b, c, d, W0);
- _R0(d, e, a, b, c, W1);
- _R0(c, d, e, a, b, W2);
- _R0(b, c, d, e, a, W3);
- // round 20 to 31
- _R2(a, b, c, d, e, W4);
- _R2(e, a, b, c, d, W5);
- _R2(d, e, a, b, c, W6);
- _R2(c, d, e, a, b, W7);
- _R2(b, c, d, e, a, W8);
- _R2(a, b, c, d, e, W9);
- _R2(e, a, b, c, d, W10);
- _R2(d, e, a, b, c, W11);
- _R2(c, d, e, a, b, W12);
- _R2(b, c, d, e, a, W13);
- _R2(a, b, c, d, e, W14);
- _R2(e, a, b, c, d, W15);
- // W[t] = ROL32(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1);
- W0 = ROL32(W13 ^ W8 ^ W2 ^ W0, 1); // t==32
- W1 = ROL32(W14 ^ W9 ^ W3 ^ W1, 1);
- W2 = ROL32(W15 ^ W10 ^ W4 ^ W2, 1);
- W3 = ROL32(W0 ^ W11 ^ W5 ^ W3, 1);
- W4 = ROL32(W1 ^ W12 ^ W6 ^ W4, 1);
- W5 = ROL32(W2 ^ W13 ^ W7 ^ W5, 1);
- W6 = ROL32(W3 ^ W14 ^ W8 ^ W6, 1);
- W7 = ROL32(W4 ^ W15 ^ W9 ^ W7, 1);
- W8 = ROL32(W5 ^ W0 ^ W10 ^ W8, 1);
- W9 = ROL32(W6 ^ W1 ^ W11 ^ W9, 1);
- W10 = ROL32(W7 ^ W2 ^ W12 ^ W10, 1);
- W11 = ROL32(W8 ^ W3 ^ W13 ^ W11, 1);
- W12 = ROL32(W9 ^ W4 ^ W14 ^ W12, 1);
- W13 = ROL32(W10 ^ W5 ^ W15 ^ W13, 1);
- W14 = ROL32(W11 ^ W6 ^ W0 ^ W14, 1);
- W15 = ROL32(W12 ^ W7 ^ W1 ^ W15, 1); // t==47
- // round 32 to 39
- _R2(d, e, a, b, c, W0);
- _R2(c, d, e, a, b, W1);
- _R2(b, c, d, e, a, W2);
- _R2(a, b, c, d, e, W3);
- _R2(e, a, b, c, d, W4);
- _R2(d, e, a, b, c, W5);
- _R2(c, d, e, a, b, W6);
- _R2(b, c, d, e, a, W7);
- // round 40 to 47
- _R4(a, b, c, d, e, W8);
- _R4(e, a, b, c, d, W9);
- _R4(d, e, a, b, c, W10);
- _R4(c, d, e, a, b, W11);
- _R4(b, c, d, e, a, W12);
- _R4(a, b, c, d, e, W13);
- _R4(e, a, b, c, d, W14);
- _R4(d, e, a, b, c, W15);
- // W[t] = ROL32(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1);
- W0 = ROL32(W13 ^ W8 ^ W2 ^ W0, 1); // t==48
- W1 = ROL32(W14 ^ W9 ^ W3 ^ W1, 1);
- W2 = ROL32(W15 ^ W10 ^ W4 ^ W2, 1);
- W3 = ROL32(W0 ^ W11 ^ W5 ^ W3, 1);
- W4 = ROL32(W1 ^ W12 ^ W6 ^ W4, 1);
- W5 = ROL32(W2 ^ W13 ^ W7 ^ W5, 1);
- W6 = ROL32(W3 ^ W14 ^ W8 ^ W6, 1);
- W7 = ROL32(W4 ^ W15 ^ W9 ^ W7, 1);
- W8 = ROL32(W5 ^ W0 ^ W10 ^ W8, 1);
- W9 = ROL32(W6 ^ W1 ^ W11 ^ W9, 1);
- W10 = ROL32(W7 ^ W2 ^ W12 ^ W10, 1);
- W11 = ROL32(W8 ^ W3 ^ W13 ^ W11, 1);
- W12 = ROL32(W9 ^ W4 ^ W14 ^ W12, 1);
- W13 = ROL32(W10 ^ W5 ^ W15 ^ W13, 1);
- W14 = ROL32(W11 ^ W6 ^ W0 ^ W14, 1);
- W15 = ROL32(W12 ^ W7 ^ W1 ^ W15, 1); // t==63
- // round 48 to 59
- _R4(c, d, e, a, b, W0);
- _R4(b, c, d, e, a, W1);
- _R4(a, b, c, d, e, W2);
- _R4(e, a, b, c, d, W3);
- _R4(d, e, a, b, c, W4);
- _R4(c, d, e, a, b, W5);
- _R4(b, c, d, e, a, W6);
- _R4(a, b, c, d, e, W7);
- _R4(e, a, b, c, d, W8);
- _R4(d, e, a, b, c, W9);
- _R4(c, d, e, a, b, W10);
- _R4(b, c, d, e, a, W11);
- // round 60 to 63
- _R6(a, b, c, d, e, W12);
- _R6(e, a, b, c, d, W13);
- _R6(d, e, a, b, c, W14);
- _R6(c, d, e, a, b, W15);
- // W[t] = ROL32(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1);
- W0 = ROL32(W13 ^ W8 ^ W2 ^ W0, 1); // t==64
- W1 = ROL32(W14 ^ W9 ^ W3 ^ W1, 1);
- W2 = ROL32(W15 ^ W10 ^ W4 ^ W2, 1);
- W3 = ROL32(W0 ^ W11 ^ W5 ^ W3, 1);
- W4 = ROL32(W1 ^ W12 ^ W6 ^ W4, 1);
- W5 = ROL32(W2 ^ W13 ^ W7 ^ W5, 1);
- W6 = ROL32(W3 ^ W14 ^ W8 ^ W6, 1);
- W7 = ROL32(W4 ^ W15 ^ W9 ^ W7, 1);
- W8 = ROL32(W5 ^ W0 ^ W10 ^ W8, 1);
- W9 = ROL32(W6 ^ W1 ^ W11 ^ W9, 1);
- W10 = ROL32(W7 ^ W2 ^ W12 ^ W10, 1);
- W11 = ROL32(W8 ^ W3 ^ W13 ^ W11, 1);
- W12 = ROL32(W9 ^ W4 ^ W14 ^ W12, 1);
- W13 = ROL32(W10 ^ W5 ^ W15 ^ W13, 1);
- W14 = ROL32(W11 ^ W6 ^ W0 ^ W14, 1);
- W15 = ROL32(W12 ^ W7 ^ W1 ^ W15, 1); // t==79
- // round 64 to 79
- _R6(b, c, d, e, a, W0);
- _R6(a, b, c, d, e, W1);
- _R6(e, a, b, c, d, W2);
- _R6(d, e, a, b, c, W3);
- _R6(c, d, e, a, b, W4);
- _R6(b, c, d, e, a, W5);
- _R6(a, b, c, d, e, W6);
- _R6(e, a, b, c, d, W7);
- _R6(d, e, a, b, c, W8);
- _R6(c, d, e, a, b, W9);
- _R6(b, c, d, e, a, W10);
- _R6(a, b, c, d, e, W11);
- _R6(e, a, b, c, d, W12);
- _R6(d, e, a, b, c, W13);
- _R6(c, d, e, a, b, W14);
- _R6(b, c, d, e, a, W15);
- a += H0;
- // need 30 bits for compare
- DWORD tmp_dw = a & 0xfffffffc;
- for (unsigned int i = 0; i < target_dw_num; i++){
- if (target_dw[i] == tmp_dw){
- b += H1;
- c += H2;
- st_sha1trip *out = &R[(blockIdx.x * BLOCK_SIZE_Y + threadIdx.y) * BLOCK_SIZE_X + threadIdx.x];
- out->count = Npass + 1;
- /*
- out->key[0] = Md[0];
- out->key[1] = Md[1];
- out->key[2] = Md[2];
- out->key[3] = Md[3];
- out->key[4] = Md[4];
- out->key[5] = Md[5];
- out->key[6] = Md[6];
- */
- out->key[7] = b64t_d[(Md[7] + (Npass >> 5)) & 63];
- out->key[8] = b64t_d[(Md[8] + (blockIdx.x >> 6)) & 63];
- out->key[9] = b64t_d[(Md[9] + blockIdx.x) & 63];
- out->key[10] = b64t_d[(Npass & 31) * BLOCK_SIZE_Y + threadIdx.y];
- out->key[11] = b64t_d[threadIdx.x];
- out->trip[0] = b64t_d[a >> 26];
- out->trip[1] = b64t_d[(a >> 20) & 63];
- out->trip[2] = b64t_d[(a >> 14) & 63];
- out->trip[3] = b64t_d[(a >> 8) & 63];
- out->trip[4] = b64t_d[(a >> 2) & 63];
- out->trip[5] = b64t_d[(a << 4 | b >> 28) & 63];
- out->trip[6] = b64t_d[(b >> 22) & 63];
- out->trip[7] = b64t_d[(b >> 16) & 63];
- out->trip[8] = b64t_d[(b >> 10) & 63];
- out->trip[9] = b64t_d[(b >> 4) & 63];
- out->trip[10] = b64t_d[(b << 2 | c >> 30) & 63];
- out->trip[11] = b64t_d[(c >> 24) & 63];
- return;
- }
- }
- }
- R[(blockIdx.x * BLOCK_SIZE_Y + threadIdx.y) * BLOCK_SIZE_X + threadIdx.x].count = 2048;
- return;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // for qsort()
- int compare_dw(const void *_a, const void *_b)
- {
- DWORD a = *(DWORD *)_a;
- DWORD b = *(DWORD *)_b;
- if (a < b){ return -1;}
- if (a > b){ return 1;}
- return 0;
- }
- // for qsort()
- int compare_str(const void *a, const void *b)
- {
- return strcmp((char *)a, (char *)b);
- }
- size_t uniq(void *array, size_t num, size_t size, int (*comp)(const void *, const void *))
- {
- char *start = (char *)array;
- char *stop = (char *)array + (size * (num - 1));
- char *dst = start;
- char *p = start;
- while (p <= stop){
- char *q = p;
- while ((q < stop) && comp(q, q + size)){
- q += size;
- }
- size_t elements = ((q - p) / size) + 1;
- memmove(dst, p, size * elements);
- dst += size * elements;
- p = q + size;
- while ((p <= stop) && comp(q, p) == 0){
- p += size;
- }
- }
- return (dst - start) / size;
- }
- int set_targets()
- {
- FILE *fp;
- char buf[256];
- DWORD target_dw_h[TARGETS_MAX];
- unsigned int target_dw_num_h;
- memset(target, 0, sizeof(target));
- if ((fp = fopen(target_file, "r")) == NULL){
- printf("Cannot open target file \"%s\"\n", target_file);
- exit(-1);
- }
- for (target_num = 0; target_num < TARGETS_MAX; ){
- fgets(buf, sizeof(buf), fp);
- if (feof(fp)){ break;}
- if (ferror(fp)){
- printf("Read error target file \"%s\"\n", target_file);
- fclose(fp);
- exit(-1);
- }
- if (buf[0] == '#' || buf[0] == '\n'){ continue;}
- for (int i = 0; i < 12; i++){
- if (buf[i] == '\n' || buf[i] == ' ' || buf[i] == '\t'){ break;}
- target[target_num][i] = buf[i];
- }
- if (strlen(target[target_num]) < 5){ continue;}
- // Base64 decode
- for (int i = 0; i < 5; i++){
- if (buf[i] >= 'A' && buf[i] <= 'Z'){
- buf[i] = buf[i] - 'A';
- }
- else if (buf[i] >= 'a' && buf[i] <= 'z'){
- buf[i] = buf[i] - 'a' + 26;
- }
- else if (buf[i] >= '0' && buf[i] <= '9'){
- buf[i] = buf[i] - '0' + 52;
- }
- else if (buf[i] == '.'){
- buf[i] = 62;
- }
- else if (buf[i] == '/'){
- buf[i] = 63;
- }
- }
- target_dw_h[target_num] = ((buf[0]<<2 | buf[1]>>4) & 0xff) << 24;
- target_dw_h[target_num] |= ((buf[1]<<4 | buf[2]>>2) & 0xff) << 16;
- target_dw_h[target_num] |= ((buf[2]<<6 | buf[3]) & 0xff) << 8;
- target_dw_h[target_num] |= (buf[4]<<2) & 0xff;
- printf("target %2d: %s\t\t%08x\n", target_num, target[target_num], target_dw_h[target_num]);
- target_num++;
- }
- fclose(fp);
- if (target_num == 0){
- printf("There is no target string\n");
- exit(-1);
- }
- qsort(target, target_num, sizeof(target[0]), compare_str);
- target_dw_num_h = target_num;
- qsort(target_dw_h, target_dw_num_h, sizeof(DWORD), compare_dw);
- target_dw_num_h = uniq(target_dw_h, target_dw_num_h, sizeof(DWORD), compare_dw);
- printf("\n%d targets found, target_dw_num is %d\n\n", target_num, target_dw_num_h);
- cudaMemcpyToSymbol(target_dw, target_dw_h, sizeof(DWORD) * target_dw_num_h);
- cudaMemcpyToSymbol("target_dw_num", &target_dw_num_h, sizeof(int));
- return 0;
- }
- // pseudo-random number generator
- unsigned long xor128()
- {
- // static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
- static unsigned long x=123456789, y=362436069, z=521288629, w=GetTickCount();
- unsigned long t;
- t=(x^(x<<11)); x=y; y=z; z=w;
- return( w=(w^(w>>19))^(t^(t>>8)) );
- }
- // ConsoleCtrlHandler
- BOOL handler(DWORD dwCtrlType)
- {
- fclose(fp_trip);
- cudaFree(Rd);
- free(R);
- return FALSE;
- }
- void usage(char *argv0)
- {
- printf("Usage:\n");
- printf(" %s [-d device] [-x blocks_per_sm] [-o trip_file] [-f target_file]\n\n", argv0);
- exit(-1);
- }
- int main(int argc, char **argv)
- {
- int deviceCount;
- BYTE M[64] = {0};
- char key[16] = {0}, trip[16] = {0};
- DWORD t1, t2;
- double delta_sec;
- unsigned long count;
- int device = 0, blocks_per_sm = 2;
- cudaDeviceProp deviceProp;
- printf("%s\n\n", PRODUCT_NAME);
- cudaGetDeviceCount(&deviceCount);
- if (deviceCount == 0){
- printf("There is no device supporting CUDA\n\n");
- exit(-1);
- }
- for (int i = 0; i < deviceCount; i++){
- cudaGetDeviceProperties(&deviceProp, i);
- printf("Device %d: \"%s\"\n", i, deviceProp.name);
- printf(" Revision number: %d.%d\n",
- deviceProp.major, deviceProp.minor);
- printf(" Total amount of global memory: %u Mbytes\n",
- deviceProp.totalGlobalMem / (1024 * 1024));
- printf(" Number of multiprocessors: %d\n",
- deviceProp.multiProcessorCount);
- printf(" Number of cores: %d\n",
- deviceProp.multiProcessorCount * 8);
- printf(" Clock rate: %.2f GHz\n\n",
- deviceProp.clockRate * 1e-6f);
- }
- strncpy(trip_file, TRIP_FILE, sizeof(trip_file));
- strncpy(target_file, TARGET_FILE, sizeof(target_file));
- if (argc > 1){
- for (int i = 1; i < argc; i++){
- if (argv[i][0] == '-' && argv[i][1] == 'd'){
- if (++i == argc){ usage(argv[0]);}
- device = atoi(argv[i]);
- }
- else if (argv[i][0] == '-' && argv[i][1] == 'x'){
- if (++i == argc){ usage(argv[0]);}
- blocks_per_sm = atoi(argv[i]);
- }
- else if (argv[i][0] == '-' && argv[i][1] == 'o'){
- if (++i == argc){ usage(argv[0]);}
- strncpy(trip_file, argv[i], sizeof(trip_file));
- trip_file[sizeof(trip_file) - 1] = 0;
- }
- else if (argv[i][0] == '-' && argv[i][1] == 'f'){
- if (++i == argc){ usage(argv[0]);}
- strncpy(target_file, argv[i], sizeof(target_file));
- target_file[sizeof(target_file) - 1] = 0;
- }
- else {
- usage(argv[0]);
- }
- }
- }
- if (device >= deviceCount){
- printf("Only %d devices supporting CUDA\n\n", deviceCount);
- exit(-1);
- }
- if (blocks_per_sm < 1 || blocks_per_sm > 8){
- printf("Blocks_per_SM must be 1 to 8\n\n");
- exit(-1);
- }
- cudaGetDeviceProperties(&deviceProp, device);
- blocks = deviceProp.multiProcessorCount * blocks_per_sm;
- cudaSetDevice(device);
- printf("Use device %d, grid is %d blocks\n\n", device, blocks);
- R_size = BLOCK_SIZE_X * BLOCK_SIZE_Y * blocks * sizeof(st_sha1trip);
- set_targets();
- if ((fp_trip = fopen(trip_file, "a")) == NULL){
- printf("Cannot open trip file \"%s\"\n", trip_file);
- exit(-1);
- }
- R = (st_sha1trip *) malloc(R_size);
- if (! R){
- fprintf(stderr, "malloc() error!\n");
- exit(-1);
- }
- memset(R, 0, R_size);
- cudaMalloc((void **)&Rd, R_size);
- M[12] = 0x80; // start of padding
- M[63] = 96; // bits of Message Block (12 bytes * 8 bits)
- SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
- SetConsoleCtrlHandler((PHANDLER_ROUTINE)handler, TRUE);
- // main loop
- for ( ; ; ){
- t1 = GetTickCount();
- count = 0;
- for (int i = 0; i < 6; i++){
- key[i] = b64t[xor128() & 63];
- }
- BYTE c7 = (BYTE)(xor128() & 63);
- key[7] = c7;
- BYTE c8 = (BYTE)(xor128() & 63);
- key[8] = c8;
- BYTE c9 = (BYTE)(xor128() & 63);
- key[9] = c9;
- for (BYTE c6 = 0; c6 < 64; c6++){
- key[6] = b64t[c6];
- memcpy(M, key, 10);
- cudaMemcpyToSymbol(Md, M, 64);
- cudaMemcpy(Rd, R, R_size, cudaMemcpyHostToDevice);
- dim3 dimBlock(BLOCK_SIZE_X, BLOCK_SIZE_Y);
- dim3 dimGrid(blocks);
- sha1trip_search<<<dimGrid, dimBlock>>>(Rd);
- cudaMemcpy(R, Rd, R_size, cudaMemcpyDeviceToHost);
- for (unsigned int r_index = 0; r_index < BLOCK_SIZE_X * BLOCK_SIZE_Y * blocks; r_index++){
- st_sha1trip *out = &R[r_index];
- count += out->count;
- if (! out->trip[0]){
- continue;
- }
- memcpy(trip, out->trip, 12);
- for (int lower = 0, upper = target_num -1; lower <= upper; ){
- int middle = (lower + upper) >> 1;
- if (strncmp(target[middle], trip, strlen(target[middle])) < 0){
- lower = middle + 1;
- }
- else if (strncmp(target[middle], trip, strlen(target[middle])) > 0){
- upper = middle - 1;
- }
- else {
- memcpy(key + 7, out->key + 7, 5);
- fprintf(fp_trip, "%s\t#%s\n", trip, key);
- fflush(fp_trip);
- break;
- }
- }
- }
- memset(R, 0, R_size);
- }
- t2 = GetTickCount();
- if (t2 > t1){
- delta_sec = (t2 - t1) * 0.001;
- }
- else {
- delta_sec = 4294967.296 + t2 * 0.001 - t1 * 0.001;
- }
- printf("%d kTrips in %.3f sec - %.3f MTrips/sec\n",
- count / 1000, delta_sec, (count / delta_sec) * 0.000001);
- }
- // never reach here
- fclose(fp_trip);
- cudaFree(Rd);
- free(R);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment