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