1=pod 2 3=head1 NAME 4 5provider-base 6- The basic OpenSSL library E<lt>-E<gt> provider functions 7 8=head1 SYNOPSIS 9 10 #include <openssl/core_dispatch.h> 11 12 /* 13 * None of these are actual functions, but are displayed like this for 14 * the function signatures for functions that are offered as function 15 * pointers in OSSL_DISPATCH arrays. 16 */ 17 18 /* Functions offered by libcrypto to the providers */ 19 const OSSL_ITEM *core_gettable_params(const OSSL_CORE_HANDLE *handle); 20 int core_get_params(const OSSL_CORE_HANDLE *handle, OSSL_PARAM params[]); 21 22 typedef void (*OSSL_thread_stop_handler_fn)(void *arg); 23 int core_thread_start(const OSSL_CORE_HANDLE *handle, 24 OSSL_thread_stop_handler_fn handfn, 25 void *arg); 26 27 OPENSSL_CORE_CTX *core_get_libctx(const OSSL_CORE_HANDLE *handle); 28 void core_new_error(const OSSL_CORE_HANDLE *handle); 29 void core_set_error_debug(const OSSL_CORE_HANDLE *handle, 30 const char *file, int line, const char *func); 31 void core_vset_error(const OSSL_CORE_HANDLE *handle, 32 uint32_t reason, const char *fmt, va_list args); 33 34 int core_obj_add_sigid(const OSSL_CORE_HANDLE *prov, const char *sign_name, 35 const char *digest_name, const char *pkey_name); 36 int core_obj_create(const OSSL_CORE_HANDLE *handle, const char *oid, 37 const char *sn, const char *ln); 38 39 /* 40 * Some OpenSSL functionality is directly offered to providers via 41 * dispatch 42 */ 43 void *CRYPTO_malloc(size_t num, const char *file, int line); 44 void *CRYPTO_zalloc(size_t num, const char *file, int line); 45 void CRYPTO_free(void *ptr, const char *file, int line); 46 void CRYPTO_clear_free(void *ptr, size_t num, 47 const char *file, int line); 48 void *CRYPTO_realloc(void *addr, size_t num, 49 const char *file, int line); 50 void *CRYPTO_clear_realloc(void *addr, size_t old_num, size_t num, 51 const char *file, int line); 52 void *CRYPTO_secure_malloc(size_t num, const char *file, int line); 53 void *CRYPTO_secure_zalloc(size_t num, const char *file, int line); 54 void CRYPTO_secure_free(void *ptr, const char *file, int line); 55 void CRYPTO_secure_clear_free(void *ptr, size_t num, 56 const char *file, int line); 57 int CRYPTO_secure_allocated(const void *ptr); 58 void OPENSSL_cleanse(void *ptr, size_t len); 59 60 unsigned char *OPENSSL_hexstr2buf(const char *str, long *buflen); 61 62 OSSL_CORE_BIO *BIO_new_file(const char *filename, const char *mode); 63 OSSL_CORE_BIO *BIO_new_membuf(const void *buf, int len); 64 int BIO_read_ex(OSSL_CORE_BIO *bio, void *data, size_t data_len, 65 size_t *bytes_read); 66 int BIO_write_ex(OSSL_CORE_BIO *bio, const void *data, size_t data_len, 67 size_t *written); 68 int BIO_up_ref(OSSL_CORE_BIO *bio); 69 int BIO_free(OSSL_CORE_BIO *bio); 70 int BIO_vprintf(OSSL_CORE_BIO *bio, const char *format, va_list args); 71 int BIO_vsnprintf(char *buf, size_t n, const char *fmt, va_list args); 72 73 void OSSL_SELF_TEST_set_callback(OSSL_LIB_CTX *libctx, OSSL_CALLBACK *cb, 74 void *cbarg); 75 76 size_t get_entropy(const OSSL_CORE_HANDLE *handle, 77 unsigned char **pout, int entropy, 78 size_t min_len, size_t max_len); 79 size_t get_user_entropy(const OSSL_CORE_HANDLE *handle, 80 unsigned char **pout, int entropy, 81 size_t min_len, size_t max_len); 82 void cleanup_entropy(const OSSL_CORE_HANDLE *handle, 83 unsigned char *buf, size_t len); 84 void cleanup_user_entropy(const OSSL_CORE_HANDLE *handle, 85 unsigned char *buf, size_t len); 86 size_t get_nonce(const OSSL_CORE_HANDLE *handle, 87 unsigned char **pout, size_t min_len, size_t max_len, 88 const void *salt, size_t salt_len); 89 size_t get_user_nonce(const OSSL_CORE_HANDLE *handle, 90 unsigned char **pout, size_t min_len, size_t max_len, 91 const void *salt, size_t salt_len); 92 void cleanup_nonce(const OSSL_CORE_HANDLE *handle, 93 unsigned char *buf, size_t len); 94 void cleanup_user_nonce(const OSSL_CORE_HANDLE *handle, 95 unsigned char *buf, size_t len); 96 97 /* Functions for querying the providers in the application library context */ 98 int provider_register_child_cb(const OSSL_CORE_HANDLE *handle, 99 int (*create_cb)(const OSSL_CORE_HANDLE *provider, 100 void *cbdata), 101 int (*remove_cb)(const OSSL_CORE_HANDLE *provider, 102 void *cbdata), 103 int (*global_props_cb)(const char *props, void *cbdata), 104 void *cbdata); 105 void provider_deregister_child_cb(const OSSL_CORE_HANDLE *handle); 106 const char *provider_name(const OSSL_CORE_HANDLE *prov); 107 void *provider_get0_provider_ctx(const OSSL_CORE_HANDLE *prov); 108 const OSSL_DISPATCH *provider_get0_dispatch(const OSSL_CORE_HANDLE *prov); 109 int provider_up_ref(const OSSL_CORE_HANDLE *prov, int activate); 110 int provider_free(const OSSL_CORE_HANDLE *prov, int deactivate); 111 112 /* Functions offered by the provider to libcrypto */ 113 void provider_teardown(void *provctx); 114 const OSSL_ITEM *provider_gettable_params(void *provctx); 115 int provider_get_params(void *provctx, OSSL_PARAM params[]); 116 const OSSL_ALGORITHM *provider_query_operation(void *provctx, 117 int operation_id, 118 const int *no_store); 119 void provider_unquery_operation(void *provctx, int operation_id, 120 const OSSL_ALGORITHM *algs); 121 const OSSL_ITEM *provider_get_reason_strings(void *provctx); 122 int provider_get_capabilities(void *provctx, const char *capability, 123 OSSL_CALLBACK *cb, void *arg); 124 int provider_self_test(void *provctx); 125 126=head1 DESCRIPTION 127 128All "functions" mentioned here are passed as function pointers between 129F<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays, in the call 130of the provider initialization function. See L<provider(7)/Provider> 131for a description of the initialization function. They are known as "upcalls". 132 133All these "functions" have a corresponding function type definition 134named B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the 135function pointer from a L<OSSL_DISPATCH(3)> element named 136B<OSSL_FUNC_{name}>. 137For example, the "function" core_gettable_params() has these: 138 139 typedef OSSL_PARAM * 140 (OSSL_FUNC_core_gettable_params_fn)(const OSSL_CORE_HANDLE *handle); 141 static ossl_inline OSSL_NAME_core_gettable_params_fn 142 OSSL_FUNC_core_gettable_params(const OSSL_DISPATCH *opf); 143 144L<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as 145macros in L<openssl-core_dispatch.h(7)>, as follows: 146 147For I<in> (the L<OSSL_DISPATCH(3)> array passed from F<libcrypto> to the 148provider): 149 150 core_gettable_params OSSL_FUNC_CORE_GETTABLE_PARAMS 151 core_get_params OSSL_FUNC_CORE_GET_PARAMS 152 core_thread_start OSSL_FUNC_CORE_THREAD_START 153 core_get_libctx OSSL_FUNC_CORE_GET_LIBCTX 154 core_new_error OSSL_FUNC_CORE_NEW_ERROR 155 core_set_error_debug OSSL_FUNC_CORE_SET_ERROR_DEBUG 156 core_vset_error OSSL_FUNC_CORE_VSET_ERROR 157 core_obj_add_sigid OSSL_FUNC_CORE_OBJ_ADD_SIGID 158 core_obj_create OSSL_FUNC_CORE_OBJ_CREATE 159 CRYPTO_malloc OSSL_FUNC_CRYPTO_MALLOC 160 CRYPTO_zalloc OSSL_FUNC_CRYPTO_ZALLOC 161 CRYPTO_free OSSL_FUNC_CRYPTO_FREE 162 CRYPTO_clear_free OSSL_FUNC_CRYPTO_CLEAR_FREE 163 CRYPTO_realloc OSSL_FUNC_CRYPTO_REALLOC 164 CRYPTO_clear_realloc OSSL_FUNC_CRYPTO_CLEAR_REALLOC 165 CRYPTO_secure_malloc OSSL_FUNC_CRYPTO_SECURE_MALLOC 166 CRYPTO_secure_zalloc OSSL_FUNC_CRYPTO_SECURE_ZALLOC 167 CRYPTO_secure_free OSSL_FUNC_CRYPTO_SECURE_FREE 168 CRYPTO_secure_clear_free OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE 169 CRYPTO_secure_allocated OSSL_FUNC_CRYPTO_SECURE_ALLOCATED 170 BIO_new_file OSSL_FUNC_BIO_NEW_FILE 171 BIO_new_mem_buf OSSL_FUNC_BIO_NEW_MEMBUF 172 BIO_read_ex OSSL_FUNC_BIO_READ_EX 173 BIO_write_ex OSSL_FUNC_BIO_WRITE_EX 174 BIO_up_ref OSSL_FUNC_BIO_UP_REF 175 BIO_free OSSL_FUNC_BIO_FREE 176 BIO_vprintf OSSL_FUNC_BIO_VPRINTF 177 BIO_vsnprintf OSSL_FUNC_BIO_VSNPRINTF 178 BIO_puts OSSL_FUNC_BIO_PUTS 179 BIO_gets OSSL_FUNC_BIO_GETS 180 BIO_ctrl OSSL_FUNC_BIO_CTRL 181 OPENSSL_cleanse OSSL_FUNC_OPENSSL_CLEANSE 182 OSSL_SELF_TEST_set_callback OSSL_FUNC_SELF_TEST_CB 183 ossl_rand_get_entropy OSSL_FUNC_GET_ENTROPY 184 ossl_rand_get_user_entropy OSSL_FUNC_GET_USER_ENTROPY 185 ossl_rand_cleanup_entropy OSSL_FUNC_CLEANUP_ENTROPY 186 ossl_rand_cleanup_user_entropy OSSL_FUNC_CLEANUP_USER_ENTROPY 187 ossl_rand_get_nonce OSSL_FUNC_GET_NONCE 188 ossl_rand_get_user_nonce OSSL_FUNC_GET_USER_NONCE 189 ossl_rand_cleanup_nonce OSSL_FUNC_CLEANUP_NONCE 190 ossl_rand_cleanup_user_nonce OSSL_FUNC_CLEANUP_USER_NONCE 191 provider_register_child_cb OSSL_FUNC_PROVIDER_REGISTER_CHILD_CB 192 provider_deregister_child_cb OSSL_FUNC_PROVIDER_DEREGISTER_CHILD_CB 193 provider_name OSSL_FUNC_PROVIDER_NAME 194 provider_get0_provider_ctx OSSL_FUNC_PROVIDER_GET0_PROVIDER_CTX 195 provider_get0_dispatch OSSL_FUNC_PROVIDER_GET0_DISPATCH 196 provider_up_ref OSSL_FUNC_PROVIDER_UP_REF 197 provider_free OSSL_FUNC_PROVIDER_FREE 198 199For I<*out> (the L<OSSL_DISPATCH(3)> array passed from the provider to 200F<libcrypto>): 201 202 provider_teardown OSSL_FUNC_PROVIDER_TEARDOWN 203 provider_gettable_params OSSL_FUNC_PROVIDER_GETTABLE_PARAMS 204 provider_get_params OSSL_FUNC_PROVIDER_GET_PARAMS 205 provider_query_operation OSSL_FUNC_PROVIDER_QUERY_OPERATION 206 provider_unquery_operation OSSL_FUNC_PROVIDER_UNQUERY_OPERATION 207 provider_get_reason_strings OSSL_FUNC_PROVIDER_GET_REASON_STRINGS 208 provider_get_capabilities OSSL_FUNC_PROVIDER_GET_CAPABILITIES 209 provider_self_test OSSL_FUNC_PROVIDER_SELF_TEST 210 211=head2 Core functions 212 213core_gettable_params() returns a constant array of descriptor 214L<OSSL_PARAM(3)>, for parameters that core_get_params() can handle. 215 216core_get_params() retrieves parameters from the core for the given I<handle>. 217See L</Core parameters> below for a description of currently known 218parameters. 219 220The core_thread_start() function informs the core that the provider has stated 221an interest in the current thread. The core will inform the provider when the 222thread eventually stops. It must be passed the I<handle> for this provider, as 223well as a callback I<handfn> which will be called when the thread stops. The 224callback will subsequently be called, with the supplied argument I<arg>, from 225the thread that is stopping and gets passed the provider context as an 226argument. This may be useful to perform thread specific clean up such as 227freeing thread local variables. 228 229core_get_libctx() retrieves the core context in which the library 230object for the current provider is stored, accessible through the I<handle>. 231This function is useful only for built-in providers such as the default 232provider. Never cast this to OSSL_LIB_CTX in a provider that is not 233built-in as the OSSL_LIB_CTX of the library loading the provider might be 234a completely different structure than the OSSL_LIB_CTX of the library the 235provider is linked to. Use L<OSSL_LIB_CTX_new_child(3)> instead to obtain 236a proper library context that is linked to the application library context. 237 238core_new_error(), core_set_error_debug() and core_vset_error() are 239building blocks for reporting an error back to the core, with 240reference to the I<handle>. 241 242=over 4 243 244=item core_new_error() 245 246allocates a new thread specific error record. 247 248This corresponds to the OpenSSL function L<ERR_new(3)>. 249 250=item core_set_error_debug() 251 252sets debugging information in the current thread specific error 253record. 254The debugging information includes the name of the file I<file>, the 255line I<line> and the function name I<func> where the error occurred. 256 257This corresponds to the OpenSSL function L<ERR_set_debug(3)>. 258 259=item core_vset_error() 260 261sets the I<reason> for the error, along with any addition data. 262The I<reason> is a number defined by the provider and used to index 263the reason strings table that's returned by 264provider_get_reason_strings(). 265The additional data is given as a format string I<fmt> and a set of 266arguments I<args>, which are treated in the same manner as with 267BIO_vsnprintf(). 268I<file> and I<line> may also be passed to indicate exactly where the 269error occurred or was reported. 270 271This corresponds to the OpenSSL function L<ERR_vset_error(3)>. 272 273=back 274 275The core_obj_create() function registers a new OID and associated short name 276I<sn> and long name I<ln> for the given I<handle>. It is similar to the OpenSSL 277function L<OBJ_create(3)> except that it returns 1 on success or 0 on failure. 278It will treat as success the case where the OID already exists (even if the 279short name I<sn> or long name I<ln> provided as arguments differ from those 280associated with the existing OID, in which case the new names are not 281associated). 282 283The core_obj_add_sigid() function registers a new composite signature algorithm 284(I<sign_name>) consisting of an underlying signature algorithm (I<pkey_name>) 285and digest algorithm (I<digest_name>) for the given I<handle>. It assumes that 286the OIDs for the composite signature algorithm as well as for the underlying 287signature and digest algorithms are either already known to OpenSSL or have been 288registered via a call to core_obj_create(). It corresponds to the OpenSSL 289function L<OBJ_add_sigid(3)>, except that the objects are identified by name 290rather than a numeric NID. Any name (OID, short name or long name) can be used 291to identify the object. It will treat as success the case where the composite 292signature algorithm already exists (even if registered against a different 293underlying signature or digest algorithm). For I<digest_name>, NULL or an 294empty string is permissible for signature algorithms that do not need a digest 295to operate correctly. The function returns 1 on success or 0 on failure. 296 297CRYPTO_malloc(), CRYPTO_zalloc(), CRYPTO_free(), CRYPTO_clear_free(), 298CRYPTO_realloc(), CRYPTO_clear_realloc(), CRYPTO_secure_malloc(), 299CRYPTO_secure_zalloc(), CRYPTO_secure_free(), 300CRYPTO_secure_clear_free(), CRYPTO_secure_allocated(), 301BIO_new_file(), BIO_new_mem_buf(), BIO_read_ex(), BIO_write_ex(), BIO_up_ref(), 302BIO_free(), BIO_vprintf(), BIO_vsnprintf(), BIO_gets(), BIO_puts(), 303BIO_ctrl(), OPENSSL_cleanse() and 304OPENSSL_hexstr2buf() correspond exactly to the public functions with 305the same name. As a matter of fact, the pointers in the L<OSSL_DISPATCH(3)> 306array are typically direct pointers to those public functions. Note that the BIO 307functions take an B<OSSL_CORE_BIO> type rather than the standard B<BIO> 308type. This is to ensure that a provider does not mix BIOs from the core 309with BIOs used on the provider side (the two are not compatible). 310OSSL_SELF_TEST_set_callback() is used to set an optional callback that can be 311passed into a provider. This may be ignored by a provider. 312 313get_entropy() retrieves seeding material from the operating system. 314The seeding material will have at least I<entropy> bytes of randomness and the 315output will have at least I<min_len> and at most I<max_len> bytes. 316The buffer address is stored in I<*pout> and the buffer length is 317returned to the caller. On error, zero is returned. 318 319get_user_entropy() is the same as get_entropy() except that it will 320attempt to gather seed material via the seed source specified by a call to 321L<RAND_set_seed_source_type(3)> or via L<config(5)/Random Configuration>. 322 323cleanup_entropy() is used to clean up and free the buffer returned by 324get_entropy(). The entropy pointer returned by get_entropy() 325is passed in B<buf> and its length in B<len>. 326 327cleanup_user_entropy() is used to clean up and free the buffer returned by 328get_user_entropy(). The entropy pointer returned by get_user_entropy() 329is passed in B<buf> and its length in B<len>. 330 331get_nonce() retrieves a nonce using the passed I<salt> parameter 332of length I<salt_len> and operating system specific information. 333The I<salt> should contain uniquely identifying information and this is 334included, in an unspecified manner, as part of the output. 335The output is stored in a buffer which contains at least I<min_len> and at 336most I<max_len> bytes. The buffer address is stored in I<*pout> and the 337buffer length returned to the caller. On error, zero is returned. 338 339get_user_nonce() is the same as get_nonce() except that it will attempt 340to gather seed material via the seed source specified by a call to 341L<RAND_set_seed_source_type(3)> or via L<config(5)/Random Configuration>. 342 343cleanup_nonce() is used to clean up and free the buffer returned by 344get_nonce(). The nonce pointer returned by get_nonce() 345is passed in B<buf> and its length in B<len>. 346 347cleanup_user_nonce() is used to clean up and free the buffer returned by 348get_user_nonce(). The nonce pointer returned by get_user_nonce() 349is passed in B<buf> and its length in B<len>. 350 351provider_register_child_cb() registers callbacks for being informed about the 352loading and unloading of providers in the application's library context. 353I<handle> is this provider's handle and I<cbdata> is this provider's data 354that will be passed back to the callbacks. It returns 1 on success or 0 355otherwise. These callbacks may be called while holding locks in libcrypto. In 356order to avoid deadlocks the callback implementation must not be long running 357and must not call other OpenSSL API functions or upcalls. 358 359I<create_cb> is a callback that will be called when a new provider is loaded 360into the application's library context. It is also called for any providers that 361are already loaded at the point that this callback is registered. The callback 362is passed the handle being used for the new provider being loadded and this 363provider's data in I<cbdata>. It should return 1 on success or 0 on failure. 364 365I<remove_cb> is a callback that will be called when a new provider is unloaded 366from the application's library context. It is passed the handle being used for 367the provider being unloaded and this provider's data in I<cbdata>. It should 368return 1 on success or 0 on failure. 369 370I<global_props_cb> is a callback that will be called when the global properties 371from the parent library context are changed. It should return 1 on success 372or 0 on failure. 373 374provider_deregister_child_cb() unregisters callbacks previously registered via 375provider_register_child_cb(). If provider_register_child_cb() has been called 376then provider_deregister_child_cb() should be called at or before the point that 377this provider's teardown function is called. 378 379provider_name() returns a string giving the name of the provider identified by 380I<handle>. 381 382provider_get0_provider_ctx() returns the provider context that is associated 383with the provider identified by I<prov>. 384 385provider_get0_dispatch() gets the dispatch table registered by the provider 386identified by I<prov> when it initialised. 387 388provider_up_ref() increments the reference count on the provider I<prov>. If 389I<activate> is nonzero then the provider is also loaded if it is not already 390loaded. It returns 1 on success or 0 on failure. 391 392provider_free() decrements the reference count on the provider I<prov>. If 393I<deactivate> is nonzero then the provider is also unloaded if it is not 394already loaded. It returns 1 on success or 0 on failure. 395 396=head2 Provider functions 397 398provider_teardown() is called when a provider is shut down and removed 399from the core's provider store. 400It must free the passed I<provctx>. 401 402provider_gettable_params() should return a constant array of 403descriptor L<OSSL_PARAM(3)>, for parameters that provider_get_params() 404can handle. 405 406provider_get_params() should process the L<OSSL_PARAM(3)> array 407I<params>, setting the values of the parameters it understands. 408 409provider_query_operation() should return a constant L<OSSL_ALGORITHM(3)> 410that corresponds to the given I<operation_id>. 411It should indicate if the core may store a reference to this array by 412setting I<*no_store> to 0 (core may store a reference) or 1 (core may 413not store a reference). 414 415provider_unquery_operation() informs the provider that the result of a 416provider_query_operation() is no longer directly required and that the function 417pointers have been copied. The I<operation_id> should match that passed to 418provider_query_operation() and I<algs> should be its return value. 419 420provider_get_reason_strings() should return a constant L<OSSL_ITEM(3)> 421array that provides reason strings for reason codes the provider may 422use when reporting errors using core_put_error(). 423 424The provider_get_capabilities() function should call the callback I<cb> passing 425it a set of L<OSSL_PARAM(3)>s and the caller supplied argument I<arg>. The 426L<OSSL_PARAM(3)>s should provide details about the capability with the name given 427in the I<capability> argument relevant for the provider context I<provctx>. If a 428provider supports multiple capabilities with the given name then it may call the 429callback multiple times (one for each capability). Capabilities can be useful for 430describing the services that a provider can offer. For further details see the 431L</CAPABILITIES> section below. It should return 1 on success or 0 on error. 432 433The provider_self_test() function should perform known answer tests on a subset 434of the algorithms that it uses, and may also verify the integrity of the 435provider module. It should return 1 on success or 0 on error. It will return 1 436if this function is not used. 437 438None of these functions are mandatory, but a provider is fairly 439useless without at least provider_query_operation(), and 440provider_gettable_params() is fairly useless if not accompanied by 441provider_get_params(). 442 443=head2 Provider parameters 444 445provider_get_params() can return the following provider parameters to the core: 446 447=over 4 448 449=item "name" (B<OSSL_PROV_PARAM_NAME>) <UTF8 ptr> 450 451This points to a string that should give a unique name for the provider. 452 453=item "version" (B<OSSL_PROV_PARAM_VERSION>) <UTF8 ptr> 454 455This points to a string that is a version number associated with this provider. 456OpenSSL in-built providers use OPENSSL_VERSION_STR, but this may be different 457for any third party provider. This string is for informational purposes only. 458 459=item "buildinfo" (B<OSSL_PROV_PARAM_BUILDINFO>) <UTF8 ptr> 460 461This points to a string that is a build information associated with this provider. 462OpenSSL in-built providers use OPENSSL_FULL_VERSION_STR, but this may be 463different for any third party provider. 464 465=item "status" (B<OSSL_PROV_PARAM_STATUS>) <unsigned integer> 466 467This returns 0 if the provider has entered an error state, otherwise it returns 4681. 469 470=back 471 472provider_gettable_params() should return the above parameters. 473 474 475=head2 Core parameters 476 477core_get_params() can retrieve the following core parameters for each provider: 478 479=over 4 480 481=item "openssl-version" (B<OSSL_PROV_PARAM_CORE_VERSION>) <UTF8 string ptr> 482 483This points to the OpenSSL libraries' full version string, i.e. the string 484expanded from the macro B<OPENSSL_VERSION_STR>. 485 486=item "provider-name" (B<OSSL_PROV_PARAM_CORE_PROV_NAME>) <UTF8 string ptr> 487 488This points to the OpenSSL libraries' idea of what the calling provider is named. 489 490=item "module-filename" (B<OSSL_PROV_PARAM_CORE_MODULE_FILENAME>) <UTF8 string ptr> 491 492This points to a string containing the full filename of the providers 493module file. 494 495=back 496 497Additionally, provider specific configuration parameters from the 498config file are available, in dotted name form. 499The dotted name form is a concatenation of section names and final 500config command name separated by periods. 501 502For example, let's say we have the following config example: 503 504 config_diagnostics = 1 505 openssl_conf = openssl_init 506 507 [openssl_init] 508 providers = providers_sect 509 510 [providers_sect] 511 foo = foo_sect 512 513 [foo_sect] 514 activate = 1 515 data1 = 2 516 data2 = str 517 more = foo_more 518 519 [foo_more] 520 data3 = foo,bar 521 522The provider will have these additional parameters available: 523 524=over 4 525 526=item "activate" 527 528pointing at the string "1" 529 530=item "data1" 531 532pointing at the string "2" 533 534=item "data2" 535 536pointing at the string "str" 537 538=item "more.data3" 539 540pointing at the string "foo,bar" 541 542=back 543 544For more information on handling parameters, see L<OSSL_PARAM(3)> as 545L<OSSL_PARAM_int(3)>. 546 547=head1 CAPABILITIES 548 549Capabilities describe some of the services that a provider can offer. 550Applications can query the capabilities to discover those services. 551 552=head3 "TLS-GROUP" Capability 553 554The "TLS-GROUP" capability can be queried by libssl to discover the list of 555TLS groups that a provider can support. Each group supported can be used for 556I<key exchange> (KEX) or I<key encapsulation method> (KEM) during a TLS 557handshake. 558TLS clients can advertise the list of TLS groups they support in the 559supported_groups extension, and TLS servers can select a group from the offered 560list that they also support. In this way a provider can add to the list of 561groups that libssl already supports with additional ones. 562 563Each TLS group that a provider supports should be described via the callback 564passed in through the provider_get_capabilities function. Each group should have 565the following details supplied (all are mandatory, except 566B<OSSL_CAPABILITY_TLS_GROUP_IS_KEM>): 567 568=over 4 569 570=item "tls-group-name" (B<OSSL_CAPABILITY_TLS_GROUP_NAME>) <UTF8 string> 571 572The name of the group as given in the IANA TLS Supported Groups registry 573L<https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8>. 574 575=item "tls-group-name-internal" (B<OSSL_CAPABILITY_TLS_GROUP_NAME_INTERNAL>) <UTF8 string> 576 577The name of the group as known by the provider. This could be the same as the 578"tls-group-name", but does not have to be. 579 580=item "tls-group-id" (B<OSSL_CAPABILITY_TLS_GROUP_ID>) <unsigned integer> 581 582The TLS group id value as given in the IANA TLS Supported Groups registry. 583 584=item "tls-group-alg" (B<OSSL_CAPABILITY_TLS_GROUP_ALG>) <UTF8 string> 585 586The name of a Key Management algorithm that the provider offers and that should 587be used with this group. Keys created should be able to support I<key exchange> 588or I<key encapsulation method> (KEM), as implied by the optional 589B<OSSL_CAPABILITY_TLS_GROUP_IS_KEM> flag. 590The algorithm must support key and parameter generation as well as the 591key/parameter generation parameter, B<OSSL_PKEY_PARAM_GROUP_NAME>. The group 592name given via "tls-group-name-internal" above will be passed via 593B<OSSL_PKEY_PARAM_GROUP_NAME> when libssl wishes to generate keys/parameters. 594 595=item "tls-group-sec-bits" (B<OSSL_CAPABILITY_TLS_GROUP_SECURITY_BITS>) <unsigned integer> 596 597The number of bits of security offered by keys in this group. The number of bits 598should be comparable with the ones given in table 2 and 3 of the NIST SP800-57 599document. 600 601=item "tls-group-is-kem" (B<OSSL_CAPABILITY_TLS_GROUP_IS_KEM>) <unsigned integer> 602 603Boolean flag to describe if the group should be used in I<key exchange> (KEX) 604mode (0, default) or in I<key encapsulation method> (KEM) mode (1). 605 606This parameter is optional: if not specified, KEX mode is assumed as the default 607mode for the group. 608 609In KEX mode, in a typical Diffie-Hellman fashion, both sides execute I<keygen> 610then I<derive> against the peer public key. To operate in KEX mode, the group 611implementation must support the provider functions as described in 612L<provider-keyexch(7)>. 613 614In KEM mode, the client executes I<keygen> and sends its public key, the server 615executes I<encapsulate> using the client's public key and sends back the 616resulting I<ciphertext>, finally the client executes I<decapsulate> to retrieve 617the same I<shared secret> generated by the server's I<encapsulate>. To operate 618in KEM mode, the group implementation must support the provider functions as 619described in L<provider-kem(7)>. 620 621Both in KEX and KEM mode, the resulting I<shared secret> is then used according 622to the protocol specification. 623 624=item "tls-min-tls" (B<OSSL_CAPABILITY_TLS_GROUP_MIN_TLS>) <integer> 625 626=item "tls-max-tls" (B<OSSL_CAPABILITY_TLS_GROUP_MAX_TLS>) <integer> 627 628=item "tls-min-dtls" (B<OSSL_CAPABILITY_TLS_GROUP_MIN_DTLS>) <integer> 629 630=item "tls-max-dtls" (B<OSSL_CAPABILITY_TLS_GROUP_MAX_DTLS>) <integer> 631 632These parameters can be used to describe the minimum and maximum TLS and DTLS 633versions supported by the group. The values equate to the on-the-wire encoding 634of the various TLS versions. For example TLSv1.3 is 0x0304 (772 decimal), and 635TLSv1.2 is 0x0303 (771 decimal). A 0 indicates that there is no defined minimum 636or maximum. A -1 indicates that the group should not be used in that protocol. 637 638=back 639 640=head3 "TLS-SIGALG" Capability 641 642The "TLS-SIGALG" capability can be queried by libssl to discover the list of 643TLS signature algorithms that a provider can support. Each signature supported 644can be used for client- or server-authentication in addition to the built-in 645signature algorithms. 646TLS1.3 clients can advertise the list of TLS signature algorithms they support 647in the signature_algorithms extension, and TLS servers can select an algorithm 648from the offered list that they also support. In this way a provider can add 649to the list of signature algorithms that libssl already supports with 650additional ones. 651 652Each TLS signature algorithm that a provider supports should be described via 653the callback passed in through the provider_get_capabilities function. Each 654algorithm can have the following details supplied: 655 656=over 4 657 658=item "iana-name" (B<OSSL_CAPABILITY_TLS_SIGALG_IANA_NAME>) <UTF8 string> 659 660The name of the signature algorithm as given in the IANA TLS Signature Scheme 661registry as "Description": 662L<https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-signaturescheme>. 663This value must be supplied. 664 665=item "iana-code-point" (B<OSSL_CAPABILITY_TLS_SIGALG_CODE_POINT>) <unsigned integer> 666 667The TLS algorithm ID value as given in the IANA TLS SignatureScheme registry. 668This value must be supplied. 669 670=item "sigalg-name" (B<OSSL_CAPABILITY_TLS_SIGALG_NAME>) <UTF8 string> 671 672A name for the full (possibly composite hash-and-signature) signature 673algorithm. 674The provider may, but is not obligated to, provide a signature implementation 675with this name; if it doesn't, this is assumed to be a composite of a pure 676signature algorithm and a hash algorithm, which must be given with the 677parameters "sig-name" and "hash-name". 678This value must be supplied. 679 680=item "sigalg-oid" (B<OSSL_CAPABILITY_TLS_SIGALG_OID>) <UTF8 string> 681 682The OID of the "sigalg-name" algorithm in canonical numeric text form. If 683this parameter is given, OBJ_create() will be used to create an OBJ and 684a NID for this OID, using the "sigalg-name" parameter for its (short) name. 685Otherwise, it's assumed to already exist in the object database, possibly 686done by the provider with the core_obj_create() upcall. 687This value is optional. 688 689=item "sig-name" (B<OSSL_CAPABILITY_TLS_SIGALG_SIG_NAME>) <UTF8 string> 690 691The name of the pure signature algorithm that is part of a composite 692"sigalg-name". If "sigalg-name" is implemented by the provider, this 693parameter is redundant and must not be given. 694This value is optional. 695 696=item "sig-oid" (B<OSSL_CAPABILITY_TLS_SIGALG_SIG_OID>) <UTF8 string> 697 698The OID of the "sig-name" algorithm in canonical numeric text form. If 699this parameter is given, OBJ_create() will be used to create an OBJ and 700a NID for this OID, using the "sig-name" parameter for its (short) name. 701Otherwise, it is assumed to already exist in the object database. This 702can be done by the provider using the core_obj_create() upcall. 703This value is optional. 704 705=item "hash-name" (B<OSSL_CAPABILITY_TLS_SIGALG_HASH_NAME>) <UTF8 string> 706 707The name of the hash algorithm that is part of a composite "sigalg-name". 708If "sigalg-name" is implemented by the provider, this parameter is redundant 709and must not be given. 710This value is optional. 711 712=item "hash-oid" (B<OSSL_CAPABILITY_TLS_SIGALG_HASH_OID>) <UTF8 string> 713 714The OID of the "hash-name" algorithm in canonical numeric text form. If 715this parameter is given, OBJ_create() will be used to create an OBJ and 716a NID for this OID, using the "hash-name" parameter for its (short) name. 717Otherwise, it's assumed to already exist in the object database, possibly 718done by the provider with the core_obj_create() upcall. 719This value is optional. 720 721=item "key-type" (B<OSSL_CAPABILITY_TLS_SIGALG_KEYTYPE>) <UTF8 string> 722 723The key type of the public key of applicable certificates. If this parameter 724isn't present, it's assumed to be the same as "sig-name" if that's present, 725otherwise "sigalg-name". 726This value is optional. 727 728=item "key-type-oid" (B<OSSL_CAPABILITY_TLS_SIGALG_KEYTYPE_OID>) <UTF8 string> 729 730The OID of the "key-type" in canonical numeric text form. If 731this parameter is given, OBJ_create() will be used to create an OBJ and 732a NID for this OID, using the "key-type" parameter for its (short) name. 733Otherwise, it's assumed to already exist in the object database, possibly 734done by the provider with the core_obj_create() upcall. 735This value is optional. 736 737=item "sec-bits" (B<OSSL_CAPABILITY_TLS_SIGALG_SECURITY_BITS>) <unsigned integer> 738 739The number of bits of security offered by keys of this algorithm. The number 740of bits should be comparable with the ones given in table 2 and 3 of the NIST 741SP800-57 document. This number is used to determine the security strength of 742the algorithm if no digest algorithm has been registered that otherwise 743defines the security strength. If the signature algorithm implements its own 744digest internally, this value needs to be set to properly reflect the overall 745security strength. 746This value must be supplied. 747 748=item "tls-min-tls" (B<OSSL_CAPABILITY_TLS_SIGALG_MIN_TLS>) <integer> 749 750=item "tls-max-tls" (B<OSSL_CAPABILITY_TLS_SIGALG_MAX_TLS>) <integer> 751 752These parameters can be used to describe the minimum and maximum TLS 753versions supported by the signature algorithm. The values equate to the 754on-the-wire encoding of the various TLS versions. For example TLSv1.3 is 7550x0304 (772 decimal), and TLSv1.2 is 0x0303 (771 decimal). A 0 indicates that 756there is no defined minimum or maximum. A -1 indicates that the signature 757algorithm should not be used in that protocol. 758Presently values representing anything other than TLS1.3 mean that the 759complete algorithm is ignored. 760 761=back 762 763=head1 NOTES 764 765The core_obj_create() and core_obj_add_sigid() functions were not thread safe 766in OpenSSL 3.0. 767 768=head1 EXAMPLES 769 770This is an example of a simple provider made available as a 771dynamically loadable module. 772It implements the fictitious algorithm C<FOO> for the fictitious 773operation C<BAR>. 774 775 #include <malloc.h> 776 #include <openssl/core.h> 777 #include <openssl/core_dispatch.h> 778 779 /* Errors used in this provider */ 780 #define E_MALLOC 1 781 782 static const OSSL_ITEM reasons[] = { 783 { E_MALLOC, "memory allocation failure" }. 784 OSSL_DISPATCH_END 785 }; 786 787 /* 788 * To ensure we get the function signature right, forward declare 789 * them using function types provided by openssl/core_dispatch.h 790 */ 791 OSSL_FUNC_bar_newctx_fn foo_newctx; 792 OSSL_FUNC_bar_freectx_fn foo_freectx; 793 OSSL_FUNC_bar_init_fn foo_init; 794 OSSL_FUNC_bar_update_fn foo_update; 795 OSSL_FUNC_bar_final_fn foo_final; 796 797 OSSL_FUNC_provider_query_operation_fn p_query; 798 OSSL_FUNC_provider_get_reason_strings_fn p_reasons; 799 OSSL_FUNC_provider_teardown_fn p_teardown; 800 801 OSSL_provider_init_fn OSSL_provider_init; 802 803 OSSL_FUNC_core_put_error *c_put_error = NULL; 804 805 /* Provider context */ 806 struct prov_ctx_st { 807 OSSL_CORE_HANDLE *handle; 808 } 809 810 /* operation context for the algorithm FOO */ 811 struct foo_ctx_st { 812 struct prov_ctx_st *provctx; 813 int b; 814 }; 815 816 static void *foo_newctx(void *provctx) 817 { 818 struct foo_ctx_st *fooctx = malloc(sizeof(*fooctx)); 819 820 if (fooctx != NULL) 821 fooctx->provctx = provctx; 822 else 823 c_put_error(provctx->handle, E_MALLOC, __FILE__, __LINE__); 824 return fooctx; 825 } 826 827 static void foo_freectx(void *fooctx) 828 { 829 free(fooctx); 830 } 831 832 static int foo_init(void *vfooctx) 833 { 834 struct foo_ctx_st *fooctx = vfooctx; 835 836 fooctx->b = 0x33; 837 } 838 839 static int foo_update(void *vfooctx, unsigned char *in, size_t inl) 840 { 841 struct foo_ctx_st *fooctx = vfooctx; 842 843 /* did you expect something serious? */ 844 if (inl == 0) 845 return 1; 846 for (; inl-- > 0; in++) 847 *in ^= fooctx->b; 848 return 1; 849 } 850 851 static int foo_final(void *vfooctx) 852 { 853 struct foo_ctx_st *fooctx = vfooctx; 854 855 fooctx->b = 0x66; 856 } 857 858 static const OSSL_DISPATCH foo_fns[] = { 859 { OSSL_FUNC_BAR_NEWCTX, (void (*)(void))foo_newctx }, 860 { OSSL_FUNC_BAR_FREECTX, (void (*)(void))foo_freectx }, 861 { OSSL_FUNC_BAR_INIT, (void (*)(void))foo_init }, 862 { OSSL_FUNC_BAR_UPDATE, (void (*)(void))foo_update }, 863 { OSSL_FUNC_BAR_FINAL, (void (*)(void))foo_final }, 864 OSSL_DISPATCH_END 865 }; 866 867 static const OSSL_ALGORITHM bars[] = { 868 { "FOO", "provider=chumbawamba", foo_fns }, 869 { NULL, NULL, NULL } 870 }; 871 872 static const OSSL_ALGORITHM *p_query(void *provctx, int operation_id, 873 int *no_store) 874 { 875 switch (operation_id) { 876 case OSSL_OP_BAR: 877 return bars; 878 } 879 return NULL; 880 } 881 882 static const OSSL_ITEM *p_reasons(void *provctx) 883 { 884 return reasons; 885 } 886 887 static void p_teardown(void *provctx) 888 { 889 free(provctx); 890 } 891 892 static const OSSL_DISPATCH prov_fns[] = { 893 { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))p_teardown }, 894 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))p_query }, 895 { OSSL_FUNC_PROVIDER_GET_REASON_STRINGS, (void (*)(void))p_reasons }, 896 OSSL_DISPATCH_END 897 }; 898 899 int OSSL_provider_init(const OSSL_CORE_HANDLE *handle, 900 const OSSL_DISPATCH *in, 901 const OSSL_DISPATCH **out, 902 void **provctx) 903 { 904 struct prov_ctx_st *pctx = NULL; 905 906 for (; in->function_id != 0; in++) 907 switch (in->function_id) { 908 case OSSL_FUNC_CORE_PUT_ERROR: 909 c_put_error = OSSL_FUNC_core_put_error(in); 910 break; 911 } 912 913 *out = prov_fns; 914 915 if ((pctx = malloc(sizeof(*pctx))) == NULL) { 916 /* 917 * ALEA IACTA EST, if the core retrieves the reason table 918 * regardless, that string will be displayed, otherwise not. 919 */ 920 c_put_error(handle, E_MALLOC, __FILE__, __LINE__); 921 return 0; 922 } 923 pctx->handle = handle; 924 return 1; 925 } 926 927This relies on a few things existing in F<openssl/core_dispatch.h>: 928 929 #define OSSL_OP_BAR 4711 930 931 #define OSSL_FUNC_BAR_NEWCTX 1 932 typedef void *(OSSL_FUNC_bar_newctx_fn)(void *provctx); 933 static ossl_inline OSSL_FUNC_bar_newctx(const OSSL_DISPATCH *opf) 934 { return (OSSL_FUNC_bar_newctx_fn *)opf->function; } 935 936 #define OSSL_FUNC_BAR_FREECTX 2 937 typedef void (OSSL_FUNC_bar_freectx_fn)(void *ctx); 938 static ossl_inline OSSL_FUNC_bar_freectx(const OSSL_DISPATCH *opf) 939 { return (OSSL_FUNC_bar_freectx_fn *)opf->function; } 940 941 #define OSSL_FUNC_BAR_INIT 3 942 typedef void *(OSSL_FUNC_bar_init_fn)(void *ctx); 943 static ossl_inline OSSL_FUNC_bar_init(const OSSL_DISPATCH *opf) 944 { return (OSSL_FUNC_bar_init_fn *)opf->function; } 945 946 #define OSSL_FUNC_BAR_UPDATE 4 947 typedef void *(OSSL_FUNC_bar_update_fn)(void *ctx, 948 unsigned char *in, size_t inl); 949 static ossl_inline OSSL_FUNC_bar_update(const OSSL_DISPATCH *opf) 950 { return (OSSL_FUNC_bar_update_fn *)opf->function; } 951 952 #define OSSL_FUNC_BAR_FINAL 5 953 typedef void *(OSSL_FUNC_bar_final_fn)(void *ctx); 954 static ossl_inline OSSL_FUNC_bar_final(const OSSL_DISPATCH *opf) 955 { return (OSSL_FUNC_bar_final_fn *)opf->function; } 956 957=head1 SEE ALSO 958 959L<provider(7)> 960 961=head1 HISTORY 962 963The concept of providers and everything surrounding them was 964introduced in OpenSSL 3.0. 965 966=head1 COPYRIGHT 967 968Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved. 969 970Licensed under the Apache License 2.0 (the "License"). You may not use 971this file except in compliance with the License. You can obtain a copy 972in the file LICENSE in the source distribution or at 973L<https://www.openssl.org/source/license.html>. 974 975=cut 976