/* Minimal WPA2-PSK supplicant (IEEE 802.11i 4-way and group handshakes, * key descriptor version 2: HMAC-SHA1-128 MIC + AES key wrap, CCMP only). * Pure C, no OS calls: the ring-3 `wifi` command moves the EAPOL frames * (SYS_WIFI_EAPOL_RX/TX) and installs the keys. Host test: make test-wpa. */ #ifndef WPA_H #define WPA_H #define WPA_NONE 0 /* frame ignored */ #define WPA_REPLY 1 /* send `reply` */ #define WPA_PTK 2 /* send `reply`, then install TK + GTK, authorize */ #define WPA_GTK 3 /* send `reply`, then install the new GTK */ #define WPA_ERR -1 /* bad MIC / replay / malformed */ struct wpa_sm { unsigned char pmk[32]; unsigned char aa[6], spa[6]; /* AP and our MAC */ unsigned char anonce[32], snonce[32]; unsigned char ptk[48]; /* KCK | KEK | TK */ unsigned char replay[8]; int have_replay, have_snonce, ptk_ok; unsigned char ie[64]; /* our RSN IE (assoc request) */ unsigned int ie_len; unsigned char ap_ie[64]; /* AP's RSN IE (beacon) */ unsigned int ap_ie_len; unsigned char gtk[32]; unsigned int gtk_len; int gtk_idx; unsigned char gtk_rsc[8]; const char *error; }; /* PMK = PBKDF2-HMAC-SHA1(passphrase, ssid, 4096, 32). */ void wpa_pmk(const char *pass, const unsigned char *ssid, unsigned int ssid_len, unsigned char pmk[32]); /* Our RSN IE: version 1, CCMP group, CCMP pairwise, PSK AKM, caps 0. */ unsigned int wpa_rsn_ie(unsigned char out[22]); void wpa_init(struct wpa_sm *sm, const unsigned char pmk[32], const unsigned char aa[6], const unsigned char spa[6], const unsigned char *ie, unsigned int ie_len, const unsigned char *ap_ie, unsigned int ap_ie_len); /* Process one EAPOL frame (starting at the EAPOL header). `reply` must * hold 256 bytes. `rng` fills the SNonce. */ int wpa_rx(struct wpa_sm *sm, const unsigned char *f, unsigned int len, unsigned char *reply, unsigned int *rlen, void (*rng)(unsigned char *out, unsigned int n)); #define WPA_TK(sm) ((sm)->ptk + 32) #define WPA_KCK(sm) ((sm)->ptk) #define WPA_KEK(sm) ((sm)->ptk + 16) #endif