diff --git a/rostests/winetests/rsaenh/rsaenh.c b/rostests/winetests/rsaenh/rsaenh.c index babc43540a8..5192c2f9afc 100644 --- a/rostests/winetests/rsaenh/rsaenh.c +++ b/rostests/winetests/rsaenh/rsaenh.c @@ -30,8 +30,14 @@ #include "winreg.h" static HCRYPTPROV hProv; +static const char *szProviders[] = {MS_ENHANCED_PROV_A, MS_DEF_PROV_A, MS_STRONG_PROV_A}; +static int iProv; static const char szContainer[] = "winetest"; -static const char szProvider[] = MS_ENHANCED_PROV_A; +static const char *szProvider; + +#define ENHANCED_PROV (iProv == 0) +#define BASE_PROV (iProv == 1) +#define STRONG_PROV (iProv == 2) typedef struct _ctdatatype { unsigned char origstr[32]; @@ -56,6 +62,8 @@ static const cryptdata cTestData[4] = { 12,12,16} }; +static int win2k; + /* * 1. Take the MD5 Hash of the container name (with an extra null byte) * 2. Turn the hash into a 4 DWORD hex value @@ -80,10 +88,12 @@ static void uniquecontainer(char *unique) { /* Windows 2000 can't handle KEY_WOW64_64KEY */ RegOpenKeyA(HKEY_LOCAL_MACHINE, szCryptography, &hkey); + win2k++; } RegQueryValueExA(hkey, szMachineGuid, NULL, NULL, (LPBYTE)guid, &size); RegCloseKey(hkey); + if (!unique) return; lstrcpyA(unique, szContainer_md5); lstrcatA(unique, "_"); lstrcatA(unique, guid); @@ -118,10 +128,12 @@ static void trace_hex(BYTE *pbData, DWORD dwLen) { } */ -static BOOL init_base_environment(DWORD dwKeyFlags) +static BOOL init_base_environment(const char *provider, DWORD dwKeyFlags) { HCRYPTKEY hKey; BOOL result; + + if (provider) szProvider = provider; pCryptDuplicateHash = (void *)GetProcAddress(GetModuleHandleA("advapi32.dll"), "CryptDuplicateHash"); @@ -414,7 +426,7 @@ static void test_hashes(void) BYTE pbHashValue[36]; BYTE pbSigValue[128]; HCRYPTKEY hKeyExchangeKey; - DWORD hashlen, len, error; + DWORD hashlen, len, error, cryptflags; int i; for (i=0; i<2048; i++) pbData[i] = (unsigned char)i; @@ -449,7 +461,14 @@ static void test_hashes(void) result = CryptHashData(hHash, pbData, sizeof(pbData), ~0); ok(!result && GetLastError() == NTE_BAD_FLAGS, "%08x\n", GetLastError()); - result = CryptHashData(hHash, pbData, sizeof(pbData), CRYPT_USERDATA); + cryptflags = CRYPT_USERDATA; + result = CryptHashData(hHash, pbData, sizeof(pbData), cryptflags); + if (!result && GetLastError() == NTE_BAD_FLAGS) /* <= NT4 */ + { + cryptflags &= ~CRYPT_USERDATA; + ok(broken(1), "Failed to support CRYPT_USERDATA flag\n"); + result = CryptHashData(hHash, pbData, sizeof(pbData), 0); + } ok(result, "%08x\n", GetLastError()); len = sizeof(DWORD); @@ -476,7 +495,7 @@ static void test_hashes(void) result = CryptHashData(hHash, pbData, sizeof(pbData), ~0); ok(!result && GetLastError() == NTE_BAD_FLAGS, "%08x\n", GetLastError()); - result = CryptHashData(hHash, pbData, sizeof(pbData), CRYPT_USERDATA); + result = CryptHashData(hHash, pbData, sizeof(pbData), cryptflags); ok(result, "%08x\n", GetLastError()); len = 16; @@ -525,7 +544,7 @@ static void test_hashes(void) result = CryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash); ok(result, "%08x\n", GetLastError()); - result = CryptHashData(hHash, pbData, 5, CRYPT_USERDATA); + result = CryptHashData(hHash, pbData, 5, cryptflags); ok(result, "%08x\n", GetLastError()); if(pCryptDuplicateHash) { @@ -649,7 +668,8 @@ static void test_hashes(void) ok(result, "CryptCreateHash failed 0x%08x\n", GetLastError()); /* Test that CryptHashData fails on this hash */ result = CryptHashData(hHash, pbData, sizeof(pbData), 0); - ok(!result && GetLastError() == NTE_BAD_ALGID, "%08x\n", GetLastError()); + ok(!result && (GetLastError() == NTE_BAD_ALGID || broken(GetLastError() == ERROR_INVALID_HANDLE)) /* Win 8 */, + "%08x\n", GetLastError()); result = CryptSetHashParam(hHash, HP_HASHVAL, pbHashValue, 0); ok(result, "%08x\n", GetLastError()); len = (DWORD)sizeof(abPlainPrivateKey); @@ -700,6 +720,13 @@ static void test_block_cipher_modes(void) memcpy(abData, plain, sizeof(plain)); + /* test default chaining mode */ + dwMode = 0xdeadbeef; + dwLen = sizeof(dwMode); + result = CryptGetKeyParam(hKey, KP_MODE, (BYTE*)&dwMode, &dwLen, 0); + ok(result, "%08x\n", GetLastError()); + ok(dwMode == CRYPT_MODE_CBC, "Wrong default chaining mode\n"); + dwMode = CRYPT_MODE_ECB; result = CryptSetKeyParam(hKey, KP_MODE, (BYTE*)&dwMode, 0); ok(result, "%08x\n", GetLastError()); @@ -765,11 +792,18 @@ static void test_block_cipher_modes(void) dwMode = CRYPT_MODE_OFB; result = CryptSetKeyParam(hKey, KP_MODE, (BYTE*)&dwMode, 0); - ok(result, "%08x\n", GetLastError()); - - dwLen = 23; - result = CryptEncrypt(hKey, 0, TRUE, 0, abData, &dwLen, 24); - ok(!result && GetLastError() == NTE_BAD_ALGID, "%08x\n", GetLastError()); + if(!result && GetLastError() == ERROR_INTERNAL_ERROR) + { + ok(broken(1), "OFB mode not supported\n"); /* Windows 8 */ + } + else + { + ok(result, "%08x\n", GetLastError()); + + dwLen = 23; + result = CryptEncrypt(hKey, 0, TRUE, 0, abData, &dwLen, 24); + ok(!result && GetLastError() == NTE_BAD_ALGID, "%08x\n", GetLastError()); + } CryptDestroyKey(hKey); } @@ -780,6 +814,9 @@ static void test_3des112(void) BOOL result; DWORD dwLen; unsigned char pbData[16], enc_data[16], bad_data[16]; + static const BYTE des112[16] = { + 0x8e, 0x0c, 0x3c, 0xa3, 0x05, 0x88, 0x5f, 0x7a, + 0x32, 0xa1, 0x06, 0x52, 0x64, 0xd2, 0x44, 0x1c }; int i; result = derive_key(CALG_3DES_112, &hKey, 0); @@ -795,6 +832,8 @@ static void test_3des112(void) result = CryptEncrypt(hKey, 0, TRUE, 0, pbData, &dwLen, 16); ok(result, "%08x\n", GetLastError()); + ok(!memcmp(pbData, des112, sizeof(des112)), "3DES_112 encryption failed!\n"); + result = CryptDecrypt(hKey, 0, TRUE, 0, pbData, &dwLen); ok(result, "%08x\n", GetLastError()); @@ -864,9 +903,18 @@ static void test_des(void) BOOL result; DWORD dwLen, dwMode; unsigned char pbData[16], enc_data[16], bad_data[16]; + static const BYTE des[16] = { + 0x58, 0x86, 0x42, 0x46, 0x65, 0x4b, 0x92, 0x62, + 0xcf, 0x0f, 0x65, 0x37, 0x43, 0x7a, 0x82, 0xb9 }; + static const BYTE des_old_behavior[16] = { + 0xb0, 0xfd, 0x11, 0x69, 0x76, 0xb1, 0xa1, 0x03, + 0xf7, 0xbc, 0x23, 0xaa, 0xd4, 0xc1, 0xc9, 0x55 }; + static const BYTE des_old_strong[16] = { + 0x9b, 0xc1, 0x2a, 0xec, 0x4a, 0xf9, 0x0f, 0x14, + 0x0a, 0xed, 0xf6, 0xd3, 0xdc, 0xad, 0xf7, 0x0c }; int i; - result = derive_key(CALG_DES, &hKey, 56); + result = derive_key(CALG_DES, &hKey, 0); if (!result) { /* rsaenh compiled without OpenSSL */ ok(GetLastError()==NTE_BAD_ALGID, "%08x\n", GetLastError()); @@ -880,6 +928,7 @@ static void test_des(void) dwLen = sizeof(DWORD); result = CryptGetKeyParam(hKey, KP_MODE, (BYTE*)&dwMode, &dwLen, 0); ok(result, "%08x\n", GetLastError()); + ok(dwMode == CRYPT_MODE_ECB, "Expected CRYPT_MODE_ECB, got %d\n", dwMode); for (i=0; i= XP changed the way DES keys are derived, this test ensures we don't break that */ + derive_key(CALG_DES, &hKey, 56); + + dwMode = CRYPT_MODE_ECB; + result = CryptSetKeyParam(hKey, KP_MODE, (BYTE*)&dwMode, 0); + ok(result, "%08x\n", GetLastError()); + + for (i=0; i= XP some tests need to be skipped */ + int old_broken[sizeof(tests)/sizeof(tests[0])]; + memset(old_broken, 0, sizeof(old_broken)); + old_broken[3] = old_broken[4] = old_broken[15] = old_broken[16] = 1; + old_broken[27] = old_broken[28] = old_broken[39] = old_broken[40] = 1; + uniquecontainer(NULL); + + for (i=0; i