VirtualBox

source: vbox/trunk/src/libs/openssl-3.0.2/test/upcallstest.c@ 94403

Last change on this file since 94403 was 94320, checked in by vboxsync, 3 years ago

libs/openssl-3.0.1: Export to OSE and fix copyright headers in Makefiles, bugref:10128

File size: 3.3 KB
Line 
1/*
2 * Copyright 2021 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 <openssl/objects.h>
11#include <openssl/crypto.h>
12#include <openssl/provider.h>
13#include "testutil.h"
14
15static const OSSL_ALGORITHM *obj_query(void *provctx, int operation_id,
16 int *no_cache)
17{
18 *no_cache = 0;
19 return NULL;
20}
21
22static const OSSL_DISPATCH obj_dispatch_table[] = {
23 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))obj_query },
24 { 0, NULL }
25};
26
27static OSSL_FUNC_core_obj_add_sigid_fn *c_obj_add_sigid = NULL;
28static OSSL_FUNC_core_obj_create_fn *c_obj_create = NULL;
29
30#define SIG_OID "1.3.6.1.4.1.16604.998877.1"
31#define SIG_SN "my-sig"
32#define SIG_LN "my-sig-long"
33#define DIGEST_OID "1.3.6.1.4.1.16604.998877.2"
34#define DIGEST_SN "my-digest"
35#define DIGEST_LN "my-digest-long"
36#define SIGALG_OID "1.3.6.1.4.1.16604.998877.3"
37#define SIGALG_SN "my-sigalg"
38#define SIGALG_LN "my-sigalg-long"
39
40static int obj_provider_init(const OSSL_CORE_HANDLE *handle,
41 const OSSL_DISPATCH *in,
42 const OSSL_DISPATCH **out,
43 void **provctx)
44{
45 *provctx = (void *)handle;
46 *out = obj_dispatch_table;
47
48 for (; in->function_id != 0; in++) {
49 switch (in->function_id) {
50 case OSSL_FUNC_CORE_OBJ_ADD_SIGID:
51 c_obj_add_sigid = OSSL_FUNC_core_obj_add_sigid(in);
52 break;
53 case OSSL_FUNC_CORE_OBJ_CREATE:
54 c_obj_create = OSSL_FUNC_core_obj_create(in);
55 break;
56 break;
57 default:
58 /* Just ignore anything we don't understand */
59 break;
60 }
61 }
62
63 if (!c_obj_create(handle, DIGEST_OID, DIGEST_SN, DIGEST_LN)
64 || !c_obj_create(handle, SIG_OID, SIG_SN, SIG_LN)
65 || !c_obj_create(handle, SIGALG_OID, SIGALG_SN, SIGALG_LN))
66 return 0;
67
68 if (!c_obj_add_sigid(handle, SIGALG_OID, DIGEST_SN, SIG_LN))
69 return 0;
70
71 return 1;
72}
73
74static int obj_create_test(void)
75{
76 OSSL_LIB_CTX *libctx = OSSL_LIB_CTX_new();
77 OSSL_PROVIDER *objprov = NULL;
78 int sigalgnid, digestnid, signid;
79 int testresult = 0;
80
81 if (!TEST_ptr(libctx))
82 goto err;
83
84 if (!TEST_true(OSSL_PROVIDER_add_builtin(libctx, "obj-prov",
85 obj_provider_init))
86 || !TEST_ptr(objprov = OSSL_PROVIDER_load(libctx, "obj-prov")))
87 goto err;
88
89 /* Check that the provider created the OIDs/NIDs we expected */
90 sigalgnid = OBJ_txt2nid(SIGALG_OID);
91 if (!TEST_int_ne(sigalgnid, NID_undef)
92 || !TEST_true(OBJ_find_sigid_algs(sigalgnid, &digestnid, &signid))
93 || !TEST_int_ne(digestnid, NID_undef)
94 || !TEST_int_ne(signid, NID_undef)
95 || !TEST_int_eq(digestnid, OBJ_sn2nid(DIGEST_SN))
96 || !TEST_int_eq(signid, OBJ_ln2nid(SIG_LN)))
97 goto err;
98
99 testresult = 1;
100 err:
101 OSSL_PROVIDER_unload(objprov);
102 OSSL_LIB_CTX_free(libctx);
103 return testresult;
104}
105
106int setup_tests(void)
107{
108
109 ADD_TEST(obj_create_test);
110
111 return 1;
112}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette