Author: cwittich
Date: Thu Mar 4 14:36:55 2010
New Revision: 45832
URL:
http://svn.reactos.org/svn/reactos?rev=45832&view=rev
Log:
[RSAENH]
sync rsaenh to wine 1.1.39
Modified:
trunk/reactos/dll/win32/rsaenh/rsaenh.c
Modified: trunk/reactos/dll/win32/rsaenh/rsaenh.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/rsaenh/rsaenh.c?…
==============================================================================
--- trunk/reactos/dll/win32/rsaenh/rsaenh.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/rsaenh/rsaenh.c [iso-8859-1] Thu Mar 4 14:36:55 2010
@@ -1219,6 +1219,8 @@
store_key_container_permissions(pKeyContainer);
release_key_container_keys(pKeyContainer);
}
+ else
+ release_key_container_keys(pKeyContainer);
HeapFree( GetProcessHeap(), 0, pKeyContainer );
}
@@ -1378,12 +1380,18 @@
(OBJECTHDR**)&pKeyContainer))
return (HCRYPTPROV)INVALID_HANDLE_VALUE;
+ /* read_key_value calls import_key, which calls import_private_key,
+ * which implicitly installs the key value into the appropriate key
+ * container key. Thus the ref count is incremented twice, once for
+ * the output key value, and once for the implicit install, and needs
+ * to be decremented to balance the two.
+ */
if (read_key_value(hKeyContainer, hKey, AT_KEYEXCHANGE,
dwProtectFlags, &hCryptKey))
- pKeyContainer->hKeyExchangeKeyPair = hCryptKey;
+ release_handle(&handle_table, hCryptKey, RSAENH_MAGIC_KEY);
if (read_key_value(hKeyContainer, hKey, AT_SIGNATURE,
dwProtectFlags, &hCryptKey))
- pKeyContainer->hSignatureKeyPair = hCryptKey;
+ release_handle(&handle_table, hCryptKey, RSAENH_MAGIC_KEY);
}
return hKeyContainer;
@@ -3065,9 +3073,9 @@
if (pCryptKey) {
new_key_impl(pCryptKey->aiAlgid, &pCryptKey->context,
pCryptKey->dwKeyLen);
setup_key(pCryptKey);
- RSAENH_CPDestroyKey(hProv, pKeyContainer->hSignatureKeyPair);
- copy_handle(&handle_table, *phKey, RSAENH_MAGIC_KEY,
- &pKeyContainer->hSignatureKeyPair);
+ release_and_install_key(hProv, *phKey,
+ &pKeyContainer->hSignatureKeyPair,
+ FALSE);
}
break;
@@ -3077,9 +3085,9 @@
if (pCryptKey) {
new_key_impl(pCryptKey->aiAlgid, &pCryptKey->context,
pCryptKey->dwKeyLen);
setup_key(pCryptKey);
- RSAENH_CPDestroyKey(hProv, pKeyContainer->hKeyExchangeKeyPair);
- copy_handle(&handle_table, *phKey, RSAENH_MAGIC_KEY,
- &pKeyContainer->hKeyExchangeKeyPair);
+ release_and_install_key(hProv, *phKey,
+ &pKeyContainer->hKeyExchangeKeyPair,
+ FALSE);
}
break;
@@ -4162,11 +4170,12 @@
LPCWSTR sDescription, DWORD dwFlags, BYTE *pbSignature,
DWORD *pdwSigLen)
{
- HCRYPTKEY hCryptKey;
+ HCRYPTKEY hCryptKey = (HCRYPTKEY)INVALID_HANDLE_VALUE;
CRYPTKEY *pCryptKey;
DWORD dwHashLen;
BYTE abHashValue[RSAENH_MAX_HASH_SIZE];
ALG_ID aiAlgid;
+ BOOL ret = FALSE;
TRACE("(hProv=%08lx, hHash=%08lx, dwKeySpec=%08x, sDescription=%s, dwFlags=%08x,
"
"pbSignature=%p, pdwSigLen=%p)\n", hProv, hHash, dwKeySpec,
debugstr_w(sDescription),
@@ -4183,18 +4192,19 @@
(OBJECTHDR**)&pCryptKey))
{
SetLastError(NTE_NO_KEY);
- return FALSE;
+ goto out;
}
if (!pbSignature) {
*pdwSigLen = pCryptKey->dwKeyLen;
- return TRUE;
+ ret = TRUE;
+ goto out;
}
if (pCryptKey->dwKeyLen > *pdwSigLen)
{
SetLastError(ERROR_MORE_DATA);
*pdwSigLen = pCryptKey->dwKeyLen;
- return FALSE;
+ goto out;
}
*pdwSigLen = pCryptKey->dwKeyLen;
@@ -4202,22 +4212,25 @@
if (!RSAENH_CPHashData(hProv, hHash, (CONST BYTE*)sDescription,
(DWORD)lstrlenW(sDescription)*sizeof(WCHAR), 0))
{
- return FALSE;
+ goto out;
}
}
dwHashLen = sizeof(DWORD);
- if (!RSAENH_CPGetHashParam(hProv, hHash, HP_ALGID, (BYTE*)&aiAlgid,
&dwHashLen, 0)) return FALSE;
+ if (!RSAENH_CPGetHashParam(hProv, hHash, HP_ALGID, (BYTE*)&aiAlgid,
&dwHashLen, 0)) goto out;
dwHashLen = RSAENH_MAX_HASH_SIZE;
- if (!RSAENH_CPGetHashParam(hProv, hHash, HP_HASHVAL, abHashValue, &dwHashLen, 0))
return FALSE;
+ if (!RSAENH_CPGetHashParam(hProv, hHash, HP_HASHVAL, abHashValue, &dwHashLen, 0))
goto out;
if (!build_hash_signature(pbSignature, *pdwSigLen, aiAlgid, abHashValue, dwHashLen,
dwFlags)) {
- return FALSE;
- }
-
- return encrypt_block_impl(pCryptKey->aiAlgid, PK_PRIVATE,
&pCryptKey->context, pbSignature, pbSignature, RSAENH_ENCRYPT);
+ goto out;
+ }
+
+ ret = encrypt_block_impl(pCryptKey->aiAlgid, PK_PRIVATE,
&pCryptKey->context, pbSignature, pbSignature, RSAENH_ENCRYPT);
+out:
+ RSAENH_CPDestroyKey(hProv, hCryptKey);
+ return ret;
}
/******************************************************************************