Skip to content

Commit 5d26467

Browse files
committed
Break out OMP implementaiton to it's own fuction so it can be called twice.
1 parent 6461595 commit 5d26467

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

src/dictionary/dictionary-omp.c

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../globals.h"
88

99
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);
1011

1112
/**
1213
* dictionary_crack() - OpenMP Implementation
@@ -67,18 +68,45 @@ int compare_candidates(FILE **file, char *password_hash, int verbose)
6768
remove_new_line(line, &candidate_array[counter]);
6869
if (counter++ == CHUNK_SIZE)
6970
{
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;
8173
}
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+
}
82110
}
83111
return result;
84112
}

0 commit comments

Comments
 (0)