Standard preamble:
========================================================================
..
.... Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.
If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.
Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================
Title "PROVIDER-BASE 7ossl"
way too many mistakes in technical documents.
All these \*(L"functions\*(R" have a corresponding function type definition named OSSL_FUNC_{name}_fn, and a helper function to retrieve the function pointer from a \s-1OSSL_DISPATCH\s0\|(3) element named \fBOSSL_FUNC_{name}. For example, the \*(L"function\*(R" core_gettable_params() has these:
.Vb 4 typedef OSSL_PARAM * (OSSL_FUNC_core_gettable_params_fn)(const OSSL_CORE_HANDLE *handle); static ossl_inline OSSL_NAME_core_gettable_params_fn OSSL_FUNC_core_gettable_params(const OSSL_DISPATCH *opf); .Ve
\s-1OSSL_DISPATCH\s0\|(3) arrays are indexed by numbers that are provided as macros in openssl-core_dispatch.h\|(7), as follows:
For in (the \s-1OSSL_DISPATCH\s0\|(3) array passed from libcrypto to the provider):
.Vb 10 core_gettable_params OSSL_FUNC_CORE_GETTABLE_PARAMS core_get_params OSSL_FUNC_CORE_GET_PARAMS core_thread_start OSSL_FUNC_CORE_THREAD_START core_get_libctx OSSL_FUNC_CORE_GET_LIBCTX core_new_error OSSL_FUNC_CORE_NEW_ERROR core_set_error_debug OSSL_FUNC_CORE_SET_ERROR_DEBUG core_vset_error OSSL_FUNC_CORE_VSET_ERROR core_obj_add_sigid OSSL_FUNC_CORE_OBJ_ADD_SIGID core_obj_create OSSL_FUNC_CORE_OBJ_CREATE CRYPTO_malloc OSSL_FUNC_CRYPTO_MALLOC CRYPTO_zalloc OSSL_FUNC_CRYPTO_ZALLOC CRYPTO_free OSSL_FUNC_CRYPTO_FREE CRYPTO_clear_free OSSL_FUNC_CRYPTO_CLEAR_FREE CRYPTO_realloc OSSL_FUNC_CRYPTO_REALLOC CRYPTO_clear_realloc OSSL_FUNC_CRYPTO_CLEAR_REALLOC CRYPTO_secure_malloc OSSL_FUNC_CRYPTO_SECURE_MALLOC CRYPTO_secure_zalloc OSSL_FUNC_CRYPTO_SECURE_ZALLOC CRYPTO_secure_free OSSL_FUNC_CRYPTO_SECURE_FREE CRYPTO_secure_clear_free OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE CRYPTO_secure_allocated OSSL_FUNC_CRYPTO_SECURE_ALLOCATED BIO_new_file OSSL_FUNC_BIO_NEW_FILE BIO_new_mem_buf OSSL_FUNC_BIO_NEW_MEMBUF BIO_read_ex OSSL_FUNC_BIO_READ_EX BIO_write_ex OSSL_FUNC_BIO_WRITE_EX BIO_up_ref OSSL_FUNC_BIO_UP_REF BIO_free OSSL_FUNC_BIO_FREE BIO_vprintf OSSL_FUNC_BIO_VPRINTF BIO_vsnprintf OSSL_FUNC_BIO_VSNPRINTF BIO_puts OSSL_FUNC_BIO_PUTS BIO_gets OSSL_FUNC_BIO_GETS BIO_ctrl OSSL_FUNC_BIO_CTRL OPENSSL_cleanse OSSL_FUNC_OPENSSL_CLEANSE OSSL_SELF_TEST_set_callback OSSL_FUNC_SELF_TEST_CB ossl_rand_get_entropy OSSL_FUNC_GET_ENTROPY ossl_rand_cleanup_entropy OSSL_FUNC_CLEANUP_ENTROPY ossl_rand_get_nonce OSSL_FUNC_GET_NONCE ossl_rand_cleanup_nonce OSSL_FUNC_CLEANUP_NONCE provider_register_child_cb OSSL_FUNC_PROVIDER_REGISTER_CHILD_CB provider_deregister_child_cb OSSL_FUNC_PROVIDER_DEREGISTER_CHILD_CB provider_name OSSL_FUNC_PROVIDER_NAME provider_get0_provider_ctx OSSL_FUNC_PROVIDER_GET0_PROVIDER_CTX provider_get0_dispatch OSSL_FUNC_PROVIDER_GET0_DISPATCH provider_up_ref OSSL_FUNC_PROVIDER_UP_REF provider_free OSSL_FUNC_PROVIDER_FREE .Ve
For *out (the \s-1OSSL_DISPATCH\s0\|(3) array passed from the provider to \fIlibcrypto):
.Vb 8 provider_teardown OSSL_FUNC_PROVIDER_TEARDOWN provider_gettable_params OSSL_FUNC_PROVIDER_GETTABLE_PARAMS provider_get_params OSSL_FUNC_PROVIDER_GET_PARAMS provider_query_operation OSSL_FUNC_PROVIDER_QUERY_OPERATION provider_unquery_operation OSSL_FUNC_PROVIDER_UNQUERY_OPERATION provider_get_reason_strings OSSL_FUNC_PROVIDER_GET_REASON_STRINGS provider_get_capabilities OSSL_FUNC_PROVIDER_GET_CAPABILITIES provider_self_test OSSL_FUNC_PROVIDER_SELF_TEST .Ve
\fBcore_get_params() retrieves parameters from the core for the given handle. See \*(L"Core parameters\*(R" below for a description of currently known parameters.
The core_thread_start() function informs the core that the provider has stated an interest in the current thread. The core will inform the provider when the thread eventually stops. It must be passed the handle for this provider, as well as a callback handfn which will be called when the thread stops. The callback will subsequently be called, with the supplied argument arg, from the thread that is stopping and gets passed the provider context as an argument. This may be useful to perform thread specific clean up such as freeing thread local variables.
\fBcore_get_libctx() retrieves the core context in which the library object for the current provider is stored, accessible through the handle. This function is useful only for built-in providers such as the default provider. Never cast this to \s-1OSSL_LIB_CTX\s0 in a provider that is not built-in as the \s-1OSSL_LIB_CTX\s0 of the library loading the provider might be a completely different structure than the \s-1OSSL_LIB_CTX\s0 of the library the provider is linked to. Use OSSL_LIB_CTX_new_child\|(3) instead to obtain a proper library context that is linked to the application library context.
\fBcore_new_error(), core_set_error_debug() and core_vset_error() are building blocks for reporting an error back to the core, with reference to the handle.
The core_obj_create() function registers a new \s-1OID\s0 and associated short name \fIsn and long name ln for the given handle. It is similar to the OpenSSL function OBJ_create\|(3) except that it returns 1 on success or 0 on failure. It will treat as success the case where the \s-1OID\s0 already exists (even if the short name sn or long name ln provided as arguments differ from those associated with the existing \s-1OID,\s0 in which case the new names are not associated). This function is not thread safe.
The core_obj_add_sigid() function registers a new composite signature algorithm (sign_name) consisting of an underlying signature algorithm (pkey_name) and digest algorithm (digest_name) for the given handle. It assumes that the OIDs for the composite signature algorithm as well as for the underlying signature and digest algorithms are either already known to OpenSSL or have been registered via a call to core_obj_create(). It corresponds to the OpenSSL function OBJ_add_sigid\|(3), except that the objects are identified by name rather than a numeric \s-1NID.\s0 Any name (\s-1OID,\s0 short name or long name) can be used to identify the object. It will treat as success the case where the composite signature algorithm already exists (even if registered against a different underlying signature or digest algorithm). For digest_name, \s-1NULL\s0 or an empty string is permissible for signature algorithms that do not need a digest to operate correctly. The function returns 1 on success or 0 on failure. This function is not thread safe.
\fBCRYPTO_malloc(), CRYPTO_zalloc(), CRYPTO_free(), CRYPTO_clear_free(), \fBCRYPTO_realloc(), CRYPTO_clear_realloc(), CRYPTO_secure_malloc(), \fBCRYPTO_secure_zalloc(), CRYPTO_secure_free(), \fBCRYPTO_secure_clear_free(), CRYPTO_secure_allocated(), \fBBIO_new_file(), BIO_new_mem_buf(), BIO_read_ex(), BIO_write_ex(), BIO_up_ref(), \fBBIO_free(), BIO_vprintf(), BIO_vsnprintf(), BIO_gets(), BIO_puts(), \fBBIO_ctrl(), OPENSSL_cleanse() and \fBOPENSSL_hexstr2buf() correspond exactly to the public functions with the same name. As a matter of fact, the pointers in the \s-1OSSL_DISPATCH\s0\|(3) array are typically direct pointers to those public functions. Note that the \s-1BIO\s0 functions take an \s-1OSSL_CORE_BIO\s0 type rather than the standard \s-1BIO\s0 type. This is to ensure that a provider does not mix BIOs from the core with BIOs used on the provider side (the two are not compatible). \fBOSSL_SELF_TEST_set_callback() is used to set an optional callback that can be passed into a provider. This may be ignored by a provider.
\fBget_entropy() retrieves seeding material from the operating system. The seeding material will have at least entropy bytes of randomness and the output will have at least min_len and at most max_len bytes. The buffer address is stored in *pout and the buffer length is returned to the caller. On error, zero is returned.
\fBcleanup_entropy() is used to clean up and free the buffer returned by \fBget_entropy(). The entropy pointer returned by get_entropy() is passed in \fBbuf and its length in len.
\fBget_nonce() retrieves a nonce using the passed salt parameter of length salt_len and operating system specific information. The salt should contain uniquely identifying information and this is included, in an unspecified manner, as part of the output. The output is stored in a buffer which contains at least min_len and at most max_len bytes. The buffer address is stored in *pout and the buffer length returned to the caller. On error, zero is returned.
\fBcleanup_nonce() is used to clean up and free the buffer returned by \fBget_nonce(). The nonce pointer returned by get_nonce() is passed in \fBbuf and its length in len.
\fBprovider_register_child_cb() registers callbacks for being informed about the loading and unloading of providers in the application's library context. \fIhandle is this provider's handle and cbdata is this provider's data that will be passed back to the callbacks. It returns 1 on success or 0 otherwise. These callbacks may be called while holding locks in libcrypto. In order to avoid deadlocks the callback implementation must not be long running and must not call other OpenSSL \s-1API\s0 functions or upcalls.
\fIcreate_cb is a callback that will be called when a new provider is loaded into the application's library context. It is also called for any providers that are already loaded at the point that this callback is registered. The callback is passed the handle being used for the new provider being loadded and this provider's data in cbdata. It should return 1 on success or 0 on failure.
\fIremove_cb is a callback that will be called when a new provider is unloaded from the application's library context. It is passed the handle being used for the provider being unloaded and this provider's data in cbdata. It should return 1 on success or 0 on failure.
\fIglobal_props_cb is a callback that will be called when the global properties from the parent library context are changed. It should return 1 on success or 0 on failure.
\fBprovider_deregister_child_cb() unregisters callbacks previously registered via \fBprovider_register_child_cb(). If provider_register_child_cb() has been called then provider_deregister_child_cb() should be called at or before the point that this provider's teardown function is called.
\fBprovider_name() returns a string giving the name of the provider identified by \fIhandle.
\fBprovider_get0_provider_ctx() returns the provider context that is associated with the provider identified by prov.
\fBprovider_get0_dispatch() gets the dispatch table registered by the provider identified by prov when it initialised.
\fBprovider_up_ref() increments the reference count on the provider prov. If \fIactivate is nonzero then the provider is also loaded if it is not already loaded. It returns 1 on success or 0 on failure.
\fBprovider_free() decrements the reference count on the provider prov. If \fIdeactivate is nonzero then the provider is also unloaded if it is not already loaded. It returns 1 on success or 0 on failure.
\fBprovider_gettable_params() should return a constant array of descriptor \s-1OSSL_PARAM\s0\|(3), for parameters that provider_get_params() can handle.
\fBprovider_get_params() should process the \s-1OSSL_PARAM\s0\|(3) array \fIparams, setting the values of the parameters it understands.
\fBprovider_query_operation() should return a constant \s-1OSSL_ALGORITHM\s0\|(3) that corresponds to the given operation_id. It should indicate if the core may store a reference to this array by setting *no_store to 0 (core may store a reference) or 1 (core may not store a reference).
\fBprovider_unquery_operation() informs the provider that the result of a \fBprovider_query_operation() is no longer directly required and that the function pointers have been copied. The operation_id should match that passed to \fBprovider_query_operation() and algs should be its return value.
\fBprovider_get_reason_strings() should return a constant \s-1OSSL_ITEM\s0\|(3) array that provides reason strings for reason codes the provider may use when reporting errors using core_put_error().
The provider_get_capabilities() function should call the callback cb passing it a set of \s-1OSSL_PARAM\s0\|(3)s and the caller supplied argument arg. The \s-1OSSL_PARAM\s0\|(3)s should provide details about the capability with the name given in the capability argument relevant for the provider context provctx. If a provider supports multiple capabilities with the given name then it may call the callback multiple times (one for each capability). Capabilities can be useful for describing the services that a provider can offer. For further details see the \*(L"\s-1CAPABILITIES\*(R"\s0 section below. It should return 1 on success or 0 on error.
The provider_self_test() function should perform known answer tests on a subset of the algorithms that it uses, and may also verify the integrity of the provider module. It should return 1 on success or 0 on error. It will return 1 if this function is not used.
None of these functions are mandatory, but a provider is fairly useless without at least provider_query_operation(), and \fBprovider_gettable_params() is fairly useless if not accompanied by \fBprovider_get_params().
\fBprovider_gettable_params() should return the above parameters.
Additionally, provider specific configuration parameters from the config file are available, in dotted name form. The dotted name form is a concatenation of section names and final config command name separated by periods.
For example, let's say we have the following config example:
.Vb 2 config_diagnostics = 1 openssl_conf = openssl_init \& [openssl_init] providers = providers_sect \& [providers_sect] foo = foo_sect \& [foo_sect] activate = 1 data1 = 2 data2 = str more = foo_more \& [foo_more] data3 = foo,bar .Ve
The provider will have these additional parameters available: Item "activate" pointing at the string \*(L"1\*(R" Item "data1" pointing at the string \*(L"2\*(R" Item "data2" pointing at the string \*(L"str\*(R" Item "more.data3" pointing at the string \*(L"foo,bar\*(R"
For more information on handling parameters, see \s-1OSSL_PARAM\s0\|(3) as \fBOSSL_PARAM_int\|(3).
\*(L"TLS-GROUP\*(R" Capability Subsection "TLS-GROUP Capability"
The \*(L"TLS-GROUP\*(R" capability can be queried by libssl to discover the list of \s-1TLS\s0 groups that a provider can support. Each group supported can be used for \fIkey exchange (\s-1KEX\s0) or key encapsulation method (\s-1KEM\s0) during a \s-1TLS\s0 handshake. \s-1TLS\s0 clients can advertise the list of \s-1TLS\s0 groups they support in the supported_groups extension, and \s-1TLS\s0 servers can select a group from the offered list that they also support. In this way a provider can add to the list of groups that libssl already supports with additional ones.
Each \s-1TLS\s0 group that a provider supports should be described via the callback passed in through the provider_get_capabilities function. Each group should have the following details supplied (all are mandatory, except \fB\s-1OSSL_CAPABILITY_TLS_GROUP_IS_KEM\s0): Item "tls-group-name (OSSL_CAPABILITY_TLS_GROUP_NAME) <UTF8 string>" The name of the group as given in the \s-1IANA TLS\s0 Supported Groups registry <https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8>. Item "tls-group-name-internal (OSSL_CAPABILITY_TLS_GROUP_NAME_INTERNAL) <UTF8 string>" The name of the group as known by the provider. This could be the same as the \*(L"tls-group-name\*(R", but does not have to be. Item "tls-group-id (OSSL_CAPABILITY_TLS_GROUP_ID) <unsigned integer>" The \s-1TLS\s0 group id value as given in the \s-1IANA TLS\s0 Supported Groups registry. Item "tls-group-alg (OSSL_CAPABILITY_TLS_GROUP_ALG) <UTF8 string>" The name of a Key Management algorithm that the provider offers and that should be used with this group. Keys created should be able to support key exchange or key encapsulation method (\s-1KEM\s0), as implied by the optional \fB\s-1OSSL_CAPABILITY_TLS_GROUP_IS_KEM\s0 flag. The algorithm must support key and parameter generation as well as the key/parameter generation parameter, \s-1OSSL_PKEY_PARAM_GROUP_NAME\s0. The group name given via \*(L"tls-group-name-internal\*(R" above will be passed via \fB\s-1OSSL_PKEY_PARAM_GROUP_NAME\s0 when libssl wishes to generate keys/parameters. Item "tls-group-sec-bits (OSSL_CAPABILITY_TLS_GROUP_SECURITY_BITS) <unsigned integer>" The number of bits of security offered by keys in this group. The number of bits should be comparable with the ones given in table 2 and 3 of the \s-1NIST SP800-57\s0 document. Item "tls-group-is-kem (OSSL_CAPABILITY_TLS_GROUP_IS_KEM) <unsigned integer>" Boolean flag to describe if the group should be used in key exchange (\s-1KEX\s0) mode (0, default) or in key encapsulation method (\s-1KEM\s0) mode (1). .Sp This parameter is optional: if not specified, \s-1KEX\s0 mode is assumed as the default mode for the group. .Sp In \s-1KEX\s0 mode, in a typical Diffie-Hellman fashion, both sides execute keygen then derive against the peer public key. To operate in \s-1KEX\s0 mode, the group implementation must support the provider functions as described in \fBprovider-keyexch\|(7). .Sp In \s-1KEM\s0 mode, the client executes keygen and sends its public key, the server executes encapsulate using the client's public key and sends back the resulting ciphertext, finally the client executes decapsulate to retrieve the same shared secret generated by the server's encapsulate. To operate in \s-1KEM\s0 mode, the group implementation must support the provider functions as described in provider-kem\|(7). .Sp Both in \s-1KEX\s0 and \s-1KEM\s0 mode, the resulting shared secret is then used according to the protocol specification. Item "tls-min-tls (OSSL_CAPABILITY_TLS_GROUP_MIN_TLS) <integer>"
0 Item "tls-max-tls (OSSL_CAPABILITY_TLS_GROUP_MAX_TLS) <integer>" Item "tls-min-dtls (OSSL_CAPABILITY_TLS_GROUP_MIN_DTLS) <integer>" Item "tls-max-dtls (OSSL_CAPABILITY_TLS_GROUP_MAX_DTLS) <integer>"
These parameters can be used to describe the minimum and maximum \s-1TLS\s0 and \s-1DTLS\s0 versions supported by the group. The values equate to the on-the-wire encoding of the various \s-1TLS\s0 versions. For example TLSv1.3 is 0x0304 (772 decimal), and TLSv1.2 is 0x0303 (771 decimal). A 0 indicates that there is no defined minimum or maximum. A -1 indicates that the group should not be used in that protocol.
.Vb 3 #include <malloc.h> #include <openssl/core.h> #include <openssl/core_dispatch.h> \& /* Errors used in this provider */ #define E_MALLOC 1 \& static const OSSL_ITEM reasons[] = { { E_MALLOC, "memory allocation failure" }. { 0, NULL } /* Termination */ }; \& /* * To ensure we get the function signature right, forward declare * them using function types provided by openssl/core_dispatch.h */ OSSL_FUNC_bar_newctx_fn foo_newctx; OSSL_FUNC_bar_freectx_fn foo_freectx; OSSL_FUNC_bar_init_fn foo_init; OSSL_FUNC_bar_update_fn foo_update; OSSL_FUNC_bar_final_fn foo_final; \& OSSL_FUNC_provider_query_operation_fn p_query; OSSL_FUNC_provider_get_reason_strings_fn p_reasons; OSSL_FUNC_provider_teardown_fn p_teardown; \& OSSL_provider_init_fn OSSL_provider_init; \& OSSL_FUNC_core_put_error *c_put_error = NULL; \& /* Provider context */ struct prov_ctx_st { OSSL_CORE_HANDLE *handle; } \& /* operation context for the algorithm FOO */ struct foo_ctx_st { struct prov_ctx_st *provctx; int b; }; \& static void *foo_newctx(void *provctx) { struct foo_ctx_st *fooctx = malloc(sizeof(*fooctx)); \& if (fooctx != NULL) fooctx->provctx = provctx; else c_put_error(provctx->handle, E_MALLOC, _\|_FILE_\|_, _\|_LINE_\|_); return fooctx; } \& static void foo_freectx(void *fooctx) { free(fooctx); } \& static int foo_init(void *vfooctx) { struct foo_ctx_st *fooctx = vfooctx; \& fooctx->b = 0x33; } \& static int foo_update(void *vfooctx, unsigned char *in, size_t inl) { struct foo_ctx_st *fooctx = vfooctx; \& /* did you expect something serious? */ if (inl == 0) return 1; for (; inl-- > 0; in++) *in ^= fooctx->b; return 1; } \& static int foo_final(void *vfooctx) { struct foo_ctx_st *fooctx = vfooctx; \& fooctx->b = 0x66; } \& static const OSSL_DISPATCH foo_fns[] = { { OSSL_FUNC_BAR_NEWCTX, (void (*)(void))foo_newctx }, { OSSL_FUNC_BAR_FREECTX, (void (*)(void))foo_freectx }, { OSSL_FUNC_BAR_INIT, (void (*)(void))foo_init }, { OSSL_FUNC_BAR_UPDATE, (void (*)(void))foo_update }, { OSSL_FUNC_BAR_FINAL, (void (*)(void))foo_final }, { 0, NULL } }; \& static const OSSL_ALGORITHM bars[] = { { "FOO", "provider=chumbawamba", foo_fns }, { NULL, NULL, NULL } }; \& static const OSSL_ALGORITHM *p_query(void *provctx, int operation_id, int *no_store) { switch (operation_id) { case OSSL_OP_BAR: return bars; } return NULL; } \& static const OSSL_ITEM *p_reasons(void *provctx) { return reasons; } \& static void p_teardown(void *provctx) { free(provctx); } \& static const OSSL_DISPATCH prov_fns[] = { { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))p_teardown }, { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))p_query }, { OSSL_FUNC_PROVIDER_GET_REASON_STRINGS, (void (*)(void))p_reasons }, { 0, NULL } }; \& int OSSL_provider_init(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx) { struct prov_ctx_st *pctx = NULL; \& for (; in->function_id != 0; in++) switch (in->function_id) { case OSSL_FUNC_CORE_PUT_ERROR: c_put_error = OSSL_FUNC_core_put_error(in); break; } \& *out = prov_fns; \& if ((pctx = malloc(sizeof(*pctx))) == NULL) { /* * ALEA IACTA EST, if the core retrieves the reason table * regardless, that string will be displayed, otherwise not. */ c_put_error(handle, E_MALLOC, _\|_FILE_\|_, _\|_LINE_\|_); return 0; } pctx->handle = handle; return 1; } .Ve
This relies on a few things existing in openssl/core_dispatch.h:
.Vb 1 #define OSSL_OP_BAR 4711 \& #define OSSL_FUNC_BAR_NEWCTX 1 typedef void *(OSSL_FUNC_bar_newctx_fn)(void *provctx); static ossl_inline OSSL_FUNC_bar_newctx(const OSSL_DISPATCH *opf) { return (OSSL_FUNC_bar_newctx_fn *)opf->function; } \& #define OSSL_FUNC_BAR_FREECTX 2 typedef void (OSSL_FUNC_bar_freectx_fn)(void *ctx); static ossl_inline OSSL_FUNC_bar_freectx(const OSSL_DISPATCH *opf) { return (OSSL_FUNC_bar_freectx_fn *)opf->function; } \& #define OSSL_FUNC_BAR_INIT 3 typedef void *(OSSL_FUNC_bar_init_fn)(void *ctx); static ossl_inline OSSL_FUNC_bar_init(const OSSL_DISPATCH *opf) { return (OSSL_FUNC_bar_init_fn *)opf->function; } \& #define OSSL_FUNC_BAR_UPDATE 4 typedef void *(OSSL_FUNC_bar_update_fn)(void *ctx, unsigned char *in, size_t inl); static ossl_inline OSSL_FUNC_bar_update(const OSSL_DISPATCH *opf) { return (OSSL_FUNC_bar_update_fn *)opf->function; } \& #define OSSL_FUNC_BAR_FINAL 5 typedef void *(OSSL_FUNC_bar_final_fn)(void *ctx); static ossl_inline OSSL_FUNC_bar_final(const OSSL_DISPATCH *opf) { return (OSSL_FUNC_bar_final_fn *)opf->function; } .Ve
Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.