Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Exile 1.8 - The Password Manager

, 7 Mar 2005
Yet another password manager.
exile_18_setup.zip
exile_1.8_setup.exe
exile_exe.zip
exile.exe
Exile.exe.manifest
icons.dll
md5.dll
mdx.dll
PwsInfo.dll
rc5.dll
exile_exe_staticmfc.zip
exile.exe
icons.dll
md5.dll
mdx.dll
rc5.dll
exile_src.zip
exile
Exile
Exile.exe.manifest
exile.dep
exile.dsp
exile.dsw
res
aboveimportant.ico
advanced.bmp
belowcritical.ico
belowinsignificant.ico
belownormal.ico
changeicon.bmp
cold.ico
collapsed.ico
critical.ico
editcategory.bmp
editelement.bmp
enterpassword.bmp
error.ico
exile.ico
expanded.ico
exporttoxml.bmp
find.ico
found.ico
important.ico
insertcategory.bmp
insertelement.bmp
insignificant.ico
md5hashgenerator.bmp
new.bmp
normal.ico
options.bmp
passwordgenerator.bmp
rsasecurity.bmp
rsasecurity.ico
search.cur
storageproperties.bmp
switch.bmp
unimportant.ico
veryimportant.ico
vssver.scc
Icons
res
icon1.ico
icon10.ico
icon11.ico
icon12.ico
icon13.ico
icon14.ico
icon15.ico
icon16.ico
icon17.ico
icon18.ico
icon19.ico
icon2.ico
icon20.ico
icon21.ico
icon22.ico
icon23.ico
icon24.ico
icon25.ico
icon26.ico
icon27.ico
icon28.ico
icon3.ico
icon4.ico
icon5.ico
icon6.ico
icon7.ico
icon8.ico
icon9.ico
md5
md5.dep
md5.dsp
mdx
pwsinfo
passwordstorageshellext.rgs
pwsinfo.def
pwsinfo.dep
pwsinfo.dsp
pwsinfo.dsw
PwsInfo.tlb
pwsinfops.def
pwsinfops.mk
rc5
rc5.dep
rc5.dsp
xml
exile_src_vs2003.zip
Exile.exe.manifest
Exile.dep
Exile.dsp
Exile.dsw
Exile.suo
msxml3.tlh
msxml3.tli
res
AboveImportant.ico
Advanced.bmp
BelowCritical.ico
BelowInsignificant.ico
BelowNormal.ico
ChangeIcon.bmp
Cold.ico
Critical.ico
EditCategory.bmp
EditElement.bmp
EnterPassword.bmp
Error.ico
Exile.ico
ExportToXML.bmp
Find.ico
Found.ico
Icon1.ico
Icon10.ico
Icon11.ico
Icon12.ico
Icon13.ico
Icon14.ico
icon15.ico
Icon16.ico
Icon17.ico
Icon18.ico
Icon19.ico
Icon2.ico
Icon20.ico
Icon21.ico
Icon22.ico
Icon23.ico
Icon24.ico
Icon25.ico
Icon26.ico
Icon27.ico
Icon28.ico
Icon3.ico
Icon4.ico
Icon5.ico
Icon6.ico
Icon7.ico
Icon8.ico
Icon9.ico
Important.ico
InsertCategory.bmp
InsertElement.bmp
Insignificant.ico
MD5HashGenerator.bmp
New.bmp
Normal.ico
Options.bmp
PasswordGenerator.bmp
RSASecurity.bmp
rsasecurity.ico
Search.cur
StorageProperties.bmp
Switch.bmp
Unimportant.ico
VeryImportant.ico
vssver.scc
MD5
MD5.dep
MD5.dsp
PwsInfo
PasswordStorageShellExt.rgs
PwsInfo.def
PwsInfo.dep
PwsInfo.dsp
PwsInfo.dsw
PwsInfo.tlb
PwsInfops.def
PwsInfops.mk
RC5
RC5.dep
RC5.dsp
/********************************************************************
	Created:	27/3/2004, 21:37
	File name: 	D:\Projects\Exile\Exile\security.cpp
	File path:	D:\Projects\Exile\Exile
	File base:	security
	File ext:	cpp
	Author:		Gogolev Anton
*********************************************************************/

#include "StdAfx.h"
#include "../mdx/mdx.h"
#include "Security.h"

