2 * WPA Supplicant - ASCII passphrase to WPA PSK tool
3 * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "crypto/sha1.h"
15 int main(int argc, char *argv[])
17 unsigned char psk[32];
19 char *ssid, *passphrase, buf[64], *pos;
23 printf("usage: wpa_passphrase <ssid> [passphrase]\n"
24 "\nIf passphrase is left out, it will be read from "
34 printf("# reading passphrase from stdin\n");
35 if (fgets(buf, sizeof(buf), stdin) == NULL) {
36 printf("Failed to read passphrase\n");
39 buf[sizeof(buf) - 1] = '\0';
41 while (*pos != '\0') {
42 if (*pos == '\r' || *pos == '\n') {
51 len = os_strlen(passphrase);
52 if (len < 8 || len > 63) {
53 printf("Passphrase must be 8..63 characters\n");
56 if (has_ctrl_char((u8 *) passphrase, len)) {
57 printf("Invalid passphrase character\n");
61 pbkdf2_sha1(passphrase, (u8 *) ssid, os_strlen(ssid), 4096, psk, 32);
63 printf("network={\n");
64 printf("\tssid=\"%s\"\n", ssid);
65 printf("\t#psk=\"%s\"\n", passphrase);
67 for (i = 0; i < 32; i++)
68 printf("%02x", psk[i]);