]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/OSSL_PARAM_int.pod
params: change OSSL_PARAM_set_unmodified() to operate on a params array
[thirdparty/openssl.git] / doc / man3 / OSSL_PARAM_int.pod
CommitLineData
7ffbd7ca
P
1=pod
2
3=head1 NAME
4
1313e37a
P
5OSSL_PARAM_double, OSSL_PARAM_int, OSSL_PARAM_int32, OSSL_PARAM_int64,
6OSSL_PARAM_long, OSSL_PARAM_size_t, OSSL_PARAM_uint, OSSL_PARAM_uint32,
4e7991b4 7OSSL_PARAM_uint64, OSSL_PARAM_ulong, OSSL_PARAM_BN, OSSL_PARAM_utf8_string,
1313e37a 8OSSL_PARAM_octet_string, OSSL_PARAM_utf8_ptr, OSSL_PARAM_octet_ptr,
a1c5cefa
RL
9OSSL_PARAM_END,
10OSSL_PARAM_construct_double, OSSL_PARAM_construct_int,
11OSSL_PARAM_construct_int32, OSSL_PARAM_construct_int64,
12OSSL_PARAM_construct_long, OSSL_PARAM_construct_size_t,
13OSSL_PARAM_construct_uint, OSSL_PARAM_construct_uint32,
14OSSL_PARAM_construct_uint64, OSSL_PARAM_construct_ulong,
15OSSL_PARAM_construct_BN, OSSL_PARAM_construct_utf8_string,
16OSSL_PARAM_construct_utf8_ptr, OSSL_PARAM_construct_octet_string,
17OSSL_PARAM_construct_octet_ptr, OSSL_PARAM_construct_end,
18OSSL_PARAM_locate, OSSL_PARAM_locate_const,
4e7991b4
P
19OSSL_PARAM_get_double, OSSL_PARAM_get_int, OSSL_PARAM_get_int32,
20OSSL_PARAM_get_int64, OSSL_PARAM_get_long, OSSL_PARAM_get_size_t,
21OSSL_PARAM_get_uint, OSSL_PARAM_get_uint32, OSSL_PARAM_get_uint64,
a1c5cefa
RL
22OSSL_PARAM_get_ulong, OSSL_PARAM_get_BN, OSSL_PARAM_get_utf8_string,
23OSSL_PARAM_get_octet_string, OSSL_PARAM_get_utf8_ptr,
24OSSL_PARAM_get_octet_ptr,
25OSSL_PARAM_set_double, OSSL_PARAM_set_int, OSSL_PARAM_set_int32,
26OSSL_PARAM_set_int64, OSSL_PARAM_set_long, OSSL_PARAM_set_size_t,
27OSSL_PARAM_set_uint, OSSL_PARAM_set_uint32, OSSL_PARAM_set_uint64,
28OSSL_PARAM_set_ulong, OSSL_PARAM_set_BN, OSSL_PARAM_set_utf8_string,
29OSSL_PARAM_set_octet_string, OSSL_PARAM_set_utf8_ptr,
8d5fb648 30OSSL_PARAM_set_octet_ptr, OSSL_PARAM_UNMODIFIED
7ffbd7ca
P
31- OSSL_PARAM helpers
32
33=head1 SYNOPSIS
34
bb82531f 35=for openssl generic
1313e37a 36
7ffbd7ca
P
37 #include <openssl/params.h>
38
a1c5cefa
RL
39 /*
40 * TYPE in function names is one of:
41 * double, int, int32, int64, long, size_t, uint, uint32, uint64, ulong
42 * Corresponding TYPE in function arguments is one of:
43 * double, int, int32_t, int64_t, long, size_t, unsigned int, uint32_t,
44 * uint64_t, unsigned long
45 */
46
7ffbd7ca 47 #define OSSL_PARAM_TYPE(key, address)
a1c5cefa 48 #define OSSL_PARAM_BN(key, address, size)
7ffbd7ca
P
49 #define OSSL_PARAM_utf8_string(key, address, size)
50 #define OSSL_PARAM_octet_string(key, address, size)
51 #define OSSL_PARAM_utf8_ptr(key, address, size)
52 #define OSSL_PARAM_octet_ptr(key, address, size)
7ffbd7ca
P
53 #define OSSL_PARAM_END
54
8d5fb648
P
55 #define OSSL_PARAM_UNMODIFIED
56
a1c5cefa 57 OSSL_PARAM OSSL_PARAM_construct_TYPE(const char *key, TYPE *buf);
7ffbd7ca 58 OSSL_PARAM OSSL_PARAM_construct_BN(const char *key, unsigned char *buf,
4e7991b4 59 size_t bsize);
7ffbd7ca 60 OSSL_PARAM OSSL_PARAM_construct_utf8_string(const char *key, char *buf,
4e7991b4 61 size_t bsize);
7ffbd7ca 62 OSSL_PARAM OSSL_PARAM_construct_octet_string(const char *key, void *buf,
4e7991b4 63 size_t bsize);
7ffbd7ca 64 OSSL_PARAM OSSL_PARAM_construct_utf8_ptr(const char *key, char **buf,
4e7991b4 65 size_t bsize);
7ffbd7ca 66 OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
4e7991b4 67 size_t bsize);
195852fe 68 OSSL_PARAM OSSL_PARAM_construct_end(void);
7ffbd7ca
P
69
70 OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *array, const char *key);
4e7991b4
P
71 const OSSL_PARAM *OSSL_PARAM_locate_const(const OSSL_PARAM *array,
72 const char *key);
7ffbd7ca 73
a1c5cefa
RL
74 int OSSL_PARAM_get_TYPE(const OSSL_PARAM *p, TYPE *val);
75 int OSSL_PARAM_set_TYPE(OSSL_PARAM *p, TYPE val);
7ffbd7ca 76
a1c5cefa
RL
77 int OSSL_PARAM_get_BN(const OSSL_PARAM *p, BIGNUM **val);
78 int OSSL_PARAM_set_BN(OSSL_PARAM *p, const BIGNUM *val);
7ffbd7ca
P
79
80 int OSSL_PARAM_get_utf8_string(const OSSL_PARAM *p, char **val,
81 size_t max_len);
4e7991b4 82 int OSSL_PARAM_set_utf8_string(OSSL_PARAM *p, const char *val);
7ffbd7ca
P
83
84 int OSSL_PARAM_get_octet_string(const OSSL_PARAM *p, void **val,
85 size_t max_len, size_t *used_len);
4e7991b4 86 int OSSL_PARAM_set_octet_string(OSSL_PARAM *p, const void *val, size_t len);
7ffbd7ca 87
a1c5cefa
RL
88 int OSSL_PARAM_get_utf8_ptr(const OSSL_PARAM *p, const char **val);
89 int OSSL_PARAM_set_utf8_ptr(OSSL_PARAM *p, const char *val);
7ffbd7ca 90
a1c5cefa 91 int OSSL_PARAM_get_octet_ptr(const OSSL_PARAM *p, const void **val,
7ffbd7ca 92 size_t *used_len);
a1c5cefa
RL
93 int OSSL_PARAM_set_octet_ptr(OSSL_PARAM *p, const void *val,
94 size_t used_len);
7ffbd7ca 95
3873887e
P
96 int OSSL_PARAM_modified(const OSSL_PARAM *param);
97 void OSSL_PARAM_set_all_unmodified(OSSL_PARAM *params);
8d5fb648 98
7ffbd7ca
P
99=head1 DESCRIPTION
100
101A collection of utility functions that simplify and add type safety to the
102OSSL_PARAM arrays. The following B<TYPE> names are supported:
103
104=over 1
105
106=item *
107
108double
109
110=item *
111
112int
113
114=item *
115
116int32 (int32_t)
117
118=item *
119
120int64 (int64_t)
121
122=item *
123
124long int (long)
125
126=item *
127
128size_t
129
130=item *
131
132uint32 (uint32_t)
133
134=item *
135
136uint64 (uint64_t)
137
138=item *
139
140unsigned int (uint)
141
142=item *
143
144unsigned long int (ulong)
145
146=back
147
148OSSL_PARAM_TYPE() are a series of macros designed to assist initialising an
149array of OSSL_PARAM structures.
150Each of these macros defines a parameter of the specified B<TYPE> with the
151provided B<key> and parameter variable B<address>.
152
153OSSL_PARAM_utf8_string(), OSSL_PARAM_octet_string(), OSSL_PARAM_utf8_ptr(),
4e7991b4
P
154OSSL_PARAM_octet_ptr(), OSSL_PARAM_BN() are macros that provide support
155for defining UTF8 strings, OCTET strings and big numbers.
7ffbd7ca
P
156A parameter with name B<key> is defined.
157The storage for this parameter is at B<address> and is of B<size> bytes.
158
7ffbd7ca
P
159OSSL_PARAM_END provides an end of parameter list marker.
160This should terminate all OSSL_PARAM arrays.
161
162OSSL_PARAM_construct_TYPE() are a series of functions that create OSSL_PARAM
163records dynamically.
164A parameter with name B<key> is created.
165The parameter will use storage pointed to by B<buf> and return size of B<ret>.
166
167OSSL_PARAM_construct_BN() is a function that constructs a large integer
168OSSL_PARAM structure.
169A parameter with name B<key>, storage B<buf>, size B<bsize> and return
170size B<rsize> is created.
171
172OSSL_PARAM_construct_utf8_string() is a function that constructs a UTF8
173string OSSL_PARAM structure.
7f588d20 174A parameter with name B<key>, storage B<buf> and size B<bsize> is created.
8b6ffd40
P
175If B<bsize> is zero, the string length is determined using strlen(3) + 1 for the
176null termination byte.
177Generally pass zero for B<bsize> instead of calling strlen(3) yourself.
7ffbd7ca
P
178
179OSSL_PARAM_construct_octet_string() is a function that constructs an OCTET
180string OSSL_PARAM structure.
7f588d20 181A parameter with name B<key>, storage B<buf> and size B<bsize> is created.
7ffbd7ca
P
182
183OSSL_PARAM_construct_utf8_ptr() is a function that constructes a UTF string
184pointer OSSL_PARAM structure.
7f588d20
P
185A parameter with name B<key>, storage pointer B<*buf> and size B<bsize>
186is created.
7ffbd7ca
P
187
188OSSL_PARAM_construct_octet_ptr() is a function that constructes an OCTET string
189pointer OSSL_PARAM structure.
7f588d20
P
190A parameter with name B<key>, storage pointer B<*buf> and size B<bsize>
191is created.
7ffbd7ca 192
195852fe
RL
193OSSL_PARAM_construct_end() is a function that constructs the terminating
194OSSL_PARAM structure.
195
7ffbd7ca
P
196OSSL_PARAM_locate() is a function that searches an B<array> of parameters for
197the one matching the B<key> name.
198
4e7991b4
P
199OSSL_PARAM_locate_const() behaves exactly like OSSL_PARAM_locate() except for
200the presence of I<const> for the B<array> argument and its return value.
201
7ffbd7ca
P
202OSSL_PARAM_get_TYPE() retrieves a value of type B<TYPE> from the parameter B<p>.
203The value is copied to the address B<val>.
204Type coercion takes place as discussed in the NOTES section.
205
c2969ff6 206OSSL_PARAM_set_TYPE() stores a value B<val> of type B<TYPE> into the parameter
7ffbd7ca 207B<p>.
8f3b8fd6
RL
208If the parameter's I<data> field is NULL, then only its I<return_size> field
209will be assigned the size the parameter's I<data> buffer should have.
7ffbd7ca
P
210Type coercion takes place as discussed in the NOTES section.
211
212OSSL_PARAM_get_BN() retrieves a BIGNUM from the parameter pointed to by B<p>.
213The BIGNUM referenced by B<val> is updated and is allocated if B<*val> is
214B<NULL>.
215
c2969ff6 216OSSL_PARAM_set_BN() stores the BIGNUM B<val> into the parameter B<p>.
8f3b8fd6
RL
217If the parameter's I<data> field is NULL, then only its I<return_size> field
218will be assigned the size the parameter's I<data> buffer should have.
7ffbd7ca
P
219
220OSSL_PARAM_get_utf8_string() retrieves a UTF8 string from the parameter
221pointed to by B<p>.
222The string is either stored into B<*val> with a length limit of B<max_len> or,
223in the case when B<*val> is B<NULL>, memory is allocated for the string and
224B<max_len> is ignored.
225If memory is allocated by this function, it must be freed by the caller.
226
227OSSL_PARAM_set_utf8_string() sets a UTF8 string from the parameter pointed to
228by B<p> to the value referenced by B<val>.
8f3b8fd6
RL
229If the parameter's I<data> field is NULL, then only its I<return_size> field
230will be assigned the size the parameter's I<data> buffer should have.
7ffbd7ca
P
231
232OSSL_PARAM_get_octet_string() retrieves an OCTET string from the parameter
233pointed to by B<p>.
234The OCTETs are either stored into B<*val> with a length limit of B<max_len> or,
235in the case when B<*val> is B<NULL>, memory is allocated and
236B<max_len> is ignored.
237If memory is allocated by this function, it must be freed by the caller.
238
239OSSL_PARAM_set_octet_string() sets an OCTET string from the parameter
240pointed to by B<p> to the value referenced by B<val>.
8f3b8fd6
RL
241If the parameter's I<data> field is NULL, then only its I<return_size> field
242will be assigned the size the parameter's I<data> buffer should have.
7ffbd7ca
P
243
244OSSL_PARAM_get_utf8_ptr() retrieves the UTF8 string pointer from the parameter
245referenced by B<p> and stores it in B<*val>.
246
247OSSL_PARAM_set_utf8_ptr() sets the UTF8 string pointer in the parameter
248referenced by B<p> to the values B<val>.
249
250OSSL_PARAM_get_octet_ptr() retrieves the OCTET string pointer from the parameter
251referenced by B<p> and stores it in B<*val>.
252The length of the OCTET string is stored in B<*used_len>.
253
254OSSL_PARAM_set_octet_ptr() sets the OCTET string pointer in the parameter
255referenced by B<p> to the values B<val>.
256The length of the OCTET string is provided by B<used_len>.
257
8d5fb648
P
258The OSSL_PARAM_UNMODIFIED macro is used to detect if a parameter was set. On
259creation, via either the macros or construct calls, the I<return_size> field
260is set to this. If the parameter is set using the calls defined herein, the
261I<return_size> field is changed.
262
3873887e
P
263OSSL_PARAM_modified() queries if the parameter B<param> has been set or not
264using the calls defined herein.
8d5fb648 265
3873887e
P
266OSSL_PARAM_set_all_unmodified() resets the unused indicator for all parameters
267in the array B<params>.
8d5fb648 268
7ffbd7ca
P
269=head1 RETURN VALUES
270
271OSSL_PARAM_construct_TYPE(), OSSL_PARAM_construct_BN(),
272OSSL_PARAM_construct_utf8_string(), OSSL_PARAM_construct_octet_string(),
273OSSL_PARAM_construct_utf8_ptr() and OSSL_PARAM_construct_octet_ptr()
274return a populated OSSL_PARAM structure.
275
4e7991b4
P
276OSSL_PARAM_locate() and OSSL_PARAM_locate_const() return a pointer to
277the matching OSSL_PARAM object. They return B<NULL> on error or when
278no object matching B<key> exists in the B<array>.
7ffbd7ca 279
8d5fb648
P
280OSSL_PARAM_modified() returns B<1> if the parameter was set and B<0> otherwise.
281
7ffbd7ca
P
282All other functions return B<1> on success and B<0> on failure.
283
284=head1 NOTES
285
9830e7ea
P
286Native types will be converted as required only if the value is exactly
287representable by the target type or parameter.
7ffbd7ca
P
288Apart from that, the functions must be used appropriately for the
289expected type of the parameter.
290
8f3b8fd6
RL
291For OSSL_PARAM_construct_utf8_ptr() and OSSL_PARAM_consstruct_octet_ptr(),
292B<bsize> is not relevant if the purpose is to send the B<OSSL_PARAM> array
293to a I<responder>, i.e. to get parameter data back.
f55ed701
RL
294In that case, B<bsize> can safely be given zero.
295See L<OSSL_PARAM(3)/DESCRIPTION> for further information on the
296possible purposes.
297
7ffbd7ca
P
298=head1 EXAMPLES
299
300Reusing the examples from L<OSSL_PARAM(3)> to just show how
301C<OSSL_PARAM> arrays can be handled using the macros and functions
302defined herein.
303
304=head2 Example 1
305
306This example is for setting parameters on some object:
307
308 #include <openssl/core.h>
309
310 const char *foo = "some string";
311 size_t foo_l = strlen(foo) + 1;
312 const char bar[] = "some other string";
313 const OSSL_PARAM set[] = {
314 OSSL_PARAM_utf8_ptr("foo", foo, foo_l),
315 OSSL_PARAM_utf8_string("bar", bar, sizeof(bar)),
316 OSSL_PARAM_END
317 };
318
319=head2 Example 2
320
16bfe6ce
RL
321This example is for requesting parameters on some object, and also
322demonstrates that the requestor isn't obligated to request all
323available parameters:
7ffbd7ca
P
324
325 const char *foo = NULL;
7ffbd7ca 326 char bar[1024];
4e7991b4
P
327 OSSL_PARAM request[] = {
328 OSSL_PARAM_utf8_ptr("foo", foo, 0),
329 OSSL_PARAM_utf8_string("bar", bar, sizeof(bar)),
7ffbd7ca
P
330 OSSL_PARAM_END
331 };
332
333A I<responder> that receives this array (as C<params> in this example)
334could fill in the parameters like this:
335
4e7991b4 336 /* OSSL_PARAM *params */
7ffbd7ca 337
4e7991b4 338 OSSL_PARAM *p;
16bfe6ce
RL
339
340 if ((p = OSSL_PARAM_locate(params, "foo")) == NULL)
341 OSSL_PARAM_set_utf8_ptr(p, "foo value");
342 if ((p = OSSL_PARAM_locate(params, "bar")) == NULL)
343 OSSL_PARAM_set_utf8_ptr(p, "bar value");
344 if ((p = OSSL_PARAM_locate(params, "cookie")) == NULL)
345 OSSL_PARAM_set_utf8_ptr(p, "cookie value");
7ffbd7ca
P
346
347=head1 SEE ALSO
348
349L<openssl-core.h(7)>, L<OSSL_PARAM(3)>
350
351=head1 HISTORY
352
4674aaf4 353These APIs were introduced in OpenSSL 3.0.
7ffbd7ca
P
354
355=head1 COPYRIGHT
356
33388b44 357Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
7ffbd7ca
P
358
359Licensed under the Apache License 2.0 (the "License"). You may not use
360this file except in compliance with the License. You can obtain a copy
361in the file LICENSE in the source distribution or at
362L<https://www.openssl.org/source/license.html>.
363
364=cut