Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/msnutils.c @ 20424:b462ef222d28
Use glib functions for endian conversion. If someone has a big endian
system and can test that this works for me, that would be great!
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 26 May 2007 13:11:35 +0000 |
parents | 983cfc2b04fa |
children | 25542d5c94ed |
comparison
equal
deleted
inserted
replaced
20423:85d131a53fa2 | 20424:b462ef222d28 |
---|---|
496 #endif | 496 #endif |
497 | 497 |
498 /*************************************************************************** | 498 /*************************************************************************** |
499 * MSN Challenge Computing Function | 499 * MSN Challenge Computing Function |
500 ***************************************************************************/ | 500 ***************************************************************************/ |
501 /*check the edian of system*/ | |
502 int | |
503 isBigEndian(void) | |
504 { | |
505 short int word = 0x0100; | |
506 char *byte = (char *)&word; | |
507 | |
508 return(byte[0]); | |
509 } | |
510 | |
511 /*swap utility*/ | |
512 unsigned int | |
513 swapInt(unsigned int dw) | |
514 { | |
515 unsigned int tmp; | |
516 tmp = (dw & 0x000000FF); | |
517 tmp = ((dw & 0x0000FF00) >> 0x08) | (tmp << 0x08); | |
518 tmp = ((dw & 0x00FF0000) >> 0x10) | (tmp << 0x08); | |
519 tmp = ((dw & 0xFF000000) >> 0x18) | (tmp << 0x08); | |
520 return(tmp); | |
521 } | |
522 | 501 |
523 /* | 502 /* |
524 * Handle MSN Chanllege computation | 503 * Handle MSN Chanllege computation |
525 *This algorithm reference with http://msnpiki.msnfanatic.com/index.php/MSNP11:Challenges | 504 *This algorithm reference with http://msnpiki.msnfanatic.com/index.php/MSNP11:Challenges |
526 */ | 505 */ |
537 unsigned char md5Hash[16], *newHash; | 516 unsigned char md5Hash[16], *newHash; |
538 unsigned int *md5Parts, *chlStringParts, newHashParts[5]; | 517 unsigned int *md5Parts, *chlStringParts, newHashParts[5]; |
539 | 518 |
540 long long nHigh=0, nLow=0; | 519 long long nHigh=0, nLow=0; |
541 | 520 |
542 int i, bigEndian; | 521 int i; |
543 | |
544 /* Determine our endianess */ | |
545 bigEndian = isBigEndian(); | |
546 | 522 |
547 /* Create the MD5 hash by using Purple MD5 algorithm*/ | 523 /* Create the MD5 hash by using Purple MD5 algorithm*/ |
548 cipher = purple_ciphers_find_cipher("md5"); | 524 cipher = purple_ciphers_find_cipher("md5"); |
549 context = purple_cipher_context_new(cipher, NULL); | 525 context = purple_cipher_context_new(cipher, NULL); |
550 | 526 |
556 purple_cipher_context_destroy(context); | 532 purple_cipher_context_destroy(context); |
557 | 533 |
558 /* Split it into four integers */ | 534 /* Split it into four integers */ |
559 md5Parts = (unsigned int *)md5Hash; | 535 md5Parts = (unsigned int *)md5Hash; |
560 for(i=0; i<4; i++){ | 536 for(i=0; i<4; i++){ |
561 /* check for endianess */ | 537 /* adjust endianess */ |
562 if(bigEndian) | 538 md5Parts[i] = GUINT_TO_LE(md5Parts[i]); |
563 md5Parts[i] = swapInt(md5Parts[i]); | |
564 | 539 |
565 /* & each integer with 0x7FFFFFFF */ | 540 /* & each integer with 0x7FFFFFFF */ |
566 /* and save one unmodified array for later */ | 541 /* and save one unmodified array for later */ |
567 newHashParts[i] = md5Parts[i]; | 542 newHashParts[i] = md5Parts[i]; |
568 md5Parts[i] &= 0x7FFFFFFF; | 543 md5Parts[i] &= 0x7FFFFFFF; |
579 | 554 |
580 /* this is magic */ | 555 /* this is magic */ |
581 for (i=0; i<(strlen(buf)/4)-1; i+=2){ | 556 for (i=0; i<(strlen(buf)/4)-1; i+=2){ |
582 long long temp; | 557 long long temp; |
583 | 558 |
584 if(bigEndian){ | 559 chlStringParts[i] = GUINT_TO_LE(chlStringParts[i]); |
585 chlStringParts[i] = swapInt(chlStringParts[i]); | 560 chlStringParts[i+1] = GUINT_TO_LE(chlStringParts[i+1]); |
586 chlStringParts[i+1] = swapInt(chlStringParts[i+1]); | |
587 } | |
588 | 561 |
589 temp=(md5Parts[0] * (((0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF)+nHigh) + md5Parts[1])%0x7FFFFFFF; | 562 temp=(md5Parts[0] * (((0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF)+nHigh) + md5Parts[1])%0x7FFFFFFF; |
590 nHigh=(md5Parts[2] * (((long long)chlStringParts[i+1]+temp) % 0x7FFFFFFF) + md5Parts[3]) % 0x7FFFFFFF; | 563 nHigh=(md5Parts[2] * (((long long)chlStringParts[i+1]+temp) % 0x7FFFFFFF) + md5Parts[3]) % 0x7FFFFFFF; |
591 nLow=nLow + nHigh + temp; | 564 nLow=nLow + nHigh + temp; |
592 } | 565 } |
596 newHashParts[0]^=nHigh; | 569 newHashParts[0]^=nHigh; |
597 newHashParts[1]^=nLow; | 570 newHashParts[1]^=nLow; |
598 newHashParts[2]^=nHigh; | 571 newHashParts[2]^=nHigh; |
599 newHashParts[3]^=nLow; | 572 newHashParts[3]^=nLow; |
600 | 573 |
601 /* swap more bytes if big endian */ | 574 /* adjust endianness */ |
602 for(i=0; i<4 && bigEndian; i++) | 575 for(i=0; i<4; i++) |
603 newHashParts[i] = swapInt(newHashParts[i]); | 576 newHashParts[i] = GUINT_TO_LE(newHashParts[i]); |
604 | 577 |
605 /* make a string of the parts */ | 578 /* make a string of the parts */ |
606 newHash = (unsigned char *)newHashParts; | 579 newHash = (unsigned char *)newHashParts; |
607 | 580 |
608 /* convert to hexadecimal */ | 581 /* convert to hexadecimal */ |