void GeneratePrivateKey(CString &rstrUserName, CString &rstrPassword, int nKeyLength, KEYINFO &rKeyInfo)
{
	rKeyInfo.pbKey = new BYTE[nKeyLength / 8];
	rKeyInfo.nKeySize = nKeyLength;
	MDXHASH hs[8]; // This is maximum as 1024 bit key is the longest available

	size_t sUserName = rstrUserName.GetLength() * sizeof(TCHAR);
	size_t sPassword = rstrPassword.GetLength() * sizeof(TCHAR);

	BYTE *pBuffer = 0; // Buffer for holding data which is to be hashed

	for(int n = 0; n < nKeyLength / 8 / 16; ++n)
	{
		// In each round we use User Name, Password and all previous 
		// hashes to get a new hash.
		// MdxGetExpandedBufferSize() calculates the size of a buffer we'll need.
		size_t sBuffer = ::MdxGetExpandedBufferSize(sUserName + sPassword + sizeof(MDXHASH) * n);
		pBuffer = new BYTE[sBuffer];

		// This is always like that
		memmove(pBuffer, rstrUserName.LockBuffer(), sUserName);
		memmove(pBuffer + sUserName, rstrPassword.LockBuffer(), sPassword);

		// And now append previous hashes
		for(int i = 0; i < n; ++i)
		{
			memmove(pBuffer + sUserName + sPassword + sizeof(MDXHASH) * i, (void *)&hs[i], sizeof(MDXHASH));
		} // for

		// Now hash what we have
		size_t sSgSize = sUserName + sPassword + sizeof(MDXHASH) * n;
		::MdxExpandData(pBuffer, sSgSize, sBuffer);
		::MdxHashData((MDX_WORD *)pBuffer, sBuffer / 64, hs[n]);

		// When we have this loop for the first time, hs[0]
		// equals to "User Name + Password" hash which is exactly what
		// we need
		if(0 == n)
			rKeyInfo.hsPassword = hs[0];

		FreeBuffer(pBuffer, sBuffer);
	} // for

	// Now moving to buffer we allocated...
	memmove(rKeyInfo.pbKey, hs, nKeyLength / 8);

	// ...and cleaning up
	CleanBuffer(hs, sizeof(MDXHASH) * 8);
}

void GeneratePasswordHash(CString &rstrUserName, CString &rstrPassword, MDXHASH &rhsPassword)
{
	size_t sUserName = rstrUserName.GetLength() * sizeof(TCHAR);
	size_t sPassword = rstrPassword.GetLength() * sizeof(TCHAR);

	BYTE *pBuffer = 0; // Buffer for holding data which is to be hashed

	size_t sBuffer = ::MdxGetExpandedBufferSize(sUserName + sPassword);
	pBuffer = new BYTE[sBuffer];

	memmove(pBuffer, rstrUserName.LockBuffer(), sUserName);
	memmove(pBuffer + sUserName, rstrPassword.LockBuffer(), sPassword);

	::MdxExpandData(pBuffer, sUserName + sPassword, sBuffer);
	::MdxHashData((MDX_WORD *)pBuffer, sBuffer / 64, rhsPassword);

	FreeBuffer(pBuffer, sUserName + sPassword);
}

void GeneratePassword(TCHAR *pszCharSet, int nCharSetLength, DWORD *pdwData,
					  int nDataLength, int nPasswordLength, TCHAR *pszPassword)
{
	if((0 == pszCharSet) || (0 == nCharSetLength) || (0 == pdwData) || (0 == nDataLength) || 
		(0 == nPasswordLength) || (0 == pszPassword))
		return;

	// First, hash ;) data we have and a character set
	size_t sData, sBuffer;
	sData = sizeof(TCHAR) * nCharSetLength;
	sBuffer = ::MdxGetExpandedBufferSize(sData);

	// Character set
	BYTE *pBuffer = new BYTE[sBuffer];
	MDXHASH hsCharset, hsData;

	memmove(pBuffer, (void *)pszCharSet, sData);

	::MdxExpandData(pBuffer, sData, sBuffer);
	::MdxHashData((MDX_WORD *)pBuffer, sBuffer / 64, hsCharset);

	FreeBuffer(pBuffer, sBuffer);

	// Input data
	sData = sizeof(DWORD) * nDataLength;
	sBuffer = ::MdxGetExpandedBufferSize(sData);

	pBuffer = new BYTE[sBuffer];

	memmove(pBuffer, (void *)pdwData, sData);

	::MdxExpandData(pBuffer, sData, sBuffer);
	::MdxHashData((MDX_WORD *)pBuffer, sBuffer / 64, hsData);

	FreeBuffer(pBuffer, sBuffer);

	// Done with preparations. Now generating password
	unsigned int nChar = 0;

	for(int n = 0; n < nPasswordLength; ++n)
	{
		// Have several versions
		switch(n % 4) 
		{
		case 0:
			nChar = hsCharset.wA ^ pdwData[n % nDataLength] ^ hsData.wD;
			break;
		case 1:
			nChar = hsCharset.wB ^ pdwData[n % nDataLength] ^ hsData.wC;
			break;
		case 2:
			nChar = hsCharset.wC ^ pdwData[n % nDataLength] ^ hsData.wB;
			break;
		case 3:
			nChar = hsCharset.wD ^ pdwData[n % nDataLength] ^ hsData.wA;
			break;
		default:
			break;
		} // switch

		nChar %= nCharSetLength;
		pszPassword[n] = pszCharSet[nChar];
	} // for

	// Done
	CleanBuffer(&hsCharset, sizeof(MDXHASH));
	CleanBuffer(&hsData, sizeof(MDXHASH));
}

void FreeBuffer(void *pBuffer, size_t sBuffer)
{
	// Do it a couple of times
	memset(pBuffer, 0, sBuffer);
	memset(pBuffer, 0xFFFF, sBuffer);

	delete [] pBuffer;
}

void CleanBuffer(void *pBuffer, size_t sBuffer)
{
	// Do it a couple of times
	memset(pBuffer, 0, sBuffer);
	memset(pBuffer, 0xFFFF, sBuffer);
}

void CleanString(CString &rstrS)
{
	for(int n = 0; n < rstrS.GetLength(); ++n)
	{
		rstrS.SetAt(n, _T('0'));
	} // for
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

AntonGogolev
Web Developer
Russian Federation Russian Federation
I'll think about it later on...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141216.1 | Last Updated 7 Mar 2005
Article Copyright 2004 by AntonGogolev
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid