[BACK]Return to crypt-sha1.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libcrypt

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libcrypt/crypt-sha1.c between version 1.3 and 1.4

version 1.3, 2006/10/27 18:22:56 version 1.4, 2011/05/09 19:15:28
Line 122  __crypt_sha1 (const char *pw, const char
Line 122  __crypt_sha1 (const char *pw, const char
     static unsigned char hmac_buf[SHA1_SIZE];      static unsigned char hmac_buf[SHA1_SIZE];
     static char passwd[(2 * sizeof(SHA1_MAGIC)) +      static char passwd[(2 * sizeof(SHA1_MAGIC)) +
                        CRYPT_SHA1_SALT_LENGTH + SHA1_SIZE];                         CRYPT_SHA1_SALT_LENGTH + SHA1_SIZE];
     char *sp;      const char *sp;
     char *ep;      char *ep;
     unsigned long ul;      unsigned long ul;
     int sl;      int sl;
Line 136  __crypt_sha1 (const char *pw, const char
Line 136  __crypt_sha1 (const char *pw, const char
      * $<tag>$<iterations>$salt[$]       * $<tag>$<iterations>$salt[$]
      * If it does not start with $ we use our default iterations.       * If it does not start with $ we use our default iterations.
      */       */
     sp = __UNCONST(salt);  
   
     /* If it starts with the magic string, then skip that */      /* If it starts with the magic string, then skip that */
     if (!strncmp(sp, magic, strlen(magic))) {      if (!strncmp(salt, magic, strlen(magic))) {
         sp += strlen(magic);          salt += strlen(magic);
         /* and get the iteration count */          /* and get the iteration count */
         iterations = strtoul(sp, &ep, 10);          iterations = strtoul(salt, &ep, 10);
         if (*ep != '$')          if (*ep != '$')
             return NULL;                /* invalid input */              return NULL;                /* invalid input */
         sp = ep + 1;                    /* skip over the '$' */          salt = ep + 1;                  /* skip over the '$' */
     } else {      } else {
         iterations = __crypt_sha1_iterations(0);          iterations = __crypt_sha1_iterations(0);
     }      }
   
     /* It stops at the next '$', max CRYPT_SHA1_ITERATIONS chars */      /* It stops at the next '$', max CRYPT_SHA1_ITERATIONS chars */
     for (ep = sp; *ep && *ep != '$' && ep < (sp + CRYPT_SHA1_ITERATIONS); ep++)      for (sp = salt; *sp && *sp != '$' && sp < (salt + CRYPT_SHA1_ITERATIONS); sp++)
         continue;          continue;
   
     /* Get the length of the actual salt */      /* Get the length of the actual salt */
     sl = ep - sp;      sl = sp - salt;
     pl = strlen(pw);      pl = strlen(pw);
   
     /*      /*
Line 163  __crypt_sha1 (const char *pw, const char
Line 162  __crypt_sha1 (const char *pw, const char
      * Prime the pump with <salt><magic><iterations>       * Prime the pump with <salt><magic><iterations>
      */       */
     dl = snprintf(passwd, sizeof (passwd), "%.*s%s%u",      dl = snprintf(passwd, sizeof (passwd), "%.*s%s%u",
                   sl, sp, magic, iterations);                    sl, salt, magic, iterations);
     /*      /*
      * Then hmac using <pw> as key, and repeat...       * Then hmac using <pw> as key, and repeat...
      */       */
     ep = __UNCONST(pw);                 /* keep gcc happy */      __hmac_sha1(passwd, dl, pw, pl, hmac_buf);
     __hmac_sha1(passwd, dl, ep, pl, hmac_buf);  
     for (i = 1; i < iterations; i++) {      for (i = 1; i < iterations; i++) {
         __hmac_sha1(hmac_buf, SHA1_SIZE, ep, pl, hmac_buf);          __hmac_sha1(hmac_buf, SHA1_SIZE, pw, pl, hmac_buf);
     }      }
     /* Now output... */      /* Now output... */
     pl = snprintf(passwd, sizeof(passwd), "%s%u$%.*s$",      pl = snprintf(passwd, sizeof(passwd), "%s%u$%.*s$",
                   magic, iterations, sl, sp);                    magic, iterations, sl, salt);
     ep = passwd + pl;      ep = passwd + pl;
   
     /* Every 3 bytes of hash gives 24 bits which is 4 base64 chars */      /* Every 3 bytes of hash gives 24 bits which is 4 base64 chars */

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

CVSweb <webmaster@jp.NetBSD.org>