random.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Copyright (C) 2015 Bernhard Reutner-Fischer
  2. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  3. */
  4. #ifndef _SYS_RANDOM_H
  5. #define _SYS_RANDOM_H 1
  6. #include <features.h>
  7. #include <stddef.h>
  8. __BEGIN_DECLS
  9. #include <bits/types.h>
  10. #ifndef __ssize_t_defined
  11. typedef __ssize_t ssize_t;
  12. # define __ssize_t_defined
  13. #endif
  14. #if defined __UCLIBC_LINUX_SPECIFIC__
  15. # if 0 /*def __ASSUME_GETRANDOM_SYSCALL */
  16. # include <linux/random.h>
  17. # else
  18. # undef GRND_NONBLOCK
  19. # undef GRND_RANDOM
  20. /*
  21. * Flags for getrandom(2)
  22. *
  23. * GRND_NONBLOCK Don't block and return EAGAIN instead
  24. * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom
  25. * GRND_INSECURE Write random data that may not be cryptographically secure.
  26. */
  27. # define GRND_NONBLOCK 0x0001
  28. # define GRND_RANDOM 0x0002
  29. # define GRND_INSECURE 0x0004
  30. # endif
  31. extern ssize_t getrandom(void *__buf, size_t count, unsigned int flags)
  32. __nonnull ((1)) __wur;
  33. /* OpenBSD-compatible access to random bytes.
  34. May be a cancellation point here, unlike in glibc/musl. */
  35. # ifndef __getentropy_defined
  36. extern int getentropy(void *__buf, size_t __len) __nonnull ((1)) __wur;
  37. # define __getentropy_defined
  38. # endif
  39. #endif
  40. __END_DECLS
  41. #endif /* sys/random.h */