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