File indexing completed on 2025-01-18 10:02:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifndef NETTLE_YARROW_H_INCLUDED
0035 #define NETTLE_YARROW_H_INCLUDED
0036
0037 #include "aes.h"
0038 #include "sha2.h"
0039
0040 #ifdef __cplusplus
0041 extern "C" {
0042 #endif
0043
0044
0045 #define yarrow256_init nettle_yarrow256_init
0046 #define yarrow256_seed nettle_yarrow256_seed
0047 #define yarrow256_update nettle_yarrow256_update
0048 #define yarrow256_random nettle_yarrow256_random
0049 #define yarrow256_is_seeded nettle_yarrow256_is_seeded
0050 #define yarrow256_needed_sources nettle_yarrow256_needed_sources
0051 #define yarrow256_fast_reseed nettle_yarrow256_fast_reseed
0052 #define yarrow256_slow_reseed nettle_yarrow256_slow_reseed
0053 #define yarrow_key_event_init nettle_yarrow_key_event_init
0054 #define yarrow_key_event_estimate nettle_yarrow_key_event_estimate
0055
0056
0057
0058 #define yarrow256_force_reseed yarrow256_slow_reseed
0059
0060 enum yarrow_pool_id { YARROW_FAST = 0, YARROW_SLOW = 1 };
0061
0062 struct yarrow_source
0063 {
0064
0065 uint32_t estimate[2];
0066
0067
0068 enum yarrow_pool_id next;
0069 };
0070
0071
0072 #define YARROW256_SEED_FILE_SIZE (2 * AES_BLOCK_SIZE)
0073
0074
0075 struct yarrow256_ctx
0076 {
0077
0078 struct sha256_ctx pools[2];
0079
0080 int seeded;
0081
0082
0083 struct aes256_ctx key;
0084 uint8_t counter[AES_BLOCK_SIZE];
0085
0086
0087 unsigned nsources;
0088 struct yarrow_source *sources;
0089 };
0090
0091 void
0092 yarrow256_init(struct yarrow256_ctx *ctx,
0093 unsigned nsources,
0094 struct yarrow_source *sources);
0095
0096 void
0097 yarrow256_seed(struct yarrow256_ctx *ctx,
0098 size_t length,
0099 const uint8_t *seed_file);
0100
0101
0102 int
0103 yarrow256_update(struct yarrow256_ctx *ctx,
0104 unsigned source, unsigned entropy,
0105 size_t length, const uint8_t *data);
0106
0107 void
0108 yarrow256_random(struct yarrow256_ctx *ctx, size_t length, uint8_t *dst);
0109
0110 int
0111 yarrow256_is_seeded(struct yarrow256_ctx *ctx);
0112
0113 unsigned
0114 yarrow256_needed_sources(struct yarrow256_ctx *ctx);
0115
0116 void
0117 yarrow256_fast_reseed(struct yarrow256_ctx *ctx);
0118
0119 void
0120 yarrow256_slow_reseed(struct yarrow256_ctx *ctx);
0121
0122
0123
0124 #define YARROW_KEY_EVENT_BUFFER 16
0125
0126 struct yarrow_key_event_ctx
0127 {
0128
0129 unsigned index;
0130 unsigned chars[YARROW_KEY_EVENT_BUFFER];
0131 unsigned previous;
0132 };
0133
0134 void
0135 yarrow_key_event_init(struct yarrow_key_event_ctx *ctx);
0136
0137 unsigned
0138 yarrow_key_event_estimate(struct yarrow_key_event_ctx *ctx,
0139 unsigned key, unsigned time);
0140
0141 #ifdef __cplusplus
0142 }
0143 #endif
0144
0145 #endif