Module: wine Branch: master Commit: cd3954e7fdeda223b81524a1f41839af90408b31 URL: http://source.winehq.org/git/wine.git/?a=commit;h=cd3954e7fdeda223b81524a1f4...
Author: Juan Lang juan.lang@gmail.com Date: Tue Jul 10 18:04:40 2007 -0700
rsaenh: Get rid of the hash idle 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(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, 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(HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwPa 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 hProv, HCRYPTHASH hHash, CONST BYTE *pb 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());