diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-12 14:38:03 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-12 14:38:03 +0000 |
commit | 900406c359c319100c892a38be2bb5d76a8f85b9 (patch) | |
tree | b0b691558f415197eeb587b848f18dff05b46897 | |
parent | 6f0540e7eca61fa10344699d023f4a90f705601d (diff) | |
download | busybox-w32-900406c359c319100c892a38be2bb5d76a8f85b9.tar.gz busybox-w32-900406c359c319100c892a38be2bb5d76a8f85b9.tar.bz2 busybox-w32-900406c359c319100c892a38be2bb5d76a8f85b9.zip |
passwd: shrink by ~10 bytes, use PRNG instead of usleep.
-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 1f488290a..a062596b4 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c | |||
@@ -5,7 +5,6 @@ | |||
5 | 5 | ||
6 | #include "busybox.h" | 6 | #include "busybox.h" |
7 | #include <syslog.h> | 7 | #include <syslog.h> |
8 | #include <sys/times.h> /* times() */ | ||
9 | 8 | ||
10 | 9 | ||
11 | static void nuke_str(char *str) | 10 | static void nuke_str(char *str) |
@@ -16,7 +15,8 @@ static void nuke_str(char *str) | |||
16 | 15 | ||
17 | static int i64c(int i) | 16 | static int i64c(int i) |
18 | { | 17 | { |
19 | if (i <= 0) | 18 | i &= 0x3f; |
19 | if (i == 0) | ||
20 | return '.'; | 20 | return '.'; |
21 | if (i == 1) | 21 | if (i == 1) |
22 | return '/'; | 22 | return '/'; |
@@ -30,23 +30,16 @@ static int i64c(int i) | |||
30 | 30 | ||
31 | static void crypt_make_salt(char *p, int cnt) | 31 | static void crypt_make_salt(char *p, int cnt) |
32 | { | 32 | { |
33 | #if !defined(__GLIBC__) | 33 | unsigned x = x; /* it's pointless to initialize it anyway :) */ |
34 | struct tms t; | ||
35 | #define TIMES times(&t) | ||
36 | #else | ||
37 | /* glibc allows for times(NULL) a-la time() */ | ||
38 | #define TIMES times(NULL) | ||
39 | #endif | ||
40 | unsigned long x = x; /* it's pointless to initialize it anyway :) */ | ||
41 | 34 | ||
42 | x += getpid(); | 35 | x += getpid() + time(NULL) + clock(); |
43 | do { | 36 | do { |
44 | /* clock() and times() variability is different between systems */ | 37 | /* x = (x*1664525 + 1013904223) mod 2^32 generator is lame |
45 | /* hopefully at least one is good enough */ | 38 | * (low-order bit is not "random", etc...), |
46 | x += time(NULL) + clock() + TIMES; | 39 | * but for our purposes it is good enough */ |
47 | *p++ = i64c(((x >> 18) ^ (x >> 6)) & 0x3f); | 40 | x = x*1664525 + 1013904223; |
48 | *p++ = i64c(((x >> 12) ^ x) & 0x3f); | 41 | *p++ = i64c(x >> 16); |
49 | usleep(100); /* or else time() etc won't change */ | 42 | *p++ = i64c(x >> 22); |
50 | } while (--cnt); | 43 | } while (--cnt); |
51 | *p = '\0'; | 44 | *p = '\0'; |
52 | } | 45 | } |