Debian Codegraph @

test/cryptounittest/test-calc-ptk.c

raw
1 /*
2 *
3 * test-calc-ptk.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 <assert.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <strings.h>
33 #include <stdlib.h>
34
35 #include "aircrack-ng/defs.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 = "\xee\x51\x88\x37\x93\xa6\xf6\x8e\x96\x15\xfe\x73\xc8\x0a\x3a\xa6"
46 "\xf2\xdd\x0e\xa5\x37\xbc\xe6\x27\xb9\x29\x18\x3c\xc6\xe5\x79\x25";
47
48 static unsigned char ostmac[6] = "\x00\x13\x46\xfe\x32\x0c";
49 static unsigned char obssid[6] = "\x00\x14\x6c\x7e\x40\x80";
50 static unsigned char osnonce[32]
51 = "\x59\x16\x8b\xc3\xa5\xdf\x18\xd7\x1e\xfb\x64\x23\xf3\x40\x08\x8d"
52 "\xab\x9e\x1b\xa2\xbb\xc5\x86\x59\xe0\x7b\x37\x64\xb0\xde\x85\x70";
53 static unsigned char oanonce[32]
54 = "\x22\x58\x54\xb0\x44\x4d\xe3\xaf\x06\xd1\x49\x2b\x85\x29\x84\xf0"
55 "\x4c\xf6\x27\x4c\x0e\x32\x18\xb8\x68\x17\x56\x86\x4d\xb7\xa0\x55";
56 static unsigned char okeymic[20]
57 = "\xd5\x35\x53\x82\xb8\xa9\xb8\x06\xdc\xaf\x99\xcd\xaf\x56\x4e\xb6"
58 "\x00\x00\x00\x00";
59
60 static unsigned char optk[80]
61 = "\x0d\xde\xae\x80\x83\xf9\x2c\xa9\xaf\xdb\x25\x0d\xde\xe5\x25\x1b"
62 "\xc0\xee\xb4\x7e\xf2\x2a\xf7\x9e\x25\x34\x6e\x8b\x73\xe2\xca\x7d"
63 "\x94\xb0\x60\x5f\x2e\xed\x66\xd8\x60\x76\xb3\x38\xa6\x65\xfe\xe3"
64 "\x9f\xde\x22\x1e\xb1\x38\x6b\x3d\xa7\xac\x6a\xbe\x7e\xe0\x00\x1f"
65 "\xbd\x92\xab\xec\xc8\xba\x49\xf0\x5d\xff\x8f\x50\x1e\xfa\xaa\xcc";
66
67 static unsigned char eptk[80]
68 = "\xea\x0e\x40\x46\x33\xc8\x02\x45\x03\x02\x86\x8c\xca\xa7\x49\xde"
69 "\x5c\xba\x5a\xbc\xb2\x67\xe2\xde\x1d\x5e\x21\xe5\x7a\xcc\xd5\x07"
70 "\x9b\x31\xe9\xff\x22\x0e\x13\x2a\xe4\xf6\xed\x9e\xf1\xac\xc8\x85"
71 "\x45\x82\x5f\xc3\x2e\xe5\x59\x61\x39\x5a\xe4\x37\x34\xd6\xc1\x07"
72 "\x98\xef\x5a\xfe\x42\xc0\x74\x26\x47\x18\x68\xa5\x77\xd4\xd1\x7e";
73
74 static unsigned char oeapol[256]
75 = "\x01\x03\x00\x75\x02\x01\x0a\x00\x10\x00\x00\x00\x00\x00\x00\x00"
76 "\x01\x59\x16\x8b\xc3\xa5\xdf\x18\xd7\x1e\xfb\x64\x23\xf3\x40\x08"
77 "\x8d\xab\x9e\x1b\xa2\xbb\xc5\x86\x59\xe0\x7b\x37\x64\xb0\xde\x85"
78 "\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
79 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
80 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
81 "\x00\x00\x16\x30\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac"
82 "\x04\x01\x00\x00\x0f\xac\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00"
83 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
84 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
85 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
86 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
87 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
88 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
89 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
90 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
91
92 unsigned char pmk[32];
93 memcpy(&pmk, &opmk, 32);
94
95 struct WPA_ST_info l_wpa;
96 struct WPA_ST_info * wpa = &l_wpa;
97 // default to zero
98 bzero(wpa, sizeof(struct WPA_ST_info));
99
100 memcpy(wpa->stmac, &ostmac, 6);
101 memcpy(wpa->bssid, &obssid, 6);
102 memcpy(wpa->ptk, &optk, 80);
103 memcpy(wpa->anonce, &oanonce, 32);
104
105 // not valid_ptk
106 if ((1 == 1) == (calc_ptk(wpa, pmk))) error++;
107 error += test(pmk, opmk, 32, argv[0]);
108 error += test(wpa->ptk, optk, 80, argv[0]);
109
110 // calc another one
111 wpa->eapol_size = 121;
112 memcpy(wpa->eapol, &oeapol, 256);
113 memcpy(wpa->keymic, &okeymic, 20);
114 memcpy(wpa->snonce, &osnonce, 32);
115
116 // valid ptk
117 if ((1 == 1) != (calc_ptk(wpa, pmk))) error++;
118 error += test(pmk, opmk, 32, argv[0]);
119 error += test(wpa->ptk, eptk, 80, argv[0]);
120
121 return error;
122 }