* yarrow.c (krb5int_yarrow_input, krb5int_yarrow_final): Don't check for
authorKen Raeburn <raeburn@mit.edu>
Mon, 1 Nov 2004 21:33:05 +0000 (21:33 +0000)
committerKen Raeburn <raeburn@mit.edu>
Mon, 1 Nov 2004 21:33:05 +0000 (21:33 +0000)
forking here.
(yarrow_output_locked): Split out from krb5int_yarrow_output, without locking.
(krb5int_yarrow_output): Do locking and call yarrow_output_locked.
(yarrow_gate_locked): New function; uses yarrow_output_locked.
(krb5int_yarrow_output_Block): Use yarrow_gate_locked.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16853 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/crypto/yarrow/ChangeLog
src/lib/crypto/yarrow/yarrow.c

index bab1a67b4b778a699d2a7433d3164109464bd34e..2e5ab05cd2e35a6b6996846c4057479252c4525f 100644 (file)
@@ -1,3 +1,13 @@
+2004-11-01  Ken Raeburn  <raeburn@mit.edu>
+
+       * yarrow.c (krb5int_yarrow_input, krb5int_yarrow_final): Don't
+       check for forking here.
+       (yarrow_output_locked): Split out from krb5int_yarrow_output,
+       without locking.
+       (krb5int_yarrow_output): Do locking and call yarrow_output_locked.
+       (yarrow_gate_locked): New function; uses yarrow_output_locked.
+       (krb5int_yarrow_output_Block): Use yarrow_gate_locked.
+
 2004-10-29  Ken Raeburn  <raeburn@mit.edu>
 
        * ylock.h: Include k5-thread.h.
index c9f41889678b546ca7ef1a3819355510610dc0b1..ae55801c918027b57e07c8387daa50b13d40e450 100644 (file)
@@ -254,7 +254,6 @@ int krb5int_yarrow_input( Yarrow_CTX* y, unsigned source_id,
     size_t estimate;
 
     if (!y) { THROW( YARROW_BAD_ARG ); }
-    TRY( Yarrow_detect_fork( y ) );
 
     if (source_id >= y->num_sources) { THROW( YARROW_BAD_SOURCE ); }
   
@@ -395,7 +394,7 @@ static int krb5int_yarrow_output_Block( Yarrow_CTX* y, void* out )
     if (y->out_count >= y->Pg)
     {
        y->out_count = 0;
-       TRY( krb5int_yarrow_gate( y ) );
+       TRY( yarrow_gate_locked( y ) );
 
        /* require new seed after reaching gates_limit */
 
@@ -478,11 +477,23 @@ int krb5int_yarrow_status( Yarrow_CTX* y, int *num_sources, unsigned *source_id,
     EXCEP_RET;
 }
 
+static int yarrow_output_locked(Yarrow_CTX*, void*, size_t);
+
 YARROW_DLL
 int krb5int_yarrow_output( Yarrow_CTX* y, void* out, size_t size )
 {
     EXCEP_DECL;
-    int locked = 0;
+    TRY( LOCK() );
+    TRY( yarrow_output_locked(y, out, size));
+CATCH:
+    UNLOCK();
+    EXCEP_RET;
+}
+
+static
+int yarrow_output_locked( Yarrow_CTX* y, void* out, size_t size )
+{
+    EXCEP_DECL;
     size_t left;
     char* outp;
     size_t use;
@@ -495,8 +506,6 @@ int krb5int_yarrow_output( Yarrow_CTX* y, void* out, size_t size )
     left = size;
     outp = out;
 
-    TRY( LOCK() );
-
     if (y->out_left > 0)
     {
        use = min(left, y->out_left);
@@ -521,8 +530,30 @@ int krb5int_yarrow_output( Yarrow_CTX* y, void* out, size_t size )
     }
 
  CATCH:
-    if ( locked ) { TRY( UNLOCK() ); }
+    EXCEP_RET;
+}
+
+static int yarrow_gate_locked(Yarrow_CTX* y)
+{
+    EXCEP_DECL;
+    byte new_K[CIPHER_KEY_SIZE];
+
+    if (!y) { THROW( YARROW_BAD_ARG ); }
   
+    TRACE( printf( "GATE[" ); );
+
+    /* K <- Next k bits of PRNG output */
+
+    TRY( yarrow_output_locked(y, new_K, CIPHER_KEY_SIZE) );
+    mem_copy(y->K, new_K, CIPHER_KEY_SIZE);
+
+    /* need to resetup the key schedule as the key has changed */
+
+    TRY (krb5int_yarrow_cipher_init(&y->cipher, y->K));
+
+ CATCH:
+    TRACE( printf( "]," ); );
+    mem_zero(new_K, sizeof(new_K));
     EXCEP_RET;
 }
 
@@ -837,7 +868,6 @@ int krb5int_yarrow_final(Yarrow_CTX* y)
     int locked = 0;
 
     if (!y) { THROW( YARROW_BAD_ARG ); }
-    TRY( Yarrow_detect_fork(y) );
     TRY( LOCK() );
     locked = 1;