ReactOS 0.4.15-dev-8138-g1e75ea8
crypt.c File Reference
#include "config.h"
#include "wine/port.h"
#include <limits.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include "ntstatus.h"
#include "crypt.h"
#include "winnls.h"
#include "winreg.h"
#include "rpc.h"
#include "wine/debug.h"
#include "wine/unicode.h"
#include "winternl.h"
Include dependency graph for crypt.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define CRYPT_Alloc(size)   (LocalAlloc(LMEM_ZEROINIT, size))
 
#define CRYPT_Free(buffer)   (LocalFree(buffer))
 
#define CRYPT_GetProvFunc(name)    if ( !(provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)) ) goto error
 
#define CRYPT_GetProvFuncOpt(name)    provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (crypt)
 
static PWSTR CRYPT_GetProvKeyName (PCWSTR pProvName)
 
static PWSTR CRYPT_GetTypeKeyName (DWORD dwType, BOOL user)
 
static BOOL CRYPT_UnicodeToANSI (LPCWSTR wstr, LPSTR *str, int strsize)
 
static BOOL CRYPT_ANSIToUnicode (LPCSTR str, LPWSTR *wstr, int wstrsize)
 
static BOOL CALLBACK CRYPT_VerifyImage (LPCSTR lpszImage, BYTE *pData)
 
static void CALLBACK CRYPT_ReturnhWnd (HWND *phWnd)
 
static PCRYPTPROV CRYPT_LoadProvider (PCWSTR pImage)
 
static void CRYPT_CreateMachineGuid (void)
 
void WINAPI CloseEncryptedFileRaw (PVOID context)
 
BOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR pszContainer, LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
 
BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
 
BOOL WINAPI CryptContextAddRef (HCRYPTPROV hProv, DWORD *pdwReserved, DWORD dwFlags)
 
BOOL WINAPI CryptReleaseContext (HCRYPTPROV hProv, DWORD dwFlags)
 
BOOL WINAPI CryptGenRandom (HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer)
 
