From 46369d79e0cd24f1ef396a692e001bfc3d1ef101 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 6 Jan 2016 14:19:17 +0100 Subject: [PATCH] bcrypt: Implement BCryptGetProperty. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/bcrypt/bcrypt_main.c | 154 +++++++++++++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 4 deletions(-) diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c index d496d80cfe0..9ad3060aa9b 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) -{ - FIXME("%p, %s, %p, %u, %p, %08x - stub\n", obj, wine_dbgstr_w(prop), buffer, count, res, flags); +#define OBJECT_LENGTH_SHA1 278 +#define OBJECT_LENGTH_SHA256 286 +#define OBJECT_LENGTH_SHA384 382 +#define OBJECT_LENGTH_SHA512 382 - return STATUS_NOT_IMPLEMENTED; +#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 ) +{ + ULONG value; + + 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,