Hans Leidekker : bcrypt: Implement BCryptCreateHash and BCryptDestroyHash.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Jan 6 14:50:56 CST 2016


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

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Wed Jan  6 14:19:16 2016 +0100

bcrypt: Implement BCryptCreateHash and BCryptDestroyHash.

Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 configure                 |  1 +
 configure.ac              |  1 +
 dlls/bcrypt/bcrypt.spec   |  2 +-
 dlls/bcrypt/bcrypt_main.c | 99 +++++++++++++++++++++++++++++++++++++++++++++--
 include/config.h.in       |  3 ++
 5 files changed, 101 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index 06e3b4a..997833d 100755
--- a/configure
+++ b/configure
@@ -6675,6 +6675,7 @@ for ac_header in \
 	AudioUnit/AudioComponent.h \
 	CL/cl.h \
 	Carbon/Carbon.h \
+	CommonCrypto/CommonDigest.h \
 	CoreAudio/CoreAudio.h \
 	CoreServices/CoreServices.h \
 	DiskArbitration/DiskArbitration.h \
diff --git a/configure.ac b/configure.ac
index d47f7e9..2b1dd81 100644
--- a/configure.ac
+++ b/configure.ac
@@ -393,6 +393,7 @@ AC_CHECK_HEADERS(\
 	AudioUnit/AudioComponent.h \
 	CL/cl.h \
 	Carbon/Carbon.h \
+	CommonCrypto/CommonDigest.h \
 	CoreAudio/CoreAudio.h \
 	CoreServices/CoreServices.h \
 	DiskArbitration/DiskArbitration.h \
diff --git a/dlls/bcrypt/bcrypt.spec b/dlls/bcrypt/bcrypt.spec
index 1c848e1..53db32a 100644
--- a/dlls/bcrypt/bcrypt.spec
+++ b/dlls/bcrypt/bcrypt.spec
@@ -8,7 +8,7 @@
 @ stub BCryptDecrypt
 @ stub BCryptDeleteContext
 @ stub BCryptDeriveKey
-@ stub BCryptDestroyHash
+@ stdcall BCryptDestroyHash(ptr)
 @ stub BCryptDestroyKey
 @ stub BCryptDestroySecret
 @ stub BCryptDuplicateHash
diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
index 310c9b6..d496d80 100644
--- a/dlls/bcrypt/bcrypt_main.c
+++ b/dlls/bcrypt/bcrypt_main.c
@@ -20,6 +20,9 @@
 #include "config.h"
 
 #include <stdarg.h>
+#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
+#include <CommonCrypto/CommonDigest.h>
+#endif
 
 #include "ntstatus.h"
 #define WIN32_NO_STATUS
@@ -81,6 +84,7 @@ NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE algorithm, UCHAR *buffer, ULON
 }
 
 #define MAGIC_ALG  (('A' << 24) | ('L' << 16) | ('G' << 8) | '0')
+#define MAGIC_HASH (('H' << 24) | ('A' << 16) | ('S' << 8) | 'H')
 struct object
 {
     ULONG magic;
@@ -159,6 +163,59 @@ NTSTATUS WINAPI BCryptGetFipsAlgorithmMode(BOOLEAN *enabled)
     return STATUS_SUCCESS;
 }
 
