Handle NULL return from os_zalloc() in sta_track_add()
[mech_eap.git] / wlantest / gcmp.c
index 5639b7e..d92f4ed 100644 (file)
@@ -41,7 +41,6 @@ static void gcmp_aad_nonce(const struct ieee80211_hdr *hdr, const u8 *data,
        }
 
        fc &= ~(WLAN_FC_RETRY | WLAN_FC_PWRMGT | WLAN_FC_MOREDATA);
-       fc |= WLAN_FC_ISWEP;
        WPA_PUT_LE16(aad, fc);
        pos = aad + 2;
        os_memcpy(pos, hdr->addr1, 3 * ETH_ALEN);
@@ -73,7 +72,7 @@ static void gcmp_aad_nonce(const struct ieee80211_hdr *hdr, const u8 *data,
 }
 
 
-u8 * gcmp_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
+u8 * gcmp_decrypt(const u8 *tk, size_t tk_len, const struct ieee80211_hdr *hdr,
                  const u8 *data, size_t data_len, size_t *decrypted_len)
 {
        u8 aad[30], nonce[12], *plain;
@@ -95,7 +94,7 @@ u8 * gcmp_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
        wpa_hexdump(MSG_EXCESSIVE, "GCMP AAD", aad, aad_len);
        wpa_hexdump(MSG_EXCESSIVE, "GCMP nonce", nonce, sizeof(nonce));
 
-       if (aes_gcm_ad(tk, 16, nonce, sizeof(nonce), m, mlen, aad, aad_len,
+       if (aes_gcm_ad(tk, tk_len, nonce, sizeof(nonce), m, mlen, aad, aad_len,
                       m + mlen, plain) < 0) {
                u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
                wpa_printf(MSG_INFO, "Invalid GCMP frame: A1=" MACSTR
@@ -113,8 +112,9 @@ u8 * gcmp_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
 }
 
 
-u8 * gcmp_encrypt(const u8 *tk, u8 *frame, size_t len, size_t hdrlen, u8 *qos,
-                 u8 *pn, int keyid, size_t *encrypted_len)
+u8 * gcmp_encrypt(const u8 *tk, size_t tk_len, const u8 *frame, size_t len,
+                 size_t hdrlen, const u8 *qos,
+                 const u8 *pn, int keyid, size_t *encrypted_len)
 {
        u8 aad[30], nonce[12], *crypt, *pos;
        size_t aad_len, plen;
@@ -130,7 +130,6 @@ u8 * gcmp_encrypt(const u8 *tk, u8 *frame, size_t len, size_t hdrlen, u8 *qos,
 
        os_memcpy(crypt, frame, hdrlen);
        hdr = (struct ieee80211_hdr *) crypt;
-       hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
        pos = crypt + hdrlen;
        *pos++ = pn[5]; /* PN0 */
        *pos++ = pn[4]; /* PN1 */
@@ -146,8 +145,8 @@ u8 * gcmp_encrypt(const u8 *tk, u8 *frame, size_t len, size_t hdrlen, u8 *qos,
        wpa_hexdump(MSG_EXCESSIVE, "GCMP AAD", aad, aad_len);
        wpa_hexdump(MSG_EXCESSIVE, "GCMP nonce", nonce, sizeof(nonce));
 
-       if (aes_gcm_ae(tk, 16, nonce, sizeof(nonce), frame + hdrlen, plen, aad,
-                      aad_len, pos, pos + plen) < 0) {
+       if (aes_gcm_ae(tk, tk_len, nonce, sizeof(nonce), frame + hdrlen, plen,
+                      aad, aad_len, pos, pos + plen) < 0) {
                os_free(crypt);
                return NULL;
        }