dssenh: Don't store the algorithm handle for hashes.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2020-10-12 16:11:08 +02:00 committed by Alexandre Julliard
parent 43dddbae7b
commit b5e931d83c
1 changed files with 19 additions and 13 deletions

View File

@ -59,7 +59,6 @@ struct container
struct hash struct hash
{ {
DWORD magic; DWORD magic;
BCRYPT_ALG_HANDLE alg_handle;
BCRYPT_HASH_HANDLE handle; BCRYPT_HASH_HANDLE handle;
DWORD len; DWORD len;
UCHAR value[64]; UCHAR value[64];
@ -475,6 +474,7 @@ BOOL WINAPI CPExportKey( HCRYPTPROV hprov, HCRYPTKEY hkey, HCRYPTKEY hexpkey, DW
static struct hash *create_hash( ALG_ID algid ) static struct hash *create_hash( ALG_ID algid )
{ {
struct hash *ret; struct hash *ret;
BCRYPT_ALG_HANDLE alg_handle;
const WCHAR *alg; const WCHAR *alg;
DWORD len; DWORD len;
@ -492,24 +492,26 @@ static struct hash *create_hash( ALG_ID algid )
default: default:
FIXME( "unhandled algorithm %u\n", algid ); FIXME( "unhandled algorithm %u\n", algid );
return 0; return NULL;
} }
if (!(ret = heap_alloc_zero( sizeof(*ret) ))) return 0; if (!(ret = heap_alloc_zero( sizeof(*ret) ))) return NULL;
ret->magic = MAGIC_HASH; ret->magic = MAGIC_HASH;
ret->len = len; ret->len = len;
if (BCryptOpenAlgorithmProvider( &ret->alg_handle, alg, MS_PRIMITIVE_PROVIDER, 0 )) if (BCryptOpenAlgorithmProvider( &alg_handle, alg, MS_PRIMITIVE_PROVIDER, 0 ))
{ {
heap_free( ret ); heap_free( ret );
return 0; return NULL;
} }
if (BCryptCreateHash( ret->alg_handle, &ret->handle, NULL, 0, NULL, 0, 0 )) if (BCryptCreateHash( alg_handle, &ret->handle, NULL, 0, NULL, 0, 0 ))
{ {
BCryptCloseAlgorithmProvider( ret->alg_handle, 0 ); BCryptCloseAlgorithmProvider( alg_handle, 0 );
heap_free( ret ); heap_free( ret );
return 0; return NULL;
} }
BCryptCloseAlgorithmProvider( alg_handle, 0 );
return ret; return ret;
} }
@ -537,6 +539,14 @@ BOOL WINAPI CPCreateHash( HCRYPTPROV hprov, ALG_ID algid, HCRYPTKEY hkey, DWORD
return TRUE; return TRUE;
} }
static void destroy_hash( struct hash *hash )
{
if (!hash) return;
BCryptDestroyHash( hash->handle );
hash->magic = 0;
heap_free( hash );
}
BOOL WINAPI CPDestroyHash( HCRYPTPROV hprov, HCRYPTHASH hhash ) BOOL WINAPI CPDestroyHash( HCRYPTPROV hprov, HCRYPTHASH hhash )
{ {
struct hash *hash = (struct hash *)hhash; struct hash *hash = (struct hash *)hhash;
@ -549,11 +559,7 @@ BOOL WINAPI CPDestroyHash( HCRYPTPROV hprov, HCRYPTHASH hhash )
return FALSE; return FALSE;
} }
BCryptDestroyHash( hash->handle ); destroy_hash( hash );
BCryptCloseAlgorithmProvider( hash->alg_handle, 0 );
hash->magic = 0;
heap_free( hash );
return TRUE; return TRUE;
} }