mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-15 04:39:42 +03:00
Added in a new landing page for Main Page doc/main.md (new) Enabled Tree View of whats available Disable Related Pages TAB as it fills up with the man pages - updated doc/Doxyfile.in Get a2x to also generate html man pages which are then included. These html files are updated to correct the lowercasing of NAME and SYNOPSIS. The SEE ALSO references to other man pages are made hyper links. - done by doc/build_man_files.sh (new) Created a new TAB Manual Pages Created a new TAB Depricated Items - done by modifing DoxygenLayout.xml file using doc/build_man_files.sh Updated .gitignore to ignore additional files and autogen.sh to clean them up man/coap*txt.in updated to display as expected in Doxygen. This only updates documentation .gitignore Makefile.am autogen.sh doc/Doxyfile.in doc/Makefile.am doc/build_man_files.sh (New) doc/main.md (New) include/coap/debug.h include/coap/encode.h include/coap/option.h include/coap/pdu.h include/coap/prng.h man/Makefile.am man/coap.txt.in man/coap_attribute.txt.in man/coap_context.txt.in man/coap_encryption.txt.in man/coap_handler.txt.in man/coap_logging.txt.in man/coap_observe.txt.in man/coap_pdu_setup.txt.in man/coap_recovery.txt.in man/coap_resource.txt.in man/coap_session.txt.in man/coap_tls_library.txt.in
128 lines
2.7 KiB
C
128 lines
2.7 KiB
C
/*
|
|
* prng.h -- Pseudo Random Numbers
|
|
*
|
|
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
|
|
*
|
|
* This file is part of the CoAP library libcoap. Please see README for terms
|
|
* of use.
|
|
*/
|
|
|
|
/**
|
|
* @file prng.h
|
|
* @brief Pseudo Random Numbers
|
|
*/
|
|
|
|
#ifndef _COAP_PRNG_H_
|
|
#define _COAP_PRNG_H_
|
|
|
|
/**
|
|
* @defgroup prng Pseudo Random Numbers
|
|
* API functions for gerating pseudo random numbers
|
|
* @{
|
|
*/
|
|
|
|
#if defined(WITH_CONTIKI)
|
|
#include <string.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
|
|
contiki_prng_impl(unsigned char *buf, size_t len) {
|
|
uint16_t v = random_rand();
|
|
while (len > sizeof(v)) {
|
|
memcpy(buf, &v, sizeof(v));
|
|
len -= sizeof(v);
|
|
buf += sizeof(v);
|
|
v = random_rand();
|
|
}
|
|
|
|
memcpy(buf, &v, len);
|
|
return 1;
|
|
}
|
|
|
|
#define prng(Buf,Length) contiki_prng_impl((Buf), (Length))
|
|
#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)) {
|
|
memcpy(buf, &v, sizeof(v));
|
|
len -= sizeof(v);
|
|
buf += sizeof(v);
|
|
v = LWIP_RAND();
|
|
}
|
|
|
|
memcpy(buf, &v, len);
|
|
return 1;
|
|
}
|
|
|
|
#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
|
|
|
|
|
|
#ifndef prng
|
|
/**
|
|
* Fills \p Buf with \p Length bytes of random data.
|
|
*
|
|
* @hideinitializer
|
|
*/
|
|
#define prng(Buf,Length) coap_prng_impl((Buf), (Length))
|
|
#endif
|
|
|
|
#ifndef prng_init
|
|
/**
|
|
* Called to set the PRNG seed. You may want to re-define this to allow for a
|
|
* better PRNG.
|
|
*
|
|
* @hideinitializer
|
|
*/
|
|
#define prng_init(Value) srand((unsigned long)(Value))
|
|
#endif
|
|
|
|
/** @} */
|
|
|
|
#endif /* _COAP_PRNG_H_ */
|