svn commit: trunk/busybox/loginutils

vda at busybox.net vda at busybox.net
Tue Dec 12 06:38:03 PST 2006


Author: vda
Date: 2006-12-12 06:38:03 -0800 (Tue, 12 Dec 2006)
New Revision: 16853

Log:
passwd: shrink by ~10 bytes, use PRNG instead of usleep.


Modified:
   trunk/busybox/loginutils/passwd.c


Changeset:
Modified: trunk/busybox/loginutils/passwd.c
===================================================================
--- trunk/busybox/loginutils/passwd.c	2006-12-12 13:16:31 UTC (rev 16852)
+++ trunk/busybox/loginutils/passwd.c	2006-12-12 14:38:03 UTC (rev 16853)
@@ -5,7 +5,6 @@
 
 #include "busybox.h"
 #include <syslog.h>
-#include <sys/times.h> /* times() */
 
 
 static void nuke_str(char *str)
@@ -16,7 +15,8 @@
 
 static int i64c(int i)
 {
-	if (i <= 0)
+	i &= 0x3f;
+	if (i == 0)
 		return '.';
 	if (i == 1)
 		return '/';
@@ -30,23 +30,16 @@
 
 static void crypt_make_salt(char *p, int cnt)
 {
-#if !defined(__GLIBC__)
-	struct tms t;
-#define TIMES times(&t)
-#else
-/* glibc allows for times(NULL) a-la time() */
-#define TIMES times(NULL)
-#endif
-	unsigned long x = x; /* it's pointless to initialize it anyway :) */
+	unsigned x = x; /* it's pointless to initialize it anyway :) */
 
-	x += getpid();
+	x += getpid() + time(NULL) + clock();
 	do {
-	/* clock() and times() variability is different between systems */
-	/* hopefully at least one is good enough */
-		x += time(NULL) + clock() + TIMES;
-		*p++ = i64c(((x >> 18) ^ (x >> 6)) & 0x3f);
-		*p++ = i64c(((x >> 12) ^ x) & 0x3f);
-		usleep(100); /* or else time() etc won't change */
+		/* x = (x*1664525 + 1013904223) mod 2^32 generator is lame
+		 * (low-order bit is not "random", etc...),
+		 * but for our purposes it is good enough */
+		x = x*1664525 + 1013904223;
+		*p++ = i64c(x >> 16);
+		*p++ = i64c(x >> 22);
 	} while (--cnt);
 	*p = '\0';
 }



More information about the busybox-cvs mailing list