Commit 27cdb54b authored by Santino Mazza's avatar Santino Mazza Committed by Alexandre Julliard

ncrypt: Initial implementation for NCryptEncrypt.

parent dd61c563
...@@ -43,6 +43,7 @@ static SECURITY_STATUS map_ntstatus(NTSTATUS status) ...@@ -43,6 +43,7 @@ static SECURITY_STATUS map_ntstatus(NTSTATUS status)
case STATUS_NO_MEMORY: return NTE_NO_MEMORY; case STATUS_NO_MEMORY: return NTE_NO_MEMORY;
case STATUS_NOT_SUPPORTED: return NTE_NOT_SUPPORTED; case STATUS_NOT_SUPPORTED: return NTE_NOT_SUPPORTED;
case NTE_BAD_DATA: return NTE_BAD_DATA; case NTE_BAD_DATA: return NTE_BAD_DATA;
case STATUS_BUFFER_TOO_SMALL: return NTE_BUFFER_TOO_SMALL;
default: default:
FIXME("unhandled status %#lx\n", status); FIXME("unhandled status %#lx\n", status);
return NTE_INTERNAL_ERROR; return NTE_INTERNAL_ERROR;
...@@ -227,9 +228,28 @@ SECURITY_STATUS WINAPI NCryptDeleteKey(NCRYPT_KEY_HANDLE key, DWORD flags) ...@@ -227,9 +228,28 @@ SECURITY_STATUS WINAPI NCryptDeleteKey(NCRYPT_KEY_HANDLE key, DWORD flags)
SECURITY_STATUS WINAPI NCryptEncrypt(NCRYPT_KEY_HANDLE key, BYTE *input, DWORD insize, void *padding, SECURITY_STATUS WINAPI NCryptEncrypt(NCRYPT_KEY_HANDLE key, BYTE *input, DWORD insize, void *padding,
BYTE *output, DWORD outsize, DWORD *result, DWORD flags) BYTE *output, DWORD outsize, DWORD *result, DWORD flags)
{ {
FIXME("(%#Ix, %p, %lu, %p, %p, %lu, %p, %#lx): stub\n", key, input, insize, padding, struct object *key_object = (struct object *)key;
TRACE("(%#Ix, %p, %lu, %p, %p, %lu, %p, %#lx)\n", key, input, insize, padding,
output, outsize, result, flags); output, outsize, result, flags);
if (flags & ~(NCRYPT_NO_PADDING_FLAG | NCRYPT_PAD_OAEP_FLAG
| NCRYPT_PAD_PKCS1_FLAG | NCRYPT_SILENT_FLAG))
{
FIXME("Flags %lx not supported\n", flags);
return NTE_BAD_FLAGS;
}
if (flags & NCRYPT_NO_PADDING_FLAG || flags & NCRYPT_PAD_OAEP_FLAG)
{
FIXME("No padding and oaep padding not supported\n");
return NTE_NOT_SUPPORTED; return NTE_NOT_SUPPORTED;
}
if (key_object->type != KEY) return NTE_INVALID_HANDLE;
return map_ntstatus(BCryptEncrypt(key_object->key.bcrypt_key, input, insize, padding,
NULL, 0, output, outsize, result, flags));
} }
SECURITY_STATUS WINAPI NCryptEnumAlgorithms(NCRYPT_PROV_HANDLE provider, DWORD alg_ops, SECURITY_STATUS WINAPI NCryptEnumAlgorithms(NCRYPT_PROV_HANDLE provider, DWORD alg_ops,
......
...@@ -550,7 +550,6 @@ static void test_NCryptEncrypt(void) ...@@ -550,7 +550,6 @@ static void test_NCryptEncrypt(void)
BYTE *output_b; BYTE *output_b;
DWORD output_size; DWORD output_size;
todo_wine {
NCryptOpenStorageProvider(&prov, NULL, 0); NCryptOpenStorageProvider(&prov, NULL, 0);
NCryptCreatePersistedKey(prov, &key, BCRYPT_RSA_ALGORITHM, NULL, 0, 0); NCryptCreatePersistedKey(prov, &key, BCRYPT_RSA_ALGORITHM, NULL, 0, 0);
...@@ -562,6 +561,7 @@ static void test_NCryptEncrypt(void) ...@@ -562,6 +561,7 @@ static void test_NCryptEncrypt(void)
/* Test encrypt with a non finalized key */ /* Test encrypt with a non finalized key */
ret = NCryptEncrypt(key, data_to_encrypt, sizeof(data_to_encrypt), NULL, NULL, 0, ret = NCryptEncrypt(key, data_to_encrypt, sizeof(data_to_encrypt), NULL, NULL, 0,
&output_size, NCRYPT_PAD_PKCS1_FLAG); &output_size, NCRYPT_PAD_PKCS1_FLAG);
todo_wine
ok(ret == NTE_BAD_KEY_STATE, "got %lx\n", ret); ok(ret == NTE_BAD_KEY_STATE, "got %lx\n", ret);
NCryptFinalizeKey(key, 0); NCryptFinalizeKey(key, 0);
...@@ -572,6 +572,8 @@ static void test_NCryptEncrypt(void) ...@@ -572,6 +572,8 @@ static void test_NCryptEncrypt(void)
ok(ret == NTE_BAD_FLAGS, "got %lx\n", ret); ok(ret == NTE_BAD_FLAGS, "got %lx\n", ret);
/* Test no padding with RSA */ /* Test no padding with RSA */
todo_wine
{
ret = NCryptEncrypt(key, data_to_encrypt, sizeof(data_to_encrypt), NULL, NULL, 0, &output_size, ret = NCryptEncrypt(key, data_to_encrypt, sizeof(data_to_encrypt), NULL, NULL, 0, &output_size,
NCRYPT_NO_PADDING_FLAG); NCRYPT_NO_PADDING_FLAG);
ok(ret == ERROR_SUCCESS, "got %lx\n", ret); ok(ret == ERROR_SUCCESS, "got %lx\n", ret);
...@@ -582,6 +584,7 @@ static void test_NCryptEncrypt(void) ...@@ -582,6 +584,7 @@ static void test_NCryptEncrypt(void)
&output_size, NCRYPT_NO_PADDING_FLAG); &output_size, NCRYPT_NO_PADDING_FLAG);
ok(ret == NTE_INVALID_PARAMETER, "got %lx\n", ret); ok(ret == NTE_INVALID_PARAMETER, "got %lx\n", ret);
free(output_a); free(output_a);
}
/* Test output RSA with PKCS1. PKCS1 should append a random padding to the data, so the output should be different /* Test output RSA with PKCS1. PKCS1 should append a random padding to the data, so the output should be different
* with each call. */ * with each call. */
...@@ -611,7 +614,6 @@ static void test_NCryptEncrypt(void) ...@@ -611,7 +614,6 @@ static void test_NCryptEncrypt(void)
free(output_b); free(output_b);
NCryptFreeObject(prov); NCryptFreeObject(prov);
}
} }
START_TEST(ncrypt) START_TEST(ncrypt)
......
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