File: random_data.h

package info (click to toggle)
nanopb 0.4.9.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,676 kB
  • sloc: ansic: 12,144; python: 2,795; cpp: 190; sh: 163; makefile: 85
file content (44 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download | duplicates (2)
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
/* This module handles generating & modifying messages randomly for the fuzz test. */

#ifndef RANDOM_DATA_H
#define RANDOM_DATA_H

#include <pb.h>

void random_set_seed(uint32_t seed);
uint32_t random_get_seed();

/* Random 32-bit integer */
uint32_t rand_word();

/* Get a random integer in range, with approximately flat distribution. */
int rand_int(int min, int max);

/* Random boolean, equal probability */
bool rand_bool();

/* Get a random byte, with skewed distribution.
 * Important corner cases like 0xFF, 0x00 and 0xFE occur more
 * often than other values. */
uint8_t rand_byte();

/* Get a random length, with skewed distribution.
 * Favors the shorter lengths, but always at least 1. */
size_t rand_len(size_t max);

/* Fills a buffer with random bytes with skewed distribution. */
void rand_fill(uint8_t *buf, size_t count);

/* Fill with random protobuf-like data */
size_t rand_fill_protobuf(uint8_t *buf, size_t min_bytes, size_t max_bytes, int min_tag);

/* Given a buffer of data, mess it up a bit by copying / swapping bytes */
void rand_mess(uint8_t *buf, size_t count);

/* Append or prepend protobuf noise, with tag values > 1000 */
void rand_protobuf_noise(uint8_t *buffer, size_t bufsize, size_t *msglen);




#endif