/
esp__test_8c-source.html
371 lines (369 loc) · 29.5 KB
/
esp__test_8c-source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<html>
<head>
<title>embedded IPsec - IPsec library</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="doxygen.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="98%" border="0" align="center">
<tr>
<td>
<h2 align="left"><img src="logo_small.gif" alt="embedded IPsec"> source
code documentation </h2>
<hr>
<!-- Generated by Doxygen 1.3.4 -->
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<h1>esp_test.c</h1><a href="esp__test_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>
00002 <span class="comment"> * embedded IPsec</span>
00003 <span class="comment"> * Copyright (c) 2003 Niklaus Schild and Christian Scheurer, HTI Biel/Bienne</span>
00004 <span class="comment"> * All rights reserved.</span>
00005 <span class="comment"> *</span>
00006 <span class="comment"> * Redistribution and use in source and binary forms, with or without modification,</span>
00007 <span class="comment"> * are permitted provided that the following conditions are met:</span>
00008 <span class="comment"> *</span>
00009 <span class="comment"> * 1. Redistributions of source code must retain the above copyright notice,</span>
00010 <span class="comment"> * this list of conditions and the following disclaimer.</span>
00011 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright notice,</span>
00012 <span class="comment"> * this list of conditions and the following disclaimer in the documentation</span>
00013 <span class="comment"> * and/or other materials provided with the distribution.</span>
00014 <span class="comment"> * 3. The name of the author may not be used to endorse or promote products</span>
00015 <span class="comment"> * derived from this software without specific prior written permission.</span>
00016 <span class="comment"> *</span>
00017 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED</span>
00018 <span class="comment"> * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF</span>
00019 <span class="comment"> * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT</span>
00020 <span class="comment"> * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,</span>
00021 <span class="comment"> * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT</span>
00022 <span class="comment"> * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</span>
00023 <span class="comment"> * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN</span>
00024 <span class="comment"> * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING</span>
00025 <span class="comment"> * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY</span>
00026 <span class="comment"> * OF SUCH DAMAGE.</span>
00027 <span class="comment"> *</span>
00028 <span class="comment"> */</span>
00029
00048 <span class="preprocessor">#include <string.h></span>
00049
00050 <span class="preprocessor">#include "<a class="code" href="util_8h.html">ipsec/util.h</a>"</span>
00051 <span class="preprocessor">#include "<a class="code" href="debug_8h.html">ipsec/debug.h</a>"</span>
00052 <span class="preprocessor">#include "<a class="code" href="structural__test_8h.html">testing/structural/structural_test.h</a>"</span>
00053
00054 <span class="preprocessor">#include "<a class="code" href="sa_8h.html">ipsec/sa.h</a>"</span>
00055 <span class="preprocessor">#include "<a class="code" href="esp_8h.html">ipsec/esp.h</a>"</span>
00056
00057
<a name="l00058"></a><a class="code" href="esp__test_8c.html#a0">00058</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="esp__test_8c.html#a0">enc_esp_packet1</a>[484] =
00059 {
00060 <span class="comment">/* IP header */</span>
00061 0x45, 0x00, 0x01, 0xE4,
00062 0x56, 0xDC, 0x00, 0x00,
00063 0x40, 0x32, 0x9E, 0x90,
00064 0xC0, 0xA8, 0x01, 0x03,
00065 0xC0, 0xA8, 0x01, 0x28,
00066 <span class="comment">/* ESP header */</span>
00067 0x00, 0x00, 0x10, 0x06,
00068 0x00, 0x00, 0x00, 0x02,
00069 <span class="comment">/* IV */</span>
00070 0xD4, 0xDB, 0xAB, 0x9A,
00071 0x9A, 0xDB, 0xD1, 0x94,
00072 <span class="comment">/* encrypted payload */</span>
00073 0x53, 0x83, 0xFB, 0x32, 0x7F, 0x7E, 0x9A, 0xE9, 0x01, 0xB3, 0x7F, 0x80,
00074 0x06, 0xCF, 0x39, 0x26, 0x6F, 0x5D, 0x25, 0x5B, 0x1E, 0x26, 0x28, 0xC4, 0xB3, 0x78, 0x04, 0xAC,
00075 0x9F, 0x0B, 0xAE, 0x9D, 0x57, 0xAC, 0x4E, 0x82, 0x0E, 0xB4, 0xBA, 0x6C, 0x27, 0x38, 0x0A, 0x71,
00076 0x9B, 0xE1, 0xF7, 0xFD, 0x14, 0xCC, 0x14, 0x0D, 0x71, 0xE5, 0xB8, 0xF7, 0x7C, 0xCB, 0xE0, 0x0B,
00077 0x04, 0x78, 0xB1, 0x7F, 0x2B, 0xEA, 0x85, 0x41, 0x95, 0x22, 0x18, 0xEE, 0x06, 0xFF, 0x79, 0x13,
00078 0x26, 0xD3, 0x08, 0x10, 0x75, 0x04, 0x53, 0x6C, 0x04, 0xFD, 0x91, 0xF3, 0x31, 0x93, 0xB6, 0x14,
00079 0xE3, 0x53, 0xF6, 0xCE, 0x6E, 0xC3, 0x74, 0xFE, 0xCE, 0x62, 0x01, 0xBD, 0x8D, 0x11, 0x26, 0x39,
00080 0x0A, 0x74, 0x51, 0xCA, 0x56, 0x42, 0x51, 0xD5, 0x7B, 0x8E, 0xA6, 0x47, 0xDC, 0x7F, 0x74, 0x09,
00081 0x90, 0x8F, 0x9A, 0xF2, 0x0C, 0x74, 0x81, 0x64, 0x10, 0x0D, 0x64, 0xCE, 0x54, 0xB5, 0x78, 0x81,
00082 0xA5, 0x90, 0x36, 0xEB, 0x82, 0xC9, 0xE7, 0x5C, 0xBD, 0x3F, 0x3B, 0x29, 0xD3, 0x2F, 0x22, 0x6E,
00083 0x6F, 0x24, 0xDD, 0xFB, 0xDD, 0x98, 0x00, 0x1D, 0x4B, 0x82, 0xCE, 0x12, 0xD1, 0x33, 0x29, 0x22,
00084 0x4F, 0x92, 0xF9, 0x94, 0xEB, 0x12, 0x57, 0x2F, 0xFA, 0x30, 0xC7, 0xF1, 0x9D, 0x72, 0xCA, 0x8D,
00085 0x25, 0xEB, 0x2C, 0x3D, 0xE3, 0xFB, 0xCC, 0xBC, 0x54, 0x11, 0x53, 0x25, 0xE2, 0xCE, 0x78, 0xF9,
00086 0xDC, 0x6F, 0xE8, 0xE2, 0xFB, 0x41, 0x3C, 0xED, 0x6F, 0x9A, 0xB1, 0xF3, 0x72, 0x78, 0x02, 0xCC,
00087 0x91, 0x3D, 0x20, 0x7F, 0xBE, 0xE9, 0x53, 0xD4, 0xFB, 0xFF, 0x6E, 0x42, 0xB1, 0xF6, 0x5E, 0x4D,
00088 0x14, 0x03, 0xB4, 0xFB, 0x2F, 0x53, 0x7A, 0xBC, 0x9E, 0xA7, 0xCE, 0x8E, 0xCA, 0x08, 0xC4, 0x7B,
00089 0x19, 0xA1, 0x2B, 0x7F, 0x6A, 0x79, 0x77, 0xCD, 0x77, 0xA4, 0xBA, 0x8C, 0xB8, 0xAC, 0x9C, 0x35,
00090 0x9C, 0x30, 0xB1, 0x29, 0x78, 0xAA, 0x4A, 0xFF, 0xB5, 0xAB, 0x5B, 0x03, 0x09, 0x43, 0xC9, 0x0F,
00091 0xFC, 0x2D, 0x50, 0x65, 0x62, 0xC2, 0xA4, 0xB2, 0xC5, 0x07, 0x4D, 0x41, 0x43, 0xEE, 0x9A, 0x23,
00092 0xA3, 0x02, 0xA5, 0x9A, 0x6E, 0xBD, 0x9E, 0x8C, 0x9F, 0xA2, 0x70, 0x52, 0x61, 0x33, 0x9A, 0x21,
00093 0x26, 0xA6, 0xBE, 0xF6, 0x82, 0x55, 0x0D, 0xB7, 0x03, 0x40, 0x56, 0x18, 0xAA, 0xAB, 0x09, 0xC1,
00094 0x3B, 0x1F, 0xC0, 0x6D, 0x62, 0x0C, 0x7D, 0xA3, 0x59, 0x96, 0x99, 0x94, 0xC3, 0x06, 0x98, 0x6B,
00095 0x64, 0x82, 0xEB, 0xCC, 0x9B, 0x3E, 0x56, 0xC3, 0xA7, 0xEB, 0x9C, 0xF7, 0x07, 0x6C, 0x07, 0x45,
00096 0x8E, 0xBC, 0x85, 0x41, 0x48, 0x69, 0x78, 0x23, 0xAB, 0xBC, 0xE7, 0x1F, 0x7B, 0xD2, 0x07, 0x81,
00097 0xDA, 0x9D, 0x1B, 0x5F, 0x0A, 0x4A, 0x37, 0x88, 0xF8, 0x1C, 0x4F, 0xB4, 0x84, 0xDC, 0x14, 0xD4,
00098 0xD3, 0x3B, 0x29, 0x2B, 0xA9, 0x42, 0x77, 0x2C, 0x91, 0x48, 0x05, 0xF5, 0x21, 0x54, 0xDD, 0xD3,
00099 0xC8, 0xB5, 0xCE, 0xB7, 0x10, 0x7E, 0x63, 0x5A, 0xF3, 0x9E, 0x2C, 0xC7, 0xBC, 0xC8, 0xC9, 0xC2,
00100 0x2D, 0xF0, 0x62, 0x5E, 0xB8, 0xA3, 0x84, 0x8A, 0x3D, 0x5D, 0xB5, 0xF0, 0x14, 0xB4, 0x77, 0xC3,
00101 0x67, 0xD0, 0x5E, 0x77,
00102 } ;
00103
<a name="l00104"></a><a class="code" href="esp__test_8c.html#a1">00104</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="esp__test_8c.html#a1">dec_esp_packet1</a>[448] =
00105 {
00106 <span class="comment">/* inner IP header (20 bytes) */</span>
00107 0x45, 0x00, 0x01, 0xB9,
00108 0x59, 0x53, 0x40, 0x00,
00109 0x40, 0x06, 0x5C, 0x70,
00110 0xC0, 0xA8, 0x01, 0x03,
00111 0xC0, 0xA8, 0x01, 0x28,
00112 <span class="comment">/* TCP header (32 bytes) */</span>
00113 0x00, 0x50, 0x80, 0x0A, 0x0F, 0x25, 0xC3, 0x55,
00114 0x47, 0x67, 0xC8, 0xD2, 0x80, 0x18, 0x7E, 0xA0,
00115 0xC4, 0x5A, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0A,
00116 0x00, 0x69, 0x9A, 0x06, 0x00, 0x07, 0x90, 0x0F,
00117 <span class="comment">/* HTTP (389 bytes) */</span>
00118 0x48, 0x54, 0x54, 0x50, 0x2F, 0x31, 0x2E, 0x30,
00119 0x20, 0x32, 0x30, 0x30, 0x20, 0x4F, 0x4B, 0x0D, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74,
00120 0x2D, 0x54, 0x79, 0x70, 0x65, 0x3A, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2F, 0x68, 0x74, 0x6D, 0x6C,
00121 0x0D, 0x0A, 0x0D, 0x0A, 0x3C, 0x68, 0x74, 0x6D, 0x6C, 0x3E, 0x0D, 0x0A, 0x3C, 0x68, 0x65, 0x61,
00122 0x64, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x68, 0x65, 0x61, 0x64, 0x3E, 0x0D, 0x0A, 0x3C, 0x62, 0x6F,
00123 0x64, 0x79, 0x20, 0x74, 0x65, 0x78, 0x74, 0x3D, 0x22, 0x23, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
00124 0x22, 0x20, 0x62, 0x67, 0x63, 0x6F, 0x6C, 0x6F, 0x72, 0x3D, 0x22, 0x23, 0x46, 0x46, 0x46, 0x46,
00125 0x39, 0x39, 0x22, 0x20, 0x6C, 0x69, 0x6E, 0x6B, 0x3D, 0x22, 0x23, 0x30, 0x30, 0x30, 0x30, 0x45,
00126 0x45, 0x22, 0x20, 0x76, 0x6C, 0x69, 0x6E, 0x6B, 0x3D, 0x22, 0x23, 0x35, 0x35, 0x31, 0x41, 0x38,
00127 0x42, 0x22, 0x20, 0x61, 0x6C, 0x69, 0x6E, 0x6B, 0x3D, 0x22, 0x23, 0x46, 0x46, 0x30, 0x30, 0x30,
00128 0x30, 0x22, 0x3E, 0x0D, 0x0A, 0x26, 0x6E, 0x62, 0x73, 0x70, 0x3B, 0x0D, 0x0A, 0x3C, 0x63, 0x65,
00129 0x6E, 0x74, 0x65, 0x72, 0x3E, 0x3C, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x20, 0x42, 0x4F, 0x52, 0x44,
00130 0x45, 0x52, 0x3D, 0x30, 0x20, 0x43, 0x4F, 0x4C, 0x53, 0x3D, 0x31, 0x20, 0x57, 0x49, 0x44, 0x54,
00131 0x48, 0x3D, 0x22, 0x39, 0x30, 0x25, 0x22, 0x20, 0x48, 0x45, 0x49, 0x47, 0x48, 0x54, 0x3D, 0x22,
00132 0x38, 0x35, 0x25, 0x22, 0x20, 0x3E, 0x0D, 0x0A, 0x3C, 0x74, 0x72, 0x20, 0x41, 0x4C, 0x49, 0x47,
00133 0x4E, 0x3D, 0x4C, 0x45, 0x46, 0x54, 0x20, 0x56, 0x41, 0x4C, 0x49, 0x47, 0x4E, 0x3D, 0x54, 0x4F,
00134 0x50, 0x3E, 0x0D, 0x0A, 0x3C, 0x74, 0x64, 0x3E, 0x3C, 0x62, 0x3E, 0x3C, 0x66, 0x6F, 0x6E, 0x74,
00135 0x20, 0x66, 0x61, 0x63, 0x65, 0x3D, 0x22, 0x56, 0x65, 0x72, 0x64, 0x61, 0x6E, 0x61, 0x22, 0x3E,
00136 0x3C, 0x66, 0x6F, 0x6E, 0x74, 0x20, 0x73, 0x69, 0x7A, 0x65, 0x3D, 0x2B, 0x32, 0x3E, 0x45, 0x6D,
00137 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x57, 0x65, 0x62, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65,
00138 0x72, 0x20, 0x54, 0x65, 0x73, 0x74, 0x3C, 0x2F, 0x66, 0x6F, 0x6E, 0x74, 0x3E, 0x3C, 0x2F, 0x66,
00139 0x6F, 0x6E, 0x74, 0x3E, 0x3C, 0x2F, 0x62, 0x3E, 0x3C, 0x2F, 0x74, 0x64, 0x3E, 0x0D, 0x0A, 0x3C,
00140 0x2F, 0x74, 0x72, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x3E, 0x0D, 0x0A,
00141 0x3C, 0x2F, 0x63, 0x65, 0x6E, 0x74, 0x65, 0x72, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x62, 0x6F, 0x64,
00142 0x79, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x68, 0x74, 0x6D, 0x6C, 0x3E, 0x0D, 0x0A,
00143 <span class="comment">/* padding (5 bytes) */</span>
00144 0x01, 0x02, 0x03, 0x04, 0x05,
00145 <span class="comment">/* padding length (1 byte) */</span>
00146 0x05,
00147 <span class="comment">/* next protocol (1 byte) */</span>
00148 0x04
00149 } ;
00150
<a name="l00151"></a><a class="code" href="esp__test_8c.html#a2">00151</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="esp__test_8c.html#a2">enc_esp_packet2</a>[100] =
00152 {
00153 <span class="comment">/* IP header */</span>
00154 0x45, 0x00, 0x00, 0x64,
00155 0x79, 0x30, 0x00, 0x00,
00156 0x40, 0x32, 0x7D, 0xBC,
00157 0xC0, 0xA8, 0x01, 0x28,
00158 0xC0, 0xA8, 0x01, 0x03,
00159 <span class="comment">/* ESP header */</span>
00160 0x00, 0x00, 0x10, 0x06,
00161 0x00, 0x00, 0x00, 0x01,
00162 <span class="comment">/* IV */</span>
00163 0x87, 0xC5, 0xBA, 0x8C,
00164 0x6F, 0x31, 0xEE, 0x1E,
00165 <span class="comment">/* encrypted payload */</span>
00166 0xFB, 0xCE, 0x75, 0xD2, 0xD4, 0x16, 0x25, 0x8A, 0x92, 0xB8, 0x63, 0x09,
00167 0xBB, 0x88, 0x7E, 0x10, 0x50, 0x2B, 0x23, 0x2F, 0xF6, 0x51, 0xF2, 0x2B, 0x82, 0xAA, 0xE5, 0xD3,
00168 0x5D, 0x4C, 0xFB, 0xCF, 0x87, 0xFB, 0xAD, 0x9F, 0x28, 0x1D, 0xFF, 0x90, 0xDD, 0x43, 0x6B, 0x04,
00169 0xBC, 0xFB, 0xD4, 0x47, 0x36, 0xBC, 0x24, 0x20, 0x71, 0x00, 0x44, 0x07, 0xC2, 0x49, 0xEB, 0x48,
00170 0x26, 0xA4, 0xA7, 0x87,
00171 } ;
00172
<a name="l00173"></a><a class="code" href="esp__test_8c.html#a3">00173</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="esp__test_8c.html#a3">dec_esp_packet2</a>[64] =
00174 {
00175 <span class="comment">/* inner IP header (20 bytes) */</span>
00176 0x45, 0x00, 0x00, 0x3C,
00177 0x58, 0xDF, 0x40, 0x00,
00178 0x40, 0x06, 0x5E, 0x61,
00179 0xC0, 0xA8, 0x01, 0x28,
00180 0xC0, 0xA8, 0x01, 0x03,
00181 <span class="comment">/* TCP header */</span>
00182 0x80, 0x0A, 0x00, 0x50, 0x47, 0x67, 0xC8, 0xD1, 0x00, 0x00, 0x00, 0x00,
00183 0xA0, 0x02, 0x7E, 0xB8, 0xEB, 0x81, 0x00, 0x00, 0x02, 0x04, 0x3F, 0x5C, 0x04, 0x02, 0x08, 0x0A,
00184 0x00, 0x07, 0x90, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x00,
00185 <span class="comment">/* padding */</span>
00186 0x01, 0x02,
00187 <span class="comment">/* padd len */</span>
00188 0x02,
00189 <span class="comment">/* next protocol*/</span>
00190 0x04,
00191 } ;
00192
<a name="l00193"></a><a class="code" href="esp__test_8c.html#a4">00193</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a> [500] ;
00194
<a name="l00195"></a><a class="code" href="esp__test_8c.html#a5">00195</a> <a class="code" href="structsa__entry__struct.html">sad_entry</a> <a class="code" href="esp__test_8c.html#a5">packet1_sa</a> = { <a class="code" href="sa_8h.html#a16">SAD_ENTRY</a>( 192,168,1,40, 255,255,255,255,
00196 0x001006,
00197 <a class="code" href="types_8h.html#a40a36">IPSEC_PROTO_ESP</a>, <a class="code" href="sa_8h.html#a7">IPSEC_TUNNEL</a>,
00198 <a class="code" href="sa_8h.html#a10">IPSEC_3DES</a>,
00199 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67,
00200 0,
00201 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)} ;
00202
<a name="l00203"></a><a class="code" href="esp__test_8c.html#a6">00203</a> <a class="code" href="structsa__entry__struct.html">sad_entry</a> <a class="code" href="esp__test_8c.html#a6">packet2_sa</a> = { <a class="code" href="sa_8h.html#a16">SAD_ENTRY</a>( 192,168,1,3, 255,255,255,255,
00204 0x001006,
00205 <a class="code" href="types_8h.html#a40a36">IPSEC_PROTO_ESP</a>, <a class="code" href="sa_8h.html#a7">IPSEC_TUNNEL</a>,
00206 <a class="code" href="sa_8h.html#a10">IPSEC_3DES</a>,
00207 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67,
00208 0,
00209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)} ;
00210
<a name="l00215"></a><a class="code" href="esp__test_8c.html#a7">00215</a> <span class="keywordtype">int</span> <a class="code" href="esp__test_8c.html#a7">test_esp_decapsulate</a>(<span class="keywordtype">void</span>)
00216 {
00217 <span class="keywordtype">int</span> local_error_count = 0 ;
00218 <span class="keywordtype">int</span> offset, len ;
00219 <a class="code" href="structsa__entry__struct.html">sad_entry</a> *sa ;
00220
00221 <span class="comment">/* test decryption of packet 1 */</span>
00222 memcpy(<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>, <a class="code" href="esp__test_8c.html#a0">enc_esp_packet1</a>, 484) ;
00223 sa = &<a class="code" href="esp__test_8c.html#a5">packet1_sa</a> ;
00224
00225 <a class="code" href="esp_8c.html#a3">ipsec_esp_decapsulate</a>((<a class="code" href="structipsec__ip__hdr__struct.html">ipsec_ip_header</a>*)<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>, &offset, &len, sa) ;
00226
00227 <span class="keywordflow">if</span>(offset != 36)
00228 {
00229 local_error_count++ ;
00230 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_decapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"offset was not calculated properly"</span>)) ;
00231 }
00232
00233 <span class="keywordflow">if</span>(len != 441)
00234 {
00235 local_error_count++ ;
00236 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_decapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"length was not calculated properly"</span>)) ;
00237 }
00238
00239 <span class="keywordflow">if</span>(memcmp(((<span class="keywordtype">char</span>*)<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>)+offset, <a class="code" href="esp__test_8c.html#a1">dec_esp_packet1</a>, len) != 0)
00240 {
00241 local_error_count++ ;
00242 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_decapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"packet was not decrypted properly"</span>)) ;
00243 }
00244
00245 <span class="comment">/* test decryption of packet2 */</span>
00246
00247 memset(<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>, 0, 500) ;
00248 memcpy(<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>, <a class="code" href="esp__test_8c.html#a2">enc_esp_packet2</a>, 100) ;
00249 sa = &<a class="code" href="esp__test_8c.html#a6">packet2_sa</a> ;
00250
00251 <a class="code" href="esp_8c.html#a3">ipsec_esp_decapsulate</a>((<a class="code" href="structipsec__ip__hdr__struct.html">ipsec_ip_header</a>*)<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>, &offset, &len, sa) ;
00252
00253 <span class="keywordflow">if</span>(offset != 36)
00254 {
00255 local_error_count++ ;
00256 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_decapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"offset was not calculated properly"</span>)) ;
00257 }
00258
00259 <span class="keywordflow">if</span>(len != 60)
00260 {
00261 local_error_count++ ;
00262 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_decapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"length was not calculated properly"</span>)) ;
00263 }
00264
00265 <span class="keywordflow">if</span>(memcmp(((<span class="keywordtype">char</span>*)<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>)+offset, <a class="code" href="esp__test_8c.html#a3">dec_esp_packet2</a>, len) != 0)
00266 {
00267 local_error_count++ ;
00268 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_decapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"packet was not decrypted properly"</span>)) ;
00269 }
00270
00271 <span class="keywordflow">return</span> local_error_count ;
00272 }
00273
<a name="l00278"></a><a class="code" href="esp__test_8c.html#a8">00278</a> <span class="keywordtype">int</span> <a class="code" href="esp__test_8c.html#a8">test_esp_encapsulate</a>(<span class="keywordtype">void</span>)
00279 {
00280 <span class="keywordtype">int</span> local_error_count = 0 ;
00281 <span class="keywordtype">int</span> offset, len ;
00282 <span class="keywordtype">int</span> cmp_len ;
00283 <span class="keywordtype">char</span> *cmp_buffer_result ;
00284 <span class="keywordtype">char</span> *cmp_buffer_expected ;
00285 <a class="code" href="structsa__entry__struct.html">sad_entry</a> *sa ;
00286
00287 memset(<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>, 0, 500) ;
00288 memcpy(&<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>[40], <a class="code" href="esp__test_8c.html#a1">dec_esp_packet1</a>, 441) ;
00289 sa = &<a class="code" href="esp__test_8c.html#a5">packet1_sa</a> ;
00290
00291 <a class="code" href="esp_8c.html#a4">ipsec_esp_encapsulate</a>((<a class="code" href="structipsec__ip__hdr__struct.html">ipsec_ip_header</a>*)&<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>[40], &offset, &len, sa, <a class="code" href="util_8c.html#a1">ipsec_inet_addr</a>(<span class="stringliteral">"192.168.1.3"</span>), <a class="code" href="util_8c.html#a1">ipsec_inet_addr</a>(<span class="stringliteral">"192.168.1.40"</span>)) ;
00292
00293 <span class="keywordflow">if</span>(offset != -36)
00294 {
00295 local_error_count++ ;
00296 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_encapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"offset was not calculated properly"</span>)) ;
00297 }
00298
00299 <span class="keywordflow">if</span>(len != 484)
00300 {
00301 local_error_count++ ;
00302 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_encapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"length was not calculated properly"</span>)) ;
00303 }
00304
00305 cmp_len = len - 20 ;
00306 cmp_buffer_result = &<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>[40+offset+20] ;
00307 cmp_buffer_expected = &<a class="code" href="esp__test_8c.html#a0">enc_esp_packet1</a>[20] ;
00308
00309 <span class="keywordflow">if</span>(memcmp(cmp_buffer_result, cmp_buffer_expected , cmp_len) != 0)
00310 {
00311 local_error_count++ ;
00312 <a class="code" href="debug_8h.html#a13">IPSEC_DUMP_BUFFER</a>(<span class="stringliteral">"RESULT"</span>, cmp_buffer_result, 0, cmp_len) ;
00313 <a class="code" href="debug_8h.html#a13">IPSEC_DUMP_BUFFER</a>(<span class="stringliteral">"EXP "</span>, cmp_buffer_expected, 0, cmp_len) ;
00314 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_encapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"packet was not encrypted properly"</span>)) ;
00315 }
00316
00317 memset(<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>, 0, 500) ;
00318 memcpy(<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>, <a class="code" href="esp__test_8c.html#a3">dec_esp_packet2</a>, 60) ;
00319 sa = &<a class="code" href="esp__test_8c.html#a5">packet1_sa</a> ;
00320
00321 <a class="code" href="esp_8c.html#a4">ipsec_esp_encapsulate</a>((<a class="code" href="structipsec__ip__hdr__struct.html">ipsec_ip_header</a>*)<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>, &offset, &len, sa, <a class="code" href="util_8c.html#a1">ipsec_inet_addr</a>(<span class="stringliteral">"192.168.1.40"</span>), <a class="code" href="util_8c.html#a1">ipsec_inet_addr</a>(<span class="stringliteral">"102.168.1.3"</span>)) ;
00322
00323 <span class="keywordflow">if</span>(offset != -36)
00324 {
00325 local_error_count++ ;
00326 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_encapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"offset was not calculated properly"</span>)) ;
00327 }
00328
00329 <span class="keywordflow">if</span>(len != 100)
00330 {
00331 local_error_count++ ;
00332 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_encapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"length was not calculated properly"</span>)) ;
00333 }
00334
00335 cmp_len = len - 20 ;
00336 cmp_buffer_result = &<a class="code" href="esp__test_8c.html#a4">esp_packet_tmp</a>[40+offset+20] ;
00337 cmp_buffer_expected = &<a class="code" href="esp__test_8c.html#a0">enc_esp_packet1</a>[20] ;
00338
00339 <span class="keywordflow">if</span>(memcmp(cmp_buffer_result, cmp_buffer_result, cmp_len) != 0)
00340 {
00341 local_error_count++ ;
00342 <a class="code" href="debug_8h.html#a13">IPSEC_DUMP_BUFFER</a>(<span class="stringliteral">"RESULT"</span>, cmp_buffer_result, 0, cmp_len) ;
00343 <a class="code" href="debug_8h.html#a13">IPSEC_DUMP_BUFFER</a>(<span class="stringliteral">"EXP "</span>, cmp_buffer_expected, 0, cmp_len) ;
00344 <a class="code" href="debug_8h.html#a10">IPSEC_LOG_TST</a>(<span class="stringliteral">"test_esp_encapsulate"</span>, <span class="stringliteral">"FAILURE"</span>, (<span class="stringliteral">"packet was not encrypted properly"</span>)) ;
00345 }
00346
00347 <span class="keywordflow">return</span> local_error_count ;
00348 }
00349
00350
<a name="l00355"></a><a class="code" href="esp__test_8c.html#a9">00355</a> <span class="keywordtype">void</span> <a class="code" href="esp__test_8c.html#a9">esp_test</a>(<a class="code" href="structtest__result__struct.html">test_result</a> *global_results)
00356 {
00357 <a class="code" href="structtest__result__struct.html">test_result</a> sub_results = {
00358 12,
00359 2,
00360 0,
00361 0,
00362 };
00363
00364 <span class="keywordtype">int</span> retcode;
00365
00366 retcode = <a class="code" href="esp__test_8c.html#a7">test_esp_decapsulate</a>() ;
00367 <a class="code" href="structural__test_8h.html#a0">IPSEC_TESTING_EVALUATE</a>(retcode, sub_results, <span class="stringliteral">"test_esp_decapsulate"</span>, (<span class="stringliteral">" "</span>));
00368
00369 retcode = <a class="code" href="esp__test_8c.html#a8">test_esp_encapsulate</a>() ;
00370 <a class="code" href="structural__test_8h.html#a0">IPSEC_TESTING_EVALUATE</a>(retcode, sub_results, <span class="stringliteral">"test_esp_encapsulate"</span>, (<span class="stringliteral">" "</span>));
00371
00372 global_results-><a class="code" href="structtest__result__struct.html#o0">tests</a> += sub_results.<a class="code" href="structtest__result__struct.html#o0">tests</a>;
00373 global_results-><a class="code" href="structtest__result__struct.html#o1">functions</a> += sub_results.<a class="code" href="structtest__result__struct.html#o1">functions</a>;
00374 global_results-><a class="code" href="structtest__result__struct.html#o2">errors</a> += sub_results.<a class="code" href="structtest__result__struct.html#o2">errors</a>;
00375 global_results-><a class="code" href="structtest__result__struct.html#o3">notimplemented</a> += sub_results.<a class="code" href="structtest__result__struct.html#o3">notimplemented</a>;
00376 }
00377
00378
</pre></div> </td>
</tr>
</table>
<hr>
<div align="center">Copyright 2003 by Christian Scheurer and Niklaus Schild</div>
</html>