svn commit: trunk/busybox/libbb

vda at busybox.net vda at busybox.net
Sun Dec 7 01:16:34 UTC 2008


Author: vda
Date: 2008-12-06 17:16:34 -0800 (Sat, 06 Dec 2008)
New Revision: 24299

Log:
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



Removed:
   trunk/busybox/libbb/crypt_make_salt.c

Modified:
   trunk/busybox/libbb/Kbuild
   trunk/busybox/libbb/pw_encrypt.c
   trunk/busybox/libbb/pw_encrypt_des.c


Changeset:
Modified: trunk/busybox/libbb/Kbuild
===================================================================
--- trunk/busybox/libbb/Kbuild	2008-12-07 00:52:58 UTC (rev 24298)
+++ trunk/busybox/libbb/Kbuild	2008-12-07 01:16:34 UTC (rev 24299)
@@ -120,9 +120,9 @@
 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 crypt_make_salt.o update_passwd.o
-lib-$(CONFIG_CHPASSWD) += pw_encrypt.o crypt_make_salt.o update_passwd.o
-lib-$(CONFIG_CRYPTPW) += pw_encrypt.o crypt_make_salt.o
+lib-$(CONFIG_PASSWD) += pw_encrypt.o update_passwd.o
+lib-$(CONFIG_CHPASSWD) += pw_encrypt.o update_passwd.o
+lib-$(CONFIG_CRYPTPW) += pw_encrypt.o
 lib-$(CONFIG_SULOGIN) += pw_encrypt.o
 lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o
 lib-$(CONFIG_VLOCK) += pw_encrypt.o correct_password.o

Deleted: trunk/busybox/libbb/crypt_make_salt.c
===================================================================
--- trunk/busybox/libbb/crypt_make_salt.c	2008-12-07 00:52:58 UTC (rev 24298)
+++ trunk/busybox/libbb/crypt_make_salt.c	2008-12-07 01:16:34 UTC (rev 24299)
@@ -1,46 +0,0 @@
-/* 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>
- *
- * Licensed under GPLv2, see file LICENSE in this tarball for details.
- */
-
-#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);
-}
-
-int FAST_FUNC crypt_make_salt(char *p, int cnt, int x)
-{
-	x += getpid() + time(NULL);
-	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';
-	return x;
-}

Modified: trunk/busybox/libbb/pw_encrypt.c
===================================================================
--- trunk/busybox/libbb/pw_encrypt.c	2008-12-07 00:52:58 UTC (rev 24298)
+++ trunk/busybox/libbb/pw_encrypt.c	2008-12-07 01:16:34 UTC (rev 24299)
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * Utility routine.
+ * Utility routines.
  *
  * Copyright (C) 1999-2004 by Erik Andersen <andersen at codepoet.org>
  *
@@ -9,25 +9,62 @@
 
 #include "libbb.h"
 
+/* static const uint8_t ascii64[] =
+ * "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ */
+
+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);
+}
+
+int FAST_FUNC crypt_make_salt(char *p, int cnt, int x)
+{
+	x += getpid() + time(NULL);
+	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';
+	return x;
+}
+
 #if ENABLE_USE_BB_CRYPT
 
-/*
- * DES and MD5 crypt implementations are taken from uclibc.
- * They were modified to not use static buffers.
- */
-
-/* Used by pw_encrypt_XXX.c */
-static const uint8_t ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 static char*
 to64(char *s, unsigned v, int n)
 {
 	while (--n >= 0) {
-		*s++ = ascii64[v & 0x3f];
+		/* *s++ = ascii64[v & 0x3f]; */
+		*s++ = i64c(v);
 		v >>= 6;
 	}
 	return s;
 }
 
+/*
+ * DES and MD5 crypt implementations are taken from uclibc.
+ * They were modified to not use static buffers.
+ */
+
 #include "pw_encrypt_des.c"
 #include "pw_encrypt_md5.c"
 #if ENABLE_USE_BB_CRYPT_SHA

Modified: trunk/busybox/libbb/pw_encrypt_des.c
===================================================================
--- trunk/busybox/libbb/pw_encrypt_des.c	2008-12-07 00:52:58 UTC (rev 24298)
+++ trunk/busybox/libbb/pw_encrypt_des.c	2008-12-07 01:16:34 UTC (rev 24299)
@@ -699,10 +699,16 @@
 static void
 to64_msb_first(char *s, unsigned v)
 {
+#if 0
 	*s++ = ascii64[(v >> 18) & 0x3f]; /* bits 23..18 */
 	*s++ = ascii64[(v >> 12) & 0x3f]; /* bits 17..12 */
 	*s++ = ascii64[(v >> 6) & 0x3f]; /* bits 11..6 */
-	*s = ascii64[v & 0x3f]; /* bits 5..0 */
+	*s   = ascii64[v & 0x3f]; /* bits 5..0 */
+#endif
+	*s++ = i64c(v >> 18); /* bits 23..18 */
+	*s++ = i64c(v >> 12); /* bits 17..12 */
+	*s++ = i64c(v >> 6); /* bits 11..6 */
+	*s   = i64c(v); /* bits 5..0 */
 }
 
 static char *




More information about the busybox-cvs mailing list