mirror of
git://source.winehq.org/git/wine.git
synced 2024-11-05 18:01:34 +00:00
bcrypt: Add a stub AES implementation.
Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
ae2d6e836b
commit
b677b58b60
4 changed files with 70 additions and 25 deletions
|
@ -26,7 +26,7 @@
|
|||
@ stub BCryptFreeBuffer
|
||||
@ stdcall BCryptGenRandom(ptr ptr long long)
|
||||
@ stub BCryptGenerateKeyPair
|
||||
@ stub BCryptGenerateSymmetricKey
|
||||
@ stdcall BCryptGenerateSymmetricKey(ptr ptr ptr long ptr long long)
|
||||
@ stdcall BCryptGetFipsAlgorithmMode(ptr)
|
||||
@ stdcall BCryptGetProperty(ptr wstr ptr long ptr long)
|
||||
@ stdcall BCryptHash(ptr ptr long ptr long ptr long)
|
||||
|
|
|
@ -135,6 +135,7 @@ struct object
|
|||
|
||||
enum alg_id
|
||||
{
|
||||
ALG_ID_AES,
|
||||
ALG_ID_MD5,
|
||||
ALG_ID_RNG,
|
||||
ALG_ID_SHA1,
|
||||
|
@ -152,6 +153,7 @@ static const struct {
|
|||
ULONG block_bits;
|
||||
const WCHAR *alg_name;
|
||||
} alg_props[] = {
|
||||
/* ALG_ID_AES */ { 654, 0, 0, BCRYPT_AES_ALGORITHM },
|
||||
/* ALG_ID_MD5 */ { 274, 16, 512, BCRYPT_MD5_ALGORITHM },
|
||||
/* ALG_ID_RNG */ { 0, 0, 0, BCRYPT_RNG_ALGORITHM },
|
||||
/* ALG_ID_SHA1 */ { 278, 20, 512, BCRYPT_SHA1_ALGORITHM },
|
||||
|
@ -210,11 +212,10 @@ NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE handle, UCHAR *buffer, ULONG c
|
|||
|
||||
NTSTATUS WINAPI BCryptOpenAlgorithmProvider( BCRYPT_ALG_HANDLE *handle, LPCWSTR id, LPCWSTR implementation, DWORD flags )
|
||||
{
|
||||
const DWORD supported_flags = BCRYPT_ALG_HANDLE_HMAC_FLAG;
|
||||
struct algorithm *alg;
|
||||
enum alg_id alg_id;
|
||||
|
||||
const DWORD supported_flags = BCRYPT_ALG_HANDLE_HMAC_FLAG;
|
||||
|
||||
TRACE( "%p, %s, %s, %08x\n", handle, wine_dbgstr_w(id), wine_dbgstr_w(implementation), flags );
|
||||
|
||||
if (!handle || !id) return STATUS_INVALID_PARAMETER;
|
||||
|
@ -224,9 +225,10 @@ NTSTATUS WINAPI BCryptOpenAlgorithmProvider( BCRYPT_ALG_HANDLE *handle, LPCWSTR
|
|||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
if (!strcmpW( id, BCRYPT_SHA1_ALGORITHM )) alg_id = ALG_ID_SHA1;
|
||||
if (!strcmpW( id, BCRYPT_AES_ALGORITHM )) alg_id = ALG_ID_AES;
|
||||
else if (!strcmpW( id, BCRYPT_MD5_ALGORITHM )) alg_id = ALG_ID_MD5;
|
||||
else if (!strcmpW( id, BCRYPT_RNG_ALGORITHM )) alg_id = ALG_ID_RNG;
|
||||
else if (!strcmpW( id, BCRYPT_SHA1_ALGORITHM )) alg_id = ALG_ID_SHA1;
|
||||
else if (!strcmpW( id, BCRYPT_SHA256_ALGORITHM )) alg_id = ALG_ID_SHA256;
|
||||
else if (!strcmpW( id, BCRYPT_SHA384_ALGORITHM )) alg_id = ALG_ID_SHA384;
|
||||
else if (!strcmpW( id, BCRYPT_SHA512_ALGORITHM )) alg_id = ALG_ID_SHA512;
|
||||
|
@ -388,6 +390,8 @@ struct hash
|
|||
struct hash_impl inner;
|
||||
};
|
||||
|
||||
#define BLOCK_LENGTH_AES 16
|
||||
|
||||
static NTSTATUS generic_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size )
|
||||
{
|
||||
if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
|
||||
|
@ -432,9 +436,43 @@ static NTSTATUS get_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *buf,
|
|||
NTSTATUS status;
|
||||
|
||||
status = generic_alg_property( id, prop, buf, size, ret_size );
|
||||
if (status == STATUS_NOT_IMPLEMENTED)
|
||||
FIXME( "unsupported property %s\n", debugstr_w(prop) );
|
||||
if (status != STATUS_NOT_IMPLEMENTED)
|
||||
return status;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case ALG_ID_AES:
|
||||
if (!strcmpW( prop, BCRYPT_BLOCK_LENGTH ))
|
||||
{
|
||||
*ret_size = sizeof(ULONG);
|
||||
if (size < sizeof(ULONG))
|
||||
return STATUS_BUFFER_TOO_SMALL;
|
||||
if (buf)
|
||||
*(ULONG *)buf = BLOCK_LENGTH_AES;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
if (!strcmpW( prop, BCRYPT_CHAINING_MODE ))
|
||||
{
|
||||
if (size >= sizeof(BCRYPT_CHAIN_MODE_CBC))
|
||||
{
|
||||
memcpy(buf, BCRYPT_CHAIN_MODE_CBC, sizeof(BCRYPT_CHAIN_MODE_CBC));
|
||||
*ret_size = sizeof(BCRYPT_CHAIN_MODE_CBC) * sizeof(WCHAR);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ret_size = sizeof(BCRYPT_CHAIN_MODE_CBC) * sizeof(WCHAR);
|
||||
return STATUS_BUFFER_TOO_SMALL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
FIXME( "unsupported property %s\n", debugstr_w(prop) );
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static NTSTATUS get_hash_property( enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size )
|
||||
|
@ -632,6 +670,14 @@ NTSTATUS WINAPI BCryptHash( BCRYPT_ALG_HANDLE algorithm, UCHAR *secret, ULONG se
|
|||
return BCryptDestroyHash( handle );
|
||||
}
|
||||
|
||||
NTSTATUS WINAPI BCryptGenerateSymmetricKey( BCRYPT_ALG_HANDLE algorithm, BCRYPT_KEY_HANDLE *handle,
|
||||
UCHAR *object, ULONG object_len, UCHAR *secret, ULONG secret_len,
|
||||
ULONG flags )
|
||||
{
|
||||
FIXME( "%p, %p, %p, %u, %p, %u, %08x\n", algorithm, handle, object, object_len, secret, secret_len, flags );
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
|
||||
{
|
||||
switch (reason)
|
||||
|
|
|
@ -704,7 +704,7 @@ static void test_aes(void)
|
|||
ULONG size, len;
|
||||
UCHAR mode[64];
|
||||
NTSTATUS ret;
|
||||
todo_wine {
|
||||
|
||||
alg = NULL;
|
||||
ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_AES_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
|
||||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
|
@ -738,7 +738,6 @@ todo_wine {
|
|||
ret = pBCryptCloseAlgorithmProvider(alg, 0);
|
||||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_BCryptGenerateSymmetricKey(void)
|
||||
{
|
||||
|
@ -757,11 +756,6 @@ static void test_BCryptGenerateSymmetricKey(void)
|
|||
NTSTATUS ret;
|
||||
|
||||
ret = pBCryptOpenAlgorithmProvider(&aes, BCRYPT_AES_ALGORITHM, NULL, 0);
|
||||
if (ret != STATUS_SUCCESS) /* remove whole IF when Wine is fixed */
|
||||
{
|
||||
todo_wine ok(0, "AES provider not available\n");
|
||||
return;
|
||||
}
|
||||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
|
||||
len = size = 0xdeadbeef;
|
||||
|
@ -771,6 +765,11 @@ static void test_BCryptGenerateSymmetricKey(void)
|
|||
key = NULL;
|
||||
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
|
||||
ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
|
||||
if (ret == STATUS_NOT_IMPLEMENTED) /* remove whole IF when Wine is fixed */
|
||||
{
|
||||
todo_wine ok(0, "BCryptGenerateSymmetricKey not implemented\n");
|
||||
return;
|
||||
}
|
||||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
ok(key != NULL, "key not set\n");
|
||||
|
||||
|
@ -846,11 +845,6 @@ static void test_BCryptEncrypt(void)
|
|||
NTSTATUS ret;
|
||||
|
||||
ret = pBCryptOpenAlgorithmProvider(&aes, BCRYPT_AES_ALGORITHM, NULL, 0);
|
||||
if (ret != STATUS_SUCCESS) /* remove whole IF when Wine is fixed */
|
||||
{
|
||||
todo_wine ok(0, "AES provider not available\n");
|
||||
return;
|
||||
}
|
||||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
|
||||
len = 0xdeadbeef;
|
||||
|
@ -860,6 +854,11 @@ static void test_BCryptEncrypt(void)
|
|||
|
||||
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
|
||||
ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
|
||||
if (ret == STATUS_NOT_IMPLEMENTED) /* remove whole IF when Wine is fixed */
|
||||
{
|
||||
todo_wine ok(0, "BCryptGenerateSymmetricKey not implemented\n");
|
||||
return;
|
||||
}
|
||||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
|
||||
/* input size is a multiple of block size */
|
||||
|
@ -937,11 +936,6 @@ static void test_BCryptDecrypt(void)
|
|||
NTSTATUS ret;
|
||||
|
||||
ret = pBCryptOpenAlgorithmProvider(&aes, BCRYPT_AES_ALGORITHM, NULL, 0);
|
||||
if (ret != STATUS_SUCCESS) /* remove whole IF when Wine is fixed */
|
||||
{
|
||||
todo_wine ok(0, "AES provider not available\n");
|
||||
return;
|
||||
}
|
||||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
|
||||
len = 0xdeadbeef;
|
||||
|
@ -951,6 +945,11 @@ static void test_BCryptDecrypt(void)
|
|||
|
||||
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
|
||||
ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
|
||||
if (ret == STATUS_NOT_IMPLEMENTED) /* remove whole IF when Wine is fixed */
|
||||
{
|
||||
todo_wine ok(0, "BCryptGenerateSymmetricKey not implemented\n");
|
||||
return;
|
||||
}
|
||||
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
||||
|
||||
/* input size is a multiple of block size */
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
@ stub BCryptFreeBuffer
|
||||
@ stdcall BCryptGenRandom(ptr ptr long long) bcrypt.BCryptGenRandom
|
||||
@ stub BCryptGenerateKeyPair
|
||||
@ stub BCryptGenerateSymmetricKey
|
||||
@ stdcall BCryptGenerateSymmetricKey(ptr ptr ptr long ptr long long) bcrypt.BCryptGenerateSymmetricKey
|
||||
@ stdcall BCryptGetFipsAlgorithmMode(ptr) bcrypt.BCryptGetFipsAlgorithmMode
|
||||
@ stdcall BCryptGetProperty(ptr wstr ptr long ptr long) bcrypt.BCryptGetProperty
|
||||
@ stdcall BCryptHash(ptr ptr long ptr long ptr long) bcrypt.BCryptHash
|
||||
|
|
Loading…
Reference in a new issue