Exemplo n.º 1
0
void Encryption::GenHive ()
{
	// This generates the first pass of the main key hive.
	// This is only done once, because the initial hive comes from the seed
	// after this, we then use expand hive to create the final key hive.
	int s = 0;

	char szMult[2];
	char szPower[1];
	char szProduct[SIZE_STRING];

	unsigned long lMult = 0;
	unsigned long lPower = 0;
	unsigned long lProduct = 0;

	MemoryBuffer memHive;
	memHive.SetSize (m_memSeed.GetAppendPointer ()*SIZE_STRING);

	for (s=0;s<m_memSeed.GetAppendPointer ()-3;s++) {

		// Copy 3 bytes at the current position into the Multiplier buffer
		ZeroMemory (szMult, 2);
		ZeroMemory (szPower, 1);
		strncpy (szMult, (char *) m_memSeed.GetBuffer ()+s, 2);
		strncpy (szPower, (char *) m_memSeed.GetBuffer ()+s+2, 1);

		lMult = atoi (szMult);
		lPower = atoi (szPower);

		ZeroMemory (szProduct, SIZE_STRING);
		lProduct = Raise (lMult, lPower);
		ultoa (lProduct, szProduct, 10);
		
		//OutputInt ("lProduct: ", lProduct);
		//OutputText ("szProduct: ", szProduct);

		memHive.Append ((char *) szProduct, strlen (szProduct));
	}

	m_memHive.SetSize (memHive.GetAppendPointer ());
	m_memHive.Append (memHive.GetBuffer (), memHive.GetAppendPointer ());
	memHive.Clear ();
}
Exemplo n.º 2
0
void Encryption::SeedChecksum ()
{
	// This function computes the checksum of the input passphrase
	// and then adds this checksum value to each byte value in the current seed string.

	MemoryBuffer memNewseed;

	char szChecksum [SIZE_STRING];
	ZeroMemory (szChecksum, SIZE_STRING);

	char szSeedpart [SIZE_STRING];
	ZeroMemory (szSeedpart, SIZE_STRING);

	char szNewseed [SIZE_STRING];
	ZeroMemory (szNewseed, SIZE_STRING);

	unsigned int iSeedpart;

	itoa (m_seedChecksum, szChecksum, 10);

	memNewseed.SetSize (strlen (szChecksum) * SIZE_STRING);

	for (int s=0;s<m_memSeed.GetAppendPointer ()-strlen(szChecksum);s++) {
		ZeroMemory (szSeedpart, SIZE_STRING);
		strncpy (szSeedpart, (char *) m_memSeed.GetBuffer ()+s, strlen (szChecksum));

		iSeedpart = atoi (szSeedpart);
		iSeedpart+=m_seedChecksum;

		ZeroMemory (szNewseed, SIZE_STRING);
		itoa (iSeedpart, szNewseed, 10);

		memNewseed.Append ((char *) szNewseed, strlen (szNewseed));
	}

	m_memSeed.Clear ();
	m_memSeed.SetSize (memNewseed.GetAppendPointer ());
	m_memSeed.Append (memNewseed.GetBuffer (), memNewseed.GetAppendPointer ());
	memNewseed.Clear ();

	//OutputSeed ();
}
Exemplo n.º 3
0
unsigned long Encryption::ExpandHive (MemoryBuffer *phive)
{
	MemoryBuffer tmpHive;

	int s = 0;
	char szMult[2];
	char szPower[1];
	char szProduct[SIZE_STRING];

	unsigned long lMult = 0;
	unsigned long lPower = 0;
	unsigned long lProduct = 0;

	tmpHive.SetSize (phive->GetAppendPointer ()*SIZE_STRING);

	for (s=0;s<phive->GetAppendPointer ()-3;s++) {
		// Copy 3 bytes at the current position into the Multiplier buffer
		ZeroMemory (szMult, 2);
		ZeroMemory (szPower, 1);
		strncpy (szMult, (char *) phive->GetBuffer ()+s, 2);
		strncpy (szPower, (char *) phive->GetBuffer ()+s+2, 1);

		lMult = atoi (szMult);
		lPower = atoi (szPower);

		ZeroMemory (szProduct, SIZE_STRING);
		lProduct = Raise (lMult, lPower);
		ultoa (lProduct, szProduct, 10);

		tmpHive.Append ((char *) szProduct, strlen (szProduct));
	}

	phive->Clear ();
	phive->SetSize (tmpHive.GetAppendPointer ());
	phive->Append (tmpHive.GetBuffer (), tmpHive.GetAppendPointer ());
	tmpHive.Clear ();
	return phive->GetAppendPointer ();
}
Exemplo n.º 4
0
bool Encryption::DoCipher (HWND hWnd, MemoryBuffer *pinbuffer, MemoryBuffer *poutbuffer, bool bEncrypt)
{
	// Single threaded encryption function. Operates in a seperate thread, but a single thread
	// only. Unfortunately on a Core Duo, or HT processor, it will only max out one of the CPU
	// windows.

	MemoryBuffer tmpBuffer;
	unsigned long rndHive = 0;
	int algsize = 100;
	unsigned long hivepointer = 0;
	unsigned long inputoffset = 0;
	unsigned long iprogress = 0;
	unsigned long ipercentage = 0;
	int algpointer = 0;
	unsigned long i = 0;

	int cTrans = 0; // Our transposition value
	int cAlg = 0; // The algorithm we use alongside the transposition value
	unsigned long cProduct = 0; // This value is the current result of the transposition multiplication
	bool cShift = 0;  // The transposition shift - up or down
	BYTE cByte = 0; // The current byte we're working on.

	if (m_bHivecreated == false) {
		OutputText ("Encryption: ", "Key hive not created.");
		return false;
	} else {
	
		tmpBuffer.SetSize ((pinbuffer->GetSize ()+sizeof (unsigned long))*2);
		OutputInt ("DoCipher: ", pinbuffer->GetSize ()*2);

		// Generate a random number between 0 and the size of the hive
		// minus 100 (we use 100 single digits for determining the transposition
		// shift mechanism and transposition multiplier

		if (bEncrypt == true) {
			rndHive = GetRand (m_memHive.GetAppendPointer ()-algsize);
			tmpBuffer.Append (&rndHive, sizeof (unsigned long));
		} else {
			memcpy (&rndHive, pinbuffer->GetBuffer (), sizeof (unsigned long));
			inputoffset+=sizeof (unsigned long);
		}

		for (i=0;i<pinbuffer->GetSize ()-inputoffset;i++) {
			
			
			cTrans = GetHiveValue (hivepointer, 2);
			cAlg = GetHiveValue (rndHive+algpointer, 1);

			if (cAlg <= 5) {
				cShift = true; // true means we transpose up
			} else {
				cShift = false; // false means we transpose down
			}

			// Now transpose the current byte given the current hive value
			// algorithm value and shift direction.
			cByte = pinbuffer->GetByte (i+inputoffset);
			cProduct = cTrans * cAlg;

			if (bEncrypt == true) {
				if (cShift == true) {
					cByte+=cProduct;
				} else {
					cByte-=cProduct;
				}
			} else {
				if (cShift == true) {
					cByte-=cProduct;
				} else {
					cByte+=cProduct;
				}
			}
			

			tmpBuffer.Append (&cByte, sizeof (BYTE));

			hivepointer+=2;
			algpointer++;

			if (hivepointer >= m_memHive.GetAppendPointer ()-2) {
				hivepointer = 0;
			}

			if (algpointer >= algsize) {
				algpointer = 0;
			}

			iprogress++;
			if (iprogress > 10000) {
				iprogress = 0;
				ipercentage = (i * 10) / (pinbuffer->GetSize ()-inputoffset);
				PostMessage (hWnd, CRYPT_MSG, CRYPT_PROGRESSSINGLE, (LPARAM) ipercentage*10);
			}
		
		}

		poutbuffer->SetSize (tmpBuffer.GetAppendPointer ());
		poutbuffer->Append (tmpBuffer.GetBuffer (), tmpBuffer.GetAppendPointer ());
		tmpBuffer.Clear ();
		PostMessage (hWnd, CRYPT_MSG, CRYPT_PROGRESSSINGLE, (LPARAM) -1);
		return true;
	}
}