rsaenh: get rid of the hash idle state...
Juan Lang
juan.lang at gmail.com
Tue Jul 10 20:14:09 CDT 2007
native doesn't behave as though it has one.
--Juan
-------------- next part --------------
From 7f79fc1b3a7cdd325b45d98d93088f24147af898 Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Tue, 10 Jul 2007 18:04:40 -0700
Subject: [PATCH] Get rid of the idle hash state, native doesn't behave as though it has one.
---
dlls/rsaenh/rsaenh.c | 11 +----------
dlls/rsaenh/tests/rsaenh.c | 39 ++++++++++++++++++++++++++++++++++++---
2 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/dlls/rsaenh/rsaenh.c b/dlls/rsaenh/rsaenh.c
index 8f58d82..1ff1370 100644
--- a/dlls/rsaenh/rsaenh.c
+++ b/dlls/rsaenh/rsaenh.c
@@ -44,7 +44,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(crypt);
*/
#define RSAENH_MAGIC_HASH 0x85938417u
#define RSAENH_MAX_HASH_SIZE 104
-#define RSAENH_HASHSTATE_IDLE 0
#define RSAENH_HASHSTATE_HASHING 1
#define RSAENH_HASHSTATE_FINISHED 2
typedef struct _RSAENH_TLS1PRF_PARAMS
@@ -1598,7 +1597,7 @@ BOOL WINAPI RSAENH_CPCreateHash(HCRYPTPR
pCryptHash->aiAlgid = Algid;
pCryptHash->hKey = hKey;
pCryptHash->hProv = hProv;
- pCryptHash->dwState = RSAENH_HASHSTATE_IDLE;
+ pCryptHash->dwState = RSAENH_HASHSTATE_HASHING;
pCryptHash->pHMACInfo = (PHMAC_INFO)NULL;
pCryptHash->dwHashSize = peaAlgidInfo->dwDefaultLen >> 3;
init_data_blob(&pCryptHash->tpPRFParams.blobLabel);
@@ -2629,11 +2628,6 @@ BOOL WINAPI RSAENH_CPGetHashParam(HCRYPT
return TRUE;
}
- if (pCryptHash->dwState == RSAENH_HASHSTATE_IDLE) {
- SetLastError(NTE_BAD_HASH_STATE);
- return FALSE;
- }
-
if (pbData && (pCryptHash->dwState != RSAENH_HASHSTATE_FINISHED))
{
finalize_hash(pCryptHash);
@@ -3290,9 +3284,6 @@ BOOL WINAPI RSAENH_CPHashData(HCRYPTPROV
return FALSE;
}
- if (pCryptHash->dwState == RSAENH_HASHSTATE_IDLE)
- pCryptHash->dwState = RSAENH_HASHSTATE_HASHING;
-
if (pCryptHash->dwState != RSAENH_HASHSTATE_HASHING)
{
SetLastError(NTE_BAD_HASH_STATE);
diff --git a/dlls/rsaenh/tests/rsaenh.c b/dlls/rsaenh/tests/rsaenh.c
index 53ec374..2a397e7 100644
--- a/dlls/rsaenh/tests/rsaenh.c
+++ b/dlls/rsaenh/tests/rsaenh.c
@@ -165,6 +165,9 @@ static void test_hashes(void)
static const unsigned char md4hash[16] = {
0x8e, 0x2a, 0x58, 0xbf, 0xf2, 0xf5, 0x26, 0x23,
0x79, 0xd2, 0x92, 0x36, 0x1b, 0x23, 0xe3, 0x81 };
+ static const unsigned char empty_md5hash[16] = {
+ 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04,
+ 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e };
static const unsigned char md5hash[16] = {
0x15, 0x76, 0xa9, 0x4d, 0x6c, 0xb3, 0x34, 0xdd,
0x12, 0x6c, 0xb1, 0xc2, 0x7f, 0x19, 0xe0, 0xf2 };
@@ -227,13 +230,13 @@ static void test_hashes(void)
result = CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);
ok(result, "%08x\n", GetLastError());
- result = CryptHashData(hHash, (BYTE*)pbData, sizeof(pbData), 0);
- ok(result, "%08x\n", GetLastError());
-
len = sizeof(DWORD);
result = CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE*)&hashlen, &len, 0);
ok(result && (hashlen == 16), "%08x, hashlen: %d\n", GetLastError(), hashlen);
+ result = CryptHashData(hHash, (BYTE*)pbData, sizeof(pbData), 0);
+ ok(result, "%08x\n", GetLastError());
+
len = 16;
result = CryptGetHashParam(hHash, HP_HASHVAL, pbHashValue, &len, 0);
ok(result, "%08x\n", GetLastError());
@@ -243,6 +246,36 @@ static void test_hashes(void)
result = CryptDestroyHash(hHash);
ok(result, "%08x\n", GetLastError());
+ result = CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);
+ ok(result, "%08x\n", GetLastError());
+
+ /* The hash is available even if CryptHashData hasn't been called */
+ len = 16;
+ result = CryptGetHashParam(hHash, HP_HASHVAL, pbHashValue, &len, 0);
+ ok(result, "%08x\n", GetLastError());
+
+ ok(!memcmp(pbHashValue, empty_md5hash, 16), "Wrong MD5 hash!\n");
+
+ /* It's also stable: getting it twice results in the same value */
+ result = CryptGetHashParam(hHash, HP_HASHVAL, pbHashValue, &len, 0);
+ ok(result, "%08x\n", GetLastError());
+
+ ok(!memcmp(pbHashValue, empty_md5hash, 16), "Wrong MD5 hash!\n");
+
+ /* Can't add data after the hash been retrieved */
+ SetLastError(0xdeadbeef);
+ result = CryptHashData(hHash, (BYTE*)pbData, sizeof(pbData), 0);
+ ok(!result && GetLastError() == NTE_BAD_HASH_STATE, "%08x\n", GetLastError());
+
+ /* You can still retrieve the hash, its value just hasn't changed */
+ result = CryptGetHashParam(hHash, HP_HASHVAL, pbHashValue, &len, 0);
+ ok(result, "%08x\n", GetLastError());
+
+ ok(!memcmp(pbHashValue, empty_md5hash, 16), "Wrong MD5 hash!\n");
+
+ result = CryptDestroyHash(hHash);
+ ok(result, "%08x\n", GetLastError());
+
/* SHA1 Hashing */
result = CryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash);
ok(result, "%08x\n", GetLastError());
--
1.4.1
More information about the wine-patches
mailing list