16 WCHAR*
testFile = L
"c:\\filterTest\\testEncryptfile1.bin";
17 WCHAR*
copyFile = L
"c:\\filterTest\\testEncryptfile1.copy.bin";
20 unsigned char iv[] = {0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff};
21 unsigned char clearText[] = {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a};
24 unsigned char key[] = {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4};
25 unsigned char cipherText[] = {0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28};
31 LARGE_INTEGER ByteOffset = {0};
32 OVERLAPPED Overlapped = {0};
33 DWORD dwTransferred = 0;
34 int nError = ERROR_SUCCESS;
43 nError = GetLastError();
44 if( nError != ERROR_ALREADY_EXISTS )
51 if( bypassFilterDriver )
53 dwFlagsAndAttributes |= FILE_ATTRIBUTE_REPARSE_POINT|
54 FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_NO_BUFFERING|FILE_FLAG_OPEN_NO_RECALL;
58 HANDLE pFile = CreateFile(
testFile,GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,dwFlagsAndAttributes,NULL);
60 if( pFile == INVALID_HANDLE_VALUE )
68 unsigned char* buffer = (
unsigned char*)_aligned_malloc(bufferLength,bufferLength);
76 ZeroMemory(buffer,65536);
81 if(!WriteFile(pFile, buffer,bufferLength, &dwTransferred, NULL))
83 nError = GetLastError();
99 _aligned_free( buffer);
109 HANDLE pFile = INVALID_HANDLE_VALUE;
117 ret = GetIVTag(
testFile,&ivLength,ivTag);
127 GENERIC_READ,NULL,NULL,
129 FILE_ATTRIBUTE_ENCRYPTED|FILE_ATTRIBUTE_REPARSE_POINT|
130 FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_NO_BUFFERING|FILE_FLAG_OPEN_NO_RECALL,
133 if( pFile == INVALID_HANDLE_VALUE )
141 unsigned char* buffer = (
unsigned char*)_aligned_malloc(bufferLength,bufferLength);
149 ret = ReadFile(pFile,buffer,bufferLength,&bufferLength,NULL);
156 if( isEncrypted && ivLength == 0)
159 PrintErrorMessage(L
"VerifyRawData failed, the encrypted file doesn't have iv tag.",0);
165 if( memcmp(buffer,
cipherText,bufferLength) == 0)
171 printf(
"Compare encrypted data failed.\r\nCipher data:");
177 printf(
"\r\nRaw data:");
180 printf(
"%2x",buffer[i]);
190 if( memcmp(buffer,
clearText,bufferLength) == 0)
196 printf(
"Compare decrypted data failed.\r\nClear data:");
197 for(
int i = 0; i <
sizeof(
clearText); i++)
202 printf(
"\r\nRaw data:");
203 for(
int i = 0; i <
sizeof(
clearText); i++)
205 printf(
"%2x",buffer[i]);
216 if( pFile != INVALID_HANDLE_VALUE )
223 _aligned_free( buffer);
234 HANDLE pFile = INVALID_HANDLE_VALUE;
235 HANDLE pFile2 = INVALID_HANDLE_VALUE;
239 unsigned char* buffer = NULL;
241 ret = GetIVTag(
testFile,&ivLength,ivTag);
256 GENERIC_READ,NULL,NULL,
258 FILE_ATTRIBUTE_ENCRYPTED|FILE_ATTRIBUTE_REPARSE_POINT|
259 FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_NO_BUFFERING|FILE_FLAG_OPEN_NO_RECALL,
262 if( pFile == INVALID_HANDLE_VALUE )
269 if( !GetFileSizeEx(pFile,&fileSize))
278 GENERIC_WRITE,NULL,NULL,
280 FILE_ATTRIBUTE_ENCRYPTED|FILE_ATTRIBUTE_REPARSE_POINT|
281 FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_NO_BUFFERING|FILE_FLAG_OPEN_NO_RECALL,
284 if( pFile2 == INVALID_HANDLE_VALUE )
290 DWORD dwTransferred = 0;
292 buffer = (
unsigned char*)_aligned_malloc(bufferLength,bufferLength);
300 ZeroMemory(buffer,65536);
302 ret = ReadFile(pFile,buffer,bufferLength,&dwTransferred,NULL);
310 if(!WriteFile(pFile2, buffer, bufferLength, &dwTransferred, NULL))
318 ret = SetFileSize(pFile2,fileSize.QuadPart);
324 if(pFile2 != INVALID_HANDLE_VALUE)
330 ret = AddIVTag(
copyFile,ivLength,ivTag);
338 if(pFile != INVALID_HANDLE_VALUE)
343 if(pFile2 != INVALID_HANDLE_VALUE)
350 _aligned_free( buffer);
360 HANDLE pFile = INVALID_HANDLE_VALUE;
363 GENERIC_READ,NULL,NULL,
365 FILE_ATTRIBUTE_NORMAL,
368 if( pFile == INVALID_HANDLE_VALUE )
375 unsigned char* buffer = (
unsigned char*)_aligned_malloc(bufferLength,bufferLength);
383 ZeroMemory(buffer,65536);
385 ret = ReadFile(pFile,buffer,bufferLength,&bufferLength,NULL);
392 if( memcmp(buffer,
clearText,bufferLength) == 0)
398 printf(
"Verified filter driver decryption data failed.\r\nclearText data:");
399 for(
int i = 0; i <
sizeof(
clearText); i++)
404 printf(
"\r\nReturn data:");
405 for(
int i = 0; i <
sizeof(
clearText); i++)
407 printf(
"%2x",buffer[i]);
418 if( pFile != INVALID_HANDLE_VALUE )
425 _aligned_free( buffer);
ULONG BYTE ULONG ivLength
BOOL VerifyRawData(BOOL isEncrypted)
BOOL VerifyFilterDriverDecryptData()
DWORD DWORD DWORD DWORD dwFlagsAndAttributes
unsigned char clearText[]
VOID EncryptionUnitTest()
unsigned char cipherText[]
BOOL CreateTestFile(BOOL bypassFilterDriver)