void msn_handle_chl(char *input, char *output) { PurpleCipher *cipher; PurpleCipherContext *context; const guchar productKey[] = MSNP15_WLM_PRODUCT_KEY; const guchar productID[] = MSNP15_WLM_PRODUCT_ID; const char hexChars[] = "0123456789abcdef"; char buf[BUFSIZE]; unsigned char md5Hash[16]; unsigned char *newHash; unsigned int *md5Parts; unsigned int *chlStringParts; unsigned int newHashParts[5]; long long nHigh = 0, nLow = 0; int len; int i; /* Create the MD5 hash by using Purple MD5 algorithm */ cipher = purple_ciphers_find_cipher("md5"); context = purple_cipher_context_new(cipher, NULL); purple_cipher_context_append(context, (guchar *)input, strlen(input)); purple_cipher_context_append(context, productKey, sizeof(productKey) - 1); purple_cipher_context_digest(context, sizeof(md5Hash), md5Hash, NULL); purple_cipher_context_destroy(context); /* Split it into four integers */ md5Parts = (unsigned int *)md5Hash; for (i = 0; i < 4; i++) { /* adjust endianess */ md5Parts[i] = GUINT_TO_LE(md5Parts[i]); /* & each integer with 0x7FFFFFFF */ /* and save one unmodified array for later */ newHashParts[i] = md5Parts[i]; md5Parts[i] &= 0x7FFFFFFF; } /* make a new string and pad with '0' to length that's a multiple of 8 */ snprintf(buf, BUFSIZE - 5, "%s%s", input, productID); len = strlen(buf); if ((len % 8) != 0) { int fix = 8 - (len % 8); memset(&buf[len], '0', fix); buf[len + fix] = '\0'; len += fix; } /* split into integers */ chlStringParts = (unsigned int *)buf; /* this is magic */ for (i = 0; i < (len / 4); i += 2) { long long temp; chlStringParts[i] = GUINT_TO_LE(chlStringParts[i]); chlStringParts[i + 1] = GUINT_TO_LE(chlStringParts[i + 1]); temp = (0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF; temp = (md5Parts[0] * (temp + nLow) + md5Parts[1]) % 0x7FFFFFFF; nHigh += temp; temp = ((long long)chlStringParts[i + 1] + temp) % 0x7FFFFFFF; nLow = (md5Parts[2] * temp + md5Parts[3]) % 0x7FFFFFFF; nHigh += nLow; } nLow = (nLow + md5Parts[1]) % 0x7FFFFFFF; nHigh = (nHigh + md5Parts[3]) % 0x7FFFFFFF; newHashParts[0] ^= nLow; newHashParts[1] ^= nHigh; newHashParts[2] ^= nLow; newHashParts[3] ^= nHigh; /* adjust endianness */ for(i = 0; i < 4; i++) newHashParts[i] = GUINT_TO_LE(newHashParts[i]); /* make a string of the parts */ newHash = (unsigned char *)newHashParts; /* convert to hexadecimal */ for (i = 0; i < 16; i++) { output[i * 2] = hexChars[(newHash[i] >> 4) & 0xF]; output[(i * 2) + 1] = hexChars[newHash[i] & 0xF]; } output[32] = '\0'; }
void msn_handle_chl(char *input, char *output) { PurpleHash *hash; const guchar productKey[] = MSNP15_WLM_PRODUCT_KEY; const guchar productID[] = MSNP15_WLM_PRODUCT_ID; const char hexChars[] = "0123456789abcdef"; char buf[BUFSIZE]; guint32 md5Parts[4]; unsigned char *newHash; guint32 chlStringParts[BUFSIZE / sizeof(guint32)]; unsigned int newHashParts[5]; long long nHigh = 0, nLow = 0; int len; int i; /* Create the MD5 hash by using Purple MD5 algorithm */ hash = purple_md5_hash_new(); purple_hash_append(hash, (guchar *)input, strlen(input)); purple_hash_append(hash, productKey, sizeof(productKey) - 1); purple_hash_digest(hash, (guchar *)md5Parts, sizeof(md5Parts)); g_object_unref(hash); /* Split it into four integers */ for (i = 0; i < 4; i++) { /* adjust endianess */ md5Parts[i] = GUINT_TO_LE(md5Parts[i]); /* & each integer with 0x7FFFFFFF */ /* and save one unmodified array for later */ newHashParts[i] = md5Parts[i]; md5Parts[i] &= 0x7FFFFFFF; } /* make a new string and pad with '0' to length that's a multiple of 8 */ snprintf(buf, BUFSIZE - 5, "%s%s", input, productID); len = strlen(buf); if ((len % 8) != 0) { int fix = 8 - (len % 8); strncpy(&buf[len], "00000000", fix); buf[len + fix] = '\0'; len += fix; } /* split into integers */ memcpy(&chlStringParts, &buf, sizeof(chlStringParts)); /* this is magic */ for (i = 0; i < (len / 4); i += 2) { long long temp; chlStringParts[i] = GUINT_TO_LE(chlStringParts[i]); chlStringParts[i + 1] = GUINT_TO_LE(chlStringParts[i + 1]); temp = (0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF; temp = (md5Parts[0] * (temp + nLow) + md5Parts[1]) % 0x7FFFFFFF; nHigh += temp; temp = ((long long)chlStringParts[i + 1] + temp) % 0x7FFFFFFF; nLow = (md5Parts[2] * temp + md5Parts[3]) % 0x7FFFFFFF; nHigh += nLow; } nLow = (nLow + md5Parts[1]) % 0x7FFFFFFF; nHigh = (nHigh + md5Parts[3]) % 0x7FFFFFFF; newHashParts[0] ^= nLow; newHashParts[1] ^= nHigh; newHashParts[2] ^= nLow; newHashParts[3] ^= nHigh; /* adjust endianness */ for(i = 0; i < 4; i++) newHashParts[i] = GUINT_TO_LE(newHashParts[i]); /* make a string of the parts */ newHash = (unsigned char *)newHashParts; /* convert to hexadecimal */ for (i = 0; i < 16; i++) { output[i * 2] = hexChars[(newHash[i] >> 4) & 0xF]; output[(i * 2) + 1] = hexChars[newHash[i] & 0xF]; } output[32] = '\0'; }
char * skypeweb_hmac_sha256(char *input) { PurpleHash *hash; const guchar productKey[] = SKYPEWEB_LOCKANDKEY_SECRET; const guchar productID[] = SKYPEWEB_LOCKANDKEY_APPID; const char hexChars[] = "0123456789abcdef"; char buf[BUFSIZE]; unsigned char sha256Hash[32]; unsigned char *newHash; unsigned int *sha256Parts; unsigned int *chlStringParts; unsigned int newHashParts[5]; gchar *output; long long nHigh = 0, nLow = 0; int len; int i; hash = purple_sha256_hash_new(); purple_hash_append(hash, (guchar *)input, strlen(input)); purple_hash_append(hash, productKey, sizeof(productKey) - 1); purple_hash_digest(hash, (guchar *)sha256Hash, sizeof(sha256Hash)); purple_hash_destroy(hash); /* Split it into four integers */ sha256Parts = (unsigned int *)sha256Hash; for (i = 0; i < 4; i++) { /* adjust endianess */ sha256Parts[i] = GUINT_TO_LE(sha256Parts[i]); /* & each integer with 0x7FFFFFFF */ /* and save one unmodified array for later */ newHashParts[i] = sha256Parts[i]; sha256Parts[i] &= 0x7FFFFFFF; } /* make a new string and pad with '0' to length that's a multiple of 8 */ snprintf(buf, BUFSIZE - 5, "%s%s", input, productID); len = strlen(buf); if ((len % 8) != 0) { int fix = 8 - (len % 8); memset(&buf[len], '0', fix); buf[len + fix] = '\0'; len += fix; } /* split into integers */ chlStringParts = (unsigned int *)buf; /* this is magic */ for (i = 0; i < (len / 4); i += 2) { long long temp; chlStringParts[i] = GUINT_TO_LE(chlStringParts[i]); chlStringParts[i + 1] = GUINT_TO_LE(chlStringParts[i + 1]); temp = (0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF; temp = (sha256Parts[0] * (temp + nLow) + sha256Parts[1]) % 0x7FFFFFFF; nHigh += temp; temp = ((long long)chlStringParts[i + 1] + temp) % 0x7FFFFFFF; nLow = (sha256Parts[2] * temp + sha256Parts[3]) % 0x7FFFFFFF; nHigh += nLow; } nLow = (nLow + sha256Parts[1]) % 0x7FFFFFFF; nHigh = (nHigh + sha256Parts[3]) % 0x7FFFFFFF; newHashParts[0] ^= nLow; newHashParts[1] ^= nHigh; newHashParts[2] ^= nLow; newHashParts[3] ^= nHigh; /* adjust endianness */ for(i = 0; i < 4; i++) newHashParts[i] = GUINT_TO_LE(newHashParts[i]); /* make a string of the parts */ newHash = (unsigned char *)newHashParts; /* convert to hexadecimal */ output = g_new0(gchar, 33); for (i = 0; i < 16; i++) { output[i * 2] = hexChars[(newHash[i] >> 4) & 0xF]; output[(i * 2) + 1] = hexChars[newHash[i] & 0xF]; } output[32] = '\0'; return output; }