From 8fe6fc7b6eace6a1cae442f3b06cc15a6c4e6423 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Mon, 1 Nov 2004 21:33:05 +0000 Subject: [PATCH] * 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. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16853 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/crypto/yarrow/ChangeLog | 10 ++++++++ src/lib/crypto/yarrow/yarrow.c | 44 +++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/lib/crypto/yarrow/ChangeLog b/src/lib/crypto/yarrow/ChangeLog index bab1a67b4..2e5ab05cd 100644 --- a/src/lib/crypto/yarrow/ChangeLog +++ b/src/lib/crypto/yarrow/ChangeLog @@ -1,3 +1,13 @@ +2004-11-01 Ken Raeburn + + * 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 * ylock.h: Include k5-thread.h. diff --git a/src/lib/crypto/yarrow/yarrow.c b/src/lib/crypto/yarrow/yarrow.c index c9f418896..ae55801c9 100644 --- a/src/lib/crypto/yarrow/yarrow.c +++ b/src/lib/crypto/yarrow/yarrow.c @@ -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; -- 2.26.2