1 /* prng.h -- Pseudo Random Numbers
3 * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
5 * This file is part of the CoAP library libcoap. Please see
6 * README for terms of use.
11 * @brief Pseudo Random Numbers
21 * @defgroup prng Pseudo Random Numbers
29 * Fills \p buf with \p len random bytes. This is the default
30 * implementation for prng(). You might want to change prng() to use
31 * a better PRNG on your specific platform.
34 coap_prng_impl(unsigned char *buf, size_t len) {
37 *buf++ = rand() & 0xFF;
39 OCFillRandomMem(buf, len);
42 #else /* WITH_CONTIKI */
46 * Fills \p buf with \p len random bytes. This is the default
47 * implementation for prng(). You might want to change prng() to use
48 * a better PRNG on your specific platform.
51 contiki_prng_impl(unsigned char *buf, size_t len) {
52 unsigned short v = random_rand();
53 while (len > sizeof(v)) {
54 memcpy(buf, &v, sizeof(v));
64 #define prng(Buf,Length) contiki_prng_impl((Buf), (Length))
65 #define prng_init(Value) random_init((unsigned short)(Value))
66 #endif /* WITH_CONTIKI */
70 * Fills \p Buf with \p Length bytes of random data.
74 #define prng(Buf,Length) coap_prng_impl((Buf), (Length))
79 * Called to set the PRNG seed. You may want to re-define this to
80 * allow for a better PRNG.
84 #define prng_init(Value) OCSeedRandom()//srand((unsigned long)(Value))
89 #endif /* _COAP_PRNG_H_ */