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_NAMEU1 YarrowPool
51 #define POOL_NAMEL1 yarrowpool
56 #define PRNG_NAMEU1 Isaac
57 #define PRNG_NAMEL1 isaac
58 #define PRNG_NAMEU2 X917
59 #define PRNG_NAMEL2 x917
60 #define PRNG_NAMEU3 Yarrow
61 #define PRNG_NAMEL3 yarrow
63 #define EXTRACTOR_NONE 0
64 #define EXTRACTOR_SHA1 1
65 #define EXTRACTOR_NAME1 SHA1
67 #if RANDOM_SECURITY_LEVEL == RANDOM_SECURITY_STRONG
68 #define CONFIG_RANDOM_POOL POOL_YARROW
69 #define CONFIG_RANDOM_EXTRACTOR EXTRACTOR_NONE // not required with a pool
70 #define CONFIG_RANDOM_PRNG PRNG_YARROW
71 #elif RANDOM_SECURITY_LEVEL == RANDOM_SECURITY_MEDIUM
72 #define CONFIG_RANDOM_POOL POOL_NONE
73 #define CONFIG_RANDOM_EXTRACTOR EXTRACTOR_SHA1
74 #define CONFIG_RANDOM_PRNG PRNG_X917
75 #elif RANDOM_SECURITY_LEVEL == RANDOM_SECURITY_MINIMUM
76 #define CONFIG_RANDOM_POOL POOL_NONE
77 #define CONFIG_RANDOM_EXTRACTOR EXTRACTOR_NONE
78 #define CONFIG_RANDOM_PRNG PRNG_ISAAC
80 #error Unsupported random security level value
83 /***************************************************************************/
84 /* Internal functions used by BeRTOS drivers to push data into */
85 /* the entropy pool */
86 /***************************************************************************/
88 #if CONFIG_RANDOM_POOL != POOL_NONE
97 * Add entropy to the global entropy pool.
99 void random_add_entropy(enum EntropySource source_idx,
100 const uint8_t *data, size_t len,
105 * Add entropy to the global interrupt pool based on the IRQ
108 * This function can be called from interrupt handlers that are
109 * triggered at unpredictable intervals (so it should not be
110 * called from clock-driven interrupts like ADC, PWM, etc.).
113 void random_add_entropy_irq(int irq);
118 * This hardware-dependent function can be used to pull raw
119 * entropy from a hardware source at startup only. It is used
120 * for initial seeding of the random generator and should not
121 * be used in different situations.
123 void random_pull_entropy(uint8_t *entropy, size_t len);
125 #endif /* SEC_RANDOM_P_H */