Guarantee now zero byte is returned by the RNG.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 10 Nov 2003 11:20:18 +0000 (11:20 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 10 Nov 2003 11:20:18 +0000 (11:20 +0000)
lib/silccrypt/silcrng.c
lib/silccrypt/silcrng.h

index 5bef88727943e8f1a16fd71ab2f0d7014569f747..df3217f431f6945c3ebec7f5cdf7b79eab1af311 100644 (file)
@@ -496,6 +496,8 @@ static SilcUInt32 silc_rng_get_position(SilcRng rng)
 
 SilcUInt8 silc_rng_get_byte(SilcRng rng)
 {
+  SilcUInt8 byte;
+
   rng->threshold++;
 
   /* Get more soft noise after 64 bits threshold */
@@ -508,7 +510,8 @@ SilcUInt8 silc_rng_get_byte(SilcRng rng)
     silc_rng_get_hard_noise(rng);
   }
 
-  return rng->pool[silc_rng_get_position(rng)];
+  do byte = rng->pool[silc_rng_get_position(rng)]; while (byte == 0x00);
+  return byte;
 }
 
 /* Return random byte as fast as possible. Reads from /dev/urandom if
@@ -529,7 +532,7 @@ SilcUInt8 silc_rng_get_byte_fast(SilcRng rng)
   if (read(rng->fd_devurandom, buf, sizeof(buf)) < 0)
     return silc_rng_get_byte(rng);
 
-  return buf[0];
+  return buf[0] != 0x00 ? buf[0] : silc_rng_get_byte(rng);
 #else
   return silc_rng_get_byte(rng);
 #endif
@@ -565,7 +568,7 @@ SilcUInt32 silc_rng_get_rn32(SilcRng rng)
   return num;
 }
 
-/* Returns random number string. Returned string is in HEX format. */
+/* Returns non-zero random number string. Returned string is in HEX format. */
 
 unsigned char *silc_rng_get_rn_string(SilcRng rng, SilcUInt32 len)
 {
@@ -580,7 +583,7 @@ unsigned char *silc_rng_get_rn_string(SilcRng rng, SilcUInt32 len)
   return string;
 }
 
-/* Returns random number binary data. */
+/* Returns non-zero random number binary data. */
 
 unsigned char *silc_rng_get_rn_data(SilcRng rng, SilcUInt32 len)
 {
index 7dbdcbf6a692655716b955db638ccb8893e36823..4ae6b7d8891fd089160a9d4e91c0e2dba308ef9f 100644 (file)
@@ -1,10 +1,10 @@
 /*
 
-  silcrng.h 
+  silcrng.h
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2002 Pekka Riikonen
+  Copyright (C) 1997 - 2003 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -39,7 +39,7 @@
 /****s* silccrypt/SilcRNGAPI/SilcRng
  *
  * NAME
- * 
+ *
  *    typedef struct SilcRngStruct *SilcRng;
  *
  * DESCRIPTION
@@ -174,7 +174,8 @@ SilcUInt32 silc_rng_get_rn32(SilcRng rng);
  * DESCRIPTION
  *
  *    Returns random string in HEX form of the length of `len' bytes.
- *    The caller must free returned data buffer.
+ *    The caller must free returned data buffer.  It is guaranteed the
+ *    data string goes not include any zero (0x00) bytes.
  *
  ***/
 unsigned char *silc_rng_get_rn_string(SilcRng rng, SilcUInt32 len);
@@ -187,8 +188,9 @@ unsigned char *silc_rng_get_rn_string(SilcRng rng, SilcUInt32 len);
  *
  * DESCRIPTION
  *
- *    Returns random binary data of the length of `len' bytes.  The 
- *    caller must free returned data buffer.
+ *    Returns random binary data of the length of `len' bytes.  The
+ *    caller must free returned data buffer.  It is guaranteed the data
+ *    buffer does not include any zero (0x00) bytes.
  *
  ***/
 unsigned char *silc_rng_get_rn_data(SilcRng rng, SilcUInt32 len);
@@ -201,7 +203,7 @@ unsigned char *silc_rng_get_rn_data(SilcRng rng, SilcUInt32 len);
  *
  * DESCRIPTION
  *
- *    Add the data buffer indicated by `buffer' of length of `len' bytes 
+ *    Add the data buffer indicated by `buffer' of length of `len' bytes
  *    as noise to the random number generator.  The random number generator
  *    is restirred (reseeded) when this function is called.
  *
@@ -317,7 +319,8 @@ SilcUInt32 silc_rng_global_get_rn32(void);
  * DESCRIPTION
  *
  *    Returns random string in HEX form of the length of `len' bytes.
- *    The caller must free returned data buffer.
+ *    The caller must free returned data buffer.  It is guaranteed the
+ *    data string goes not include any zero (0x00) bytes.
  *
  ***/
 unsigned char *silc_rng_global_get_rn_string(SilcUInt32 len);
@@ -330,8 +333,9 @@ unsigned char *silc_rng_global_get_rn_string(SilcUInt32 len);
  *
  * DESCRIPTION
  *
- *    Returns random binary data of the length of `len' bytes.  The 
- *    caller must free returned data buffer.
+ *    Returns random binary data of the length of `len' bytes.  The
+ *    caller must free returned data buffer.  It is guaranteed the data
+ *    buffer does not include any zero (0x00) bytes.
  *
  ***/
 unsigned char *silc_rng_global_get_rn_data(SilcUInt32 len);
@@ -344,7 +348,7 @@ unsigned char *silc_rng_global_get_rn_data(SilcUInt32 len);
  *
  * DESCRIPTION
  *
- *    Add the data buffer indicated by `buffer' of length of `len' bytes 
+ *    Add the data buffer indicated by `buffer' of length of `len' bytes
  *    as noise to the random number generator.  The random number generator
  *    is restirred (reseeded) when this function is called.
  *