Skip to content
Snippets Groups Projects
Commit 1078e1fd authored by Niels Möller's avatar Niels Möller
Browse files

(yarrow256_needed_sources): New function.

(yarrow256_is_seeded): New function.
(yarrow256_update): Use yarrow256_needed_sources.

Rev: src/nettle/yarrow256.c:1.12
parent 74f85d40
No related branches found
No related tags found
No related merge requests found
...@@ -307,20 +307,8 @@ yarrow256_update(struct yarrow256_ctx *ctx, ...@@ -307,20 +307,8 @@ yarrow256_update(struct yarrow256_ctx *ctx,
/* FIXME: This is somewhat inefficient. It would be better to /* FIXME: This is somewhat inefficient. It would be better to
* either maintain the count, or do this loop only if the * either maintain the count, or do this loop only if the
* current source just crossed the threshold. */ * current source just crossed the threshold. */
unsigned k, i;
for (i = k = 0; i < ctx->nsources; i++)
if (ctx->sources[i].estimate[YARROW_SLOW] >= YARROW_SLOW_THRESHOLD)
k++;
#if YARROW_DEBUG
fprintf(stderr,
"yarrow256_update: source_index = %d,\n"
" slow pool estimate = %d,\n"
" number of sources above threshold = %d\n",
source_index, source->estimate[YARROW_SLOW], k);
#endif
if (k >= YARROW_SLOW_K) if (!yarrow256_needed_sources(ctx))
{ {
yarrow_slow_reseed(ctx); yarrow_slow_reseed(ctx);
ctx->seeded = 1; ctx->seeded = 1;
...@@ -368,3 +356,32 @@ yarrow256_random(struct yarrow256_ctx *ctx, unsigned length, uint8_t *dst) ...@@ -368,3 +356,32 @@ yarrow256_random(struct yarrow256_ctx *ctx, unsigned length, uint8_t *dst)
} }
yarrow_gate(ctx); yarrow_gate(ctx);
} }
int
yarrow256_is_seeded(struct yarrow256_ctx *ctx)
{
return ctx->seeded;
}
unsigned
yarrow256_needed_sources(struct yarrow256_ctx *ctx)
{
/* FIXME: This is somewhat inefficient. It would be better to
* either maintain the count, or do this loop only if the
* current source just crossed the threshold. */
unsigned k, i;
for (i = k = 0; i < ctx->nsources; i++)
if (ctx->sources[i].estimate[YARROW_SLOW] >= YARROW_SLOW_THRESHOLD)
k++;
#if YARROW_DEBUG
fprintf(stderr,
"yarrow256_needed_sources: source_index = %d,\n"
" slow pool estimate = %d,\n"
" number of sources above threshold = %d\n",
source_index, source->estimate[YARROW_SLOW], k);
#endif
return (k < YARROW_SLOW_K) ? (YARROW_SLOW_K - k) : 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment