xref: /freebsd/tools/regression/net80211/ccmp/test_ccmp.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
12efe996bSSam Leffler /*-
22efe996bSSam Leffler  * Copyright (c) 2004 Sam Leffler, Errno Consulting
32efe996bSSam Leffler  * All rights reserved.
42efe996bSSam Leffler  *
52efe996bSSam Leffler  * Redistribution and use in source and binary forms, with or without
62efe996bSSam Leffler  * modification, are permitted provided that the following conditions
72efe996bSSam Leffler  * are met:
82efe996bSSam Leffler  * 1. Redistributions of source code must retain the above copyright
92efe996bSSam Leffler  *    notice, this list of conditions and the following disclaimer.
102efe996bSSam Leffler  * 2. Redistributions in binary form must reproduce the above copyright
112efe996bSSam Leffler  *    notice, this list of conditions and the following disclaimer in the
122efe996bSSam Leffler  *    documentation and/or other materials provided with the distribution.
132efe996bSSam Leffler  * 3. The name of the author may not be used to endorse or promote products
142efe996bSSam Leffler  *    derived from this software without specific prior written permission.
152efe996bSSam Leffler  *
162efe996bSSam Leffler  * Alternatively, this software may be distributed under the terms of the
172efe996bSSam Leffler  * GNU General Public License ("GPL") version 2 as published by the Free
182efe996bSSam Leffler  * Software Foundation.
192efe996bSSam Leffler  *
202efe996bSSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
212efe996bSSam Leffler  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
222efe996bSSam Leffler  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
232efe996bSSam Leffler  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
242efe996bSSam Leffler  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
252efe996bSSam Leffler  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
262efe996bSSam Leffler  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
272efe996bSSam Leffler  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
282efe996bSSam Leffler  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
292efe996bSSam Leffler  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
302efe996bSSam Leffler  */
312efe996bSSam Leffler 
322efe996bSSam Leffler /*
332efe996bSSam Leffler  * CCMP test module.
342efe996bSSam Leffler  *
352efe996bSSam Leffler  * Test vectors come from section I.7.4 of P802.11i/D7.0, October 2003.
362efe996bSSam Leffler  *
372efe996bSSam Leffler  * To use this tester load the net80211 layer (either as a module or
382efe996bSSam Leffler  * by statically configuring it into your kernel), then kldload this
392efe996bSSam Leffler  * module.  It should automatically run all test cases and print
402efe996bSSam Leffler  * information for each.  To run one or more tests you can specify a
412efe996bSSam Leffler  * tests parameter to the module that is a bit mask of the set of tests
422efe996bSSam Leffler  * you want; e.g. insmod ccmp_test tests=7 will run only test mpdu's
432efe996bSSam Leffler  * 1, 2, and 3.
442efe996bSSam Leffler  */
452efe996bSSam Leffler #include <sys/param.h>
462efe996bSSam Leffler #include <sys/kernel.h>
472efe996bSSam Leffler #include <sys/systm.h>
482efe996bSSam Leffler #include <sys/mbuf.h>
492efe996bSSam Leffler #include <sys/module.h>
502efe996bSSam Leffler 
512efe996bSSam Leffler #include <sys/socket.h>
522efe996bSSam Leffler 
532efe996bSSam Leffler #include <net/if.h>
54*3c64fc9cSAndriy Voskoboinyk #include <net/if_var.h>
552efe996bSSam Leffler #include <net/if_media.h>
562efe996bSSam Leffler 
572efe996bSSam Leffler #include <net80211/ieee80211_var.h>
582efe996bSSam Leffler 
592efe996bSSam Leffler /*
602efe996bSSam Leffler ==== CCMP test mpdu   1 ====
612efe996bSSam Leffler 
622efe996bSSam Leffler -- MPDU Fields
632efe996bSSam Leffler 
642efe996bSSam Leffler 7  Version  = 0
652efe996bSSam Leffler 8  Type     = 2   SubType  = 0  Data
662efe996bSSam Leffler 9  ToDS     = 0   FromDS   = 0
672efe996bSSam Leffler 10  MoreFrag = 0   Retry    = 1
682efe996bSSam Leffler 11  PwrMgt   = 0   moreData = 0
692efe996bSSam Leffler 12  Encrypt  = 1
702efe996bSSam Leffler 13  Order    = 0
712efe996bSSam Leffler 14  Duration = 11459
722efe996bSSam Leffler 15  A1 = 0f-d2-e1-28-a5-7c    DA
732efe996bSSam Leffler 16  A2 = 50-30-f1-84-44-08    SA
742efe996bSSam Leffler 17  A3 = ab-ae-a5-b8-fc-ba    BSSID
752efe996bSSam Leffler 18  SC = 0x3380
762efe996bSSam Leffler 19  seqNum = 824 (0x0338)  fraqNum = 0 (0x00)
772efe996bSSam Leffler 20  Algorithm = AES_CCM
782efe996bSSam Leffler 21  Key ID = 0
792efe996bSSam Leffler 22  TK = c9 7c 1f 67 ce 37 11 85  51 4a 8a 19 f2 bd d5 2f
802efe996bSSam Leffler 23  PN = 199027030681356  (0xB5039776E70C)
812efe996bSSam Leffler 24  802.11 Header =  08 48 c3 2c 0f d2 e1 28 a5 7c 50 30 f1 84 44 08
822efe996bSSam Leffler 25  	ab ae a5 b8 fc ba 80 33
832efe996bSSam Leffler 26  Muted 802.11 Header =  08 40 0f d2 e1 28 a5 7c 50 30 f1 84 44 08
842efe996bSSam Leffler 27  	ab ae a5 b8 fc ba 00 00
852efe996bSSam Leffler 28  CCMP Header =  0c e7 00 20 76 97 03 b5
862efe996bSSam Leffler 29  CCM Nonce = 00 50 30 f1 84 44 08 b5  03 97 76 e7 0c
872efe996bSSam Leffler 30 Plaintext Data = f8 ba 1a 55 d0 2f 85 ae 96 7b b6 2f b6 cd a8 eb
882efe996bSSam Leffler 1	7e 78 a0 50
892efe996bSSam Leffler 2  CCM MIC =  78 45 ce 0b 16 f9 76 23
902efe996bSSam Leffler 3  -- Encrypted MPDU with FCS
912efe996bSSam Leffler 4  08 48 c3 2c 0f d2 e1 28 a5 7c 50 30 f1 84 44 08 ab ae a5 b8 fc ba
922efe996bSSam Leffler 5  80 33 0c e7 00 20 76 97 03 b5 f3 d0 a2 fe 9a 3d bf 23 42 a6 43 e4
932efe996bSSam Leffler 6  32 46 e8 0c 3c 04 d0 19 78 45 ce 0b 16 f9 76 23 1d 99 f0 66
942efe996bSSam Leffler */
952efe996bSSam Leffler static const u_int8_t test1_key[] = {		/* TK */
962efe996bSSam Leffler 	0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,  0x51, 0x4a, 0x8a,
972efe996bSSam Leffler 	0x19, 0xf2, 0xbd, 0xd5, 0x2f
982efe996bSSam Leffler };
992efe996bSSam Leffler static const u_int8_t test1_plaintext[] = {	/* Plaintext MPDU w/o MIC */
1002efe996bSSam Leffler 	0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,	/* 802.11 Header */
1012efe996bSSam Leffler 	0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
1022efe996bSSam Leffler 	0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
1032efe996bSSam Leffler 	0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,	/* Plaintext Data */
1042efe996bSSam Leffler 	0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
1052efe996bSSam Leffler 	0x7e, 0x78, 0xa0, 0x50,
1062efe996bSSam Leffler };
1072efe996bSSam Leffler static const u_int8_t test1_encrypted[] = {	/* Encrypted MPDU with MIC */
1082efe996bSSam Leffler 	0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
1092efe996bSSam Leffler 	0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
1102efe996bSSam Leffler 	0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
1112efe996bSSam Leffler 	0x0c, 0xe7, 0x00, 0x20, 0x76, 0x97, 0x03, 0xb5,
1122efe996bSSam Leffler 	0xf3, 0xd0, 0xa2, 0xfe, 0x9a, 0x3d, 0xbf, 0x23,
1132efe996bSSam Leffler 	0x42, 0xa6, 0x43, 0xe4, 0x32, 0x46, 0xe8, 0x0c,
1142efe996bSSam Leffler 	0x3c, 0x04, 0xd0, 0x19, 0x78, 0x45, 0xce, 0x0b,
1152efe996bSSam Leffler 	0x16, 0xf9, 0x76, 0x23,
1162efe996bSSam Leffler };
1172efe996bSSam Leffler 
1182efe996bSSam Leffler /*
1192efe996bSSam Leffler ==== CCMP test mpdu   2 ====
1202efe996bSSam Leffler 
1212efe996bSSam Leffler -- MPDU Fields
1222efe996bSSam Leffler 
1232efe996bSSam Leffler  9  Version  = 0
1242efe996bSSam Leffler 10  Type     = 2   SubType  = 3  Data+CF-Ack+CF-Poll
1252efe996bSSam Leffler 11  ToDS     = 0   FromDS   = 0
1262efe996bSSam Leffler 12  MoreFrag = 0   Retry    = 0
1272efe996bSSam Leffler 13  PwrMgt   = 0   moreData = 0
1282efe996bSSam Leffler 14  Encrypt  = 1
1292efe996bSSam Leffler 15  Order    = 1
1302efe996bSSam Leffler 16  Duration = 20842
1312efe996bSSam Leffler 17  A1 = ea-10-0c-84-68-50    DA
1322efe996bSSam Leffler 18  A2 = ee-c1-76-2c-88-de    SA
1332efe996bSSam Leffler 19  A3 = af-2e-e9-f4-6a-07    BSSID
1342efe996bSSam Leffler 20  SC = 0xCCE0
1352efe996bSSam Leffler 21  seqNum = 3278 (0x0CCE)  fraqNum = 0 (0x00)
1362efe996bSSam Leffler 22  Algorithm = AES_CCM
1372efe996bSSam Leffler 23  Key ID = 2
1382efe996bSSam Leffler 24  TK = 8f 7a 05 3f a5 77 a5 59  75 29 27 20 97 a6 03 d5
1392efe996bSSam Leffler 25  PN = 54923164817386  (0x31F3CBBA97EA)
1402efe996bSSam Leffler 26  802.11 Header =  38 c0 6a 51 ea 10 0c 84 68 50 ee c1 76 2c 88 de
1412efe996bSSam Leffler 27  	af 2e e9 f4 6a 07 e0 cc
1422efe996bSSam Leffler 28  Muted 802.11 Header =  08 c0 ea 10 0c 84 68 50 ee c1 76 2c 88 de
1432efe996bSSam Leffler 29  	af 2e e9 f4 6a 07 00 00
1442efe996bSSam Leffler 30  CCMP Header =  ea 97 00 a0 ba cb f3 31
1452efe996bSSam Leffler 31  CCM Nonce = 00 ee c1 76 2c 88 de 31  f3 cb ba 97 ea
1462efe996bSSam Leffler 32  Plaintext Data = 83 a0 63 4b 5e d7 62 7e b9 df 22 5e 05 74 03 42
1472efe996bSSam Leffler 33  	de 19 41 17
1482efe996bSSam Leffler 34  CCM MIC =  54 2f bf 8d a0 6a a4 ae
1492efe996bSSam Leffler 35  -- Encrypted MPDU with FCS
1502efe996bSSam Leffler 36  38 c0 6a 51 ea 10 0c 84 68 50 ee c1 76 2c 88 de af 2e e9 f4 6a 07
1512efe996bSSam Leffler 37  e0 cc ea 97 00 a0 ba cb f3 31 81 4b 69 65 d0 5b f2 b2 ed 38 d4 be
1522efe996bSSam Leffler 38  b0 69 fe 82 71 4a 61 0b 54 2f bf 8d a0 6a a4 ae 25 3c 47 38
1532efe996bSSam Leffler */
1542efe996bSSam Leffler static const u_int8_t test2_key[] = {		/* TK */
1552efe996bSSam Leffler 	0x8f, 0x7a, 0x05, 0x3f, 0xa5, 0x77, 0xa5, 0x59,  0x75, 0x29, 0x27,
1562efe996bSSam Leffler 	0x20, 0x97, 0xa6, 0x03, 0xd5
1572efe996bSSam Leffler };
1582efe996bSSam Leffler static const u_int8_t test2_plaintext[] = {	/* Plaintext MPDU w/o MIC */
1592efe996bSSam Leffler 	0x38, 0xc0, 0x6a, 0x51, 0xea, 0x10, 0x0c, 0x84, 0x68, 0x50, 0xee,
1602efe996bSSam Leffler 	0xc1, 0x76, 0x2c, 0x88, 0xde, 0xaf, 0x2e, 0xe9, 0xf4, 0x6a, 0x07,
1612efe996bSSam Leffler 	0xe0, 0xcc,
1622efe996bSSam Leffler 	0x83, 0xa0, 0x63, 0x4b, 0x5e, 0xd7, 0x62, 0x7e, 0xb9, 0xdf, 0x22,
1632efe996bSSam Leffler 	0x5e, 0x05, 0x74, 0x03, 0x42, 0xde, 0x19, 0x41, 0x17
1642efe996bSSam Leffler };
1652efe996bSSam Leffler static const u_int8_t test2_encrypted[] = {	/* Encrypted MPDU with MIC */
1662efe996bSSam Leffler 	0x38, 0xc0, 0x6a, 0x51, 0xea, 0x10, 0x0c, 0x84, 0x68, 0x50, 0xee,
1672efe996bSSam Leffler 	0xc1, 0x76, 0x2c, 0x88, 0xde, 0xaf, 0x2e, 0xe9, 0xf4, 0x6a, 0x07,
1682efe996bSSam Leffler 	0xe0, 0xcc, 0xea, 0x97, 0x00, 0xa0, 0xba, 0xcb, 0xf3, 0x31, 0x81,
1692efe996bSSam Leffler 	0x4b, 0x69, 0x65, 0xd0, 0x5b, 0xf2, 0xb2, 0xed, 0x38, 0xd4, 0xbe,
1702efe996bSSam Leffler 	0xb0, 0x69, 0xfe, 0x82, 0x71, 0x4a, 0x61, 0x0b, 0x54, 0x2f, 0xbf,
1712efe996bSSam Leffler 	0x8d, 0xa0, 0x6a, 0xa4, 0xae,
1722efe996bSSam Leffler };
1732efe996bSSam Leffler 
1742efe996bSSam Leffler /*
1752efe996bSSam Leffler ==== CCMP test mpdu   3 ====
1762efe996bSSam Leffler 
1772efe996bSSam Leffler -- MPDU Fields
1782efe996bSSam Leffler 
1792efe996bSSam Leffler 41  Version  = 0
1802efe996bSSam Leffler 42  Type     = 2   SubType  = 11
1812efe996bSSam Leffler 43  ToDS     = 0   FromDS   = 0
1822efe996bSSam Leffler 44  MoreFrag = 0   Retry    = 1
1832efe996bSSam Leffler 45  PwrMgt   = 0   moreData = 0
1842efe996bSSam Leffler 46  Encrypt  = 1
1852efe996bSSam Leffler 47  Order    = 1
1862efe996bSSam Leffler 48  Duration = 25052
1872efe996bSSam Leffler 49  A1 = d9-57-7d-f7-63-c8    DA
1882efe996bSSam Leffler 50 A2 = b6-a8-8a-df-36-91    SA
1892efe996bSSam Leffler 1  A3 = dc-4a-8b-ca-94-dd    BSSID
1902efe996bSSam Leffler 2  SC = 0x8260
1912efe996bSSam Leffler 3  seqNum = 2086 (0x0826)  fraqNum = 0 (0x00)
1922efe996bSSam Leffler 4  QC = 0x0000
1932efe996bSSam Leffler 5  MSDU Priority = 0 (0x0)
1942efe996bSSam Leffler 6  Algorithm = AES_CCM
1952efe996bSSam Leffler 7  Key ID = 2
1962efe996bSSam Leffler 8  TK = 40 cf b7 a6 2e 88 01 3b  d6 d3 af fc c1 91 04 1e
1972efe996bSSam Leffler 9  PN = 52624639632814  (0x2FDCA0F3A5AE)
1982efe996bSSam Leffler 10  802.11 Header =  b8 c8 dc 61 d9 57 7d f7 63 c8 b6 a8 8a df 36 91
1992efe996bSSam Leffler 11  	dc 4a 8b ca 94 dd 60 82 20 85
2002efe996bSSam Leffler 12  Muted 802.11 Header =  88 c0 d9 57 7d f7 63 c8 b6 a8 8a df 36 91
2012efe996bSSam Leffler 13  	dc 4a 8b ca 94 dd 00 00 00 00
2022efe996bSSam Leffler 14  CCMP Header =  ae a5 00 a0 f3 a0 dc 2f
2032efe996bSSam Leffler 15  CCM Nonce = 00 b6 a8 8a df 36 91 2f dc a0 f3 a5 ae
2042efe996bSSam Leffler 16  Plaintext Data  = 2c 1b d0 36 83 1c 95 49 6c 5f 4d bf 3d 55 9e 72
2052efe996bSSam Leffler 17  	de 80 2a 18
2062efe996bSSam Leffler 18  CCM MIC =  fd 1f 1f 61 a9 fb 4b b3
2072efe996bSSam Leffler 19  -- Encrypted MPDU with FCS
2082efe996bSSam Leffler 20  b8 c8 dc 61 d9 57 7d f7 63 c8 b6 a8 8a df 36 91 dc 4a 8b ca 94 dd
2092efe996bSSam Leffler 21  60 82 20 85 ae a5 00 a0 f3 a0 dc 2f 89 d8 58 03 40 b6 26 a0 b6 d4
2102efe996bSSam Leffler 22  d0 13 bf 18 f2 91 b8 96 46 c8 fd 1f 1f 61 a9 fb 4b b3 60 3f 5a ad
2112efe996bSSam Leffler */
2122efe996bSSam Leffler static const u_int8_t test3_key[] = {		/* TK */
2132efe996bSSam Leffler 	0x40, 0xcf, 0xb7, 0xa6, 0x2e, 0x88, 0x01, 0x3b,  0xd6, 0xd3,
2142efe996bSSam Leffler 	0xaf, 0xfc, 0xc1, 0x91, 0x04, 0x1e
2152efe996bSSam Leffler };
2162efe996bSSam Leffler static const u_int8_t test3_plaintext[] = {	/* Plaintext MPDU w/o MIC */
2172efe996bSSam Leffler 	0xb8, 0xc8, 0xdc, 0x61, 0xd9, 0x57, 0x7d, 0xf7, 0x63, 0xc8,
2182efe996bSSam Leffler 	0xb6, 0xa8, 0x8a, 0xdf, 0x36, 0x91, 0xdc, 0x4a, 0x8b, 0xca,
2192efe996bSSam Leffler 	0x94, 0xdd, 0x60, 0x82, 0x20, 0x85,
2202efe996bSSam Leffler 	0x2c, 0x1b, 0xd0, 0x36, 0x83, 0x1c, 0x95, 0x49, 0x6c, 0x5f,
2212efe996bSSam Leffler 	0x4d, 0xbf, 0x3d, 0x55, 0x9e, 0x72, 0xde, 0x80, 0x2a, 0x18
2222efe996bSSam Leffler };
2232efe996bSSam Leffler static const u_int8_t test3_encrypted[] = {	/* Encrypted MPDU with MIC */
2242efe996bSSam Leffler 	0xb8, 0xc8, 0xdc, 0x61, 0xd9, 0x57, 0x7d, 0xf7, 0x63, 0xc8,
2252efe996bSSam Leffler 	0xb6, 0xa8, 0x8a, 0xdf, 0x36, 0x91, 0xdc, 0x4a, 0x8b, 0xca,
2262efe996bSSam Leffler 	0x94, 0xdd, 0x60, 0x82, 0x20, 0x85, 0xae, 0xa5, 0x00, 0xa0,
2272efe996bSSam Leffler 	0xf3, 0xa0, 0xdc, 0x2f, 0x89, 0xd8, 0x58, 0x03, 0x40, 0xb6,
2282efe996bSSam Leffler 	0x26, 0xa0, 0xb6, 0xd4, 0xd0, 0x13, 0xbf, 0x18, 0xf2, 0x91,
2292efe996bSSam Leffler 	0xb8, 0x96, 0x46, 0xc8, 0xfd, 0x1f, 0x1f, 0x61, 0xa9, 0xfb,
2302efe996bSSam Leffler 	0x4b, 0xb3,
2312efe996bSSam Leffler };
2322efe996bSSam Leffler 
2332efe996bSSam Leffler /*
2342efe996bSSam Leffler ==== CCMP test mpdu  4 ====
2352efe996bSSam Leffler 
2362efe996bSSam Leffler -- MPDU Fields
2372efe996bSSam Leffler 25  Version  = 0
2382efe996bSSam Leffler 26  Type     = 2   SubType  = 10
2392efe996bSSam Leffler 27  ToDS     = 0   FromDS   = 1
2402efe996bSSam Leffler 28  MoreFrag = 0   Retry    = 1
2412efe996bSSam Leffler 29  PwrMgt   = 0   moreData = 0
2422efe996bSSam Leffler 30  Encrypt  = 1
2432efe996bSSam Leffler 31  Order    = 1
2442efe996bSSam Leffler 32  Duration = 4410
2452efe996bSSam Leffler 33  A1 = 71-2a-9d-df-11-db    DA
2462efe996bSSam Leffler 34  A2 = 8e-f8-22-73-47-01    BSSID
2472efe996bSSam Leffler 35  A3 = 59-14-0d-d6-46-a2    SA
2482efe996bSSam Leffler 36  SC = 0x2FC0
2492efe996bSSam Leffler 37  seqNum = 764 (0x02FC)  fraqNum = 0 (0x00)
2502efe996bSSam Leffler 38  QC = 0x0007
2512efe996bSSam Leffler 39  MSDU Priority = 7 (0x0)
2522efe996bSSam Leffler 40  Algorithm = AES_CCM
2532efe996bSSam Leffler 41  Key ID = 0
2542efe996bSSam Leffler 42  TK = 8c 89 a2 eb c9 6c 76 02  70 7f cf 24 b3 2d 38 33
2552efe996bSSam Leffler 43  PN = 270963670912995  (0xF670A55A0FE3)
2562efe996bSSam Leffler 44  802.11 Header =  a8 ca 3a 11 71 2a 9d df 11 db 8e f8 22 73 47 01
2572efe996bSSam Leffler 45  	59 14 0d d6 46 a2 c0 2f 67 a5
2582efe996bSSam Leffler 46  Muted 802.11 Header =  88 c2 71 2a 9d df 11 db 8e f8 22 73 47 01
2592efe996bSSam Leffler 47  	59 14 0d d6 46 a2 00 00 07 00
2602efe996bSSam Leffler 48  CCMP Header =  e3 0f 00 20 5a a5 70 f6
2612efe996bSSam Leffler 49  CCM Nonce = 07 8e f8 22 73 47 01 f6  70 a5 5a 0f e3
2622efe996bSSam Leffler 50  Plaintext Data = 4f ad 2b 1c 29 0f a5 eb d8 72 fb c3 f3 a0 74 89
2632efe996bSSam Leffler 51  	8f 8b 2f bb
2642efe996bSSam Leffler 52  CCM MIC =  31 fc 88 00 4f 35 ee 3d
2652efe996bSSam Leffler -- Encrypted MPDU with FCS
2662efe996bSSam Leffler 2  a8 ca 3a 11 71 2a 9d df 11 db 8e f8 22 73 47 01 59 14 0d d6 46 a2
2672efe996bSSam Leffler 3  c0 2f 67 a5 e3 0f 00 20 5a a5 70 f6 9d 59 b1 5f 37 14 48 c2 30 f4
2682efe996bSSam Leffler 4  d7 39 05 2e 13 ab 3b 1a 7b 10 31 fc 88 00 4f 35 ee 3d 45 a7 4a 30
2692efe996bSSam Leffler */
2702efe996bSSam Leffler static const u_int8_t test4_key[] = {		/* TK */
2712efe996bSSam Leffler 	0x8c, 0x89, 0xa2, 0xeb, 0xc9, 0x6c, 0x76, 0x02,
2722efe996bSSam Leffler 	0x70, 0x7f, 0xcf, 0x24, 0xb3, 0x2d, 0x38, 0x33,
2732efe996bSSam Leffler };
2742efe996bSSam Leffler static const u_int8_t test4_plaintext[] = {	/* Plaintext MPDU w/o MIC */
2752efe996bSSam Leffler 	0xa8, 0xca, 0x3a, 0x11, 0x71, 0x2a, 0x9d, 0xdf, 0x11, 0xdb,
2762efe996bSSam Leffler 	0x8e, 0xf8, 0x22, 0x73, 0x47, 0x01, 0x59, 0x14, 0x0d, 0xd6,
2772efe996bSSam Leffler 	0x46, 0xa2, 0xc0, 0x2f, 0x67, 0xa5,
2782efe996bSSam Leffler 	0x4f, 0xad, 0x2b, 0x1c, 0x29, 0x0f, 0xa5, 0xeb, 0xd8, 0x72,
2792efe996bSSam Leffler 	0xfb, 0xc3, 0xf3, 0xa0, 0x74, 0x89, 0x8f, 0x8b, 0x2f, 0xbb,
2802efe996bSSam Leffler };
2812efe996bSSam Leffler static const u_int8_t test4_encrypted[] = {	/* Encrypted MPDU with MIC */
2822efe996bSSam Leffler 	0xa8, 0xca, 0x3a, 0x11, 0x71, 0x2a, 0x9d, 0xdf, 0x11, 0xdb,
2832efe996bSSam Leffler 	0x8e, 0xf8, 0x22, 0x73, 0x47, 0x01, 0x59, 0x14, 0x0d, 0xd6,
2842efe996bSSam Leffler 	0x46, 0xa2, 0xc0, 0x2f, 0x67, 0xa5, 0xe3, 0x0f, 0x00, 0x20,
2852efe996bSSam Leffler 	0x5a, 0xa5, 0x70, 0xf6, 0x9d, 0x59, 0xb1, 0x5f, 0x37, 0x14,
2862efe996bSSam Leffler 	0x48, 0xc2, 0x30, 0xf4, 0xd7, 0x39, 0x05, 0x2e, 0x13, 0xab,
2872efe996bSSam Leffler 	0x3b, 0x1a, 0x7b, 0x10, 0x31, 0xfc, 0x88, 0x00, 0x4f, 0x35,
2882efe996bSSam Leffler 	0xee, 0x3d,
2892efe996bSSam Leffler };
2902efe996bSSam Leffler 
2912efe996bSSam Leffler /*
2922efe996bSSam Leffler ==== CCMP test mpdu   5 ====
2932efe996bSSam Leffler 
2942efe996bSSam Leffler -- MPDU Fields
2952efe996bSSam Leffler 
2962efe996bSSam Leffler 7  Version  = 0
2972efe996bSSam Leffler 8  Type     = 2   SubType  = 8
2982efe996bSSam Leffler 9  ToDS     = 0   FromDS   = 1
2992efe996bSSam Leffler 10  MoreFrag = 0   Retry    = 1
3002efe996bSSam Leffler 11  PwrMgt   = 1   moreData = 0
3012efe996bSSam Leffler 12  Encrypt  = 1
3022efe996bSSam Leffler 13  Order    = 1
3032efe996bSSam Leffler 14  Duration = 16664
3042efe996bSSam Leffler 15  A1 = 45-de-c6-9a-74-80    DA
3052efe996bSSam Leffler 16  A2 = f3-51-94-6b-c9-6b    BSSID
3062efe996bSSam Leffler 17  A3 = e2-76-fb-e6-c1-27    SA
3072efe996bSSam Leffler 18  SC = 0xF280
3082efe996bSSam Leffler 19  seqNum = 3880 (0x0F28)  fraqNum = 0 (0x00)
3092efe996bSSam Leffler 20  QC = 0x000b
3102efe996bSSam Leffler 21  MSDU Priority = 0 (0x0)
3112efe996bSSam Leffler 22  Algorithm = AES_CCM
3122efe996bSSam Leffler 23  Key ID = 2
3132efe996bSSam Leffler 24  TK = a5 74 d5 14 3b b2 5e fd  de ff 30 12 2f df d0 66
3142efe996bSSam Leffler 25  PN = 184717420531255  (0xA7FFE03C0E37)
3152efe996bSSam Leffler 26  802.11 Header =  88 da 18 41 45 de c6 9a 74 80 f3 51 94 6b c9 6b
3162efe996bSSam Leffler 27  	e2 76 fb e6 c1 27 80 f2 4b 19
3172efe996bSSam Leffler 28  Muted 802.11 Header =  88 c2 45 de c6 9a 74 80 f3 51 94 6b c9 6b
3182efe996bSSam Leffler 29  	e2 76 fb e6 c1 27 00 00 0b 00
3192efe996bSSam Leffler 30  CCMP Header =  37 0e 00 a0 3c e0 ff a7
3202efe996bSSam Leffler 31  CCM Nonce = 0b f3 51 94 6b c9 6b a7 ff e0 3c 0e 37
3212efe996bSSam Leffler 32  Plaintext Data = 28 96 9b 95 4f 26 3a 80 18 a9 ef 70 a8 b0 51 46
3222efe996bSSam Leffler 33  	24 81 92 2e
3232efe996bSSam Leffler 34  CCM MIC =  ce 0c 3b e1 97 d3 05 eb
3242efe996bSSam Leffler 35  -- Encrypted MPDU with FCS
3252efe996bSSam Leffler 36  88 da 18 41 45 de c6 9a 74 80 f3 51 94 6b c9 6b e2 76 fb e6 c1 27
3262efe996bSSam Leffler 37  80 f2 4b 19 37 0e 00 a0 3c e0 ff a7 eb 4a e4 95 6a 80 1d a9 62 4b
3272efe996bSSam Leffler 38  7e 0c 18 b2 3e 61 5e c0 3a f6 ce 0c 3b e1 97 d3 05 eb c8 9e a1 b5
3282efe996bSSam Leffler */
3292efe996bSSam Leffler static const u_int8_t test5_key[] = {		/* TK */
3302efe996bSSam Leffler 	0xa5, 0x74, 0xd5, 0x14, 0x3b, 0xb2, 0x5e, 0xfd,
3312efe996bSSam Leffler 	0xde, 0xff, 0x30, 0x12, 0x2f, 0xdf, 0xd0, 0x66,
3322efe996bSSam Leffler };
3332efe996bSSam Leffler static const u_int8_t test5_plaintext[] = {	/* Plaintext MPDU w/o MIC */
3342efe996bSSam Leffler 	0x88, 0xda, 0x18, 0x41, 0x45, 0xde, 0xc6, 0x9a, 0x74, 0x80,
3352efe996bSSam Leffler 	0xf3, 0x51, 0x94, 0x6b, 0xc9, 0x6b, 0xe2, 0x76, 0xfb, 0xe6,
3362efe996bSSam Leffler 	0xc1, 0x27, 0x80, 0xf2, 0x4b, 0x19,
3372efe996bSSam Leffler 	0x28, 0x96, 0x9b, 0x95, 0x4f, 0x26, 0x3a, 0x80, 0x18, 0xa9,
3382efe996bSSam Leffler 	0xef, 0x70, 0xa8, 0xb0, 0x51, 0x46, 0x24, 0x81, 0x92, 0x2e,
3392efe996bSSam Leffler };
3402efe996bSSam Leffler static const u_int8_t test5_encrypted[] = {	/* Encrypted MPDU with MIC */
3412efe996bSSam Leffler 	0x88, 0xda, 0x18, 0x41, 0x45, 0xde, 0xc6, 0x9a, 0x74, 0x80,
3422efe996bSSam Leffler 	0xf3, 0x51, 0x94, 0x6b, 0xc9, 0x6b, 0xe2, 0x76, 0xfb, 0xe6,
3432efe996bSSam Leffler 	0xc1, 0x27, 0x80, 0xf2, 0x4b, 0x19, 0x37, 0x0e, 0x00, 0xa0,
3442efe996bSSam Leffler 	0x3c, 0xe0, 0xff, 0xa7, 0xeb, 0x4a, 0xe4, 0x95, 0x6a, 0x80,
3452efe996bSSam Leffler 	0x1d, 0xa9, 0x62, 0x4b, 0x7e, 0x0c, 0x18, 0xb2, 0x3e, 0x61,
3462efe996bSSam Leffler 	0x5e, 0xc0, 0x3a, 0xf6, 0xce, 0x0c, 0x3b, 0xe1, 0x97, 0xd3,
3472efe996bSSam Leffler 	0x05, 0xeb,
3482efe996bSSam Leffler };
3492efe996bSSam Leffler 
3502efe996bSSam Leffler /*
3512efe996bSSam Leffler ==== CCMP test mpdu   6 ====
3522efe996bSSam Leffler 
3532efe996bSSam Leffler -- MPDU Fields
3542efe996bSSam Leffler 
3552efe996bSSam Leffler 41  Version  = 0
3562efe996bSSam Leffler 42  Type     = 2   SubType  = 8
3572efe996bSSam Leffler 43  ToDS     = 0   FromDS   = 1
3582efe996bSSam Leffler 44  MoreFrag = 0   Retry    = 0
3592efe996bSSam Leffler 45  PwrMgt   = 1   moreData = 0
3602efe996bSSam Leffler 46  Encrypt  = 1
3612efe996bSSam Leffler 47  Order    = 0
3622efe996bSSam Leffler 48  Duration = 8161
3632efe996bSSam Leffler 49  A1 = 5a-f2-84-30-fd-ab    DA
3642efe996bSSam Leffler 50  A2 = bf-f9-43-b9-f9-a6    BSSID
3652efe996bSSam Leffler 1   A3 = ab-1d-98-c7-fe-73    SA
3662efe996bSSam Leffler 2  SC = 0x7150
3672efe996bSSam Leffler 3  seqNum = 1813 (0x0715)  fraqNum = 0 (0x00)
3682efe996bSSam Leffler 4  QC = 0x000d
3692efe996bSSam Leffler 5  PSDU Priority = 13 (0xd)
3702efe996bSSam Leffler 6  Algorithm = AES_CCM
3712efe996bSSam Leffler 7  Key ID = 1
3722efe996bSSam Leffler 8  TK = f7 1e ea 4e 1f 58 80 4b 97 17 23 0a d0 61 46 41
3732efe996bSSam Leffler 9  PN    = 118205765159305  (0x6B81ECA48989)
3742efe996bSSam Leffler 10  802.11 Header =  88 52 e1 1f 5a f2 84 30 fd ab bf f9 43 b9 f9 a6
3752efe996bSSam Leffler 11  	ab 1d 98 c7 fe 73 50 71  3d 6a
3762efe996bSSam Leffler 12  Muted 802.11 Header =  88 42 5a f2 84 30 fd ab bf f9 43 b9 f9 a6
3772efe996bSSam Leffler 13  	ab 1d 98 c7 fe 73 00 00 0d 00
3782efe996bSSam Leffler 14  CCMP Header =  89 89 00 60 a4 ec 81 6b
3792efe996bSSam Leffler 15  CCM Nonce = 0d bf f9 43 b9 f9 a6 6b  81 ec a4 89 89
3802efe996bSSam Leffler 16  Plaintext Data = ab fd a2 2d 3a 0b fc 9c c1 fc 07 93 63 c2 fc a1
3812efe996bSSam Leffler 17  	43 e6 eb 1d
3822efe996bSSam Leffler 18  CCM MIC =  30 9a 8d 5c 46 6b bb 71
3832efe996bSSam Leffler 19  -- Encrypted MPDU with FCS
3842efe996bSSam Leffler 20  88 52 e1 1f 5a f2 84 30 fd ab bf f9 43 b9 f9 a6 ab 1d 98 c7 fe 73
3852efe996bSSam Leffler 21  50 71 3d 6a 89 89 00 60 a4 ec 81 6b 9a 70 9b 60 a3 9d 40 b1 df b6
3862efe996bSSam Leffler 22  12 e1 8b 5f 11 4b ad b6 cc 86 30 9a 8d 5c 46 6b bb 71 86 c0 4e 97
3872efe996bSSam Leffler */
3882efe996bSSam Leffler static const u_int8_t test6_key[] = {		/* TK */
3892efe996bSSam Leffler 	0xf7, 0x1e, 0xea, 0x4e, 0x1f, 0x58, 0x80, 0x4b,
3902efe996bSSam Leffler 	0x97, 0x17, 0x23, 0x0a, 0xd0, 0x61, 0x46, 0x41,
3912efe996bSSam Leffler };
3922efe996bSSam Leffler static const u_int8_t test6_plaintext[] = {	/* Plaintext MPDU w/o MIC */
3932efe996bSSam Leffler 	0x88, 0x52, 0xe1, 0x1f, 0x5a, 0xf2, 0x84, 0x30, 0xfd, 0xab,
3942efe996bSSam Leffler 	0xbf, 0xf9, 0x43, 0xb9, 0xf9, 0xa6, 0xab, 0x1d, 0x98, 0xc7,
3952efe996bSSam Leffler 	0xfe, 0x73, 0x50, 0x71, 0x3d, 0x6a,
3962efe996bSSam Leffler 	0xab, 0xfd, 0xa2, 0x2d, 0x3a, 0x0b, 0xfc, 0x9c, 0xc1, 0xfc,
3972efe996bSSam Leffler 	0x07, 0x93, 0x63, 0xc2, 0xfc, 0xa1, 0x43, 0xe6, 0xeb, 0x1d,
3982efe996bSSam Leffler };
3992efe996bSSam Leffler static const u_int8_t test6_encrypted[] = {	/* Encrypted MPDU with MIC */
4002efe996bSSam Leffler 	0x88, 0x52, 0xe1, 0x1f, 0x5a, 0xf2, 0x84, 0x30, 0xfd, 0xab,
4012efe996bSSam Leffler 	0xbf, 0xf9, 0x43, 0xb9, 0xf9, 0xa6, 0xab, 0x1d, 0x98, 0xc7,
4022efe996bSSam Leffler 	0xfe, 0x73, 0x50, 0x71, 0x3d, 0x6a, 0x89, 0x89, 0x00, 0x60,
4032efe996bSSam Leffler 	0xa4, 0xec, 0x81, 0x6b, 0x9a, 0x70, 0x9b, 0x60, 0xa3, 0x9d,
4042efe996bSSam Leffler 	0x40, 0xb1, 0xdf, 0xb6, 0x12, 0xe1, 0x8b, 0x5f, 0x11, 0x4b,
4052efe996bSSam Leffler 	0xad, 0xb6, 0xcc, 0x86, 0x30, 0x9a, 0x8d, 0x5c, 0x46, 0x6b,
4062efe996bSSam Leffler 	0xbb, 0x71,
4072efe996bSSam Leffler };
4082efe996bSSam Leffler 
4092efe996bSSam Leffler /*
4102efe996bSSam Leffler ==== CCMP test mpdu   7 ====
4112efe996bSSam Leffler 
4122efe996bSSam Leffler -- MPDU Fields
4132efe996bSSam Leffler 
4142efe996bSSam Leffler 25  Version  = 0
4152efe996bSSam Leffler 26  Type     = 2   SubType  = 1  Data+CF-Ack
4162efe996bSSam Leffler 27  ToDS     = 1   FromDS   = 0
4172efe996bSSam Leffler 28  MoreFrag = 0   Retry    = 1
4182efe996bSSam Leffler 29  PwrMgt   = 1   moreData = 1
4192efe996bSSam Leffler 30  Encrypt  = 1
4202efe996bSSam Leffler 31  Order    = 0
4212efe996bSSam Leffler 32  Duration = 18049
4222efe996bSSam Leffler 33  A1 = 9b-50-f4-fd-56-f6    BSSID
4232efe996bSSam Leffler 34  A2 = ef-ec-95-20-16-91    SA
4242efe996bSSam Leffler 35  A3 = 83-57-0c-4c-cd-ee    DA
4252efe996bSSam Leffler 36  SC = 0xA020
4262efe996bSSam Leffler 37  seqNum = 2562 (0x0A02)  fraqNum = 0 (0x00)
4272efe996bSSam Leffler 38  Algorithm = AES_CCM
4282efe996bSSam Leffler 39  Key ID = 3
4292efe996bSSam Leffler 40  TK = 1b db 34 98 0e 03 81 24 a1 db 1a 89 2b ec 36 6a
4302efe996bSSam Leffler 41  PN = 104368786630435  (0x5EEC4073E723)
4312efe996bSSam Leffler 42  Header =  18 79 81 46 9b 50 f4 fd 56 f6 ef ec 95 20 16 91 83 57
4322efe996bSSam Leffler 43  	0c 4c cd ee 20 a0
4332efe996bSSam Leffler 44  Muted MAC Header =  08 41 9b 50 f4 fd 56 f6 ef ec 95 20 16 91
4342efe996bSSam Leffler 45  	83 57 0c 4c cd ee 00 00
4352efe996bSSam Leffler 46  CCMP Header =  23 e7 00 e0 73 40 ec 5e
4362efe996bSSam Leffler 47  CCM Nonce = 00 ef ec 95 20 16 91 5e ec 40 73 e7 23
4372efe996bSSam Leffler 48  Plaintext Data = 98 be ca 86 f4 b3 8d a2 0c fd f2 47 24 c5 8e b8
4382efe996bSSam Leffler 49  	35 66 53 39
4392efe996bSSam Leffler 50  CCM MIC =  2d 09 57 ec fa be 95 b9
4402efe996bSSam Leffler -- Encrypted MPDU with FCS
4412efe996bSSam Leffler 1  18 79 81 46 9b 50 f4 fd 56 f6 ef ec 95 20 16 91 83 57 0c 4c cd ee
4422efe996bSSam Leffler 2  20 a0 23 e7 00 e0 73 40 ec 5e 12 c5 37 eb f3 ab 58 4e f1 fe f9 a1
4432efe996bSSam Leffler 3  f3 54 7a 8c 13 b3 22 5a 2d 09 57 ec fa be 95 b9 aa fa 0c c8
4442efe996bSSam Leffler */
4452efe996bSSam Leffler static const u_int8_t test7_key[] = {		/* TK */
4462efe996bSSam Leffler 	0x1b, 0xdb, 0x34, 0x98, 0x0e, 0x03, 0x81, 0x24,
4472efe996bSSam Leffler 	0xa1, 0xdb, 0x1a, 0x89, 0x2b, 0xec, 0x36, 0x6a,
4482efe996bSSam Leffler };
4492efe996bSSam Leffler static const u_int8_t test7_plaintext[] = {	/* Plaintext MPDU w/o MIC */
4502efe996bSSam Leffler 	0x18, 0x79, 0x81, 0x46, 0x9b, 0x50, 0xf4, 0xfd, 0x56, 0xf6,
4512efe996bSSam Leffler 	0xef, 0xec, 0x95, 0x20, 0x16, 0x91, 0x83, 0x57, 0x0c, 0x4c,
4522efe996bSSam Leffler 	0xcd, 0xee, 0x20, 0xa0,
4532efe996bSSam Leffler 	0x98, 0xbe, 0xca, 0x86, 0xf4, 0xb3, 0x8d, 0xa2, 0x0c, 0xfd,
4542efe996bSSam Leffler 	0xf2, 0x47, 0x24, 0xc5, 0x8e, 0xb8, 0x35, 0x66, 0x53, 0x39,
4552efe996bSSam Leffler };
4562efe996bSSam Leffler static const u_int8_t test7_encrypted[] = {	/* Encrypted MPDU with MIC */
4572efe996bSSam Leffler 	0x18, 0x79, 0x81, 0x46, 0x9b, 0x50, 0xf4, 0xfd, 0x56, 0xf6,
4582efe996bSSam Leffler 	0xef, 0xec, 0x95, 0x20, 0x16, 0x91, 0x83, 0x57, 0x0c, 0x4c,
4592efe996bSSam Leffler 	0xcd, 0xee, 0x20, 0xa0, 0x23, 0xe7, 0x00, 0xe0, 0x73, 0x40,
4602efe996bSSam Leffler 	0xec, 0x5e, 0x12, 0xc5, 0x37, 0xeb, 0xf3, 0xab, 0x58, 0x4e,
4612efe996bSSam Leffler 	0xf1, 0xfe, 0xf9, 0xa1, 0xf3, 0x54, 0x7a, 0x8c, 0x13, 0xb3,
4622efe996bSSam Leffler 	0x22, 0x5a, 0x2d, 0x09, 0x57, 0xec, 0xfa, 0xbe, 0x95, 0xb9,
4632efe996bSSam Leffler };
4642efe996bSSam Leffler 
4652efe996bSSam Leffler /*
4662efe996bSSam Leffler ==== CCMP test mpdu   8 ====
4672efe996bSSam Leffler 
4682efe996bSSam Leffler -- MPDU Fields
4692efe996bSSam Leffler 
4702efe996bSSam Leffler 6  Version  = 0
4712efe996bSSam Leffler 7  Type     = 2   SubType  = 11
4722efe996bSSam Leffler 8  ToDS     = 1   FromDS   = 0
4732efe996bSSam Leffler 9  MoreFrag = 0   Retry    = 1
4742efe996bSSam Leffler 10  PwrMgt   = 1   moreData = 0
4752efe996bSSam Leffler 11  Encrypt  = 1
4762efe996bSSam Leffler 12  Order    = 1
4772efe996bSSam Leffler 13  Duration = 29260
4782efe996bSSam Leffler 14  A1 = 55-2d-5f-72-bb-70    BSSID
4792efe996bSSam Leffler 15  A2 = ca-3f-3a-ae-60-c4    SA
4802efe996bSSam Leffler 16  A3 = 8b-a9-b5-f8-2c-2f    DA
4812efe996bSSam Leffler 17  SC = 0xEB50
4822efe996bSSam Leffler 18  seqNum = 3765 (0x0EB5)  fraqNum = 0 (0x00)
4832efe996bSSam Leffler 19  QC = 0x000a
4842efe996bSSam Leffler 20  MSDU Priority = 10 (0xa)
4852efe996bSSam Leffler 21  Algorithm = AES_CCM
4862efe996bSSam Leffler 22  Key ID = 2
4872efe996bSSam Leffler 23  TK = 6e ac 1b f5 4b d5 4e db 23 21 75 43 03 02 4c 71
4882efe996bSSam Leffler 24  PN    = 227588596223197  (0xCEFD996ECCDD)
4892efe996bSSam Leffler 25  802.11 Header =  b8 d9 4c 72 55 2d 5f 72 bb 70 ca 3f 3a ae 60 c4
4902efe996bSSam Leffler 26  	8b a9 b5 f8 2c 2f 50 eb 2a 55
4912efe996bSSam Leffler 27  Muted 802.11 Header =  88 c1 55 2d 5f 72 bb 70 ca 3f 3a ae 60 c4
4922efe996bSSam Leffler 28  	8b a9 b5 f8 2c 2f 00 00 0a 00
4932efe996bSSam Leffler 29  CCMP Header =  dd cc 00 a0 6e 99 fd ce
4942efe996bSSam Leffler 30  CCM Nonce = 0a ca 3f 3a ae 60 c4 ce fd 99 6e cc dd
4952efe996bSSam Leffler 31  Plaintext Data = 57 cb 5c 0e 5f cd 88 5e 9a 42 39 e9 b9 ca d6 0d
4962efe996bSSam Leffler 32  	64 37 59 79
4972efe996bSSam Leffler 33  CCM MIC =  6d ba 8e f7 f0 80 87 dd
4982efe996bSSam Leffler -- Encrypted MPDU with FCS
4992efe996bSSam Leffler 35  b8 d9 4c 72 55 2d 5f 72 bb 70 ca 3f 3a ae 60 c4 8b a9 b5 f8 2c 2f
5002efe996bSSam Leffler 36  50 eb 2a 55 dd cc 00 a0 6e 99 fd ce 4b f2 81 ef 8e c7 73 9f 91 59
5012efe996bSSam Leffler 37  1b 97 a8 7d c1 4b 3f a1 74 62 6d ba 8e f7 f0 80 87 dd 0c 65 74 3f
5022efe996bSSam Leffler */
5032efe996bSSam Leffler static const u_int8_t test8_key[] = {		/* TK */
5042efe996bSSam Leffler 	0x6e, 0xac, 0x1b, 0xf5, 0x4b, 0xd5, 0x4e, 0xdb,
5052efe996bSSam Leffler 	0x23, 0x21, 0x75, 0x43, 0x03, 0x02, 0x4c, 0x71,
5062efe996bSSam Leffler };
5072efe996bSSam Leffler static const u_int8_t test8_plaintext[] = {	/* Plaintext MPDU w/o MIC */
5082efe996bSSam Leffler 	0xb8, 0xd9, 0x4c, 0x72, 0x55, 0x2d, 0x5f, 0x72, 0xbb, 0x70,
5092efe996bSSam Leffler 	0xca, 0x3f, 0x3a, 0xae, 0x60, 0xc4, 0x8b, 0xa9, 0xb5, 0xf8,
5102efe996bSSam Leffler 	0x2c, 0x2f, 0x50, 0xeb, 0x2a, 0x55,
5112efe996bSSam Leffler 	0x57, 0xcb, 0x5c, 0x0e, 0x5f, 0xcd, 0x88, 0x5e, 0x9a, 0x42,
5122efe996bSSam Leffler 	0x39, 0xe9, 0xb9, 0xca, 0xd6, 0x0d, 0x64, 0x37, 0x59, 0x79,
5132efe996bSSam Leffler };
5142efe996bSSam Leffler static const u_int8_t test8_encrypted[] = {	/* Encrypted MPDU with MIC */
5152efe996bSSam Leffler 	0xb8, 0xd9, 0x4c, 0x72, 0x55, 0x2d, 0x5f, 0x72, 0xbb, 0x70,
5162efe996bSSam Leffler 	0xca, 0x3f, 0x3a, 0xae, 0x60, 0xc4, 0x8b, 0xa9, 0xb5, 0xf8,
5172efe996bSSam Leffler 	0x2c, 0x2f, 0x50, 0xeb, 0x2a, 0x55, 0xdd, 0xcc, 0x00, 0xa0,
5182efe996bSSam Leffler 	0x6e, 0x99, 0xfd, 0xce, 0x4b, 0xf2, 0x81, 0xef, 0x8e, 0xc7,
5192efe996bSSam Leffler 	0x73, 0x9f, 0x91, 0x59, 0x1b, 0x97, 0xa8, 0x7d, 0xc1, 0x4b,
5202efe996bSSam Leffler 	0x3f, 0xa1, 0x74, 0x62, 0x6d, 0xba, 0x8e, 0xf7, 0xf0, 0x80,
5212efe996bSSam Leffler 	0x87, 0xdd,
5222efe996bSSam Leffler };
5232efe996bSSam Leffler 
5242efe996bSSam Leffler #define	TEST(n,name,cipher,keyix,pn) { \
5252efe996bSSam Leffler 	name, IEEE80211_CIPHER_##cipher,keyix, pn##LL, \
5262efe996bSSam Leffler 	test##n##_key,   sizeof(test##n##_key), \
5272efe996bSSam Leffler 	test##n##_plaintext, sizeof(test##n##_plaintext), \
5282efe996bSSam Leffler 	test##n##_encrypted, sizeof(test##n##_encrypted) \
5292efe996bSSam Leffler }
5302efe996bSSam Leffler 
5312efe996bSSam Leffler struct ciphertest {
5322efe996bSSam Leffler 	const char	*name;
5332efe996bSSam Leffler 	int		cipher;
5342efe996bSSam Leffler 	int		keyix;
5352efe996bSSam Leffler 	u_int64_t	pn;
5362efe996bSSam Leffler 	const u_int8_t	*key;
5372efe996bSSam Leffler 	size_t		key_len;
5382efe996bSSam Leffler 	const u_int8_t	*plaintext;
5392efe996bSSam Leffler 	size_t		plaintext_len;
5402efe996bSSam Leffler 	const u_int8_t	*encrypted;
5412efe996bSSam Leffler 	size_t		encrypted_len;
5422efe996bSSam Leffler } ccmptests[] = {
5432efe996bSSam Leffler 	TEST(1, "CCMP test mpdu 1", AES_CCM, 0, 199027030681356),
5442efe996bSSam Leffler 	TEST(2, "CCMP test mpdu 2", AES_CCM, 2, 54923164817386),
5452efe996bSSam Leffler 	TEST(3, "CCMP test mpdu 3", AES_CCM, 2, 52624639632814),
5462efe996bSSam Leffler 	TEST(4, "CCMP test mpdu 4", AES_CCM, 0, 270963670912995),
5472efe996bSSam Leffler 	TEST(5, "CCMP test mpdu 5", AES_CCM, 2, 184717420531255),
5482efe996bSSam Leffler 	TEST(6, "CCMP test mpdu 6", AES_CCM, 1, 118205765159305),
5492efe996bSSam Leffler 	TEST(7, "CCMP test mpdu 7", AES_CCM, 3, 104368786630435),
5502efe996bSSam Leffler 	TEST(8, "CCMP test mpdu 8", AES_CCM, 2, 227588596223197),
5512efe996bSSam Leffler };
5522efe996bSSam Leffler 
5532efe996bSSam Leffler static void
dumpdata(const char * tag,const void * p,size_t len)5542efe996bSSam Leffler dumpdata(const char *tag, const void *p, size_t len)
5552efe996bSSam Leffler {
5562efe996bSSam Leffler 	int i;
5572efe996bSSam Leffler 
5582efe996bSSam Leffler 	printf("%s: 0x%p len %u", tag, p, len);
5592efe996bSSam Leffler 	for (i = 0; i < len; i++) {
5602efe996bSSam Leffler 		if ((i % 16) == 0)
5612efe996bSSam Leffler 			printf("\n%03d:", i);
5622efe996bSSam Leffler 		printf(" %02x", ((const u_int8_t *)p)[i]);
5632efe996bSSam Leffler 	}
5642efe996bSSam Leffler 	printf("\n");
5652efe996bSSam Leffler }
5662efe996bSSam Leffler 
5672efe996bSSam Leffler static void
cmpfail(const void * gen,size_t genlen,const void * ref,size_t reflen)5682efe996bSSam Leffler cmpfail(const void *gen, size_t genlen, const void *ref, size_t reflen)
5692efe996bSSam Leffler {
5702efe996bSSam Leffler 	int i;
5712efe996bSSam Leffler 
5722efe996bSSam Leffler 	for (i = 0; i < genlen; i++)
5732efe996bSSam Leffler 		if (((const u_int8_t *)gen)[i] != ((const u_int8_t *)ref)[i]) {
5742efe996bSSam Leffler 			printf("first difference at byte %u\n", i);
5752efe996bSSam Leffler 			break;
5762efe996bSSam Leffler 		}
5772efe996bSSam Leffler 	dumpdata("Generated", gen, genlen);
5782efe996bSSam Leffler 	dumpdata("Reference", ref, reflen);
5792efe996bSSam Leffler }
5802efe996bSSam Leffler 
5812efe996bSSam Leffler static void
printtest(const struct ciphertest * t)5822efe996bSSam Leffler printtest(const struct ciphertest *t)
5832efe996bSSam Leffler {
5842efe996bSSam Leffler 	printf("keyix %u pn %llu key_len %u plaintext_len %u\n"
5852efe996bSSam Leffler 		, t->keyix
5862efe996bSSam Leffler 		, t->pn
5872efe996bSSam Leffler 		, t->key_len
5882efe996bSSam Leffler 		, t->plaintext_len
5892efe996bSSam Leffler 	);
5902efe996bSSam Leffler }
5912efe996bSSam Leffler 
5922efe996bSSam Leffler static int
runtest(struct ieee80211vap * vap,struct ciphertest * t)593*3c64fc9cSAndriy Voskoboinyk runtest(struct ieee80211vap *vap, struct ciphertest *t)
5942efe996bSSam Leffler {
595*3c64fc9cSAndriy Voskoboinyk 	struct ieee80211_key *key = &vap->iv_nw_keys[t->keyix];
5962efe996bSSam Leffler 	struct mbuf *m = NULL;
5972efe996bSSam Leffler 	const struct ieee80211_cipher *cip;
598*3c64fc9cSAndriy Voskoboinyk 	int hdrlen;
5992efe996bSSam Leffler 
6002efe996bSSam Leffler 	printf("%s: ", t->name);
6012efe996bSSam Leffler 
6022efe996bSSam Leffler 	/*
6032efe996bSSam Leffler 	 * Setup key.
6042efe996bSSam Leffler 	 */
605*3c64fc9cSAndriy Voskoboinyk 	memset(key, 0, sizeof(*key));
606*3c64fc9cSAndriy Voskoboinyk 	key->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
607*3c64fc9cSAndriy Voskoboinyk 	key->wk_cipher = &ieee80211_cipher_none;
608*3c64fc9cSAndriy Voskoboinyk 	if (!ieee80211_crypto_newkey(vap, t->cipher,
609*3c64fc9cSAndriy Voskoboinyk 	    IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, key)) {
6102efe996bSSam Leffler 		printf("FAIL: ieee80211_crypto_newkey failed\n");
6112efe996bSSam Leffler 		goto bad;
6122efe996bSSam Leffler 	}
6132efe996bSSam Leffler 
614*3c64fc9cSAndriy Voskoboinyk 	memcpy(key->wk_key, t->key, t->key_len);
615*3c64fc9cSAndriy Voskoboinyk 	key->wk_keylen = t->key_len;
616*3c64fc9cSAndriy Voskoboinyk 	memset(key->wk_keyrsc, 0, sizeof(key->wk_keyrsc));
617*3c64fc9cSAndriy Voskoboinyk 	key->wk_keytsc = t->pn-1;	/* PN-1 since we do encap */
618*3c64fc9cSAndriy Voskoboinyk 	if (!ieee80211_crypto_setkey(vap, key)) {
6192efe996bSSam Leffler 		printf("FAIL: ieee80211_crypto_setkey failed\n");
6202efe996bSSam Leffler 		goto bad;
6212efe996bSSam Leffler 	}
6222efe996bSSam Leffler 
6232efe996bSSam Leffler 	/*
6242efe996bSSam Leffler 	 * Craft frame from plaintext data.
6252efe996bSSam Leffler 	 */
626*3c64fc9cSAndriy Voskoboinyk 	cip = key->wk_cipher;
6272efe996bSSam Leffler 	m = m_getcl(M_NOWAIT, MT_HEADER, M_PKTHDR);
6282efe996bSSam Leffler 	m->m_data += cip->ic_header;
6292efe996bSSam Leffler 	memcpy(mtod(m, void *), t->plaintext, t->plaintext_len);
6302efe996bSSam Leffler 	m->m_len = t->plaintext_len;
6312efe996bSSam Leffler 	m->m_pkthdr.len = m->m_len;
632*3c64fc9cSAndriy Voskoboinyk 	hdrlen = ieee80211_anyhdrsize(mtod(m, void *));
6332efe996bSSam Leffler 
6342efe996bSSam Leffler 	/*
6352efe996bSSam Leffler 	 * Encrypt frame w/ MIC.
6362efe996bSSam Leffler 	 */
637*3c64fc9cSAndriy Voskoboinyk 	if (!cip->ic_encap(key, m)) {
6382efe996bSSam Leffler 		printtest(t);
6392efe996bSSam Leffler 		printf("FAIL: ccmp encap failed\n");
6402efe996bSSam Leffler 		goto bad;
6412efe996bSSam Leffler 	}
6422efe996bSSam Leffler 	/*
6432efe996bSSam Leffler 	 * Verify: frame length, frame contents.
6442efe996bSSam Leffler 	 */
6452efe996bSSam Leffler 	if (m->m_pkthdr.len != t->encrypted_len) {
6462efe996bSSam Leffler 		printf("FAIL: encap data length mismatch\n");
6472efe996bSSam Leffler 		printtest(t);
6482efe996bSSam Leffler 		cmpfail(mtod(m, const void *), m->m_pkthdr.len,
6492efe996bSSam Leffler 			t->encrypted, t->encrypted_len);
6502efe996bSSam Leffler 		goto bad;
6512efe996bSSam Leffler 	} else if (memcmp(mtod(m, const void *), t->encrypted, t->encrypted_len)) {
6522efe996bSSam Leffler 		printf("FAIL: encrypt data does not compare\n");
6532efe996bSSam Leffler 		printtest(t);
6542efe996bSSam Leffler 		cmpfail(mtod(m, const void *), m->m_pkthdr.len,
6552efe996bSSam Leffler 			t->encrypted, t->encrypted_len);
6562efe996bSSam Leffler 		dumpdata("Plaintext", t->plaintext, t->plaintext_len);
6572efe996bSSam Leffler 		goto bad;
6582efe996bSSam Leffler 	}
6592efe996bSSam Leffler 
6602efe996bSSam Leffler 	/*
6612efe996bSSam Leffler 	 * Decrypt frame; strip MIC.
6622efe996bSSam Leffler 	 */
663*3c64fc9cSAndriy Voskoboinyk 	if (!cip->ic_decap(key, m, hdrlen)) {
6642efe996bSSam Leffler 		printf("FAIL: ccmp decap failed\n");
6652efe996bSSam Leffler 		printtest(t);
6662efe996bSSam Leffler 		cmpfail(mtod(m, const void *), m->m_len,
6672efe996bSSam Leffler 			t->plaintext, t->plaintext_len);
6682efe996bSSam Leffler 		goto bad;
6692efe996bSSam Leffler 	}
6702efe996bSSam Leffler 	/*
6712efe996bSSam Leffler 	 * Verify: frame length, frame contents.
6722efe996bSSam Leffler 	 */
6732efe996bSSam Leffler 	if (m->m_pkthdr.len != t->plaintext_len) {
6742efe996bSSam Leffler 		printf("FAIL: decap botch; length mismatch\n");
6752efe996bSSam Leffler 		printtest(t);
6762efe996bSSam Leffler 		cmpfail(mtod(m, const void *), m->m_pkthdr.len,
6772efe996bSSam Leffler 			t->plaintext, t->plaintext_len);
6782efe996bSSam Leffler 		goto bad;
6792efe996bSSam Leffler 	} else if (memcmp(mtod(m, const void *), t->plaintext, t->plaintext_len)) {
6802efe996bSSam Leffler 		printf("FAIL: decap botch; data does not compare\n");
6812efe996bSSam Leffler 		printtest(t);
6822efe996bSSam Leffler 		cmpfail(mtod(m, const void *), m->m_pkthdr.len,
683*3c64fc9cSAndriy Voskoboinyk 			t->plaintext, t->plaintext_len);
6842efe996bSSam Leffler 		goto bad;
6852efe996bSSam Leffler 	}
6862efe996bSSam Leffler 	m_freem(m);
687*3c64fc9cSAndriy Voskoboinyk 	ieee80211_crypto_delkey(vap, key);
6882efe996bSSam Leffler 	printf("PASS\n");
6892efe996bSSam Leffler 	return 1;
6902efe996bSSam Leffler bad:
6912efe996bSSam Leffler 	if (m != NULL)
6922efe996bSSam Leffler 		m_freem(m);
693*3c64fc9cSAndriy Voskoboinyk 	ieee80211_crypto_delkey(vap, key);
6942efe996bSSam Leffler 	return 0;
6952efe996bSSam Leffler }
6962efe996bSSam Leffler 
6972efe996bSSam Leffler /*
6982efe996bSSam Leffler  * Module glue.
6992efe996bSSam Leffler  */
7002efe996bSSam Leffler 
7012efe996bSSam Leffler static	int tests = -1;
7022efe996bSSam Leffler static	int debug = 0;
7032efe996bSSam Leffler 
7042efe996bSSam Leffler static int
init_crypto_ccmp_test(void)7052efe996bSSam Leffler init_crypto_ccmp_test(void)
7062efe996bSSam Leffler {
7072efe996bSSam Leffler 	struct ieee80211com ic;
708*3c64fc9cSAndriy Voskoboinyk 	struct ieee80211vap vap;
709*3c64fc9cSAndriy Voskoboinyk 	struct ifnet ifp;
7102efe996bSSam Leffler 	int i, pass, total;
7112efe996bSSam Leffler 
7122efe996bSSam Leffler 	memset(&ic, 0, sizeof(ic));
713*3c64fc9cSAndriy Voskoboinyk 	memset(&vap, 0, sizeof(vap));
714*3c64fc9cSAndriy Voskoboinyk 	memset(&ifp, 0, sizeof(ifp));
715*3c64fc9cSAndriy Voskoboinyk 
7162efe996bSSam Leffler 	ieee80211_crypto_attach(&ic);
7172efe996bSSam Leffler 
718*3c64fc9cSAndriy Voskoboinyk 	/* some minimal initialization */
719*3c64fc9cSAndriy Voskoboinyk 	strncpy(ifp.if_xname, "test_ccmp", sizeof(ifp.if_xname));
720*3c64fc9cSAndriy Voskoboinyk 	vap.iv_ic = &ic;
721*3c64fc9cSAndriy Voskoboinyk 	vap.iv_ifp = &ifp;
722*3c64fc9cSAndriy Voskoboinyk 	if (debug)
723*3c64fc9cSAndriy Voskoboinyk 		vap.iv_debug = IEEE80211_MSG_CRYPTO;
724*3c64fc9cSAndriy Voskoboinyk 	ieee80211_crypto_vattach(&vap);
725*3c64fc9cSAndriy Voskoboinyk 
7262efe996bSSam Leffler 	pass = 0;
7272efe996bSSam Leffler 	total = 0;
728*3c64fc9cSAndriy Voskoboinyk 	for (i = 0; i < nitems(ccmptests); i++)
7292efe996bSSam Leffler 		if (tests & (1<<i)) {
7302efe996bSSam Leffler 			total++;
731*3c64fc9cSAndriy Voskoboinyk 			pass += runtest(&vap, &ccmptests[i]);
7322efe996bSSam Leffler 		}
7332efe996bSSam Leffler 	printf("%u of %u 802.11i AES-CCMP test vectors passed\n", pass, total);
734*3c64fc9cSAndriy Voskoboinyk 
735*3c64fc9cSAndriy Voskoboinyk 	ieee80211_crypto_vdetach(&vap);
7362efe996bSSam Leffler 	ieee80211_crypto_detach(&ic);
737*3c64fc9cSAndriy Voskoboinyk 
7382efe996bSSam Leffler 	return (pass == total ? 0 : -1);
7392efe996bSSam Leffler }
7402efe996bSSam Leffler 
7412efe996bSSam Leffler static int
test_ccmp_modevent(module_t mod,int type,void * unused)7422efe996bSSam Leffler test_ccmp_modevent(module_t mod, int type, void *unused)
7432efe996bSSam Leffler {
7442efe996bSSam Leffler 	switch (type) {
7452efe996bSSam Leffler 	case MOD_LOAD:
7462efe996bSSam Leffler 		(void) init_crypto_ccmp_test();
7472efe996bSSam Leffler 		return 0;
7482efe996bSSam Leffler 	case MOD_UNLOAD:
7492efe996bSSam Leffler 		return 0;
7502efe996bSSam Leffler 	}
7512efe996bSSam Leffler 	return EINVAL;
7522efe996bSSam Leffler }
7532efe996bSSam Leffler 
7542efe996bSSam Leffler static moduledata_t test_ccmp_mod = {
7552efe996bSSam Leffler 	"test_ccmp",
7562efe996bSSam Leffler 	test_ccmp_modevent,
7579823d527SKevin Lo 	0
7582efe996bSSam Leffler };
7592efe996bSSam Leffler DECLARE_MODULE(test_ccmp, test_ccmp_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
7602efe996bSSam Leffler MODULE_VERSION(test_ccmp, 1);
7612efe996bSSam Leffler MODULE_DEPEND(test_ccmp, wlan, 1, 1, 1);
762