random_data.h 1.2 KB

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