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>
32 #include "smblib-priv.h"
33 #define uchar unsigned char
34 extern int DEBUGLEVEL;
36 void strupper(char *s);
39 This implements the X/Open SMB password encryption
40 It takes a password, a 8 byte "crypt key" and puts 24 bytes of
41 encrypted password into p24 */
42 void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24)
44 uchar p14[15], p21[21];
48 strlcpy((char *)p14,(char *)passwd,14);
50 strupper((char *)p14);
55 /* Routines for Windows NT MD4 Hash functions. */
56 static int _my_wcslen(int16 *str)
65 * Convert a string into an NT UNICODE string.
66 * Note that regardless of processor type
67 * this must be in intel (little-endian)
71 static int _my_mbstowcs(int16 *dst, uchar *src, int len)
76 for(i = 0; i < len; i++) {
88 * Creates the MD4 Hash of the users password in NT UNICODE.
91 void E_md4hash(uchar *passwd, uchar *p16)
96 /* Password cannot be longer than 128 characters */
97 len = strlen((char *)passwd);
100 /* Password must be converted to NT unicode */
101 _my_mbstowcs(wpwd, passwd, len);
102 wpwd[len] = 0; /* Ensure string is null terminated */
103 /* Calculate length in bytes */
104 len = _my_wcslen(wpwd) * sizeof(int16);
106 mdfour(p16, (unsigned char *)wpwd, len);
109 /* Does the NT MD4 hash then des encryption. */
111 void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24)
117 E_md4hash(passwd, p21);
121 /* Does both the NT and LM owfs of a user's password */
123 void nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16)
126 strlcpy(passwd, pwd, sizeof(passwd));
128 /* Calculate the MD4 hash (NT compatible) of the password */
129 memset(nt_p16, '\0', 16);
130 E_md4hash((uchar *)passwd, (uchar *)nt_p16);
132 /* Mangle the passwords into Lanman format */
136 /* Calculate the SMB (lanman) hash functions of the password */
138 memset(p16, '\0', 16);
139 E_P16((uchar *) passwd, (uchar *)p16);
141 /* clear out local copy of user's password (just being paranoid). */
142 bzero(passwd, sizeof(passwd));
145 void strupper(char *s)
150 #if !defined(KANJI_WIN95_COMPATIBILITY)
151 if(lp_client_code_page() == KANJI_CODEPAGE)
154 if (is_shift_jis (*s))
156 if (is_sj_lower (s[0], s[1]))
157 s[1] = sj_toupper2 (s[1]);
160 else if (is_kana (*s))
172 #endif */ /* KANJI_WIN95_COMPATIBILITY */