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