diff --git a/yarrow.h b/yarrow.h index 52690bcf8fe37960b031c242ce0fcc5a343df03d..a5fac25c38e50e7670f0ca7b6540346a69423667 100644 --- a/yarrow.h +++ b/yarrow.h @@ -40,10 +40,15 @@ extern "C" { #define yarrow256_random nettle_yarrow256_random #define yarrow256_is_seeded nettle_yarrow256_is_seeded #define yarrow256_needed_sources nettle_yarrow256_needed_sources -#define yarrow256_force_reseed nettle_yarrow256_force_reseed +#define yarrow256_fast_reseed nettle_yarrow256_fast_reseed +#define yarrow256_slow_reseed nettle_yarrow256_slow_reseed #define yarrow_key_event_init nettle_yarrow_key_event_init #define yarrow_key_event_estimate nettle_yarrow_key_event_estimate +/* Obsolete alias for backwards compatibility. Will be deleted in some + later version. */ +#define yarrow256_force_reseed yarrow256_slow_reseed + enum yarrow_pool_id { YARROW_FAST = 0, YARROW_SLOW = 1 }; struct yarrow_source @@ -64,8 +69,6 @@ struct yarrow256_ctx /* Indexed by yarrow_pool_id */ struct sha256_ctx pools[2]; - uint8_t seed_file[YARROW256_SEED_FILE_SIZE]; - int seeded; /* The current key and counter block */ @@ -103,7 +106,10 @@ unsigned yarrow256_needed_sources(struct yarrow256_ctx *ctx); void -yarrow256_force_reseed(struct yarrow256_ctx *ctx); +yarrow256_fast_reseed(struct yarrow256_ctx *ctx); + +void +yarrow256_slow_reseed(struct yarrow256_ctx *ctx); /* Key event estimator */ diff --git a/yarrow256.c b/yarrow256.c index 184c5a338a15e1803649ffe4119cea7191d7ae38..e1ae77c14c331cd2b6032177b87aba1e2c85eadd 100644 --- a/yarrow256.c +++ b/yarrow256.c @@ -69,10 +69,6 @@ #define YARROW_MAX_ENTROPY 0x100000 /* Forward declarations */ - -static void -yarrow_fast_reseed(struct yarrow256_ctx *ctx); - static void yarrow_gate(struct yarrow256_ctx *ctx); @@ -88,9 +84,8 @@ yarrow256_init(struct yarrow256_ctx *ctx, ctx->seeded = 0; - /* Not strictly, necessary, but it makes it easier to see if the + /* Not strictly necessary, but it makes it easier to see if the * values are sane. */ - memset(ctx->seed_file, 0, YARROW256_SEED_FILE_SIZE); memset(ctx->counter, 0, sizeof(ctx->counter)); ctx->nsources = n; @@ -112,7 +107,7 @@ yarrow256_seed(struct yarrow256_ctx *ctx, assert(length > 0); sha256_update(&ctx->pools[YARROW_FAST], length, seed_file); - yarrow_fast_reseed(ctx); + yarrow256_fast_reseed(ctx); ctx->seeded = 1; } @@ -171,14 +166,14 @@ yarrow_iterate(uint8_t *digest) /* NOTE: The SHA-256 digest size equals the AES key size, so we need * no "size adaptor". */ -static void -yarrow_fast_reseed(struct yarrow256_ctx *ctx) +void +yarrow256_fast_reseed(struct yarrow256_ctx *ctx) { uint8_t digest[SHA256_DIGEST_SIZE]; unsigned i; #if YARROW_DEBUG - fprintf(stderr, "yarrow_fast_reseed\n"); + fprintf(stderr, "yarrow256_fast_reseed\n"); #endif /* We feed two block of output using the current key into the pool @@ -206,23 +201,16 @@ yarrow_fast_reseed(struct yarrow256_ctx *ctx) /* Reset estimates. */ for (i = 0; i<ctx->nsources; i++) ctx->sources[i].estimate[YARROW_FAST] = 0; - - /* New seed file. */ - /* FIXME: Extract this into a function of its own. */ - for (i = 0; i < sizeof(ctx->seed_file); i+= AES_BLOCK_SIZE) - yarrow_generate_block(ctx, ctx->seed_file + i); - - yarrow_gate(ctx); } -static void -yarrow_slow_reseed(struct yarrow256_ctx *ctx) +void +yarrow256_slow_reseed(struct yarrow256_ctx *ctx) { uint8_t digest[SHA256_DIGEST_SIZE]; unsigned i; #if YARROW_DEBUG - fprintf(stderr, "yarrow_slow_reseed\n"); + fprintf(stderr, "yarrow256_slow_reseed\n"); #endif /* Get digest of the slow pool*/ @@ -232,7 +220,7 @@ yarrow_slow_reseed(struct yarrow256_ctx *ctx) /* Feed it into the fast pool */ sha256_update(&ctx->pools[YARROW_FAST], sizeof(digest), digest); - yarrow_fast_reseed(ctx); + yarrow256_fast_reseed(ctx); /* Reset estimates. */ for (i = 0; i<ctx->nsources; i++) @@ -295,7 +283,7 @@ yarrow256_update(struct yarrow256_ctx *ctx, #endif if (source->estimate[YARROW_FAST] >= YARROW_FAST_THRESHOLD) { - yarrow_fast_reseed(ctx); + yarrow256_fast_reseed(ctx); return 1; } else @@ -305,7 +293,7 @@ yarrow256_update(struct yarrow256_ctx *ctx, { if (!yarrow256_needed_sources(ctx)) { - yarrow_slow_reseed(ctx); + yarrow256_slow_reseed(ctx); ctx->seeded = 1; return 1; @@ -380,9 +368,3 @@ yarrow256_needed_sources(struct yarrow256_ctx *ctx) return (k < YARROW_SLOW_K) ? (YARROW_SLOW_K - k) : 0; } - -void -yarrow256_force_reseed(struct yarrow256_ctx *ctx) -{ - yarrow_slow_reseed(ctx); -}