crypt32: Implement CryptVerifyDetachedMessageHash.

This commit is contained in:
Juan Lang 2008-08-26 09:40:37 -07:00 committed by Alexandre Julliard
parent 1097513697
commit 4e6515e027
2 changed files with 48 additions and 16 deletions

View File

@ -269,8 +269,52 @@ BOOL WINAPI CryptVerifyDetachedMessageHash(PCRYPT_HASH_MESSAGE_PARA pHashPara,
const BYTE *rgpbToBeHashed[], DWORD rgcbToBeHashed[], BYTE *pbComputedHash,
DWORD *pcbComputedHash)
{
FIXME("(%p, %p, %d, %d, %p, %p, %p, %p): stub\n", pHashPara,
pbDetachedHashBlob, cbDetachedHashBlob, cToBeHashed, rgpbToBeHashed,
rgcbToBeHashed, pbComputedHash, pcbComputedHash);
return FALSE;
HCRYPTMSG msg;
BOOL ret = FALSE;
TRACE("(%p, %p, %d, %d, %p, %p, %p, %p)\n", pHashPara, pbDetachedHashBlob,
cbDetachedHashBlob, cToBeHashed, rgpbToBeHashed, rgcbToBeHashed,
pbComputedHash, pcbComputedHash);
if (pHashPara->cbSize != sizeof(CRYPT_HASH_MESSAGE_PARA))
{
SetLastError(E_INVALIDARG);
return FALSE;
}
if (GET_CMSG_ENCODING_TYPE(pHashPara->dwMsgEncodingType) !=
PKCS_7_ASN_ENCODING)
{
SetLastError(E_INVALIDARG);
return FALSE;
}
msg = CryptMsgOpenToDecode(pHashPara->dwMsgEncodingType, CMSG_DETACHED_FLAG,
0, pHashPara->hCryptProv, NULL, NULL);
if (msg)
{
DWORD i;
ret = CryptMsgUpdate(msg, pbDetachedHashBlob, cbDetachedHashBlob, TRUE);
if (ret)
{
if (cToBeHashed)
{
for (i = 0; ret && i < cToBeHashed; i++)
{
ret = CryptMsgUpdate(msg, rgpbToBeHashed[i],
rgcbToBeHashed[i], i == cToBeHashed - 1 ? TRUE : FALSE);
}
}
else
ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
}
if (ret)
{
ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_HASH, NULL);
if (ret && pcbComputedHash)
ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0,
pbComputedHash, pcbComputedHash);
}
CryptMsgClose(msg);
}
return ret;
}

View File

@ -109,35 +109,30 @@ static void test_verify_detached_message_hash(void)
SetLastError(0xdeadbeef);
ret = CryptVerifyDetachedMessageHash(&para, NULL, 0, 0, NULL, NULL, NULL,
NULL);
todo_wine
ok(!ret && GetLastError() == E_INVALIDARG,
"expected E_INVALIDARG, got %08x\n", GetLastError());
para.cbSize = sizeof(para);
SetLastError(0xdeadbeef);
ret = CryptVerifyDetachedMessageHash(&para, NULL, 0, 0, NULL, NULL, NULL,
NULL);
todo_wine
ok(!ret && GetLastError() == E_INVALIDARG,
"expected E_INVALIDARG, got %08x\n", GetLastError());
para.dwMsgEncodingType = PKCS_7_ASN_ENCODING;
SetLastError(0xdeadbeef);
ret = CryptVerifyDetachedMessageHash(&para, NULL, 0, 0, NULL, NULL, NULL,
NULL);
todo_wine
ok(!ret && GetLastError() == CRYPT_E_ASN1_EOD,
"expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError());
para.dwMsgEncodingType = X509_ASN_ENCODING;
SetLastError(0xdeadbeef);
ret = CryptVerifyDetachedMessageHash(&para, NULL, 0, 0, NULL, NULL, NULL,
NULL);
todo_wine
ok(!ret && GetLastError() == E_INVALIDARG,
"expected E_INVALIDARG, got %08x\n", GetLastError());
para.dwMsgEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
SetLastError(0xdeadbeef);
ret = CryptVerifyDetachedMessageHash(&para, NULL, 0, 0, NULL, NULL, NULL,
NULL);
todo_wine
ok(!ret && GetLastError() == CRYPT_E_ASN1_EOD,
"expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError());
/* Curiously, passing no data to hash succeeds.. */
@ -150,7 +145,6 @@ static void test_verify_detached_message_hash(void)
pMsgData = msgData;
ret = CryptVerifyDetachedMessageHash(&para, detachedHashContent,
sizeof(detachedHashContent), 1, &pMsgData, &size, NULL, NULL);
todo_wine
ok(ret, "CryptVerifyDetachedMessageHash failed: %08x\n", GetLastError());
/* while passing data to hash that isn't the content of the message fails.
*/
@ -159,7 +153,6 @@ static void test_verify_detached_message_hash(void)
SetLastError(0xdeadbeef);
ret = CryptVerifyDetachedMessageHash(&para, detachedHashContent,
sizeof(detachedHashContent), 1, &pMsgData, &size, NULL, NULL);
todo_wine
ok(!ret && GetLastError() == CRYPT_E_HASH_VALUE,
"expected CRYPT_E_HASH_VALUE, got %08x\n", GetLastError());
/* Getting the size of the hash while passing no hash data causes the
@ -168,28 +161,23 @@ static void test_verify_detached_message_hash(void)
SetLastError(0xdeadbeef);
ret = CryptVerifyDetachedMessageHash(&para, detachedHashContent,
sizeof(detachedHashContent), 0, NULL, NULL, NULL, &hashSize);
todo_wine
ok(!ret && GetLastError() == CRYPT_E_HASH_VALUE,
"expected CRYPT_E_HASH_VALUE, got %08x\n", GetLastError());
size = sizeof(msgData);
pMsgData = msgData;
ret = CryptVerifyDetachedMessageHash(&para, detachedHashContent,
sizeof(detachedHashContent), 1, &pMsgData, &size, NULL, &hashSize);
todo_wine {
ok(ret, "CryptVerifyDetachedMessageHash failed: %08x\n", GetLastError());
ok(hashSize == sizeof(hash), "unexpected size %d\n", hashSize);
}
hashSize = 1;
SetLastError(0xdeadbeef);
ret = CryptVerifyDetachedMessageHash(&para, detachedHashContent,
sizeof(detachedHashContent), 1, &pMsgData, &size, hash, &hashSize);
todo_wine
ok(!ret && GetLastError() == ERROR_MORE_DATA,
"expected ERROR_MORE_DATA, got %08x\n", GetLastError());
hashSize = sizeof(hash);
ret = CryptVerifyDetachedMessageHash(&para, detachedHashContent,
sizeof(detachedHashContent), 1, &pMsgData, &size, hash, &hashSize);
todo_wine
ok(ret, "CryptVerifyDetachedMessageHash failed: %08x\n", GetLastError());
}