Home | History | Annotate | Line # | Download | only in man3
      1  1.1  christos =pod
      2  1.1  christos 
      3  1.1  christos =head1 NAME
      4  1.1  christos 
      5  1.1  christos OSSL_PARAM - a structure to pass or request object parameters
      6  1.1  christos 
      7  1.1  christos =head1 SYNOPSIS
      8  1.1  christos 
      9  1.1  christos  #include <openssl/core.h>
     10  1.1  christos 
     11  1.1  christos  typedef struct ossl_param_st OSSL_PARAM;
     12  1.1  christos  struct ossl_param_st {
     13  1.1  christos      const char *key;             /* the name of the parameter */
     14  1.3  christos      unsigned int data_type;      /* declare what kind of content is in data */
     15  1.1  christos      void *data;                  /* value being passed in or out */
     16  1.1  christos      size_t data_size;            /* data size */
     17  1.1  christos      size_t return_size;          /* returned size */
     18  1.1  christos  };
     19  1.1  christos 
     20  1.1  christos =head1 DESCRIPTION
     21  1.1  christos 
     22  1.1  christos B<OSSL_PARAM> is a type that allows passing arbitrary data for some
     23  1.1  christos object between two parties that have no or very little shared
     24  1.1  christos knowledge about their respective internal structures for that object.
     25  1.1  christos 
     26  1.1  christos A typical usage example could be an application that wants to set some
     27  1.1  christos parameters for an object, or wants to find out some parameters of an
     28  1.1  christos object.
     29  1.1  christos 
     30  1.1  christos Arrays of this type can be used for the following purposes:
     31  1.1  christos 
     32  1.1  christos =over 4
     33  1.1  christos 
     34  1.1  christos =item * Setting parameters for some object
     35  1.1  christos 
     36  1.1  christos The caller sets up the B<OSSL_PARAM> array and calls some function
     37  1.1  christos (the I<setter>) that has intimate knowledge about the object that can
     38  1.1  christos take the data from the B<OSSL_PARAM> array and assign them in a
     39  1.1  christos suitable form for the internal structure of the object.
     40  1.1  christos 
     41  1.1  christos =item * Request parameters of some object
     42  1.1  christos 
     43  1.2  christos The caller (the I<requester>) sets up the B<OSSL_PARAM> array and
     44  1.1  christos calls some function (the I<responder>) that has intimate knowledge
     45  1.1  christos about the object, which can take the internal data of the object and
     46  1.1  christos copy (possibly convert) that to the memory prepared by the
     47  1.2  christos I<requester> and pointed at with the B<OSSL_PARAM> I<data>.
     48  1.1  christos 
     49  1.1  christos =item * Request parameter descriptors
     50  1.1  christos 
     51  1.1  christos The caller gets an array of constant B<OSSL_PARAM>, which describe
     52  1.1  christos available parameters and some of their properties; name, data type and
     53  1.1  christos expected data size.
     54  1.1  christos For a detailed description of each field for this use, see the field
     55  1.1  christos descriptions below.
     56  1.1  christos 
     57  1.1  christos The caller may then use the information from this descriptor array to
     58  1.1  christos build up its own B<OSSL_PARAM> array to pass down to a I<setter> or
     59  1.1  christos I<responder>.
     60  1.1  christos 
     61  1.1  christos =back
     62  1.1  christos 
     63  1.1  christos Normally, the order of the an B<OSSL_PARAM> array is not relevant.
     64  1.1  christos However, if the I<responder> can handle multiple elements with the
     65  1.1  christos same key, those elements must be handled in the order they are in.
     66  1.1  christos 
     67  1.1  christos An B<OSSL_PARAM> array must have a terminating element, where I<key>
     68  1.1  christos is NULL.  The usual full terminating template is:
     69  1.1  christos 
     70  1.1  christos     { NULL, 0, NULL, 0, 0 }
     71  1.1  christos 
     72  1.1  christos This can also be specified using L<OSSL_PARAM_END(3)>.
     73  1.1  christos 
     74  1.1  christos =head2 Functional support
     75  1.1  christos 
     76  1.1  christos Libcrypto offers a limited set of helper functions to handle
     77  1.1  christos B<OSSL_PARAM> items and arrays, please see L<OSSL_PARAM_get_int(3)>.
     78  1.1  christos Developers are free to extend or replace those as they see fit.
     79  1.1  christos 
     80  1.1  christos =head2 B<OSSL_PARAM> fields
     81  1.1  christos 
     82  1.1  christos =over 4
     83  1.1  christos 
     84  1.1  christos =item I<key>
     85  1.1  christos 
     86  1.1  christos The identity of the parameter in the form of a string.
     87  1.1  christos 
     88  1.1  christos In an B<OSSL_PARAM> array, an item with this field set to NULL is
     89  1.1  christos considered a terminating item.
     90  1.1  christos 
     91  1.1  christos =item I<data_type>
     92  1.1  christos 
     93  1.1  christos The I<data_type> is a value that describes the type and organization of
     94  1.1  christos the data.
     95  1.1  christos See L</Supported types> below for a description of the types.
     96  1.1  christos 
     97  1.1  christos =item I<data>
     98  1.1  christos 
     99  1.1  christos =item I<data_size>
    100  1.1  christos 
    101  1.1  christos I<data> is a pointer to the memory where the parameter data is (when
    102  1.1  christos setting parameters) or shall (when requesting parameters) be stored,
    103  1.1  christos and I<data_size> is its size in bytes.
    104  1.1  christos The organization of the data depends on the parameter type and flag.
    105  1.1  christos 
    106  1.1  christos The I<data_size> needs special attention with the parameter type
    107  1.1  christos B<OSSL_PARAM_UTF8_STRING> in relation to C strings.  When setting
    108  1.1  christos parameters, the size should be set to the length of the string, not
    109  1.1  christos counting the terminating NUL byte.  When requesting parameters, the
    110  1.1  christos size should be set to the size of the buffer to be populated, which
    111  1.2  christos should accommodate enough space for a terminating NUL byte.
    112  1.1  christos 
    113  1.1  christos When I<requesting parameters>, it's acceptable for I<data> to be NULL.
    114  1.2  christos This can be used by the I<requester> to figure out dynamically exactly
    115  1.1  christos how much buffer space is needed to store the parameter data.
    116  1.1  christos In this case, I<data_size> is ignored.
    117  1.1  christos 
    118  1.1  christos When the B<OSSL_PARAM> is used as a parameter descriptor, I<data>
    119  1.1  christos should be ignored.
    120  1.1  christos If I<data_size> is zero, it means that an arbitrary data size is
    121  1.1  christos accepted, otherwise it specifies the maximum size allowed.
    122  1.1  christos 
    123  1.1  christos =item I<return_size>
    124  1.1  christos 
    125  1.1  christos When an array of B<OSSL_PARAM> is used to request data, the
    126  1.1  christos I<responder> must set this field to indicate size of the parameter
    127  1.1  christos data, including padding as the case may be.
    128  1.1  christos In case the I<data_size> is an unsuitable size for the data, the
    129  1.1  christos I<responder> must still set this field to indicate the minimum data
    130  1.1  christos size required.
    131  1.1  christos (further notes on this in L</NOTES> below).
    132  1.1  christos 
    133  1.1  christos When the B<OSSL_PARAM> is used as a parameter descriptor,
    134  1.1  christos I<return_size> should be ignored.
    135  1.1  christos 
    136  1.1  christos =back
    137  1.1  christos 
    138  1.1  christos B<NOTE:>
    139  1.1  christos 
    140  1.1  christos The key names and associated types are defined by the entity that
    141  1.1  christos offers these parameters, i.e. names for parameters provided by the
    142  1.1  christos OpenSSL libraries are defined by the libraries, and names for
    143  1.1  christos parameters provided by providers are defined by those providers,
    144  1.1  christos except for the pointer form of strings (see data type descriptions
    145  1.1  christos below).
    146  1.1  christos Entities that want to set or request parameters need to know what
    147  1.1  christos those keys are and of what type, any functionality between those two
    148  1.1  christos entities should remain oblivious and just pass the B<OSSL_PARAM> array
    149  1.1  christos along.
    150  1.1  christos 
    151  1.1  christos =head2 Supported types
    152  1.1  christos 
    153  1.1  christos The I<data_type> field can be one of the following types:
    154  1.1  christos 
    155  1.1  christos =over 4
    156  1.1  christos 
    157  1.1  christos =item B<OSSL_PARAM_INTEGER>
    158  1.1  christos 
    159  1.1  christos =item B<OSSL_PARAM_UNSIGNED_INTEGER>
    160  1.1  christos 
    161  1.1  christos The parameter data is an integer (signed or unsigned) of arbitrary
    162  1.1  christos length, organized in native form, i.e. most significant byte first on
    163  1.1  christos Big-Endian systems, and least significant byte first on Little-Endian
    164  1.1  christos systems.
    165  1.1  christos 
    166  1.1  christos =item B<OSSL_PARAM_REAL>
    167  1.1  christos 
    168  1.1  christos The parameter data is a floating point value in native form.
    169  1.1  christos 
    170  1.1  christos =item B<OSSL_PARAM_UTF8_STRING>
    171  1.1  christos 
    172  1.1  christos The parameter data is a printable string.
    173  1.1  christos 
    174  1.1  christos =item B<OSSL_PARAM_OCTET_STRING>
    175  1.1  christos 
    176  1.1  christos The parameter data is an arbitrary string of bytes.
    177  1.1  christos 
    178  1.1  christos =item B<OSSL_PARAM_UTF8_PTR>
    179  1.1  christos 
    180  1.1  christos The parameter data is a pointer to a printable string.
    181  1.1  christos 
    182  1.1  christos The difference between this and B<OSSL_PARAM_UTF8_STRING> is that I<data>
    183  1.1  christos doesn't point directly at the data, but to a pointer that points to the data.
    184  1.1  christos 
    185  1.1  christos If there is any uncertainty about which to use, B<OSSL_PARAM_UTF8_STRING> is
    186  1.1  christos almost certainly the correct choice.
    187  1.1  christos 
    188  1.1  christos This is used to indicate that constant data is or will be passed,
    189  1.1  christos and there is therefore no need to copy the data that is passed, just
    190  1.1  christos the pointer to it.
    191  1.1  christos 
    192  1.1  christos I<data_size> must be set to the size of the data, not the size of the
    193  1.1  christos pointer to the data.
    194  1.1  christos If this is used in a parameter request,
    195  1.1  christos I<data_size> is not relevant.  However, the I<responder> will set
    196  1.1  christos I<return_size> to the size of the data.
    197  1.1  christos 
    198  1.1  christos Note that the use of this type is B<fragile> and can only be safely
    199  1.1  christos used for data that remains constant and in a constant location for a
    200  1.1  christos long enough duration (such as the life-time of the entity that
    201  1.1  christos offers these parameters).
    202  1.1  christos 
    203  1.1  christos =item B<OSSL_PARAM_OCTET_PTR>
    204  1.1  christos 
    205  1.1  christos The parameter data is a pointer to an arbitrary string of bytes.
    206  1.1  christos 
    207  1.1  christos The difference between this and B<OSSL_PARAM_OCTET_STRING> is that
    208  1.1  christos I<data> doesn't point directly at the data, but to a pointer that
    209  1.1  christos points to the data.
    210  1.1  christos 
    211  1.1  christos If there is any uncertainty about which to use, B<OSSL_PARAM_OCTET_STRING> is
    212  1.1  christos almost certainly the correct choice.
    213  1.1  christos 
    214  1.1  christos This is used to indicate that constant data is or will be passed, and
    215  1.1  christos there is therefore no need to copy the data that is passed, just the
    216  1.1  christos pointer to it.
    217  1.1  christos 
    218  1.1  christos I<data_size> must be set to the size of the data, not the size of the
    219  1.1  christos pointer to the data.
    220  1.1  christos If this is used in a parameter request,
    221  1.1  christos I<data_size> is not relevant.  However, the I<responder> will set
    222  1.1  christos I<return_size> to the size of the data.
    223  1.1  christos 
    224  1.1  christos Note that the use of this type is B<fragile> and can only be safely
    225  1.1  christos used for data that remains constant and in a constant location for a
    226  1.1  christos long enough duration (such as the life-time of the entity that
    227  1.1  christos offers these parameters).
    228  1.1  christos 
    229  1.1  christos =back
    230  1.1  christos 
    231  1.1  christos =head1 NOTES
    232  1.1  christos 
    233  1.1  christos Both when setting and requesting parameters, the functions that are
    234  1.1  christos called will have to decide what is and what is not an error.
    235  1.1  christos The recommended behaviour is:
    236  1.1  christos 
    237  1.1  christos =over 4
    238  1.1  christos 
    239  1.1  christos =item *
    240  1.1  christos 
    241  1.1  christos Keys that a I<setter> or I<responder> doesn't recognise should simply
    242  1.1  christos be ignored.
    243  1.1  christos That in itself isn't an error.
    244  1.1  christos 
    245  1.1  christos =item *
    246  1.1  christos 
    247  1.1  christos If the keys that a called I<setter> recognises form a consistent
    248  1.1  christos enough set of data, that call should succeed.
    249  1.1  christos 
    250  1.1  christos =item *
    251  1.1  christos 
    252  1.1  christos Apart from the I<return_size>, a I<responder> must never change the fields
    253  1.1  christos of an B<OSSL_PARAM>.
    254  1.1  christos To return a value, it should change the contents of the memory that
    255  1.1  christos I<data> points at.
    256  1.1  christos 
    257  1.1  christos =item *
    258  1.1  christos 
    259  1.1  christos If the data type for a key that it's associated with is incorrect,
    260  1.1  christos the called function may return an error.
    261  1.1  christos 
    262  1.1  christos The called function may also try to convert the data to a suitable
    263  1.1  christos form (for example, it's plausible to pass a large number as an octet
    264  1.1  christos string, so even though a given key is defined as an
    265  1.1  christos B<OSSL_PARAM_UNSIGNED_INTEGER>, is plausible to pass the value as an
    266  1.1  christos B<OSSL_PARAM_OCTET_STRING>), but this is in no way mandatory.
    267  1.1  christos 
    268  1.1  christos =item *
    269  1.1  christos 
    270  1.2  christos If I<data> for a B<OSSL_PARAM_OCTET_STRING> or a
    271  1.2  christos B<OSSL_PARAM_UTF8_STRING> is NULL, the I<responder> should
    272  1.2  christos set I<return_size> to the size of the item to be returned
    273  1.2  christos and return success. Later the responder will be called again
    274  1.2  christos with I<data> pointing at the place for the value to be put.
    275  1.2  christos 
    276  1.2  christos =item *
    277  1.2  christos 
    278  1.1  christos If a I<responder> finds that some data sizes are too small for the
    279  1.1  christos requested data, it must set I<return_size> for each such
    280  1.1  christos B<OSSL_PARAM> item to the minimum required size, and eventually return
    281  1.1  christos an error.
    282  1.1  christos 
    283  1.1  christos =item *
    284  1.1  christos 
    285  1.1  christos For the integer type parameters (B<OSSL_PARAM_UNSIGNED_INTEGER> and
    286  1.1  christos B<OSSL_PARAM_INTEGER>), a I<responder> may choose to return an error
    287  1.1  christos if the I<data_size> isn't a suitable size (even if I<data_size> is
    288  1.1  christos bigger than needed).  If the I<responder> finds the size suitable, it
    289  1.1  christos must fill all I<data_size> bytes and ensure correct padding for the
    290  1.1  christos native endianness, and set I<return_size> to the same value as
    291  1.1  christos I<data_size>.
    292  1.1  christos 
    293  1.1  christos =back
    294  1.1  christos 
    295  1.1  christos =begin comment RETURN VALUES doesn't make sense for a manual that only
    296  1.1  christos describes a type, but document checkers still want that section, and
    297  1.1  christos to have more than just the section title.
    298  1.1  christos 
    299  1.1  christos =head1 RETURN VALUES
    300  1.1  christos 
    301  1.1  christos txt
    302  1.1  christos 
    303  1.1  christos =end comment
    304  1.1  christos 
    305  1.1  christos =head1 EXAMPLES
    306  1.1  christos 
    307  1.1  christos A couple of examples to just show how B<OSSL_PARAM> arrays could be
    308  1.1  christos set up.
    309  1.1  christos 
    310  1.1  christos =head3 Example 1
    311  1.1  christos 
    312  1.1  christos This example is for setting parameters on some object:
    313  1.1  christos 
    314  1.1  christos     #include <openssl/core.h>
    315  1.1  christos 
    316  1.1  christos     const char *foo = "some string";
    317  1.1  christos     size_t foo_l = strlen(foo);
    318  1.1  christos     const char bar[] = "some other string";
    319  1.1  christos     OSSL_PARAM set[] = {
    320  1.1  christos         { "foo", OSSL_PARAM_UTF8_PTR, &foo, foo_l, 0 },
    321  1.1  christos         { "bar", OSSL_PARAM_UTF8_STRING, (void *)&bar, sizeof(bar) - 1, 0 },
    322  1.1  christos         { NULL, 0, NULL, 0, 0 }
    323  1.1  christos     };
    324  1.1  christos 
    325  1.1  christos =head3 Example 2
    326  1.1  christos 
    327  1.1  christos This example is for requesting parameters on some object:
    328  1.1  christos 
    329  1.1  christos     const char *foo = NULL;
    330  1.1  christos     size_t foo_l;
    331  1.1  christos     char bar[1024];
    332  1.1  christos     size_t bar_l;
    333  1.1  christos     OSSL_PARAM request[] = {
    334  1.1  christos         { "foo", OSSL_PARAM_UTF8_PTR, &foo, 0 /*irrelevant*/, 0 },
    335  1.1  christos         { "bar", OSSL_PARAM_UTF8_STRING, &bar, sizeof(bar), 0 },
    336  1.1  christos         { NULL, 0, NULL, 0, 0 }
    337  1.1  christos     };
    338  1.1  christos 
    339  1.1  christos A I<responder> that receives this array (as I<params> in this example)
    340  1.1  christos could fill in the parameters like this:
    341  1.1  christos 
    342  1.1  christos     /* OSSL_PARAM *params */
    343  1.1  christos 
    344  1.1  christos     int i;
    345  1.1  christos 
    346  1.1  christos     for (i = 0; params[i].key != NULL; i++) {
    347  1.1  christos         if (strcmp(params[i].key, "foo") == 0) {
    348  1.1  christos             *(char **)params[i].data = "foo value";
    349  1.1  christos             params[i].return_size = 9; /* length of "foo value" string */
    350  1.1  christos         } else if (strcmp(params[i].key, "bar") == 0) {
    351  1.1  christos             memcpy(params[i].data, "bar value", 10);
    352  1.1  christos             params[i].return_size = 9; /* length of "bar value" string */
    353  1.1  christos         }
    354  1.1  christos         /* Ignore stuff we don't know */
    355  1.1  christos     }
    356  1.1  christos 
    357  1.1  christos =head1 SEE ALSO
    358  1.1  christos 
    359  1.1  christos L<openssl-core.h(7)>, L<OSSL_PARAM_get_int(3)>, L<OSSL_PARAM_dup(3)>
    360  1.1  christos 
    361  1.1  christos =head1 HISTORY
    362  1.1  christos 
    363  1.1  christos B<OSSL_PARAM> was added in OpenSSL 3.0.
    364  1.1  christos 
    365  1.1  christos =head1 COPYRIGHT
    366  1.1  christos 
    367  1.2  christos Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
    368  1.1  christos 
    369  1.1  christos Licensed under the Apache License 2.0 (the "License").  You may not use
    370  1.1  christos this file except in compliance with the License.  You can obtain a copy
    371  1.1  christos in the file LICENSE in the source distribution or at
    372  1.1  christos L<https://www.openssl.org/source/license.html>.
    373  1.1  christos 
    374  1.1  christos =cut
    375