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

Denys Vlasenko vda.linux at googlemail.com
Fri Jun 13 20:09:15 UTC 2008


On Friday 13 June 2008 19:30, Peter Kjellerstedt wrote:
> > -----Original Message-----
> > From: uclibc-bounces at uclibc.org [mailto:uclibc-bounces at uclibc.org] On
> > Behalf Of Denys Vlasenko
> > Sent: den 13 juni 2008 17:46
> > To: uclibc at uclibc.org
> > Subject: Re: [PATCH] use 36 byte buffer in md5 instead of 120, shrink
> > code
> >
> > On Friday 13 June 2008 17:45, Denys Vlasenko wrote:
> > > 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.
> >
> > Now even with patch actually attached.
> > --
> > vda
> 
> You changed the type of the second argument to __md5_to64() from
> unsigned long to unsigned, but in __md5_crypt() you are still
> passing it l (stupid variable name) which is unsigned long.

Good eyes, I didn't think about chasing that variable's type.
It didn't materially affect generated code, but being consistent
is better.

Anyway, unsigned long->unsigned was intended. unsigned long can be
64 bit wide, we don't need that. 32 bits is enough here (24 actually).

In this patch, I fix it, and also move "unsigned l" into
much smaller scope. Helps next reader/editor to see it.
--
vda


-------------- next part --------------
A non-text attachment was scrubbed...
Name: a.patch
Type: text/x-diff
Size: 2306 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/uclibc/attachments/20080613/810e7a2c/attachment.bin 


More information about the uClibc mailing list