If there is no commitid, we need to initialize Delta->commitid to NULL to
[dragonfly.git] / contrib / wpa_supplicant-0.4.9 / wpa_passphrase.c
blob2a68cb52cf393c4c2502a51ae01d2c486898b67b
1 /*
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
10 * license.
12 * See README and COPYING for more details.
15 #include <stdio.h>
16 #include <string.h>
18 #include "common.h"
19 #include "sha1.h"
22 int main(int argc, char *argv[])
24 unsigned char psk[32];
25 int i;
26 char *ssid, *passphrase, buf[64], *pos;
28 if (argc < 2) {
29 printf("usage: wpa_passphrase <ssid> [passphrase]\n"
30 "\nIf passphrase is left out, it will be read from "
31 "stdin\n");
32 return 1;
35 ssid = argv[1];
37 if (argc > 2) {
38 passphrase = argv[2];
39 } else {
40 printf("# reading passphrase from stdin\n");
41 if (fgets(buf, sizeof(buf), stdin) == NULL) {
42 printf("Failed to read passphrase\n");
43 return 1;
45 buf[sizeof(buf) - 1] = '\0';
46 pos = buf;
47 while (*pos != '\0') {
48 if (*pos == '\r' || *pos == '\n') {
49 *pos = '\0';
50 break;
52 pos++;
54 passphrase = buf;
57 if (strlen(passphrase) < 8 || strlen(passphrase) > 63) {
58 printf("Passphrase must be 8..63 characters\n");
59 return 1;
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);
67 printf("\tpsk=");
68 for (i = 0; i < 32; i++)
69 printf("%02x", psk[i]);
70 printf("\n");
71 printf("}\n");
73 return 0;