Hans Leidekker : bcrypt: Implement BCryptGetProperty.

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


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

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

bcrypt: Implement BCryptGetProperty.

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

---

 dlls/bcrypt/bcrypt_main.c | 152 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 149 insertions(+), 3 deletions(-)

diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
index d496d80..9ad3060 100644
--- a/dlls/bcrypt/bcrypt_main.c
+++ b/dlls/bcrypt/bcrypt_main.c
@@ -216,11 +216,157 @@ static NTSTATUS hash_init( struct hash *hash )
 }
 #endif
 
-NTSTATUS WINAPI BCryptGetProperty(BCRYPT_HANDLE obj, LPCWSTR prop, UCHAR *buffer, ULONG count, ULONG *res, ULONG flags)
+#define OBJECT_LENGTH_SHA1      278
+#define OBJECT_LENGTH_SHA256    286
+#define OBJECT_LENGTH_SHA384    382
+#define OBJECT_LENGTH_SHA512    382
+
+#define HASH_DIGEST_LENGTH_SHA1     20
+#define HASH_DIGEST_LENGTH_SHA256   32
+#define HASH_DIGEST_LENGTH_SHA384   48
+#define HASH_DIGEST_LENGTH_SHA512   64
+
+static NTSTATUS get_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size )
 {
-    FIXME("%p, %s, %p, %u, %p, %08x - stub\n", obj, wine_dbgstr_w(prop), buffer, count, res, flags);
+    ULONG value;
 
-    return STATUS_NOT_IMPLEMENTED;
+    switch (id)
+    {
+    case ALG_ID_SHA1:
+        if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
+        {
+            value = OBJECT_LENGTH_SHA1;
+            break;
+        }
+        FIXME( "unsupported sha1 algorithm property %s\n", debugstr_w(prop) );
+        return STATUS_NOT_IMPLEMENTED;
+
+    case ALG_ID_SHA256:
+        if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
+        {
+            value = OBJECT_LENGTH_SHA256;
+            break;
+        }
+        FIXME( "unsupported sha256 algorithm property %s\n", debugstr_w(prop) );
+        return STATUS_NOT_IMPLEMENTED;
+
+    case ALG_ID_SHA384:
+        if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
+        {
+            value = OBJECT_LENGTH_SHA384;
+            break;
+        }
+        FIXME( "unsupported sha384 algorithm property %s\n", debugstr_w(prop) );
+        return STATUS_NOT_IMPLEMENTED;
+
+    case ALG_ID_SHA512:
+        if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
+        {
+            value = OBJECT_LENGTH_SHA512;
+            break;
+        }
+        FIXME( "unsupported sha512 algorithm property %s\n", debugstr_w(prop) );
+        return STATUS_NOT_IMPLEMENTED;
+
+    default:
+        FIXME( "unsupported algorithm %u\n", id );
+        return STATUS_NOT_IMPLEMENTED;
+    }
+
+    if (size < sizeof(ULONG))
+    {
+        *ret_size = sizeof(ULONG);
+        return STATUS_BUFFER_TOO_SMALL;
+    }
+    if (buf) *(ULONG *)buf = value;
+    *ret_size = sizeof(ULONG);
+
+    return STATUS_SUCCESS;
+}
+
+static NTSTATUS get_hash_property( enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size )
+{
+    ULONG value;
+
+    switch (id)
+    {
+    case ALG_ID_SHA1:
+        if (!strcmpW( prop, BCRYPT_HASH_LENGTH ))
+        {
+            value = HASH_DIGEST_LENGTH_SHA1;
+            break;
+        }
+        FIXME( "unsupported sha1 hash property %s\n", debugstr_w(prop) );
+        return STATUS_NOT_IMPLEMENTED;
+
+    case ALG_ID_SHA256:
+        if (!strcmpW( prop, BCRYPT_HASH_LENGTH ))
+        {
+            value = HASH_DIGEST_LENGTH_SHA256;
+            break;
+        }
+        FIXME( "unsupported sha256 hash property %s\n", debugstr_w(prop) );
+        return STATUS_NOT_IMPLEMENTED;
+
+    case ALG_ID_SHA384:
+        if (!strcmpW( prop, BCRYPT_HASH_LENGTH ))
+        {
+            value = HASH_DIGEST_LENGTH_SHA384;
+            break;
+        }
+        FIXME( "unsupported sha384 hash property %s\n", debugstr_w(prop) );
+        return STATUS_NOT_IMPLEMENTED;
+
+    case ALG_ID_SHA512:
+        if (!strcmpW( prop, BCRYPT_HASH_LENGTH ))
+        {
+            value = HASH_DIGEST_LENGTH_SHA512;
+            break;
+        }
+        FIXME( "unsupported sha512 hash property %s\n", debugstr_w(prop) );
+        return STATUS_NOT_IMPLEMENTED;
+
+    default:
+        FIXME( "unsupported hash %u\n", id );
+        return STATUS_NOT_IMPLEMENTED;
+    }
+
+    if (size < sizeof(ULONG))
+    {
+        *ret_size = sizeof(ULONG);
+        return STATUS_BUFFER_TOO_SMALL;
+    }
+    if (buf) *(ULONG *)buf = value;
+    *ret_size = sizeof(ULONG);
+
+    return STATUS_SUCCESS;
+}
+
+NTSTATUS WINAPI BCryptGetProperty( BCRYPT_HANDLE handle, LPCWSTR prop, UCHAR *buffer, ULONG count, ULONG *res, ULONG flags )
+{
+    struct object *object = handle;
+
+    TRACE( "%p, %s, %p, %u, %p, %08x\n", handle, wine_dbgstr_w(prop), buffer, count, res, flags );
+
+    if (!object) return STATUS_INVALID_HANDLE;
+    if (!prop || !res) return STATUS_INVALID_PARAMETER;
+
+    switch (object->magic)
+    {
+    case MAGIC_ALG:
+    {
+        const struct algorithm *alg = (const struct algorithm *)object;
+        return get_alg_property( alg->id, prop, buffer, count, res );
+    }
+    case MAGIC_HASH:
+    {
+        const struct hash *hash = (const struct hash *)object;
+        return get_hash_property( hash->alg_id, prop, buffer, count, res );
+    }
+    default:
+        WARN( "unknown magic %08x", object->magic );
+        return STATUS_INVALID_HANDLE;
+    }
 }
 
 NTSTATUS WINAPI BCryptCreateHash( BCRYPT_ALG_HANDLE algorithm, BCRYPT_HASH_HANDLE *handle, UCHAR *object, ULONG objectlen,




More information about the wine-cvs mailing list