1PROVIDER-BASE(7ossl)                OpenSSL               PROVIDER-BASE(7ossl)
2
3
4

NAME

6       provider-base - The basic OpenSSL library <-> provider functions
7

SYNOPSIS

9        #include <openssl/core_dispatch.h>
10
11        /*
12         * None of these are actual functions, but are displayed like this for
13         * the function signatures for functions that are offered as function
14         * pointers in OSSL_DISPATCH arrays.
15         */
16
17        /* Functions offered by libcrypto to the providers */
18        const OSSL_ITEM *core_gettable_params(const OSSL_CORE_HANDLE *handle);
19        int core_get_params(const OSSL_CORE_HANDLE *handle, OSSL_PARAM params[]);
20
21        typedef void (*OSSL_thread_stop_handler_fn)(void *arg);
22        int core_thread_start(const OSSL_CORE_HANDLE *handle,
23                              OSSL_thread_stop_handler_fn handfn,
24                              void *arg);
25
26        OPENSSL_CORE_CTX *core_get_libctx(const OSSL_CORE_HANDLE *handle);
27        void core_new_error(const OSSL_CORE_HANDLE *handle);
28        void core_set_error_debug(const OSSL_CORE_HANDLE *handle,
29                                  const char *file, int line, const char *func);
30        void core_vset_error(const OSSL_CORE_HANDLE *handle,
31                             uint32_t reason, const char *fmt, va_list args);
32
33        int core_obj_add_sigid(const OSSL_CORE_HANDLE *prov, const char  *sign_name,
34                               const char *digest_name, const char *pkey_name);
35        int core_obj_create(const OSSL_CORE_HANDLE *handle, const char *oid,
36                            const char *sn, const char *ln);
37
38        /*
39         * Some OpenSSL functionality is directly offered to providers via
40         * dispatch
41         */
42        void *CRYPTO_malloc(size_t num, const char *file, int line);
43        void *CRYPTO_zalloc(size_t num, const char *file, int line);
44        void CRYPTO_free(void *ptr, const char *file, int line);
45        void CRYPTO_clear_free(void *ptr, size_t num,
46                               const char *file, int line);
47        void *CRYPTO_realloc(void *addr, size_t num,
48                             const char *file, int line);
49        void *CRYPTO_clear_realloc(void *addr, size_t old_num, size_t num,
50                                   const char *file, int line);
51        void *CRYPTO_secure_malloc(size_t num, const char *file, int line);
52        void *CRYPTO_secure_zalloc(size_t num, const char *file, int line);
53        void CRYPTO_secure_free(void *ptr, const char *file, int line);
54        void CRYPTO_secure_clear_free(void *ptr, size_t num,
55                                      const char *file, int line);
56        int CRYPTO_secure_allocated(const void *ptr);
57        void OPENSSL_cleanse(void *ptr, size_t len);
58
59        unsigned char *OPENSSL_hexstr2buf(const char *str, long *buflen);
60
61        OSSL_CORE_BIO *BIO_new_file(const char *filename, const char *mode);
62        OSSL_CORE_BIO *BIO_new_membuf(const void *buf, int len);
63        int BIO_read_ex(OSSL_CORE_BIO *bio, void *data, size_t data_len,
64                        size_t *bytes_read);
65        int BIO_write_ex(OSSL_CORE_BIO *bio, const void *data, size_t data_len,
66                         size_t *written);
67        int BIO_up_ref(OSSL_CORE_BIO *bio);
68        int BIO_free(OSSL_CORE_BIO *bio);
69        int BIO_vprintf(OSSL_CORE_BIO *bio, const char *format, va_list args);
70        int BIO_vsnprintf(char *buf, size_t n, const char *fmt, va_list args);
71
72        void OSSL_SELF_TEST_set_callback(OSSL_LIB_CTX *libctx, OSSL_CALLBACK *cb,
73                                         void *cbarg);
74
75        size_t get_entropy(const OSSL_CORE_HANDLE *handle,
76                           unsigned char **pout, int entropy,
77                           size_t min_len, size_t max_len);
78        void cleanup_entropy(const OSSL_CORE_HANDLE *handle,
79                             unsigned char *buf, size_t len);
80        size_t get_nonce(const OSSL_CORE_HANDLE *handle,
81                         unsigned char **pout, size_t min_len, size_t max_len,
82                         const void *salt, size_t salt_len);
83        void cleanup_nonce(const OSSL_CORE_HANDLE *handle,
84                           unsigned char *buf, size_t len);
85
86        /* Functions for querying the providers in the application library context */
87        int provider_register_child_cb(const OSSL_CORE_HANDLE *handle,
88                            int (*create_cb)(const OSSL_CORE_HANDLE *provider,
89                                             void *cbdata),
90                            int (*remove_cb)(const OSSL_CORE_HANDLE *provider,
91                                             void *cbdata),
92                            int (*global_props_cb)(const char *props, void *cbdata),
93                            void *cbdata);
94        void provider_deregister_child_cb(const OSSL_CORE_HANDLE *handle);
95        const char *provider_name(const OSSL_CORE_HANDLE *prov);
96        void *provider_get0_provider_ctx(const OSSL_CORE_HANDLE *prov);
97        const OSSL_DISPATCH *provider_get0_dispatch(const OSSL_CORE_HANDLE *prov);
98        int provider_up_ref(const OSSL_CORE_HANDLE *prov, int activate);
99        int provider_free(const OSSL_CORE_HANDLE *prov, int deactivate);
100
101        /* Functions offered by the provider to libcrypto */
102        void provider_teardown(void *provctx);
103        const OSSL_ITEM *provider_gettable_params(void *provctx);
104        int provider_get_params(void *provctx, OSSL_PARAM params[]);
105        const OSSL_ALGORITHM *provider_query_operation(void *provctx,
106                                                       int operation_id,
107                                                       const int *no_store);
108        void provider_unquery_operation(void *provctx, int operation_id,
109                                        const OSSL_ALGORITHM *algs);
110        const OSSL_ITEM *provider_get_reason_strings(void *provctx);
111        int provider_get_capabilities(void *provctx, const char *capability,
112                                      OSSL_CALLBACK *cb, void *arg);
113        int provider_self_test(void *provctx);
114

