Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/ncrypt_internal.c | 28 ++++++++++++++++++++++++++++ dlls/ncrypt/ncrypt_internal.h | 2 ++ dlls/ncrypt/ncrypt_main.c | 28 ++++++++++++++++++++++++++-- dlls/ncrypt/tests/ncrypt.c | 2 -- 4 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/dlls/ncrypt/ncrypt_internal.c b/dlls/ncrypt/ncrypt_internal.c index 370391d8171..2bbbd58af64 100644 --- a/dlls/ncrypt/ncrypt_internal.c +++ b/dlls/ncrypt/ncrypt_internal.c @@ -41,3 +41,31 @@ int allocate_key_object(struct ncrypt_object **keyobject) (*keyobject)->type = KEY; return ERROR_SUCCESS; } + +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%x\n", keyobject); + return NTE_INVALID_HANDLE; + } + break; + } + + return ERROR_SUCCESS; +} diff --git a/dlls/ncrypt/ncrypt_internal.h b/dlls/ncrypt/ncrypt_internal.h index 94c63ba2274..33e25da6b21 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; @@ -91,5 +92,6 @@ struct ncrypt_object };
int allocate_key_object(struct ncrypt_object **keyobject); +int free_key_object(struct ncrypt_object *keyobject);
#endif // NCRYPT_INTERNAL_H diff --git a/dlls/ncrypt/ncrypt_main.c b/dlls/ncrypt/ncrypt_main.c index 717b67eae9f..671e0ecdc7d 100644 --- a/dlls/ncrypt/ncrypt_main.c +++ b/dlls/ncrypt/ncrypt_main.c @@ -90,8 +90,32 @@ SECURITY_STATUS WINAPI NCryptFreeBuffer(PVOID buf)
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%x\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%x\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/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index f982f090254..eacb53f2dd3 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -131,7 +131,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); @@ -145,7 +144,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)