CBMC
random.c
Go to the documentation of this file.
1 /* FUNCTION: getrandom */
2 
3 #ifndef __CPROVER_ERRNO_H_INCLUDED
4 #include <errno.h>
5 #define __CPROVER_ERRNO_H_INCLUDED
6 #endif
7 
8 #if defined(__GLIBC__) && \
9  (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
10 
11 # ifndef __CPROVER_SYS_RANDOM_H_INCLUDED
12 # include <sys/random.h>
13 # define __CPROVER_SYS_RANDOM_H_INCLUDED
14 # endif
15 
16 # ifndef GRND_NONBLOCK
17 # define GRND_NONBLOCK 0
18 # endif
19 
20 __CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
21 size_t __VERIFIER_nondet_size_t(void);
22 
23 ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)
24 {
25  if(flags & GRND_NONBLOCK && __VERIFIER_nondet___CPROVER_bool())
26  return -1;
27 
28  char bytes[buflen];
29  __CPROVER_array_replace(buf, bytes);
30 
31  size_t actual_bytes = __VERIFIER_nondet_size_t();
32  __CPROVER_assume(actual_bytes <= buflen);
33  return (ssize_t)actual_bytes;
34 }
35 
36 #endif
void __CPROVER_array_replace(const void *dest, const void *src)
void __CPROVER_assume(__CPROVER_bool assumption)
__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void)
size_t __VERIFIER_nondet_size_t(void)