rsaenh: Store a BCRYPT_HASH_HANDLE in CRYPTHASH.

Signed-off-by: Sven Baars <sbaars@codeweavers.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Sven Baars 2022-02-15 12:45:46 +01:00 committed by Alexandre Julliard
parent 0dcdfae29a
commit bb4c43de94
3 changed files with 28 additions and 32 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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);