DESCRIPTION

116       All "functions" mentioned here are passed as function pointers between
117       libcrypto and the provider in OSSL_DISPATCH(3) arrays, in the call of
118       the provider initialization function.  See "Provider" in provider(7)
119       for a description of the initialization function. They are known as
120       "upcalls".
121
122       All these "functions" have a corresponding function type definition
123       named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
124       function pointer from a OSSL_DISPATCH(3) element named
125       OSSL_FUNC_{name}.  For example, the "function" core_gettable_params()
126       has these:
127
128        typedef OSSL_PARAM *
129            (OSSL_FUNC_core_gettable_params_fn)(const OSSL_CORE_HANDLE *handle);
130        static ossl_inline OSSL_NAME_core_gettable_params_fn
131            OSSL_FUNC_core_gettable_params(const OSSL_DISPATCH *opf);
132
133       OSSL_DISPATCH(3) arrays are indexed by numbers that are provided as
134       macros in openssl-core_dispatch.h(7), as follows:
135
136       For in (the OSSL_DISPATCH(3) array passed from libcrypto to the
137       provider):
138
139        core_gettable_params           OSSL_FUNC_CORE_GETTABLE_PARAMS
140        core_get_params                OSSL_FUNC_CORE_GET_PARAMS
141        core_thread_start              OSSL_FUNC_CORE_THREAD_START
142        core_get_libctx                OSSL_FUNC_CORE_GET_LIBCTX
143        core_new_error                 OSSL_FUNC_CORE_NEW_ERROR
144        core_set_error_debug           OSSL_FUNC_CORE_SET_ERROR_DEBUG
145        core_vset_error                OSSL_FUNC_CORE_VSET_ERROR
146        core_obj_add_sigid             OSSL_FUNC_CORE_OBJ_ADD_SIGID
147        core_obj_create                OSSL_FUNC_CORE_OBJ_CREATE
148        CRYPTO_malloc                  OSSL_FUNC_CRYPTO_MALLOC
149        CRYPTO_zalloc                  OSSL_FUNC_CRYPTO_ZALLOC
150        CRYPTO_free                    OSSL_FUNC_CRYPTO_FREE
151        CRYPTO_clear_free              OSSL_FUNC_CRYPTO_CLEAR_FREE
152        CRYPTO_realloc                 OSSL_FUNC_CRYPTO_REALLOC
153        CRYPTO_clear_realloc           OSSL_FUNC_CRYPTO_CLEAR_REALLOC
154        CRYPTO_secure_malloc           OSSL_FUNC_CRYPTO_SECURE_MALLOC
155        CRYPTO_secure_zalloc           OSSL_FUNC_CRYPTO_SECURE_ZALLOC
156        CRYPTO_secure_free             OSSL_FUNC_CRYPTO_SECURE_FREE
157        CRYPTO_secure_clear_free       OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE
158        CRYPTO_secure_allocated        OSSL_FUNC_CRYPTO_SECURE_ALLOCATED
159        BIO_new_file                   OSSL_FUNC_BIO_NEW_FILE
160        BIO_new_mem_buf                OSSL_FUNC_BIO_NEW_MEMBUF
161        BIO_read_ex                    OSSL_FUNC_BIO_READ_EX
162        BIO_write_ex                   OSSL_FUNC_BIO_WRITE_EX
163        BIO_up_ref                     OSSL_FUNC_BIO_UP_REF
164        BIO_free                       OSSL_FUNC_BIO_FREE
165        BIO_vprintf                    OSSL_FUNC_BIO_VPRINTF
166        BIO_vsnprintf                  OSSL_FUNC_BIO_VSNPRINTF
167        BIO_puts                       OSSL_FUNC_BIO_PUTS
168        BIO_gets                       OSSL_FUNC_BIO_GETS
169        BIO_ctrl                       OSSL_FUNC_BIO_CTRL
170        OPENSSL_cleanse                OSSL_FUNC_OPENSSL_CLEANSE
171        OSSL_SELF_TEST_set_callback    OSSL_FUNC_SELF_TEST_CB
172        ossl_rand_get_entropy          OSSL_FUNC_GET_ENTROPY
173        ossl_rand_cleanup_entropy      OSSL_FUNC_CLEANUP_ENTROPY
174        ossl_rand_get_nonce            OSSL_FUNC_GET_NONCE
175        ossl_rand_cleanup_nonce        OSSL_FUNC_CLEANUP_NONCE
176        provider_register_child_cb     OSSL_FUNC_PROVIDER_REGISTER_CHILD_CB
177        provider_deregister_child_cb   OSSL_FUNC_PROVIDER_DEREGISTER_CHILD_CB
178        provider_name                  OSSL_FUNC_PROVIDER_NAME
179        provider_get0_provider_ctx     OSSL_FUNC_PROVIDER_GET0_PROVIDER_CTX
180        provider_get0_dispatch         OSSL_FUNC_PROVIDER_GET0_DISPATCH
181        provider_up_ref                OSSL_FUNC_PROVIDER_UP_REF
182        provider_free                  OSSL_FUNC_PROVIDER_FREE
183
184       For *out (the OSSL_DISPATCH(3) array passed from the provider to
185       libcrypto):
186
187        provider_teardown              OSSL_FUNC_PROVIDER_TEARDOWN
188        provider_gettable_params       OSSL_FUNC_PROVIDER_GETTABLE_PARAMS
189        provider_get_params            OSSL_FUNC_PROVIDER_GET_PARAMS
190        provider_query_operation       OSSL_FUNC_PROVIDER_QUERY_OPERATION
191        provider_unquery_operation     OSSL_FUNC_PROVIDER_UNQUERY_OPERATION
192        provider_get_reason_strings    OSSL_FUNC_PROVIDER_GET_REASON_STRINGS
193        provider_get_capabilities      OSSL_FUNC_PROVIDER_GET_CAPABILITIES
194        provider_self_test             OSSL_FUNC_PROVIDER_SELF_TEST
195
196   Core functions
197       core_gettable_params() returns a constant array of descriptor
198       OSSL_PARAM(3), for parameters that core_get_params() can handle.
199
200       core_get_params() retrieves parameters from the core for the given
201       handle.  See "Core parameters" below for a description of currently
202       known parameters.
203
204       The core_thread_start() function informs the core that the provider has
205       stated an interest in the current thread. The core will inform the
206       provider when the thread eventually stops. It must be passed the handle
207       for this provider, as well as a callback handfn which will be called
208       when the thread stops. The callback will subsequently be called, with
209       the supplied argument arg, from the thread that is stopping and gets
210       passed the provider context as an argument. This may be useful to
211       perform thread specific clean up such as freeing thread local
212       variables.
213
214       core_get_libctx() retrieves the core context in which the library
215       object for the current provider is stored, accessible through the
216       handle.  This function is useful only for built-in providers such as
217       the default provider. Never cast this to OSSL_LIB_CTX in a provider
218       that is not built-in as the OSSL_LIB_CTX of the library loading the
219       provider might be a completely different structure than the
220       OSSL_LIB_CTX of the library the provider is linked to. Use
221       OSSL_LIB_CTX_new_child(3) instead to obtain a proper library context
222       that is linked to the application library context.
223
224       core_new_error(), core_set_error_debug() and core_vset_error() are
225       building blocks for reporting an error back to the core, with reference
226       to the handle.
227
228       core_new_error()
229           allocates a new thread specific error record.
230
231           This corresponds to the OpenSSL function ERR_new(3).
232
233       core_set_error_debug()
234           sets debugging information in the current thread specific error
235           record.  The debugging information includes the name of the file
236           file, the line line and the function name func where the error
237           occurred.
238
239           This corresponds to the OpenSSL function ERR_set_debug(3).
240
241       core_vset_error()
242           sets the reason for the error, along with any addition data.  The
243           reason is a number defined by the provider and used to index the
244           reason strings table that's returned by
245           provider_get_reason_strings().  The additional data is given as a
246           format string fmt and a set of arguments args, which are treated in
247           the same manner as with BIO_vsnprintf().  file and line may also be
248           passed to indicate exactly where the error occurred or was
249           reported.
250
251           This corresponds to the OpenSSL function ERR_vset_error(3).
252
253       The core_obj_create() function registers a new OID and associated short
254       name sn and long name ln for the given handle. It is similar to the
255       OpenSSL function OBJ_create(3) except that it returns 1 on success or 0
256       on failure.  It will treat as success the case where the OID already
257       exists (even if the short name sn or long name ln provided as arguments
258       differ from those associated with the existing OID, in which case the
259       new names are not associated).  This function is not thread safe.
260
261       The core_obj_add_sigid() function registers a new composite signature
262       algorithm (sign_name) consisting of an underlying signature algorithm
263       (pkey_name) and digest algorithm (digest_name) for the given handle. It
264       assumes that the OIDs for the composite signature algorithm as well as
265       for the underlying signature and digest algorithms are either already
266       known to OpenSSL or have been registered via a call to
267       core_obj_create(). It corresponds to the OpenSSL function
268       OBJ_add_sigid(3), except that the objects are identified by name rather
269       than a numeric NID. Any name (OID, short name or long name) can be used
270       to identify the object. It will treat as success the case where the
271       composite signature algorithm already exists (even if registered
272       against a different underlying signature or digest algorithm). For
273       digest_name, NULL or an empty string is permissible for signature
274       algorithms that do not need a digest to operate correctly. The function
275       returns 1 on success or 0 on failure.  This function is not thread
276       safe.
277
278       CRYPTO_malloc(), CRYPTO_zalloc(), CRYPTO_free(), CRYPTO_clear_free(),
279       CRYPTO_realloc(), CRYPTO_clear_realloc(), CRYPTO_secure_malloc(),
280       CRYPTO_secure_zalloc(), CRYPTO_secure_free(),
281       CRYPTO_secure_clear_free(), CRYPTO_secure_allocated(), BIO_new_file(),
282       BIO_new_mem_buf(), BIO_read_ex(), BIO_write_ex(), BIO_up_ref(),
283       BIO_free(), BIO_vprintf(), BIO_vsnprintf(), BIO_gets(), BIO_puts(),
284       BIO_ctrl(), OPENSSL_cleanse() and OPENSSL_hexstr2buf() correspond
285       exactly to the public functions with the same name.  As a matter of
286       fact, the pointers in the OSSL_DISPATCH(3) array are typically direct
287       pointers to those public functions. Note that the BIO functions take an
288       OSSL_CORE_BIO type rather than the standard BIO type. This is to ensure
289       that a provider does not mix BIOs from the core with BIOs used on the
290       provider side (the two are not compatible).
291       OSSL_SELF_TEST_set_callback() is used to set an optional callback that
292       can be passed into a provider. This may be ignored by a provider.
293
294       get_entropy() retrieves seeding material from the operating system.
295       The seeding material will have at least entropy bytes of randomness and
296       the output will have at least min_len and at most max_len bytes.  The
297       buffer address is stored in *pout and the buffer length is returned to
298       the caller.  On error, zero is returned.
299
300       cleanup_entropy() is used to clean up and free the buffer returned by
301       get_entropy().  The entropy pointer returned by get_entropy() is passed
302       in buf and its length in len.
303
304       get_nonce() retrieves a nonce using the passed salt parameter of length
305       salt_len and operating system specific information.  The salt should
306       contain uniquely identifying information and this is included, in an
307       unspecified manner, as part of the output.  The output is stored in a
308       buffer which contains at least min_len and at most max_len bytes.  The
309       buffer address is stored in *pout and the buffer length returned to the
310       caller.  On error, zero is returned.
311
312       cleanup_nonce() is used to clean up and free the buffer returned by
313       get_nonce().  The nonce pointer returned by get_nonce() is passed in
314       buf and its length in len.
315
316       provider_register_child_cb() registers callbacks for being informed
317       about the loading and unloading of providers in the application's
318       library context.  handle is this provider's handle and cbdata is this
319       provider's data that will be passed back to the callbacks. It returns 1
320       on success or 0 otherwise. These callbacks may be called while holding
321       locks in libcrypto. In order to avoid deadlocks the callback
322       implementation must not be long running and must not call other OpenSSL
323       API functions or upcalls.
324
325       create_cb is a callback that will be called when a new provider is
326       loaded into the application's library context. It is also called for
327       any providers that are already loaded at the point that this callback
328       is registered. The callback is passed the handle being used for the new
329       provider being loadded and this provider's data in cbdata. It should
330       return 1 on success or 0 on failure.
331
332       remove_cb is a callback that will be called when a new provider is
333       unloaded from the application's library context. It is passed the
334       handle being used for the provider being unloaded and this provider's
335       data in cbdata. It should return 1 on success or 0 on failure.
336
337       global_props_cb is a callback that will be called when the global
338       properties from the parent library context are changed. It should
339       return 1 on success or 0 on failure.
340
341       provider_deregister_child_cb() unregisters callbacks previously
342       registered via provider_register_child_cb(). If
343       provider_register_child_cb() has been called then
344       provider_deregister_child_cb() should be called at or before the point
345       that this provider's teardown function is called.
346
347       provider_name() returns a string giving the name of the provider
348       identified by handle.
349
350       provider_get0_provider_ctx() returns the provider context that is
351       associated with the provider identified by prov.
352
353       provider_get0_dispatch() gets the dispatch table registered by the
354       provider identified by prov when it initialised.
355
356       provider_up_ref() increments the reference count on the provider prov.
357       If activate is nonzero then the provider is also loaded if it is not
358       already loaded. It returns 1 on success or 0 on failure.
359
360       provider_free() decrements the reference count on the provider prov. If
361       deactivate is nonzero then the provider is also unloaded if it is not
362       already loaded. It returns 1 on success or 0 on failure.
363
364   Provider functions
365       provider_teardown() is called when a provider is shut down and removed
366       from the core's provider store.  It must free the passed provctx.
367
368       provider_gettable_params() should return a constant array of descriptor
369       OSSL_PARAM(3), for parameters that provider_get_params() can handle.
370
371       provider_get_params() should process the OSSL_PARAM(3) array params,
372       setting the values of the parameters it understands.
373
374       provider_query_operation() should return a constant OSSL_ALGORITHM(3)
375       that corresponds to the given operation_id.  It should indicate if the
376       core may store a reference to this array by setting *no_store to 0
377       (core may store a reference) or 1 (core may not store a reference).
378
379       provider_unquery_operation() informs the provider that the result of a
380       provider_query_operation() is no longer directly required and that the
381       function pointers have been copied.  The operation_id should match that
382       passed to provider_query_operation() and algs should be its return
383       value.
384
385       provider_get_reason_strings() should return a constant OSSL_ITEM(3)
386       array that provides reason strings for reason codes the provider may
387       use when reporting errors using core_put_error().
388
389       The provider_get_capabilities() function should call the callback cb
390       passing it a set of OSSL_PARAM(3)s and the caller supplied argument
391       arg. The OSSL_PARAM(3)s should provide details about the capability
392       with the name given in the capability argument relevant for the
393       provider context provctx. If a provider supports multiple capabilities
394       with the given name then it may call the callback multiple times (one
395       for each capability). Capabilities can be useful for describing the
396       services that a provider can offer. For further details see the
397       "CAPABILITIES" section below. It should return 1 on success or 0 on
398       error.
399
400       The provider_self_test() function should perform known answer tests on
401       a subset of the algorithms that it uses, and may also verify the
402       integrity of the provider module. It should return 1 on success or 0 on
403       error. It will return 1 if this function is not used.
404
405       None of these functions are mandatory, but a provider is fairly useless
406       without at least provider_query_operation(), and
407       provider_gettable_params() is fairly useless if not accompanied by
408       provider_get_params().
409
410   Provider parameters
411       provider_get_params() can return the following provider parameters to
412       the core:
413
414       "name" (OSSL_PROV_PARAM_NAME) <UTF8 ptr>
415           This points to a string that should give a unique name for the
416           provider.
417
418       "version" (OSSL_PROV_PARAM_VERSION) <UTF8 ptr>
419           This points to a string that is a version number associated with
420           this provider.  OpenSSL in-built providers use OPENSSL_VERSION_STR,
421           but this may be different for any third party provider. This string
422           is for informational purposes only.
423
424       "buildinfo" (OSSL_PROV_PARAM_BUILDINFO) <UTF8 ptr>
425           This points to a string that is a build information associated with
426           this provider.  OpenSSL in-built providers use
427           OPENSSL_FULL_VERSION_STR, but this may be different for any third
428           party provider.
429
430       "status" (OSSL_PROV_PARAM_STATUS) <unsigned integer>
431           This returns 0 if the provider has entered an error state,
432           otherwise it returns 1.
433
434       provider_gettable_params() should return the above parameters.
435
436   Core parameters
437       core_get_params() can retrieve the following core parameters for each
438       provider:
439
440       "openssl-version" (OSSL_PROV_PARAM_CORE_VERSION) <UTF8 string ptr>
441           This points to the OpenSSL libraries' full version string, i.e. the
442           string expanded from the macro OPENSSL_VERSION_STR.
443
444       "provider-name" (OSSL_PROV_PARAM_CORE_PROV_NAME) <UTF8 string ptr>
445           This points to the OpenSSL libraries' idea of what the calling
446           provider is named.
447
448       "module-filename" (OSSL_PROV_PARAM_CORE_MODULE_FILENAME) <UTF8 string
449       ptr>
450           This points to a string containing the full filename of the
451           providers module file.
452
453       Additionally, provider specific configuration parameters from the
454       config file are available, in dotted name form.  The dotted name form
455       is a concatenation of section names and final config command name
456       separated by periods.
457
458       For example, let's say we have the following config example:
459
460        config_diagnostics = 1
461        openssl_conf = openssl_init
462
463        [openssl_init]
464        providers = providers_sect
465
466        [providers_sect]
467        foo = foo_sect
468
469        [foo_sect]
470        activate = 1
471        data1 = 2
472        data2 = str
473        more = foo_more
474
475        [foo_more]
476        data3 = foo,bar
477
478       The provider will have these additional parameters available:
479
480       "activate"
481           pointing at the string "1"
482
483       "data1"
484           pointing at the string "2"
485
486       "data2"
487           pointing at the string "str"
488
489       "more.data3"
490           pointing at the string "foo,bar"
491
492       For more information on handling parameters, see OSSL_PARAM(3) as
493       OSSL_PARAM_int(3).
494

