=?UTF-8?Q?Orhan=20Kavrako=C4=9Flu=20?=: crypt32: Implement CryptHashCertificate2.

Alexandre Julliard julliard at winehq.org
Tue Jan 29 15:18:16 CST 2019


Module: wine
Branch: master
Commit: d3c606954b8ee341f5984d15fc9f9cb637fb557b
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=d3c606954b8ee341f5984d15fc9f9cb637fb557b

Author: Orhan Kavrakoğlu <aibok42 at gmail.com>
Date:   Tue Jan 29 08:17:17 2019 +0300

crypt32: Implement CryptHashCertificate2.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46516
Signed-off-by: Orhan Kavrakoğlu <aibok42 at gmail.com>
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/crypt32/cert.c       | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 dlls/crypt32/crypt32.spec |  1 +
 include/wincrypt.h        |  4 ++++
 3 files changed, 58 insertions(+)

diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c
index eb646cd..f4cde69 100644
--- a/dlls/crypt32/cert.c
+++ b/dlls/crypt32/cert.c
@@ -2213,6 +2213,59 @@ BOOL WINAPI CryptHashCertificate(HCRYPTPROV_LEGACY hCryptProv, ALG_ID Algid,
     return ret;
 }
 
+BOOL WINAPI CryptHashCertificate2(LPCWSTR pwszCNGHashAlgid, DWORD dwFlags,
+ void *pvReserved, const BYTE *pbEncoded, DWORD cbEncoded, BYTE *pbComputedHash,
+ DWORD *pcbComputedHash)
+{
+    BCRYPT_HASH_HANDLE hash = NULL;
+    BCRYPT_ALG_HANDLE alg = NULL;
+    NTSTATUS status;
+    DWORD hash_len;
+    DWORD hash_len_size;
+
+    TRACE("(%s, %08x, %p, %p, %d, %p, %p)\n", debugstr_w(pwszCNGHashAlgid),
+     dwFlags, pvReserved, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash);
+
+    if ((status = BCryptOpenAlgorithmProvider(&alg, pwszCNGHashAlgid, NULL, 0)))
+    {
+        if (status == STATUS_NOT_IMPLEMENTED)
+            status = STATUS_NOT_FOUND;
+        goto done;
+    }
+
+    if ((status = BCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0)))
+        goto done;
+
+    if ((status = BCryptGetProperty(hash, BCRYPT_HASH_LENGTH, (BYTE *)&hash_len, sizeof(hash_len), &hash_len_size, 0)))
+        goto done;
+
+    if (!pbComputedHash)
+    {
+        *pcbComputedHash = hash_len;
+        goto done;
+    }
+
+    if (*pcbComputedHash < hash_len)
+    {
+        status = ERROR_MORE_DATA;
+        goto done;
+    }
+
+    *pcbComputedHash = hash_len;
+
+    if ((status = BCryptHashData(hash, (BYTE *)pbEncoded, cbEncoded, 0)))
+        goto done;
+
+    if ((status = BCryptFinishHash(hash, pbComputedHash, hash_len, 0)))
+        goto done;
+
+done:
+    if (hash) BCryptDestroyHash(hash);
+    if (alg)  BCryptCloseAlgorithmProvider(alg, 0);
+    if (status) SetLastError(status);
+    return !status;
+}
+
 BOOL WINAPI CryptHashPublicKeyInfo(HCRYPTPROV_LEGACY hCryptProv, ALG_ID Algid,
  DWORD dwFlags, DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pInfo,
  BYTE *pbComputedHash, DWORD *pcbComputedHash)
diff --git a/dlls/crypt32/crypt32.spec b/dlls/crypt32/crypt32.spec
index 1815a1d..4399f7c 100644
--- a/dlls/crypt32/crypt32.spec
+++ b/dlls/crypt32/crypt32.spec
@@ -136,6 +136,7 @@
 @ stdcall CryptGetOIDFunctionAddress(long long str long ptr ptr)
 @ stdcall CryptGetOIDFunctionValue(long str str wstr ptr ptr ptr)
 @ stdcall CryptHashCertificate(long long long ptr long ptr ptr)
+@ stdcall CryptHashCertificate2(wstr long ptr ptr long ptr ptr)
 @ stdcall CryptHashMessage(ptr long long ptr ptr ptr ptr ptr ptr)
 @ stdcall CryptHashPublicKeyInfo(long long long long ptr ptr ptr)
 @ stdcall CryptHashToBeSigned(ptr long ptr long ptr ptr)
diff --git a/include/wincrypt.h b/include/wincrypt.h
index 5036ff5..8d9106e 100644
--- a/include/wincrypt.h
+++ b/include/wincrypt.h
@@ -4387,6 +4387,10 @@ BOOL WINAPI CryptHashCertificate(HCRYPTPROV_LEGACY hCryptProv, ALG_ID Algid,
  DWORD dwFlags, const BYTE *pbEncoded, DWORD cbEncoded, BYTE *pbComputedHash,
  DWORD *pcbComputedHash);
 
+BOOL WINAPI CryptHashCertificate2(LPCWSTR pwszCNGHashAlgid, DWORD dwFlags,
+ void *pvReserved, const BYTE *pbEncoded, DWORD cbEncoded, BYTE *pbComputedHash,
+ DWORD *pcbComputedHash);
+
 BOOL WINAPI CryptHashPublicKeyInfo(HCRYPTPROV_LEGACY hCryptProv, ALG_ID Algid,
  DWORD dwFlags, DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pInfo,
  BYTE *pbComputedHash, DWORD *pcbComputedHash);




More information about the wine-cvs mailing list