diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-07 01:16:34 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-07 01:16:34 +0000 |
commit | d1a84a2880073f6cc5e2f9f4e5f236cd110f01a0 (patch) | |
tree | 8e5b81c863ef3b91870812e822fecc3d97b0aff7 | |
parent | db12d1d733ab7de0c5f4cda261eb79fd334a4ed9 (diff) | |
download | busybox-w32-d1a84a2880073f6cc5e2f9f4e5f236cd110f01a0.tar.gz busybox-w32-d1a84a2880073f6cc5e2f9f4e5f236cd110f01a0.tar.bz2 busybox-w32-d1a84a2880073f6cc5e2f9f4e5f236cd110f01a0.zip |
libbb: move crypt_make_salt() to pw_encrypt.c, reuse
bin-to-ascii64 conversion which does not require an array.
function old new delta
to64 29 33 +4
to64_msb_first 63 62 -1
ascii64 65 - -65
-rw-r--r-- | libbb/Kbuild | 6 | ||||
-rw-r--r-- | libbb/crypt_make_salt.c | 46 | ||||
-rw-r--r-- | libbb/pw_encrypt.c | 55 | ||||
-rw-r--r-- | libbb/pw_encrypt_des.c | 8 |
4 files changed, 56 insertions, 59 deletions
diff --git a/libbb/Kbuild b/libbb/Kbuild index b82f03c56..2c8830f99 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild | |||
@@ -120,9 +120,9 @@ lib-y += xrealloc_vector.o | |||
120 | lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o | 120 | lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o |
121 | lib-$(CONFIG_LOSETUP) += loop.o | 121 | lib-$(CONFIG_LOSETUP) += loop.o |
122 | lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o | 122 | lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o |
123 | lib-$(CONFIG_PASSWD) += pw_encrypt.o crypt_make_salt.o update_passwd.o | 123 | lib-$(CONFIG_PASSWD) += pw_encrypt.o update_passwd.o |
124 | lib-$(CONFIG_CHPASSWD) += pw_encrypt.o crypt_make_salt.o update_passwd.o | 124 | lib-$(CONFIG_CHPASSWD) += pw_encrypt.o update_passwd.o |
125 | lib-$(CONFIG_CRYPTPW) += pw_encrypt.o crypt_make_salt.o | 125 | lib-$(CONFIG_CRYPTPW) += pw_encrypt.o |
126 | lib-$(CONFIG_SULOGIN) += pw_encrypt.o | 126 | lib-$(CONFIG_SULOGIN) += pw_encrypt.o |
127 | lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o | 127 | lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o |
128 | lib-$(CONFIG_VLOCK) += pw_encrypt.o correct_password.o | 128 | lib-$(CONFIG_VLOCK) += pw_encrypt.o correct_password.o |
diff --git a/libbb/crypt_make_salt.c b/libbb/crypt_make_salt.c deleted file mode 100644 index 14bb0ddc9..000000000 --- a/libbb/crypt_make_salt.c +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * crypt_make_salt | ||
4 | * | ||
5 | * i64c was also put here, this is the only function that uses it. | ||
6 | * | ||
7 | * Lifted from loginutils/passwd.c by Thomas Lundquist <thomasez@zelow.no> | ||
8 | * | ||
9 | * Licensed under GPLv2, see file LICENSE in this tarball for details. | ||
10 | */ | ||
11 | |||
12 | #include "libbb.h" | ||
13 | |||
14 | static int i64c(int i) | ||
15 | { | ||
16 | i &= 0x3f; | ||
17 | if (i == 0) | ||
18 | return '.'; | ||
19 | if (i == 1) | ||
20 | return '/'; | ||
21 | if (i < 12) | ||
22 | return ('0' - 2 + i); | ||
23 | if (i < 38) | ||
24 | return ('A' - 12 + i); | ||
25 | return ('a' - 38 + i); | ||
26 | } | ||
27 | |||
28 | int FAST_FUNC crypt_make_salt(char *p, int cnt, int x) | ||
29 | { | ||
30 | x += getpid() + time(NULL); | ||
31 | do { | ||
32 | /* x = (x*1664525 + 1013904223) % 2^32 generator is lame | ||
33 | * (low-order bit is not "random", etc...), | ||
34 | * but for our purposes it is good enough */ | ||
35 | x = x*1664525 + 1013904223; | ||
36 | /* BTW, Park and Miller's "minimal standard generator" is | ||
37 | * x = x*16807 % ((2^31)-1) | ||
38 | * It has no problem with visibly alternating lowest bit | ||
39 | * but is also weak in cryptographic sense + needs div, | ||
40 | * which needs more code (and slower) on many CPUs */ | ||
41 | *p++ = i64c(x >> 16); | ||
42 | *p++ = i64c(x >> 22); | ||
43 | } while (--cnt); | ||
44 | *p = '\0'; | ||
45 | return x; | ||
46 | } | ||
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c index 572591ea9..6fc0ba87c 100644 --- a/libbb/pw_encrypt.c +++ b/libbb/pw_encrypt.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Utility routine. | 3 | * Utility routines. |
4 | * | 4 | * |
5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
6 | * | 6 | * |
@@ -9,25 +9,62 @@ | |||
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | #if ENABLE_USE_BB_CRYPT | 12 | /* static const uint8_t ascii64[] = |
13 | 13 | * "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | |
14 | /* | ||
15 | * DES and MD5 crypt implementations are taken from uclibc. | ||
16 | * They were modified to not use static buffers. | ||
17 | */ | 14 | */ |
18 | 15 | ||
19 | /* Used by pw_encrypt_XXX.c */ | 16 | static int i64c(int i) |
20 | static const uint8_t ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | 17 | { |
18 | i &= 0x3f; | ||
19 | if (i == 0) | ||
20 | return '.'; | ||
21 | if (i == 1) | ||
22 | return '/'; | ||
23 | if (i < 12) | ||
24 | return ('0' - 2 + i); | ||
25 | if (i < 38) | ||
26 | return ('A' - 12 + i); | ||
27 | return ('a' - 38 + i); | ||
28 | } | ||
29 | |||
30 | int FAST_FUNC crypt_make_salt(char *p, int cnt, int x) | ||
31 | { | ||
32 | x += getpid() + time(NULL); | ||
33 | do { | ||
34 | /* x = (x*1664525 + 1013904223) % 2^32 generator is lame | ||
35 | * (low-order bit is not "random", etc...), | ||
36 | * but for our purposes it is good enough */ | ||
37 | x = x*1664525 + 1013904223; | ||
38 | /* BTW, Park and Miller's "minimal standard generator" is | ||
39 | * x = x*16807 % ((2^31)-1) | ||
40 | * It has no problem with visibly alternating lowest bit | ||
41 | * but is also weak in cryptographic sense + needs div, | ||
42 | * which needs more code (and slower) on many CPUs */ | ||
43 | *p++ = i64c(x >> 16); | ||
44 | *p++ = i64c(x >> 22); | ||
45 | } while (--cnt); | ||
46 | *p = '\0'; | ||
47 | return x; | ||
48 | } | ||
49 | |||
50 | #if ENABLE_USE_BB_CRYPT | ||
51 | |||
21 | static char* | 52 | static char* |
22 | to64(char *s, unsigned v, int n) | 53 | to64(char *s, unsigned v, int n) |
23 | { | 54 | { |
24 | while (--n >= 0) { | 55 | while (--n >= 0) { |
25 | *s++ = ascii64[v & 0x3f]; | 56 | /* *s++ = ascii64[v & 0x3f]; */ |
57 | *s++ = i64c(v); | ||
26 | v >>= 6; | 58 | v >>= 6; |
27 | } | 59 | } |
28 | return s; | 60 | return s; |
29 | } | 61 | } |
30 | 62 | ||
63 | /* | ||
64 | * DES and MD5 crypt implementations are taken from uclibc. | ||
65 | * They were modified to not use static buffers. | ||
66 | */ | ||
67 | |||
31 | #include "pw_encrypt_des.c" | 68 | #include "pw_encrypt_des.c" |
32 | #include "pw_encrypt_md5.c" | 69 | #include "pw_encrypt_md5.c" |
33 | #if ENABLE_USE_BB_CRYPT_SHA | 70 | #if ENABLE_USE_BB_CRYPT_SHA |
diff --git a/libbb/pw_encrypt_des.c b/libbb/pw_encrypt_des.c index 4e506f498..52548d623 100644 --- a/libbb/pw_encrypt_des.c +++ b/libbb/pw_encrypt_des.c | |||
@@ -699,10 +699,16 @@ do_des(struct des_ctx *ctx, /*uint32_t l_in, uint32_t r_in,*/ uint32_t *l_out, u | |||
699 | static void | 699 | static void |
700 | to64_msb_first(char *s, unsigned v) | 700 | to64_msb_first(char *s, unsigned v) |
701 | { | 701 | { |
702 | #if 0 | ||
702 | *s++ = ascii64[(v >> 18) & 0x3f]; /* bits 23..18 */ | 703 | *s++ = ascii64[(v >> 18) & 0x3f]; /* bits 23..18 */ |
703 | *s++ = ascii64[(v >> 12) & 0x3f]; /* bits 17..12 */ | 704 | *s++ = ascii64[(v >> 12) & 0x3f]; /* bits 17..12 */ |
704 | *s++ = ascii64[(v >> 6) & 0x3f]; /* bits 11..6 */ | 705 | *s++ = ascii64[(v >> 6) & 0x3f]; /* bits 11..6 */ |
705 | *s = ascii64[v & 0x3f]; /* bits 5..0 */ | 706 | *s = ascii64[v & 0x3f]; /* bits 5..0 */ |
707 | #endif | ||
708 | *s++ = i64c(v >> 18); /* bits 23..18 */ | ||
709 | *s++ = i64c(v >> 12); /* bits 17..12 */ | ||
710 | *s++ = i64c(v >> 6); /* bits 11..6 */ | ||
711 | *s = i64c(v); /* bits 5..0 */ | ||
706 | } | 712 | } |
707 | 713 | ||
708 | static char * | 714 | static char * |