*/
#include <advapi32.h>
-#include "crypt.h"
-
-#include <wine/unicode.h>
-#include <wine/debug.h>
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
-
-/*
- * Note: this code is harmless on little-endian machines.
- */
-VOID byteReverse(unsigned char *buf, unsigned longs)
-{
- unsigned int t;
-
- do
- {
- t = (unsigned int)((unsigned)buf[3] << 8 | buf[2]) << 16 |
- ((unsigned)buf[1] << 8 | buf[0]);
- *(unsigned int *)buf = t;
- buf += 4;
- } while (--longs);
-}
-
-static HWND crypt_hWindow ;
+static HWND crypt_hWindow;
#define CRYPT_Alloc(size) (LocalAlloc(LMEM_ZEROINIT, size))
#define CRYPT_Free(buffer) (LocalFree(buffer))
return keyname;
}
-/* CRYPT_UnicodeTOANSI
+/* 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
+ * str - pointer to ANSI string or pointer to null pointer if we have to do the allocation
+ * strsize - size of buffer pointed to by str
*
* returns TRUE if unsuccessful, FALSE otherwise.
* 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));
- else
- count = min( count, strsize );
+
+ if (!*str)
+ {
+ strsize = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
+ *str = CRYPT_Alloc(strsize * sizeof(CHAR));
+ }
+ else if (strsize < 0)
+ {
+ strsize = INT_MAX; /* windows will pretend that the buffer is infinitely long */
+ }
+
if (*str)
{
- WideCharToMultiByte(CP_ACP, 0, wstr, -1, *str, count, NULL, NULL);
+ WideCharToMultiByte(CP_ACP, 0, wstr, -1, *str, strsize, NULL, NULL);
return TRUE;
}
+
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
return TRUE;
}
-static BOOL CALLBACK CRYPT_ReturnhWnd(HWND *phWnd)
+static void CALLBACK CRYPT_ReturnhWnd(HWND *phWnd)
{
- if (!phWnd)
- return FALSE;
- *phWnd = crypt_hWindow;
- return TRUE;
+ if (phWnd) *phWnd = crypt_hWindow;
}
#define CRYPT_GetProvFunc(name) \
/* FIXME: Not sure what the pbContextInfo field is for.
* Does it need memory allocation?
- */
+ */
provider->pVTable->Version = 3;
- provider->pVTable->pFuncVerifyImage = CRYPT_VerifyImage;
- provider->pVTable->pFuncReturnhWnd = CRYPT_ReturnhWnd;
+ provider->pVTable->FuncVerifyImage = CRYPT_VerifyImage;
+ provider->pVTable->FuncReturnhWnd = CRYPT_ReturnhWnd;
provider->pVTable->dwProvType = 0;
provider->pVTable->pbContextInfo = NULL;
provider->pVTable->cbContextInfo = 0;
* dwProvType [I] Crypto provider type to get a handle.
* dwFlags [I] flags for the operation
*
- * RETURNS
+ * RETURNS
* TRUE on success, FALSE on failure.
*/
BOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR pszContainer,
SetLastError(NTE_BAD_PROV_TYPE);
return FALSE;
}
-
+
if (!phProv)
{
SetLastError(ERROR_INVALID_PARAMETER);
goto error;
}
pProv->pVTable->dwProvType = dwProvType;
- if(!CRYPT_UnicodeToANSI(provname, &provnameA, -1))
+ if(!CRYPT_UnicodeToANSI(provname, &provnameA, 0))
{
/* CRYPT_UnicodeToANSI calls SetLastError */
goto error;
}
pProv->pVTable->pszProvName = provnameA;
- if(!CRYPT_UnicodeToANSI(pszContainer, &pszContainerA, -1))
+ if(!CRYPT_UnicodeToANSI(pszContainer, &pszContainerA, 0))
{
/* CRYPT_UnicodeToANSI calls SetLastError */
goto error;
PWSTR pProvider = NULL, pContainer = NULL;
BOOL ret = FALSE;
- TRACE("(%p, %s, %s, %d, %08x)\n", phProv, pszContainer,
- pszProvider, dwProvType, dwFlags);
+ TRACE("(%p, %s, %s, %d, %08x)\n", phProv, debugstr_a(pszContainer),
+ debugstr_a(pszProvider), dwProvType, dwFlags);
if ( !CRYPT_ANSIToUnicode(pszContainer, &pContainer, -1) )
{
*/
BOOL WINAPI CryptContextAddRef (HCRYPTPROV hProv, DWORD *pdwReserved, DWORD dwFlags)
{
- PCRYPTPROV pProv = (PCRYPTPROV)hProv;
+ PCRYPTPROV pProv = (PCRYPTPROV)hProv;
TRACE("(0x%lx, %p, %08x)\n", hProv, pdwReserved, dwFlags);
}
pProv->refcount--;
- if (pProv->refcount <= 0)
+ if (pProv->refcount <= 0)
{
ret = pProv->pFuncs->pCPReleaseContext(pProv->hPrivate, dwFlags);
pProv->dwMagic = 0;
TRACE("(0x%lx, 0x%x, 0x%lx, %08x, %p)\n", hProv, Algid, hKey, dwFlags, phHash);
- if (!prov)
- {
- SetLastError(ERROR_INVALID_HANDLE);
- return FALSE;
- }
- if (!phHash || prov->dwMagic != MAGIC_CRYPTPROV)
+ if (!prov || !phHash || prov->dwMagic != MAGIC_CRYPTPROV ||
+ (key && key->dwMagic != MAGIC_CRYPTKEY))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
hash->pProvider = prov;
-
+ hash->dwMagic = MAGIC_CRYPTHASH;
if (prov->pFuncs->pCPCreateHash(prov->hPrivate, Algid,
key ? key->hPrivate : 0, 0, &hash->hPrivate))
{
}
/* CSP error! */
+ hash->dwMagic = 0;
CRYPT_Free(hash);
*phHash = 0;
return FALSE;
TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hHash, Final, dwFlags, pbData, pdwDataLen);
- if (!key || !pbData || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!key || !pbData || !pdwDataLen ||
+ !key->pProvider || key->dwMagic != MAGIC_CRYPTKEY ||
+ key->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
- if (!phKey || prov->dwMagic != MAGIC_CRYPTPROV)
+ if (!phKey || prov->dwMagic != MAGIC_CRYPTPROV || hash->dwMagic != MAGIC_CRYPTHASH)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
key->pProvider = prov;
+ key->dwMagic = MAGIC_CRYPTKEY;
if (prov->pFuncs->pCPDeriveKey(prov->hPrivate, Algid, hash->hPrivate, dwFlags, &key->hPrivate))
{
*phKey = (HCRYPTKEY)key;
}
/* CSP error! */
+ key->dwMagic = 0;
CRYPT_Free(key);
*phKey = 0;
return FALSE;
return FALSE;
}
- if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
+ hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
prov = hash->pProvider;
ret = prov->pFuncs->pCPDestroyHash(prov->hPrivate, hash->hPrivate);
+ hash->dwMagic = 0;
CRYPT_Free(hash);
return ret;
}
return FALSE;
}
- if (!key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!key->pProvider || key->dwMagic != MAGIC_CRYPTKEY ||
+ key->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
prov = key->pProvider;
ret = prov->pFuncs->pCPDestroyKey(prov->hPrivate, key->hPrivate);
+ key->dwMagic = 0;
CRYPT_Free(key);
return ret;
}
TRACE("(0x%lx, %p, %08x, %p)\n", hHash, pdwReserved, dwFlags, phHash);
orghash = (PCRYPTHASH)hHash;
- if (!orghash || pdwReserved || !phHash || !orghash->pProvider ||
- orghash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!orghash || pdwReserved || !phHash || !orghash->pProvider ||
+ orghash->dwMagic != MAGIC_CRYPTHASH || orghash->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
newhash->pProvider = prov;
+ newhash->dwMagic = MAGIC_CRYPTHASH;
if (prov->pFuncs->pCPDuplicateHash(prov->hPrivate, orghash->hPrivate, pdwReserved, dwFlags, &newhash->hPrivate))
{
*phHash = (HCRYPTHASH)newhash;
return TRUE;
}
+ newhash->dwMagic = 0;
CRYPT_Free(newhash);
return FALSE;
}
TRACE("(0x%lx, %p, %08x, %p)\n", hKey, pdwReserved, dwFlags, phKey);
orgkey = (PCRYPTKEY)hKey;
- if (!orgkey || pdwReserved || !phKey || !orgkey->pProvider ||
+ if (!orgkey || pdwReserved || !phKey || !orgkey->pProvider ||
+ orgkey->dwMagic != MAGIC_CRYPTKEY ||
orgkey->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
}
newkey->pProvider = prov;
+ newkey->dwMagic = MAGIC_CRYPTKEY;
if (prov->pFuncs->pCPDuplicateKey(prov->hPrivate, orgkey->hPrivate, pdwReserved, dwFlags, &newkey->hPrivate))
{
*phKey = (HCRYPTKEY)newkey;
return TRUE;
}
+ newkey->dwMagic = 0;
CRYPT_Free(newkey);
return FALSE;
}
TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p, %d)\n", hKey, hHash, Final, dwFlags, pbData, pdwDataLen, dwBufLen);
- if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!key || !pdwDataLen || !key->pProvider ||
+ key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
'P','r','o','v','i','d','e','r',0
};
static const WCHAR typeW[] = {'T','y','p','e',0};
+ BOOL ret;
TRACE("(%d, %p, %d, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
pdwProvType, pszProvName, pcbProvName);
return FALSE;
}
+ ret = TRUE;
if (!pszProvName)
{
DWORD numkeys;
WCHAR *provNameW;
-
+
RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &numkeys, pcbProvName,
NULL, NULL, NULL, NULL, NULL, NULL);
-
+
if (!(provNameW = CRYPT_Alloc(*pcbProvName * sizeof(WCHAR))))
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ RegCloseKey(hKey);
return FALSE;
}
if (dwIndex >= numkeys)
{
SetLastError(ERROR_NO_MORE_ITEMS);
- return FALSE;
+ ret = FALSE;
}
} else {
DWORD size = sizeof(DWORD);
DWORD result;
HKEY subkey;
-
+
result = RegEnumKeyW(hKey, dwIndex, pszProvName, *pcbProvName / sizeof(WCHAR));
if (result)
{
SetLastError(result);
+ RegCloseKey(hKey);
return FALSE;
}
if (RegOpenKeyW(hKey, pszProvName, &subkey))
+ {
+ RegCloseKey(hKey);
return FALSE;
+ }
+
if (RegQueryValueExW(subkey, typeW, NULL, NULL, (BYTE*)pdwProvType, &size))
- return FALSE;
+ ret = FALSE;
+
RegCloseKey(subkey);
}
RegCloseKey(hKey);
- return TRUE;
+ return ret;
}
/******************************************************************************
{
PWSTR str = NULL;
DWORD bufsize;
- BOOL ret; /* = FALSE; */
+ BOOL ret;
TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
pdwProvType, pszProvName, pcbProvName);
if (dwIndex >= numkeys)
{
SetLastError(ERROR_NO_MORE_ITEMS);
+ RegCloseKey(hKey);
return FALSE;
}
keylen++;
if ( !(keyname = CRYPT_Alloc(keylen*sizeof(WCHAR))) )
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ RegCloseKey(hKey);
return FALSE;
}
if ( RegEnumKeyW(hKey, dwIndex, keyname, keylen) ) {
CRYPT_Free(keyname);
+ RegCloseKey(hKey);
return FALSE;
}
RegOpenKeyW(hKey, keyname, &hSubkey);
+ RegCloseKey(hKey);
+
ch = keyname + strlenW(keyname);
/* Convert "Type 000" to 0, etc/ */
*pdwProvType = *(--ch) - '0';
*pdwProvType += (*(--ch) - '0') * 10;
*pdwProvType += (*(--ch) - '0') * 100;
CRYPT_Free(keyname);
-
+
result = RegQueryValueExW(hSubkey, typenameW, NULL, &dwType, (LPBYTE)pszTypeName, pcbTypeName);
if (result)
{
SetLastError(result);
+ RegCloseKey(hSubkey);
return FALSE;
}
RegCloseKey(hSubkey);
- RegCloseKey(hKey);
return TRUE;
}
/******************************************************************************
* CryptExportKey (ADVAPI32.@)
- *
+ *
* Exports a cryptographic key from a CSP.
*
* PARAMS
TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hExpKey, dwBlobType, dwFlags, pbData, pdwDataLen);
- if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!key || !pdwDataLen || !key->pProvider ||
+ key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
TRACE("(0x%lx, %d, %08x, %p)\n", hProv, Algid, dwFlags, phKey);
- if (!prov)
- {
- SetLastError(ERROR_INVALID_HANDLE);
- return FALSE;
- }
if (!phKey || !prov || prov->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
}
key->pProvider = prov;
-
+ key->dwMagic = MAGIC_CRYPTKEY;
if (prov->pFuncs->pCPGenKey(prov->hPrivate, Algid, dwFlags, &key->hPrivate))
{
*phKey = (HCRYPTKEY)key;
}
/* CSP error! */
+ key->dwMagic = 0;
CRYPT_Free(key);
return FALSE;
}
return FALSE;
}
CRYPT_Free(keyname);
-
- result = RegQueryValueExW(hKey, nameW, NULL, NULL, (LPBYTE)pszProvName, pcbProvName);
+
+ result = RegQueryValueExW(hKey, nameW, NULL, NULL, (LPBYTE)pszProvName, pcbProvName);
+ RegCloseKey(hKey);
+
if (result)
{
if (result != ERROR_MORE_DATA)
SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
else
SetLastError(result);
-
+
return FALSE;
}
-
- RegCloseKey(hKey);
+
return TRUE;
}
{
PWSTR str = NULL;
DWORD bufsize;
- BOOL ret = FALSE;
+ BOOL ret;
TRACE("(%d, %p, %08x, %p, %p)\n", dwProvType, pdwReserved, dwFlags, pszProvName, pcbProvName);
TRACE("(0x%lx, %d, %p, %p, %08x)\n", hHash, dwParam, pbData, pdwDataLen, dwFlags);
- if (!hash || !pdwDataLen || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!hash || !pdwDataLen || !hash->pProvider ||
+ hash->dwMagic != MAGIC_CRYPTHASH || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
TRACE("(0x%lx, %d, %p, %p, %08x)\n", hKey, dwParam, pbData, pdwDataLen, dwFlags);
- if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!key || !pdwDataLen || !key->pProvider ||
+ key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
key->pProvider = prov;
-
+ key->dwMagic = MAGIC_CRYPTKEY;
if (prov->pFuncs->pCPGetUserKey(prov->hPrivate, dwKeySpec, &key->hPrivate))
{
*phUserKey = (HCRYPTKEY)key;
}
/* CSP Error */
+ key->dwMagic = 0;
CRYPT_Free(key);
*phUserKey = 0;
return FALSE;
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
- if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
+ hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
*
* Compute the cryptographic hash of a session key object.
*
- * PARAMS
+ * PARAMS
* hHash [I] Handle to the hash object.
* hKey [I] Handle to the key to be hashed.
* dwFlags [I] Can be CRYPT_LITTLE_ENDIAN.
return FALSE;
}
- if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
+ hash->pProvider->dwMagic != MAGIC_CRYPTPROV || key->dwMagic != MAGIC_CRYPTKEY)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
* Success: TRUE
* Failure: FALSE
*/
-BOOL WINAPI CryptImportKey (HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
+BOOL WINAPI CryptImportKey (HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen,
HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
{
PCRYPTPROV prov = (PCRYPTPROV)hProv;
TRACE("(0x%lx, %p, %d, 0x%lx, %08x, %p)\n", hProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
- if (!prov || !pbData || !dwDataLen || !phKey || prov->dwMagic != MAGIC_CRYPTPROV)
+ if (!prov || !pbData || !dwDataLen || !phKey ||
+ prov->dwMagic != MAGIC_CRYPTPROV ||
+ (pubkey && pubkey->dwMagic != MAGIC_CRYPTKEY))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
importkey->pProvider = prov;
+ importkey->dwMagic = MAGIC_CRYPTKEY;
if (prov->pFuncs->pCPImportKey(prov->hPrivate, pbData, dwDataLen,
pubkey ? pubkey->hPrivate : 0, dwFlags, &importkey->hPrivate))
{
return TRUE;
}
+ importkey->dwMagic = 0;
CRYPT_Free(importkey);
return FALSE;
}
PCRYPTHASH hash = (PCRYPTHASH)hHash;
PCRYPTPROV prov;
- TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
+ TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
hHash, dwKeySpec, debugstr_w(sDescription), dwFlags, pbSignature, pdwSigLen);
if (!hash)
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
- if (!pdwSigLen || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!pdwSigLen || !hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
+ hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
LPWSTR wsDescription;
BOOL result;
- TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
+ TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n",
hHash, dwKeySpec, debugstr_a(sDescription), dwFlags, pbSignature, pdwSigLen);
CRYPT_ANSIToUnicode(sDescription, &wsDescription, -1);
* Success: TRUE
* Failure: FALSE
*/
-BOOL WINAPI CryptSetHashParam (HCRYPTHASH hHash, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
+BOOL WINAPI CryptSetHashParam (HCRYPTHASH hHash, DWORD dwParam, const BYTE *pbData, DWORD dwFlags)
{
PCRYPTPROV prov;
PCRYPTHASH hash = (PCRYPTHASH)hHash;
TRACE("(0x%lx, %d, %p, %08x)\n", hHash, dwParam, pbData, dwFlags);
- if (!hash || !pbData || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!hash || !pbData || !hash->pProvider ||
+ hash->dwMagic != MAGIC_CRYPTHASH || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
* Success: TRUE
* Failure: FALSE
*/
-BOOL WINAPI CryptSetKeyParam (HCRYPTKEY hKey, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
+BOOL WINAPI CryptSetKeyParam (HCRYPTKEY hKey, DWORD dwParam, const BYTE *pbData, DWORD dwFlags)
{
PCRYPTPROV prov;
PCRYPTKEY key = (PCRYPTKEY)hKey;
TRACE("(0x%lx, %d, %p, %08x)\n", hKey, dwParam, pbData, dwFlags);
- if (!key || !pbData || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
+ if (!key || !pbData || !key->pProvider ||
+ key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
return FALSE;
}
CRYPT_Free(keyname);
-
+
if (dwFlags & CRYPT_DELETE_DEFAULT)
{
RegDeleteValueW(hTypeKey, nameW);
return FALSE;
}
CRYPT_Free(keyname);
-
+
if (RegSetValueExW(hTypeKey, nameW, 0, REG_SZ, (const BYTE *)pszProvName,
(strlenW(pszProvName) + 1)*sizeof(WCHAR)))
{
RegCloseKey(hProvKey);
return FALSE;
}
-
+
RegCloseKey(hProvKey);
}
RegCloseKey(hTypeKey);
* Success: TRUE
* Failure: FALSE
*/
-BOOL WINAPI CryptSetProvParam (HCRYPTPROV hProv, DWORD dwParam, CONST BYTE *pbData, DWORD dwFlags)
+BOOL WINAPI CryptSetProvParam (HCRYPTPROV hProv, DWORD dwParam, const BYTE *pbData, DWORD dwFlags)
{
PCRYPTPROV prov = (PCRYPTPROV)hProv;
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
- if (dwFlags & PP_USE_HARDWARE_RNG)
+ if (dwParam == PP_USE_HARDWARE_RNG)
{
FIXME("PP_USE_HARDWARE_RNG: What do I do with this?\n");
FIXME("\tLetting the CSP decide.\n");
* RETURNS
* Success: TRUE
* Failure: FALSE
- *
+ *
* 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.
*/
-BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, CONST BYTE *pbSignature, DWORD dwSigLen,
+BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, const BYTE *pbSignature, DWORD dwSigLen,
HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags)
{
PCRYPTHASH hash = (PCRYPTHASH)hHash;
TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature,
dwSigLen, hPubKey, debugstr_w(sDescription), dwFlags);
- if (!hash || !key ||
+ if (!hash || !key || key->dwMagic != MAGIC_CRYPTKEY || hash->dwMagic != MAGIC_CRYPTHASH ||
!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV ||
!key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
-
+
prov = hash->pProvider;
return prov->pFuncs->pCPVerifySignature(prov->hPrivate, hash->hPrivate, pbSignature, dwSigLen,
key->hPrivate, sDescription, dwFlags);
*
* See CryptVerifySignatureW.
*/
-BOOL WINAPI CryptVerifySignatureA (HCRYPTHASH hHash, CONST BYTE *pbSignature, DWORD dwSigLen,
+BOOL WINAPI CryptVerifySignatureA (HCRYPTHASH hHash, const BYTE *pbSignature, DWORD dwSigLen,
HCRYPTKEY hPubKey, LPCSTR sDescription, DWORD dwFlags)
{
LPWSTR wsDescription;
return result;
}
+
+#ifndef __REACTOS__
+/******************************************************************************
+ * SystemFunction030 (ADVAPI32.@)
+ *
+ * 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
+ */
+BOOL WINAPI SystemFunction030(LPCVOID b1, LPCVOID b2)
+{
+ return !memcmp(b1, b2, 0x10);
+}
+
+/******************************************************************************
+ * 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;
+}
+
+/******************************************************************************
+ * 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.
+ *
+ * RETURNS
+ * Success: TRUE
+ * Failure: FALSE
+ */
+
+BOOLEAN WINAPI SystemFunction036(PVOID pbBuffer, ULONG dwLen)
+{
+ 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);
+ }
+ else
+ FIXME("couldn't open /dev/urandom\n");
+ SetLastError(NTE_FAIL);
+ return FALSE;
+}
+
+/*
+ These functions have nearly identical prototypes to CryptProtectMemory and CryptUnprotectMemory,
+ in crypt32.dll.
+ */
+
+/******************************************************************************
+ * SystemFunction040 (ADVAPI32.@)
+ *
+ * MSDN documents this function as RtlEncryptMemory and declares it in ntsecapi.h.
+ *
+ * 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
+ *
+ * RETURNS
+ * Success: STATUS_SUCCESS
+ * Failure: NTSTATUS error code
+ *
+ * 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.
+ */
+NTSTATUS WINAPI SystemFunction040(PVOID memory, ULONG length, ULONG flags)
+{
+ FIXME("(%p, %x, %x): stub [RtlEncryptMemory]\n", memory, length, flags);
+ return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction041 (ADVAPI32.@)
+ *
+ * MSDN documents this function as RtlDecryptMemory and declares it in ntsecapi.h.
+ *
+ * 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
+ *
+ * RETURNS
+ * Success: STATUS_SUCCESS
+ * Failure: NTSTATUS error code
+ *
+ * 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.
+ */
+NTSTATUS WINAPI SystemFunction041(PVOID memory, ULONG length, ULONG flags)
+{
+ FIXME("(%p, %x, %x): stub [RtlDecryptMemory]\n", memory, length, flags);
+ return STATUS_SUCCESS;
+}
+#endif /* !__REACTOS __ */
+
+/******************************************************************************
+ * WriteEncryptedFileRaw (ADVAPI32.@)
+ *
+ * Import encrypted files
+ *
+ * PARAMS
+ * import [I] pointer to the import callback function
+ * callback [I] pointer to the application defined context
+ * context [I] pointer to the system context
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: NTSTATUS error code
+ */
+DWORD WINAPI WriteEncryptedFileRaw(PFE_IMPORT_FUNC import, PVOID callback, PVOID context)
+{
+ FIXME("(%p, %p, %p): stub\n", import, callback, context);
+ return ERROR_CALL_NOT_IMPLEMENTED;
+}