Juan Lang : crypt32: Implement CryptVerifyDetachedMessageHash.

Alexandre Julliard julliard at winehq.org
Wed Aug 27 08:24:11 CDT 2008


Module: wine
Branch: master
Commit: 4e6515e0276c7b2e7cc498bea8bf9fec84246fc5
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=4e6515e0276c7b2e7cc498bea8bf9fec84246fc5

Author: Juan Lang <juan.lang at gmail.com>
Date:   Tue Aug 26 09:40:37 2008 -0700

crypt32: Implement CryptVerifyDetachedMessageHash.

---

 dlls/crypt32/message.c       |   52 ++++++++++++++++++++++++++++++++++++++---
 dlls/crypt32/tests/message.c |   12 ---------
 2 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/dlls/crypt32/message.c b/dlls/crypt32/message.c
index b139094..9413dd6 100644
--- a/dlls/crypt32/message.c
+++ b/dlls/crypt32/message.c
@@ -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;
 }
diff --git a/dlls/crypt32/tests/message.c b/dlls/crypt32/tests/message.c
index b3b6abe..adfa0eb 100644
--- a/dlls/crypt32/tests/message.c
+++ b/dlls/crypt32/tests/message.c
@@ -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());
 }
 




More information about the wine-cvs mailing list