Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 13 Jun 2012 08:10:32 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: FreeSec crypt()

* Rich Felker <dalias@...ifal.cx> [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 <sys/types.h>
> #include <string.h>
> 
> struct _crypt_extended_local {
> 	u_int32_t saltbits;
> 	u_int32_t en_keysl[16], en_keysr[16];
> };
> 

-#include <sys/types.h>
+#include <stdint.h>

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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.