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_depends = "isaac", "cipher", "sha1", "yarrow", "yarrow_pool", "x917", "aes"
39 * $WIZ$ module_supports = "stm32 or lm3s"
45 #include "cfg/cfg_random.h"
46 #include <cfg/compiler.h>
49 * \name Security level definition
52 * Configure the security level required by the application.
54 * Application developers are suggested to keep the strongest
55 * setting (default) unless there are memory or code size issues.
57 * Available settings are:
59 * * \a RANDOM_SECURITY_STRONG: The random library will use
60 * an entropy pool, automatically feeded by drivers, to gather
61 * entropy from hardware sources. Data from the pool will
62 * be used to reseed a secure random number generator. Moreover,
63 * the generator will be automatically initialised
64 * with enough entropy to generate safe random numbers even
65 * immediately after hw reset.
66 * The overall structure is the same as used by modern
67 * desktop PCs for generating secure random numbers.
69 * * \a RANDOM_SECURITY_MEDIUM: This intermediate settings will
70 * avoid usage of an entropy pool, to reduce memory and code
71 * usage. The security of this settings relies only on the
72 * good behaviour of the random number generator (even though
73 * it will be well-seeded at startup).
75 * * \a RANDOM_SECURITY_MINIMUM: This is the lighter setting that
76 * allows minimal memory and code usage, and it suggested only
77 * for extremely constrained systems, that only generates few
78 * random numbers. Even if the generator is still secure on
79 * paper, its seeding will not be safe (though still entropic
80 * to allow different sequences to be generated after each reset).
82 * $WIZ$ random_level = "RANDOM_SECURITY_MINIMUM", "RANDOM_SECURITY_MEDIUM", "RANDOM_SECURITY_STRONG"
85 #define RANDOM_SECURITY_MINIMUM 0
86 #define RANDOM_SECURITY_MEDIUM 1
87 #define RANDOM_SECURITY_STRONG 2
90 void random_init(void);
92 void random_gen(uint8_t *out, size_t len);
94 INLINE uint8_t random_gen8(void)
101 INLINE uint16_t random_gen16(void)
108 INLINE uint32_t random_gen32(void)
115 #endif /* SEC_RANDOM_H */