tests.c

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

C
1,169
字号

			if (strcmp (name, "AES") == 0)
			{
				// Verify the ciphertext of the "moving" data unit using the IEEE test vector #14
				if (memcmp (XTS_vectors[XTS_TEST_COUNT-1].ciphertext,
					(unsigned char *) buf + testCase * ENCRYPTION_DATA_UNIT_SIZE,
					ENCRYPTION_DATA_UNIT_SIZE) != 0)
				{
					return FALSE;
				}

				// CRC of all data units in the buffer for each test case
				switch (testCase)
				{
				case 0: 
					if (crc != 0x888f2990)
						return FALSE;
					nTestsPerformed++;
					break;
				case 1:
					if (crc != 0xea28ea34)
						return FALSE;
					nTestsPerformed++;
					break;
				case 2:
					if (crc != 0xe058f5a2)
						return FALSE;
					nTestsPerformed++;
					break;
				case 3:
					if (crc != 0x10473dc9)
						return FALSE;
					nTestsPerformed++;
					break;
				}
			}
			else if (strcmp (name, "Serpent") == 0)
			{
				switch (testCase)
				{
				case 0:
					if (crc != 0x7edfecb3)
						return FALSE;
					nTestsPerformed++;
					break;
				case 1:
					if (crc != 0x357baaaa)
						return FALSE;
					nTestsPerformed++;
					break;
				case 2:
					if (crc != 0xc7b9fca5)
						return FALSE;
					nTestsPerformed++;
					break;
				case 3:
					if (crc != 0xb5263e0c)
						return FALSE;
					nTestsPerformed++;
					break;
				}
			}
			else if (strcmp (name, "Twofish") == 0)
			{
				switch (testCase)
				{
				case 0:
					if (crc != 0x91525124)
						return FALSE;
					nTestsPerformed++;
					break;
				case 1:
					if (crc != 0x2895cc47)
						return FALSE;
					nTestsPerformed++;
					break;
				case 2:
					if (crc != 0x6bee346d)
						return FALSE;
					nTestsPerformed++;
					break;
				case 3:
					if (crc != 0xb1c45759)
						return FALSE;
					nTestsPerformed++;
					break;
				}
			}
			else if (strcmp (name, "AES-Twofish") == 0)
			{
				switch (testCase)
				{
				case 0:
					if (crc != 0x6cea7fa2)
						return FALSE;
					nTestsPerformed++;
					break;
				case 1:
					if (crc != 0x69052c4c)
						return FALSE;
					nTestsPerformed++;
					break;
				case 2:
					if (crc != 0x88db8de5)
						return FALSE;
					nTestsPerformed++;
					break;
				case 3:
					if (crc != 0xf16fd8c5)
						return FALSE;
					nTestsPerformed++;
					break;
				}
			}
			else if (strcmp (name, "AES-Twofish-Serpent") == 0)
			{
				switch (testCase)
				{
				case 0:
					if (crc != 0xa2d7d82a)
						return FALSE;
					nTestsPerformed++;
					break;
				case 1:
					if (crc != 0xdbf76412)
						return FALSE;
					nTestsPerformed++;
					break;
				case 2:
					if (crc != 0xdf0ea03e)
						return FALSE;
					nTestsPerformed++;
					break;
				case 3:
					if (crc != 0xdadedff7)
						return FALSE;
					nTestsPerformed++;
					break;
				}
			}
			else if (strcmp (name, "Serpent-AES") == 0)
			{
				switch (testCase)
				{
				case 0:
					if (crc != 0x6dd133b3)
						return FALSE;
					nTestsPerformed++;
					break;
				case 1:
					if (crc != 0x0e5717d2)
						return FALSE;
					nTestsPerformed++;
					break;
				case 2:
					if (crc != 0x39f83cd9)
						return FALSE;
					nTestsPerformed++;
					break;
				case 3:
					if (crc != 0x8a79fa2c)
						return FALSE;
					nTestsPerformed++;
					break;
				}
			}
			else if (strcmp (name, "Serpent-Twofish-AES") == 0)
			{
				switch (testCase)
				{
				case 0:
					if (crc != 0xe536daf8)
						return FALSE;
					nTestsPerformed++;
					break;
				case 1:
					if (crc != 0x3ae89e7f)
						return FALSE;
					nTestsPerformed++;
					break;
				case 2:
					if (crc != 0x2cc1301a)
						return FALSE;
					nTestsPerformed++;
					break;
				case 3:
					if (crc != 0xcac7bdc7)
						return FALSE;
					nTestsPerformed++;
					break;
				}
			}
			else if (strcmp (name, "Twofish-Serpent") == 0)
			{
				switch (testCase)
				{
				case 0:
					if (crc != 0x2686c859)
						return FALSE;
					nTestsPerformed++;
					break;
				case 1:
					if (crc != 0x8a201780)
						return FALSE;
					nTestsPerformed++;
					break;
				case 2:
					if (crc != 0x8dd13796)
						return FALSE;
					nTestsPerformed++;
					break;
				case 3:
					if (crc != 0xe95196cb)
						return FALSE;
					nTestsPerformed++;
					break;
				}
			}

			if (crc == 0x9f5edd58)
				return FALSE;

			DecryptDataUnits (buf, &unitNo, nbrUnits, ci);

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

			nTestsPerformed++;
		}
		testCase++;
	}

	/* Encryption/decryption of a buffer (typically, a volume header) */

⌨️ 快捷键说明

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