Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/rsaenh/implglue.c | 20 ++++++++++---------- dlls/rsaenh/implglue.h | 14 +++++--------- dlls/rsaenh/rsaenh.c | 26 +++++++++++++------------- 3 files changed, 28 insertions(+), 32 deletions(-)
diff --git a/dlls/rsaenh/implglue.c b/dlls/rsaenh/implglue.c index 9d90ad70f53..d98a08b2f31 100644 --- a/dlls/rsaenh/implglue.c +++ b/dlls/rsaenh/implglue.c @@ -32,8 +32,8 @@
/* Function prototype copied from dlls/advapi32/crypt.c */ BOOL WINAPI SystemFunction036(PVOID pbBuffer, ULONG dwLen); - -BOOL init_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext) + +BOOL init_hash_impl(ALG_ID aiAlgid, BCRYPT_HASH_HANDLE *hash_handle) { BCRYPT_ALG_HANDLE provider; NTSTATUS status; @@ -74,27 +74,27 @@ BOOL init_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext)
if (status) return FALSE;
- status = BCryptCreateHash(provider, &pHashContext->bcrypt_hash, NULL, 0, NULL, 0, 0); + status = BCryptCreateHash(provider, hash_handle, NULL, 0, NULL, 0, 0); BCryptCloseAlgorithmProvider(provider, 0); return !status; }
-BOOL update_hash_impl(HASH_CONTEXT *pHashContext, const BYTE *pbData, DWORD dwDataLen) +BOOL update_hash_impl(BCRYPT_HASH_HANDLE hash_handle, const BYTE *pbData, DWORD dwDataLen) { - BCryptHashData(pHashContext->bcrypt_hash, (UCHAR*)pbData, dwDataLen, 0); + BCryptHashData(hash_handle, (UCHAR*)pbData, dwDataLen, 0); return TRUE; }
-BOOL finalize_hash_impl(HASH_CONTEXT *pHashContext, BYTE *pbHashValue) +BOOL finalize_hash_impl(BCRYPT_HASH_HANDLE hash_handle, BYTE *pbHashValue) { - BCryptFinishHash(pHashContext->bcrypt_hash, pbHashValue, RSAENH_MAX_HASH_SIZE, 0); - BCryptDestroyHash(pHashContext->bcrypt_hash); + BCryptFinishHash(hash_handle, pbHashValue, RSAENH_MAX_HASH_SIZE, 0); + BCryptDestroyHash(hash_handle); return TRUE; }
-BOOL duplicate_hash_impl(const HASH_CONTEXT *pSrcHashContext, HASH_CONTEXT *pDestHashContext) +BOOL duplicate_hash_impl(BCRYPT_HASH_HANDLE src_hash_handle, BCRYPT_HASH_HANDLE *dest_hash_handle) { - return !BCryptDuplicateHash(pSrcHashContext->bcrypt_hash, &pDestHashContext->bcrypt_hash, NULL, 0, 0); + return !BCryptDuplicateHash(src_hash_handle, dest_hash_handle, NULL, 0, 0); }
BOOL new_key_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen) diff --git a/dlls/rsaenh/implglue.h b/dlls/rsaenh/implglue.h index 9be642e9b60..06fa3f4430a 100644 --- a/dlls/rsaenh/implglue.h +++ b/dlls/rsaenh/implglue.h @@ -29,10 +29,6 @@
#define RSAENH_MAX_HASH_SIZE 104
-typedef union tagHASH_CONTEXT { - BCRYPT_HASH_HANDLE bcrypt_hash; -} HASH_CONTEXT; - typedef union tagKEY_CONTEXT { rc2_key rc2; des_key des; @@ -42,12 +38,12 @@ typedef union tagKEY_CONTEXT { rsa_key rsa; } KEY_CONTEXT;
-BOOL init_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext) DECLSPEC_HIDDEN; -BOOL update_hash_impl(HASH_CONTEXT *pHashContext, const BYTE *pbData, +BOOL init_hash_impl(ALG_ID aiAlgid, BCRYPT_HASH_HANDLE *hash_handle) DECLSPEC_HIDDEN; +BOOL update_hash_impl(BCRYPT_HASH_HANDLE hash_handle, const BYTE *pbData, DWORD dwDataLen) DECLSPEC_HIDDEN; -BOOL finalize_hash_impl(HASH_CONTEXT *pHashContext, BYTE *pbHashValue) DECLSPEC_HIDDEN; -BOOL duplicate_hash_impl(const HASH_CONTEXT *pSrcHashContext, - HASH_CONTEXT *pDestHashContext) DECLSPEC_HIDDEN; +BOOL finalize_hash_impl(BCRYPT_HASH_HANDLE hash_handle, BYTE *pbHashValue) DECLSPEC_HIDDEN; +BOOL duplicate_hash_impl(BCRYPT_HASH_HANDLE src_hash_handle, + BCRYPT_HASH_HANDLE *dest_hash_handle) DECLSPEC_HIDDEN;
BOOL new_key_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen) DECLSPEC_HIDDEN; BOOL free_key_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext) DECLSPEC_HIDDEN; diff --git a/dlls/rsaenh/rsaenh.c b/dlls/rsaenh/rsaenh.c index a4deb80b0e1..c913c0c71ee 100644 --- a/dlls/rsaenh/rsaenh.c +++ b/dlls/rsaenh/rsaenh.c @@ -58,7 +58,7 @@ typedef struct tagCRYPTHASH HCRYPTPROV hProv; DWORD dwHashSize; DWORD dwState; - HASH_CONTEXT context; + BCRYPT_HASH_HANDLE hash_handle; BYTE abHashValue[RSAENH_MAX_HASH_SIZE]; PHMAC_INFO pHMACInfo; RSAENH_TLS1PRF_PARAMS tpPRFParams; @@ -627,8 +627,8 @@ static inline BOOL init_hash(CRYPTHASH *pCryptHash) { pAlgInfo = get_algid_info(pCryptHash->hProv, pCryptHash->pHMACInfo->HashAlgid); if (!pAlgInfo) return FALSE; pCryptHash->dwHashSize = pAlgInfo->dwDefaultLen >> 3; - init_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context); - update_hash_impl(&pCryptHash->context, + init_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->hash_handle); + update_hash_impl(pCryptHash->hash_handle, pCryptHash->pHMACInfo->pbInnerString, pCryptHash->pHMACInfo->cbInnerString); } @@ -642,7 +642,7 @@ static inline BOOL init_hash(CRYPTHASH *pCryptHash) { return TRUE;
default: - return init_hash_impl(pCryptHash->aiAlgid, &pCryptHash->context); + return init_hash_impl(pCryptHash->aiAlgid, &pCryptHash->hash_handle); } }
@@ -664,7 +664,7 @@ static inline void update_hash(CRYPTHASH *pCryptHash, const BYTE *pbData, DWORD { case CALG_HMAC: if (pCryptHash->pHMACInfo) - update_hash_impl(&pCryptHash->context, pbData, dwDataLen); + update_hash_impl(pCryptHash->hash_handle, pbData, dwDataLen); break;
case CALG_MAC: @@ -677,7 +677,7 @@ static inline void update_hash(CRYPTHASH *pCryptHash, const BYTE *pbData, DWORD break;
default: - update_hash_impl(&pCryptHash->context, pbData, dwDataLen); + update_hash_impl(pCryptHash->hash_handle, pbData, dwDataLen); } }
@@ -699,15 +699,15 @@ static inline void finalize_hash(CRYPTHASH *pCryptHash) { if (pCryptHash->pHMACInfo) { BYTE abHashValue[RSAENH_MAX_HASH_SIZE];
- finalize_hash_impl(&pCryptHash->context, pCryptHash->abHashValue); + finalize_hash_impl(pCryptHash->hash_handle, pCryptHash->abHashValue); memcpy(abHashValue, pCryptHash->abHashValue, pCryptHash->dwHashSize); - init_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context); - update_hash_impl(&pCryptHash->context, + init_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->hash_handle); + update_hash_impl(pCryptHash->hash_handle, pCryptHash->pHMACInfo->pbOuterString, pCryptHash->pHMACInfo->cbOuterString); - update_hash_impl(&pCryptHash->context, + update_hash_impl(pCryptHash->hash_handle, abHashValue, pCryptHash->dwHashSize); - finalize_hash_impl(&pCryptHash->context, pCryptHash->abHashValue); + finalize_hash_impl(pCryptHash->hash_handle, pCryptHash->abHashValue); } break;
@@ -718,7 +718,7 @@ static inline void finalize_hash(CRYPTHASH *pCryptHash) { break;
default: - finalize_hash_impl(&pCryptHash->context, pCryptHash->abHashValue); + finalize_hash_impl(pCryptHash->hash_handle, pCryptHash->abHashValue); } }
@@ -2371,7 +2371,7 @@ BOOL WINAPI RSAENH_CPDuplicateHash(HCRYPTPROV hUID, HCRYPTHASH hHash, DWORD *pdw if (*phHash != (HCRYPTHASH)INVALID_HANDLE_VALUE) { *pDestHash = *pSrcHash; - duplicate_hash_impl(&pSrcHash->context, &pDestHash->context); + duplicate_hash_impl(pSrcHash->hash_handle, &pDestHash->hash_handle); copy_hmac_info(&pDestHash->pHMACInfo, pSrcHash->pHMACInfo); copy_data_blob(&pDestHash->tpPRFParams.blobLabel, &pSrcHash->tpPRFParams.blobLabel); copy_data_blob(&pDestHash->tpPRFParams.blobSeed, &pSrcHash->tpPRFParams.blobSeed);
Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/rsaenh/rsaenh.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/dlls/rsaenh/rsaenh.c b/dlls/rsaenh/rsaenh.c index c913c0c71ee..a10559bb7b2 100644 --- a/dlls/rsaenh/rsaenh.c +++ b/dlls/rsaenh/rsaenh.c @@ -594,13 +594,16 @@ static BOOL copy_hmac_info(PHMAC_INFO *dst, const HMAC_INFO *src) { * Destructor for hash objects * * PARAMS - * pCryptHash [I] Pointer to the hash object to be destroyed. + * pCryptHash [I] Pointer to the hash object to be destroyed. * Will be invalid after function returns! */ static void destroy_hash(OBJECTHDR *pObject) { CRYPTHASH *pCryptHash = (CRYPTHASH*)pObject; - + + if (pCryptHash->hash_handle) + BCryptDestroyHash(pCryptHash->hash_handle); + free_hmac_info(pCryptHash->pHMACInfo); free_data_blob(&pCryptHash->tpPRFParams.blobLabel); free_data_blob(&pCryptHash->tpPRFParams.blobSeed); @@ -2211,6 +2214,7 @@ BOOL WINAPI RSAENH_CPCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, pCryptHash->hProv = hProv; pCryptHash->dwState = RSAENH_HASHSTATE_HASHING; pCryptHash->pHMACInfo = NULL; + pCryptHash->hash_handle = NULL; pCryptHash->dwHashSize = peaAlgidInfo->dwDefaultLen >> 3; init_data_blob(&pCryptHash->tpPRFParams.blobLabel); init_data_blob(&pCryptHash->tpPRFParams.blobSeed);
Signed-off-by: Hans Leidekker hans@codeweavers.com
Sven Baars sbaars@codeweavers.com writes:
Signed-off-by: Sven Baars sbaars@codeweavers.com
dlls/rsaenh/rsaenh.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
This breaks the tests:
tools/runtest -q -P wine -T . -M crypt32.dll -p dlls/crypt32/tests/crypt32_test.exe cert && touch dlls/crypt32/tests/cert.ok wine: Unhandled page fault on write access to 00000004 at address 7BC25526 (thread 0178), starting debugger... Unhandled exception: page fault on write access to 0x00000004 in 32-bit code (0x7bc25526). Register dump: CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b EIP:7bc25526 ESP:0031f710 EBP:0031f728 EFLAGS:00010202( R- -- I - - - ) EAX:01120f68 EBX:01120048 ECX:00000a98 EDX:011204d0 ESI:00000000 EDI:00000000 Stack dump: 0x0031f710: 01120094 00000002 01120f68 01120048 0x0031f720: 011204e8 011204f0 0031f768 7bc25fb4 0x0031f730: 01120094 00000002 01120000 00000000 0x0031f740: 00000000 01120048 0031f788 01120000 0x0031f750: 01120000 00000a98 0031f7c8 01120000 0x0031f760: 01120000 011204e8 0031f7c8 7bc2683c Backtrace: =>0 0x7bc25526 list_remove+0x6(elem=<internal error>) [Z:\home\julliard\wine\wine\include\wine\list.h:100] in ntdll (0x0031f728) 1 0x7bc25526 HEAP_CreateFreeBlock+0x126(subheap=<register EBX not accessible in this frame>, ptr=<register EDX not accessible in this frame>, size=<register ECX not accessible in this frame>) [Z:\home\julliard\wine\wine\dlls\ntdll\heap.c:492] in ntdll (0x0031f728) 2 0x7bc25fb4 HEAP_MakeInUseBlockFree+0xe4(subheap=<register EBX not accessible in this frame>, pArena=<is not available>) [Z:\home\julliard\wine\wine\dlls\ntdll\heap.c:666] in ntdll (0x0031f768) 3 0x7bc2683c RtlFreeHeap+0x67(heap=<internal error>, flags=<internal error>, ptr=<internal error>) [Z:\home\julliard\wine\wine\dlls\ntdll\heap.c:1769] in ntdll (0x0031f7c8) 4 0x7bc27b3a RtlFreeHeap+0x35(heap=<internal error>, flags=<internal error>, ptr=<internal error>) [Z:\home\julliard\wine\wine\dlls\ntdll\heap.c:1744] in ntdll (0x0031f808) 5 0x70b74b93 msvcrt_heap_free+0x4b(ptr=<internal error>) [Z:\home\julliard\wine\wine\dlls\msvcrt\heap.c:114] in ucrtbase (0x0031f838) 6 0x70b74b93 free+0x5e(ptr=<internal error>) [Z:\home\julliard\wine\wine\dlls\msvcrt\heap.c:413] in ucrtbase (0x0031f838) 7 0x66244676 BCryptDestroyHash+0x36(handle=011204F0) [Z:\home\julliard\wine\wine\dlls\bcrypt\bcrypt_main.c:894] in bcrypt (0x0031f878) 8 0x6fe4c56b destroy_hash+0x1b(pObject=006126C8) [Z:\home\julliard\wine\wine\dlls\rsaenh\rsaenh.c:605] in rsaenh (0x0031f8b8) 9 0x6fe42ad2 release_handle+0x92(lpTable=6FE6F000, handle=0x2, dwType=0x85938417) [Z:\home\julliard\wine\wine\dlls\rsaenh\handle.c:245] in rsaenh (0x0031f908) 10 0x6fe4d28b RSAENH_CPDestroyHash+0x6b(hProv=0x1, hHash=0x2) [Z:\home\julliard\wine\wine\dlls\rsaenh\rsaenh.c:2289] in rsaenh (0x0031f938) 11 0x6174f76b CryptDestroyHash+0x7b(hHash=<internal error>) [Z:\home\julliard\wine\wine\dlls\advapi32\crypt.c:889] in advapi32 (0x0031f978) 12 0x6e8c7e32 CryptHashCertificate+0x142(hCryptProv=<internal error>, Algid=<internal error>, dwFlags=<internal error>, pbEncoded=<internal error>, cbEncoded=<internal error>, pbComputedHash=<internal error>, pcbComputedHash=<internal error>) [Z:\home\julliard\wine\wine\dlls\crypt32\cert.c:2263] in crypt32 (0x0031f9f8) 13 0x6e8c8a15 CertContext_GetHashProp+0x35(pcbData=<internal error>, pvData=<internal error>, toHashLen=<internal error>, toHash=<internal error>, algID=<internal error>, dwPropId=<internal error>, cert=<internal error>) [Z:\home\julliard\wine\wine\dlls\crypt32\cert.c:398] in crypt32 (0x0031fa68) 14 0x6e8c8a15 CertContext_GetProperty+0x4a5(cert=<register EBX not accessible in this frame>, dwPropId=<internal error>, pvData=<register ESI not accessible in this frame>, pcbData=0031FB20) [Z:\home\julliard\wine\wine\dlls\crypt32\cert.c:579] in crypt32 (0x0031fa68) 15 0x6e8c8b0f CertGetCertificateContextProperty+0x4f(pCertContext=<internal error>, dwPropId=<internal error>, pvData=<internal error>, pcbData=<internal error>) [Z:\home\julliard\wine\wine\dlls\crypt32\cert.c:654] in crypt32 (0x0031fac8) 16 0x6e8c8d9e add_cert_to_store+0x4e(store=<register ESI not accessible in this frame>, cert=<register EBX not accessible in this frame>, add_disposition=<register EDI not accessible in this frame>, use_link=0, ret_context=0031FC0C) [Z:\home\julliard\wine\wine\dlls\crypt32\cert.c:193] in crypt32 (0x0031fb58) 17 0x6e8c93d9 CertAddCertificateContextToStore+0x1a(ppStoreContext=<internal error>, dwAddDisposition=<internal error>, pCertContext=<internal error>, hCertStore=<internal error>) [Z:\home\julliard\wine\wine\dlls\crypt32\cert.c:290] in crypt32 (0x0031fbb8) 18 0x6e8c93d9 CertAddEncodedCertificateToStore+0x79(hCertStore=<internal error>, dwCertEncodingType=<internal error>, pbCertEncoded=<internal error>, cbCertEncoded=<internal error>, dwAddDisposition=<internal error>, ppCertContext=<internal error>) [Z:\home\julliard\wine\wine\dlls\crypt32\cert.c:65] in crypt32 (0x0031fbb8) 19 0x00407dbe testGetSubjectCert+0x13e() [Z:\home\julliard\wine\wine\dlls\crypt32\tests\cert.c:1382] in crypt32_test (0x0031fc98) 20 0x00411106 func_cert+0x36() [Z:\home\julliard\wine\wine\dlls\crypt32\tests\cert.c:4336] in crypt32_test (0x0031fe08) 21 0x0046626b run_test+0xe6(name=<internal error>) [Z:\home\julliard\wine\wine\include\wine\test.h:614] in crypt32_test (0x0031fee8) 22 0x0046626b main+0x26b(argc=<internal error>, argv=<internal error>) [Z:\home\julliard\wine\wine\include\wine\test.h:697] in crypt32_test (0x0031fee8) 23 0x00465f7f mainCRTStartup+0x7f() [Z:\home\julliard\wine\wine\dlls\msvcrt\crt_main.c:60] in crypt32_test (0x0031ff30) 24 0x7b62de90 WriteTapemark+0x100(device=7FFD1000, type=<is not available>, count=<is not available>, immediate=<is not available>) [Z:\home\julliard\wine\wine\dlls\kernel32\tape.c:317] in kernel32 (0x0031ff48) 25 0x7bc57c27 RtlWakeConditionVariable+0x57(variable=7B62DE80) [Z:\home\julliard\wine\wine\dlls\ntdll\sync.c:766] in ntdll (0x0031ff5c) 26 0x7bc582e0 RtlCreateUserThread(entry=00465F00, arg=7FFD1000) [Z:\home\julliard\wine\wine\dlls\ntdll\thread.c:261] in ntdll (0x0031ffec) 0x7bc25526 HEAP_CreateFreeBlock+0x126 [Z:\home\julliard\wine\wine\dlls\ntdll\heap.c:492] in ntdll: movl %esi,0x4(%edi) 492 pArena->size |= ARENA_FLAG_FREE;