1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,351 @@ |
1 |
+/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm |
|
2 |
+ */ |
|
3 |
+ |
|
4 |
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All |
|
5 |
+rights reserved. |
|
6 |
+ |
|
7 |
+License to copy and use this software is granted provided that it |
|
8 |
+is identified as the "RSA Data Security, Inc. MD5 Message-Digest |
|
9 |
+Algorithm" in all material mentioning or referencing this software |
|
10 |
+or this function. |
|
11 |
+ |
|
12 |
+License is also granted to make and use derivative works provided |
|
13 |
+that such works are identified as "derived from the RSA Data |
|
14 |
+Security, Inc. MD5 Message-Digest Algorithm" in all material |
|
15 |
+mentioning or referencing the derived work. |
|
16 |
+ |
|
17 |
+RSA Data Security, Inc. makes no representations concerning either |
|
18 |
+the merchantability of this software or the suitability of this |
|
19 |
+software for any particular purpose. It is provided "as is" |
|
20 |
+without express or implied warranty of any kind. |
|
21 |
+ |
|
22 |
+These notices must be retained in any copies of any part of this |
|
23 |
+documentation and/or software. |
|
24 |
+ */ |
|
25 |
+ |
|
26 |
+#include "md5global.h" |
|
27 |
+#include "md5.h" |
|
28 |
+ |
|
29 |
+#define USE_MEM |
|
30 |
+ |
|
31 |
+/* Constants for MD5Transform routine. |
|
32 |
+ */ |
|
33 |
+ |
|
34 |
+ |
|
35 |
+ |
|
36 |
+ |
|
37 |
+#define S11 7 |
|
38 |
+#define S12 12 |
|
39 |
+#define S13 17 |
|
40 |
+#define S14 22 |
|
41 |
+#define S21 5 |
|
42 |
+#define S22 9 |
|
43 |
+#define S23 14 |
|
44 |
+#define S24 20 |
|
45 |
+#define S31 4 |
|
46 |
+#define S32 11 |
|
47 |
+#define S33 16 |
|
48 |
+#define S34 23 |
|
49 |
+#define S41 6 |
|
50 |
+#define S42 10 |
|
51 |
+#define S43 15 |
|
52 |
+#define S44 21 |
|
53 |
+ |
|
54 |
+static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64])); |
|
55 |
+static void Encode PROTO_LIST |
|
56 |
+ ((unsigned char *, UINT4 *, unsigned int)); |
|
57 |
+static void Decode PROTO_LIST |
|
58 |
+ ((UINT4 *, unsigned char *, unsigned int)); |
|
59 |
+static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int)); |
|
60 |
+static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int)); |
|
61 |
+ |
|
62 |
+static unsigned char PADDING[64] = { |
|
63 |
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
64 |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
65 |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
|
66 |
+}; |
|
67 |
+ |
|
68 |
+/* F, G, H and I are basic MD5 functions. |
|
69 |
+ */ |
|
70 |
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) |
|
71 |
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) |
|
72 |
+#define H(x, y, z) ((x) ^ (y) ^ (z)) |
|
73 |
+#define I(x, y, z) ((y) ^ ((x) | (~z))) |
|
74 |
+ |
|
75 |
+/* ROTATE_LEFT rotates x left n bits. |
|
76 |
+ */ |
|
77 |
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) |
|
78 |
+ |
|
79 |
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. |
|
80 |
+Rotation is separate from addition to prevent recomputation. |
|
81 |
+ */ |
|
82 |
+#define FF(a, b, c, d, x, s, ac) { \ |
|
83 |
+ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ |
|
84 |
+ (a) = ROTATE_LEFT ((a), (s)); \ |
|
85 |
+ (a) += (b); \ |
|
86 |
+ } |
|
87 |
+#define GG(a, b, c, d, x, s, ac) { \ |
|
88 |
+ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ |
|
89 |
+ (a) = ROTATE_LEFT ((a), (s)); \ |
|
90 |
+ (a) += (b); \ |
|
91 |
+ } |
|
92 |
+#define HH(a, b, c, d, x, s, ac) { \ |
|
93 |
+ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ |
|
94 |
+ (a) = ROTATE_LEFT ((a), (s)); \ |
|
95 |
+ (a) += (b); \ |
|
96 |
+ } |
|
97 |
+#define II(a, b, c, d, x, s, ac) { \ |
|
98 |
+ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ |
|
99 |
+ (a) = ROTATE_LEFT ((a), (s)); \ |
|
100 |
+ (a) += (b); \ |
|
101 |
+ } |
|
102 |
+ |
|
103 |
+/* MD5 initialization. Begins an MD5 operation, writing a new context. |
|
104 |
+ */ |
|
105 |
+void MD5Init (context) |
|
106 |
+MD5_CTX *context; /* context */ |
|
107 |
+{ |
|
108 |
+ context->count[0] = context->count[1] = 0; |
|
109 |
+ /* Load magic initialization constants. |
|
110 |
+*/ |
|
111 |
+ context->state[0] = 0x67452301; |
|
112 |
+ context->state[1] = 0xefcdab89; |
|
113 |
+ context->state[2] = 0x98badcfe; |
|
114 |
+ context->state[3] = 0x10325476; |
|
115 |
+} |
|
116 |
+ |
|
117 |
+/* MD5 block update operation. Continues an MD5 message-digest |
|
118 |
+ operation, processing another message block, and updating the |
|
119 |
+ context. |
|
120 |
+ */ |
|
121 |
+void MD5Update (context, input, inputLen) |
|
122 |
+MD5_CTX *context; /* context */ |
|
123 |
+unsigned char *input; /* input block */ |
|
124 |
+unsigned int inputLen; /* length of input block */ |
|
125 |
+{ |
|
126 |
+ unsigned int i, index, partLen; |
|
127 |
+ |
|
128 |
+ /* Compute number of bytes mod 64 */ |
|
129 |
+ index = (unsigned int)((context->count[0] >> 3) & 0x3F); |
|
130 |
+ |
|
131 |
+ /* Update number of bits */ |
|
132 |
+ if ((context->count[0] += ((UINT4)inputLen << 3)) |
|
133 |
+ |
|
134 |
+ < ((UINT4)inputLen << 3)) |
|
135 |
+ context->count[1]++; |
|
136 |
+ context->count[1] += ((UINT4)inputLen >> 29); |
|
137 |
+ |
|
138 |
+ partLen = 64 - index; |
|
139 |
+ |
|
140 |
+ /* Transform as many times as possible. |
|
141 |
+*/ |
|
142 |
+ if (inputLen >= partLen) { |
|
143 |
+ MD5_memcpy |
|
144 |
+ ((POINTER)&context->buffer[index], (POINTER)input, partLen); |
|
145 |
+ MD5Transform (context->state, context->buffer); |
|
146 |
+ |
|
147 |
+ for (i = partLen; i + 63 < inputLen; i += 64) |
|
148 |
+ MD5Transform (context->state, &input[i]); |
|
149 |
+ |
|
150 |
+ index = 0; |
|
151 |
+ } |
|
152 |
+ else |
|
153 |
+ i = 0; |
|
154 |
+ |
|
155 |
+ /* Buffer remaining input */ |
|
156 |
+ MD5_memcpy |
|
157 |
+ ((POINTER)&context->buffer[index], (POINTER)&input[i], |
|
158 |
+ inputLen-i); |
|
159 |
+} |
|
160 |
+ |
|
161 |
+/* MD5 finalization. Ends an MD5 message-digest operation, writing the |
|
162 |
+ the message digest and zeroizing the context. |
|
163 |
+ */ |
|
164 |
+void MD5Final (digest, context) |
|
165 |
+unsigned char digest[16]; /* message digest */ |
|
166 |
+MD5_CTX *context; /* context */ |
|
167 |
+{ |
|
168 |
+ unsigned char bits[8]; |
|
169 |
+ unsigned int index, padLen; |
|
170 |
+ |
|
171 |
+ /* Save number of bits */ |
|
172 |
+ Encode (bits, context->count, 8); |
|
173 |
+ |
|
174 |
+ /* Pad out to 56 mod 64. |
|
175 |
+*/ |
|
176 |
+ index = (unsigned int)((context->count[0] >> 3) & 0x3f); |
|
177 |
+ padLen = (index < 56) ? (56 - index) : (120 - index); |
|
178 |
+ MD5Update (context, PADDING, padLen); |
|
179 |
+ |
|
180 |
+ /* Append length (before padding) */ |
|
181 |
+ MD5Update (context, bits, 8); |
|
182 |
+ |
|
183 |
+ /* Store state in digest */ |
|
184 |
+ Encode (digest, context->state, 16); |
|
185 |
+ |
|
186 |
+ /* Zeroize sensitive information. |
|
187 |
+*/ |
|
188 |
+ MD5_memset ((POINTER)context, 0, sizeof (*context)); |
|
189 |
+} |
|
190 |
+ |
|
191 |
+/* MD5 basic transformation. Transforms state based on block. |
|
192 |
+ */ |
|
193 |
+static void MD5Transform (state, block) |
|
194 |
+UINT4 state[4]; |
|
195 |
+unsigned char block[64]; |
|
196 |
+{ |
|
197 |
+ UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; |
|
198 |
+ |
|
199 |
+ Decode (x, block, 64); |
|
200 |
+ |
|
201 |
+ /* Round 1 */ |
|
202 |
+ FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ |
|
203 |
+ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ |
|
204 |
+ FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ |
|
205 |
+ FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ |
|
206 |
+ FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ |
|
207 |
+ FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ |
|
208 |
+ FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ |
|
209 |
+ FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ |
|
210 |
+ FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ |
|
211 |
+ FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ |
|
212 |
+ FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ |
|
213 |
+ FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ |
|
214 |
+ FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ |
|
215 |
+ FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ |
|
216 |
+ FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ |
|
217 |
+ FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ |
|
218 |
+ |
|
219 |
+ /* Round 2 */ |
|
220 |
+ GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ |
|
221 |
+ GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ |
|
222 |
+ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ |
|
223 |
+ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ |
|
224 |
+ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ |
|
225 |
+ GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ |
|
226 |
+ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ |
|
227 |
+ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ |
|
228 |
+ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ |
|
229 |
+ GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ |
|
230 |
+ GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ |
|
231 |
+ GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ |
|
232 |
+ GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ |
|
233 |
+ GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ |
|
234 |
+ GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ |
|
235 |
+ GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ |
|
236 |
+ |
|
237 |
+ /* Round 3 */ |
|
238 |
+ HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ |
|
239 |
+ HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ |
|
240 |
+ HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ |
|
241 |
+ HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ |
|
242 |
+ HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ |
|
243 |
+ HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ |
|
244 |
+ HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ |
|
245 |
+ HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ |
|
246 |
+ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ |
|
247 |
+ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ |
|
248 |
+ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ |
|
249 |
+ HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ |
|
250 |
+ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ |
|
251 |
+ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ |
|
252 |
+ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ |
|
253 |
+ HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ |
|
254 |
+ |
|
255 |
+ /* Round 4 */ |
|
256 |
+ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ |
|
257 |
+ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ |
|
258 |
+ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ |
|
259 |
+ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ |
|
260 |
+ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ |
|
261 |
+ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ |
|
262 |
+ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ |
|
263 |
+ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ |
|
264 |
+ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ |
|
265 |
+ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ |
|
266 |
+ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ |
|
267 |
+ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ |
|
268 |
+ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ |
|
269 |
+ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ |
|
270 |
+ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ |
|
271 |
+ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ |
|
272 |
+ |
|
273 |
+ state[0] += a; |
|
274 |
+ state[1] += b; |
|
275 |
+ state[2] += c; |
|
276 |
+ state[3] += d; |
|
277 |
+ |
|
278 |
+ /* Zeroize sensitive information. |
|
279 |
+*/ |
|
280 |
+ MD5_memset ((POINTER)x, 0, sizeof (x)); |
|
281 |
+} |
|
282 |
+ |
|
283 |
+/* Encodes input (UINT4) into output (unsigned char). Assumes len is |
|
284 |
+ a multiple of 4. |
|
285 |
+ */ |
|
286 |
+static void Encode (output, input, len) |
|
287 |
+unsigned char *output; |
|
288 |
+UINT4 *input; |
|
289 |
+unsigned int len; |
|
290 |
+{ |
|
291 |
+ unsigned int i, j; |
|
292 |
+ |
|
293 |
+ for (i = 0, j = 0; j < len; i++, j += 4) { |
|
294 |
+ output[j] = (unsigned char)(input[i] & 0xff); |
|
295 |
+ output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); |
|
296 |
+ output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); |
|
297 |
+ output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); |
|
298 |
+ } |
|
299 |
+} |
|
300 |
+ |
|
301 |
+/* Decodes input (unsigned char) into output (UINT4). Assumes len is |
|
302 |
+ a multiple of 4. |
|
303 |
+ */ |
|
304 |
+static void Decode (output, input, len) |
|
305 |
+UINT4 *output; |
|
306 |
+unsigned char *input; |
|
307 |
+unsigned int len; |
|
308 |
+{ |
|
309 |
+ unsigned int i, j; |
|
310 |
+ |
|
311 |
+ for (i = 0, j = 0; j < len; i++, j += 4) |
|
312 |
+ output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | |
|
313 |
+ (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); |
|
314 |
+} |
|
315 |
+ |
|
316 |
+/* Note: Replace "for loop" with standard memcpy if possible. |
|
317 |
+ */ |
|
318 |
+ |
|
319 |
+static void MD5_memcpy (output, input, len) |
|
320 |
+POINTER output; |
|
321 |
+POINTER input; |
|
322 |
+unsigned int len; |
|
323 |
+{ |
|
324 |
+ |
|
325 |
+#ifndef USE_MEM |
|
326 |
+ unsigned int i; |
|
327 |
+ |
|
328 |
+ for (i = 0; i < len; i++) |
|
329 |
+ output[i] = input[i]; |
|
330 |
+#else |
|
331 |
+ memcpy( output, input, len ); |
|
332 |
+#endif |
|
333 |
+} |
|
334 |
+ |
|
335 |
+/* Note: Replace "for loop" with standard memset if possible. |
|
336 |
+ */ |
|
337 |
+static void MD5_memset (output, value, len) |
|
338 |
+POINTER output; |
|
339 |
+int value; |
|
340 |
+unsigned int len; |
|
341 |
+{ |
|
342 |
+ |
|
343 |
+#ifndef USE_MEM |
|
344 |
+ unsigned int i; |
|
345 |
+ for (i = 0; i < len; i++) |
|
346 |
+ ((char *)output)[i] = (char)value; |
|
347 |
+#else |
|
348 |
+ memset( output, value, len ); |
|
349 |
+#endif |
|
350 |
+} |
|
351 |
+ |
0 | 352 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,37 @@ |
1 |
+/* MD5.H - header file for MD5C.C |
|
2 |
+ */ |
|
3 |
+ |
|
4 |
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All |
|
5 |
+rights reserved. |
|
6 |
+ |
|
7 |
+License to copy and use this software is granted provided that it |
|
8 |
+is identified as the "RSA Data Security, Inc. MD5 Message-Digest |
|
9 |
+Algorithm" in all material mentioning or referencing this software |
|
10 |
+or this function. |
|
11 |
+ |
|
12 |
+License is also granted to make and use derivative works provided |
|
13 |
+that such works are identified as "derived from the RSA Data |
|
14 |
+Security, Inc. MD5 Message-Digest Algorithm" in all material |
|
15 |
+mentioning or referencing the derived work. |
|
16 |
+ |
|
17 |
+RSA Data Security, Inc. makes no representations concerning either |
|
18 |
+the merchantability of this software or the suitability of this |
|
19 |
+software for any particular purpose. It is provided "as is" |
|
20 |
+without express or implied warranty of any kind. |
|
21 |
+ |
|
22 |
+These notices must be retained in any copies of any part of this |
|
23 |
+documentation and/or software. |
|
24 |
+ */ |
|
25 |
+ |
|
26 |
+/* MD5 context. */ |
|
27 |
+typedef struct { |
|
28 |
+ UINT4 state[4]; /* state (ABCD) */ |
|
29 |
+ UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ |
|
30 |
+ unsigned char buffer[64]; /* input buffer */ |
|
31 |
+} MD5_CTX; |
|
32 |
+ |
|
33 |
+void MD5Init PROTO_LIST ((MD5_CTX *)); |
|
34 |
+void MD5Update PROTO_LIST |
|
35 |
+ ((MD5_CTX *, unsigned char *, unsigned int)); |
|
36 |
+void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *)); |
|
37 |
+ |
0 | 38 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,31 @@ |
1 |
+/* GLOBAL.H - RSAREF types and constants |
|
2 |
+ */ |
|
3 |
+ |
|
4 |
+/* PROTOTYPES should be set to one if and only if the compiler supports |
|
5 |
+ function argument prototyping. |
|
6 |
+The following makes PROTOTYPES default to 0 if it has not already |
|
7 |
+ been defined with C compiler flags. |
|
8 |
+ */ |
|
9 |
+#ifndef PROTOTYPES |
|
10 |
+#define PROTOTYPES 0 |
|
11 |
+#endif |
|
12 |
+ |
|
13 |
+/* POINTER defines a generic pointer type */ |
|
14 |
+typedef unsigned char *POINTER; |
|
15 |
+ |
|
16 |
+/* UINT2 defines a two byte word */ |
|
17 |
+typedef unsigned short int UINT2; |
|
18 |
+ |
|
19 |
+/* UINT4 defines a four byte word */ |
|
20 |
+typedef unsigned long int UINT4; |
|
21 |
+ |
|
22 |
+/* PROTO_LIST is defined depending on how PROTOTYPES is defined above. |
|
23 |
+If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it |
|
24 |
+ returns an empty list. |
|
25 |
+ */ |
|
26 |
+#if PROTOTYPES |
|
27 |
+#define PROTO_LIST(list) list |
|
28 |
+#else |
|
29 |
+#define PROTO_LIST(list) () |
|
30 |
+#endif |
|
31 |
+ |
0 | 32 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,62 @@ |
1 |
+/* MDDRIVER.C - test driver for MD2, MD4 and MD5 |
|
2 |
+ */ |
|
3 |
+ |
|
4 |
+ |
|
5 |
+/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All |
|
6 |
+rights reserved. |
|
7 |
+ |
|
8 |
+RSA Data Security, Inc. makes no representations concerning either |
|
9 |
+the merchantability of this software or the suitability of this |
|
10 |
+software for any particular purpose. It is provided "as is" |
|
11 |
+without express or implied warranty of any kind. |
|
12 |
+ |
|
13 |
+These notices must be retained in any copies of any part of this |
|
14 |
+documentation and/or software. |
|
15 |
+ */ |
|
16 |
+ |
|
17 |
+/* |
|
18 |
+ |
|
19 |
+jku: added support to deal with vectors |
|
20 |
+ |
|
21 |
+*/ |
|
22 |
+ |
|
23 |
+#define MD 5 |
|
24 |
+ |
|
25 |
+#include <stdio.h> |
|
26 |
+#include <time.h> |
|
27 |
+#include <string.h> |
|
28 |
+#include "md5global.h" |
|
29 |
+#include "md5.h" |
|
30 |
+#include "md5utils.h" |
|
31 |
+ |
|
32 |
+#include "dprint.h" |
|
33 |
+ |
|
34 |
+ |
|
35 |
+static void MDString PROTO_LIST ((char *)); |
|
36 |
+ |
|
37 |
+#define MD_CTX MD5_CTX |
|
38 |
+#define MDInit MD5Init |
|
39 |
+#define MDUpdate MD5Update |
|
40 |
+#define MDFinal MD5Final |
|
41 |
+ |
|
42 |
+ |
|
43 |
+/* Digests a string array and store the result in dst; assumes |
|
44 |
+ 32 bytes in dst |
|
45 |
+ */ |
|
46 |
+void MDStringArray (char *dst, str src[], int size) |
|
47 |
+{ |
|
48 |
+ MD_CTX context; |
|
49 |
+ unsigned char digest[16]; |
|
50 |
+ int i; |
|
51 |
+ |
|
52 |
+ MDInit (&context); |
|
53 |
+ for (i=0; i<size; i++) { |
|
54 |
+ MDUpdate (&context, src[i].s, src[i].len); |
|
55 |
+ } |
|
56 |
+ MDFinal (digest, &context); |
|
57 |
+ |
|
58 |
+ for (i=0; i<16; i++) |
|
59 |
+ sprintf(dst+i*2, "%02x", digest[i] ); |
|
60 |
+ |
|
61 |
+ DBG("DEBUG: MD5 calculated: %32s\n", dst ); |
|
62 |
+} |
... | ... |
@@ -4,30 +4,7 @@ |
4 | 4 |
struct cell *T; |
5 | 5 |
unsigned int global_msg_id; |
6 | 6 |
struct s_table* hash_table; |
7 |
- |
|
8 |
- |
|
9 |
-struct cell* t_lookupOriginalT( struct s_table* hash_table , struct sip_msg* p_msg ); |
|
10 |
-int t_reply_matching( struct s_table* , struct sip_msg* , struct cell** , unsigned int* ); |
|
11 |
-int t_store_incoming_reply( struct cell* , unsigned int , struct sip_msg* ); |
|
12 |
-int t_relay_reply( struct cell* , unsigned int , struct sip_msg* ); |
|
13 |
-int t_check( struct s_table* , struct sip_msg* ); |
|
14 |
-int t_all_final( struct cell * ); |
|
15 |
-int t_build_and_send_ACK( struct cell *Trans , unsigned int brach ); |
|
16 |
-int relay_lowest_reply_upstream( struct cell *Trans , struct sip_msg *p_msg ); |
|
17 |
-int push_reply_from_uac_to_uas( struct sip_msg * , unsigned int ); |
|
18 |
-int t_cancel_branch(unsigned int branch); //TO DO |
|
19 |
- |
|
20 |
-int send_udp_to( char *buf, unsigned buflen, struct sockaddr_in* to, unsigned tolen ); |
|
21 |
- |
|
22 |
-void retransmission_handler( void *); |
|
23 |
-void final_response_handler( void *); |
|
24 |
-void wait_handler( void *); |
|
25 |
-void delete_handler( void *); |
|
26 |
- |
|
27 |
-int add_branch_label( struct cell *Trans, struct sip_msg *p_msg , int branch ); |
|
28 |
- |
|
29 |
- |
|
30 |
- |
|
7 |
+int sock_fd; |
|
31 | 8 |
|
32 | 9 |
|
33 | 10 |
|
... | ... |
@@ -278,7 +255,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int |
278 | 255 |
T->outbound_request[branch]->to.sin_addr.s_addr = ntohl( dest_ip ) ; |
279 | 256 |
|
280 | 257 |
if (add_branch_label( T, p_msg , branch )==-1) return -1; |
281 |
- buf = build_req_buf_from_sip_req( p_msg, &len); |
|
258 |
+ buf = build_buf_from_sip_request ( p_msg, &len); |
|
282 | 259 |
if (!buf) |
283 | 260 |
return -1; |
284 | 261 |
T->outbound_request[branch]->bufflen = len ; |
... | ... |
@@ -287,6 +264,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int |
287 | 264 |
free( buf ) ; |
288 | 265 |
}/* end for the first time */ |
289 | 266 |
|
267 |
+ |
|
290 | 268 |
/* sets and starts the RETRANS timer */ |
291 | 269 |
T->outbound_request[branch]->nr_retrans = 0; |
292 | 270 |
T->outbound_request[branch]->max_retrans = |
... | ... |
@@ -295,7 +273,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int |
295 | 273 |
T->outbound_request[branch]->timeout = RETR_T1; |
296 | 274 |
/* send the request */ |
297 | 275 |
udp_send( T->outbound_request[branch]->buffer , T->outbound_request[branch]->bufflen , |
298 |
- (struct sockaddr*)&(T->outbound_request[branch]->to) , sizeof(struct sockaddr_in) ); |
|
276 |
+ &(T->outbound_request[branch]->to) , sizeof(struct sockaddr_in) ); |
|
299 | 277 |
} |
300 | 278 |
|
301 | 279 |
|
... | ... |
@@ -529,19 +507,19 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc |
529 | 507 |
/* getting the hash_index from the brach param , via header*/ |
530 | 508 |
begin = p_msg->via1->branch->value.s; |
531 | 509 |
for( ; *begin!='.' ; begin++ ); |
532 |
- hash_index = strtol( ++begin , &end , 16 ); |
|
510 |
+ hash_index = strtol( ++begin , &end , 10 ); |
|
533 | 511 |
/*if the hash index is corect */ |
534 | 512 |
if ( *end=='.' && hash_index>=0 && hash_index<TABLE_ENTRIES-1 ) |
535 | 513 |
{ |
536 | 514 |
/* getting the entry label value */ |
537 | 515 |
begin=end++ ; |
538 |
- entry_label = strtol( ++begin , &end , 16 ); |
|
516 |
+ entry_label = strtol( ++begin , &end , 10 ); |
|
539 | 517 |
/* if the entry label also is corect */ |
540 | 518 |
if ( *end=='.' && entry_label>=0 ) |
541 | 519 |
{ |
542 | 520 |
/* getting the branch_id value */ |
543 | 521 |
begin=end++ ; |
544 |
- branch_id = strtol( ++begin , &end , 16 ); |
|
522 |
+ branch_id = strtol( ++begin , &end , 10 ); |
|
545 | 523 |
/* if the entry label also is corect */ |
546 | 524 |
if ( branch_id>=0 ) |
547 | 525 |
{ |
... | ... |
@@ -896,8 +874,28 @@ void delete_handler( void *attr) |
896 | 874 |
to outgoing requests |
897 | 875 |
*/ |
898 | 876 |
int add_branch_label( struct cell *trans, struct sip_msg *p_msg, int branch ) |
899 |
-{ trans->label; |
|
877 |
+{ |
|
878 |
+ char *c; |
|
879 |
+ |
|
880 |
+ |
|
881 |
+ /* check size now */ |
|
882 |
+/* |
|
883 |
+ if (p_msg->add_to_branch.len+ .... > MAX_BRANCH_PARAM_LEN ) { |
|
884 |
+ LOG(L_ERR, "ERROR: add_branch_label: too small branch buffer\n"); |
|
885 |
+ return -1; |
|
886 |
+ } |
|
887 |
+*/ |
|
888 |
+ |
|
889 |
+ /* check if there already was something else -- if not, allocate */ |
|
890 |
+ |
|
891 |
+/* |
|
892 |
+ = (char*)sh_malloc( MAX_BRANCH_PARAM_LEN ); |
|
893 |
+ |
|
894 |
+ |
|
895 |
+ |
|
896 |
+ trans->label; |
|
900 | 897 |
trans->hash_index; |
901 | 898 |
p_msg->add_to_branch; |
902 | 899 |
branch; |
900 |
+*/ |
|
903 | 901 |
} |