Changeset 2528cda for protocols/msn/msn_util.c
- Timestamp:
- 2010-08-08T15:34:49Z (14 years ago)
- Branches:
- master
- Children:
- 5fecede
- Parents:
- b890626 (diff), ee6cc94 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/msn_util.c
rb890626 r2528cda 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 04Wilmer van der Gaast and others *4 * Copyright 2002-2010 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 26 26 #include "nogaim.h" 27 27 #include "msn.h" 28 #include "md5.h" 28 29 #include <ctype.h> 29 30 … … 444 445 return msn_write( ic, buf, strlen( buf ) ) != 0; 445 446 } 447 448 unsigned int little_endian( unsigned int dw ) 449 { 450 #if defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN 451 return dw; 452 #else 453 /* We're still not sure if this machine is big endian since the 454 constants above are not that portable. Don't swap bytes, just 455 force-compose a 32-bit little endian integer. */ 456 unsigned int ret = 0, i; 457 char *dst = (char*) (&ret + 1); 458 459 for (i = 0; i < 4; i ++) 460 { 461 *(--dst) = dw >> 24; 462 dw <<= 8; 463 } 464 465 return ret; 466 #endif 467 } 468 469 /* Copied and heavily modified from http://tmsnc.sourceforge.net/chl.c */ 470 char *msn_p11_challenge( char *challenge ) 471 { 472 char *output, buf[256]; 473 md5_state_t md5c; 474 unsigned char md5Hash[16], *newHash; 475 unsigned int *md5Parts, *chlStringParts, newHashParts[5]; 476 long long nHigh = 0, nLow = 0; 477 int i, n; 478 479 /* Create the MD5 hash */ 480 md5_init(&md5c); 481 md5_append(&md5c, (unsigned char*) challenge, strlen(challenge)); 482 md5_append(&md5c, (unsigned char*) MSNP11_PROD_KEY, strlen(MSNP11_PROD_KEY)); 483 md5_finish(&md5c, md5Hash); 484 485 /* Split it into four integers */ 486 md5Parts = (unsigned int *)md5Hash; 487 for (i = 0; i < 4; i ++) 488 { 489 md5Parts[i] = little_endian(md5Parts[i]); 490 491 /* & each integer with 0x7FFFFFFF */ 492 /* and save one unmodified array for later */ 493 newHashParts[i] = md5Parts[i]; 494 md5Parts[i] &= 0x7FFFFFFF; 495 } 496 497 /* make a new string and pad with '0' */ 498 n = g_snprintf(buf, sizeof(buf)-5, "%s%s00000000", challenge, MSNP11_PROD_ID); 499 /* truncate at an 8-byte boundary */ 500 buf[n&=~7] = '\0'; 501 502 /* split into integers */ 503 chlStringParts = (unsigned int *)buf; 504 505 /* this is magic */ 506 for (i = 0; i < (n / 4) - 1; i += 2) 507 { 508 long long temp; 509 510 chlStringParts[i] = little_endian(chlStringParts[i]); 511 chlStringParts[i+1] = little_endian(chlStringParts[i+1]); 512 513 temp = (md5Parts[0] * (((0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF)+nHigh) + md5Parts[1])%0x7FFFFFFF; 514 nHigh = (md5Parts[2] * (((long long)chlStringParts[i+1]+temp) % 0x7FFFFFFF) + md5Parts[3]) % 0x7FFFFFFF; 515 nLow = nLow + nHigh + temp; 516 } 517 nHigh = (nHigh+md5Parts[1]) % 0x7FFFFFFF; 518 nLow = (nLow+md5Parts[3]) % 0x7FFFFFFF; 519 520 newHashParts[0] ^= nHigh; 521 newHashParts[1] ^= nLow; 522 newHashParts[2] ^= nHigh; 523 newHashParts[3] ^= nLow; 524 525 /* swap more bytes if big endian */ 526 for (i = 0; i < 4; i ++) 527 newHashParts[i] = little_endian(newHashParts[i]); 528 529 /* make a string of the parts */ 530 newHash = (unsigned char *)newHashParts; 531 532 /* convert to hexadecimal */ 533 output = g_new(char, 33); 534 for (i = 0; i < 16; i ++) 535 sprintf(output + i * 2, "%02x", newHash[i]); 536 537 return output; 538 }
Note: See TracChangeset
for help on using the changeset viewer.