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