diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-12 16:55:59 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-12 16:55:59 +0000 |
commit | 4ea83bf562c44a6792e7c77e7d87cba91f86f763 (patch) | |
tree | 64dba9163b29724e282c1e94027001a11978e74b /libbb/pw_encrypt.c | |
parent | 9de462205542547694299e9fe2bc321088ab79aa (diff) | |
download | busybox-w32-4ea83bf562c44a6792e7c77e7d87cba91f86f763.tar.gz busybox-w32-4ea83bf562c44a6792e7c77e7d87cba91f86f763.tar.bz2 busybox-w32-4ea83bf562c44a6792e7c77e7d87cba91f86f763.zip |
uclibc insists on having 70k static buffer for crypt.
For bbox it's not acceptable. Roll our own des and md5 crypt
implementation. Against older uclibc:
text data bss dec hex filename
759945 604 6684 767233 bb501 busybox_old
759766 604 6684 767054 bb44e busybox_unstripped
so, we still save on code size.
Diffstat (limited to 'libbb/pw_encrypt.c')
-rw-r--r-- | libbb/pw_encrypt.c | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c index e9cf4e3b8..d439fc3b4 100644 --- a/libbb/pw_encrypt.c +++ b/libbb/pw_encrypt.c | |||
@@ -8,11 +8,52 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | #include <crypt.h> | ||
12 | 11 | ||
13 | char *pw_encrypt(const char *clear, const char *salt) | 12 | /* |
13 | * DES and MD5 crypt implementations are taken from uclibc. | ||
14 | * They were modified to not use static buffers. | ||
15 | * Comparison with uclibc (before uclibc had 70k staic buffers reinstated): | ||
16 | * text data bss dec hex filename | ||
17 | * 759909 604 6684 767197 bb4dd busybox_old | ||
18 | * 759579 604 6684 766867 bb393 busybox_unstripped | ||
19 | */ | ||
20 | /* Common for them */ | ||
21 | static const uint8_t ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
22 | #include "pw_encrypt_des.c" | ||
23 | #include "pw_encrypt_md5.c" | ||
24 | |||
25 | |||
26 | static struct const_des_ctx *des_cctx; | ||
27 | static struct des_ctx *des_ctx; | ||
28 | |||
29 | /* my_crypt returns malloc'ed data */ | ||
30 | static char *my_crypt(const char *key, const char *salt) | ||
31 | { | ||
32 | /* First, check if we are supposed to be using the MD5 replacement | ||
33 | * instead of DES... */ | ||
34 | if (salt[0] == '$' && salt[1] == '1' && salt[2] == '$') { | ||
35 | return md5_crypt(xzalloc(MD5_OUT_BUFSIZE), (unsigned char*)key, (unsigned char*)salt); | ||
36 | } | ||
37 | |||
38 | { | ||
39 | if (!des_cctx) | ||
40 | des_cctx = const_des_init(); | ||
41 | des_ctx = des_init(des_ctx, des_cctx); | ||
42 | return des_crypt(des_ctx, xzalloc(DES_OUT_BUFSIZE), (unsigned char*)key, (unsigned char*)salt); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | /* So far nobody wants to have it public */ | ||
47 | static void my_crypt_cleanup(void) | ||
48 | { | ||
49 | free(des_cctx); | ||
50 | free(des_ctx); | ||
51 | des_cctx = NULL; | ||
52 | des_ctx = NULL; | ||
53 | } | ||
54 | |||
55 | char *pw_encrypt(const char *clear, const char *salt, int cleanup) | ||
14 | { | 56 | { |
15 | /* Was static char[BIGNUM]. Malloced thing works as well */ | ||
16 | static char *cipher; | 57 | static char *cipher; |
17 | 58 | ||
18 | #if 0 /* was CONFIG_FEATURE_SHA1_PASSWORDS, but there is no such thing??? */ | 59 | #if 0 /* was CONFIG_FEATURE_SHA1_PASSWORDS, but there is no such thing??? */ |
@@ -22,6 +63,10 @@ char *pw_encrypt(const char *clear, const char *salt) | |||
22 | #endif | 63 | #endif |
23 | 64 | ||
24 | free(cipher); | 65 | free(cipher); |
25 | cipher = xstrdup(crypt(clear, salt)); | 66 | cipher = my_crypt(clear, salt); |
67 | |||
68 | if (cleanup) | ||
69 | my_crypt_cleanup(); | ||
70 | |||
26 | return cipher; | 71 | return cipher; |
27 | } | 72 | } |