Commit df83abb2 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

bcrypt: Add support for generating DH keys.

parent 81d71ee0
......@@ -132,6 +132,7 @@ enum alg_id
ALG_ID_RSA,
/* secret agreement */
ALG_ID_DH,
ALG_ID_ECDH_P256,
ALG_ID_ECDH_P384,
......
......@@ -114,6 +114,7 @@ builtin_algorithms[] =
{ BCRYPT_MD4_ALGORITHM, BCRYPT_HASH_INTERFACE, 270, 16, 512 },
{ BCRYPT_MD2_ALGORITHM, BCRYPT_HASH_INTERFACE, 270, 16, 128 },
{ BCRYPT_RSA_ALGORITHM, BCRYPT_ASYMMETRIC_ENCRYPTION_INTERFACE, 0, 0, 0 },
{ BCRYPT_DH_ALGORITHM, BCRYPT_SECRET_AGREEMENT_INTERFACE, 0, 0, 0 },
{ BCRYPT_ECDH_P256_ALGORITHM, BCRYPT_SECRET_AGREEMENT_INTERFACE, 0, 0, 0 },
{ BCRYPT_ECDH_P384_ALGORITHM, BCRYPT_SECRET_AGREEMENT_INTERFACE, 0, 0, 0 },
{ BCRYPT_RSA_SIGN_ALGORITHM, BCRYPT_SIGNATURE_INTERFACE, 0, 0, 0 },
......@@ -237,7 +238,7 @@ static const struct algorithm pseudo_algorithms[] =
{{ 0 }}, /* RC2_CBC */
{{ 0 }}, /* RC2_ECB */
{{ 0 }}, /* RC2_CFB */
{{ 0 }}, /* DH */
{{ MAGIC_ALG }, ALG_ID_DH },
{{ 0 }}, /* ECDH */
{{ MAGIC_ALG }, ALG_ID_ECDH_P256 },
{{ MAGIC_ALG }, ALG_ID_ECDH_P384 },
......
......@@ -982,6 +982,11 @@ static NTSTATUS key_asymmetric_generate( void *args )
bitlen = key->u.a.bitlen;
break;
case ALG_ID_DH:
pk_alg = GNUTLS_PK_DH;
bitlen = key->u.a.bitlen;
break;
case ALG_ID_DSA:
pk_alg = GNUTLS_PK_DSA;
bitlen = key->u.a.bitlen;
......
......@@ -3137,6 +3137,22 @@ derive_end:
BCryptCloseAlgorithmProvider(alg, 0);
}
static void test_DH(void)
{
BCRYPT_KEY_HANDLE key;
NTSTATUS status;
key = NULL;
status = BCryptGenerateKeyPair(BCRYPT_DH_ALG_HANDLE, &key, 512, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
ok(key != NULL, "key not set\n");
status = BCryptFinalizeKeyPair(key, 0);
todo_wine ok(status == STATUS_SUCCESS, "got %#lx\n", status);
BCryptDestroyKey(key);
}
static void test_BCryptEnumContextFunctions(void)
{
CRYPT_CONTEXT_FUNCTIONS *buffer;
......@@ -3724,6 +3740,7 @@ START_TEST(bcrypt)
test_RSA();
test_RSA_SIGN();
test_ECDH();
test_DH();
test_BCryptEnumContextFunctions();
test_BCryptSignHash();
test_BCryptEnumAlgorithms();
......
......@@ -71,6 +71,8 @@ typedef LONG NTSTATUS;
#define BCRYPT_DSA_PRIVATE_BLOB L"DSAPRIVATEBLOB"
#define BCRYPT_PUBLIC_KEY_BLOB L"PUBLICBLOB"
#define BCRYPT_PRIVATE_KEY_BLOB L"PRIVATEBLOB"
#define BCRYPT_DH_PUBLIC_BLOB L"DHPUBLICBLOB"
#define BCRYPT_DH_PRIVATE_BLOB L"DHPRIVATEBLOB"
#define LEGACY_DSA_PUBLIC_BLOB L"CAPIDSAPUBLICBLOB"
#define LEGACY_DSA_PRIVATE_BLOB L"CAPIDSAPRIVATEBLOB"
#define LEGACY_DSA_V2_PUBLIC_BLOB L"V2CAPIDSAPUBLICBLOB"
......@@ -84,6 +86,7 @@ typedef LONG NTSTATUS;
#define BCRYPT_3DES_ALGORITHM L"3DES"
#define BCRYPT_AES_ALGORITHM L"AES"
#define BCRYPT_DES_ALGORITHM L"DES"
#define BCRYPT_DH_ALGORITHM L"DH"
#define BCRYPT_DSA_ALGORITHM L"DSA"
#define BCRYPT_ECDH_P256_ALGORITHM L"ECDH_P256"
#define BCRYPT_ECDH_P384_ALGORITHM L"ECDH_P384"
......@@ -146,6 +149,8 @@ static const WCHAR BCRYPT_DSA_PUBLIC_BLOB[] = {'D','S','A','P','U','B','L','I','
static const WCHAR BCRYPT_DSA_PRIVATE_BLOB[] = {'D','S','A','P','R','I','V','A','T','E','B','L','O','B',0};
static const WCHAR BCRYPT_PUBLIC_KEY_BLOB[] = {'P','U','B','L','I','C','B','L','O','B',0};
static const WCHAR BCRYPT_PRIVATE_KEY_BLOB[] = {'P','R','I','V','A','T','E','B','L','O','B',0};
static const WCHAR BCRYPT_DH_PUBLIC_BLOB[] = {'D','H','P','U','B','L','I','C','B','L','O','B',0};
static const WCHAR BCRYPT_DH_PRIVATE_BLOB[] = {'D','H','P','R','I','V','A','T','E','B','L','O','B',0};
static const WCHAR LEGACY_DSA_PUBLIC_BLOB[] = {'C','A','P','I','D','S','A','P','U','B','L','I','C','B','L','O','B',0};
static const WCHAR LEGACY_DSA_PRIVATE_BLOB[] = {'C','A','P','I','D','S','A','P','R','I','V','A','T','E','B','L','O','B',0};
static const WCHAR LEGACY_DSA_V2_PUBLIC_BLOB[] = {'V','2','C','A','P','I','D','S','A','P','U','B','L','I','C','B','L','O','B',0};
......@@ -161,6 +166,7 @@ static const WCHAR MS_PLATFORM_CRYPTO_PROVIDER[] = \
static const WCHAR BCRYPT_3DES_ALGORITHM[] = {'3','D','E','S',0};
static const WCHAR BCRYPT_AES_ALGORITHM[] = {'A','E','S',0};
static const WCHAR BCRYPT_DES_ALGORITHM[] = {'D','E','S',0};
static const WCHAR BCRYPT_DH_ALGORITHM[] = {'D','H',0};
static const WCHAR BCRYPT_DSA_ALGORITHM[] = {'D','S','A',0};
static const WCHAR BCRYPT_ECDH_P256_ALGORITHM[] = {'E','C','D','H','_','P','2','5','6',0};
static const WCHAR BCRYPT_ECDH_P384_ALGORITHM[] = {'E','C','D','H','_','P','3','8','4',0};
......@@ -348,6 +354,15 @@ typedef struct _BCRYPT_DSA_KEY_BLOB_V2
UCHAR Count[4];
} BCRYPT_DSA_KEY_BLOB_V2, *PBCRYPT_DSA_KEY_BLOB_V2;
#define BCRYPT_DH_PUBLIC_MAGIC 0x42504844
#define BCRYPT_DH_PRIVATE_MAGIC 0x56504844
typedef struct _BCRYPT_DH_KEY_BLOB
{
ULONG dwMagic;
ULONG cbKey;
} BCRYPT_DH_KEY_BLOB, *PBCRYPT_DH_KEY_BLOB;
#define BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_VERSION 1
#define BCRYPT_AUTH_MODE_CHAIN_CALLS_FLAG 0x00000001
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment