]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/wpa_supplicant/wpa_passphrase.c
This commit was generated by cvs2svn to compensate for changes in r152058,
[FreeBSD/FreeBSD.git] / contrib / wpa_supplicant / wpa_passphrase.c
1 /*
2  * WPA Supplicant - ASCII passphrase to WPA PSK tool
3  * Copyright (c) 2003-2004, Jouni Malinen <jkmaline@cc.hut.fi>
4  *
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.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include <stdio.h>
16 #include <string.h>
17
18 #include "common.h"
19 #include "sha1.h"
20
21
22 int main(int argc, char *argv[])
23 {
24         unsigned char psk[32];
25         int i;
26         char *ssid, *passphrase;
27
28         if (argc != 3) {
29                 printf("usage: wpa_passphrase <ssid> <passphrase>\n");
30                 return 1;
31         }
32
33         ssid = argv[1];
34         passphrase = argv[2];
35
36         if (strlen(passphrase) < 8 || strlen(passphrase) > 63) {
37                 printf("Passphrase must be 8..63 characters\n");
38                 return 1;
39         }
40
41         pbkdf2_sha1(passphrase, ssid, strlen(ssid), 4096, psk, 32);
42
43         printf("network={\n");
44         printf("\tssid=\"%s\"\n", ssid);
45         printf("\t#psk=\"%s\"\n", passphrase);
46         printf("\tpsk=");
47         for (i = 0; i < 32; i++)
48                 printf("%02x", psk[i]);
49         printf("\n");
50         printf("}\n");
51
52         return 0;
53 }