mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-31 11:26:10 +00:00
bcrypt: Added BCRYPT_ALGORITHM_NAME property implementation.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
f0e499f292
commit
f13cff3a01
2 changed files with 44 additions and 4 deletions
|
@ -182,11 +182,12 @@ enum alg_id
|
|||
|
||||
static const struct {
|
||||
ULONG hash_length;
|
||||
const WCHAR *alg_name;
|
||||
} alg_props[] = {
|
||||
/* ALG_ID_SHA1 */ { 20 },
|
||||
/* ALG_ID_SHA256 */ { 32 },
|
||||
/* ALG_ID_SHA384 */ { 48 },
|
||||
/* ALG_ID_SHA512 */ { 64 }
|
||||
/* ALG_ID_SHA1 */ { 20, BCRYPT_SHA1_ALGORITHM },
|
||||
/* ALG_ID_SHA256 */ { 32, BCRYPT_SHA256_ALGORITHM },
|
||||
/* ALG_ID_SHA384 */ { 48, BCRYPT_SHA384_ALGORITHM },
|
||||
/* ALG_ID_SHA512 */ { 64, BCRYPT_SHA512_ALGORITHM }
|
||||
};
|
||||
|
||||
struct algorithm
|
||||
|
@ -442,6 +443,16 @@ static NTSTATUS generic_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *
|
|||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (!strcmpW( prop, BCRYPT_ALGORITHM_NAME ))
|
||||
{
|
||||
*ret_size = (strlenW(alg_props[id].alg_name)+1)*sizeof(WCHAR);
|
||||
if (size < *ret_size)
|
||||
return STATUS_BUFFER_TOO_SMALL;
|
||||
if(buf)
|
||||
memcpy(buf, alg_props[id].alg_name, *ret_size);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,13 @@ static void format_hash(const UCHAR *bytes, ULONG size, char *buf)
|
|||
return;
|
||||
}
|
||||
|
||||
static int strcmp_wa(const WCHAR *strw, const char *stra)
|
||||
{
|
||||
WCHAR buf[512];
|
||||
MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(buf[0]));
|
||||
return lstrcmpW(strw, buf);
|
||||
}
|
||||
|
||||
#define test_hash_length(a,b) _test_hash_length(__LINE__,a,b)
|
||||
static void _test_hash_length(unsigned line, void *handle, ULONG exlen)
|
||||
{
|
||||
|
@ -91,6 +98,20 @@ static void _test_hash_length(unsigned line, void *handle, ULONG exlen)
|
|||
ok_(__FILE__,line)(len == exlen, "len = %u, expected %u\n", len, exlen);
|
||||
}
|
||||
|
||||
#define test_alg_name(a,b) _test_alg_name(__LINE__,a,b)
|
||||
static void _test_alg_name(unsigned line, void *handle, const char *exname)
|
||||
{
|
||||
ULONG size = 0xdeadbeef;
|
||||
UCHAR buf[256];
|
||||
const WCHAR *name = (const WCHAR*)buf;
|
||||
NTSTATUS status;
|
||||
|
||||
status = BCryptGetProperty(handle, BCRYPT_ALGORITHM_NAME, buf, sizeof(buf), &size, 0);
|
||||
ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: %08x\n", status);
|
||||
ok_(__FILE__,line)(size == (strlen(exname)+1)*sizeof(WCHAR), "got %u\n", size);
|
||||
ok_(__FILE__,line)(!strcmp_wa(name, exname), "alg name = %s, expected %s\n", wine_dbgstr_w(name), exname);
|
||||
}
|
||||
|
||||
static void test_sha1(void)
|
||||
{
|
||||
static const char expected[] = "961fa64958818f767707072755d7018dcd278e94";
|
||||
|
@ -136,6 +157,7 @@ static void test_sha1(void)
|
|||
ok(size == sizeof(len), "got %u\n", size);
|
||||
|
||||
test_hash_length(alg, 20);
|
||||
test_alg_name(alg, "SHA1");
|
||||
|
||||
hash = NULL;
|
||||
len = sizeof(buf);
|
||||
|
@ -147,6 +169,7 @@ static void test_sha1(void)
|
|||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
|
||||
test_hash_length(hash, 20);
|
||||
test_alg_name(hash, "SHA1");
|
||||
|
||||
memset(sha1, 0, sizeof(sha1));
|
||||
ret = BCryptFinishHash(hash, sha1, sizeof(sha1), 0);
|
||||
|
@ -207,6 +230,7 @@ static void test_sha256(void)
|
|||
ok(size == sizeof(len), "got %u\n", size);
|
||||
|
||||
test_hash_length(alg, 32);
|
||||
test_alg_name(alg, "SHA256");
|
||||
|
||||
hash = NULL;
|
||||
len = sizeof(buf);
|
||||
|
@ -218,6 +242,7 @@ static void test_sha256(void)
|
|||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
|
||||
test_hash_length(hash, 32);
|
||||
test_alg_name(hash, "SHA256");
|
||||
|
||||
memset(sha256, 0, sizeof(sha256));
|
||||
ret = BCryptFinishHash(hash, sha256, sizeof(sha256), 0);
|
||||
|
@ -278,6 +303,7 @@ static void test_sha384(void)
|
|||
ok(size == sizeof(len), "got %u\n", size);
|
||||
|
||||
test_hash_length(alg, 48);
|
||||
test_alg_name(alg, "SHA384");
|
||||
|
||||
hash = NULL;
|
||||
len = sizeof(buf);
|
||||
|
@ -289,6 +315,7 @@ static void test_sha384(void)
|
|||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
|
||||
test_hash_length(hash, 48);
|
||||
test_alg_name(hash, "SHA384");
|
||||
|
||||
memset(sha384, 0, sizeof(sha384));
|
||||
ret = BCryptFinishHash(hash, sha384, sizeof(sha384), 0);
|
||||
|
@ -350,6 +377,7 @@ static void test_sha512(void)
|
|||
ok(size == sizeof(len), "got %u\n", size);
|
||||
|
||||
test_hash_length(alg, 64);
|
||||
test_alg_name(alg, "SHA512");
|
||||
|
||||
hash = NULL;
|
||||
len = sizeof(buf);
|
||||
|
@ -361,6 +389,7 @@ static void test_sha512(void)
|
|||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
|
||||
test_hash_length(hash, 64);
|
||||
test_alg_name(hash, "SHA512");
|
||||
|
||||
memset(sha512, 0, sizeof(sha512));
|
||||
ret = BCryptFinishHash(hash, sha512, sizeof(sha512), 0);
|
||||
|
|
Loading…
Reference in a new issue