bcrypt: Add support for PUBLICKEY blob types.

Signed-off-by: Santino Mazza <mazzasantino1206@gmail.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Santino Mazza 2022-03-04 08:45:17 +01:00 committed by Alexandre Julliard
parent 2c5084e05f
commit b3073dc14a
2 changed files with 44 additions and 0 deletions

View File

@ -1775,6 +1775,34 @@ NTSTATUS WINAPI BCryptImportKeyPair( BCRYPT_ALG_HANDLE algorithm, BCRYPT_KEY_HAN
return STATUS_NOT_IMPLEMENTED;
}
if (!wcscmp( type, BCRYPT_PUBLIC_KEY_BLOB ))
{
BCRYPT_KEY_BLOB *key_blob = (BCRYPT_KEY_BLOB *)input;
if (input_len < sizeof(*key_blob)) return STATUS_INVALID_PARAMETER;
switch (key_blob->Magic)
{
case BCRYPT_ECDH_PUBLIC_P256_MAGIC:
case BCRYPT_ECDSA_PUBLIC_P256_MAGIC:
case BCRYPT_ECDSA_PUBLIC_P384_MAGIC:
type = BCRYPT_ECCPUBLIC_BLOB;
break;
case BCRYPT_RSAPUBLIC_MAGIC:
type = BCRYPT_RSAPUBLIC_BLOB;
break;
case BCRYPT_DSA_PUBLIC_MAGIC:
type = BCRYPT_DSA_PUBLIC_BLOB;
break;
default:
FIXME( "unsupported key magic %#lx\n", key_blob->Magic );
return STATUS_NOT_SUPPORTED;
}
}
return key_import_pair( alg, type, ret_key, input, input_len );
}

View File

@ -1845,6 +1845,10 @@ static void test_ECDSA(void)
ecckey->dwMagic = BCRYPT_ECDSA_PUBLIC_P256_MAGIC;
ecckey->cbKey = 32;
status = BCryptImportKeyPair(alg, NULL, BCRYPT_PUBLIC_KEY_BLOB, &key, buffer, size, 0);
ok(!status, "BCryptImportKeyPair failed: %#lx\n", status);
BCryptDestroyKey(key);
status = BCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &key, buffer, size, 0);
ok(!status, "BCryptImportKeyPair failed: %#lx\n", status);
@ -2015,6 +2019,10 @@ static void test_RSA(void)
ok(schemes, "schemes not set\n");
ok(size == sizeof(schemes), "got %lu\n", size);
ret = BCryptImportKeyPair(alg, NULL, BCRYPT_PUBLIC_KEY_BLOB, &key, rsaPublicBlob, sizeof(rsaPublicBlob), 0);
ok(!ret, "BCryptImportKeyPair failed: %#lx\n", ret);
BCryptDestroyKey(key);
ret = BCryptImportKeyPair(alg, NULL, BCRYPT_RSAPUBLIC_BLOB, &key, rsaPublicBlob, sizeof(rsaPublicBlob), 0);
ok(!ret, "BCryptImportKeyPair failed: %#lx\n", ret);
@ -2341,6 +2349,10 @@ static void test_ECDH(void)
ok(ecckey->cbKey == 32, "got %lu\n", ecckey->cbKey);
ok(size == sizeof(*ecckey) + ecckey->cbKey * 2, "got %lu\n", size);
status = BCryptImportKeyPair(alg, NULL, BCRYPT_PUBLIC_KEY_BLOB, &pubkey, buf, size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
BCryptDestroyKey(pubkey);
status = BCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &pubkey, buf, size, 0);
ok(status == STATUS_SUCCESS, "got %#lx\n", status);
HeapFree(GetProcessHeap(), 0, buf);
@ -2842,6 +2854,10 @@ static void test_DSA(void)
ret = BCryptGetProperty(alg, L"PaddingSchemes", (UCHAR *)&schemes, sizeof(schemes), &size, 0);
ok(ret == STATUS_NOT_SUPPORTED, "got %#lx\n", ret);
ret = BCryptImportKeyPair(alg, NULL, BCRYPT_PUBLIC_KEY_BLOB, &key, dsaPublicBlob, sizeof(dsaPublicBlob), 0);
ok(!ret, "got %#lx\n", ret);
BCryptDestroyKey(key);
ret = BCryptImportKeyPair(alg, NULL, BCRYPT_DSA_PUBLIC_BLOB, &key, dsaPublicBlob, sizeof(dsaPublicBlob), 0);
ok(!ret, "got %#lx\n", ret);