3 * A "lagged fibonacci" pseudorandomness generator.
5 * Described in Knuth, TAOCP, 3.6
8 /* nettle, low-level cryptographics library
10 * Copyright (C) 2002 Niels Möller
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston,
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
34 #include "nettle-types.h"
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
46 #define _KNUTH_LFIB_KK 100
48 struct knuth_lfib_ctx
{
49 uint32_t x
[_KNUTH_LFIB_KK
];
54 knuth_lfib_init(struct knuth_lfib_ctx
*ctx
, uint32_t seed
);
56 /* Get's a single number in the range 0 ... 2^30-1 */
57 uint32_t knuth_lfib_get(struct knuth_lfib_ctx
*ctx
);
59 /* Get an array of numbers */
61 knuth_lfib_get_array(struct knuth_lfib_ctx
*ctx
,
62 unsigned n
, uint32_t * a
);
64 /* Get an array of octets. */
66 knuth_lfib_random(struct knuth_lfib_ctx
*ctx
,
67 unsigned n
, uint8_t * dst
);
72 #endif /* NETTLE_KNUTH_LFIB_H_INCLUDED */