1 1.1 christos /* 2 1.1.1.2 christos * Copyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * 4 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos * this file except in compliance with the License. You can obtain a copy 6 1.1 christos * in the file LICENSE in the source distribution or at 7 1.1 christos * https://www.openssl.org/source/license.html 8 1.1 christos */ 9 1.1 christos 10 1.1 christos #include <stddef.h> 11 1.1 christos #include <openssl/provider.h> 12 1.1 christos #include <openssl/evp.h> 13 1.1 christos #include "testutil.h" 14 1.1 christos 15 1.1 christos static int test_provider(OSSL_LIB_CTX *ctx) 16 1.1 christos { 17 1.1 christos EVP_KEYMGMT *rsameth = NULL; 18 1.1 christos const OSSL_PROVIDER *prov = NULL; 19 1.1 christos int ok; 20 1.1 christos 21 1.1 christos ok = TEST_true(OSSL_PROVIDER_available(ctx, "default")) 22 1.1 christos && TEST_ptr(rsameth = EVP_KEYMGMT_fetch(ctx, "RSA", NULL)) 23 1.1 christos && TEST_ptr(prov = EVP_KEYMGMT_get0_provider(rsameth)) 24 1.1 christos && TEST_str_eq(OSSL_PROVIDER_get0_name(prov), "default"); 25 1.1 christos 26 1.1 christos EVP_KEYMGMT_free(rsameth); 27 1.1 christos return ok; 28 1.1 christos } 29 1.1 christos 30 1.1 christos static int test_fallback_provider(void) 31 1.1 christos { 32 1.1 christos return test_provider(NULL); 33 1.1 christos } 34 1.1 christos 35 1.1 christos static int test_explicit_provider(void) 36 1.1 christos { 37 1.1 christos OSSL_LIB_CTX *ctx = NULL; 38 1.1 christos OSSL_PROVIDER *prov = NULL; 39 1.1 christos int ok; 40 1.1 christos 41 1.1 christos ok = TEST_ptr(ctx = OSSL_LIB_CTX_new()) 42 1.1.1.2 christos && TEST_ptr(prov = OSSL_PROVIDER_load(ctx, "default")); 43 1.1.1.2 christos 44 1.1.1.2 christos if (ok) { 45 1.1.1.2 christos ok = test_provider(ctx); 46 1.1.1.2 christos if (ok) 47 1.1.1.2 christos ok = TEST_true(OSSL_PROVIDER_unload(prov)); 48 1.1.1.2 christos else 49 1.1.1.2 christos OSSL_PROVIDER_unload(prov); 50 1.1.1.2 christos } 51 1.1 christos 52 1.1 christos OSSL_LIB_CTX_free(ctx); 53 1.1 christos return ok; 54 1.1 christos } 55 1.1 christos 56 1.1 christos 57 1.1 christos int setup_tests(void) 58 1.1 christos { 59 1.1 christos ADD_TEST(test_fallback_provider); 60 1.1 christos ADD_TEST(test_explicit_provider); 61 1.1 christos return 1; 62 1.1 christos } 63 1.1 christos 64