1 | /*
|
---|
2 | * Copyright 1999 Ian Schmidt
|
---|
3 | * Copyright 2001 Travis Michielsen
|
---|
4 | *
|
---|
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.
|
---|
9 | *
|
---|
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.
|
---|
14 | *
|
---|
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
|
---|
18 | */
|
---|
19 |
|
---|
20 | /***********************************************************************
|
---|
21 | *
|
---|
22 | * TODO:
|
---|
23 | * - Reference counting
|
---|
24 | * - Thread-safing
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include <os2win.h>
|
---|
28 | #include <stdlib.h>
|
---|
29 | #include <stdarg.h>
|
---|
30 | #include <string.h>
|
---|
31 | #include <odinwrap.h>
|
---|
32 | #include <misc.h>
|
---|
33 | #include "wincrypt.h"
|
---|
34 |
|
---|
35 | ODINDEBUGCHANNEL(ADVAPI32-CRYPT)
|
---|
36 |
|
---|
37 | #include "config.h"
|
---|
38 | #include "wine/port.h"
|
---|
39 |
|
---|
40 | #include <time.h>
|
---|
41 | //#include <stdlib.h>
|
---|
42 | #include <stdio.h>
|
---|
43 | //#include <sys/types.h>
|
---|
44 | #ifdef HAVE_SYS_STAT_H
|
---|
45 | # include <sys/stat.h>
|
---|
46 | #endif
|
---|
47 | #include <fcntl.h>
|
---|
48 | #ifdef HAVE_UNISTD_H
|
---|
49 | # include <unistd.h>
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | #include "ntstatus.h"
|
---|
53 | #define WIN32_NO_STATUS
|
---|
54 | #include "crypt.h"
|
---|
55 | #include "winnls.h"
|
---|
56 | #include "winreg.h"
|
---|
57 | #include "rpc.h"
|
---|
58 | #include "debugtools.h"
|
---|
59 | #include "wine/unicode.h"
|
---|
60 | //#include "winternl.h"
|
---|
61 |
|
---|
62 | static HWND crypt_hWindow;
|
---|
63 |
|
---|
64 | #define CRYPT_Alloc(size) (LocalAlloc(LMEM_ZEROINIT, size))
|
---|
65 | #define CRYPT_Free(buffer) (LocalFree((HLOCAL)buffer))
|
---|
66 |
|
---|
67 | static inline PWSTR CRYPT_GetProvKeyName(PCWSTR pProvName)
|
---|
68 | {
|
---|
69 | static const WCHAR KEYSTR[] = {
|
---|
70 | 'S','o','f','t','w','a','r','e','\\',
|
---|
71 | 'M','i','c','r','o','s','o','f','t','\\',
|
---|
72 | 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
---|
73 | 'D','e','f','a','u','l','t','s','\\',
|
---|
74 | 'P','r','o','v','i','d','e','r','\\',0
|
---|
75 | };
|
---|
76 | PWSTR keyname;
|
---|
77 |
|
---|
78 | keyname = (PWSTR)CRYPT_Alloc((strlenW(KEYSTR) + strlenW(pProvName) +1)*sizeof(WCHAR));
|
---|
79 | if (keyname)
|
---|
80 | {
|
---|
81 | strcpyW(keyname, KEYSTR);
|
---|
82 | strcpyW(keyname + strlenW(KEYSTR), pProvName);
|
---|
83 | } else
|
---|
84 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
85 | return keyname;
|
---|
86 | }
|
---|
87 |
|
---|
88 | static inline PWSTR CRYPT_GetTypeKeyName(DWORD dwType, BOOL user)
|
---|
89 | {
|
---|
90 | static const WCHAR MACHINESTR[] = {
|
---|
91 | 'S','o','f','t','w','a','r','e','\\',
|
---|
92 | 'M','i','c','r','o','s','o','f','t','\\',
|
---|
93 | 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
---|
94 | 'D','e','f','a','u','l','t','s','\\',
|
---|
95 | 'P','r','o','v','i','d','e','r',' ','T','y','p','e','s','\\',
|
---|
96 | 'T','y','p','e',' ','X','X','X',0
|
---|
97 | };
|
---|
98 | static const WCHAR USERSTR[] = {
|
---|
99 | 'S','o','f','t','w','a','r','e','\\',
|
---|
100 | 'M','i','c','r','o','s','o','f','t','\\',
|
---|
101 | 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
---|
102 | 'P','r','o','v','i','d','e','r',' ','T','y','p','e',' ','X','X','X',0
|
---|
103 | };
|
---|
104 | PWSTR keyname;
|
---|
105 | PWSTR ptr;
|
---|
106 |
|
---|
107 | keyname = (PWSTR)CRYPT_Alloc( ((user ? strlenW(USERSTR) : strlenW(MACHINESTR)) +1)*sizeof(WCHAR));
|
---|
108 | if (keyname)
|
---|
109 | {
|
---|
110 | user ? strcpyW(keyname, USERSTR) : strcpyW(keyname, MACHINESTR);
|
---|
111 | ptr = keyname + strlenW(keyname);
|
---|
112 | *(--ptr) = (dwType % 10) + '0';
|
---|
113 | *(--ptr) = ((dwType / 10) % 10) + '0';
|
---|
114 | *(--ptr) = (dwType / 100) + '0';
|
---|
115 | } else
|
---|
116 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
117 | return keyname;
|
---|
118 | }
|
---|
119 |
|
---|
120 | /* CRYPT_UnicodeTOANSI
|
---|
121 | * wstr - unicode string
|
---|
122 | * str - pointer to ANSI string
|
---|
123 | * strsize - size of buffer pointed to by str or -1 if we have to do the allocation
|
---|
124 | *
|
---|
125 | * returns TRUE if unsuccessful, FALSE otherwise.
|
---|
126 | * if wstr is NULL, returns TRUE and sets str to NULL! Value of str should be checked after call
|
---|
127 | */
|
---|
128 | static inline BOOL CRYPT_UnicodeToANSI(LPCWSTR wstr, LPSTR* str, int strsize)
|
---|
129 | {
|
---|
130 | int count;
|
---|
131 |
|
---|
132 | if (!wstr)
|
---|
133 | {
|
---|
134 | *str = NULL;
|
---|
135 | return TRUE;
|
---|
136 | }
|
---|
137 | count = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
|
---|
138 | if (strsize == -1)
|
---|
139 | *str = (LPSTR)CRYPT_Alloc(count * sizeof(CHAR));
|
---|
140 | else
|
---|
141 | count = min( count, strsize );
|
---|
142 | if (*str)
|
---|
143 | {
|
---|
144 | WideCharToMultiByte(CP_ACP, 0, wstr, -1, *str, count, NULL, NULL);
|
---|
145 | return TRUE;
|
---|
146 | }
|
---|
147 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
148 | return FALSE;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /* CRYPT_ANSITOUnicode
|
---|
152 | * str - ANSI string
|
---|
153 | * wstr - pointer to unicode string
|
---|
154 | * wstrsize - size of buffer pointed to by wstr or -1 if we have to do the allocation
|
---|
155 | */
|
---|
156 | static inline BOOL CRYPT_ANSIToUnicode(LPCSTR str, LPWSTR* wstr, int wstrsize)
|
---|
157 | {
|
---|
158 | unsigned int wcount;
|
---|
159 |
|
---|
160 | if (!str)
|
---|
161 | {
|
---|
162 | *wstr = NULL;
|
---|
163 | return TRUE;
|
---|
164 | }
|
---|
165 | wcount = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
|
---|
166 | if (wstrsize == -1)
|
---|
167 | *wstr = (PWSTR)CRYPT_Alloc(wcount * sizeof(WCHAR));
|
---|
168 | else
|
---|
169 | wcount = min( wcount, wstrsize/sizeof(WCHAR) );
|
---|
170 | if (*wstr)
|
---|
171 | {
|
---|
172 | MultiByteToWideChar(CP_ACP, 0, str, -1, *wstr, wcount);
|
---|
173 | return TRUE;
|
---|
174 | }
|
---|
175 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
176 | return FALSE;
|
---|
177 | }
|
---|
178 |
|
---|
179 | /* These next 2 functions are used by the VTableProvStruc structure */
|
---|
180 | static BOOL CALLBACK CRYPT_VerifyImage(LPCSTR lpszImage, BYTE* pData)
|
---|
181 | {
|
---|
182 | if (!lpszImage || !pData)
|
---|
183 | {
|
---|
184 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
185 | return FALSE;
|
---|
186 | }
|
---|
187 |
|
---|
188 | FIXME("(%s, %p): not verifying image\n", lpszImage, pData);
|
---|
189 |
|
---|
190 | return TRUE;
|
---|
191 | }
|
---|
192 |
|
---|
193 | static BOOL CALLBACK CRYPT_ReturnhWnd(HWND *phWnd)
|
---|
194 | {
|
---|
195 | if (!phWnd)
|
---|
196 | return FALSE;
|
---|
197 | *phWnd = crypt_hWindow;
|
---|
198 | return TRUE;
|
---|
199 | }
|
---|
200 |
|
---|
201 | #define CRYPT_GetProvFunc(name) \
|
---|
202 | if ( !(provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)) ) goto error
|
---|
203 | #define CRYPT_GetProvFuncOpt(name) \
|
---|
204 | provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)
|
---|
205 | static PCRYPTPROV CRYPT_LoadProvider(PCWSTR pImage)
|
---|
206 | {
|
---|
207 | PCRYPTPROV provider;
|
---|
208 | DWORD errorcode = ERROR_NOT_ENOUGH_MEMORY;
|
---|
209 |
|
---|
210 | if ( !(provider = CRYPT_Alloc(sizeof(CRYPTPROV))) ) goto error;
|
---|
211 | if ( !(provider->pFuncs = CRYPT_Alloc(sizeof(PROVFUNCS))) ) goto error;
|
---|
212 | if ( !(provider->pVTable = CRYPT_Alloc(sizeof(VTableProvStruc))) ) goto error;
|
---|
213 | if ( !(provider->hModule = LoadLibraryW(pImage)) )
|
---|
214 | {
|
---|
215 | errorcode = (GetLastError() == ERROR_FILE_NOT_FOUND) ? NTE_PROV_DLL_NOT_FOUND : NTE_PROVIDER_DLL_FAIL;
|
---|
216 | FIXME("Failed to load dll %s\n", debugstr_w(pImage));
|
---|
217 | goto error;
|
---|
218 | }
|
---|
219 | provider->dwMagic = MAGIC_CRYPTPROV;
|
---|
220 | provider->refcount = 1;
|
---|
221 |
|
---|
222 | errorcode = NTE_PROVIDER_DLL_FAIL;
|
---|
223 | CRYPT_GetProvFunc(CPAcquireContext);
|
---|
224 | CRYPT_GetProvFunc(CPCreateHash);
|
---|
225 | CRYPT_GetProvFunc(CPDecrypt);
|
---|
226 | CRYPT_GetProvFunc(CPDeriveKey);
|
---|
227 | CRYPT_GetProvFunc(CPDestroyHash);
|
---|
228 | CRYPT_GetProvFunc(CPDestroyKey);
|
---|
229 | CRYPT_GetProvFuncOpt(CPDuplicateHash);
|
---|
230 | CRYPT_GetProvFuncOpt(CPDuplicateKey);
|
---|
231 | CRYPT_GetProvFunc(CPEncrypt);
|
---|
232 | CRYPT_GetProvFunc(CPExportKey);
|
---|
233 | CRYPT_GetProvFunc(CPGenKey);
|
---|
234 | CRYPT_GetProvFunc(CPGenRandom);
|
---|
235 | CRYPT_GetProvFunc(CPGetHashParam);
|
---|
236 | CRYPT_GetProvFunc(CPGetKeyParam);
|
---|
237 | CRYPT_GetProvFunc(CPGetProvParam);
|
---|
238 | CRYPT_GetProvFunc(CPGetUserKey);
|
---|
239 | CRYPT_GetProvFunc(CPHashData);
|
---|
240 | CRYPT_GetProvFunc(CPHashSessionKey);
|
---|
241 | CRYPT_GetProvFunc(CPImportKey);
|
---|
242 | CRYPT_GetProvFunc(CPReleaseContext);
|
---|
243 | CRYPT_GetProvFunc(CPSetHashParam);
|
---|
244 | CRYPT_GetProvFunc(CPSetKeyParam);
|
---|
245 | CRYPT_GetProvFunc(CPSetProvParam);
|
---|
246 | CRYPT_GetProvFunc(CPSignHash);
|
---|
247 | CRYPT_GetProvFunc(CPVerifySignature);
|
---|
248 |
|
---|
249 | /* FIXME: Not sure what the pbContextInfo field is for.
|
---|
250 | * Does it need memory allocation?
|
---|
251 | */
|
---|
252 | provider->pVTable->Version = 3;
|
---|
253 | provider->pVTable->pFuncVerifyImage = (FARPROC)CRYPT_VerifyImage;
|
---|
254 | provider->pVTable->pFuncReturnhWnd = (FARPROC)CRYPT_ReturnhWnd;
|
---|
255 | provider->pVTable->dwProvType = 0;
|
---|
256 | provider->pVTable->pbContextInfo = NULL;
|
---|
257 | provider->pVTable->cbContextInfo = 0;
|
---|
258 | provider->pVTable->pszProvName = NULL;
|
---|
259 | return provider;
|
---|
260 |
|
---|
261 | error:
|
---|
262 | SetLastError(errorcode);
|
---|
263 | if (provider)
|
---|
264 | {
|
---|
265 | provider->dwMagic = 0;
|
---|
266 | if (provider->hModule)
|
---|
267 | FreeLibrary(provider->hModule);
|
---|
268 | CRYPT_Free(provider->pVTable);
|
---|
269 | CRYPT_Free(provider->pFuncs);
|
---|
270 | CRYPT_Free(provider);
|
---|
271 | }
|
---|
272 | return NULL;
|
---|
273 | }
|
---|
274 | #undef CRYPT_GetProvFunc
|
---|
275 | #undef CRYPT_GetProvFuncOpt
|
---|
276 |
|
---|
277 |
|
---|
278 | static void CRYPT_CreateMachineGuid(void)
|
---|
279 | {
|
---|
280 | static const WCHAR cryptographyW[] = {
|
---|
281 | 'S','o','f','t','w','a','r','e','\\',
|
---|
282 | 'M','i','c','r','o','s','o','f','t','\\',
|
---|
283 | 'C','r','y','p','t','o','g','r','a','p','h','y',0 };
|
---|
284 | static const WCHAR machineGuidW[] = {
|
---|
285 | 'M','a','c','h','i','n','e','G','u','i','d',0 };
|
---|
286 | LONG r;
|
---|
287 | HKEY key;
|
---|
288 |
|
---|
289 | r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, cryptographyW, 0, KEY_ALL_ACCESS,
|
---|
290 | &key);
|
---|
291 | if (!r)
|
---|
292 | {
|
---|
293 | DWORD size;
|
---|
294 |
|
---|
295 | r = RegQueryValueExW(key, machineGuidW, NULL, NULL, NULL, &size);
|
---|
296 | if (r == ERROR_FILE_NOT_FOUND)
|
---|
297 | {
|
---|
298 | static const WCHAR rpcrt4[] = {
|
---|
299 | 'r','p','c','r','t','4',0 };
|
---|
300 | HMODULE lib = LoadLibraryW(rpcrt4);
|
---|
301 |
|
---|
302 | if (lib)
|
---|
303 | {
|
---|
304 | RPC_STATUS (*RPC_ENTRY pUuidCreate)(UUID *);
|
---|
305 | UUID uuid;
|
---|
306 | WCHAR buf[37];
|
---|
307 | RPC_STATUS rs;
|
---|
308 | static const WCHAR uuidFmt[] = {
|
---|
309 | '%','0','8','x','-','%','0','4','x','-',
|
---|
310 | '%','0','4','x','-','%','0','2','x',
|
---|
311 | '%','0','2','x','-','%','0','2','x',
|
---|
312 | '%','0','2','x','%','0','2','x',
|
---|
313 | '%','0','2','x','%','0','2','x',
|
---|
314 | '%','0','2','x',0 };
|
---|
315 |
|
---|
316 | pUuidCreate = GetProcAddress(lib, "UuidCreate");
|
---|
317 | rs = pUuidCreate(&uuid);
|
---|
318 | if (rs == S_OK)
|
---|
319 | {
|
---|
320 | sprintfW(buf, uuidFmt,
|
---|
321 | uuid.Data1, uuid.Data2, uuid.Data3,
|
---|
322 | uuid.Data4[0], uuid.Data4[1],
|
---|
323 | uuid.Data4[2], uuid.Data4[3],
|
---|
324 | uuid.Data4[4], uuid.Data4[5],
|
---|
325 | uuid.Data4[6], uuid.Data4[7] );
|
---|
326 | RegSetValueExW(key, machineGuidW, 0, REG_SZ,
|
---|
327 | (const BYTE *)buf,
|
---|
328 | (lstrlenW(buf)+1)*sizeof(WCHAR));
|
---|
329 | }
|
---|
330 | FreeLibrary(lib);
|
---|
331 | }
|
---|
332 | }
|
---|
333 | RegCloseKey(key);
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 | /******************************************************************************
|
---|
338 | * CryptAcquireContextW (ADVAPI32.@)
|
---|
339 | *
|
---|
340 | * Acquire a crypto provider context handle.
|
---|
341 | *
|
---|
342 | * PARAMS
|
---|
343 | * phProv [O] Pointer to HCRYPTPROV for the output.
|
---|
344 | * pszContainer [I] Key Container Name
|
---|
345 | * pszProvider [I] Cryptographic Service Provider Name
|
---|
346 | * dwProvType [I] Crypto provider type to get a handle.
|
---|
347 | * dwFlags [I] flags for the operation
|
---|
348 | *
|
---|
349 | * RETURNS
|
---|
350 | * TRUE on success, FALSE on failure.
|
---|
351 | */
|
---|
352 | BOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR pszContainer,
|
---|
353 | LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
|
---|
354 | {
|
---|
355 | PCRYPTPROV pProv = NULL;
|
---|
356 | HKEY key;
|
---|
357 | PWSTR imagepath = NULL, keyname = NULL, provname = NULL, temp = NULL;
|
---|
358 | PSTR provnameA = NULL, pszContainerA = NULL;
|
---|
359 | DWORD keytype, type, len;
|
---|
360 | ULONG r;
|
---|
361 | static const WCHAR nameW[] = {'N','a','m','e',0};
|
---|
362 | static const WCHAR typeW[] = {'T','y','p','e',0};
|
---|
363 | static const WCHAR imagepathW[] = {'I','m','a','g','e',' ','P','a','t','h',0};
|
---|
364 |
|
---|
365 | TRACE("(%p, %s, %s, %d, %08x)\n", phProv, debugstr_w(pszContainer),
|
---|
366 | debugstr_w(pszProvider), dwProvType, dwFlags);
|
---|
367 |
|
---|
368 | if (dwProvType < 1 || dwProvType > MAXPROVTYPES)
|
---|
369 | {
|
---|
370 | SetLastError(NTE_BAD_PROV_TYPE);
|
---|
371 | return FALSE;
|
---|
372 | }
|
---|
373 |
|
---|
374 | if (!phProv)
|
---|
375 | {
|
---|
376 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
377 | return FALSE;
|
---|
378 | }
|
---|
379 |
|
---|
380 | /* Make sure the MachineGuid value exists */
|
---|
381 | CRYPT_CreateMachineGuid();
|
---|
382 |
|
---|
383 | if (!pszProvider || !*pszProvider)
|
---|
384 | {
|
---|
385 | /* No CSP name specified so try the user default CSP first
|
---|
386 | * then try the machine default CSP
|
---|
387 | */
|
---|
388 | if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, TRUE)) ) {
|
---|
389 | TRACE("No provider registered for crypto provider type %d.\n", dwProvType);
|
---|
390 | SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
---|
391 | return FALSE;
|
---|
392 | }
|
---|
393 | if (RegOpenKeyW(HKEY_CURRENT_USER, keyname, &key))
|
---|
394 | {
|
---|
395 | CRYPT_Free(keyname);
|
---|
396 | if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, FALSE)) ) {
|
---|
397 | TRACE("No type registered for crypto provider type %d.\n", dwProvType);
|
---|
398 | RegCloseKey(key);
|
---|
399 | SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
---|
400 | goto error;
|
---|
401 | }
|
---|
402 | if (RegOpenKeyW(HKEY_LOCAL_MACHINE, keyname, &key)) {
|
---|
403 | TRACE("Did not find registry entry of crypto provider for %s.\n", debugstr_w(keyname));
|
---|
404 | CRYPT_Free(keyname);
|
---|
405 | RegCloseKey(key);
|
---|
406 | SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
---|
407 | goto error;
|
---|
408 | }
|
---|
409 | }
|
---|
410 | CRYPT_Free(keyname);
|
---|
411 | r = RegQueryValueExW(key, nameW, NULL, &keytype, NULL, &len);
|
---|
412 | if( r != ERROR_SUCCESS || !len || keytype != REG_SZ)
|
---|
413 | {
|
---|
414 | TRACE("error %d reading size of 'Name' from registry\n", r );
|
---|
415 | RegCloseKey(key);
|
---|
416 | SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
---|
417 | goto error;
|
---|
418 | }
|
---|
419 | if(!(provname = CRYPT_Alloc(len)))
|
---|
420 | {
|
---|
421 | RegCloseKey(key);
|
---|
422 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
423 | goto error;
|
---|
424 | }
|
---|
425 | r = RegQueryValueExW(key, nameW, NULL, NULL, (LPBYTE)provname, &len);
|
---|
426 | if( r != ERROR_SUCCESS )
|
---|
427 | {
|
---|
428 | TRACE("error %d reading 'Name' from registry\n", r );
|
---|
429 | RegCloseKey(key);
|
---|
430 | SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
---|
431 | goto error;
|
---|
432 | }
|
---|
433 | RegCloseKey(key);
|
---|
434 | } else {
|
---|
435 | if ( !(provname = CRYPT_Alloc((strlenW(pszProvider) +1)*sizeof(WCHAR))) )
|
---|
436 | {
|
---|
437 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
438 | goto error;
|
---|
439 | }
|
---|
440 | strcpyW(provname, pszProvider);
|
---|
441 | }
|
---|
442 |
|
---|
443 | keyname = CRYPT_GetProvKeyName(provname);
|
---|
444 | r = RegOpenKeyW(HKEY_LOCAL_MACHINE, keyname, &key);
|
---|
445 | CRYPT_Free(keyname);
|
---|
446 | if (r != ERROR_SUCCESS)
|
---|
447 | {
|
---|
448 | SetLastError(NTE_KEYSET_NOT_DEF);
|
---|
449 | goto error;
|
---|
450 | }
|
---|
451 | len = sizeof(DWORD);
|
---|
452 | r = RegQueryValueExW(key, typeW, NULL, NULL, (BYTE*)&type, &len);
|
---|
453 | if (r != ERROR_SUCCESS)
|
---|
454 | {
|
---|
455 | SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
---|
456 | goto error;
|
---|
457 | }
|
---|
458 | if (type != dwProvType)
|
---|
459 | {
|
---|
460 | TRACE("Crypto provider has wrong type (%d vs expected %d).\n", type, dwProvType);
|
---|
461 | SetLastError(NTE_PROV_TYPE_NO_MATCH);
|
---|
462 | goto error;
|
---|
463 | }
|
---|
464 |
|
---|
465 | r = RegQueryValueExW(key, imagepathW, NULL, &keytype, NULL, &len);
|
---|
466 | if ( r != ERROR_SUCCESS || keytype != REG_SZ)
|
---|
467 | {
|
---|
468 | TRACE("error %d reading size of 'Image Path' from registry\n", r );
|
---|
469 | RegCloseKey(key);
|
---|
470 | SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
---|
471 | goto error;
|
---|
472 | }
|
---|
473 | if (!(temp = CRYPT_Alloc(len)))
|
---|
474 | {
|
---|
475 | RegCloseKey(key);
|
---|
476 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
477 | goto error;
|
---|
478 | }
|
---|
479 | r = RegQueryValueExW(key, imagepathW, NULL, NULL, (LPBYTE)temp, &len);
|
---|
480 | if( r != ERROR_SUCCESS )
|
---|
481 | {
|
---|
482 | TRACE("error %d reading 'Image Path' from registry\n", r );
|
---|
483 | RegCloseKey(key);
|
---|
484 | SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
---|
485 | goto error;
|
---|
486 | }
|
---|
487 | RegCloseKey(key);
|
---|
488 | len = ExpandEnvironmentStringsW(temp, NULL, 0);
|
---|
489 | if ( !(imagepath = CRYPT_Alloc(len*sizeof(WCHAR))) )
|
---|
490 | {
|
---|
491 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
492 | goto error;
|
---|
493 | }
|
---|
494 | if (!ExpandEnvironmentStringsW(temp, imagepath, len))
|
---|
495 | {
|
---|
496 | /* ExpandEnvironmentStrings will call SetLastError */
|
---|
497 | goto error;
|
---|
498 | }
|
---|
499 | pProv = CRYPT_LoadProvider(imagepath);
|
---|
500 | if (!pProv) {
|
---|
501 | /* CRYPT_LoadProvider calls SetLastError */
|
---|
502 | goto error;
|
---|
503 | }
|
---|
504 | pProv->pVTable->dwProvType = dwProvType;
|
---|
505 | if(!CRYPT_UnicodeToANSI(provname, &provnameA, -1))
|
---|
506 | {
|
---|
507 | /* CRYPT_UnicodeToANSI calls SetLastError */
|
---|
508 | goto error;
|
---|
509 | }
|
---|
510 | pProv->pVTable->pszProvName = provnameA;
|
---|
511 | if(!CRYPT_UnicodeToANSI(pszContainer, &pszContainerA, -1))
|
---|
512 | {
|
---|
513 | /* CRYPT_UnicodeToANSI calls SetLastError */
|
---|
514 | goto error;
|
---|
515 | }
|
---|
516 | if (pProv->pFuncs->pCPAcquireContext(&pProv->hPrivate, pszContainerA, dwFlags, pProv->pVTable))
|
---|
517 | {
|
---|
518 | /* MSDN: When this flag is set, the value returned in phProv is undefined,
|
---|
519 | * and thus, the CryptReleaseContext function need not be called afterwards.
|
---|
520 | * Therefore, we must clean up everything now.
|
---|
521 | */
|
---|
522 | if (dwFlags & CRYPT_DELETEKEYSET)
|
---|
523 | {
|
---|
524 | pProv->dwMagic = 0;
|
---|
525 | FreeLibrary(pProv->hModule);
|
---|
526 | CRYPT_Free(provnameA);
|
---|
527 | CRYPT_Free(pProv->pVTable);
|
---|
528 | CRYPT_Free(pProv->pFuncs);
|
---|
529 | CRYPT_Free(pProv);
|
---|
530 | } else {
|
---|
531 | *phProv = (HCRYPTPROV)pProv;
|
---|
532 | }
|
---|
533 | CRYPT_Free(pszContainerA);
|
---|
534 | CRYPT_Free(provname);
|
---|
535 | CRYPT_Free(temp);
|
---|
536 | CRYPT_Free(imagepath);
|
---|
537 | return TRUE;
|
---|
538 | }
|
---|
539 | /* FALLTHROUGH TO ERROR IF FALSE - CSP internal error! */
|
---|
540 | error:
|
---|
541 | if (pProv)
|
---|
542 | {
|
---|
543 | pProv->dwMagic = 0;
|
---|
544 | if (pProv->hModule)
|
---|
545 | FreeLibrary(pProv->hModule);
|
---|
546 | CRYPT_Free(pProv->pVTable);
|
---|
547 | CRYPT_Free(pProv->pFuncs);
|
---|
548 | CRYPT_Free(pProv);
|
---|
549 | }
|
---|
550 | CRYPT_Free(pszContainerA);
|
---|
551 | CRYPT_Free(provnameA);
|
---|
552 | CRYPT_Free(provname);
|
---|
553 | CRYPT_Free(temp);
|
---|
554 | CRYPT_Free(imagepath);
|
---|
555 | return FALSE;
|
---|
556 | }
|
---|
557 |
|
---|
558 | /******************************************************************************
|
---|
559 | * CryptAcquireContextA (ADVAPI32.@)
|
---|
560 | *
|
---|
561 | * See CryptAcquireContextW.
|
---|
562 | */
|
---|
563 | BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
---|
564 | LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
|
---|
565 | {
|
---|
566 | PWSTR pProvider = NULL, pContainer = NULL;
|
---|
567 | BOOL ret = FALSE;
|
---|
568 |
|
---|
569 | TRACE("(%p, %s, %s, %d, %08x)\n", phProv, pszContainer,
|
---|
570 | pszProvider, dwProvType, dwFlags);
|
---|
571 |
|
---|
572 | if ( !CRYPT_ANSIToUnicode(pszContainer, &pContainer, -1) )
|
---|
573 | {
|
---|
574 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
575 | return FALSE;
|
---|
576 | }
|
---|
577 | if ( !CRYPT_ANSIToUnicode(pszProvider, &pProvider, -1) )
|
---|
578 | {
|
---|
579 | CRYPT_Free(pContainer);
|
---|
580 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
581 | return FALSE;
|
---|
582 | }
|
---|
583 |
|
---|
584 | ret = CryptAcquireContextW(phProv, pContainer, pProvider, dwProvType, dwFlags);
|
---|
585 |
|
---|
586 | CRYPT_Free(pContainer);
|
---|
587 | CRYPT_Free(pProvider);
|
---|
588 |
|
---|
589 | return ret;
|
---|
590 | }
|
---|
591 |
|
---|
592 | /******************************************************************************
|
---|
593 | * CryptContextAddRef (ADVAPI32.@)
|
---|
594 | *
|
---|
595 | * Increases reference count of a cryptographic service provider handle
|
---|
596 | * by one.
|
---|
597 | *
|
---|
598 | * PARAMS
|
---|
599 | * hProv [I] Handle to the CSP whose reference is being incremented.
|
---|
600 | * pdwReserved [IN] Reserved for future use and must be NULL.
|
---|
601 | * dwFlags [I] Reserved for future use and must be NULL.
|
---|
602 | *
|
---|
603 | * RETURNS
|
---|
604 | * Success: TRUE
|
---|
605 | * Failure: FALSE
|
---|
606 | */
|
---|
607 | BOOL WINAPI CryptContextAddRef (HCRYPTPROV hProv, DWORD *pdwReserved, DWORD dwFlags)
|
---|
608 | {
|
---|
609 | PCRYPTPROV pProv = (PCRYPTPROV)hProv;
|
---|
610 |
|
---|
611 | TRACE("(0x%lx, %p, %08x)\n", hProv, pdwReserved, dwFlags);
|
---|
612 |
|
---|
613 | if (!pProv)
|
---|
614 | {
|
---|
615 | SetLastError(NTE_BAD_UID);
|
---|
616 | return FALSE;
|
---|
617 | }
|
---|
618 |
|
---|
619 | if (pProv->dwMagic != MAGIC_CRYPTPROV)
|
---|
620 | {
|
---|
621 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
622 | return FALSE;
|
---|
623 | }
|
---|
624 |
|
---|
625 | pProv->refcount++;
|
---|
626 | return TRUE;
|
---|
627 | }
|
---|
628 |
|
---|
629 | /******************************************************************************
|
---|
630 | * CryptReleaseContext (ADVAPI32.@)
|
---|
631 | *
|
---|
632 | * Releases the handle of a CSP. Reference count is decreased.
|
---|
633 | *
|
---|
634 | * PARAMS
|
---|
635 | * hProv [I] Handle of a CSP.
|
---|
636 | * dwFlags [I] Reserved for future use and must be NULL.
|
---|
637 | *
|
---|
638 | * RETURNS
|
---|
639 | * Success: TRUE
|
---|
640 | * Failure: FALSE
|
---|
641 | */
|
---|
642 | BOOL WINAPI CryptReleaseContext (HCRYPTPROV hProv, ULONG_PTR dwFlags)
|
---|
643 | {
|
---|
644 | PCRYPTPROV pProv = (PCRYPTPROV)hProv;
|
---|
645 | BOOL ret = TRUE;
|
---|
646 |
|
---|
647 | TRACE("(0x%lx, %08lx)\n", hProv, dwFlags);
|
---|
648 |
|
---|
649 | if (!pProv)
|
---|
650 | {
|
---|
651 | SetLastError(NTE_BAD_UID);
|
---|
652 | return FALSE;
|
---|
653 | }
|
---|
654 |
|
---|
655 | if (pProv->dwMagic != MAGIC_CRYPTPROV)
|
---|
656 | {
|
---|
657 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
658 | return FALSE;
|
---|
659 | }
|
---|
660 |
|
---|
661 | pProv->refcount--;
|
---|
662 | if (pProv->refcount <= 0)
|
---|
663 | {
|
---|
664 | ret = pProv->pFuncs->pCPReleaseContext(pProv->hPrivate, dwFlags);
|
---|
665 | pProv->dwMagic = 0;
|
---|
666 | FreeLibrary(pProv->hModule);
|
---|
667 | #if 0
|
---|
668 | CRYPT_Free(pProv->pVTable->pContextInfo);
|
---|
669 | #endif
|
---|
670 | CRYPT_Free(pProv->pVTable->pszProvName);
|
---|
671 | CRYPT_Free(pProv->pVTable);
|
---|
672 | CRYPT_Free(pProv->pFuncs);
|
---|
673 | CRYPT_Free(pProv);
|
---|
674 | }
|
---|
675 | return ret;
|
---|
676 | }
|
---|
677 |
|
---|
678 | /******************************************************************************
|
---|
679 | * CryptGenRandom (ADVAPI32.@)
|
---|
680 | *
|
---|
681 | * Fills a buffer with cryptographically random bytes.
|
---|
682 | *
|
---|
683 | * PARAMS
|
---|
684 | * hProv [I] Handle of a CSP.
|
---|
685 | * dwLen [I] Number of bytes to generate.
|
---|
686 | * pbBuffer [I/O] Buffer to contain random bytes.
|
---|
687 | *
|
---|
688 | * RETURNS
|
---|
689 | * Success: TRUE
|
---|
690 | * Failure: FALSE
|
---|
691 | *
|
---|
692 | * NOTES
|
---|
693 | * pdBuffer must be at least dwLen bytes long.
|
---|
694 | */
|
---|
695 | BOOL WINAPI CryptGenRandom (HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer)
|
---|
696 | {
|
---|
697 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
698 |
|
---|
699 | TRACE("(0x%lx, %d, %p)\n", hProv, dwLen, pbBuffer);
|
---|
700 |
|
---|
701 | if (!hProv)
|
---|
702 | {
|
---|
703 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
704 | return FALSE;
|
---|
705 | }
|
---|
706 |
|
---|
707 | if (prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
708 | {
|
---|
709 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
710 | return FALSE;
|
---|
711 | }
|
---|
712 |
|
---|
713 | return prov->pFuncs->pCPGenRandom(prov->hPrivate, dwLen, pbBuffer);
|
---|
714 | }
|
---|
715 |
|
---|
716 | /******************************************************************************
|
---|
717 | * CryptCreateHash (ADVAPI32.@)
|
---|
718 | *
|
---|
719 | * Initiates the hashing of a stream of data.
|
---|
720 | *
|
---|
721 | * PARAMS
|
---|
722 | * hProv [I] Handle of a CSP.
|
---|
723 | * Algid [I] Identifies the hash algorithm to use.
|
---|
724 | * hKey [I] Key for the hash (if required).
|
---|
725 | * dwFlags [I] Reserved for future use and must be NULL.
|
---|
726 | * phHash [O] Address of the future handle to the new hash object.
|
---|
727 | *
|
---|
728 | * RETURNS
|
---|
729 | * Success: TRUE
|
---|
730 | * Failure: FALSE
|
---|
731 | *
|
---|
732 | * NOTES
|
---|
733 | * If the algorithm is a keyed hash, hKey is the key.
|
---|
734 | */
|
---|
735 | BOOL WINAPI CryptCreateHash (HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey,
|
---|
736 | DWORD dwFlags, HCRYPTHASH *phHash)
|
---|
737 | {
|
---|
738 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
739 | PCRYPTKEY key = (PCRYPTKEY)hKey;
|
---|
740 | PCRYPTHASH hash;
|
---|
741 |
|
---|
742 | TRACE("(0x%lx, 0x%x, 0x%lx, %08x, %p)\n", hProv, Algid, hKey, dwFlags, phHash);
|
---|
743 |
|
---|
744 | if (!prov)
|
---|
745 | {
|
---|
746 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
747 | return FALSE;
|
---|
748 | }
|
---|
749 | if (!phHash || prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
750 | {
|
---|
751 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
752 | return FALSE;
|
---|
753 | }
|
---|
754 | if (dwFlags)
|
---|
755 | {
|
---|
756 | SetLastError(NTE_BAD_FLAGS);
|
---|
757 | return FALSE;
|
---|
758 | }
|
---|
759 | if ( !(hash = CRYPT_Alloc(sizeof(CRYPTHASH))) )
|
---|
760 | {
|
---|
761 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
762 | return FALSE;
|
---|
763 | }
|
---|
764 |
|
---|
765 | hash->pProvider = prov;
|
---|
766 |
|
---|
767 | if (prov->pFuncs->pCPCreateHash(prov->hPrivate, Algid,
|
---|
768 | key ? key->hPrivate : 0, 0, &hash->hPrivate))
|
---|
769 | {
|
---|
770 | *phHash = (HCRYPTHASH)hash;
|
---|
771 | return TRUE;
|
---|
772 | }
|
---|
773 |
|
---|
774 | /* CSP error! */
|
---|
775 | CRYPT_Free(hash);
|
---|
776 | *phHash = 0;
|
---|
777 | return FALSE;
|
---|
778 | }
|
---|
779 |
|
---|
780 | /******************************************************************************
|
---|
781 | * CryptDecrypt (ADVAPI32.@)
|
---|
782 | *
|
---|
783 | * Decrypts data encrypted by CryptEncrypt.
|
---|
784 | *
|
---|
785 | * PARAMS
|
---|
786 | * hKey [I] Handle to the decryption key.
|
---|
787 | * hHash [I] Handle to a hash object.
|
---|
788 | * Final [I] TRUE if this is the last section to be decrypted.
|
---|
789 | * dwFlags [I] Reserved for future use. Can be CRYPT_OAEP.
|
---|
790 | * pbData [I/O] Buffer that holds the encrypted data. Holds decrypted
|
---|
791 | * data on return
|
---|
792 | * pdwDataLen [I/O] Length of pbData before and after the call.
|
---|
793 | *
|
---|
794 | * RETURNS
|
---|
795 | * Success: TRUE
|
---|
796 | * Failure: FALSE
|
---|
797 | */
|
---|
798 | BOOL WINAPI CryptDecrypt (HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final,
|
---|
799 | DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
|
---|
800 | {
|
---|
801 | PCRYPTPROV prov;
|
---|
802 | PCRYPTKEY key = (PCRYPTKEY)hKey;
|
---|
803 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
804 |
|
---|
805 | TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hHash, Final, dwFlags, pbData, pdwDataLen);
|
---|
806 |
|
---|
807 | if (!key || !pbData || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
808 | {
|
---|
809 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
810 | return FALSE;
|
---|
811 | }
|
---|
812 |
|
---|
813 | prov = key->pProvider;
|
---|
814 | return prov->pFuncs->pCPDecrypt(prov->hPrivate, key->hPrivate, hash ? hash->hPrivate : 0,
|
---|
815 | Final, dwFlags, pbData, pdwDataLen);
|
---|
816 | }
|
---|
817 |
|
---|
818 | /******************************************************************************
|
---|
819 | * CryptDeriveKey (ADVAPI32.@)
|
---|
820 | *
|
---|
821 | * Generates session keys derived from a base data value.
|
---|
822 | *
|
---|
823 | * PARAMS
|
---|
824 | * hProv [I] Handle to a CSP.
|
---|
825 | * Algid [I] Identifies the symmetric encryption algorithm to use.
|
---|
826 | * hBaseData [I] Handle to a hash object.
|
---|
827 | * dwFlags [I] Type of key to generate.
|
---|
828 | * phKey [I/O] Address of the newly generated key.
|
---|
829 | *
|
---|
830 | * RETURNS
|
---|
831 | * Success: TRUE
|
---|
832 | * Failure: FALSE
|
---|
833 | */
|
---|
834 | BOOL WINAPI CryptDeriveKey (HCRYPTPROV hProv, ALG_ID Algid, HCRYPTHASH hBaseData,
|
---|
835 | DWORD dwFlags, HCRYPTKEY *phKey)
|
---|
836 | {
|
---|
837 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
838 | PCRYPTHASH hash = (PCRYPTHASH)hBaseData;
|
---|
839 | PCRYPTKEY key;
|
---|
840 |
|
---|
841 | TRACE("(0x%lx, 0x%08x, 0x%lx, 0x%08x, %p)\n", hProv, Algid, hBaseData, dwFlags, phKey);
|
---|
842 |
|
---|
843 | if (!prov || !hash)
|
---|
844 | {
|
---|
845 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
846 | return FALSE;
|
---|
847 | }
|
---|
848 | if (!phKey || prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
849 | {
|
---|
850 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
851 | return FALSE;
|
---|
852 | }
|
---|
853 | if ( !(key = CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
---|
854 | {
|
---|
855 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
856 | return FALSE;
|
---|
857 | }
|
---|
858 |
|
---|
859 | key->pProvider = prov;
|
---|
860 | if (prov->pFuncs->pCPDeriveKey(prov->hPrivate, Algid, hash->hPrivate, dwFlags, &key->hPrivate))
|
---|
861 | {
|
---|
862 | *phKey = (HCRYPTKEY)key;
|
---|
863 | return TRUE;
|
---|
864 | }
|
---|
865 |
|
---|
866 | /* CSP error! */
|
---|
867 | CRYPT_Free(key);
|
---|
868 | *phKey = 0;
|
---|
869 | return FALSE;
|
---|
870 | }
|
---|
871 |
|
---|
872 | /******************************************************************************
|
---|
873 | * CryptDestroyHash (ADVAPI32.@)
|
---|
874 | *
|
---|
875 | * Destroys the hash object referenced by hHash.
|
---|
876 | *
|
---|
877 | * PARAMS
|
---|
878 | * hHash [I] Handle of the hash object to be destroyed.
|
---|
879 | *
|
---|
880 | * RETURNS
|
---|
881 | * Success: TRUE
|
---|
882 | * Failure: FALSE
|
---|
883 | */
|
---|
884 | BOOL WINAPI CryptDestroyHash (HCRYPTHASH hHash)
|
---|
885 | {
|
---|
886 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
887 | PCRYPTPROV prov;
|
---|
888 | BOOL ret;
|
---|
889 |
|
---|
890 | TRACE("(0x%lx)\n", hHash);
|
---|
891 |
|
---|
892 | if (!hash)
|
---|
893 | {
|
---|
894 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
895 | return FALSE;
|
---|
896 | }
|
---|
897 |
|
---|
898 | if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
899 | {
|
---|
900 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
901 | return FALSE;
|
---|
902 | }
|
---|
903 |
|
---|
904 | prov = hash->pProvider;
|
---|
905 | ret = prov->pFuncs->pCPDestroyHash(prov->hPrivate, hash->hPrivate);
|
---|
906 | CRYPT_Free(hash);
|
---|
907 | return ret;
|
---|
908 | }
|
---|
909 |
|
---|
910 | /******************************************************************************
|
---|
911 | * CryptDestroyKey (ADVAPI32.@)
|
---|
912 | *
|
---|
913 | * Releases the handle referenced by hKey.
|
---|
914 | *
|
---|
915 | * PARAMS
|
---|
916 | * hKey [I] Handle of the key to be destroyed.
|
---|
917 | *
|
---|
918 | * RETURNS
|
---|
919 | * Success: TRUE
|
---|
920 | * Failure: FALSE
|
---|
921 | */
|
---|
922 | BOOL WINAPI CryptDestroyKey (HCRYPTKEY hKey)
|
---|
923 | {
|
---|
924 | PCRYPTKEY key = (PCRYPTKEY)hKey;
|
---|
925 | PCRYPTPROV prov;
|
---|
926 | BOOL ret;
|
---|
927 |
|
---|
928 | TRACE("(0x%lx)\n", hKey);
|
---|
929 |
|
---|
930 | if (!key)
|
---|
931 | {
|
---|
932 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
933 | return FALSE;
|
---|
934 | }
|
---|
935 |
|
---|
936 | if (!key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
937 | {
|
---|
938 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
939 | return FALSE;
|
---|
940 | }
|
---|
941 |
|
---|
942 | prov = key->pProvider;
|
---|
943 | ret = prov->pFuncs->pCPDestroyKey(prov->hPrivate, key->hPrivate);
|
---|
944 | CRYPT_Free(key);
|
---|
945 | return ret;
|
---|
946 | }
|
---|
947 |
|
---|
948 | /******************************************************************************
|
---|
949 | * CryptDuplicateHash (ADVAPI32.@)
|
---|
950 | *
|
---|
951 | * Duplicates a hash.
|
---|
952 | *
|
---|
953 | * PARAMS
|
---|
954 | * hHash [I] Handle to the hash to be copied.
|
---|
955 | * pdwReserved [I] Reserved for future use and must be zero.
|
---|
956 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
957 | * phHash [O] Address of the handle to receive the copy.
|
---|
958 | *
|
---|
959 | * RETURNS
|
---|
960 | * Success: TRUE
|
---|
961 | * Failure: FALSE
|
---|
962 | */
|
---|
963 | BOOL WINAPI CryptDuplicateHash (HCRYPTHASH hHash, DWORD *pdwReserved,
|
---|
964 | DWORD dwFlags, HCRYPTHASH *phHash)
|
---|
965 | {
|
---|
966 | PCRYPTPROV prov;
|
---|
967 | PCRYPTHASH orghash, newhash;
|
---|
968 |
|
---|
969 | TRACE("(0x%lx, %p, %08x, %p)\n", hHash, pdwReserved, dwFlags, phHash);
|
---|
970 |
|
---|
971 | orghash = (PCRYPTHASH)hHash;
|
---|
972 | if (!orghash || pdwReserved || !phHash || !orghash->pProvider ||
|
---|
973 | orghash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
974 | {
|
---|
975 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
976 | return FALSE;
|
---|
977 | }
|
---|
978 |
|
---|
979 | prov = orghash->pProvider;
|
---|
980 | if (!prov->pFuncs->pCPDuplicateHash)
|
---|
981 | {
|
---|
982 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
---|
983 | return FALSE;
|
---|
984 | }
|
---|
985 |
|
---|
986 | if ( !(newhash = CRYPT_Alloc(sizeof(CRYPTHASH))) )
|
---|
987 | {
|
---|
988 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
989 | return FALSE;
|
---|
990 | }
|
---|
991 |
|
---|
992 | newhash->pProvider = prov;
|
---|
993 | if (prov->pFuncs->pCPDuplicateHash(prov->hPrivate, orghash->hPrivate, pdwReserved, dwFlags, &newhash->hPrivate))
|
---|
994 | {
|
---|
995 | *phHash = (HCRYPTHASH)newhash;
|
---|
996 | return TRUE;
|
---|
997 | }
|
---|
998 | CRYPT_Free(newhash);
|
---|
999 | return FALSE;
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 | /******************************************************************************
|
---|
1003 | * CryptDuplicateKey (ADVAPI32.@)
|
---|
1004 | *
|
---|
1005 | * Duplicate a key and the key's state.
|
---|
1006 | *
|
---|
1007 | * PARAMS
|
---|
1008 | * hKey [I] Handle of the key to copy.
|
---|
1009 | * pdwReserved [I] Reserved for future use and must be NULL.
|
---|
1010 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
1011 | * phKey [I] Address of the handle to the duplicated key.
|
---|
1012 | *
|
---|
1013 | * RETURNS
|
---|
1014 | * Success: TRUE
|
---|
1015 | * Failure: FALSE
|
---|
1016 | */
|
---|
1017 | BOOL WINAPI CryptDuplicateKey (HCRYPTKEY hKey, DWORD *pdwReserved, DWORD dwFlags, HCRYPTKEY *phKey)
|
---|
1018 | {
|
---|
1019 | PCRYPTPROV prov;
|
---|
1020 | PCRYPTKEY orgkey, newkey;
|
---|
1021 |
|
---|
1022 | TRACE("(0x%lx, %p, %08x, %p)\n", hKey, pdwReserved, dwFlags, phKey);
|
---|
1023 |
|
---|
1024 | orgkey = (PCRYPTKEY)hKey;
|
---|
1025 | if (!orgkey || pdwReserved || !phKey || !orgkey->pProvider ||
|
---|
1026 | orgkey->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1027 | {
|
---|
1028 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1029 | return FALSE;
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | prov = orgkey->pProvider;
|
---|
1033 | if (!prov->pFuncs->pCPDuplicateKey)
|
---|
1034 | {
|
---|
1035 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
---|
1036 | return FALSE;
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | if ( !(newkey = CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
---|
1040 | {
|
---|
1041 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1042 | return FALSE;
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 | newkey->pProvider = prov;
|
---|
1046 | if (prov->pFuncs->pCPDuplicateKey(prov->hPrivate, orgkey->hPrivate, pdwReserved, dwFlags, &newkey->hPrivate))
|
---|
1047 | {
|
---|
1048 | *phKey = (HCRYPTKEY)newkey;
|
---|
1049 | return TRUE;
|
---|
1050 | }
|
---|
1051 | CRYPT_Free(newkey);
|
---|
1052 | return FALSE;
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | /******************************************************************************
|
---|
1056 | * CryptEncrypt (ADVAPI32.@)
|
---|
1057 | *
|
---|
1058 | * Encrypts data.
|
---|
1059 | *
|
---|
1060 | * PARAMS
|
---|
1061 | * hKey [I] Handle to the encryption key.
|
---|
1062 | * hHash [I] Handle to a hash object.
|
---|
1063 | * Final [I] TRUE if this is the last section to encrypt.
|
---|
1064 | * dwFlags [I] Can be CRYPT_OAEP.
|
---|
1065 | * pbData [I/O] Data to be encrypted. Contains encrypted data after call.
|
---|
1066 | * pdwDataLen [I/O] Length of the data to encrypt. Contains the length of the
|
---|
1067 | * encrypted data after call.
|
---|
1068 | * dwBufLen [I] Length of the input pbData buffer.
|
---|
1069 | *
|
---|
1070 | * RETURNS
|
---|
1071 | * Success: TRUE
|
---|
1072 | * Failure: FALSE
|
---|
1073 | *
|
---|
1074 | * NOTES
|
---|
1075 | * If pbData is NULL, CryptEncrypt determines stores the number of bytes
|
---|
1076 | * required for the returned data in pdwDataLen.
|
---|
1077 | */
|
---|
1078 | BOOL WINAPI CryptEncrypt (HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final,
|
---|
1079 | DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
|
---|
1080 | {
|
---|
1081 | PCRYPTPROV prov;
|
---|
1082 | PCRYPTKEY key = (PCRYPTKEY)hKey;
|
---|
1083 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1084 |
|
---|
1085 | TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p, %d)\n", hKey, hHash, Final, dwFlags, pbData, pdwDataLen, dwBufLen);
|
---|
1086 |
|
---|
1087 | if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1088 | {
|
---|
1089 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1090 | return FALSE;
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | prov = key->pProvider;
|
---|
1094 | return prov->pFuncs->pCPEncrypt(prov->hPrivate, key->hPrivate, hash ? hash->hPrivate : 0,
|
---|
1095 | Final, dwFlags, pbData, pdwDataLen, dwBufLen);
|
---|
1096 | }
|
---|
1097 |
|
---|
1098 | /******************************************************************************
|
---|
1099 | * CryptEnumProvidersW (ADVAPI32.@)
|
---|
1100 | *
|
---|
1101 | * Returns the next available CSP.
|
---|
1102 | *
|
---|
1103 | * PARAMS
|
---|
1104 | * dwIndex [I] Index of the next provider to be enumerated.
|
---|
1105 | * pdwReserved [I] Reserved for future use and must be NULL.
|
---|
1106 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
1107 | * pdwProvType [O] DWORD designating the type of the provider.
|
---|
1108 | * pszProvName [O] Buffer that receives data from the provider.
|
---|
1109 | * pcbProvName [I/O] Specifies the size of pszProvName. Contains the number
|
---|
1110 | * of bytes stored in the buffer on return.
|
---|
1111 | *
|
---|
1112 | * RETURNS
|
---|
1113 | * Success: TRUE
|
---|
1114 | * Failure: FALSE
|
---|
1115 | *
|
---|
1116 | * NOTES
|
---|
1117 | * If pszProvName is NULL, CryptEnumProvidersW sets the size of the name
|
---|
1118 | * for memory allocation purposes.
|
---|
1119 | */
|
---|
1120 | BOOL WINAPI CryptEnumProvidersW (DWORD dwIndex, DWORD *pdwReserved,
|
---|
1121 | DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszProvName, DWORD *pcbProvName)
|
---|
1122 | {
|
---|
1123 | HKEY hKey;
|
---|
1124 | static const WCHAR providerW[] = {
|
---|
1125 | 'S','o','f','t','w','a','r','e','\\',
|
---|
1126 | 'M','i','c','r','o','s','o','f','t','\\',
|
---|
1127 | 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
---|
1128 | 'D','e','f','a','u','l','t','s','\\',
|
---|
1129 | 'P','r','o','v','i','d','e','r',0
|
---|
1130 | };
|
---|
1131 | static const WCHAR typeW[] = {'T','y','p','e',0};
|
---|
1132 |
|
---|
1133 | TRACE("(%d, %p, %d, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
---|
1134 | pdwProvType, pszProvName, pcbProvName);
|
---|
1135 |
|
---|
1136 | if (pdwReserved || !pcbProvName)
|
---|
1137 | {
|
---|
1138 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1139 | return FALSE;
|
---|
1140 | }
|
---|
1141 | if (dwFlags)
|
---|
1142 | {
|
---|
1143 | SetLastError(NTE_BAD_FLAGS);
|
---|
1144 | return FALSE;
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | if (RegOpenKeyW(HKEY_LOCAL_MACHINE, providerW, &hKey))
|
---|
1148 | {
|
---|
1149 | SetLastError(NTE_FAIL);
|
---|
1150 | return FALSE;
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | if (!pszProvName)
|
---|
1154 | {
|
---|
1155 | DWORD numkeys;
|
---|
1156 | WCHAR *provNameW;
|
---|
1157 |
|
---|
1158 | RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &numkeys, pcbProvName,
|
---|
1159 | NULL, NULL, NULL, NULL, NULL, NULL);
|
---|
1160 |
|
---|
1161 | if (!(provNameW = CRYPT_Alloc(*pcbProvName * sizeof(WCHAR))))
|
---|
1162 | {
|
---|
1163 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1164 | return FALSE;
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | RegEnumKeyExW(hKey, dwIndex, provNameW, pcbProvName, NULL, NULL, NULL, NULL);
|
---|
1168 | CRYPT_Free(provNameW);
|
---|
1169 | (*pcbProvName)++;
|
---|
1170 | *pcbProvName *= sizeof(WCHAR);
|
---|
1171 |
|
---|
1172 | if (dwIndex >= numkeys)
|
---|
1173 | {
|
---|
1174 | SetLastError(ERROR_NO_MORE_ITEMS);
|
---|
1175 | return FALSE;
|
---|
1176 | }
|
---|
1177 | } else {
|
---|
1178 | DWORD size = sizeof(DWORD);
|
---|
1179 | DWORD result;
|
---|
1180 | HKEY subkey;
|
---|
1181 |
|
---|
1182 | result = RegEnumKeyW(hKey, dwIndex, pszProvName, *pcbProvName / sizeof(WCHAR));
|
---|
1183 | if (result)
|
---|
1184 | {
|
---|
1185 | SetLastError(result);
|
---|
1186 | return FALSE;
|
---|
1187 | }
|
---|
1188 | if (RegOpenKeyW(hKey, pszProvName, &subkey))
|
---|
1189 | return FALSE;
|
---|
1190 | if (RegQueryValueExW(subkey, typeW, NULL, NULL, (BYTE*)pdwProvType, &size))
|
---|
1191 | return FALSE;
|
---|
1192 | RegCloseKey(subkey);
|
---|
1193 | }
|
---|
1194 | RegCloseKey(hKey);
|
---|
1195 | return TRUE;
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 | /******************************************************************************
|
---|
1199 | * CryptEnumProvidersA (ADVAPI32.@)
|
---|
1200 | *
|
---|
1201 | * See CryptEnumProvidersW.
|
---|
1202 | */
|
---|
1203 | BOOL WINAPI CryptEnumProvidersA (DWORD dwIndex, DWORD *pdwReserved,
|
---|
1204 | DWORD dwFlags, DWORD *pdwProvType, LPSTR pszProvName, DWORD *pcbProvName)
|
---|
1205 | {
|
---|
1206 | PWSTR str = NULL;
|
---|
1207 | DWORD bufsize;
|
---|
1208 | BOOL ret; /* = FALSE; */
|
---|
1209 |
|
---|
1210 | TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
---|
1211 | pdwProvType, pszProvName, pcbProvName);
|
---|
1212 |
|
---|
1213 | if(!CryptEnumProvidersW(dwIndex, pdwReserved, dwFlags, pdwProvType, NULL, &bufsize))
|
---|
1214 | return FALSE;
|
---|
1215 | if ( pszProvName && !(str = CRYPT_Alloc(bufsize)) )
|
---|
1216 | {
|
---|
1217 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1218 | return FALSE;
|
---|
1219 | }
|
---|
1220 | ret = CryptEnumProvidersW(dwIndex, pdwReserved, dwFlags, pdwProvType, str, &bufsize);
|
---|
1221 | if (str)
|
---|
1222 | CRYPT_UnicodeToANSI(str, &pszProvName, *pcbProvName);
|
---|
1223 | *pcbProvName = bufsize / sizeof(WCHAR); /* FIXME: not correct */
|
---|
1224 | if (str)
|
---|
1225 | {
|
---|
1226 | CRYPT_Free(str);
|
---|
1227 | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
---|
1228 | {
|
---|
1229 | SetLastError(ERROR_MORE_DATA);
|
---|
1230 | return FALSE;
|
---|
1231 | }
|
---|
1232 | }
|
---|
1233 | return ret;
|
---|
1234 | }
|
---|
1235 |
|
---|
1236 | /******************************************************************************
|
---|
1237 | * CryptEnumProviderTypesW (ADVAPI32.@)
|
---|
1238 | *
|
---|
1239 | * Retrieves the next type of CSP supported.
|
---|
1240 | *
|
---|
1241 | * PARAMS
|
---|
1242 | * dwIndex [I] Index of the next provider to be enumerated.
|
---|
1243 | * pdwReserved [I] Reserved for future use and must be NULL.
|
---|
1244 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
1245 | * pdwProvType [O] DWORD designating the type of the provider.
|
---|
1246 | * pszTypeName [O] Buffer that receives data from the provider type.
|
---|
1247 | * pcbTypeName [I/O] Specifies the size of pszTypeName. Contains the number
|
---|
1248 | * of bytes stored in the buffer on return.
|
---|
1249 | *
|
---|
1250 | * RETURNS
|
---|
1251 | * Success: TRUE
|
---|
1252 | * Failure: FALSE
|
---|
1253 | *
|
---|
1254 | * NOTES
|
---|
1255 | * If pszTypeName is NULL, CryptEnumProviderTypesW sets the size of the name
|
---|
1256 | * for memory allocation purposes.
|
---|
1257 | */
|
---|
1258 | BOOL WINAPI CryptEnumProviderTypesW (DWORD dwIndex, DWORD *pdwReserved,
|
---|
1259 | DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszTypeName, DWORD *pcbTypeName)
|
---|
1260 | {
|
---|
1261 | HKEY hKey, hSubkey;
|
---|
1262 | DWORD keylen, numkeys, dwType;
|
---|
1263 | PWSTR keyname, ch;
|
---|
1264 | DWORD result;
|
---|
1265 | static const WCHAR KEYSTR[] = {
|
---|
1266 | 'S','o','f','t','w','a','r','e','\\',
|
---|
1267 | 'M','i','c','r','o','s','o','f','t','\\',
|
---|
1268 | 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
---|
1269 | 'D','e','f','a','u','l','t','s','\\',
|
---|
1270 | 'P','r','o','v','i','d','e','r',' ','T','y','p','e','s',0
|
---|
1271 | };
|
---|
1272 | static const WCHAR typenameW[] = {'T','y','p','e','N','a','m','e',0};
|
---|
1273 |
|
---|
1274 | TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved,
|
---|
1275 | dwFlags, pdwProvType, pszTypeName, pcbTypeName);
|
---|
1276 |
|
---|
1277 | if (pdwReserved || !pdwProvType || !pcbTypeName)
|
---|
1278 | {
|
---|
1279 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1280 | return FALSE;
|
---|
1281 | }
|
---|
1282 | if (dwFlags)
|
---|
1283 | {
|
---|
1284 | SetLastError(NTE_BAD_FLAGS);
|
---|
1285 | return FALSE;
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 | if (RegOpenKeyW(HKEY_LOCAL_MACHINE, KEYSTR, &hKey))
|
---|
1289 | return FALSE;
|
---|
1290 |
|
---|
1291 | RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &numkeys, &keylen, NULL, NULL, NULL, NULL, NULL, NULL);
|
---|
1292 | if (dwIndex >= numkeys)
|
---|
1293 | {
|
---|
1294 | SetLastError(ERROR_NO_MORE_ITEMS);
|
---|
1295 | return FALSE;
|
---|
1296 | }
|
---|
1297 | keylen++;
|
---|
1298 | if ( !(keyname = CRYPT_Alloc(keylen*sizeof(WCHAR))) )
|
---|
1299 | {
|
---|
1300 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1301 | return FALSE;
|
---|
1302 | }
|
---|
1303 | if ( RegEnumKeyW(hKey, dwIndex, keyname, keylen) ) {
|
---|
1304 | CRYPT_Free(keyname);
|
---|
1305 | return FALSE;
|
---|
1306 | }
|
---|
1307 | RegOpenKeyW(hKey, keyname, &hSubkey);
|
---|
1308 | ch = keyname + strlenW(keyname);
|
---|
1309 | /* Convert "Type 000" to 0, etc/ */
|
---|
1310 | *pdwProvType = *(--ch) - '0';
|
---|
1311 | *pdwProvType += (*(--ch) - '0') * 10;
|
---|
1312 | *pdwProvType += (*(--ch) - '0') * 100;
|
---|
1313 | CRYPT_Free(keyname);
|
---|
1314 |
|
---|
1315 | result = RegQueryValueExW(hSubkey, typenameW, NULL, &dwType, (LPBYTE)pszTypeName, pcbTypeName);
|
---|
1316 | if (result)
|
---|
1317 | {
|
---|
1318 | SetLastError(result);
|
---|
1319 | return FALSE;
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 | RegCloseKey(hSubkey);
|
---|
1323 | RegCloseKey(hKey);
|
---|
1324 | return TRUE;
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | /******************************************************************************
|
---|
1328 | * CryptEnumProviderTypesA (ADVAPI32.@)
|
---|
1329 | *
|
---|
1330 | * See CryptEnumProviderTypesW.
|
---|
1331 | */
|
---|
1332 | BOOL WINAPI CryptEnumProviderTypesA (DWORD dwIndex, DWORD *pdwReserved,
|
---|
1333 | DWORD dwFlags, DWORD *pdwProvType, LPSTR pszTypeName, DWORD *pcbTypeName)
|
---|
1334 | {
|
---|
1335 | PWSTR str = NULL;
|
---|
1336 | DWORD bufsize;
|
---|
1337 | BOOL ret;
|
---|
1338 |
|
---|
1339 | TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
---|
1340 | pdwProvType, pszTypeName, pcbTypeName);
|
---|
1341 |
|
---|
1342 | if(!CryptEnumProviderTypesW(dwIndex, pdwReserved, dwFlags, pdwProvType, NULL, &bufsize))
|
---|
1343 | return FALSE;
|
---|
1344 | if ( pszTypeName && !(str = CRYPT_Alloc(bufsize)) )
|
---|
1345 | {
|
---|
1346 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1347 | return FALSE;
|
---|
1348 | }
|
---|
1349 | ret = CryptEnumProviderTypesW(dwIndex, pdwReserved, dwFlags, pdwProvType, str, &bufsize);
|
---|
1350 | if (str)
|
---|
1351 | CRYPT_UnicodeToANSI(str, &pszTypeName, *pcbTypeName);
|
---|
1352 | *pcbTypeName = bufsize / sizeof(WCHAR);
|
---|
1353 | if (str)
|
---|
1354 | {
|
---|
1355 | CRYPT_Free(str);
|
---|
1356 | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
---|
1357 | {
|
---|
1358 | SetLastError(ERROR_MORE_DATA);
|
---|
1359 | return FALSE;
|
---|
1360 | }
|
---|
1361 | }
|
---|
1362 | return ret;
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 | /******************************************************************************
|
---|
1366 | * CryptExportKey (ADVAPI32.@)
|
---|
1367 | *
|
---|
1368 | * Exports a cryptographic key from a CSP.
|
---|
1369 | *
|
---|
1370 | * PARAMS
|
---|
1371 | * hKey [I] Handle to the key to export.
|
---|
1372 | * hExpKey [I] Handle to a cryptographic key of the end user.
|
---|
1373 | * dwBlobType [I] Type of BLOB to be exported.
|
---|
1374 | * dwFlags [I] CRYPT_DESTROYKEY/SSL2_FALLBACK/OAEP.
|
---|
1375 | * pbData [O] Buffer to receive BLOB data.
|
---|
1376 | * pdwDataLen [I/O] Specifies the size of pbData.
|
---|
1377 | *
|
---|
1378 | * RETURNS
|
---|
1379 | * Success: TRUE
|
---|
1380 | * Failure: FALSE
|
---|
1381 | *
|
---|
1382 | * NOTES
|
---|
1383 | * if pbData is NULL, CryptExportKey sets pdwDataLen as the size of the
|
---|
1384 | * buffer needed to hold the BLOB.
|
---|
1385 | */
|
---|
1386 | BOOL WINAPI CryptExportKey (HCRYPTKEY hKey, HCRYPTKEY hExpKey, DWORD dwBlobType,
|
---|
1387 | DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
|
---|
1388 | {
|
---|
1389 | PCRYPTPROV prov;
|
---|
1390 | PCRYPTKEY key = (PCRYPTKEY)hKey, expkey = (PCRYPTKEY)hExpKey;
|
---|
1391 |
|
---|
1392 | TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hExpKey, dwBlobType, dwFlags, pbData, pdwDataLen);
|
---|
1393 |
|
---|
1394 | if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1395 | {
|
---|
1396 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1397 | return FALSE;
|
---|
1398 | }
|
---|
1399 |
|
---|
1400 | prov = key->pProvider;
|
---|
1401 | return prov->pFuncs->pCPExportKey(prov->hPrivate, key->hPrivate, expkey ? expkey->hPrivate : 0,
|
---|
1402 | dwBlobType, dwFlags, pbData, pdwDataLen);
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | /******************************************************************************
|
---|
1406 | * CryptGenKey (ADVAPI32.@)
|
---|
1407 | *
|
---|
1408 | * Generates a random cryptographic session key or a pub/priv key pair.
|
---|
1409 | *
|
---|
1410 | * PARAMS
|
---|
1411 | * hProv [I] Handle to a CSP.
|
---|
1412 | * Algid [I] Algorithm to use to make key.
|
---|
1413 | * dwFlags [I] Specifies type of key to make.
|
---|
1414 | * phKey [I] Address of the handle to which the new key is copied.
|
---|
1415 | *
|
---|
1416 | * RETURNS
|
---|
1417 | * Success: TRUE
|
---|
1418 | * Failure: FALSE
|
---|
1419 | */
|
---|
1420 | BOOL WINAPI CryptGenKey (HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey)
|
---|
1421 | {
|
---|
1422 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
1423 | PCRYPTKEY key;
|
---|
1424 |
|
---|
1425 | TRACE("(0x%lx, %d, %08x, %p)\n", hProv, Algid, dwFlags, phKey);
|
---|
1426 |
|
---|
1427 | if (!prov)
|
---|
1428 | {
|
---|
1429 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
1430 | return FALSE;
|
---|
1431 | }
|
---|
1432 | if (!phKey || !prov || prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
1433 | {
|
---|
1434 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1435 | return FALSE;
|
---|
1436 | }
|
---|
1437 | if ( !(key = CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
---|
1438 | {
|
---|
1439 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1440 | return FALSE;
|
---|
1441 | }
|
---|
1442 |
|
---|
1443 | key->pProvider = prov;
|
---|
1444 |
|
---|
1445 | if (prov->pFuncs->pCPGenKey(prov->hPrivate, Algid, dwFlags, &key->hPrivate))
|
---|
1446 | {
|
---|
1447 | *phKey = (HCRYPTKEY)key;
|
---|
1448 | return TRUE;
|
---|
1449 | }
|
---|
1450 |
|
---|
1451 | /* CSP error! */
|
---|
1452 | CRYPT_Free(key);
|
---|
1453 | return FALSE;
|
---|
1454 | }
|
---|
1455 |
|
---|
1456 | /******************************************************************************
|
---|
1457 | * CryptGetDefaultProviderW (ADVAPI32.@)
|
---|
1458 | *
|
---|
1459 | * Finds the default CSP of a certain provider type.
|
---|
1460 | *
|
---|
1461 | * PARAMS
|
---|
1462 | * dwProvType [I] Provider type to look for.
|
---|
1463 | * pdwReserved [I] Reserved for future use and must be NULL.
|
---|
1464 | * dwFlags [I] CRYPT_MACHINE_DEFAULT/USER_DEFAULT
|
---|
1465 | * pszProvName [O] Name of the default CSP.
|
---|
1466 | * pcbProvName [I/O] Size of pszProvName
|
---|
1467 | *
|
---|
1468 | * RETURNS
|
---|
1469 | * Success: TRUE
|
---|
1470 | * Failure: FALSE
|
---|
1471 | *
|
---|
1472 | * NOTES
|
---|
1473 | * If pszProvName is NULL, pcbProvName will hold the size of the buffer for
|
---|
1474 | * memory allocation purposes on return.
|
---|
1475 | */
|
---|
1476 | BOOL WINAPI CryptGetDefaultProviderW (DWORD dwProvType, DWORD *pdwReserved,
|
---|
1477 | DWORD dwFlags, LPWSTR pszProvName, DWORD *pcbProvName)
|
---|
1478 | {
|
---|
1479 | HKEY hKey;
|
---|
1480 | PWSTR keyname;
|
---|
1481 | DWORD result;
|
---|
1482 | static const WCHAR nameW[] = {'N','a','m','e',0};
|
---|
1483 |
|
---|
1484 | if (pdwReserved || !pcbProvName)
|
---|
1485 | {
|
---|
1486 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1487 | return FALSE;
|
---|
1488 | }
|
---|
1489 | if (dwFlags & ~(CRYPT_USER_DEFAULT | CRYPT_MACHINE_DEFAULT))
|
---|
1490 | {
|
---|
1491 | SetLastError(NTE_BAD_FLAGS);
|
---|
1492 | return FALSE;
|
---|
1493 | }
|
---|
1494 | if (dwProvType > 999)
|
---|
1495 | {
|
---|
1496 | SetLastError(NTE_BAD_PROV_TYPE);
|
---|
1497 | return FALSE;
|
---|
1498 | }
|
---|
1499 | if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, dwFlags & CRYPT_USER_DEFAULT)) )
|
---|
1500 | {
|
---|
1501 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1502 | return FALSE;
|
---|
1503 | }
|
---|
1504 | if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE ,keyname, &hKey))
|
---|
1505 | {
|
---|
1506 | CRYPT_Free(keyname);
|
---|
1507 | SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
---|
1508 | return FALSE;
|
---|
1509 | }
|
---|
1510 | CRYPT_Free(keyname);
|
---|
1511 |
|
---|
1512 | result = RegQueryValueExW(hKey, nameW, NULL, NULL, (LPBYTE)pszProvName, pcbProvName);
|
---|
1513 | if (result)
|
---|
1514 | {
|
---|
1515 | if (result != ERROR_MORE_DATA)
|
---|
1516 | SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
---|
1517 | else
|
---|
1518 | SetLastError(result);
|
---|
1519 |
|
---|
1520 | return FALSE;
|
---|
1521 | }
|
---|
1522 |
|
---|
1523 | RegCloseKey(hKey);
|
---|
1524 | return TRUE;
|
---|
1525 | }
|
---|
1526 |
|
---|
1527 | /******************************************************************************
|
---|
1528 | * CryptGetDefaultProviderA (ADVAPI32.@)
|
---|
1529 | *
|
---|
1530 | * See CryptGetDefaultProviderW.
|
---|
1531 | */
|
---|
1532 | BOOL WINAPI CryptGetDefaultProviderA (DWORD dwProvType, DWORD *pdwReserved,
|
---|
1533 | DWORD dwFlags, LPSTR pszProvName, DWORD *pcbProvName)
|
---|
1534 | {
|
---|
1535 | PWSTR str = NULL;
|
---|
1536 | DWORD bufsize;
|
---|
1537 | BOOL ret = FALSE;
|
---|
1538 |
|
---|
1539 | TRACE("(%d, %p, %08x, %p, %p)\n", dwProvType, pdwReserved, dwFlags, pszProvName, pcbProvName);
|
---|
1540 |
|
---|
1541 | CryptGetDefaultProviderW(dwProvType, pdwReserved, dwFlags, NULL, &bufsize);
|
---|
1542 | if ( pszProvName && !(str = CRYPT_Alloc(bufsize)) )
|
---|
1543 | {
|
---|
1544 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1545 | return FALSE;
|
---|
1546 | }
|
---|
1547 | ret = CryptGetDefaultProviderW(dwProvType, pdwReserved, dwFlags, str, &bufsize);
|
---|
1548 | if (str)
|
---|
1549 | CRYPT_UnicodeToANSI(str, &pszProvName, *pcbProvName);
|
---|
1550 | *pcbProvName = bufsize / sizeof(WCHAR);
|
---|
1551 | if (str)
|
---|
1552 | {
|
---|
1553 | CRYPT_Free(str);
|
---|
1554 | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
---|
1555 | {
|
---|
1556 | SetLastError(ERROR_MORE_DATA);
|
---|
1557 | return FALSE;
|
---|
1558 | }
|
---|
1559 | }
|
---|
1560 | return ret;
|
---|
1561 | }
|
---|
1562 |
|
---|
1563 | /******************************************************************************
|
---|
1564 | * CryptGetHashParam (ADVAPI32.@)
|
---|
1565 | *
|
---|
1566 | * Retrieves data that controls the operations of a hash object.
|
---|
1567 | *
|
---|
1568 | * PARAMS
|
---|
1569 | * hHash [I] Handle of the hash object to question.
|
---|
1570 | * dwParam [I] Query type.
|
---|
1571 | * pbData [O] Buffer that receives the value data.
|
---|
1572 | * pdwDataLen [I/O] Size of the pbData buffer.
|
---|
1573 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
1574 | *
|
---|
1575 | * RETURNS
|
---|
1576 | * Success: TRUE
|
---|
1577 | * Failure: FALSE
|
---|
1578 | *
|
---|
1579 | * NOTES
|
---|
1580 | * If pbData is NULL, pdwDataLen will contain the length required.
|
---|
1581 | */
|
---|
1582 | BOOL WINAPI CryptGetHashParam (HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData,
|
---|
1583 | DWORD *pdwDataLen, DWORD dwFlags)
|
---|
1584 | {
|
---|
1585 | PCRYPTPROV prov;
|
---|
1586 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1587 |
|
---|
1588 | TRACE("(0x%lx, %d, %p, %p, %08x)\n", hHash, dwParam, pbData, pdwDataLen, dwFlags);
|
---|
1589 |
|
---|
1590 | if (!hash || !pdwDataLen || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1591 | {
|
---|
1592 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1593 | return FALSE;
|
---|
1594 | }
|
---|
1595 |
|
---|
1596 | prov = hash->pProvider;
|
---|
1597 | return prov->pFuncs->pCPGetHashParam(prov->hPrivate, hash->hPrivate, dwParam,
|
---|
1598 | pbData, pdwDataLen, dwFlags);
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 | /******************************************************************************
|
---|
1602 | * CryptGetKeyParam (ADVAPI32.@)
|
---|
1603 | *
|
---|
1604 | * Retrieves data that controls the operations of a key.
|
---|
1605 | *
|
---|
1606 | * PARAMS
|
---|
1607 | * hKey [I] Handle to they key in question.
|
---|
1608 | * dwParam [I] Specifies query type.
|
---|
1609 | * pbData [O] Sequence of bytes to receive data.
|
---|
1610 | * pdwDataLen [I/O] Size of pbData.
|
---|
1611 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
1612 | *
|
---|
1613 | * RETURNS
|
---|
1614 | * Success: TRUE
|
---|
1615 | * Failure: FALSE
|
---|
1616 | *
|
---|
1617 | * NOTES
|
---|
1618 | * If pbData is NULL, pdwDataLen is set to the needed length of the buffer.
|
---|
1619 | */
|
---|
1620 | BOOL WINAPI CryptGetKeyParam (HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData,
|
---|
1621 | DWORD *pdwDataLen, DWORD dwFlags)
|
---|
1622 | {
|
---|
1623 | PCRYPTPROV prov;
|
---|
1624 | PCRYPTKEY key = (PCRYPTKEY)hKey;
|
---|
1625 |
|
---|
1626 | TRACE("(0x%lx, %d, %p, %p, %08x)\n", hKey, dwParam, pbData, pdwDataLen, dwFlags);
|
---|
1627 |
|
---|
1628 | if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1629 | {
|
---|
1630 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1631 | return FALSE;
|
---|
1632 | }
|
---|
1633 |
|
---|
1634 | prov = key->pProvider;
|
---|
1635 | return prov->pFuncs->pCPGetKeyParam(prov->hPrivate, key->hPrivate, dwParam,
|
---|
1636 | pbData, pdwDataLen, dwFlags);
|
---|
1637 | }
|
---|
1638 |
|
---|
1639 | /******************************************************************************
|
---|
1640 | * CryptGetProvParam (ADVAPI32.@)
|
---|
1641 | *
|
---|
1642 | * Retrieves parameters that control the operations of a CSP.
|
---|
1643 | *
|
---|
1644 | * PARAMS
|
---|
1645 | * hProv [I] Handle of the CSP in question.
|
---|
1646 | * dwParam [I] Specifies query type.
|
---|
1647 | * pbData [O] Buffer to receive the data.
|
---|
1648 | * pdwDataLen [I/O] Size of pbData.
|
---|
1649 | * dwFlags [I] see MSDN Docs.
|
---|
1650 | *
|
---|
1651 | * RETURNS
|
---|
1652 | * Success: TRUE
|
---|
1653 | * Failure: FALSE
|
---|
1654 | *
|
---|
1655 | * NOTES
|
---|
1656 | * If pbData is NULL, pdwDataLen is set to the needed buffer length.
|
---|
1657 | */
|
---|
1658 | BOOL WINAPI CryptGetProvParam (HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData,
|
---|
1659 | DWORD *pdwDataLen, DWORD dwFlags)
|
---|
1660 | {
|
---|
1661 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
1662 |
|
---|
1663 | TRACE("(0x%lx, %d, %p, %p, %08x)\n", hProv, dwParam, pbData, pdwDataLen, dwFlags);
|
---|
1664 |
|
---|
1665 | if (!prov || prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
1666 | {
|
---|
1667 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1668 | return FALSE;
|
---|
1669 | }
|
---|
1670 |
|
---|
1671 | return prov->pFuncs->pCPGetProvParam(prov->hPrivate, dwParam, pbData, pdwDataLen, dwFlags);
|
---|
1672 | }
|
---|
1673 |
|
---|
1674 | /******************************************************************************
|
---|
1675 | * CryptGetUserKey (ADVAPI32.@)
|
---|
1676 | *
|
---|
1677 | * Gets a handle of one of a user's two public/private key pairs.
|
---|
1678 | *
|
---|
1679 | * PARAMS
|
---|
1680 | * hProv [I] Handle of a CSP.
|
---|
1681 | * dwKeySpec [I] Private key to use.
|
---|
1682 | * phUserKey [O] Pointer to the handle of the retrieved keys.
|
---|
1683 | *
|
---|
1684 | * RETURNS
|
---|
1685 | * Success: TRUE
|
---|
1686 | * Failure: FALSE
|
---|
1687 | */
|
---|
1688 | BOOL WINAPI CryptGetUserKey (HCRYPTPROV hProv, DWORD dwKeySpec, HCRYPTKEY *phUserKey)
|
---|
1689 | {
|
---|
1690 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
1691 | PCRYPTKEY key;
|
---|
1692 |
|
---|
1693 | TRACE("(0x%lx, %d, %p)\n", hProv, dwKeySpec, phUserKey);
|
---|
1694 |
|
---|
1695 | if (!prov)
|
---|
1696 | {
|
---|
1697 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
1698 | return FALSE;
|
---|
1699 | }
|
---|
1700 | if (!phUserKey || prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
1701 | {
|
---|
1702 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1703 | return FALSE;
|
---|
1704 | }
|
---|
1705 | if ( !(key = CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
---|
1706 | {
|
---|
1707 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1708 | return FALSE;
|
---|
1709 | }
|
---|
1710 |
|
---|
1711 | key->pProvider = prov;
|
---|
1712 |
|
---|
1713 | if (prov->pFuncs->pCPGetUserKey(prov->hPrivate, dwKeySpec, &key->hPrivate))
|
---|
1714 | {
|
---|
1715 | *phUserKey = (HCRYPTKEY)key;
|
---|
1716 | return TRUE;
|
---|
1717 | }
|
---|
1718 |
|
---|
1719 | /* CSP Error */
|
---|
1720 | CRYPT_Free(key);
|
---|
1721 | *phUserKey = 0;
|
---|
1722 | return FALSE;
|
---|
1723 | }
|
---|
1724 |
|
---|
1725 | /******************************************************************************
|
---|
1726 | * CryptHashData (ADVAPI32.@)
|
---|
1727 | *
|
---|
1728 | * Adds data to a hash object.
|
---|
1729 | *
|
---|
1730 | * PARAMS
|
---|
1731 | * hHash [I] Handle of the hash object.
|
---|
1732 | * pbData [I] Buffer of data to be hashed.
|
---|
1733 | * dwDataLen [I] Number of bytes to add.
|
---|
1734 | * dwFlags [I] Can be CRYPT_USERDATA
|
---|
1735 | *
|
---|
1736 | * RETURNS
|
---|
1737 | * Success: TRUE
|
---|
1738 | * Failure: FALSE
|
---|
1739 | */
|
---|
1740 | BOOL WINAPI CryptHashData (HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
|
---|
1741 | {
|
---|
1742 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1743 | PCRYPTPROV prov;
|
---|
1744 |
|
---|
1745 | TRACE("(0x%lx, %p, %d, %08x)\n", hHash, pbData, dwDataLen, dwFlags);
|
---|
1746 |
|
---|
1747 | if (!hash)
|
---|
1748 | {
|
---|
1749 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
1750 | return FALSE;
|
---|
1751 | }
|
---|
1752 | if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1753 | {
|
---|
1754 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1755 | return FALSE;
|
---|
1756 | }
|
---|
1757 |
|
---|
1758 | prov = hash->pProvider;
|
---|
1759 | return prov->pFuncs->pCPHashData(prov->hPrivate, hash->hPrivate, pbData, dwDataLen, dwFlags);
|
---|
1760 | }
|
---|
1761 |
|
---|
1762 | /******************************************************************************
|
---|
1763 | * CryptHashSessionKey (ADVAPI32.@)
|
---|
1764 | *
|
---|
1765 | * Compute the cryptographic hash of a session key object.
|
---|
1766 | *
|
---|
1767 | * PARAMS
|
---|
1768 | * hHash [I] Handle to the hash object.
|
---|
1769 | * hKey [I] Handle to the key to be hashed.
|
---|
1770 | * dwFlags [I] Can be CRYPT_LITTLE_ENDIAN.
|
---|
1771 | *
|
---|
1772 | * RETURNS
|
---|
1773 | * Success: TRUE
|
---|
1774 | * Failure: FALSE
|
---|
1775 | */
|
---|
1776 | BOOL WINAPI CryptHashSessionKey (HCRYPTHASH hHash, HCRYPTKEY hKey, DWORD dwFlags)
|
---|
1777 | {
|
---|
1778 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1779 | PCRYPTKEY key = (PCRYPTKEY)hKey;
|
---|
1780 | PCRYPTPROV prov;
|
---|
1781 |
|
---|
1782 | TRACE("(0x%lx, 0x%lx, %08x)\n", hHash, hKey, dwFlags);
|
---|
1783 |
|
---|
1784 | if (!hash || !key)
|
---|
1785 | {
|
---|
1786 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
1787 | return FALSE;
|
---|
1788 | }
|
---|
1789 |
|
---|
1790 | if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1791 | {
|
---|
1792 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1793 | return FALSE;
|
---|
1794 | }
|
---|
1795 |
|
---|
1796 | prov = hash->pProvider;
|
---|
1797 | return prov->pFuncs->pCPHashSessionKey(prov->hPrivate, hash->hPrivate, key->hPrivate, dwFlags);
|
---|
1798 | }
|
---|
1799 |
|
---|
1800 | /******************************************************************************
|
---|
1801 | * CryptImportKey (ADVAPI32.@)
|
---|
1802 | *
|
---|
1803 | * Transfer a cryptographic key from a key BLOB into a cryptographic service provider (CSP).
|
---|
1804 | *
|
---|
1805 | * PARAMS
|
---|
1806 | * hProv [I] Handle of a CSP.
|
---|
1807 | * pbData [I] Contains the key to be imported.
|
---|
1808 | * dwDataLen [I] Length of the key.
|
---|
1809 | * hPubKey [I] Cryptographic key that decrypts pdData
|
---|
1810 | * dwFlags [I] Used only with a public/private key pair.
|
---|
1811 | * phKey [O] Imported key.
|
---|
1812 | *
|
---|
1813 | * RETURNS
|
---|
1814 | * Success: TRUE
|
---|
1815 | * Failure: FALSE
|
---|
1816 | */
|
---|
1817 | BOOL WINAPI CryptImportKey (HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
|
---|
1818 | HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
|
---|
1819 | {
|
---|
1820 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
1821 | PCRYPTKEY pubkey = (PCRYPTKEY)hPubKey, importkey;
|
---|
1822 |
|
---|
1823 | TRACE("(0x%lx, %p, %d, 0x%lx, %08x, %p)\n", hProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
|
---|
1824 |
|
---|
1825 | if (!prov || !pbData || !dwDataLen || !phKey || prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
1826 | {
|
---|
1827 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1828 | return FALSE;
|
---|
1829 | }
|
---|
1830 |
|
---|
1831 | if ( !(importkey = CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
---|
1832 | {
|
---|
1833 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1834 | return FALSE;
|
---|
1835 | }
|
---|
1836 |
|
---|
1837 | importkey->pProvider = prov;
|
---|
1838 | if (prov->pFuncs->pCPImportKey(prov->hPrivate, pbData, dwDataLen,
|
---|
1839 | pubkey ? pubkey->hPrivate : 0, dwFlags, &importkey->hPrivate))
|
---|
1840 | {
|
---|
1841 | *phKey = (HCRYPTKEY)importkey;
|
---|
1842 | return TRUE;
|
---|
1843 | }
|
---|
1844 |
|
---|
1845 | CRYPT_Free(importkey);
|
---|
1846 | return FALSE;
|
---|
1847 | }
|
---|
1848 |
|
---|
1849 | /******************************************************************************
|
---|
1850 | * CryptSignHashW (ADVAPI32.@)
|
---|
1851 | *
|
---|
1852 | * Signs data.
|
---|
1853 | *
|
---|
1854 | * PARAMS
|
---|
1855 | * hHash [I] Handle of the hash object to be signed.
|
---|
1856 | * dwKeySpec [I] Private key to use.
|
---|
1857 | * sDescription [I] Should be NULL.
|
---|
1858 | * dwFlags [I] CRYPT_NOHASHOID/X931_FORMAT.
|
---|
1859 | * pbSignature [O] Buffer of the signature data.
|
---|
1860 | * pdwSigLen [I/O] Size of the pbSignature buffer.
|
---|
1861 | *
|
---|
1862 | * RETURNS
|
---|
1863 | * Success: TRUE
|
---|
1864 | * Failure: FALSE
|
---|
1865 | *
|
---|
1866 | * NOTES
|
---|
1867 | * Because of security flaws sDescription should not be used and should thus be
|
---|
1868 | * NULL. It is supported only for compatibility with Microsoft's Cryptographic
|
---|
1869 | * Providers.
|
---|
1870 | */
|
---|
1871 | BOOL WINAPI CryptSignHashW (HCRYPTHASH hHash, DWORD dwKeySpec, LPCWSTR sDescription,
|
---|
1872 | DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
|
---|
1873 | {
|
---|
1874 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1875 | PCRYPTPROV prov;
|
---|
1876 |
|
---|
1877 | TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
|
---|
1878 | hHash, dwKeySpec, debugstr_w(sDescription), dwFlags, pbSignature, pdwSigLen);
|
---|
1879 |
|
---|
1880 | if (!hash)
|
---|
1881 | {
|
---|
1882 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
1883 | return FALSE;
|
---|
1884 | }
|
---|
1885 | if (!pdwSigLen || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1886 | {
|
---|
1887 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1888 | return FALSE;
|
---|
1889 | }
|
---|
1890 |
|
---|
1891 | prov = hash->pProvider;
|
---|
1892 | return prov->pFuncs->pCPSignHash(prov->hPrivate, hash->hPrivate, dwKeySpec, sDescription,
|
---|
1893 | dwFlags, pbSignature, pdwSigLen);
|
---|
1894 | }
|
---|
1895 |
|
---|
1896 | /******************************************************************************
|
---|
1897 | * CryptSignHashA (ADVAPI32.@)
|
---|
1898 | *
|
---|
1899 | * See CryptSignHashW.
|
---|
1900 | */
|
---|
1901 | BOOL WINAPI CryptSignHashA (HCRYPTHASH hHash, DWORD dwKeySpec, LPCSTR sDescription,
|
---|
1902 | DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
|
---|
1903 | {
|
---|
1904 | LPWSTR wsDescription;
|
---|
1905 | BOOL result;
|
---|
1906 |
|
---|
1907 | TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
|
---|
1908 | hHash, dwKeySpec, debugstr_a(sDescription), dwFlags, pbSignature, pdwSigLen);
|
---|
1909 |
|
---|
1910 | CRYPT_ANSIToUnicode(sDescription, &wsDescription, -1);
|
---|
1911 | result = CryptSignHashW(hHash, dwKeySpec, wsDescription, dwFlags, pbSignature, pdwSigLen);
|
---|
1912 | CRYPT_Free(wsDescription);
|
---|
1913 |
|
---|
1914 | return result;
|
---|
1915 | }
|
---|
1916 |
|
---|
1917 | /******************************************************************************
|
---|
1918 | * CryptSetHashParam (ADVAPI32.@)
|
---|
1919 | *
|
---|
1920 | * Customizes the operations of a hash object.
|
---|
1921 | *
|
---|
1922 | * PARAMS
|
---|
1923 | * hHash [I] Handle of the hash object to set parameters.
|
---|
1924 | * dwParam [I] HP_HMAC_INFO/HASHVAL.
|
---|
1925 | * pbData [I] Value data buffer.
|
---|
1926 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
1927 | *
|
---|
1928 | * RETURNS
|
---|
1929 | * Success: TRUE
|
---|
1930 | * Failure: FALSE
|
---|
1931 | */
|
---|
1932 | BOOL WINAPI CryptSetHashParam (HCRYPTHASH hHash, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
|
---|
1933 | {
|
---|
1934 | PCRYPTPROV prov;
|
---|
1935 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1936 |
|
---|
1937 | TRACE("(0x%lx, %d, %p, %08x)\n", hHash, dwParam, pbData, dwFlags);
|
---|
1938 |
|
---|
1939 | if (!hash || !pbData || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1940 | {
|
---|
1941 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1942 | return FALSE;
|
---|
1943 | }
|
---|
1944 |
|
---|
1945 | prov = hash->pProvider;
|
---|
1946 | return prov->pFuncs->pCPSetHashParam(prov->hPrivate, hash->hPrivate,
|
---|
1947 | dwParam, pbData, dwFlags);
|
---|
1948 | }
|
---|
1949 |
|
---|
1950 | /******************************************************************************
|
---|
1951 | * CryptSetKeyParam (ADVAPI32.@)
|
---|
1952 | *
|
---|
1953 | * Customizes a session key's operations.
|
---|
1954 | *
|
---|
1955 | * PARAMS
|
---|
1956 | * hKey [I] Handle to the key to set values.
|
---|
1957 | * dwParam [I] See MSDN Doc.
|
---|
1958 | * pbData [I] Buffer of values to set.
|
---|
1959 | * dwFlags [I] Only used when dwParam == KP_ALGID.
|
---|
1960 | *
|
---|
1961 | * RETURNS
|
---|
1962 | * Success: TRUE
|
---|
1963 | * Failure: FALSE
|
---|
1964 | */
|
---|
1965 | BOOL WINAPI CryptSetKeyParam (HCRYPTKEY hKey, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
|
---|
1966 | {
|
---|
1967 | PCRYPTPROV prov;
|
---|
1968 | PCRYPTKEY key = (PCRYPTKEY)hKey;
|
---|
1969 |
|
---|
1970 | TRACE("(0x%lx, %d, %p, %08x)\n", hKey, dwParam, pbData, dwFlags);
|
---|
1971 |
|
---|
1972 | if (!key || !pbData || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1973 | {
|
---|
1974 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1975 | return FALSE;
|
---|
1976 | }
|
---|
1977 |
|
---|
1978 | prov = key->pProvider;
|
---|
1979 | return prov->pFuncs->pCPSetKeyParam(prov->hPrivate, key->hPrivate,
|
---|
1980 | dwParam, pbData, dwFlags);
|
---|
1981 | }
|
---|
1982 |
|
---|
1983 | /******************************************************************************
|
---|
1984 | * CryptSetProviderA (ADVAPI32.@)
|
---|
1985 | *
|
---|
1986 | * Specifies the current user's default CSP.
|
---|
1987 | *
|
---|
1988 | * PARAMS
|
---|
1989 | * pszProvName [I] Name of the new default CSP.
|
---|
1990 | * dwProvType [I] Provider type of the CSP.
|
---|
1991 | *
|
---|
1992 | * RETURNS
|
---|
1993 | * Success: TRUE
|
---|
1994 | * Failure: FALSE
|
---|
1995 | */
|
---|
1996 | BOOL WINAPI CryptSetProviderA (LPCSTR pszProvName, DWORD dwProvType)
|
---|
1997 | {
|
---|
1998 | TRACE("(%s, %d)\n", pszProvName, dwProvType);
|
---|
1999 | return CryptSetProviderExA(pszProvName, dwProvType, NULL, CRYPT_USER_DEFAULT);
|
---|
2000 | }
|
---|
2001 |
|
---|
2002 | /******************************************************************************
|
---|
2003 | * CryptSetProviderW (ADVAPI32.@)
|
---|
2004 | *
|
---|
2005 | * See CryptSetProviderA.
|
---|
2006 | */
|
---|
2007 | BOOL WINAPI CryptSetProviderW (LPCWSTR pszProvName, DWORD dwProvType)
|
---|
2008 | {
|
---|
2009 | TRACE("(%s, %d)\n", debugstr_w(pszProvName), dwProvType);
|
---|
2010 | return CryptSetProviderExW(pszProvName, dwProvType, NULL, CRYPT_USER_DEFAULT);
|
---|
2011 | }
|
---|
2012 |
|
---|
2013 | /******************************************************************************
|
---|
2014 | * CryptSetProviderExW (ADVAPI32.@)
|
---|
2015 | *
|
---|
2016 | * Specifies the default CSP.
|
---|
2017 | *
|
---|
2018 | * PARAMS
|
---|
2019 | * pszProvName [I] Name of the new default CSP.
|
---|
2020 | * dwProvType [I] Provider type of the CSP.
|
---|
2021 | * pdwReserved [I] Reserved for future use and must be NULL.
|
---|
2022 | * dwFlags [I] See MSDN Doc.
|
---|
2023 | *
|
---|
2024 | * RETURNS
|
---|
2025 | * Success: TRUE
|
---|
2026 | * Failure: FALSE
|
---|
2027 | */
|
---|
2028 | BOOL WINAPI CryptSetProviderExW (LPCWSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
|
---|
2029 | {
|
---|
2030 | HKEY hProvKey, hTypeKey;
|
---|
2031 | PWSTR keyname;
|
---|
2032 | static const WCHAR nameW[] = {'N','a','m','e',0};
|
---|
2033 |
|
---|
2034 | TRACE("(%s, %d, %p, %08x)\n", debugstr_w(pszProvName), dwProvType, pdwReserved, dwFlags);
|
---|
2035 |
|
---|
2036 | if (!pszProvName || pdwReserved)
|
---|
2037 | {
|
---|
2038 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2039 | return FALSE;
|
---|
2040 | }
|
---|
2041 | if (dwProvType > MAXPROVTYPES)
|
---|
2042 | {
|
---|
2043 | SetLastError(NTE_BAD_PROV_TYPE);
|
---|
2044 | return FALSE;
|
---|
2045 | }
|
---|
2046 | if (dwFlags & ~(CRYPT_MACHINE_DEFAULT | CRYPT_USER_DEFAULT | CRYPT_DELETE_DEFAULT)
|
---|
2047 | || dwFlags == CRYPT_DELETE_DEFAULT)
|
---|
2048 | {
|
---|
2049 | SetLastError(NTE_BAD_FLAGS);
|
---|
2050 | return FALSE;
|
---|
2051 | }
|
---|
2052 |
|
---|
2053 | if (!(keyname = CRYPT_GetTypeKeyName(dwProvType, dwFlags & CRYPT_USER_DEFAULT)))
|
---|
2054 | {
|
---|
2055 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
2056 | return FALSE;
|
---|
2057 | }
|
---|
2058 | if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
---|
2059 | keyname, &hTypeKey))
|
---|
2060 | {
|
---|
2061 | CRYPT_Free(keyname);
|
---|
2062 | SetLastError(NTE_BAD_PROVIDER);
|
---|
2063 | return FALSE;
|
---|
2064 | }
|
---|
2065 | CRYPT_Free(keyname);
|
---|
2066 |
|
---|
2067 | if (dwFlags & CRYPT_DELETE_DEFAULT)
|
---|
2068 | {
|
---|
2069 | RegDeleteValueW(hTypeKey, nameW);
|
---|
2070 | }
|
---|
2071 | else
|
---|
2072 | {
|
---|
2073 | if (!(keyname = CRYPT_GetProvKeyName(pszProvName)))
|
---|
2074 | {
|
---|
2075 | RegCloseKey(hTypeKey);
|
---|
2076 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
2077 | return FALSE;
|
---|
2078 | }
|
---|
2079 | if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
---|
2080 | keyname, &hProvKey))
|
---|
2081 | {
|
---|
2082 | CRYPT_Free(keyname);
|
---|
2083 | RegCloseKey(hTypeKey);
|
---|
2084 | SetLastError(NTE_BAD_PROVIDER);
|
---|
2085 | return FALSE;
|
---|
2086 | }
|
---|
2087 | CRYPT_Free(keyname);
|
---|
2088 |
|
---|
2089 | if (RegSetValueExW(hTypeKey, nameW, 0, REG_SZ, (const BYTE *)pszProvName,
|
---|
2090 | (strlenW(pszProvName) + 1)*sizeof(WCHAR)))
|
---|
2091 | {
|
---|
2092 | RegCloseKey(hTypeKey);
|
---|
2093 | RegCloseKey(hProvKey);
|
---|
2094 | return FALSE;
|
---|
2095 | }
|
---|
2096 |
|
---|
2097 | RegCloseKey(hProvKey);
|
---|
2098 | }
|
---|
2099 | RegCloseKey(hTypeKey);
|
---|
2100 |
|
---|
2101 | return TRUE;
|
---|
2102 | }
|
---|
2103 |
|
---|
2104 | /******************************************************************************
|
---|
2105 | * CryptSetProviderExA (ADVAPI32.@)
|
---|
2106 | *
|
---|
2107 | * See CryptSetProviderExW.
|
---|
2108 | */
|
---|
2109 | BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
|
---|
2110 | {
|
---|
2111 | BOOL ret = FALSE;
|
---|
2112 | PWSTR str = NULL;
|
---|
2113 |
|
---|
2114 | TRACE("(%s, %d, %p, %08x)\n", pszProvName, dwProvType, pdwReserved, dwFlags);
|
---|
2115 |
|
---|
2116 | if (CRYPT_ANSIToUnicode(pszProvName, &str, -1))
|
---|
2117 | {
|
---|
2118 | ret = CryptSetProviderExW(str, dwProvType, pdwReserved, dwFlags);
|
---|
2119 | CRYPT_Free(str);
|
---|
2120 | }
|
---|
2121 | return ret;
|
---|
2122 | }
|
---|
2123 |
|
---|
2124 | /******************************************************************************
|
---|
2125 | * CryptSetProvParam (ADVAPI32.@)
|
---|
2126 | *
|
---|
2127 | * Customizes the operations of a CSP.
|
---|
2128 | *
|
---|
2129 | * PARAMS
|
---|
2130 | * hProv [I] Handle of a CSP.
|
---|
2131 | * dwParam [I] See MSDN Doc.
|
---|
2132 | * pbData [I] Buffer that contains a value to set as a parameter.
|
---|
2133 | * dwFlags [I] if dwParam is PP_USE_HARDWARE_RNG, dwFlags must be zero.
|
---|
2134 | *
|
---|
2135 | * RETURNS
|
---|
2136 | * Success: TRUE
|
---|
2137 | * Failure: FALSE
|
---|
2138 | */
|
---|
2139 | BOOL WINAPI CryptSetProvParam (HCRYPTPROV hProv, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
|
---|
2140 | {
|
---|
2141 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
2142 |
|
---|
2143 | TRACE("(0x%lx, %d, %p, %08x)\n", hProv, dwParam, pbData, dwFlags);
|
---|
2144 |
|
---|
2145 | if (!prov)
|
---|
2146 | {
|
---|
2147 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
2148 | return FALSE;
|
---|
2149 | }
|
---|
2150 | if (prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
2151 | {
|
---|
2152 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2153 | return FALSE;
|
---|
2154 | }
|
---|
2155 | if (dwFlags & PP_USE_HARDWARE_RNG)
|
---|
2156 | {
|
---|
2157 | FIXME("PP_USE_HARDWARE_RNG: What do I do with this?\n");
|
---|
2158 | FIXME("\tLetting the CSP decide.\n");
|
---|
2159 | }
|
---|
2160 | if (dwFlags & PP_CLIENT_HWND)
|
---|
2161 | {
|
---|
2162 | /* FIXME: Should verify the parameter */
|
---|
2163 | if (pbData /* && IsWindow((HWND)pbData) */)
|
---|
2164 | {
|
---|
2165 | crypt_hWindow = (HWND)(pbData);
|
---|
2166 | return TRUE;
|
---|
2167 | } else {
|
---|
2168 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2169 | return FALSE;
|
---|
2170 | }
|
---|
2171 | }
|
---|
2172 | /* All other flags go to the CSP */
|
---|
2173 | return prov->pFuncs->pCPSetProvParam(prov->hPrivate, dwParam, pbData, dwFlags);
|
---|
2174 | }
|
---|
2175 |
|
---|
2176 | /******************************************************************************
|
---|
2177 | * CryptVerifySignatureW (ADVAPI32.@)
|
---|
2178 | *
|
---|
2179 | * Verifies the signature of a hash object.
|
---|
2180 | *
|
---|
2181 | * PARAMS
|
---|
2182 | * hHash [I] Handle of the hash object to verify.
|
---|
2183 | * pbSignature [I] Signature data to verify.
|
---|
2184 | * dwSigLen [I] Size of pbSignature.
|
---|
2185 | * hPubKey [I] Handle to the public key to authenticate signature.
|
---|
2186 | * sDescription [I] Should be NULL.
|
---|
2187 | * dwFlags [I] See MSDN doc.
|
---|
2188 | *
|
---|
2189 | * RETURNS
|
---|
2190 | * Success: TRUE
|
---|
2191 | * Failure: FALSE
|
---|
2192 | *
|
---|
2193 | * NOTES
|
---|
2194 | * Because of security flaws sDescription should not be used and should thus be
|
---|
2195 | * NULL. It is supported only for compatibility with Microsoft's Cryptographic
|
---|
2196 | * Providers.
|
---|
2197 | */
|
---|
2198 | BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, CONST BYTE *pbSignature, DWORD dwSigLen,
|
---|
2199 | HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags)
|
---|
2200 | {
|
---|
2201 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
2202 | PCRYPTKEY key = (PCRYPTKEY)hPubKey;
|
---|
2203 | PCRYPTPROV prov;
|
---|
2204 |
|
---|
2205 | TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature,
|
---|
2206 | dwSigLen, hPubKey, debugstr_w(sDescription), dwFlags);
|
---|
2207 |
|
---|
2208 | if (!hash || !key ||
|
---|
2209 | !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV ||
|
---|
2210 | !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
2211 | {
|
---|
2212 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2213 | return FALSE;
|
---|
2214 | }
|
---|
2215 |
|
---|
2216 | prov = hash->pProvider;
|
---|
2217 | return prov->pFuncs->pCPVerifySignature(prov->hPrivate, hash->hPrivate, pbSignature, dwSigLen,
|
---|
2218 | key->hPrivate, sDescription, dwFlags);
|
---|
2219 | }
|
---|
2220 |
|
---|
2221 | /******************************************************************************
|
---|
2222 | * CryptVerifySignatureA (ADVAPI32.@)
|
---|
2223 | *
|
---|
2224 | * See CryptVerifySignatureW.
|
---|
2225 | */
|
---|
2226 | BOOL WINAPI CryptVerifySignatureA (HCRYPTHASH hHash, CONST BYTE *pbSignature, DWORD dwSigLen,
|
---|
2227 | HCRYPTKEY hPubKey, LPCSTR sDescription, DWORD dwFlags)
|
---|
2228 | {
|
---|
2229 | LPWSTR wsDescription;
|
---|
2230 | BOOL result;
|
---|
2231 |
|
---|
2232 | TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature,
|
---|
2233 | dwSigLen, hPubKey, debugstr_a(sDescription), dwFlags);
|
---|
2234 |
|
---|
2235 | CRYPT_ANSIToUnicode(sDescription, &wsDescription, -1);
|
---|
2236 | result = CryptVerifySignatureW(hHash, pbSignature, dwSigLen, hPubKey, wsDescription, dwFlags);
|
---|
2237 | CRYPT_Free(wsDescription);
|
---|
2238 |
|
---|
2239 | return result;
|
---|
2240 | }
|
---|
2241 |
|
---|
2242 | /******************************************************************************
|
---|
2243 | * SystemFunction030 (ADVAPI32.@)
|
---|
2244 | *
|
---|
2245 | * Tests if two blocks of 16 bytes are equal
|
---|
2246 | *
|
---|
2247 | * PARAMS
|
---|
2248 | * b1,b2 [I] block of 16 bytes
|
---|
2249 | *
|
---|
2250 | * RETURNS
|
---|
2251 | * TRUE if blocks are the same
|
---|
2252 | * FALSE if blocks are different
|
---|
2253 | */
|
---|
2254 | BOOL WINAPI SystemFunction030(PVOID b1, PVOID b2)
|
---|
2255 | {
|
---|
2256 | return !memcmp(b1, b2, 0x10);
|
---|
2257 | }
|
---|
2258 |
|
---|
2259 | /******************************************************************************
|
---|
2260 | * SystemFunction035 (ADVAPI32.@)
|
---|
2261 | *
|
---|
2262 | * Described here:
|
---|
2263 | http://disc.server.com/discussion.cgi?disc=148775;article=942;title=Coding%2FASM%2FSystem
|
---|
2264 | *
|
---|
2265 | * NOTES
|
---|
2266 | * Stub, always return TRUE.
|
---|
2267 | */
|
---|
2268 | BOOL WINAPI SystemFunction035(LPCSTR lpszDllFilePath)
|
---|
2269 | {
|
---|
2270 | FIXME("%s: stub\n", debugstr_a(lpszDllFilePath));
|
---|
2271 | return TRUE;
|
---|
2272 | }
|
---|
2273 |
|
---|
2274 | /******************************************************************************
|
---|
2275 | * SystemFunction036 (ADVAPI32.@)
|
---|
2276 | *
|
---|
2277 | * MSDN documents this function as RtlGenRandom and declares it in ntsecapi.h
|
---|
2278 | *
|
---|
2279 | * PARAMS
|
---|
2280 | * pbBufer [O] Pointer to memory to receive random bytes.
|
---|
2281 | * dwLen [I] Number of random bytes to fetch.
|
---|
2282 | *
|
---|
2283 | * RETURNS
|
---|
2284 | * Success: TRUE
|
---|
2285 | * Failure: FALSE
|
---|
2286 | */
|
---|
2287 |
|
---|
2288 | BOOL WINAPI SystemFunction036(PVOID pbBuffer, ULONG dwLen)
|
---|
2289 | {
|
---|
2290 | int dev_random;
|
---|
2291 | #if 0
|
---|
2292 | dev_random = open("/dev/urandom", O_RDONLY);
|
---|
2293 | if (dev_random != -1)
|
---|
2294 | {
|
---|
2295 | if (read(dev_random, pbBuffer, dwLen) == dwLen)
|
---|
2296 | {
|
---|
2297 | close(dev_random);
|
---|
2298 | return TRUE;
|
---|
2299 | }
|
---|
2300 | close(dev_random);
|
---|
2301 | }
|
---|
2302 | else
|
---|
2303 | FIXME("couldn't open /dev/urandom\n");
|
---|
2304 | #endif
|
---|
2305 | SetLastError(NTE_FAIL);
|
---|
2306 | return FALSE;
|
---|
2307 | }
|
---|
2308 |
|
---|
2309 | /*
|
---|
2310 | These functions have nearly identical prototypes to CryptProtectMemory and CryptUnprotectMemory,
|
---|
2311 | in crypt32.dll.
|
---|
2312 | */
|
---|
2313 |
|
---|
2314 | /******************************************************************************
|
---|
2315 | * SystemFunction040 (ADVAPI32.@)
|
---|
2316 | *
|
---|
2317 | * MSDN documents this function as RtlEncryptMemory.
|
---|
2318 | *
|
---|
2319 | * PARAMS
|
---|
2320 | * memory [I/O] Pointer to memory to encrypt.
|
---|
2321 | * length [I] Length of region to encrypt in bytes.
|
---|
2322 | * flags [I] Control whether other processes are able to decrypt the memory.
|
---|
2323 | * RTL_ENCRYPT_OPTION_SAME_PROCESS
|
---|
2324 | * RTL_ENCRYPT_OPTION_CROSS_PROCESS
|
---|
2325 | * RTL_ENCRYPT_OPTION_SAME_LOGON
|
---|
2326 | *
|
---|
2327 | * RETURNS
|
---|
2328 | * Success: STATUS_SUCCESS
|
---|
2329 | * Failure: NTSTATUS error code
|
---|
2330 | *
|
---|
2331 | * NOTES
|
---|
2332 | * length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
|
---|
2333 | * If flags are specified when encrypting, the same flag value must be given
|
---|
2334 | * when decrypting the memory.
|
---|
2335 | */
|
---|
2336 | NTSTATUS WINAPI SystemFunction040(PVOID memory, ULONG length, ULONG flags)
|
---|
2337 | {
|
---|
2338 | FIXME("(%p, %x, %x): stub [RtlEncryptMemory]\n", memory, length, flags);
|
---|
2339 | return STATUS_SUCCESS;
|
---|
2340 | }
|
---|
2341 |
|
---|
2342 | /******************************************************************************
|
---|
2343 | * SystemFunction041 (ADVAPI32.@)
|
---|
2344 | *
|
---|
2345 | * MSDN documents this function as RtlDecryptMemory.
|
---|
2346 | *
|
---|
2347 | * PARAMS
|
---|
2348 | * memory [I/O] Pointer to memory to decrypt.
|
---|
2349 | * length [I] Length of region to decrypt in bytes.
|
---|
2350 | * flags [I] Control whether other processes are able to decrypt the memory.
|
---|
2351 | * RTL_ENCRYPT_OPTION_SAME_PROCESS
|
---|
2352 | * RTL_ENCRYPT_OPTION_CROSS_PROCESS
|
---|
2353 | * RTL_ENCRYPT_OPTION_SAME_LOGON
|
---|
2354 | *
|
---|
2355 | * RETURNS
|
---|
2356 | * Success: STATUS_SUCCESS
|
---|
2357 | * Failure: NTSTATUS error code
|
---|
2358 | *
|
---|
2359 | * NOTES
|
---|
2360 | * length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
|
---|
2361 | * If flags are specified when encrypting, the same flag value must be given
|
---|
2362 | * when decrypting the memory.
|
---|
2363 | */
|
---|
2364 | NTSTATUS WINAPI SystemFunction041(PVOID memory, ULONG length, ULONG flags)
|
---|
2365 | {
|
---|
2366 | FIXME("(%p, %x, %x): stub [RtlDecryptMemory]\n", memory, length, flags);
|
---|
2367 | return STATUS_SUCCESS;
|
---|
2368 | }
|
---|