BOOL WINAPI CryptCreateHash (HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
 
BOOL WINAPI CryptDecrypt (HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
 
BOOL WINAPI CryptDeriveKey (HCRYPTPROV hProv, ALG_ID Algid, HCRYPTHASH hBaseData, DWORD dwFlags, HCRYPTKEY *phKey)
 
BOOL WINAPI CryptDestroyHash (HCRYPTHASH hHash)
 
BOOL WINAPI CryptDestroyKey (HCRYPTKEY hKey)
 
BOOL WINAPI CryptDuplicateHash (HCRYPTHASH hHash, DWORD *pdwReserved, DWORD dwFlags, HCRYPTHASH *phHash)
 
BOOL WINAPI CryptDuplicateKey (HCRYPTKEY hKey, DWORD *pdwReserved, DWORD dwFlags, HCRYPTKEY *phKey)
 
BOOL WINAPI CryptEncrypt (HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
 
BOOL WINAPI CryptEnumProvidersW (DWORD dwIndex, DWORD *pdwReserved, DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszProvName, DWORD *pcbProvName)
 
BOOL WINAPI CryptEnumProvidersA (DWORD dwIndex, DWORD *pdwReserved, DWORD dwFlags, DWORD *pdwProvType, LPSTR pszProvName, DWORD *pcbProvName)
 
BOOL WINAPI CryptEnumProviderTypesW (DWORD dwIndex, DWORD *pdwReserved, DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszTypeName, DWORD *pcbTypeName)
 
BOOL WINAPI CryptEnumProviderTypesA (DWORD dwIndex, DWORD *pdwReserved, DWORD dwFlags, DWORD *pdwProvType, LPSTR pszTypeName, DWORD *pcbTypeName)
 
BOOL WINAPI CryptExportKey (HCRYPTKEY hKey, HCRYPTKEY hExpKey, DWORD dwBlobType, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
 
BOOL WINAPI CryptGenKey (HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey)
 
BOOL WINAPI CryptGetDefaultProviderW (DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags, LPWSTR pszProvName, DWORD *pcbProvName)
 
BOOL WINAPI CryptGetDefaultProviderA (DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags, LPSTR pszProvName, DWORD *pcbProvName)
 
BOOL WINAPI CryptGetHashParam (HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
 
BOOL WINAPI CryptGetKeyParam (HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
 
BOOL WINAPI CryptGetProvParam (HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
 
BOOL WINAPI CryptGetUserKey (HCRYPTPROV hProv, DWORD dwKeySpec, HCRYPTKEY *phUserKey)
 
BOOL WINAPI CryptHashData (HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
 
BOOL WINAPI CryptHashSessionKey (HCRYPTHASH hHash, HCRYPTKEY hKey, DWORD dwFlags)
 
BOOL WINAPI CryptImportKey (HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
 
BOOL WINAPI CryptSignHashW (HCRYPTHASH hHash, DWORD dwKeySpec, LPCWSTR sDescription, DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
 
BOOL WINAPI CryptSignHashA (HCRYPTHASH hHash, DWORD dwKeySpec, LPCSTR sDescription, DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
 
BOOL WINAPI CryptSetHashParam (HCRYPTHASH hHash, DWORD dwParam, const BYTE *pbData, DWORD dwFlags)
 
BOOL WINAPI CryptSetKeyParam (HCRYPTKEY hKey, DWORD dwParam, const BYTE *pbData, DWORD dwFlags)
 
BOOL WINAPI CryptSetProviderA (LPCSTR pszProvName, DWORD dwProvType)
 
BOOL WINAPI CryptSetProviderW (LPCWSTR pszProvName, DWORD dwProvType)
 
BOOL WINAPI CryptSetProviderExW (LPCWSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
 
BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
 
BOOL WINAPI CryptSetProvParam (HCRYPTPROV hProv, DWORD dwParam, const BYTE *pbData, DWORD dwFlags)
 
BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, const BYTE *pbSignature, DWORD dwSigLen, HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags)
 
BOOL WINAPI CryptVerifySignatureA (HCRYPTHASH hHash, const BYTE *pbSignature, DWORD dwSigLen, HCRYPTKEY hPubKey, LPCSTR sDescription, DWORD dwFlags)
 
DWORD WINAPI OpenEncryptedFileRawA (LPCSTR filename, ULONG flags, PVOID *context)
 
DWORD WINAPI OpenEncryptedFileRawW (LPCWSTR filename, ULONG flags, PVOID *context)
 
DWORD WINAPI ReadEncryptedFileRaw (PFE_EXPORT_FUNC export, PVOID callback, PVOID context)
 
BOOL WINAPI SystemFunction030 (LPCVOID b1, LPCVOID b2)
 
BOOL WINAPI SystemFunction035 (LPCSTR lpszDllFilePath)
 
BOOLEAN WINAPI SystemFunction036 (PVOID pbBuffer, ULONG dwLen)
 
NTSTATUS WINAPI SystemFunction040 (PVOID memory, ULONG length, ULONG flags)
 
NTSTATUS WINAPI SystemFunction041 (PVOID memory, ULONG length, ULONG flags)
 
DWORD WINAPI WriteEncryptedFileRaw (PFE_IMPORT_FUNC import, PVOID callback, PVOID context)
 

Variables

static HWND crypt_hWindow
 

Macro Definition Documentation

◆ CRYPT_Alloc

#define CRYPT_Alloc (   size)    (LocalAlloc(LMEM_ZEROINIT, size))

Definition at line 61 of file crypt.c.

◆ CRYPT_Free

#define CRYPT_Free (   buffer)    (LocalFree(buffer))

Definition at line 62 of file crypt.c.

◆ CRYPT_GetProvFunc

#define CRYPT_GetProvFunc (   name)     if ( !(provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)) ) goto error

Definition at line 200 of file crypt.c.

◆ CRYPT_GetProvFuncOpt

#define CRYPT_GetProvFuncOpt (   name)     provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)

Definition at line 202 of file crypt.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 47 of file crypt.c.

Function Documentation

◆ CloseEncryptedFileRaw()

void WINAPI CloseEncryptedFileRaw ( PVOID  context)

Definition at line 338 of file crypt.c.

339{
340 FIXME("(%p): stub\n", context);
341}
#define FIXME(fmt,...)
Definition: debug.h:114
Definition: http.c:7252

◆ CRYPT_ANSIToUnicode()

static BOOL CRYPT_ANSIToUnicode ( LPCSTR  str,
LPWSTR wstr,
int  wstrsize 
)
inlinestatic

Definition at line 158 of file crypt.c.

159{
160 unsigned int wcount;
161
162 if (!str)
163 {
164 *wstr = NULL;
165 return TRUE;
166 }
167 wcount = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
168 if (wstrsize == -1)
169 *wstr = CRYPT_Alloc(wcount * sizeof(WCHAR));
170 else
171 wcount = min( wcount, wstrsize/sizeof(WCHAR) );
172 if (*wstr)
173 {
174 MultiByteToWideChar(CP_ACP, 0, str, -1, *wstr, wcount);
175 return TRUE;
176 }
178 return FALSE;
179}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CRYPT_Alloc(size)
Definition: crypt.c:61
#define CP_ACP
Definition: compat.h:109
#define SetLastError(x)
Definition: compat.h:752
#define MultiByteToWideChar
Definition: compat.h:110
#define min(a, b)
Definition: monoChain.cc:55
const WCHAR * str
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CryptAcquireContextA(), CryptSetProviderExA(), CryptSignHashA(), and CryptVerifySignatureA().

◆ CRYPT_CreateMachineGuid()

static void CRYPT_CreateMachineGuid ( void  )
static

Definition at line 277 of file crypt.c.

278{
279 static const WCHAR cryptographyW[] = {
280 'S','o','f','t','w','a','r','e','\\',
281 'M','i','c','r','o','s','o','f','t','\\',
282 'C','r','y','p','t','o','g','r','a','p','h','y',0 };
283 static const WCHAR machineGuidW[] = {
284 'M','a','c','h','i','n','e','G','u','i','d',0 };
285 LONG r;
286 HKEY key;
287
289 &key);
290 if (!r)
291 {
292 DWORD size;
293
294 r = RegQueryValueExW(key, machineGuidW, NULL, NULL, NULL, &size);
295 if (r == ERROR_FILE_NOT_FOUND)
296 {
297 UUID uuid;
298 WCHAR buf[37];
299 RPC_STATUS rs;
300 static const WCHAR uuidFmt[] = {
301 '%','0','8','x','-','%','0','4','x','-',
302 '%','0','4','x','-','%','0','2','x',
303 '%','0','2','x','-','%','0','2','x',
304 '%','0','2','x','%','0','2','x',
305 '%','0','2','x','%','0','2','x',
306 '%','0','2','x',0 };
307
308 rs = UuidCreate(&uuid);
309 if (rs == S_OK)
310 {
311 sprintfW(buf, uuidFmt,
312 uuid.Data1, uuid.Data2, uuid.Data3,
313 uuid.Data4[0], uuid.Data4[1],
314 uuid.Data4[2], uuid.Data4[3],
315 uuid.Data4[4], uuid.Data4[5],
316 uuid.Data4[6], uuid.Data4[7] );
317 RegSetValueExW(key, machineGuidW, 0, REG_SZ,
318 (const BYTE *)buf,
319 (lstrlenW(buf)+1)*sizeof(WCHAR));
320 }
321 }
323 }
324}
#define RegCloseKey(hKey)
Definition: registry.h:49
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define lstrlenW
Definition: compat.h:750
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
Definition: msctf.idl:550
#define S_OK
Definition: intsafe.h:52
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
long LONG
Definition: pedump.c:60
#define sprintfW
Definition: unicode.h:64
RPC_STATUS WINAPI UuidCreate(UUID *Uuid)
Definition: rpcrt4_main.c:305
long RPC_STATUS
Definition: rpc.h:52
Definition: copy.c:22
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
unsigned char BYTE
Definition: xxhash.c:193

Referenced by CryptAcquireContextW().

◆ CRYPT_GetProvKeyName()

static PWSTR CRYPT_GetProvKeyName ( PCWSTR  pProvName)
inlinestatic

Definition at line 64 of file crypt.c.

65{
66 static const WCHAR KEYSTR[] = {
67 'S','o','f','t','w','a','r','e','\\',
68 'M','i','c','r','o','s','o','f','t','\\',
69 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
70 'D','e','f','a','u','l','t','s','\\',
71 'P','r','o','v','i','d','e','r','\\',0
72 };
73 PWSTR keyname;
74
75 keyname = CRYPT_Alloc((strlenW(KEYSTR) + strlenW(pProvName) +1)*sizeof(WCHAR));
76 if (keyname)
77 {
78 strcpyW(keyname, KEYSTR);
79 strcpyW(keyname + strlenW(KEYSTR), pProvName);
80 } else
82 return keyname;
83}
#define strlenW(s)
Definition: unicode.h:34
#define strcpyW(d, s)
Definition: unicode.h:35
uint16_t * PWSTR
Definition: typedefs.h:56

Referenced by CryptAcquireContextW(), and CryptSetProviderExW().

◆ CRYPT_GetTypeKeyName()

static PWSTR CRYPT_GetTypeKeyName ( DWORD  dwType,
BOOL  user 
)
inlinestatic

Definition at line 85 of file crypt.c.

86{
87 static const WCHAR MACHINESTR[] = {
88 'S','o','f','t','w','a','r','e','\\',
89 'M','i','c','r','o','s','o','f','t','\\',
90 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
91 'D','e','f','a','u','l','t','s','\\',
92 'P','r','o','v','i','d','e','r',' ','T','y','p','e','s','\\',
93 'T','y','p','e',' ','X','X','X',0
94 };
95 static const WCHAR USERSTR[] = {
96 'S','o','f','t','w','a','r','e','\\',
97 'M','i','c','r','o','s','o','f','t','\\',
98 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
99 'P','r','o','v','i','d','e','r',' ','T','y','p','e',' ','X','X','X',0
100 };
101 PWSTR keyname;
102 PWSTR ptr;
103
104 keyname = CRYPT_Alloc( ((user ? strlenW(USERSTR) : strlenW(MACHINESTR)) +1)*sizeof(WCHAR));
105 if (keyname)
106 {
107 user ? strcpyW(keyname, USERSTR) : strcpyW(keyname, MACHINESTR);
108 ptr = keyname + strlenW(keyname);
109 *(--ptr) = (dwType % 10) + '0';
110 *(--ptr) = ((dwType / 10) % 10) + '0';
111 *(--ptr) = (dwType / 100) + '0';
112 } else
114 return keyname;
115}
void user(int argc, const char *argv[])
Definition: cmds.c:1350
static PVOID ptr
Definition: dispmode.c:27

Referenced by CryptAcquireContextW(), CryptGetDefaultProviderW(), and CryptSetProviderExW().

◆ CRYPT_LoadProvider()

static PCRYPTPROV CRYPT_LoadProvider ( PCWSTR  pImage)
static

Definition at line 204 of file crypt.c.

205{
206 PCRYPTPROV provider;
207 DWORD errorcode = ERROR_NOT_ENOUGH_MEMORY;
208
209 if ( !(provider = CRYPT_Alloc(sizeof(CRYPTPROV))) ) goto error;
210 if ( !(provider->pFuncs = CRYPT_Alloc(sizeof(PROVFUNCS))) ) goto error;
211 if ( !(provider->pVTable = CRYPT_Alloc(sizeof(VTableProvStruc))) ) goto error;
212 if ( !(provider->hModule = LoadLibraryW(pImage)) )
213 {
215 FIXME("Failed to load dll %s\n", debugstr_w(pImage));
216 goto error;
217 }
218 provider->dwMagic = MAGIC_CRYPTPROV;
219 provider->refcount = 1;
220
221 errorcode = NTE_PROVIDER_DLL_FAIL;
222 CRYPT_GetProvFunc(CPAcquireContext);
223 CRYPT_GetProvFunc(CPCreateHash);
224 CRYPT_GetProvFunc(CPDecrypt);
225 CRYPT_GetProvFunc(CPDeriveKey);
226 CRYPT_GetProvFunc(CPDestroyHash);
227 CRYPT_GetProvFunc(CPDestroyKey);
228 CRYPT_GetProvFuncOpt(CPDuplicateHash);
229 CRYPT_GetProvFuncOpt(CPDuplicateKey);
230 CRYPT_GetProvFunc(CPEncrypt);
231 CRYPT_GetProvFunc(CPExportKey);
232 CRYPT_GetProvFunc(CPGenKey);
233 CRYPT_GetProvFunc(CPGenRandom);
234 CRYPT_GetProvFunc(CPGetHashParam);
235 CRYPT_GetProvFunc(CPGetKeyParam);
236 CRYPT_GetProvFunc(CPGetProvParam);
237 CRYPT_GetProvFunc(CPGetUserKey);
238 CRYPT_GetProvFunc(CPHashData);
239 CRYPT_GetProvFunc(CPHashSessionKey);
240 CRYPT_GetProvFunc(CPImportKey);
241 CRYPT_GetProvFunc(CPReleaseContext);
242 CRYPT_GetProvFunc(CPSetHashParam);
243 CRYPT_GetProvFunc(CPSetKeyParam);
244 CRYPT_GetProvFunc(CPSetProvParam);
245 CRYPT_GetProvFunc(CPSignHash);
246 CRYPT_GetProvFunc(CPVerifySignature);
247
248 /* FIXME: Not sure what the pbContextInfo field is for.
249 * Does it need memory allocation?
250 */
251 provider->pVTable->Version = 3;
254 provider->pVTable->dwProvType = 0;
255 provider->pVTable->pbContextInfo = NULL;
256 provider->pVTable->cbContextInfo = 0;
257 provider->pVTable->pszProvName = NULL;
258 return provider;
259
260error:
261 SetLastError(errorcode);
262 if (provider)
263 {
264 provider->dwMagic = 0;
265 if (provider->hModule)
266 FreeLibrary(provider->hModule);
267 CRYPT_Free(provider->pVTable);
268 CRYPT_Free(provider->pFuncs);
269 CRYPT_Free(provider);
270 }
271 return NULL;
272}
#define CRYPT_Free(buffer)
Definition: crypt.c:62
#define CRYPT_GetProvFunc(name)
Definition: crypt.c:200
#define CRYPT_GetProvFuncOpt(name)
Definition: crypt.c:202
static BOOL CALLBACK CRYPT_VerifyImage(LPCSTR lpszImage, BYTE *pData)
Definition: crypt.c:182
static void CALLBACK CRYPT_ReturnhWnd(HWND *phWnd)
Definition: crypt.c:195
#define MAGIC_CRYPTPROV
Definition: crypt.h:61
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
#define debugstr_w
Definition: kernel32.h:32
#define error(str)
Definition: mkdosfs.c:1605
BYTE * pbContextInfo
Definition: wincrypt.h:706
FARPROC FuncVerifyImage
Definition: wincrypt.h:702
FARPROC FuncReturnhWnd
Definition: wincrypt.h:703
LPSTR pszProvName
Definition: wincrypt.h:708
DWORD dwProvType
Definition: wincrypt.h:705
DWORD cbContextInfo
Definition: wincrypt.h:707
HMODULE hModule
Definition: crypt.h:69
PVTableProvStruc pVTable
Definition: crypt.h:72
PPROVFUNCS pFuncs
Definition: crypt.h:70
LONG refcount
Definition: crypt.h:68
DWORD dwMagic
Definition: crypt.h:67
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define NTE_PROV_DLL_NOT_FOUND
Definition: winerror.h:2898
#define NTE_PROVIDER_DLL_FAIL
Definition: winerror.h:2897

Referenced by CryptAcquireContextW().

◆ CRYPT_ReturnhWnd()

static void CALLBACK CRYPT_ReturnhWnd ( HWND phWnd)
static

Definition at line 195 of file crypt.c.

196{
197 if (phWnd) *phWnd = crypt_hWindow;
198}
static HWND crypt_hWindow
Definition: crypt.c:59

Referenced by CRYPT_LoadProvider().

◆ CRYPT_UnicodeToANSI()

static BOOL CRYPT_UnicodeToANSI ( LPCWSTR  wstr,
LPSTR str,
int  strsize 
)
inlinestatic

Definition at line 125 of file crypt.c.

126{
127 if (!wstr)
128 {
129 *str = NULL;
130 return TRUE;
131 }
132
133 if (!*str)
134 {
135 strsize = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
136 *str = CRYPT_Alloc(strsize * sizeof(CHAR));
137 }
138 else if (strsize < 0)
139 {
140 strsize = INT_MAX; /* windows will pretend that the buffer is infinitely long */
141 }
142
143 if (*str)
144 {
145 WideCharToMultiByte(CP_ACP, 0, wstr, -1, *str, strsize, NULL, NULL);
146 return TRUE;
147 }
148
150 return FALSE;
151}
#define WideCharToMultiByte
Definition: compat.h:111
#define INT_MAX
Definition: limits.h:40
char CHAR
Definition: xmlstorage.h:175

Referenced by CryptAcquireContextW(), CryptEnumProvidersA(), CryptEnumProviderTypesA(), and CryptGetDefaultProviderA().

◆ CRYPT_VerifyImage()

static BOOL CALLBACK CRYPT_VerifyImage ( LPCSTR  lpszImage,
BYTE pData 
)
static

Definition at line 182 of file crypt.c.

183{
184 if (!lpszImage || !pData)
185 {
187 return FALSE;
188 }
189
190 FIXME("(%s, %p): not verifying image\n", lpszImage, pData);
191
192 return TRUE;
193}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830

Referenced by CRYPT_LoadProvider().

◆ CryptAcquireContextA()

BOOL WINAPI CryptAcquireContextA ( HCRYPTPROV phProv,
LPCSTR  pszContainer,
LPCSTR  pszProvider,
DWORD  dwProvType,
DWORD  dwFlags 
)

Definition at line 569 of file crypt.c.

571{
572 PWSTR pProvider = NULL, pContainer = NULL;
573 BOOL ret = FALSE;
574
575 TRACE("(%p, %s, %s, %d, %08x)\n", phProv, debugstr_a(pszContainer),
576 debugstr_a(pszProvider), dwProvType, dwFlags);
577
578 if ( !CRYPT_ANSIToUnicode(pszContainer, &pContainer, -1) )
579 {
581 return FALSE;
582 }
583 if ( !CRYPT_ANSIToUnicode(pszProvider, &pProvider, -1) )
584 {
585 CRYPT_Free(pContainer);
587 return FALSE;
588 }
589
590 ret = CryptAcquireContextW(phProv, pContainer, pProvider, dwProvType, dwFlags);
591
592 CRYPT_Free(pContainer);
594
595 return ret;
596}
static BOOL CRYPT_ANSIToUnicode(LPCSTR str, LPWSTR *wstr, int wstrsize)
Definition: crypt.c:158
BOOL WINAPI CryptAcquireContextW(HCRYPTPROV *phProv, LPCWSTR pszContainer, LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
Definition: crypt.c:358
unsigned int BOOL
Definition: ntddk_ex.h:94
FxWmiProvider * pProvider
Definition: fxwmiapi.cpp:54
#define debugstr_a
Definition: kernel32.h:31
#define TRACE(s)
Definition: solgame.cpp:4
int ret
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Referenced by clean_up_aes_environment(), clean_up_base_environment(), CRYPT_CreateKeyProv(), init_aes_environment(), init_base_environment(), init_function_pointers(), test_container_sd(), test_hashes(), test_key_initialization(), test_null_provider(), test_rsa_round_trip(), test_schannel_provider(), and testPortPublicKeyInfo().

◆ CryptAcquireContextW()

BOOL WINAPI CryptAcquireContextW ( HCRYPTPROV phProv,
LPCWSTR  pszContainer,
LPCWSTR  pszProvider,
DWORD  dwProvType,
DWORD  dwFlags 
)

Definition at line 358 of file crypt.c.

360{
361 PCRYPTPROV pProv = NULL;
362 HKEY key;
363 PWSTR imagepath = NULL, keyname = NULL, provname = NULL, temp = NULL;
364 PSTR provnameA = NULL, pszContainerA = NULL;
365 DWORD keytype, type, len;
366 ULONG r;
367 static const WCHAR nameW[] = {'N','a','m','e',0};
368 static const WCHAR typeW[] = {'T','y','p','e',0};
369 static const WCHAR imagepathW[] = {'I','m','a','g','e',' ','P','a','t','h',0};
370
371 TRACE("(%p, %s, %s, %d, %08x)\n", phProv, debugstr_w(pszContainer),
372 debugstr_w(pszProvider), dwProvType, dwFlags);
373
374 if (dwProvType < 1 || dwProvType > MAXPROVTYPES)
375 {
377 return FALSE;
378 }
379
380 if (!phProv)
381 {
383 return FALSE;
384 }
385
386 /* Make sure the MachineGuid value exists */
388
389 if (!pszProvider || !*pszProvider)
390 {
391 /* No CSP name specified so try the user default CSP first
392 * then try the machine default CSP
393 */
394 if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, TRUE)) ) {
395 TRACE("No provider registered for crypto provider type %d.\n", dwProvType);
397 return FALSE;
398 }
399 if (RegOpenKeyW(HKEY_CURRENT_USER, keyname, &key))
400 {
401 CRYPT_Free(keyname);
402 if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, FALSE)) ) {
403 TRACE("No type registered for crypto provider type %d.\n", dwProvType);
406 goto error;
407 }
408 if (RegOpenKeyW(HKEY_LOCAL_MACHINE, keyname, &key)) {
409 TRACE("Did not find registry entry of crypto provider for %s.\n", debugstr_w(keyname));
410 CRYPT_Free(keyname);
413 goto error;
414 }
415 }
416 CRYPT_Free(keyname);
417 r = RegQueryValueExW(key, nameW, NULL, &keytype, NULL, &len);
418 if( r != ERROR_SUCCESS || !len || keytype != REG_SZ)
419 {
420 TRACE("error %d reading size of 'Name' from registry\n", r );
423 goto error;
424 }
425 if(!(provname = CRYPT_Alloc(len)))
426 {
429 goto error;
430 }
431 r = RegQueryValueExW(key, nameW, NULL, NULL, (LPBYTE)provname, &len);
432 if( r != ERROR_SUCCESS )
433 {
434 TRACE("error %d reading 'Name' from registry\n", r );
437 goto error;
438 }
440 } else {
441 if ( !(provname = CRYPT_Alloc((strlenW(pszProvider) +1)*sizeof(WCHAR))) )
442 {
444 goto error;
445 }
446 strcpyW(provname, pszProvider);
447 }
448
449 keyname = CRYPT_GetProvKeyName(provname);
450 r = RegOpenKeyW(HKEY_LOCAL_MACHINE, keyname, &key);
451 CRYPT_Free(keyname);
452 if (r != ERROR_SUCCESS)
453 {
455 goto error;
456 }
457 len = sizeof(DWORD);
459 if (r != ERROR_SUCCESS)
460 {
462 goto error;
463 }
464 if (type != dwProvType)
465 {
466 TRACE("Crypto provider has wrong type (%d vs expected %d).\n", type, dwProvType);
468 goto error;
469 }
470
471 r = RegQueryValueExW(key, imagepathW, NULL, &keytype, NULL, &len);
472 if ( r != ERROR_SUCCESS || keytype != REG_SZ)
473 {
474 TRACE("error %d reading size of 'Image Path' from registry\n", r );
477 goto error;
478 }
479 if (!(temp = CRYPT_Alloc(len)))
480 {
483 goto error;
484 }
485 r = RegQueryValueExW(key, imagepathW, NULL, NULL, (LPBYTE)temp, &len);
486 if( r != ERROR_SUCCESS )
487 {
488 TRACE("error %d reading 'Image Path' from registry\n", r );
491 goto error;
492 }
495 if ( !(imagepath = CRYPT_Alloc(len*sizeof(WCHAR))) )
496 {
498 goto error;
499 }
500 if (!ExpandEnvironmentStringsW(temp, imagepath, len))
501 {
502 /* ExpandEnvironmentStrings will call SetLastError */
503 goto error;
504 }
505 pProv = CRYPT_LoadProvider(imagepath);
506 if (!pProv) {
507 /* CRYPT_LoadProvider calls SetLastError */
508 goto error;
509 }
510 pProv->pVTable->dwProvType = dwProvType;
511 if(!CRYPT_UnicodeToANSI(provname, &provnameA, 0))
512 {
513 /* CRYPT_UnicodeToANSI calls SetLastError */
514 goto error;
515 }
516 pProv->pVTable->pszProvName = provnameA;
517 if(!CRYPT_UnicodeToANSI(pszContainer, &pszContainerA, 0))
518 {
519 /* CRYPT_UnicodeToANSI calls SetLastError */
520 goto error;
521 }
522 if (pProv->pFuncs->pCPAcquireContext(&pProv->hPrivate, pszContainerA, dwFlags, pProv->pVTable))
523 {
524 /* MSDN: When this flag is set, the value returned in phProv is undefined,
525 * and thus, the CryptReleaseContext function need not be called afterwards.
526 * Therefore, we must clean up everything now.
527 */
529 {
530 pProv->dwMagic = 0;
531 FreeLibrary(pProv->hModule);
532 CRYPT_Free(provnameA);
533 CRYPT_Free(pProv->pVTable);
534 CRYPT_Free(pProv->pFuncs);
535 CRYPT_Free(pProv);
536 } else {
537 *phProv = (HCRYPTPROV)pProv;
538 }
539 CRYPT_Free(pszContainerA);
540 CRYPT_Free(provname);
542 CRYPT_Free(imagepath);
543 return TRUE;
544 }
545 /* FALLTHROUGH TO ERROR IF FALSE - CSP internal error! */
546error:
547 if (pProv)
548 {
549 pProv->dwMagic = 0;
550 if (pProv->hModule)
551 FreeLibrary(pProv->hModule);
552 CRYPT_Free(pProv->pVTable);
553 CRYPT_Free(pProv->pFuncs);
554 CRYPT_Free(pProv);
555 }
556 CRYPT_Free(pszContainerA);
557 CRYPT_Free(provnameA);
558 CRYPT_Free(provname);
560 CRYPT_Free(imagepath);
561 return FALSE;
562}
static const WCHAR nameW[]
Definition: main.c:46
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
static PWSTR CRYPT_GetProvKeyName(PCWSTR pProvName)
Definition: crypt.c:64
static PCRYPTPROV CRYPT_LoadProvider(PCWSTR pImage)
Definition: crypt.c:204
static PWSTR CRYPT_GetTypeKeyName(DWORD dwType, BOOL user)
Definition: crypt.c:85
static BOOL CRYPT_UnicodeToANSI(LPCWSTR wstr, LPSTR *str, int strsize)
Definition: crypt.c:125
static void CRYPT_CreateMachineGuid(void)
Definition: crypt.c:277
#define MAXPROVTYPES
Definition: crypt.h:89
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
static const WCHAR typeW[]
Definition: name.c:51
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLenum GLsizei len
Definition: glext.h:6722
#define DWORD
Definition: nt_native.h:44
static calc_node_t temp
Definition: rpn_ieee.c:38
HCRYPTPROV hPrivate
Definition: crypt.h:71
char * PSTR
Definition: typedefs.h:51
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define CRYPT_DELETEKEYSET
Definition: wincrypt.h:2071
#define NTE_BAD_PROV_TYPE
Definition: winerror.h:2888
#define NTE_KEYSET_NOT_DEF
Definition: winerror.h:2893
#define NTE_PROV_TYPE_ENTRY_BAD
Definition: winerror.h:2892
#define NTE_PROV_TYPE_NO_MATCH
Definition: winerror.h:2895
#define NTE_PROV_TYPE_NOT_DEF
Definition: winerror.h:2891
#define HKEY_CURRENT_USER
Definition: winreg.h:11

Referenced by CertCreateSelfSignCertificate(), CRYPT_AcquirePrivateKeyFromProvInfo(), CRYPT_GetDefaultProvider(), CryptAcquireContextA(), CryptCATAdminCalcHashFromFileHandle(), CryptCATAdminEnumCatalogFromHash(), CryptProtectData(), CryptUnprotectData(), DllRegisterServer(), export_acquire_private_key(), find_key_prov_info_in_provider(), hash_file(), I_CryptGetDefaultCryptProv(), init_function_pointers(), key_prov_info_matches_cert(), save_pfx(), SOFTPUB_VerifyImageHash(), START_TEST(), and testAcquireSecurityContext().

◆ CryptContextAddRef()

BOOL WINAPI CryptContextAddRef ( HCRYPTPROV  hProv,
DWORD pdwReserved,
DWORD  dwFlags 
)

Definition at line 613 of file crypt.c.

614{
615 PCRYPTPROV pProv = (PCRYPTPROV)hProv;
616
617 TRACE("(0x%lx, %p, %08x)\n", hProv, pdwReserved, dwFlags);
618
619 if (!pProv)
620 {
622 return FALSE;
623 }
624
625 if (pProv->dwMagic != MAGIC_CRYPTPROV)
626 {
628 return FALSE;
629 }
630
632 return TRUE;
633}
#define InterlockedIncrement
Definition: armddk.h:53
struct tagCRYPTPROV * PCRYPTPROV
static HCRYPTPROV hProv
Definition: rsaenh.c:32
_Reserved_ DWORD * pdwReserved
Definition: wincrypt.h:4254
#define NTE_BAD_UID
Definition: winerror.h:2869

Referenced by I_CryptGetDefaultCryptProv().

◆ CryptCreateHash()

BOOL WINAPI CryptCreateHash ( HCRYPTPROV  hProv,
ALG_ID  Algid,
HCRYPTKEY  hKey,
DWORD  dwFlags,
HCRYPTHASH phHash 
)

Definition at line 740 of file crypt.c.

742{
746
747 TRACE("(0x%lx, 0x%x, 0x%lx, %08x, %p)\n", hProv, Algid, hKey, dwFlags, phHash);
748
749 if (!prov || !phHash || prov->dwMagic != MAGIC_CRYPTPROV ||
750 (key && key->dwMagic != MAGIC_CRYPTKEY))
751 {
753 return FALSE;
754 }
755 if (dwFlags)
756 {
758 return FALSE;
759 }
760 if ( !(hash = CRYPT_Alloc(sizeof(CRYPTHASH))) )
761 {
763 return FALSE;
764 }
765
766 hash->pProvider = prov;
767 hash->dwMagic = MAGIC_CRYPTHASH;
768 if (prov->pFuncs->pCPCreateHash(prov->hPrivate, Algid,
769 key ? key->hPrivate : 0, 0, &hash->hPrivate))
770 {
771 *phHash = (HCRYPTHASH)hash;
772 return TRUE;
773 }
774
775 /* CSP error! */
776 hash->dwMagic = 0;
778 *phHash = 0;
779 return FALSE;
780}
#define MAGIC_CRYPTHASH
Definition: crypt.h:63
#define MAGIC_CRYPTKEY
Definition: crypt.h:62
struct tagCRYPTKEY * PCRYPTKEY
FxAutoRegKey hKey
Definition: _hash_fun.h:40
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:50
#define NTE_BAD_FLAGS
Definition: winerror.h:2877

Referenced by CDecodeMsg_FinalizeHashedContent(), CHashEncodeMsg_Open(), create_silly_rename(), CRYPT_VerifySignature(), CryptCATAdminCalcHashFromFileHandle(), CryptHashCertificate(), CryptHashPublicKeyInfo(), CryptHashToBeSigned(), CryptProtectData(), CryptSignCertificate(), CryptUnprotectData(), CSignedMsgData_ConstructSignerHandles(), derive_key(), hash_dib(), hash_file(), load_encryption_key(), nfs41_client_owner(), rdssl_hash_clear(), rdssl_hash_info_create(), rdssl_hmac_md5(), SOFTPUB_VerifyImageHash(), test_hashes(), test_hmac(), test_import_hmac(), test_key_derivation(), test_mac(), test_rc2(), test_rc4(), test_schannel_provider(), test_sha2(), test_verify_signature(), and verifySig().

◆ CryptDecrypt()

BOOL WINAPI CryptDecrypt ( HCRYPTKEY  hKey,
HCRYPTHASH  hHash,
BOOL  Final,
DWORD  dwFlags,
BYTE pbData,
DWORD pdwDataLen 
)

Definition at line 800 of file crypt.c.

802{
803 PCRYPTPROV prov;
806
807 TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hHash, Final, dwFlags, pbData, pdwDataLen);
808
809 if (!key || !pbData || !pdwDataLen ||
810 !key->pProvider || key->dwMagic != MAGIC_CRYPTKEY ||
811 key->pProvider->dwMagic != MAGIC_CRYPTPROV)
812 {
814 return FALSE;
815 }
816
817 prov = key->pProvider;
818 return prov->pFuncs->pCPDecrypt(prov->hPrivate, key->hPrivate, hash ? hash->hPrivate : 0,
820}
struct tagCRYPTHASH * PCRYPTHASH
_In_ HCRYPTHASH _In_ BOOL Final
Definition: wincrypt.h:4199
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
_In_ HCRYPTHASH hHash
Definition: wincrypt.h:4198
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE _Inout_ DWORD * pdwDataLen
Definition: wincrypt.h:4202

Referenced by CDecodeEnvelopedMsg_CrtlDecrypt(), CryptUnprotectData(), test_3des(), test_3des112(), test_aes(), test_block_cipher_modes(), test_des(), test_import_private(), test_rc2(), test_rc4(), test_rsa_encrypt(), and test_rsa_round_trip().

◆ CryptDeriveKey()

BOOL WINAPI CryptDeriveKey ( HCRYPTPROV  hProv,
ALG_ID  Algid,
HCRYPTHASH  hBaseData,
DWORD  dwFlags,
HCRYPTKEY phKey 
)

Definition at line 838 of file crypt.c.

840{
842 PCRYPTHASH hash = (PCRYPTHASH)hBaseData;
844
845 TRACE("(0x%lx, 0x%08x, 0x%lx, 0x%08x, %p)\n", hProv, Algid, hBaseData, dwFlags, phKey);
846
847 if (!prov || !hash)
848 {
850 return FALSE;
851 }
852 if (!phKey || prov->dwMagic != MAGIC_CRYPTPROV || hash->dwMagic != MAGIC_CRYPTHASH)
853 {
855 return FALSE;
856 }
857 if ( !(key = CRYPT_Alloc(sizeof(CRYPTKEY))) )
858 {
860 return FALSE;
861 }
862
863 key->pProvider = prov;
864 key->dwMagic = MAGIC_CRYPTKEY;
865 if (prov->pFuncs->pCPDeriveKey(prov->hPrivate, Algid, hash->hPrivate, dwFlags, &key->hPrivate))
866 {
867 *phKey = (HCRYPTKEY)key;
868 return TRUE;
869 }
870
871 /* CSP error! */
872 key->dwMagic = 0;
874 *phKey = 0;
875 return FALSE;
876}
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49

Referenced by derive_key(), load_encryption_key(), test_key_derivation(), test_rc2(), test_rc4(), and test_schannel_provider().

◆ CryptDestroyHash()

◆ CryptDestroyKey()

BOOL WINAPI CryptDestroyKey ( HCRYPTKEY  hKey)

Definition at line 930 of file crypt.c.

931{
933 PCRYPTPROV prov;
934 BOOL ret;
935
936 TRACE("(0x%lx)\n", hKey);
937
938 if (!key)
939 {
941 return FALSE;
942 }
943
944 if (!key->pProvider || key->dwMagic != MAGIC_CRYPTKEY ||
945 key->pProvider->dwMagic != MAGIC_CRYPTPROV)
946 {
948 return FALSE;
949 }
950
951 prov = key->pProvider;
952 ret = prov->pFuncs->pCPDestroyKey(prov->hPrivate, key->hPrivate);
953 key->dwMagic = 0;
955 return ret;
956}

Referenced by CDecodeEnvelopedMsg_CrtlDecrypt(), CDecodeSignedMsg_VerifySignatureWithKey(), CEnvelopedEncodeMsg_Close(), CertCreateSelfSignCertificate(), CertGetPublicKeyLength(), CRYPT_CreateKeyProv(), CRYPT_ExportKeyTrans(), CRYPT_ExportPublicKeyInfoEx(), CRYPT_ImportKeyTrans(), CRYPT_VerifySignature(), CryptProtectData(), CryptUnprotectData(), export_is_key_exportable(), init_aes_environment(), init_base_environment(), rdssl_cert_to_rkey(), rdssl_rc4_info_delete(), rdssl_rc4_set_key(), test_3des(), test_3des112(), test_aes(), test_block_cipher_modes(), test_decode_msg_get_param(), test_des(), test_hashes(), test_hmac(), test_import_export(), test_import_hmac(), test_import_private(), test_key_derivation(), test_key_initialization(), test_key_permissions(), test_mac(), test_null_provider(), test_rc2(), test_rc4(), test_rsa_encrypt(), test_rsa_round_trip(), test_schannel_provider(), test_sign_message(), test_signed_msg_encoding(), test_signed_msg_update(), test_verify_signature(), testAcquireCertPrivateKey(), testAcquireSecurityContext(), testCreateSelfSignCert(), testExportPublicKey(), testImportPublicKey(), and testSignCert().

◆ CryptDuplicateHash()

BOOL WINAPI CryptDuplicateHash ( HCRYPTHASH  hHash,
DWORD pdwReserved,
DWORD  dwFlags,
HCRYPTHASH phHash 
)

Definition at line 973 of file crypt.c.

975{
976 PCRYPTPROV prov;
977 PCRYPTHASH orghash, newhash;
978
979 TRACE("(0x%lx, %p, %08x, %p)\n", hHash, pdwReserved, dwFlags, phHash);
980
981 orghash = (PCRYPTHASH)hHash;
982 if (!orghash || pdwReserved || !phHash || !orghash->pProvider ||
983 orghash->dwMagic != MAGIC_CRYPTHASH || orghash->pProvider->dwMagic != MAGIC_CRYPTPROV)
984 {
986 return FALSE;
987 }
988
989 prov = orghash->pProvider;
990 if (!prov->pFuncs->pCPDuplicateHash)
991 {
993 return FALSE;
994 }
995
996 if ( !(newhash = CRYPT_Alloc(sizeof(CRYPTHASH))) )
997 {
999 return FALSE;
1000 }
1001
1002 newhash->pProvider = prov;
1003 newhash->dwMagic = MAGIC_CRYPTHASH;
1004 if (prov->pFuncs->pCPDuplicateHash(prov->hPrivate, orghash->hPrivate, pdwReserved, dwFlags, &newhash->hPrivate))
1005 {
1006 *phHash = (HCRYPTHASH)newhash;
1007 return TRUE;
1008 }
1009 newhash->dwMagic = 0;
1010 CRYPT_Free(newhash);
1011 return FALSE;
1012}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
PCRYPTPROV pProvider
Definition: crypt.h:85
HCRYPTHASH hPrivate
Definition: crypt.h:86
DWORD dwMagic
Definition: crypt.h:84

◆ CryptDuplicateKey()

BOOL WINAPI CryptDuplicateKey ( HCRYPTKEY  hKey,
DWORD pdwReserved,
DWORD  dwFlags,
HCRYPTKEY phKey 
)

Definition at line 1029 of file crypt.c.

1030{
1031 PCRYPTPROV prov;
1032 PCRYPTKEY orgkey, newkey;
1033
1034 TRACE("(0x%lx, %p, %08x, %p)\n", hKey, pdwReserved, dwFlags, phKey);
1035
1036 orgkey = (PCRYPTKEY)hKey;
1037 if (!orgkey || pdwReserved || !phKey || !orgkey->pProvider ||
1038 orgkey->dwMagic != MAGIC_CRYPTKEY ||
1039 orgkey->pProvider->dwMagic != MAGIC_CRYPTPROV)
1040 {
1042 return FALSE;
1043 }
1044
1045 prov = orgkey->pProvider;
1046 if (!prov->pFuncs->pCPDuplicateKey)
1047 {
1049 return FALSE;
1050 }
1051
1052 if ( !(newkey = CRYPT_Alloc(sizeof(CRYPTKEY))) )
1053 {
1055 return FALSE;
1056 }
1057
1058 newkey->pProvider = prov;
1059 newkey->dwMagic = MAGIC_CRYPTKEY;
1060 if (prov->pFuncs->pCPDuplicateKey(prov->hPrivate, orgkey->hPrivate, pdwReserved, dwFlags, &newkey->hPrivate))
1061 {
1062 *phKey = (HCRYPTKEY)newkey;
1063 return TRUE;
1064 }
1065 newkey->dwMagic = 0;
1066 CRYPT_Free(newkey);
1067 return FALSE;
1068}
HCRYPTKEY hPrivate
Definition: crypt.h:79
DWORD dwMagic
Definition: crypt.h:77
PCRYPTPROV pProvider
Definition: crypt.h:78

◆ CryptEncrypt()

BOOL WINAPI CryptEncrypt ( HCRYPTKEY  hKey,
HCRYPTHASH  hHash,
BOOL  Final,
DWORD  dwFlags,
BYTE pbData,
DWORD pdwDataLen,
DWORD  dwBufLen 
)

Definition at line 1093 of file crypt.c.

1095{
1096 PCRYPTPROV prov;
1099
1100 TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p, %d)\n", hKey, hHash, Final, dwFlags, pbData, pdwDataLen, dwBufLen);
1101
1102 if (!key || !pdwDataLen || !key->pProvider ||
1103 key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
1104 {
1106 return FALSE;
1107 }
1108
1109 prov = key->pProvider;
1110 return prov->pFuncs->pCPEncrypt(prov->hPrivate, key->hPrivate, hash ? hash->hPrivate : 0,
1112}
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_ DWORD _In_ DWORD dwBufLen
Definition: wincrypt.h:4246

Referenced by CEnvelopedEncodeMsg_Update(), CryptProtectData(), rdssl_rc4_crypt(), test_3des(), test_3des112(), test_aes(), test_block_cipher_modes(), test_des(), test_key_derivation(), test_mac(), test_rc2(), test_rc4(), test_rsa_encrypt(), test_rsa_round_trip(), and test_schannel_provider().

◆ CryptEnumProvidersA()

BOOL WINAPI CryptEnumProvidersA ( DWORD  dwIndex,
DWORD pdwReserved,
DWORD  dwFlags,
DWORD pdwProvType,
LPSTR  pszProvName,
DWORD pcbProvName 
)

Definition at line 1228 of file crypt.c.

1230{
1231 PWSTR str = NULL;
1232 DWORD bufsize;
1233 BOOL ret;
1234
1235 TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
1237
1239 return FALSE;
1240 if ( pszProvName && !(str = CRYPT_Alloc(bufsize)) )
1241 {
1243 return FALSE;
1244 }
1246 if (str)
1248 *pcbProvName = bufsize / sizeof(WCHAR); /* FIXME: not correct */
1249 if (str)
1250 {
1251 CRYPT_Free(str);
1253 {
1255 return FALSE;
1256 }
1257 }
1258 return ret;
1259}
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
BOOL WINAPI CryptEnumProvidersW(DWORD dwIndex, DWORD *pdwReserved, DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszProvName, DWORD *pcbProvName)
Definition: crypt.c:1136
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
_Reserved_ DWORD _In_ DWORD _Out_ DWORD _Out_writes_bytes_to_opt_ pcbProvName LPSTR _Inout_ DWORD * pcbProvName
Definition: wincrypt.h:4258
_Reserved_ DWORD _In_ DWORD _Out_ DWORD * pdwProvType
Definition: wincrypt.h:4256
_Reserved_ DWORD _In_ DWORD _Out_writes_bytes_to_opt_ pcbProvName LPSTR pszProvName
Definition: wincrypt.h:4358

◆ CryptEnumProvidersW()

BOOL WINAPI CryptEnumProvidersW ( DWORD  dwIndex,
DWORD pdwReserved,
DWORD  dwFlags,
DWORD pdwProvType,
LPWSTR  pszProvName,
DWORD pcbProvName 
)

Definition at line 1136 of file crypt.c.

1138{
1139 HKEY hKey;
1140 static const WCHAR providerW[] = {
1141 'S','o','f','t','w','a','r','e','\\',
1142 'M','i','c','r','o','s','o','f','t','\\',
1143 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
1144 'D','e','f','a','u','l','t','s','\\',
1145 'P','r','o','v','i','d','e','r',0
1146 };
1147 static const WCHAR typeW[] = {'T','y','p','e',0};
1148 BOOL ret;
1149
1150 TRACE("(%d, %p, %d, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
1152
1153 if (pdwReserved || !pcbProvName)
1154 {
1156 return FALSE;
1157 }
1158 if (dwFlags)
1159 {
1161 return FALSE;
1162 }
1163
1164 if (RegOpenKeyW(HKEY_LOCAL_MACHINE, providerW, &hKey))
1165 {
1167 return FALSE;
1168 }
1169
1170 ret = TRUE;
1171 if (!pszProvName)
1172 {
1173 DWORD numkeys;
1174 WCHAR *provNameW;
1175
1177 NULL, NULL, NULL, NULL, NULL, NULL);
1178
1179 if (!(provNameW = CRYPT_Alloc(*pcbProvName * sizeof(WCHAR))))
1180 {
1183 return FALSE;
1184 }
1185
1186 RegEnumKeyExW(hKey, dwIndex, provNameW, pcbProvName, NULL, NULL, NULL, NULL);
1187 CRYPT_Free(provNameW);
1188 (*pcbProvName)++;
1189 *pcbProvName *= sizeof(WCHAR);
1190
1191 if (dwIndex >= numkeys)
1192 {
1194 ret = FALSE;
1195 }
1196 } else {
1197 DWORD size = sizeof(DWORD);
1198 DWORD result;
1199 HKEY subkey;
1200
1201 result = RegEnumKeyW(hKey, dwIndex, pszProvName, *pcbProvName / sizeof(WCHAR));
1202 if (result)
1203 {
1206 return FALSE;
1207 }
1208 if (RegOpenKeyW(hKey, pszProvName, &subkey))
1209 {
1211 return FALSE;
1212 }
1213
1214 if (RegQueryValueExW(subkey, typeW, NULL, NULL, (BYTE*)pdwProvType, &size))
1215 ret = FALSE;
1216
1217 RegCloseKey(subkey);
1218 }
1220 return ret;
1221}
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2504
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3662
LONG WINAPI RegEnumKeyW(HKEY hKey, DWORD dwIndex, LPWSTR lpName, DWORD cbName)
Definition: reg.c:2393
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
GLuint64EXT * result
Definition: glext.h:11304
#define NTE_FAIL
Definition: winerror.h:2900

Referenced by CryptEnumProvidersA(), find_matching_provider(), and I_CryptGetDefaultCryptProv().

◆ CryptEnumProviderTypesA()

BOOL WINAPI CryptEnumProviderTypesA ( DWORD  dwIndex,
DWORD pdwReserved,
DWORD  dwFlags,
DWORD pdwProvType,
LPSTR  pszTypeName,
DWORD pcbTypeName 
)

Definition at line 1362 of file crypt.c.

1364{
1365 PWSTR str = NULL;
1366 DWORD bufsize;
1367 BOOL ret;
1368
1369 TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
1370 pdwProvType, pszTypeName, pcbTypeName);
1371
1373 return FALSE;
1374 if ( pszTypeName && !(str = CRYPT_Alloc(bufsize)) )
1375 {
1377 return FALSE;
1378 }
1380 if (str)
1381 CRYPT_UnicodeToANSI(str, &pszTypeName, *pcbTypeName);
1382 *pcbTypeName = bufsize / sizeof(WCHAR);
1383 if (str)
1384 {
1385 CRYPT_Free(str);
1387 {
1389 return FALSE;
1390 }
1391 }
1392 return ret;
1393}
BOOL WINAPI CryptEnumProviderTypesW(DWORD dwIndex, DWORD *pdwReserved, DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszTypeName, DWORD *pcbTypeName)
Definition: crypt.c:1283
_Reserved_ DWORD _In_ DWORD _Out_ DWORD _Out_writes_bytes_to_opt_ pcbTypeName LPSTR _Inout_ DWORD * pcbTypeName
Definition: wincrypt.h:4284

◆ CryptEnumProviderTypesW()

BOOL WINAPI CryptEnumProviderTypesW ( DWORD  dwIndex,
DWORD pdwReserved,
DWORD  dwFlags,
DWORD pdwProvType,
LPWSTR  pszTypeName,
DWORD pcbTypeName 
)

Definition at line 1283 of file crypt.c.

1285{
1286 HKEY hKey, hSubkey;
1287 DWORD keylen, numkeys, dwType;
1288 PWSTR keyname, ch;
1289 DWORD result;
1290 static const WCHAR KEYSTR[] = {
1291 'S','o','f','t','w','a','r','e','\\',
1292 'M','i','c','r','o','s','o','f','t','\\',
1293 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
1294 'D','e','f','a','u','l','t','s','\\',
1295 'P','r','o','v','i','d','e','r',' ','T','y','p','e','s',0
1296 };
1297 static const WCHAR typenameW[] = {'T','y','p','e','N','a','m','e',0};
1298
1299 TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved,
1300 dwFlags, pdwProvType, pszTypeName, pcbTypeName);
1301
1303 {
1305 return FALSE;
1306 }
1307 if (dwFlags)
1308 {
1310 return FALSE;
1311 }
1312
1313 if (RegOpenKeyW(HKEY_LOCAL_MACHINE, KEYSTR, &hKey))
1314 return FALSE;
1315
1316 RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &numkeys, &keylen, NULL, NULL, NULL, NULL, NULL, NULL);
1317 if (dwIndex >= numkeys)
1318 {
1321 return FALSE;
1322 }
1323 keylen++;
1324 if ( !(keyname = CRYPT_Alloc(keylen*sizeof(WCHAR))) )
1325 {
1328 return FALSE;
1329 }
1330 if ( RegEnumKeyW(hKey, dwIndex, keyname, keylen) ) {
1331 CRYPT_Free(keyname);
1333 return FALSE;
1334 }
1335 RegOpenKeyW(hKey, keyname, &hSubkey);
1337
1338 ch = keyname + strlenW(keyname);
1339 /* Convert "Type 000" to 0, etc/ */
1340 *pdwProvType = *(--ch) - '0';
1341 *pdwProvType += (*(--ch) - '0') * 10;
1342 *pdwProvType += (*(--ch) - '0') * 100;
1343 CRYPT_Free(keyname);
1344
1345 result = RegQueryValueExW(hSubkey, typenameW, NULL, &dwType, (LPBYTE)pszTypeName, pcbTypeName);
1346 if (result)
1347 {
1349 RegCloseKey(hSubkey);
1350 return FALSE;
1351 }
1352
1353 RegCloseKey(hSubkey);
1354 return TRUE;
1355}

Referenced by CryptEnumProviderTypesA().

◆ CryptExportKey()

BOOL WINAPI CryptExportKey ( HCRYPTKEY  hKey,
HCRYPTKEY  hExpKey,
DWORD  dwBlobType,
DWORD  dwFlags,
BYTE pbData,
DWORD pdwDataLen 
)

Definition at line 1416 of file crypt.c.

1418{
1419 PCRYPTPROV prov;
1420 PCRYPTKEY key = (PCRYPTKEY)hKey, expkey = (PCRYPTKEY)hExpKey;
1421
1422 TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hExpKey, dwBlobType, dwFlags, pbData, pdwDataLen);
1423
1424 if (!key || !pdwDataLen || !key->pProvider ||
1425 key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
1426 {
1428 return FALSE;
1429 }
1430
1431 prov = key->pProvider;
1432 return prov->pFuncs->pCPExportKey(prov->hPrivate, key->hPrivate, expkey ? expkey->hPrivate : 0,
1433 dwBlobType, dwFlags, pbData, pdwDataLen);
1434}

Referenced by CRYPT_ExportKeyTrans(), CRYPT_ExportPublicKeyInfoEx(), rdssl_cert_to_rkey(), test_import_export(), test_import_private(), test_key_permissions(), test_rsa_encrypt(), test_rsa_round_trip(), and testAcquireCertPrivateKey().

◆ CryptGenKey()

BOOL WINAPI CryptGenKey ( HCRYPTPROV  hProv,
ALG_ID  Algid,
DWORD  dwFlags,
HCRYPTKEY phKey 
)

Definition at line 1451 of file crypt.c.

1452{
1453 PCRYPTPROV prov = (PCRYPTPROV)hProv;
1454 PCRYPTKEY key;
1455
1456 TRACE("(0x%lx, %d, %08x, %p)\n", hProv, Algid, dwFlags, phKey);
1457
1458 if (!phKey || !prov || prov->dwMagic != MAGIC_CRYPTPROV)
1459 {
1461 return FALSE;
1462 }
1463 if ( !(key = CRYPT_Alloc(sizeof(CRYPTKEY))) )
1464 {
1466 return FALSE;
1467 }
1468
1469 key->pProvider = prov;
1470 key->dwMagic = MAGIC_CRYPTKEY;
1471 if (prov->pFuncs->pCPGenKey(prov->hPrivate, Algid, dwFlags, &key->hPrivate))
1472 {
1473 *phKey = (HCRYPTKEY)key;
1474 return TRUE;
1475 }
1476
1477 /* CSP error! */
1478 key->dwMagic = 0;
1479 CRYPT_Free(key);
1480 return FALSE;
1481}

Referenced by CertCreateSelfSignCertificate(), CRYPT_CreateKeyProv(), CRYPT_GenKey(), init_aes_environment(), init_base_environment(), test_null_provider(), test_rsa_round_trip(), testCreateSelfSignCert(), testExportPublicKey(), and testSignCert().

◆ CryptGenRandom()

BOOL WINAPI CryptGenRandom ( HCRYPTPROV  hProv,
DWORD  dwLen,
BYTE pbBuffer 
)

Definition at line 700 of file crypt.c.

701{
703
704 TRACE("(0x%lx, %d, %p)\n", hProv, dwLen, pbBuffer);
705
706 if (!hProv)
707 {
709 return FALSE;
710 }
711
712 if (prov->dwMagic != MAGIC_CRYPTPROV)
713 {
715 return FALSE;
716 }
717
718 return prov->pFuncs->pCPGenRandom(prov->hPrivate, dwLen, pbBuffer);
719}

Referenced by CertCreateSelfSignCertificate(), fill_protect_data(), and test_gen_random().

◆ CryptGetDefaultProviderA()

BOOL WINAPI CryptGetDefaultProviderA ( DWORD  dwProvType,
DWORD pdwReserved,
DWORD  dwFlags,
LPSTR  pszProvName,
DWORD pcbProvName 
)

Definition at line 1560 of file crypt.c.

1562{
1563 PWSTR str = NULL;
1564 DWORD bufsize;
1565 BOOL ret;
1566
1567 TRACE("(%d, %p, %08x, %p, %p)\n", dwProvType, pdwReserved, dwFlags, pszProvName, pcbProvName);
1568
1570 if ( pszProvName && !(str = CRYPT_Alloc(bufsize)) )
1571 {
1573 return FALSE;
1574 }
1576 if (str)
1578 *pcbProvName = bufsize / sizeof(WCHAR);
1579 if (str)
1580 {
1581 CRYPT_Free(str);
1583 {
1585 return FALSE;
1586 }
1587 }
1588 return ret;
1589}
BOOL WINAPI CryptGetDefaultProviderW(DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags, LPWSTR pszProvName, DWORD *pcbProvName)
Definition: crypt.c:1503

◆ CryptGetDefaultProviderW()

BOOL WINAPI CryptGetDefaultProviderW ( DWORD  dwProvType,
DWORD pdwReserved,
DWORD  dwFlags,
LPWSTR  pszProvName,
DWORD pcbProvName 
)

Definition at line 1503 of file crypt.c.

1505{
1506 HKEY hKey;
1507 PWSTR keyname;
1508 DWORD result;
1509 static const WCHAR nameW[] = {'N','a','m','e',0};
1510
1511 if (pdwReserved || !pcbProvName)
1512 {
1514 return FALSE;
1515 }
1517 {
1519 return FALSE;
1520 }
1521 if (dwProvType > 999)
1522 {
1524 return FALSE;
1525 }
1526 if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, dwFlags & CRYPT_USER_DEFAULT)) )
1527 {
1529 return FALSE;
1530 }
1532 {
1533 CRYPT_Free(keyname);
1535 return FALSE;
1536 }
1537 CRYPT_Free(keyname);
1538
1541
1542 if (result)
1543 {
1544 if (result != ERROR_MORE_DATA)
1546 else
1548
1549 return FALSE;
1550 }
1551
1552 return TRUE;
1553}
#define CRYPT_MACHINE_DEFAULT
Definition: wincrypt.h:2076
#define CRYPT_USER_DEFAULT
Definition: wincrypt.h:2077

