2 * WPA Supplicant - ASCII passphrase to WPA PSK tool
3 * Copyright (c) 2003-2005, Jouni Malinen <jkmaline@cc.hut.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
22 int main(int argc, char *argv[])
24 unsigned char psk[32];
26 char *ssid, *passphrase, buf[64], *pos;
29 printf("usage: wpa_passphrase <ssid> [passphrase]\n"
30 "\nIf passphrase is left out, it will be read from "
40 printf("# reading passphrase from stdin\n");
41 if (fgets(buf, sizeof(buf), stdin) == NULL) {
42 printf("Failed to read passphrase\n");
45 buf[sizeof(buf) - 1] = '\0';
47 while (*pos != '\0') {
48 if (*pos == '\r' || *pos == '\n') {
57 if (strlen(passphrase) < 8 || strlen(passphrase) > 63) {
58 printf("Passphrase must be 8..63 characters\n");
62 pbkdf2_sha1(passphrase, ssid, strlen(ssid), 4096, psk, 32);
64 printf("network={\n");
65 printf("\tssid=\"%s\"\n", ssid);
66 printf("\t#psk=\"%s\"\n", passphrase);
68 for (i = 0; i < 32; i++)
69 printf("%02x", psk[i]);