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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 /***********************************************************************
23 * - Reference counting
28 #include "wine/port.h"
33 #include <sys/types.h>
34 #ifdef HAVE_SYS_STAT_H
35 # include <sys/stat.h>
43 #define WIN32_NO_STATUS
47 #include "wine/debug.h"
48 #include "wine/unicode.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(crypt
);
53 static HWND crypt_hWindow
;
55 #define CRYPT_Alloc(size) (LocalAlloc(LMEM_ZEROINIT, size))
56 #define CRYPT_Free(buffer) (LocalFree((HLOCAL)buffer))
58 static inline PWSTR
CRYPT_GetProvKeyName(PCWSTR pProvName
)
60 static const WCHAR KEYSTR
[] = {
61 'S','o','f','t','w','a','r','e','\\',
62 'M','i','c','r','o','s','o','f','t','\\',
63 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
64 'D','e','f','a','u','l','t','s','\\',
65 'P','r','o','v','i','d','e','r','\\',0
69 keyname
= CRYPT_Alloc((strlenW(KEYSTR
) + strlenW(pProvName
) +1)*sizeof(WCHAR
));
72 strcpyW(keyname
, KEYSTR
);
73 strcpyW(keyname
+ strlenW(KEYSTR
), pProvName
);
75 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
79 static inline PWSTR
CRYPT_GetTypeKeyName(DWORD dwType
, BOOL user
)
81 static const WCHAR MACHINESTR
[] = {
82 'S','o','f','t','w','a','r','e','\\',
83 'M','i','c','r','o','s','o','f','t','\\',
84 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
85 'D','e','f','a','u','l','t','s','\\',
86 'P','r','o','v','i','d','e','r',' ','T','y','p','e','s','\\',
87 'T','y','p','e',' ','X','X','X',0
89 static const WCHAR USERSTR
[] = {
90 'S','o','f','t','w','a','r','e','\\',
91 'M','i','c','r','o','s','o','f','t','\\',
92 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
93 'P','r','o','v','i','d','e','r',' ','T','y','p','e',' ','X','X','X',0
98 keyname
= CRYPT_Alloc( ((user
? strlenW(USERSTR
) : strlenW(MACHINESTR
)) +1)*sizeof(WCHAR
));
101 user
? strcpyW(keyname
, USERSTR
) : strcpyW(keyname
, MACHINESTR
);
102 ptr
= keyname
+ strlenW(keyname
);
103 *(--ptr
) = (dwType
% 10) + '0';
104 *(--ptr
) = ((dwType
/ 10) % 10) + '0';
105 *(--ptr
) = (dwType
/ 100) + '0';
107 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
111 /* CRYPT_UnicodeTOANSI
112 * wstr - unicode string
113 * str - pointer to ANSI string
114 * strsize - size of buffer pointed to by str or -1 if we have to do the allocation
116 * returns TRUE if unsuccessful, FALSE otherwise.
117 * if wstr is NULL, returns TRUE and sets str to NULL! Value of str should be checked after call
119 static inline BOOL
CRYPT_UnicodeToANSI(LPCWSTR wstr
, LPSTR
* str
, int strsize
)
128 count
= WideCharToMultiByte(CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
130 *str
= CRYPT_Alloc(count
* sizeof(CHAR
));
132 count
= min( count
, strsize
);
135 WideCharToMultiByte(CP_ACP
, 0, wstr
, -1, *str
, count
, NULL
, NULL
);
138 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
142 /* CRYPT_ANSITOUnicode
144 * wstr - pointer to unicode string
145 * wstrsize - size of buffer pointed to by wstr or -1 if we have to do the allocation
147 static inline BOOL
CRYPT_ANSIToUnicode(LPCSTR str
, LPWSTR
* wstr
, int wstrsize
)
156 wcount
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
158 *wstr
= CRYPT_Alloc(wcount
* sizeof(WCHAR
));
160 wcount
= min( wcount
, wstrsize
/sizeof(WCHAR
) );
163 MultiByteToWideChar(CP_ACP
, 0, str
, -1, *wstr
, wcount
);
166 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
170 /* These next 2 functions are used by the VTableProvStruc structure */
171 static BOOL CALLBACK
CRYPT_VerifyImage(LPCSTR lpszImage
, BYTE
* pData
)
173 if (!lpszImage
|| !pData
)
175 SetLastError(ERROR_INVALID_PARAMETER
);
179 FIXME("(%s, %p): not verifying image\n", lpszImage
, pData
);
184 static BOOL CALLBACK
CRYPT_ReturnhWnd(HWND
*phWnd
)
188 *phWnd
= crypt_hWindow
;
192 #define CRYPT_GetProvFunc(name) \
193 if ( !(provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)) ) goto error
194 #define CRYPT_GetProvFuncOpt(name) \
195 provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)
196 static PCRYPTPROV
CRYPT_LoadProvider(PCWSTR pImage
)
199 DWORD errorcode
= ERROR_NOT_ENOUGH_MEMORY
;
201 if ( !(provider
= CRYPT_Alloc(sizeof(CRYPTPROV
))) ) goto error
;
202 if ( !(provider
->pFuncs
= CRYPT_Alloc(sizeof(PROVFUNCS
))) ) goto error
;
203 if ( !(provider
->pVTable
= CRYPT_Alloc(sizeof(VTableProvStruc
))) ) goto error
;
204 if ( !(provider
->hModule
= LoadLibraryW(pImage
)) )
206 errorcode
= (GetLastError() == ERROR_FILE_NOT_FOUND
) ? NTE_PROV_DLL_NOT_FOUND
: NTE_PROVIDER_DLL_FAIL
;
207 FIXME("Failed to load dll %s\n", debugstr_w(pImage
));
210 provider
->dwMagic
= MAGIC_CRYPTPROV
;
211 provider
->refcount
= 1;
213 errorcode
= NTE_PROVIDER_DLL_FAIL
;
214 CRYPT_GetProvFunc(CPAcquireContext
);
215 CRYPT_GetProvFunc(CPCreateHash
);
216 CRYPT_GetProvFunc(CPDecrypt
);
217 CRYPT_GetProvFunc(CPDeriveKey
);
218 CRYPT_GetProvFunc(CPDestroyHash
);
219 CRYPT_GetProvFunc(CPDestroyKey
);
220 CRYPT_GetProvFuncOpt(CPDuplicateHash
);
221 CRYPT_GetProvFuncOpt(CPDuplicateKey
);
222 CRYPT_GetProvFunc(CPEncrypt
);
223 CRYPT_GetProvFunc(CPExportKey
);
224 CRYPT_GetProvFunc(CPGenKey
);
225 CRYPT_GetProvFunc(CPGenRandom
);
226 CRYPT_GetProvFunc(CPGetHashParam
);
227 CRYPT_GetProvFunc(CPGetKeyParam
);
228 CRYPT_GetProvFunc(CPGetProvParam
);
229 CRYPT_GetProvFunc(CPGetUserKey
);
230 CRYPT_GetProvFunc(CPHashData
);
231 CRYPT_GetProvFunc(CPHashSessionKey
);
232 CRYPT_GetProvFunc(CPImportKey
);
233 CRYPT_GetProvFunc(CPReleaseContext
);
234 CRYPT_GetProvFunc(CPSetHashParam
);
235 CRYPT_GetProvFunc(CPSetKeyParam
);
236 CRYPT_GetProvFunc(CPSetProvParam
);
237 CRYPT_GetProvFunc(CPSignHash
);
238 CRYPT_GetProvFunc(CPVerifySignature
);
240 /* FIXME: Not sure what the pbContextInfo field is for.
241 * Does it need memory allocation?
243 provider
->pVTable
->Version
= 3;
244 provider
->pVTable
->pFuncVerifyImage
= (FARPROC
)CRYPT_VerifyImage
;
245 provider
->pVTable
->pFuncReturnhWnd
= (FARPROC
)CRYPT_ReturnhWnd
;
246 provider
->pVTable
->dwProvType
= 0;
247 provider
->pVTable
->pbContextInfo
= NULL
;
248 provider
->pVTable
->cbContextInfo
= 0;
249 provider
->pVTable
->pszProvName
= NULL
;
253 SetLastError(errorcode
);
256 provider
->dwMagic
= 0;
257 if (provider
->hModule
)
258 FreeLibrary(provider
->hModule
);
259 CRYPT_Free(provider
->pVTable
);
260 CRYPT_Free(provider
->pFuncs
);
261 CRYPT_Free(provider
);
265 #undef CRYPT_GetProvFunc
266 #undef CRYPT_GetProvFuncOpt
269 /******************************************************************************
270 * CryptAcquireContextW (ADVAPI32.@)
272 * Acquire a crypto provider context handle.
275 * phProv [O] Pointer to HCRYPTPROV for the output.
276 * pszContainer [I] Key Container Name
277 * pszProvider [I] Cryptographic Service Provider Name
278 * dwProvType [I] Crypto provider type to get a handle.
279 * dwFlags [I] flags for the operation
282 * TRUE on success, FALSE on failure.
284 BOOL WINAPI
CryptAcquireContextW (HCRYPTPROV
*phProv
, LPCWSTR pszContainer
,
285 LPCWSTR pszProvider
, DWORD dwProvType
, DWORD dwFlags
)
287 PCRYPTPROV pProv
= NULL
;
289 PWSTR imagepath
= NULL
, keyname
= NULL
, provname
= NULL
, temp
= NULL
;
290 PSTR provnameA
= NULL
, pszContainerA
= NULL
;
291 DWORD keytype
, type
, len
;
293 static const WCHAR nameW
[] = {'N','a','m','e',0};
294 static const WCHAR typeW
[] = {'T','y','p','e',0};
295 static const WCHAR imagepathW
[] = {'I','m','a','g','e',' ','P','a','t','h',0};
297 TRACE("(%p, %s, %s, %d, %08x)\n", phProv
, debugstr_w(pszContainer
),
298 debugstr_w(pszProvider
), dwProvType
, dwFlags
);
300 if (dwProvType
< 1 || dwProvType
> MAXPROVTYPES
)
302 SetLastError(NTE_BAD_PROV_TYPE
);
308 SetLastError(ERROR_INVALID_PARAMETER
);
312 if (!pszProvider
|| !*pszProvider
)
314 /* No CSP name specified so try the user default CSP first
315 * then try the machine default CSP
317 if ( !(keyname
= CRYPT_GetTypeKeyName(dwProvType
, TRUE
)) ) {
318 TRACE("No provider registered for crypto provider type %d.\n", dwProvType
);
319 SetLastError(NTE_PROV_TYPE_NOT_DEF
);
322 if (RegOpenKeyW(HKEY_CURRENT_USER
, keyname
, &key
))
325 if ( !(keyname
= CRYPT_GetTypeKeyName(dwProvType
, FALSE
)) ) {
326 TRACE("No type registered for crypto provider type %d.\n", dwProvType
);
328 SetLastError(NTE_PROV_TYPE_NOT_DEF
);
331 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, keyname
, &key
)) {
332 TRACE("Did not find registry entry of crypto provider for %s.\n", debugstr_w(keyname
));
335 SetLastError(NTE_PROV_TYPE_NOT_DEF
);
340 r
= RegQueryValueExW(key
, nameW
, NULL
, &keytype
, NULL
, &len
);
341 if( r
!= ERROR_SUCCESS
|| !len
|| keytype
!= REG_SZ
)
343 TRACE("error %d reading size of 'Name' from registry\n", r
);
345 SetLastError(NTE_PROV_TYPE_ENTRY_BAD
);
348 if(!(provname
= CRYPT_Alloc(len
)))
351 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
354 r
= RegQueryValueExW(key
, nameW
, NULL
, NULL
, (LPBYTE
)provname
, &len
);
355 if( r
!= ERROR_SUCCESS
)
357 TRACE("error %d reading 'Name' from registry\n", r
);
359 SetLastError(NTE_PROV_TYPE_ENTRY_BAD
);
364 if ( !(provname
= CRYPT_Alloc((strlenW(pszProvider
) +1)*sizeof(WCHAR
))) )
366 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
369 strcpyW(provname
, pszProvider
);
372 keyname
= CRYPT_GetProvKeyName(provname
);
373 r
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, keyname
, &key
);
375 if (r
!= ERROR_SUCCESS
)
377 SetLastError(NTE_KEYSET_NOT_DEF
);
381 r
= RegQueryValueExW(key
, typeW
, NULL
, NULL
, (BYTE
*)&type
, &len
);
382 if (r
!= ERROR_SUCCESS
)
384 SetLastError(NTE_PROV_TYPE_ENTRY_BAD
);
387 if (type
!= dwProvType
)
389 TRACE("Crypto provider has wrong type (%d vs expected %d).\n", type
, dwProvType
);
390 SetLastError(NTE_PROV_TYPE_NO_MATCH
);
394 r
= RegQueryValueExW(key
, imagepathW
, NULL
, &keytype
, NULL
, &len
);
395 if ( r
!= ERROR_SUCCESS
|| keytype
!= REG_SZ
)
397 TRACE("error %d reading size of 'Image Path' from registry\n", r
);
399 SetLastError(NTE_PROV_TYPE_ENTRY_BAD
);
402 if (!(temp
= CRYPT_Alloc(len
)))
405 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
408 r
= RegQueryValueExW(key
, imagepathW
, NULL
, NULL
, (LPBYTE
)temp
, &len
);
409 if( r
!= ERROR_SUCCESS
)
411 TRACE("error %d reading 'Image Path' from registry\n", r
);
413 SetLastError(NTE_PROV_TYPE_ENTRY_BAD
);
417 len
= ExpandEnvironmentStringsW(temp
, NULL
, 0);
418 if ( !(imagepath
= CRYPT_Alloc(len
*sizeof(WCHAR
))) )
420 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
423 if (!ExpandEnvironmentStringsW(temp
, imagepath
, len
))
425 /* ExpandEnvironmentStrings will call SetLastError */
428 pProv
= CRYPT_LoadProvider(imagepath
);
430 /* CRYPT_LoadProvider calls SetLastError */
433 pProv
->pVTable
->dwProvType
= dwProvType
;
434 if(!CRYPT_UnicodeToANSI(provname
, &provnameA
, -1))
436 /* CRYPT_UnicodeToANSI calls SetLastError */
439 pProv
->pVTable
->pszProvName
= provnameA
;
440 if(!CRYPT_UnicodeToANSI(pszContainer
, &pszContainerA
, -1))
442 /* CRYPT_UnicodeToANSI calls SetLastError */
445 if (pProv
->pFuncs
->pCPAcquireContext(&pProv
->hPrivate
, pszContainerA
, dwFlags
, pProv
->pVTable
))
447 /* MSDN: When this flag is set, the value returned in phProv is undefined,
448 * and thus, the CryptReleaseContext function need not be called afterwards.
449 * Therefore, we must clean up everything now.
451 if (dwFlags
& CRYPT_DELETEKEYSET
)
454 FreeLibrary(pProv
->hModule
);
455 CRYPT_Free(provnameA
);
456 CRYPT_Free(pProv
->pVTable
);
457 CRYPT_Free(pProv
->pFuncs
);
460 *phProv
= (HCRYPTPROV
)pProv
;
462 CRYPT_Free(pszContainerA
);
463 CRYPT_Free(provname
);
465 CRYPT_Free(imagepath
);
468 /* FALLTHROUGH TO ERROR IF FALSE - CSP internal error! */
474 FreeLibrary(pProv
->hModule
);
475 CRYPT_Free(pProv
->pVTable
);
476 CRYPT_Free(pProv
->pFuncs
);
479 CRYPT_Free(pszContainerA
);
480 CRYPT_Free(provnameA
);
481 CRYPT_Free(provname
);
483 CRYPT_Free(imagepath
);
487 /******************************************************************************
488 * CryptAcquireContextA (ADVAPI32.@)
490 * See CryptAcquireContextW.
492 BOOL WINAPI
CryptAcquireContextA (HCRYPTPROV
*phProv
, LPCSTR pszContainer
,
493 LPCSTR pszProvider
, DWORD dwProvType
, DWORD dwFlags
)
495 PWSTR pProvider
= NULL
, pContainer
= NULL
;
498 TRACE("(%p, %s, %s, %d, %08x)\n", phProv
, pszContainer
,
499 pszProvider
, dwProvType
, dwFlags
);
501 if ( !CRYPT_ANSIToUnicode(pszContainer
, &pContainer
, -1) )
503 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
506 if ( !CRYPT_ANSIToUnicode(pszProvider
, &pProvider
, -1) )
508 CRYPT_Free(pContainer
);
509 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
513 ret
= CryptAcquireContextW(phProv
, pContainer
, pProvider
, dwProvType
, dwFlags
);
515 CRYPT_Free(pContainer
);
516 CRYPT_Free(pProvider
);
521 /******************************************************************************
522 * CryptContextAddRef (ADVAPI32.@)
524 * Increases reference count of a cryptographic service provider handle
528 * hProv [I] Handle to the CSP whose reference is being incremented.
529 * pdwReserved [IN] Reserved for future use and must be NULL.
530 * dwFlags [I] Reserved for future use and must be NULL.
536 BOOL WINAPI
CryptContextAddRef (HCRYPTPROV hProv
, DWORD
*pdwReserved
, DWORD dwFlags
)
538 PCRYPTPROV pProv
= (PCRYPTPROV
)hProv
;
540 TRACE("(0x%lx, %p, %08x)\n", hProv
, pdwReserved
, dwFlags
);
544 SetLastError(NTE_BAD_UID
);
548 if (pProv
->dwMagic
!= MAGIC_CRYPTPROV
)
550 SetLastError(ERROR_INVALID_PARAMETER
);
558 /******************************************************************************
559 * CryptReleaseContext (ADVAPI32.@)
561 * Releases the handle of a CSP. Reference count is decreased.
564 * hProv [I] Handle of a CSP.
565 * dwFlags [I] Reserved for future use and must be NULL.
571 BOOL WINAPI
CryptReleaseContext (HCRYPTPROV hProv
, ULONG_PTR dwFlags
)
573 PCRYPTPROV pProv
= (PCRYPTPROV
)hProv
;
576 TRACE("(0x%lx, %08lx)\n", hProv
, dwFlags
);
580 SetLastError(NTE_BAD_UID
);
584 if (pProv
->dwMagic
!= MAGIC_CRYPTPROV
)
586 SetLastError(ERROR_INVALID_PARAMETER
);
591 if (pProv
->refcount
<= 0)
593 ret
= pProv
->pFuncs
->pCPReleaseContext(pProv
->hPrivate
, dwFlags
);
595 FreeLibrary(pProv
->hModule
);
597 CRYPT_Free(pProv
->pVTable
->pContextInfo
);
599 CRYPT_Free(pProv
->pVTable
->pszProvName
);
600 CRYPT_Free(pProv
->pVTable
);
601 CRYPT_Free(pProv
->pFuncs
);
607 /******************************************************************************
608 * CryptGenRandom (ADVAPI32.@)
610 * Fills a buffer with cryptographically random bytes.
613 * hProv [I] Handle of a CSP.
614 * dwLen [I] Number of bytes to generate.
615 * pbBuffer [I/O] Buffer to contain random bytes.
622 * pdBuffer must be at least dwLen bytes long.
624 BOOL WINAPI
CryptGenRandom (HCRYPTPROV hProv
, DWORD dwLen
, BYTE
*pbBuffer
)
626 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
628 TRACE("(0x%lx, %d, %p)\n", hProv
, dwLen
, pbBuffer
);
632 SetLastError(ERROR_INVALID_HANDLE
);
636 if (prov
->dwMagic
!= MAGIC_CRYPTPROV
)
638 SetLastError(ERROR_INVALID_PARAMETER
);
642 return prov
->pFuncs
->pCPGenRandom(prov
->hPrivate
, dwLen
, pbBuffer
);
645 /******************************************************************************
646 * CryptCreateHash (ADVAPI32.@)
648 * Initiates the hashing of a stream of data.
651 * hProv [I] Handle of a CSP.
652 * Algid [I] Identifies the hash algorithm to use.
653 * hKey [I] Key for the hash (if required).
654 * dwFlags [I] Reserved for future use and must be NULL.
655 * phHash [O] Address of the future handle to the new hash object.
662 * If the algorithm is a keyed hash, hKey is the key.
664 BOOL WINAPI
CryptCreateHash (HCRYPTPROV hProv
, ALG_ID Algid
, HCRYPTKEY hKey
,
665 DWORD dwFlags
, HCRYPTHASH
*phHash
)
667 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
668 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
671 TRACE("(0x%lx, 0x%x, 0x%lx, %08x, %p)\n", hProv
, Algid
, hKey
, dwFlags
, phHash
);
675 SetLastError(ERROR_INVALID_HANDLE
);
678 if (!phHash
|| prov
->dwMagic
!= MAGIC_CRYPTPROV
)
680 SetLastError(ERROR_INVALID_PARAMETER
);
685 SetLastError(NTE_BAD_FLAGS
);
688 if ( !(hash
= CRYPT_Alloc(sizeof(CRYPTHASH
))) )
690 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
694 hash
->pProvider
= prov
;
696 if (prov
->pFuncs
->pCPCreateHash(prov
->hPrivate
, Algid
,
697 key
? key
->hPrivate
: 0, 0, &hash
->hPrivate
))
699 *phHash
= (HCRYPTHASH
)hash
;
709 /******************************************************************************
710 * CryptDecrypt (ADVAPI32.@)
712 * Decrypts data encrypted by CryptEncrypt.
715 * hKey [I] Handle to the decryption key.
716 * hHash [I] Handle to a hash object.
717 * Final [I] TRUE if this is the last section to be decrypted.
718 * dwFlags [I] Reserved for future use. Can be CRYPT_OAEP.
719 * pbData [I/O] Buffer that holds the encrypted data. Holds decrypted
721 * pdwDataLen [I/O] Length of pbData before and after the call.
727 BOOL WINAPI
CryptDecrypt (HCRYPTKEY hKey
, HCRYPTHASH hHash
, BOOL Final
,
728 DWORD dwFlags
, BYTE
*pbData
, DWORD
*pdwDataLen
)
731 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
732 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
734 TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey
, hHash
, Final
, dwFlags
, pbData
, pdwDataLen
);
736 if (!key
|| !pbData
|| !pdwDataLen
|| !key
->pProvider
|| key
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
738 SetLastError(ERROR_INVALID_PARAMETER
);
742 prov
= key
->pProvider
;
743 return prov
->pFuncs
->pCPDecrypt(prov
->hPrivate
, key
->hPrivate
, hash
? hash
->hPrivate
: 0,
744 Final
, dwFlags
, pbData
, pdwDataLen
);
747 /******************************************************************************
748 * CryptDeriveKey (ADVAPI32.@)
750 * Generates session keys derived from a base data value.
753 * hProv [I] Handle to a CSP.
754 * Algid [I] Identifies the symmetric encryption algorithm to use.
755 * hBaseData [I] Handle to a hash object.
756 * dwFlags [I] Type of key to generate.
757 * phKey [I/O] Address of the newly generated key.
763 BOOL WINAPI
CryptDeriveKey (HCRYPTPROV hProv
, ALG_ID Algid
, HCRYPTHASH hBaseData
,
764 DWORD dwFlags
, HCRYPTKEY
*phKey
)
766 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
767 PCRYPTHASH hash
= (PCRYPTHASH
)hBaseData
;
770 TRACE("(0x%lx, 0x%08x, 0x%lx, 0x%08x, %p)\n", hProv
, Algid
, hBaseData
, dwFlags
, phKey
);
774 SetLastError(ERROR_INVALID_HANDLE
);
777 if (!phKey
|| prov
->dwMagic
!= MAGIC_CRYPTPROV
)
779 SetLastError(ERROR_INVALID_PARAMETER
);
782 if ( !(key
= CRYPT_Alloc(sizeof(CRYPTKEY
))) )
784 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
788 key
->pProvider
= prov
;
789 if (prov
->pFuncs
->pCPDeriveKey(prov
->hPrivate
, Algid
, hash
->hPrivate
, dwFlags
, &key
->hPrivate
))
791 *phKey
= (HCRYPTKEY
)key
;
801 /******************************************************************************
802 * CryptDestroyHash (ADVAPI32.@)
804 * Destroys the hash object referenced by hHash.
807 * hHash [I] Handle of the hash object to be destroyed.
813 BOOL WINAPI
CryptDestroyHash (HCRYPTHASH hHash
)
815 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
819 TRACE("(0x%lx)\n", hHash
);
823 SetLastError(ERROR_INVALID_HANDLE
);
827 if (!hash
->pProvider
|| hash
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
829 SetLastError(ERROR_INVALID_PARAMETER
);
833 prov
= hash
->pProvider
;
834 ret
= prov
->pFuncs
->pCPDestroyHash(prov
->hPrivate
, hash
->hPrivate
);
839 /******************************************************************************
840 * CryptDestroyKey (ADVAPI32.@)
842 * Releases the handle referenced by hKey.
845 * hKey [I] Handle of the key to be destroyed.
851 BOOL WINAPI
CryptDestroyKey (HCRYPTKEY hKey
)
853 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
857 TRACE("(0x%lx)\n", hKey
);
861 SetLastError(ERROR_INVALID_HANDLE
);
865 if (!key
->pProvider
|| key
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
867 SetLastError(ERROR_INVALID_PARAMETER
);
871 prov
= key
->pProvider
;
872 ret
= prov
->pFuncs
->pCPDestroyKey(prov
->hPrivate
, key
->hPrivate
);
877 /******************************************************************************
878 * CryptDuplicateHash (ADVAPI32.@)
883 * hHash [I] Handle to the hash to be copied.
884 * pdwReserved [I] Reserved for future use and must be zero.
885 * dwFlags [I] Reserved for future use and must be zero.
886 * phHash [O] Address of the handle to receive the copy.
892 BOOL WINAPI
CryptDuplicateHash (HCRYPTHASH hHash
, DWORD
*pdwReserved
,
893 DWORD dwFlags
, HCRYPTHASH
*phHash
)
896 PCRYPTHASH orghash
, newhash
;
898 TRACE("(0x%lx, %p, %08x, %p)\n", hHash
, pdwReserved
, dwFlags
, phHash
);
900 orghash
= (PCRYPTHASH
)hHash
;
901 if (!orghash
|| pdwReserved
|| !phHash
|| !orghash
->pProvider
||
902 orghash
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
904 SetLastError(ERROR_INVALID_PARAMETER
);
908 prov
= orghash
->pProvider
;
909 if (!prov
->pFuncs
->pCPDuplicateHash
)
911 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
915 if ( !(newhash
= CRYPT_Alloc(sizeof(CRYPTHASH
))) )
917 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
921 newhash
->pProvider
= prov
;
922 if (prov
->pFuncs
->pCPDuplicateHash(prov
->hPrivate
, orghash
->hPrivate
, pdwReserved
, dwFlags
, &newhash
->hPrivate
))
924 *phHash
= (HCRYPTHASH
)newhash
;
931 /******************************************************************************
932 * CryptDuplicateKey (ADVAPI32.@)
934 * Duplicate a key and the key's state.
937 * hKey [I] Handle of the key to copy.
938 * pdwReserved [I] Reserved for future use and must be NULL.
939 * dwFlags [I] Reserved for future use and must be zero.
940 * phKey [I] Address of the handle to the duplicated key.
946 BOOL WINAPI
CryptDuplicateKey (HCRYPTKEY hKey
, DWORD
*pdwReserved
, DWORD dwFlags
, HCRYPTKEY
*phKey
)
949 PCRYPTKEY orgkey
, newkey
;
951 TRACE("(0x%lx, %p, %08x, %p)\n", hKey
, pdwReserved
, dwFlags
, phKey
);
953 orgkey
= (PCRYPTKEY
)hKey
;
954 if (!orgkey
|| pdwReserved
|| !phKey
|| !orgkey
->pProvider
||
955 orgkey
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
957 SetLastError(ERROR_INVALID_PARAMETER
);
961 prov
= orgkey
->pProvider
;
962 if (!prov
->pFuncs
->pCPDuplicateKey
)
964 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
968 if ( !(newkey
= CRYPT_Alloc(sizeof(CRYPTKEY
))) )
970 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
974 newkey
->pProvider
= prov
;
975 if (prov
->pFuncs
->pCPDuplicateKey(prov
->hPrivate
, orgkey
->hPrivate
, pdwReserved
, dwFlags
, &newkey
->hPrivate
))
977 *phKey
= (HCRYPTKEY
)newkey
;
984 /******************************************************************************
985 * CryptEncrypt (ADVAPI32.@)
990 * hKey [I] Handle to the encryption key.
991 * hHash [I] Handle to a hash object.
992 * Final [I] TRUE if this is the last section to encrypt.
993 * dwFlags [I] Can be CRYPT_OAEP.
994 * pbData [I/O] Data to be encrypted. Contains encrypted data after call.
995 * pdwDataLen [I/O] Length of the data to encrypt. Contains the length of the
996 * encrypted data after call.
997 * dwBufLen [I] Length of the input pbData buffer.
1004 * If pbData is NULL, CryptEncrypt determines stores the number of bytes
1005 * required for the returned data in pdwDataLen.
1007 BOOL WINAPI
CryptEncrypt (HCRYPTKEY hKey
, HCRYPTHASH hHash
, BOOL Final
,
1008 DWORD dwFlags
, BYTE
*pbData
, DWORD
*pdwDataLen
, DWORD dwBufLen
)
1011 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
1012 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
1014 TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p, %d)\n", hKey
, hHash
, Final
, dwFlags
, pbData
, pdwDataLen
, dwBufLen
);
1016 if (!key
|| !pdwDataLen
|| !key
->pProvider
|| key
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
1018 SetLastError(ERROR_INVALID_PARAMETER
);
1022 prov
= key
->pProvider
;
1023 return prov
->pFuncs
->pCPEncrypt(prov
->hPrivate
, key
->hPrivate
, hash
? hash
->hPrivate
: 0,
1024 Final
, dwFlags
, pbData
, pdwDataLen
, dwBufLen
);
1027 /******************************************************************************
1028 * CryptEnumProvidersW (ADVAPI32.@)
1030 * Returns the next available CSP.
1033 * dwIndex [I] Index of the next provider to be enumerated.
1034 * pdwReserved [I] Reserved for future use and must be NULL.
1035 * dwFlags [I] Reserved for future use and must be zero.
1036 * pdwProvType [O] DWORD designating the type of the provider.
1037 * pszProvName [O] Buffer that receives data from the provider.
1038 * pcbProvName [I/O] Specifies the size of pszProvName. Contains the number
1039 * of bytes stored in the buffer on return.
1046 * If pszProvName is NULL, CryptEnumProvidersW sets the size of the name
1047 * for memory allocation purposes.
1049 BOOL WINAPI
CryptEnumProvidersW (DWORD dwIndex
, DWORD
*pdwReserved
,
1050 DWORD dwFlags
, DWORD
*pdwProvType
, LPWSTR pszProvName
, DWORD
*pcbProvName
)
1053 static const WCHAR providerW
[] = {
1054 'S','o','f','t','w','a','r','e','\\',
1055 'M','i','c','r','o','s','o','f','t','\\',
1056 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
1057 'D','e','f','a','u','l','t','s','\\',
1058 'P','r','o','v','i','d','e','r',0
1060 static const WCHAR typeW
[] = {'T','y','p','e',0};
1062 TRACE("(%d, %p, %d, %p, %p, %p)\n", dwIndex
, pdwReserved
, dwFlags
,
1063 pdwProvType
, pszProvName
, pcbProvName
);
1065 if (pdwReserved
|| !pcbProvName
)
1067 SetLastError(ERROR_INVALID_PARAMETER
);
1072 SetLastError(NTE_BAD_FLAGS
);
1076 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, providerW
, &hKey
))
1078 SetLastError(NTE_FAIL
);
1087 RegQueryInfoKeyW(hKey
, NULL
, NULL
, NULL
, &numkeys
, pcbProvName
,
1088 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1090 if (!(provNameW
= CRYPT_Alloc(*pcbProvName
* sizeof(WCHAR
))))
1092 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1096 RegEnumKeyExW(hKey
, dwIndex
, provNameW
, pcbProvName
, NULL
, NULL
, NULL
, NULL
);
1097 CRYPT_Free(provNameW
);
1099 *pcbProvName
*= sizeof(WCHAR
);
1101 if (dwIndex
>= numkeys
)
1103 SetLastError(ERROR_NO_MORE_ITEMS
);
1107 DWORD size
= sizeof(DWORD
);
1111 result
= RegEnumKeyW(hKey
, dwIndex
, pszProvName
, *pcbProvName
/ sizeof(WCHAR
));
1114 SetLastError(result
);
1117 if (RegOpenKeyW(hKey
, pszProvName
, &subkey
))
1119 if (RegQueryValueExW(subkey
, typeW
, NULL
, NULL
, (BYTE
*)pdwProvType
, &size
))
1121 RegCloseKey(subkey
);
1127 /******************************************************************************
1128 * CryptEnumProvidersA (ADVAPI32.@)
1130 * See CryptEnumProvidersW.
1132 BOOL WINAPI
CryptEnumProvidersA (DWORD dwIndex
, DWORD
*pdwReserved
,
1133 DWORD dwFlags
, DWORD
*pdwProvType
, LPSTR pszProvName
, DWORD
*pcbProvName
)
1137 BOOL ret
; /* = FALSE; */
1139 TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex
, pdwReserved
, dwFlags
,
1140 pdwProvType
, pszProvName
, pcbProvName
);
1142 if(!CryptEnumProvidersW(dwIndex
, pdwReserved
, dwFlags
, pdwProvType
, NULL
, &strlen
))
1144 if ( pszProvName
&& !(str
= CRYPT_Alloc(strlen
)) )
1146 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1149 ret
= CryptEnumProvidersW(dwIndex
, pdwReserved
, dwFlags
, pdwProvType
, str
, &strlen
);
1151 CRYPT_UnicodeToANSI(str
, &pszProvName
, *pcbProvName
);
1152 *pcbProvName
= strlen
/ sizeof(WCHAR
); /* FIXME: not correct */
1156 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1158 SetLastError(ERROR_MORE_DATA
);
1165 /******************************************************************************
1166 * CryptEnumProviderTypesW (ADVAPI32.@)
1168 * Retrieves the next type of CSP supported.
1171 * dwIndex [I] Index of the next provider to be enumerated.
1172 * pdwReserved [I] Reserved for future use and must be NULL.
1173 * dwFlags [I] Reserved for future use and must be zero.
1174 * pdwProvType [O] DWORD designating the type of the provider.
1175 * pszTypeName [O] Buffer that receives data from the provider type.
1176 * pcbTypeName [I/O] Specifies the size of pszTypeName. Contains the number
1177 * of bytes stored in the buffer on return.
1184 * If pszTypeName is NULL, CryptEnumProviderTypesW sets the size of the name
1185 * for memory allocation purposes.
1187 BOOL WINAPI
CryptEnumProviderTypesW (DWORD dwIndex
, DWORD
*pdwReserved
,
1188 DWORD dwFlags
, DWORD
*pdwProvType
, LPWSTR pszTypeName
, DWORD
*pcbTypeName
)
1191 DWORD keylen
, numkeys
, dwType
;
1194 static const WCHAR KEYSTR
[] = {
1195 'S','o','f','t','w','a','r','e','\\',
1196 'M','i','c','r','o','s','o','f','t','\\',
1197 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
1198 'D','e','f','a','u','l','t','s','\\',
1199 'P','r','o','v','i','d','e','r',' ','T','y','p','e','s',0
1201 static const WCHAR typenameW
[] = {'T','y','p','e','N','a','m','e',0};
1203 TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex
, pdwReserved
,
1204 dwFlags
, pdwProvType
, pszTypeName
, pcbTypeName
);
1206 if (pdwReserved
|| !pdwProvType
|| !pcbTypeName
)
1208 SetLastError(ERROR_INVALID_PARAMETER
);
1213 SetLastError(NTE_BAD_FLAGS
);
1217 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
, KEYSTR
, &hKey
))
1220 RegQueryInfoKeyW(hKey
, NULL
, NULL
, NULL
, &numkeys
, &keylen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1221 if (dwIndex
>= numkeys
)
1223 SetLastError(ERROR_NO_MORE_ITEMS
);
1227 if ( !(keyname
= CRYPT_Alloc(keylen
*sizeof(WCHAR
))) )
1229 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1232 if ( RegEnumKeyW(hKey
, dwIndex
, keyname
, keylen
) ) {
1233 CRYPT_Free(keyname
);
1236 RegOpenKeyW(hKey
, keyname
, &hSubkey
);
1237 ch
= keyname
+ strlenW(keyname
);
1238 /* Convert "Type 000" to 0, etc/ */
1239 *pdwProvType
= *(--ch
) - '0';
1240 *pdwProvType
+= (*(--ch
) - '0') * 10;
1241 *pdwProvType
+= (*(--ch
) - '0') * 100;
1242 CRYPT_Free(keyname
);
1244 result
= RegQueryValueExW(hSubkey
, typenameW
, NULL
, &dwType
, (LPBYTE
)pszTypeName
, pcbTypeName
);
1247 SetLastError(result
);
1251 RegCloseKey(hSubkey
);
1256 /******************************************************************************
1257 * CryptEnumProviderTypesA (ADVAPI32.@)
1259 * See CryptEnumProviderTypesW.
1261 BOOL WINAPI
CryptEnumProviderTypesA (DWORD dwIndex
, DWORD
*pdwReserved
,
1262 DWORD dwFlags
, DWORD
*pdwProvType
, LPSTR pszTypeName
, DWORD
*pcbTypeName
)
1268 TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex
, pdwReserved
, dwFlags
,
1269 pdwProvType
, pszTypeName
, pcbTypeName
);
1271 if(!CryptEnumProviderTypesW(dwIndex
, pdwReserved
, dwFlags
, pdwProvType
, NULL
, &strlen
))
1273 if ( pszTypeName
&& !(str
= CRYPT_Alloc(strlen
)) )
1275 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1278 ret
= CryptEnumProviderTypesW(dwIndex
, pdwReserved
, dwFlags
, pdwProvType
, str
, &strlen
);
1280 CRYPT_UnicodeToANSI(str
, &pszTypeName
, *pcbTypeName
);
1281 *pcbTypeName
= strlen
/ sizeof(WCHAR
);
1285 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1287 SetLastError(ERROR_MORE_DATA
);
1294 /******************************************************************************
1295 * CryptExportKey (ADVAPI32.@)
1297 * Exports a cryptographic key from a CSP.
1300 * hKey [I] Handle to the key to export.
1301 * hExpKey [I] Handle to a cryptographic key of the end user.
1302 * dwBlobType [I] Type of BLOB to be exported.
1303 * dwFlags [I] CRYPT_DESTROYKEY/SSL2_FALLBACK/OAEP.
1304 * pbData [O] Buffer to receive BLOB data.
1305 * pdwDataLen [I/O] Specifies the size of pbData.
1312 * if pbData is NULL, CryptExportKey sets pdwDataLen as the size of the
1313 * buffer needed to hold the BLOB.
1315 BOOL WINAPI
CryptExportKey (HCRYPTKEY hKey
, HCRYPTKEY hExpKey
, DWORD dwBlobType
,
1316 DWORD dwFlags
, BYTE
*pbData
, DWORD
*pdwDataLen
)
1319 PCRYPTKEY key
= (PCRYPTKEY
)hKey
, expkey
= (PCRYPTKEY
)hExpKey
;
1321 TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey
, hExpKey
, dwBlobType
, dwFlags
, pbData
, pdwDataLen
);
1323 if (!key
|| !pdwDataLen
|| !key
->pProvider
|| key
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
1325 SetLastError(ERROR_INVALID_PARAMETER
);
1329 prov
= key
->pProvider
;
1330 return prov
->pFuncs
->pCPExportKey(prov
->hPrivate
, key
->hPrivate
, expkey
? expkey
->hPrivate
: 0,
1331 dwBlobType
, dwFlags
, pbData
, pdwDataLen
);
1334 /******************************************************************************
1335 * CryptGenKey (ADVAPI32.@)
1337 * Generates a random cryptographic session key or a pub/priv key pair.
1340 * hProv [I] Handle to a CSP.
1341 * Algid [I] Algorithm to use to make key.
1342 * dwFlags [I] Specifies type of key to make.
1343 * phKey [I] Address of the handle to which the new key is copied.
1349 BOOL WINAPI
CryptGenKey (HCRYPTPROV hProv
, ALG_ID Algid
, DWORD dwFlags
, HCRYPTKEY
*phKey
)
1351 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
1354 TRACE("(0x%lx, %d, %08x, %p)\n", hProv
, Algid
, dwFlags
, phKey
);
1358 SetLastError(ERROR_INVALID_HANDLE
);
1361 if (!phKey
|| !prov
|| prov
->dwMagic
!= MAGIC_CRYPTPROV
)
1363 SetLastError(ERROR_INVALID_PARAMETER
);
1366 if ( !(key
= CRYPT_Alloc(sizeof(CRYPTKEY
))) )
1368 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1372 key
->pProvider
= prov
;
1374 if (prov
->pFuncs
->pCPGenKey(prov
->hPrivate
, Algid
, dwFlags
, &key
->hPrivate
))
1376 *phKey
= (HCRYPTKEY
)key
;
1385 /******************************************************************************
1386 * CryptGetDefaultProviderW (ADVAPI32.@)
1388 * Finds the default CSP of a certain provider type.
1391 * dwProvType [I] Provider type to look for.
1392 * pdwReserved [I] Reserved for future use and must be NULL.
1393 * dwFlags [I] CRYPT_MACHINE_DEFAULT/USER_DEFAULT
1394 * pszProvName [O] Name of the default CSP.
1395 * pcbProvName [I/O] Size of pszProvName
1402 * If pszProvName is NULL, pcbProvName will hold the size of the buffer for
1403 * memory allocation purposes on return.
1405 BOOL WINAPI
CryptGetDefaultProviderW (DWORD dwProvType
, DWORD
*pdwReserved
,
1406 DWORD dwFlags
, LPWSTR pszProvName
, DWORD
*pcbProvName
)
1411 static const WCHAR nameW
[] = {'N','a','m','e',0};
1413 if (pdwReserved
|| !pcbProvName
)
1415 SetLastError(ERROR_INVALID_PARAMETER
);
1418 if (dwFlags
& ~(CRYPT_USER_DEFAULT
| CRYPT_MACHINE_DEFAULT
))
1420 SetLastError(NTE_BAD_FLAGS
);
1423 if (dwProvType
> 999)
1425 SetLastError(NTE_BAD_PROV_TYPE
);
1428 if ( !(keyname
= CRYPT_GetTypeKeyName(dwProvType
, dwFlags
& CRYPT_USER_DEFAULT
)) )
1430 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1433 if (RegOpenKeyW((dwFlags
& CRYPT_USER_DEFAULT
) ? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
,keyname
, &hKey
))
1435 CRYPT_Free(keyname
);
1436 SetLastError(NTE_PROV_TYPE_NOT_DEF
);
1439 CRYPT_Free(keyname
);
1441 result
= RegQueryValueExW(hKey
, nameW
, NULL
, NULL
, (LPBYTE
)pszProvName
, pcbProvName
);
1444 if (result
!= ERROR_MORE_DATA
)
1445 SetLastError(NTE_PROV_TYPE_ENTRY_BAD
);
1447 SetLastError(result
);
1456 /******************************************************************************
1457 * CryptGetDefaultProviderA (ADVAPI32.@)
1459 * See CryptGetDefaultProviderW.
1461 BOOL WINAPI
CryptGetDefaultProviderA (DWORD dwProvType
, DWORD
*pdwReserved
,
1462 DWORD dwFlags
, LPSTR pszProvName
, DWORD
*pcbProvName
)
1468 TRACE("(%d, %p, %08x, %p, %p)\n", dwProvType
, pdwReserved
, dwFlags
, pszProvName
, pcbProvName
);
1470 CryptGetDefaultProviderW(dwProvType
, pdwReserved
, dwFlags
, NULL
, &strlen
);
1471 if ( pszProvName
&& !(str
= CRYPT_Alloc(strlen
)) )
1473 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1476 ret
= CryptGetDefaultProviderW(dwProvType
, pdwReserved
, dwFlags
, str
, &strlen
);
1478 CRYPT_UnicodeToANSI(str
, &pszProvName
, *pcbProvName
);
1479 *pcbProvName
= strlen
/ sizeof(WCHAR
);
1483 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1485 SetLastError(ERROR_MORE_DATA
);
1492 /******************************************************************************
1493 * CryptGetHashParam (ADVAPI32.@)
1495 * Retrieves data that controls the operations of a hash object.
1498 * hHash [I] Handle of the hash object to question.
1499 * dwParam [I] Query type.
1500 * pbData [O] Buffer that receives the value data.
1501 * pdwDataLen [I/O] Size of the pbData buffer.
1502 * dwFlags [I] Reserved for future use and must be zero.
1509 * If pbData is NULL, pdwDataLen will contain the length required.
1511 BOOL WINAPI
CryptGetHashParam (HCRYPTHASH hHash
, DWORD dwParam
, BYTE
*pbData
,
1512 DWORD
*pdwDataLen
, DWORD dwFlags
)
1515 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
1517 TRACE("(0x%lx, %d, %p, %p, %08x)\n", hHash
, dwParam
, pbData
, pdwDataLen
, dwFlags
);
1519 if (!hash
|| !pdwDataLen
|| !hash
->pProvider
|| hash
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
1521 SetLastError(ERROR_INVALID_PARAMETER
);
1525 prov
= hash
->pProvider
;
1526 return prov
->pFuncs
->pCPGetHashParam(prov
->hPrivate
, hash
->hPrivate
, dwParam
,
1527 pbData
, pdwDataLen
, dwFlags
);
1530 /******************************************************************************
1531 * CryptGetKeyParam (ADVAPI32.@)
1533 * Retrieves data that controls the operations of a key.
1536 * hKey [I] Handle to they key in question.
1537 * dwParam [I] Specifies query type.
1538 * pbData [O] Sequence of bytes to receive data.
1539 * pdwDataLen [I/O] Size of pbData.
1540 * dwFlags [I] Reserved for future use and must be zero.
1547 * If pbData is NULL, pdwDataLen is set to the needed length of the buffer.
1549 BOOL WINAPI
CryptGetKeyParam (HCRYPTKEY hKey
, DWORD dwParam
, BYTE
*pbData
,
1550 DWORD
*pdwDataLen
, DWORD dwFlags
)
1553 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
1555 TRACE("(0x%lx, %d, %p, %p, %08x)\n", hKey
, dwParam
, pbData
, pdwDataLen
, dwFlags
);
1557 if (!key
|| !pdwDataLen
|| !key
->pProvider
|| key
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
1559 SetLastError(ERROR_INVALID_PARAMETER
);
1563 prov
= key
->pProvider
;
1564 return prov
->pFuncs
->pCPGetKeyParam(prov
->hPrivate
, key
->hPrivate
, dwParam
,
1565 pbData
, pdwDataLen
, dwFlags
);
1568 /******************************************************************************
1569 * CryptGetProvParam (ADVAPI32.@)
1571 * Retrieves parameters that control the operations of a CSP.
1574 * hProv [I] Handle of the CSP in question.
1575 * dwParam [I] Specifies query type.
1576 * pbData [O] Buffer to receive the data.
1577 * pdwDataLen [I/O] Size of pbData.
1578 * dwFlags [I] see MSDN Docs.
1585 * If pbData is NULL, pdwDataLen is set to the needed buffer length.
1587 BOOL WINAPI
CryptGetProvParam (HCRYPTPROV hProv
, DWORD dwParam
, BYTE
*pbData
,
1588 DWORD
*pdwDataLen
, DWORD dwFlags
)
1590 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
1592 TRACE("(0x%lx, %d, %p, %p, %08x)\n", hProv
, dwParam
, pbData
, pdwDataLen
, dwFlags
);
1594 if (!prov
|| prov
->dwMagic
!= MAGIC_CRYPTPROV
)
1596 SetLastError(ERROR_INVALID_PARAMETER
);
1600 return prov
->pFuncs
->pCPGetProvParam(prov
->hPrivate
, dwParam
, pbData
, pdwDataLen
, dwFlags
);
1603 /******************************************************************************
1604 * CryptGetUserKey (ADVAPI32.@)
1606 * Gets a handle of one of a user's two public/private key pairs.
1609 * hProv [I] Handle of a CSP.
1610 * dwKeySpec [I] Private key to use.
1611 * phUserKey [O] Pointer to the handle of the retrieved keys.
1617 BOOL WINAPI
CryptGetUserKey (HCRYPTPROV hProv
, DWORD dwKeySpec
, HCRYPTKEY
*phUserKey
)
1619 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
1622 TRACE("(0x%lx, %d, %p)\n", hProv
, dwKeySpec
, phUserKey
);
1626 SetLastError(ERROR_INVALID_HANDLE
);
1629 if (!phUserKey
|| prov
->dwMagic
!= MAGIC_CRYPTPROV
)
1631 SetLastError(ERROR_INVALID_PARAMETER
);
1634 if ( !(key
= CRYPT_Alloc(sizeof(CRYPTKEY
))) )
1636 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1640 key
->pProvider
= prov
;
1642 if (prov
->pFuncs
->pCPGetUserKey(prov
->hPrivate
, dwKeySpec
, &key
->hPrivate
))
1644 *phUserKey
= (HCRYPTKEY
)key
;
1654 /******************************************************************************
1655 * CryptHashData (ADVAPI32.@)
1657 * Adds data to a hash object.
1660 * hHash [I] Handle of the hash object.
1661 * pbData [I] Buffer of data to be hashed.
1662 * dwDataLen [I] Number of bytes to add.
1663 * dwFlags [I] Can be CRYPT_USERDATA
1669 BOOL WINAPI
CryptHashData (HCRYPTHASH hHash
, const BYTE
*pbData
, DWORD dwDataLen
, DWORD dwFlags
)
1671 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
1674 TRACE("(0x%lx, %p, %d, %08x)\n", hHash
, pbData
, dwDataLen
, dwFlags
);
1678 SetLastError(ERROR_INVALID_HANDLE
);
1681 if (!hash
->pProvider
|| hash
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
1683 SetLastError(ERROR_INVALID_PARAMETER
);
1687 prov
= hash
->pProvider
;
1688 return prov
->pFuncs
->pCPHashData(prov
->hPrivate
, hash
->hPrivate
, pbData
, dwDataLen
, dwFlags
);
1691 /******************************************************************************
1692 * CryptHashSessionKey (ADVAPI32.@)
1694 * Compute the cryptographic hash of a session key object.
1697 * hHash [I] Handle to the hash object.
1698 * hKey [I] Handle to the key to be hashed.
1699 * dwFlags [I] Can be CRYPT_LITTLE_ENDIAN.
1705 BOOL WINAPI
CryptHashSessionKey (HCRYPTHASH hHash
, HCRYPTKEY hKey
, DWORD dwFlags
)
1707 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
1708 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
1711 TRACE("(0x%lx, 0x%lx, %08x)\n", hHash
, hKey
, dwFlags
);
1715 SetLastError(ERROR_INVALID_HANDLE
);
1719 if (!hash
->pProvider
|| hash
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
1721 SetLastError(ERROR_INVALID_PARAMETER
);
1725 prov
= hash
->pProvider
;
1726 return prov
->pFuncs
->pCPHashSessionKey(prov
->hPrivate
, hash
->hPrivate
, key
->hPrivate
, dwFlags
);
1729 /******************************************************************************
1730 * CryptImportKey (ADVAPI32.@)
1732 * Transfer a cryptographic key from a key BLOB into a cryptographic service provider (CSP).
1735 * hProv [I] Handle of a CSP.
1736 * pbData [I] Contains the key to be imported.
1737 * dwDataLen [I] Length of the key.
1738 * hPubKey [I] Cryptographic key that decrypts pdData
1739 * dwFlags [I] Used only with a public/private key pair.
1740 * phKey [O] Imported key.
1746 BOOL WINAPI
CryptImportKey (HCRYPTPROV hProv
, CONST BYTE
*pbData
, DWORD dwDataLen
,
1747 HCRYPTKEY hPubKey
, DWORD dwFlags
, HCRYPTKEY
*phKey
)
1749 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
1750 PCRYPTKEY pubkey
= (PCRYPTKEY
)hPubKey
, importkey
;
1752 TRACE("(0x%lx, %p, %d, 0x%lx, %08x, %p)\n", hProv
, pbData
, dwDataLen
, hPubKey
, dwFlags
, phKey
);
1754 if (!prov
|| !pbData
|| !dwDataLen
|| !phKey
|| prov
->dwMagic
!= MAGIC_CRYPTPROV
)
1756 SetLastError(ERROR_INVALID_PARAMETER
);
1760 if ( !(importkey
= CRYPT_Alloc(sizeof(CRYPTKEY
))) )
1762 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1766 importkey
->pProvider
= prov
;
1767 if (prov
->pFuncs
->pCPImportKey(prov
->hPrivate
, pbData
, dwDataLen
,
1768 pubkey
? pubkey
->hPrivate
: 0, dwFlags
, &importkey
->hPrivate
))
1770 *phKey
= (HCRYPTKEY
)importkey
;
1774 CRYPT_Free(importkey
);
1778 /******************************************************************************
1779 * CryptSignHashW (ADVAPI32.@)
1784 * hHash [I] Handle of the hash object to be signed.
1785 * dwKeySpec [I] Private key to use.
1786 * sDescription [I] Should be NULL.
1787 * dwFlags [I] CRYPT_NOHASHOID/X931_FORMAT.
1788 * pbSignature [O] Buffer of the signature data.
1789 * pdwSigLen [I/O] Size of the pbSignature buffer.
1796 * Because of security flaws sDescription should not be used and should thus be
1797 * NULL. It is supported only for compatibility with Microsoft's Cryptographic
1800 BOOL WINAPI
CryptSignHashW (HCRYPTHASH hHash
, DWORD dwKeySpec
, LPCWSTR sDescription
,
1801 DWORD dwFlags
, BYTE
*pbSignature
, DWORD
*pdwSigLen
)
1803 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
1806 TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
1807 hHash
, dwKeySpec
, debugstr_w(sDescription
), dwFlags
, pbSignature
, pdwSigLen
);
1811 SetLastError(ERROR_INVALID_HANDLE
);
1814 if (!pdwSigLen
|| !hash
->pProvider
|| hash
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
1816 SetLastError(ERROR_INVALID_PARAMETER
);
1820 prov
= hash
->pProvider
;
1821 return prov
->pFuncs
->pCPSignHash(prov
->hPrivate
, hash
->hPrivate
, dwKeySpec
, sDescription
,
1822 dwFlags
, pbSignature
, pdwSigLen
);
1825 /******************************************************************************
1826 * CryptSignHashA (ADVAPI32.@)
1828 * See CryptSignHashW.
1830 BOOL WINAPI
CryptSignHashA (HCRYPTHASH hHash
, DWORD dwKeySpec
, LPCSTR sDescription
,
1831 DWORD dwFlags
, BYTE
*pbSignature
, DWORD
*pdwSigLen
)
1833 LPWSTR wsDescription
;
1836 TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
1837 hHash
, dwKeySpec
, debugstr_a(sDescription
), dwFlags
, pbSignature
, pdwSigLen
);
1839 CRYPT_ANSIToUnicode(sDescription
, &wsDescription
, -1);
1840 result
= CryptSignHashW(hHash
, dwKeySpec
, wsDescription
, dwFlags
, pbSignature
, pdwSigLen
);
1841 CRYPT_Free(wsDescription
);
1846 /******************************************************************************
1847 * CryptSetHashParam (ADVAPI32.@)
1849 * Customizes the operations of a hash object.
1852 * hHash [I] Handle of the hash object to set parameters.
1853 * dwParam [I] HP_HMAC_INFO/HASHVAL.
1854 * pbData [I] Value data buffer.
1855 * dwFlags [I] Reserved for future use and must be zero.
1861 BOOL WINAPI
CryptSetHashParam (HCRYPTHASH hHash
, DWORD dwParam
, CONST BYTE
*pbData
, DWORD dwFlags
)
1864 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
1866 TRACE("(0x%lx, %d, %p, %08x)\n", hHash
, dwParam
, pbData
, dwFlags
);
1868 if (!hash
|| !pbData
|| !hash
->pProvider
|| hash
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
1870 SetLastError(ERROR_INVALID_PARAMETER
);
1874 prov
= hash
->pProvider
;
1875 return prov
->pFuncs
->pCPSetHashParam(prov
->hPrivate
, hash
->hPrivate
,
1876 dwParam
, pbData
, dwFlags
);
1879 /******************************************************************************
1880 * CryptSetKeyParam (ADVAPI32.@)
1882 * Customizes a session key's operations.
1885 * hKey [I] Handle to the key to set values.
1886 * dwParam [I] See MSDN Doc.
1887 * pbData [I] Buffer of values to set.
1888 * dwFlags [I] Only used when dwParam == KP_ALGID.
1894 BOOL WINAPI
CryptSetKeyParam (HCRYPTKEY hKey
, DWORD dwParam
, CONST BYTE
*pbData
, DWORD dwFlags
)
1897 PCRYPTKEY key
= (PCRYPTKEY
)hKey
;
1899 TRACE("(0x%lx, %d, %p, %08x)\n", hKey
, dwParam
, pbData
, dwFlags
);
1901 if (!key
|| !pbData
|| !key
->pProvider
|| key
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
1903 SetLastError(ERROR_INVALID_PARAMETER
);
1907 prov
= key
->pProvider
;
1908 return prov
->pFuncs
->pCPSetKeyParam(prov
->hPrivate
, key
->hPrivate
,
1909 dwParam
, pbData
, dwFlags
);
1912 /******************************************************************************
1913 * CryptSetProviderA (ADVAPI32.@)
1915 * Specifies the current user's default CSP.
1918 * pszProvName [I] Name of the new default CSP.
1919 * dwProvType [I] Provider type of the CSP.
1925 BOOL WINAPI
CryptSetProviderA (LPCSTR pszProvName
, DWORD dwProvType
)
1927 TRACE("(%s, %d)\n", pszProvName
, dwProvType
);
1928 return CryptSetProviderExA(pszProvName
, dwProvType
, NULL
, CRYPT_USER_DEFAULT
);
1931 /******************************************************************************
1932 * CryptSetProviderW (ADVAPI32.@)
1934 * See CryptSetProviderA.
1936 BOOL WINAPI
CryptSetProviderW (LPCWSTR pszProvName
, DWORD dwProvType
)
1938 TRACE("(%s, %d)\n", debugstr_w(pszProvName
), dwProvType
);
1939 return CryptSetProviderExW(pszProvName
, dwProvType
, NULL
, CRYPT_USER_DEFAULT
);
1942 /******************************************************************************
1943 * CryptSetProviderExW (ADVAPI32.@)
1945 * Specifies the default CSP.
1948 * pszProvName [I] Name of the new default CSP.
1949 * dwProvType [I] Provider type of the CSP.
1950 * pdwReserved [I] Reserved for future use and must be NULL.
1951 * dwFlags [I] See MSDN Doc.
1957 BOOL WINAPI
CryptSetProviderExW (LPCWSTR pszProvName
, DWORD dwProvType
, DWORD
*pdwReserved
, DWORD dwFlags
)
1959 HKEY hProvKey
, hTypeKey
;
1961 static const WCHAR nameW
[] = {'N','a','m','e',0};
1963 TRACE("(%s, %d, %p, %08x)\n", debugstr_w(pszProvName
), dwProvType
, pdwReserved
, dwFlags
);
1965 if (!pszProvName
|| pdwReserved
)
1967 SetLastError(ERROR_INVALID_PARAMETER
);
1970 if (dwProvType
> MAXPROVTYPES
)
1972 SetLastError(NTE_BAD_PROV_TYPE
);
1975 if (dwFlags
& ~(CRYPT_MACHINE_DEFAULT
| CRYPT_USER_DEFAULT
| CRYPT_DELETE_DEFAULT
)
1976 || dwFlags
== CRYPT_DELETE_DEFAULT
)
1978 SetLastError(NTE_BAD_FLAGS
);
1982 if (!(keyname
= CRYPT_GetTypeKeyName(dwProvType
, dwFlags
& CRYPT_USER_DEFAULT
)))
1984 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1987 if (RegOpenKeyW((dwFlags
& CRYPT_USER_DEFAULT
) ? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
,
1988 keyname
, &hTypeKey
))
1990 CRYPT_Free(keyname
);
1991 SetLastError(NTE_BAD_PROVIDER
);
1994 CRYPT_Free(keyname
);
1996 if (dwFlags
& CRYPT_DELETE_DEFAULT
)
1998 RegDeleteValueW(hTypeKey
, nameW
);
2002 if (!(keyname
= CRYPT_GetProvKeyName(pszProvName
)))
2004 RegCloseKey(hTypeKey
);
2005 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2008 if (RegOpenKeyW((dwFlags
& CRYPT_USER_DEFAULT
) ? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
,
2009 keyname
, &hProvKey
))
2011 CRYPT_Free(keyname
);
2012 RegCloseKey(hTypeKey
);
2013 SetLastError(NTE_BAD_PROVIDER
);
2016 CRYPT_Free(keyname
);
2018 if (RegSetValueExW(hTypeKey
, nameW
, 0, REG_SZ
, (const BYTE
*)pszProvName
,
2019 (strlenW(pszProvName
) + 1)*sizeof(WCHAR
)))
2021 RegCloseKey(hTypeKey
);
2022 RegCloseKey(hProvKey
);
2026 RegCloseKey(hProvKey
);
2028 RegCloseKey(hTypeKey
);
2033 /******************************************************************************
2034 * CryptSetProviderExA (ADVAPI32.@)
2036 * See CryptSetProviderExW.
2038 BOOL WINAPI
CryptSetProviderExA (LPCSTR pszProvName
, DWORD dwProvType
, DWORD
*pdwReserved
, DWORD dwFlags
)
2043 TRACE("(%s, %d, %p, %08x)\n", pszProvName
, dwProvType
, pdwReserved
, dwFlags
);
2045 if (CRYPT_ANSIToUnicode(pszProvName
, &str
, -1))
2047 ret
= CryptSetProviderExW(str
, dwProvType
, pdwReserved
, dwFlags
);
2053 /******************************************************************************
2054 * CryptSetProvParam (ADVAPI32.@)
2056 * Customizes the operations of a CSP.
2059 * hProv [I] Handle of a CSP.
2060 * dwParam [I] See MSDN Doc.
2061 * pbData [I] Buffer that contains a value to set as a parameter.
2062 * dwFlags [I] if dwParam is PP_USE_HARDWARE_RNG, dwFlags must be zero.
2068 BOOL WINAPI
CryptSetProvParam (HCRYPTPROV hProv
, DWORD dwParam
, CONST BYTE
*pbData
, DWORD dwFlags
)
2070 PCRYPTPROV prov
= (PCRYPTPROV
)hProv
;
2072 TRACE("(0x%lx, %d, %p, %08x)\n", hProv
, dwParam
, pbData
, dwFlags
);
2076 SetLastError(ERROR_INVALID_HANDLE
);
2079 if (prov
->dwMagic
!= MAGIC_CRYPTPROV
)
2081 SetLastError(ERROR_INVALID_PARAMETER
);
2084 if (dwFlags
& PP_USE_HARDWARE_RNG
)
2086 FIXME("PP_USE_HARDWARE_RNG: What do I do with this?\n");
2087 FIXME("\tLetting the CSP decide.\n");
2089 if (dwFlags
& PP_CLIENT_HWND
)
2091 /* FIXME: Should verify the parameter */
2092 if (pbData
/* && IsWindow((HWND)pbData) */)
2094 crypt_hWindow
= (HWND
)(pbData
);
2097 SetLastError(ERROR_INVALID_PARAMETER
);
2101 /* All other flags go to the CSP */
2102 return prov
->pFuncs
->pCPSetProvParam(prov
->hPrivate
, dwParam
, pbData
, dwFlags
);
2105 /******************************************************************************
2106 * CryptVerifySignatureW (ADVAPI32.@)
2108 * Verifies the signature of a hash object.
2111 * hHash [I] Handle of the hash object to verify.
2112 * pbSignature [I] Signature data to verify.
2113 * dwSigLen [I] Size of pbSignature.
2114 * hPubKey [I] Handle to the public key to authenticate signature.
2115 * sDescription [I] Should be NULL.
2116 * dwFlags [I] See MSDN doc.
2123 * Because of security flaws sDescription should not be used and should thus be
2124 * NULL. It is supported only for compatibility with Microsoft's Cryptographic
2127 BOOL WINAPI
CryptVerifySignatureW (HCRYPTHASH hHash
, CONST BYTE
*pbSignature
, DWORD dwSigLen
,
2128 HCRYPTKEY hPubKey
, LPCWSTR sDescription
, DWORD dwFlags
)
2130 PCRYPTHASH hash
= (PCRYPTHASH
)hHash
;
2131 PCRYPTKEY key
= (PCRYPTKEY
)hPubKey
;
2134 TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash
, pbSignature
,
2135 dwSigLen
, hPubKey
, debugstr_w(sDescription
), dwFlags
);
2137 if (!hash
|| !key
||
2138 !hash
->pProvider
|| hash
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
||
2139 !key
->pProvider
|| key
->pProvider
->dwMagic
!= MAGIC_CRYPTPROV
)
2141 SetLastError(ERROR_INVALID_PARAMETER
);
2145 prov
= hash
->pProvider
;
2146 return prov
->pFuncs
->pCPVerifySignature(prov
->hPrivate
, hash
->hPrivate
, pbSignature
, dwSigLen
,
2147 key
->hPrivate
, sDescription
, dwFlags
);
2150 /******************************************************************************
2151 * CryptVerifySignatureA (ADVAPI32.@)
2153 * See CryptVerifySignatureW.
2155 BOOL WINAPI
CryptVerifySignatureA (HCRYPTHASH hHash
, CONST BYTE
*pbSignature
, DWORD dwSigLen
,
2156 HCRYPTKEY hPubKey
, LPCSTR sDescription
, DWORD dwFlags
)
2158 LPWSTR wsDescription
;
2161 TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash
, pbSignature
,
2162 dwSigLen
, hPubKey
, debugstr_a(sDescription
), dwFlags
);
2164 CRYPT_ANSIToUnicode(sDescription
, &wsDescription
, -1);
2165 result
= CryptVerifySignatureW(hHash
, pbSignature
, dwSigLen
, hPubKey
, wsDescription
, dwFlags
);
2166 CRYPT_Free(wsDescription
);
2171 /******************************************************************************
2172 * SystemFunction030 (ADVAPI32.@)
2174 * Tests if two blocks of 16 bytes are equal
2177 * b1,b2 [I] block of 16 bytes
2180 * TRUE if blocks are the same
2181 * FALSE if blocks are different
2183 BOOL WINAPI
SystemFunction030(PVOID b1
, PVOID b2
)
2185 return !memcmp(b1
, b2
, 0x10);
2188 /******************************************************************************
2189 * SystemFunction035 (ADVAPI32.@)
2192 http://disc.server.com/discussion.cgi?disc=148775;article=942;title=Coding%2FASM%2FSystem
2195 * Stub, always return TRUE.
2197 BOOL WINAPI
SystemFunction035(LPCSTR lpszDllFilePath
)
2199 FIXME("%s: stub\n", debugstr_a(lpszDllFilePath
));
2203 /******************************************************************************
2204 * SystemFunction036 (ADVAPI32.@)
2206 * MSDN documents this function as RtlGenRandom and declares it in ntsecapi.h
2209 * pbBufer [O] Pointer to memory to receive random bytes.
2210 * dwLen [I] Number of random bytes to fetch.
2217 BOOL WINAPI
SystemFunction036(PVOID pbBuffer
, ULONG dwLen
)
2221 /* FIXME: /dev/urandom does not provide random numbers of a sufficient
2222 * quality for cryptographic applications. /dev/random is much better,
2223 * but it blocks if the kernel has not yet collected enough entropy for
2224 * the request, which will suspend the calling thread for an indefinite
2225 * amount of time. */
2226 dev_random
= open("/dev/urandom", O_RDONLY
);
2227 if (dev_random
!= -1)
2229 if (read(dev_random
, pbBuffer
, dwLen
) == (ssize_t
)dwLen
)
2236 SetLastError(NTE_FAIL
);
2241 These functions have nearly identical prototypes to CryptProtectMemory and CryptUnprotectMemory,
2245 /******************************************************************************
2246 * SystemFunction040 (ADVAPI32.@)
2248 * MSDN documents this function as RtlEncryptMemory.
2251 * memory [I/O] Pointer to memory to encrypt.
2252 * length [I] Length of region to encrypt in bytes.
2253 * flags [I] Control whether other processes are able to decrypt the memory.
2254 * RTL_ENCRYPT_OPTION_SAME_PROCESS
2255 * RTL_ENCRYPT_OPTION_CROSS_PROCESS
2256 * RTL_ENCRYPT_OPTION_SAME_LOGON
2259 * Success: STATUS_SUCCESS
2260 * Failure: NTSTATUS error code
2263 * length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
2264 * If flags are specified when encrypting, the same flag value must be given
2265 * when decrypting the memory.
2267 NTSTATUS WINAPI
SystemFunction040(PVOID memory
, ULONG length
, ULONG flags
)
2269 FIXME("(%p, %x, %x): stub [RtlEncryptMemory]\n", memory
, length
, flags
);
2270 return STATUS_SUCCESS
;
2273 /******************************************************************************
2274 * SystemFunction041 (ADVAPI32.@)
2276 * MSDN documents this function as RtlDecryptMemory.
2279 * memory [I/O] Pointer to memory to decrypt.
2280 * length [I] Length of region to decrypt in bytes.
2281 * flags [I] Control whether other processes are able to decrypt the memory.
2282 * RTL_ENCRYPT_OPTION_SAME_PROCESS
2283 * RTL_ENCRYPT_OPTION_CROSS_PROCESS
2284 * RTL_ENCRYPT_OPTION_SAME_LOGON
2287 * Success: STATUS_SUCCESS
2288 * Failure: NTSTATUS error code
2291 * length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
2292 * If flags are specified when encrypting, the same flag value must be given
2293 * when decrypting the memory.
2295 NTSTATUS WINAPI
SystemFunction041(PVOID memory
, ULONG length
, ULONG flags
)
2297 FIXME("(%p, %x, %x): stub [RtlDecryptMemory]\n", memory
, length
, flags
);
2298 return STATUS_SUCCESS
;