Changeset 481 for trunk/src/sh_utils.c


Ignore:
Timestamp:
Jul 18, 2015, 5:06:52 PM (6 years ago)
Author:
katerina
Message:

Enhancements and fixes for tickets #374, #375, #376, #377, #378, and #379.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_utils.c

    r473 r481  
    309309          }
    310310        }
    311         out[rem] = ','; ++rem;
    312         while (p[1] == '\n') ++p; /* scan over consecutive newlines */
     311        out[rem] = ','; ++rem;    /* <-- ensures (rem > 0) is true    */
     312        while (p[1] == '\n') ++p; /* scan over consecutive newlines   */
    313313        state = 0;
    314314        if (p[1] == '\0') {
    315           if (rem > 0) out[rem-1] = '\0';
     315          out[rem-1] = '\0';      /* rem > 0 because of 4 lines above */
    316316          break;
    317317        }
     
    782782  char hashbuf[KEYBUF_SIZE];
    783783
    784 
     784  int         result;
    785785  size_t      i;
    786786
    787787  SL_ENTER(_("sh_util_hmac_tiger"));
    788   ASSERT((KEY_BLOCK <= (KEY_LEN/2)), _("KEY_BLOCK <= (KEY_LEN/2)"))
    789 
    790   if (KEY_BLOCK > (KEY_LEN/2))
    791     {
    792       (void) sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
    793       sl_strlcpy(res, hashbuf, len);
    794       SL_RETURN(res, _("sh_util_hmac_tiger"));
    795     }
     788
     789  ASSERT((KEY_BLOCK <= (KEY_LEN/2)), _("KEY_BLOCK <= (KEY_LEN/2)"));
    796790
    797791  memcpy (K, zap, KEY_BLOCK);
    798792
    799   if (sh_util_hextobinary (K, hexkey, KEY_LEN) < 0)
    800     {
    801       (void) sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
    802       sl_strlcpy(res, hashbuf, len);
    803       SL_RETURN(res, _("sh_util_hmac_tiger"));
    804     }
    805 
    806   if (sl_ok_adds(textlen, KEY_BLOCK))
     793  result = sh_util_hextobinary (K, hexkey, KEY_LEN);
     794
     795  ASSERT((result >= 0), _("result >= 0"));
     796
     797  if ((result >= 0) && sl_ok_adds(textlen, KEY_BLOCK))
    807798    {
    808799      inner = (char *) SH_ALLOC (textlen + KEY_BLOCK);
     
    830821  /* now compute the hash
    831822   */
    832   h1 = sh_tiger_hash_uint32 ( outer,
    833                               TIGER_DATA,
    834                               KEY_BLOCK,
     823  h1 = sh_tiger_hash_uint32 ( outer, TIGER_DATA, KEY_BLOCK,
    835824                              kbuf, KEY_BYT/sizeof(UINT32));
    836825  for (i = 0; i < (KEY_LEN/8); ++i)
    837     {
    838       /* cc[i] = h1[i]; */
    839       copy_four ( (unsigned char *) &(cc[i]), h1[i]);
    840     }
    841 
    842   h2 = sh_tiger_hash_uint32 ( inner,
    843                               TIGER_DATA,
     826    copy_four ( (unsigned char *) &(cc[i]), h1[i]);
     827
     828  h2 = sh_tiger_hash_uint32 ( inner, TIGER_DATA,
    844829                              (unsigned long) KEY_BLOCK+textlen,
    845830                              kbuf, KEY_BYT/sizeof(UINT32));
    846831  for (i = KEY_LEN/8; i < (KEY_LEN/4); ++i)
    847     {
    848       copy_four ( (unsigned char *) &(cc[i]), h2[i - (KEY_LEN/8)]);
    849       /* cc[i] = h2[i - (KEY_LEN/8)]; */
    850     }
     832    copy_four ( (unsigned char *) &(cc[i]), h2[i - (KEY_LEN/8)]);
     833
    851834  SH_FREE(inner);
    852835 
     
    10331016
    10341017
    1035 /* interval [0, 4294967296]
     1018/* interval [0, 4294967295]
    10361019 */
    10371020static UINT32 taus_get_long (void *vstate)
     
    11601143  char                 bufx[9 * sizeof(UINT32) + 1];
    11611144  int                  status;
    1162   static unsigned long seed_time = 0;
     1145  static unsigned long seed_time    = 0;
     1146  static unsigned long seed_counter = 3000;
    11631147  unsigned long        gtime;
    11641148
     
    11671151  if (skey->rngI == GOOD)
    11681152    {
    1169       if ( (sh_unix_longtime () - seed_time) < 7200)
     1153      ++seed_counter;
     1154
     1155      if ( ((sh_unix_longtime () - seed_time) < 1800) &&
     1156           ( seed_counter                     < 3000))
    11701157        SL_RETURN( (0), _("taus_seed"));
    11711158    }
    11721159 
    1173   seed_time = sh_unix_longtime ();
     1160  seed_time    = sh_unix_longtime ();
     1161  seed_counter = 0;
    11741162
    11751163  status = sh_entropy (24, bufx);
     
    18341822int sh_util_obscurename (ShErrLevel level, const char * name_orig, int flag)
    18351823{
    1836   const unsigned char * name = (unsigned char *) name_orig;
     1824  const unsigned char * name = (const unsigned char *) name_orig;
    18371825  char * safe;
    18381826  unsigned int i;
     
    23082296  unsigned char b;
    23092297  size_t lout = 0;
    2310   int    w = 0;
     2298  unsigned int  w = 0;
    23112299
    23122300  if (out && in)
Note: See TracChangeset for help on using the changeset viewer.