1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

bug fix in the new des code.

I had one of the sbox[] constants wrong, which interestingly gave a
20% chance of the whole algorithm failing.
(This used to be commit 9a42f88a09)
This commit is contained in:
Andrew Tridgell 1997-09-16 03:53:54 +00:00
parent d6ed29012b
commit 72b02acd7e

View File

@ -85,7 +85,7 @@ static int sbox[8][4][16] = {
{{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7},
{0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8},
{4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0},
{15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 1}},
{15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}},
{{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10},
{3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5},
@ -122,7 +122,6 @@ static int sbox[8][4][16] = {
{7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8},
{2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}}};
static void permute(char *out, char *in, int *p, int n)
{
int i;
@ -230,6 +229,7 @@ static void dodes(char *out, char *in, char *key)
}
concat(rl, r, l, 32, 32);
permute(out, rl, perm6, 64);
}
@ -254,7 +254,7 @@ static void str_to_key(unsigned char *str,unsigned char *key)
/* this is the entry point to the DES routine. The key is 56 bits (no parity) */
void smbdes(unsigned char *out, unsigned char *in, unsigned char *key)
{
int i, j;
int i;
char outb[64];
char inb[64];
char keyb[64];
@ -268,23 +268,15 @@ void smbdes(unsigned char *out, unsigned char *in, unsigned char *key)
outb[i] = 0;
}
for (i=0;i<8;i++) {
int count = 0;
for (j=0;j<7;j++)
count += keyb[i*8 + j];
if ((count&1) == 0)
keyb[i*8 + 7] = 1;
else
keyb[i*8 + 7] = 0;
}
dodes(outb, inb, keyb);
for (i=0;i<8;i++) {
out[i] = 0;
}
for (i=0;i<64;i++) {
if (outb[i])
out[i/8] |= (1<<(7-(i%8)));
else
out[i/8] &= ~(1<<(7-(i%8)));
}
}