svn commit: trunk/busybox: libbb loginutils
vda at busybox.net
vda at busybox.net
Tue May 8 16:23:35 PDT 2007
Author: vda
Date: 2007-05-08 16:23:35 -0700 (Tue, 08 May 2007)
New Revision: 18588
Log:
cryptpw: forgot svn add... how typical of me :(
Added:
trunk/busybox/libbb/crypt_make_salt.c
trunk/busybox/loginutils/cryptpw.c
Modified:
trunk/busybox/libbb/Kbuild
Changeset:
Modified: trunk/busybox/libbb/Kbuild
===================================================================
--- trunk/busybox/libbb/Kbuild 2007-05-08 23:12:21 UTC (rev 18587)
+++ trunk/busybox/libbb/Kbuild 2007-05-08 23:23:35 UTC (rev 18588)
@@ -21,7 +21,6 @@
lib-y += crc32.o
lib-y += create_icmp6_socket.o
lib-y += create_icmp_socket.o
-lib-y += crypt_make_salt.o
lib-y += default_error_retval.o
lib-y += device_open.o
lib-y += dump.o
@@ -103,10 +102,8 @@
lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o
lib-$(CONFIG_LOSETUP) += loop.o
lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o
-lib-$(CONFIG_PASSWD) += pw_encrypt.o
-lib-$(CONFIG_PASSWD) += crypt_make_salt.o
-lib-$(CONFIG_CRYPTPW) += pw_encrypt.o
-lib-$(CONFIG_CRYPTPW) += crypt_make_salt.o
+lib-$(CONFIG_PASSWD) += pw_encrypt.o crypt_make_salt.o
+lib-$(CONFIG_CRYPTPW) += pw_encrypt.o crypt_make_salt.o
lib-$(CONFIG_SULOGIN) += pw_encrypt.o
lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o
lib-$(CONFIG_VLOCK) += correct_password.o
Added: trunk/busybox/libbb/crypt_make_salt.c
===================================================================
--- trunk/busybox/libbb/crypt_make_salt.c (rev 0)
+++ trunk/busybox/libbb/crypt_make_salt.c 2007-05-08 23:23:35 UTC (rev 18588)
@@ -0,0 +1,48 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * crypt_make_salt
+ *
+ * i64c was also put here, this is the only function that uses it.
+ *
+ * Lifted from loginutils/passwd.c by Thomas Lundquist <thomasez at zelow.no>
+ *
+ */
+
+#include "libbb.h"
+
+static int i64c(int i)
+{
+ i &= 0x3f;
+ if (i == 0)
+ return '.';
+ if (i == 1)
+ return '/';
+ if (i < 12)
+ return ('0' - 2 + i);
+ if (i < 38)
+ return ('A' - 12 + i);
+ return ('a' - 38 + i);
+}
+
+
+void crypt_make_salt(char *p, int cnt)
+{
+ unsigned x = x; /* it's pointless to initialize it anyway :) */
+
+ x += getpid() + time(NULL) + clock();
+ do {
+ /* x = (x*1664525 + 1013904223) % 2^32 generator is lame
+ * (low-order bit is not "random", etc...),
+ * but for our purposes it is good enough */
+ x = x*1664525 + 1013904223;
+ /* BTW, Park and Miller's "minimal standard generator" is
+ * x = x*16807 % ((2^31)-1)
+ * It has no problem with visibly alternating lowest bit
+ * but is also weak in cryptographic sense + needs div,
+ * which needs more code (and slower) on many CPUs */
+ *p++ = i64c(x >> 16);
+ *p++ = i64c(x >> 22);
+ } while (--cnt);
+ *p = '\0';
+}
+
Added: trunk/busybox/loginutils/cryptpw.c
===================================================================
--- trunk/busybox/loginutils/cryptpw.c (rev 0)
+++ trunk/busybox/loginutils/cryptpw.c 2007-05-08 23:23:35 UTC (rev 18588)
@@ -0,0 +1,37 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * cryptpw.c
+ *
+ * Cooked from passwd.c by Thomas Lundquist <thomasez at zelow.no>
+ *
+ */
+
+#include "busybox.h"
+
+int cryptpw_main(int argc, char **argv);
+int cryptpw_main(int argc, char **argv)
+{
+ char *clear;
+ char salt[sizeof("$N$XXXXXXXX")]; /* "$N$XXXXXXXX" or "XX" */
+ const char *opt_a = "md5";
+
+ getopt32(argc, argv, "a:", &opt_a);
+ /* move past the commandline options */
+ /*argc -= optind; - unused */
+ argv += optind;
+
+ crypt_make_salt(salt, 1); /* des */
+ if (strcasecmp(opt_a, "md5") == 0) {
+ strcpy(salt, "$1$");
+ crypt_make_salt(salt + 3, 4);
+ } else if (strcasecmp(opt_a, "des") != 0) {
+ bb_show_usage();
+ }
+
+ clear = argv[0];
+ if (!clear)
+ clear = xmalloc_getline(stdin);
+
+ puts(pw_encrypt(clear, salt));
+ return 0;
+}
More information about the busybox-cvs
mailing list