aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_decompose_chain1.c
blob: a084c13debb2e10be69c9ff483e9f93b65275cfc (plain) (blame)
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
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


extern inline size_t librecrypt_decompose_chain1(char *hash);


#else
# ifndef FUZZ


#define CHECK(IN, OUT, N)\
	do {\
		assert(sizeof(IN) <= sizeof(buf));\
		assert(sizeof(IN) == sizeof(OUT));\
		CANARY_FILL(buf);\
		stpcpy(buf, (IN));\
		n = librecrypt_decompose_chain1(buf);\
		EXPECT(n == (N));\
		EXPECT(n == librecrypt_chain_length(IN));\
		EXPECT(!memcmp(buf, (OUT), sizeof(IN)));\
		CANARY_CHECK(buf, sizeof(IN));\
	} while (0)


int
main(void)
{
	char buf[64u];
	size_t n;

	SET_UP_ALARM();
	INIT_RESOURCE_TEST();

	/* Check each '>' was replaced with NUL, and number
	 * of '>' plus 1 (number of algorithms) was returned */
	CHECK("", "", 1u);
	CHECK(">", "\0", 2u);
	CHECK("a$b>c$d>e$f", "a$b\0c$d\0e$f", 3u);

	STOP_RESOURCE_TEST();
	return 0;
}


# else


extern volatile size_t discarded_return_value;
volatile size_t discarded_return_value;

int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
	char *hash;
	hash = malloc(size + 1u);
	assert(hash);
	memcpy(hash, data, size);
	hash[size] = '\0';
	discarded_return_value = librecrypt_decompose_chain1(hash);
	free(hash);
	return 0;
}


# endif
#endif