2 * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/core.h>
11 #include <openssl/core_dispatch.h>
12 #include <openssl/core_names.h>
13 #include <openssl/provider.h>
14 #include <openssl/crypto.h>
15 #include <openssl/evp.h>
18 #define MYPROPERTIES "foo.bar=yes"
20 static OSSL_FUNC_provider_query_operation_fn testprov_query;
21 static OSSL_FUNC_digest_get_params_fn tmpmd_get_params;
22 static OSSL_FUNC_digest_digest_fn tmpmd_digest;
24 static int tmpmd_get_params(OSSL_PARAM params[])
28 p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_BLOCK_SIZE);
29 if (p != NULL && !OSSL_PARAM_set_size_t(p, 1))
32 p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE);
33 if (p != NULL && !OSSL_PARAM_set_size_t(p, 1))
39 static int tmpmd_digest(void *provctx, const unsigned char *in, size_t inl,
40 unsigned char *out, size_t *outl, size_t outsz)
45 static const OSSL_DISPATCH testprovmd_functions[] = {
46 { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))tmpmd_get_params },
47 { OSSL_FUNC_DIGEST_DIGEST, (void (*)(void))tmpmd_digest },
51 static const OSSL_ALGORITHM testprov_digests[] = {
52 { "testprovmd", MYPROPERTIES, testprovmd_functions },
56 static const OSSL_ALGORITHM *testprov_query(void *provctx,
61 return operation_id == OSSL_OP_DIGEST ? testprov_digests : NULL;
64 static const OSSL_DISPATCH testprov_dispatch_table[] = {
65 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))testprov_query },
69 static int testprov_provider_init(const OSSL_CORE_HANDLE *handle,
70 const OSSL_DISPATCH *in,
71 const OSSL_DISPATCH **out,
74 *provctx = (void *)handle;
75 *out = testprov_dispatch_table;
80 DEFAULT_PROPS_FIRST = 0,
81 DEFAULT_PROPS_AFTER_LOAD,
82 DEFAULT_PROPS_AFTER_FETCH,
86 static int test_default_props_and_providers(int propsorder)
89 OSSL_PROVIDER *testprov = NULL;
90 EVP_MD *testprovmd = NULL;
93 if (!TEST_ptr(libctx = OSSL_LIB_CTX_new())
94 || !TEST_true(OSSL_PROVIDER_add_builtin(libctx, "testprov",
95 testprov_provider_init)))
98 if (propsorder == DEFAULT_PROPS_FIRST
99 && !TEST_true(EVP_set_default_properties(libctx, MYPROPERTIES)))
102 if (!TEST_ptr(testprov = OSSL_PROVIDER_load(libctx, "testprov")))
105 if (propsorder == DEFAULT_PROPS_AFTER_LOAD
106 && !TEST_true(EVP_set_default_properties(libctx, MYPROPERTIES)))
109 if (!TEST_ptr(testprovmd = EVP_MD_fetch(libctx, "testprovmd", NULL)))
112 if (propsorder == DEFAULT_PROPS_AFTER_FETCH) {
113 if (!TEST_true(EVP_set_default_properties(libctx, MYPROPERTIES)))
115 EVP_MD_free(testprovmd);
116 if (!TEST_ptr(testprovmd = EVP_MD_fetch(libctx, "testprovmd", NULL)))
122 EVP_MD_free(testprovmd);
123 OSSL_PROVIDER_unload(testprov);
124 OSSL_LIB_CTX_free(libctx);
128 int setup_tests(void)
130 ADD_ALL_TESTS(test_default_props_and_providers, DEFAULT_PROPS_FINAL);