Commit c534fa1e authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

Implement CryptMem and undocumented I_Crypt*Tls functions, with tests.

parent 473cac84
...@@ -120,9 +120,9 @@ ...@@ -120,9 +120,9 @@
@ stdcall CryptInitOIDFunctionSet(str long) @ stdcall CryptInitOIDFunctionSet(str long)
@ stub CryptInstallOIDFunctionAddress @ stub CryptInstallOIDFunctionAddress
@ stub CryptLoadSip @ stub CryptLoadSip
@ stub CryptMemAlloc @ stdcall CryptMemAlloc(long)
@ stub CryptMemFree @ stdcall CryptMemFree(ptr)
@ stub CryptMemRealloc @ stdcall CryptMemRealloc(ptr long)
@ stub CryptMsgCalculateEncodedLength @ stub CryptMsgCalculateEncodedLength
@ stub CryptMsgClose @ stub CryptMsgClose
@ stub CryptMsgControl @ stub CryptMsgControl
...@@ -164,21 +164,22 @@ ...@@ -164,21 +164,22 @@
@ stub CryptVerifyMessageSignature @ stub CryptVerifyMessageSignature
@ stub CryptVerifyMessageSignatureWithKey @ stub CryptVerifyMessageSignatureWithKey
@ stub CryptVerifySignatureU @ stub CryptVerifySignatureU
@ stub I_CryptAllocTls @ stdcall I_CryptAllocTls()
@ stdcall I_CryptCreateLruCache(long long) @ stdcall I_CryptCreateLruCache(long long)
@ stub I_CryptCreateLruEntry @ stub I_CryptCreateLruEntry
@ stub I_CryptDetachTls @ stdcall I_CryptDetachTls(long)
@ stdcall I_CryptFindLruEntryData(long) @ stdcall I_CryptFindLruEntryData(long)
@ stdcall I_CryptFlushLruCache(long) @ stdcall I_CryptFlushLruCache(long)
@ stdcall I_CryptFreeLruCache(long) @ stdcall I_CryptFreeLruCache(long)
@ stdcall I_CryptFreeTls(long long)
@ stub I_CryptGetDefaultCryptProv @ stub I_CryptGetDefaultCryptProv
@ stub I_CryptGetDefaultCryptProvForEncrypt @ stub I_CryptGetDefaultCryptProvForEncrypt
@ stub I_CryptGetOssGlobal @ stub I_CryptGetOssGlobal
@ stub I_CryptGetTls @ stdcall I_CryptGetTls(long)
@ stub I_CryptInsertLruEntry @ stub I_CryptInsertLruEntry
@ stub I_CryptInstallOssGlobal @ stub I_CryptInstallOssGlobal
@ stub I_CryptReleaseLruEntry @ stub I_CryptReleaseLruEntry
@ stub I_CryptSetTls @ stdcall I_CryptSetTls(long ptr)
@ stub I_CryptUninstallOssGlobal @ stub I_CryptUninstallOssGlobal
@ stub PFXExportCertStore @ stub PFXExportCertStore
@ stub PFXImportCertStore @ stub PFXImportCertStore
......
...@@ -304,3 +304,48 @@ DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId) ...@@ -304,3 +304,48 @@ DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
} }
return 0; return 0;
} }
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
{
return HeapAlloc(GetProcessHeap(), 0, cbSize);
}
LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
{
return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
}
VOID WINAPI CryptMemFree(LPVOID pv)
{
HeapFree(GetProcessHeap(), 0, pv);
}
DWORD WINAPI I_CryptAllocTls(void)
{
return TlsAlloc();
}
LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
{
LPVOID ret;
ret = TlsGetValue(dwTlsIndex);
TlsSetValue(dwTlsIndex, NULL);
return ret;
}
LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
{
return TlsGetValue(dwTlsIndex);
}
BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
{
return TlsSetValue(dwTlsIndex, lpTlsValue);
}
BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
{
TRACE("(%ld, %ld)\n", dwTlsIndex, unknown);
return TlsFree(dwTlsIndex);
}
...@@ -274,6 +274,102 @@ static void test_verifyTimeValidity(void) ...@@ -274,6 +274,102 @@ static void test_verifyTimeValidity(void)
ok(ret == -1, "Expected -1, got %ld\n", ret); ok(ret == -1, "Expected -1, got %ld\n", ret);
} }
static void test_cryptAllocate(void)
{
LPVOID buf;
buf = CryptMemAlloc(0);
ok(buf != NULL, "CryptMemAlloc failed: %08lx\n", GetLastError());
CryptMemFree(buf);
buf = CryptMemRealloc(NULL, 0);
ok(!buf, "Expected NULL\n");
buf = CryptMemAlloc(0);
buf = CryptMemRealloc(buf, 1);
ok(buf != NULL, "CryptMemRealloc failed: %08lx\n", GetLastError());
CryptMemFree(buf);
}
typedef DWORD (WINAPI *I_CryptAllocTlsFunc)(void);
typedef LPVOID (WINAPI *I_CryptDetachTlsFunc)(DWORD dwTlsIndex);
typedef LPVOID (WINAPI *I_CryptGetTlsFunc)(DWORD dwTlsIndex);
typedef BOOL (WINAPI *I_CryptSetTlsFunc)(DWORD dwTlsIndex, LPVOID lpTlsValue);
typedef BOOL (WINAPI *I_CryptFreeTlsFunc)(DWORD dwTlsIndex, DWORD unknown);
static I_CryptAllocTlsFunc pI_CryptAllocTls;
static I_CryptDetachTlsFunc pI_CryptDetachTls;
static I_CryptGetTlsFunc pI_CryptGetTls;
static I_CryptSetTlsFunc pI_CryptSetTls;
static I_CryptFreeTlsFunc pI_CryptFreeTls;
static void test_cryptTls(void)
{
HMODULE lib = LoadLibraryA("crypt32.dll");
if (lib)
{
DWORD index;
BOOL ret;
pI_CryptAllocTls = (I_CryptAllocTlsFunc)GetProcAddress(lib,
"I_CryptAllocTls");
pI_CryptDetachTls = (I_CryptDetachTlsFunc)GetProcAddress(lib,
"I_CryptDetachTls");
pI_CryptGetTls = (I_CryptGetTlsFunc)GetProcAddress(lib,
"I_CryptGetTls");
pI_CryptSetTls = (I_CryptSetTlsFunc)GetProcAddress(lib,
"I_CryptSetTls");
pI_CryptFreeTls = (I_CryptFreeTlsFunc)GetProcAddress(lib,
"I_CryptFreeTls");
/* One normal pass */
index = pI_CryptAllocTls();
ok(index, "I_CryptAllocTls failed: %08lx\n", GetLastError());
if (index)
{
LPVOID ptr;
ptr = pI_CryptGetTls(index);
ok(!ptr, "Expected NULL\n");
ret = pI_CryptSetTls(index, (LPVOID)0xdeadbeef);
ok(ret, "I_CryptSetTls failed: %08lx\n", GetLastError());
ptr = pI_CryptGetTls(index);
ok(ptr == (LPVOID)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", ptr);
/* This crashes
ret = pI_CryptFreeTls(index, 1);
*/
ret = pI_CryptFreeTls(index, 0);
ok(ret, "I_CryptFreeTls failed: %08lx\n", GetLastError());
ret = pI_CryptFreeTls(index, 0);
/* Not sure if this fails because TlsFree should fail, so leave as
* todo for now.
*/
todo_wine ok(!ret && GetLastError() ==
HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
"Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %08lx\n",
GetLastError());
}
/* Similar pass, check I_CryptDetachTls */
index = pI_CryptAllocTls();
ok(index, "I_CryptAllocTls failed: %08lx\n", GetLastError());
if (index)
{
LPVOID ptr;
ptr = pI_CryptGetTls(index);
ok(!ptr, "Expected NULL\n");
ret = pI_CryptSetTls(index, (LPVOID)0xdeadbeef);
ok(ret, "I_CryptSetTls failed: %08lx\n", GetLastError());
ptr = pI_CryptGetTls(index);
ok(ptr == (LPVOID)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", ptr);
ptr = pI_CryptDetachTls(index);
ok(ptr == (LPVOID)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", ptr);
ptr = pI_CryptGetTls(index);
ok(!ptr, "Expected NULL\n");
}
FreeLibrary(lib);
}
}
START_TEST(main) START_TEST(main)
{ {
testOIDToAlgID(); testOIDToAlgID();
...@@ -282,4 +378,6 @@ START_TEST(main) ...@@ -282,4 +378,6 @@ START_TEST(main)
test_findExtension(); test_findExtension();
test_findRDNAttr(); test_findRDNAttr();
test_verifyTimeValidity(); test_verifyTimeValidity();
test_cryptAllocate();
test_cryptTls();
} }
...@@ -2273,6 +2273,10 @@ BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, BYTE *pbSignature, DWORD dw ...@@ -2273,6 +2273,10 @@ BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, BYTE *pbSignature, DWORD dw
#define CryptVerifySignature WINELIB_NAME_AW(CryptVerifySignature) #define CryptVerifySignature WINELIB_NAME_AW(CryptVerifySignature)
/* crypt32.dll functions */ /* crypt32.dll functions */
LPVOID WINAPI CryptMemAlloc(ULONG cbSize);
LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize);
VOID WINAPI CryptMemFree(LPVOID pv);
BOOL WINAPI CryptRegisterOIDFunction(DWORD,LPCSTR,LPCSTR,LPCWSTR,LPCSTR); BOOL WINAPI CryptRegisterOIDFunction(DWORD,LPCSTR,LPCSTR,LPCWSTR,LPCSTR);
BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName, BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
LPCSTR pszOID, LPCWSTR szValueName, DWORD *pdwValueType, LPCSTR pszOID, LPCWSTR szValueName, DWORD *pdwValueType,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment