bcrypt: Added BCryptHash function.
Signed-off-by: Patrick Armstrong <pat@oldpatricka.com> Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
7d72595475
commit
408251948e
|
@ -29,6 +29,7 @@
|
||||||
@ stub BCryptGenerateSymmetricKey
|
@ stub BCryptGenerateSymmetricKey
|
||||||
@ stdcall BCryptGetFipsAlgorithmMode(ptr)
|
@ stdcall BCryptGetFipsAlgorithmMode(ptr)
|
||||||
@ stdcall BCryptGetProperty(ptr wstr ptr long ptr long)
|
@ stdcall BCryptGetProperty(ptr wstr ptr long ptr long)
|
||||||
|
@ stdcall BCryptHash(ptr ptr long ptr long ptr long)
|
||||||
@ stdcall BCryptHashData(ptr ptr long long)
|
@ stdcall BCryptHashData(ptr ptr long long)
|
||||||
@ stub BCryptImportKey
|
@ stub BCryptImportKey
|
||||||
@ stub BCryptImportKeyPair
|
@ stub BCryptImportKeyPair
|
||||||
|
|
|
@ -808,6 +808,38 @@ NTSTATUS WINAPI BCryptFinishHash( BCRYPT_HASH_HANDLE handle, UCHAR *output, ULON
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NTSTATUS WINAPI BCryptHash( BCRYPT_ALG_HANDLE algorithm, UCHAR *secret, ULONG secretlen,
|
||||||
|
UCHAR *input, ULONG inputlen, UCHAR *output, ULONG outputlen )
|
||||||
|
{
|
||||||
|
NTSTATUS status;
|
||||||
|
BCRYPT_HASH_HANDLE handle;
|
||||||
|
|
||||||
|
TRACE( "%p, %p, %u, %p, %u, %p, %u\n", algorithm, secret, secretlen,
|
||||||
|
input, inputlen, output, outputlen );
|
||||||
|
|
||||||
|
status = BCryptCreateHash( algorithm, &handle, NULL, 0, secret, secretlen, 0);
|
||||||
|
if (status != STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = BCryptHashData( handle, input, inputlen, 0 );
|
||||||
|
if (status != STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
BCryptDestroyHash( handle );
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = BCryptFinishHash( handle, output, outputlen, 0 );
|
||||||
|
if (status != STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
BCryptDestroyHash( handle );
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BCryptDestroyHash( handle );
|
||||||
|
}
|
||||||
|
|
||||||
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
|
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
|
||||||
{
|
{
|
||||||
switch (reason)
|
switch (reason)
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
|
|
||||||
#include "wine/test.h"
|
#include "wine/test.h"
|
||||||
|
|
||||||
|
static NTSTATUS (WINAPI *pBCryptHash)( BCRYPT_ALG_HANDLE algorithm, UCHAR *secret, ULONG secretlen,
|
||||||
|
UCHAR *input, ULONG inputlen, UCHAR *output, ULONG outputlen );
|
||||||
|
|
||||||
static void test_BCryptGenRandom(void)
|
static void test_BCryptGenRandom(void)
|
||||||
{
|
{
|
||||||
NTSTATUS ret;
|
NTSTATUS ret;
|
||||||
|
@ -648,8 +651,55 @@ static void test_md5(void)
|
||||||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_BcryptHash(void)
|
||||||
|
{
|
||||||
|
static const char expected[] =
|
||||||
|
"e2a3e68d23ce348b8f68b3079de3d4c9";
|
||||||
|
static const char expected_hmac[] =
|
||||||
|
"7bda029b93fa8d817fcc9e13d6bdf092";
|
||||||
|
BCRYPT_ALG_HANDLE alg;
|
||||||
|
UCHAR md5[16], md5_hmac[16];
|
||||||
|
char str[65];
|
||||||
|
NTSTATUS ret;
|
||||||
|
|
||||||
|
alg = NULL;
|
||||||
|
ret = BCryptOpenAlgorithmProvider(&alg, BCRYPT_MD5_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
|
||||||
|
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||||
|
ok(alg != NULL, "alg not set\n");
|
||||||
|
|
||||||
|
test_hash_length(alg, 16);
|
||||||
|
test_alg_name(alg, "MD5");
|
||||||
|
|
||||||
|
memset(md5, 0, sizeof(md5));
|
||||||
|
ret = pBCryptHash(alg, NULL, 0, (UCHAR *)"test", sizeof("test"), md5, sizeof(md5));
|
||||||
|
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||||
|
format_hash( md5, sizeof(md5), str );
|
||||||
|
ok(!strcmp(str, expected), "got %s\n", str);
|
||||||
|
|
||||||
|
ret = BCryptCloseAlgorithmProvider(alg, 0);
|
||||||
|
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||||
|
|
||||||
|
alg = NULL;
|
||||||
|
memset(md5_hmac, 0, sizeof(md5_hmac));
|
||||||
|
ret = BCryptOpenAlgorithmProvider(&alg, BCRYPT_MD5_ALGORITHM, MS_PRIMITIVE_PROVIDER, BCRYPT_ALG_HANDLE_HMAC_FLAG);
|
||||||
|
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||||
|
ok(alg != NULL, "alg not set\n");
|
||||||
|
|
||||||
|
ret = pBCryptHash(alg, (UCHAR *)"key", sizeof("key"), (UCHAR *)"test", sizeof("test"), md5_hmac, sizeof(md5_hmac));
|
||||||
|
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||||
|
format_hash( md5_hmac, sizeof(md5_hmac), str );
|
||||||
|
ok(!strcmp(str, expected_hmac), "got %s\n", str);
|
||||||
|
|
||||||
|
ret = BCryptCloseAlgorithmProvider(alg, 0);
|
||||||
|
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(bcrypt)
|
START_TEST(bcrypt)
|
||||||
{
|
{
|
||||||
|
HMODULE module;
|
||||||
|
|
||||||
|
module = GetModuleHandleA( "bcrypt.dll" );
|
||||||
|
|
||||||
test_BCryptGenRandom();
|
test_BCryptGenRandom();
|
||||||
test_BCryptGetFipsAlgorithmMode();
|
test_BCryptGetFipsAlgorithmMode();
|
||||||
test_sha1();
|
test_sha1();
|
||||||
|
@ -657,4 +707,11 @@ START_TEST(bcrypt)
|
||||||
test_sha384();
|
test_sha384();
|
||||||
test_sha512();
|
test_sha512();
|
||||||
test_md5();
|
test_md5();
|
||||||
|
|
||||||
|
pBCryptHash = (void *)GetProcAddress( module, "BCryptHash" );
|
||||||
|
|
||||||
|
if (pBCryptHash)
|
||||||
|
test_BcryptHash();
|
||||||
|
else
|
||||||
|
win_skip("BCryptHash is not available\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ NTSTATUS WINAPI BCryptFinishHash(BCRYPT_HASH_HANDLE, PUCHAR, ULONG, ULONG);
|
||||||
NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE, PUCHAR, ULONG, ULONG);
|
NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE, PUCHAR, ULONG, ULONG);
|
||||||
NTSTATUS WINAPI BCryptGetFipsAlgorithmMode(BOOLEAN *);
|
NTSTATUS WINAPI BCryptGetFipsAlgorithmMode(BOOLEAN *);
|
||||||
NTSTATUS WINAPI BCryptGetProperty(BCRYPT_HANDLE, LPCWSTR, PUCHAR, ULONG, ULONG *, ULONG);
|
NTSTATUS WINAPI BCryptGetProperty(BCRYPT_HANDLE, LPCWSTR, PUCHAR, ULONG, ULONG *, ULONG);
|
||||||
|
NTSTATUS WINAPI BCryptHash(BCRYPT_ALG_HANDLE, PUCHAR, ULONG, PUCHAR, ULONG, PUCHAR, ULONG);
|
||||||
NTSTATUS WINAPI BCryptHashData(BCRYPT_HASH_HANDLE, PUCHAR, ULONG, ULONG);
|
NTSTATUS WINAPI BCryptHashData(BCRYPT_HASH_HANDLE, PUCHAR, ULONG, ULONG);
|
||||||
NTSTATUS WINAPI BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE *, LPCWSTR, LPCWSTR, ULONG);
|
NTSTATUS WINAPI BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE *, LPCWSTR, LPCWSTR, ULONG);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue