4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
33 * \brief High-level random number generation functions.
34 * \author Giovanni Bajo <rasky@develer.com>
36 * $WIZ$ module_name = "random"
37 * $WIZ$ module_configuration = "bertos/cfg/cfg_random.h"
38 * $WIZ$ module_supports = "stm32 or lm3s"
44 #include "cfg/cfg_random.h"
45 #include <cfg/compiler.h>
48 * \name Security level definition
51 * Configure the security level required by the application.
53 * Application developers are suggested to keep the strongest
54 * setting (default) unless there are memory or code size issues.
56 * Available settings are:
58 * * \a RANDOM_SECURITY_STRONG: The random library will use
59 * an entropy pool, automatically feeded by drivers, to gather
60 * entropy from hardware sources. Data from the pool will
61 * be used to reseed a secure random number generator. Moreover,
62 * the generator will be automatically initialised
63 * with enough entropy to generate safe random numbers even
64 * immediately after hw reset.
65 * The overall structure is the same as used by modern
66 * desktop PCs for generating secure random numbers.
68 * * \a RANDOM_SECURITY_MEDIUM: This intermediate settings will
69 * avoid usage of an entropy pool, to reduce memory and code
70 * usage. The security of this settings relies only on the
71 * good behaviour of the random number generator (even though
72 * it will be well-seeded at startup).
74 * * \a RANDOM_SECURITY_MINIMUM: This is the lighter setting that
75 * allows minimal memory and code usage, and it suggested only
76 * for extremely constrained systems, that only generates few
77 * random numbers. Even if the generator is still secure on
78 * paper, its seeding will not be safe (though still entropic
79 * to allow different sequences to be generated after each reset).
81 * $WIZ$ random_level = "RANDOM_SECURITY_MINIMUM", "RANDOM_SECURITY_MEDIUM", "RANDOM_SECURITY_STRONG"
84 #define RANDOM_SECURITY_MINIMUM 0
85 #define RANDOM_SECURITY_MEDIUM 1
86 #define RANDOM_SECURITY_STRONG 2
89 void random_init(void);
91 void random_gen(uint8_t *out, size_t len);
93 INLINE uint8_t random_gen8(void)
100 INLINE uint16_t random_gen16(void)
107 INLINE uint32_t random_gen32(void)
114 #endif /* SEC_RANDOM_H */