Debian Codegraph @

test/cryptounittest/test-calc-mic.c

raw
1 /*
2 *
3 * test-calc-mic.c
4 *
5 * Copyright (C) 2012 Carlos Alberto Lopez Perez <[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/defs.h"
35 #include "aircrack-ng/aircrack-ng.h"
36 #include "aircrack-ng/crypto/crypto.h"
37 #include "tests.h"
38
39 int main(int argc, char ** argv)
40 {
41 if (argc < 1) return 1;
42
43 int error = 0;
44 static unsigned char opmk[32]
45 = "\x6f\xe8\x57\xc0\xb7\x42\xdf\xc2\xda\x8a\x1f\xe8\xb1\xb4\xb4\x62"
46 "\x8d\x9f\xbb\xb0\x60\x82\x6b\x83\xcb\x43\xb6\x4b\x13\xe1\x03\xe8";
47
48 static unsigned char optk[80]
49 = "\x28\x00\x00\x00\x00\x00\x00\x00\x18\x81\xd5\x96\xff\x7f\x00\x00"
50 "\x64\x00\x00\x00\x00\x00\x00\x00\x9f\x84\x00\x51\xd8\x7f\x00\x00"
51 "\x58\x33\xcf\x01\x00\x00\x00\x00\x21\x00\x00\x00\x00\x00\x00\x00"
52 "\x10\xb3\xd3\x01\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00"
53 "\x30\x9d\xd3\x01\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00";
54
55 static unsigned char omic[20]
56 = "\x01\x00\x00\x00\x00\x00\x00\x00\x64\x00\x00\x00\x00\x00\x00\x00"
57 "\x30\x9d\xd3\x01";
58
59 //expected
60 static unsigned char eptk[80]
61 = "\x9a\x75\xef\x0b\xde\x7c\x20\x9c\xca\xe1\x3f\x54\xb1\xb3\x3e\xa3"
62 "\xfa\x01\x66\x16\x6e\x30\x81\x1f\x1b\xaa\xff\x8d\x1c\x1a\xc1\x63"
63 "\x82\xa4\x9b\x50\xb8\x60\x88\xc5\xcb\x79\x3b\x54\x26\x61\xa2\x8a"
64 "\x64\x69\x3c\x72\xb8\x66\x73\xe0\xa8\x2d\x48\xc7\x47\x68\xcb\xf9"
65 "\xa1\xbf\x86\xcc\x30\xb9\xd6\x3d\xe8\x82\x59\x25\xec\x1f\x4d\x3f";
66 // expected emic when wpa.keyver=2
67 static unsigned char emic2[20]
68 = "\x6f\x04\x89\xcf\x74\x06\xac\xf0\xae\x8f\xcb\x32\xbc\xe5\x7c\x37"
69 "\x79\x3a\x23\x61";
70 // expected emic when wpa.keyver=1
71 static unsigned char emic1[20]
72 = "\x9c\xc3\xfa\xa0\xc6\x85\x96\x1d\x84\x06\xbb\x65\x77\x45\x13\x5d"
73 "\x30\x9d\xd3\x01";
74 // AP structure
75 struct AP_info l_ap;
76 struct AP_info * ap = &l_ap;
77 bzero(ap, sizeof(struct AP_info));
78
79 unsigned char stmac[6] = "\x00\x13\x46\xfe\x32\x0c";
80 unsigned char snonce[32]
81 = "\x59\x16\x8b\xc3\xa5\xdf\x18\xd7\x1e\xfb\x64\x23\xf3\x40\x08\x8d"
82 "\xab\x9e\x1b\xa2\xbb\xc5\x86\x59\xe0\x7b\x37\x64\xb0\xde\x85\x70";
83 unsigned char anonce[32]
84 = "\x22\x58\x54\xb0\x44\x4d\xe3\xaf\x06\xd1\x49\x2b\x85\x29\x84\xf0"
85 "\x4c\xf6\x27\x4c\x0e\x32\x18\xb8\x68\x17\x56\x86\x4d\xb7\xa0\x55";
86 unsigned char keymic[16]
87 = "\xd5\x35\x53\x82\xb8\xa9\xb8\x06\xdc\xaf\x99\xcd\xaf\x56\x4e\xb6";
88 unsigned char eapol[256]
89 = "\x01\x03\x00\x75\x02\x01\x0a\x00\x10\x00\x00\x00\x00\x00\x00\x00"
90 "\x01\x59\x16\x8b\xc3\xa5\xdf\x18\xd7\x1e\xfb\x64\x23\xf3\x40\x08"
91 "\x8d\xab\x9e\x1b\xa2\xbb\xc5\x86\x59\xe0\x7b\x37\x64\xb0\xde\x85"
92 "\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
93 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
94 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
95 "\x00\x00\x16\x30\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac"
96 "\x04\x01\x00\x00\x0f\xac\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00"
97 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
98 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
99 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
100 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
101 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
102 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
103 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
104 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
105 unsigned char bssid[6] = "\x00\x14\x6c\x7e\x40\x80";
106 unsigned char essid[33] = "Harkonen";
107
108 struct WPA_hdsk wpa; /* valid WPA handshake data */
109 memset(&wpa, 0, sizeof(wpa));
110 memcpy(&wpa.stmac, &stmac, 6);
111 memcpy(&wpa.snonce, &snonce, 32);
112 memcpy(&wpa.anonce, &anonce, 32);
113 memcpy(&wpa.keymic, &keymic, 16);
114 memcpy(&wpa.eapol, &eapol, 256);
115 wpa.eapol_size = 121;
116 wpa.state = 7;
117 memcpy(&ap->bssid, bssid, 6);
118 memcpy(&ap->essid, essid, 33);
119
120 unsigned char pmk[32];
121 memcpy(&pmk, &opmk, 32);
122 unsigned char ptk[80];
123 memcpy(&ptk, &optk, 80);
124 unsigned char mic[20];
125 memcpy(&mic, &omic, 20);
126
127 wpa.keyver = 1;
128 ap->wpa = wpa;
129 calc_mic(ap, pmk, ptk, mic);
130
131 error += test(pmk, opmk, 32, argv[0]);
132 error += test(ptk, eptk, 80, argv[0]);
133 error += test(mic, emic1, 20, argv[0]);
134
135 wpa.keyver = 2;
136 ap->wpa = wpa;
137 calc_mic(ap, pmk, ptk, mic);
138 error += test(pmk, opmk, 32, argv[0]);
139 error += test(ptk, eptk, 80, argv[0]);
140 error += test(mic, emic2, 20, argv[0]);
141
142 return error;
143 }