summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2001-06-15 04:47:05 +0000
committerTim Potter <tpot@samba.org>2001-06-15 04:47:05 +0000
commit8888bf6582485433493e76139fa36e4d9f3be3a1 (patch)
tree6c67db6a8bd1494c463f882e47825b056959a3bb /source3
parent1aa05a31ac9eb0987e641312195ed12c76476b27 (diff)
downloadsamba-8888bf6582485433493e76139fa36e4d9f3be3a1.tar.gz
samba-8888bf6582485433493e76139fa36e4d9f3be3a1.tar.bz2
samba-8888bf6582485433493e76139fa36e4d9f3be3a1.zip
Merged encode_pw_buffer() and nt_owf_genW() functions from TNG branch.
(This used to be commit fb80cf2aa13883c6dac461f95bc1000c4881d724)
Diffstat (limited to 'source3')
-rw-r--r--source3/libsmb/smbencrypt.c49
1 files changed, 49 insertions, 0 deletions
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
@@ -229,6 +229,39 @@ BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[
}
/***********************************************************
+ 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
************************************************************/
BOOL decode_pw_buffer(char in_buffer[516], char *new_pwrd,
@@ -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);
+}