fork(1) download
  1. #include <stdio.h>
  2. #include <getopt.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <math.h>
  7. #include <stdbool.h>
  8. #include <sys/time.h>
  9.  
  10. typedef unsigned int uint;
  11. typedef unsigned long long ull;
  12.  
  13. __device__ uint LR(uint a, int x){
  14. return a << x | a >> 32-x;
  15. }
  16.  
  17. __global__ void sha1_kernel(ull* res, ull IDX) {
  18. ull id = threadIdx.x | (ull)blockIdx.x << 10 | (ull)blockIdx.y << 20 | (ull)IDX << 32, idx = id;
  19. uint h0, h1, h2, h3, h4;
  20. h0 = 0x63744d88; h1 = 0xf3eeebf1; h2 = 0x2e63d1c4; h3 = 0x761de6c4; h4 = 0x98de7acd;
  21.  
  22. uint w[16];
  23. for(int i = 0; i < 8; i++, idx >>= 16){
  24. w[i] = 0x40404040u | (idx&15) << 24 | (idx>>4&15) << 16 | (idx>>8&15) << 8 | (idx>>12&15);
  25. }
  26. w[8] = 0x0a800000;
  27. for(int i = 9; i < 15; i++) w[i] = 0;
  28. w[15] = 1800;
  29.  
  30. uint a, b, c, d, e, f, k;
  31. a = h0; b = h1; c = h2; d = h3; e = h4;
  32. for(int i = 0; i < 16; i++){
  33. f = (b&c)|(~b&d);
  34. k = 0x5A827999;
  35. uint tmp = LR(a, 5) + f + e + k + w[i&15];
  36. e = d; d = c; c = LR(b, 30); b = a; a = tmp;
  37. }
  38. for(int i = 16; i < 20; i++){
  39. w[i&15] = LR(w[i-3&15]^w[i-8&15]^w[i-14&15]^w[i&15], 1);
  40.  
  41. f = (b&c)|(~b&d);
  42. k = 0x5A827999;
  43.  
  44. uint tmp = LR(a, 5) + f + e + k + w[i&15];
  45. e = d; d = c; c = LR(b, 30); b = a; a = tmp;
  46. }
  47. for(int i = 20; i < 40; i++){
  48. w[i&15] = LR(w[i-3&15]^w[i-8&15]^w[i-14&15]^w[i&15], 1);
  49.  
  50. f = (b^c^d);
  51. k = 0x6ED9EBA1;
  52.  
  53. uint tmp = LR(a, 5) + f + e + k + w[i&15];
  54. e = d; d = c; c = LR(b, 30); b = a; a = tmp;
  55. }
  56. for(int i = 40; i < 60; i++){
  57. w[i&15] = LR(w[i-3&15]^w[i-8&15]^w[i-14&15]^w[i&15], 1);
  58.  
  59. f = (b&c)|(b&d)|(c&d);
  60. k = 0x8F1BBCDC;
  61.  
  62. uint tmp = LR(a, 5) + f + e + k + w[i&15];
  63. e = d; d = c; c = LR(b, 30); b = a; a = tmp;
  64. }
  65. for(int i = 60; i < 80; i++){
  66. w[i&15] = LR(w[i-3&15]^w[i-8&15]^w[i-14&15]^w[i&15], 1);
  67.  
  68. f = b^c^d;
  69. k = 0xCA62C1D6;
  70.  
  71. uint tmp = LR(a, 5) + f + e + k + w[i&15];
  72. e = d; d = c; c = LR(b, 30); b = a; a = tmp;
  73. }
  74. h0 = h0 + a;
  75. h1 = h1 + b;
  76. h2 = h2 + c;
  77. h3 = h3 + d;
  78. h4 = h4 + e;
  79. if(h0 == 0 && (h1 >> 20) == 0) *res = id;
  80. }
  81.  
  82. const int SZ = 4096 * 4096;
  83.  
  84. ull *res;
  85. ull res_copy;
  86.  
  87. int main()
  88. {
  89. dim3 threadsPerBlock(1024, 1);
  90. dim3 numBlocks(1024, 4096);
  91.  
  92. cudaMalloc(&res, sizeof(ull));
  93.  
  94. for(int i = 200000;; i++){
  95. printf("IDX : %d\n", i);
  96. sha1_kernel<<<numBlocks, threadsPerBlock>>>(res, i);
  97.  
  98. cudaMemcpy(&res_copy, res, sizeof(ull), cudaMemcpyDeviceToHost);
  99. if(res_copy == 0) continue;
  100. for(int i = 0; i < 16; i++){
  101. printf("%c", 64 | res_copy&15);
  102. res_copy /= 16;
  103. }
  104. break;
  105. }
  106. }
  107.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:13:1: error: ‘__device__’ does not name a type
 __device__ uint LR(uint a, int x){
 ^~~~~~~~~~
prog.cpp:17:1: error: ‘__global__’ does not name a type
 __global__ void sha1_kernel(ull* res, ull IDX) {
 ^~~~~~~~~~
prog.cpp: In function ‘int main()’:
prog.cpp:89:2: error: ‘dim3’ was not declared in this scope
  dim3 threadsPerBlock(1024, 1);
  ^~~~
prog.cpp:90:7: error: expected ‘;’ before ‘numBlocks’
  dim3 numBlocks(1024, 4096);
       ^~~~~~~~~
prog.cpp:92:30: error: ‘cudaMalloc’ was not declared in this scope
  cudaMalloc(&res, sizeof(ull));
                              ^
prog.cpp:96:3: error: ‘sha1_kernel’ was not declared in this scope
   sha1_kernel<<<numBlocks, threadsPerBlock>>>(res, i);
   ^~~~~~~~~~~
prog.cpp:96:16: error: expected primary-expression before ‘<’ token
   sha1_kernel<<<numBlocks, threadsPerBlock>>>(res, i);
                ^
prog.cpp:96:17: error: ‘numBlocks’ was not declared in this scope
   sha1_kernel<<<numBlocks, threadsPerBlock>>>(res, i);
                 ^~~~~~~~~
prog.cpp:96:28: error: ‘threadsPerBlock’ was not declared in this scope
   sha1_kernel<<<numBlocks, threadsPerBlock>>>(res, i);
                            ^~~~~~~~~~~~~~~
prog.cpp:96:45: error: expected primary-expression before ‘>’ token
   sha1_kernel<<<numBlocks, threadsPerBlock>>>(res, i);
                                             ^
prog.cpp:98:43: error: ‘cudaMemcpyDeviceToHost’ was not declared in this scope
   cudaMemcpy(&res_copy, res, sizeof(ull), cudaMemcpyDeviceToHost);
                                           ^~~~~~~~~~~~~~~~~~~~~~
prog.cpp:98:65: error: ‘cudaMemcpy’ was not declared in this scope
   cudaMemcpy(&res_copy, res, sizeof(ull), cudaMemcpyDeviceToHost);
                                                                 ^
stdout
Standard output is empty