summaryrefslogtreecommitdiff
path: root/yarrow256.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2001-11-14 17:21:36 +0100
committerNiels Möller <nisse@lysator.liu.se>2001-11-14 17:21:36 +0100
commit1078e1fdeb7cd110bd8f0c21a20ad3227c5d55ce (patch)
tree81f96c6f4cdbda631ba87cb73cb230fcb817f14c /yarrow256.c
parent74f85d4082225f2c7809e9281d7fe435f1b06b11 (diff)
downloadnettle-1078e1fdeb7cd110bd8f0c21a20ad3227c5d55ce.tar.gz
(yarrow256_needed_sources): New function.
(yarrow256_is_seeded): New function. (yarrow256_update): Use yarrow256_needed_sources. Rev: src/nettle/yarrow256.c:1.12
Diffstat (limited to 'yarrow256.c')
-rw-r--r--yarrow256.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/yarrow256.c b/yarrow256.c
index cfd92bd2..6ddc9a2e 100644
--- a/yarrow256.c
+++ b/yarrow256.c
@@ -307,20 +307,8 @@ yarrow256_update(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_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);
ctx->seeded = 1;
@@ -368,3 +356,32 @@ yarrow256_random(struct yarrow256_ctx *ctx, unsigned length, uint8_t *dst)
}
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;
+}