-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
79 lines (73 loc) · 2.01 KB
/
main.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*Calculating WPA2 PSK hashes
Author(s) : Lukas Mirow, contributors of the wpa_supplicant project
*/
#define HASHES_PER_RUN 180
#define RUNS 5
#define DEBUG
#define FAKE_SSID "ssid"
#define FAKE_PSK "psk"
#include <iostream>
#include "wpa2_hash_wrapper.hpp"
#include <mpi.h>
#include <cmath>
using namespace std;
float calc_hashes_per_second(unsigned& amount, struct timespec& start, struct timespec& end)
{
float ret;
ret = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1e9;
ret = (float)amount / ret;
return ret;
}
float execute_benchmarks(unsigned amount)
{
int id, process_count;
struct timespec t_start, t_end;
unsigned h_start, h_end;
MPI_Comm_size(MPI_COMM_WORLD, &process_count);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
h_start = HASHES_PER_RUN / process_count * id;
h_end = h_start + HASHES_PER_RUN/ process_count;
#ifdef DEBUG
cout << "Process " << id << " from " << h_start << " to " << h_end << endl;
#endif //DEBUG
clock_gettime(CLOCK_MONOTONIC_RAW, &t_start);
for (size_t i = h_start; i < h_end; i++)
calc_wpa2_hash(FAKE_SSID, FAKE_PSK);
clock_gettime(CLOCK_MONOTONIC_RAW, &t_end);
return calc_hashes_per_second(amount, t_start, t_end);
}
void print_benchmark_result(float *res)
{
float min, mean, max;
min = INFINITY;
mean = 0;
max = -INFINITY;
for (unsigned i = 0; i < RUNS; i++)
{
if (res[i] < min)
min = res[i];
if (res[i] > max)
max = res[i];
mean += res[i];
}
mean /= RUNS;
cout << RUNS << " times " << HASHES_PER_RUN << " hashes were calculated" << endl;
cout << "Minimum hashes per second: " << min << endl;
cout << "Average hashes per second: " << mean << endl;
cout << "Maximum hashes per second: " << max << endl;
}
int main(int argc, char **argv)
{
float res[RUNS];
int id;
if (MPI_Init(&argc, &argv) != 0)
exit(1);
for (unsigned j = 0; j < RUNS; j++)
res[j] = execute_benchmarks(HASHES_PER_RUN);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
MPI_Finalize();
if (id != 0)
return 0;
print_benchmark_result(res); //FIXME: Is printed in every process...
return 0;
}