Skip to content

Commit

Permalink
Contiki-NG: Switch to secure PRNG
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrentz authored and mrdeep1 committed Aug 7, 2023
1 parent ef943c9 commit a401a2a
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/coap_prng.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifdef HAVE_GETRANDOM
#include <sys/random.h>
#elif defined(WITH_CONTIKI)
#include "lib/random.h"
#include "lib/csprng.h"
#else /* !WITH_CONTIKI */
#include <stdlib.h>
#endif /* !WITH_CONTIKI */
Expand Down Expand Up @@ -96,18 +96,7 @@ coap_prng_default(void *buf, size_t len) {
return 1;

#elif defined(WITH_CONTIKI)
size_t i;
uint_fast8_t j;
unsigned short r;

for (i = 0; i < len;) {
r = random_rand();
for (j = 0; (i < len) && (j < sizeof(r)); i++, j++) {
((uint8_t *)buf)[i] = r & 0xFF;
r >>= 8;
}
}
return 1;
return csprng_rand(buf, len);

#elif defined(_WIN32)
return coap_prng_impl(buf,len);
Expand Down

0 comments on commit a401a2a

Please sign in to comment.