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
23 #include "libradius.h"
31 static const char * hex = "0123456789ABCDEF";
33 static void tohex (const unsigned char * src, size_t len, char *dst)
36 for (i=0; i<len; i++) {
37 dst[(i*2)] = hex[(src[i] >> 4)];
38 dst[(i*2) + 1] = hex[(src[i]&0x0F)];
43 static void ntpwdhash (char *szHash, const char *szPassword)
45 char szUnicodePass[513];
50 * NT passwords are unicode. Convert plain text password
51 * to unicode by inserting a zero every other byte
53 nPasswordLen = strlen(szPassword);
54 for (i = 0; i < nPasswordLen; i++) {
55 szUnicodePass[i << 1] = szPassword[i];
56 szUnicodePass[(i << 1) + 1] = 0;
59 /* Encrypt Unicode password to a 16-byte MD4 hash */
60 md4_calc(szHash, szUnicodePass, (nPasswordLen<<1) );
65 int main (int argc, char *argv[])
73 fprintf(stderr, "LM Hash \tNT Hash\n");
74 fprintf(stderr, "--------------------------------\t--------------------------------\n");
76 for (i = 1; i < argc; i++ ) {
78 if (l && password[l-1] == '\n') password [l-1] = 0;
79 lrad_lmpwdhash(argv[i], hash);
80 tohex (hash, 16, lmpass);
81 ntpwdhash (hash, argv[i]);
82 tohex (hash, 16, ntpass);
83 printf("%s\t%s\n", lmpass, ntpass);