]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/provider_test.c
Implement EVP_MAC_do_all_ex()
[thirdparty/openssl.git] / test / provider_test.c
1 /*
2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10 #include <stddef.h>
11 #include <openssl/provider.h>
12 #include "testutil.h"
13
14 extern OSSL_provider_init_fn PROVIDER_INIT_FUNCTION_NAME;
15
16 static char buf[256];
17 static OSSL_PARAM greeting_request[] = {
18 { "greeting", OSSL_PARAM_UTF8_STRING, buf, sizeof(buf) },
19 { NULL, 0, NULL, 0, 0 }
20 };
21
22 static int test_provider(const char *name)
23 {
24 OSSL_PROVIDER *prov = NULL;
25 const char *greeting = NULL;
26 char expected_greeting[256];
27
28 BIO_snprintf(expected_greeting, sizeof(expected_greeting),
29 "Hello OpenSSL %.20s, greetings from %s!",
30 OPENSSL_VERSION_STR, name);
31
32 return
33 TEST_ptr(prov = OSSL_PROVIDER_load(NULL, name))
34 && TEST_true(OSSL_PROVIDER_get_params(prov, greeting_request))
35 && TEST_ptr(greeting = greeting_request[0].data)
36 && TEST_size_t_gt(greeting_request[0].data_size, 0)
37 && TEST_str_eq(greeting, expected_greeting)
38 && TEST_true(OSSL_PROVIDER_unload(prov));
39 }
40
41 static int test_builtin_provider(void)
42 {
43 const char *name = "p_test_builtin";
44
45 return
46 TEST_true(OSSL_PROVIDER_add_builtin(NULL, name,
47 PROVIDER_INIT_FUNCTION_NAME))
48 && test_provider(name);
49 }
50
51 #ifndef NO_PROVIDER_MODULE
52 static int test_loaded_provider(void)
53 {
54 const char *name = "p_test";
55
56 return test_provider(name);
57 }
58 #endif
59
60 int setup_tests(void)
61 {
62 ADD_TEST(test_builtin_provider);
63 #ifndef NO_PROVIDER_MODULE
64 ADD_TEST(test_loaded_provider);
65 #endif
66 return 1;
67 }
68