From b84a309d82f4b17b017a63f52a6a6a372b2cf7ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Fri, 24 Oct 2008 21:43:47 +0200
Subject: [PATCH] * yarrow256.c (yarrow256_fast_reseed): Renamed (was
 yarrow_fast_reseed) and made non-static. Don't generate seed file here, let
 the application use yarrow256_random instead. (yarrow256_slow_reseed):
 Renamed (was yarrow_slow_reseed) and made non-static.
 (yarrow256_force_reseed): Deleted function, use yarrow256_slow_reseed
 instead. For backwards compatibility, yarrow.h defines yarrow256_force_reseed
 as an alias for that function.

* yarrow.h (struct yarrow256_ctx): Deleted seed_file buffer.

Rev: nettle/yarrow.h:1.2
Rev: nettle/yarrow256.c:1.4
---
 yarrow.h    | 14 ++++++++++----
 yarrow256.c | 40 +++++++++++-----------------------------
 2 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/yarrow.h b/yarrow.h
index 52690bcf..a5fac25c 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 184c5a33..e1ae77c1 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);
-}
-- 
GitLab