test_vectors.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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/eloop.h"
  11. #include "wlantest.h"
  12. static void test_vector_tkip(void)
  13. {
  14. u8 tk[] = {
  15. 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56,
  16. 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12,
  17. 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78,
  18. 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34
  19. };
  20. u8 pn[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
  21. u8 frame[] = {
  22. 0x08, 0x42, 0x2c, 0x00, 0x02, 0x03, 0x04, 0x05,
  23. 0x06, 0x08, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  24. 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xd0, 0x02,
  25. /* 0x00, 0x20, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, */
  26. 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00,
  27. 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
  28. 0x40, 0x01, 0xa5, 0x55, 0xc0, 0xa8, 0x0a, 0x02,
  29. 0xc0, 0xa8, 0x0a, 0x01, 0x08, 0x00, 0x3a, 0xb0,
  30. 0x00, 0x00, 0x00, 0x00, 0xcd, 0x4c, 0x05, 0x00,
  31. 0x00, 0x00, 0x00, 0x00, 0x08, 0x09, 0x0a, 0x0b,
  32. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
  33. 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
  34. 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  35. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
  36. 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
  37. 0x34, 0x35, 0x36, 0x37,
  38. /* 0x68, 0x81, 0xa3, 0xf3, 0xd6, 0x48, 0xd0, 0x3c */
  39. };
  40. u8 *enc, *plain;
  41. size_t enc_len, plain_len;
  42. wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.6.3 TKIP test "
  43. "vector\n");
  44. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  45. wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
  46. wpa_hexdump(MSG_INFO, "Plaintext MPDU", frame, sizeof(frame));
  47. enc = tkip_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
  48. if (enc == NULL) {
  49. wpa_printf(MSG_ERROR, "Failed to encrypt TKIP frame");
  50. return;
  51. }
  52. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  53. wpa_debug_level = MSG_INFO;
  54. plain = tkip_decrypt(tk, (const struct ieee80211_hdr *) enc,
  55. enc + 24, enc_len - 24, &plain_len);
  56. wpa_debug_level = MSG_EXCESSIVE;
  57. os_free(enc);
  58. if (plain == NULL) {
  59. wpa_printf(MSG_ERROR, "Failed to decrypt TKIP frame");
  60. return;
  61. }
  62. if (plain_len != sizeof(frame) - 24 ||
  63. os_memcmp(plain, frame + 24, plain_len) != 0) {
  64. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  65. plain, plain_len);
  66. }
  67. os_free(plain);
  68. }
  69. static void test_vector_ccmp(void)
  70. {
  71. u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
  72. 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f };
  73. u8 pn[] = { 0xB5, 0x03, 0x97, 0x76, 0xE7, 0x0C };
  74. u8 frame[] = {
  75. 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
  76. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  77. 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
  78. 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
  79. 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
  80. 0x7e, 0x78, 0xa0, 0x50
  81. };
  82. u8 *enc, *plain;
  83. size_t enc_len, plain_len;
  84. u8 fcs[4];
  85. wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.6.4 CCMP test "
  86. "vector\n");
  87. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  88. wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
  89. wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
  90. wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
  91. enc = ccmp_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
  92. if (enc == NULL) {
  93. wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
  94. return;
  95. }
  96. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  97. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  98. wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
  99. wpa_debug_level = MSG_INFO;
  100. plain = ccmp_decrypt(tk, (const struct ieee80211_hdr *) enc,
  101. enc + 24, enc_len - 24, &plain_len);
  102. wpa_debug_level = MSG_EXCESSIVE;
  103. os_free(enc);
  104. if (plain == NULL) {
  105. wpa_printf(MSG_ERROR, "Failed to decrypt CCMP frame");
  106. return;
  107. }
  108. if (plain_len != sizeof(frame) - 24 ||
  109. os_memcmp(plain, frame + 24, plain_len) != 0) {
  110. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  111. plain, plain_len);
  112. }
  113. os_free(plain);
  114. }
  115. static void test_vector_bip(void)
  116. {
  117. u8 igtk[] = {
  118. 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
  119. 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf
  120. };
  121. u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
  122. u8 frame[] = {
  123. 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  124. 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  125. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
  126. 0x02, 0x00
  127. };
  128. u8 *prot;
  129. size_t prot_len;
  130. wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.9.1 BIP with broadcast "
  131. "Deauthentication frame\n");
  132. wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
  133. wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
  134. wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
  135. prot = bip_protect(igtk, sizeof(igtk), frame, sizeof(frame),
  136. ipn, 4, &prot_len);
  137. if (prot == NULL) {
  138. wpa_printf(MSG_ERROR, "Failed to protect BIP frame");
  139. return;
  140. }
  141. wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
  142. os_free(prot);
  143. }
  144. static void test_vector_ccmp_mgmt(void)
  145. {
  146. u8 tk[] = { 0x66, 0xed, 0x21, 0x04, 0x2f, 0x9f, 0x26, 0xd7,
  147. 0x11, 0x57, 0x06, 0xe4, 0x04, 0x14, 0xcf, 0x2e };
  148. u8 pn[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
  149. u8 frame[] = {
  150. 0xc0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  151. 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  152. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  153. 0x02, 0x00
  154. };
  155. u8 *enc, *plain;
  156. size_t enc_len, plain_len;
  157. wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.9.2 CCMP with unicast "
  158. "Deauthentication frame\n");
  159. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  160. wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
  161. wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
  162. wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
  163. enc = ccmp_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
  164. if (enc == NULL) {
  165. wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
  166. return;
  167. }
  168. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  169. wpa_debug_level = MSG_INFO;
  170. plain = ccmp_decrypt(tk, (const struct ieee80211_hdr *) enc,
  171. enc + 24, enc_len - 24, &plain_len);
  172. wpa_debug_level = MSG_EXCESSIVE;
  173. os_free(enc);
  174. if (plain == NULL) {
  175. wpa_printf(MSG_ERROR, "Failed to decrypt CCMP frame");
  176. return;
  177. }
  178. if (plain_len != sizeof(frame) - 24 ||
  179. os_memcmp(plain, frame + 24, plain_len) != 0) {
  180. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  181. plain, plain_len);
  182. }
  183. os_free(plain);
  184. }
  185. struct gcmp_test {
  186. u8 tk[16];
  187. u8 pn[6];
  188. u8 frame[300];
  189. size_t hdr_len;
  190. size_t payload_len;
  191. u8 mic[16];
  192. u8 encr[300];
  193. };
  194. static struct gcmp_test gcmp_vectors[] =
  195. {
  196. {
  197. .tk = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  198. 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa },
  199. .pn = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
  200. .frame = {
  201. 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  202. 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  203. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
  204. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  205. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  206. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  207. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  208. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  209. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  210. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  211. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  212. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  213. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  214. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  215. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  216. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  217. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  218. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  219. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  220. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  221. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  222. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  223. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  224. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  225. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  226. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  227. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  228. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  229. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  230. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  231. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  232. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  233. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  234. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  235. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  236. },
  237. .hdr_len = 24,
  238. .payload_len = 256,
  239. .mic = {
  240. 0x80, 0xCB, 0x06, 0x62, 0xEA, 0x71, 0xAB, 0xFD,
  241. 0x9F, 0x04, 0xC7, 0xF8, 0x72, 0xF5, 0x80, 0x90 },
  242. .encr = {
  243. 0x5F, 0x55, 0x78, 0xC1, 0x8F, 0x13, 0x7A, 0xD2,
  244. 0x79, 0xBF, 0x3F, 0x2B, 0x24, 0xC7, 0xBD, 0x8F,
  245. 0x27, 0x7A, 0x1B, 0xE6, 0x77, 0x0D, 0xA1, 0xD9,
  246. 0x8B, 0x70, 0xC6, 0xD2, 0x8A, 0xE0, 0x1C, 0x55,
  247. 0x9E, 0xCB, 0xA6, 0xA0, 0x1D, 0xB0, 0x67, 0xC5,
  248. 0xA2, 0x7E, 0x4D, 0xB0, 0x8C, 0xDA, 0xDC, 0x77,
  249. 0x52, 0xAD, 0x63, 0x7E, 0xAF, 0x0A, 0x18, 0xED,
  250. 0x13, 0xFB, 0xAA, 0x14, 0x3B, 0xAF, 0xEF, 0x18,
  251. 0xF8, 0xFB, 0xCE, 0x4C, 0x65, 0xE8, 0x6B, 0xD0,
  252. 0x2A, 0x87, 0xB6, 0x01, 0xB7, 0xEA, 0xB9, 0x3F,
  253. 0x2B, 0xBC, 0x87, 0x4C, 0x8A, 0x71, 0x05, 0x80,
  254. 0xF5, 0x02, 0x34, 0x1A, 0x6A, 0x53, 0x39, 0x31,
  255. 0x43, 0xDE, 0x4C, 0x9E, 0xC6, 0xA2, 0x86, 0xF1,
  256. 0x25, 0x71, 0x83, 0x78, 0xAE, 0xDC, 0x84, 0xEB,
  257. 0xA2, 0xB3, 0x0F, 0x5C, 0x28, 0xBB, 0x5D, 0x75,
  258. 0xC6, 0xB0, 0x25, 0x46, 0x6D, 0x06, 0x51, 0xC7,
  259. 0x22, 0xDC, 0x71, 0x15, 0x1F, 0x21, 0x2D, 0x68,
  260. 0x87, 0x82, 0x8A, 0x03, 0x82, 0xE9, 0x28, 0x8A,
  261. 0x7F, 0x43, 0xD5, 0x2B, 0x7D, 0x25, 0x08, 0x61,
  262. 0x57, 0x64, 0x69, 0x54, 0xBB, 0x43, 0xB5, 0x7E,
  263. 0xA5, 0x87, 0xA0, 0x25, 0xF4, 0x0C, 0xE7, 0x45,
  264. 0x11, 0xE4, 0xDD, 0x22, 0x85, 0xB4, 0x0B, 0xA3,
  265. 0xF3, 0xB9, 0x62, 0x62, 0xCB, 0xC2, 0x8C, 0x6A,
  266. 0xA7, 0xBE, 0x44, 0x3E, 0x7B, 0x41, 0xE1, 0xEB,
  267. 0xFF, 0x52, 0x48, 0x57, 0xA6, 0x81, 0x68, 0x97,
  268. 0x75, 0x01, 0x15, 0xB0, 0x23, 0x1A, 0xB7, 0xC2,
  269. 0x84, 0x72, 0xC0, 0x6D, 0xD0, 0xB4, 0x9B, 0xE9,
  270. 0xF3, 0x69, 0xA8, 0xC3, 0x9C, 0xCD, 0x0D, 0xB7,
  271. 0x98, 0x35, 0x10, 0xE1, 0xAE, 0x8F, 0x05, 0xD7,
  272. 0x75, 0x45, 0xE0, 0x23, 0x5C, 0xDB, 0xD6, 0x12,
  273. 0xF3, 0x15, 0x07, 0x54, 0xCE, 0xE5, 0xCE, 0x6A,
  274. 0x12, 0x25, 0xD9, 0x95, 0x25, 0x02, 0x6F, 0x74
  275. }
  276. },
  277. {
  278. .tk = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
  279. 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f },
  280. .pn = { 0x00, 0x89, 0x5F, 0x5F, 0x2B, 0x08 },
  281. .frame = {
  282. 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
  283. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  284. 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
  285. 0x03, 0x00,
  286. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  287. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  288. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  289. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  290. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
  291. },
  292. .hdr_len = 26,
  293. .payload_len = 40,
  294. .mic = {
  295. 0xde, 0xf6, 0x19, 0xc2, 0xa3, 0x74, 0xb6, 0xdf,
  296. 0x66, 0xff, 0xa5, 0x3b, 0x6c, 0x69, 0xd7, 0x9e },
  297. .encr = {
  298. 0x60, 0xe9, 0x70, 0x0c, 0xc4, 0xd4, 0x0a, 0xc6,
  299. 0xd2, 0x88, 0xb2, 0x01, 0xc3, 0x8f, 0x5b, 0xf0,
  300. 0x8b, 0x80, 0x74, 0x42, 0x64, 0x0a, 0x15, 0x96,
  301. 0xe5, 0xdb, 0xda, 0xd4, 0x1d, 0x1f, 0x36, 0x23,
  302. 0xf4, 0x5d, 0x7a, 0x12, 0xdb, 0x7a, 0xfb, 0x23
  303. }
  304. }
  305. };
  306. static int run_gcmp(int idx, struct gcmp_test *vector)
  307. {
  308. u8 *enc, *plain;
  309. size_t enc_len, plain_len;
  310. u8 fcs[4];
  311. int err = 0;
  312. wpa_printf(MSG_INFO,
  313. "\nIEEE Std 802.11ad-2012, M.11.1 GCMP test mpdu #%d\n",
  314. idx);
  315. wpa_hexdump(MSG_INFO, "TK", vector->tk, sizeof(vector->tk));
  316. wpa_hexdump(MSG_INFO, "PN", vector->pn, sizeof(vector->pn));
  317. wpa_hexdump(MSG_INFO, "802.11 Header", vector->frame, vector->hdr_len);
  318. wpa_hexdump(MSG_INFO, "Plaintext Data",
  319. vector->frame + vector->hdr_len,
  320. vector->payload_len);
  321. enc = gcmp_encrypt(vector->tk, sizeof(vector->tk),
  322. vector->frame,
  323. vector->hdr_len + vector->payload_len,
  324. vector->hdr_len,
  325. vector->hdr_len == 26 ?
  326. vector->frame + vector->hdr_len - 2 : NULL,
  327. vector->pn, 0, &enc_len);
  328. if (enc == NULL) {
  329. wpa_printf(MSG_ERROR, "Failed to encrypt GCMP frame");
  330. return 1;
  331. }
  332. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  333. if (os_memcmp(vector->encr, enc + vector->hdr_len + 8,
  334. vector->payload_len) != 0) {
  335. wpa_printf(MSG_ERROR, "GCMP test mpdu #%d enctypted data mismatch",
  336. idx);
  337. err++;
  338. }
  339. if (os_memcmp(vector->mic, enc + enc_len - sizeof(vector->mic),
  340. sizeof(vector->mic)) != 0) {
  341. wpa_printf(MSG_ERROR, "GCMP test mpdu #%d MIC mismatch", idx);
  342. err++;
  343. }
  344. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  345. wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
  346. wpa_debug_level = MSG_INFO;
  347. plain = gcmp_decrypt(vector->tk, sizeof(vector->tk),
  348. (const struct ieee80211_hdr *) enc,
  349. enc + vector->hdr_len,
  350. enc_len - vector->hdr_len, &plain_len);
  351. wpa_debug_level = MSG_EXCESSIVE;
  352. os_free(enc);
  353. if (plain == NULL) {
  354. wpa_printf(MSG_ERROR, "Failed to decrypt GCMP frame");
  355. return 1;
  356. }
  357. if (plain_len != vector->payload_len ||
  358. os_memcmp(plain, vector->frame + vector->hdr_len, plain_len) != 0) {
  359. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  360. plain, plain_len);
  361. err++;
  362. }
  363. os_free(plain);
  364. return err;
  365. }
  366. static int test_vector_gcmp(void)
  367. {
  368. int err = 0;
  369. int i;
  370. for (i = 0; i < ARRAY_SIZE(gcmp_vectors); i++) {
  371. if (run_gcmp(i + 1, &gcmp_vectors[i]))
  372. err++;
  373. }
  374. return err;
  375. }
  376. static int test_vector_gcmp_256(void)
  377. {
  378. u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
  379. 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f,
  380. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  381. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
  382. u8 pn[] = {
  383. 0x00, 0x89, 0x5F, 0x5F, 0x2B, 0x08
  384. };
  385. u8 frame[] = {
  386. 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
  387. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  388. 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
  389. 0x03, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
  390. 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
  391. 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
  392. 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
  393. 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
  394. 0x26, 0x27
  395. };
  396. u8 encr[] = {
  397. 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
  398. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  399. 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
  400. 0x03, 0x00, 0x08, 0x2b, 0x00, 0x20, 0x5f, 0x5f,
  401. 0x89, 0x00, 0x65, 0x83, 0x43, 0xc8, 0xb1, 0x44,
  402. 0x47, 0xd9, 0x21, 0x1d, 0xef, 0xd4, 0x6a, 0xd8,
  403. 0x9c, 0x71, 0x0c, 0x6f, 0xc3, 0x33, 0x33, 0x23,
  404. 0x6e, 0x39, 0x97, 0xb9, 0x17, 0x6a, 0x5a, 0x8b,
  405. 0xe7, 0x79, 0xb2, 0x12, 0x66, 0x55, 0x5e, 0x70,
  406. 0xad, 0x79, 0x11, 0x43, 0x16, 0x85, 0x90, 0x95,
  407. 0x47, 0x3d, 0x5b, 0x1b, 0xd5, 0x96, 0xb3, 0xde,
  408. 0xa3, 0xbf
  409. };
  410. u8 *enc, *plain;
  411. size_t enc_len, plain_len;
  412. u8 fcs[4];
  413. int err = 0;
  414. wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.11.1 GCMP-256 test vector\n");
  415. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  416. wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
  417. wpa_hexdump(MSG_INFO, "802.11 Header", frame, 26);
  418. wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 26, sizeof(frame) - 26);
  419. enc = gcmp_encrypt(tk, sizeof(tk), frame, sizeof(frame), 26, frame + 24,
  420. pn, 0, &enc_len);
  421. if (enc == NULL) {
  422. wpa_printf(MSG_ERROR, "Failed to encrypt GCMP frame");
  423. return 1;
  424. }
  425. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  426. if (enc_len != sizeof(encr) || os_memcmp(enc, encr, enc_len) != 0) {
  427. wpa_printf(MSG_ERROR, "GCMP-256 test vector mismatch");
  428. err++;
  429. }
  430. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  431. wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
  432. wpa_debug_level = MSG_INFO;
  433. plain = gcmp_decrypt(tk, sizeof(tk), (const struct ieee80211_hdr *) enc,
  434. enc + 26, enc_len - 26, &plain_len);
  435. wpa_debug_level = MSG_EXCESSIVE;
  436. os_free(enc);
  437. if (plain == NULL) {
  438. wpa_printf(MSG_ERROR, "Failed to decrypt GCMP frame");
  439. return 1;
  440. }
  441. if (plain_len != sizeof(frame) - 26 ||
  442. os_memcmp(plain, frame + 26, plain_len) != 0) {
  443. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  444. plain, plain_len);
  445. err++;
  446. }
  447. os_free(plain);
  448. return err;
  449. }
  450. static int test_vector_ccmp_256(void)
  451. {
  452. u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
  453. 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f,
  454. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  455. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
  456. u8 pn[] = { 0xB5, 0x03, 0x97, 0x76, 0xE7, 0x0C };
  457. u8 frame[] = {
  458. 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
  459. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  460. 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
  461. 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
  462. 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
  463. 0x7e, 0x78, 0xa0, 0x50
  464. };
  465. u8 encr[] = {
  466. 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
  467. 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
  468. 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
  469. 0x0c, 0xe7, 0x00, 0x20, 0x76, 0x97, 0x03, 0xb5,
  470. 0x6d, 0x15, 0x5d, 0x88, 0x32, 0x66, 0x82, 0x56,
  471. 0xd6, 0xa9, 0x2b, 0x78, 0xe1, 0x1d, 0x8e, 0x54,
  472. 0x49, 0x5d, 0xd1, 0x74, 0x80, 0xaa, 0x56, 0xc9,
  473. 0x49, 0x2e, 0x88, 0x2b, 0x97, 0x64, 0x2f, 0x80,
  474. 0xd5, 0x0f, 0xe9, 0x7b
  475. };
  476. u8 *enc, *plain;
  477. size_t enc_len, plain_len;
  478. u8 fcs[4];
  479. int err = 0;
  480. wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.6.4 CCMP-256 test vector\n");
  481. wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
  482. wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
  483. wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
  484. wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
  485. enc = ccmp_256_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0,
  486. &enc_len);
  487. if (enc == NULL) {
  488. wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
  489. return 1;
  490. }
  491. wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
  492. if (enc_len != sizeof(encr) || os_memcmp(enc, encr, enc_len) != 0) {
  493. wpa_printf(MSG_ERROR, "CCMP-256 test vector mismatch");
  494. err++;
  495. }
  496. WPA_PUT_LE32(fcs, crc32(enc, enc_len));
  497. wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
  498. wpa_debug_level = MSG_INFO;
  499. plain = ccmp_256_decrypt(tk, (const struct ieee80211_hdr *) enc,
  500. enc + 24, enc_len - 24, &plain_len);
  501. wpa_debug_level = MSG_EXCESSIVE;
  502. os_free(enc);
  503. if (plain == NULL) {
  504. wpa_printf(MSG_ERROR, "Failed to decrypt CCMP-256 frame");
  505. return 1;
  506. }
  507. if (plain_len != sizeof(frame) - 24 ||
  508. os_memcmp(plain, frame + 24, plain_len) != 0) {
  509. wpa_hexdump(MSG_ERROR, "Decryption result did not match",
  510. plain, plain_len);
  511. err++;
  512. }
  513. os_free(plain);
  514. return err;
  515. }
  516. static int test_vector_bip_gmac_128(void)
  517. {
  518. u8 igtk[] = {
  519. 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
  520. 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf
  521. };
  522. u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
  523. u8 frame[] = {
  524. 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  525. 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  526. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
  527. 0x02, 0x00
  528. };
  529. u8 res[] = {
  530. 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  531. 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  532. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
  533. 0x02, 0x00, 0x4c, 0x18, 0x04, 0x00, 0x04, 0x00,
  534. 0x00, 0x00, 0x00, 0x00, 0x3e, 0xd8, 0x62, 0xfb,
  535. 0x0f, 0x33, 0x38, 0xdd, 0x33, 0x86, 0xc8, 0x97,
  536. 0xe2, 0xed, 0x05, 0x3d
  537. };
  538. u8 *prot;
  539. size_t prot_len;
  540. int err = 0;
  541. wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.9.1 BIP-GMAC-128 with broadcast "
  542. "Deauthentication frame\n");
  543. wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
  544. wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
  545. wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
  546. prot = bip_gmac_protect(igtk, sizeof(igtk), frame, sizeof(frame),
  547. ipn, 4, &prot_len);
  548. if (prot == NULL) {
  549. wpa_printf(MSG_ERROR, "Failed to protect BIP-GMAC-128 frame");
  550. return 1;
  551. }
  552. wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
  553. if (prot_len != sizeof(res) || os_memcmp(res, prot, prot_len) != 0) {
  554. wpa_printf(MSG_ERROR, "BIP-GMAC-128 test vector mismatch");
  555. err++;
  556. }
  557. os_free(prot);
  558. return err;
  559. }
  560. static int test_vector_bip_gmac_256(void)
  561. {
  562. u8 igtk[] = {
  563. 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
  564. 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf,
  565. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  566. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  567. };
  568. u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
  569. u8 frame[] = {
  570. 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  571. 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  572. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
  573. 0x02, 0x00
  574. };
  575. u8 res[] = {
  576. 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
  577. 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  578. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
  579. 0x02, 0x00, 0x4c, 0x18, 0x04, 0x00, 0x04, 0x00,
  580. 0x00, 0x00, 0x00, 0x00, 0x23, 0xbe, 0x59, 0xdc,
  581. 0xc7, 0x02, 0x2e, 0xe3, 0x83, 0x62, 0x7e, 0xbb,
  582. 0x10, 0x17, 0xdd, 0xfc
  583. };
  584. u8 *prot;
  585. size_t prot_len;
  586. int err = 0;
  587. wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.9.1 BIP-GMAC-256 with broadcast Deauthentication frame\n");
  588. wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
  589. wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
  590. wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
  591. prot = bip_gmac_protect(igtk, sizeof(igtk), frame, sizeof(frame),
  592. ipn, 4, &prot_len);
  593. if (prot == NULL) {
  594. wpa_printf(MSG_ERROR, "Failed to protect BIP-GMAC-256 frame");
  595. return 1;
  596. }
  597. wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
  598. if (prot_len != sizeof(res) || os_memcmp(res, prot, prot_len) != 0) {
  599. wpa_printf(MSG_ERROR, "BIP-GMAC-128 test vector mismatch");
  600. err++;
  601. }
  602. os_free(prot);
  603. return err;
  604. }
  605. int main(int argc, char *argv[])
  606. {
  607. int errors = 0;
  608. wpa_debug_level = MSG_EXCESSIVE;
  609. wpa_debug_show_keys = 1;
  610. if (os_program_init())
  611. return -1;
  612. test_vector_tkip();
  613. test_vector_ccmp();
  614. test_vector_bip();
  615. test_vector_ccmp_mgmt();
  616. errors += test_vector_gcmp();
  617. errors += test_vector_gcmp_256();
  618. errors += test_vector_ccmp_256();
  619. errors += test_vector_bip_gmac_128();
  620. errors += test_vector_bip_gmac_256();
  621. if (errors)
  622. wpa_printf(MSG_INFO, "One or more test vectors failed");
  623. os_program_deinit();
  624. return errors ? -1 : 0;
  625. }