1219019Sgabor/* 2219019Sgabor * hostapd - Plaintext password to NtPasswordHash 3219019Sgabor * Copyright (c) 2005, Jouni Malinen <j@w1.fi> 4219019Sgabor * 5219019Sgabor * This software may be distributed under the terms of the BSD license. 6219019Sgabor * See README for more details. 7219019Sgabor */ 8219019Sgabor 9219019Sgabor#include "includes.h" 10219019Sgabor 11219019Sgabor#include "common.h" 12219019Sgabor#include "crypto/ms_funcs.h" 13219019Sgabor 14219019Sgabor 15219019Sgaborint main(int argc, char *argv[]) 16219019Sgabor{ 17219019Sgabor unsigned char password_hash[16]; 18219019Sgabor size_t i; 19219019Sgabor char *password, buf[64], *pos; 20219019Sgabor 21219019Sgabor if (argc > 1) 22219019Sgabor password = argv[1]; 23219019Sgabor else { 24219019Sgabor if (fgets(buf, sizeof(buf), stdin) == NULL) { 25219019Sgabor printf("Failed to read password\n"); 26219019Sgabor return 1; 27219019Sgabor } 28219019Sgabor buf[sizeof(buf) - 1] = '\0'; 29219019Sgabor pos = buf; 30219019Sgabor while (*pos != '\0') { 31219019Sgabor if (*pos == '\r' || *pos == '\n') { 32219019Sgabor *pos = '\0'; 33219019Sgabor break; 34219019Sgabor } 35219019Sgabor pos++; 36219019Sgabor } 37219019Sgabor password = buf; 38219019Sgabor } 39219019Sgabor 40219019Sgabor if (nt_password_hash((u8 *) password, strlen(password), password_hash)) 41219019Sgabor return -1; 42219019Sgabor for (i = 0; i < sizeof(password_hash); i++) 43219019Sgabor printf("%02x", password_hash[i]); 44219019Sgabor printf("\n"); 45219019Sgabor 46219019Sgabor return 0; 47219019Sgabor} 48219019Sgabor