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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST
int
librecrypt_test_supported(const char *phrase, size_t len, int text, const char *settings, void *reserved)
{
const struct algorithm *algo;
size_t n;
(void) reserved;
/* For each chained algorithm */
for (;;) {
/* Measure until next '>' */
for (n = 0u; settings[n]; n++)
if (settings[n] == LIBRECRYPT_ALGORITHM_LINK_DELIMITER)
break;
/* Identify algorithm */
algo = librecrypt_find_first_algorithm_(settings, n);
if (!algo)
return 0;
/* Check configuration and input support, and get hash size */
if (!(*algo->test_supported)(phrase, len, text, settings, n, &len))
return 0;
/* Return just process last chained algorithm */
if (!settings[n])
return 1;
/* Hashes are binary */
phrase = NULL;
text = 0;
/* Go to next algorithm */
settings = &settings[n]; /* conf */
settings++; /* '>' */
}
}
#else
# ifndef FUZZ
#define NSA "$~no~such~algorithm~$"
#define CHECK(ALGO, VALID, INVALID)\
do {\
EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO VALID, NULL) == 1);\
EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO VALID">"NSA, NULL) == 0);\
EXPECT(librecrypt_test_supported(NULL, 4096u, 0, NSA">"ALGO VALID, NULL) == 0);\
EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO VALID">"ALGO VALID, NULL) == 1);\
EXPECT(librecrypt_test_supported(NULL, 4096u, 0, ALGO INVALID, NULL) == 0);\
} while (0)
int
main(void)
{
SET_UP_ALARM();
INIT_RESOURCE_TEST();
EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, NSA, NULL) == 0);
EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, NSA">", NULL) == 0);
EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, ">"NSA, NULL) == 0);
EXPECT(librecrypt_test_supported("abcdefgh", 8u, 1, NSA">"NSA, NULL) == 0);
IF__argon2i__SUPPORTED(CHECK("$argon2i$v=19$", "m=8,t=1,p=1$*16$*40", "m=0,t=0,p=0$*1$*1"));
IF__argon2d__SUPPORTED(CHECK("$argon2d$v=19$", "m=8,t=1,p=1$*16$*40", "m=0,t=0,p=0$*1$*1"));
IF__argon2id__SUPPORTED(CHECK("$argon2id$v=19$", "m=8,t=1,p=1$*16$*40", "m=0,t=0,p=0$*1$*1"));
IF__argon2ds__SUPPORTED(CHECK("$argon2ds$v=19$", "m=8,t=1,p=1$*16$*40", "m=0,t=0,p=0$*1$*1"));
STOP_RESOURCE_TEST();
return 0;
}
# else
extern volatile int discarded_return_value;
volatile int discarded_return_value;
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
const void *phrase;
size_t len;
int text;
char *settings;
if (size < 4u)
return 0;
text = (int)data[0u] & 1;
len = (size_t)data[1u];
if (len > size - 2u)
return 0;
phrase = &data[2u];
data = &data[2u + len];
size -= 2u + len;
settings = malloc(size + 1u);
assert(settings);
memcpy(settings, data, size);
settings[size] = '\0';
discarded_return_value = librecrypt_test_supported(phrase, len, text, settings, NULL);
free(settings);
return 0;
}
# endif
#endif
|