]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
* libmisc/salt.c: Add prototype for l64a(), gensalt(),
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 6 Jan 2008 14:50:26 +0000 (14:50 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 6 Jan 2008 14:50:26 +0000 (14:50 +0000)
  SHA_salt_size(), and SHA_salt_rounds().
* libmisc/salt.c: l64a() and gensalt() are static.
* libmisc/salt.c: The `meth' parameter of crypt_make_salt() is a
  const. (ditto for the method variable).
* libmisc/salt.c: SHA_salt_rounds returns a const string.
* libmisc/salt.c: Avoid warnings with cast of random() to double.
* libmisc/salt.c: Replace rand() by random().

ChangeLog
libmisc/salt.c

index 6a329d96dbcfc70f3a21ba2888730c546608afbe..8bbd2803541f0874d0597e49780bd527413e7944 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-01-06  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * libmisc/salt.c: Add prototype for l64a(), gensalt(),
+       SHA_salt_size(), and SHA_salt_rounds().
+       * libmisc/salt.c: l64a() and gensalt() are static.
+       * libmisc/salt.c: The `meth' parameter of crypt_make_salt() is a
+       const. (ditto for the method variable).
+       * libmisc/salt.c: SHA_salt_rounds returns a const string.
+       * libmisc/salt.c: Avoid warnings with cast of random() to double.
+       * libmisc/salt.c: Replace rand() by random().
+
 2008-01-06  Nicolas François  <nicolas.francois@centraliens.net>
 
        * lib/Makefile.am: Do not link libshadow.la with the intl, crypt,
index 2a9ecd2e530f54bfba383b0e214156bb3fcbb2e0..30ac920ff90bc8c7f6a6b81dbc6ba96677c24e31 100644 (file)
 #include "defines.h"
 #include "getdef.h"
 
+/* local function prototypes */
 #ifndef HAVE_L64A
-char *l64a(long value)
+char *l64a(long value);
+#endif
+static char *gensalt (unsigned int salt_size);
+#ifdef USE_SHA_CRYPT
+static unsigned int SHA_salt_size (void);
+static const char *SHA_salt_rounds (int *prefered_rounds);
+#endif
+
+#ifndef HAVE_L64A
+static char *l64a(long value)
 {
        static char buf[8];
        char *s = buf;
@@ -66,8 +76,9 @@ char *l64a(long value)
  */
 static unsigned int SHA_salt_size (void)
 {
-       srandom ((unsigned int)time (NULL));
-       return 8 + (double)random () * 9 / RAND_MAX;
+       double rand_rounds = 9 * random ();
+       rand_rounds /= RAND_MAX;
+       return 8 + rand_rounds;
 }
 
 /* ! Arguments evaluated twice ! */
@@ -84,7 +95,7 @@ static unsigned int SHA_salt_size (void)
 /*
  * Return a salt prefix specifying the rounds number for the SHA crypt methods.
  */
-static char *SHA_salt_rounds (int *prefered_rounds)
+static const char *SHA_salt_rounds (int *prefered_rounds)
 {
        static char rounds_prefix[18];
        long rounds;
@@ -92,6 +103,7 @@ static char *SHA_salt_rounds (int *prefered_rounds)
        if (NULL == prefered_rounds) {
                long min_rounds = getdef_long ("SHA_CRYPT_MIN_ROUNDS", -1);
                long max_rounds = getdef_long ("SHA_CRYPT_MAX_ROUNDS", -1);
+               double rand_rounds;
 
                if (-1 == min_rounds && -1 == max_rounds)
                        return "";
@@ -106,8 +118,9 @@ static char *SHA_salt_rounds (int *prefered_rounds)
                        max_rounds = min_rounds;
 
                srand (time (NULL));
-               rounds = min_rounds +
-                        (double)rand () * (max_rounds-min_rounds+1)/RAND_MAX;
+               rand_rounds = (max_rounds-min_rounds+1) * random ();
+               rand_rounds /= RAND_MAX;
+               rounds = min_rounds + rand_rounds;
        } else if (0 == *prefered_rounds)
                return "";
        else
@@ -138,7 +151,8 @@ static char *SHA_salt_rounds (int *prefered_rounds)
 #define MAX_SALT_SIZE 16
 #define MIN_SALT_SIZE 8
 
-char *gensalt (unsigned int salt_size) {
+static char *gensalt (unsigned int salt_size)
+{
        static char salt[32];
 
        salt[0] = '\0';
@@ -170,7 +184,7 @@ char *gensalt (unsigned int salt_size) {
  *  * For the SHA256 and SHA512 method, this specifies the number of rounds
  *    (if not NULL).
  */
-char *crypt_make_salt (char *meth, void *arg)
+char *crypt_make_salt (const char *meth, void *arg)
 {
        /* Max result size for the SHA methods:
         *  +3          $5$
@@ -180,7 +194,7 @@ char *crypt_make_salt (char *meth, void *arg)
         */
        static char result[40];
        size_t salt_len = 8;
-       char *method;
+       const char *method;
 
        result[0] = '\0';
 
@@ -220,3 +234,4 @@ char *crypt_make_salt (char *meth, void *arg)
 
        return result;
 }
+