wpa_passphrase.c

Go to the documentation of this file.
00001 
00016 #include <stdio.h>
00017 #include <string.h>
00018 
00019 #include "common.h"
00020 #include "sha1.h"
00021 
00022 
00023 int main(int argc, char *argv[])
00024 {
00025         unsigned char psk[32];
00026         int i;
00027         char *ssid, *passphrase, buf[64], *pos;
00028 
00029         if (argc < 2) {
00030                 printf("usage: wpa_passphrase <ssid> [passphrase]\n"
00031                         "\nIf passphrase is left out, it will be read from "
00032                         "stdin\n");
00033                 return 1;
00034         }
00035 
00036         ssid = argv[1];
00037 
00038         if (argc > 2) {
00039                 passphrase = argv[2];
00040         } else {
00041                 printf("# reading passphrase from stdin\n");
00042                 if (fgets(buf, sizeof(buf), stdin) == NULL) {
00043                         printf("Failed to read passphrase\n");
00044                         return 1;
00045                 }
00046                 buf[sizeof(buf) - 1] = '\0';
00047                 pos = buf;
00048                 while (*pos != '\0') {
00049                         if (*pos == '\r' || *pos == '\n') {
00050                                 *pos = '\0';
00051                                 break;
00052                         }
00053                         pos++;
00054                 }
00055                 passphrase = buf;
00056         }
00057 
00058         if (strlen(passphrase) < 8 || strlen(passphrase) > 63) {
00059                 printf("Passphrase must be 8..63 characters\n");
00060                 return 1;
00061         }
00062 
00063         pbkdf2_sha1(passphrase, ssid, strlen(ssid), 4096, psk, 32);
00064 
00065         printf("network={\n");
00066         printf("\tssid=\"%s\"\n", ssid);
00067         printf("\t#psk=\"%s\"\n", passphrase);
00068         printf("\tpsk=");
00069         for (i = 0; i < 32; i++)
00070                 printf("%02x", psk[i]);
00071         printf("\n");
00072         printf("}\n");
00073 
00074         return 0;
00075 }
00076 

Generated on Sat May 6 21:13:42 2006 for wpa_supplicant by  doxygen 1.4.2