2017-03-11 12:56:22 -08:00
|
|
|
From b05734fe9746e5dbbfcf248b2b892d6e09006956 Mon Sep 17 00:00:00 2001
|
2016-12-20 13:36:51 -08:00
|
|
|
From: Hans Leidekker <hans@codeweavers.com>
|
|
|
|
Date: Mon, 19 Dec 2016 19:38:52 +0100
|
|
|
|
Subject: bcrypt: Add AES provider.
|
|
|
|
|
|
|
|
---
|
|
|
|
dlls/bcrypt/bcrypt.spec | 10 +-
|
2017-03-11 12:56:22 -08:00
|
|
|
dlls/bcrypt/bcrypt_main.c | 353 ++++++++++++++++++++++++++++++++++++++++++++-
|
2016-12-20 13:36:51 -08:00
|
|
|
dlls/bcrypt/tests/bcrypt.c | 18 +--
|
2017-01-19 02:02:48 -08:00
|
|
|
dlls/ncrypt/ncrypt.spec | 10 +-
|
2016-12-20 13:36:51 -08:00
|
|
|
include/bcrypt.h | 3 +
|
2017-03-11 12:56:22 -08:00
|
|
|
5 files changed, 361 insertions(+), 33 deletions(-)
|
2016-12-20 13:36:51 -08:00
|
|
|
|
|
|
|
diff --git a/dlls/bcrypt/bcrypt.spec b/dlls/bcrypt/bcrypt.spec
|
2017-03-11 12:56:22 -08:00
|
|
|
index a1cce4423dc..9ecd21d767c 100644
|
2016-12-20 13:36:51 -08:00
|
|
|
--- a/dlls/bcrypt/bcrypt.spec
|
|
|
|
+++ b/dlls/bcrypt/bcrypt.spec
|
|
|
|
@@ -5,15 +5,15 @@
|
|
|
|
@ stub BCryptConfigureContextFunction
|
|
|
|
@ stub BCryptCreateContext
|
|
|
|
@ stdcall BCryptCreateHash(ptr ptr ptr long ptr long long)
|
|
|
|
-@ stub BCryptDecrypt
|
|
|
|
+@ stdcall BCryptDecrypt(ptr ptr long ptr ptr long ptr long ptr long)
|
|
|
|
@ stub BCryptDeleteContext
|
|
|
|
@ stub BCryptDeriveKey
|
|
|
|
@ stdcall BCryptDestroyHash(ptr)
|
|
|
|
-@ stub BCryptDestroyKey
|
|
|
|
+@ stdcall BCryptDestroyKey(ptr)
|
|
|
|
@ stub BCryptDestroySecret
|
2017-03-11 12:56:22 -08:00
|
|
|
@ stdcall BCryptDuplicateHash(ptr ptr ptr long long)
|
2016-12-20 13:36:51 -08:00
|
|
|
@ stub BCryptDuplicateKey
|
|
|
|
-@ stub BCryptEncrypt
|
|
|
|
+@ stdcall BCryptEncrypt(ptr ptr long ptr ptr long ptr long ptr long)
|
|
|
|
@ stdcall BCryptEnumAlgorithms(long ptr ptr long)
|
|
|
|
@ stub BCryptEnumContextFunctionProviders
|
|
|
|
@ stub BCryptEnumContextFunctions
|
|
|
|
@@ -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)
|
|
|
|
@@ -46,7 +46,7 @@
|
|
|
|
@ stub BCryptSecretAgreement
|
|
|
|
@ stub BCryptSetAuditingInterface
|
|
|
|
@ stub BCryptSetContextFunctionProperty
|
|
|
|
-@ stub BCryptSetProperty
|
|
|
|
+@ stdcall BCryptSetProperty(ptr wstr ptr long long)
|
|
|
|
@ stub BCryptSignHash
|
|
|
|
@ stub BCryptUnregisterConfigChangeNotify
|
|
|
|
@ stub BCryptUnregisterProvider
|
|
|
|
diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
|
2017-03-11 12:56:22 -08:00
|
|
|
index 80d7ddb9466..247b3dc7327 100644
|
2016-12-20 13:36:51 -08:00
|
|
|
--- a/dlls/bcrypt/bcrypt_main.c
|
|
|
|
+++ b/dlls/bcrypt/bcrypt_main.c
|
2017-03-09 19:53:06 -08:00
|
|
|
@@ -51,6 +51,10 @@ WINE_DECLARE_DEBUG_CHANNEL(winediag);
|
2016-12-20 13:36:51 -08:00
|
|
|
|
|
|
|
static void *libgnutls_handle;
|
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
|
|
|
|
+MAKE_FUNCPTR(gnutls_cipher_init);
|
|
|
|
+MAKE_FUNCPTR(gnutls_cipher_deinit);
|
|
|
|
+MAKE_FUNCPTR(gnutls_cipher_encrypt2);
|
|
|
|
+MAKE_FUNCPTR(gnutls_cipher_decrypt2);
|
|
|
|
MAKE_FUNCPTR(gnutls_global_deinit);
|
|
|
|
MAKE_FUNCPTR(gnutls_global_init);
|
|
|
|
MAKE_FUNCPTR(gnutls_global_set_log_function);
|
2017-03-09 19:53:06 -08:00
|
|
|
@@ -80,6 +84,10 @@ static BOOL gnutls_initialize(void)
|
2016-12-20 13:36:51 -08:00
|
|
|
goto fail; \
|
|
|
|
}
|
|
|
|
|
|
|
|
+ LOAD_FUNCPTR(gnutls_cipher_init)
|
|
|
|
+ LOAD_FUNCPTR(gnutls_cipher_deinit)
|
|
|
|
+ LOAD_FUNCPTR(gnutls_cipher_encrypt2)
|
|
|
|
+ LOAD_FUNCPTR(gnutls_cipher_decrypt2)
|
|
|
|
LOAD_FUNCPTR(gnutls_global_deinit)
|
|
|
|
LOAD_FUNCPTR(gnutls_global_init)
|
|
|
|
LOAD_FUNCPTR(gnutls_global_set_log_function)
|
2017-03-09 19:53:06 -08:00
|
|
|
@@ -128,6 +136,7 @@ NTSTATUS WINAPI BCryptEnumAlgorithms(ULONG dwAlgOperations, ULONG *pAlgCount,
|
2016-12-20 13:36:51 -08:00
|
|
|
|
|
|
|
#define MAGIC_ALG (('A' << 24) | ('L' << 16) | ('G' << 8) | '0')
|
|
|
|
#define MAGIC_HASH (('H' << 24) | ('A' << 16) | ('S' << 8) | 'H')
|
|
|
|
+#define MAGIC_KEY (('K' << 24) | ('E' << 16) | ('Y' << 8) | '0')
|
|
|
|
struct object
|
|
|
|
{
|
|
|
|
ULONG magic;
|
2017-03-09 19:53:06 -08:00
|
|
|
@@ -135,6 +144,7 @@ struct object
|
2016-12-20 13:36:51 -08:00
|
|
|
|
|
|
|
enum alg_id
|
|
|
|
{
|
|
|
|
+ ALG_ID_AES,
|
|
|
|
ALG_ID_MD5,
|
|
|
|
ALG_ID_RNG,
|
|
|
|
ALG_ID_SHA1,
|
2017-03-11 12:56:22 -08:00
|
|
|
@@ -152,6 +162,7 @@ static const struct {
|
2017-03-09 19:53:06 -08:00
|
|
|
ULONG block_bits;
|
2016-12-20 13:36:51 -08:00
|
|
|
const WCHAR *alg_name;
|
|
|
|
} alg_props[] = {
|
2017-03-11 12:56:22 -08:00
|
|
|
+ /* 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 +221,10 @@ NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE handle, UCHAR *buffer, ULONG c
|
2016-12-20 13:36:51 -08:00
|
|
|
|
|
|
|
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;
|
2017-03-11 12:56:22 -08:00
|
|
|
@@ -224,9 +234,10 @@ NTSTATUS WINAPI BCryptOpenAlgorithmProvider( BCRYPT_ALG_HANDLE *handle, LPCWSTR
|
2016-12-20 13:36:51 -08:00
|
|
|
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;
|
2017-03-11 12:56:22 -08:00
|
|
|
@@ -388,6 +399,8 @@ struct hash
|
2017-03-09 19:53:06 -08:00
|
|
|
struct hash_impl inner;
|
|
|
|
};
|
2016-12-20 13:36:51 -08:00
|
|
|
|
|
|
|
+#define BLOCK_LENGTH_AES 16
|
|
|
|
+
|
|
|
|
static NTSTATUS generic_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size )
|
|
|
|
{
|
2017-03-11 12:56:22 -08:00
|
|
|
if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
|
|
|
|
@@ -432,9 +445,43 @@ static NTSTATUS get_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *buf,
|
|
|
|
NTSTATUS status;
|
2016-12-20 13:36:51 -08:00
|
|
|
|
2017-03-11 12:56:22 -08:00
|
|
|
status = generic_alg_property( id, prop, buf, size, ret_size );
|
|
|
|
- if (status == STATUS_NOT_IMPLEMENTED)
|
|
|
|
- FIXME( "unsupported property %s\n", debugstr_w(prop) );
|
|
|
|
- return status;
|
|
|
|
+ if (status != STATUS_NOT_IMPLEMENTED)
|
|
|
|
+ return status;
|
|
|
|
+
|
|
|
|
+ switch (id)
|
|
|
|
+ {
|
2016-12-20 13:36:51 -08:00
|
|
|
+ case ALG_ID_AES:
|
|
|
|
+ if (!strcmpW( prop, BCRYPT_BLOCK_LENGTH ))
|
|
|
|
+ {
|
2017-03-11 12:56:22 -08:00
|
|
|
+ *ret_size = sizeof(ULONG);
|
|
|
|
+ if (size < sizeof(ULONG))
|
|
|
|
+ return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
+ if (buf)
|
|
|
|
+ *(ULONG *)buf = BLOCK_LENGTH_AES;
|
|
|
|
+ return STATUS_SUCCESS;
|
2016-12-20 13:36:51 -08:00
|
|
|
+ }
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ }
|
2017-03-11 12:56:22 -08:00
|
|
|
+ break;
|
2016-12-20 13:36:51 -08:00
|
|
|
+
|
2017-03-11 12:56:22 -08:00
|
|
|
+ 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 )
|
|
|
|
@@ -474,6 +521,13 @@ NTSTATUS WINAPI BCryptGetProperty( BCRYPT_HANDLE handle, LPCWSTR prop, UCHAR *bu
|
2016-12-20 13:36:51 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+NTSTATUS WINAPI BCryptSetProperty( BCRYPT_HANDLE handle, const WCHAR *prop, UCHAR *value,
|
|
|
|
+ ULONG size, ULONG flags )
|
|
|
|
+{
|
|
|
|
+ FIXME( "%p, %s, %p, %u, %08x\n", handle, debugstr_w(prop), value, size, flags );
|
|
|
|
+ return STATUS_NOT_IMPLEMENTED;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
NTSTATUS WINAPI BCryptCreateHash( BCRYPT_ALG_HANDLE algorithm, BCRYPT_HASH_HANDLE *handle, UCHAR *object, ULONG objectlen,
|
|
|
|
UCHAR *secret, ULONG secretlen, ULONG flags )
|
|
|
|
{
|
2017-03-11 12:56:22 -08:00
|
|
|
@@ -632,6 +686,293 @@ NTSTATUS WINAPI BCryptHash( BCRYPT_ALG_HANDLE algorithm, UCHAR *secret, ULONG se
|
2016-12-20 13:36:51 -08:00
|
|
|
return BCryptDestroyHash( handle );
|
|
|
|
}
|
|
|
|
|
2017-01-29 03:46:25 -08:00
|
|
|
+#if defined(HAVE_GNUTLS_HASH) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
|
2016-12-20 13:36:51 -08:00
|
|
|
+struct key
|
|
|
|
+{
|
|
|
|
+ struct object hdr;
|
|
|
|
+ enum alg_id alg_id;
|
|
|
|
+ ULONG block_size;
|
|
|
|
+ gnutls_cipher_hd_t handle;
|
|
|
|
+ UCHAR *secret;
|
|
|
|
+ ULONG secret_len;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static ULONG get_block_size( enum alg_id alg )
|
|
|
|
+{
|
|
|
|
+ ULONG ret = 0, size = sizeof(ret);
|
|
|
|
+ get_alg_property( alg, BCRYPT_BLOCK_LENGTH, (UCHAR *)&ret, sizeof(ret), &size );
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static NTSTATUS key_init( struct key *key, enum alg_id id, UCHAR *secret, ULONG secret_len )
|
|
|
|
+{
|
|
|
|
+ if (!libgnutls_handle) return STATUS_INTERNAL_ERROR;
|
|
|
|
+
|
|
|
|
+ switch (id)
|
|
|
|
+ {
|
|
|
|
+ case ALG_ID_AES:
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ FIXME( "algorithm %u not supported\n", id );
|
|
|
|
+ return STATUS_NOT_SUPPORTED;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!(key->block_size = get_block_size( id ))) return STATUS_INVALID_PARAMETER;
|
|
|
|
+
|
|
|
|
+ key->alg_id = id;
|
|
|
|
+ key->handle = 0; /* initialized on first use */
|
|
|
|
+ key->secret = secret;
|
|
|
|
+ key->secret_len = secret_len;
|
|
|
|
+
|
|
|
|
+ return STATUS_SUCCESS;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static gnutls_cipher_algorithm_t get_gnutls_cipher( const struct key *key )
|
|
|
|
+{
|
|
|
|
+ switch (key->alg_id)
|
|
|
|
+ {
|
|
|
|
+ case ALG_ID_AES:
|
|
|
|
+ FIXME( "handle block size and chaining mode\n" );
|
|
|
|
+ return GNUTLS_CIPHER_AES_128_CBC;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ FIXME( "algorithm %u not supported\n", key->alg_id );
|
|
|
|
+ return GNUTLS_CIPHER_UNKNOWN;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static NTSTATUS key_set_params( struct key *key, UCHAR *iv, ULONG iv_len )
|
|
|
|
+{
|
|
|
|
+ gnutls_cipher_algorithm_t cipher;
|
|
|
|
+ gnutls_datum_t secret, vector;
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ if (key->handle)
|
|
|
|
+ {
|
|
|
|
+ pgnutls_cipher_deinit( key->handle );
|
|
|
|
+ key->handle = NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ((cipher = get_gnutls_cipher( key )) == GNUTLS_CIPHER_UNKNOWN)
|
|
|
|
+ return STATUS_NOT_SUPPORTED;
|
|
|
|
+
|
|
|
|
+ secret.data = key->secret;
|
|
|
|
+ secret.size = key->secret_len;
|
|
|
|
+ if (iv)
|
|
|
|
+ {
|
|
|
|
+ vector.data = iv;
|
|
|
|
+ vector.size = iv_len;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ((ret = pgnutls_cipher_init( &key->handle, cipher, &secret, iv ? &vector : NULL )))
|
|
|
|
+ {
|
|
|
|
+ pgnutls_perror( ret );
|
|
|
|
+ return STATUS_INTERNAL_ERROR;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return STATUS_SUCCESS;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static NTSTATUS key_encrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output,
|
|
|
|
+ ULONG output_len )
|
|
|
|
+{
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ if ((ret = pgnutls_cipher_encrypt2( key->handle, input, input_len, output, output_len )))
|
|
|
|
+ {
|
|
|
|
+ pgnutls_perror( ret );
|
|
|
|
+ return STATUS_INTERNAL_ERROR;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return STATUS_SUCCESS;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static NTSTATUS key_decrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output,
|
|
|
|
+ ULONG output_len )
|
|
|
|
+{
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ if ((ret = pgnutls_cipher_decrypt2( key->handle, input, input_len, output, output_len )))
|
|
|
|
+ {
|
|
|
|
+ pgnutls_perror( ret );
|
|
|
|
+ return STATUS_INTERNAL_ERROR;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return STATUS_SUCCESS;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static NTSTATUS key_destroy( struct key *key )
|
|
|
|
+{
|
|
|
|
+ if (key->handle) pgnutls_cipher_deinit( key->handle );
|
|
|
|
+ HeapFree( GetProcessHeap(), 0, key->secret );
|
|
|
|
+ HeapFree( GetProcessHeap(), 0, key );
|
|
|
|
+ return STATUS_SUCCESS;
|
|
|
|
+}
|
|
|
|
+#else
|
|
|
|
+struct key
|
|
|
|
+{
|
|
|
|
+ struct object hdr;
|
|
|
|
+ ULONG block_size;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static NTSTATUS key_init( struct key *key, enum alg_id id, const UCHAR *secret, ULONG secret_len )
|
|
|
|
+{
|
|
|
|
+ ERR( "support for keys not available at build time\n" );
|
|
|
|
+ return STATUS_NOT_IMPLEMENTED;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static NTSTATUS key_set_params( struct key *key, UCHAR *iv, ULONG iv_len )
|
|
|
|
+{
|
|
|
|
+ ERR( "support for keys not available at build time\n" );
|
|
|
|
+ return STATUS_NOT_IMPLEMENTED;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static NTSTATUS key_encrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output,
|
|
|
|
+ ULONG output_len )
|
|
|
|
+{
|
|
|
|
+ ERR( "support for keys not available at build time\n" );
|
|
|
|
+ return STATUS_NOT_IMPLEMENTED;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static NTSTATUS key_decrypt( struct key *key, const UCHAR *input, ULONG input_len, UCHAR *output,
|
|
|
|
+ ULONG output_len )
|
|
|
|
+{
|
|
|
|
+ ERR( "support for keys not available at build time\n" );
|
|
|
|
+ return STATUS_NOT_IMPLEMENTED;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static NTSTATUS key_destroy( struct key *key )
|
|
|
|
+{
|
|
|
|
+ ERR( "support for keys not available at build time\n" );
|
|
|
|
+ return STATUS_NOT_IMPLEMENTED;
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+NTSTATUS WINAPI BCryptGenerateSymmetricKey( BCRYPT_ALG_HANDLE algorithm, BCRYPT_KEY_HANDLE *handle,
|
|
|
|
+ UCHAR *object, ULONG object_len, UCHAR *secret, ULONG secret_len,
|
|
|
|
+ ULONG flags )
|
|
|
|
+{
|
|
|
|
+ struct algorithm *alg = algorithm;
|
|
|
|
+ struct key *key;
|
|
|
|
+ NTSTATUS status;
|
|
|
|
+
|
|
|
|
+ TRACE( "%p, %p, %p, %u, %p, %u, %08x\n", alg, handle, object, object_len, secret, secret_len, flags );
|
|
|
|
+
|
|
|
|
+ if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE;
|
|
|
|
+ if (object) FIXME( "ignoring object buffer\n" );
|
|
|
|
+
|
|
|
|
+ if (!(key = HeapAlloc( GetProcessHeap(), 0, sizeof(*key) ))) return STATUS_NO_MEMORY;
|
|
|
|
+ key->hdr.magic = MAGIC_KEY;
|
|
|
|
+
|
|
|
|
+ if ((status = key_init( key, alg->id, secret, secret_len )))
|
|
|
|
+ {
|
|
|
|
+ HeapFree( GetProcessHeap(), 0, key );
|
|
|
|
+ return status;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ *handle = key;
|
|
|
|
+ return STATUS_SUCCESS;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+NTSTATUS WINAPI BCryptDestroyKey( BCRYPT_KEY_HANDLE handle )
|
|
|
|
+{
|
|
|
|
+ struct key *key = handle;
|
|
|
|
+
|
|
|
|
+ TRACE( "%p\n", handle );
|
|
|
|
+
|
|
|
|
+ if (!key || key->hdr.magic != MAGIC_KEY) return STATUS_INVALID_HANDLE;
|
|
|
|
+ return key_destroy( key );
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+NTSTATUS WINAPI BCryptEncrypt( BCRYPT_KEY_HANDLE handle, UCHAR *input, ULONG input_len,
|
|
|
|
+ void *padding, UCHAR *iv, ULONG iv_len, UCHAR *output,
|
|
|
|
+ ULONG output_len, ULONG *ret_len, ULONG flags )
|
|
|
|
+{
|
|
|
|
+ struct key *key = handle;
|
|
|
|
+ ULONG bytes_left = input_len;
|
|
|
|
+ UCHAR *buf, *src, *dst;
|
|
|
|
+ NTSTATUS status;
|
|
|
|
+
|
|
|
|
+ TRACE( "%p, %p, %u, %p, %p, %u, %p, %u, %p, %08x\n", handle, input, input_len,
|
|
|
|
+ padding, iv, iv_len, output, output_len, ret_len, flags );
|
|
|
|
+
|
|
|
|
+ if (!key || key->hdr.magic != MAGIC_KEY) return STATUS_INVALID_HANDLE;
|
|
|
|
+ if (padding)
|
|
|
|
+ {
|
|
|
|
+ FIXME( "padding info not implemented\n" );
|
|
|
|
+ return STATUS_NOT_IMPLEMENTED;
|
|
|
|
+ }
|
|
|
|
+ if (flags & ~BCRYPT_BLOCK_PADDING)
|
|
|
|
+ {
|
|
|
|
+ FIXME( "flags %08x not implemented\n", flags );
|
|
|
|
+ return STATUS_NOT_IMPLEMENTED;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ((status = key_set_params( key, iv, iv_len ))) return status;
|
|
|
|
+
|
|
|
|
+ *ret_len = input_len;
|
|
|
|
+ if (input_len & (key->block_size - 1))
|
|
|
|
+ {
|
|
|
|
+ if (!(flags & BCRYPT_BLOCK_PADDING)) return STATUS_INVALID_BUFFER_SIZE;
|
|
|
|
+ *ret_len = (input_len + key->block_size - 1) & ~(key->block_size - 1);
|
|
|
|
+ }
|
|
|
|
+ if (!output) return STATUS_SUCCESS;
|
|
|
|
+ if (output_len < *ret_len) return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
+
|
|
|
|
+ src = input;
|
|
|
|
+ dst = output;
|
|
|
|
+ while (bytes_left >= key->block_size)
|
|
|
|
+ {
|
|
|
|
+ if ((status = key_encrypt( key, src, key->block_size, dst, key->block_size ))) return status;
|
|
|
|
+ bytes_left -= key->block_size;
|
|
|
|
+ src += key->block_size;
|
|
|
|
+ dst += key->block_size;
|
|
|
|
+ }
|
|
|
|
+ if (bytes_left)
|
|
|
|
+ {
|
|
|
|
+ if (!(buf = HeapAlloc( GetProcessHeap(), 0, key->block_size ))) return STATUS_NO_MEMORY;
|
|
|
|
+ memcpy( buf, src, bytes_left );
|
|
|
|
+ memset( buf + bytes_left, key->block_size - bytes_left, key->block_size - bytes_left );
|
|
|
|
+ status = key_encrypt( key, buf, key->block_size, dst, key->block_size );
|
|
|
|
+ HeapFree( GetProcessHeap(), 0, buf );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return status;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+NTSTATUS WINAPI BCryptDecrypt( BCRYPT_KEY_HANDLE handle, UCHAR *input, ULONG input_len,
|
|
|
|
+ void *padding, UCHAR *iv, ULONG iv_len, UCHAR *output,
|
|
|
|
+ ULONG output_len, ULONG *ret_len, ULONG flags )
|
|
|
|
+{
|
|
|
|
+ struct key *key = handle;
|
|
|
|
+ NTSTATUS status;
|
|
|
|
+
|
2016-12-25 13:40:45 -08:00
|
|
|
+ TRACE( "%p, %p, %u, %p, %p, %u, %p, %u, %p, %08x\n", handle, input, input_len,
|
2016-12-20 13:36:51 -08:00
|
|
|
+ padding, iv, iv_len, output, output_len, ret_len, flags );
|
|
|
|
+
|
|
|
|
+ if (!key || key->hdr.magic != MAGIC_KEY) return STATUS_INVALID_HANDLE;
|
|
|
|
+ if (padding)
|
|
|
|
+ {
|
|
|
|
+ FIXME( "padding info not implemented\n" );
|
|
|
|
+ return STATUS_NOT_IMPLEMENTED;
|
|
|
|
+ }
|
|
|
|
+ if (flags & ~BCRYPT_BLOCK_PADDING)
|
|
|
|
+ {
|
|
|
|
+ FIXME( "flags %08x not supported\n", flags );
|
|
|
|
+ return STATUS_NOT_IMPLEMENTED;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ((status = key_set_params( key, iv, iv_len ))) return status;
|
|
|
|
+
|
|
|
|
+ *ret_len = input_len;
|
|
|
|
+ if (input_len & (key->block_size - 1)) return STATUS_INVALID_BUFFER_SIZE;
|
|
|
|
+ if (!output) return STATUS_SUCCESS;
|
|
|
|
+ if (output_len < *ret_len) return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
+
|
|
|
|
+ return key_decrypt( key, input, input_len, output, output_len );
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
|
|
|
|
{
|
|
|
|
switch (reason)
|
|
|
|
diff --git a/dlls/bcrypt/tests/bcrypt.c b/dlls/bcrypt/tests/bcrypt.c
|
2017-03-11 12:56:22 -08:00
|
|
|
index 42312b45b78..4d5891b461b 100644
|
2016-12-20 13:36:51 -08:00
|
|
|
--- a/dlls/bcrypt/tests/bcrypt.c
|
|
|
|
+++ b/dlls/bcrypt/tests/bcrypt.c
|
2017-03-11 12:56:22 -08:00
|
|
|
@@ -704,7 +704,7 @@ static void test_aes(void)
|
2016-12-20 13:36:51 -08:00
|
|
|
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);
|
2017-03-11 12:56:22 -08:00
|
|
|
@@ -738,7 +738,6 @@ todo_wine {
|
2016-12-20 13:36:51 -08:00
|
|
|
ret = pBCryptCloseAlgorithmProvider(alg, 0);
|
|
|
|
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
|
|
|
|
}
|
|
|
|
-}
|
|
|
|
|
|
|
|
static void test_BCryptGenerateSymmetricKey(void)
|
|
|
|
{
|
2017-03-11 12:56:22 -08:00
|
|
|
@@ -757,11 +756,6 @@ static void test_BCryptGenerateSymmetricKey(void)
|
2016-12-20 13:36:51 -08:00
|
|
|
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;
|
2017-03-11 12:56:22 -08:00
|
|
|
@@ -846,11 +840,6 @@ static void test_BCryptEncrypt(void)
|
2016-12-20 13:36:51 -08:00
|
|
|
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;
|
2017-03-11 12:56:22 -08:00
|
|
|
@@ -937,11 +926,6 @@ static void test_BCryptDecrypt(void)
|
2016-12-20 13:36:51 -08:00
|
|
|
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;
|
2017-01-19 02:02:48 -08:00
|
|
|
diff --git a/dlls/ncrypt/ncrypt.spec b/dlls/ncrypt/ncrypt.spec
|
2017-03-11 12:56:22 -08:00
|
|
|
index 6e871a5d6b8..1a78853bf49 100644
|
2017-01-19 02:02:48 -08:00
|
|
|
--- a/dlls/ncrypt/ncrypt.spec
|
|
|
|
+++ b/dlls/ncrypt/ncrypt.spec
|
|
|
|
@@ -5,17 +5,17 @@
|
|
|
|
@ stub BCryptConfigureContextFunction
|
|
|
|
@ stub BCryptCreateContext
|
|
|
|
@ stdcall BCryptCreateHash(ptr ptr ptr long ptr long long) bcrypt.BCryptCreateHash
|
|
|
|
-@ stub BCryptDecrypt
|
|
|
|
+@ stdcall BCryptDecrypt(ptr ptr long ptr ptr long ptr long ptr long) bcrypt.BCryptDecrypt
|
|
|
|
@ stub BCryptDeleteContext
|
|
|
|
@ stub BCryptDeriveKey
|
|
|
|
@ stub BCryptDeriveKeyCapi
|
|
|
|
@ stub BCryptDeriveKeyPBKDF2
|
|
|
|
@ stdcall BCryptDestroyHash(ptr) bcrypt.BCryptDestroyHash
|
|
|
|
-@ stub BCryptDestroyKey
|
|
|
|
+@ stdcall BCryptDestroyKey(ptr) bcrypt.BCryptDestroyKey
|
|
|
|
@ stub BCryptDestroySecret
|
2017-03-11 12:56:22 -08:00
|
|
|
@ stdcall BCryptDuplicateHash(ptr ptr ptr long long) bcrypt.BCryptDuplicateHash
|
2017-01-19 02:02:48 -08:00
|
|
|
@ stub BCryptDuplicateKey
|
|
|
|
-@ stub BCryptEncrypt
|
|
|
|
+@ stdcall BCryptEncrypt(ptr ptr long ptr ptr long ptr long ptr long) bcrypt.BCryptEncrypt
|
|
|
|
@ stdcall BCryptEnumAlgorithms(long ptr ptr long) bcrypt.BCryptEnumAlgorithms
|
|
|
|
@ stub BCryptEnumContextFunctionProviders
|
|
|
|
@ stub BCryptEnumContextFunctions
|
|
|
|
@@ -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
|
|
|
|
@@ -49,7 +49,7 @@
|
|
|
|
@ stub BCryptSecretAgreement
|
|
|
|
@ stub BCryptSetAuditingInterface
|
|
|
|
@ stub BCryptSetContextFunctionProperty
|
|
|
|
-@ stub BCryptSetProperty
|
|
|
|
+@ stdcall BCryptSetProperty(ptr wstr ptr long long) bcrypt.BCryptSetProperty
|
|
|
|
@ stub BCryptSignHash
|
|
|
|
@ stub BCryptUnregisterConfigChangeNotify
|
|
|
|
@ stub BCryptUnregisterProvider
|
2016-12-20 13:36:51 -08:00
|
|
|
diff --git a/include/bcrypt.h b/include/bcrypt.h
|
2017-01-19 02:02:48 -08:00
|
|
|
index 05d0691f9c3..6af85e36143 100644
|
2016-12-20 13:36:51 -08:00
|
|
|
--- a/include/bcrypt.h
|
|
|
|
+++ b/include/bcrypt.h
|
|
|
|
@@ -74,6 +74,9 @@ typedef LONG NTSTATUS;
|
|
|
|
#define BCRYPT_CHAIN_MODE_NA (const WCHAR []){'C','h','a','i','n','i','n','g','M','o','d','e','N','/','A',0}
|
|
|
|
#define BCRYPT_CHAIN_MODE_CBC (const WCHAR []){'C','h','a','i','n','i','n','g','M','o','d','e','C','B','C',0}
|
|
|
|
#define BCRYPT_CHAIN_MODE_ECB (const WCHAR []){'C','h','a','i','n','i','n','g','M','o','d','e','E','C','B',0}
|
|
|
|
+#define BCRYPT_CHAIN_MODE_CFB (const WCHAR []){'C','h','a','i','n','i','n','g','M','o','d','e','C','F','B',0}
|
|
|
|
+#define BCRYPT_CHAIN_MODE_CCM (const WCHAR []){'C','h','a','i','n','i','n','g','M','o','d','e','C','C','M',0}
|
|
|
|
+#define BCRYPT_CHAIN_MODE_GCM (const WCHAR []){'C','h','a','i','n','i','n','g','M','o','d','e','G','C','M',0}
|
|
|
|
|
|
|
|
typedef struct _BCRYPT_ALGORITHM_IDENTIFIER
|
|
|
|
{
|
|
|
|
--
|
2017-01-19 02:02:48 -08:00
|
|
|
2.11.0
|
2016-12-20 13:36:51 -08:00
|
|
|
|