20#include <sys/random.h>
25#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
26#include <entropy_poll.h>
31errno_t __cdecl rand_s( _Out_
unsigned int* _RandomValue );
38coap_prng_impl(
unsigned char *buf,
size_t len ) {
42 if ( rand_s( &r ) != 0 )
44 for ( i = 0; i < len && i < 4; i++ ) {
61#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
63 return (mbedtls_hardware_poll(NULL, buf, len, NULL) ? 0 : 1);
66 return (getrandom(buf, len, 0) > 0) ? 1 : 0;
69 return coap_prng_impl(buf,len);
71 unsigned char *dst = (
unsigned char *)buf;
73 *dst++ = rand() & 0xFF;
82#if defined(WITH_CONTIKI)
84#elif defined(WITH_LWIP) && defined(LWIP_RAND)
Pulls together all the internal only header files.
static int coap_prng_default(void *buf, size_t len)
static coap_rand_func_t rand_func
int(* coap_rand_func_t)(void *out, size_t len)
Data type for random number generator function.
void coap_set_prng(coap_rand_func_t rng)
Replaces the current random number generation function with the default function rng.
int coap_prng(void *buf, size_t len)
Fills buf with len random bytes using the default pseudo random number generator.
void coap_prng_init(unsigned int seed)
Seeds the default random number generation function with the given seed.
#define COAP_STATIC_INLINE