IDF release/v4.0 08219f3cf

This commit is contained in:
me-no-dev
2020-01-25 14:51:58 +00:00
parent 8c723be135
commit 41ba143063
858 changed files with 37940 additions and 49396 deletions

View File

@ -12,31 +12,16 @@
* @brief Pseudo Random Numbers
*/
#ifndef _COAP_PRNG_H_
#define _COAP_PRNG_H_
#ifndef COAP_PRNG_H_
#define COAP_PRNG_H_
/**
* @defgroup prng Pseudo Random Numbers
* API functions for gerating pseudo random numbers
* @{
*/
#if defined(WITH_POSIX) || (defined(WITH_LWIP) && !defined(LWIP_RAND))
#include <stdlib.h>
/**
* 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.
*/
static inline int
coap_prng_impl(unsigned char *buf, size_t len) {
while (len--)
*buf++ = rand() & 0xFF;
return 1;
}
#endif /* WITH_POSIX */
#ifdef WITH_CONTIKI
#if defined(WITH_CONTIKI)
#include <string.h>
/**
@ -44,9 +29,9 @@ coap_prng_impl(unsigned char *buf, size_t len) {
* prng(). You might want to change prng() to use a better PRNG on your specific
* platform.
*/
static inline int
COAP_STATIC_INLINE int
contiki_prng_impl(unsigned char *buf, size_t len) {
unsigned short v = random_rand();
uint16_t v = random_rand();
while (len > sizeof(v)) {
memcpy(buf, &v, sizeof(v));
len -= sizeof(v);
@ -59,11 +44,9 @@ contiki_prng_impl(unsigned char *buf, size_t len) {
}
#define prng(Buf,Length) contiki_prng_impl((Buf), (Length))
#define prng_init(Value) random_init((unsigned short)(Value))
#endif /* WITH_CONTIKI */
#if defined(WITH_LWIP) && defined(LWIP_RAND)
static inline int
#define prng_init(Value) random_init((uint16_t)(Value))
#elif defined(WITH_LWIP) && defined(LWIP_RAND)
COAP_STATIC_INLINE int
lwip_prng_impl(unsigned char *buf, size_t len) {
u32_t v = LWIP_RAND();
while (len > sizeof(v)) {
@ -79,8 +62,46 @@ 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>
/**
* 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-- )
*buf++ = rand() & 0xFF;
return 1;
}
#endif
#endif /* WITH_LWIP */
#ifndef prng
/**
@ -103,4 +124,4 @@ lwip_prng_impl(unsigned char *buf, size_t len) {
/** @} */
#endif /* _COAP_PRNG_H_ */
#endif /* COAP_PRNG_H_ */