rsaenh: CALG_AES cannot be used if the key length was not specified.

This commit is contained in:
Bruno Jesus 2014-07-23 00:48:51 -03:00 committed by Alexandre Julliard
parent 453d6dc105
commit f5c687e365
2 changed files with 9 additions and 18 deletions

View File

@ -780,7 +780,7 @@ static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTK
{ {
HCRYPTKEY hCryptKey; HCRYPTKEY hCryptKey;
CRYPTKEY *pCryptKey; CRYPTKEY *pCryptKey;
DWORD dwKeyLen = HIWORD(dwFlags); DWORD dwKeyLen = HIWORD(dwFlags), bKeyLen = dwKeyLen;
const PROV_ENUMALGS_EX *peaAlgidInfo; const PROV_ENUMALGS_EX *peaAlgidInfo;
*ppCryptKey = NULL; *ppCryptKey = NULL;
@ -839,6 +839,14 @@ static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTK
*/ */
break; break;
case CALG_AES:
if (!bKeyLen)
{
TRACE("missing key len for CALG_AES\n");
SetLastError(NTE_BAD_ALGID);
return (HCRYPTKEY)INVALID_HANDLE_VALUE;
}
/* fall through */
default: default:
if (dwKeyLen % 8 || if (dwKeyLen % 8 ||
dwKeyLen > peaAlgidInfo->dwMaxLen || dwKeyLen > peaAlgidInfo->dwMaxLen ||

View File

@ -3511,13 +3511,6 @@ static void test_key_derivation(const char *prov)
/* 47 */ /* 47 */
}, },
}; };
/* Temporary struct to hold wine broken cases */
struct broken
{
int mode, exp_data, blen;
} wine_broken[sizeof(tests)/sizeof(tests[0])];
/* Due to differences between encryption from <= 2000 and >= XP some tests need to be skipped */ /* Due to differences between encryption from <= 2000 and >= XP some tests need to be skipped */
int old_broken[sizeof(tests)/sizeof(tests[0])]; int old_broken[sizeof(tests)/sizeof(tests[0])];
memset(old_broken, 0, sizeof(old_broken)); memset(old_broken, 0, sizeof(old_broken));
@ -3525,10 +3518,6 @@ static void test_key_derivation(const char *prov)
old_broken[27] = old_broken[28] = old_broken[39] = old_broken[40] = 1; old_broken[27] = old_broken[28] = old_broken[39] = old_broken[40] = 1;
uniquecontainer(NULL); uniquecontainer(NULL);
memset(wine_broken, 0, sizeof(wine_broken));
wine_broken[8].mode = wine_broken[8].blen = 1;
wine_broken[20] = wine_broken[32] = wine_broken[44] = wine_broken[8];
for (i=0; i<sizeof(tests)/sizeof(tests[0]); i++) for (i=0; i<sizeof(tests)/sizeof(tests[0]); i++)
{ {
if (win2k && old_broken[i]) continue; if (win2k && old_broken[i]) continue;
@ -3567,23 +3556,17 @@ static void test_key_derivation(const char *prov)
mode = 0xdeadbeef; mode = 0xdeadbeef;
result = CryptGetKeyParam(hKey, KP_MODE, (BYTE*)&mode, &len, 0); result = CryptGetKeyParam(hKey, KP_MODE, (BYTE*)&mode, &len, 0);
ok(result, "Test [%s %d]: CryptGetKeyParam failed with error %08x\n", prov, i, GetLastError()); ok(result, "Test [%s %d]: CryptGetKeyParam failed with error %08x\n", prov, i, GetLastError());
if (wine_broken[i].mode) winetest_start_todo("wine");
ok(mode == tests[i].chain_mode, "Test [%s %d]: Expected chaining mode %d, got %d\n", ok(mode == tests[i].chain_mode, "Test [%s %d]: Expected chaining mode %d, got %d\n",
prov, i, tests[i].chain_mode, mode); prov, i, tests[i].chain_mode, mode);
if (wine_broken[i].mode) winetest_end_todo("wine");
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
len = 4; len = 4;
result = CryptEncrypt(hKey, 0, TRUE, 0, dvData, &len, sizeof(dvData)); result = CryptEncrypt(hKey, 0, TRUE, 0, dvData, &len, sizeof(dvData));
ok(result, "Test [%s %d]: CryptEncrypt failed with error 0x%08x\n", prov, i, GetLastError()); ok(result, "Test [%s %d]: CryptEncrypt failed with error 0x%08x\n", prov, i, GetLastError());
if (wine_broken[i].blen) winetest_start_todo("wine");
ok(len == tests[i].blocklen, "Test [%s %d]: Expected block len %d, got %d\n", ok(len == tests[i].blocklen, "Test [%s %d]: Expected block len %d, got %d\n",
prov, i, tests[i].blocklen, len); prov, i, tests[i].blocklen, len);
if (wine_broken[i].blen) winetest_end_todo("wine");
if (wine_broken[i].exp_data) winetest_start_todo("wine");
ok(!memcmp(dvData, tests[i].expected_enc, tests[i].blocklen), ok(!memcmp(dvData, tests[i].expected_enc, tests[i].blocklen),
"Test [%s %d]: Encrypted data comparison failed\n", prov, i); "Test [%s %d]: Encrypted data comparison failed\n", prov, i);
if (wine_broken[i].exp_data) winetest_end_todo("wine");
CryptDestroyKey(hKey); CryptDestroyKey(hKey);
err: err: