From 33242df5dc6af3d6bf2a7ae5af30a5d6418c1633 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Thu, 26 Sep 2013 16:41:54 +0000 Subject: [PATCH] [RSAENH_WINETEST] * Sync with Wine 1.7.1. CORE-7469 svn path=/trunk/; revision=60374 --- rostests/winetests/rsaenh/CMakeLists.txt | 7 +- rostests/winetests/rsaenh/rsaenh.c | 152 ++++++++++++++++++++++- rostests/winetests/rsaenh/testlist.c | 5 +- 3 files changed, 150 insertions(+), 14 deletions(-) diff --git a/rostests/winetests/rsaenh/CMakeLists.txt b/rostests/winetests/rsaenh/CMakeLists.txt index db0dcb76f9a..d8eedc3b3e5 100644 --- a/rostests/winetests/rsaenh/CMakeLists.txt +++ b/rostests/winetests/rsaenh/CMakeLists.txt @@ -1,10 +1,5 @@ -add_definitions( - -D__ROS_LONG64__ - -D_DLL -D__USE_CRTIMP) - add_executable(rsaenh_winetest rsaenh.c testlist.c) -target_link_libraries(rsaenh_winetest wine) set_module_type(rsaenh_winetest win32cui) -add_importlibs(rsaenh_winetest advapi32 msvcrt kernel32 ntdll) +add_importlibs(rsaenh_winetest advapi32 msvcrt kernel32) add_cd_file(TARGET rsaenh_winetest DESTINATION reactos/bin FOR all) diff --git a/rostests/winetests/rsaenh/rsaenh.c b/rostests/winetests/rsaenh/rsaenh.c index 4af3cdcc433..f43a4e4f0cd 100644 --- a/rostests/winetests/rsaenh/rsaenh.c +++ b/rostests/winetests/rsaenh/rsaenh.c @@ -773,7 +773,7 @@ static void test_3des112(void) HCRYPTKEY hKey; BOOL result; DWORD dwLen; - unsigned char pbData[16]; + unsigned char pbData[16], enc_data[16], bad_data[16]; int i; result = derive_key(CALG_3DES_112, &hKey, 0); @@ -800,6 +800,7 @@ static void test_3des112(void) result = CryptEncrypt(hKey, 0, TRUE, 0, pbData, &dwLen, cTestData[i].buflen); ok(result, "%08x\n", GetLastError()); ok(dwLen==cTestData[i].buflen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].buflen); + memcpy(enc_data, pbData, cTestData[i].buflen); result = CryptDecrypt(hKey, 0, TRUE, 0, pbData, &dwLen); ok(result, "%08x\n", GetLastError()); @@ -811,6 +812,41 @@ static void test_3des112(void) printBytes("expected",cTestData[i].decstr,cTestData[i].strlen); printBytes("got",pbData,dwLen); } + + /* Test bad data: + Decrypting a block of bad data with Final = TRUE should restore the + initial state of the key as well as decrypting a block of good data. + */ + + /* Changing key state by setting Final = FALSE */ + dwLen = cTestData[i].buflen; + memcpy(pbData, enc_data, cTestData[i].buflen); + result = CryptDecrypt(hKey, 0, FALSE, 0, pbData, &dwLen); + ok(result, "%08x\n", GetLastError()); + + /* Restoring key state by decrypting bad_data with Final = TRUE */ + memcpy(bad_data, enc_data, cTestData[i].buflen); + bad_data[cTestData[i].buflen - 1] = ~bad_data[cTestData[i].buflen - 1]; + SetLastError(0xdeadbeef); + result = CryptDecrypt(hKey, 0, TRUE, 0, bad_data, &dwLen); + ok(!result, "CryptDecrypt should failed!\n"); + ok(GetLastError() == NTE_BAD_DATA, "%08x\n", GetLastError()); + ok(dwLen==cTestData[i].buflen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].buflen); + ok(memcmp(pbData,cTestData[i].decstr,cTestData[1].enclen)==0,"decryption incorrect %d\n",i); + + /* Checking key state */ + dwLen = cTestData[i].buflen; + memcpy(pbData, enc_data, cTestData[i].buflen); + result = CryptDecrypt(hKey, 0, TRUE, 0, pbData, &dwLen); + ok(result, "%08x\n", GetLastError()); + ok(dwLen==cTestData[i].enclen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].enclen); + ok(memcmp(pbData,cTestData[i].decstr,cTestData[1].enclen)==0,"decryption incorrect %d\n",i); + if((dwLen != cTestData[i].enclen) || + memcmp(pbData,cTestData[i].decstr,cTestData[i].enclen)) + { + printBytes("expected",cTestData[i].decstr,cTestData[i].strlen); + printBytes("got",pbData,dwLen); + } } result = CryptDestroyKey(hKey); ok(result, "%08x\n", GetLastError()); @@ -821,7 +857,7 @@ static void test_des(void) HCRYPTKEY hKey; BOOL result; DWORD dwLen, dwMode; - unsigned char pbData[16]; + unsigned char pbData[16], enc_data[16], bad_data[16]; int i; result = derive_key(CALG_DES, &hKey, 56); @@ -856,6 +892,7 @@ static void test_des(void) result = CryptEncrypt(hKey, 0, TRUE, 0, pbData, &dwLen, cTestData[i].buflen); ok(result, "%08x\n", GetLastError()); ok(dwLen==cTestData[i].buflen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].buflen); + memcpy(enc_data, pbData, cTestData[i].buflen); result = CryptDecrypt(hKey, 0, TRUE, 0, pbData, &dwLen); ok(result, "%08x\n", GetLastError()); @@ -867,6 +904,41 @@ static void test_des(void) printBytes("expected",cTestData[i].decstr,cTestData[i].strlen); printBytes("got",pbData,dwLen); } + + /* Test bad data: + Decrypting a block of bad data with Final = TRUE should restore the + initial state of the key as well as decrypting a block of good data. + */ + + /* Changing key state by setting Final = FALSE */ + dwLen = cTestData[i].buflen; + memcpy(pbData, enc_data, cTestData[i].buflen); + result = CryptDecrypt(hKey, 0, FALSE, 0, pbData, &dwLen); + ok(result, "%08x\n", GetLastError()); + + /* Restoring key state by decrypting bad_data with Final = TRUE */ + memcpy(bad_data, enc_data, cTestData[i].buflen); + bad_data[cTestData[i].buflen - 1] = ~bad_data[cTestData[i].buflen - 1]; + SetLastError(0xdeadbeef); + result = CryptDecrypt(hKey, 0, TRUE, 0, bad_data, &dwLen); + ok(!result, "CryptDecrypt should failed!\n"); + ok(GetLastError() == NTE_BAD_DATA, "%08x\n", GetLastError()); + ok(dwLen==cTestData[i].buflen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].buflen); + ok(memcmp(pbData,cTestData[i].decstr,cTestData[1].enclen)==0,"decryption incorrect %d\n",i); + + /* Checking key state */ + dwLen = cTestData[i].buflen; + memcpy(pbData, enc_data, cTestData[i].buflen); + result = CryptDecrypt(hKey, 0, TRUE, 0, pbData, &dwLen); + ok(result, "%08x\n", GetLastError()); + ok(dwLen==cTestData[i].enclen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].enclen); + ok(memcmp(pbData,cTestData[i].decstr,cTestData[1].enclen)==0,"decryption incorrect %d\n",i); + if((dwLen != cTestData[i].enclen) || + memcmp(pbData,cTestData[i].decstr,cTestData[i].enclen)) + { + printBytes("expected",cTestData[i].decstr,cTestData[i].strlen); + printBytes("got",pbData,dwLen); + } } result = CryptDestroyKey(hKey); @@ -878,7 +950,7 @@ static void test_3des(void) HCRYPTKEY hKey; BOOL result; DWORD dwLen; - unsigned char pbData[16]; + unsigned char pbData[16], enc_data[16], bad_data[16]; static const BYTE des3[16] = { 0x7b, 0xba, 0xdd, 0xa2, 0x39, 0xd3, 0x7b, 0xb3, 0xc7, 0x51, 0x81, 0x41, 0x53, 0xe8, 0xcf, 0xeb }; @@ -906,6 +978,7 @@ static void test_3des(void) result = CryptEncrypt(hKey, 0, TRUE, 0, pbData, &dwLen, cTestData[i].buflen); ok(result, "%08x\n", GetLastError()); ok(dwLen==cTestData[i].buflen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].buflen); + memcpy(enc_data, pbData, cTestData[i].buflen); result = CryptDecrypt(hKey, 0, TRUE, 0, pbData, &dwLen); ok(result, "%08x\n", GetLastError()); @@ -917,6 +990,41 @@ static void test_3des(void) printBytes("expected",cTestData[i].decstr,cTestData[i].strlen); printBytes("got",pbData,dwLen); } + + /* Test bad data: + Decrypting a block of bad data with Final = TRUE should restore the + initial state of the key as well as decrypting a block of good data. + */ + + /* Changing key state by setting Final = FALSE */ + dwLen = cTestData[i].buflen; + memcpy(pbData, enc_data, cTestData[i].buflen); + result = CryptDecrypt(hKey, 0, FALSE, 0, pbData, &dwLen); + ok(result, "%08x\n", GetLastError()); + + /* Restoring key state by decrypting bad_data with Final = TRUE */ + memcpy(bad_data, enc_data, cTestData[i].buflen); + bad_data[cTestData[i].buflen - 1] = ~bad_data[cTestData[i].buflen - 1]; + SetLastError(0xdeadbeef); + result = CryptDecrypt(hKey, 0, TRUE, 0, bad_data, &dwLen); + ok(!result, "CryptDecrypt should failed!\n"); + ok(GetLastError() == NTE_BAD_DATA, "%08x\n", GetLastError()); + ok(dwLen==cTestData[i].buflen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].buflen); + ok(memcmp(pbData,cTestData[i].decstr,cTestData[1].enclen)==0,"decryption incorrect %d\n",i); + + /* Checking key state */ + dwLen = cTestData[i].buflen; + memcpy(pbData, enc_data, cTestData[i].buflen); + result = CryptDecrypt(hKey, 0, TRUE, 0, pbData, &dwLen); + ok(result, "%08x\n", GetLastError()); + ok(dwLen==cTestData[i].enclen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].enclen); + ok(memcmp(pbData,cTestData[i].decstr,cTestData[1].enclen)==0,"decryption incorrect %d\n",i); + if((dwLen != cTestData[i].enclen) || + memcmp(pbData,cTestData[i].decstr,cTestData[i].enclen)) + { + printBytes("expected",cTestData[i].decstr,cTestData[i].strlen); + printBytes("got",pbData,dwLen); + } } result = CryptDestroyKey(hKey); ok(result, "%08x\n", GetLastError()); @@ -927,7 +1035,7 @@ static void test_aes(int keylen) HCRYPTKEY hKey; BOOL result; DWORD dwLen; - unsigned char pbData[16]; + unsigned char pbData[16], enc_data[16], bad_data[16]; int i; switch (keylen) @@ -969,7 +1077,43 @@ static void test_aes(int keylen) result = CryptEncrypt(hKey, 0, TRUE, 0, pbData, &dwLen, cTestData[i].buflen); ok(result, "%08x\n", GetLastError()); ok(dwLen==cTestData[i].buflen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].buflen); + memcpy(enc_data, pbData, cTestData[i].buflen); + + result = CryptDecrypt(hKey, 0, TRUE, 0, pbData, &dwLen); + ok(result, "%08x\n", GetLastError()); + ok(dwLen==cTestData[i].enclen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].enclen); + ok(memcmp(pbData,cTestData[i].decstr,cTestData[1].enclen)==0,"decryption incorrect %d\n",i); + if((dwLen != cTestData[i].enclen) || + memcmp(pbData,cTestData[i].decstr,cTestData[i].enclen)) + { + printBytes("expected",cTestData[i].decstr,cTestData[i].strlen); + printBytes("got",pbData,dwLen); + } + + /* Test bad data: + Decrypting a block of bad data with Final = TRUE should restore the + initial state of the key as well as decrypting a block of good data. + */ + + /* Changing key state by setting Final = FALSE */ + dwLen = cTestData[i].buflen; + memcpy(pbData, enc_data, cTestData[i].buflen); + result = CryptDecrypt(hKey, 0, FALSE, 0, pbData, &dwLen); + ok(result, "%08x\n", GetLastError()); + + /* Restoring key state by decrypting bad_data with Final = TRUE */ + memcpy(bad_data, enc_data, cTestData[i].buflen); + bad_data[cTestData[i].buflen - 1] = ~bad_data[cTestData[i].buflen - 1]; + SetLastError(0xdeadbeef); + result = CryptDecrypt(hKey, 0, TRUE, 0, bad_data, &dwLen); + ok(!result, "CryptDecrypt should failed!\n"); + ok(GetLastError() == NTE_BAD_DATA, "%08x\n", GetLastError()); + ok(dwLen==cTestData[i].buflen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].buflen); + ok(memcmp(pbData,cTestData[i].decstr,cTestData[1].enclen)==0,"decryption incorrect %d\n",i); + /* Checking key state */ + dwLen = cTestData[i].buflen; + memcpy(pbData, enc_data, cTestData[i].buflen); result = CryptDecrypt(hKey, 0, TRUE, 0, pbData, &dwLen); ok(result, "%08x\n", GetLastError()); ok(dwLen==cTestData[i].enclen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].enclen); diff --git a/rostests/winetests/rsaenh/testlist.c b/rostests/winetests/rsaenh/testlist.c index 0c1563415d0..748ba835b22 100644 --- a/rostests/winetests/rsaenh/testlist.c +++ b/rostests/winetests/rsaenh/testlist.c @@ -1,10 +1,7 @@ /* Automatically generated file; DO NOT EDIT!! */ -#define WIN32_LEAN_AND_MEAN -#include - #define STANDALONE -#include "wine/test.h" +#include extern void func_rsaenh(void); -- 2.17.1