crypt32(6/21): Implement verifying the hash of a decoded hash
message
Juan Lang
juan.lang at gmail.com
Tue Aug 21 09:22:22 CDT 2007
--Juan
-------------- next part --------------
From b60c59e6804a2d56ea462022fd75754e7ed84375 Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang at gmail.com>
Date: Mon, 20 Aug 2007 17:40:25 -0700
Subject: [PATCH] Implement verifying the hash of a decoded hash message
---
dlls/crypt32/msg.c | 34 +++++++++++++++++++++++++++++++++-
dlls/crypt32/tests/msg.c | 2 +-
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c
index 036f2f7..516bc1b 100644
--- a/dlls/crypt32/msg.c
+++ b/dlls/crypt32/msg.c
@@ -1926,6 +1926,38 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMS
return ret;
}
+static BOOL CDecodeHashMsg_VerifyHash(CDecodeMsg *msg)
+{
+ BOOL ret;
+ CRYPT_DATA_BLOB hashBlob;
+
+ ret = ContextPropertyList_FindProperty(msg->properties,
+ CMSG_HASH_DATA_PARAM, &hashBlob);
+ if (ret)
+ {
+ DWORD computedHashSize = 0;
+
+ ret = CDecodeHashMsg_GetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, NULL,
+ &computedHashSize);
+ if (hashBlob.cbData == computedHashSize)
+ {
+ LPBYTE computedHash = CryptMemAlloc(computedHashSize);
+
+ if (computedHash)
+ {
+ ret = CDecodeHashMsg_GetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0,
+ computedHash, &computedHashSize);
+ if (ret)
+ ret = !memcmp(hashBlob.pbData, computedHash,
+ hashBlob.cbData);
+ }
+ else
+ ret = FALSE;
+ }
+ }
+ return ret;
+}
+
static BOOL CDecodeMsg_Control(HCRYPTMSG hCryptMsg, DWORD dwFlags,
DWORD dwCtrlType, const void *pvCtrlPara)
{
@@ -1955,7 +1987,7 @@ static BOOL CDecodeMsg_Control(HCRYPTMSG
switch (msg->type)
{
case CMSG_HASHED:
- FIXME("CMSG_CTRL_VERIFY_HASH: stub\n");
+ ret = CDecodeHashMsg_VerifyHash(msg);
break;
default:
SetLastError(CRYPT_E_INVALID_MSG_TYPE);
diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index b373470..72932fe 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -2246,13 +2246,13 @@ static void test_msg_control(void)
TRUE);
/* Oddly enough, this fails */
ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_HASH, NULL);
+ todo_wine
ok(!ret, "Expected failure\n");
CryptMsgClose(msg);
msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, CMSG_HASHED, 0, NULL,
NULL);
CryptMsgUpdate(msg, hashBareContent, sizeof(hashBareContent), TRUE);
ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_HASH, NULL);
- todo_wine
ok(ret, "CryptMsgControl failed: %08x\n", GetLastError());
/* Can't decrypt an indeterminate-type message */
SetLastError(0xdeadbeef);
--
1.4.1
More information about the wine-patches
mailing list