ntdll: Add support for Win 10.
[wine/multimedia.git] / dlls / crypt32 / main.c
blob241a1d96620cda32eadc3d378ba3d88bd55d2d83
1 /*
2 * Copyright 2002 Mike McCormack for CodeWeavers
3 * Copyright 2005 Juan Lang
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wincrypt.h"
27 #include "winreg.h"
28 #include "winuser.h"
29 #include "i_cryptasn1tls.h"
30 #include "crypt32_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
35 static HCRYPTPROV hDefProv;
36 HINSTANCE hInstance;
38 BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, PVOID pvReserved)
40 switch (fdwReason)
42 case DLL_PROCESS_ATTACH:
43 hInstance = hInst;
44 DisableThreadLibraryCalls(hInst);
45 init_empty_store();
46 crypt_oid_init();
47 break;
48 case DLL_PROCESS_DETACH:
49 if (pvReserved) break;
50 crypt_oid_free();
51 crypt_sip_free();
52 root_store_free();
53 default_chain_engine_free();
54 if (hDefProv) CryptReleaseContext(hDefProv, 0);
55 break;
57 return TRUE;
60 HCRYPTPROV CRYPT_GetDefaultProvider(void)
62 if (!hDefProv)
64 HCRYPTPROV prov;
66 if (!CryptAcquireContextW(&prov, NULL, MS_ENH_RSA_AES_PROV_W,
67 PROV_RSA_AES, CRYPT_VERIFYCONTEXT))
68 return hDefProv;
69 InterlockedCompareExchangePointer((PVOID *)&hDefProv, (PVOID)prov,
70 NULL);
71 if (hDefProv != prov)
72 CryptReleaseContext(prov, 0);
74 return hDefProv;
77 typedef void * HLRUCACHE;
79 /* this function is called by Internet Explorer when it is about to verify a
80 * downloaded component. The first parameter appears to be a pointer to an
81 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
82 * The second parameter appears to be an out parameter, whatever it's set to is
83 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
85 BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
87 FIXME("(%p, %p): stub!\n", unknown, out);
88 *out = (void *)0xbaadf00d;
89 return TRUE;
92 BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
94 FIXME("(%08x, %08x): stub!\n", unk0, unk1);
95 return FALSE;
98 BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
100 FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
101 return FALSE;
104 BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
106 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
107 return FALSE;
110 DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
112 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
113 return 0;
116 HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
118 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
119 return h;
122 LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
124 return HeapAlloc(GetProcessHeap(), 0, cbSize);
127 LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
129 return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
132 VOID WINAPI CryptMemFree(LPVOID pv)
134 HeapFree(GetProcessHeap(), 0, pv);
137 DWORD WINAPI I_CryptAllocTls(void)
139 return TlsAlloc();
142 LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
144 LPVOID ret;
146 ret = TlsGetValue(dwTlsIndex);
147 TlsSetValue(dwTlsIndex, NULL);
148 return ret;
151 LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
153 return TlsGetValue(dwTlsIndex);
156 BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
158 return TlsSetValue(dwTlsIndex, lpTlsValue);
161 BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
163 BOOL ret;
165 TRACE("(%d, %d)\n", dwTlsIndex, unknown);
167 ret = TlsFree(dwTlsIndex);
168 if (!ret) SetLastError( E_INVALIDARG );
169 return ret;
172 BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
174 FIXME("%08x\n", x);
175 return FALSE;
178 HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(DWORD reserved)
180 HCRYPTPROV ret;
182 TRACE("(%08x)\n", reserved);
184 if (reserved)
186 SetLastError(E_INVALIDARG);
187 return 0;
189 ret = CRYPT_GetDefaultProvider();
190 CryptContextAddRef(ret, NULL, 0);
191 return ret;
194 BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
195 DWORD *value)
197 static const WCHAR safer[] = {
198 'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
199 'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
200 'C','e','r','t','i','f','i','c','a','t','e','s','\\',
201 'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
202 'S','a','f','e','r',0 };
203 HKEY key;
204 LONG rc;
205 BOOL ret = FALSE;
207 TRACE("(%s, %p)\n", debugstr_w(name), value);
209 *value = 0;
210 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key);
211 if (rc == ERROR_SUCCESS)
213 DWORD size = sizeof(DWORD);
215 if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
216 ret = TRUE;
217 RegCloseKey(key);
219 return ret;
222 DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
224 static int ret = 8;
225 ret++;
226 FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
227 return ret;
230 BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void* z)
232 FIXME("(%p %08x %p): stub\n", x, y, z);
233 return TRUE;
236 BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
238 FIXME("(%08x): stub\n", x);
239 return TRUE;
242 ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
244 FIXME("(%08x): stub\n", x);
245 return NULL;
248 ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
250 FIXME("(%08x): stub\n", x);
251 return NULL;
254 BOOL WINAPI CryptProtectMemory(void *data, DWORD len, DWORD flags)
256 FIXME("(%p %u %08x): stub\n", data, len, flags);
257 return TRUE;
260 BOOL WINAPI CryptUnprotectMemory(void *data, DWORD len, DWORD flags)
262 FIXME("(%p %u %08x): stub\n", data, len, flags);
263 return TRUE;