mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-15 12:44:55 +03:00
coap_prng.c: Added alternate RNG implementation
- For targets having their own hardware entropy/RNG implementation using mbedtls_hardware_poll() - This change was made as since mbedtls-3.x, passing a RNG function to all functions that accept a f_rng parameter is mandatory
This commit is contained in:
1 parent
6aa967cee1
commit
02deef8da6
1 file changed
+8
@@ -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 );
|
||||
@@ -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 */
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user