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;
22 printf("usage: wpa_passphrase <ssid> [passphrase]\n"
23 "\nIf passphrase is left out, it will be read from "
33 printf("# reading passphrase from stdin\n");
34 if (fgets(buf, sizeof(buf), stdin) == NULL) {
35 printf("Failed to read passphrase\n");
38 buf[sizeof(buf) - 1] = '\0';
40 while (*pos != '\0') {
41 if (*pos == '\r' || *pos == '\n') {
50 if (os_strlen(passphrase) < 8 || os_strlen(passphrase) > 63) {
51 printf("Passphrase must be 8..63 characters\n");
55 pbkdf2_sha1(passphrase, (u8 *) ssid, os_strlen(ssid), 4096, psk, 32);
57 printf("network={\n");
58 printf("\tssid=\"%s\"\n", ssid);
59 printf("\t#psk=\"%s\"\n", passphrase);
61 for (i = 0; i < 32; i++)
62 printf("%02x", psk[i]);