Change RC5_32_set_key to return an int type
[openssl.git] / test / provider_internal_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/crypto.h>
12 #include "internal/provider.h"
13 #include "testutil.h"
14
15 extern OSSL_provider_init_fn PROVIDER_INIT_FUNCTION_NAME;
16
17 static char buf[256];
18 static OSSL_PARAM greeting_request[] = {
19     { "greeting", OSSL_PARAM_UTF8_STRING, buf, sizeof(buf), 0 },
20     { NULL, 0, NULL, 0, 0 }
21 };
22
23 static int test_provider(OSSL_PROVIDER *prov, const char *expected_greeting)
24 {
25     const char *greeting = NULL;
26     int ret = 0;
27
28     ret =
29         TEST_true(ossl_provider_activate(prov))
30         && TEST_true(ossl_provider_get_params(prov, greeting_request))
31         && TEST_ptr(greeting = greeting_request[0].data)
32         && TEST_size_t_gt(greeting_request[0].data_size, 0)
33         && TEST_str_eq(greeting, expected_greeting);
34
35     TEST_info("Got this greeting: %s\n", greeting);
36     ossl_provider_free(prov);
37     return ret;
38 }
39
40 static const char *expected_greeting1(const char *name)
41 {
42     static char expected_greeting[256] = "";
43
44     BIO_snprintf(expected_greeting, sizeof(expected_greeting),
45                  "Hello OpenSSL %.20s, greetings from %s!",
46                  OPENSSL_VERSION_STR, name);
47
48     return expected_greeting;
49 }
50
51 static int test_builtin_provider(void)
52 {
53     const char *name = "p_test_builtin";
54     OSSL_PROVIDER *prov = NULL;
55
56     return
57         TEST_ptr(prov =
58                  ossl_provider_new(NULL, name, PROVIDER_INIT_FUNCTION_NAME))
59         && test_provider(prov, expected_greeting1(name));
60 }
61
62 #ifndef NO_PROVIDER_MODULE
63 static int test_loaded_provider(void)
64 {
65     const char *name = "p_test";
66     OSSL_PROVIDER *prov = NULL;
67
68     return
69         TEST_ptr(prov = ossl_provider_new(NULL, name, NULL))
70         && test_provider(prov, expected_greeting1(name));
71 }
72
73 static int test_configured_provider(void)
74 {
75     const char *name = "p_test_configured";
76     OSSL_PROVIDER *prov = NULL;
77     /* This MUST match the config file */
78     const char *expected_greeting =
79         "Hello OpenSSL, greetings from Test Provider";
80
81     return
82         OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL)
83         && TEST_ptr(prov = ossl_provider_find(NULL, name))
84         && test_provider(prov, expected_greeting);
85 }
86 #endif
87
88 int setup_tests(void)
89 {
90     ADD_TEST(test_builtin_provider);
91 #ifndef NO_PROVIDER_MODULE
92     ADD_TEST(test_loaded_provider);
93     ADD_TEST(test_configured_provider);
94 #endif
95     return 1;
96 }
97