From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/1100 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: FreeSec crypt() Date: Wed, 13 Jun 2012 08:10:32 +0200 Message-ID: <20120613061032.GH17860@port70.net> References: <20120612235113.GA21296@openwall.com> <20120613011842.GA163@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1339567849 4252 80.91.229.3 (13 Jun 2012 06:10:49 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 13 Jun 2012 06:10:49 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-1101-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jun 13 08:10:48 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Segmz-0008HD-BT for gllmg-musl@plane.gmane.org; Wed, 13 Jun 2012 08:10:45 +0200 Original-Received: (qmail 5189 invoked by uid 550); 13 Jun 2012 06:10:45 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 5180 invoked from network); 13 Jun 2012 06:10:45 -0000 Content-Disposition: inline In-Reply-To: <20120613011842.GA163@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:1100 Archived-At: * Rich Felker [2012-06-12 21:18:42 -0400]: > On Wed, Jun 13, 2012 at 03:51:13AM +0400, Solar Designer wrote: > > Rich - > > > > As discussed on IRC, here is a revision of the FreeSec crypt() code with > > Thanks. Here's a _really_ quick draft, untested, of the direction I > wanted to take it with making the tables static-initialized. Note that my comments: > #include > #include > > struct _crypt_extended_local { > u_int32_t saltbits; > u_int32_t en_keysl[16], en_keysr[16]; > }; > -#include +#include s/u_int32_t/uint32_t/g s/u_char/unsigned char/g > static inline int > ascii_to_bin(int ch) > { > int sch = ch>127 ? -(256-ch) : ch; > int retval; > > retval = sch - '.'; > if (sch >= 'A') { > retval = sch - ('A' - 12); > if (sch >= 'a') > retval = sch - ('a' - 38); > } > retval &= 0x3f; > > return retval; > } > s/inline// on [-128,255] the following code gives the same result: static int ascii_to_bin2(int c) { if (c >= 128) c += -128 + 18; else if (c >= 97) c += -97 + 38; else if (c >= 65) c += -65 + 12; else c += 128 + 18; return (unsigned)c % 64; } > char * > _crypt_extended_r(const char *key, const char *setting, char *output) > { ... > while (q - (u_char *) keybuf < sizeof(keybuf)) { > *q++ = *key << 1; implementation-defined signed shift > for (i = 1, count = 0; i < 5; i++) { > int value = ascii_to_bin(setting[i]); > if (ascii64[value] != setting[i]) > return NULL; > count |= value << (i - 1) * 6; > } signed shift (harmless) > while (q - (u_char *) keybuf < sizeof(keybuf) && *key) > *q++ ^= *key++ << 1; signed shift