Remove tag files.
[bertos.git] / bertos / sec / prng / isaac.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \brief ISAAC implementation
34  * \author Giovanni Bajo <rasky@develer.com>
35  *
36  */
37
38 #ifndef SEC_PRNG_ISAAC_H
39 #define SEC_PRNG_ISAAC_H
40
41 #include <sec/prng.h>
42
43 /**
44  * Size of the internal ISAAC state (in 32-bit words).
45  *
46  * ISAAC is known to generate unbiased data as follows:
47  *   * 3 words: 2^37 unbiased values
48  *   * 4 words: 2^45 unbiased values
49  *   * 5 words: 2^53 unbiased values
50  *   * 6 words: 2^61 unbiased values
51  *   * 7 words: 2^69 unbiased values
52  *   * 8 words: 2^77 unbiased values
53  *
54  * The period of the generator is usually much longer, but it is
55  * obviously uninteresting for a CSPRNG.
56  */
57 #define CONFIG_ISAAC_RANDSIZL   (3)
58 #define CONFIG_ISAAC_RANDSIZ    (1<<(CONFIG_ISAAC_RANDSIZL))
59
60 typedef struct IsaacContext
61 {
62         PRNG prng;
63         uint32_t randcnt;
64         uint32_t randrsl[CONFIG_ISAAC_RANDSIZ];
65         uint32_t randmem[CONFIG_ISAAC_RANDSIZ];
66         uint32_t randa;
67         uint32_t randb;
68         uint32_t randc;
69 } IsaacContext;
70
71 void isaac_init(IsaacContext *ctx);
72
73 #define isaac_stackinit(...) \
74         ({ IsaacContext *ctx = alloca(sizeof(IsaacContext)); isaac_init(ctx , ##__VA_ARGS__); &ctx->prng; })
75
76
77 #endif /* SEC_PRNG_ISAAC_H */