CAPABILITIES

496       Capabilities describe some of the services that a provider can offer.
497       Applications can query the capabilities to discover those services.
498
499       "TLS-GROUP" Capability
500
501       The "TLS-GROUP" capability can be queried by libssl to discover the
502       list of TLS groups that a provider can support. Each group supported
503       can be used for key exchange (KEX) or key encapsulation method (KEM)
504       during a TLS handshake.  TLS clients can advertise the list of TLS
505       groups they support in the supported_groups extension, and TLS servers
506       can select a group from the offered list that they also support. In
507       this way a provider can add to the list of groups that libssl already
508       supports with additional ones.
509
510       Each TLS group that a provider supports should be described via the
511       callback passed in through the provider_get_capabilities function. Each
512       group should have the following details supplied (all are mandatory,
513       except OSSL_CAPABILITY_TLS_GROUP_IS_KEM):
514
515       "tls-group-name" (OSSL_CAPABILITY_TLS_GROUP_NAME) <UTF8 string>
516           The name of the group as given in the IANA TLS Supported Groups
517           registry
518           <https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8>.
519
520       "tls-group-name-internal" (OSSL_CAPABILITY_TLS_GROUP_NAME_INTERNAL)
521       <UTF8 string>
522           The name of the group as known by the provider. This could be the
523           same as the "tls-group-name", but does not have to be.
524
525       "tls-group-id" (OSSL_CAPABILITY_TLS_GROUP_ID) <unsigned integer>
526           The TLS group id value as given in the IANA TLS Supported Groups
527           registry.
528
529       "tls-group-alg" (OSSL_CAPABILITY_TLS_GROUP_ALG) <UTF8 string>
530           The name of a Key Management algorithm that the provider offers and
531           that should be used with this group. Keys created should be able to
532           support key exchange or key encapsulation method (KEM), as implied
533           by the optional OSSL_CAPABILITY_TLS_GROUP_IS_KEM flag.  The
534           algorithm must support key and parameter generation as well as the
535           key/parameter generation parameter, OSSL_PKEY_PARAM_GROUP_NAME. The
536           group name given via "tls-group-name-internal" above will be passed
537           via OSSL_PKEY_PARAM_GROUP_NAME when libssl wishes to generate
538           keys/parameters.
539
540       "tls-group-sec-bits" (OSSL_CAPABILITY_TLS_GROUP_SECURITY_BITS)
541       <unsigned integer>
542           The number of bits of security offered by keys in this group. The
543           number of bits should be comparable with the ones given in table 2
544           and 3 of the NIST SP800-57 document.
545
546       "tls-group-is-kem" (OSSL_CAPABILITY_TLS_GROUP_IS_KEM) <unsigned
547       integer>
548           Boolean flag to describe if the group should be used in key
549           exchange (KEX) mode (0, default) or in key encapsulation method
550           (KEM) mode (1).
551
552           This parameter is optional: if not specified, KEX mode is assumed
553           as the default mode for the group.
554
555           In KEX mode, in a typical Diffie-Hellman fashion, both sides
556           execute keygen then derive against the peer public key. To operate
557           in KEX mode, the group implementation must support the provider
558           functions as described in provider-keyexch(7).
559
560           In KEM mode, the client executes keygen and sends its public key,
561           the server executes encapsulate using the client's public key and
562           sends back the resulting ciphertext, finally the client executes
563           decapsulate to retrieve the same shared secret generated by the
564           server's encapsulate. To operate in KEM mode, the group
565           implementation must support the provider functions as described in
566           provider-kem(7).
567
568           Both in KEX and KEM mode, the resulting shared secret is then used
569           according to the protocol specification.
570
571       "tls-min-tls" (OSSL_CAPABILITY_TLS_GROUP_MIN_TLS) <integer>
572       "tls-max-tls" (OSSL_CAPABILITY_TLS_GROUP_MAX_TLS) <integer>
573       "tls-min-dtls" (OSSL_CAPABILITY_TLS_GROUP_MIN_DTLS) <integer>
574       "tls-max-dtls" (OSSL_CAPABILITY_TLS_GROUP_MAX_DTLS) <integer>
575           These parameters can be used to describe the minimum and maximum
576           TLS and DTLS versions supported by the group. The values equate to
577           the on-the-wire encoding of the various TLS versions. For example
578           TLSv1.3 is 0x0304 (772 decimal), and TLSv1.2 is 0x0303 (771
579           decimal). A 0 indicates that there is no defined minimum or
580           maximum. A -1 indicates that the group should not be used in that
581           protocol.
582

