forked from programmingmind/cudaRSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crackRSA.cu
50 lines (35 loc) · 1.22 KB
/
crackRSA.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// driver for rsa cracking
#include <stdio.h>
#include "common.h"
#include "gcd.h"
//Main function to read keys from file and then matrix, yeah!
int main (int argc, char * argv[]) {
char *res, *cudaRes;
bigInt *numbers, *cudaNums;
if (argc != 2) {
printf("error, syntax is %s <file name>\n", argv[0]);
return 0;
}
int numKeys = readFile(argv[1], &numbers, &res);
int countBytes = 1 + ((numKeys - 1) /8);
int numSize = SIZE_BYTES * numKeys;
cudaMalloc(&cudaNums, numSize);
cudaMalloc(&cudaRes, numKeys * countBytes);
cudaMemset(cudaRes, 0, numKeys * countBytes);
cudaMemcpy(cudaNums, numbers, numSize, cudaMemcpyHostToDevice);
int dimBlock = SIZE*2;
int dimGrid = 1 + ((numKeys - 1) / dimBlock);
printf("%d blocks of size %d\n", dimGrid, dimBlock);
//Lets gcd
for (int offset = 0; offset < numKeys; offset += WORK_SIZE) {
// <<<dimGrid, dimBlock>>>
findGCDs<<<dimGrid, dimBlock>>>(cudaNums, numKeys, cudaRes, offset);
}
cudaMemcpy(res, cudaRes, numKeys * countBytes, cudaMemcpyDeviceToHost);
cudaFree(cudaNums);
cudaFree(cudaRes);
writeFiles("privateKeys", numKeys, numbers, res);
free(numbers);
free(res);
return 0;
}