Skip to content

Commit

Permalink
Merge pull request #828 from laukik-hase/feature/mbedtls_3x_rng_alt
Browse files Browse the repository at this point in the history
`coap_prng.c`: Added alternate RNG implementation
  • Loading branch information
obgm authored Feb 23, 2022
2 parents ecb931d + 02deef8 commit 0ae4d62
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/coap_prng.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <stdlib.h>
#endif /* !HAVE_GETRANDOM */

#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
#include <entropy_poll.h>
#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */

#if defined(_WIN32)

errno_t __cdecl rand_s( _Out_ unsigned int* _RandomValue );
Expand Down Expand Up @@ -50,6 +54,9 @@ coap_prng_impl( unsigned char *buf, size_t len ) {

static int
coap_prng_default(void *buf, size_t len) {
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
return mbedtls_hardware_poll(NULL, buf, len, NULL);
#else /* !MBEDTLS_ENTROPY_HARDWARE_ALT */
#ifdef HAVE_GETRANDOM
return getrandom(buf, len, 0);
#else /* !HAVE_GETRANDOM */
Expand All @@ -62,6 +69,7 @@ coap_prng_default(void *buf, size_t len) {
return 1;
#endif /* !_WIN32 */
#endif /* !HAVE_GETRANDOM */
#endif /* !MBEDTLS_ENTROPY_HARDWARE_ALT */
}

static coap_rand_func_t rand_func = coap_prng_default;
Expand Down

0 comments on commit 0ae4d62

Please sign in to comment.