2018-02-28 17:28:01 -08:00
|
|
|
From 790c773742b2a0a4b4a8672de3bdfcbf539dc046 Mon Sep 17 00:00:00 2001
|
2016-12-25 13:40:45 -08:00
|
|
|
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
|
|
|
|
Date: Mon, 26 Dec 2016 08:28:24 +0100
|
2018-02-28 17:28:01 -08:00
|
|
|
Subject: [PATCH 20/36] bcrypt: Implement BCryptDuplicateKey.
|
2016-12-25 13:40:45 -08:00
|
|
|
|
|
|
|
---
|
|
|
|
dlls/bcrypt/bcrypt.spec | 2 +-
|
|
|
|
dlls/bcrypt/bcrypt_main.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
|
2017-01-19 02:02:48 -08:00
|
|
|
dlls/ncrypt/ncrypt.spec | 2 +-
|
|
|
|
3 files changed, 51 insertions(+), 2 deletions(-)
|
2016-12-25 13:40:45 -08:00
|
|
|
|
|
|
|
diff --git a/dlls/bcrypt/bcrypt.spec b/dlls/bcrypt/bcrypt.spec
|
2018-02-28 17:28:01 -08:00
|
|
|
index 21b54b4934..28c2394ce4 100644
|
2016-12-25 13:40:45 -08:00
|
|
|
--- a/dlls/bcrypt/bcrypt.spec
|
|
|
|
+++ b/dlls/bcrypt/bcrypt.spec
|
|
|
|
@@ -12,7 +12,7 @@
|
|
|
|
@ stdcall BCryptDestroyKey(ptr)
|
|
|
|
@ stub BCryptDestroySecret
|
|
|
|
@ stdcall BCryptDuplicateHash(ptr ptr ptr long long)
|
|
|
|
-@ stub BCryptDuplicateKey
|
|
|
|
+@ stdcall BCryptDuplicateKey(ptr ptr ptr long long)
|
|
|
|
@ stdcall BCryptEncrypt(ptr ptr long ptr ptr long ptr long ptr long)
|
|
|
|
@ stdcall BCryptEnumAlgorithms(long ptr ptr long)
|
|
|
|
@ stub BCryptEnumContextFunctionProviders
|
|
|
|
diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
|
2018-02-28 17:28:01 -08:00
|
|
|
index bdf02ca375..8d4b5ade64 100644
|
2016-12-25 13:40:45 -08:00
|
|
|
--- a/dlls/bcrypt/bcrypt_main.c
|
|
|
|
+++ b/dlls/bcrypt/bcrypt_main.c
|
2018-02-28 17:28:01 -08:00
|
|
|
@@ -954,6 +954,24 @@ static NTSTATUS key_init( struct key *key, struct algorithm *alg, const UCHAR *s
|
2016-12-25 13:40:45 -08:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static NTSTATUS key_duplicate( struct key *key_orig, struct key *key_copy )
|
|
|
|
+{
|
|
|
|
+ UCHAR *buffer;
|
|
|
|
+
|
|
|
|
+ if (!(buffer = HeapAlloc( GetProcessHeap(), 0, key_orig->secret_len ))) return STATUS_NO_MEMORY;
|
|
|
|
+ memcpy( buffer, key_orig->secret, key_orig->secret_len );
|
|
|
|
+
|
|
|
|
+ key_copy->hdr = key_orig->hdr;
|
|
|
|
+ key_copy->alg_id = key_orig->alg_id;
|
|
|
|
+ key_copy->mode = key_orig->mode;
|
|
|
|
+ key_copy->block_size = key_orig->block_size;
|
|
|
|
+ key_copy->handle = NULL;
|
|
|
|
+ key_copy->secret = buffer;
|
|
|
|
+ key_copy->secret_len = key_orig->secret_len;
|
|
|
|
+
|
|
|
|
+ return STATUS_SUCCESS;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static gnutls_cipher_algorithm_t get_gnutls_cipher( const struct key *key )
|
|
|
|
{
|
|
|
|
switch (key->alg_id)
|
2018-02-28 17:28:01 -08:00
|
|
|
@@ -1156,6 +1174,13 @@ static NTSTATUS key_init( struct key *key, struct algorithm *alg, const UCHAR *s
|
2016-12-25 13:40:45 -08:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static NTSTATUS key_duplicate( struct key *key_orig, struct key *key_copy )
|
|
|
|
+{
|
|
|
|
+ ERR( "support for keys not available at build time\n" );
|
|
|
|
+ key_copy->mode = MODE_ID_CBC;
|
|
|
|
+ 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" );
|
2018-02-28 17:28:01 -08:00
|
|
|
@@ -1284,6 +1309,30 @@ NTSTATUS WINAPI BCryptExportKey(BCRYPT_KEY_HANDLE export_key, BCRYPT_KEY_HANDLE
|
|
|
|
return key_export( key, type, output, output_len, size );
|
2016-12-25 13:40:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
+NTSTATUS WINAPI BCryptDuplicateKey( BCRYPT_KEY_HANDLE handle, BCRYPT_KEY_HANDLE *handle_copy,
|
|
|
|
+ UCHAR *object, ULONG object_len, ULONG flags )
|
|
|
|
+{
|
|
|
|
+ struct key *key_orig = handle;
|
|
|
|
+ struct key *key_copy;
|
|
|
|
+ NTSTATUS status;
|
|
|
|
+
|
|
|
|
+ TRACE( "%p, %p, %p, %u, %08x\n", handle, handle_copy, object, object_len, flags );
|
|
|
|
+
|
|
|
|
+ if (!key_orig || key_orig->hdr.magic != MAGIC_KEY) return STATUS_INVALID_HANDLE;
|
|
|
|
+ if (!handle_copy) return STATUS_INVALID_PARAMETER;
|
|
|
|
+ if (!(key_copy = HeapAlloc( GetProcessHeap(), 0, sizeof(*key_copy) )))
|
|
|
|
+ return STATUS_NO_MEMORY;
|
|
|
|
+
|
|
|
|
+ if ((status = key_duplicate( key_orig, key_copy )))
|
|
|
|
+ {
|
|
|
|
+ HeapFree( GetProcessHeap(), 0, key_copy );
|
|
|
|
+ return status;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ *handle_copy = key_copy;
|
|
|
|
+ return STATUS_SUCCESS;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
NTSTATUS WINAPI BCryptDestroyKey( BCRYPT_KEY_HANDLE handle )
|
|
|
|
{
|
|
|
|
struct key *key = handle;
|
2017-01-19 02:02:48 -08:00
|
|
|
diff --git a/dlls/ncrypt/ncrypt.spec b/dlls/ncrypt/ncrypt.spec
|
2018-02-28 17:28:01 -08:00
|
|
|
index 5d5fae0b5c..d0f0f56cc4 100644
|
2017-01-19 02:02:48 -08:00
|
|
|
--- a/dlls/ncrypt/ncrypt.spec
|
|
|
|
+++ b/dlls/ncrypt/ncrypt.spec
|
|
|
|
@@ -14,7 +14,7 @@
|
|
|
|
@ stdcall BCryptDestroyKey(ptr) bcrypt.BCryptDestroyKey
|
|
|
|
@ stub BCryptDestroySecret
|
|
|
|
@ stdcall BCryptDuplicateHash(ptr ptr ptr long long) bcrypt.BCryptDuplicateHash
|
|
|
|
-@ stub BCryptDuplicateKey
|
|
|
|
+@ stdcall BCryptDuplicateKey(ptr ptr ptr long long) bcrypt.BCryptDuplicateKey
|
|
|
|
@ stdcall BCryptEncrypt(ptr ptr long ptr ptr long ptr long ptr long) bcrypt.BCryptEncrypt
|
|
|
|
@ stdcall BCryptEnumAlgorithms(long ptr ptr long) bcrypt.BCryptEnumAlgorithms
|
|
|
|
@ stub BCryptEnumContextFunctionProviders
|
2016-12-25 13:40:45 -08:00
|
|
|
--
|
2018-02-28 17:28:01 -08:00
|
|
|
2.16.1
|
2016-12-25 13:40:45 -08:00
|
|
|
|