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/objects.h>
11 #include <openssl/crypto.h>
12 #include <openssl/provider.h>
15 static const OSSL_ALGORITHM *obj_query(void *provctx, int operation_id,
22 static const OSSL_DISPATCH obj_dispatch_table[] = {
23 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))obj_query },
27 static OSSL_FUNC_core_obj_add_sigid_fn *c_obj_add_sigid = NULL;
28 static OSSL_FUNC_core_obj_create_fn *c_obj_create = NULL;
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"
40 static int obj_provider_init(const OSSL_CORE_HANDLE *handle,
41 const OSSL_DISPATCH *in,
42 const OSSL_DISPATCH **out,
45 *provctx = (void *)handle;
46 *out = obj_dispatch_table;
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);
53 case OSSL_FUNC_CORE_OBJ_CREATE:
54 c_obj_create = OSSL_FUNC_core_obj_create(in);
58 /* Just ignore anything we don't understand */
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))
68 if (!c_obj_add_sigid(handle, SIGALG_OID, DIGEST_SN, SIG_LN))
74 static int obj_create_test(void)
76 OSSL_LIB_CTX *libctx = OSSL_LIB_CTX_new();
77 OSSL_PROVIDER *objprov = NULL;
78 int sigalgnid, digestnid, signid;
81 if (!TEST_ptr(libctx))
84 if (!TEST_true(OSSL_PROVIDER_add_builtin(libctx, "obj-prov",
86 || !TEST_ptr(objprov = OSSL_PROVIDER_load(libctx, "obj-prov")))
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)))
101 OSSL_PROVIDER_unload(objprov);
102 OSSL_LIB_CTX_free(libctx);
106 int setup_tests(void)
109 ADD_TEST(obj_create_test);