2 * Copyright 1999 Ian Schmidt
3 * Copyright 2001 Travis Michielsen
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 /***********************************************************************
23 * - Reference counting
25 * - Signature checking
32 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(crypt
);
45 HWND crypt_hWindow
= 0;
47 #define CRYPT_ReturnLastError(err) {SetLastError(err); return FALSE;}
49 #define CRYPT_Alloc(size) ((LPVOID)LocalAlloc(LMEM_ZEROINIT, size))
50 #define CRYPT_Free(buffer) (LocalFree((HLOCAL)buffer))
52 static inline PSTR
CRYPT_GetProvKeyName(PCSTR pProvName
)
54 const PSTR KEYSTR
= "Software\\Microsoft\\Cryptography\\Defaults\\Provider\\";
57 keyname
= CRYPT_Alloc(strlen(KEYSTR
) + strlen(pProvName
) +1);
60 strcpy(keyname
, KEYSTR
);
61 strcpy(keyname
+ strlen(KEYSTR
), pProvName
);
63 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
67 static inline PSTR
CRYPT_GetTypeKeyName(DWORD dwType
, BOOL user
)
69 const PSTR MACHINESTR
= "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types\\Type XXX";
70 const PSTR USERSTR
= "Software\\Microsoft\\Cryptography\\Provider Type XXX";
74 keyname
= CRYPT_Alloc( (user
? strlen(USERSTR
) : strlen(MACHINESTR
)) +1);
77 user
? strcpy(keyname
, USERSTR
) : strcpy(keyname
, MACHINESTR
);
78 ptr
= keyname
+ strlen(keyname
);
79 *(--ptr
) = (dwType
% 10) + '0';
80 *(--ptr
) = (dwType
/ 10) + '0';
81 *(--ptr
) = (dwType
/ 100) + '0';
83 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
87 /* CRYPT_UnicodeTOANSI
88 * wstr - unicode string
89 * str - pointer to ANSI string
90 * strsize - size of buffer pointed to by str or -1 if we have to do the allocation
92 * returns TRUE if unsuccessfull, FALSE otherwise.
93 * if wstr is NULL, returns TRUE and sets str to NULL! Value of str should be checked after call
95 static inline BOOL
CRYPT_UnicodeToANSI(LPCWSTR wstr
, LPSTR
* str
, int strsize
)
104 count
= WideCharToMultiByte(CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
105 count
= count
< strsize
? count
: strsize
;
107 *str
= CRYPT_Alloc(count
* sizeof(CHAR
));
110 WideCharToMultiByte(CP_ACP
, 0, wstr
, -1, *str
, count
, NULL
, NULL
);
113 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
117 /* CRYPT_ANSITOUnicode
119 * wstr - pointer to unicode string
120 * wstrsize - size of buffer pointed to by wstr or -1 if we have to do the allocation
122 static inline BOOL
CRYPT_ANSIToUnicode(LPCSTR str
, LPWSTR
* wstr
, int wstrsize
)
131 wcount
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
132 wcount
= wcount
< wstrsize
/sizeof(WCHAR
) ? wcount
: wstrsize
/sizeof(WCHAR
);
134 *wstr
= CRYPT_Alloc(wcount
* sizeof(WCHAR
));
137 MultiByteToWideChar(CP_ACP
, 0, str
, -1, *wstr
, wcount
);
140 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
144 /* These next 2 functions are used by the VTableProvStruc structure */
145 BOOL
CRYPT_VerifyImage(LPCSTR lpszImage
, BYTE
* pData
)
147 if (!lpszImage
|| !pData
)
149 SetLastError(ERROR_INVALID_PARAMETER
);
152 /* FIXME: Actually verify the image! */
156 BOOL
CRYPT_ReturnhWnd(HWND
*phWnd
)
160 *phWnd
= crypt_hWindow
;
164 #define CRYPT_GetProvFunc(name) \
165 if ( !(provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)) ) goto error
166 #define CRYPT_GetProvFuncOpt(name) \
167 provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)
168 PCRYPTPROV
CRYPT_LoadProvider(PSTR pImage
)
171 DWORD errorcode
= ERROR_NOT_ENOUGH_MEMORY
;
173 if ( !(provider
= CRYPT_Alloc(sizeof(CRYPTPROV
))) ) goto error
;
174 if ( !(provider
->pFuncs
= CRYPT_Alloc(sizeof(PROVFUNCS
))) ) goto error
;
175 if ( !(provider
->pVTable
= CRYPT_Alloc(sizeof(VTableProvStruc
))) ) goto error
;
176 if ( !(provider
->hModule
= LoadLibraryA(pImage
)) )
178 errorcode
= (GetLastError() == ERROR_FILE_NOT_FOUND
) ? NTE_PROV_DLL_NOT_FOUND
: NTE_PROVIDER_DLL_FAIL
;
182 errorcode
= NTE_PROVIDER_DLL_FAIL
;
183 CRYPT_GetProvFunc(CPAcquireContext
);
184 CRYPT_GetProvFunc(CPCreateHash
);
185 CRYPT_GetProvFunc(CPDecrypt
);
186 CRYPT_GetProvFunc(CPDeriveKey
);
187 CRYPT_GetProvFunc(CPDestroyHash
);
188 CRYPT_GetProvFunc(CPDestroyKey
);
189 CRYPT_GetProvFuncOpt(CPDuplicateHash
);
190 CRYPT_GetProvFuncOpt(CPDuplicateKey
);
191 CRYPT_GetProvFunc(CPEncrypt
);
192 CRYPT_GetProvFunc(CPExportKey
);
193 CRYPT_GetProvFunc(CPGenKey
);
194 CRYPT_GetProvFunc(CPGenRandom
);
195 CRYPT_GetProvFunc(CPGetHashParam
);
196 CRYPT_GetProvFunc(CPGetKeyParam
);
197 CRYPT_GetProvFunc(CPGetProvParam
);
198 CRYPT_GetProvFunc(CPGetUserKey
);
199 CRYPT_GetProvFunc(CPHashData
);
200 CRYPT_GetProvFunc(CPHashSessionKey
);
201 CRYPT_GetProvFunc(CPImportKey
);
202 CRYPT_GetProvFunc(CPReleaseContext
);
203 CRYPT_GetProvFunc(CPSetHashParam
);
204 CRYPT_GetProvFunc(CPSetKeyParam
);
205 CRYPT_GetProvFunc(CPSetProvParam
);
206 CRYPT_GetProvFunc(CPSignHash
);
207 CRYPT_GetProvFunc(CPVerifySignature
);
209 /* FIXME: Not sure what the pbContextInfo field is for.
210 * Does it need memory allocation?
212 provider
->pVTable
->Version
= 3;
213 provider
->pVTable
->pFuncVerifyImage
= CRYPT_VerifyImage
;
214 provider
->pVTable
->pFuncReturnhWnd
= CRYPT_ReturnhWnd
;
215 provider
->pVTable
->dwProvType
= 0;
216 provider
->pVTable
->pbContextInfo
= NULL
;
217 provider
->pVTable
->cbContextInfo
= 0;
218 provider
->pVTable
->pszProvName
= NULL
;
222 SetLastError(errorcode
);
225 if (provider
->hModule
)
226 FreeLibrary(provider
->hModule
);
227 CRYPT_Free(provider
->pVTable
);
228 CRYPT_Free(provider
->pFuncs
);
229 CRYPT_Free(provider
);
233 #undef CRYPT_GetProvFunc
234 #undef CRYPT_GetProvFuncOpt
237 /******************************************************************************
238 * CryptAcquireContextA (ADVAPI32.@)
239 * Acquire a crypto provider context handle.
242 * phProv: Pointer to HCRYPTPROV for the output.
243 * pszContainer: Key Container Name
244 * pszProvider: Cryptographic Service Provider Name
245 * dwProvType: Crypto provider type to get a handle.
246 * dwFlags: flags for the operation
248 * RETURNS TRUE on success, FALSE on failure.
250 BOOL WINAPI
CryptAcquireContextA (HCRYPTPROV
*phProv
, LPCSTR pszContainer
,
251 LPCSTR pszProvider
, DWORD dwProvType
, DWORD dwFlags
)
253 PCRYPTPROV pProv
= NULL
;
255 PSTR imagepath
= NULL
, keyname
= NULL
, provname
= NULL
, temp
= NULL
;
259 DWORD keytype
, type
, len
;
261 TRACE("(%p, %s, %s, %ld, %08lx)\n", phProv
, pszContainer
,
262 pszProvider
, dwProvType
, dwFlags
);
264 if (!phProv
|| !dwProvType
)
266 SetLastError(ERROR_INVALID_PARAMETER
);
269 if (dwProvType
> MAXPROVTYPES
)
271 SetLastError(NTE_BAD_PROV_TYPE
);
277 /* No CSP name specified so try the user default CSP first
278 * then try the machine default CSP
280 if ( !(keyname
= CRYPT_GetTypeKeyName(dwProvType
, TRUE
)) )
281 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
282 if (RegOpenKeyA(HKEY_CURRENT_USER
, keyname
, &key
))
285 if ( !(keyname
= CRYPT_GetTypeKeyName(dwProvType
, FALSE
)) )
286 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
287 if (RegOpenKeyA(HKEY_LOCAL_MACHINE
, keyname
, &key
)) goto error
;
290 RegQueryValueExA(key
, "Name", NULL
, &keytype
, NULL
, &len
);
291 if (!len
|| keytype
!= REG_SZ
|| !(provname
= CRYPT_Alloc(len
))) goto error
;
292 RegQueryValueExA(key
, "Name", NULL
, NULL
, provname
, &len
);
295 if ( !(provname
= CRYPT_Alloc(strlen(pszProvider
) +1)) )
296 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
297 strcpy(provname
, pszProvider
);
300 keyname
= CRYPT_GetProvKeyName(provname
);
301 if (RegOpenKeyA(HKEY_LOCAL_MACHINE
, keyname
, &key
)) goto error
;
304 RegQueryValueExA(key
, "Type", NULL
, NULL
, (BYTE
*)&type
, &len
);
305 if (type
!= dwProvType
)
307 SetLastError(NTE_BAD_PROV_TYPE
);
311 RegQueryValueExA(key
, "Image Path", NULL
, &keytype
, NULL
, &len
);
312 if (keytype
!= REG_SZ
|| !(temp
= CRYPT_Alloc(len
))) goto error
;
313 RegQueryValueExA(key
, "Image Path", NULL
, NULL
, temp
, &len
);
316 len
= ExpandEnvironmentStringsA(temp
, NULL
, 0);
317 if ( !(imagepath
= CRYPT_Alloc(len
)) )
319 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
322 if (!ExpandEnvironmentStringsA(temp
, imagepath
, len
)) goto error
;
325 if (!CRYPT_VerifyImage(imagepath
, signature
)) goto error
;
327 pProv
= CRYPT_LoadProvider(imagepath
);
329 CRYPT_Free(imagepath
);
330 if (!pProv
) goto error
;
332 if (pProv
->pFuncs
->pCPAcquireContext(&pProv
->hPrivate
, (CHAR
*)pszContainer
, dwFlags
, pProv
->pVTable
))
334 /* MSDN: When this flag is set, the value returned in phProv is undefined,
335 * and thus, the CryptReleaseContext function need not be called afterwards.
336 * Therefore, we must clean up everything now.
338 if (dwFlags
& CRYPT_DELETEKEYSET
)
340 FreeLibrary(pProv
->hModule
);
341 CRYPT_Free(provname
);
342 CRYPT_Free(pProv
->pFuncs
);
345 pProv
->pVTable
->pszProvName
= provname
;
346 pProv
->pVTable
->dwProvType
= dwProvType
;
347 *phProv
= (HCRYPTPROV
)pProv
;
351 /* FALLTHROUGH TO ERROR IF FALSE - CSP internal error! */
355 FreeLibrary(pProv
->hModule
);
356 CRYPT_Free(pProv
->pVTable
);
357 CRYPT_Free(pProv
->pFuncs
);
360 CRYPT_Free(provname
);
362 CRYPT_Free(imagepath
);
367 /******************************************************************************
368 * CryptAcquireContextW (ADVAPI32.@)
370 BOOL WINAPI
CryptAcquireContextW (HCRYPTPROV
*phProv
, LPCWSTR pszContainer
,
371 LPCWSTR pszProvider
, DWORD dwProvType
, DWORD dwFlags
)
373 PSTR pProvider
= NULL
, pContainer
= NULL
;
376 TRACE("(%p, %s, %s, %ld, %08lx)\n", phProv
, debugstr_w(pszContainer
),
377 debugstr_w(pszProvider
), dwProvType
, dwFlags
);
379 if ( !CRYPT_UnicodeToANSI(pszContainer
, &pContainer
, -1) )
380 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
381 if ( !CRYPT_UnicodeToANSI(pszProvider
, &pProvider
, -1) )
383 CRYPT_Free(pContainer
);
384 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
387 ret
= CryptAcquireContextA(phProv
, pContainer
, pProvider
, dwProvType
, dwFlags
);
390 CRYPT_Free(pContainer
);
392 CRYPT_Free(pProvider
);
397 /******************************************************************************
398 * CryptContextAddRef (ADVAPI32.@)
400 BOOL WINAPI
CryptContextAddRef (HCRYPTPROV hProv
, DWORD
*pdwReserved
, DWORD dwFlags
)
402 FIXME("(0x%lx, %p, %08lx): stub!\n", hProv
, pdwReserved
, dwFlags
);
404 /* InterlockIncrement?? */
407 /******************************************************************************
408 * CryptReleaseContext (ADVAPI32.@)
410 BOOL WINAPI
CryptReleaseContext (HCRYPTPROV hProv
, DWORD dwFlags
)
412 PCRYPTPROV pProv
= (PCRYPTPROV
)hProv
;
415 TRACE("(0x%lx, %08ld)\n", hProv
, dwFlags
);
419 SetLastError(NTE_BAD_UID
);
422 /* FIXME: Decrement the counter here first if possible */
423 ret
= pProv
->pFuncs
->pCPReleaseContext(pProv
->hPrivate
, dwFlags
);
424 FreeLibrary(pProv
->hModule
);
426 CRYPT_Free(pProv
->pVTable
->pContextInfo
);
428 CRYPT_Free(pProv
->pVTable
->pszProvName
);
429 CRYPT_Free(pProv
->pVTable
);
430 CRYPT_Free(pProv
->pFuncs
);
435 /******************************************************************************
436 * CryptGenRandom (ADVAPI32.@)
438 BOOL WINAPI
CryptGenRandom (HCRYPTPROV hProv
, DWORD dwLen
, BYTE
*pbBuffer
)
440 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
442 TRACE("(0x%lx, %ld, %p)\n", hProv
, dwLen
, pbBuffer
);
445 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
447 return prov
->pFuncs
->pCPGenRandom(prov
->hPrivate
, dwLen
, pbBuffer
);
450 /******************************************************************************
451 * CryptCreateHash (ADVAPI32.@)
453 BOOL WINAPI
CryptCreateHash (HCRYPTPROV hProv
, ALG_ID Algid
, HCRYPTKEY hKey
,
454 DWORD dwFlags
, HCRYPTHASH
*phHash
)
456 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
457 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
460 TRACE("(0x%lx, 0x%x, 0x%lx, %08lx, %p)\n", hProv
, Algid
, hKey
, dwFlags
, phHash
);
463 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
465 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
467 CRYPT_ReturnLastError(NTE_BAD_FLAGS
);
468 if ( !(hash
= CRYPT_Alloc(sizeof(CRYPTHASH
))) )
469 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
471 hash
->pProvider
= prov
;
473 if (prov
->pFuncs
->pCPCreateHash(prov
->hPrivate
, Algid
,
474 key
? key
->hPrivate
: 0, 0, &hash
->hPrivate
))
476 *phHash
= (HCRYPTHASH
)hash
;
485 /******************************************************************************
486 * CryptDecrypt (ADVAPI32.@)
488 BOOL WINAPI
CryptDecrypt (HCRYPTKEY hKey
, HCRYPTHASH hHash
, BOOL Final
,
489 DWORD dwFlags
, BYTE
*pbData
, DWORD
*pdwDataLen
)
492 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
493 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
495 TRACE("(0x%lx, 0x%lx, %d, %08lx, %p, %p)\n", hKey
, hHash
, Final
, dwFlags
, pbData
, pdwDataLen
);
497 if (!key
|| !pbData
|| !pdwDataLen
)
498 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
500 prov
= key
->pProvider
;
501 return prov
->pFuncs
->pCPDecrypt(prov
->hPrivate
, key
->hPrivate
, hash
? hash
->hPrivate
: 0,
502 Final
, dwFlags
, pbData
, pdwDataLen
);
505 /******************************************************************************
506 * CryptDeriveKey (ADVAPI32.@)
508 BOOL WINAPI
CryptDeriveKey (HCRYPTPROV hProv
, ALG_ID Algid
, HCRYPTHASH hBaseData
,
509 DWORD dwFlags
, HCRYPTKEY
*phKey
)
511 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
512 PCRYPTHASH hash
= (PCRYPTHASH
)hBaseData
;
515 TRACE("(0x%lx, %d, 0x%ld, %08ld, %p)\n", hProv
, Algid
, hBaseData
, dwFlags
, phKey
);
518 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
520 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
521 if ( !(key
= CRYPT_Alloc(sizeof(CRYPTKEY
))) )
522 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
524 key
->pProvider
= prov
;
525 if (prov
->pFuncs
->pCPDeriveKey(prov
->hPrivate
, Algid
, hash
->hPrivate
, dwFlags
, &key
->hPrivate
))
527 *phKey
= (HCRYPTKEY
)key
;
536 /******************************************************************************
537 * CryptDestroyHash (ADVAPI32.@)
539 BOOL WINAPI
CryptDestroyHash (HCRYPTHASH hHash
)
541 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
545 TRACE("(0x%lx)\n", hHash
);
548 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
550 prov
= hash
->pProvider
;
551 ret
= prov
->pFuncs
->pCPDestroyHash(prov
->hPrivate
, hash
->hPrivate
);
556 /******************************************************************************
557 * CryptDestroyKey (ADVAPI32.@)
559 BOOL WINAPI
CryptDestroyKey (HCRYPTKEY hKey
)
561 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
565 TRACE("(0x%lx)\n", hKey
);
568 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
570 prov
= key
->pProvider
;
571 ret
= prov
->pFuncs
->pCPDestroyKey(prov
->hPrivate
, key
->hPrivate
);
576 /******************************************************************************
577 * CryptDuplicateHash (ADVAPI32.@)
579 BOOL WINAPI
CryptDuplicateHash (HCRYPTHASH hHash
, DWORD
*pdwReserved
,
580 DWORD dwFlags
, HCRYPTHASH
*phHash
)
583 PCRYPTHASH orghash
, newhash
;
585 TRACE("(0x%lx, %p, %08ld, %p)\n", hHash
, pdwReserved
, dwFlags
, phHash
);
587 orghash
= (PCRYPTHASH
)hHash
;
588 if (!orghash
|| pdwReserved
|| !phHash
)
589 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
591 prov
= orghash
->pProvider
;
592 if (!prov
->pFuncs
->pCPDuplicateHash
)
593 CRYPT_ReturnLastError(ERROR_CALL_NOT_IMPLEMENTED
);
595 if ( !(newhash
= CRYPT_Alloc(sizeof(CRYPTHASH
))) )
596 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
598 newhash
->pProvider
= prov
;
599 if (prov
->pFuncs
->pCPDuplicateHash(prov
->hPrivate
, orghash
->hPrivate
, pdwReserved
, dwFlags
, &newhash
->hPrivate
))
601 *phHash
= (HCRYPTHASH
)newhash
;
608 /******************************************************************************
609 * CryptDuplicateKey (ADVAPI32.@)
611 BOOL WINAPI
CryptDuplicateKey (HCRYPTKEY hKey
, DWORD
*pdwReserved
, DWORD dwFlags
, HCRYPTKEY
*phKey
)
614 PCRYPTKEY orgkey
, newkey
;
616 TRACE("(0x%lx, %p, %08ld, %p)\n", hKey
, pdwReserved
, dwFlags
, phKey
);
618 orgkey
= (PCRYPTKEY
)hKey
;
619 if (!orgkey
|| pdwReserved
|| !phKey
)
620 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
622 prov
= orgkey
->pProvider
;
623 if (!prov
->pFuncs
->pCPDuplicateKey
)
624 CRYPT_ReturnLastError(ERROR_CALL_NOT_IMPLEMENTED
);
626 if ( !(newkey
= CRYPT_Alloc(sizeof(CRYPTKEY
))) )
627 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
629 newkey
->pProvider
= prov
;
630 if (prov
->pFuncs
->pCPDuplicateKey(prov
->hPrivate
, orgkey
->hPrivate
, pdwReserved
, dwFlags
, &newkey
->hPrivate
))
632 *phKey
= (HCRYPTKEY
)newkey
;
639 /******************************************************************************
640 * CryptEncrypt (ADVAPI32.@)
642 BOOL WINAPI
CryptEncrypt (HCRYPTKEY hKey
, HCRYPTHASH hHash
, BOOL Final
,
643 DWORD dwFlags
, BYTE
*pbData
, DWORD
*pdwDataLen
, DWORD dwBufLen
)
646 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
647 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
649 TRACE("(0x%lx, 0x%lx, %d, %08ld, %p, %p, %ld)\n", hKey
, hHash
, Final
, dwFlags
, pbData
, pdwDataLen
, dwBufLen
);
651 if (!key
|| !pdwDataLen
)
652 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
654 prov
= key
->pProvider
;
655 return prov
->pFuncs
->pCPEncrypt(prov
->hPrivate
, key
->hPrivate
, hash
? hash
->hPrivate
: 0,
656 Final
, dwFlags
, pbData
, pdwDataLen
, dwBufLen
);
659 /******************************************************************************
660 * CryptEnumProvidersA (ADVAPI32.@)
662 BOOL WINAPI
CryptEnumProvidersA (DWORD dwIndex
, DWORD
*pdwReserved
,
663 DWORD dwFlags
, DWORD
*pdwProvType
, LPSTR pszProvName
, DWORD
*pcbProvName
)
667 TRACE("(%ld, %p, %ld, %p, %p, %p)\n", dwIndex
, pdwReserved
, dwFlags
,
668 pdwProvType
, pszProvName
, pcbProvName
);
670 if (pdwReserved
|| !pcbProvName
) CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
671 if (dwFlags
) CRYPT_ReturnLastError(NTE_BAD_FLAGS
);
673 if (RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\Cryptography\\Defaults\\Provider", &hKey
))
674 CRYPT_ReturnLastError(NTE_FAIL
);
679 RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, &numkeys
, pcbProvName
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
681 if (dwIndex
>= numkeys
)
682 CRYPT_ReturnLastError(ERROR_NO_MORE_ITEMS
);
684 DWORD size
= sizeof(DWORD
);
686 if (RegEnumKeyA(hKey
, dwIndex
, pszProvName
, *pcbProvName
))
688 if (RegOpenKeyA(hKey
, pszProvName
, &subkey
))
690 if (RegQueryValueExA(subkey
, "Type", NULL
, NULL
, (BYTE
*)pdwProvType
, &size
))
698 /******************************************************************************
699 * CryptEnumProvidersW (ADVAPI32.@)
701 BOOL WINAPI
CryptEnumProvidersW (DWORD dwIndex
, DWORD
*pdwReserved
,
702 DWORD dwFlags
, DWORD
*pdwProvType
, LPWSTR pszProvName
, DWORD
*pcbProvName
)
706 BOOL ret
; /* = FALSE; */
708 TRACE("(%ld, %p, %08ld, %p, %p, %p)\n", dwIndex
, pdwReserved
, dwFlags
,
709 pdwProvType
, pszProvName
, pcbProvName
);
711 strlen
= *pcbProvName
/ sizeof(WCHAR
);
712 if ( pszProvName
&& (str
= CRYPT_Alloc(strlen
)) )
713 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
714 ret
= CryptEnumProvidersA(dwIndex
, pdwReserved
, dwFlags
, pdwProvType
, str
, &strlen
);
717 CRYPT_ANSIToUnicode(str
, &pszProvName
, *pcbProvName
);
720 *pcbProvName
= strlen
* sizeof(WCHAR
);
724 /******************************************************************************
725 * CryptEnumProviderTypesA (ADVAPI32.@)
727 BOOL WINAPI
CryptEnumProviderTypesA (DWORD dwIndex
, DWORD
*pdwReserved
,
728 DWORD dwFlags
, DWORD
*pdwProvType
, LPSTR pszTypeName
, DWORD
*pcbTypeName
)
731 DWORD keylen
, numkeys
;
734 TRACE("(%ld, %p, %08ld, %p, %p, %p)\n", dwIndex
, pdwReserved
,
735 dwFlags
, pdwProvType
, pszTypeName
, pcbTypeName
);
737 if (pdwReserved
|| !pdwProvType
|| !pcbTypeName
)
738 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
739 if (dwFlags
) CRYPT_ReturnLastError(NTE_BAD_FLAGS
);
741 if (RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types", &hKey
))
744 RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, &numkeys
, &keylen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
745 if (dwIndex
>= numkeys
)
746 CRYPT_ReturnLastError(ERROR_NO_MORE_ITEMS
);
748 if ( !(keyname
= CRYPT_Alloc(keylen
)) )
749 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
750 if ( RegEnumKeyA(hKey
, dwIndex
, keyname
, keylen
) )
752 RegOpenKeyA(hKey
, keyname
, &hSubkey
);
753 ch
= keyname
+ strlen(keyname
);
754 /* Convert "Type 000" to 0, etc/ */
755 *pdwProvType
= *(--ch
) - '0';
756 *pdwProvType
+= (*(--ch
) - '0') * 10;
757 *pdwProvType
+= (*(--ch
) - '0') * 100;
759 RegQueryValueA(hSubkey
, "TypeName", pszTypeName
, pcbTypeName
);
760 RegCloseKey(hSubkey
);
765 /******************************************************************************
766 * CryptEnumProviderTypesW (ADVAPI32.@)
768 BOOL WINAPI
CryptEnumProviderTypesW (DWORD dwIndex
, DWORD
*pdwReserved
,
769 DWORD dwFlags
, DWORD
*pdwProvType
, LPWSTR pszTypeName
, DWORD
*pcbTypeName
)
775 TRACE("(%ld, %p, %08ld, %p, %p, %p)\n", dwIndex
, pdwReserved
, dwFlags
,
776 pdwProvType
, pszTypeName
, pcbTypeName
);
777 strlen
= *pcbTypeName
/ sizeof(WCHAR
);
778 if ( pszTypeName
&& (str
= CRYPT_Alloc(strlen
)) )
779 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
780 ret
= CryptEnumProviderTypesA(dwIndex
, pdwReserved
, dwFlags
, pdwProvType
, str
, &strlen
);
783 CRYPT_ANSIToUnicode(str
, &pszTypeName
, *pcbTypeName
);
786 *pcbTypeName
= strlen
* sizeof(WCHAR
);
790 /******************************************************************************
791 * CryptExportKey (ADVAPI32.@)
793 BOOL WINAPI
CryptExportKey (HCRYPTKEY hKey
, HCRYPTKEY hExpKey
, DWORD dwBlobType
,
794 DWORD dwFlags
, BYTE
*pbData
, DWORD
*pdwDataLen
)
797 PCRYPTKEY key
= (PCRYPTKEY
)hKey
, expkey
= (PCRYPTKEY
)hExpKey
;
799 TRACE("(0x%lx, 0x%lx, %ld, %08ld, %p, %p)\n", hKey
, hExpKey
, dwBlobType
, dwFlags
, pbData
, pdwDataLen
);
801 if (!key
|| pdwDataLen
)
802 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
804 prov
= key
->pProvider
;
805 return prov
->pFuncs
->pCPExportKey(prov
->hPrivate
, key
->hPrivate
, expkey
? expkey
->hPrivate
: 0,
806 dwBlobType
, dwFlags
, pbData
, pdwDataLen
);
809 /******************************************************************************
810 * CryptGenKey (ADVAPI32.@)
812 BOOL WINAPI
CryptGenKey (HCRYPTPROV hProv
, ALG_ID Algid
, DWORD dwFlags
, HCRYPTKEY
*phKey
)
814 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
817 TRACE("(0x%lx, %d, %08ld, %p)\n", hProv
, Algid
, dwFlags
, phKey
);
820 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
822 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
823 if ( !(key
= CRYPT_Alloc(sizeof(CRYPTKEY
))) )
824 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
826 key
->pProvider
= prov
;
828 if (prov
->pFuncs
->pCPGenKey(prov
->hPrivate
, Algid
, dwFlags
, &key
->hPrivate
))
830 *phKey
= (HCRYPTKEY
)key
;
839 /******************************************************************************
840 * CryptGetDefaultProviderA (ADVAPI32.@)
842 BOOL WINAPI
CryptGetDefaultProviderA (DWORD dwProvType
, DWORD
*pdwReserved
,
843 DWORD dwFlags
, LPSTR pszProvName
, DWORD
*pcbProvName
)
848 if (pdwReserved
|| !pcbProvName
)
849 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
850 if (dwFlags
& ~(CRYPT_USER_DEFAULT
| CRYPT_MACHINE_DEFAULT
))
851 CRYPT_ReturnLastError(NTE_BAD_FLAGS
);
852 if (dwProvType
> 999)
853 CRYPT_ReturnLastError(NTE_BAD_PROV_TYPE
);
854 if ( !(keyname
= CRYPT_GetTypeKeyName(dwProvType
, dwFlags
& CRYPT_USER_DEFAULT
)) )
855 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
856 if (RegOpenKeyA((dwFlags
& CRYPT_USER_DEFAULT
) ? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
,keyname
, &hKey
))
859 CRYPT_ReturnLastError(NTE_PROV_TYPE_NOT_DEF
);
862 if (RegQueryValueExA(hKey
, "Name", NULL
, NULL
, pszProvName
, pcbProvName
))
864 if (GetLastError() != ERROR_MORE_DATA
)
865 SetLastError(NTE_PROV_TYPE_ENTRY_BAD
);
872 /******************************************************************************
873 * CryptGetDefaultProviderW (ADVAPI32.@)
875 BOOL WINAPI
CryptGetDefaultProviderW (DWORD dwProvType
, DWORD
*pdwReserved
,
876 DWORD dwFlags
, LPWSTR pszProvName
, DWORD
*pcbProvName
)
882 TRACE("(%ld, %p, %08ld, %p, %p)\n", dwProvType
, pdwReserved
, dwFlags
, pszProvName
, pcbProvName
);
884 strlen
= *pcbProvName
/ sizeof(WCHAR
);
885 if ( pszProvName
&& !(str
= CRYPT_Alloc(strlen
)) )
886 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
887 ret
= CryptGetDefaultProviderA(dwProvType
, pdwReserved
, dwFlags
, str
, &strlen
);
890 CRYPT_ANSIToUnicode(str
, &pszProvName
, *pcbProvName
);
893 *pcbProvName
= strlen
* sizeof(WCHAR
);
897 /******************************************************************************
898 * CryptGetHashParam (ADVAPI32.@)
900 BOOL WINAPI
CryptGetHashParam (HCRYPTHASH hHash
, DWORD dwParam
, BYTE
*pbData
,
901 DWORD
*pdwDataLen
, DWORD dwFlags
)
904 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
906 TRACE("(0x%lx, %ld, %p, %p, %08ld)\n", hHash
, dwParam
, pbData
, pdwDataLen
, dwFlags
);
908 if (!hash
|| !pdwDataLen
)
909 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
911 prov
= hash
->pProvider
;
912 return prov
->pFuncs
->pCPGetHashParam(prov
->hPrivate
, hash
->hPrivate
, dwParam
,
913 pbData
, pdwDataLen
, dwFlags
);
916 /******************************************************************************
917 * CryptGetKeyParam (ADVAPI32.@)
919 BOOL WINAPI
CryptGetKeyParam (HCRYPTKEY hKey
, DWORD dwParam
, BYTE
*pbData
,
920 DWORD
*pdwDataLen
, DWORD dwFlags
)
923 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
925 TRACE("(0x%lx, %ld, %p, %p, %08ld)\n", hKey
, dwParam
, pbData
, pdwDataLen
, dwFlags
);
927 if (!key
|| !pdwDataLen
)
928 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
930 prov
= key
->pProvider
;
931 return prov
->pFuncs
->pCPGetKeyParam(prov
->hPrivate
, key
->hPrivate
, dwParam
,
932 pbData
, pdwDataLen
, dwFlags
);
935 /******************************************************************************
936 * CryptGetProvParam (ADVAPI32.@)
938 BOOL WINAPI
CryptGetProvParam (HCRYPTPROV hProv
, DWORD dwParam
, BYTE
*pbData
,
939 DWORD
*pdwDataLen
, DWORD dwFlags
)
941 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
943 TRACE("(0x%lx, %ld, %p, %p, %08ld)\n", hProv
, dwParam
, pbData
, pdwDataLen
, dwFlags
);
945 return prov
->pFuncs
->pCPGetProvParam(prov
->hPrivate
, dwParam
, pbData
, pdwDataLen
, dwFlags
);
948 /******************************************************************************
949 * CryptGetUserKey (ADVAPI32.@)
951 BOOL WINAPI
CryptGetUserKey (HCRYPTPROV hProv
, DWORD dwKeySpec
, HCRYPTKEY
*phUserKey
)
953 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
956 TRACE("(0x%lx, %ld, %p)\n", hProv
, dwKeySpec
, phUserKey
);
959 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
961 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
962 if ( !(key
= CRYPT_Alloc(sizeof(CRYPTKEY
))) )
963 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
965 key
->pProvider
= prov
;
967 if (prov
->pFuncs
->pCPGetUserKey(prov
->hPrivate
, dwKeySpec
, &key
->hPrivate
))
969 *phUserKey
= (HCRYPTKEY
)key
;
978 /******************************************************************************
979 * CryptHashData (ADVAPI32.@)
981 BOOL WINAPI
CryptHashData (HCRYPTHASH hHash
, BYTE
*pbData
, DWORD dwDataLen
, DWORD dwFlags
)
983 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
986 TRACE("(0x%lx, %p, %ld, %08ld)\n", hHash
, pbData
, dwDataLen
, dwFlags
);
989 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
990 if (!pbData
|| !dwDataLen
)
991 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
993 prov
= hash
->pProvider
;
994 return prov
->pFuncs
->pCPHashData(prov
->hPrivate
, hash
->hPrivate
, pbData
, dwDataLen
, dwFlags
);
997 /******************************************************************************
998 * CryptHashSessionKey (ADVAPI32.@)
1000 BOOL WINAPI
CryptHashSessionKey (HCRYPTHASH hHash
, HCRYPTKEY hKey
, DWORD dwFlags
)
1002 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
1003 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
1006 TRACE("(0x%lx, 0x%lx, %08ld)\n", hHash
, hKey
, dwFlags
);
1009 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
1011 prov
= hash
->pProvider
;
1012 return prov
->pFuncs
->pCPHashSessionKey(prov
->hPrivate
, hash
->hPrivate
, key
->hPrivate
, dwFlags
);
1015 /******************************************************************************
1016 * CryptImportKey (ADVAPI32.@)
1018 BOOL WINAPI
CryptImportKey (HCRYPTPROV hProv
, BYTE
*pbData
, DWORD dwDataLen
,
1019 HCRYPTKEY hPubKey
, DWORD dwFlags
, HCRYPTKEY
*phKey
)
1021 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
1022 PCRYPTKEY pubkey
= (PCRYPTKEY
)hPubKey
, importkey
;
1024 TRACE("(0x%lx, %p, %ld, 0x%lx, %08ld, %p)\n", hProv
, pbData
, dwDataLen
, hPubKey
, dwFlags
, phKey
);
1026 if (!prov
|| !pbData
|| !dwDataLen
|| !phKey
)
1027 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
1029 if ( !(importkey
= CRYPT_Alloc(sizeof(CRYPTKEY
))) )
1030 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
1032 importkey
->pProvider
= prov
;
1033 if (prov
->pFuncs
->pCPImportKey(prov
->hPrivate
, pbData
, dwDataLen
,
1034 pubkey
? pubkey
->hPrivate
: 0, dwFlags
, &importkey
->hPrivate
))
1036 *phKey
= (HCRYPTKEY
)importkey
;
1040 CRYPT_Free(importkey
);
1044 /******************************************************************************
1047 * Note: Since the sDesciption (string) is supposed to be NULL and
1048 * is only retained for compatibility no string conversions are required
1049 * and only one implementation is required for both ANSI and Unicode.
1050 * We still need to export both:
1052 * CryptSignHashA (ADVAPI32.@)
1053 * CryptSignHashW (ADVAPI32.@)
1055 BOOL WINAPI
CryptSignHashA (HCRYPTHASH hHash
, DWORD dwKeySpec
, LPCSTR sDescription
,
1056 DWORD dwFlags
, BYTE
*pbSignature
, DWORD
*pdwSigLen
)
1058 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
1061 TRACE("(0x%lx, %ld, %08ld, %p, %p)\n", hHash
, dwKeySpec
, dwFlags
, pbSignature
, pdwSigLen
);
1063 WARN("The sDescription parameter is not supported (and no longer used). Ignoring.\n");
1066 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
1068 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
1070 prov
= hash
->pProvider
;
1071 return prov
->pFuncs
->pCPSignHash(prov
->hPrivate
, hash
->hPrivate
, dwKeySpec
, NULL
,
1072 dwFlags
, pbSignature
, pdwSigLen
);
1075 /******************************************************************************
1076 * CryptSetHashParam (ADVAPI32.@)
1078 BOOL WINAPI
CryptSetHashParam (HCRYPTHASH hHash
, DWORD dwParam
, BYTE
*pbData
, DWORD dwFlags
)
1081 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
1083 TRACE("(0x%lx, %ld, %p, %08ld)\n", hHash
, dwParam
, pbData
, dwFlags
);
1085 if (!hash
|| !pbData
)
1086 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
1088 prov
= hash
->pProvider
;
1089 return prov
->pFuncs
->pCPSetHashParam(prov
->hPrivate
, hash
->hPrivate
,
1090 dwParam
, pbData
, dwFlags
);
1093 /******************************************************************************
1094 * CryptSetKeyParam (ADVAPI32.@)
1096 BOOL WINAPI
CryptSetKeyParam (HCRYPTKEY hKey
, DWORD dwParam
, BYTE
*pbData
, DWORD dwFlags
)
1099 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
1101 TRACE("(0x%lx, %ld, %p, %08ld)\n", hKey
, dwParam
, pbData
, dwFlags
);
1103 if (!key
|| !pbData
)
1104 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
1106 prov
= key
->pProvider
;
1107 return prov
->pFuncs
->pCPSetKeyParam(prov
->hPrivate
, key
->hPrivate
,
1108 dwParam
, pbData
, dwFlags
);
1111 /******************************************************************************
1112 * CryptSetProviderA (ADVAPI32.@)
1114 BOOL WINAPI
CryptSetProviderA (LPCSTR pszProvName
, DWORD dwProvType
)
1116 TRACE("(%s, %ld)\n", pszProvName
, dwProvType
);
1117 return CryptSetProviderExA(pszProvName
, dwProvType
, NULL
, CRYPT_USER_DEFAULT
);
1120 /******************************************************************************
1121 * CryptSetProviderW (ADVAPI32.@)
1123 BOOL WINAPI
CryptSetProviderW (LPCWSTR pszProvName
, DWORD dwProvType
)
1125 TRACE("(%s, %ld)\n", debugstr_w(pszProvName
), dwProvType
);
1126 return CryptSetProviderExW(pszProvName
, dwProvType
, NULL
, CRYPT_USER_DEFAULT
);
1129 /******************************************************************************
1130 * CryptSetProviderExA (ADVAPI32.@)
1132 BOOL WINAPI
CryptSetProviderExA (LPCSTR pszProvName
, DWORD dwProvType
, DWORD
*pdwReserved
, DWORD dwFlags
)
1137 TRACE("(%s, %ld, %p, %08ld)\n", pszProvName
, dwProvType
, pdwReserved
, dwFlags
);
1139 if (!pszProvName
|| pdwReserved
)
1140 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
1141 if (dwProvType
> MAXPROVTYPES
)
1142 CRYPT_ReturnLastError(NTE_BAD_PROV_TYPE
);
1143 if (dwFlags
& ~(CRYPT_MACHINE_DEFAULT
| CRYPT_USER_DEFAULT
| CRYPT_DELETE_DEFAULT
)
1144 || dwFlags
== CRYPT_DELETE_DEFAULT
)
1145 CRYPT_ReturnLastError(NTE_BAD_FLAGS
);
1147 if (dwFlags
& CRYPT_DELETE_DEFAULT
)
1149 if ( !(keyname
= CRYPT_GetTypeKeyName(dwProvType
, dwFlags
& CRYPT_USER_DEFAULT
)) )
1150 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
1151 RegDeleteKeyA( (dwFlags
& CRYPT_USER_DEFAULT
) ? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
, keyname
);
1152 CRYPT_Free(keyname
);
1156 if ( !(keyname
= CRYPT_GetProvKeyName(pszProvName
)) )
1157 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
1158 if (RegOpenKeyA(HKEY_LOCAL_MACHINE
, keyname
, &hKey
))
1160 CRYPT_Free(keyname
);
1161 CRYPT_ReturnLastError(NTE_BAD_PROVIDER
);
1163 CRYPT_Free(keyname
);
1165 if ( !(keyname
= CRYPT_GetTypeKeyName(dwProvType
, dwFlags
& CRYPT_USER_DEFAULT
)) )
1166 CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY
);
1167 RegCreateKeyA( (dwFlags
& CRYPT_USER_DEFAULT
) ? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
, keyname
, &hKey
);
1168 CRYPT_Free(keyname
);
1169 if (RegSetValueExA(hKey
, "Name", 0, REG_SZ
, pszProvName
, strlen(pszProvName
) +1))
1174 /******************************************************************************
1175 * CryptSetProviderExW (ADVAPI32.@)
1177 BOOL WINAPI
CryptSetProviderExW (LPCWSTR pszProvName
, DWORD dwProvType
, DWORD
*pdwReserved
, DWORD dwFlags
)
1182 TRACE("(%s, %ld, %p, %08ld)\n", debugstr_w(pszProvName
), dwProvType
, pdwReserved
, dwFlags
);
1184 if (CRYPT_UnicodeToANSI(pszProvName
, &str
, -1))
1186 ret
= CryptSetProviderExA(str
, dwProvType
, pdwReserved
, dwFlags
);
1192 /******************************************************************************
1193 * CryptSetProvParam (ADVAPI32.@)
1195 BOOL WINAPI
CryptSetProvParam (HCRYPTPROV hProv
, DWORD dwParam
, BYTE
*pbData
, DWORD dwFlags
)
1197 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
1199 TRACE("(0x%lx, %ld, %p, %08ld)\n", hProv
, dwParam
, pbData
, dwFlags
);
1202 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
1203 if (dwFlags
& PP_USE_HARDWARE_RNG
)
1205 FIXME("PP_USE_HARDWARE_RNG: What do I do with this?\n");
1206 FIXME("\tLetting the CSP decide.\n");
1208 if (dwFlags
& PP_CLIENT_HWND
)
1210 /* FIXME: Should verify the parameter */
1211 if (pbData
/* && IsWindow((HWND)pbData) */)
1213 crypt_hWindow
= (HWND
)(pbData
);
1216 SetLastError(ERROR_INVALID_PARAMETER
);
1220 /* All other flags go to the CSP */
1221 return prov
->pFuncs
->pCPSetProvParam(prov
->hPrivate
, dwParam
, pbData
, dwFlags
);
1224 /******************************************************************************
1225 * CryptVerifySignatureA
1227 * Note: Since the sDesciption (string) is supposed to be NULL and
1228 * is only retained for compatibility no string conversions are required
1229 * and only one implementation is required for both ANSI and Unicode.
1230 * We still need to export both:
1232 * CryptVerifySignatureA (ADVAPI32.@)
1233 * CryptVerifySignatureW (ADVAPI32.@)
1235 BOOL WINAPI
CryptVerifySignatureA (HCRYPTHASH hHash
, BYTE
*pbSignature
, DWORD dwSigLen
,
1236 HCRYPTKEY hPubKey
, LPCSTR sDescription
, DWORD dwFlags
)
1238 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
1239 PCRYPTKEY key
= (PCRYPTKEY
)hPubKey
;
1242 TRACE("(0x%lx, %p, %ld, 0x%lx, %08ld)\n", hHash
, pbSignature
,
1243 dwSigLen
, hPubKey
, dwFlags
);
1245 WARN("The sDescription parameter is not supported (and no longer used). Ignoring.\n");
1248 CRYPT_ReturnLastError(ERROR_INVALID_HANDLE
);
1249 if (!pbSignature
|| !dwSigLen
)
1250 CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER
);
1252 prov
= hash
->pProvider
;
1253 return prov
->pFuncs
->pCPVerifySignature(prov
->hPrivate
, hash
->hPrivate
, pbSignature
, dwSigLen
,
1254 key
->hPrivate
, NULL
, dwFlags
);