mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-20 22:39:05 +03:00
Use crypto secure version of rand to generate the message ids on windows.
This commit is contained in:
1 parent
3ee4552dcf
commit
9b3cf894fc
2 files changed
+28
-6
No files matched your search
@@ -61,6 +61,30 @@ lwip_prng_impl(unsigned char *buf, size_t len) {
|
||||
|
||||
#define prng(Buf,Length) lwip_prng_impl((Buf), (Length))
|
||||
#define prng_init(Value)
|
||||
#elif defined(_WIN32)
|
||||
#define prng_init(Value)
|
||||
errno_t __cdecl rand_s( _Out_ unsigned int* _RandomValue );
|
||||
/**
|
||||
* Fills \p buf with \p len random bytes. This is the default implementation for
|
||||
* prng(). You might want to change prng() to use a better PRNG on your specific
|
||||
* platform.
|
||||
*/
|
||||
COAP_STATIC_INLINE int
|
||||
coap_prng_impl( unsigned char *buf, size_t len ) {
|
||||
while ( len != 0 ) {
|
||||
uint32_t r = 0;
|
||||
size_t i;
|
||||
if ( rand_s( &r ) != 0 )
|
||||
return 0;
|
||||
for ( i = 0; i < len && i < 4; i++ ) {
|
||||
*buf++ = (uint8_t)r;
|
||||
r >>= 8;
|
||||
}
|
||||
len -= i;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
@@ -353,15 +353,13 @@ coap_new_context(
|
||||
#endif /* not WITH_CONTIKI */
|
||||
|
||||
coap_clock_init();
|
||||
#ifdef WITH_LWIP
|
||||
#if defined(WITH_LWIP)
|
||||
prng_init(LWIP_RAND());
|
||||
#endif /* WITH_LWIP */
|
||||
#ifdef WITH_CONTIKI
|
||||
#elif defined(WITH_CONTIKI)
|
||||
prng_init((ptrdiff_t)listen_addr ^ clock_offset);
|
||||
#endif /* WITH_LWIP */
|
||||
#ifdef WITH_POSIX
|
||||
#elif !defined(_WIN32)
|
||||
prng_init((unsigned long)listen_addr ^ clock_offset);
|
||||
#endif /* WITH_POSIX */
|
||||
#endif
|
||||
|
||||
#ifndef WITH_CONTIKI
|
||||
if (!c) {
|
||||
|
||||
Reference in new issue
Block a user