svn commit: trunk/busybox/libbb

vda at busybox.net vda at busybox.net
Thu Dec 4 15:29:36 UTC 2008


Author: vda
Date: 2008-12-04 07:29:35 -0800 (Thu, 04 Dec 2008)
New Revision: 24267

Log:
libbb/crypt: code shrink

function                                             old     new   delta
to64_msb_first                                         -      63     +63
des_crypt                                           1509    1338    -171
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 63/-171)          Total: -108 bytes



Modified:
   trunk/busybox/libbb/pw_encrypt_des.c
   trunk/busybox/libbb/pw_encrypt_md5.c


Changeset:
Modified: trunk/busybox/libbb/pw_encrypt_des.c
===================================================================
--- trunk/busybox/libbb/pw_encrypt_des.c	2008-12-04 14:30:50 UTC (rev 24266)
+++ trunk/busybox/libbb/pw_encrypt_des.c	2008-12-04 15:29:35 UTC (rev 24267)
@@ -696,13 +696,22 @@
 
 #define DES_OUT_BUFSIZE 21
 
+static void
+to64_msb_first(char *s, unsigned v)
+{
+	*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 */
+}
+
 static char *
 NOINLINE
 des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE],
 		const unsigned char *key, const unsigned char *setting)
 {
-	uint32_t salt, l, r0, r1, keybuf[2];
-	uint8_t *p, *q;
+	uint32_t salt, r0, r1, keybuf[2];
+	uint8_t *q;
 
 	/*
 	 * Copy the key, shifting each character up by one bit
@@ -733,34 +742,39 @@
 	 */
 	output[1] = setting[1] ? setting[1] : output[0];
 
-	p = (uint8_t *)output + 2;
-
 	setup_salt(ctx, salt);
-	/*
-	 * Do it.
-	 */
+	/* Do it. */
 	do_des(ctx, /*0, 0,*/ &r0, &r1, 25 /* count */);
 
-	/*
-	 * Now encode the result...
-	 */
-	l = (r0 >> 8);
-	*p++ = ascii64[(l >> 18) & 0x3f];
-	*p++ = ascii64[(l >> 12) & 0x3f];
-	*p++ = ascii64[(l >> 6) & 0x3f];
-	*p++ = ascii64[l & 0x3f];
-
+	/* Now encode the result. */
+#if 0
+{
+	uint32_t l = (r0 >> 8);
+	q = (uint8_t *)output + 2;
+	*q++ = ascii64[(l >> 18) & 0x3f]; /* bits 31..26 of r0 */
+	*q++ = ascii64[(l >> 12) & 0x3f]; /* bits 25..20 of r0 */
+	*q++ = ascii64[(l >> 6) & 0x3f]; /* bits 19..14 of r0 */
+	*q++ = ascii64[l & 0x3f]; /* bits 13..8 of r0 */
 	l = ((r0 << 16) | (r1 >> 16));
-	*p++ = ascii64[(l >> 18) & 0x3f];
-	*p++ = ascii64[(l >> 12) & 0x3f];
-	*p++ = ascii64[(l >> 6) & 0x3f];
-	*p++ = ascii64[l & 0x3f];
-
+	*q++ = ascii64[(l >> 18) & 0x3f]; /* bits 7..2 of r0 */
+	*q++ = ascii64[(l >> 12) & 0x3f]; /* bits 1..2 of r0 and 31..28 of r1 */
+	*q++ = ascii64[(l >> 6) & 0x3f]; /* bits 27..22 of r1 */
+	*q++ = ascii64[l & 0x3f]; /* bits 21..16 of r1 */
 	l = r1 << 2;
-	*p++ = ascii64[(l >> 12) & 0x3f];
-	*p++ = ascii64[(l >> 6) & 0x3f];
-	*p++ = ascii64[l & 0x3f];
-	*p = 0;
+	*q++ = ascii64[(l >> 12) & 0x3f]; /* bits 15..10 of r1 */
+	*q++ = ascii64[(l >> 6) & 0x3f]; /* bits 9..4 of r1 */
+	*q++ = ascii64[l & 0x3f]; /* bits 3..0 of r1 + 00 */
+	*q = 0;
+}
+#else
+	/* Each call takes low-order 24 bits and stores 4 chars */
+	/* bits 31..8 of r0 */
+	to64_msb_first(output + 2, (r0 >> 8));
+	/* bits 7..0 of r0 and 31..16 of r1 */
+	to64_msb_first(output + 6, (r0 << 16) | (r1 >> 16));
+	/* (bits 15..0 of r1 + 00) and NUL byte */
+	to64_msb_first(output + 10, (r1 << 8));
+#endif
 
 	return output;
 }

Modified: trunk/busybox/libbb/pw_encrypt_md5.c
===================================================================
--- trunk/busybox/libbb/pw_encrypt_md5.c	2008-12-04 14:30:50 UTC (rev 24266)
+++ trunk/busybox/libbb/pw_encrypt_md5.c	2008-12-04 15:29:35 UTC (rev 24267)
@@ -65,10 +65,6 @@
  * by Erik Andersen to remove reentrance stuff...
  */
 
-#define MD5_MAGIC_STR "$1$"
-#define MD5_MAGIC_LEN (sizeof(MD5_MAGIC_STR) - 1)
-static const unsigned char __md5__magic[] = MD5_MAGIC_STR;
-
 /*
  * UNIX password
  *
@@ -163,5 +159,3 @@
 
 	return result;
 }
-#undef MD5_MAGIC_STR
-#undef MD5_MAGIC_LEN




More information about the busybox-cvs mailing list