-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-consistency.cpp
65 lines (56 loc) · 1.98 KB
/
check-consistency.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
#include <array>
#include <cstddef> // for std::size_t
#include <iostream>
#include <random>
#include <string>
#include <vector>
#include "halftime-hash.hpp"
using namespace std;
template <int out_length>
void Generate(const uint64_t entropy[halftime_hash::advanced::MaxEntropyBytesNeeded()]) {
vector<char> input(halftime_hash::kCodeCoverageByteLength, 'X');
uint64_t output[out_length];
for (size_t i = 0; i < halftime_hash::kCodeCoverageByteLength; ++i) {
halftime_hash::advanced::V4<out_length>(entropy, input.data(), i, output);
for (int j = 0; j < out_length; ++j) {
cout << hex << output[j] << ' ';
}
cout << endl;
}
}
template <int out_length>
bool Check(const uint64_t entropy[halftime_hash::advanced::MaxEntropyBytesNeeded()]) {
vector<char> input(halftime_hash::kCodeCoverageByteLength, 'X');
uint64_t output[out_length];
for (size_t i = 0; i < halftime_hash::kCodeCoverageByteLength; ++i) {
halftime_hash::advanced::V4<out_length>(entropy, input.data(), i, output);
for (int j = 0; j < out_length; ++j) {
uint64_t check;
cin >> hex >> check;
if (check != output[j]) return false;
}
}
return true;
}
void GenerateAll(const uint64_t entropy[halftime_hash::advanced::MaxEntropyBytesNeeded()]) {
Generate<2>(entropy);
Generate<3>(entropy);
Generate<4>(entropy);
Generate<5>(entropy);
}
int main(int argc, char ** argv) {
if (argc < 2) return 1;
array<uint64_t, halftime_hash::advanced::MaxEntropyBytesNeeded()> entropy;
generate(entropy.begin(), entropy.end(), mt19937_64());
if (string("generate") == argv[1]) {
GenerateAll(entropy.data());
} else if (string("check") == argv[1]) {
cout << "2 " << (Check<2>(entropy.data()) ? "OK" : "NOT OK") << endl;
cout << "3 " << (Check<3>(entropy.data()) ? "OK" : "NOT OK") << endl;
cout << "4 " << (Check<4>(entropy.data()) ? "OK" : "NOT OK") << endl;
cout << "5 " << (Check<5>(entropy.data()) ? "OK" : "NOT OK") << endl;
} else {
return 1;
}
return 0;
}