hostapd: Update vendor branch to 0.6.10
[dragonfly.git] / contrib / hostapd / hostapd / nt_password_hash.c
1 /*
2  * hostapd - Plaintext password to NtPasswordHash
3  * Copyright (c) 2005, Jouni Malinen <j@w1.fi>
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 version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include "includes.h"
16
17 #include "common.h"
18 #include "ms_funcs.h"
19
20
21 int main(int argc, char *argv[])
22 {
23         unsigned char password_hash[16];
24         size_t i;
25         char *password, buf[64], *pos;
26
27         if (argc > 1)
28                 password = argv[1];
29         else {
30                 if (fgets(buf, sizeof(buf), stdin) == NULL) {
31                         printf("Failed to read password\n");
32                         return 1;
33                 }
34                 buf[sizeof(buf) - 1] = '\0';
35                 pos = buf;
36                 while (*pos != '\0') {
37                         if (*pos == '\r' || *pos == '\n') {
38                                 *pos = '\0';
39                                 break;
40                         }
41                         pos++;
42                 }
43                 password = buf;
44         }
45
46         nt_password_hash((u8 *) password, strlen(password), password_hash);
47         for (i = 0; i < sizeof(password_hash); i++)
48                 printf("%02x", password_hash[i]);
49         printf("\n");
50
51         return 0;
52 }