1999-02-13 10:08:33 +01:00
|
|
|
/*
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright 1999 Ian Schmidt
|
|
|
|
* Copyright 2001 Travis Michielsen
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-02-13 10:08:33 +01:00
|
|
|
*/
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2002-04-29 20:48:56 +02:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* - Reference counting
|
|
|
|
* - Thread-safing
|
|
|
|
*/
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2005-06-17 22:56:02 +02:00
|
|
|
#include "config.h"
|
2005-08-03 23:25:10 +02:00
|
|
|
#include "wine/port.h"
|
2005-06-17 22:56:02 +02:00
|
|
|
|
2000-10-24 03:39:29 +02:00
|
|
|
#include <time.h>
|
|
|
|
#include <stdlib.h>
|
2002-01-10 20:29:40 +01:00
|
|
|
#include <stdio.h>
|
2005-05-23 14:08:00 +02:00
|
|
|
#include <sys/types.h>
|
2005-06-17 22:56:02 +02:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
2005-05-23 14:08:00 +02:00
|
|
|
#include <fcntl.h>
|
2005-06-17 22:56:02 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2000-10-24 03:39:29 +02:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2002-01-10 20:29:40 +01:00
|
|
|
#include "crypt.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "winreg.h"
|
2008-03-25 18:39:22 +01:00
|
|
|
#include "rpc.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2005-09-28 13:59:04 +02:00
|
|
|
#include "wine/unicode.h"
|
2004-04-17 02:23:50 +02:00
|
|
|
#include "winternl.h"
|
1999-02-13 10:08:33 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2006-06-12 13:41:15 +02:00
|
|
|
static HWND crypt_hWindow;
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2007-12-01 17:14:25 +01:00
|
|
|
#define CRYPT_Alloc(size) (LocalAlloc(LMEM_ZEROINIT, size))
|
2009-02-16 09:53:37 +01:00
|
|
|
#define CRYPT_Free(buffer) (LocalFree(buffer))
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
static inline PWSTR CRYPT_GetProvKeyName(PCWSTR pProvName)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
2005-09-28 13:59:04 +02:00
|
|
|
static const WCHAR KEYSTR[] = {
|
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
|
|
|
'D','e','f','a','u','l','t','s','\\',
|
|
|
|
'P','r','o','v','i','d','e','r','\\',0
|
|
|
|
};
|
|
|
|
PWSTR keyname;
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
keyname = CRYPT_Alloc((strlenW(KEYSTR) + strlenW(pProvName) +1)*sizeof(WCHAR));
|
2002-01-10 20:29:40 +01:00
|
|
|
if (keyname)
|
|
|
|
{
|
2005-09-28 13:59:04 +02:00
|
|
|
strcpyW(keyname, KEYSTR);
|
|
|
|
strcpyW(keyname + strlenW(KEYSTR), pProvName);
|
2002-01-10 20:29:40 +01:00
|
|
|
} else
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return keyname;
|
|
|
|
}
|
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
static inline PWSTR CRYPT_GetTypeKeyName(DWORD dwType, BOOL user)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
2005-09-28 13:59:04 +02:00
|
|
|
static const WCHAR MACHINESTR[] = {
|
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
|
|
|
'D','e','f','a','u','l','t','s','\\',
|
|
|
|
'P','r','o','v','i','d','e','r',' ','T','y','p','e','s','\\',
|
|
|
|
'T','y','p','e',' ','X','X','X',0
|
|
|
|
};
|
|
|
|
static const WCHAR USERSTR[] = {
|
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
|
|
|
'P','r','o','v','i','d','e','r',' ','T','y','p','e',' ','X','X','X',0
|
|
|
|
};
|
|
|
|
PWSTR keyname;
|
|
|
|
PWSTR ptr;
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
keyname = CRYPT_Alloc( ((user ? strlenW(USERSTR) : strlenW(MACHINESTR)) +1)*sizeof(WCHAR));
|
2002-01-10 20:29:40 +01:00
|
|
|
if (keyname)
|
|
|
|
{
|
2005-09-28 13:59:04 +02:00
|
|
|
user ? strcpyW(keyname, USERSTR) : strcpyW(keyname, MACHINESTR);
|
|
|
|
ptr = keyname + strlenW(keyname);
|
2002-01-10 20:29:40 +01:00
|
|
|
*(--ptr) = (dwType % 10) + '0';
|
2004-07-22 21:43:03 +02:00
|
|
|
*(--ptr) = ((dwType / 10) % 10) + '0';
|
2002-01-10 20:29:40 +01:00
|
|
|
*(--ptr) = (dwType / 100) + '0';
|
|
|
|
} else
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return keyname;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CRYPT_UnicodeTOANSI
|
|
|
|
* wstr - unicode string
|
|
|
|
* str - pointer to ANSI string
|
|
|
|
* strsize - size of buffer pointed to by str or -1 if we have to do the allocation
|
|
|
|
*
|
2006-09-07 20:01:50 +02:00
|
|
|
* returns TRUE if unsuccessful, FALSE otherwise.
|
2002-01-10 20:29:40 +01:00
|
|
|
* if wstr is NULL, returns TRUE and sets str to NULL! Value of str should be checked after call
|
|
|
|
*/
|
|
|
|
static inline BOOL CRYPT_UnicodeToANSI(LPCWSTR wstr, LPSTR* str, int strsize)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (!wstr)
|
|
|
|
{
|
|
|
|
*str = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
count = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
|
|
|
|
if (strsize == -1)
|
|
|
|
*str = CRYPT_Alloc(count * sizeof(CHAR));
|
2004-12-20 19:52:41 +01:00
|
|
|
else
|
|
|
|
count = min( count, strsize );
|
2002-01-10 20:29:40 +01:00
|
|
|
if (*str)
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, wstr, -1, *str, count, NULL, NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CRYPT_ANSITOUnicode
|
|
|
|
* str - ANSI string
|
|
|
|
* wstr - pointer to unicode string
|
|
|
|
* wstrsize - size of buffer pointed to by wstr or -1 if we have to do the allocation
|
|
|
|
*/
|
|
|
|
static inline BOOL CRYPT_ANSIToUnicode(LPCSTR str, LPWSTR* wstr, int wstrsize)
|
|
|
|
{
|
2007-09-21 22:17:23 +02:00
|
|
|
unsigned int wcount;
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (!str)
|
|
|
|
{
|
|
|
|
*wstr = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
wcount = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
|
|
|
|
if (wstrsize == -1)
|
|
|
|
*wstr = CRYPT_Alloc(wcount * sizeof(WCHAR));
|
2004-12-20 19:52:41 +01:00
|
|
|
else
|
|
|
|
wcount = min( wcount, wstrsize/sizeof(WCHAR) );
|
2002-01-10 20:29:40 +01:00
|
|
|
if (*wstr)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str, -1, *wstr, wcount);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-04-29 20:48:56 +02:00
|
|
|
/* These next 2 functions are used by the VTableProvStruc structure */
|
2003-07-22 01:50:39 +02:00
|
|
|
static BOOL CALLBACK CRYPT_VerifyImage(LPCSTR lpszImage, BYTE* pData)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
|
|
|
if (!lpszImage || !pData)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-10-22 05:04:30 +02:00
|
|
|
|
2004-01-06 21:40:31 +01:00
|
|
|
FIXME("(%s, %p): not verifying image\n", lpszImage, pData);
|
2003-10-22 05:04:30 +02:00
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:31:12 +02:00
|
|
|
static void CALLBACK CRYPT_ReturnhWnd(HWND *phWnd)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
2009-10-07 13:31:12 +02:00
|
|
|
if (phWnd) *phWnd = crypt_hWindow;
|
2002-01-10 20:29:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#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)
|
2007-03-03 23:36:05 +01:00
|
|
|
static PCRYPTPROV CRYPT_LoadProvider(PCWSTR pImage)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
|
|
|
PCRYPTPROV provider;
|
|
|
|
DWORD errorcode = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
|
|
|
if ( !(provider = CRYPT_Alloc(sizeof(CRYPTPROV))) ) goto error;
|
|
|
|
if ( !(provider->pFuncs = CRYPT_Alloc(sizeof(PROVFUNCS))) ) goto error;
|
|
|
|
if ( !(provider->pVTable = CRYPT_Alloc(sizeof(VTableProvStruc))) ) goto error;
|
2005-09-28 13:59:04 +02:00
|
|
|
if ( !(provider->hModule = LoadLibraryW(pImage)) )
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
|
|
|
errorcode = (GetLastError() == ERROR_FILE_NOT_FOUND) ? NTE_PROV_DLL_NOT_FOUND : NTE_PROVIDER_DLL_FAIL;
|
2005-09-28 13:59:04 +02:00
|
|
|
FIXME("Failed to load dll %s\n", debugstr_w(pImage));
|
2002-01-10 20:29:40 +01:00
|
|
|
goto error;
|
|
|
|
}
|
2005-04-11 14:55:36 +02:00
|
|
|
provider->dwMagic = MAGIC_CRYPTPROV;
|
2004-07-14 01:34:13 +02:00
|
|
|
provider->refcount = 1;
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
errorcode = NTE_PROVIDER_DLL_FAIL;
|
|
|
|
CRYPT_GetProvFunc(CPAcquireContext);
|
|
|
|
CRYPT_GetProvFunc(CPCreateHash);
|
|
|
|
CRYPT_GetProvFunc(CPDecrypt);
|
|
|
|
CRYPT_GetProvFunc(CPDeriveKey);
|
|
|
|
CRYPT_GetProvFunc(CPDestroyHash);
|
|
|
|
CRYPT_GetProvFunc(CPDestroyKey);
|
|
|
|
CRYPT_GetProvFuncOpt(CPDuplicateHash);
|
|
|
|
CRYPT_GetProvFuncOpt(CPDuplicateKey);
|
|
|
|
CRYPT_GetProvFunc(CPEncrypt);
|
|
|
|
CRYPT_GetProvFunc(CPExportKey);
|
|
|
|
CRYPT_GetProvFunc(CPGenKey);
|
|
|
|
CRYPT_GetProvFunc(CPGenRandom);
|
|
|
|
CRYPT_GetProvFunc(CPGetHashParam);
|
|
|
|
CRYPT_GetProvFunc(CPGetKeyParam);
|
|
|
|
CRYPT_GetProvFunc(CPGetProvParam);
|
|
|
|
CRYPT_GetProvFunc(CPGetUserKey);
|
|
|
|
CRYPT_GetProvFunc(CPHashData);
|
|
|
|
CRYPT_GetProvFunc(CPHashSessionKey);
|
|
|
|
CRYPT_GetProvFunc(CPImportKey);
|
|
|
|
CRYPT_GetProvFunc(CPReleaseContext);
|
|
|
|
CRYPT_GetProvFunc(CPSetHashParam);
|
|
|
|
CRYPT_GetProvFunc(CPSetKeyParam);
|
|
|
|
CRYPT_GetProvFunc(CPSetProvParam);
|
|
|
|
CRYPT_GetProvFunc(CPSignHash);
|
|
|
|
CRYPT_GetProvFunc(CPVerifySignature);
|
|
|
|
|
2002-04-29 20:48:56 +02:00
|
|
|
/* FIXME: Not sure what the pbContextInfo field is for.
|
|
|
|
* Does it need memory allocation?
|
|
|
|
*/
|
2002-01-10 20:29:40 +01:00
|
|
|
provider->pVTable->Version = 3;
|
2009-10-07 13:31:12 +02:00
|
|
|
provider->pVTable->FuncVerifyImage = CRYPT_VerifyImage;
|
|
|
|
provider->pVTable->FuncReturnhWnd = CRYPT_ReturnhWnd;
|
2002-01-10 20:29:40 +01:00
|
|
|
provider->pVTable->dwProvType = 0;
|
|
|
|
provider->pVTable->pbContextInfo = NULL;
|
|
|
|
provider->pVTable->cbContextInfo = 0;
|
|
|
|
provider->pVTable->pszProvName = NULL;
|
|
|
|
return provider;
|
|
|
|
|
|
|
|
error:
|
|
|
|
SetLastError(errorcode);
|
|
|
|
if (provider)
|
|
|
|
{
|
2005-04-11 14:55:36 +02:00
|
|
|
provider->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
if (provider->hModule)
|
|
|
|
FreeLibrary(provider->hModule);
|
|
|
|
CRYPT_Free(provider->pVTable);
|
|
|
|
CRYPT_Free(provider->pFuncs);
|
|
|
|
CRYPT_Free(provider);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#undef CRYPT_GetProvFunc
|
|
|
|
#undef CRYPT_GetProvFuncOpt
|
|
|
|
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2008-03-25 18:39:22 +01:00
|
|
|
static void CRYPT_CreateMachineGuid(void)
|
|
|
|
{
|
|
|
|
static const WCHAR cryptographyW[] = {
|
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'C','r','y','p','t','o','g','r','a','p','h','y',0 };
|
|
|
|
static const WCHAR machineGuidW[] = {
|
|
|
|
'M','a','c','h','i','n','e','G','u','i','d',0 };
|
|
|
|
LONG r;
|
|
|
|
HKEY key;
|
|
|
|
|
|
|
|
r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, cryptographyW, 0, KEY_ALL_ACCESS,
|
|
|
|
&key);
|
|
|
|
if (!r)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
r = RegQueryValueExW(key, machineGuidW, NULL, NULL, NULL, &size);
|
|
|
|
if (r == ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
2010-06-21 16:56:12 +02:00
|
|
|
UUID uuid;
|
|
|
|
WCHAR buf[37];
|
|
|
|
RPC_STATUS rs;
|
|
|
|
static const WCHAR uuidFmt[] = {
|
|
|
|
'%','0','8','x','-','%','0','4','x','-',
|
|
|
|
'%','0','4','x','-','%','0','2','x',
|
|
|
|
'%','0','2','x','-','%','0','2','x',
|
|
|
|
'%','0','2','x','%','0','2','x',
|
|
|
|
'%','0','2','x','%','0','2','x',
|
|
|
|
'%','0','2','x',0 };
|
2008-03-25 18:39:22 +01:00
|
|
|
|
2010-06-21 16:56:12 +02:00
|
|
|
rs = UuidCreate(&uuid);
|
|
|
|
if (rs == S_OK)
|
|
|
|
{
|
|
|
|
sprintfW(buf, uuidFmt,
|
|
|
|
uuid.Data1, uuid.Data2, uuid.Data3,
|
|
|
|
uuid.Data4[0], uuid.Data4[1],
|
|
|
|
uuid.Data4[2], uuid.Data4[3],
|
|
|
|
uuid.Data4[4], uuid.Data4[5],
|
|
|
|
uuid.Data4[6], uuid.Data4[7] );
|
|
|
|
RegSetValueExW(key, machineGuidW, 0, REG_SZ,
|
|
|
|
(const BYTE *)buf,
|
|
|
|
(lstrlenW(buf)+1)*sizeof(WCHAR));
|
|
|
|
}
|
2008-03-25 18:39:22 +01:00
|
|
|
}
|
|
|
|
RegCloseKey(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-13 10:08:33 +01:00
|
|
|
/******************************************************************************
|
2005-09-28 13:59:04 +02:00
|
|
|
* CryptAcquireContextW (ADVAPI32.@)
|
2005-11-04 12:43:27 +01:00
|
|
|
*
|
1999-02-13 10:08:33 +01:00
|
|
|
* Acquire a crypto provider context handle.
|
2001-09-12 19:09:56 +02:00
|
|
|
*
|
1999-02-13 10:08:33 +01:00
|
|
|
* PARAMS
|
2005-11-04 12:43:27 +01:00
|
|
|
* phProv [O] Pointer to HCRYPTPROV for the output.
|
|
|
|
* pszContainer [I] Key Container Name
|
|
|
|
* pszProvider [I] Cryptographic Service Provider Name
|
|
|
|
* dwProvType [I] Crypto provider type to get a handle.
|
|
|
|
* dwFlags [I] flags for the operation
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success, FALSE on failure.
|
1999-02-13 10:08:33 +01:00
|
|
|
*/
|
2005-09-28 13:59:04 +02:00
|
|
|
BOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR pszContainer,
|
|
|
|
LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV pProv = NULL;
|
|
|
|
HKEY key;
|
2005-09-28 13:59:04 +02:00
|
|
|
PWSTR imagepath = NULL, keyname = NULL, provname = NULL, temp = NULL;
|
|
|
|
PSTR provnameA = NULL, pszContainerA = NULL;
|
2002-04-29 20:48:56 +02:00
|
|
|
DWORD keytype, type, len;
|
2003-11-18 21:40:12 +01:00
|
|
|
ULONG r;
|
2005-09-28 13:59:04 +02:00
|
|
|
static const WCHAR nameW[] = {'N','a','m','e',0};
|
|
|
|
static const WCHAR typeW[] = {'T','y','p','e',0};
|
|
|
|
static const WCHAR imagepathW[] = {'I','m','a','g','e',' ','P','a','t','h',0};
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%p, %s, %s, %d, %08x)\n", phProv, debugstr_w(pszContainer),
|
2005-09-28 13:59:04 +02:00
|
|
|
debugstr_w(pszProvider), dwProvType, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2004-07-22 21:43:03 +02:00
|
|
|
if (dwProvType < 1 || dwProvType > MAXPROVTYPES)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
2004-07-22 21:43:03 +02:00
|
|
|
SetLastError(NTE_BAD_PROV_TYPE);
|
2002-01-10 20:29:40 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-07-22 21:43:03 +02:00
|
|
|
|
|
|
|
if (!phProv)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
2004-07-22 21:43:03 +02:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2002-01-10 20:29:40 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-25 18:39:22 +01:00
|
|
|
/* Make sure the MachineGuid value exists */
|
|
|
|
CRYPT_CreateMachineGuid();
|
|
|
|
|
2004-07-24 04:27:15 +02:00
|
|
|
if (!pszProvider || !*pszProvider)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
2002-04-29 20:48:56 +02:00
|
|
|
/* No CSP name specified so try the user default CSP first
|
|
|
|
* then try the machine default CSP
|
|
|
|
*/
|
2003-09-22 21:37:55 +02:00
|
|
|
if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, TRUE)) ) {
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("No provider registered for crypto provider type %d.\n", dwProvType);
|
2003-10-22 05:04:30 +02:00
|
|
|
SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
|
|
|
return FALSE;
|
2003-09-22 21:37:55 +02:00
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
if (RegOpenKeyW(HKEY_CURRENT_USER, keyname, &key))
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
|
|
|
CRYPT_Free(keyname);
|
2003-09-22 21:37:55 +02:00
|
|
|
if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, FALSE)) ) {
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("No type registered for crypto provider type %d.\n", dwProvType);
|
2003-10-22 05:04:30 +02:00
|
|
|
RegCloseKey(key);
|
|
|
|
SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
|
|
|
goto error;
|
2003-09-22 21:37:55 +02:00
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
if (RegOpenKeyW(HKEY_LOCAL_MACHINE, keyname, &key)) {
|
|
|
|
TRACE("Did not find registry entry of crypto provider for %s.\n", debugstr_w(keyname));
|
2004-07-16 21:19:00 +02:00
|
|
|
CRYPT_Free(keyname);
|
2003-10-22 05:04:30 +02:00
|
|
|
RegCloseKey(key);
|
|
|
|
SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
2003-09-22 21:37:55 +02:00
|
|
|
goto error;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
}
|
|
|
|
CRYPT_Free(keyname);
|
2005-09-28 13:59:04 +02:00
|
|
|
r = RegQueryValueExW(key, nameW, NULL, &keytype, NULL, &len);
|
2003-11-18 21:40:12 +01:00
|
|
|
if( r != ERROR_SUCCESS || !len || keytype != REG_SZ)
|
2003-10-22 05:04:30 +02:00
|
|
|
{
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("error %d reading size of 'Name' from registry\n", r );
|
2003-10-22 05:04:30 +02:00
|
|
|
RegCloseKey(key);
|
|
|
|
SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if(!(provname = CRYPT_Alloc(len)))
|
|
|
|
{
|
|
|
|
RegCloseKey(key);
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
goto error;
|
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
r = RegQueryValueExW(key, nameW, NULL, NULL, (LPBYTE)provname, &len);
|
2003-11-18 21:40:12 +01:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("error %d reading 'Name' from registry\n", r );
|
2003-11-18 21:40:12 +01:00
|
|
|
RegCloseKey(key);
|
|
|
|
SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
|
|
|
goto error;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
RegCloseKey(key);
|
|
|
|
} else {
|
2005-09-28 13:59:04 +02:00
|
|
|
if ( !(provname = CRYPT_Alloc((strlenW(pszProvider) +1)*sizeof(WCHAR))) )
|
2003-10-22 05:04:30 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2003-10-22 05:04:30 +02:00
|
|
|
goto error;
|
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
strcpyW(provname, pszProvider);
|
2002-01-10 20:29:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
keyname = CRYPT_GetProvKeyName(provname);
|
2005-09-28 13:59:04 +02:00
|
|
|
r = RegOpenKeyW(HKEY_LOCAL_MACHINE, keyname, &key);
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(keyname);
|
2004-07-24 04:27:15 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError(NTE_KEYSET_NOT_DEF);
|
|
|
|
goto error;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
len = sizeof(DWORD);
|
2005-09-28 13:59:04 +02:00
|
|
|
r = RegQueryValueExW(key, typeW, NULL, NULL, (BYTE*)&type, &len);
|
2004-07-24 04:27:15 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
2004-07-24 04:27:15 +02:00
|
|
|
SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (type != dwProvType)
|
|
|
|
{
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("Crypto provider has wrong type (%d vs expected %d).\n", type, dwProvType);
|
2004-07-24 04:27:15 +02:00
|
|
|
SetLastError(NTE_PROV_TYPE_NO_MATCH);
|
2002-01-10 20:29:40 +01:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
r = RegQueryValueExW(key, imagepathW, NULL, &keytype, NULL, &len);
|
2003-11-18 21:40:12 +01:00
|
|
|
if ( r != ERROR_SUCCESS || keytype != REG_SZ)
|
2003-10-22 05:04:30 +02:00
|
|
|
{
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("error %d reading size of 'Image Path' from registry\n", r );
|
2003-10-22 05:04:30 +02:00
|
|
|
RegCloseKey(key);
|
|
|
|
SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!(temp = CRYPT_Alloc(len)))
|
|
|
|
{
|
|
|
|
RegCloseKey(key);
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
goto error;
|
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
r = RegQueryValueExW(key, imagepathW, NULL, NULL, (LPBYTE)temp, &len);
|
2003-11-18 21:40:12 +01:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("error %d reading 'Image Path' from registry\n", r );
|
2003-11-18 21:40:12 +01:00
|
|
|
RegCloseKey(key);
|
|
|
|
SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
|
|
|
goto error;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
RegCloseKey(key);
|
2005-09-28 13:59:04 +02:00
|
|
|
len = ExpandEnvironmentStringsW(temp, NULL, 0);
|
|
|
|
if ( !(imagepath = CRYPT_Alloc(len*sizeof(WCHAR))) )
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
goto error;
|
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
if (!ExpandEnvironmentStringsW(temp, imagepath, len))
|
2003-10-22 05:04:30 +02:00
|
|
|
{
|
|
|
|
/* ExpandEnvironmentStrings will call SetLastError */
|
|
|
|
goto error;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
pProv = CRYPT_LoadProvider(imagepath);
|
2003-09-22 21:37:55 +02:00
|
|
|
if (!pProv) {
|
2003-10-22 05:04:30 +02:00
|
|
|
/* CRYPT_LoadProvider calls SetLastError */
|
2003-09-22 21:37:55 +02:00
|
|
|
goto error;
|
|
|
|
}
|
2004-05-13 01:29:44 +02:00
|
|
|
pProv->pVTable->dwProvType = dwProvType;
|
2005-09-28 13:59:04 +02:00
|
|
|
if(!CRYPT_UnicodeToANSI(provname, &provnameA, -1))
|
|
|
|
{
|
|
|
|
/* CRYPT_UnicodeToANSI calls SetLastError */
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
pProv->pVTable->pszProvName = provnameA;
|
|
|
|
if(!CRYPT_UnicodeToANSI(pszContainer, &pszContainerA, -1))
|
|
|
|
{
|
|
|
|
/* CRYPT_UnicodeToANSI calls SetLastError */
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (pProv->pFuncs->pCPAcquireContext(&pProv->hPrivate, pszContainerA, dwFlags, pProv->pVTable))
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
2002-04-29 20:48:56 +02:00
|
|
|
/* MSDN: When this flag is set, the value returned in phProv is undefined,
|
|
|
|
* and thus, the CryptReleaseContext function need not be called afterwards.
|
|
|
|
* Therefore, we must clean up everything now.
|
2005-04-11 14:55:36 +02:00
|
|
|
*/
|
2002-01-10 20:29:40 +01:00
|
|
|
if (dwFlags & CRYPT_DELETEKEYSET)
|
|
|
|
{
|
2005-04-11 14:55:36 +02:00
|
|
|
pProv->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
FreeLibrary(pProv->hModule);
|
2005-09-28 13:59:04 +02:00
|
|
|
CRYPT_Free(provnameA);
|
|
|
|
CRYPT_Free(pProv->pVTable);
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(pProv->pFuncs);
|
|
|
|
CRYPT_Free(pProv);
|
|
|
|
} else {
|
|
|
|
*phProv = (HCRYPTPROV)pProv;
|
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
CRYPT_Free(pszContainerA);
|
|
|
|
CRYPT_Free(provname);
|
2004-08-02 20:49:26 +02:00
|
|
|
CRYPT_Free(temp);
|
|
|
|
CRYPT_Free(imagepath);
|
2002-01-10 20:29:40 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2002-04-29 20:48:56 +02:00
|
|
|
/* FALLTHROUGH TO ERROR IF FALSE - CSP internal error! */
|
2002-01-10 20:29:40 +01:00
|
|
|
error:
|
|
|
|
if (pProv)
|
|
|
|
{
|
2005-04-11 14:55:36 +02:00
|
|
|
pProv->dwMagic = 0;
|
2004-09-14 19:43:41 +02:00
|
|
|
if (pProv->hModule)
|
|
|
|
FreeLibrary(pProv->hModule);
|
2006-11-30 05:50:58 +01:00
|
|
|
CRYPT_Free(pProv->pVTable);
|
|
|
|
CRYPT_Free(pProv->pFuncs);
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(pProv);
|
|
|
|
}
|
2006-11-30 05:50:58 +01:00
|
|
|
CRYPT_Free(pszContainerA);
|
|
|
|
CRYPT_Free(provnameA);
|
|
|
|
CRYPT_Free(provname);
|
|
|
|
CRYPT_Free(temp);
|
|
|
|
CRYPT_Free(imagepath);
|
2001-09-12 19:09:56 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-02-13 10:08:33 +01:00
|
|
|
|
2001-09-12 19:09:56 +02:00
|
|
|
/******************************************************************************
|
2005-09-28 13:59:04 +02:00
|
|
|
* CryptAcquireContextA (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
2005-11-04 12:43:27 +01:00
|
|
|
* See CryptAcquireContextW.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2005-09-28 13:59:04 +02:00
|
|
|
BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|
|
|
LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
|
1999-02-13 10:08:33 +01:00
|
|
|
{
|
2005-09-28 13:59:04 +02:00
|
|
|
PWSTR pProvider = NULL, pContainer = NULL;
|
2002-01-10 20:29:40 +01:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%p, %s, %s, %d, %08x)\n", phProv, pszContainer,
|
2005-09-28 13:59:04 +02:00
|
|
|
pszProvider, dwProvType, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
if ( !CRYPT_ANSIToUnicode(pszContainer, &pContainer, -1) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
if ( !CRYPT_ANSIToUnicode(pszProvider, &pProvider, -1) )
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
|
|
|
CRYPT_Free(pContainer);
|
2007-01-05 12:45:46 +01:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
2002-01-10 20:29:40 +01:00
|
|
|
}
|
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
ret = CryptAcquireContextW(phProv, pContainer, pProvider, dwProvType, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2006-11-30 05:50:58 +01:00
|
|
|
CRYPT_Free(pContainer);
|
|
|
|
CRYPT_Free(pProvider);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptContextAddRef (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Increases reference count of a cryptographic service provider handle
|
|
|
|
* by one.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProv [I] Handle to the CSP whose reference is being incremented.
|
|
|
|
* pdwReserved [IN] Reserved for future use and must be NULL.
|
|
|
|
* dwFlags [I] Reserved for future use and must be NULL.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2002-01-10 20:29:40 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptContextAddRef (HCRYPTPROV hProv, DWORD *pdwReserved, DWORD dwFlags)
|
|
|
|
{
|
2004-07-14 01:34:13 +02:00
|
|
|
PCRYPTPROV pProv = (PCRYPTPROV)hProv;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %p, %08x)\n", hProv, pdwReserved, dwFlags);
|
2004-07-14 01:34:13 +02:00
|
|
|
|
|
|
|
if (!pProv)
|
|
|
|
{
|
|
|
|
SetLastError(NTE_BAD_UID);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-04-11 14:55:36 +02:00
|
|
|
if (pProv->dwMagic != MAGIC_CRYPTPROV)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-07-14 01:34:13 +02:00
|
|
|
pProv->refcount++;
|
|
|
|
return TRUE;
|
1999-02-13 10:08:33 +01:00
|
|
|
}
|
|
|
|
|
1999-10-31 03:07:05 +01:00
|
|
|
/******************************************************************************
|
2002-01-10 20:29:40 +01:00
|
|
|
* CryptReleaseContext (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Releases the handle of a CSP. Reference count is decreased.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProv [I] Handle of a CSP.
|
|
|
|
* dwFlags [I] Reserved for future use and must be NULL.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
1999-10-31 03:07:05 +01:00
|
|
|
*/
|
2007-07-31 19:02:53 +02:00
|
|
|
BOOL WINAPI CryptReleaseContext (HCRYPTPROV hProv, ULONG_PTR dwFlags)
|
1999-07-31 15:07:19 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV pProv = (PCRYPTPROV)hProv;
|
2004-07-14 01:34:13 +02:00
|
|
|
BOOL ret = TRUE;
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2007-07-31 19:02:53 +02:00
|
|
|
TRACE("(0x%lx, %08lx)\n", hProv, dwFlags);
|
2001-09-12 19:09:56 +02:00
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
if (!pProv)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
SetLastError(NTE_BAD_UID);
|
|
|
|
return FALSE;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
2004-07-14 01:34:13 +02:00
|
|
|
|
2005-04-11 14:55:36 +02:00
|
|
|
if (pProv->dwMagic != MAGIC_CRYPTPROV)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-07-14 01:34:13 +02:00
|
|
|
pProv->refcount--;
|
|
|
|
if (pProv->refcount <= 0)
|
|
|
|
{
|
|
|
|
ret = pProv->pFuncs->pCPReleaseContext(pProv->hPrivate, dwFlags);
|
2005-04-11 14:55:36 +02:00
|
|
|
pProv->dwMagic = 0;
|
2004-07-14 01:34:13 +02:00
|
|
|
FreeLibrary(pProv->hModule);
|
2002-04-29 20:48:56 +02:00
|
|
|
#if 0
|
2004-07-14 01:34:13 +02:00
|
|
|
CRYPT_Free(pProv->pVTable->pContextInfo);
|
2002-04-29 20:48:56 +02:00
|
|
|
#endif
|
2004-07-14 01:34:13 +02:00
|
|
|
CRYPT_Free(pProv->pVTable->pszProvName);
|
|
|
|
CRYPT_Free(pProv->pVTable);
|
|
|
|
CRYPT_Free(pProv->pFuncs);
|
|
|
|
CRYPT_Free(pProv);
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
return ret;
|
1999-07-31 15:07:19 +02:00
|
|
|
}
|
1999-02-13 10:08:33 +01:00
|
|
|
|
2001-09-12 19:09:56 +02:00
|
|
|
/******************************************************************************
|
2002-01-10 20:29:40 +01:00
|
|
|
* CryptGenRandom (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Fills a buffer with cryptographically random bytes.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProv [I] Handle of a CSP.
|
|
|
|
* dwLen [I] Number of bytes to generate.
|
|
|
|
* pbBuffer [I/O] Buffer to contain random bytes.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* pdBuffer must be at least dwLen bytes long.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2002-01-10 20:29:40 +01:00
|
|
|
BOOL WINAPI CryptGenRandom (HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %p)\n", hProv, dwLen, pbBuffer);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (!hProv)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2005-04-11 14:55:36 +02:00
|
|
|
if (prov->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-04-11 14:55:36 +02:00
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
return prov->pFuncs->pCPGenRandom(prov->hPrivate, dwLen, pbBuffer);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
2000-10-24 03:39:29 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
2001-09-12 19:09:56 +02:00
|
|
|
* CryptCreateHash (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Initiates the hashing of a stream of data.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProv [I] Handle of a CSP.
|
|
|
|
* Algid [I] Identifies the hash algorithm to use.
|
|
|
|
* hKey [I] Key for the hash (if required).
|
|
|
|
* dwFlags [I] Reserved for future use and must be NULL.
|
|
|
|
* phHash [O] Address of the future handle to the new hash object.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If the algorithm is a keyed hash, hKey is the key.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptCreateHash (HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey,
|
|
|
|
DWORD dwFlags, HCRYPTHASH *phHash)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
|
|
|
PCRYPTKEY key = (PCRYPTKEY)hKey;
|
|
|
|
PCRYPTHASH hash;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, 0x%x, 0x%lx, %08x, %p)\n", hProv, Algid, hKey, dwFlags, phHash);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (!prov)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!phHash || prov->dwMagic != MAGIC_CRYPTPROV ||
|
|
|
|
(key && key->dwMagic != MAGIC_CRYPTKEY))
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
if (dwFlags)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(NTE_BAD_FLAGS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
if ( !(hash = CRYPT_Alloc(sizeof(CRYPTHASH))) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
hash->pProvider = prov;
|
2010-08-18 02:14:42 +02:00
|
|
|
hash->dwMagic = MAGIC_CRYPTHASH;
|
2002-01-10 20:29:40 +01:00
|
|
|
if (prov->pFuncs->pCPCreateHash(prov->hPrivate, Algid,
|
|
|
|
key ? key->hPrivate : 0, 0, &hash->hPrivate))
|
2002-08-13 20:05:19 +02:00
|
|
|
{
|
|
|
|
*phHash = (HCRYPTHASH)hash;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2002-04-29 20:48:56 +02:00
|
|
|
/* CSP error! */
|
2010-08-18 02:14:42 +02:00
|
|
|
hash->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(hash);
|
2004-10-27 23:15:10 +02:00
|
|
|
*phHash = 0;
|
2001-09-12 19:09:56 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptDecrypt (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Decrypts data encrypted by CryptEncrypt.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hKey [I] Handle to the decryption key.
|
|
|
|
* hHash [I] Handle to a hash object.
|
|
|
|
* Final [I] TRUE if this is the last section to be decrypted.
|
|
|
|
* dwFlags [I] Reserved for future use. Can be CRYPT_OAEP.
|
|
|
|
* pbData [I/O] Buffer that holds the encrypted data. Holds decrypted
|
|
|
|
* data on return
|
|
|
|
* pdwDataLen [I/O] Length of pbData before and after the call.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptDecrypt (HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final,
|
|
|
|
DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov;
|
|
|
|
PCRYPTKEY key = (PCRYPTKEY)hKey;
|
|
|
|
PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hHash, Final, dwFlags, pbData, pdwDataLen);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!key || !pbData || !pdwDataLen ||
|
|
|
|
!key->pProvider || key->dwMagic != MAGIC_CRYPTKEY ||
|
|
|
|
key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = key->pProvider;
|
|
|
|
return prov->pFuncs->pCPDecrypt(prov->hPrivate, key->hPrivate, hash ? hash->hPrivate : 0,
|
|
|
|
Final, dwFlags, pbData, pdwDataLen);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptDeriveKey (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Generates session keys derived from a base data value.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProv [I] Handle to a CSP.
|
|
|
|
* Algid [I] Identifies the symmetric encryption algorithm to use.
|
|
|
|
* hBaseData [I] Handle to a hash object.
|
|
|
|
* dwFlags [I] Type of key to generate.
|
|
|
|
* phKey [I/O] Address of the newly generated key.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptDeriveKey (HCRYPTPROV hProv, ALG_ID Algid, HCRYPTHASH hBaseData,
|
|
|
|
DWORD dwFlags, HCRYPTKEY *phKey)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
|
|
|
PCRYPTHASH hash = (PCRYPTHASH)hBaseData;
|
|
|
|
PCRYPTKEY key;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, 0x%08x, 0x%lx, 0x%08x, %p)\n", hProv, Algid, hBaseData, dwFlags, phKey);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (!prov || !hash)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!phKey || prov->dwMagic != MAGIC_CRYPTPROV || hash->dwMagic != MAGIC_CRYPTHASH)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
if ( !(key = CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
key->pProvider = prov;
|
2010-08-18 02:14:42 +02:00
|
|
|
key->dwMagic = MAGIC_CRYPTKEY;
|
2002-01-10 20:29:40 +01:00
|
|
|
if (prov->pFuncs->pCPDeriveKey(prov->hPrivate, Algid, hash->hPrivate, dwFlags, &key->hPrivate))
|
2002-08-13 20:05:19 +02:00
|
|
|
{
|
|
|
|
*phKey = (HCRYPTKEY)key;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2002-04-29 20:48:56 +02:00
|
|
|
/* CSP error! */
|
2010-08-18 02:14:42 +02:00
|
|
|
key->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(key);
|
2004-10-11 21:52:54 +02:00
|
|
|
*phKey = 0;
|
2001-09-12 19:09:56 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptDestroyHash (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Destroys the hash object referenced by hHash.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hHash [I] Handle of the hash object to be destroyed.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptDestroyHash (HCRYPTHASH hHash)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
|
|
|
PCRYPTPROV prov;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(0x%lx)\n", hHash);
|
|
|
|
|
|
|
|
if (!hash)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
|
|
|
|
hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
prov = hash->pProvider;
|
|
|
|
ret = prov->pFuncs->pCPDestroyHash(prov->hPrivate, hash->hPrivate);
|
2010-08-18 02:14:42 +02:00
|
|
|
hash->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(hash);
|
|
|
|
return ret;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2004-07-13 01:32:10 +02:00
|
|
|
* CryptDestroyKey (ADVAPI32.@)
|
|
|
|
*
|
|
|
|
* Releases the handle referenced by hKey.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hKey [I] Handle of the key to be destroyed.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptDestroyKey (HCRYPTKEY hKey)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTKEY key = (PCRYPTKEY)hKey;
|
|
|
|
PCRYPTPROV prov;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(0x%lx)\n", hKey);
|
|
|
|
|
|
|
|
if (!key)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!key->pProvider || key->dwMagic != MAGIC_CRYPTKEY ||
|
|
|
|
key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-04-11 14:55:36 +02:00
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
prov = key->pProvider;
|
|
|
|
ret = prov->pFuncs->pCPDestroyKey(prov->hPrivate, key->hPrivate);
|
2010-08-18 02:14:42 +02:00
|
|
|
key->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(key);
|
|
|
|
return ret;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptDuplicateHash (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Duplicates a hash.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hHash [I] Handle to the hash to be copied.
|
|
|
|
* pdwReserved [I] Reserved for future use and must be zero.
|
|
|
|
* dwFlags [I] Reserved for future use and must be zero.
|
|
|
|
* phHash [O] Address of the handle to receive the copy.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptDuplicateHash (HCRYPTHASH hHash, DWORD *pdwReserved,
|
|
|
|
DWORD dwFlags, HCRYPTHASH *phHash)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov;
|
|
|
|
PCRYPTHASH orghash, newhash;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %p, %08x, %p)\n", hHash, pdwReserved, dwFlags, phHash);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
orghash = (PCRYPTHASH)hHash;
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!orghash || pdwReserved || !phHash || !orghash->pProvider ||
|
|
|
|
orghash->dwMagic != MAGIC_CRYPTHASH || orghash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2005-04-11 14:55:36 +02:00
|
|
|
{
|
2007-01-05 12:45:46 +01:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
2005-04-11 14:55:36 +02:00
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = orghash->pProvider;
|
|
|
|
if (!prov->pFuncs->pCPDuplicateHash)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if ( !(newhash = CRYPT_Alloc(sizeof(CRYPTHASH))) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
newhash->pProvider = prov;
|
2010-08-18 02:14:42 +02:00
|
|
|
newhash->dwMagic = MAGIC_CRYPTHASH;
|
2002-01-10 20:29:40 +01:00
|
|
|
if (prov->pFuncs->pCPDuplicateHash(prov->hPrivate, orghash->hPrivate, pdwReserved, dwFlags, &newhash->hPrivate))
|
|
|
|
{
|
|
|
|
*phHash = (HCRYPTHASH)newhash;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-08-18 02:14:42 +02:00
|
|
|
newhash->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(newhash);
|
2001-09-12 19:09:56 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptDuplicateKey (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Duplicate a key and the key's state.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hKey [I] Handle of the key to copy.
|
|
|
|
* pdwReserved [I] Reserved for future use and must be NULL.
|
|
|
|
* dwFlags [I] Reserved for future use and must be zero.
|
|
|
|
* phKey [I] Address of the handle to the duplicated key.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptDuplicateKey (HCRYPTKEY hKey, DWORD *pdwReserved, DWORD dwFlags, HCRYPTKEY *phKey)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov;
|
|
|
|
PCRYPTKEY orgkey, newkey;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %p, %08x, %p)\n", hKey, pdwReserved, dwFlags, phKey);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
orgkey = (PCRYPTKEY)hKey;
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!orgkey || pdwReserved || !phKey || !orgkey->pProvider ||
|
|
|
|
orgkey->dwMagic != MAGIC_CRYPTKEY ||
|
2005-04-11 14:55:36 +02:00
|
|
|
orgkey->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
|
|
|
{
|
2007-01-05 12:45:46 +01:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
2005-04-11 14:55:36 +02:00
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = orgkey->pProvider;
|
|
|
|
if (!prov->pFuncs->pCPDuplicateKey)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if ( !(newkey = CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
newkey->pProvider = prov;
|
2010-08-18 02:14:42 +02:00
|
|
|
newkey->dwMagic = MAGIC_CRYPTKEY;
|
2002-01-10 20:29:40 +01:00
|
|
|
if (prov->pFuncs->pCPDuplicateKey(prov->hPrivate, orgkey->hPrivate, pdwReserved, dwFlags, &newkey->hPrivate))
|
|
|
|
{
|
|
|
|
*phKey = (HCRYPTKEY)newkey;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-08-18 02:14:42 +02:00
|
|
|
newkey->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(newkey);
|
2001-09-12 19:09:56 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptEncrypt (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Encrypts data.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2007-04-07 01:46:59 +02:00
|
|
|
* hKey [I] Handle to the encryption key.
|
2004-07-13 01:32:10 +02:00
|
|
|
* hHash [I] Handle to a hash object.
|
|
|
|
* Final [I] TRUE if this is the last section to encrypt.
|
|
|
|
* dwFlags [I] Can be CRYPT_OAEP.
|
|
|
|
* pbData [I/O] Data to be encrypted. Contains encrypted data after call.
|
|
|
|
* pdwDataLen [I/O] Length of the data to encrypt. Contains the length of the
|
|
|
|
* encrypted data after call.
|
|
|
|
* dwBufLen [I] Length of the input pbData buffer.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If pbData is NULL, CryptEncrypt determines stores the number of bytes
|
|
|
|
* required for the returned data in pdwDataLen.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptEncrypt (HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final,
|
|
|
|
DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov;
|
|
|
|
PCRYPTKEY key = (PCRYPTKEY)hKey;
|
|
|
|
PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p, %d)\n", hKey, hHash, Final, dwFlags, pbData, pdwDataLen, dwBufLen);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!key || !pdwDataLen || !key->pProvider ||
|
|
|
|
key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = key->pProvider;
|
|
|
|
return prov->pFuncs->pCPEncrypt(prov->hPrivate, key->hPrivate, hash ? hash->hPrivate : 0,
|
|
|
|
Final, dwFlags, pbData, pdwDataLen, dwBufLen);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2004-08-12 05:24:10 +02:00
|
|
|
* CryptEnumProvidersW (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
2007-04-07 01:46:59 +02:00
|
|
|
* Returns the next available CSP.
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dwIndex [I] Index of the next provider to be enumerated.
|
|
|
|
* pdwReserved [I] Reserved for future use and must be NULL.
|
|
|
|
* dwFlags [I] Reserved for future use and must be zero.
|
|
|
|
* pdwProvType [O] DWORD designating the type of the provider.
|
|
|
|
* pszProvName [O] Buffer that receives data from the provider.
|
|
|
|
* pcbProvName [I/O] Specifies the size of pszProvName. Contains the number
|
2004-08-13 21:45:40 +02:00
|
|
|
* of bytes stored in the buffer on return.
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
2004-08-13 21:45:40 +02:00
|
|
|
* If pszProvName is NULL, CryptEnumProvidersW sets the size of the name
|
2004-07-13 01:32:10 +02:00
|
|
|
* for memory allocation purposes.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2004-08-12 05:24:10 +02:00
|
|
|
BOOL WINAPI CryptEnumProvidersW (DWORD dwIndex, DWORD *pdwReserved,
|
|
|
|
DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszProvName, DWORD *pcbProvName)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
HKEY hKey;
|
2004-08-12 05:24:10 +02:00
|
|
|
static const WCHAR providerW[] = {
|
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
|
|
|
'D','e','f','a','u','l','t','s','\\',
|
|
|
|
'P','r','o','v','i','d','e','r',0
|
|
|
|
};
|
|
|
|
static const WCHAR typeW[] = {'T','y','p','e',0};
|
2011-08-04 01:55:56 +02:00
|
|
|
BOOL ret;
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%d, %p, %d, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
2001-09-12 19:09:56 +02:00
|
|
|
pdwProvType, pszProvName, pcbProvName);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2007-01-05 12:45:46 +01:00
|
|
|
if (pdwReserved || !pcbProvName)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (dwFlags)
|
|
|
|
{
|
|
|
|
SetLastError(NTE_BAD_FLAGS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2004-08-12 05:24:10 +02:00
|
|
|
if (RegOpenKeyW(HKEY_LOCAL_MACHINE, providerW, &hKey))
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(NTE_FAIL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2011-08-04 01:55:56 +02:00
|
|
|
ret = TRUE;
|
2002-01-10 20:29:40 +01:00
|
|
|
if (!pszProvName)
|
|
|
|
{
|
|
|
|
DWORD numkeys;
|
2004-08-12 05:24:10 +02:00
|
|
|
WCHAR *provNameW;
|
2004-08-10 00:53:58 +02:00
|
|
|
|
2004-08-12 05:24:10 +02:00
|
|
|
RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &numkeys, pcbProvName,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
2004-08-10 00:53:58 +02:00
|
|
|
|
2004-08-12 05:24:10 +02:00
|
|
|
if (!(provNameW = CRYPT_Alloc(*pcbProvName * sizeof(WCHAR))))
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2011-08-04 01:55:56 +02:00
|
|
|
RegCloseKey(hKey);
|
2007-01-05 12:45:46 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-08-12 05:24:10 +02:00
|
|
|
RegEnumKeyExW(hKey, dwIndex, provNameW, pcbProvName, NULL, NULL, NULL, NULL);
|
2005-09-28 13:59:04 +02:00
|
|
|
CRYPT_Free(provNameW);
|
2002-01-10 20:29:40 +01:00
|
|
|
(*pcbProvName)++;
|
2004-08-12 05:24:10 +02:00
|
|
|
*pcbProvName *= sizeof(WCHAR);
|
2005-09-28 13:59:04 +02:00
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
if (dwIndex >= numkeys)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NO_MORE_ITEMS);
|
2011-08-04 01:55:56 +02:00
|
|
|
ret = FALSE;
|
2007-01-05 12:45:46 +01:00
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
} else {
|
|
|
|
DWORD size = sizeof(DWORD);
|
2004-08-13 21:45:40 +02:00
|
|
|
DWORD result;
|
2002-01-10 20:29:40 +01:00
|
|
|
HKEY subkey;
|
2004-08-13 21:45:40 +02:00
|
|
|
|
|
|
|
result = RegEnumKeyW(hKey, dwIndex, pszProvName, *pcbProvName / sizeof(WCHAR));
|
|
|
|
if (result)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(result);
|
2011-08-04 01:55:56 +02:00
|
|
|
RegCloseKey(hKey);
|
2007-01-05 12:45:46 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-08-12 05:24:10 +02:00
|
|
|
if (RegOpenKeyW(hKey, pszProvName, &subkey))
|
2011-08-04 01:55:56 +02:00
|
|
|
{
|
|
|
|
RegCloseKey(hKey);
|
2002-01-10 20:29:40 +01:00
|
|
|
return FALSE;
|
2011-08-04 01:55:56 +02:00
|
|
|
}
|
|
|
|
|
2004-08-12 05:24:10 +02:00
|
|
|
if (RegQueryValueExW(subkey, typeW, NULL, NULL, (BYTE*)pdwProvType, &size))
|
2011-08-04 01:55:56 +02:00
|
|
|
ret = FALSE;
|
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
RegCloseKey(subkey);
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
2011-08-04 01:55:56 +02:00
|
|
|
return ret;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2004-08-12 05:24:10 +02:00
|
|
|
* CryptEnumProvidersA (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
2005-11-04 12:43:27 +01:00
|
|
|
* See CryptEnumProvidersW.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2004-08-12 05:24:10 +02:00
|
|
|
BOOL WINAPI CryptEnumProvidersA (DWORD dwIndex, DWORD *pdwReserved,
|
|
|
|
DWORD dwFlags, DWORD *pdwProvType, LPSTR pszProvName, DWORD *pcbProvName)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2004-08-12 05:24:10 +02:00
|
|
|
PWSTR str = NULL;
|
2008-05-05 13:13:02 +02:00
|
|
|
DWORD bufsize;
|
2011-08-04 01:55:56 +02:00
|
|
|
BOOL ret;
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
2001-09-12 19:09:56 +02:00
|
|
|
pdwProvType, pszProvName, pcbProvName);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2008-05-05 13:13:02 +02:00
|
|
|
if(!CryptEnumProvidersW(dwIndex, pdwReserved, dwFlags, pdwProvType, NULL, &bufsize))
|
2007-05-02 22:12:20 +02:00
|
|
|
return FALSE;
|
2008-05-05 13:13:02 +02:00
|
|
|
if ( pszProvName && !(str = CRYPT_Alloc(bufsize)) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-05-05 13:13:02 +02:00
|
|
|
ret = CryptEnumProvidersW(dwIndex, pdwReserved, dwFlags, pdwProvType, str, &bufsize);
|
2002-01-10 20:29:40 +01:00
|
|
|
if (str)
|
2004-08-12 05:24:10 +02:00
|
|
|
CRYPT_UnicodeToANSI(str, &pszProvName, *pcbProvName);
|
2008-05-05 13:13:02 +02:00
|
|
|
*pcbProvName = bufsize / sizeof(WCHAR); /* FIXME: not correct */
|
2005-09-28 13:59:04 +02:00
|
|
|
if (str)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(str);
|
2005-09-28 13:59:04 +02:00
|
|
|
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
}
|
|
|
|
return ret;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2005-11-04 12:43:27 +01:00
|
|
|
* CryptEnumProviderTypesW (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Retrieves the next type of CSP supported.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dwIndex [I] Index of the next provider to be enumerated.
|
|
|
|
* pdwReserved [I] Reserved for future use and must be NULL.
|
|
|
|
* dwFlags [I] Reserved for future use and must be zero.
|
|
|
|
* pdwProvType [O] DWORD designating the type of the provider.
|
|
|
|
* pszTypeName [O] Buffer that receives data from the provider type.
|
|
|
|
* pcbTypeName [I/O] Specifies the size of pszTypeName. Contains the number
|
2004-08-13 21:45:40 +02:00
|
|
|
* of bytes stored in the buffer on return.
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
2005-09-28 13:59:04 +02:00
|
|
|
* If pszTypeName is NULL, CryptEnumProviderTypesW sets the size of the name
|
2004-07-13 01:32:10 +02:00
|
|
|
* for memory allocation purposes.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2005-09-28 13:59:04 +02:00
|
|
|
BOOL WINAPI CryptEnumProviderTypesW (DWORD dwIndex, DWORD *pdwReserved,
|
|
|
|
DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszTypeName, DWORD *pcbTypeName)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
HKEY hKey, hSubkey;
|
2004-07-15 20:59:34 +02:00
|
|
|
DWORD keylen, numkeys, dwType;
|
2005-09-28 13:59:04 +02:00
|
|
|
PWSTR keyname, ch;
|
2004-08-18 00:08:16 +02:00
|
|
|
DWORD result;
|
2005-09-28 13:59:04 +02:00
|
|
|
static const WCHAR KEYSTR[] = {
|
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
|
|
|
'D','e','f','a','u','l','t','s','\\',
|
|
|
|
'P','r','o','v','i','d','e','r',' ','T','y','p','e','s',0
|
|
|
|
};
|
|
|
|
static const WCHAR typenameW[] = {'T','y','p','e','N','a','m','e',0};
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved,
|
2002-01-10 20:29:40 +01:00
|
|
|
dwFlags, pdwProvType, pszTypeName, pcbTypeName);
|
|
|
|
|
|
|
|
if (pdwReserved || !pdwProvType || !pcbTypeName)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (dwFlags)
|
|
|
|
{
|
|
|
|
SetLastError(NTE_BAD_FLAGS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
if (RegOpenKeyW(HKEY_LOCAL_MACHINE, KEYSTR, &hKey))
|
2002-01-10 20:29:40 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &numkeys, &keylen, NULL, NULL, NULL, NULL, NULL, NULL);
|
2002-01-10 20:29:40 +01:00
|
|
|
if (dwIndex >= numkeys)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NO_MORE_ITEMS);
|
2011-08-04 01:55:56 +02:00
|
|
|
RegCloseKey(hKey);
|
2007-01-05 12:45:46 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
keylen++;
|
2005-09-28 13:59:04 +02:00
|
|
|
if ( !(keyname = CRYPT_Alloc(keylen*sizeof(WCHAR))) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2011-08-04 01:55:56 +02:00
|
|
|
RegCloseKey(hKey);
|
2007-01-05 12:45:46 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
if ( RegEnumKeyW(hKey, dwIndex, keyname, keylen) ) {
|
2003-10-01 05:14:29 +02:00
|
|
|
CRYPT_Free(keyname);
|
2011-08-04 01:55:56 +02:00
|
|
|
RegCloseKey(hKey);
|
2002-01-10 20:29:40 +01:00
|
|
|
return FALSE;
|
2003-10-01 05:14:29 +02:00
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
RegOpenKeyW(hKey, keyname, &hSubkey);
|
2011-08-04 01:55:56 +02:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
ch = keyname + strlenW(keyname);
|
2002-04-29 20:48:56 +02:00
|
|
|
/* Convert "Type 000" to 0, etc/ */
|
2002-01-10 20:29:40 +01:00
|
|
|
*pdwProvType = *(--ch) - '0';
|
|
|
|
*pdwProvType += (*(--ch) - '0') * 10;
|
|
|
|
*pdwProvType += (*(--ch) - '0') * 100;
|
|
|
|
CRYPT_Free(keyname);
|
2004-08-18 00:08:16 +02:00
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
result = RegQueryValueExW(hSubkey, typenameW, NULL, &dwType, (LPBYTE)pszTypeName, pcbTypeName);
|
2004-08-18 00:08:16 +02:00
|
|
|
if (result)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(result);
|
2011-08-04 01:55:56 +02:00
|
|
|
RegCloseKey(hSubkey);
|
2007-01-05 12:45:46 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-08-18 00:08:16 +02:00
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
RegCloseKey(hSubkey);
|
|
|
|
return TRUE;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2005-09-28 13:59:04 +02:00
|
|
|
* CryptEnumProviderTypesA (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
2005-11-04 12:43:27 +01:00
|
|
|
* See CryptEnumProviderTypesW.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2005-09-28 13:59:04 +02:00
|
|
|
BOOL WINAPI CryptEnumProviderTypesA (DWORD dwIndex, DWORD *pdwReserved,
|
|
|
|
DWORD dwFlags, DWORD *pdwProvType, LPSTR pszTypeName, DWORD *pcbTypeName)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2005-09-28 13:59:04 +02:00
|
|
|
PWSTR str = NULL;
|
2008-05-05 13:13:02 +02:00
|
|
|
DWORD bufsize;
|
2002-01-10 20:29:40 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
2001-09-12 19:09:56 +02:00
|
|
|
pdwProvType, pszTypeName, pcbTypeName);
|
2005-09-28 13:59:04 +02:00
|
|
|
|
2008-05-05 13:13:02 +02:00
|
|
|
if(!CryptEnumProviderTypesW(dwIndex, pdwReserved, dwFlags, pdwProvType, NULL, &bufsize))
|
2007-05-02 22:12:20 +02:00
|
|
|
return FALSE;
|
2008-05-05 13:13:02 +02:00
|
|
|
if ( pszTypeName && !(str = CRYPT_Alloc(bufsize)) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-05-05 13:13:02 +02:00
|
|
|
ret = CryptEnumProviderTypesW(dwIndex, pdwReserved, dwFlags, pdwProvType, str, &bufsize);
|
2005-09-28 13:59:04 +02:00
|
|
|
if (str)
|
|
|
|
CRYPT_UnicodeToANSI(str, &pszTypeName, *pcbTypeName);
|
2008-05-05 13:13:02 +02:00
|
|
|
*pcbTypeName = bufsize / sizeof(WCHAR);
|
2002-01-10 20:29:40 +01:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
CRYPT_Free(str);
|
2005-09-28 13:59:04 +02:00
|
|
|
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
}
|
|
|
|
return ret;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptExportKey (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Exports a cryptographic key from a CSP.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hKey [I] Handle to the key to export.
|
|
|
|
* hExpKey [I] Handle to a cryptographic key of the end user.
|
|
|
|
* dwBlobType [I] Type of BLOB to be exported.
|
|
|
|
* dwFlags [I] CRYPT_DESTROYKEY/SSL2_FALLBACK/OAEP.
|
|
|
|
* pbData [O] Buffer to receive BLOB data.
|
|
|
|
* pdwDataLen [I/O] Specifies the size of pbData.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* if pbData is NULL, CryptExportKey sets pdwDataLen as the size of the
|
|
|
|
* buffer needed to hold the BLOB.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptExportKey (HCRYPTKEY hKey, HCRYPTKEY hExpKey, DWORD dwBlobType,
|
|
|
|
DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov;
|
|
|
|
PCRYPTKEY key = (PCRYPTKEY)hKey, expkey = (PCRYPTKEY)hExpKey;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hExpKey, dwBlobType, dwFlags, pbData, pdwDataLen);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!key || !pdwDataLen || !key->pProvider ||
|
|
|
|
key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = key->pProvider;
|
|
|
|
return prov->pFuncs->pCPExportKey(prov->hPrivate, key->hPrivate, expkey ? expkey->hPrivate : 0,
|
|
|
|
dwBlobType, dwFlags, pbData, pdwDataLen);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptGenKey (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Generates a random cryptographic session key or a pub/priv key pair.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProv [I] Handle to a CSP.
|
|
|
|
* Algid [I] Algorithm to use to make key.
|
|
|
|
* dwFlags [I] Specifies type of key to make.
|
|
|
|
* phKey [I] Address of the handle to which the new key is copied.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptGenKey (HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
|
|
|
PCRYPTKEY key;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %08x, %p)\n", hProv, Algid, dwFlags, phKey);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2005-04-11 14:55:36 +02:00
|
|
|
if (!phKey || !prov || prov->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
if ( !(key = CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
key->pProvider = prov;
|
2010-08-18 02:14:42 +02:00
|
|
|
key->dwMagic = MAGIC_CRYPTKEY;
|
2002-01-10 20:29:40 +01:00
|
|
|
if (prov->pFuncs->pCPGenKey(prov->hPrivate, Algid, dwFlags, &key->hPrivate))
|
2002-08-13 20:05:19 +02:00
|
|
|
{
|
|
|
|
*phKey = (HCRYPTKEY)key;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2002-04-29 20:48:56 +02:00
|
|
|
/* CSP error! */
|
2010-08-18 02:14:42 +02:00
|
|
|
key->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(key);
|
2001-09-12 19:09:56 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2005-09-28 13:59:04 +02:00
|
|
|
* CryptGetDefaultProviderW (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Finds the default CSP of a certain provider type.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dwProvType [I] Provider type to look for.
|
|
|
|
* pdwReserved [I] Reserved for future use and must be NULL.
|
|
|
|
* dwFlags [I] CRYPT_MACHINE_DEFAULT/USER_DEFAULT
|
|
|
|
* pszProvName [O] Name of the default CSP.
|
|
|
|
* pcbProvName [I/O] Size of pszProvName
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If pszProvName is NULL, pcbProvName will hold the size of the buffer for
|
|
|
|
* memory allocation purposes on return.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2005-09-28 13:59:04 +02:00
|
|
|
BOOL WINAPI CryptGetDefaultProviderW (DWORD dwProvType, DWORD *pdwReserved,
|
|
|
|
DWORD dwFlags, LPWSTR pszProvName, DWORD *pcbProvName)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
HKEY hKey;
|
2005-09-28 13:59:04 +02:00
|
|
|
PWSTR keyname;
|
2004-08-20 21:25:35 +02:00
|
|
|
DWORD result;
|
2005-09-28 13:59:04 +02:00
|
|
|
static const WCHAR nameW[] = {'N','a','m','e',0};
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (pdwReserved || !pcbProvName)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
if (dwFlags & ~(CRYPT_USER_DEFAULT | CRYPT_MACHINE_DEFAULT))
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(NTE_BAD_FLAGS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-22 00:25:17 +02:00
|
|
|
if (dwProvType > 999)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(NTE_BAD_PROV_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, dwFlags & CRYPT_USER_DEFAULT)) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE ,keyname, &hKey))
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
|
|
|
CRYPT_Free(keyname);
|
2007-01-05 12:45:46 +01:00
|
|
|
SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
|
|
|
return FALSE;
|
2002-01-10 20:29:40 +01:00
|
|
|
}
|
|
|
|
CRYPT_Free(keyname);
|
2004-08-20 21:25:35 +02:00
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
result = RegQueryValueExW(hKey, nameW, NULL, NULL, (LPBYTE)pszProvName, pcbProvName);
|
2011-08-04 01:55:56 +02:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
2004-08-20 21:25:35 +02:00
|
|
|
if (result)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
2004-08-20 21:25:35 +02:00
|
|
|
if (result != ERROR_MORE_DATA)
|
2002-01-10 20:29:40 +01:00
|
|
|
SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
2004-08-20 21:25:35 +02:00
|
|
|
else
|
|
|
|
SetLastError(result);
|
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-08-20 21:25:35 +02:00
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
return TRUE;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2005-09-28 13:59:04 +02:00
|
|
|
* CryptGetDefaultProviderA (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
2005-11-04 12:43:27 +01:00
|
|
|
* See CryptGetDefaultProviderW.
|
2000-10-24 03:39:29 +02:00
|
|
|
*/
|
2005-09-28 13:59:04 +02:00
|
|
|
BOOL WINAPI CryptGetDefaultProviderA (DWORD dwProvType, DWORD *pdwReserved,
|
|
|
|
DWORD dwFlags, LPSTR pszProvName, DWORD *pcbProvName)
|
2000-10-24 03:39:29 +02:00
|
|
|
{
|
2005-09-28 13:59:04 +02:00
|
|
|
PWSTR str = NULL;
|
2008-05-05 13:13:02 +02:00
|
|
|
DWORD bufsize;
|
2011-08-04 01:55:56 +02:00
|
|
|
BOOL ret;
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%d, %p, %08x, %p, %p)\n", dwProvType, pdwReserved, dwFlags, pszProvName, pcbProvName);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2008-05-05 13:13:02 +02:00
|
|
|
CryptGetDefaultProviderW(dwProvType, pdwReserved, dwFlags, NULL, &bufsize);
|
|
|
|
if ( pszProvName && !(str = CRYPT_Alloc(bufsize)) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-05-05 13:13:02 +02:00
|
|
|
ret = CryptGetDefaultProviderW(dwProvType, pdwReserved, dwFlags, str, &bufsize);
|
2005-09-28 13:59:04 +02:00
|
|
|
if (str)
|
|
|
|
CRYPT_UnicodeToANSI(str, &pszProvName, *pcbProvName);
|
2008-05-05 13:13:02 +02:00
|
|
|
*pcbProvName = bufsize / sizeof(WCHAR);
|
2002-01-10 20:29:40 +01:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
CRYPT_Free(str);
|
2005-09-28 13:59:04 +02:00
|
|
|
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
}
|
|
|
|
return ret;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
2000-10-24 03:39:29 +02:00
|
|
|
|
2001-09-12 19:09:56 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CryptGetHashParam (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Retrieves data that controls the operations of a hash object.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hHash [I] Handle of the hash object to question.
|
|
|
|
* dwParam [I] Query type.
|
|
|
|
* pbData [O] Buffer that receives the value data.
|
|
|
|
* pdwDataLen [I/O] Size of the pbData buffer.
|
|
|
|
* dwFlags [I] Reserved for future use and must be zero.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If pbData is NULL, pdwDataLen will contain the length required.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptGetHashParam (HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData,
|
|
|
|
DWORD *pdwDataLen, DWORD dwFlags)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov;
|
|
|
|
PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %p, %p, %08x)\n", hHash, dwParam, pbData, pdwDataLen, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!hash || !pdwDataLen || !hash->pProvider ||
|
|
|
|
hash->dwMagic != MAGIC_CRYPTHASH || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = hash->pProvider;
|
|
|
|
return prov->pFuncs->pCPGetHashParam(prov->hPrivate, hash->hPrivate, dwParam,
|
|
|
|
pbData, pdwDataLen, dwFlags);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
2000-10-24 03:39:29 +02:00
|
|
|
|
2001-09-12 19:09:56 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CryptGetKeyParam (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Retrieves data that controls the operations of a key.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hKey [I] Handle to they key in question.
|
|
|
|
* dwParam [I] Specifies query type.
|
|
|
|
* pbData [O] Sequence of bytes to receive data.
|
|
|
|
* pdwDataLen [I/O] Size of pbData.
|
|
|
|
* dwFlags [I] Reserved for future use and must be zero.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If pbData is NULL, pdwDataLen is set to the needed length of the buffer.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptGetKeyParam (HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData,
|
|
|
|
DWORD *pdwDataLen, DWORD dwFlags)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov;
|
|
|
|
PCRYPTKEY key = (PCRYPTKEY)hKey;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %p, %p, %08x)\n", hKey, dwParam, pbData, pdwDataLen, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!key || !pdwDataLen || !key->pProvider ||
|
|
|
|
key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = key->pProvider;
|
|
|
|
return prov->pFuncs->pCPGetKeyParam(prov->hPrivate, key->hPrivate, dwParam,
|
|
|
|
pbData, pdwDataLen, dwFlags);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
2000-10-24 03:39:29 +02:00
|
|
|
|
2001-09-12 19:09:56 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CryptGetProvParam (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Retrieves parameters that control the operations of a CSP.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProv [I] Handle of the CSP in question.
|
|
|
|
* dwParam [I] Specifies query type.
|
|
|
|
* pbData [O] Buffer to receive the data.
|
|
|
|
* pdwDataLen [I/O] Size of pbData.
|
|
|
|
* dwFlags [I] see MSDN Docs.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If pbData is NULL, pdwDataLen is set to the needed buffer length.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptGetProvParam (HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData,
|
|
|
|
DWORD *pdwDataLen, DWORD dwFlags)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %p, %p, %08x)\n", hProv, dwParam, pbData, pdwDataLen, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2005-04-11 14:55:36 +02:00
|
|
|
if (!prov || prov->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-04-11 14:55:36 +02:00
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
return prov->pFuncs->pCPGetProvParam(prov->hPrivate, dwParam, pbData, pdwDataLen, dwFlags);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
2000-10-24 03:39:29 +02:00
|
|
|
|
2001-09-12 19:09:56 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CryptGetUserKey (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Gets a handle of one of a user's two public/private key pairs.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProv [I] Handle of a CSP.
|
|
|
|
* dwKeySpec [I] Private key to use.
|
|
|
|
* phUserKey [O] Pointer to the handle of the retrieved keys.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptGetUserKey (HCRYPTPROV hProv, DWORD dwKeySpec, HCRYPTKEY *phUserKey)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
|
|
|
PCRYPTKEY key;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %p)\n", hProv, dwKeySpec, phUserKey);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (!prov)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-04-11 14:55:36 +02:00
|
|
|
if (!phUserKey || prov->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
if ( !(key = CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
key->pProvider = prov;
|
2010-08-18 02:14:42 +02:00
|
|
|
key->dwMagic = MAGIC_CRYPTKEY;
|
2002-01-10 20:29:40 +01:00
|
|
|
if (prov->pFuncs->pCPGetUserKey(prov->hPrivate, dwKeySpec, &key->hPrivate))
|
2002-08-13 20:05:19 +02:00
|
|
|
{
|
|
|
|
*phUserKey = (HCRYPTKEY)key;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2002-04-29 20:48:56 +02:00
|
|
|
/* CSP Error */
|
2010-08-18 02:14:42 +02:00
|
|
|
key->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(key);
|
2004-11-01 22:07:24 +01:00
|
|
|
*phUserKey = 0;
|
2001-09-12 19:09:56 +02:00
|
|
|
return FALSE;
|
2000-10-24 03:39:29 +02:00
|
|
|
}
|
|
|
|
|
2001-09-12 19:09:56 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CryptHashData (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Adds data to a hash object.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hHash [I] Handle of the hash object.
|
|
|
|
* pbData [I] Buffer of data to be hashed.
|
|
|
|
* dwDataLen [I] Number of bytes to add.
|
|
|
|
* dwFlags [I] Can be CRYPT_USERDATA
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2005-07-18 11:07:57 +02:00
|
|
|
BOOL WINAPI CryptHashData (HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
|
|
|
PCRYPTPROV prov;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %p, %d, %08x)\n", hHash, pbData, dwDataLen, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (!hash)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
|
|
|
|
hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = hash->pProvider;
|
|
|
|
return prov->pFuncs->pCPHashData(prov->hPrivate, hash->hPrivate, pbData, dwDataLen, dwFlags);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptHashSessionKey (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
2005-11-12 20:12:03 +01:00
|
|
|
* Compute the cryptographic hash of a session key object.
|
|
|
|
*
|
2004-07-13 01:32:10 +02:00
|
|
|
* PARAMS
|
|
|
|
* hHash [I] Handle to the hash object.
|
|
|
|
* hKey [I] Handle to the key to be hashed.
|
|
|
|
* dwFlags [I] Can be CRYPT_LITTLE_ENDIAN.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptHashSessionKey (HCRYPTHASH hHash, HCRYPTKEY hKey, DWORD dwFlags)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
|
|
|
PCRYPTKEY key = (PCRYPTKEY)hKey;
|
|
|
|
PCRYPTPROV prov;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, 0x%lx, %08x)\n", hHash, hKey, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (!hash || !key)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
|
|
|
|
hash->pProvider->dwMagic != MAGIC_CRYPTPROV || key->dwMagic != MAGIC_CRYPTKEY)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-04-11 14:55:36 +02:00
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
prov = hash->pProvider;
|
|
|
|
return prov->pFuncs->pCPHashSessionKey(prov->hPrivate, hash->hPrivate, key->hPrivate, dwFlags);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptImportKey (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
2005-11-12 20:12:03 +01:00
|
|
|
* Transfer a cryptographic key from a key BLOB into a cryptographic service provider (CSP).
|
|
|
|
*
|
2004-07-13 01:32:10 +02:00
|
|
|
* PARAMS
|
|
|
|
* hProv [I] Handle of a CSP.
|
|
|
|
* pbData [I] Contains the key to be imported.
|
|
|
|
* dwDataLen [I] Length of the key.
|
|
|
|
* hPubKey [I] Cryptographic key that decrypts pdData
|
|
|
|
* dwFlags [I] Used only with a public/private key pair.
|
|
|
|
* phKey [O] Imported key.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2007-01-29 14:49:46 +01:00
|
|
|
BOOL WINAPI CryptImportKey (HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
|
2001-09-12 19:09:56 +02:00
|
|
|
HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
|
|
|
PCRYPTKEY pubkey = (PCRYPTKEY)hPubKey, importkey;
|
2000-10-24 03:39:29 +02:00
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %p, %d, 0x%lx, %08x, %p)\n", hProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!prov || !pbData || !dwDataLen || !phKey ||
|
|
|
|
prov->dwMagic != MAGIC_CRYPTPROV ||
|
|
|
|
(pubkey && pubkey->dwMagic != MAGIC_CRYPTKEY))
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if ( !(importkey = CRYPT_Alloc(sizeof(CRYPTKEY))) )
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
importkey->pProvider = prov;
|
2010-08-18 02:14:42 +02:00
|
|
|
importkey->dwMagic = MAGIC_CRYPTKEY;
|
2002-01-10 20:29:40 +01:00
|
|
|
if (prov->pFuncs->pCPImportKey(prov->hPrivate, pbData, dwDataLen,
|
|
|
|
pubkey ? pubkey->hPrivate : 0, dwFlags, &importkey->hPrivate))
|
|
|
|
{
|
|
|
|
*phKey = (HCRYPTKEY)importkey;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
importkey->dwMagic = 0;
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(importkey);
|
2001-09-12 19:09:56 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2002-01-10 20:29:40 +01:00
|
|
|
* CryptSignHashW (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Signs data.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hHash [I] Handle of the hash object to be signed.
|
|
|
|
* dwKeySpec [I] Private key to use.
|
2004-12-21 15:34:18 +01:00
|
|
|
* sDescription [I] Should be NULL.
|
2004-07-13 01:32:10 +02:00
|
|
|
* dwFlags [I] CRYPT_NOHASHOID/X931_FORMAT.
|
|
|
|
* pbSignature [O] Buffer of the signature data.
|
|
|
|
* pdwSigLen [I/O] Size of the pbSignature buffer.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2004-12-21 15:34:18 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Because of security flaws sDescription should not be used and should thus be
|
|
|
|
* NULL. It is supported only for compatibility with Microsoft's Cryptographic
|
|
|
|
* Providers.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2004-12-21 15:34:18 +01:00
|
|
|
BOOL WINAPI CryptSignHashW (HCRYPTHASH hHash, DWORD dwKeySpec, LPCWSTR sDescription,
|
2001-09-12 19:09:56 +02:00
|
|
|
DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
|
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
|
|
|
PCRYPTPROV prov;
|
2001-09-12 19:09:56 +02:00
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
|
2004-12-21 15:34:18 +01:00
|
|
|
hHash, dwKeySpec, debugstr_w(sDescription), dwFlags, pbSignature, pdwSigLen);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (!hash)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!pdwSigLen || !hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
|
|
|
|
hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = hash->pProvider;
|
2004-12-21 15:34:18 +01:00
|
|
|
return prov->pFuncs->pCPSignHash(prov->hPrivate, hash->hPrivate, dwKeySpec, sDescription,
|
2002-01-10 20:29:40 +01:00
|
|
|
dwFlags, pbSignature, pdwSigLen);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
2004-12-21 15:34:18 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* CryptSignHashA (ADVAPI32.@)
|
|
|
|
*
|
2005-11-04 12:43:27 +01:00
|
|
|
* See CryptSignHashW.
|
2004-12-21 15:34:18 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptSignHashA (HCRYPTHASH hHash, DWORD dwKeySpec, LPCSTR sDescription,
|
|
|
|
DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
|
|
|
|
{
|
|
|
|
LPWSTR wsDescription;
|
|
|
|
BOOL result;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
|
2004-12-21 15:34:18 +01:00
|
|
|
hHash, dwKeySpec, debugstr_a(sDescription), dwFlags, pbSignature, pdwSigLen);
|
|
|
|
|
|
|
|
CRYPT_ANSIToUnicode(sDescription, &wsDescription, -1);
|
|
|
|
result = CryptSignHashW(hHash, dwKeySpec, wsDescription, dwFlags, pbSignature, pdwSigLen);
|
2006-11-30 05:50:58 +01:00
|
|
|
CRYPT_Free(wsDescription);
|
2004-12-21 15:34:18 +01:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-09-12 19:09:56 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CryptSetHashParam (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Customizes the operations of a hash object.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hHash [I] Handle of the hash object to set parameters.
|
|
|
|
* dwParam [I] HP_HMAC_INFO/HASHVAL.
|
|
|
|
* pbData [I] Value data buffer.
|
|
|
|
* dwFlags [I] Reserved for future use and must be zero.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2007-01-29 14:49:46 +01:00
|
|
|
BOOL WINAPI CryptSetHashParam (HCRYPTHASH hHash, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov;
|
|
|
|
PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %p, %08x)\n", hHash, dwParam, pbData, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!hash || !pbData || !hash->pProvider ||
|
|
|
|
hash->dwMagic != MAGIC_CRYPTHASH || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = hash->pProvider;
|
|
|
|
return prov->pFuncs->pCPSetHashParam(prov->hPrivate, hash->hPrivate,
|
|
|
|
dwParam, pbData, dwFlags);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2002-01-18 19:57:43 +01:00
|
|
|
* CryptSetKeyParam (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Customizes a session key's operations.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hKey [I] Handle to the key to set values.
|
|
|
|
* dwParam [I] See MSDN Doc.
|
|
|
|
* pbData [I] Buffer of values to set.
|
|
|
|
* dwFlags [I] Only used when dwParam == KP_ALGID.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2007-01-29 14:49:46 +01:00
|
|
|
BOOL WINAPI CryptSetKeyParam (HCRYPTKEY hKey, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov;
|
|
|
|
PCRYPTKEY key = (PCRYPTKEY)hKey;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %p, %08x)\n", hKey, dwParam, pbData, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!key || !pbData || !key->pProvider ||
|
|
|
|
key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
prov = key->pProvider;
|
|
|
|
return prov->pFuncs->pCPSetKeyParam(prov->hPrivate, key->hPrivate,
|
|
|
|
dwParam, pbData, dwFlags);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptSetProviderA (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Specifies the current user's default CSP.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pszProvName [I] Name of the new default CSP.
|
|
|
|
* dwProvType [I] Provider type of the CSP.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptSetProviderA (LPCSTR pszProvName, DWORD dwProvType)
|
|
|
|
{
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%s, %d)\n", pszProvName, dwProvType);
|
2002-01-10 20:29:40 +01:00
|
|
|
return CryptSetProviderExA(pszProvName, dwProvType, NULL, CRYPT_USER_DEFAULT);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptSetProviderW (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
2005-11-04 12:43:27 +01:00
|
|
|
* See CryptSetProviderA.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CryptSetProviderW (LPCWSTR pszProvName, DWORD dwProvType)
|
|
|
|
{
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%s, %d)\n", debugstr_w(pszProvName), dwProvType);
|
2002-01-10 20:29:40 +01:00
|
|
|
return CryptSetProviderExW(pszProvName, dwProvType, NULL, CRYPT_USER_DEFAULT);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2005-09-28 13:59:04 +02:00
|
|
|
* CryptSetProviderExW (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Specifies the default CSP.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pszProvName [I] Name of the new default CSP.
|
|
|
|
* dwProvType [I] Provider type of the CSP.
|
|
|
|
* pdwReserved [I] Reserved for future use and must be NULL.
|
|
|
|
* dwFlags [I] See MSDN Doc.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2005-09-28 13:59:04 +02:00
|
|
|
BOOL WINAPI CryptSetProviderExW (LPCWSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2004-08-31 01:57:18 +02:00
|
|
|
HKEY hProvKey, hTypeKey;
|
2005-09-28 13:59:04 +02:00
|
|
|
PWSTR keyname;
|
|
|
|
static const WCHAR nameW[] = {'N','a','m','e',0};
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%s, %d, %p, %08x)\n", debugstr_w(pszProvName), dwProvType, pdwReserved, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (!pszProvName || pdwReserved)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-22 00:25:17 +02:00
|
|
|
if (dwProvType > MAXPROVTYPES)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(NTE_BAD_PROV_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
if (dwFlags & ~(CRYPT_MACHINE_DEFAULT | CRYPT_USER_DEFAULT | CRYPT_DELETE_DEFAULT)
|
|
|
|
|| dwFlags == CRYPT_DELETE_DEFAULT)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(NTE_BAD_FLAGS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-08-31 01:57:18 +02:00
|
|
|
if (!(keyname = CRYPT_GetTypeKeyName(dwProvType, dwFlags & CRYPT_USER_DEFAULT)))
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
2004-08-31 01:57:18 +02:00
|
|
|
keyname, &hTypeKey))
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
|
|
|
CRYPT_Free(keyname);
|
2007-01-05 12:45:46 +01:00
|
|
|
SetLastError(NTE_BAD_PROVIDER);
|
|
|
|
return FALSE;
|
2002-01-10 20:29:40 +01:00
|
|
|
}
|
|
|
|
CRYPT_Free(keyname);
|
2004-08-31 01:57:18 +02:00
|
|
|
|
|
|
|
if (dwFlags & CRYPT_DELETE_DEFAULT)
|
|
|
|
{
|
2005-09-28 13:59:04 +02:00
|
|
|
RegDeleteValueW(hTypeKey, nameW);
|
2004-08-31 01:57:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(keyname = CRYPT_GetProvKeyName(pszProvName)))
|
|
|
|
{
|
|
|
|
RegCloseKey(hTypeKey);
|
2007-01-05 12:45:46 +01:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
2004-08-31 01:57:18 +02:00
|
|
|
}
|
2005-09-28 13:59:04 +02:00
|
|
|
if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
2004-08-31 01:57:18 +02:00
|
|
|
keyname, &hProvKey))
|
|
|
|
{
|
|
|
|
CRYPT_Free(keyname);
|
|
|
|
RegCloseKey(hTypeKey);
|
2007-01-05 12:45:46 +01:00
|
|
|
SetLastError(NTE_BAD_PROVIDER);
|
|
|
|
return FALSE;
|
2004-08-31 01:57:18 +02:00
|
|
|
}
|
|
|
|
CRYPT_Free(keyname);
|
|
|
|
|
2006-08-25 23:14:38 +02:00
|
|
|
if (RegSetValueExW(hTypeKey, nameW, 0, REG_SZ, (const BYTE *)pszProvName,
|
|
|
|
(strlenW(pszProvName) + 1)*sizeof(WCHAR)))
|
2004-08-31 01:57:18 +02:00
|
|
|
{
|
|
|
|
RegCloseKey(hTypeKey);
|
|
|
|
RegCloseKey(hProvKey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hProvKey);
|
|
|
|
}
|
|
|
|
RegCloseKey(hTypeKey);
|
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
return TRUE;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2005-09-28 13:59:04 +02:00
|
|
|
* CryptSetProviderExA (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
2005-11-04 12:43:27 +01:00
|
|
|
* See CryptSetProviderExW.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2005-09-28 13:59:04 +02:00
|
|
|
BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
BOOL ret = FALSE;
|
2005-09-28 13:59:04 +02:00
|
|
|
PWSTR str = NULL;
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(%s, %d, %p, %08x)\n", pszProvName, dwProvType, pdwReserved, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2005-09-28 13:59:04 +02:00
|
|
|
if (CRYPT_ANSIToUnicode(pszProvName, &str, -1))
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
2005-09-28 13:59:04 +02:00
|
|
|
ret = CryptSetProviderExW(str, dwProvType, pdwReserved, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
CRYPT_Free(str);
|
|
|
|
}
|
|
|
|
return ret;
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CryptSetProvParam (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Customizes the operations of a CSP.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProv [I] Handle of a CSP.
|
|
|
|
* dwParam [I] See MSDN Doc.
|
|
|
|
* pbData [I] Buffer that contains a value to set as a parameter.
|
|
|
|
* dwFlags [I] if dwParam is PP_USE_HARDWARE_RNG, dwFlags must be zero.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2007-01-29 14:49:46 +01:00
|
|
|
BOOL WINAPI CryptSetProvParam (HCRYPTPROV hProv, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTPROV prov = (PCRYPTPROV)hProv;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %d, %p, %08x)\n", hProv, dwParam, pbData, dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
|
|
|
if (!prov)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-04-11 14:55:36 +02:00
|
|
|
if (prov->dwMagic != MAGIC_CRYPTPROV)
|
2007-01-05 12:45:46 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-10 20:29:40 +01:00
|
|
|
if (dwFlags & PP_USE_HARDWARE_RNG)
|
|
|
|
{
|
|
|
|
FIXME("PP_USE_HARDWARE_RNG: What do I do with this?\n");
|
|
|
|
FIXME("\tLetting the CSP decide.\n");
|
|
|
|
}
|
|
|
|
if (dwFlags & PP_CLIENT_HWND)
|
|
|
|
{
|
2002-04-29 20:48:56 +02:00
|
|
|
/* FIXME: Should verify the parameter */
|
|
|
|
if (pbData /* && IsWindow((HWND)pbData) */)
|
2002-01-10 20:29:40 +01:00
|
|
|
{
|
|
|
|
crypt_hWindow = (HWND)(pbData);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2002-04-29 20:48:56 +02:00
|
|
|
/* All other flags go to the CSP */
|
2002-01-10 20:29:40 +01:00
|
|
|
return prov->pFuncs->pCPSetProvParam(prov->hPrivate, dwParam, pbData, dwFlags);
|
2001-09-12 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2002-01-10 20:29:40 +01:00
|
|
|
* CryptVerifySignatureW (ADVAPI32.@)
|
2004-07-13 01:32:10 +02:00
|
|
|
*
|
|
|
|
* Verifies the signature of a hash object.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hHash [I] Handle of the hash object to verify.
|
|
|
|
* pbSignature [I] Signature data to verify.
|
|
|
|
* dwSigLen [I] Size of pbSignature.
|
|
|
|
* hPubKey [I] Handle to the public key to authenticate signature.
|
2004-12-21 15:34:18 +01:00
|
|
|
* sDescription [I] Should be NULL.
|
2004-07-13 01:32:10 +02:00
|
|
|
* dwFlags [I] See MSDN doc.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2004-12-21 15:34:18 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Because of security flaws sDescription should not be used and should thus be
|
|
|
|
* NULL. It is supported only for compatibility with Microsoft's Cryptographic
|
|
|
|
* Providers.
|
2001-09-12 19:09:56 +02:00
|
|
|
*/
|
2007-01-29 14:49:46 +01:00
|
|
|
BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, CONST BYTE *pbSignature, DWORD dwSigLen,
|
2004-12-21 15:34:18 +01:00
|
|
|
HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags)
|
2001-09-12 19:09:56 +02:00
|
|
|
{
|
2002-01-10 20:29:40 +01:00
|
|
|
PCRYPTHASH hash = (PCRYPTHASH)hHash;
|
|
|
|
PCRYPTKEY key = (PCRYPTKEY)hPubKey;
|
|
|
|
PCRYPTPROV prov;
|
2001-09-12 19:09:56 +02:00
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature,
|
2004-12-21 15:34:18 +01:00
|
|
|
dwSigLen, hPubKey, debugstr_w(sDescription), dwFlags);
|
2002-01-10 20:29:40 +01:00
|
|
|
|
2010-08-18 02:14:42 +02:00
|
|
|
if (!hash || !key || key->dwMagic != MAGIC_CRYPTKEY || hash->dwMagic != MAGIC_CRYPTHASH ||
|
2005-04-11 14:55:36 +02:00
|
|
|
!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV ||
|
|
|
|
!key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
|
|
|
|
{
|
2007-01-05 12:45:46 +01:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
2005-04-11 14:55:36 +02:00
|
|
|
}
|
|
|
|
|
2002-01-10 20:29:40 +01:00
|
|
|
prov = hash->pProvider;
|
|
|
|
return prov->pFuncs->pCPVerifySignature(prov->hPrivate, hash->hPrivate, pbSignature, dwSigLen,
|
2004-12-21 15:34:18 +01:00
|
|
|
key->hPrivate, sDescription, dwFlags);
|
2000-10-24 03:39:29 +02:00
|
|
|
}
|
2004-04-17 02:23:50 +02:00
|
|
|
|
2004-12-21 15:34:18 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* CryptVerifySignatureA (ADVAPI32.@)
|
|
|
|
*
|
2005-11-04 12:43:27 +01:00
|
|
|
* See CryptVerifySignatureW.
|
2004-12-21 15:34:18 +01:00
|
|
|
*/
|
2007-01-29 14:49:46 +01:00
|
|
|
BOOL WINAPI CryptVerifySignatureA (HCRYPTHASH hHash, CONST BYTE *pbSignature, DWORD dwSigLen,
|
2004-12-21 15:34:18 +01:00
|
|
|
HCRYPTKEY hPubKey, LPCSTR sDescription, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
LPWSTR wsDescription;
|
|
|
|
BOOL result;
|
|
|
|
|
2006-10-03 15:48:41 +02:00
|
|
|
TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature,
|
2004-12-21 15:34:18 +01:00
|
|
|
dwSigLen, hPubKey, debugstr_a(sDescription), dwFlags);
|
|
|
|
|
|
|
|
CRYPT_ANSIToUnicode(sDescription, &wsDescription, -1);
|
|
|
|
result = CryptVerifySignatureW(hHash, pbSignature, dwSigLen, hPubKey, wsDescription, dwFlags);
|
2006-11-30 05:50:58 +01:00
|
|
|
CRYPT_Free(wsDescription);
|
2004-12-21 15:34:18 +01:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2004-04-17 02:23:50 +02:00
|
|
|
|
2006-06-04 12:40:54 +02:00
|
|
|
/******************************************************************************
|
2006-06-05 18:42:52 +02:00
|
|
|
* SystemFunction030 (ADVAPI32.@)
|
2006-06-04 12:40:54 +02:00
|
|
|
*
|
|
|
|
* Tests if two blocks of 16 bytes are equal
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* b1,b2 [I] block of 16 bytes
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if blocks are the same
|
|
|
|
* FALSE if blocks are different
|
|
|
|
*/
|
2009-03-26 22:23:50 +01:00
|
|
|
BOOL WINAPI SystemFunction030(LPCVOID b1, LPCVOID b2)
|
2006-06-04 12:40:54 +02:00
|
|
|
{
|
|
|
|
return !memcmp(b1, b2, 0x10);
|
|
|
|
}
|
|
|
|
|
2006-06-23 09:15:24 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* SystemFunction035 (ADVAPI32.@)
|
|
|
|
*
|
|
|
|
* Described here:
|
|
|
|
http://disc.server.com/discussion.cgi?disc=148775;article=942;title=Coding%2FASM%2FSystem
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Stub, always return TRUE.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SystemFunction035(LPCSTR lpszDllFilePath)
|
|
|
|
{
|
|
|
|
FIXME("%s: stub\n", debugstr_a(lpszDllFilePath));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-05-23 14:08:00 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* SystemFunction036 (ADVAPI32.@)
|
|
|
|
*
|
|
|
|
* MSDN documents this function as RtlGenRandom and declares it in ntsecapi.h
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pbBufer [O] Pointer to memory to receive random bytes.
|
|
|
|
* dwLen [I] Number of random bytes to fetch.
|
2005-11-04 12:43:27 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2005-05-23 14:08:00 +02:00
|
|
|
*/
|
|
|
|
|
2010-03-21 16:30:58 +01:00
|
|
|
BOOLEAN WINAPI SystemFunction036(PVOID pbBuffer, ULONG dwLen)
|
2005-05-23 14:08:00 +02:00
|
|
|
{
|
|
|
|
int dev_random;
|
|
|
|
|
|
|
|
dev_random = open("/dev/urandom", O_RDONLY);
|
|
|
|
if (dev_random != -1)
|
|
|
|
{
|
|
|
|
if (read(dev_random, pbBuffer, dwLen) == (ssize_t)dwLen)
|
|
|
|
{
|
|
|
|
close(dev_random);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
close(dev_random);
|
|
|
|
}
|
2008-10-23 20:38:04 +02:00
|
|
|
else
|
|
|
|
FIXME("couldn't open /dev/urandom\n");
|
2005-05-23 14:08:00 +02:00
|
|
|
SetLastError(NTE_FAIL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-04-17 02:23:50 +02:00
|
|
|
/*
|
|
|
|
These functions have nearly identical prototypes to CryptProtectMemory and CryptUnprotectMemory,
|
|
|
|
in crypt32.dll.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SystemFunction040 (ADVAPI32.@)
|
|
|
|
*
|
2010-03-21 16:31:02 +01:00
|
|
|
* MSDN documents this function as RtlEncryptMemory and declares it in ntsecapi.h.
|
2005-04-20 17:18:42 +02:00
|
|
|
*
|
2004-12-14 16:26:04 +01:00
|
|
|
* PARAMS
|
|
|
|
* memory [I/O] Pointer to memory to encrypt.
|
|
|
|
* length [I] Length of region to encrypt in bytes.
|
|
|
|
* flags [I] Control whether other processes are able to decrypt the memory.
|
|
|
|
* RTL_ENCRYPT_OPTION_SAME_PROCESS
|
|
|
|
* RTL_ENCRYPT_OPTION_CROSS_PROCESS
|
|
|
|
* RTL_ENCRYPT_OPTION_SAME_LOGON
|
|
|
|
*
|
2005-11-04 12:43:27 +01:00
|
|
|
* RETURNS
|
|
|
|
* Success: STATUS_SUCCESS
|
|
|
|
* Failure: NTSTATUS error code
|
|
|
|
*
|
2004-12-14 16:26:04 +01:00
|
|
|
* NOTES
|
|
|
|
* length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
|
|
|
|
* If flags are specified when encrypting, the same flag value must be given
|
|
|
|
* when decrypting the memory.
|
2004-04-17 02:23:50 +02:00
|
|
|
*/
|
2005-04-20 17:18:42 +02:00
|
|
|
NTSTATUS WINAPI SystemFunction040(PVOID memory, ULONG length, ULONG flags)
|
2004-04-17 02:23:50 +02:00
|
|
|
{
|
2006-10-03 15:48:41 +02:00
|
|
|
FIXME("(%p, %x, %x): stub [RtlEncryptMemory]\n", memory, length, flags);
|
2004-04-17 02:23:50 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SystemFunction041 (ADVAPI32.@)
|
|
|
|
*
|
2010-03-21 16:31:02 +01:00
|
|
|
* MSDN documents this function as RtlDecryptMemory and declares it in ntsecapi.h.
|
2005-04-20 17:18:42 +02:00
|
|
|
*
|
2004-12-14 16:26:04 +01:00
|
|
|
* PARAMS
|
|
|
|
* memory [I/O] Pointer to memory to decrypt.
|
|
|
|
* length [I] Length of region to decrypt in bytes.
|
|
|
|
* flags [I] Control whether other processes are able to decrypt the memory.
|
|
|
|
* RTL_ENCRYPT_OPTION_SAME_PROCESS
|
|
|
|
* RTL_ENCRYPT_OPTION_CROSS_PROCESS
|
|
|
|
* RTL_ENCRYPT_OPTION_SAME_LOGON
|
|
|
|
*
|
2005-11-04 12:43:27 +01:00
|
|
|
* RETURNS
|
|
|
|
* Success: STATUS_SUCCESS
|
|
|
|
* Failure: NTSTATUS error code
|
|
|
|
*
|
2004-12-14 16:26:04 +01:00
|
|
|
* NOTES
|
|
|
|
* length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
|
|
|
|
* If flags are specified when encrypting, the same flag value must be given
|
|
|
|
* when decrypting the memory.
|
2004-04-17 02:23:50 +02:00
|
|
|
*/
|
2005-04-20 17:18:42 +02:00
|
|
|
NTSTATUS WINAPI SystemFunction041(PVOID memory, ULONG length, ULONG flags)
|
2004-04-17 02:23:50 +02:00
|
|
|
{
|
2006-10-03 15:48:41 +02:00
|
|
|
FIXME("(%p, %x, %x): stub [RtlDecryptMemory]\n", memory, length, flags);
|
2004-04-17 02:23:50 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|