Exemple #1
0
CID ClientManager::makeCid(const string& aNick, const string& aHubUrl) const throw() {
	string n = Text::toLower(aNick);
	TigerHash th;
	th.update(n.c_str(), n.length());
	th.update(Text::toLower(aHubUrl).c_str(), aHubUrl.length());
	// Construct hybrid CID from the bits of the tiger hash - should be
	// fairly random, and hopefully low-collision
	return CID(th.finalize());
}
void AdcHub::password(const string& pwd) { 
	if(state != STATE_VERIFY)
		return;
	if(!salt.empty()) {
		static const int SALT_SIZE = 192/8;
		u_int8_t buf[SALT_SIZE];
		Encoder::fromBase32(salt.c_str(), buf, SALT_SIZE);
		const string& x = pwd;
		TigerHash th;
		th.update(getMe()->getCID().getData(), CID::SIZE);
		th.update(x.data(), x.length());
		th.update(buf, SALT_SIZE);
		send("HPAS " + getMe()->getCID().toBase32() + " " + Encoder::toBase32(th.finalize(), TigerHash::HASH_SIZE) + "\n");
		salt.clear();
	}
}
Exemple #3
0
static void __cdecl loadFlash_Thread(void *p) {
	debug("Avatar thread executed...\n");
	SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE);

	flash_avatar_item* fai = (flash_avatar_item*)p;
	IShockwaveFlash* flash = fai->pFlash;

	if ( _tcschr(fai->hFA.cUrl, '?') == NULL) {
		// make hash of url
		debug("Making TTH hash from URL...\n");
		TigerHash th;
		th.update(fai->hFA.cUrl, _tcslen(fai->hFA.cUrl));
		th.finalize();

		// create local path name
		TCHAR name[MAX_PATH], path[MAX_PATH];
		TCHAR tth[((TigerHash::HASH_SIZE * 8) / 5) + 2];
		FOLDERSGETDATA fgd = {0};

		fgd.cbSize = sizeof(FOLDERSGETDATA);
		fgd.nMaxPathSize = MAX_PATH;
		fgd.szPathT = path;
		fgd.flags = FF_TCHAR;
		if (!hAvatarsFolder || CallService(MS_FOLDERS_GET_PATH, (WPARAM)hAvatarsFolder, (LPARAM)&fgd)) {
			if(ServiceExists(MS_UTILS_REPLACEVARS))
				mir_sntprintf(path, MAX_PATH, _T("%s\\%s"), VARST(_T("%miranda_avatarcache%")), _T("Flash"));
			else
				PathToAbsoluteT( _T("Flash"), path);
		}
		else {
			if(_tcslen(path) && path[_tcslen(path)-1]=='\\')
				path[_tcslen(path)-1] = 0;
		}

		CreateDirectory(path, NULL); // create directory if it doesn't exist
		mir_sntprintf(name, MAX_PATH, _T("%s\\%s.swf"), path, th.toBase32(tth));

		// download remote file if it doesn't exist
		if (GetFileAttributes(name) == 0xFFFFFFFF) {
			debug("Downloading flash file...\n");
			DownloadFlashFile( _T2A(fai->hFA.cUrl), name, 0);
		}

		// load and play local flash movie
		debug("Loading flash movie...\n");
		flash->LoadMovie(0, _bstr_t(name).copy());
	}
	Sleep(100);
	flash->Play();

	// change flash frame according user's status
	int status;
	if (fai->hFA.hContact)
		status = db_get_w(fai->hFA.hContact, fai->getProto(), "Status", ID_STATUS_OFFLINE);
	else
		status = CallProtoService(fai->getProto(), PS_GETSTATUS, 0, 0);

	getFace();
	flash->SetVariable(L"face.emotion", _bstr_t(face).copy());
	flash->Release();
}
Exemple #4
0
CID ClientManager::getMyCID() {
	TigerHash tiger;
	tiger.update(getMyPID().data(), CID::SIZE);
	return CID(tiger.finalize());
}
Exemple #5
0
int TestTiger()
{
	TigerHash tiger;

	const char *teststring = NULL;
	size_t length = 0;

	/* These tests are from http://www.cs.technion.ac.il/~biham/Reports/Tiger/tiger2-test-vectors-nessie-format.dat */

	teststring = ""; length = strlen(teststring);
	tiger.Process(teststring, length);
	TEST_ASSERT(strcmp(tiger.ToString(), "3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3") == 0);

	teststring = "a"; length = strlen(teststring);
	tiger.Process(teststring, length);
	TEST_ASSERT(strcmp(tiger.ToString(), "77befbef2e7ef8ab2ec8f93bf587a7fc613e247f5f247809") == 0);

	teststring = "abc"; length = strlen(teststring);
	tiger.Process(teststring, length);
	TEST_ASSERT(strcmp(tiger.ToString(), "2aab1484e8c158f2bfb8c5ff41b57a525129131c957b5f93") == 0);

	teststring = "message digest"; length = strlen(teststring);
	tiger.Process(teststring, length);
	TEST_ASSERT(strcmp(tiger.ToString(), "d981f8cb78201a950dcf3048751e441c517fca1aa55a29f6") == 0);

	teststring = "abcdefghijklmnopqrstuvwxyz"; length = strlen(teststring);
	tiger.Process(teststring, length);
	TEST_ASSERT(strcmp(tiger.ToString(), "1714a472eee57d30040412bfcc55032a0b11602ff37beee9") == 0);

	teststring = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; length = strlen(teststring);
	tiger.Process(teststring, length);
	TEST_ASSERT(strcmp(tiger.ToString(), "8dcea680a17583ee502ba38a3c368651890ffbccdc49a8cc") == 0);

	teststring = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"; length = strlen(teststring);
	tiger.Process(teststring, length);
	TEST_ASSERT(strcmp(tiger.ToString(), "1c14795529fd9f207a958f84c52f11e887fa0cabdfd91bfd") == 0);

	TigerHash otherhash;
	otherhash.Process("cheese", 6);
	TEST_ASSERT(otherhash != tiger && tiger != otherhash);

	otherhash.Process(teststring, length);
	TEST_ASSERT(otherhash == tiger && tiger == otherhash);

	return 0;
}