1 /* This module handles generating & modifying messages randomly for the fuzz test. */
2 
3 #ifndef RANDOM_DATA_H
4 #define RANDOM_DATA_H
5 
6 #include <pb.h>
7 
8 void random_set_seed(uint32_t seed);
9 uint32_t random_get_seed();
10 
11 /* Random 32-bit integer */
12 uint32_t rand_word();
13 
14 /* Get a random integer in range, with approximately flat distribution. */
15 int rand_int(int min, int max);
16 
17 /* Random boolean, equal probability */
18 bool rand_bool();
19 
20 /* Get a random byte, with skewed distribution.
21  * Important corner cases like 0xFF, 0x00 and 0xFE occur more
22  * often than other values. */
23 uint8_t rand_byte();
24 
25 /* Get a random length, with skewed distribution.
26  * Favors the shorter lengths, but always at least 1. */
27 size_t rand_len(size_t max);
28 
29 /* Fills a buffer with random bytes with skewed distribution. */
30 void rand_fill(uint8_t *buf, size_t count);
31 
32 /* Fill with random protobuf-like data */
33 size_t rand_fill_protobuf(uint8_t *buf, size_t min_bytes, size_t max_bytes, int min_tag);
34 
35 /* Given a buffer of data, mess it up a bit by copying / swapping bytes */
36 void rand_mess(uint8_t *buf, size_t count);
37 
38 /* Append or prepend protobuf noise, with tag values > 1000 */
39 void rand_protobuf_noise(uint8_t *buffer, size_t bufsize, size_t *msglen);
40 
41 
42 
43 
44 #endif
45