tizen 2.3.1 release
[external/nettle.git] / knuth-lfib.h
1 /* knuth-lfib.h
2  *
3  * A "lagged fibonacci" pseudorandomness generator.
4  *
5  * Described in Knuth, TAOCP, 3.6
6  */
7
8 /* nettle, low-level cryptographics library
9  *
10  * Copyright (C) 2002 Niels Möller
11  *  
12  * The nettle library is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License as published by
14  * the Free Software Foundation; either version 2.1 of the License, or (at your
15  * option) any later version.
16  * 
17  * The nettle library is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
20  * License for more details.
21  * 
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with the nettle library; see the file COPYING.LIB.  If not, write to
24  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25  * MA 02111-1307, USA.
26  */
27
28 /* NOTE: This generator is totally inappropriate for cryptographic
29  * applications. It is useful for generating deterministic but
30  * random-looking test data, and is used by the Nettle testsuite. */
31 #ifndef NETTLE_KNUTH_LFIB_H_INCLUDED
32 #define NETTLE_KNUTH_LFIB_H_INCLUDED
33
34 #include "nettle-types.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /* Namespace mangling */
41 #define knuth_lfib_init nettle_knuth_lfib_init
42 #define knuth_lfib_get nettle_knuth_lfib_get
43 #define knuth_lfib_get_array nettle_knuth_lfib_get_array
44 #define knuth_lfib_random nettle_knuth_lfib_random
45
46 #define _KNUTH_LFIB_KK 100
47
48 struct knuth_lfib_ctx
49 {
50   uint32_t x[_KNUTH_LFIB_KK];
51   unsigned index;
52 };
53
54 void
55 knuth_lfib_init(struct knuth_lfib_ctx *ctx, uint32_t seed);
56
57 /* Get's a single number in the range 0 ... 2^30-1 */
58 uint32_t
59 knuth_lfib_get(struct knuth_lfib_ctx *ctx);
60
61 /* Get an array of numbers */
62 void
63 knuth_lfib_get_array(struct knuth_lfib_ctx *ctx,
64                      unsigned n, uint32_t *a);
65
66 /* Get an array of octets. */
67 void
68 knuth_lfib_random(struct knuth_lfib_ctx *ctx,
69                   unsigned n, uint8_t *dst);
70
71 #ifdef __cplusplus
72 }
73 #endif
74
75 #endif /* NETTLE_KNUTH_LFIB_H_INCLUDED */