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 --- v3: Make sure we don't try to free the hash after it has already been freed by finalize_hash().
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..d03f647832e 100644 --- a/dlls/rsaenh/rsaenh.c +++ b/dlls/rsaenh/rsaenh.c @@ -594,13 +594,14 @@ 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; - + + BCryptDestroyHash(pCryptHash->hash_handle); free_hmac_info(pCryptHash->pHMACInfo); free_data_blob(&pCryptHash->tpPRFParams.blobLabel); free_data_blob(&pCryptHash->tpPRFParams.blobSeed); @@ -708,6 +709,7 @@ static inline void finalize_hash(CRYPTHASH *pCryptHash) { update_hash_impl(pCryptHash->hash_handle, abHashValue, pCryptHash->dwHashSize); finalize_hash_impl(pCryptHash->hash_handle, pCryptHash->abHashValue); + pCryptHash->hash_handle = NULL; } break;
@@ -719,6 +721,7 @@ static inline void finalize_hash(CRYPTHASH *pCryptHash) {
default: finalize_hash_impl(pCryptHash->hash_handle, pCryptHash->abHashValue); + pCryptHash->hash_handle = NULL; } }
@@ -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