[PATCH] Fix test vector issues

Henry Ptasinski henry at e78com.com
Thu Jul 13 06:29:32 PDT 2023


- Commit b20991da6936a1baae9f2239ee127610a6f5335d introduced errors in
   the order of arguments to the calls of ccmp_decrypt() and
   ccmp_256_decrypt().  Corrected the order of arguments.

. Includeed the PTID in the PV1 nonce construction.

- Made minor formatting changes.

Signed-off-by: Henry Ptasinski <henry at e78com.com>
---
  wlantest/ccmp.c         | 13 +++++++++----
  wlantest/test_vectors.c | 12 ++++++------
  2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/wlantest/ccmp.c b/wlantest/ccmp.c
index 894aa743b..d6594b9ca 100644
--- a/wlantest/ccmp.c
+++ b/wlantest/ccmp.c
@@ -91,7 +91,7 @@ static void ccmp_aad_nonce_pv1(const u8 *hdr, const u8 *a1, const u8 *a2,
  			       const u8 *a3, const u8 *pn,
  			       u8 *aad, size_t *aad_len, u8 *nonce)
  {
-	u16 fc, type;
+	u16 fc, type, ptid;
  	u8 *pos;
  
  	nonce[0] = BIT(5); /* PV1 */
@@ -102,6 +102,11 @@ static void ccmp_aad_nonce_pv1(const u8 *hdr, const u8 *a1, const u8 *a2,
  
  	if (type == 1)
  		nonce[0] |= 0x10; /* Management */
+	else if ((type == 0) || (type == 3)) {
+		/* QoS Data */
+		ptid = (fc & (BIT(5) | BIT(6) | BIT(7))) >> 5;
+		nonce[0] |= ptid;
+	}
  
  	fc &= ~(BIT(10) | BIT(11) | BIT(13) | BIT(14) | BIT(15));
  	fc |= BIT(12);
@@ -167,7 +172,7 @@ u8 * ccmp_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
  	os_memset(aad, 0, sizeof(aad));
  	ccmp_aad_nonce(hdr, data, a1, a2, a3, aad, &aad_len, nonce);
  	wpa_hexdump(MSG_EXCESSIVE, "CCMP AAD", aad, aad_len);
-	wpa_hexdump(MSG_EXCESSIVE, "CCMP nonce", nonce, 13);
+	wpa_hexdump(MSG_EXCESSIVE, "CCM Nonce", nonce, 13);
  
  	if (aes_ccm_ad(tk, 16, nonce, 8, data + 8, mlen, aad, aad_len,
  		       data + 8 + mlen, plain) < 0) {
@@ -232,7 +237,7 @@ u8 * ccmp_encrypt(const u8 *tk, u8 *frame, size_t len, size_t hdrlen,
  	os_memset(aad, 0, sizeof(aad));
  	ccmp_aad_nonce(hdr, crypt + hdrlen, a1, a2, a3, aad, &aad_len, nonce);
  	wpa_hexdump(MSG_EXCESSIVE, "CCMP AAD", aad, aad_len);
-	wpa_hexdump(MSG_EXCESSIVE, "CCMP nonce", nonce, 13);
+	wpa_hexdump(MSG_EXCESSIVE, "CCM Nonce", nonce, 13);
  
  	if (aes_ccm_ae(tk, 16, nonce, 8, frame + hdrlen, plen, aad, aad_len,
  		       pos, pos + plen) < 0) {
@@ -274,7 +279,7 @@ u8 * ccmp_encrypt_pv1(const u8 *tk, const u8 *a1, const u8 *a2, const u8 *a3,
  	os_memset(aad, 0, sizeof(aad));
  	ccmp_aad_nonce_pv1(crypt, a1, a2, a3, pn, aad, &aad_len, nonce);
  	wpa_hexdump(MSG_EXCESSIVE, "CCMP AAD", aad, aad_len);
-	wpa_hexdump(MSG_EXCESSIVE, "CCMP nonce", nonce, sizeof(nonce));
+	wpa_hexdump(MSG_EXCESSIVE, "CCM Nonce", nonce, sizeof(nonce));
  
  	if (aes_ccm_ae(tk, 16, nonce, 8, frame + hdrlen, plen, aad, aad_len,
  		       pos, pos + plen) < 0) {
diff --git a/wlantest/test_vectors.c b/wlantest/test_vectors.c
index 3638f67b6..f2517cb8c 100644
--- a/wlantest/test_vectors.c
+++ b/wlantest/test_vectors.c
@@ -120,7 +120,7 @@ static void test_vector_ccmp(void)
  
  	wpa_debug_level = MSG_INFO;
  	plain = ccmp_decrypt(tk, (const struct ieee80211_hdr *) enc,
-			     enc + 24, NULL, NULL, NULL, enc_len - 24,
+			     NULL, NULL, NULL, enc + 24, enc_len - 24,
  			     &plain_len);
  	wpa_debug_level = MSG_EXCESSIVE;
  	os_free(enc);
@@ -200,7 +200,7 @@ static void test_vector_ccmp_pv1(void)
  	wpa_hexdump(MSG_INFO, "PN (PN0..PN5)", pn, sizeof(pn));
  
  	wpa_printf(MSG_INFO,
-		   "\nPV1 test vector #1:\nHeader compression used and A3 was previously stored at the receiver\n");
+		   "\nPV1 test vector #1:\nHeader compression used and A3 was previously stored at the receiver");
  	fc = WPA_GET_LE16(frame1);
  	wpa_printf(MSG_INFO,
  		   "FC=0x%04x (PV=%u Type=%u PTID/Subtype=%u From_DS=%u More_Fragments=%u Power_Management=%u More_Data=%u Protected_Frame=%u End_of_SP=%u Relayed_Frame=%u Ack_Policy=%u)",
@@ -249,7 +249,7 @@ static void test_vector_ccmp_pv1(void)
  	wpa_hexdump(MSG_INFO, "Encrypted Frame FCS", fcs, sizeof(fcs));
  
  	wpa_printf(MSG_INFO,
-		   "\nPV1 test vector #2:\nHeader compression used and A3 was not previously stored at the receiver\n");
+		   "\nPV1 test vector #2:\nHeader compression used and A3 was not previously stored at the receiver");
  	fc = WPA_GET_LE16(frame2);
  	wpa_printf(MSG_INFO,
  		   "FC=0x%04x (PV=%u Type=%u PTID/Subtype=%u From_DS=%u More_Fragments=%u Power_Management=%u More_Data=%u Protected_Frame=%u End_of_SP=%u Relayed_Frame=%u Ack_Policy=%u)",
@@ -299,7 +299,7 @@ static void test_vector_ccmp_pv1(void)
  	wpa_hexdump(MSG_INFO, "Encrypted Frame FCS", fcs, sizeof(fcs));
  
  	wpa_printf(MSG_INFO,
-		   "\nPV1 test vector #3:\nType 3 frame from SA to DA(=BSSID) (i.e., no separate DA in this example)\n");
+		   "\nPV1 test vector #3:\nType 3 frame from SA to DA(=BSSID) (i.e., no separate DA in this example)");
  	fc = WPA_GET_LE16(frame3);
  	wpa_printf(MSG_INFO,
  		   "FC=0x%04x (PV=%u Type=%u PTID/Subtype=%u From_DS=%u More_Fragments=%u Power_Management=%u More_Data=%u Protected_Frame=%u End_of_SP=%u Relayed_Frame=%u Ack_Policy=%u)",
@@ -414,7 +414,7 @@ static void test_vector_ccmp_mgmt(void)
  
  	wpa_debug_level = MSG_INFO;
  	plain = ccmp_decrypt(tk, (const struct ieee80211_hdr *) enc,
-			     enc + 24, NULL, NULL, NULL, enc_len - 24,
+			     NULL, NULL, NULL, enc + 24, enc_len - 24,
  			     &plain_len);
  	wpa_debug_level = MSG_EXCESSIVE;
  	os_free(enc);
@@ -789,7 +789,7 @@ static int test_vector_ccmp_256(void)
  
  	wpa_debug_level = MSG_INFO;
  	plain = ccmp_256_decrypt(tk, (const struct ieee80211_hdr *) enc,
-				 enc + 24, NULL, NULL, NULL, enc_len - 24,
+				 NULL, NULL, NULL, enc + 24, enc_len - 24,
  				 &plain_len);
  	wpa_debug_level = MSG_EXCESSIVE;
  	os_free(enc);
-- 
2.39.2




More information about the Hostap mailing list