2 * smbencrypt.c Produces LM-Password and NT-Password from
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Copyright 2002 3APA3A for FreeRADIUS project
22 #include <freeradius-devel/autoconf.h>
28 #include <freeradius-devel/md4.h>
32 static const char * hex = "0123456789ABCDEF";
34 static void tohex (const unsigned char * src, size_t len, char *dst)
37 for (i=0; i<len; i++) {
38 dst[(i*2)] = hex[(src[i] >> 4)];
39 dst[(i*2) + 1] = hex[(src[i]&0x0F)];
44 static void ntpwdhash (char *szHash, const char *szPassword)
46 char szUnicodePass[513];
51 * NT passwords are unicode. Convert plain text password
52 * to unicode by inserting a zero every other byte
54 nPasswordLen = strlen(szPassword);
55 for (i = 0; i < nPasswordLen; i++) {
56 szUnicodePass[i << 1] = szPassword[i];
57 szUnicodePass[(i << 1) + 1] = 0;
60 /* Encrypt Unicode password to a 16-byte MD4 hash */
61 md4_calc(szHash, szUnicodePass, (nPasswordLen<<1) );
66 int main (int argc, char *argv[])
74 fprintf(stderr, "LM Hash \tNT Hash\n");
75 fprintf(stderr, "--------------------------------\t--------------------------------\n");
77 for (i = 1; i < argc; i++ ) {
79 if (l && password[l-1] == '\n') password [l-1] = 0;
80 smbdes_lmpwdhash(argv[i], hash);
81 tohex (hash, 16, lmpass);
82 ntpwdhash (hash, argv[i]);
83 tohex (hash, 16, ntpass);
84 printf("%s\t%s\n", lmpass, ntpass);