Home | History | Annotate | Line # | Download | only in man3
      1 =pod
      2 
      3 =head1 NAME
      4 
      5 ossl_provider_find, ossl_provider_new, ossl_provider_up_ref,
      6 ossl_provider_free, ossl_provider_set_module_path,
      7 ossl_provider_set_child, ossl_provider_get_parent,
      8 ossl_provider_up_ref_parent, ossl_provider_free_parent,
      9 ossl_provider_default_props_update, ossl_provider_get0_dispatch,
     10 ossl_provider_init_as_child, ossl_provider_deinit_child,
     11 ossl_provider_activate, ossl_provider_deactivate, ossl_provider_add_to_store,
     12 ossl_provider_ctx,
     13 ossl_provider_doall_activated,
     14 ossl_provider_name, ossl_provider_dso,
     15 ossl_provider_module_name, ossl_provider_module_path,
     16 ossl_provider_libctx,
     17 ossl_provider_teardown, ossl_provider_gettable_params,
     18 ossl_provider_get_params,
     19 ossl_provider_query_operation, ossl_provider_unquery_operation,
     20 ossl_provider_random_bytes,
     21 ossl_provider_set_operation_bit, ossl_provider_test_operation_bit,
     22 ossl_provider_get_capabilities
     23 - internal provider routines
     24 
     25 =head1 SYNOPSIS
     26 
     27  #include "internal/provider.h"
     28 
     29  OSSL_PROVIDER *ossl_provider_find(OSSL_LIB_CTX *libctx, const char *name,
     30                                    int noconfig);
     31  OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name,
     32                                   ossl_provider_init_fn *init_function
     33                                   int noconfig);
     34  int ossl_provider_up_ref(OSSL_PROVIDER *prov);
     35  void ossl_provider_free(OSSL_PROVIDER *prov);
     36 
     37  /* Setters */
     38  int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *path);
     39 
     40  /* Child Providers */
     41  int ossl_provider_set_child(OSSL_PROVIDER *prov,
     42                              const OSSL_CORE_HANDLE *handle);
     43  const OSSL_CORE_HANDLE *ossl_provider_get_parent(OSSL_PROVIDER *prov);
     44  int ossl_provider_up_ref_parent(OSSL_PROVIDER *prov, int activate);
     45  int ossl_provider_free_parent(OSSL_PROVIDER *prov, int deactivate);
     46  int ossl_provider_default_props_update(OSSL_LIB_CTX *libctx,
     47                                         const char *props);
     48 
     49  /*
     50   * Activate the Provider
     51   * If the Provider is a module, the module will be loaded
     52   */
     53  int ossl_provider_activate(OSSL_PROVIDER *prov, int upcalls, int aschild);
     54  int ossl_provider_deactivate(OSSL_PROVIDER *prov, int removechildren);
     55  int ossl_provider_add_to_store(OSSL_PROVIDER *prov, OSSL_PROVIDER **actualprov,
     56                                 int retain_fallbacks);
     57 
     58  /* Return pointer to the provider's context */
     59  void *ossl_provider_ctx(const OSSL_PROVIDER *prov);
     60 
     61  const OSSL_DISPATCH *ossl_provider_get0_dispatch(const OSSL_PROVIDER *prov);
     62 
     63  /* Iterate over all loaded providers */
     64  int ossl_provider_doall_activated(OSSL_LIB_CTX *,
     65                                    int (*cb)(OSSL_PROVIDER *provider,
     66                                              void *cbdata),
     67                                    void *cbdata);
     68 
     69  /* Getters for other library functions */
     70  const char *ossl_provider_name(OSSL_PROVIDER *prov);
     71  const DSO *ossl_provider_dso(OSSL_PROVIDER *prov);
     72  const char *ossl_provider_module_name(OSSL_PROVIDER *prov);
     73  const char *ossl_provider_module_path(OSSL_PROVIDER *prov);
     74  OSSL_LIB_CTX *ossl_provider_libctx(const OSSL_PROVIDER *prov);
     75 
     76  /* Thin wrappers around calls to the provider */
     77  void ossl_provider_teardown(const OSSL_PROVIDER *prov);
     78  const OSSL_PARAM *ossl_provider_gettable_params(const OSSL_PROVIDER *prov);
     79  int ossl_provider_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]);
     80  int ossl_provider_get_capabilities(const OSSL_PROVIDER *prov,
     81                                    const char *capability,
     82                                    OSSL_CALLBACK *cb,
     83                                    void *arg);
     84  const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
     85                                                      int operation_id,
     86                                                      int *no_cache);
     87  void ossl_provider_unquery_operation(const OSSL_PROVIDER *prov,
     88                                       int operation_id,
     89                                       const OSSL_ALGORITHM *algs);
     90  int ossl_provider_random_bytes(const OSSL_PROVIDER *prov, int which,
     91                                 void *buf, size_t n, unsigned int strength);
     92 
     93  int ossl_provider_set_operation_bit(OSSL_PROVIDER *provider, size_t bitnum);
     94  int ossl_provider_test_operation_bit(OSSL_PROVIDER *provider, size_t bitnum,
     95                                       int *result);
     96 
     97  int ossl_provider_init_as_child(OSSL_LIB_CTX *ctx,
     98                                  const OSSL_CORE_HANDLE *handle,
     99                                  const OSSL_DISPATCH *in);
    100  void ossl_provider_deinit_child(OSSL_LIB_CTX *ctx);
    101 
    102 =head1 DESCRIPTION
    103 
    104 I<OSSL_PROVIDER> is a type that holds all the necessary information
    105 to handle a provider, regardless of if it's built in to the
    106 application or the OpenSSL libraries, or if it's a loadable provider
    107 module.
    108 Instances of this type are commonly referred to as "provider objects".
    109 
    110 A provider object is always stored in a set of provider objects
    111 in the library context.
    112 
    113 Provider objects are reference counted.
    114 
    115 Provider objects are initially inactive, i.e. they are only recorded
    116 in the store, but are not used.
    117 They are activated with the first call to ossl_provider_activate(),
    118 and are deactivated with the last call to ossl_provider_deactivate().
    119 Activation affects a separate counter.
    120 
    121 =head2 Functions
    122 
    123 ossl_provider_find() finds an existing provider object in the provider
    124 object store by I<name>.
    125 The config file will be automatically loaded unless I<noconfig> is set.
    126 Typically I<noconfig> should be 0.
    127 We set I<noconfig> to 1 only when calling these functions while processing a
    128 config file in order to avoid recursively attempting to load the file.
    129 The provider object it finds has its reference count incremented.
    130 
    131 ossl_provider_new() creates a new provider object named I<name> and
    132 stores it in the provider object store, unless there already is one
    133 there with the same name.
    134 If there already is one with the same name, it's returned with its
    135 reference count incremented.
    136 The config file will be automatically loaded unless I<noconfig> is set.
    137 Typically I<noconfig> should be 0.
    138 We set I<noconfig> to 1 only when calling these functions while processing a
    139 config file in order to avoid recursively attempting to load the file.
    140 The reference count of a newly created provider object will always
    141 be 2; one for being added to the store, and one for the returned
    142 reference.
    143 If I<init_function> is NULL, the provider is assumed to be a
    144 dynamically loadable module, with the symbol B<OSSL_provider_init> as
    145 its initialisation function.
    146 If I<init_function> isn't NULL, the provider is assumed to be built
    147 in, with I<init_function> being the pointer to its initialisation
    148 function.
    149 For further description of the initialisation function, see the
    150 description of ossl_provider_activate() below.
    151 
    152 ossl_provider_up_ref() increments the provider object I<prov>'s
    153 reference count.
    154 
    155 ossl_provider_free() decrements the provider object I<prov>'s
    156 reference count; when it drops to zero, the provider object is assumed
    157 to have fallen out of use and will be deinitialized (its I<teardown>
    158 function is called), and the associated module will be unloaded if one
    159 was loaded, and I<prov> itself will be freed.
    160 
    161 ossl_provider_set_module_path() sets the module path to load the
    162 provider module given the provider object I<prov>.
    163 This will be used in preference to automatically trying to figure out
    164 the path from the provider name and the default module directory (more
    165 on this in L</NOTES>).
    166 
    167 ossl_provider_libctx() returns the library context the given
    168 provider I<prov> is registered in.
    169 
    170 ossl_provider_set_child() marks this provider as a child of a provider in the
    171 parent library context. I<handle> is the B<OSSL_CORE_HANDLE> object passed to
    172 the provider's B<OSSL_provider_init> function.
    173 
    174 ossl_provider_get_parent() obtains the handle on the parent provider.
    175 
    176 ossl_provider_up_ref_parent() increases the reference count on the parent
    177 provider. If I<activate> is nonzero then the parent provider is also activated.
    178 
    179 ossl_provider_free_parent() decreases the reference count on the parent
    180 provider. If I<deactivate> is nonzero then the parent provider is also
    181 deactivated.
    182 
    183 ossl_provider_default_props_update() is responsible for informing any child
    184 providers of an update to the default properties. The new properties are
    185 supplied in the I<props> string.
    186 
    187 ossl_provider_activate() "activates" the provider for the given
    188 provider object I<prov> by incrementing its activation count, flagging
    189 it as activated, and initializing it if it isn't already initialized.
    190 Initializing means one of the following:
    191 
    192 =over 4
    193 
    194 =item *
    195 
    196 If an initialization function was given with ossl_provider_new(), that
    197 function will get called.
    198 
    199 =item *
    200 
    201 If no initialization function was given with ossl_provider_new(), a
    202 loadable module with the I<name> that was given to ossl_provider_new()
    203 will be located and loaded, then the symbol B<OSSL_provider_init> will
    204 be located in that module, and called.
    205 
    206 =back
    207 
    208 If I<upcalls> is nonzero then, if this is a child provider, upcalls to the
    209 parent libctx will be made to inform it of an up-ref. If I<aschild> is nonzero
    210 then the provider will only be activated if it is a child provider. Otherwise
    211 no action is taken and ossl_provider_activate() returns success.
    212 
    213 ossl_provider_deactivate() "deactivates" the provider for the given
    214 provider object I<prov> by decrementing its activation count.  When
    215 that count reaches zero, the activation flag is cleared. If the
    216 I<removechildren> parameter is 0 then no attempt is made to remove any
    217 associated child providers.
    218 
    219 ossl_provider_add_to_store() adds the provider I<prov> to the provider store and
    220 makes it available to other threads. This will prevent future automatic loading
    221 of fallback providers, unless I<retain_fallbacks> is true. If a provider of the
    222 same name already exists in the store then it is not added but this function
    223 still returns success. On success the I<actualprov> value is populated with a
    224 pointer to the provider of the given name that is now in the store. The
    225 reference passed in the I<prov> argument is consumed by this function. A
    226 reference to the provider that should be used is passed back in the
    227 I<actualprov> argument.
    228 
    229 ossl_provider_ctx() returns a context created by the provider.
    230 Outside of the provider, it's completely opaque, but it needs to be
    231 passed back to some of the provider functions.
    232 
    233 ossl_provider_get0_dispatch() returns the dispatch table that the provider
    234 initially returned in the I<out> parameter of its B<OSSL_provider_init>
    235 function.
    236 
    237 ossl_provider_doall_activated() iterates over all the currently
    238 "activated" providers, and calls I<cb> for each of them.
    239 If no providers have been "activated" yet, it tries to activate all
    240 available fallback providers before iterating over them.
    241 
    242 ossl_provider_name() returns the name that was given with
    243 ossl_provider_new().
    244 
    245 ossl_provider_dso() returns a reference to the module, for providers
    246 that come in the form of loadable modules.
    247 
    248 ossl_provider_module_name() returns the filename of the module, for
    249 providers that come in the form of loadable modules.
    250 
    251 ossl_provider_module_path() returns the full path of the module file,
    252 for providers that come in the form of loadable modules.
    253 
    254 ossl_provider_teardown() calls the provider's I<teardown> function, if
    255 the provider has one.
    256 
    257 ossl_provider_gettable_params() calls the provider's I<gettable_params>
    258 function, if the provider has one.
    259 It should return an array of I<OSSL_PARAM> to describe all the
    260 parameters that the provider has for the provider object.
    261 
    262 ossl_provider_get_params() calls the provider's parameter request
    263 responder.
    264 It should treat the given I<OSSL_PARAM> array as described in
    265 L<OSSL_PARAM(3)>.
    266 
    267 ossl_provider_get_capabilities() calls the provider's I<get_capabilities> function,
    268 if the provider has one. It provides the name of the I<capability> and a
    269 callback I<cb> parameter to call for each capability that has a matching name in
    270 the provider. The callback gets passed OSSL_PARAM details about the capability as
    271 well as the caller supplied argument I<arg>.
    272 
    273 ossl_provider_query_operation() calls the provider's
    274 I<query_operation> function, if the provider has one.
    275 It should return an array of I<OSSL_ALGORITHM> for the given
    276 I<operation_id>.
    277 
    278 ossl_provider_unquery_operation() informs the provider that the result of
    279 ossl_provider_query_operation() is no longer going to be directly accessed and
    280 that all relevant information has been copied.
    281 
    282 ossl_provider_random_bytes() queries the provider, I<prov>, randomness
    283 source for I<n> bytes of entropy which are returned in the buffer
    284 I<buf>, the returned entropy will have a number of bits of I<strength>.
    285 The entropy is drawn from the source, I<which>, which can be:
    286 
    287 =over 4
    288 
    289 =item *
    290 
    291 OSSL_PROV_RANDOM_PUBLIC for a source equivalent to L<RAND_bytes(3)> or
    292 
    293 =item *
    294 
    295 .OSSL_PROV_RANDOM_PRIVATE for a source equivalent to L<RAND_priv_bytes(3)>.
    296 
    297 =back
    298 
    299 Specifying other values for I<which> will result in an unspecified source but will
    300 not result in an error.
    301 
    302 ossl_provider_set_operation_bit() registers a 1 for operation I<bitnum>
    303 in a bitstring that's internal to I<provider>.
    304 
    305 ossl_provider_test_operation_bit() checks if the bit operation I<bitnum>
    306 is set (1) or not (0) in the internal I<provider> bitstring, and sets
    307 I<*result> to 1 or 0 accordingly.
    308 
    309 ossl_provider_init_as_child() stores in the library context I<ctx> references to
    310 the necessary upcalls for managing child providers. The I<handle> and I<in>
    311 parameters are the B<OSSL_CORE_HANDLE> and L<OSSL_DISPATCH(3)> pointers that were
    312 passed to the provider's B<OSSL_provider_init> function.
    313 
    314 ossl_provider_deinit_child() deregisters callbacks from the parent library
    315 context about provider creation or removal events for the child library context
    316 I<ctx>. Must only be called if I<ctx> is a child library context.
    317 
    318 =head1 NOTES
    319 
    320 Locating a provider module happens as follows:
    321 
    322 =over 4
    323 
    324 =item 1.
    325 
    326 If a path was given with ossl_provider_set_module_path(), use that as
    327 module path.
    328 Otherwise, use the provider object's name as module path, with
    329 platform specific standard extensions added.
    330 
    331 =item 2.
    332 
    333 If the environment variable B<OPENSSL_MODULES> is defined, assume its
    334 value is a directory specification and merge it with the module path.
    335 Otherwise, merge the value of the OpenSSL built in macro B<MODULESDIR>
    336 with the module path.
    337 
    338 =back
    339 
    340 When this process is done, the result is used when trying to load the
    341 provider module.
    342 
    343 The command C<openssl version -m> can be used to find out the value
    344 of the built in macro B<MODULESDIR>.
    345 
    346 =head1 RETURN VALUES
    347 
    348 ossl_provider_find() and ossl_provider_new() return a pointer to a
    349 provider object (I<OSSL_PROVIDER>) on success, or NULL on error.
    350 
    351 ossl_provider_up_ref() returns the value of the reference count after
    352 it has been incremented.
    353 
    354 ossl_provider_free() doesn't return any value.
    355 
    356 ossl_provider_doall_activated() returns 1 if the callback was called for all
    357 activated providers.  A return value of 0 means that the callback was not
    358 called for any activated providers.
    359 
    360 ossl_provider_set_module_path(),
    361 ossl_provider_activate(), ossl_provider_activate_leave_fallbacks() and
    362 ossl_provider_deactivate(), ossl_provider_add_to_store(),
    363 ossl_provider_default_props_update() return 1 on success, or 0 on error.
    364 
    365 ossl_provider_name(), ossl_provider_dso(),
    366 ossl_provider_module_name(), and ossl_provider_module_path() return a
    367 pointer to their respective data if it's available, otherwise NULL
    368 is returned.
    369 
    370 ossl_provider_libctx() return a pointer to the library context.
    371 This may be NULL, and is perfectly valid, as it denotes the default
    372 global library context.
    373 
    374 ossl_provider_teardown() doesn't return any value.
    375 
    376 ossl_provider_gettable_params() returns a pointer to a constant
    377 I<OSSL_PARAM> array if this function is available in the provider,
    378 otherwise NULL.
    379 
    380 ossl_provider_get_params() returns 1 on success, or 0 on error.
    381 If this function isn't available in the provider, 0 is returned.
    382 
    383 ossl_provider_set_operation_bit() and ossl_provider_test_operation_bit()
    384 return 1 on success, or 0 on error.
    385 
    386 ossl_provider_get_capabilities() returns 1 on success, or 0 on error.
    387 If this function isn't available in the provider or the provider does not
    388 support the requested capability then 0 is returned.
    389 
    390 ossl_provider_random_bytes() returns 1 on success or 0 or -1 on error as per
    391 L<RAND_bytes(3)>.
    392 
    393 =head1 SEE ALSO
    394 
    395 L<OSSL_PROVIDER(3)>, L<provider(7)>, L<openssl(1)>
    396 
    397 =head1 HISTORY
    398 
    399 The functions described here were all added in OpenSSL 3.0.
    400 
    401 =head1 COPYRIGHT
    402 
    403 Copyright 2019-2025 The OpenSSL Project Authors. All Rights Reserved.
    404 
    405 Licensed under the Apache License 2.0 (the "License").  You may not use
    406 this file except in compliance with the License.  You can obtain a copy
    407 in the file LICENSE in the source distribution or at
    408 L<https://www.openssl.org/source/license.html>.
    409 
    410 =cut
    411