1 /* prng.h -- Pseudo Random Numbers
3 * Copyright (C) 2010--2012 Olaf Bergmann <bergmann@tzi.org>
5 * This file is part of the library tinydtls. Please see
6 * README for terms of use.
11 * @brief Pseudo Random Numbers
20 * @defgroup prng Pseudo Random Numbers
28 * Fills \p buf with \p len random bytes. This is the default
29 * implementation for prng(). You might want to change prng() to use
30 * a better PRNG on your specific platform.
33 dtls_prng(unsigned char *buf, size_t len) {
35 *buf++ = rand() & 0xFF;
40 dtls_prng_init(unsigned short seed) {
43 #else /* WITH_CONTIKI */
49 dtls_prng(unsigned char *buf, size_t len)
51 return contiki_prng_impl(buf, len);
55 * Fills \p buf with \p len random bytes. This is the default
56 * implementation for prng(). You might want to change prng() to use
57 * a better PRNG on your specific platform.
60 dtls_prng(unsigned char *buf, size_t len) {
61 unsigned short v = random_rand();
62 while (len > sizeof(v)) {
63 memcpy(buf, &v, sizeof(v));
72 #endif /* HAVE_PRNG */
75 dtls_prng_init(unsigned short seed) {
78 #endif /* WITH_CONTIKI */
82 #endif /* _DTLS_PRNG_H_ */