EXAMPLES

584       This is an example of a simple provider made available as a dynamically
585       loadable module.  It implements the fictitious algorithm "FOO" for the
586       fictitious operation "BAR".
587
588        #include <malloc.h>
589        #include <openssl/core.h>
590        #include <openssl/core_dispatch.h>
591
592        /* Errors used in this provider */
593        #define E_MALLOC       1
594
595        static const OSSL_ITEM reasons[] = {
596            { E_MALLOC, "memory allocation failure" }.
597            { 0, NULL } /* Termination */
598        };
599
600        /*
601         * To ensure we get the function signature right, forward declare
602         * them using function types provided by openssl/core_dispatch.h
603         */
604        OSSL_FUNC_bar_newctx_fn foo_newctx;
605        OSSL_FUNC_bar_freectx_fn foo_freectx;
606        OSSL_FUNC_bar_init_fn foo_init;
607        OSSL_FUNC_bar_update_fn foo_update;
608        OSSL_FUNC_bar_final_fn foo_final;
609
610        OSSL_FUNC_provider_query_operation_fn p_query;
611        OSSL_FUNC_provider_get_reason_strings_fn p_reasons;
612        OSSL_FUNC_provider_teardown_fn p_teardown;
613
614        OSSL_provider_init_fn OSSL_provider_init;
615
616        OSSL_FUNC_core_put_error *c_put_error = NULL;
617
618        /* Provider context */
619        struct prov_ctx_st {
620            OSSL_CORE_HANDLE *handle;
621        }
622
623        /* operation context for the algorithm FOO */
624        struct foo_ctx_st {
625            struct prov_ctx_st *provctx;
626            int b;
627        };
628
629        static void *foo_newctx(void *provctx)
630        {
631            struct foo_ctx_st *fooctx = malloc(sizeof(*fooctx));
632
633            if (fooctx != NULL)
634                fooctx->provctx = provctx;
635            else
636                c_put_error(provctx->handle, E_MALLOC, __FILE__, __LINE__);
637            return fooctx;
638        }
639
640        static void foo_freectx(void *fooctx)
641        {
642            free(fooctx);
643        }
644
645        static int foo_init(void *vfooctx)
646        {
647            struct foo_ctx_st *fooctx = vfooctx;
648
649            fooctx->b = 0x33;
650        }
651
652        static int foo_update(void *vfooctx, unsigned char *in, size_t inl)
653        {
654            struct foo_ctx_st *fooctx = vfooctx;
655
656            /* did you expect something serious? */
657            if (inl == 0)
658                return 1;
659            for (; inl-- > 0; in++)
660                *in ^= fooctx->b;
661            return 1;
662        }
663
664        static int foo_final(void *vfooctx)
665        {
666            struct foo_ctx_st *fooctx = vfooctx;
667
668            fooctx->b = 0x66;
669        }
670
671        static const OSSL_DISPATCH foo_fns[] = {
672            { OSSL_FUNC_BAR_NEWCTX, (void (*)(void))foo_newctx },
673            { OSSL_FUNC_BAR_FREECTX, (void (*)(void))foo_freectx },
674            { OSSL_FUNC_BAR_INIT, (void (*)(void))foo_init },
675            { OSSL_FUNC_BAR_UPDATE, (void (*)(void))foo_update },
676            { OSSL_FUNC_BAR_FINAL, (void (*)(void))foo_final },
677            { 0, NULL }
678        };
679
680        static const OSSL_ALGORITHM bars[] = {
681            { "FOO", "provider=chumbawamba", foo_fns },
682            { NULL, NULL, NULL }
683        };
684
685        static const OSSL_ALGORITHM *p_query(void *provctx, int operation_id,
686                                             int *no_store)
687        {
688            switch (operation_id) {
689            case OSSL_OP_BAR:
690                return bars;
691            }
692            return NULL;
693        }
694
695        static const OSSL_ITEM *p_reasons(void *provctx)
696        {
697            return reasons;
698        }
699
700        static void p_teardown(void *provctx)
701        {
702            free(provctx);
703        }
704
705        static const OSSL_DISPATCH prov_fns[] = {
706            { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))p_teardown },
707            { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))p_query },
708            { OSSL_FUNC_PROVIDER_GET_REASON_STRINGS, (void (*)(void))p_reasons },
709            { 0, NULL }
710        };
711
712        int OSSL_provider_init(const OSSL_CORE_HANDLE *handle,
713                               const OSSL_DISPATCH *in,
714                               const OSSL_DISPATCH **out,
715                               void **provctx)
716        {
717            struct prov_ctx_st *pctx = NULL;
718
719            for (; in->function_id != 0; in++)
720                switch (in->function_id) {
721                case OSSL_FUNC_CORE_PUT_ERROR:
722                    c_put_error = OSSL_FUNC_core_put_error(in);
723                    break;
724                }
725
726            *out = prov_fns;
727
728            if ((pctx = malloc(sizeof(*pctx))) == NULL) {
729                /*
730                 * ALEA IACTA EST, if the core retrieves the reason table
731                 * regardless, that string will be displayed, otherwise not.
732                 */
733                c_put_error(handle, E_MALLOC, __FILE__, __LINE__);
734                return 0;
735            }
736            pctx->handle = handle;
737            return 1;
738        }
739
740       This relies on a few things existing in openssl/core_dispatch.h:
741
742        #define OSSL_OP_BAR            4711
743
744        #define OSSL_FUNC_BAR_NEWCTX      1
745        typedef void *(OSSL_FUNC_bar_newctx_fn)(void *provctx);
746        static ossl_inline OSSL_FUNC_bar_newctx(const OSSL_DISPATCH *opf)
747        { return (OSSL_FUNC_bar_newctx_fn *)opf->function; }
748
749        #define OSSL_FUNC_BAR_FREECTX     2
750        typedef void (OSSL_FUNC_bar_freectx_fn)(void *ctx);
751        static ossl_inline OSSL_FUNC_bar_freectx(const OSSL_DISPATCH *opf)
752        { return (OSSL_FUNC_bar_freectx_fn *)opf->function; }
753
754        #define OSSL_FUNC_BAR_INIT        3
755        typedef void *(OSSL_FUNC_bar_init_fn)(void *ctx);
756        static ossl_inline OSSL_FUNC_bar_init(const OSSL_DISPATCH *opf)
757        { return (OSSL_FUNC_bar_init_fn *)opf->function; }
758
759        #define OSSL_FUNC_BAR_UPDATE      4
760        typedef void *(OSSL_FUNC_bar_update_fn)(void *ctx,
761                                              unsigned char *in, size_t inl);
762        static ossl_inline OSSL_FUNC_bar_update(const OSSL_DISPATCH *opf)
763        { return (OSSL_FUNC_bar_update_fn *)opf->function; }
764
765        #define OSSL_FUNC_BAR_FINAL       5
766        typedef void *(OSSL_FUNC_bar_final_fn)(void *ctx);
767        static ossl_inline OSSL_FUNC_bar_final(const OSSL_DISPATCH *opf)
768        { return (OSSL_FUNC_bar_final_fn *)opf->function; }
769

SEE ALSO

771       provider(7)
772

HISTORY

774       The concept of providers and everything surrounding them was introduced
775       in OpenSSL 3.0.
776
778       Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
779
780       Licensed under the Apache License 2.0 (the "License").  You may not use
781       this file except in compliance with the License.  You can obtain a copy
782       in the file LICENSE in the source distribution or at
783       <https://www.openssl.org/source/license.html>.
784
785
786
7873.0.9                             2023-07-27              PROVIDER-BASE(7ossl)
Impressum