Merged encode_pw_buffer() and nt_owf_genW() functions from TNG branch.
authorTim Potter <tpot@samba.org>
Fri, 15 Jun 2001 04:47:05 +0000 (04:47 +0000)
committerTim Potter <tpot@samba.org>
Fri, 15 Jun 2001 04:47:05 +0000 (04:47 +0000)
(This used to be commit fb80cf2aa13883c6dac461f95bc1000c4881d724)

source3/libsmb/smbencrypt.c

index caf9256787928cf9febdbdeaf79a7ecf2c52bea1..68af1b4941bf3f0ab5f9bad9ae4b0b0b062590ab 100644 (file)
@@ -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);
+}