From b5a5236f207867d52acb8573d69c92a7691b2d3f Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Fri, 19 Mar 1999 15:09:25 +0000 Subject: Implemented encryption algorithm used for a number of RPC buffers. (actually, decryption only currently because I need to get some sleep). Basically another Microsoft twist on DES; the "master key" is the user's NT hash MD4'd and subsets of this are chosen as the 56-bit DES keys. (This used to be commit f09388fa6f41a13ca035b5b2ff40be804608f619) --- source3/libsmb/smbencrypt.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'source3/libsmb/smbencrypt.c') diff --git a/source3/libsmb/smbencrypt.c b/source3/libsmb/smbencrypt.c index e35cccd734..3835c99815 100644 --- a/source3/libsmb/smbencrypt.c +++ b/source3/libsmb/smbencrypt.c @@ -226,3 +226,48 @@ BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[ return True; } +int nt_decrypt_string2(STRING2 *out, STRING2 *in, char nt_hash[16]) +{ + uchar bufhdr[8]; + int datalen; + + uchar key[16]; + uchar *keyptr = key; + uchar *keyend = key + sizeof(key); + + uchar *outbuf = (uchar *)out->buffer; + uchar *inbuf = (uchar *)in->buffer; + uchar *inbufend; + + + mdfour(key, nt_hash, 16); + + smbhash(bufhdr, inbuf, keyptr, 0); + datalen = IVAL(bufhdr, 0); + + if ((datalen > in->str_str_len) || (datalen > MAX_STRINGLEN)) + { + DEBUG(0, ("nt_decrypt_string2: failed\n")); + return False; + } + + out->str_max_len = out->str_str_len = datalen; + inbuf += 8; + inbufend = inbuf + datalen; + + while (inbuf < inbufend) + { + keyptr += 7; + if (keyptr + 7 > keyend) + { + keyptr = (keyend - keyptr) + key; + } + + smbhash(outbuf, inbuf, keyptr, 0); + + inbuf += 8; + outbuf += 8; + } + + return True; +} -- cgit