From 8888bf6582485433493e76139fa36e4d9f3be3a1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 15 Jun 2001 04:47:05 +0000 Subject: Merged encode_pw_buffer() and nt_owf_genW() functions from TNG branch. (This used to be commit fb80cf2aa13883c6dac461f95bc1000c4881d724) --- source3/libsmb/smbencrypt.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'source3/libsmb/smbencrypt.c') diff --git a/source3/libsmb/smbencrypt.c b/source3/libsmb/smbencrypt.c index caf9256787..68af1b4941 100644 --- a/source3/libsmb/smbencrypt.c +++ b/source3/libsmb/smbencrypt.c @@ -228,6 +228,39 @@ BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[ return True; } +/*********************************************************** + encode a password buffer +************************************************************/ +BOOL encode_pw_buffer(char buffer[516], const char *new_pass, + int new_pw_len, BOOL nt_pass_set) +{ + generate_random_buffer(buffer, 516, True); + + if (nt_pass_set) + { + /* + * nt passwords are in unicode. last char overwrites NULL + * in ascii_to_unibuf, so use SIVAL *afterwards*. + */ + new_pw_len *= 2; + ascii_to_unistr((uint16 *)&buffer[512 - new_pw_len], new_pass, + new_pw_len); + } + else + { + memcpy(&buffer[512 - new_pw_len], new_pass, new_pw_len); + } + + /* + * The length of the new password is in the last 4 bytes of + * the data buffer. + */ + + SIVAL(buffer, 512, new_pw_len); + + return True; +} + /*********************************************************** decode a password buffer ************************************************************/ @@ -319,3 +352,19 @@ BOOL decode_pw_buffer(char in_buffer[516], char *new_pwrd, } +/* Calculate the NT owfs of a user's password */ +void nt_owf_genW(const UNISTR2 *pwd, uchar nt_p16[16]) +{ + char buf[512]; + int i; + + for (i = 0; i < MIN(pwd->uni_str_len, sizeof(buf) / 2); i++) + { + SIVAL(buf, i * 2, pwd->buffer[i]); + } + /* Calculate the MD4 hash (NT compatible) of the password */ + mdfour(nt_p16, buf, pwd->uni_str_len * 2); + + /* clear out local copy of user's password (just being paranoid). */ + ZERO_STRUCT(buf); +} -- cgit