Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 7 Jan 2012 02:46:06 +0400
From: Solar Designer <solar@...nwall.com>
To: john-dev@...ts.openwall.com
Subject: Re: Bit slice implementation of DES based hashes

On Fri, Jan 06, 2012 at 05:51:20PM +0530, Piyush Mittal wrote:
> Extremely sorry to say but I am not getting how initial permutation is
> calculated? What I am doing is as follows:
...
> i.e 0000000011101000000000010010011100010111000001001100001010101111
> 
> but I am not getting the same sequence. What am I missing ?

The attached program prints the bit sequence above.  There are two
peculiarities: the initial block octets (represented by ASCII characters
in your case) were in big-endian bit order, and additionally the two
32-bit block halves need to be swapped.  The former is a property of DES
(or rather of its specs), whereas the latter I don't recall the origin of.

You might want to note that DES_raw_get_binary() does both of these
swaps, too: the former (bit endianness) by having mask go from 0x20 to 1
(and not the other way around) for the 6-bit values being decoded, and
the latter in DES_do_IP() (by XOR'ing the dst bit number with 0x20).

Alexander

#include <stdio.h>

static unsigned char DES_IP[64] = {
	57, 49, 41, 33, 25, 17, 9, 1,
	59, 51, 43, 35, 27, 19, 11, 3,
	61, 53, 45, 37, 29, 21, 13, 5,
	63, 55, 47, 39, 31, 23, 15, 7,
	56, 48, 40, 32, 24, 16, 8, 0,
	58, 50, 42, 34, 26, 18, 10, 2,
	60, 52, 44, 36, 28, 20, 12, 4,
	62, 54, 46, 38, 30, 22, 14, 6
};

static unsigned char *block = "KGS!@...";

int main(void)
{
	int dst;

	for (dst = 0; dst < 64; dst++) {
		int src = DES_IP[dst ^ 0x20];
		printf("%u",
		    (unsigned int)(block[src >> 3] >> (7 - (src & 7))) & 1);
	}
	putchar('\n');

	return 0;
}

Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