+#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
+struct hash
+{
+    struct object hdr;
+    enum alg_id   alg_id;
+    union
+    {
+        CC_SHA1_CTX   sha1_ctx;
+        CC_SHA256_CTX sha256_ctx;
+        CC_SHA512_CTX sha512_ctx;
+    } u;
+};
+
+static NTSTATUS hash_init( struct hash *hash )
+{
+    switch (hash->alg_id)
+    {
+    case ALG_ID_SHA1:
+        CC_SHA1_Init( &hash->u.sha1_ctx );
+        break;
+
+    case ALG_ID_SHA256:
+        CC_SHA256_Init( &hash->u.sha256_ctx );
+        break;
+
+    case ALG_ID_SHA384:
+        CC_SHA384_Init( &hash->u.sha512_ctx );
+        break;
+
+    case ALG_ID_SHA512:
+        CC_SHA512_Init( &hash->u.sha512_ctx );
+        break;
+
+    default:
+        ERR( "unhandled id %u\n", hash->alg_id );
+        return STATUS_NOT_IMPLEMENTED;
+    }
+    return STATUS_SUCCESS;
+}
+#else
+struct hash
+{
+    struct object hdr;
+    enum alg_id   alg_id;
+};
+
+static NTSTATUS hash_init( struct hash *hash )
+{
+    ERR( "support for hashes not available at build time\n" );
+    return STATUS_NOT_IMPLEMENTED;
+}
+#endif
+
 NTSTATUS WINAPI BCryptGetProperty(BCRYPT_HANDLE obj, LPCWSTR prop, UCHAR *buffer, ULONG count, ULONG *res, ULONG flags)
 {
     FIXME("%p, %s, %p, %u, %p, %08x - stub\n", obj, wine_dbgstr_w(prop), buffer, count, res, flags);
@@ -166,10 +223,44 @@ NTSTATUS WINAPI BCryptGetProperty(BCRYPT_HANDLE obj, LPCWSTR prop, UCHAR *buffer
     return STATUS_NOT_IMPLEMENTED;
 }
 
-NTSTATUS WINAPI BCryptCreateHash(BCRYPT_ALG_HANDLE algorithm, BCRYPT_HASH_HANDLE* hash, UCHAR* hashobject,
-				 ULONG hashobjectlen, UCHAR *secret, ULONG secretlen, ULONG flags)
+NTSTATUS WINAPI BCryptCreateHash( BCRYPT_ALG_HANDLE algorithm, BCRYPT_HASH_HANDLE *handle, UCHAR *object, ULONG objectlen,
+                                  UCHAR *secret, ULONG secretlen, ULONG flags )
 {
-    FIXME("%p, %p, %p, %u, %p, %u, %08x - stub\n", algorithm, hash, hashobject, hashobjectlen, secret, secretlen, flags);
+    struct algorithm *alg = algorithm;
+    struct hash *hash;
+    NTSTATUS status;
 
-    return STATUS_NOT_IMPLEMENTED;
+    TRACE( "%p, %p, %p, %u, %p, %u, %08x - stub\n", algorithm, handle, object, objectlen,
+           secret, secretlen, flags );
+    if (flags)
+    {
+        FIXME( "unimplemented flags %08x\n", flags );
+        return STATUS_NOT_IMPLEMENTED;
+    }
+
+    if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE;
+    if (object) FIXME( "ignoring object buffer\n" );
+
+    if (!(hash = HeapAlloc( GetProcessHeap(), 0, sizeof(*hash) ))) return STATUS_NO_MEMORY;
+    hash->hdr.magic = MAGIC_HASH;
+    hash->alg_id    = alg->id;
+    if ((status = hash_init( hash )) != STATUS_SUCCESS)
+    {
+        HeapFree( GetProcessHeap(), 0, hash );
+        return status;
+    }
+
+    *handle = hash;
+    return STATUS_SUCCESS;
+}
+
+NTSTATUS WINAPI BCryptDestroyHash( BCRYPT_HASH_HANDLE handle )
+{
+    struct hash *hash = handle;
+
+    TRACE( "%p\n", handle );
+
+    if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_HANDLE;
+    HeapFree( GetProcessHeap(), 0, hash );
+    return STATUS_SUCCESS;
 }
diff --git a/include/config.h.in b/include/config.h.in
index 61817f4..514e5fe 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -71,6 +71,9 @@
 /* Define to 1 if you have the <CL/cl.h> header file. */
 #undef HAVE_CL_CL_H
 
+/* Define to 1 if you have the <CommonCrypto/CommonDigest.h> header file. */
+#undef HAVE_COMMONCRYPTO_COMMONDIGEST_H
+
 /* Define to 1 if you have the <CoreAudio/CoreAudio.h> header file. */
 #undef HAVE_COREAUDIO_COREAUDIO_H
 




More information about the wine-cvs mailing list