# HG changeset patch # User Sean Egan # Date 1065134816 0 # Node ID 4c0b7e7118ee34c39a5deab47a066d6c28cbf18b # Parent eda3de6dacbb69894cbbbad81d638b8d21817795 [gaim-migrate @ 7694] . committer: Tailor Script diff -r eda3de6dacbb -r 4c0b7e7118ee src/protocols/yahoo/yahoo.c --- a/src/protocols/yahoo/yahoo.c Thu Oct 02 13:06:42 2003 +0000 +++ b/src/protocols/yahoo/yahoo.c Thu Oct 02 22:46:56 2003 +0000 @@ -1007,13 +1007,12 @@ unsigned int magic[64]; unsigned int magic_work = 0; - unsigned int value = 0; - + + char comparison_src[20]; int x; int cnt = 0; int magic_cnt = 0; int magic_len; - int times = 0; memset(&pass_hash_xor1, 0, 64); memset(&pass_hash_xor2, 0, 64); @@ -1107,67 +1106,46 @@ magic[magic_cnt+1] = byte1; } - /* Magic: Phase 3. Final phase; this gives us our - * key. */ - - magic_cnt = 1; + /* Magic: Phase 3. This computes 20 bytes. The first 4 bytes are used as our magic + * key (and may be changed later); the next 16 bytes are an MD5 sum of the magic key + * plus 3 bytes. The 3 bytes are found by looping, and they represent the offsets + * into particular functions we'll later call to potentially alter the magic key. + * + * %-) + */ - for (;;) { - unsigned int cl = magic[magic_cnt] & 0xff; - unsigned int bl = magic[magic_cnt+1] & 0xff; - - if (!bl || !cl) - break; - - if (magic_cnt > magic_len) - break; + magic_cnt = 1; + x = 0; + + do { + unsigned int bl = 0; + unsigned int cl = magic[magic_cnt++]; - if (cl <= 0x7f) - bl = cl; - else { - if (cl >= 0x0e0) { - cl = cl & 0x0f; - cl = cl << 6; - bl = bl & 0x3f; - bl = cl + bl; - bl = bl << 6; - } else { - cl = cl & 0x1f; - cl = cl << 6; - bl = cl; - } + if (magic_cnt >= magic_len) + break; + + if (cl > 0x7F) { + if (cl < 0xe0) + bl = cl = (cl & 0x1f) << 6; + else { + bl = magic[magic_cnt++]; + cl = (cl & 0x0f) << 6; + bl = ((bl & 0x3f) + cl) << 6; + } - cl = magic[magic_cnt+2]; - - if (!cl) - break; - - cl = cl & 0x3f; - bl = bl + cl; - } + cl = magic[magic_cnt++]; + bl = (cl & 0x3f) + bl; + } else + bl = cl; - /* Result is bl. - */ - - magic_cnt += 3; + comparison_src[x++] = (bl & 0xff00) >> 8; + comparison_src[x++] = bl & 0xff; + } while (x < 20); + + /* First four bytes are magic key. */ + for (x = 0; x < 4; x++) + magic_key_char[x] = comparison_src[x]; - if (times == 0) { - value |= (bl & 0xff) << 8; - value |= (bl & 0xff00) >> 8; - } else { - value |= (bl & 0xff) << 24; - value |= (bl & 0xff00) << 8; - break; - } - - times++; - } - - /* Dump magic key into a char for SHA1 action. */ - magic_key_char[0] = value & 0xff; - magic_key_char[1] = (value >> 8) & 0xff; - magic_key_char[2] = (value >> 16) & 0xff; - magic_key_char[3] = (value >> 24) & 0xff; /* Get password and crypt hashes as per usual. */ md5_init(&ctx);