Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix valgrind warnings on NTLM setup_schedule()
We were reading the byte off the end of the hash, only to shift it right
by seven and retain a single bit of it... which we then negated when we
calculated the parity.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jun 23, 2014
1 parent 1cdefb0 commit 4bc1536
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ntlm.c
Expand Up @@ -616,8 +616,8 @@ static void deskey (DES_KS k, unsigned char *key, int decrypt)
}
}

#define KEYBITS(k,s) \
(((k[(s) / 8] << ((s) % 8)) & 0xFF) | (k[(s) / 8 + 1] >> (8 - (s) % 8)))
#define HIKEYBITS(k,s) ((k[(s) / 8] << ((s) % 8)) & 0xFF)
#define LOKEYBITS(k,s) (k[(s) / 8 + 1] >> (8 - (s) % 8))

/* DES utils */
/* Set up a key schedule based on a 56bit key */
Expand All @@ -627,7 +627,12 @@ static void setup_schedule (const unsigned char *key_56, DES_KS ks)
int i, c, bit;

for (i = 0; i < 8; i++) {
key[i] = KEYBITS (key_56, i * 7);
key[i] = HIKEYBITS (key_56, i * 7);
/* Mask in the low bits only if they're used. It doesn't
* matter if we get an unwanted bit 0; it's going to be
* overwritten with parity anyway. */
if (i && i < 7)
key[i] |= LOKEYBITS(key_56, i * 7);

/* Fix parity */
for (c = bit = 0; bit < 8; bit++)
Expand Down

0 comments on commit 4bc1536

Please sign in to comment.