tests.c

来自「使用visual studio 2005 开发的开源文件、磁盘加密软件。这是6.」· C语言 代码 · 共 1,169 行 · 第 1/5 页

C
1,169
字号
	nbrUnits = sizeof (buf) / ENCRYPTION_DATA_UNIT_SIZE;

	// Test all EAs that support this mode of operation
	for (ci->ea = EAGetFirst (); ci->ea != 0; ci->ea = EAGetNext (ci->ea))
	{
		if (!EAIsModeSupported (ci->ea, ci->mode))
			continue;

		EAGetName (name, ci->ea);

		if (EAInit (ci->ea, key1, ci->ks) != ERR_SUCCESS)
			return FALSE;

		memcpy (&ci->k2, XTS_vectors[XTS_TEST_COUNT-1].key2, sizeof (XTS_vectors[XTS_TEST_COUNT-1].key2));

		if (!EAInitMode (ci))
			return FALSE;

		// Each data unit will contain the same plaintext
		for (i = 0; i < nbrUnits; i++)
		{
			memcpy ((unsigned char *) buf + i * ENCRYPTION_DATA_UNIT_SIZE, 
				XTS_vectors[XTS_TEST_COUNT-1].plaintext, 
				ENCRYPTION_DATA_UNIT_SIZE);
		}

		EncryptBuffer (buf, sizeof (buf), ci);

		crc = GetCrc32 (buf, sizeof (buf));

		if (strcmp (name, "AES") == 0)
		{
			if (crc != 0x33b91fab)
				return FALSE;
			nTestsPerformed++;
		}
		else if (strcmp (name, "Serpent") == 0)
		{
			if (crc != 0x3494d480)
				return FALSE;
			nTestsPerformed++;
		}
		else if (strcmp (name, "Twofish") == 0)
		{
			if (crc != 0xc4d65b46)
				return FALSE;
			nTestsPerformed++;
		}
		else if (strcmp (name, "AES-Twofish") == 0)
		{
			if (crc != 0x14ce7385)
				return FALSE;
			nTestsPerformed++;
		}
		else if (strcmp (name, "AES-Twofish-Serpent") == 0)
		{
			if (crc != 0x0ec81bf7)
				return FALSE;
			nTestsPerformed++;
		}
		else if (strcmp (name, "Serpent-AES") == 0)
		{
			if (crc != 0x42f919ad)
				return FALSE;
			nTestsPerformed++;
		}
		else if (strcmp (name, "Serpent-Twofish-AES") == 0)
		{
			if (crc != 0x208d5c58)
				return FALSE;
			nTestsPerformed++;
		}
		else if (strcmp (name, "Twofish-Serpent") == 0)
		{
			if (crc != 0xbe78cec1)
				return FALSE;
			nTestsPerformed++;
		}

		if (crc == 0x9f5edd58)
			return FALSE;

		DecryptBuffer (buf, sizeof (buf), ci);

		if (GetCrc32 (buf, sizeof (buf)) != 0x9f5edd58)
			return FALSE;

		nTestsPerformed++;
	}

	return (nTestsPerformed == 80);
}


BOOL TestLegacySectorBufEncryption (PCRYPTO_INFO ci)
{
	unsigned char buf [ENCRYPTION_DATA_UNIT_SIZE * 2];
	unsigned int i;
	char name[64];
	unsigned __int32 crc;
	UINT64_STRUCT unitNo;
	TC_LARGEST_COMPILER_UINT nbrUnits;
	int blockSize;
	BOOL lrw64InitDone = FALSE;
	BOOL lrw128InitDone = FALSE;
	int nTestsPerformed = 0;

	unitNo.Value = 0x0234567890ABCDEFull;
	nbrUnits = sizeof (buf) / ENCRYPTION_DATA_UNIT_SIZE;

	for (i = 0; i < sizeof (buf); i++)
		buf[i] = (unsigned char) i;

	for (i = 0; i < sizeof (ci->k2); i++)
		ci->k2[i] = (unsigned char) i;

	// Test all EAs
	for (ci->ea = EAGetFirst (); ci->ea != 0; ci->ea = EAGetNext (ci->ea))
	{
		EAGetName (name, ci->ea);
		blockSize = CipherGetBlockSize (EAGetFirstCipher (ci->ea));

		if (EAInit (ci->ea, (unsigned char *)buf, ci->ks) == ERR_CIPHER_INIT_FAILURE)
			return FALSE;

		// Test all available modes of operation
		for (ci->mode = EAGetFirstMode (ci->ea);
			ci->mode != 0;
			ci->mode = EAGetNextMode (ci->ea, ci->mode))
		{
			if (ci->mode == XTS)
				continue;	// XTS mode is tested in another function

			if (ci->mode == LRW
				&& (blockSize == 8 && !lrw64InitDone || blockSize == 16 && !lrw128InitDone ))
			{
				if (!EAInitMode (ci))
					return FALSE;

				if (blockSize == 8)
					lrw64InitDone = TRUE;
				else if (blockSize == 16)
					lrw128InitDone = TRUE;
			}

			EncryptDataUnits (buf, &unitNo, nbrUnits, ci);
			crc = GetCrc32 (buf, sizeof (buf));

			switch (ci->mode)
			{
			case LRW:		// Deprecated/legacy
				if (strcmp (name, "AES") == 0)
				{
					if (crc != 0x5237acf9)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "Blowfish") == 0)	// Deprecated/legacy
				{
					if (crc != 0xf94d5300)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "CAST5") == 0)		// Deprecated/legacy
				{
					if (crc != 0x33971e82)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "Serpent") == 0)
				{
					if (crc != 0x7fb86805)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "Triple DES") == 0)	// Deprecated/legacy
				{
					if (crc != 0x2b20bb84)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "Twofish") == 0)
				{
					if (crc != 0xa9de0f0b)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "AES-Twofish") == 0)
				{
					if (crc != 0x4ed0fd80)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "AES-Twofish-Serpent") == 0)
				{
					if (crc != 0xea04b3cf)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "Serpent-AES") == 0)
				{
					if (crc != 0x0d33596a)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "Serpent-Twofish-AES") == 0)
				{
					if (crc != 0x2845d0e3)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "Twofish-Serpent") == 0)
				{
					if (crc != 0xca65c5cd)
						return FALSE;
					nTestsPerformed++;
				}
				break;

			case CBC:		// Deprecated/legacy
			case INNER_CBC:	// Deprecated/legacy
			case OUTER_CBC:	// Deprecated/legacy
				if (strcmp (name, "AES") == 0)
				{
					if (crc != 0x2274f53d)
						return FALSE;
					nTestsPerformed++;
				}
				else if (strcmp (name, "Blowfish") == 0)	// Deprecated/legacy
				{
					if (crc != 0x033899a1)
						return FALSE;
					nTestsPerform

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?