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 = (fn##name *)GetProcAddress(provider->hModule, #name)) ) goto error
|
---|
203 | #define CRYPT_GetProvFuncOpt(name) \
|
---|
204 | provider->pFuncs->p##name = (fn##name *)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 = (PCRYPTPROV)CRYPT_Alloc(sizeof(CRYPTPROV))) ) goto error;
|
---|
211 | if ( !(provider->pFuncs = (PPROVFUNCS)CRYPT_Alloc(sizeof(PROVFUNCS))) ) goto error;
|
---|
212 | if ( !(provider->pVTable = (PVTableProvStruc)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 | (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 = (PWSTR)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 = (PWSTR)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 = (PWSTR)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 = (PWSTR)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 = (PCRYPTHASH)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 = (PCRYPTKEY)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 = (PCRYPTHASH)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 = (PCRYPTKEY)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 | dprintf(("CryptEnumProvidersW error. cannot open key"));
|
---|
1150 | SetLastError(NTE_FAIL);
|
---|
1151 | return FALSE;
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 | if (!pszProvName)
|
---|
1155 | {
|
---|
1156 | DWORD numkeys;
|
---|
1157 | WCHAR *provNameW;
|
---|
1158 |
|
---|
1159 | RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &numkeys, pcbProvName,
|
---|
1160 | NULL, NULL, NULL, NULL, NULL, NULL);
|
---|
1161 |
|
---|
1162 | if (!(provNameW = (WCHAR *)CRYPT_Alloc(*pcbProvName * sizeof(WCHAR))))
|
---|
1163 | {
|
---|
1164 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1165 | return FALSE;
|
---|
1166 | }
|
---|
1167 |
|
---|
1168 | RegEnumKeyExW(hKey, dwIndex, provNameW, pcbProvName, NULL, NULL, NULL, NULL);
|
---|
1169 | CRYPT_Free(provNameW);
|
---|
1170 | (*pcbProvName)++;
|
---|
1171 | *pcbProvName *= sizeof(WCHAR);
|
---|
1172 |
|
---|
1173 | if (dwIndex >= numkeys)
|
---|
1174 | {
|
---|
1175 | SetLastError(ERROR_NO_MORE_ITEMS);
|
---|
1176 | return FALSE;
|
---|
1177 | }
|
---|
1178 | } else {
|
---|
1179 | DWORD size = sizeof(DWORD);
|
---|
1180 | DWORD result;
|
---|
1181 | HKEY subkey;
|
---|
1182 |
|
---|
1183 | result = RegEnumKeyW(hKey, dwIndex, pszProvName, *pcbProvName / sizeof(WCHAR));
|
---|
1184 | if (result)
|
---|
1185 | {
|
---|
1186 | SetLastError(result);
|
---|
1187 | return FALSE;
|
---|
1188 | }
|
---|
1189 | if (RegOpenKeyW(hKey, pszProvName, &subkey))
|
---|
1190 | return FALSE;
|
---|
1191 | if (RegQueryValueExW(subkey, typeW, NULL, NULL, (BYTE*)pdwProvType, &size))
|
---|
1192 | return FALSE;
|
---|
1193 | RegCloseKey(subkey);
|
---|
1194 | }
|
---|
1195 | RegCloseKey(hKey);
|
---|
1196 | return TRUE;
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | /******************************************************************************
|
---|
1200 | * CryptEnumProvidersA (ADVAPI32.@)
|
---|
1201 | *
|
---|
1202 | * See CryptEnumProvidersW.
|
---|
1203 | */
|
---|
1204 | BOOL WINAPI CryptEnumProvidersA (DWORD dwIndex, DWORD *pdwReserved,
|
---|
1205 | DWORD dwFlags, DWORD *pdwProvType, LPSTR pszProvName, DWORD *pcbProvName)
|
---|
1206 | {
|
---|
1207 | PWSTR str = NULL;
|
---|
1208 | DWORD bufsize;
|
---|
1209 | BOOL ret; /* = FALSE; */
|
---|
1210 |
|
---|
1211 | TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
---|
1212 | pdwProvType, pszProvName, pcbProvName);
|
---|
1213 |
|
---|
1214 | if(!CryptEnumProvidersW(dwIndex, pdwReserved, dwFlags, pdwProvType, NULL, &bufsize))
|
---|
1215 | return FALSE;
|
---|
1216 | if ( pszProvName && !(str = (PWSTR)CRYPT_Alloc(bufsize)) )
|
---|
1217 | {
|
---|
1218 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1219 | return FALSE;
|
---|
1220 | }
|
---|
1221 | ret = CryptEnumProvidersW(dwIndex, pdwReserved, dwFlags, pdwProvType, str, &bufsize);
|
---|
1222 | if (str)
|
---|
1223 | CRYPT_UnicodeToANSI(str, &pszProvName, *pcbProvName);
|
---|
1224 | *pcbProvName = bufsize / sizeof(WCHAR); /* FIXME: not correct */
|
---|
1225 | if (str)
|
---|
1226 | {
|
---|
1227 | CRYPT_Free(str);
|
---|
1228 | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
---|
1229 | {
|
---|
1230 | SetLastError(ERROR_MORE_DATA);
|
---|
1231 | return FALSE;
|
---|
1232 | }
|
---|
1233 | }
|
---|
1234 | return ret;
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | /******************************************************************************
|
---|
1238 | * CryptEnumProviderTypesW (ADVAPI32.@)
|
---|
1239 | *
|
---|
1240 | * Retrieves the next type of CSP supported.
|
---|
1241 | *
|
---|
1242 | * PARAMS
|
---|
1243 | * dwIndex [I] Index of the next provider to be enumerated.
|
---|
1244 | * pdwReserved [I] Reserved for future use and must be NULL.
|
---|
1245 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
1246 | * pdwProvType [O] DWORD designating the type of the provider.
|
---|
1247 | * pszTypeName [O] Buffer that receives data from the provider type.
|
---|
1248 | * pcbTypeName [I/O] Specifies the size of pszTypeName. Contains the number
|
---|
1249 | * of bytes stored in the buffer on return.
|
---|
1250 | *
|
---|
1251 | * RETURNS
|
---|
1252 | * Success: TRUE
|
---|
1253 | * Failure: FALSE
|
---|
1254 | *
|
---|
1255 | * NOTES
|
---|
1256 | * If pszTypeName is NULL, CryptEnumProviderTypesW sets the size of the name
|
---|
1257 | * for memory allocation purposes.
|
---|
1258 | */
|
---|
1259 | BOOL WINAPI CryptEnumProviderTypesW (DWORD dwIndex, DWORD *pdwReserved,
|
---|
1260 | DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszTypeName, DWORD *pcbTypeName)
|
---|
1261 | {
|
---|
1262 | HKEY hKey, hSubkey;
|
---|
1263 | DWORD keylen, numkeys, dwType;
|
---|
1264 | PWSTR keyname, ch;
|
---|
1265 | DWORD result;
|
---|
1266 | static const WCHAR KEYSTR[] = {
|
---|
1267 | 'S','o','f','t','w','a','r','e','\\',
|
---|
1268 | 'M','i','c','r','o','s','o','f','t','\\',
|
---|
1269 | 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
---|
1270 | 'D','e','f','a','u','l','t','s','\\',
|
---|
1271 | 'P','r','o','v','i','d','e','r',' ','T','y','p','e','s',0
|
---|
1272 | };
|
---|
1273 | static const WCHAR typenameW[] = {'T','y','p','e','N','a','m','e',0};
|
---|
1274 |
|
---|
1275 | TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved,
|
---|
1276 | dwFlags, pdwProvType, pszTypeName, pcbTypeName);
|
---|
1277 |
|
---|
1278 | if (pdwReserved || !pdwProvType || !pcbTypeName)
|
---|
1279 | {
|
---|
1280 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1281 | return FALSE;
|
---|
1282 | }
|
---|
1283 | if (dwFlags)
|
---|
1284 | {
|
---|
1285 | SetLastError(NTE_BAD_FLAGS);
|
---|
1286 | return FALSE;
|
---|
1287 | }
|
---|
1288 |
|
---|
1289 | if (RegOpenKeyW(HKEY_LOCAL_MACHINE, KEYSTR, &hKey))
|
---|
1290 | return FALSE;
|
---|
1291 |
|
---|
1292 | RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &numkeys, &keylen, NULL, NULL, NULL, NULL, NULL, NULL);
|
---|
1293 | if (dwIndex >= numkeys)
|
---|
1294 | {
|
---|
1295 | SetLastError(ERROR_NO_MORE_ITEMS);
|
---|
1296 | return FALSE;
|
---|
1297 | }
|
---|
1298 | keylen++;
|
---|
1299 | if ( !(keyname = (PWSTR)CRYPT_Alloc(keylen*sizeof(WCHAR))) )
|
---|
1300 | {
|
---|
1301 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1302 | return FALSE;
|
---|
1303 | }
|
---|
1304 | if ( RegEnumKeyW(hKey, dwIndex, keyname, keylen) ) {
|
---|
1305 | CRYPT_Free(keyname);
|
---|
1306 | return FALSE;
|
---|
1307 | }
|
---|
1308 | RegOpenKeyW(hKey, keyname, &hSubkey);
|
---|
1309 | ch = keyname + strlenW(keyname);
|
---|
1310 | /* Convert "Type 000" to 0, etc/ */
|
---|
1311 | *pdwProvType = *(--ch) - '0';
|
---|
1312 | *pdwProvType += (*(--ch) - '0') * 10;
|
---|
1313 | *pdwProvType += (*(--ch) - '0') * 100;
|
---|
1314 | CRYPT_Free(keyname);
|
---|
1315 |
|
---|
1316 | result = RegQueryValueExW(hSubkey, typenameW, NULL, &dwType, (LPBYTE)pszTypeName, pcbTypeName);
|
---|
1317 | if (result)
|
---|
1318 | {
|
---|
1319 | SetLastError(result);
|
---|
1320 | return FALSE;
|
---|
1321 | }
|
---|
1322 |
|
---|
1323 | RegCloseKey(hSubkey);
|
---|
1324 | RegCloseKey(hKey);
|
---|
1325 | return TRUE;
|
---|
1326 | }
|
---|
1327 |
|
---|
1328 | /******************************************************************************
|
---|
1329 | * CryptEnumProviderTypesA (ADVAPI32.@)
|
---|
1330 | *
|
---|
1331 | * See CryptEnumProviderTypesW.
|
---|
1332 | */
|
---|
1333 | BOOL WINAPI CryptEnumProviderTypesA (DWORD dwIndex, DWORD *pdwReserved,
|
---|
1334 | DWORD dwFlags, DWORD *pdwProvType, LPSTR pszTypeName, DWORD *pcbTypeName)
|
---|
1335 | {
|
---|
1336 | PWSTR str = NULL;
|
---|
1337 | DWORD bufsize;
|
---|
1338 | BOOL ret;
|
---|
1339 |
|
---|
1340 | TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
---|
1341 | pdwProvType, pszTypeName, pcbTypeName);
|
---|
1342 |
|
---|
1343 | if(!CryptEnumProviderTypesW(dwIndex, pdwReserved, dwFlags, pdwProvType, NULL, &bufsize))
|
---|
1344 | return FALSE;
|
---|
1345 | if ( pszTypeName && !(str = (PWSTR)CRYPT_Alloc(bufsize)) )
|
---|
1346 | {
|
---|
1347 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1348 | return FALSE;
|
---|
1349 | }
|
---|
1350 | ret = CryptEnumProviderTypesW(dwIndex, pdwReserved, dwFlags, pdwProvType, str, &bufsize);
|
---|
1351 | if (str)
|
---|
1352 | CRYPT_UnicodeToANSI(str, &pszTypeName, *pcbTypeName);
|
---|
1353 | *pcbTypeName = bufsize / sizeof(WCHAR);
|
---|
1354 | if (str)
|
---|
1355 | {
|
---|
1356 | CRYPT_Free(str);
|
---|
1357 | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
---|
1358 | {
|
---|
1359 | SetLastError(ERROR_MORE_DATA);
|
---|
1360 | return FALSE;
|
---|
1361 | }
|
---|
1362 | }
|
---|
1363 | return ret;
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | /******************************************************************************
|
---|
1367 | * CryptExportKey (ADVAPI32.@)
|
---|
1368 | *
|
---|
1369 | * Exports a cryptographic key from a CSP.
|
---|
1370 | *
|
---|
1371 | * PARAMS
|
---|
1372 | * hKey [I] Handle to the key to export.
|
---|
1373 | * hExpKey [I] Handle to a cryptographic key of the end user.
|
---|
1374 | * dwBlobType [I] Type of BLOB to be exported.
|
---|
1375 | * dwFlags [I] CRYPT_DESTROYKEY/SSL2_FALLBACK/OAEP.
|
---|
1376 | * pbData [O] Buffer to receive BLOB data.
|
---|
1377 | * pdwDataLen [I/O] Specifies the size of pbData.
|
---|
1378 | *
|
---|
1379 | * RETURNS
|
---|
1380 | * Success: TRUE
|
---|
1381 | * Failure: FALSE
|
---|
1382 | *
|
---|
1383 | * NOTES
|
---|
1384 | * if pbData is NULL, CryptExportKey sets pdwDataLen as the size of the
|
---|
1385 | * buffer needed to hold the BLOB.
|
---|
1386 | */
|
---|
1387 | BOOL WINAPI CryptExportKey (HCRYPTKEY hKey, HCRYPTKEY hExpKey, DWORD dwBlobType,
|
---|
1388 | DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
|
---|
1389 | {
|
---|
1390 | PCRYPTPROV prov;
|
---|
1391 | PCRYPTKEY key = (PCRYPTKEY)hKey, expkey = (PCRYPTKEY)hExpKey;
|
---|
1392 |
|
---|
1393 | TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hExpKey, dwBlobType, dwFlags, pbData, pdwDataLen);
|
---|
1394 |
|
---|
1395 | if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1396 | {
|
---|
1397 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1398 | return FALSE;
|
---|
1399 | }
|
---|
1400 |
|
---|
1401 | prov = key->pProvider;
|
---|
1402 | return prov->pFuncs->pCPExportKey(prov->hPrivate, key->hPrivate, expkey ? expkey->hPrivate : 0,
|
---|
1403 | dwBlobType, dwFlags, pbData, pdwDataLen);
|
---|
1404 | }
|
---|
1405 |
|
---|
1406 | /******************************************************************************
|
---|
1407 | * CryptGenKey (ADVAPI32.@)
|
---|
1408 | *
|
---|
1409 | * Generates a random cryptographic session key or a pub/priv key pair.
|
---|
1410 | *
|
---|
1411 | * PARAMS
|
---|
1412 | * hProv [I] Handle to a CSP.
|
---|
1413 | * Algid [I] Algorithm to use to make key.
|
---|
1414 | * dwFlags [I] Specifies type of key to make.
|
---|
1415 | * phKey [I] Address of the handle to which the new key is copied.
|
---|
1416 | *
|
---|
1417 | * RETURNS
|
---|
1418 | * Success: TRUE
|
---|
1419 | * Failure: FALSE
|
---|
1420 | */
|
---|
1421 | BOOL WINAPI CryptGenKey (HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey)
|
---|
1422 | {
|
---|
1423 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
1424 | PCRYPTKEY key;
|
---|
1425 |
|
---|
1426 | TRACE("(0x%lx, %d, %08x, %p)\n", hProv, Algid, dwFlags, phKey);
|
---|
1427 |
|
---|
1428 | if (!prov)
|
---|
1429 | {
|
---|
1430 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
1431 | return FALSE;
|
---|
1432 | }
|
---|
1433 | if (!phKey || !prov || prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
1434 | {
|
---|
1435 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1436 | return FALSE;
|
---|
1437 | }
|
---|
1438 | if ( !(key = (PCRYPTKEY)CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
---|
1439 | {
|
---|
1440 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1441 | return FALSE;
|
---|
1442 | }
|
---|
1443 |
|
---|
1444 | key->pProvider = prov;
|
---|
1445 |
|
---|
1446 | if (prov->pFuncs->pCPGenKey(prov->hPrivate, Algid, dwFlags, &key->hPrivate))
|
---|
1447 | {
|
---|
1448 | *phKey = (HCRYPTKEY)key;
|
---|
1449 | return TRUE;
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | /* CSP error! */
|
---|
1453 | CRYPT_Free(key);
|
---|
1454 | return FALSE;
|
---|
1455 | }
|
---|
1456 |
|
---|
1457 | /******************************************************************************
|
---|
1458 | * CryptGetDefaultProviderW (ADVAPI32.@)
|
---|
1459 | *
|
---|
1460 | * Finds the default CSP of a certain provider type.
|
---|
1461 | *
|
---|
1462 | * PARAMS
|
---|
1463 | * dwProvType [I] Provider type to look for.
|
---|
1464 | * pdwReserved [I] Reserved for future use and must be NULL.
|
---|
1465 | * dwFlags [I] CRYPT_MACHINE_DEFAULT/USER_DEFAULT
|
---|
1466 | * pszProvName [O] Name of the default CSP.
|
---|
1467 | * pcbProvName [I/O] Size of pszProvName
|
---|
1468 | *
|
---|
1469 | * RETURNS
|
---|
1470 | * Success: TRUE
|
---|
1471 | * Failure: FALSE
|
---|
1472 | *
|
---|
1473 | * NOTES
|
---|
1474 | * If pszProvName is NULL, pcbProvName will hold the size of the buffer for
|
---|
1475 | * memory allocation purposes on return.
|
---|
1476 | */
|
---|
1477 | BOOL WINAPI CryptGetDefaultProviderW (DWORD dwProvType, DWORD *pdwReserved,
|
---|
1478 | DWORD dwFlags, LPWSTR pszProvName, DWORD *pcbProvName)
|
---|
1479 | {
|
---|
1480 | HKEY hKey;
|
---|
1481 | PWSTR keyname;
|
---|
1482 | DWORD result;
|
---|
1483 | static const WCHAR nameW[] = {'N','a','m','e',0};
|
---|
1484 |
|
---|
1485 | if (pdwReserved || !pcbProvName)
|
---|
1486 | {
|
---|
1487 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1488 | return FALSE;
|
---|
1489 | }
|
---|
1490 | if (dwFlags & ~(CRYPT_USER_DEFAULT | CRYPT_MACHINE_DEFAULT))
|
---|
1491 | {
|
---|
1492 | SetLastError(NTE_BAD_FLAGS);
|
---|
1493 | return FALSE;
|
---|
1494 | }
|
---|
1495 | if (dwProvType > 999)
|
---|
1496 | {
|
---|
1497 | SetLastError(NTE_BAD_PROV_TYPE);
|
---|
1498 | return FALSE;
|
---|
1499 | }
|
---|
1500 | if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, dwFlags & CRYPT_USER_DEFAULT)) )
|
---|
1501 | {
|
---|
1502 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1503 | return FALSE;
|
---|
1504 | }
|
---|
1505 | if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE ,keyname, &hKey))
|
---|
1506 | {
|
---|
1507 | CRYPT_Free(keyname);
|
---|
1508 | SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
---|
1509 | return FALSE;
|
---|
1510 | }
|
---|
1511 | CRYPT_Free(keyname);
|
---|
1512 |
|
---|
1513 | result = RegQueryValueExW(hKey, nameW, NULL, NULL, (LPBYTE)pszProvName, pcbProvName);
|
---|
1514 | if (result)
|
---|
1515 | {
|
---|
1516 | if (result != ERROR_MORE_DATA)
|
---|
1517 | SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
---|
1518 | else
|
---|
1519 | SetLastError(result);
|
---|
1520 |
|
---|
1521 | return FALSE;
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | RegCloseKey(hKey);
|
---|
1525 | return TRUE;
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 | /******************************************************************************
|
---|
1529 | * CryptGetDefaultProviderA (ADVAPI32.@)
|
---|
1530 | *
|
---|
1531 | * See CryptGetDefaultProviderW.
|
---|
1532 | */
|
---|
1533 | BOOL WINAPI CryptGetDefaultProviderA (DWORD dwProvType, DWORD *pdwReserved,
|
---|
1534 | DWORD dwFlags, LPSTR pszProvName, DWORD *pcbProvName)
|
---|
1535 | {
|
---|
1536 | PWSTR str = NULL;
|
---|
1537 | DWORD bufsize;
|
---|
1538 | BOOL ret = FALSE;
|
---|
1539 |
|
---|
1540 | TRACE("(%d, %p, %08x, %p, %p)\n", dwProvType, pdwReserved, dwFlags, pszProvName, pcbProvName);
|
---|
1541 |
|
---|
1542 | CryptGetDefaultProviderW(dwProvType, pdwReserved, dwFlags, NULL, &bufsize);
|
---|
1543 | if ( pszProvName && !(str = (PWSTR)CRYPT_Alloc(bufsize)) )
|
---|
1544 | {
|
---|
1545 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1546 | return FALSE;
|
---|
1547 | }
|
---|
1548 | ret = CryptGetDefaultProviderW(dwProvType, pdwReserved, dwFlags, str, &bufsize);
|
---|
1549 | if (str)
|
---|
1550 | CRYPT_UnicodeToANSI(str, &pszProvName, *pcbProvName);
|
---|
1551 | *pcbProvName = bufsize / sizeof(WCHAR);
|
---|
1552 | if (str)
|
---|
1553 | {
|
---|
1554 | CRYPT_Free(str);
|
---|
1555 | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
---|
1556 | {
|
---|
1557 | SetLastError(ERROR_MORE_DATA);
|
---|
1558 | return FALSE;
|
---|
1559 | }
|
---|
1560 | }
|
---|
1561 | return ret;
|
---|
1562 | }
|
---|
1563 |
|
---|
1564 | /******************************************************************************
|
---|
1565 | * CryptGetHashParam (ADVAPI32.@)
|
---|
1566 | *
|
---|
1567 | * Retrieves data that controls the operations of a hash object.
|
---|
1568 | *
|
---|
1569 | * PARAMS
|
---|
1570 | * hHash [I] Handle of the hash object to question.
|
---|
1571 | * dwParam [I] Query type.
|
---|
1572 | * pbData [O] Buffer that receives the value data.
|
---|
1573 | * pdwDataLen [I/O] Size of the pbData buffer.
|
---|
1574 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
1575 | *
|
---|
1576 | * RETURNS
|
---|
1577 | * Success: TRUE
|
---|
1578 | * Failure: FALSE
|
---|
1579 | *
|
---|
1580 | * NOTES
|
---|
1581 | * If pbData is NULL, pdwDataLen will contain the length required.
|
---|
1582 | */
|
---|
1583 | BOOL WINAPI CryptGetHashParam (HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData,
|
---|
1584 | DWORD *pdwDataLen, DWORD dwFlags)
|
---|
1585 | {
|
---|
1586 | PCRYPTPROV prov;
|
---|
1587 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1588 |
|
---|
1589 | TRACE("(0x%lx, %d, %p, %p, %08x)\n", hHash, dwParam, pbData, pdwDataLen, dwFlags);
|
---|
1590 |
|
---|
1591 | if (!hash || !pdwDataLen || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1592 | {
|
---|
1593 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1594 | return FALSE;
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 | prov = hash->pProvider;
|
---|
1598 | return prov->pFuncs->pCPGetHashParam(prov->hPrivate, hash->hPrivate, dwParam,
|
---|
1599 | pbData, pdwDataLen, dwFlags);
|
---|
1600 | }
|
---|
1601 |
|
---|
1602 | /******************************************************************************
|
---|
1603 | * CryptGetKeyParam (ADVAPI32.@)
|
---|
1604 | *
|
---|
1605 | * Retrieves data that controls the operations of a key.
|
---|
1606 | *
|
---|
1607 | * PARAMS
|
---|
1608 | * hKey [I] Handle to they key in question.
|
---|
1609 | * dwParam [I] Specifies query type.
|
---|
1610 | * pbData [O] Sequence of bytes to receive data.
|
---|
1611 | * pdwDataLen [I/O] Size of pbData.
|
---|
1612 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
1613 | *
|
---|
1614 | * RETURNS
|
---|
1615 | * Success: TRUE
|
---|
1616 | * Failure: FALSE
|
---|
1617 | *
|
---|
1618 | * NOTES
|
---|
1619 | * If pbData is NULL, pdwDataLen is set to the needed length of the buffer.
|
---|
1620 | */
|
---|
1621 | BOOL WINAPI CryptGetKeyParam (HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData,
|
---|
1622 | DWORD *pdwDataLen, DWORD dwFlags)
|
---|
1623 | {
|
---|
1624 | PCRYPTPROV prov;
|
---|
1625 | PCRYPTKEY key = (PCRYPTKEY)hKey;
|
---|
1626 |
|
---|
1627 | TRACE("(0x%lx, %d, %p, %p, %08x)\n", hKey, dwParam, pbData, pdwDataLen, dwFlags);
|
---|
1628 |
|
---|
1629 | if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1630 | {
|
---|
1631 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1632 | return FALSE;
|
---|
1633 | }
|
---|
1634 |
|
---|
1635 | prov = key->pProvider;
|
---|
1636 | return prov->pFuncs->pCPGetKeyParam(prov->hPrivate, key->hPrivate, dwParam,
|
---|
1637 | pbData, pdwDataLen, dwFlags);
|
---|
1638 | }
|
---|
1639 |
|
---|
1640 | /******************************************************************************
|
---|
1641 | * CryptGetProvParam (ADVAPI32.@)
|
---|
1642 | *
|
---|
1643 | * Retrieves parameters that control the operations of a CSP.
|
---|
1644 | *
|
---|
1645 | * PARAMS
|
---|
1646 | * hProv [I] Handle of the CSP in question.
|
---|
1647 | * dwParam [I] Specifies query type.
|
---|
1648 | * pbData [O] Buffer to receive the data.
|
---|
1649 | * pdwDataLen [I/O] Size of pbData.
|
---|
1650 | * dwFlags [I] see MSDN Docs.
|
---|
1651 | *
|
---|
1652 | * RETURNS
|
---|
1653 | * Success: TRUE
|
---|
1654 | * Failure: FALSE
|
---|
1655 | *
|
---|
1656 | * NOTES
|
---|
1657 | * If pbData is NULL, pdwDataLen is set to the needed buffer length.
|
---|
1658 | */
|
---|
1659 | BOOL WINAPI CryptGetProvParam (HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData,
|
---|
1660 | DWORD *pdwDataLen, DWORD dwFlags)
|
---|
1661 | {
|
---|
1662 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
1663 |
|
---|
1664 | TRACE("(0x%lx, %d, %p, %p, %08x)\n", hProv, dwParam, pbData, pdwDataLen, dwFlags);
|
---|
1665 |
|
---|
1666 | if (!prov || prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
1667 | {
|
---|
1668 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1669 | return FALSE;
|
---|
1670 | }
|
---|
1671 |
|
---|
1672 | return prov->pFuncs->pCPGetProvParam(prov->hPrivate, dwParam, pbData, pdwDataLen, dwFlags);
|
---|
1673 | }
|
---|
1674 |
|
---|
1675 | /******************************************************************************
|
---|
1676 | * CryptGetUserKey (ADVAPI32.@)
|
---|
1677 | *
|
---|
1678 | * Gets a handle of one of a user's two public/private key pairs.
|
---|
1679 | *
|
---|
1680 | * PARAMS
|
---|
1681 | * hProv [I] Handle of a CSP.
|
---|
1682 | * dwKeySpec [I] Private key to use.
|
---|
1683 | * phUserKey [O] Pointer to the handle of the retrieved keys.
|
---|
1684 | *
|
---|
1685 | * RETURNS
|
---|
1686 | * Success: TRUE
|
---|
1687 | * Failure: FALSE
|
---|
1688 | */
|
---|
1689 | BOOL WINAPI CryptGetUserKey (HCRYPTPROV hProv, DWORD dwKeySpec, HCRYPTKEY *phUserKey)
|
---|
1690 | {
|
---|
1691 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
1692 | PCRYPTKEY key;
|
---|
1693 |
|
---|
1694 | TRACE("(0x%lx, %d, %p)\n", hProv, dwKeySpec, phUserKey);
|
---|
1695 |
|
---|
1696 | if (!prov)
|
---|
1697 | {
|
---|
1698 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
1699 | return FALSE;
|
---|
1700 | }
|
---|
1701 | if (!phUserKey || prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
1702 | {
|
---|
1703 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1704 | return FALSE;
|
---|
1705 | }
|
---|
1706 | if ( !(key = (PCRYPTKEY)CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
---|
1707 | {
|
---|
1708 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1709 | return FALSE;
|
---|
1710 | }
|
---|
1711 |
|
---|
1712 | key->pProvider = prov;
|
---|
1713 |
|
---|
1714 | if (prov->pFuncs->pCPGetUserKey(prov->hPrivate, dwKeySpec, &key->hPrivate))
|
---|
1715 | {
|
---|
1716 | *phUserKey = (HCRYPTKEY)key;
|
---|
1717 | return TRUE;
|
---|
1718 | }
|
---|
1719 |
|
---|
1720 | /* CSP Error */
|
---|
1721 | CRYPT_Free(key);
|
---|
1722 | *phUserKey = 0;
|
---|
1723 | return FALSE;
|
---|
1724 | }
|
---|
1725 |
|
---|
1726 | /******************************************************************************
|
---|
1727 | * CryptHashData (ADVAPI32.@)
|
---|
1728 | *
|
---|
1729 | * Adds data to a hash object.
|
---|
1730 | *
|
---|
1731 | * PARAMS
|
---|
1732 | * hHash [I] Handle of the hash object.
|
---|
1733 | * pbData [I] Buffer of data to be hashed.
|
---|
1734 | * dwDataLen [I] Number of bytes to add.
|
---|
1735 | * dwFlags [I] Can be CRYPT_USERDATA
|
---|
1736 | *
|
---|
1737 | * RETURNS
|
---|
1738 | * Success: TRUE
|
---|
1739 | * Failure: FALSE
|
---|
1740 | */
|
---|
1741 | BOOL WINAPI CryptHashData (HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
|
---|
1742 | {
|
---|
1743 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1744 | PCRYPTPROV prov;
|
---|
1745 |
|
---|
1746 | TRACE("(0x%lx, %p, %d, %08x)\n", hHash, pbData, dwDataLen, dwFlags);
|
---|
1747 |
|
---|
1748 | if (!hash)
|
---|
1749 | {
|
---|
1750 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
1751 | return FALSE;
|
---|
1752 | }
|
---|
1753 | if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1754 | {
|
---|
1755 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1756 | return FALSE;
|
---|
1757 | }
|
---|
1758 |
|
---|
1759 | prov = hash->pProvider;
|
---|
1760 | return prov->pFuncs->pCPHashData(prov->hPrivate, hash->hPrivate, pbData, dwDataLen, dwFlags);
|
---|
1761 | }
|
---|
1762 |
|
---|
1763 | /******************************************************************************
|
---|
1764 | * CryptHashSessionKey (ADVAPI32.@)
|
---|
1765 | *
|
---|
1766 | * Compute the cryptographic hash of a session key object.
|
---|
1767 | *
|
---|
1768 | * PARAMS
|
---|
1769 | * hHash [I] Handle to the hash object.
|
---|
1770 | * hKey [I] Handle to the key to be hashed.
|
---|
1771 | * dwFlags [I] Can be CRYPT_LITTLE_ENDIAN.
|
---|
1772 | *
|
---|
1773 | * RETURNS
|
---|
1774 | * Success: TRUE
|
---|
1775 | * Failure: FALSE
|
---|
1776 | */
|
---|
1777 | BOOL WINAPI CryptHashSessionKey (HCRYPTHASH hHash, HCRYPTKEY hKey, DWORD dwFlags)
|
---|
1778 | {
|
---|
1779 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1780 | PCRYPTKEY key = (PCRYPTKEY)hKey;
|
---|
1781 | PCRYPTPROV prov;
|
---|
1782 |
|
---|
1783 | TRACE("(0x%lx, 0x%lx, %08x)\n", hHash, hKey, dwFlags);
|
---|
1784 |
|
---|
1785 | if (!hash || !key)
|
---|
1786 | {
|
---|
1787 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
1788 | return FALSE;
|
---|
1789 | }
|
---|
1790 |
|
---|
1791 | if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1792 | {
|
---|
1793 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1794 | return FALSE;
|
---|
1795 | }
|
---|
1796 |
|
---|
1797 | prov = hash->pProvider;
|
---|
1798 | return prov->pFuncs->pCPHashSessionKey(prov->hPrivate, hash->hPrivate, key->hPrivate, dwFlags);
|
---|
1799 | }
|
---|
1800 |
|
---|
1801 | /******************************************************************************
|
---|
1802 | * CryptImportKey (ADVAPI32.@)
|
---|
1803 | *
|
---|
1804 | * Transfer a cryptographic key from a key BLOB into a cryptographic service provider (CSP).
|
---|
1805 | *
|
---|
1806 | * PARAMS
|
---|
1807 | * hProv [I] Handle of a CSP.
|
---|
1808 | * pbData [I] Contains the key to be imported.
|
---|
1809 | * dwDataLen [I] Length of the key.
|
---|
1810 | * hPubKey [I] Cryptographic key that decrypts pdData
|
---|
1811 | * dwFlags [I] Used only with a public/private key pair.
|
---|
1812 | * phKey [O] Imported key.
|
---|
1813 | *
|
---|
1814 | * RETURNS
|
---|
1815 | * Success: TRUE
|
---|
1816 | * Failure: FALSE
|
---|
1817 | */
|
---|
1818 | BOOL WINAPI CryptImportKey (HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
|
---|
1819 | HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
|
---|
1820 | {
|
---|
1821 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
1822 | PCRYPTKEY pubkey = (PCRYPTKEY)hPubKey, importkey;
|
---|
1823 |
|
---|
1824 | TRACE("(0x%lx, %p, %d, 0x%lx, %08x, %p)\n", hProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
|
---|
1825 |
|
---|
1826 | if (!prov || !pbData || !dwDataLen || !phKey || prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
1827 | {
|
---|
1828 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1829 | return FALSE;
|
---|
1830 | }
|
---|
1831 |
|
---|
1832 | if ( !(importkey = (PCRYPTKEY)CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
---|
1833 | {
|
---|
1834 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1835 | return FALSE;
|
---|
1836 | }
|
---|
1837 |
|
---|
1838 | importkey->pProvider = prov;
|
---|
1839 | if (prov->pFuncs->pCPImportKey(prov->hPrivate, pbData, dwDataLen,
|
---|
1840 | pubkey ? pubkey->hPrivate : 0, dwFlags, &importkey->hPrivate))
|
---|
1841 | {
|
---|
1842 | *phKey = (HCRYPTKEY)importkey;
|
---|
1843 | return TRUE;
|
---|
1844 | }
|
---|
1845 |
|
---|
1846 | CRYPT_Free(importkey);
|
---|
1847 | return FALSE;
|
---|
1848 | }
|
---|
1849 |
|
---|
1850 | /******************************************************************************
|
---|
1851 | * CryptSignHashW (ADVAPI32.@)
|
---|
1852 | *
|
---|
1853 | * Signs data.
|
---|
1854 | *
|
---|
1855 | * PARAMS
|
---|
1856 | * hHash [I] Handle of the hash object to be signed.
|
---|
1857 | * dwKeySpec [I] Private key to use.
|
---|
1858 | * sDescription [I] Should be NULL.
|
---|
1859 | * dwFlags [I] CRYPT_NOHASHOID/X931_FORMAT.
|
---|
1860 | * pbSignature [O] Buffer of the signature data.
|
---|
1861 | * pdwSigLen [I/O] Size of the pbSignature buffer.
|
---|
1862 | *
|
---|
1863 | * RETURNS
|
---|
1864 | * Success: TRUE
|
---|
1865 | * Failure: FALSE
|
---|
1866 | *
|
---|
1867 | * NOTES
|
---|
1868 | * Because of security flaws sDescription should not be used and should thus be
|
---|
1869 | * NULL. It is supported only for compatibility with Microsoft's Cryptographic
|
---|
1870 | * Providers.
|
---|
1871 | */
|
---|
1872 | BOOL WINAPI CryptSignHashW (HCRYPTHASH hHash, DWORD dwKeySpec, LPCWSTR sDescription,
|
---|
1873 | DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
|
---|
1874 | {
|
---|
1875 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1876 | PCRYPTPROV prov;
|
---|
1877 |
|
---|
1878 | TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
|
---|
1879 | hHash, dwKeySpec, debugstr_w(sDescription), dwFlags, pbSignature, pdwSigLen);
|
---|
1880 |
|
---|
1881 | if (!hash)
|
---|
1882 | {
|
---|
1883 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
1884 | return FALSE;
|
---|
1885 | }
|
---|
1886 | if (!pdwSigLen || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1887 | {
|
---|
1888 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1889 | return FALSE;
|
---|
1890 | }
|
---|
1891 |
|
---|
1892 | prov = hash->pProvider;
|
---|
1893 | return prov->pFuncs->pCPSignHash(prov->hPrivate, hash->hPrivate, dwKeySpec, sDescription,
|
---|
1894 | dwFlags, pbSignature, pdwSigLen);
|
---|
1895 | }
|
---|
1896 |
|
---|
1897 | /******************************************************************************
|
---|
1898 | * CryptSignHashA (ADVAPI32.@)
|
---|
1899 | *
|
---|
1900 | * See CryptSignHashW.
|
---|
1901 | */
|
---|
1902 | BOOL WINAPI CryptSignHashA (HCRYPTHASH hHash, DWORD dwKeySpec, LPCSTR sDescription,
|
---|
1903 | DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
|
---|
1904 | {
|
---|
1905 | LPWSTR wsDescription;
|
---|
1906 | BOOL result;
|
---|
1907 |
|
---|
1908 | TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
|
---|
1909 | hHash, dwKeySpec, debugstr_a(sDescription), dwFlags, pbSignature, pdwSigLen);
|
---|
1910 |
|
---|
1911 | CRYPT_ANSIToUnicode(sDescription, &wsDescription, -1);
|
---|
1912 | result = CryptSignHashW(hHash, dwKeySpec, wsDescription, dwFlags, pbSignature, pdwSigLen);
|
---|
1913 | CRYPT_Free(wsDescription);
|
---|
1914 |
|
---|
1915 | return result;
|
---|
1916 | }
|
---|
1917 |
|
---|
1918 | /******************************************************************************
|
---|
1919 | * CryptSetHashParam (ADVAPI32.@)
|
---|
1920 | *
|
---|
1921 | * Customizes the operations of a hash object.
|
---|
1922 | *
|
---|
1923 | * PARAMS
|
---|
1924 | * hHash [I] Handle of the hash object to set parameters.
|
---|
1925 | * dwParam [I] HP_HMAC_INFO/HASHVAL.
|
---|
1926 | * pbData [I] Value data buffer.
|
---|
1927 | * dwFlags [I] Reserved for future use and must be zero.
|
---|
1928 | *
|
---|
1929 | * RETURNS
|
---|
1930 | * Success: TRUE
|
---|
1931 | * Failure: FALSE
|
---|
1932 | */
|
---|
1933 | BOOL WINAPI CryptSetHashParam (HCRYPTHASH hHash, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
|
---|
1934 | {
|
---|
1935 | PCRYPTPROV prov;
|
---|
1936 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
1937 |
|
---|
1938 | TRACE("(0x%lx, %d, %p, %08x)\n", hHash, dwParam, pbData, dwFlags);
|
---|
1939 |
|
---|
1940 | if (!hash || !pbData || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1941 | {
|
---|
1942 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1943 | return FALSE;
|
---|
1944 | }
|
---|
1945 |
|
---|
1946 | prov = hash->pProvider;
|
---|
1947 | return prov->pFuncs->pCPSetHashParam(prov->hPrivate, hash->hPrivate,
|
---|
1948 | dwParam, pbData, dwFlags);
|
---|
1949 | }
|
---|
1950 |
|
---|
1951 | /******************************************************************************
|
---|
1952 | * CryptSetKeyParam (ADVAPI32.@)
|
---|
1953 | *
|
---|
1954 | * Customizes a session key's operations.
|
---|
1955 | *
|
---|
1956 | * PARAMS
|
---|
1957 | * hKey [I] Handle to the key to set values.
|
---|
1958 | * dwParam [I] See MSDN Doc.
|
---|
1959 | * pbData [I] Buffer of values to set.
|
---|
1960 | * dwFlags [I] Only used when dwParam == KP_ALGID.
|
---|
1961 | *
|
---|
1962 | * RETURNS
|
---|
1963 | * Success: TRUE
|
---|
1964 | * Failure: FALSE
|
---|
1965 | */
|
---|
1966 | BOOL WINAPI CryptSetKeyParam (HCRYPTKEY hKey, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
|
---|
1967 | {
|
---|
1968 | PCRYPTPROV prov;
|
---|
1969 | PCRYPTKEY key = (PCRYPTKEY)hKey;
|
---|
1970 |
|
---|
1971 | TRACE("(0x%lx, %d, %p, %08x)\n", hKey, dwParam, pbData, dwFlags);
|
---|
1972 |
|
---|
1973 | if (!key || !pbData || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
1974 | {
|
---|
1975 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1976 | return FALSE;
|
---|
1977 | }
|
---|
1978 |
|
---|
1979 | prov = key->pProvider;
|
---|
1980 | return prov->pFuncs->pCPSetKeyParam(prov->hPrivate, key->hPrivate,
|
---|
1981 | dwParam, pbData, dwFlags);
|
---|
1982 | }
|
---|
1983 |
|
---|
1984 | /******************************************************************************
|
---|
1985 | * CryptSetProviderA (ADVAPI32.@)
|
---|
1986 | *
|
---|
1987 | * Specifies the current user's default CSP.
|
---|
1988 | *
|
---|
1989 | * PARAMS
|
---|
1990 | * pszProvName [I] Name of the new default CSP.
|
---|
1991 | * dwProvType [I] Provider type of the CSP.
|
---|
1992 | *
|
---|
1993 | * RETURNS
|
---|
1994 | * Success: TRUE
|
---|
1995 | * Failure: FALSE
|
---|
1996 | */
|
---|
1997 | BOOL WINAPI CryptSetProviderA (LPCSTR pszProvName, DWORD dwProvType)
|
---|
1998 | {
|
---|
1999 | TRACE("(%s, %d)\n", pszProvName, dwProvType);
|
---|
2000 | return CryptSetProviderExA(pszProvName, dwProvType, NULL, CRYPT_USER_DEFAULT);
|
---|
2001 | }
|
---|
2002 |
|
---|
2003 | /******************************************************************************
|
---|
2004 | * CryptSetProviderW (ADVAPI32.@)
|
---|
2005 | *
|
---|
2006 | * See CryptSetProviderA.
|
---|
2007 | */
|
---|
2008 | BOOL WINAPI CryptSetProviderW (LPCWSTR pszProvName, DWORD dwProvType)
|
---|
2009 | {
|
---|
2010 | TRACE("(%s, %d)\n", debugstr_w(pszProvName), dwProvType);
|
---|
2011 | return CryptSetProviderExW(pszProvName, dwProvType, NULL, CRYPT_USER_DEFAULT);
|
---|
2012 | }
|
---|
2013 |
|
---|
2014 | /******************************************************************************
|
---|
2015 | * CryptSetProviderExW (ADVAPI32.@)
|
---|
2016 | *
|
---|
2017 | * Specifies the default CSP.
|
---|
2018 | *
|
---|
2019 | * PARAMS
|
---|
2020 | * pszProvName [I] Name of the new default CSP.
|
---|
2021 | * dwProvType [I] Provider type of the CSP.
|
---|
2022 | * pdwReserved [I] Reserved for future use and must be NULL.
|
---|
2023 | * dwFlags [I] See MSDN Doc.
|
---|
2024 | *
|
---|
2025 | * RETURNS
|
---|
2026 | * Success: TRUE
|
---|
2027 | * Failure: FALSE
|
---|
2028 | */
|
---|
2029 | BOOL WINAPI CryptSetProviderExW (LPCWSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
|
---|
2030 | {
|
---|
2031 | HKEY hProvKey, hTypeKey;
|
---|
2032 | PWSTR keyname;
|
---|
2033 | static const WCHAR nameW[] = {'N','a','m','e',0};
|
---|
2034 |
|
---|
2035 | TRACE("(%s, %d, %p, %08x)\n", debugstr_w(pszProvName), dwProvType, pdwReserved, dwFlags);
|
---|
2036 |
|
---|
2037 | if (!pszProvName || pdwReserved)
|
---|
2038 | {
|
---|
2039 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2040 | return FALSE;
|
---|
2041 | }
|
---|
2042 | if (dwProvType > MAXPROVTYPES)
|
---|
2043 | {
|
---|
2044 | SetLastError(NTE_BAD_PROV_TYPE);
|
---|
2045 | return FALSE;
|
---|
2046 | }
|
---|
2047 | if (dwFlags & ~(CRYPT_MACHINE_DEFAULT | CRYPT_USER_DEFAULT | CRYPT_DELETE_DEFAULT)
|
---|
2048 | || dwFlags == CRYPT_DELETE_DEFAULT)
|
---|
2049 | {
|
---|
2050 | SetLastError(NTE_BAD_FLAGS);
|
---|
2051 | return FALSE;
|
---|
2052 | }
|
---|
2053 |
|
---|
2054 | if (!(keyname = CRYPT_GetTypeKeyName(dwProvType, dwFlags & CRYPT_USER_DEFAULT)))
|
---|
2055 | {
|
---|
2056 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
2057 | return FALSE;
|
---|
2058 | }
|
---|
2059 | if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
---|
2060 | keyname, &hTypeKey))
|
---|
2061 | {
|
---|
2062 | CRYPT_Free(keyname);
|
---|
2063 | SetLastError(NTE_BAD_PROVIDER);
|
---|
2064 | return FALSE;
|
---|
2065 | }
|
---|
2066 | CRYPT_Free(keyname);
|
---|
2067 |
|
---|
2068 | if (dwFlags & CRYPT_DELETE_DEFAULT)
|
---|
2069 | {
|
---|
2070 | RegDeleteValueW(hTypeKey, (WCHAR*)nameW);
|
---|
2071 | }
|
---|
2072 | else
|
---|
2073 | {
|
---|
2074 | if (!(keyname = CRYPT_GetProvKeyName(pszProvName)))
|
---|
2075 | {
|
---|
2076 | RegCloseKey(hTypeKey);
|
---|
2077 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
2078 | return FALSE;
|
---|
2079 | }
|
---|
2080 | if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
---|
2081 | keyname, &hProvKey))
|
---|
2082 | {
|
---|
2083 | CRYPT_Free(keyname);
|
---|
2084 | RegCloseKey(hTypeKey);
|
---|
2085 | SetLastError(NTE_BAD_PROVIDER);
|
---|
2086 | return FALSE;
|
---|
2087 | }
|
---|
2088 | CRYPT_Free(keyname);
|
---|
2089 |
|
---|
2090 | if (RegSetValueExW(hTypeKey, nameW, 0, REG_SZ, (BYTE *)pszProvName,
|
---|
2091 | (strlenW(pszProvName) + 1)*sizeof(WCHAR)))
|
---|
2092 | {
|
---|
2093 | RegCloseKey(hTypeKey);
|
---|
2094 | RegCloseKey(hProvKey);
|
---|
2095 | return FALSE;
|
---|
2096 | }
|
---|
2097 |
|
---|
2098 | RegCloseKey(hProvKey);
|
---|
2099 | }
|
---|
2100 | RegCloseKey(hTypeKey);
|
---|
2101 |
|
---|
2102 | return TRUE;
|
---|
2103 | }
|
---|
2104 |
|
---|
2105 | /******************************************************************************
|
---|
2106 | * CryptSetProviderExA (ADVAPI32.@)
|
---|
2107 | *
|
---|
2108 | * See CryptSetProviderExW.
|
---|
2109 | */
|
---|
2110 | BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
|
---|
2111 | {
|
---|
2112 | BOOL ret = FALSE;
|
---|
2113 | PWSTR str = NULL;
|
---|
2114 |
|
---|
2115 | TRACE("(%s, %d, %p, %08x)\n", pszProvName, dwProvType, pdwReserved, dwFlags);
|
---|
2116 |
|
---|
2117 | if (CRYPT_ANSIToUnicode(pszProvName, &str, -1))
|
---|
2118 | {
|
---|
2119 | ret = CryptSetProviderExW(str, dwProvType, pdwReserved, dwFlags);
|
---|
2120 | CRYPT_Free(str);
|
---|
2121 | }
|
---|
2122 | return ret;
|
---|
2123 | }
|
---|
2124 |
|
---|
2125 | /******************************************************************************
|
---|
2126 | * CryptSetProvParam (ADVAPI32.@)
|
---|
2127 | *
|
---|
2128 | * Customizes the operations of a CSP.
|
---|
2129 | *
|
---|
2130 | * PARAMS
|
---|
2131 | * hProv [I] Handle of a CSP.
|
---|
2132 | * dwParam [I] See MSDN Doc.
|
---|
2133 | * pbData [I] Buffer that contains a value to set as a parameter.
|
---|
2134 | * dwFlags [I] if dwParam is PP_USE_HARDWARE_RNG, dwFlags must be zero.
|
---|
2135 | *
|
---|
2136 | * RETURNS
|
---|
2137 | * Success: TRUE
|
---|
2138 | * Failure: FALSE
|
---|
2139 | */
|
---|
2140 | BOOL WINAPI CryptSetProvParam (HCRYPTPROV hProv, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
|
---|
2141 | {
|
---|
2142 | PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
---|
2143 |
|
---|
2144 | TRACE("(0x%lx, %d, %p, %08x)\n", hProv, dwParam, pbData, dwFlags);
|
---|
2145 |
|
---|
2146 | if (!prov)
|
---|
2147 | {
|
---|
2148 | SetLastError(ERROR_INVALID_HANDLE);
|
---|
2149 | return FALSE;
|
---|
2150 | }
|
---|
2151 | if (prov->dwMagic != MAGIC_CRYPTPROV)
|
---|
2152 | {
|
---|
2153 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2154 | return FALSE;
|
---|
2155 | }
|
---|
2156 | if (dwFlags & PP_USE_HARDWARE_RNG)
|
---|
2157 | {
|
---|
2158 | FIXME("PP_USE_HARDWARE_RNG: What do I do with this?\n");
|
---|
2159 | FIXME("\tLetting the CSP decide.\n");
|
---|
2160 | }
|
---|
2161 | if (dwFlags & PP_CLIENT_HWND)
|
---|
2162 | {
|
---|
2163 | /* FIXME: Should verify the parameter */
|
---|
2164 | if (pbData /* && IsWindow((HWND)pbData) */)
|
---|
2165 | {
|
---|
2166 | crypt_hWindow = (HWND)(pbData);
|
---|
2167 | return TRUE;
|
---|
2168 | } else {
|
---|
2169 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2170 | return FALSE;
|
---|
2171 | }
|
---|
2172 | }
|
---|
2173 | /* All other flags go to the CSP */
|
---|
2174 | return prov->pFuncs->pCPSetProvParam(prov->hPrivate, dwParam, pbData, dwFlags);
|
---|
2175 | }
|
---|
2176 |
|
---|
2177 | /******************************************************************************
|
---|
2178 | * CryptVerifySignatureW (ADVAPI32.@)
|
---|
2179 | *
|
---|
2180 | * Verifies the signature of a hash object.
|
---|
2181 | *
|
---|
2182 | * PARAMS
|
---|
2183 | * hHash [I] Handle of the hash object to verify.
|
---|
2184 | * pbSignature [I] Signature data to verify.
|
---|
2185 | * dwSigLen [I] Size of pbSignature.
|
---|
2186 | * hPubKey [I] Handle to the public key to authenticate signature.
|
---|
2187 | * sDescription [I] Should be NULL.
|
---|
2188 | * dwFlags [I] See MSDN doc.
|
---|
2189 | *
|
---|
2190 | * RETURNS
|
---|
2191 | * Success: TRUE
|
---|
2192 | * Failure: FALSE
|
---|
2193 | *
|
---|
2194 | * NOTES
|
---|
2195 | * Because of security flaws sDescription should not be used and should thus be
|
---|
2196 | * NULL. It is supported only for compatibility with Microsoft's Cryptographic
|
---|
2197 | * Providers.
|
---|
2198 | */
|
---|
2199 | BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, CONST BYTE *pbSignature, DWORD dwSigLen,
|
---|
2200 | HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags)
|
---|
2201 | {
|
---|
2202 | PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
---|
2203 | PCRYPTKEY key = (PCRYPTKEY)hPubKey;
|
---|
2204 | PCRYPTPROV prov;
|
---|
2205 |
|
---|
2206 | TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature,
|
---|
2207 | dwSigLen, hPubKey, debugstr_w(sDescription), dwFlags);
|
---|
2208 |
|
---|
2209 | if (!hash || !key ||
|
---|
2210 | !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV ||
|
---|
2211 | !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
---|
2212 | {
|
---|
2213 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2214 | return FALSE;
|
---|
2215 | }
|
---|
2216 |
|
---|
2217 | prov = hash->pProvider;
|
---|
2218 | return prov->pFuncs->pCPVerifySignature(prov->hPrivate, hash->hPrivate, pbSignature, dwSigLen,
|
---|
2219 | key->hPrivate, sDescription, dwFlags);
|
---|
2220 | }
|
---|
2221 |
|
---|
2222 | /******************************************************************************
|
---|
2223 | * CryptVerifySignatureA (ADVAPI32.@)
|
---|
2224 | *
|
---|
2225 | * See CryptVerifySignatureW.
|
---|
2226 | */
|
---|
2227 | BOOL WINAPI CryptVerifySignatureA (HCRYPTHASH hHash, CONST BYTE *pbSignature, DWORD dwSigLen,
|
---|
2228 | HCRYPTKEY hPubKey, LPCSTR sDescription, DWORD dwFlags)
|
---|
2229 | {
|
---|
2230 | LPWSTR wsDescription;
|
---|
2231 | BOOL result;
|
---|
2232 |
|
---|
2233 | TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature,
|
---|
2234 | dwSigLen, hPubKey, debugstr_a(sDescription), dwFlags);
|
---|
2235 |
|
---|
2236 | CRYPT_ANSIToUnicode(sDescription, &wsDescription, -1);
|
---|
2237 | result = CryptVerifySignatureW(hHash, pbSignature, dwSigLen, hPubKey, wsDescription, dwFlags);
|
---|
2238 | CRYPT_Free(wsDescription);
|
---|
2239 |
|
---|
2240 | return result;
|
---|
2241 | }
|
---|
2242 |
|
---|
2243 | /******************************************************************************
|
---|
2244 | * SystemFunction030 (ADVAPI32.@)
|
---|
2245 | *
|
---|
2246 | * Tests if two blocks of 16 bytes are equal
|
---|
2247 | *
|
---|
2248 | * PARAMS
|
---|
2249 | * b1,b2 [I] block of 16 bytes
|
---|
2250 | *
|
---|
2251 | * RETURNS
|
---|
2252 | * TRUE if blocks are the same
|
---|
2253 | * FALSE if blocks are different
|
---|
2254 | */
|
---|
2255 | BOOL WINAPI SystemFunction030(PVOID b1, PVOID b2)
|
---|
2256 | {
|
---|
2257 | return !memcmp(b1, b2, 0x10);
|
---|
2258 | }
|
---|
2259 |
|
---|
2260 | /******************************************************************************
|
---|
2261 | * SystemFunction035 (ADVAPI32.@)
|
---|
2262 | *
|
---|
2263 | * Described here:
|
---|
2264 | http://disc.server.com/discussion.cgi?disc=148775;article=942;title=Coding%2FASM%2FSystem
|
---|
2265 | *
|
---|
2266 | * NOTES
|
---|
2267 | * Stub, always return TRUE.
|
---|
2268 | */
|
---|
2269 | BOOL WINAPI SystemFunction035(LPCSTR lpszDllFilePath)
|
---|
2270 | {
|
---|
2271 | FIXME("%s: stub\n", debugstr_a(lpszDllFilePath));
|
---|
2272 | return TRUE;
|
---|
2273 | }
|
---|
2274 |
|
---|
2275 | /******************************************************************************
|
---|
2276 | * SystemFunction036 (ADVAPI32.@)
|
---|
2277 | *
|
---|
2278 | * MSDN documents this function as RtlGenRandom and declares it in ntsecapi.h
|
---|
2279 | *
|
---|
2280 | * PARAMS
|
---|
2281 | * pbBufer [O] Pointer to memory to receive random bytes.
|
---|
2282 | * dwLen [I] Number of random bytes to fetch.
|
---|
2283 | *
|
---|
2284 | * RETURNS
|
---|
2285 | * Success: TRUE
|
---|
2286 | * Failure: FALSE
|
---|
2287 | */
|
---|
2288 |
|
---|
2289 | BOOL WINAPI SystemFunction036(PVOID pbBuffer, ULONG dwLen)
|
---|
2290 | {
|
---|
2291 | char *rand_buf = (char*)pbBuffer;
|
---|
2292 | int i;
|
---|
2293 |
|
---|
2294 | if (!pbBuffer || dwLen <= 0)
|
---|
2295 | {
|
---|
2296 | dprintf(("SystemFunction036 error. cannot get random number length %d", dwLen));
|
---|
2297 | SetLastError(NTE_FAIL);
|
---|
2298 | return FALSE;
|
---|
2299 | }
|
---|
2300 |
|
---|
2301 | for (i=0; i<dwLen; i++)
|
---|
2302 | {
|
---|
2303 | rand_buf[i] = (char)rand();
|
---|
2304 | }
|
---|
2305 | return TRUE;
|
---|
2306 | }
|
---|
2307 |
|
---|
2308 | /*
|
---|
2309 | These functions have nearly identical prototypes to CryptProtectMemory and CryptUnprotectMemory,
|
---|
2310 | in crypt32.dll.
|
---|
2311 | */
|
---|
2312 |
|
---|
2313 | /******************************************************************************
|
---|
2314 | * SystemFunction040 (ADVAPI32.@)
|
---|
2315 | *
|
---|
2316 | * MSDN documents this function as RtlEncryptMemory.
|
---|
2317 | *
|
---|
2318 | * PARAMS
|
---|
2319 | * memory [I/O] Pointer to memory to encrypt.
|
---|
2320 | * length [I] Length of region to encrypt in bytes.
|
---|
2321 | * flags [I] Control whether other processes are able to decrypt the memory.
|
---|
2322 | * RTL_ENCRYPT_OPTION_SAME_PROCESS
|
---|
2323 | * RTL_ENCRYPT_OPTION_CROSS_PROCESS
|
---|
2324 | * RTL_ENCRYPT_OPTION_SAME_LOGON
|
---|
2325 | *
|
---|
2326 | * RETURNS
|
---|
2327 | * Success: STATUS_SUCCESS
|
---|
2328 | * Failure: NTSTATUS error code
|
---|
2329 | *
|
---|
2330 | * NOTES
|
---|
2331 | * length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
|
---|
2332 | * If flags are specified when encrypting, the same flag value must be given
|
---|
2333 | * when decrypting the memory.
|
---|
2334 | */
|
---|
2335 | NTSTATUS WINAPI SystemFunction040(PVOID memory, ULONG length, ULONG flags)
|
---|
2336 | {
|
---|
2337 | FIXME("(%p, %x, %x): stub [RtlEncryptMemory]\n", memory, length, flags);
|
---|
2338 | return STATUS_SUCCESS;
|
---|
2339 | }
|
---|
2340 |
|
---|
2341 | /******************************************************************************
|
---|
2342 | * SystemFunction041 (ADVAPI32.@)
|
---|
2343 | *
|
---|
2344 | * MSDN documents this function as RtlDecryptMemory.
|
---|
2345 | *
|
---|
2346 | * PARAMS
|
---|
2347 | * memory [I/O] Pointer to memory to decrypt.
|
---|
2348 | * length [I] Length of region to decrypt in bytes.
|
---|
2349 | * flags [I] Control whether other processes are able to decrypt the memory.
|
---|
2350 | * RTL_ENCRYPT_OPTION_SAME_PROCESS
|
---|
2351 | * RTL_ENCRYPT_OPTION_CROSS_PROCESS
|
---|
2352 | * RTL_ENCRYPT_OPTION_SAME_LOGON
|
---|
2353 | *
|
---|
2354 | * RETURNS
|
---|
2355 | * Success: STATUS_SUCCESS
|
---|
2356 | * Failure: NTSTATUS error code
|
---|
2357 | *
|
---|
2358 | * NOTES
|
---|
2359 | * length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
|
---|
2360 | * If flags are specified when encrypting, the same flag value must be given
|
---|
2361 | * when decrypting the memory.
|
---|
2362 | */
|
---|
2363 | NTSTATUS WINAPI SystemFunction041(PVOID memory, ULONG length, ULONG flags)
|
---|
2364 | {
|
---|
2365 | FIXME("(%p, %x, %x): stub [RtlDecryptMemory]\n", memory, length, flags);
|
---|
2366 | return STATUS_SUCCESS;
|
---|
2367 | }
|
---|