2 Unix SMB/Netbios implementation.
4 SMB parameters and setup
5 Copyright (C) Andrew Tridgell 1992-1997
6 Modified by Jeremy Allison 1995.
7 Copyright 2006 The FreeRADIUS server project
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <freeradius-devel/ident.h>
27 #include "smblib-priv.h"
28 #define uchar unsigned char
29 extern int DEBUGLEVEL;
38 #include "byteorder.h"
40 void strupper(char *s);
43 This implements the X/Open SMB password encryption
44 It takes a password, a 8 byte "crypt key" and puts 24 bytes of
45 encrypted password into p24 */
46 void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24)
48 uchar p14[15], p21[21];
52 strlcpy((char *)p14,(char *)passwd,14);
54 strupper((char *)p14);
59 /* Routines for Windows NT MD4 Hash functions. */
60 static int _my_wcslen(int16 *str)
69 * Convert a string into an NT UNICODE string.
70 * Note that regardless of processor type
71 * this must be in intel (little-endian)
75 static int _my_mbstowcs(int16 *dst, uchar *src, int len)
80 for(i = 0; i < len; i++) {
92 * Creates the MD4 Hash of the users password in NT UNICODE.
95 void E_md4hash(uchar *passwd, uchar *p16)
100 /* Password cannot be longer than 128 characters */
101 len = strlen((char *)passwd);
104 /* Password must be converted to NT unicode */
105 _my_mbstowcs(wpwd, passwd, len);
106 wpwd[len] = 0; /* Ensure string is null terminated */
107 /* Calculate length in bytes */
108 len = _my_wcslen(wpwd) * sizeof(int16);
110 mdfour(p16, (unsigned char *)wpwd, len);
113 /* Does the NT MD4 hash then des encryption. */
115 void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24)
121 E_md4hash(passwd, p21);
125 /* Does both the NT and LM owfs of a user's password */
127 void nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16)
130 strlcpy(passwd, pwd, sizeof(passwd));
132 /* Calculate the MD4 hash (NT compatible) of the password */
133 memset(nt_p16, '\0', 16);
134 E_md4hash((uchar *)passwd, (uchar *)nt_p16);
136 /* Mangle the passwords into Lanman format */
140 /* Calculate the SMB (lanman) hash functions of the password */
142 memset(p16, '\0', 16);
143 E_P16((uchar *) passwd, (uchar *)p16);
145 /* clear out local copy of user's password (just being paranoid). */
146 bzero(passwd, sizeof(passwd));
149 void strupper(char *s)
154 #if !defined(KANJI_WIN95_COMPATIBILITY)
155 if(lp_client_code_page() == KANJI_CODEPAGE)
158 if (is_shift_jis (*s))
160 if (is_sj_lower (s[0], s[1]))
161 s[1] = sj_toupper2 (s[1]);
164 else if (is_kana (*s))
176 #endif */ /* KANJI_WIN95_COMPATIBILITY */