From 1078e1fdeb7cd110bd8f0c21a20ad3227c5d55ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Wed, 14 Nov 2001 17:21:36 +0100
Subject: [PATCH] (yarrow256_needed_sources): New function.
 (yarrow256_is_seeded): New function. (yarrow256_update): Use
 yarrow256_needed_sources.

Rev: src/nettle/yarrow256.c:1.12
---
 yarrow256.c | 43 ++++++++++++++++++++++++++++++-------------
 1 file 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;
+}
-- 
GitLab