aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-05-08 23:23:35 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-05-08 23:23:35 +0000
commit0cf26b79dde109a2a6d76c08e79524a9a507677e (patch)
tree089381ac1517da548d262ed60a7b12a742c9ee51
parent9896d7ce326e39553e958782f067418811a5d08e (diff)
downloadbusybox-w32-0cf26b79dde109a2a6d76c08e79524a9a507677e.tar.gz
busybox-w32-0cf26b79dde109a2a6d76c08e79524a9a507677e.tar.bz2
busybox-w32-0cf26b79dde109a2a6d76c08e79524a9a507677e.zip
cryptpw: forgot svn add... how typical of me :(
git-svn-id: svn://busybox.net/trunk/busybox@18588 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--libbb/Kbuild7
-rw-r--r--libbb/crypt_make_salt.c48
-rw-r--r--loginutils/cryptpw.c37
3 files changed, 87 insertions, 5 deletions
diff --git a/libbb/Kbuild b/libbb/Kbuild
index eeca7d536..5cc8d1428 100644
--- a/libbb/Kbuild
+++ b/libbb/Kbuild
@@ -21,7 +21,6 @@ lib-y += copyfd.o
21lib-y += crc32.o 21lib-y += crc32.o
22lib-y += create_icmp6_socket.o 22lib-y += create_icmp6_socket.o
23lib-y += create_icmp_socket.o 23lib-y += create_icmp_socket.o
24lib-y += crypt_make_salt.o
25lib-y += default_error_retval.o 24lib-y += default_error_retval.o
26lib-y += device_open.o 25lib-y += device_open.o
27lib-y += dump.o 26lib-y += dump.o
@@ -103,10 +102,8 @@ lib-y += xreadlink.o
103lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o 102lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o
104lib-$(CONFIG_LOSETUP) += loop.o 103lib-$(CONFIG_LOSETUP) += loop.o
105lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o 104lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o
106lib-$(CONFIG_PASSWD) += pw_encrypt.o 105lib-$(CONFIG_PASSWD) += pw_encrypt.o crypt_make_salt.o
107lib-$(CONFIG_PASSWD) += crypt_make_salt.o 106lib-$(CONFIG_CRYPTPW) += pw_encrypt.o crypt_make_salt.o
108lib-$(CONFIG_CRYPTPW) += pw_encrypt.o
109lib-$(CONFIG_CRYPTPW) += crypt_make_salt.o
110lib-$(CONFIG_SULOGIN) += pw_encrypt.o 107lib-$(CONFIG_SULOGIN) += pw_encrypt.o
111lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o 108lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o
112lib-$(CONFIG_VLOCK) += correct_password.o 109lib-$(CONFIG_VLOCK) += correct_password.o
diff --git a/libbb/crypt_make_salt.c b/libbb/crypt_make_salt.c
new file mode 100644
index 000000000..12e96328f
--- /dev/null
+++ b/libbb/crypt_make_salt.c
@@ -0,0 +1,48 @@
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 */
10
11#include "libbb.h"
12
13static int i64c(int i)
14{
15 i &= 0x3f;
16 if (i == 0)
17 return '.';
18 if (i == 1)
19 return '/';
20 if (i < 12)
21 return ('0' - 2 + i);
22 if (i < 38)
23 return ('A' - 12 + i);
24 return ('a' - 38 + i);
25}
26
27
28void crypt_make_salt(char *p, int cnt)
29{
30 unsigned x = x; /* it's pointless to initialize it anyway :) */
31
32 x += getpid() + time(NULL) + clock();
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}
48
diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c
new file mode 100644
index 000000000..d4bcad3e0
--- /dev/null
+++ b/loginutils/cryptpw.c
@@ -0,0 +1,37 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * cryptpw.c
4 *
5 * Cooked from passwd.c by Thomas Lundquist <thomasez@zelow.no>
6 *
7 */
8
9#include "busybox.h"
10
11int cryptpw_main(int argc, char **argv);
12int cryptpw_main(int argc, char **argv)
13{
14 char *clear;
15 char salt[sizeof("$N$XXXXXXXX")]; /* "$N$XXXXXXXX" or "XX" */
16 const char *opt_a = "md5";
17
18 getopt32(argc, argv, "a:", &opt_a);
19 /* move past the commandline options */
20 /*argc -= optind; - unused */
21 argv += optind;
22
23 crypt_make_salt(salt, 1); /* des */
24 if (strcasecmp(opt_a, "md5") == 0) {
25 strcpy(salt, "$1$");
26 crypt_make_salt(salt + 3, 4);
27 } else if (strcasecmp(opt_a, "des") != 0) {
28 bb_show_usage();
29 }
30
31 clear = argv[0];
32 if (!clear)
33 clear = xmalloc_getline(stdin);
34
35 puts(pw_encrypt(clear, salt));
36 return 0;
37}