-
Notifications
You must be signed in to change notification settings - Fork 80
/
generate_dict.cpp
75 lines (59 loc) · 1.5 KB
/
generate_dict.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
#include <cstdint>
#include <cstddef>
#include <sstream>
#include <iomanip>
#include <vector>
#include <optional>
#include <stdio.h>
#include <fuzzing/datasource/id.hpp>
#include "repository_map.h"
static void write(FILE* fp, uint64_t val) {
fprintf(fp, "\"");
for (size_t i = 0; i < 8; i++) {
fprintf(fp, "\\x%02X", (uint8_t)(val & 0xFF));
val >>= 8;
}
fprintf(fp, "\"\n");
}
template <class T>
static void writeMap(FILE* fp, const T& map) {
for (const auto item : map ) {
write(fp, item.first);
}
}
static void writeBuffer(FILE* fp, const size_t size) {
if ( size > 255 ) {
printf("Sizes > 255 unsupported\n");
abort();
}
std::stringstream ss;
ss << "\"";
for (size_t i = 0; i < 4 + size; i++) {
if ( i == 0 ) {
ss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << size;
} else {
ss << "\\x00";
}
}
ss << "\"";
fprintf(fp, "%s\n", ss.str().c_str());
}
int main(void)
{
using fuzzing::datasource::ID;
FILE* fp = fopen("cryptofuzz-dict.txt", "wb");
writeMap(fp, ModuleLUTMap);
writeMap(fp, OperationLUTMap);
writeMap(fp, DigestLUTMap);
writeMap(fp, CipherLUTMap);
writeMap(fp, ECC_CurveLUTMap);
writeMap(fp, CalcOpLUTMap);
{
const std::vector<uint8_t> bufferSizes = {1, 2, 4, 8, 12, 16, 32};
for (const auto& size : bufferSizes) {
writeBuffer(fp, size);
}
}
fclose(fp);
return 0;
}