Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/main.c | 57 +++++++++++++++++++++++++++++++++-- dlls/ncrypt/ncrypt_internal.h | 1 + dlls/ncrypt/tests/ncrypt.c | 2 -- 3 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c index 54d80c83d67..491423a2643 100644 --- a/dlls/ncrypt/main.c +++ b/dlls/ncrypt/main.c @@ -88,10 +88,63 @@ SECURITY_STATUS WINAPI NCryptFreeBuffer(PVOID buf) return NTE_NOT_SUPPORTED; }
+int free_key_object(struct ncrypt_object *keyobject) +{ + struct ncrypt_key_object *key = &keyobject->object.key; + switch (key->algtype) + { + case RSA: + { + free(key->payload.rsa_key.modulus); + free(key->payload.rsa_key.public_exp); + if (key->payload.rsa_key.type == PRIVATE) + { + free(key->payload.rsa_key.prime1); + free(key->payload.rsa_key.prime2); + } + } + break; + + default: + { + ERR("invalid key object 0x%p\n", keyobject); + return NTE_INVALID_HANDLE; + } + break; + } + + return ERROR_SUCCESS; +} + SECURITY_STATUS WINAPI NCryptFreeObject(NCRYPT_HANDLE object) { - FIXME("(0x%lx): stub\n", object); - return NTE_NOT_SUPPORTED; + struct ncrypt_object *ncryptobj = (struct ncrypt_object *)object; + if (ncryptobj == NULL) + { + ERR("invalid handle 0x%p\n", ncryptobj); + return NTE_INVALID_HANDLE; + } + + switch (ncryptobj->type) + { + case KEY: + { + int ret = free_key_object(ncryptobj); + if (ret != ERROR_SUCCESS) + return ret; + } + break; + + default: + { + ERR("invalid handle 0x%p\n", ncryptobj); + return NTE_INVALID_HANDLE; + } + break; + } + + free(ncryptobj); + return ERROR_SUCCESS; }
SECURITY_STATUS WINAPI NCryptGetProperty(NCRYPT_HANDLE object, const WCHAR *property, PBYTE output, diff --git a/dlls/ncrypt/ncrypt_internal.h b/dlls/ncrypt/ncrypt_internal.h index 0948d84925e..81bd4bb442f 100644 --- a/dlls/ncrypt/ncrypt_internal.h +++ b/dlls/ncrypt/ncrypt_internal.h @@ -41,6 +41,7 @@ enum key_algorithm_type
struct ncrypt_rsa_key { + enum asymmetric_key_type type; DWORD public_exp_size; BYTE *public_exp; DWORD modulus_size; diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index c5ba5080241..05d430f246f 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -142,7 +142,6 @@ static void test_ncrypt_free_object(void) SECURITY_STATUS ret = NCryptOpenStorageProvider(&prov, NULL, 0); ok(ret == ERROR_SUCCESS, "got 0x%x\n", ret);
- todo_wine { NCRYPT_KEY_HANDLE key; ret = NCryptImportKey(prov, (NCRYPT_KEY_HANDLE)NULL, BCRYPT_RSAPUBLIC_BLOB, NULL, &key, rsa_key_blob, sizeof(rsa_key_blob), 0); ret = NCryptFreeObject(key); @@ -156,7 +155,6 @@ static void test_ncrypt_free_object(void) ret = NCryptFreeObject(key); ok(ret == NTE_INVALID_HANDLE, "got 0x%x\n", ret); free(key); - } }
START_TEST(ncrypt)