diff options
author | Denis Vlasenko | 2006-12-12 14:38:03 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-12-12 14:38:03 +0000 |
commit | 900406c359c319100c892a38be2bb5d76a8f85b9 (patch) | |
tree | b0b691558f415197eeb587b848f18dff05b46897 /loginutils | |
parent | 6f0540e7eca61fa10344699d023f4a90f705601d (diff) | |
download | busybox-900406c359c319100c892a38be2bb5d76a8f85b9.zip busybox-900406c359c319100c892a38be2bb5d76a8f85b9.tar.gz |
passwd: shrink by ~10 bytes, use PRNG instead of usleep.
Diffstat (limited to 'loginutils')
-rw-r--r-- | loginutils/passwd.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/loginutils/passwd.c b/loginutils/passwd.c index 1f48829..a062596 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c @@ -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 void nuke_str(char *str) static int i64c(int i) { - if (i <= 0) + i &= 0x3f; + if (i == 0) return '.'; if (i == 1) return '/'; @@ -30,23 +30,16 @@ static int i64c(int i) 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'; } |