test_vectors.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. /*
  2. * test_vectors - IEEE 802.11 test vector generator
  3. * Copyright (c) 2012, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/crc32.h"
  11. #include "utils/eloop.h"
  12. #include "common/ieee802_11_defs.h"
  13. #include "wlantest.h"
  14. static void test_vector_tkip(void)
  15. {
  16. u8 tk[] = {
  17. 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56,
  18. 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12,
  19. 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78,
  20. 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34
  21. };
  22. u8 pn[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
  23. u8 frame[] = {
  24. 0x08, 0x42, 0x2c, 0x00, 0x02, 0x03, 0x04, 0x05,
  25. 0x06, 0x08, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  26. 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xd0, 0x02,
  27. /* 0x00, 0x20, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, */
  28. 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00,
  29. 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
  30. 0x40, 0x01, 0xa5, 0x55, 0xc0, 0xa8, 0x0a, 0x02,
  31. 0xc0, 0xa8, 0x0a, 0x01, 0x08, 0x00, 0x3a, 0xb0,
  32. 0x00, 0x00, 0x00, 0x00, 0xcd, 0x4c, 0x05, 0x00,
  33. 0x00, 0x00, 0x00, 0x00, 0x08, 0x09, 0x0a, 0x0b,
  34. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
  35. 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
  36. 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  37. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
  38. 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
  39. 0x34, 0x35, 0x36, 0x37,
  40. /* 0x68, 0x81, 0xa3, 0xf3, 0xd6, 0x48, 0xd0, 0x3c */
  41. };
  42. u8 *enc, *plain;
  43. size_t enc_len, plain_len;
  44. wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.6.3 TKIP test "
  45. "vector\n");
  46. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  47. wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
  48. wpa_hexdump(MSG_INFO, "Plaintext MPDU", frame, sizeof(frame));
  49. enc = tkip_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
  50. if (enc == NULL) {
  51. wpa_printf(MSG_ERROR, "Failed to encrypt TKIP frame");
  52. return;
  53. }
  54. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  55. wpa_debug_level = MSG_INFO;
  56. plain = tkip_decrypt(tk, (const struct ieee80211_hdr *) enc,
  57. enc + 24, enc_len - 24, &plain_len);
  58. wpa_debug_level = MSG_EXCESSIVE;
  59. os_free(enc);
  60. if (plain == NULL) {
  61. wpa_printf(MSG_ERROR, "Failed to decrypt TKIP frame");
  62. return;
  63. }
  64. if (plain_len != sizeof(frame) - 24 ||
  65. os_memcmp(plain, frame + 24, plain_len) != 0) {
  66. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  67. plain, plain_len);
  68. }
  69. os_free(plain);
  70. }
  71. static void test_vector_ccmp(void)
  72. {
  73. u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
  74. 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f };
  75. u8 pn[] = { 0xB5, 0x03, 0x97, 0x76, 0xE7, 0x0C };
  76. u8 frame[] = {
  77. 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
  78. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  79. 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
  80. 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
  81. 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
  82. 0x7e, 0x78, 0xa0, 0x50
  83. };
  84. u8 *enc, *plain;
  85. size_t enc_len, plain_len;
  86. u8 fcs[4];
  87. wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.6.4 CCMP test "
  88. "vector\n");
  89. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  90. wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
  91. wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
  92. wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
  93. enc = ccmp_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
  94. if (enc == NULL) {
  95. wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
  96. return;
  97. }
  98. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  99. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  100. wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
  101. wpa_debug_level = MSG_INFO;
  102. plain = ccmp_decrypt(tk, (const struct ieee80211_hdr *) enc,
  103. enc + 24, enc_len - 24, &plain_len);
  104. wpa_debug_level = MSG_EXCESSIVE;
  105. os_free(enc);
  106. if (plain == NULL) {
  107. wpa_printf(MSG_ERROR, "Failed to decrypt CCMP frame");
  108. return;
  109. }
  110. if (plain_len != sizeof(frame) - 24 ||
  111. os_memcmp(plain, frame + 24, plain_len) != 0) {
  112. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  113. plain, plain_len);
  114. }
  115. os_free(plain);
  116. }
  117. static void test_vector_ccmp_pv1(void)
  118. {
  119. u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
  120. 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f };
  121. u8 pn[8];
  122. u8 frame1[] = {
  123. 0x61, 0x00, 0xa2, 0xae, 0xa5, 0xb8, 0xfc, 0xba,
  124. 0x07, 0x00, 0x80, 0x33,
  125. 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
  126. 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
  127. 0x7e, 0x78, 0xa0, 0x50
  128. };
  129. u8 frame2[] = {
  130. 0x61, 0x00, 0xa2, 0xae, 0xa5, 0xb8, 0xfc, 0xba,
  131. 0x07, 0x20, 0x80, 0x33, 0x02, 0xd2, 0xe1, 0x28,
  132. 0xa5, 0x7c,
  133. 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
  134. 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
  135. 0x7e, 0x78, 0xa0, 0x50
  136. };
  137. u8 frame3[] = {
  138. 0x6d, 0x00, 0xa2, 0xae, 0xa5, 0xb8, 0xfc, 0xba,
  139. 0x52, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
  140. 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
  141. 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
  142. 0x7e, 0x78, 0xa0, 0x50
  143. };
  144. u8 *enc;
  145. size_t enc_len;
  146. u8 fcs[4];
  147. u8 bssid[ETH_ALEN] = { 0xa2, 0xae, 0xa5, 0xb8, 0xfc, 0xba };
  148. u8 da[ETH_ALEN] = { 0x02, 0xd2, 0xe1, 0x28, 0xa5, 0x7c };
  149. u8 sa[ETH_ALEN] = { 0x52, 0x30, 0xf1, 0x84, 0x44, 0x08 };
  150. u16 aid = 7;
  151. u32 bpn = 123;
  152. u16 sc = 0x3380;
  153. int key_id = 0;
  154. u16 fc;
  155. int tid = 3;
  156. u16 sid;
  157. wpa_printf(MSG_INFO,
  158. "\nIEEE P802.11ah/D10.0, J.6.4 CCMP PV1 test vectors\n");
  159. wpa_printf(MSG_INFO, "BSSID: " MACSTR, MAC2STR(bssid));
  160. wpa_printf(MSG_INFO, "DA: " MACSTR, MAC2STR(da));
  161. wpa_printf(MSG_INFO, "SA: " MACSTR, MAC2STR(sa));
  162. wpa_printf(MSG_INFO, "Association ID: %u", aid);
  163. wpa_printf(MSG_INFO, "Base PN: %u (0x%08x)", bpn, bpn);
  164. wpa_printf(MSG_INFO, "SC = 0x%04x (FragNum=%u SeqNum=%u)",
  165. sc, WLAN_GET_SEQ_FRAG(sc), WLAN_GET_SEQ_SEQ(sc));
  166. wpa_printf(MSG_INFO, "TID = %u", tid);
  167. wpa_printf(MSG_INFO, "Key ID: %u", key_id);
  168. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  169. wpa_printf(MSG_INFO, "PN = SC||BPN");
  170. WPA_PUT_LE16(&pn[0], sc);
  171. WPA_PUT_LE32(&pn[2], bpn);
  172. wpa_hexdump(MSG_INFO, "PN (PN0..PN5)", pn, sizeof(pn));
  173. wpa_printf(MSG_INFO,
  174. "\nPV1 test vector #1:\nHeader compression used and A3 was previously stored at the receiver\n");
  175. fc = WPA_GET_LE16(frame1);
  176. wpa_printf(MSG_INFO,
  177. "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)",
  178. fc,
  179. fc & WLAN_FC_PVER,
  180. (fc & (BIT(2) | BIT(3) | BIT(4))) >> 2,
  181. (fc & (BIT(5) | BIT(6) | BIT(7))) >> 5,
  182. !!(fc & BIT(8)),
  183. !!(fc & BIT(9)),
  184. !!(fc & BIT(10)),
  185. !!(fc & BIT(11)),
  186. !!(fc & BIT(12)),
  187. !!(fc & BIT(13)),
  188. !!(fc & BIT(14)),
  189. !!(fc & BIT(15)));
  190. wpa_printf(MSG_INFO, "A1=" MACSTR, MAC2STR(&frame1[2]));
  191. sid = WPA_GET_LE16(&frame1[8]);
  192. wpa_printf(MSG_INFO,
  193. "A2=%02x %02x (SID: AID=%u A3_Present=%u A4_Present=%u A-MSDU=%u); corresponds to 52:30:f1:84:44:08 in uncompressed header",
  194. frame1[8], frame1[9],
  195. sid & ~(BIT(13) | BIT(14) | BIT(15)),
  196. !!(sid & BIT(13)),
  197. !!(sid & BIT(14)),
  198. !!(sid & BIT(15)));
  199. sc = WPA_GET_LE16(&frame1[10]);
  200. wpa_printf(MSG_INFO, "Sequence Control: %02x %02x (FN=%u SN=%u)",
  201. frame1[10], frame1[11],
  202. WLAN_GET_SEQ_FRAG(sc), WLAN_GET_SEQ_SEQ(sc));
  203. wpa_printf(MSG_INFO, "A3 not present; corresponds to 02:d2:e1:28:a5:7c in uncompressed header");
  204. wpa_printf(MSG_INFO, "A4 not present");
  205. wpa_hexdump(MSG_INFO, "Plaintext Frame Header", frame1, 12);
  206. wpa_hexdump(MSG_INFO, "Plaintext Frame Body",
  207. frame1 + 12, sizeof(frame1) - 12);
  208. enc = ccmp_encrypt_pv1(tk, &frame1[2], sa, da, frame1, sizeof(frame1),
  209. 12, pn, key_id, &enc_len);
  210. if (enc == NULL) {
  211. wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
  212. return;
  213. }
  214. wpa_hexdump(MSG_INFO, "Encrypted Frame Header", enc, 12);
  215. wpa_hexdump(MSG_INFO, "Encrypted Frame Frame Body",
  216. enc + 12, enc_len - 12);
  217. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  218. wpa_hexdump(MSG_INFO, "Encrypted Frame FCS", fcs, sizeof(fcs));
  219. wpa_printf(MSG_INFO,
  220. "\nPV1 test vector #2:\nHeader compression used and A3 was not previously stored at the receiver\n");
  221. fc = WPA_GET_LE16(frame2);
  222. wpa_printf(MSG_INFO,
  223. "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)",
  224. fc,
  225. fc & WLAN_FC_PVER,
  226. (fc & (BIT(2) | BIT(3) | BIT(4))) >> 2,
  227. (fc & (BIT(5) | BIT(6) | BIT(7))) >> 5,
  228. !!(fc & BIT(8)),
  229. !!(fc & BIT(9)),
  230. !!(fc & BIT(10)),
  231. !!(fc & BIT(11)),
  232. !!(fc & BIT(12)),
  233. !!(fc & BIT(13)),
  234. !!(fc & BIT(14)),
  235. !!(fc & BIT(15)));
  236. wpa_printf(MSG_INFO, "A1=" MACSTR, MAC2STR(&frame2[2]));
  237. sid = WPA_GET_LE16(&frame2[8]);
  238. wpa_printf(MSG_INFO,
  239. "A2=%02x %02x (SID: AID=%u A3_Present=%u A4_Present=%u A-MSDU=%u); corresponds to 52:30:f1:84:44:08 in uncompressed header",
  240. frame2[8], frame2[9],
  241. sid & ~(BIT(13) | BIT(14) | BIT(15)),
  242. !!(sid & BIT(13)),
  243. !!(sid & BIT(14)),
  244. !!(sid & BIT(15)));
  245. sc = WPA_GET_LE16(&frame2[10]);
  246. wpa_printf(MSG_INFO, "Sequence Control: %02x %02x (FN=%u SN=%u)",
  247. frame2[10], frame2[11],
  248. WLAN_GET_SEQ_FRAG(sc), WLAN_GET_SEQ_SEQ(sc));
  249. wpa_printf(MSG_INFO, "A3=" MACSTR, MAC2STR(&frame2[12]));
  250. wpa_printf(MSG_INFO, "A4 not present");
  251. wpa_hexdump(MSG_INFO, "Plaintext Frame Header", frame2, 18);
  252. wpa_hexdump(MSG_INFO, "Plaintext Frame Body",
  253. frame2 + 18, sizeof(frame2) - 18);
  254. enc = ccmp_encrypt_pv1(tk, &frame2[2], sa, &frame2[12],
  255. frame2, sizeof(frame2), 18, pn, key_id,
  256. &enc_len);
  257. if (enc == NULL) {
  258. wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
  259. return;
  260. }
  261. wpa_hexdump(MSG_INFO, "Encrypted Frame Header", enc, 18);
  262. wpa_hexdump(MSG_INFO, "Encrypted Frame Frame Body",
  263. enc + 18, enc_len - 18);
  264. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  265. wpa_hexdump(MSG_INFO, "Encrypted Frame FCS", fcs, sizeof(fcs));
  266. wpa_printf(MSG_INFO,
  267. "\nPV1 test vector #3:\nType 3 frame from SA to DA(=BSSID) (i.e., no separate DA in this example)\n");
  268. fc = WPA_GET_LE16(frame3);
  269. wpa_printf(MSG_INFO,
  270. "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)",
  271. fc,
  272. fc & WLAN_FC_PVER,
  273. (fc & (BIT(2) | BIT(3) | BIT(4))) >> 2,
  274. (fc & (BIT(5) | BIT(6) | BIT(7))) >> 5,
  275. !!(fc & BIT(8)),
  276. !!(fc & BIT(9)),
  277. !!(fc & BIT(10)),
  278. !!(fc & BIT(11)),
  279. !!(fc & BIT(12)),
  280. !!(fc & BIT(13)),
  281. !!(fc & BIT(14)),
  282. !!(fc & BIT(15)));
  283. wpa_printf(MSG_INFO, "A1=" MACSTR, MAC2STR(&frame3[2]));
  284. wpa_printf(MSG_INFO, "A2=" MACSTR, MAC2STR(&frame3[8]));
  285. sc = WPA_GET_LE16(&frame3[14]);
  286. wpa_printf(MSG_INFO, "Sequence Control: %02x %02x (FN=%u SN=%u)",
  287. frame3[14], frame3[15],
  288. WLAN_GET_SEQ_FRAG(sc), WLAN_GET_SEQ_SEQ(sc));
  289. wpa_printf(MSG_INFO,
  290. "A3 not present; corresponds to 02:d2:e1:28:a5:7c in uncompressed header");
  291. wpa_printf(MSG_INFO, "A4 not present");
  292. wpa_hexdump(MSG_INFO, "Plaintext Frame Header", frame3, 16);
  293. wpa_hexdump(MSG_INFO, "Plaintext Frame Body",
  294. frame3 + 16, sizeof(frame3) - 16);
  295. enc = ccmp_encrypt_pv1(tk, &frame3[2], &frame3[8], da,
  296. frame3, sizeof(frame3), 16, pn, key_id,
  297. &enc_len);
  298. if (enc == NULL) {
  299. wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
  300. return;
  301. }
  302. wpa_hexdump(MSG_INFO, "Encrypted Frame Header", enc, 16);
  303. wpa_hexdump(MSG_INFO, "Encrypted Frame Frame Body",
  304. enc + 16, enc_len - 16);
  305. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  306. wpa_hexdump(MSG_INFO, "Encrypted Frame FCS", fcs, sizeof(fcs));
  307. wpa_debug_level = MSG_INFO;
  308. }
  309. static void test_vector_bip(void)
  310. {
  311. u8 igtk[] = {
  312. 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
  313. 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf
  314. };
  315. u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
  316. u8 frame[] = {
  317. 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  318. 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  319. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
  320. 0x02, 0x00
  321. };
  322. u8 *prot;
  323. size_t prot_len;
  324. wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.9.1 BIP with broadcast "
  325. "Deauthentication frame\n");
  326. wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
  327. wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
  328. wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
  329. prot = bip_protect(igtk, sizeof(igtk), frame, sizeof(frame),
  330. ipn, 4, &prot_len);
  331. if (prot == NULL) {
  332. wpa_printf(MSG_ERROR, "Failed to protect BIP frame");
  333. return;
  334. }
  335. wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
  336. os_free(prot);
  337. }
  338. static void test_vector_ccmp_mgmt(void)
  339. {
  340. u8 tk[] = { 0x66, 0xed, 0x21, 0x04, 0x2f, 0x9f, 0x26, 0xd7,
  341. 0x11, 0x57, 0x06, 0xe4, 0x04, 0x14, 0xcf, 0x2e };
  342. u8 pn[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
  343. u8 frame[] = {
  344. 0xc0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  345. 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  346. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  347. 0x02, 0x00
  348. };
  349. u8 *enc, *plain;
  350. size_t enc_len, plain_len;
  351. wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.9.2 CCMP with unicast "
  352. "Deauthentication frame\n");
  353. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  354. wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
  355. wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
  356. wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
  357. enc = ccmp_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
  358. if (enc == NULL) {
  359. wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
  360. return;
  361. }
  362. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  363. wpa_debug_level = MSG_INFO;
  364. plain = ccmp_decrypt(tk, (const struct ieee80211_hdr *) enc,
  365. enc + 24, enc_len - 24, &plain_len);
  366. wpa_debug_level = MSG_EXCESSIVE;
  367. os_free(enc);
  368. if (plain == NULL) {
  369. wpa_printf(MSG_ERROR, "Failed to decrypt CCMP frame");
  370. return;
  371. }
  372. if (plain_len != sizeof(frame) - 24 ||
  373. os_memcmp(plain, frame + 24, plain_len) != 0) {
  374. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  375. plain, plain_len);
  376. }
  377. os_free(plain);
  378. }
  379. struct gcmp_test {
  380. u8 tk[16];
  381. u8 pn[6];
  382. u8 frame[300];
  383. size_t hdr_len;
  384. size_t payload_len;
  385. u8 mic[16];
  386. u8 encr[300];
  387. };
  388. static const struct gcmp_test gcmp_vectors[] =
  389. {
  390. {
  391. .tk = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  392. 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa },
  393. .pn = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
  394. .frame = {
  395. 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  396. 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  397. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
  398. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  399. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  400. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  401. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  402. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  403. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  404. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  405. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  406. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  407. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  408. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  409. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  410. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  411. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  412. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  413. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  414. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  415. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  416. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  417. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  418. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  419. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  420. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  421. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  422. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  423. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  424. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  425. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  426. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  427. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  428. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  429. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  430. },
  431. .hdr_len = 24,
  432. .payload_len = 256,
  433. .mic = {
  434. 0x80, 0xCB, 0x06, 0x62, 0xEA, 0x71, 0xAB, 0xFD,
  435. 0x9F, 0x04, 0xC7, 0xF8, 0x72, 0xF5, 0x80, 0x90 },
  436. .encr = {
  437. 0x5F, 0x55, 0x78, 0xC1, 0x8F, 0x13, 0x7A, 0xD2,
  438. 0x79, 0xBF, 0x3F, 0x2B, 0x24, 0xC7, 0xBD, 0x8F,
  439. 0x27, 0x7A, 0x1B, 0xE6, 0x77, 0x0D, 0xA1, 0xD9,
  440. 0x8B, 0x70, 0xC6, 0xD2, 0x8A, 0xE0, 0x1C, 0x55,
  441. 0x9E, 0xCB, 0xA6, 0xA0, 0x1D, 0xB0, 0x67, 0xC5,
  442. 0xA2, 0x7E, 0x4D, 0xB0, 0x8C, 0xDA, 0xDC, 0x77,
  443. 0x52, 0xAD, 0x63, 0x7E, 0xAF, 0x0A, 0x18, 0xED,
  444. 0x13, 0xFB, 0xAA, 0x14, 0x3B, 0xAF, 0xEF, 0x18,
  445. 0xF8, 0xFB, 0xCE, 0x4C, 0x65, 0xE8, 0x6B, 0xD0,
  446. 0x2A, 0x87, 0xB6, 0x01, 0xB7, 0xEA, 0xB9, 0x3F,
  447. 0x2B, 0xBC, 0x87, 0x4C, 0x8A, 0x71, 0x05, 0x80,
  448. 0xF5, 0x02, 0x34, 0x1A, 0x6A, 0x53, 0x39, 0x31,
  449. 0x43, 0xDE, 0x4C, 0x9E, 0xC6, 0xA2, 0x86, 0xF1,
  450. 0x25, 0x71, 0x83, 0x78, 0xAE, 0xDC, 0x84, 0xEB,
  451. 0xA2, 0xB3, 0x0F, 0x5C, 0x28, 0xBB, 0x5D, 0x75,
  452. 0xC6, 0xB0, 0x25, 0x46, 0x6D, 0x06, 0x51, 0xC7,
  453. 0x22, 0xDC, 0x71, 0x15, 0x1F, 0x21, 0x2D, 0x68,
  454. 0x87, 0x82, 0x8A, 0x03, 0x82, 0xE9, 0x28, 0x8A,
  455. 0x7F, 0x43, 0xD5, 0x2B, 0x7D, 0x25, 0x08, 0x61,
  456. 0x57, 0x64, 0x69, 0x54, 0xBB, 0x43, 0xB5, 0x7E,
  457. 0xA5, 0x87, 0xA0, 0x25, 0xF4, 0x0C, 0xE7, 0x45,
  458. 0x11, 0xE4, 0xDD, 0x22, 0x85, 0xB4, 0x0B, 0xA3,
  459. 0xF3, 0xB9, 0x62, 0x62, 0xCB, 0xC2, 0x8C, 0x6A,
  460. 0xA7, 0xBE, 0x44, 0x3E, 0x7B, 0x41, 0xE1, 0xEB,
  461. 0xFF, 0x52, 0x48, 0x57, 0xA6, 0x81, 0x68, 0x97,
  462. 0x75, 0x01, 0x15, 0xB0, 0x23, 0x1A, 0xB7, 0xC2,
  463. 0x84, 0x72, 0xC0, 0x6D, 0xD0, 0xB4, 0x9B, 0xE9,
  464. 0xF3, 0x69, 0xA8, 0xC3, 0x9C, 0xCD, 0x0D, 0xB7,
  465. 0x98, 0x35, 0x10, 0xE1, 0xAE, 0x8F, 0x05, 0xD7,
  466. 0x75, 0x45, 0xE0, 0x23, 0x5C, 0xDB, 0xD6, 0x12,
  467. 0xF3, 0x15, 0x07, 0x54, 0xCE, 0xE5, 0xCE, 0x6A,
  468. 0x12, 0x25, 0xD9, 0x95, 0x25, 0x02, 0x6F, 0x74
  469. }
  470. },
  471. {
  472. .tk = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
  473. 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f },
  474. .pn = { 0x00, 0x89, 0x5F, 0x5F, 0x2B, 0x08 },
  475. .frame = {
  476. 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
  477. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  478. 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
  479. 0x03, 0x00,
  480. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  481. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  482. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  483. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  484. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
  485. },
  486. .hdr_len = 26,
  487. .payload_len = 40,
  488. .mic = {
  489. 0xde, 0xf6, 0x19, 0xc2, 0xa3, 0x74, 0xb6, 0xdf,
  490. 0x66, 0xff, 0xa5, 0x3b, 0x6c, 0x69, 0xd7, 0x9e },
  491. .encr = {
  492. 0x60, 0xe9, 0x70, 0x0c, 0xc4, 0xd4, 0x0a, 0xc6,
  493. 0xd2, 0x88, 0xb2, 0x01, 0xc3, 0x8f, 0x5b, 0xf0,
  494. 0x8b, 0x80, 0x74, 0x42, 0x64, 0x0a, 0x15, 0x96,
  495. 0xe5, 0xdb, 0xda, 0xd4, 0x1d, 0x1f, 0x36, 0x23,
  496. 0xf4, 0x5d, 0x7a, 0x12, 0xdb, 0x7a, 0xfb, 0x23
  497. }
  498. }
  499. };
  500. static int run_gcmp(int idx, const struct gcmp_test *vector)
  501. {
  502. u8 *enc, *plain;
  503. size_t enc_len, plain_len;
  504. u8 fcs[4];
  505. int err = 0;
  506. wpa_printf(MSG_INFO,
  507. "\nIEEE Std 802.11ad-2012, M.11.1 GCMP test mpdu #%d\n",
  508. idx);
  509. wpa_hexdump(MSG_INFO, "TK", vector->tk, sizeof(vector->tk));
  510. wpa_hexdump(MSG_INFO, "PN", vector->pn, sizeof(vector->pn));
  511. wpa_hexdump(MSG_INFO, "802.11 Header", vector->frame, vector->hdr_len);
  512. wpa_hexdump(MSG_INFO, "Plaintext Data",
  513. vector->frame + vector->hdr_len,
  514. vector->payload_len);
  515. enc = gcmp_encrypt(vector->tk, sizeof(vector->tk),
  516. vector->frame,
  517. vector->hdr_len + vector->payload_len,
  518. vector->hdr_len,
  519. vector->hdr_len == 26 ?
  520. vector->frame + vector->hdr_len - 2 : NULL,
  521. vector->pn, 0, &enc_len);
  522. if (enc == NULL) {
  523. wpa_printf(MSG_ERROR, "Failed to encrypt GCMP frame");
  524. return 1;
  525. }
  526. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  527. if (os_memcmp(vector->encr, enc + vector->hdr_len + 8,
  528. vector->payload_len) != 0) {
  529. wpa_printf(MSG_ERROR, "GCMP test mpdu #%d enctypted data mismatch",
  530. idx);
  531. err++;
  532. }
  533. if (os_memcmp(vector->mic, enc + enc_len - sizeof(vector->mic),
  534. sizeof(vector->mic)) != 0) {
  535. wpa_printf(MSG_ERROR, "GCMP test mpdu #%d MIC mismatch", idx);
  536. err++;
  537. }
  538. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  539. wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
  540. wpa_debug_level = MSG_INFO;
  541. plain = gcmp_decrypt(vector->tk, sizeof(vector->tk),
  542. (const struct ieee80211_hdr *) enc,
  543. enc + vector->hdr_len,
  544. enc_len - vector->hdr_len, &plain_len);
  545. wpa_debug_level = MSG_EXCESSIVE;
  546. os_free(enc);
  547. if (plain == NULL) {
  548. wpa_printf(MSG_ERROR, "Failed to decrypt GCMP frame");
  549. return 1;
  550. }
  551. if (plain_len != vector->payload_len ||
  552. os_memcmp(plain, vector->frame + vector->hdr_len, plain_len) != 0) {
  553. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  554. plain, plain_len);
  555. err++;
  556. }
  557. os_free(plain);
  558. return err;
  559. }
  560. static int test_vector_gcmp(void)
  561. {
  562. int err = 0;
  563. int i;
  564. for (i = 0; i < ARRAY_SIZE(gcmp_vectors); i++) {
  565. if (run_gcmp(i + 1, &gcmp_vectors[i]))
  566. err++;
  567. }
  568. return err;
  569. }
  570. static int test_vector_gcmp_256(void)
  571. {
  572. u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
  573. 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f,
  574. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  575. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
  576. u8 pn[] = {
  577. 0x00, 0x89, 0x5F, 0x5F, 0x2B, 0x08
  578. };
  579. u8 frame[] = {
  580. 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
  581. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  582. 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
  583. 0x03, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
  584. 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
  585. 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
  586. 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
  587. 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
  588. 0x26, 0x27
  589. };
  590. u8 encr[] = {
  591. 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
  592. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  593. 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
  594. 0x03, 0x00, 0x08, 0x2b, 0x00, 0x20, 0x5f, 0x5f,
  595. 0x89, 0x00, 0x65, 0x83, 0x43, 0xc8, 0xb1, 0x44,
  596. 0x47, 0xd9, 0x21, 0x1d, 0xef, 0xd4, 0x6a, 0xd8,
  597. 0x9c, 0x71, 0x0c, 0x6f, 0xc3, 0x33, 0x33, 0x23,
  598. 0x6e, 0x39, 0x97, 0xb9, 0x17, 0x6a, 0x5a, 0x8b,
  599. 0xe7, 0x79, 0xb2, 0x12, 0x66, 0x55, 0x5e, 0x70,
  600. 0xad, 0x79, 0x11, 0x43, 0x16, 0x85, 0x90, 0x95,
  601. 0x47, 0x3d, 0x5b, 0x1b, 0xd5, 0x96, 0xb3, 0xde,
  602. 0xa3, 0xbf
  603. };
  604. u8 *enc, *plain;
  605. size_t enc_len, plain_len;
  606. u8 fcs[4];
  607. int err = 0;
  608. wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.11.1 GCMP-256 test vector\n");
  609. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  610. wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
  611. wpa_hexdump(MSG_INFO, "802.11 Header", frame, 26);
  612. wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 26, sizeof(frame) - 26);
  613. enc = gcmp_encrypt(tk, sizeof(tk), frame, sizeof(frame), 26, frame + 24,
  614. pn, 0, &enc_len);
  615. if (enc == NULL) {
  616. wpa_printf(MSG_ERROR, "Failed to encrypt GCMP frame");
  617. return 1;
  618. }
  619. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  620. if (enc_len != sizeof(encr) || os_memcmp(enc, encr, enc_len) != 0) {
  621. wpa_printf(MSG_ERROR, "GCMP-256 test vector mismatch");
  622. err++;
  623. }
  624. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  625. wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
  626. wpa_debug_level = MSG_INFO;
  627. plain = gcmp_decrypt(tk, sizeof(tk), (const struct ieee80211_hdr *) enc,
  628. enc + 26, enc_len - 26, &plain_len);
  629. wpa_debug_level = MSG_EXCESSIVE;
  630. os_free(enc);
  631. if (plain == NULL) {
  632. wpa_printf(MSG_ERROR, "Failed to decrypt GCMP frame");
  633. return 1;
  634. }
  635. if (plain_len != sizeof(frame) - 26 ||
  636. os_memcmp(plain, frame + 26, plain_len) != 0) {
  637. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  638. plain, plain_len);
  639. err++;
  640. }
  641. os_free(plain);
  642. return err;
  643. }
  644. static int test_vector_ccmp_256(void)
  645. {
  646. u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
  647. 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f,
  648. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  649. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
  650. u8 pn[] = { 0xB5, 0x03, 0x97, 0x76, 0xE7, 0x0C };
  651. u8 frame[] = {
  652. 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
  653. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  654. 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
  655. 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
  656. 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
  657. 0x7e, 0x78, 0xa0, 0x50
  658. };
  659. u8 encr[] = {
  660. 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
  661. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  662. 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
  663. 0x0c, 0xe7, 0x00, 0x20, 0x76, 0x97, 0x03, 0xb5,
  664. 0x6d, 0x15, 0x5d, 0x88, 0x32, 0x66, 0x82, 0x56,
  665. 0xd6, 0xa9, 0x2b, 0x78, 0xe1, 0x1d, 0x8e, 0x54,
  666. 0x49, 0x5d, 0xd1, 0x74, 0x80, 0xaa, 0x56, 0xc9,
  667. 0x49, 0x2e, 0x88, 0x2b, 0x97, 0x64, 0x2f, 0x80,
  668. 0xd5, 0x0f, 0xe9, 0x7b
  669. };
  670. u8 *enc, *plain;
  671. size_t enc_len, plain_len;
  672. u8 fcs[4];
  673. int err = 0;
  674. wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.6.4 CCMP-256 test vector\n");
  675. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  676. wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
  677. wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
  678. wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
  679. enc = ccmp_256_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0,
  680. &enc_len);
  681. if (enc == NULL) {
  682. wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
  683. return 1;
  684. }
  685. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  686. if (enc_len != sizeof(encr) || os_memcmp(enc, encr, enc_len) != 0) {
  687. wpa_printf(MSG_ERROR, "CCMP-256 test vector mismatch");
  688. err++;
  689. }
  690. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  691. wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
  692. wpa_debug_level = MSG_INFO;
  693. plain = ccmp_256_decrypt(tk, (const struct ieee80211_hdr *) enc,
  694. enc + 24, enc_len - 24, &plain_len);
  695. wpa_debug_level = MSG_EXCESSIVE;
  696. os_free(enc);
  697. if (plain == NULL) {
  698. wpa_printf(MSG_ERROR, "Failed to decrypt CCMP-256 frame");
  699. return 1;
  700. }
  701. if (plain_len != sizeof(frame) - 24 ||
  702. os_memcmp(plain, frame + 24, plain_len) != 0) {
  703. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  704. plain, plain_len);
  705. err++;
  706. }
  707. os_free(plain);
  708. return err;
  709. }
  710. static int test_vector_bip_gmac_128(void)
  711. {
  712. u8 igtk[] = {
  713. 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
  714. 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf
  715. };
  716. u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
  717. u8 frame[] = {
  718. 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  719. 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  720. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
  721. 0x02, 0x00
  722. };
  723. u8 res[] = {
  724. 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  725. 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  726. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
  727. 0x02, 0x00, 0x4c, 0x18, 0x04, 0x00, 0x04, 0x00,
  728. 0x00, 0x00, 0x00, 0x00, 0x3e, 0xd8, 0x62, 0xfb,
  729. 0x0f, 0x33, 0x38, 0xdd, 0x33, 0x86, 0xc8, 0x97,
  730. 0xe2, 0xed, 0x05, 0x3d
  731. };
  732. u8 *prot;
  733. size_t prot_len;
  734. int err = 0;
  735. wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.9.1 BIP-GMAC-128 with broadcast "
  736. "Deauthentication frame\n");
  737. wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
  738. wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
  739. wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
  740. prot = bip_gmac_protect(igtk, sizeof(igtk), frame, sizeof(frame),
  741. ipn, 4, &prot_len);
  742. if (prot == NULL) {
  743. wpa_printf(MSG_ERROR, "Failed to protect BIP-GMAC-128 frame");
  744. return 1;
  745. }
  746. wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
  747. if (prot_len != sizeof(res) || os_memcmp(res, prot, prot_len) != 0) {
  748. wpa_printf(MSG_ERROR, "BIP-GMAC-128 test vector mismatch");
  749. err++;
  750. }
  751. os_free(prot);
  752. return err;
  753. }
  754. static int test_vector_bip_gmac_256(void)
  755. {
  756. u8 igtk[] = {
  757. 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
  758. 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf,
  759. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  760. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  761. };
  762. u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
  763. u8 frame[] = {
  764. 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  765. 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  766. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
  767. 0x02, 0x00
  768. };
  769. u8 res[] = {
  770. 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  771. 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  772. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
  773. 0x02, 0x00, 0x4c, 0x18, 0x04, 0x00, 0x04, 0x00,
  774. 0x00, 0x00, 0x00, 0x00, 0x23, 0xbe, 0x59, 0xdc,
  775. 0xc7, 0x02, 0x2e, 0xe3, 0x83, 0x62, 0x7e, 0xbb,
  776. 0x10, 0x17, 0xdd, 0xfc
  777. };
  778. u8 *prot;
  779. size_t prot_len;
  780. int err = 0;
  781. wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.9.1 BIP-GMAC-256 with broadcast Deauthentication frame\n");
  782. wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
  783. wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
  784. wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
  785. prot = bip_gmac_protect(igtk, sizeof(igtk), frame, sizeof(frame),
  786. ipn, 4, &prot_len);
  787. if (prot == NULL) {
  788. wpa_printf(MSG_ERROR, "Failed to protect BIP-GMAC-256 frame");
  789. return 1;
  790. }
  791. wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
  792. if (prot_len != sizeof(res) || os_memcmp(res, prot, prot_len) != 0) {
  793. wpa_printf(MSG_ERROR, "BIP-GMAC-128 test vector mismatch");
  794. err++;
  795. }
  796. os_free(prot);
  797. return err;
  798. }
  799. int main(int argc, char *argv[])
  800. {
  801. int errors = 0;
  802. wpa_debug_level = MSG_EXCESSIVE;
  803. wpa_debug_show_keys = 1;
  804. if (os_program_init())
  805. return -1;
  806. test_vector_tkip();
  807. test_vector_ccmp();
  808. test_vector_ccmp_pv1();
  809. test_vector_bip();
  810. test_vector_ccmp_mgmt();
  811. errors += test_vector_gcmp();
  812. errors += test_vector_gcmp_256();
  813. errors += test_vector_ccmp_256();
  814. errors += test_vector_bip_gmac_128();
  815. errors += test_vector_bip_gmac_256();
  816. if (errors)
  817. wpa_printf(MSG_INFO, "One or more test vectors failed");
  818. os_program_deinit();
  819. return errors ? -1 : 0;
  820. }