Debian Codegraph @

test/cryptounittest/test-encrypt-ccmp.c

raw
1 /*
2 *
3 * test-encrypt-ccmp.c
4 *
5 * Copyright (C) 2015 Jorn van Engelen <[email protected]>
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301, USA.
22 *
23 */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <strings.h>
32 #include <stdlib.h>
33
34 #include "aircrack-ng/crypto/crypto.h"
35 #include "tests.h"
36
37 #define BUFFER_SIZE 65536
38
39 int main(int argc, char ** argv)
40 {
41 int error = 0;
42 int caplen = 44;
43
44 // CCMP test vector as described in IEEE 802.11(TM)-2012, Section M.6.4.
45
46 unsigned char tk1[16]
47 = "\xc9\x7c\x1f\x67\xce\x37\x11\x85\x51\x4a\x8a\x19\xf2\xbd\xd5\x2f";
48
49 unsigned char pn[6] = "\xb5\x03\x97\x76\xe7\x0c";
50
51 unsigned char h80211[44]
52 = "\x08\x48\xc3\x2c\x0f\xd2\xe1\x28\xa5\x7c\x50\x30\xf1\x84\x44\x08"
53 "\xab\xae\xa5\xb8\xfc\xba\x80\x33\xf8\xba\x1a\x55\xd0\x2f\x85\xae"
54 "\x96\x7b\xb6\x2f\xb6\xcd\xa8\xeb\x7e\x78\xa0\x50";
55
56 unsigned char expected[60]
57 = "\x08\x48\xc3\x2c\x0f\xd2\xe1\x28\xa5\x7c\x50\x30\xf1\x84\x44\x08"
58 "\xab\xae\xa5\xb8\xfc\xba\x80\x33\x0c\xe7\x00\x20\x76\x97\x03\xb5"
59 "\xf3\xd0\xa2\xfe\x9a\x3d\xbf\x23\x42\xa6\x43\xe4\x32\x46\xe8\x0c"
60 "\x3c\x04\xd0\x19\x78\x45\xce\x0b\x16\xf9\x76\x23";
61
62 unsigned char expected_output[BUFFER_SIZE];
63 unsigned char input[BUFFER_SIZE];
64
65 if (argc < 1) return 1;
66
67 bzero(expected_output, BUFFER_SIZE);
68 bzero(input, BUFFER_SIZE);
69 memcpy(expected_output, expected, sizeof(expected));
70 memcpy(input, h80211, sizeof(h80211));
71
72 caplen = encrypt_ccmp(input, caplen, tk1, pn);
73 if (caplen != sizeof(expected)) error++;
74 error += test(input, expected_output, sizeof(expected), argv[0]);
75
76 return error;
77 }