mirror of
https://github.com/eclipse/tinydtls.git
synced 2025-05-08 11:27:36 +08:00
dtls_prng_posix.c: Fix random() only support
Use of random() requires that _GNU_SOURCE is defined. Cannot use variables named rand. Make sure that dtls_prng.o is rebuilt whenever any of the platform-specific/dtls_prng_*.c files are updated. Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
This commit is contained in:
parent
11c8e7d612
commit
a5fa982aa5
@ -85,6 +85,8 @@ dirs: $(SUBDIRS)
|
||||
$(MAKE) -C $$dir ; \
|
||||
done
|
||||
|
||||
dtls_prng.o:: $(wildcard platform-specific/dtls_prng_*.c)
|
||||
|
||||
$(SUB_OBJECTS)::
|
||||
$(MAKE) -C $(@D) $(@F)
|
||||
|
||||
|
@ -18,6 +18,12 @@
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifdef HAVE_RANDOM
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif /* _GNU_SOURCE */
|
||||
#endif /* HAVE_RANDOM */
|
||||
|
||||
#include "tinydtls.h"
|
||||
#include "dtls_prng.h"
|
||||
#include "dtls_debug.h"
|
||||
@ -44,16 +50,16 @@ dtls_prng(unsigned char *buf, size_t len) {
|
||||
if (len) {
|
||||
size_t klen = len;
|
||||
uint8_t byte_counter = RAND_BYTES;
|
||||
uint32_t rand = random();
|
||||
uint32_t rand_val = random();
|
||||
while (1) {
|
||||
*buf++ = rand & 0xFF;
|
||||
*buf++ = rand_val & 0xFF;
|
||||
if (!--klen) {
|
||||
break;
|
||||
}
|
||||
if (--byte_counter) {
|
||||
rand >>= 8;
|
||||
rand_val >>= 8;
|
||||
} else {
|
||||
rand = random();
|
||||
rand_val = random();
|
||||
byte_counter = RAND_BYTES;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user