Debian Codegraph @

lib/ce-wep/uniqueiv.c

raw symbols SCIP
1 /*
2 * IV uniqueness detection method.
3 *
4 * Copyright (C) 2004-2008 Stanislaw Pusep:
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 *
21 * In addition, as a special exception, the copyright holders give
22 * permission to link the code of portions of this program with the
23 * OpenSSL library under certain conditions as described in each
24 * individual source file, and distribute linked combinations
25 * including the two.
26 * You must obey the GNU General Public License in all respects
27 * for all of the code used other than OpenSSL. * If you modify
28 * file(s) with this exception, you may extend this exception to your
29 * version of the file(s), but you are not obligated to do so. * If you
30 * do not wish to do so, delete this exception statement from your
31 * version. * If you delete this exception statement from all source
32 * files in the program, then also delete it here.
33 */
34
35 /*
36 * Each IV byte is stored in corresponding "level". We have 3 levels with
37 * IV[2] as root index (level 0), IV[1] and IV[2] as level 2 and level 1
38 * indices respectively. Space required to allocate all data is at maximum
39 * 2^24/8 (2 MB) and space required by filled index structures is 257 KB.
40 */
41
42 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`!
43 #include "config.h"cxx . . $ `<file>/config.h`/
44 #endif
45
46 #include <stdlib.h>
47
48 #include "aircrack-ng/defs.h"cxx . . $ `<file>/include/aircrack-ng/defs.h`/
49 #include "aircrack-ng/ce-wep/uniqueiv.h"cxx . . $ `<file>/include/aircrack-ng/ce-wep/uniqueiv.h`/
50
51 /* allocate root structure */
52
53 unsigned char ** uniqueiv_initcxx . . $ uniqueiv_init(8d4b1aa48f4fba7d).(void)
54 {
55 int i;
56
57 /* allocate root bucket (level 0) as vector of pointers */
58
59 unsigned char ** uiv_root
60 = (unsigned char **) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(256 * sizeof(unsigned char *));
61
62 if (uiv_root == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) return (NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
63
64 /* setup initial state as empty */
65
66 for (i = 0; i < 256; ++i) uiv_root[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
67
68 return (uiv_root);
69 }
70
71 /* update records with new IV */
72
73 int uniqueiv_markcxx . . $ uniqueiv_mark(75dd5cdb910d2114).(unsigned char ** uiv_root, unsigned char IV[3])
74 {
75 unsigned char ** uiv_lvl1;
76 unsigned char * uiv_lvl2;
77 short i;
78
79 if (uiv_root == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) return (0);
80
81 /* select bucket from level 1 */
82
83 uiv_lvl1 = (unsigned char **) uiv_root[IV[2]];
84
85 /* create if it doesn't exist */
86
87 if (uiv_lvl1 == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
88 {
89 /* allocate level 2 bucket being a vector of bits */
90
91 uiv_lvl1 = (unsigned char **) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(256 * sizeof(unsigned char *));
92
93 if (uiv_lvl1 == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) return (1);
94
95 /* setup initial state as empty */
96
97 for (i = 0; i < 256; i++) uiv_lvl1[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
98
99 /* link to parent bucket */
100
101 uiv_root[IV[2]] = (unsigned char *) uiv_lvl1;
102 }
103
104 /* select bucket from level 2 */
105
106 uiv_lvl2 = (unsigned char *) uiv_lvl1[IV[1]];
107
108 /* create if it doesn't exist */
109
110 if (uiv_lvl2 == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
111 {
112 /* allocate level 2 bucket as a vector of pointers */
113
114 uiv_lvl2 = (unsigned char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(32 * sizeof(unsigned char));
115
116 if (uiv_lvl2 == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) return (1);
117
118 /* setup initial state as empty */
119
120 for (i = 0; i < 32; i++) uiv_lvl2[i] = 0;
121
122 /* link to parent bucket */
123
124 uiv_lvl1[IV[1]] = uiv_lvl2;
125 }
126
127 /* place single bit into level 2 bucket */
128
129 uiv_lvl2[BITWISE_OFFTcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:43:9`!(IV[0])] |= BITWISE_MASKcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:47:9`!(IV[0]);
130
131 return (0);
132 }
133
134 /* check if already seen IV */
135
136 int uniqueiv_checkcxx . . $ uniqueiv_check(75dd5cdb910d2114).(unsigned char ** uiv_root, unsigned char IV[3])
137 {
138 unsigned char ** uiv_lvl1;
139 unsigned char * uiv_lvl2;
140
141 if (uiv_root == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) return (IV_NOTHEREcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:38:9`!);
142
143 /* select bucket from level 1 */
144
145 uiv_lvl1 = (unsigned char **) uiv_root[IV[2]];
146
147 /* stop here if not even allocated */
148
149 if (uiv_lvl1 == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) return (IV_NOTHEREcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:38:9`!);
150
151 /* select bucket from level 2 */
152
153 uiv_lvl2 = (unsigned char *) uiv_lvl1[IV[1]];
154
155 /* stop here if not even allocated */
156
157 if (uiv_lvl2 == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) return (IV_NOTHEREcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:38:9`!);
158
159 /* check single bit from level 2 bucket */
160
161 if ((uiv_lvl2[BITWISE_OFFTcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:43:9`!(IV[0])] & BITWISE_MASKcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:47:9`!(IV[0])) == 0)
162 return (IV_NOTHEREcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:38:9`!);
163 else
164 return (IV_PRESENTcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:39:9`!);
165 }
166
167 /* unallocate everything */
168
169 void uniqueiv_wipecxx . . $ uniqueiv_wipe(4b3a895eaed56756).(unsigned char ** uiv_root)
170 {
171 int i, j;
172 unsigned char ** uiv_lvl1;
173 unsigned char * uiv_lvl2;
174
175 if (uiv_root == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) return;
176
177 /* recursively wipe out allocated buckets */
178
179 for (i = 0; i < 256; ++i)
180 {
181 uiv_lvl1 = (unsigned char **) uiv_root[i];
182
183 if (uiv_lvl1 != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
184 {
185 for (j = 0; j < 256; ++j)
186 {
187 uiv_lvl2 = (unsigned char *) uiv_lvl1[j];
188
189 if (uiv_lvl2 != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
190 {
191 freecxx . . $ free(5d22bdacc48458e8).(uiv_lvl2);
192 uiv_lvl2 = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
193 }
194 }
195
196 freecxx . . $ free(5d22bdacc48458e8).(uiv_lvl1);
197 uiv_lvl1 = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
198 }
199 }
200
201 freecxx . . $ free(5d22bdacc48458e8).(uiv_root);
202 uiv_root = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
203
204 return;
205 }
206
207 unsigned char * data_initcxx . . $ data_init(37d8967d10cb1e7b).(void)
208 {
209 // It could eat up to (256*256*256) * 3 bytes = 48Mb :/
210 unsigned char * IVs
211 = (unsigned char *) calloccxx . . $ calloc(63a7bf2941bfcd7a).(256 * 256 * 256 * 3, sizeof(unsigned char));
212 ALLEGEcxx . . $ `include/aircrack-ng/defs.h:42:9`!(IVs != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
213 return (IVs);
214 }
215
216 /* Checking WEP packet:
217 * The 2 first bytes of 2 different data packets having the same IV (for the
218 * same AP)
219 * should be exactly the same due to the fact that unencrypted, they are always
220 * the same:
221 * AA AA
222 */
223
224 int data_checkcxx . . $ data_check(e258224de377f1a3).(unsigned char * data_root,
225 unsigned char IV[3],
226 unsigned char data[2])
227 {
228 int IV_position, cloaking;
229
230 // Init vars
231 cloaking = NO_CLOAKINGcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:54:9`!;
232
233 // Make sure it is allocated
234 if (data_root != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
235 {
236 // Try to find IV
237 IV_position = (((IV[0] * 256) + IV[1]) * 256) + IV[2];
238 IV_position *= 3;
239
240 // Check if existing
241 if (*(data_root + IV_position) == 0)
242 {
243 // Not existing
244 *(data_root + IV_position) = 1;
245
246 // Add it
247 *(data_root + IV_position + 1) = data[0];
248 *(data_root + IV_position + 2) = data[1];
249 }
250 else
251 {
252 // Good, we found it, so check it now
253 if (*(data_root + IV_position + 1) != data[0]
254 || *(data_root + IV_position + 2) != data[1])
255 {
256 cloaking = CLOAKINGcxx . . $ `include/aircrack-ng/ce-wep/uniqueiv.h:55:9`!;
257 }
258 }
259 }
260 // else, cannot detect since it is not started
261
262 return (cloaking);
263 }
264
265 void data_wipecxx . . $ data_wipe(f25546b61a629de7).(unsigned char * data)
266 {
267 if (data) freecxx . . $ free(5d22bdacc48458e8).(data);
268 }