1PROVIDER-BASE(7ossl) OpenSSL PROVIDER-BASE(7ossl)
2
3
4
6 provider-base - The basic OpenSSL library <-> provider functions
7
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
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).
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.
276
277 CRYPTO_malloc(), CRYPTO_zalloc(), CRYPTO_free(), CRYPTO_clear_free(),
278 CRYPTO_realloc(), CRYPTO_clear_realloc(), CRYPTO_secure_malloc(),
279 CRYPTO_secure_zalloc(), CRYPTO_secure_free(),
280 CRYPTO_secure_clear_free(), CRYPTO_secure_allocated(), BIO_new_file(),
281 BIO_new_mem_buf(), BIO_read_ex(), BIO_write_ex(), BIO_up_ref(),
282 BIO_free(), BIO_vprintf(), BIO_vsnprintf(), BIO_gets(), BIO_puts(),
283 BIO_ctrl(), OPENSSL_cleanse() and OPENSSL_hexstr2buf() correspond
284 exactly to the public functions with the same name. As a matter of
285 fact, the pointers in the OSSL_DISPATCH(3) array are typically direct
286 pointers to those public functions. Note that the BIO functions take an
287 OSSL_CORE_BIO type rather than the standard BIO type. This is to ensure
288 that a provider does not mix BIOs from the core with BIOs used on the
289 provider side (the two are not compatible).
290 OSSL_SELF_TEST_set_callback() is used to set an optional callback that
291 can be passed into a provider. This may be ignored by a provider.
292
293 get_entropy() retrieves seeding material from the operating system.
294 The seeding material will have at least entropy bytes of randomness and
295 the output will have at least min_len and at most max_len bytes. The
296 buffer address is stored in *pout and the buffer length is returned to
297 the caller. On error, zero is returned.
298
299 cleanup_entropy() is used to clean up and free the buffer returned by
300 get_entropy(). The entropy pointer returned by get_entropy() is passed
301 in buf and its length in len.
302
303 get_nonce() retrieves a nonce using the passed salt parameter of length
304 salt_len and operating system specific information. The salt should
305 contain uniquely identifying information and this is included, in an
306 unspecified manner, as part of the output. The output is stored in a
307 buffer which contains at least min_len and at most max_len bytes. The
308 buffer address is stored in *pout and the buffer length returned to the
309 caller. On error, zero is returned.
310
311 cleanup_nonce() is used to clean up and free the buffer returned by
312 get_nonce(). The nonce pointer returned by get_nonce() is passed in
313 buf and its length in len.
314
315 provider_register_child_cb() registers callbacks for being informed
316 about the loading and unloading of providers in the application's
317 library context. handle is this provider's handle and cbdata is this
318 provider's data that will be passed back to the callbacks. It returns 1
319 on success or 0 otherwise. These callbacks may be called while holding
320 locks in libcrypto. In order to avoid deadlocks the callback
321 implementation must not be long running and must not call other OpenSSL
322 API functions or upcalls.
323
324 create_cb is a callback that will be called when a new provider is
325 loaded into the application's library context. It is also called for
326 any providers that are already loaded at the point that this callback
327 is registered. The callback is passed the handle being used for the new
328 provider being loadded and this provider's data in cbdata. It should
329 return 1 on success or 0 on failure.
330
331 remove_cb is a callback that will be called when a new provider is
332 unloaded from the application's library context. It is passed the
333 handle being used for the provider being unloaded and this provider's
334 data in cbdata. It should return 1 on success or 0 on failure.
335
336 global_props_cb is a callback that will be called when the global
337 properties from the parent library context are changed. It should
338 return 1 on success or 0 on failure.
339
340 provider_deregister_child_cb() unregisters callbacks previously
341 registered via provider_register_child_cb(). If
342 provider_register_child_cb() has been called then
343 provider_deregister_child_cb() should be called at or before the point
344 that this provider's teardown function is called.
345
346 provider_name() returns a string giving the name of the provider
347 identified by handle.
348
349 provider_get0_provider_ctx() returns the provider context that is
350 associated with the provider identified by prov.
351
352 provider_get0_dispatch() gets the dispatch table registered by the
353 provider identified by prov when it initialised.
354
355 provider_up_ref() increments the reference count on the provider prov.
356 If activate is nonzero then the provider is also loaded if it is not
357 already loaded. It returns 1 on success or 0 on failure.
358
359 provider_free() decrements the reference count on the provider prov. If
360 deactivate is nonzero then the provider is also unloaded if it is not
361 already loaded. It returns 1 on success or 0 on failure.
362
363 Provider functions
364 provider_teardown() is called when a provider is shut down and removed
365 from the core's provider store. It must free the passed provctx.
366
367 provider_gettable_params() should return a constant array of descriptor
368 OSSL_PARAM(3), for parameters that provider_get_params() can handle.
369
370 provider_get_params() should process the OSSL_PARAM(3) array params,
371 setting the values of the parameters it understands.
372
373 provider_query_operation() should return a constant OSSL_ALGORITHM(3)
374 that corresponds to the given operation_id. It should indicate if the
375 core may store a reference to this array by setting *no_store to 0
376 (core may store a reference) or 1 (core may not store a reference).
377
378 provider_unquery_operation() informs the provider that the result of a
379 provider_query_operation() is no longer directly required and that the
380 function pointers have been copied. The operation_id should match that
381 passed to provider_query_operation() and algs should be its return
382 value.
383
384 provider_get_reason_strings() should return a constant OSSL_ITEM(3)
385 array that provides reason strings for reason codes the provider may
386 use when reporting errors using core_put_error().
387
388 The provider_get_capabilities() function should call the callback cb
389 passing it a set of OSSL_PARAM(3)s and the caller supplied argument
390 arg. The OSSL_PARAM(3)s should provide details about the capability
391 with the name given in the capability argument relevant for the
392 provider context provctx. If a provider supports multiple capabilities
393 with the given name then it may call the callback multiple times (one
394 for each capability). Capabilities can be useful for describing the
395 services that a provider can offer. For further details see the
396 "CAPABILITIES" section below. It should return 1 on success or 0 on
397 error.
398
399 The provider_self_test() function should perform known answer tests on
400 a subset of the algorithms that it uses, and may also verify the
401 integrity of the provider module. It should return 1 on success or 0 on
402 error. It will return 1 if this function is not used.
403
404 None of these functions are mandatory, but a provider is fairly useless
405 without at least provider_query_operation(), and
406 provider_gettable_params() is fairly useless if not accompanied by
407 provider_get_params().
408
409 Provider parameters
410 provider_get_params() can return the following provider parameters to
411 the core:
412
413 "name" (OSSL_PROV_PARAM_NAME) <UTF8 ptr>
414 This points to a string that should give a unique name for the
415 provider.
416
417 "version" (OSSL_PROV_PARAM_VERSION) <UTF8 ptr>
418 This points to a string that is a version number associated with
419 this provider. OpenSSL in-built providers use OPENSSL_VERSION_STR,
420 but this may be different for any third party provider. This string
421 is for informational purposes only.
422
423 "buildinfo" (OSSL_PROV_PARAM_BUILDINFO) <UTF8 ptr>
424 This points to a string that is a build information associated with
425 this provider. OpenSSL in-built providers use
426 OPENSSL_FULL_VERSION_STR, but this may be different for any third
427 party provider.
428
429 "status" (OSSL_PROV_PARAM_STATUS) <unsigned integer>
430 This returns 0 if the provider has entered an error state,
431 otherwise it returns 1.
432
433 provider_gettable_params() should return the above parameters.
434
435 Core parameters
436 core_get_params() can retrieve the following core parameters for each
437 provider:
438
439 "openssl-version" (OSSL_PROV_PARAM_CORE_VERSION) <UTF8 string ptr>
440 This points to the OpenSSL libraries' full version string, i.e. the
441 string expanded from the macro OPENSSL_VERSION_STR.
442
443 "provider-name" (OSSL_PROV_PARAM_CORE_PROV_NAME) <UTF8 string ptr>
444 This points to the OpenSSL libraries' idea of what the calling
445 provider is named.
446
447 "module-filename" (OSSL_PROV_PARAM_CORE_MODULE_FILENAME) <UTF8 string
448 ptr>
449 This points to a string containing the full filename of the
450 providers module file.
451
452 Additionally, provider specific configuration parameters from the
453 config file are available, in dotted name form. The dotted name form
454 is a concatenation of section names and final config command name
455 separated by periods.
456
457 For example, let's say we have the following config example:
458
459 config_diagnostics = 1
460 openssl_conf = openssl_init
461
462 [openssl_init]
463 providers = providers_sect
464
465 [providers_sect]
466 foo = foo_sect
467
468 [foo_sect]
469 activate = 1
470 data1 = 2
471 data2 = str
472 more = foo_more
473
474 [foo_more]
475 data3 = foo,bar
476
477 The provider will have these additional parameters available:
478
479 "activate"
480 pointing at the string "1"
481
482 "data1"
483 pointing at the string "2"
484
485 "data2"
486 pointing at the string "str"
487
488 "more.data3"
489 pointing at the string "foo,bar"
490
491 For more information on handling parameters, see OSSL_PARAM(3) as
492 OSSL_PARAM_int(3).
493
495 Capabilities describe some of the services that a provider can offer.
496 Applications can query the capabilities to discover those services.
497
498 "TLS-GROUP" Capability
499
500 The "TLS-GROUP" capability can be queried by libssl to discover the
501 list of TLS groups that a provider can support. Each group supported
502 can be used for key exchange (KEX) or key encapsulation method (KEM)
503 during a TLS handshake. TLS clients can advertise the list of TLS
504 groups they support in the supported_groups extension, and TLS servers
505 can select a group from the offered list that they also support. In
506 this way a provider can add to the list of groups that libssl already
507 supports with additional ones.
508
509 Each TLS group that a provider supports should be described via the
510 callback passed in through the provider_get_capabilities function. Each
511 group should have the following details supplied (all are mandatory,
512 except OSSL_CAPABILITY_TLS_GROUP_IS_KEM):
513
514 "tls-group-name" (OSSL_CAPABILITY_TLS_GROUP_NAME) <UTF8 string>
515 The name of the group as given in the IANA TLS Supported Groups
516 registry
517 <https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8>.
518
519 "tls-group-name-internal" (OSSL_CAPABILITY_TLS_GROUP_NAME_INTERNAL)
520 <UTF8 string>
521 The name of the group as known by the provider. This could be the
522 same as the "tls-group-name", but does not have to be.
523
524 "tls-group-id" (OSSL_CAPABILITY_TLS_GROUP_ID) <unsigned integer>
525 The TLS group id value as given in the IANA TLS Supported Groups
526 registry.
527
528 "tls-group-alg" (OSSL_CAPABILITY_TLS_GROUP_ALG) <UTF8 string>
529 The name of a Key Management algorithm that the provider offers and
530 that should be used with this group. Keys created should be able to
531 support key exchange or key encapsulation method (KEM), as implied
532 by the optional OSSL_CAPABILITY_TLS_GROUP_IS_KEM flag. The
533 algorithm must support key and parameter generation as well as the
534 key/parameter generation parameter, OSSL_PKEY_PARAM_GROUP_NAME. The
535 group name given via "tls-group-name-internal" above will be passed
536 via OSSL_PKEY_PARAM_GROUP_NAME when libssl wishes to generate
537 keys/parameters.
538
539 "tls-group-sec-bits" (OSSL_CAPABILITY_TLS_GROUP_SECURITY_BITS)
540 <unsigned integer>
541 The number of bits of security offered by keys in this group. The
542 number of bits should be comparable with the ones given in table 2
543 and 3 of the NIST SP800-57 document.
544
545 "tls-group-is-kem" (OSSL_CAPABILITY_TLS_GROUP_IS_KEM) <unsigned
546 integer>
547 Boolean flag to describe if the group should be used in key
548 exchange (KEX) mode (0, default) or in key encapsulation method
549 (KEM) mode (1).
550
551 This parameter is optional: if not specified, KEX mode is assumed
552 as the default mode for the group.
553
554 In KEX mode, in a typical Diffie-Hellman fashion, both sides
555 execute keygen then derive against the peer public key. To operate
556 in KEX mode, the group implementation must support the provider
557 functions as described in provider-keyexch(7).
558
559 In KEM mode, the client executes keygen and sends its public key,
560 the server executes encapsulate using the client's public key and
561 sends back the resulting ciphertext, finally the client executes
562 decapsulate to retrieve the same shared secret generated by the
563 server's encapsulate. To operate in KEM mode, the group
564 implementation must support the provider functions as described in
565 provider-kem(7).
566
567 Both in KEX and KEM mode, the resulting shared secret is then used
568 according to the protocol specification.
569
570 "tls-min-tls" (OSSL_CAPABILITY_TLS_GROUP_MIN_TLS) <integer>
571 "tls-max-tls" (OSSL_CAPABILITY_TLS_GROUP_MAX_TLS) <integer>
572 "tls-min-dtls" (OSSL_CAPABILITY_TLS_GROUP_MIN_DTLS) <integer>
573 "tls-max-dtls" (OSSL_CAPABILITY_TLS_GROUP_MAX_DTLS) <integer>
574 These parameters can be used to describe the minimum and maximum
575 TLS and DTLS versions supported by the group. The values equate to
576 the on-the-wire encoding of the various TLS versions. For example
577 TLSv1.3 is 0x0304 (772 decimal), and TLSv1.2 is 0x0303 (771
578 decimal). A 0 indicates that there is no defined minimum or
579 maximum. A -1 indicates that the group should not be used in that
580 protocol.
581
583 The core_obj_create() and core_obj_add_sigid() functions were not
584 thread safe in OpenSSL 3.0.
585
587 This is an example of a simple provider made available as a dynamically
588 loadable module. It implements the fictitious algorithm "FOO" for the
589 fictitious operation "BAR".
590
591 #include <malloc.h>
592 #include <openssl/core.h>
593 #include <openssl/core_dispatch.h>
594
595 /* Errors used in this provider */
596 #define E_MALLOC 1
597
598 static const OSSL_ITEM reasons[] = {
599 { E_MALLOC, "memory allocation failure" }.
600 { 0, NULL } /* Termination */
601 };
602
603 /*
604 * To ensure we get the function signature right, forward declare
605 * them using function types provided by openssl/core_dispatch.h
606 */
607 OSSL_FUNC_bar_newctx_fn foo_newctx;
608 OSSL_FUNC_bar_freectx_fn foo_freectx;
609 OSSL_FUNC_bar_init_fn foo_init;
610 OSSL_FUNC_bar_update_fn foo_update;
611 OSSL_FUNC_bar_final_fn foo_final;
612
613 OSSL_FUNC_provider_query_operation_fn p_query;
614 OSSL_FUNC_provider_get_reason_strings_fn p_reasons;
615 OSSL_FUNC_provider_teardown_fn p_teardown;
616
617 OSSL_provider_init_fn OSSL_provider_init;
618
619 OSSL_FUNC_core_put_error *c_put_error = NULL;
620
621 /* Provider context */
622 struct prov_ctx_st {
623 OSSL_CORE_HANDLE *handle;
624 }
625
626 /* operation context for the algorithm FOO */
627 struct foo_ctx_st {
628 struct prov_ctx_st *provctx;
629 int b;
630 };
631
632 static void *foo_newctx(void *provctx)
633 {
634 struct foo_ctx_st *fooctx = malloc(sizeof(*fooctx));
635
636 if (fooctx != NULL)
637 fooctx->provctx = provctx;
638 else
639 c_put_error(provctx->handle, E_MALLOC, __FILE__, __LINE__);
640 return fooctx;
641 }
642
643 static void foo_freectx(void *fooctx)
644 {
645 free(fooctx);
646 }
647
648 static int foo_init(void *vfooctx)
649 {
650 struct foo_ctx_st *fooctx = vfooctx;
651
652 fooctx->b = 0x33;
653 }
654
655 static int foo_update(void *vfooctx, unsigned char *in, size_t inl)
656 {
657 struct foo_ctx_st *fooctx = vfooctx;
658
659 /* did you expect something serious? */
660 if (inl == 0)
661 return 1;
662 for (; inl-- > 0; in++)
663 *in ^= fooctx->b;
664 return 1;
665 }
666
667 static int foo_final(void *vfooctx)
668 {
669 struct foo_ctx_st *fooctx = vfooctx;
670
671 fooctx->b = 0x66;
672 }
673
674 static const OSSL_DISPATCH foo_fns[] = {
675 { OSSL_FUNC_BAR_NEWCTX, (void (*)(void))foo_newctx },
676 { OSSL_FUNC_BAR_FREECTX, (void (*)(void))foo_freectx },
677 { OSSL_FUNC_BAR_INIT, (void (*)(void))foo_init },
678 { OSSL_FUNC_BAR_UPDATE, (void (*)(void))foo_update },
679 { OSSL_FUNC_BAR_FINAL, (void (*)(void))foo_final },
680 { 0, NULL }
681 };
682
683 static const OSSL_ALGORITHM bars[] = {
684 { "FOO", "provider=chumbawamba", foo_fns },
685 { NULL, NULL, NULL }
686 };
687
688 static const OSSL_ALGORITHM *p_query(void *provctx, int operation_id,
689 int *no_store)
690 {
691 switch (operation_id) {
692 case OSSL_OP_BAR:
693 return bars;
694 }
695 return NULL;
696 }
697
698 static const OSSL_ITEM *p_reasons(void *provctx)
699 {
700 return reasons;
701 }
702
703 static void p_teardown(void *provctx)
704 {
705 free(provctx);
706 }
707
708 static const OSSL_DISPATCH prov_fns[] = {
709 { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))p_teardown },
710 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))p_query },
711 { OSSL_FUNC_PROVIDER_GET_REASON_STRINGS, (void (*)(void))p_reasons },
712 { 0, NULL }
713 };
714
715 int OSSL_provider_init(const OSSL_CORE_HANDLE *handle,
716 const OSSL_DISPATCH *in,
717 const OSSL_DISPATCH **out,
718 void **provctx)
719 {
720 struct prov_ctx_st *pctx = NULL;
721
722 for (; in->function_id != 0; in++)
723 switch (in->function_id) {
724 case OSSL_FUNC_CORE_PUT_ERROR:
725 c_put_error = OSSL_FUNC_core_put_error(in);
726 break;
727 }
728
729 *out = prov_fns;
730
731 if ((pctx = malloc(sizeof(*pctx))) == NULL) {
732 /*
733 * ALEA IACTA EST, if the core retrieves the reason table
734 * regardless, that string will be displayed, otherwise not.
735 */
736 c_put_error(handle, E_MALLOC, __FILE__, __LINE__);
737 return 0;
738 }
739 pctx->handle = handle;
740 return 1;
741 }
742
743 This relies on a few things existing in openssl/core_dispatch.h:
744
745 #define OSSL_OP_BAR 4711
746
747 #define OSSL_FUNC_BAR_NEWCTX 1
748 typedef void *(OSSL_FUNC_bar_newctx_fn)(void *provctx);
749 static ossl_inline OSSL_FUNC_bar_newctx(const OSSL_DISPATCH *opf)
750 { return (OSSL_FUNC_bar_newctx_fn *)opf->function; }
751
752 #define OSSL_FUNC_BAR_FREECTX 2
753 typedef void (OSSL_FUNC_bar_freectx_fn)(void *ctx);
754 static ossl_inline OSSL_FUNC_bar_freectx(const OSSL_DISPATCH *opf)
755 { return (OSSL_FUNC_bar_freectx_fn *)opf->function; }
756
757 #define OSSL_FUNC_BAR_INIT 3
758 typedef void *(OSSL_FUNC_bar_init_fn)(void *ctx);
759 static ossl_inline OSSL_FUNC_bar_init(const OSSL_DISPATCH *opf)
760 { return (OSSL_FUNC_bar_init_fn *)opf->function; }
761
762 #define OSSL_FUNC_BAR_UPDATE 4
763 typedef void *(OSSL_FUNC_bar_update_fn)(void *ctx,
764 unsigned char *in, size_t inl);
765 static ossl_inline OSSL_FUNC_bar_update(const OSSL_DISPATCH *opf)
766 { return (OSSL_FUNC_bar_update_fn *)opf->function; }
767
768 #define OSSL_FUNC_BAR_FINAL 5
769 typedef void *(OSSL_FUNC_bar_final_fn)(void *ctx);
770 static ossl_inline OSSL_FUNC_bar_final(const OSSL_DISPATCH *opf)
771 { return (OSSL_FUNC_bar_final_fn *)opf->function; }
772
774 provider(7)
775
777 The concept of providers and everything surrounding them was introduced
778 in OpenSSL 3.0.
779
781 Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
782
783 Licensed under the Apache License 2.0 (the "License"). You may not use
784 this file except in compliance with the License. You can obtain a copy
785 in the file LICENSE in the source distribution or at
786 <https://www.openssl.org/source/license.html>.
787
788
789
7903.1.1 2023-08-31 PROVIDER-BASE(7ossl)