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
40 #include <openssl/params.h>
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)
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)
55 #define OSSL_PARAM_END
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);
70 OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *array, const char *key);
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);
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);
78 int OSSL_PARAM_get_utf8_string(const OSSL_PARAM *p, char **val,
80 int OSSL_PARAM_set_utf8_string(const OSSL_PARAM *p, const char *val);
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,
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);
90 int OSSL_PARAM_get_octet_ptr(const OSSL_PARAM *p, void **val,
92 int OSSL_PARAM_set_octet_ptr(const OSSL_PARAM *p, void *val, size_t used_len);
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:
139 unsigned long int (ulong)
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>.
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.
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.
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>.
169 OSSL_PARAM_END provides an end of parameter list marker.
170 This should terminate all OSSL_PARAM arrays.
172 OSSL_PARAM_construct_TYPE() are a series of functions that create OSSL_PARAM
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>.
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.
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.
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.
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.
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.
202 OSSL_PARAM_construct_end() is a function that constructs the terminating
203 OSSL_PARAM structure.
205 OSSL_PARAM_locate() is a function that searches an B<array> of parameters for
206 the one matching the B<key> name.
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.
212 OSSL_PARAM_set_TYPE() stores a value B<val> of type B<TYPE> into the paramter
214 Type coercion takes place as discussed in the NOTES section.
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
220 OSSL_PARAM_set_BN() stores the BIGNUM B<val> into the paramater B<p>.
222 OSSL_PARAM_get_utf8_string() retrieves a UTF8 string from the parameter
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.
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>.
232 OSSL_PARAM_get_octet_string() retrieves an OCTET string from the parameter
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.
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>.
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>.
245 OSSL_PARAM_set_utf8_ptr() sets the UTF8 string pointer in the parameter
246 referenced by B<p> to the values B<val>.
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>.
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>.
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.
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
267 All other functions return B<1> on success and B<0> on failure.
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.
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
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
291 This example is for setting parameters on some object:
293 #include <openssl/core.h>
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)),
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:
310 const char *foo = NULL;
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),
320 A I<responder> that receives this array (as C<params> in this example)
321 could fill in the parameters like this:
323 /* const OSSL_PARAM *params */
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");
336 L<openssl-core.h(7)>, L<OSSL_PARAM(3)>
340 These APIs were introduced in OpenSSL 3.0.0.
344 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
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>.