Referenced by CryptGetDefaultProviderA().

◆ CryptGetHashParam()

◆ CryptGetKeyParam()

BOOL WINAPI CryptGetKeyParam ( HCRYPTKEY  hKey,
DWORD  dwParam,
BYTE pbData,
DWORD pdwDataLen,
DWORD  dwFlags 
)

Definition at line 1649 of file crypt.c.

1651{
1652 PCRYPTPROV prov;
1654
1655 TRACE("(0x%lx, %d, %p, %p, %08x)\n", hKey, dwParam, pbData, pdwDataLen, dwFlags);
1656
1657 if (!key || !pdwDataLen || !key->pProvider ||
1658 key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
1659 {
1661 return FALSE;
1662 }
1663
1664 prov = key->pProvider;
1665 return prov->pFuncs->pCPGetKeyParam(prov->hPrivate, key->hPrivate, dwParam,
1667}

Referenced by CertGetPublicKeyLength(), export_is_key_exportable(), test_aes(), test_block_cipher_modes(), test_des(), test_import_export(), test_import_private(), test_key_derivation(), test_key_permissions(), test_rc2(), test_rc4(), test_rsa_encrypt(), and testImportPublicKey().

◆ CryptGetProvParam()

BOOL WINAPI CryptGetProvParam ( HCRYPTPROV  hProv,
DWORD  dwParam,
BYTE pbData,
DWORD pdwDataLen,
DWORD  dwFlags 
)

Definition at line 1688 of file crypt.c.

1690{
1691 PCRYPTPROV prov = (PCRYPTPROV)hProv;
1692
1693 TRACE("(0x%lx, %d, %p, %p, %08x)\n", hProv, dwParam, pbData, pdwDataLen, dwFlags);
1694
1695 if (!prov || prov->dwMagic != MAGIC_CRYPTPROV)
1696 {
1698 return FALSE;
1699 }
1700
1701 return prov->pFuncs->pCPGetProvParam(prov->hPrivate, dwParam, pbData, pdwDataLen, dwFlags);
1702}

Referenced by CertContext_SetKeyProvInfo(), find_key_prov_info_in_provider(), is_supported_algid(), test_container_sd(), test_enum_container(), test_getDefaultCryptProv(), test_null_provider(), and test_prov().

◆ CryptGetUserKey()

BOOL WINAPI CryptGetUserKey ( HCRYPTPROV  hProv,
DWORD  dwKeySpec,
HCRYPTKEY phUserKey 
)

Definition at line 1718 of file crypt.c.

1719{
1720 PCRYPTPROV prov = (PCRYPTPROV)hProv;
1721 PCRYPTKEY key;
1722
1723 TRACE("(0x%lx, %d, %p)\n", hProv, dwKeySpec, phUserKey);
1724
1725 if (!prov)
1726 {
1728 return FALSE;
1729 }
1730 if (!phUserKey || prov->dwMagic != MAGIC_CRYPTPROV)
1731 {
1733 return FALSE;
1734 }
1735 if ( !(key = CRYPT_Alloc(sizeof(CRYPTKEY))) )
1736 {
1738 return FALSE;
1739 }
1740
1741 key->pProvider = prov;
1742 key->dwMagic = MAGIC_CRYPTKEY;
1743 if (prov->pFuncs->pCPGetUserKey(prov->hPrivate, dwKeySpec, &key->hPrivate))
1744 {
1745 *phUserKey = (HCRYPTKEY)key;
1746 return TRUE;
1747 }
1748
1749 /* CSP Error */
1750 key->dwMagic = 0;
1751 CRYPT_Free(key);
1752 *phUserKey = 0;
1753 return FALSE;
1754}

Referenced by CertCreateSelfSignCertificate(), CRYPT_ExportPublicKeyInfoEx(), CRYPT_ImportKeyTrans(), export_is_key_exportable(), test_import_export(), test_key_initialization(), test_key_permissions(), test_null_provider(), test_rsa_encrypt(), and test_rsa_round_trip().

◆ CryptHashData()

◆ CryptHashSessionKey()

BOOL WINAPI CryptHashSessionKey ( HCRYPTHASH  hHash,
HCRYPTKEY  hKey,
DWORD  dwFlags 
)

Definition at line 1808 of file crypt.c.

1809{
1812 PCRYPTPROV prov;
1813
1814 TRACE("(0x%lx, 0x%lx, %08x)\n", hHash, hKey, dwFlags);
1815
1816 if (!hash || !key)
1817 {
1819 return FALSE;
1820 }
1821
1822 if (!hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
1823 hash->pProvider->dwMagic != MAGIC_CRYPTPROV || key->dwMagic != MAGIC_CRYPTKEY)
1824 {
1826 return FALSE;
1827 }
1828
1829 prov = hash->pProvider;
1830 return prov->pFuncs->pCPHashSessionKey(prov->hPrivate, hash->hPrivate, key->hPrivate, dwFlags);
1831}

◆ CryptImportKey()

BOOL WINAPI CryptImportKey ( HCRYPTPROV  hProv,
const BYTE pbData,
DWORD  dwDataLen,
HCRYPTKEY  hPubKey,
DWORD  dwFlags,
HCRYPTKEY phKey 
)

Definition at line 1850 of file crypt.c.

1852{
1853 PCRYPTPROV prov = (PCRYPTPROV)hProv;
1854 PCRYPTKEY pubkey = (PCRYPTKEY)hPubKey, importkey;
1855
1856 TRACE("(0x%lx, %p, %d, 0x%lx, %08x, %p)\n", hProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
1857
1858 if (!prov || !pbData || !dwDataLen || !phKey ||
1859 prov->dwMagic != MAGIC_CRYPTPROV ||
1860 (pubkey && pubkey->dwMagic != MAGIC_CRYPTKEY))
1861 {
1863 return FALSE;
1864 }
1865
1866 if ( !(importkey = CRYPT_Alloc(sizeof(CRYPTKEY))) )
1867 {
1869 return FALSE;
1870 }
1871
1872 importkey->pProvider = prov;
1873 importkey->dwMagic = MAGIC_CRYPTKEY;
1874 if (prov->pFuncs->pCPImportKey(prov->hPrivate, pbData, dwDataLen,
1875 pubkey ? pubkey->hPrivate : 0, dwFlags, &importkey->hPrivate))
1876 {
1877 *phKey = (HCRYPTKEY)importkey;
1878 return TRUE;
1879 }
1880
1881 importkey->dwMagic = 0;
1882 CRYPT_Free(importkey);
1883 return FALSE;
1884}
static const WCHAR pubkey[]
Definition: asmname.c:68

Referenced by CRYPT_ImportKeyTrans(), CRYPT_ImportPublicKeyInfoEx(), rdssl_hmac_md5(), rdssl_rc4_set_key(), test_decode_msg_get_param(), test_hashes(), test_import_export(), test_import_hmac(), test_import_private(), test_key_initialization(), test_null_provider(), test_rsa_round_trip(), test_schannel_provider(), test_sign_message(), test_signed_msg_encoding(), test_signed_msg_update(), test_verify_signature(), testAcquireCertPrivateKey(), and testAcquireSecurityContext().

◆ CryptReleaseContext()

BOOL WINAPI CryptReleaseContext ( HCRYPTPROV  hProv,
DWORD  dwFlags 
)

Definition at line 648 of file crypt.c.

649{
650 PCRYPTPROV pProv = (PCRYPTPROV)hProv;
651 BOOL ret = TRUE;
652
653 TRACE("(0x%lx, %08x)\n", hProv, dwFlags);
654
655 if (!pProv)
656 {
658 return FALSE;
659 }
660
661 if (pProv->dwMagic != MAGIC_CRYPTPROV)
662 {
664 return FALSE;
665 }
666
667 if (InterlockedDecrement(&pProv->refcount) == 0)
668 {
669 ret = pProv->pFuncs->pCPReleaseContext(pProv->hPrivate, dwFlags);
670 pProv->dwMagic = 0;
671 FreeLibrary(pProv->hModule);
672#if 0
673 CRYPT_Free(pProv->pVTable->pContextInfo);
674#endif
676 CRYPT_Free(pProv->pVTable);
677 CRYPT_Free(pProv->pFuncs);
678 CRYPT_Free(pProv);
679 }
680 return ret;
681}
#define InterlockedDecrement
Definition: armddk.h:52

Referenced by CDecodeMsg_Close(), CEnvelopedEncodeMsg_Close(), CEnvelopedEncodeMsg_Open(), CertContext_SetProperty(), CertCreateSelfSignCertificate(), CHashEncodeMsg_Close(), clean_up_aes_environment(), clean_up_base_environment(), create_silly_rename(), CRYPT_FileNameOpenStoreW(), CRYPT_FileOpenStore(), CRYPT_GetDefaultProvider(), CRYPT_MemOpenStore(), CRYPT_MsgOpenStore(), CRYPT_RegOpenStore(), CRYPT_SysOpenStoreW(), CryptCATAdminCalcHashFromFileHandle(), CryptCATAdminEnumCatalogFromHash(), CryptProtectData(), CryptSignMessage(), CryptUnprotectData(), CSignedEncodeMsg_Open(), detect_nt(), DllMain(), DllRegisterServer(), export_private_key_dlg_proc(), find_key_prov_info_in_provider(), hash_file(), I_CryptGetDefaultCryptProv(), key_prov_info_matches_cert(), nfs41_client_owner(), rdssl_cert_to_rkey(), rdssl_hash_info_create(), rdssl_hash_info_delete(), rdssl_hmac_md5(), rdssl_rc4_info_delete(), SOFTPUB_VerifyImageHash(), START_TEST(), test_container_sd(), test_decode_msg_get_param(), test_encrypt_message(), test_enveloped_msg_open(), test_getDefaultCryptProv(), test_hashes(), test_key_initialization(), test_null_provider(), test_rsa_round_trip(), test_schannel_provider(), test_sign_message(), test_signed_msg_encoding(), test_signed_msg_get_param(), test_signed_msg_open(), test_signed_msg_update(), test_sip(), testAcquireCertPrivateKey(), testAcquireSecurityContext(), testCertSigs(), testCreateSelfSignCert(), and testPortPublicKeyInfo().

◆ CryptSetHashParam()

BOOL WINAPI CryptSetHashParam ( HCRYPTHASH  hHash,
DWORD  dwParam,
const BYTE pbData,
DWORD  dwFlags 
)

Definition at line 1970 of file crypt.c.

1971{
1972 PCRYPTPROV prov;
1974
1975 TRACE("(0x%lx, %d, %p, %08x)\n", hHash, dwParam, pbData, dwFlags);
1976
1977 if (!hash || !pbData || !hash->pProvider ||
1978 hash->dwMagic != MAGIC_CRYPTHASH || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
1979 {
1981 return FALSE;
1982 }
1983
1984 prov = hash->pProvider;
1985 return prov->pFuncs->pCPSetHashParam(prov->hPrivate, hash->hPrivate,
1986 dwParam, pbData, dwFlags);
1987}

Referenced by rdssl_hmac_md5(), test_hashes(), test_hmac(), test_import_hmac(), and test_schannel_provider().

◆ CryptSetKeyParam()

BOOL WINAPI CryptSetKeyParam ( HCRYPTKEY  hKey,
DWORD  dwParam,
const BYTE pbData,
DWORD  dwFlags 
)

Definition at line 2004 of file crypt.c.

2005{
2006 PCRYPTPROV prov;
2008
2009 TRACE("(0x%lx, %d, %p, %08x)\n", hKey, dwParam, pbData, dwFlags);
2010
2011 if (!key || !pbData || !key->pProvider ||
2012 key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
2013 {
2015 return FALSE;
2016 }
2017
2018 prov = key->pProvider;
2019 return prov->pFuncs->pCPSetKeyParam(prov->hPrivate, key->hPrivate,
2020 dwParam, pbData, dwFlags);
2021}

Referenced by test_block_cipher_modes(), test_des(), test_key_permissions(), test_rc2(), test_rc4(), test_rsa_encrypt(), and test_schannel_provider().

◆ CryptSetProviderA()

BOOL WINAPI CryptSetProviderA ( LPCSTR  pszProvName,
DWORD  dwProvType 
)

Definition at line 2036 of file crypt.c.

2037{
2038 TRACE("(%s, %d)\n", pszProvName, dwProvType);
2040}
BOOL WINAPI CryptSetProviderExA(LPCSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
Definition: crypt.c:2149

◆ CryptSetProviderExA()

BOOL WINAPI CryptSetProviderExA ( LPCSTR  pszProvName,
DWORD  dwProvType,
DWORD pdwReserved,
DWORD  dwFlags 
)

Definition at line 2149 of file crypt.c.

2150{
2151 BOOL ret = FALSE;
2152 PWSTR str = NULL;
2153
2154 TRACE("(%s, %d, %p, %08x)\n", pszProvName, dwProvType, pdwReserved, dwFlags);
2155
2157 {
2159 CRYPT_Free(str);
2160 }
2161 return ret;
2162}
BOOL WINAPI CryptSetProviderExW(LPCWSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
Definition: crypt.c:2068

Referenced by CryptSetProviderA().

◆ CryptSetProviderExW()

BOOL WINAPI CryptSetProviderExW ( LPCWSTR  pszProvName,
DWORD  dwProvType,
DWORD pdwReserved,
DWORD  dwFlags 
)

Definition at line 2068 of file crypt.c.

2069{
2070 HKEY hProvKey, hTypeKey;
2071 PWSTR keyname;
2072 static const WCHAR nameW[] = {'N','a','m','e',0};
2073
2074 TRACE("(%s, %d, %p, %08x)\n", debugstr_w(pszProvName), dwProvType, pdwReserved, dwFlags);
2075
2076 if (!pszProvName || pdwReserved)
2077 {
2079 return FALSE;
2080 }
2081 if (dwProvType > MAXPROVTYPES)
2082 {
2084 return FALSE;
2085 }
2088 {
2090 return FALSE;
2091 }
2092
2093 if (!(keyname = CRYPT_GetTypeKeyName(dwProvType, dwFlags & CRYPT_USER_DEFAULT)))
2094 {
2096 return FALSE;
2097 }
2099 keyname, &hTypeKey))
2100 {
2101 CRYPT_Free(keyname);
2103 return FALSE;
2104 }
2105 CRYPT_Free(keyname);
2106
2108 {
2109 RegDeleteValueW(hTypeKey, nameW);
2110 }
2111 else
2112 {
2113 if (!(keyname = CRYPT_GetProvKeyName(pszProvName)))
2114 {
2115 RegCloseKey(hTypeKey);
2117 return FALSE;
2118 }
2120 keyname, &hProvKey))
2121 {
2122 CRYPT_Free(keyname);
2123 RegCloseKey(hTypeKey);
2125 return FALSE;
2126 }
2127 CRYPT_Free(keyname);
2128
2129 if (RegSetValueExW(hTypeKey, nameW, 0, REG_SZ, (const BYTE *)pszProvName,
2130 (strlenW(pszProvName) + 1)*sizeof(WCHAR)))
2131 {
2132 RegCloseKey(hTypeKey);
2133 RegCloseKey(hProvKey);
2134 return FALSE;
2135 }
2136
2137 RegCloseKey(hProvKey);
2138 }
2139 RegCloseKey(hTypeKey);
2140
2141 return TRUE;
2142}
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
#define CRYPT_DELETE_DEFAULT
Definition: wincrypt.h:2078
#define NTE_BAD_PROVIDER
Definition: winerror.h:2887

Referenced by CryptSetProviderExA(), and CryptSetProviderW().

◆ CryptSetProviderW()

BOOL WINAPI CryptSetProviderW ( LPCWSTR  pszProvName,
DWORD  dwProvType 
)

Definition at line 2047 of file crypt.c.

2048{
2049 TRACE("(%s, %d)\n", debugstr_w(pszProvName), dwProvType);
2051}

◆ CryptSetProvParam()

BOOL WINAPI CryptSetProvParam ( HCRYPTPROV  hProv,
DWORD  dwParam,
const BYTE pbData,
DWORD  dwFlags 
)

Definition at line 2179 of file crypt.c.

2180{
2181 PCRYPTPROV prov = (PCRYPTPROV)hProv;
2182
2183 TRACE("(0x%lx, %d, %p, %08x)\n", hProv, dwParam, pbData, dwFlags);
2184
2185 if (!prov)
2186 {
2188 return FALSE;
2189 }
2190 if (prov->dwMagic != MAGIC_CRYPTPROV)
2191 {
2193 return FALSE;
2194 }
2195 if (dwParam == PP_USE_HARDWARE_RNG)
2196 {
2197 FIXME("PP_USE_HARDWARE_RNG: What do I do with this?\n");
2198 FIXME("\tLetting the CSP decide.\n");
2199 }
2200 if (dwFlags & PP_CLIENT_HWND)
2201 {
2202 /* FIXME: Should verify the parameter */
2203 if (pbData /* && IsWindow((HWND)pbData) */)
2204 {
2206 return TRUE;
2207 } else {
2209 return FALSE;
2210 }
2211 }
2212 /* All other flags go to the CSP */
2213 return prov->pFuncs->pCPSetProvParam(prov->hPrivate, dwParam, pbData, dwFlags);
2214}
HANDLE HWND
Definition: compat.h:19
#define PP_CLIENT_HWND
Definition: wincrypt.h:2081
#define PP_USE_HARDWARE_RNG
Definition: wincrypt.h:2113

Referenced by CRYPT_AcquirePrivateKeyFromProvInfo(), and export_acquire_private_key().

◆ CryptSignHashA()

BOOL WINAPI CryptSignHashA ( HCRYPTHASH  hHash,
DWORD  dwKeySpec,
LPCSTR  sDescription,
DWORD  dwFlags,
BYTE pbSignature,
DWORD pdwSigLen 
)

Definition at line 1939 of file crypt.c.

1941{
1942 LPWSTR wsDescription;
1943 BOOL result;
1944
1945 TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
1946 hHash, dwKeySpec, debugstr_a(sDescription), dwFlags, pbSignature, pdwSigLen);
1947
1948 CRYPT_ANSIToUnicode(sDescription, &wsDescription, -1);
1949 result = CryptSignHashW(hHash, dwKeySpec, wsDescription, dwFlags, pbSignature, pdwSigLen);
1950 CRYPT_Free(wsDescription);
1951
1952 return result;
1953}
BOOL WINAPI CryptSignHashW(HCRYPTHASH hHash, DWORD dwKeySpec, LPCWSTR sDescription, DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
Definition: crypt.c:1908
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by test_hashes(), and verifySig().

◆ CryptSignHashW()

BOOL WINAPI CryptSignHashW ( HCRYPTHASH  hHash,
DWORD  dwKeySpec,
LPCWSTR  sDescription,
DWORD  dwFlags,
BYTE pbSignature,
DWORD pdwSigLen 
)

Definition at line 1908 of file crypt.c.

1910{
1912 PCRYPTPROV prov;
1913
1914 TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
1915 hHash, dwKeySpec, debugstr_w(sDescription), dwFlags, pbSignature, pdwSigLen);
1916
1917 if (!hash)
1918 {
1920 return FALSE;
1921 }
1922 if (!pdwSigLen || !hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
1923 hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
1924 {
1926 return FALSE;
1927 }
1928
1929 prov = hash->pProvider;
1930 return prov->pFuncs->pCPSignHash(prov->hPrivate, hash->hPrivate, dwKeySpec, sDescription,
1931 dwFlags, pbSignature, pdwSigLen);
1932}

Referenced by CryptSignCertificate(), CryptSignHashA(), and CSignedMsgData_Sign().

◆ CryptVerifySignatureA()

BOOL WINAPI CryptVerifySignatureA ( HCRYPTHASH  hHash,
const BYTE pbSignature,
DWORD  dwSigLen,
HCRYPTKEY  hPubKey,
LPCSTR  sDescription,
DWORD  dwFlags 
)

Definition at line 2266 of file crypt.c.

2268{
2269 LPWSTR wsDescription;
2270 BOOL result;
2271
2272 TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature,
2273 dwSigLen, hPubKey, debugstr_a(sDescription), dwFlags);
2274
2275 CRYPT_ANSIToUnicode(sDescription, &wsDescription, -1);
2276 result = CryptVerifySignatureW(hHash, pbSignature, dwSigLen, hPubKey, wsDescription, dwFlags);
2277 CRYPT_Free(wsDescription);
2278
2279 return result;
2280}
BOOL WINAPI CryptVerifySignatureW(HCRYPTHASH hHash, const BYTE *pbSignature, DWORD dwSigLen, HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags)
Definition: crypt.c:2238

Referenced by test_verify_signature().

◆ CryptVerifySignatureW()

BOOL WINAPI CryptVerifySignatureW ( HCRYPTHASH  hHash,
const BYTE pbSignature,
DWORD  dwSigLen,
HCRYPTKEY  hPubKey,
LPCWSTR  sDescription,
DWORD  dwFlags 
)

Definition at line 2238 of file crypt.c.

2240{
2242 PCRYPTKEY key = (PCRYPTKEY)hPubKey;
2243 PCRYPTPROV prov;
2244
2245 TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature,
2246 dwSigLen, hPubKey, debugstr_w(sDescription), dwFlags);
2247
2248 if (!hash || !key || key->dwMagic != MAGIC_CRYPTKEY || hash->dwMagic != MAGIC_CRYPTHASH ||
2249 !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV ||
2250 !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
2251 {
2253 return FALSE;
2254 }
2255
2256 prov = hash->pProvider;
2257 return prov->pFuncs->pCPVerifySignature(prov->hPrivate, hash->hPrivate, pbSignature, dwSigLen,
2258 key->hPrivate, sDescription, dwFlags);
2259}

Referenced by CDecodeSignedMsg_VerifySignatureWithKey(), CRYPT_VerifySignature(), and CryptVerifySignatureA().

◆ OpenEncryptedFileRawA()

DWORD WINAPI OpenEncryptedFileRawA ( LPCSTR  filename,
ULONG  flags,
PVOID context 
)

Definition at line 2287 of file crypt.c.

2288{
2289 FIXME("(%s, %x, %p): stub\n", debugstr_a(filename), flags, context);
2291}
GLbitfield flags
Definition: glext.h:7161
const char * filename
Definition: ioapi.h:137

◆ OpenEncryptedFileRawW()

DWORD WINAPI OpenEncryptedFileRawW ( LPCWSTR  filename,
ULONG  flags,
PVOID context 
)

Definition at line 2306 of file crypt.c.

2307{
2308 FIXME("(%s, %x, %p): stub\n", debugstr_w(filename), flags, context);
2310}

◆ ReadEncryptedFileRaw()

DWORD WINAPI ReadEncryptedFileRaw ( PFE_EXPORT_FUNC  export,
PVOID  callback,
PVOID  context 
)

Definition at line 2325 of file crypt.c.

2326{
2327 FIXME("(%p, %p, %p): stub\n", export, callback, context);
2329}
static IPrintDialogCallback callback
Definition: printdlg.c:326

◆ SystemFunction030()

BOOL WINAPI SystemFunction030 ( LPCVOID  b1,
LPCVOID  b2 
)

Definition at line 2344 of file crypt.c.

2345{
2346 return !memcmp(b1, b2, 0x10);
2347}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static CRYPT_DATA_BLOB b2[]
Definition: msg.c:582
static CRYPT_DATA_BLOB b1[]
Definition: msg.c:573

◆ SystemFunction035()

BOOL WINAPI SystemFunction035 ( LPCSTR  lpszDllFilePath)

Definition at line 2358 of file crypt.c.

2359{
2360 FIXME("%s: stub\n", debugstr_a(lpszDllFilePath));
2361 return TRUE;
2362}

◆ SystemFunction036()

BOOLEAN WINAPI SystemFunction036 ( PVOID  pbBuffer,
ULONG  dwLen 
)

Definition at line 2378 of file crypt.c.

2379{
2380 int dev_random;
2381
2382 dev_random = open("/dev/urandom", O_RDONLY);
2383 if (dev_random != -1)
2384 {
2385 if (!IsBadWritePtr( pbBuffer, dwLen ) &&
2386 read(dev_random, pbBuffer, dwLen) == (ssize_t)dwLen)
2387 {
2388 close(dev_random);
2389 return TRUE;
2390 }
2391 close(dev_random);
2392 }
2393 else
2394 FIXME("couldn't open /dev/urandom\n");
2396 return FALSE;
2397}
#define read
Definition: acwin.h:96
#define O_RDONLY
Definition: acwin.h:108
#define open
Definition: acwin.h:95
#define close
Definition: acwin.h:98
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:883
int ssize_t
Definition: rosdhcp.h:48

Referenced by gen_rand_impl().

◆ SystemFunction040()

NTSTATUS WINAPI SystemFunction040 ( PVOID  memory,
ULONG  length,
ULONG  flags 
)

Definition at line 2426 of file crypt.c.

2427{
2428 FIXME("(%p, %x, %x): stub [RtlEncryptMemory]\n", memory, length, flags);
2429 return STATUS_SUCCESS;
2430}
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
static char memory[1024 *256]
Definition: process.c:116
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ SystemFunction041()

NTSTATUS WINAPI SystemFunction041 ( PVOID  memory,
ULONG  length,
ULONG  flags 
)

Definition at line 2454 of file crypt.c.

2455{
2456 FIXME("(%p, %x, %x): stub [RtlDecryptMemory]\n", memory, length, flags);
2457 return STATUS_SUCCESS;
2458}

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( crypt  )

◆ WriteEncryptedFileRaw()

DWORD WINAPI WriteEncryptedFileRaw ( PFE_IMPORT_FUNC  import,
PVOID  callback,
PVOID  context 
)

Definition at line 2474 of file crypt.c.

2475{
2476 FIXME("(%p, %p, %p): stub\n", import, callback, context);
2478}

Variable Documentation

◆ crypt_hWindow

HWND crypt_hWindow
static

Definition at line 59 of file crypt.c.

Referenced by CRYPT_ReturnhWnd(), and CryptSetProvParam().