Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / yarrow.h
blob8a0de5f696d8b404f44a401ed4625ce08e7eb177
1 /* yarrow.h
3 * The yarrow pseudo-randomness generator.
4 */
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001 Niels Möller
9 *
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 * MA 02111-1301, USA.
26 #ifndef NETTLE_YARROW_H_INCLUDED
27 #define NETTLE_YARROW_H_INCLUDED
29 #include "aes.h"
30 #include "sha2.h"
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
36 /* Name mangling */
37 #define yarrow256_init nettle_yarrow256_init
38 #define yarrow256_seed nettle_yarrow256_seed
39 #define yarrow256_update nettle_yarrow256_update
40 #define yarrow256_random nettle_yarrow256_random
41 #define yarrow256_is_seeded nettle_yarrow256_is_seeded
42 #define yarrow256_needed_sources nettle_yarrow256_needed_sources
43 #define yarrow256_fast_reseed nettle_yarrow256_fast_reseed
44 #define yarrow256_slow_reseed nettle_yarrow256_slow_reseed
45 #define yarrow_key_event_init nettle_yarrow_key_event_init
46 #define yarrow_key_event_estimate nettle_yarrow_key_event_estimate
48 /* Obsolete alias for backwards compatibility. Will be deleted in some
49 later version. */
50 #define yarrow256_force_reseed yarrow256_slow_reseed
52 enum yarrow_pool_id { YARROW_FAST = 0, YARROW_SLOW = 1 };
54 struct yarrow_source
56 /* Indexed by yarrow_pool_id */
57 uint32_t estimate[2];
59 /* The pool next sample should go to. */
60 enum yarrow_pool_id next;
64 #define YARROW256_SEED_FILE_SIZE (2 * AES_BLOCK_SIZE)
66 /* Yarrow-256, based on SHA-256 and AES-256 */
67 struct yarrow256_ctx
69 /* Indexed by yarrow_pool_id */
70 struct sha256_ctx pools[2];
72 int seeded;
74 /* The current key and counter block */
75 struct aes_ctx key;
76 uint8_t counter[AES_BLOCK_SIZE];
78 /* The entropy sources */
79 unsigned nsources;
80 struct yarrow_source *sources;
83 void
84 yarrow256_init(struct yarrow256_ctx *ctx,
85 unsigned nsources,
86 struct yarrow_source *sources);
88 void
89 yarrow256_seed(struct yarrow256_ctx *ctx,
90 unsigned length,
91 const uint8_t *seed_file);
93 /* Returns 1 on reseed */
94 int
95 yarrow256_update(struct yarrow256_ctx *ctx,
96 unsigned source, unsigned entropy,
97 unsigned length, const uint8_t *data);
99 void
100 yarrow256_random(struct yarrow256_ctx *ctx, unsigned length, uint8_t *dst);
103 yarrow256_is_seeded(struct yarrow256_ctx *ctx);
105 unsigned
106 yarrow256_needed_sources(struct yarrow256_ctx *ctx);
108 void
109 yarrow256_fast_reseed(struct yarrow256_ctx *ctx);
111 void
112 yarrow256_slow_reseed(struct yarrow256_ctx *ctx);
115 /* Key event estimator */
116 #define YARROW_KEY_EVENT_BUFFER 16
118 struct yarrow_key_event_ctx
120 /* Counter for initial priming of the state */
121 unsigned index;
122 unsigned chars[YARROW_KEY_EVENT_BUFFER];
123 unsigned previous;
126 void
127 yarrow_key_event_init(struct yarrow_key_event_ctx *ctx);
129 unsigned
130 yarrow_key_event_estimate(struct yarrow_key_event_ctx *ctx,
131 unsigned key, unsigned time);
133 #ifdef __cplusplus
135 #endif
137 #endif /* NETTLE_YARROW_H_INCLUDED */