[PATCH] use 36 byte buffer in md5 instead of 120, shrink code

Denys Vlasenko vda.linux at googlemail.com
Fri Jun 13 15:45:03 UTC 2008


md5 crypt stores result in the form $1$xxx$yyyyyyyyy<NUL>

where xxx is salt (up to 8 chars) and yyy is hash
(22 chars). Using 120 bytes buffer for it is excessive.

The patch also replaces e.g. strcat(passwd,"$")
which writes $ between xxx and yyyy above with one-byte store,
which is shorter.

__md5_to64 is made to return advanced pointer, eliminating
the need to do it at call sites.

Size:

    text           data     bss     dec     hex filename
-   1905              0     120    2025     7e9 libcrypt/md5.o
+   1879              0      36    1915     77b libcrypt/md5.o

Run tested:
  TEST_EXEC crypt/ crypt
  TEST_DIFF crypt/ crypt.out crypt.out.good
  TEST_EXEC crypt/ md5c-test
  TEST_EXEC crypt/ crypt_glibc
  TEST_DIFF crypt/ crypt_glibc.out crypt.out.good
  TEST_EXEC crypt/ md5c-test_glibc

Please review.
--
vda



More information about the uClibc mailing list