|
7 | 7 | #include "../globals.h" |
8 | 8 |
|
9 | 9 | int compare_candidates(FILE **file, char *password_hash, int verbose); |
| 10 | +int run_chunk(char *password_hash, char **candidate_array, int chunk_size, int verbose); |
10 | 11 |
|
11 | 12 | /** |
12 | 13 | * dictionary_crack() - OpenMP Implementation |
@@ -67,18 +68,45 @@ int compare_candidates(FILE **file, char *password_hash, int verbose) |
67 | 68 | remove_new_line(line, &candidate_array[counter]); |
68 | 69 | if (counter++ == CHUNK_SIZE) |
69 | 70 | { |
70 | | - #pragma omp parallel |
71 | | - #pragma omp for schedule(auto) |
72 | | - for (counter=0; counter<CHUNK_SIZE; counter++) |
73 | | - { |
74 | | - int tempResult = do_comparison(password_hash, candidate_array[counter], verbose); |
75 | | - if (tempResult == FOUND) { |
76 | | - #pragma omp critical |
77 | | - result = FOUND; |
78 | | - } |
79 | | - } |
80 | | - counter = 0; |
| 71 | + result = run_chunk(password_hash, candidate_array, CHUNK_SIZE, verbose); |
| 72 | + counter=0; |
81 | 73 | } |
| 74 | + } |
| 75 | + // finish off remaining work that didn't fit in a chunk. |
| 76 | + if (counter > 0) |
| 77 | + { |
| 78 | + result = run_chunk(password_hash, candidate_array, counter, verbose); |
| 79 | + } |
| 80 | + return result; |
| 81 | +} |
| 82 | + |
| 83 | +/** |
| 84 | + * run_chunk() - does hash comaprison on a chunk of passwords read from disk |
| 85 | + * (OpenMP Implementation) |
| 86 | + * |
| 87 | + * 1. Manages iterating through the dictionary file and initiating the has comparisons. |
| 88 | + * 2. Returns the result value (FOUND or NOT_FOUND) and the plain text password, if found. |
| 89 | + * |
| 90 | + * @param file is a pointer to the dictionary file in memory. |
| 91 | + * @param password_hash is the hashed password string to crack. |
| 92 | + * @param candidate_array is the array of candidate passwords. |
| 93 | + * @param array_size is the size of the candidate array. |
| 94 | + * @param verbose is a flag for verbose mode. Set to 1 to enable. |
| 95 | + * @return the result as an integer value, FOUND (0) or NOT_FOUND (1). |
| 96 | + */ |
| 97 | +int run_chunk(char *password_hash, char **candidate_array, int array_size, int verbose) |
| 98 | +{ |
| 99 | + int result = NOT_FOUND; |
| 100 | + int i; |
| 101 | + #pragma omp parallel |
| 102 | + #pragma omp for schedule(auto) |
| 103 | + for (i=0; i<array_size; i++) |
| 104 | + { |
| 105 | + int tempResult = do_comparison(password_hash, candidate_array[i], verbose); |
| 106 | + if (tempResult == FOUND) { |
| 107 | + #pragma omp critical |
| 108 | + result = FOUND; |
| 109 | + } |
82 | 110 | } |
83 | 111 | return result; |
84 | 112 | } |
0 commit comments