Rename 'buffer' to 'data' in OSSL_PARAM
[openssl.git] / doc / man3 / OSSL_PARAM.pod
1 =pod
2
3 =head1 NAME
4
5 OSSL_PARAM - a structure to pass or request object parameters
6
7 =head1 SYNOPSIS
8
9  #include <openssl/core.h>
10
11  typedef struct ossl_param_st OSSL_PARAM;
12  struct ossl_param_st {
13      const char *key;             /* the name of the parameter */
14      unsigned char data_type;     /* declare what kind of content is in data */
15      void *data;                  /* value being passed in or out */
16      size_t data_size;            /* data size */
17      size_t *return_size;         /* OPTIONAL: address to content size */
18  };
19
20 =head1 DESCRIPTION
21
22 C<OSSL_PARAM> is a type that allows passing arbitrary data for some
23 object between two parties that have no or very little shared
24 knowledge about their respective internal structures for that object.
25
26 A typical usage example could be an application that wants to set some
27 parameters for an object, or wants to find out some parameters of an
28 object.
29
30 Arrays of this type can be used for two purposes:
31
32 =over 4
33
34 =item *
35
36 Setting parameters for some object.
37 The caller sets up the C<OSSL_PARAM> array and calls some function
38 (the I<setter>) that has intimate knowledge about the object that can
39 take the data from the C<OSSL_PARAM> array and assign them in a
40 suitable form for the internal structure of the object.
41
42 =item *
43
44 Request parameters of some object.
45 The caller (the I<requestor>) sets up the C<OSSL_PARAM> array and
46 calls some function (the I<responder>) that has intimate knowledge
47 about the object, which can take the internal data of the object and
48 copy (possibly convert) that to the memory prepared by the
49 I<requestor> and pointed at with the C<OSSL_PARAM> C<data>.
50
51 =back
52
53 =head2 C<OSSL_PARAM> fields
54
55 =over 4
56
57 =item C<key>
58
59 The identity of the parameter in the form of a string.
60
61 =item C<data_type>
62
63 =for comment It's still debated if this field should be present, or if
64 the type should always be implied by how it's used.
65 Either way, these data types will have to be passed together with the
66 names as an array of OSSL_ITEM, for discovery purposes.
67
68 The C<data_type> is a value that describes the type and organization of
69 the data.
70 See L</Supported types> below for a description of the types.
71
72 =item C<data>
73
74 =item C<data_size>
75
76 C<data> is a pointer to the memory where the parameter data is (when
77 setting parameters) or shall (when requesting parameters) be stored,
78 and C<data_size> is its size in bytes.
79 The organization of the data depends on the parameter type and flag.
80
81 =item C<return_size>
82
83 When an array of C<OSSL_PARAM> is used to request data, the
84 I<responder> must set this field to indicate the actual size of the
85 parameter data.
86 In case the C<data_size> is too small for the data, the I<responder>
87 must still set this field to indicate the minimum data size required.
88
89 =back
90
91 B<NOTE:>
92
93 The key names and associated types are defined by the entity that
94 offers these parameters, i.e. names for parameters provided by the
95 OpenSSL libraries are defined by the libraries, and names for
96 parameters provided by providers are defined by those providers,
97 except for the pointer form of strings (see data type descriptions
98 below).
99 Entities that want to set or request parameters need to know what
100 those keys are and of what type, any functionality between those two
101 entities should remain oblivious and just pass the C<OSSL_PARAM> array
102 along.
103
104 =head2 Supported types
105
106 The C<data_type> field can be one of the following types:
107
108 =over 4
109
110 =item C<OSSL_PARAM_INTEGER>
111
112 =item C<OSSL_PARAM_UNSIGNED_INTEGER>
113
114 The parameter data is an integer (signed or unsigned) of arbitrary
115 length, organized in native form, i.e. most significant byte first on
116 Big-Endian systems, and least significant byte first on Little-Endian
117 systems.
118
119 =item C<OSSL_PARAM_REAL>
120
121 =for comment It's still debated if we need this or not.
122
123 The parameter data is a floating point value in native form.
124
125 =item C<OSSL_PARAM_UTF8_STRING>
126
127 The parameter data is a printable string.
128
129 =item C<OSSL_PARAM_OCTET_STRING>
130
131 The parameter data is an arbitrary string of bytes.
132
133 =back
134
135 Additionally, this flag can be added to any type:
136
137 =over 4
138
139 =item C<OSSL_PARAM_POINTER_FLAG>
140
141 With this flag, C<data> doesn't point directly at the data, but at a
142 pointer that points at the data.
143
144 This can be used to indicate that constant data is or will be passed,
145 and there is therefore no need to copy the data that is passed, just
146 the pointer to it.
147
148 If an C<OSSL_PARAM> with this flag set is used to set a parameter,
149 C<data_size> must be set to the size of the data, not the size of
150 the pointer to the data.
151
152 If this C<OSSL_PARAM> is used in a parameter request, C<data_size>
153 is not relevant.
154 However, the I<responder> will set C<*return_size> to the size of the
155 data (again, not the size of the pointer to the data).
156
157 Note that the use of this flag is B<fragile> and can only be safely
158 used for data that remains constant and in a constant location for a
159 long enough duration (such as the life-time of the entity that
160 offers these parameters).
161
162 =back
163
164 For convenience, these types are provided:
165
166 =over 4
167
168 =item C<OSSL_PARAM_UTF8_STRING_PTR>
169
170 =item C<OSSL_PARAM_OCTET_STRING_PTR>
171
172 These are combinations of C<OSSL_PARAM_UTF8_STRING> as well as
173 C<OSSL_PARAM_OCTET_STRING> with C<OSSL_PARAM_POINTER_FLAG>.
174
175 =back
176
177 =head1 NOTES
178
179 Both when setting and requesting parameters, the functions that are
180 called will have to decide what is and what is not an error.
181 The recommended behaviour is:
182
183 =over 4
184
185 =item *
186
187 Keys that a I<setter> or I<responder> doesn't recognise should simply
188 be ignored.
189 That in itself isn't an error.
190
191 =item *
192
193 If the keys that a called I<setter> recognises form a consistent
194 enough set of data, that call should succeed.
195
196 =item *
197
198 A I<responder> must never change the fields of an C<OSSL_PARAM>, it
199 may only change the contents of the memory that C<data> and
200 C<return_size> point at.
201
202 =item *
203
204 If the data type for a key that it's associated with is incorrect,
205 the called function may return an error.
206
207 The called function may also try to convert the data to a suitable
208 form (for example, it's plausible to pass a large number as an octet
209 string, so even though a given key is defined as an
210 C<OSSL_PARAM_UNSIGNED_INTEGER>, is plausible to pass the value as an
211 C<OSSL_PARAM_OCTET_STRING>), but this is in no way mandatory.
212
213 =item *
214
215 If a I<responder> finds that some data sizes are too small for the
216 requested data, it must set C<*return_size> for each such
217 C<OSSL_PARAM> item to the required size, and eventually return an
218 error.
219
220 =back
221
222 =begin comment RETURN VALUES doesn't make sense for a manual that only
223 describes a type, but document checkers still want that section, and
224 to have more than just the section title.
225
226 =head1 RETURN VALUES
227
228 txt
229
230 =end comment
231
232 =head1 EXAMPLES
233
234 A couple of examples to just show how C<OSSL_PARAM> arrays could be
235 set up.
236
237 =head3 Example 1
238
239 This example is for setting parameters on some object:
240
241     #include <openssl/core.h>
242
243     const char *foo = "some string";
244     size_t foo_l = strlen(foo) + 1;
245     const char bar[] = "some other string";
246     const OSSL_PARAM set[] = {
247         { "foo", OSSL_PARAM_UTF8_STRING_PTR, &foo, foo_l, NULL },
248         { "bar", OSSL_PARAM_UTF8_STRING, &bar, sizeof(bar), NULL },
249         { NULL, 0, NULL, 0, NULL }
250     };
251
252 =head3 Example 2
253
254 This example is for requesting parameters on some object:
255
256     const char *foo = NULL;
257     size_t foo_l;
258     char bar[1024];
259     size_t bar_l;
260     const OSSL_PARAM request[] = {
261         { "foo", OSSL_PARAM_UTF8_STRING_PTR, &foo, 0 /*irrelevant*/, &foo_l },
262         { "bar", OSSL_PARAM_UTF8_STRING, &bar, sizeof(bar), &bar_l },
263         { NULL, 0, NULL, 0, NULL }
264     };
265
266 A I<responder> that receives this array (as C<params> in this example)
267 could fill in the parameters like this:
268
269     /* const OSSL_PARAM *params */
270
271     int i;
272
273     for (i = 0; params[i].key != NULL; i++) {
274         if (strcmp(params[i].key, "foo") == 0) {
275             *(char **)params[i].data = "foo value";
276             *params[i].return_size = 10; /* size of "foo value" */
277         } else if (strcmp(params[i].key, "bar") == 0) {
278             memcpy(params[1].data, "bar value", 10);
279             *params[1].return_size = 10; /* size of "bar value" */
280         }
281         /* Ignore stuff we don't know */
282     }
283
284 =head1 SEE ALSO
285
286 L<openssl-core.h(7)>
287
288 =head1 HISTORY
289
290 C<OSSL_PARAM> was added in OpenSSL 3.0.
291
292 =head1 COPYRIGHT
293
294 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
295
296 Licensed under the Apache License 2.0 (the "License").  You may not use
297 this file except in compliance with the License.  You can obtain a copy
298 in the file LICENSE in the source distribution or at
299 L<https://www.openssl.org/source/license.html>.
300
301 =cut