comparison libmpdemux/realrtsp/real.c @ 19256:ed6ca050bba5

The real hash function is just a md5, replace with lavu code
author rtogni
date Sun, 30 Jul 2006 14:45:27 +0000
parents d385666efa27
children 4679f22bbdae
comparison
equal deleted inserted replaced
19255:e9437f0553d1 19256:ed6ca050bba5
34 #include "../bswap.h" 34 #include "../bswap.h"
35 #include "real.h" 35 #include "real.h"
36 #include "asmrp.h" 36 #include "asmrp.h"
37 #include "sdpplin.h" 37 #include "sdpplin.h"
38 #include "xbuffer.h" 38 #include "xbuffer.h"
39 #if USE_LIBAVUTIL_SO
40 #include "ffmpeg/md5.h"
41 #else
42 #include "libavutil/md5.h"
43 #endif
39 44
40 /* 45 /*
41 #define LOG 46 #define LOG
42 */ 47 */
43 48
82 printf ("\n"); 87 printf ("\n");
83 } 88 }
84 #endif 89 #endif
85 90
86 91
87 static void hash(char *field, char *param) {
88
89 uint32_t a, b, c, d;
90
91
92 /* fill variables */
93 a= le2me_32(*(uint32_t*)(field));
94 b= le2me_32(*(uint32_t*)(field+4));
95 c= le2me_32(*(uint32_t*)(field+8));
96 d= le2me_32(*(uint32_t*)(field+12));
97
98 #ifdef LOG
99 printf("real: hash input: %x %x %x %x\n", a, b, c, d);
100 printf("real: hash parameter:\n");
101 hexdump(param, 64);
102 printf("real: hash field:\n");
103 hexdump(field, 64+24);
104 #endif
105
106 a = ((b & c) | (~b & d)) + le2me_32(*((uint32_t*)(param+0x00))) + a - 0x28955B88;
107 a = ((a << 0x07) | (a >> 0x19)) + b;
108 d = ((a & b) | (~a & c)) + le2me_32(*((uint32_t*)(param+0x04))) + d - 0x173848AA;
109 d = ((d << 0x0c) | (d >> 0x14)) + a;
110 c = ((d & a) | (~d & b)) + le2me_32(*((uint32_t*)(param+0x08))) + c + 0x242070DB;
111 c = ((c << 0x11) | (c >> 0x0f)) + d;
112 b = ((c & d) | (~c & a)) + le2me_32(*((uint32_t*)(param+0x0c))) + b - 0x3E423112;
113 b = ((b << 0x16) | (b >> 0x0a)) + c;
114 a = ((b & c) | (~b & d)) + le2me_32(*((uint32_t*)(param+0x10))) + a - 0x0A83F051;
115 a = ((a << 0x07) | (a >> 0x19)) + b;
116 d = ((a & b) | (~a & c)) + le2me_32(*((uint32_t*)(param+0x14))) + d + 0x4787C62A;
117 d = ((d << 0x0c) | (d >> 0x14)) + a;
118 c = ((d & a) | (~d & b)) + le2me_32(*((uint32_t*)(param+0x18))) + c - 0x57CFB9ED;
119 c = ((c << 0x11) | (c >> 0x0f)) + d;
120 b = ((c & d) | (~c & a)) + le2me_32(*((uint32_t*)(param+0x1c))) + b - 0x02B96AFF;
121 b = ((b << 0x16) | (b >> 0x0a)) + c;
122 a = ((b & c) | (~b & d)) + le2me_32(*((uint32_t*)(param+0x20))) + a + 0x698098D8;
123 a = ((a << 0x07) | (a >> 0x19)) + b;
124 d = ((a & b) | (~a & c)) + le2me_32(*((uint32_t*)(param+0x24))) + d - 0x74BB0851;
125 d = ((d << 0x0c) | (d >> 0x14)) + a;
126 c = ((d & a) | (~d & b)) + le2me_32(*((uint32_t*)(param+0x28))) + c - 0x0000A44F;
127 c = ((c << 0x11) | (c >> 0x0f)) + d;
128 b = ((c & d) | (~c & a)) + le2me_32(*((uint32_t*)(param+0x2C))) + b - 0x76A32842;
129 b = ((b << 0x16) | (b >> 0x0a)) + c;
130 a = ((b & c) | (~b & d)) + le2me_32(*((uint32_t*)(param+0x30))) + a + 0x6B901122;
131 a = ((a << 0x07) | (a >> 0x19)) + b;
132 d = ((a & b) | (~a & c)) + le2me_32(*((uint32_t*)(param+0x34))) + d - 0x02678E6D;
133 d = ((d << 0x0c) | (d >> 0x14)) + a;
134 c = ((d & a) | (~d & b)) + le2me_32(*((uint32_t*)(param+0x38))) + c - 0x5986BC72;
135 c = ((c << 0x11) | (c >> 0x0f)) + d;
136 b = ((c & d) | (~c & a)) + le2me_32(*((uint32_t*)(param+0x3c))) + b + 0x49B40821;
137 b = ((b << 0x16) | (b >> 0x0a)) + c;
138
139 a = ((b & d) | (~d & c)) + le2me_32(*((uint32_t*)(param+0x04))) + a - 0x09E1DA9E;
140 a = ((a << 0x05) | (a >> 0x1b)) + b;
141 d = ((a & c) | (~c & b)) + le2me_32(*((uint32_t*)(param+0x18))) + d - 0x3FBF4CC0;
142 d = ((d << 0x09) | (d >> 0x17)) + a;
143 c = ((d & b) | (~b & a)) + le2me_32(*((uint32_t*)(param+0x2c))) + c + 0x265E5A51;
144 c = ((c << 0x0e) | (c >> 0x12)) + d;
145 b = ((c & a) | (~a & d)) + le2me_32(*((uint32_t*)(param+0x00))) + b - 0x16493856;
146 b = ((b << 0x14) | (b >> 0x0c)) + c;
147 a = ((b & d) | (~d & c)) + le2me_32(*((uint32_t*)(param+0x14))) + a - 0x29D0EFA3;
148 a = ((a << 0x05) | (a >> 0x1b)) + b;
149 d = ((a & c) | (~c & b)) + le2me_32(*((uint32_t*)(param+0x28))) + d + 0x02441453;
150 d = ((d << 0x09) | (d >> 0x17)) + a;
151 c = ((d & b) | (~b & a)) + le2me_32(*((uint32_t*)(param+0x3c))) + c - 0x275E197F;
152 c = ((c << 0x0e) | (c >> 0x12)) + d;
153 b = ((c & a) | (~a & d)) + le2me_32(*((uint32_t*)(param+0x10))) + b - 0x182C0438;
154 b = ((b << 0x14) | (b >> 0x0c)) + c;
155 a = ((b & d) | (~d & c)) + le2me_32(*((uint32_t*)(param+0x24))) + a + 0x21E1CDE6;
156 a = ((a << 0x05) | (a >> 0x1b)) + b;
157 d = ((a & c) | (~c & b)) + le2me_32(*((uint32_t*)(param+0x38))) + d - 0x3CC8F82A;
158 d = ((d << 0x09) | (d >> 0x17)) + a;
159 c = ((d & b) | (~b & a)) + le2me_32(*((uint32_t*)(param+0x0c))) + c - 0x0B2AF279;
160 c = ((c << 0x0e) | (c >> 0x12)) + d;
161 b = ((c & a) | (~a & d)) + le2me_32(*((uint32_t*)(param+0x20))) + b + 0x455A14ED;
162 b = ((b << 0x14) | (b >> 0x0c)) + c;
163 a = ((b & d) | (~d & c)) + le2me_32(*((uint32_t*)(param+0x34))) + a - 0x561C16FB;
164 a = ((a << 0x05) | (a >> 0x1b)) + b;
165 d = ((a & c) | (~c & b)) + le2me_32(*((uint32_t*)(param+0x08))) + d - 0x03105C08;
166 d = ((d << 0x09) | (d >> 0x17)) + a;
167 c = ((d & b) | (~b & a)) + le2me_32(*((uint32_t*)(param+0x1c))) + c + 0x676F02D9;
168 c = ((c << 0x0e) | (c >> 0x12)) + d;
169 b = ((c & a) | (~a & d)) + le2me_32(*((uint32_t*)(param+0x30))) + b - 0x72D5B376;
170 b = ((b << 0x14) | (b >> 0x0c)) + c;
171
172 a = (b ^ c ^ d) + le2me_32(*((uint32_t*)(param+0x14))) + a - 0x0005C6BE;
173 a = ((a << 0x04) | (a >> 0x1c)) + b;
174 d = (a ^ b ^ c) + le2me_32(*((uint32_t*)(param+0x20))) + d - 0x788E097F;
175 d = ((d << 0x0b) | (d >> 0x15)) + a;
176 c = (d ^ a ^ b) + le2me_32(*((uint32_t*)(param+0x2c))) + c + 0x6D9D6122;
177 c = ((c << 0x10) | (c >> 0x10)) + d;
178 b = (c ^ d ^ a) + le2me_32(*((uint32_t*)(param+0x38))) + b - 0x021AC7F4;
179 b = ((b << 0x17) | (b >> 0x09)) + c;
180 a = (b ^ c ^ d) + le2me_32(*((uint32_t*)(param+0x04))) + a - 0x5B4115BC;
181 a = ((a << 0x04) | (a >> 0x1c)) + b;
182 d = (a ^ b ^ c) + le2me_32(*((uint32_t*)(param+0x10))) + d + 0x4BDECFA9;
183 d = ((d << 0x0b) | (d >> 0x15)) + a;
184 c = (d ^ a ^ b) + le2me_32(*((uint32_t*)(param+0x1c))) + c - 0x0944B4A0;
185 c = ((c << 0x10) | (c >> 0x10)) + d;
186 b = (c ^ d ^ a) + le2me_32(*((uint32_t*)(param+0x28))) + b - 0x41404390;
187 b = ((b << 0x17) | (b >> 0x09)) + c;
188 a = (b ^ c ^ d) + le2me_32(*((uint32_t*)(param+0x34))) + a + 0x289B7EC6;
189 a = ((a << 0x04) | (a >> 0x1c)) + b;
190 d = (a ^ b ^ c) + le2me_32(*((uint32_t*)(param+0x00))) + d - 0x155ED806;
191 d = ((d << 0x0b) | (d >> 0x15)) + a;
192 c = (d ^ a ^ b) + le2me_32(*((uint32_t*)(param+0x0c))) + c - 0x2B10CF7B;
193 c = ((c << 0x10) | (c >> 0x10)) + d;
194 b = (c ^ d ^ a) + le2me_32(*((uint32_t*)(param+0x18))) + b + 0x04881D05;
195 b = ((b << 0x17) | (b >> 0x09)) + c;
196 a = (b ^ c ^ d) + le2me_32(*((uint32_t*)(param+0x24))) + a - 0x262B2FC7;
197 a = ((a << 0x04) | (a >> 0x1c)) + b;
198 d = (a ^ b ^ c) + le2me_32(*((uint32_t*)(param+0x30))) + d - 0x1924661B;
199 d = ((d << 0x0b) | (d >> 0x15)) + a;
200 c = (d ^ a ^ b) + le2me_32(*((uint32_t*)(param+0x3c))) + c + 0x1fa27cf8;
201 c = ((c << 0x10) | (c >> 0x10)) + d;
202 b = (c ^ d ^ a) + le2me_32(*((uint32_t*)(param+0x08))) + b - 0x3B53A99B;
203 b = ((b << 0x17) | (b >> 0x09)) + c;
204
205 a = ((~d | b) ^ c) + le2me_32(*((uint32_t*)(param+0x00))) + a - 0x0BD6DDBC;
206 a = ((a << 0x06) | (a >> 0x1a)) + b;
207 d = ((~c | a) ^ b) + le2me_32(*((uint32_t*)(param+0x1c))) + d + 0x432AFF97;
208 d = ((d << 0x0a) | (d >> 0x16)) + a;
209 c = ((~b | d) ^ a) + le2me_32(*((uint32_t*)(param+0x38))) + c - 0x546BDC59;
210 c = ((c << 0x0f) | (c >> 0x11)) + d;
211 b = ((~a | c) ^ d) + le2me_32(*((uint32_t*)(param+0x14))) + b - 0x036C5FC7;
212 b = ((b << 0x15) | (b >> 0x0b)) + c;
213 a = ((~d | b) ^ c) + le2me_32(*((uint32_t*)(param+0x30))) + a + 0x655B59C3;
214 a = ((a << 0x06) | (a >> 0x1a)) + b;
215 d = ((~c | a) ^ b) + le2me_32(*((uint32_t*)(param+0x0C))) + d - 0x70F3336E;
216 d = ((d << 0x0a) | (d >> 0x16)) + a;
217 c = ((~b | d) ^ a) + le2me_32(*((uint32_t*)(param+0x28))) + c - 0x00100B83;
218 c = ((c << 0x0f) | (c >> 0x11)) + d;
219 b = ((~a | c) ^ d) + le2me_32(*((uint32_t*)(param+0x04))) + b - 0x7A7BA22F;
220 b = ((b << 0x15) | (b >> 0x0b)) + c;
221 a = ((~d | b) ^ c) + le2me_32(*((uint32_t*)(param+0x20))) + a + 0x6FA87E4F;
222 a = ((a << 0x06) | (a >> 0x1a)) + b;
223 d = ((~c | a) ^ b) + le2me_32(*((uint32_t*)(param+0x3c))) + d - 0x01D31920;
224 d = ((d << 0x0a) | (d >> 0x16)) + a;
225 c = ((~b | d) ^ a) + le2me_32(*((uint32_t*)(param+0x18))) + c - 0x5CFEBCEC;
226 c = ((c << 0x0f) | (c >> 0x11)) + d;
227 b = ((~a | c) ^ d) + le2me_32(*((uint32_t*)(param+0x34))) + b + 0x4E0811A1;
228 b = ((b << 0x15) | (b >> 0x0b)) + c;
229 a = ((~d | b) ^ c) + le2me_32(*((uint32_t*)(param+0x10))) + a - 0x08AC817E;
230 a = ((a << 0x06) | (a >> 0x1a)) + b;
231 d = ((~c | a) ^ b) + le2me_32(*((uint32_t*)(param+0x2c))) + d - 0x42C50DCB;
232 d = ((d << 0x0a) | (d >> 0x16)) + a;
233 c = ((~b | d) ^ a) + le2me_32(*((uint32_t*)(param+0x08))) + c + 0x2AD7D2BB;
234 c = ((c << 0x0f) | (c >> 0x11)) + d;
235 b = ((~a | c) ^ d) + le2me_32(*((uint32_t*)(param+0x24))) + b - 0x14792C6F;
236 b = ((b << 0x15) | (b >> 0x0b)) + c;
237
238 #ifdef LOG
239 printf("real: hash output: %x %x %x %x\n", a, b, c, d);
240 #endif
241
242 a += le2me_32(*((uint32_t *)(field+0)));
243 *((uint32_t *)(field+0)) = le2me_32(a);
244 b += le2me_32(*((uint32_t *)(field+4)));
245 *((uint32_t *)(field+4)) = le2me_32(b);
246 c += le2me_32(*((uint32_t *)(field+8)));
247 *((uint32_t *)(field+8)) = le2me_32(c);
248 d += le2me_32(*((uint32_t *)(field+12)));
249 *((uint32_t *)(field+12)) = le2me_32(d);
250
251 #ifdef LOG
252 printf("real: hash field:\n");
253 hexdump(field, 64+24);
254 #endif
255 }
256
257 static void call_hash (char *key, char *challenge, int len) {
258
259 uint32_t *ptr1, *ptr2;
260 uint32_t a, b, c, d;
261 uint32_t tmp;
262
263 ptr1=(uint32_t*)(key+16);
264 ptr2=(uint32_t*)(key+20);
265
266 a = le2me_32(*ptr1);
267 b = (a >> 3) & 0x3f;
268 a += len * 8;
269 *ptr1 = le2me_32(a);
270
271 if (a < (len << 3))
272 {
273 #ifdef LOG
274 printf("not verified: (len << 3) > a true\n");
275 #endif
276 ptr2 += 4;
277 }
278
279 tmp = le2me_32(*ptr2);
280 tmp += (len >> 0x1d);
281 *ptr2 = le2me_32(tmp);
282 a = 64 - b;
283 c = 0;
284 if (a <= len)
285 {
286
287 memcpy(key+b+24, challenge, a);
288 hash(key, key+24);
289 c = a;
290 d = c + 0x3f;
291
292 while ( d < len ) {
293
294 #ifdef LOG
295 printf("not verified: while ( d < len )\n");
296 #endif
297 hash(key, challenge+d-0x3f);
298 d += 64;
299 c += 64;
300 }
301 b = 0;
302 }
303
304 memcpy(key+b+24, challenge+c, len-c);
305 }
306
307 static void calc_response (char *result, char *field) {
308
309 char buf1[128];
310 char buf2[128];
311 int i;
312
313 memset (buf1, 0, 64);
314 *buf1 = 128;
315
316 memcpy (buf2, field+16, 8);
317
318 i = ( le2me_32(*((uint32_t*)(buf2))) >> 3 ) & 0x3f;
319
320 if (i < 56) {
321 i = 56 - i;
322 } else {
323 #ifdef LOG
324 printf("not verified: ! (i < 56)\n");
325 #endif
326 i = 120 - i;
327 }
328
329 call_hash (field, buf1, i);
330 call_hash (field, buf2, 8);
331
332 memcpy (result, field, 16);
333
334 }
335
336
337 static void calc_response_string (char *result, char *challenge) { 92 static void calc_response_string (char *result, char *challenge) {
338 93
339 char field[128];
340 char zres[20]; 94 char zres[20];
341 int i; 95 int i;
342 96
343 /* initialize our field */ 97 av_md5_sum(zres, challenge, 64);
344 BE_32C (field, 0x01234567);
345 BE_32C ((field+4), 0x89ABCDEF);
346 BE_32C ((field+8), 0xFEDCBA98);
347 BE_32C ((field+12), 0x76543210);
348 BE_32C ((field+16), 0x00000000);
349 BE_32C ((field+20), 0x00000000);
350
351 /* calculate response */
352 call_hash(field, challenge, 64);
353 calc_response(zres,field);
354 98
355 /* convert zres to ascii string */ 99 /* convert zres to ascii string */
356 for (i=0; i<16; i++ ) { 100 for (i=0; i<16; i++ ) {
357 char a, b; 101 char a, b;
358 102