crypt32: Implement verifying the hash of a decoded hash message.

This commit is contained in:
Juan Lang 2007-08-20 17:40:25 -07:00 committed by Alexandre Julliard
parent e7ce5ae2bc
commit 3e88838b60
2 changed files with 34 additions and 2 deletions

View file

@ -1926,6 +1926,38 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
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 hCryptMsg, DWORD dwFlags,
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);

View file

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