nt_password_hash.c 922 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * hostapd - Plaintext password to NtPasswordHash
  3. * Copyright (c) 2005, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "crypto/ms_funcs.h"
  11. int main(int argc, char *argv[])
  12. {
  13. unsigned char password_hash[16];
  14. size_t i;
  15. char *password, buf[64], *pos;
  16. if (argc > 1)
  17. password = argv[1];
  18. else {
  19. if (fgets(buf, sizeof(buf), stdin) == NULL) {
  20. printf("Failed to read password\n");
  21. return 1;
  22. }
  23. buf[sizeof(buf) - 1] = '\0';
  24. pos = buf;
  25. while (*pos != '\0') {
  26. if (*pos == '\r' || *pos == '\n') {
  27. *pos = '\0';
  28. break;
  29. }
  30. pos++;
  31. }
  32. password = buf;
  33. }
  34. if (nt_password_hash((u8 *) password, strlen(password), password_hash))
  35. return -1;
  36. for (i = 0; i < sizeof(password_hash); i++)
  37. printf("%02x", password_hash[i]);
  38. printf("\n");
  39. return 0;
  40. }