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 Internal function definitions for random
34 * \author Giovanni Bajo <rasky@develer.com>
38 #ifndef SEC_RANDOM_P_H
39 #define SEC_RANDOM_P_H
41 #include <cfg/compiler.h>
42 #include <sec/random.h>
44 /********************************************************************************/
45 /* Configuration of the random module */
46 /********************************************************************************/
50 #define POOL_NAME1 Yarrow
55 #define PRNG_NAME1 ISAAC
56 #define PRNG_NAME2 X917
57 #define PRNG_NAME3 Yarrow
59 #define EXTRACTOR_NONE 0
60 #define EXTRACTOR_SHA1 1
61 #define EXTRACTOR_NAME1 SHA1
63 #if RANDOM_SECURITY_LEVEL == RANDOM_SECURITY_STRONG
64 #define CONFIG_RANDOM_POOL POOL_YARROW
65 #define CONFIG_RANDOM_EXTRACTOR EXTRACTOR_NONE // not required with a pool
66 #define CONFIG_RANDOM_PRNG PRNG_ISAAC // FIXME: PRNG_YARROW
67 #elif RANDOM_SECURITY_LEVEL == RANDOM_SECURITY_MEDIUM
68 #define CONFIG_RANDOM_POOL POOL_NONE
69 #define CONFIG_RANDOM_EXTRACTOR EXTRACTOR_SHA1
70 #define CONFIG_RANDOM_PRNG PRNG_ISAAC // FIXME: PRNG_X917
71 #elif RANDOM_SECURITY_LEVEL == RANDOM_SECURITY_MINIMUM
72 #define CONFIG_RANDOM_POOL POOL_NONE
73 #define CONFIG_RANDOM_EXTRACTOR EXTRACTOR_NONE
74 #define CONFIG_RANDOM_PRNG PRNG_ISAAC
76 #error Unsupported random security level value
79 /***************************************************************************/
80 /* Internal functions used by BeRTOS drivers to push data into */
81 /* the entropy pool */
82 /***************************************************************************/
84 #if CONFIG_RANDOM_POOL != POOL_NONE
93 * Add entropy to the global entropy pool.
95 void random_add_entropy(enum EntropySource source_idx,
96 const uint8_t *data, size_t len,
101 * Add entropy to the global interrupt pool based on the IRQ
104 * This function can be called from interrupt handlers that are
105 * triggered at unpredictable intervals (so it should not be
106 * called from clock-driven interrupts like ADC, PWM, etc.).
109 void random_add_entropy_irq(int irq);
114 * This hardware-dependent function can be used to pull raw
115 * entropy from a hardware source at startup only. It is used
116 * for initial seeding of the random generator and should not
117 * be used in different situations.
119 void random_pull_entropy(uint8_t *entropy, size_t len);
121 #endif /* SEC_RANDOM_P_H */