Path: blob/main/tools/regression/net80211/ccmp/test_ccmp.c
106278 views
/*-1* Copyright (c) 2004 Sam Leffler, Errno Consulting2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. The name of the author may not be used to endorse or promote products13* derived from this software without specific prior written permission.14*15* Alternatively, this software may be distributed under the terms of the16* GNU General Public License ("GPL") version 2 as published by the Free17* Software Foundation.18*19* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR20* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES21* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.22* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,23* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT24* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,25* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY26* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT27* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF28* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.29*/3031/*32* CCMP test module.33*34* Test vectors come from section I.7.4 of P802.11i/D7.0, October 2003.35*36* To use this tester load the net80211 layer (either as a module or37* by statically configuring it into your kernel), then kldload this38* module. It should automatically run all test cases and print39* information for each. To run one or more tests you can specify a40* tests parameter to the module that is a bit mask of the set of tests41* you want; e.g. insmod ccmp_test tests=7 will run only test mpdu's42* 1, 2, and 3.43*/44#include <sys/param.h>45#include <sys/kernel.h>46#include <sys/systm.h>47#include <sys/mbuf.h>48#include <sys/module.h>4950#include <sys/socket.h>5152#include <net/if.h>53#include <net/if_var.h>54#include <net/if_media.h>5556#include <net80211/ieee80211_var.h>5758/*59==== CCMP test mpdu 1 ====6061-- MPDU Fields62637 Version = 0648 Type = 2 SubType = 0 Data659 ToDS = 0 FromDS = 06610 MoreFrag = 0 Retry = 16711 PwrMgt = 0 moreData = 06812 Encrypt = 16913 Order = 07014 Duration = 114597115 A1 = 0f-d2-e1-28-a5-7c DA7216 A2 = 50-30-f1-84-44-08 SA7317 A3 = ab-ae-a5-b8-fc-ba BSSID7418 SC = 0x33807519 seqNum = 824 (0x0338) fraqNum = 0 (0x00)7620 Algorithm = AES_CCM7721 Key ID = 07822 TK = c9 7c 1f 67 ce 37 11 85 51 4a 8a 19 f2 bd d5 2f7923 PN = 199027030681356 (0xB5039776E70C)8024 802.11 Header = 08 48 c3 2c 0f d2 e1 28 a5 7c 50 30 f1 84 44 088125 ab ae a5 b8 fc ba 80 338226 Muted 802.11 Header = 08 40 0f d2 e1 28 a5 7c 50 30 f1 84 44 088327 ab ae a5 b8 fc ba 00 008428 CCMP Header = 0c e7 00 20 76 97 03 b58529 CCM Nonce = 00 50 30 f1 84 44 08 b5 03 97 76 e7 0c8630 Plaintext Data = f8 ba 1a 55 d0 2f 85 ae 96 7b b6 2f b6 cd a8 eb871 7e 78 a0 50882 CCM MIC = 78 45 ce 0b 16 f9 76 23893 -- Encrypted MPDU with FCS904 08 48 c3 2c 0f d2 e1 28 a5 7c 50 30 f1 84 44 08 ab ae a5 b8 fc ba915 80 33 0c e7 00 20 76 97 03 b5 f3 d0 a2 fe 9a 3d bf 23 42 a6 43 e4926 32 46 e8 0c 3c 04 d0 19 78 45 ce 0b 16 f9 76 23 1d 99 f0 6693*/94static const u_int8_t test1_key[] = { /* TK */950xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85, 0x51, 0x4a, 0x8a,960x19, 0xf2, 0xbd, 0xd5, 0x2f97};98static const u_int8_t test1_plaintext[] = { /* Plaintext MPDU w/o MIC */990x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28, /* 802.11 Header */1000xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,1010xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,1020xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae, /* Plaintext Data */1030x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,1040x7e, 0x78, 0xa0, 0x50,105};106static const u_int8_t test1_encrypted[] = { /* Encrypted MPDU with MIC */1070x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,1080xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,1090xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,1100x0c, 0xe7, 0x00, 0x20, 0x76, 0x97, 0x03, 0xb5,1110xf3, 0xd0, 0xa2, 0xfe, 0x9a, 0x3d, 0xbf, 0x23,1120x42, 0xa6, 0x43, 0xe4, 0x32, 0x46, 0xe8, 0x0c,1130x3c, 0x04, 0xd0, 0x19, 0x78, 0x45, 0xce, 0x0b,1140x16, 0xf9, 0x76, 0x23,115};116117/*118==== CCMP test mpdu 2 ====119120-- MPDU Fields1211229 Version = 012310 Type = 2 SubType = 3 Data+CF-Ack+CF-Poll12411 ToDS = 0 FromDS = 012512 MoreFrag = 0 Retry = 012613 PwrMgt = 0 moreData = 012714 Encrypt = 112815 Order = 112916 Duration = 2084213017 A1 = ea-10-0c-84-68-50 DA13118 A2 = ee-c1-76-2c-88-de SA13219 A3 = af-2e-e9-f4-6a-07 BSSID13320 SC = 0xCCE013421 seqNum = 3278 (0x0CCE) fraqNum = 0 (0x00)13522 Algorithm = AES_CCM13623 Key ID = 213724 TK = 8f 7a 05 3f a5 77 a5 59 75 29 27 20 97 a6 03 d513825 PN = 54923164817386 (0x31F3CBBA97EA)13926 802.11 Header = 38 c0 6a 51 ea 10 0c 84 68 50 ee c1 76 2c 88 de14027 af 2e e9 f4 6a 07 e0 cc14128 Muted 802.11 Header = 08 c0 ea 10 0c 84 68 50 ee c1 76 2c 88 de14229 af 2e e9 f4 6a 07 00 0014330 CCMP Header = ea 97 00 a0 ba cb f3 3114431 CCM Nonce = 00 ee c1 76 2c 88 de 31 f3 cb ba 97 ea14532 Plaintext Data = 83 a0 63 4b 5e d7 62 7e b9 df 22 5e 05 74 03 4214633 de 19 41 1714734 CCM MIC = 54 2f bf 8d a0 6a a4 ae14835 -- Encrypted MPDU with FCS14936 38 c0 6a 51 ea 10 0c 84 68 50 ee c1 76 2c 88 de af 2e e9 f4 6a 0715037 e0 cc ea 97 00 a0 ba cb f3 31 81 4b 69 65 d0 5b f2 b2 ed 38 d4 be15138 b0 69 fe 82 71 4a 61 0b 54 2f bf 8d a0 6a a4 ae 25 3c 47 38152*/153static const u_int8_t test2_key[] = { /* TK */1540x8f, 0x7a, 0x05, 0x3f, 0xa5, 0x77, 0xa5, 0x59, 0x75, 0x29, 0x27,1550x20, 0x97, 0xa6, 0x03, 0xd5156};157static const u_int8_t test2_plaintext[] = { /* Plaintext MPDU w/o MIC */1580x38, 0xc0, 0x6a, 0x51, 0xea, 0x10, 0x0c, 0x84, 0x68, 0x50, 0xee,1590xc1, 0x76, 0x2c, 0x88, 0xde, 0xaf, 0x2e, 0xe9, 0xf4, 0x6a, 0x07,1600xe0, 0xcc,1610x83, 0xa0, 0x63, 0x4b, 0x5e, 0xd7, 0x62, 0x7e, 0xb9, 0xdf, 0x22,1620x5e, 0x05, 0x74, 0x03, 0x42, 0xde, 0x19, 0x41, 0x17163};164static const u_int8_t test2_encrypted[] = { /* Encrypted MPDU with MIC */1650x38, 0xc0, 0x6a, 0x51, 0xea, 0x10, 0x0c, 0x84, 0x68, 0x50, 0xee,1660xc1, 0x76, 0x2c, 0x88, 0xde, 0xaf, 0x2e, 0xe9, 0xf4, 0x6a, 0x07,1670xe0, 0xcc, 0xea, 0x97, 0x00, 0xa0, 0xba, 0xcb, 0xf3, 0x31, 0x81,1680x4b, 0x69, 0x65, 0xd0, 0x5b, 0xf2, 0xb2, 0xed, 0x38, 0xd4, 0xbe,1690xb0, 0x69, 0xfe, 0x82, 0x71, 0x4a, 0x61, 0x0b, 0x54, 0x2f, 0xbf,1700x8d, 0xa0, 0x6a, 0xa4, 0xae,171};172173/*174==== CCMP test mpdu 3 ====175176-- MPDU Fields17717841 Version = 017942 Type = 2 SubType = 1118043 ToDS = 0 FromDS = 018144 MoreFrag = 0 Retry = 118245 PwrMgt = 0 moreData = 018346 Encrypt = 118447 Order = 118548 Duration = 2505218649 A1 = d9-57-7d-f7-63-c8 DA18750 A2 = b6-a8-8a-df-36-91 SA1881 A3 = dc-4a-8b-ca-94-dd BSSID1892 SC = 0x82601903 seqNum = 2086 (0x0826) fraqNum = 0 (0x00)1914 QC = 0x00001925 MSDU Priority = 0 (0x0)1936 Algorithm = AES_CCM1947 Key ID = 21958 TK = 40 cf b7 a6 2e 88 01 3b d6 d3 af fc c1 91 04 1e1969 PN = 52624639632814 (0x2FDCA0F3A5AE)19710 802.11 Header = b8 c8 dc 61 d9 57 7d f7 63 c8 b6 a8 8a df 36 9119811 dc 4a 8b ca 94 dd 60 82 20 8519912 Muted 802.11 Header = 88 c0 d9 57 7d f7 63 c8 b6 a8 8a df 36 9120013 dc 4a 8b ca 94 dd 00 00 00 0020114 CCMP Header = ae a5 00 a0 f3 a0 dc 2f20215 CCM Nonce = 00 b6 a8 8a df 36 91 2f dc a0 f3 a5 ae20316 Plaintext Data = 2c 1b d0 36 83 1c 95 49 6c 5f 4d bf 3d 55 9e 7220417 de 80 2a 1820518 CCM MIC = fd 1f 1f 61 a9 fb 4b b320619 -- Encrypted MPDU with FCS20720 b8 c8 dc 61 d9 57 7d f7 63 c8 b6 a8 8a df 36 91 dc 4a 8b ca 94 dd20821 60 82 20 85 ae a5 00 a0 f3 a0 dc 2f 89 d8 58 03 40 b6 26 a0 b6 d420922 d0 13 bf 18 f2 91 b8 96 46 c8 fd 1f 1f 61 a9 fb 4b b3 60 3f 5a ad210*/211static const u_int8_t test3_key[] = { /* TK */2120x40, 0xcf, 0xb7, 0xa6, 0x2e, 0x88, 0x01, 0x3b, 0xd6, 0xd3,2130xaf, 0xfc, 0xc1, 0x91, 0x04, 0x1e214};215static const u_int8_t test3_plaintext[] = { /* Plaintext MPDU w/o MIC */2160xb8, 0xc8, 0xdc, 0x61, 0xd9, 0x57, 0x7d, 0xf7, 0x63, 0xc8,2170xb6, 0xa8, 0x8a, 0xdf, 0x36, 0x91, 0xdc, 0x4a, 0x8b, 0xca,2180x94, 0xdd, 0x60, 0x82, 0x20, 0x85,2190x2c, 0x1b, 0xd0, 0x36, 0x83, 0x1c, 0x95, 0x49, 0x6c, 0x5f,2200x4d, 0xbf, 0x3d, 0x55, 0x9e, 0x72, 0xde, 0x80, 0x2a, 0x18221};222static const u_int8_t test3_encrypted[] = { /* Encrypted MPDU with MIC */2230xb8, 0xc8, 0xdc, 0x61, 0xd9, 0x57, 0x7d, 0xf7, 0x63, 0xc8,2240xb6, 0xa8, 0x8a, 0xdf, 0x36, 0x91, 0xdc, 0x4a, 0x8b, 0xca,2250x94, 0xdd, 0x60, 0x82, 0x20, 0x85, 0xae, 0xa5, 0x00, 0xa0,2260xf3, 0xa0, 0xdc, 0x2f, 0x89, 0xd8, 0x58, 0x03, 0x40, 0xb6,2270x26, 0xa0, 0xb6, 0xd4, 0xd0, 0x13, 0xbf, 0x18, 0xf2, 0x91,2280xb8, 0x96, 0x46, 0xc8, 0xfd, 0x1f, 0x1f, 0x61, 0xa9, 0xfb,2290x4b, 0xb3,230};231232/*233==== CCMP test mpdu 4 ====234235-- MPDU Fields23625 Version = 023726 Type = 2 SubType = 1023827 ToDS = 0 FromDS = 123928 MoreFrag = 0 Retry = 124029 PwrMgt = 0 moreData = 024130 Encrypt = 124231 Order = 124332 Duration = 441024433 A1 = 71-2a-9d-df-11-db DA24534 A2 = 8e-f8-22-73-47-01 BSSID24635 A3 = 59-14-0d-d6-46-a2 SA24736 SC = 0x2FC024837 seqNum = 764 (0x02FC) fraqNum = 0 (0x00)24938 QC = 0x000725039 MSDU Priority = 7 (0x0)25140 Algorithm = AES_CCM25241 Key ID = 025342 TK = 8c 89 a2 eb c9 6c 76 02 70 7f cf 24 b3 2d 38 3325443 PN = 270963670912995 (0xF670A55A0FE3)25544 802.11 Header = a8 ca 3a 11 71 2a 9d df 11 db 8e f8 22 73 47 0125645 59 14 0d d6 46 a2 c0 2f 67 a525746 Muted 802.11 Header = 88 c2 71 2a 9d df 11 db 8e f8 22 73 47 0125847 59 14 0d d6 46 a2 00 00 07 0025948 CCMP Header = e3 0f 00 20 5a a5 70 f626049 CCM Nonce = 07 8e f8 22 73 47 01 f6 70 a5 5a 0f e326150 Plaintext Data = 4f ad 2b 1c 29 0f a5 eb d8 72 fb c3 f3 a0 74 8926251 8f 8b 2f bb26352 CCM MIC = 31 fc 88 00 4f 35 ee 3d264-- Encrypted MPDU with FCS2652 a8 ca 3a 11 71 2a 9d df 11 db 8e f8 22 73 47 01 59 14 0d d6 46 a22663 c0 2f 67 a5 e3 0f 00 20 5a a5 70 f6 9d 59 b1 5f 37 14 48 c2 30 f42674 d7 39 05 2e 13 ab 3b 1a 7b 10 31 fc 88 00 4f 35 ee 3d 45 a7 4a 30268*/269static const u_int8_t test4_key[] = { /* TK */2700x8c, 0x89, 0xa2, 0xeb, 0xc9, 0x6c, 0x76, 0x02,2710x70, 0x7f, 0xcf, 0x24, 0xb3, 0x2d, 0x38, 0x33,272};273static const u_int8_t test4_plaintext[] = { /* Plaintext MPDU w/o MIC */2740xa8, 0xca, 0x3a, 0x11, 0x71, 0x2a, 0x9d, 0xdf, 0x11, 0xdb,2750x8e, 0xf8, 0x22, 0x73, 0x47, 0x01, 0x59, 0x14, 0x0d, 0xd6,2760x46, 0xa2, 0xc0, 0x2f, 0x67, 0xa5,2770x4f, 0xad, 0x2b, 0x1c, 0x29, 0x0f, 0xa5, 0xeb, 0xd8, 0x72,2780xfb, 0xc3, 0xf3, 0xa0, 0x74, 0x89, 0x8f, 0x8b, 0x2f, 0xbb,279};280static const u_int8_t test4_encrypted[] = { /* Encrypted MPDU with MIC */2810xa8, 0xca, 0x3a, 0x11, 0x71, 0x2a, 0x9d, 0xdf, 0x11, 0xdb,2820x8e, 0xf8, 0x22, 0x73, 0x47, 0x01, 0x59, 0x14, 0x0d, 0xd6,2830x46, 0xa2, 0xc0, 0x2f, 0x67, 0xa5, 0xe3, 0x0f, 0x00, 0x20,2840x5a, 0xa5, 0x70, 0xf6, 0x9d, 0x59, 0xb1, 0x5f, 0x37, 0x14,2850x48, 0xc2, 0x30, 0xf4, 0xd7, 0x39, 0x05, 0x2e, 0x13, 0xab,2860x3b, 0x1a, 0x7b, 0x10, 0x31, 0xfc, 0x88, 0x00, 0x4f, 0x35,2870xee, 0x3d,288};289290/*291==== CCMP test mpdu 5 ====292293-- MPDU Fields2942957 Version = 02968 Type = 2 SubType = 82979 ToDS = 0 FromDS = 129810 MoreFrag = 0 Retry = 129911 PwrMgt = 1 moreData = 030012 Encrypt = 130113 Order = 130214 Duration = 1666430315 A1 = 45-de-c6-9a-74-80 DA30416 A2 = f3-51-94-6b-c9-6b BSSID30517 A3 = e2-76-fb-e6-c1-27 SA30618 SC = 0xF28030719 seqNum = 3880 (0x0F28) fraqNum = 0 (0x00)30820 QC = 0x000b30921 MSDU Priority = 0 (0x0)31022 Algorithm = AES_CCM31123 Key ID = 231224 TK = a5 74 d5 14 3b b2 5e fd de ff 30 12 2f df d0 6631325 PN = 184717420531255 (0xA7FFE03C0E37)31426 802.11 Header = 88 da 18 41 45 de c6 9a 74 80 f3 51 94 6b c9 6b31527 e2 76 fb e6 c1 27 80 f2 4b 1931628 Muted 802.11 Header = 88 c2 45 de c6 9a 74 80 f3 51 94 6b c9 6b31729 e2 76 fb e6 c1 27 00 00 0b 0031830 CCMP Header = 37 0e 00 a0 3c e0 ff a731931 CCM Nonce = 0b f3 51 94 6b c9 6b a7 ff e0 3c 0e 3732032 Plaintext Data = 28 96 9b 95 4f 26 3a 80 18 a9 ef 70 a8 b0 51 4632133 24 81 92 2e32234 CCM MIC = ce 0c 3b e1 97 d3 05 eb32335 -- Encrypted MPDU with FCS32436 88 da 18 41 45 de c6 9a 74 80 f3 51 94 6b c9 6b e2 76 fb e6 c1 2732537 80 f2 4b 19 37 0e 00 a0 3c e0 ff a7 eb 4a e4 95 6a 80 1d a9 62 4b32638 7e 0c 18 b2 3e 61 5e c0 3a f6 ce 0c 3b e1 97 d3 05 eb c8 9e a1 b5327*/328static const u_int8_t test5_key[] = { /* TK */3290xa5, 0x74, 0xd5, 0x14, 0x3b, 0xb2, 0x5e, 0xfd,3300xde, 0xff, 0x30, 0x12, 0x2f, 0xdf, 0xd0, 0x66,331};332static const u_int8_t test5_plaintext[] = { /* Plaintext MPDU w/o MIC */3330x88, 0xda, 0x18, 0x41, 0x45, 0xde, 0xc6, 0x9a, 0x74, 0x80,3340xf3, 0x51, 0x94, 0x6b, 0xc9, 0x6b, 0xe2, 0x76, 0xfb, 0xe6,3350xc1, 0x27, 0x80, 0xf2, 0x4b, 0x19,3360x28, 0x96, 0x9b, 0x95, 0x4f, 0x26, 0x3a, 0x80, 0x18, 0xa9,3370xef, 0x70, 0xa8, 0xb0, 0x51, 0x46, 0x24, 0x81, 0x92, 0x2e,338};339static const u_int8_t test5_encrypted[] = { /* Encrypted MPDU with MIC */3400x88, 0xda, 0x18, 0x41, 0x45, 0xde, 0xc6, 0x9a, 0x74, 0x80,3410xf3, 0x51, 0x94, 0x6b, 0xc9, 0x6b, 0xe2, 0x76, 0xfb, 0xe6,3420xc1, 0x27, 0x80, 0xf2, 0x4b, 0x19, 0x37, 0x0e, 0x00, 0xa0,3430x3c, 0xe0, 0xff, 0xa7, 0xeb, 0x4a, 0xe4, 0x95, 0x6a, 0x80,3440x1d, 0xa9, 0x62, 0x4b, 0x7e, 0x0c, 0x18, 0xb2, 0x3e, 0x61,3450x5e, 0xc0, 0x3a, 0xf6, 0xce, 0x0c, 0x3b, 0xe1, 0x97, 0xd3,3460x05, 0xeb,347};348349/*350==== CCMP test mpdu 6 ====351352-- MPDU Fields35335441 Version = 035542 Type = 2 SubType = 835643 ToDS = 0 FromDS = 135744 MoreFrag = 0 Retry = 035845 PwrMgt = 1 moreData = 035946 Encrypt = 136047 Order = 036148 Duration = 816136249 A1 = 5a-f2-84-30-fd-ab DA36350 A2 = bf-f9-43-b9-f9-a6 BSSID3641 A3 = ab-1d-98-c7-fe-73 SA3652 SC = 0x71503663 seqNum = 1813 (0x0715) fraqNum = 0 (0x00)3674 QC = 0x000d3685 PSDU Priority = 13 (0xd)3696 Algorithm = AES_CCM3707 Key ID = 13718 TK = f7 1e ea 4e 1f 58 80 4b 97 17 23 0a d0 61 46 413729 PN = 118205765159305 (0x6B81ECA48989)37310 802.11 Header = 88 52 e1 1f 5a f2 84 30 fd ab bf f9 43 b9 f9 a637411 ab 1d 98 c7 fe 73 50 71 3d 6a37512 Muted 802.11 Header = 88 42 5a f2 84 30 fd ab bf f9 43 b9 f9 a637613 ab 1d 98 c7 fe 73 00 00 0d 0037714 CCMP Header = 89 89 00 60 a4 ec 81 6b37815 CCM Nonce = 0d bf f9 43 b9 f9 a6 6b 81 ec a4 89 8937916 Plaintext Data = ab fd a2 2d 3a 0b fc 9c c1 fc 07 93 63 c2 fc a138017 43 e6 eb 1d38118 CCM MIC = 30 9a 8d 5c 46 6b bb 7138219 -- Encrypted MPDU with FCS38320 88 52 e1 1f 5a f2 84 30 fd ab bf f9 43 b9 f9 a6 ab 1d 98 c7 fe 7338421 50 71 3d 6a 89 89 00 60 a4 ec 81 6b 9a 70 9b 60 a3 9d 40 b1 df b638522 12 e1 8b 5f 11 4b ad b6 cc 86 30 9a 8d 5c 46 6b bb 71 86 c0 4e 97386*/387static const u_int8_t test6_key[] = { /* TK */3880xf7, 0x1e, 0xea, 0x4e, 0x1f, 0x58, 0x80, 0x4b,3890x97, 0x17, 0x23, 0x0a, 0xd0, 0x61, 0x46, 0x41,390};391static const u_int8_t test6_plaintext[] = { /* Plaintext MPDU w/o MIC */3920x88, 0x52, 0xe1, 0x1f, 0x5a, 0xf2, 0x84, 0x30, 0xfd, 0xab,3930xbf, 0xf9, 0x43, 0xb9, 0xf9, 0xa6, 0xab, 0x1d, 0x98, 0xc7,3940xfe, 0x73, 0x50, 0x71, 0x3d, 0x6a,3950xab, 0xfd, 0xa2, 0x2d, 0x3a, 0x0b, 0xfc, 0x9c, 0xc1, 0xfc,3960x07, 0x93, 0x63, 0xc2, 0xfc, 0xa1, 0x43, 0xe6, 0xeb, 0x1d,397};398static const u_int8_t test6_encrypted[] = { /* Encrypted MPDU with MIC */3990x88, 0x52, 0xe1, 0x1f, 0x5a, 0xf2, 0x84, 0x30, 0xfd, 0xab,4000xbf, 0xf9, 0x43, 0xb9, 0xf9, 0xa6, 0xab, 0x1d, 0x98, 0xc7,4010xfe, 0x73, 0x50, 0x71, 0x3d, 0x6a, 0x89, 0x89, 0x00, 0x60,4020xa4, 0xec, 0x81, 0x6b, 0x9a, 0x70, 0x9b, 0x60, 0xa3, 0x9d,4030x40, 0xb1, 0xdf, 0xb6, 0x12, 0xe1, 0x8b, 0x5f, 0x11, 0x4b,4040xad, 0xb6, 0xcc, 0x86, 0x30, 0x9a, 0x8d, 0x5c, 0x46, 0x6b,4050xbb, 0x71,406};407408/*409==== CCMP test mpdu 7 ====410411-- MPDU Fields41241325 Version = 041426 Type = 2 SubType = 1 Data+CF-Ack41527 ToDS = 1 FromDS = 041628 MoreFrag = 0 Retry = 141729 PwrMgt = 1 moreData = 141830 Encrypt = 141931 Order = 042032 Duration = 1804942133 A1 = 9b-50-f4-fd-56-f6 BSSID42234 A2 = ef-ec-95-20-16-91 SA42335 A3 = 83-57-0c-4c-cd-ee DA42436 SC = 0xA02042537 seqNum = 2562 (0x0A02) fraqNum = 0 (0x00)42638 Algorithm = AES_CCM42739 Key ID = 342840 TK = 1b db 34 98 0e 03 81 24 a1 db 1a 89 2b ec 36 6a42941 PN = 104368786630435 (0x5EEC4073E723)43042 Header = 18 79 81 46 9b 50 f4 fd 56 f6 ef ec 95 20 16 91 83 5743143 0c 4c cd ee 20 a043244 Muted MAC Header = 08 41 9b 50 f4 fd 56 f6 ef ec 95 20 16 9143345 83 57 0c 4c cd ee 00 0043446 CCMP Header = 23 e7 00 e0 73 40 ec 5e43547 CCM Nonce = 00 ef ec 95 20 16 91 5e ec 40 73 e7 2343648 Plaintext Data = 98 be ca 86 f4 b3 8d a2 0c fd f2 47 24 c5 8e b843749 35 66 53 3943850 CCM MIC = 2d 09 57 ec fa be 95 b9439-- Encrypted MPDU with FCS4401 18 79 81 46 9b 50 f4 fd 56 f6 ef ec 95 20 16 91 83 57 0c 4c cd ee4412 20 a0 23 e7 00 e0 73 40 ec 5e 12 c5 37 eb f3 ab 58 4e f1 fe f9 a14423 f3 54 7a 8c 13 b3 22 5a 2d 09 57 ec fa be 95 b9 aa fa 0c c8443*/444static const u_int8_t test7_key[] = { /* TK */4450x1b, 0xdb, 0x34, 0x98, 0x0e, 0x03, 0x81, 0x24,4460xa1, 0xdb, 0x1a, 0x89, 0x2b, 0xec, 0x36, 0x6a,447};448static const u_int8_t test7_plaintext[] = { /* Plaintext MPDU w/o MIC */4490x18, 0x79, 0x81, 0x46, 0x9b, 0x50, 0xf4, 0xfd, 0x56, 0xf6,4500xef, 0xec, 0x95, 0x20, 0x16, 0x91, 0x83, 0x57, 0x0c, 0x4c,4510xcd, 0xee, 0x20, 0xa0,4520x98, 0xbe, 0xca, 0x86, 0xf4, 0xb3, 0x8d, 0xa2, 0x0c, 0xfd,4530xf2, 0x47, 0x24, 0xc5, 0x8e, 0xb8, 0x35, 0x66, 0x53, 0x39,454};455static const u_int8_t test7_encrypted[] = { /* Encrypted MPDU with MIC */4560x18, 0x79, 0x81, 0x46, 0x9b, 0x50, 0xf4, 0xfd, 0x56, 0xf6,4570xef, 0xec, 0x95, 0x20, 0x16, 0x91, 0x83, 0x57, 0x0c, 0x4c,4580xcd, 0xee, 0x20, 0xa0, 0x23, 0xe7, 0x00, 0xe0, 0x73, 0x40,4590xec, 0x5e, 0x12, 0xc5, 0x37, 0xeb, 0xf3, 0xab, 0x58, 0x4e,4600xf1, 0xfe, 0xf9, 0xa1, 0xf3, 0x54, 0x7a, 0x8c, 0x13, 0xb3,4610x22, 0x5a, 0x2d, 0x09, 0x57, 0xec, 0xfa, 0xbe, 0x95, 0xb9,462};463464/*465==== CCMP test mpdu 8 ====466467-- MPDU Fields4684696 Version = 04707 Type = 2 SubType = 114718 ToDS = 1 FromDS = 04729 MoreFrag = 0 Retry = 147310 PwrMgt = 1 moreData = 047411 Encrypt = 147512 Order = 147613 Duration = 2926047714 A1 = 55-2d-5f-72-bb-70 BSSID47815 A2 = ca-3f-3a-ae-60-c4 SA47916 A3 = 8b-a9-b5-f8-2c-2f DA48017 SC = 0xEB5048118 seqNum = 3765 (0x0EB5) fraqNum = 0 (0x00)48219 QC = 0x000a48320 MSDU Priority = 10 (0xa)48421 Algorithm = AES_CCM48522 Key ID = 248623 TK = 6e ac 1b f5 4b d5 4e db 23 21 75 43 03 02 4c 7148724 PN = 227588596223197 (0xCEFD996ECCDD)48825 802.11 Header = b8 d9 4c 72 55 2d 5f 72 bb 70 ca 3f 3a ae 60 c448926 8b a9 b5 f8 2c 2f 50 eb 2a 5549027 Muted 802.11 Header = 88 c1 55 2d 5f 72 bb 70 ca 3f 3a ae 60 c449128 8b a9 b5 f8 2c 2f 00 00 0a 0049229 CCMP Header = dd cc 00 a0 6e 99 fd ce49330 CCM Nonce = 0a ca 3f 3a ae 60 c4 ce fd 99 6e cc dd49431 Plaintext Data = 57 cb 5c 0e 5f cd 88 5e 9a 42 39 e9 b9 ca d6 0d49532 64 37 59 7949633 CCM MIC = 6d ba 8e f7 f0 80 87 dd497-- Encrypted MPDU with FCS49835 b8 d9 4c 72 55 2d 5f 72 bb 70 ca 3f 3a ae 60 c4 8b a9 b5 f8 2c 2f49936 50 eb 2a 55 dd cc 00 a0 6e 99 fd ce 4b f2 81 ef 8e c7 73 9f 91 5950037 1b 97 a8 7d c1 4b 3f a1 74 62 6d ba 8e f7 f0 80 87 dd 0c 65 74 3f501*/502static const u_int8_t test8_key[] = { /* TK */5030x6e, 0xac, 0x1b, 0xf5, 0x4b, 0xd5, 0x4e, 0xdb,5040x23, 0x21, 0x75, 0x43, 0x03, 0x02, 0x4c, 0x71,505};506static const u_int8_t test8_plaintext[] = { /* Plaintext MPDU w/o MIC */5070xb8, 0xd9, 0x4c, 0x72, 0x55, 0x2d, 0x5f, 0x72, 0xbb, 0x70,5080xca, 0x3f, 0x3a, 0xae, 0x60, 0xc4, 0x8b, 0xa9, 0xb5, 0xf8,5090x2c, 0x2f, 0x50, 0xeb, 0x2a, 0x55,5100x57, 0xcb, 0x5c, 0x0e, 0x5f, 0xcd, 0x88, 0x5e, 0x9a, 0x42,5110x39, 0xe9, 0xb9, 0xca, 0xd6, 0x0d, 0x64, 0x37, 0x59, 0x79,512};513static const u_int8_t test8_encrypted[] = { /* Encrypted MPDU with MIC */5140xb8, 0xd9, 0x4c, 0x72, 0x55, 0x2d, 0x5f, 0x72, 0xbb, 0x70,5150xca, 0x3f, 0x3a, 0xae, 0x60, 0xc4, 0x8b, 0xa9, 0xb5, 0xf8,5160x2c, 0x2f, 0x50, 0xeb, 0x2a, 0x55, 0xdd, 0xcc, 0x00, 0xa0,5170x6e, 0x99, 0xfd, 0xce, 0x4b, 0xf2, 0x81, 0xef, 0x8e, 0xc7,5180x73, 0x9f, 0x91, 0x59, 0x1b, 0x97, 0xa8, 0x7d, 0xc1, 0x4b,5190x3f, 0xa1, 0x74, 0x62, 0x6d, 0xba, 0x8e, 0xf7, 0xf0, 0x80,5200x87, 0xdd,521};522523#define TEST(n,name,cipher,keyix,pn) { \524name, IEEE80211_CIPHER_##cipher,keyix, pn##LL, \525test##n##_key, sizeof(test##n##_key), \526test##n##_plaintext, sizeof(test##n##_plaintext), \527test##n##_encrypted, sizeof(test##n##_encrypted) \528}529530struct ciphertest {531const char *name;532int cipher;533int keyix;534u_int64_t pn;535const u_int8_t *key;536size_t key_len;537const u_int8_t *plaintext;538size_t plaintext_len;539const u_int8_t *encrypted;540size_t encrypted_len;541} ccmptests[] = {542TEST(1, "CCMP test mpdu 1", AES_CCM, 0, 199027030681356),543TEST(2, "CCMP test mpdu 2", AES_CCM, 2, 54923164817386),544TEST(3, "CCMP test mpdu 3", AES_CCM, 2, 52624639632814),545TEST(4, "CCMP test mpdu 4", AES_CCM, 0, 270963670912995),546TEST(5, "CCMP test mpdu 5", AES_CCM, 2, 184717420531255),547TEST(6, "CCMP test mpdu 6", AES_CCM, 1, 118205765159305),548TEST(7, "CCMP test mpdu 7", AES_CCM, 3, 104368786630435),549TEST(8, "CCMP test mpdu 8", AES_CCM, 2, 227588596223197),550};551552static void553dumpdata(const char *tag, const void *p, size_t len)554{555int i;556557printf("%s: 0x%p len %u", tag, p, len);558for (i = 0; i < len; i++) {559if ((i % 16) == 0)560printf("\n%03d:", i);561printf(" %02x", ((const u_int8_t *)p)[i]);562}563printf("\n");564}565566static void567cmpfail(const void *gen, size_t genlen, const void *ref, size_t reflen)568{569int i;570571for (i = 0; i < genlen; i++)572if (((const u_int8_t *)gen)[i] != ((const u_int8_t *)ref)[i]) {573printf("first difference at byte %u\n", i);574break;575}576dumpdata("Generated", gen, genlen);577dumpdata("Reference", ref, reflen);578}579580static void581printtest(const struct ciphertest *t)582{583printf("keyix %u pn %llu key_len %u plaintext_len %u\n"584, t->keyix585, t->pn586, t->key_len587, t->plaintext_len588);589}590591static int592runtest(struct ieee80211vap *vap, struct ciphertest *t)593{594struct ieee80211_key *key = &vap->iv_nw_keys[t->keyix];595struct mbuf *m = NULL;596const struct ieee80211_cipher *cip;597int hdrlen;598599printf("%s: ", t->name);600601/*602* Setup key.603*/604memset(key, 0, sizeof(*key));605key->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;606key->wk_cipher = &ieee80211_cipher_none;607if (!ieee80211_crypto_newkey(vap, t->cipher,608IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, key)) {609printf("FAIL: ieee80211_crypto_newkey failed\n");610goto bad;611}612613memcpy(key->wk_key, t->key, t->key_len);614key->wk_keylen = t->key_len;615memset(key->wk_keyrsc, 0, sizeof(key->wk_keyrsc));616key->wk_keytsc = t->pn-1; /* PN-1 since we do encap */617if (!ieee80211_crypto_setkey(vap, key)) {618printf("FAIL: ieee80211_crypto_setkey failed\n");619goto bad;620}621622/*623* Craft frame from plaintext data.624*/625cip = key->wk_cipher;626m = m_getcl(M_NOWAIT, MT_HEADER, M_PKTHDR);627m->m_data += cip->ic_header;628memcpy(mtod(m, void *), t->plaintext, t->plaintext_len);629m->m_len = t->plaintext_len;630m->m_pkthdr.len = m->m_len;631hdrlen = ieee80211_anyhdrsize(mtod(m, void *));632633/*634* Encrypt frame w/ MIC.635*/636if (!cip->ic_encap(key, m)) {637printtest(t);638printf("FAIL: ccmp encap failed\n");639goto bad;640}641/*642* Verify: frame length, frame contents.643*/644if (m->m_pkthdr.len != t->encrypted_len) {645printf("FAIL: encap data length mismatch\n");646printtest(t);647cmpfail(mtod(m, const void *), m->m_pkthdr.len,648t->encrypted, t->encrypted_len);649goto bad;650} else if (memcmp(mtod(m, const void *), t->encrypted, t->encrypted_len)) {651printf("FAIL: encrypt data does not compare\n");652printtest(t);653cmpfail(mtod(m, const void *), m->m_pkthdr.len,654t->encrypted, t->encrypted_len);655dumpdata("Plaintext", t->plaintext, t->plaintext_len);656goto bad;657}658659/*660* Decrypt frame; strip MIC.661*/662if (!cip->ic_decap(key, m, hdrlen)) {663printf("FAIL: ccmp decap failed\n");664printtest(t);665cmpfail(mtod(m, const void *), m->m_len,666t->plaintext, t->plaintext_len);667goto bad;668}669/*670* Verify: frame length, frame contents.671*/672if (m->m_pkthdr.len != t->plaintext_len) {673printf("FAIL: decap botch; length mismatch\n");674printtest(t);675cmpfail(mtod(m, const void *), m->m_pkthdr.len,676t->plaintext, t->plaintext_len);677goto bad;678} else if (memcmp(mtod(m, const void *), t->plaintext, t->plaintext_len)) {679printf("FAIL: decap botch; data does not compare\n");680printtest(t);681cmpfail(mtod(m, const void *), m->m_pkthdr.len,682t->plaintext, t->plaintext_len);683goto bad;684}685m_freem(m);686ieee80211_crypto_delkey(vap, key);687printf("PASS\n");688return 1;689bad:690if (m != NULL)691m_freem(m);692ieee80211_crypto_delkey(vap, key);693return 0;694}695696/*697* Module glue.698*/699700static int tests = -1;701static int debug = 0;702703static int704init_crypto_ccmp_test(void)705{706struct ieee80211com ic;707struct ieee80211vap vap;708struct ifnet ifp;709int i, pass, total;710711memset(&ic, 0, sizeof(ic));712memset(&vap, 0, sizeof(vap));713memset(&ifp, 0, sizeof(ifp));714715ieee80211_crypto_attach(&ic);716717/* some minimal initialization */718strncpy(ifp.if_xname, "test_ccmp", sizeof(ifp.if_xname));719vap.iv_ic = ⁣720vap.iv_ifp = &ifp;721if (debug)722vap.iv_debug = IEEE80211_MSG_CRYPTO;723ieee80211_crypto_vattach(&vap);724725pass = 0;726total = 0;727for (i = 0; i < nitems(ccmptests); i++)728if (tests & (1<<i)) {729total++;730pass += runtest(&vap, &ccmptests[i]);731}732printf("%u of %u 802.11i AES-CCMP test vectors passed\n", pass, total);733734ieee80211_crypto_vdetach(&vap);735ieee80211_crypto_detach(&ic);736737return (pass == total ? 0 : -1);738}739740static int741test_ccmp_modevent(module_t mod, int type, void *unused)742{743switch (type) {744case MOD_LOAD:745(void) init_crypto_ccmp_test();746return 0;747case MOD_UNLOAD:748return 0;749}750return EINVAL;751}752753static moduledata_t test_ccmp_mod = {754"test_ccmp",755test_ccmp_modevent,7560757};758DECLARE_MODULE(test_ccmp, test_ccmp_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);759MODULE_VERSION(test_ccmp, 1);760MODULE_DEPEND(test_ccmp, wlan, 1, 1, 1);761762763