Index: trunk/src/sh_utils.c
===================================================================
--- trunk/src/sh_utils.c	(revision 133)
+++ trunk/src/sh_utils.c	(revision 137)
@@ -45,4 +45,5 @@
 #include "sh_tiger.h"
 #include "sh_entropy.h"
+#include "sh_pthread.h"
 
 #undef  FIL__
@@ -570,7 +571,6 @@
 }
 
-char * sh_util_charhex( unsigned char i )
-{
-  static char i2h[2];
+char * sh_util_charhex( unsigned char i , char * i2h)
+{
   int j, k;
 
@@ -669,5 +669,4 @@
   UINT32    * h2;
   UINT32      cc[KEY_LEN/4];
-  char      * res;
   UINT32      kbuf[KEY_BYT/sizeof(UINT32)];
   char hashbuf[KEYBUF_SIZE];
@@ -681,5 +680,6 @@
   if (KEY_BLOCK > (KEY_LEN/2))
     {
-      res = sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      (void) sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      sl_strlcpy(res, hashbuf, len);
       SL_RETURN(res, _("sh_util_hmac_tiger"));
     }
@@ -689,5 +689,6 @@
   if (sh_util_hextobinary (K, hexkey, KEY_LEN) < 0)
     {
-      res = sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      (void) sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      sl_strlcpy(res, hashbuf, len);
       SL_RETURN(res, _("sh_util_hmac_tiger"));
     }
@@ -712,5 +713,6 @@
 		      _("integer overflow"), 
 		      _("sh_util_hmac_tiger"));
-      res = sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      (void) sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      sl_strlcpy(res, hashbuf, len);
       SL_RETURN(res, _("sh_util_hmac_tiger"));
     }
@@ -749,8 +751,10 @@
 
 static char * sh_util_hash_tiger ( char * hexkey,  
-				   char * text, size_t textlen
+				   char * text, size_t textlen,
 				   char * res, size_t len)
 {
   char           h2[2*KEY_LEN+1];
+  char hashbuf[KEYBUF_SIZE];
+
   SL_ENTER(_("sh_util_hash_tiger"));
 
@@ -760,5 +764,5 @@
 				  (unsigned long) textlen,
 				  hashbuf, sizeof(hashbuf)), 
-		    2*KEY_LEN+1,
+		    2*KEY_LEN+1
 		    );
 
@@ -917,6 +921,8 @@
   UINT32 * state = (UINT32 *) vstate;
 
+  /*
   if (skey->rngI == BAD)
     (void)taus_seed();
+  */
 
 #define TAUSWORTHE(s,a,b,c,d) ((s &c) <<d) ^ (((s <<a) ^s) >>b)
@@ -932,8 +938,8 @@
  * input for a one-way hash function.
  */
-UINT32   taus_svec[6];
-
-UINT32 taus_get (void *state1, void *state2, void *state3)
-{
+
+UINT32 taus_get ()
+{
+  UINT32   taus_svec[6];
   UINT32   retval;
   UINT32 * res;
@@ -943,17 +949,24 @@
   UINT32       kbuf[KEY_BYT/sizeof(UINT32)];
 
+  SH_MUTEX_LOCK_UNSAFE(mutex_skey);
   if (res_num > 0)
     {
       retval  = res_vec[res_num];
       res_num = (res_num == 5) ? 0 : (res_num + 1);
+      SH_MUTEX_UNLOCK_UNSAFE(mutex_skey); /* alternative path */
       return  retval;
     }
-
-  taus_svec[0] = taus_get_long (state1);
-  taus_svec[1] = taus_get_long (state2);
-  taus_svec[2] = taus_get_long (state3);
-  taus_svec[3] = taus_get_long (state1);
-  taus_svec[4] = taus_get_long (state2);
-  taus_svec[5] = taus_get_long (state3);
+  SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
+
+  (void)taus_seed();
+
+  SH_MUTEX_LOCK_UNSAFE(mutex_skey);
+  taus_svec[0] = taus_get_long (&(skey->rng0[0]));
+  taus_svec[1] = taus_get_long (&(skey->rng1[0]));
+  taus_svec[2] = taus_get_long (&(skey->rng2[2]));
+  taus_svec[3] = taus_get_long (&(skey->rng0[0]));
+  taus_svec[4] = taus_get_long (&(skey->rng1[0]));
+  taus_svec[5] = taus_get_long (&(skey->rng2[0]));
+  SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
 
   res     = sh_tiger_hash_uint32 ( (char *) &taus_svec[0], 
@@ -962,4 +975,5 @@
 				   kbuf, KEY_BYT/sizeof(UINT32));
 
+  SH_MUTEX_LOCK_UNSAFE(mutex_skey);
   for (i = 1; i < 6; ++i)
     { 
@@ -968,4 +982,5 @@
   retval  = taus_svec[0];
   res_num = 1;
+  SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
 
   taus_svec[0] = 0; taus_svec[1] = 0; taus_svec[2] = 0; 
@@ -1027,4 +1042,5 @@
   int                  status;
   static unsigned long seed_time = 0;
+  unsigned long        gtime;
 
   SL_ENTER(_("taus_seed"));
@@ -1032,5 +1048,5 @@
   if (skey->rngI == GOOD)
     {
-      if ( (sh_unix_longtime () - seed_time) < 3600)
+      if ( (sh_unix_longtime () - seed_time) < 7200)
 	SL_RETURN( (0), _("taus_seed"));
     }
@@ -1042,5 +1058,5 @@
   if (!SL_ISERROR(status))
     {
-      skey->rngI = GOOD;
+      SH_MUTEX_LOCK_UNSAFE(mutex_skey);
       memcpy (&skey->rng0[0], &bufx[0],                  2*sizeof(UINT32));
       memcpy (&skey->rng1[0], &bufx[2*sizeof(UINT32)],   2*sizeof(UINT32));
@@ -1056,4 +1072,6 @@
       taus_set_from_state( &(skey->rng2[0]), &(skey->rng2[0]));
 
+      skey->rngI = GOOD;
+      SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
       SL_RETURN( (0), _("taus_seed"));
     }
@@ -1064,13 +1082,16 @@
   /* emergency backup - unsafe !
    */
-  skey->rngI = GOOD;
 #ifdef HAVE_GETTIMEOFDAY
-  taus_set_from_ulong ( &(skey->rng0[0]), LCG (sh_unix_notime())      );
+  gtime = sh_unix_notime();
 #else
-  taus_set_from_ulong ( &(skey->rng0[0]), LCG (seed_time)      );
+  gtime = seed_time;
 #endif
+
+  SH_MUTEX_LOCK_UNSAFE(mutex_skey);
+  taus_set_from_ulong ( &(skey->rng0[0]), LCG (gtime)          );
   taus_set_from_ulong ( &(skey->rng1[0]), LCG (skey->rng0[0])  );
   taus_set_from_ulong ( &(skey->rng2[0]), LCG (skey->rng1[0])  );
   skey->rngI = BAD;
+  SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
 
   SL_RETURN( (-1), _("taus_seed"));
