All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
smbencrypt.c
Go to the documentation of this file.
1 /*
2  * smbencrypt.c Produces LM-Password and NT-Password from
3  * cleartext password
4  *
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.
9  *
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.
14  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  *
19  * Copyright 2002 3APA3A for FreeRADIUS project
20  Copyright 2006 The FreeRADIUS server project
21  */
22 
23 RCSID("$Id: d6a20dccf25084ec877e38e59b2daf185cb4bbbb $")
24 
25 #include <freeradius-devel/libradius.h>
26 #include <freeradius-devel/md4.h>
27 #include <freeradius-devel/md5.h>
28 #include <freeradius-devel/sha1.h>
29 #include <ctype.h>
30 
31 
32 #include "smbdes.h"
33 
34 static char const hex[] = "0123456789ABCDEF";
35 
36 /*
37  * FIXME: use functions in freeradius
38  */
39 static void tohex (unsigned char const *src, size_t len, char *dst)
40 {
41  size_t i;
42  for (i=0; i<len; i++) {
43  dst[(i*2)] = hex[(src[i] >> 4)];
44  dst[(i*2) + 1] = hex[(src[i]&0x0F)];
45  }
46  dst[(i*2)] = 0;
47 }
48 
49 static void ntpwdhash(uint8_t *out, char const *password)
50 {
51  ssize_t len;
52  uint8_t ucs2_password[512];
53 
54  len = fr_utf8_to_ucs2(ucs2_password, sizeof(ucs2_password), password, strlen(password));
55  if (len < 0) {
56  *out = '\0';
57  return;
58  }
59  fr_md4_calc(out, (uint8_t *) ucs2_password, len);
60 }
61 
62 int main (int argc, char *argv[])
63 {
64  int i, l;
65  char password[1024];
66  uint8_t hash[16];
67  char ntpass[33];
68  char lmpass[33];
69 
70  fprintf(stderr, "LM Hash \tNT Hash\n");
71  fprintf(stderr, "--------------------------------\t--------------------------------\n");
72  fflush(stderr);
73  for (i = 1; i < argc; i++ ) {
74  strlcpy(password, argv[i], sizeof(password));
75  l = strlen(password);
76  if (l && password[l-1] == '\n') password [l-1] = 0;
77  smbdes_lmpwdhash(password, hash);
78  tohex (hash, 16, lmpass);
79  ntpwdhash (hash, password);
80  tohex (hash, 16, ntpass);
81  printf("%s\t%s\n", lmpass, ntpass);
82  }
83  return 0;
84 }
void smbdes_lmpwdhash(char const *password, uint8_t *lmhash)
Definition: smbdes.c:318
int main(int argc, char *argv[])
Definition: smbencrypt.c:62
void fr_md4_calc(uint8_t out[MD4_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
Calculate the MD4 hash of the contents of a buffer.
Definition: md4.c:24
static unsigned int hash(char const *username, unsigned int tablesize)
Definition: rlm_passwd.c:124
static void tohex(unsigned char const *src, size_t len, char *dst)
Definition: smbencrypt.c:39
ssize_t fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inlen)
Convert UTF8 string to UCS2 encoding.
Definition: misc.c:580
static void ntpwdhash(uint8_t *out, char const *password)
Definition: smbencrypt.c:49
size_t strlcpy(char *dst, char const *src, size_t siz)
Definition: strlcpy.c:38
static char const hex[]
Definition: smbencrypt.c:34
#define RCSID(id)
Definition: build.h:135