3 * The yarrow pseudo-randomness generator.
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001 Niels Möller
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., 59 Temple Place - Suite 330, Boston,
26 #ifndef NETTLE_YARROW_H_INCLUDED
27 #define NETTLE_YARROW_H_INCLUDED
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
50 #define yarrow256_force_reseed yarrow256_slow_reseed
52 enum yarrow_pool_id { YARROW_FAST = 0, YARROW_SLOW = 1 };
56 /* Indexed by yarrow_pool_id */
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 */
69 /* Indexed by yarrow_pool_id */
70 struct sha256_ctx pools[2];
74 /* The current key and counter block */
76 uint8_t counter[AES_BLOCK_SIZE];
78 /* The entropy sources */
80 struct yarrow_source *sources;
84 yarrow256_init(struct yarrow256_ctx *ctx,
86 struct yarrow_source *sources);
89 yarrow256_seed(struct yarrow256_ctx *ctx,
91 const uint8_t *seed_file);
93 /* Returns 1 on reseed */
95 yarrow256_update(struct yarrow256_ctx *ctx,
96 unsigned source, unsigned entropy,
97 unsigned length, const uint8_t *data);
100 yarrow256_random(struct yarrow256_ctx *ctx, unsigned length, uint8_t *dst);
103 yarrow256_is_seeded(struct yarrow256_ctx *ctx);
106 yarrow256_needed_sources(struct yarrow256_ctx *ctx);
109 yarrow256_fast_reseed(struct yarrow256_ctx *ctx);
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 */
122 unsigned chars[YARROW_KEY_EVENT_BUFFER];
127 yarrow_key_event_init(struct yarrow_key_event_ctx *ctx);
130 yarrow_key_event_estimate(struct yarrow_key_event_ctx *ctx,
131 unsigned key, unsigned time);
137 #endif /* NETTLE_YARROW_H_INCLUDED */