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,
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_locate, OSSL_PARAM_get_TYPE,
14 OSSL_PARAM_set_TYPE, OSSL_PARAM_get_BN, OSSL_PARAM_set_BN,
15 OSSL_PARAM_get_utf8_string, OSSL_PARAM_set_utf8_string,
16 OSSL_PARAM_get_octet_string, OSSL_PARAM_set_octet_string,
17 OSSL_PARAM_get_utf8_ptr, OSSL_PARAM_set_utf8_ptr, OSSL_PARAM_get_octet_ptr,
18 OSSL_PARAM_set_octet_ptr
23 #include <openssl/params.h>
25 #define OSSL_PARAM_TYPE(key, address)
26 #define OSSL_PARAM_utf8_string(key, address, size)
27 #define OSSL_PARAM_octet_string(key, address, size)
28 #define OSSL_PARAM_utf8_ptr(key, address, size)
29 #define OSSL_PARAM_octet_ptr(key, address, size)
30 #define OSSL_PARAM_SIZED_TYPE(key, address, return_size)
31 #define OSSL_PARAM_SIZED_BN(key, address, size, return_size)
32 #define OSSL_PARAM_SIZED_utf8_string(key, address, size, return_size)
33 #define OSSL_PARAM_SIZED_octet_string(key, address, size, return_size)
34 #define OSSL_PARAM_SIZED_utf8_ptr(key, address, size, return_size)
35 #define OSSL_PARAM_SIZED_octet_ptr(key, address, size, return_size)
36 #define OSSL_PARAM_END
38 OSSL_PARAM OSSL_PARAM_construct_TYPE(const char *key, TYPE *buf, size_t *ret);
39 OSSL_PARAM OSSL_PARAM_construct_BN(const char *key, unsigned char *buf,
40 size_t bsize, size_t *rsize);
41 OSSL_PARAM OSSL_PARAM_construct_utf8_string(const char *key, char *buf,
42 size_t bsize, size_t *rsize);
43 OSSL_PARAM OSSL_PARAM_construct_octet_string(const char *key, void *buf,
44 size_t bsize, size_t *rsize);
45 OSSL_PARAM OSSL_PARAM_construct_utf8_ptr(const char *key, char **buf,
47 OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
50 OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *array, const char *key);
52 int OSSL_PARAM_get_TYPE(const OSSL_PARAM *p, const char *key, TYPE *val);
53 int OSSL_PARAM_set_TYPE(const OSSL_PARAM *p, const char *key, TYPE val);
55 int OSSL_PARAM_get_BN(const OSSL_PARAM *p, const char *key, BIGNUM **val);
56 int OSSL_PARAM_set_BN(const OSSL_PARAM *p, const char *key, const BIGNUM *val);
58 int OSSL_PARAM_get_utf8_string(const OSSL_PARAM *p, char **val,
60 int OSSL_PARAM_set_utf8_string(const OSSL_PARAM *p, const char *val);
62 int OSSL_PARAM_get_octet_string(const OSSL_PARAM *p, void **val,
63 size_t max_len, size_t *used_len);
64 int OSSL_PARAM_set_octet_string(const OSSL_PARAM *p, const void *val,
67 int OSSL_PARAM_get_utf8_ptr(const OSSL_PARAM *p, char **val);
68 int OSSL_PARAM_set_utf8_ptr(const OSSL_PARAM *p, char *val);
70 int OSSL_PARAM_get_octet_ptr(const OSSL_PARAM *p, void **val,
72 int OSSL_PARAM_set_octet_ptr(const OSSL_PARAM *p, void *val, size_t used_len);
76 A collection of utility functions that simplify and add type safety to the
77 OSSL_PARAM arrays. The following B<TYPE> names are supported:
119 unsigned long int (ulong)
123 OSSL_PARAM_TYPE() are a series of macros designed to assist initialising an
124 array of OSSL_PARAM structures.
125 Each of these macros defines a parameter of the specified B<TYPE> with the
126 provided B<key> and parameter variable B<address>.
128 OSSL_PARAM_utf8_string(), OSSL_PARAM_octet_string(), OSSL_PARAM_utf8_ptr(),
129 OSSL_PARAM_octet_ptr() are macros that provide support for defining UTF8
130 strings and OCTET strings.
131 A parameter with name B<key> is defined.
132 The storage for this parameter is at B<address> and is of B<size> bytes.
134 OSSL_PARAM_SIZED_TYPE() are a second series of macros designed to assist with
135 the initialisation of OSSL_PARAM structures.
136 They are similar to the OSSL_PARAM_TYPE() macros but also include a
137 B<return_size> argument which contains the address of a size_t variable which
138 will be populated with the actual size of the parameter upon return from a
139 OSSL_PARAM_set_TYPE() call.
141 OSSL_PARAM_SIZED_BN(), OSSL_PARAM_SIZED_utf8_string(),
142 OSSL_PARAM_SIZED_octet_string(), OSSL_PARAM_SIZED_utf8_ptr(),
143 OSSL_PARAM_SIZED_octet_ptr() are macros that provide support for defining large
144 integers, UTF8 string and OCTET strings in an OSSL_PARAM array.
145 A parameter with name B<key> is defined.
146 The storage for this parameter is at B<address> and is of B<size> bytes.
147 The size used by the parameter value, in bytes, is written to B<return_size>.
149 OSSL_PARAM_END provides an end of parameter list marker.
150 This should terminate all OSSL_PARAM arrays.
152 OSSL_PARAM_construct_TYPE() are a series of functions that create OSSL_PARAM
154 A parameter with name B<key> is created.
155 The parameter will use storage pointed to by B<buf> and return size of B<ret>.
157 OSSL_PARAM_construct_BN() is a function that constructs a large integer
158 OSSL_PARAM structure.
159 A parameter with name B<key>, storage B<buf>, size B<bsize> and return
160 size B<rsize> is created.
162 OSSL_PARAM_construct_utf8_string() is a function that constructs a UTF8
163 string OSSL_PARAM structure.
164 A parameter with name B<key>, storage B<buf>, size B<bsize> and return
165 size B<rsize> is created.
167 OSSL_PARAM_construct_octet_string() is a function that constructs an OCTET
168 string OSSL_PARAM structure.
169 A parameter with name B<key>, storage B<buf>, size B<bsize> and return
170 size B<rsize> is created.
172 OSSL_PARAM_construct_utf8_ptr() is a function that constructes a UTF string
173 pointer OSSL_PARAM structure.
174 A parameter with name B<key>, storage pointer B<*buf> and return size B<rsize>
177 OSSL_PARAM_construct_octet_ptr() is a function that constructes an OCTET string
178 pointer OSSL_PARAM structure.
179 A parameter with name B<key>, storage pointer B<*buf> and return size B<rsize>
182 OSSL_PARAM_locate() is a function that searches an B<array> of parameters for
183 the one matching the B<key> name.
185 OSSL_PARAM_get_TYPE() retrieves a value of type B<TYPE> from the parameter B<p>.
186 The value is copied to the address B<val>.
187 Type coercion takes place as discussed in the NOTES section.
189 OSSL_PARAM_set_TYPE() stores a value B<val> of type B<TYPE> into the paramter
191 Type coercion takes place as discussed in the NOTES section.
193 OSSL_PARAM_get_BN() retrieves a BIGNUM from the parameter pointed to by B<p>.
194 The BIGNUM referenced by B<val> is updated and is allocated if B<*val> is
197 OSSL_PARAM_set_BN() stores the BIGNUM B<val> into the paramater B<p>.
199 OSSL_PARAM_get_utf8_string() retrieves a UTF8 string from the parameter
201 The string is either stored into B<*val> with a length limit of B<max_len> or,
202 in the case when B<*val> is B<NULL>, memory is allocated for the string and
203 B<max_len> is ignored.
204 If memory is allocated by this function, it must be freed by the caller.
206 OSSL_PARAM_set_utf8_string() sets a UTF8 string from the parameter pointed to
207 by B<p> to the value referenced by B<val>.
209 OSSL_PARAM_get_octet_string() retrieves an OCTET string from the parameter
211 The OCTETs are either stored into B<*val> with a length limit of B<max_len> or,
212 in the case when B<*val> is B<NULL>, memory is allocated and
213 B<max_len> is ignored.
214 If memory is allocated by this function, it must be freed by the caller.
216 OSSL_PARAM_set_octet_string() sets an OCTET string from the parameter
217 pointed to by B<p> to the value referenced by B<val>.
219 OSSL_PARAM_get_utf8_ptr() retrieves the UTF8 string pointer from the parameter
220 referenced by B<p> and stores it in B<*val>.
222 OSSL_PARAM_set_utf8_ptr() sets the UTF8 string pointer in the parameter
223 referenced by B<p> to the values B<val>.
225 OSSL_PARAM_get_octet_ptr() retrieves the OCTET string pointer from the parameter
226 referenced by B<p> and stores it in B<*val>.
227 The length of the OCTET string is stored in B<*used_len>.
229 OSSL_PARAM_set_octet_ptr() sets the OCTET string pointer in the parameter
230 referenced by B<p> to the values B<val>.
231 The length of the OCTET string is provided by B<used_len>.
235 OSSL_PARAM_construct_TYPE(), OSSL_PARAM_construct_BN(),
236 OSSL_PARAM_construct_utf8_string(), OSSL_PARAM_construct_octet_string(),
237 OSSL_PARAM_construct_utf8_ptr() and OSSL_PARAM_construct_octet_ptr()
238 return a populated OSSL_PARAM structure.
240 OSSL_PARAM_locate() returns a pointer to the matching OSSL_PARAM object.
241 It returns B<NULL> on error or when no object matching B<key> exists in
244 All other functions return B<1> on success and B<0> on failure.
248 Integral types will be widened and sign extended as required.
249 Apart from that, the functions must be used appropriately for the
250 expected type of the parameter.
254 Reusing the examples from L<OSSL_PARAM(3)> to just show how
255 C<OSSL_PARAM> arrays can be handled using the macros and functions
260 This example is for setting parameters on some object:
262 #include <openssl/core.h>
264 const char *foo = "some string";
265 size_t foo_l = strlen(foo) + 1;
266 const char bar[] = "some other string";
267 const OSSL_PARAM set[] = {
268 OSSL_PARAM_utf8_ptr("foo", foo, foo_l),
269 OSSL_PARAM_utf8_string("bar", bar, sizeof(bar)),
275 This example is for requesting parameters on some object:
277 const char *foo = NULL;
281 const OSSL_PARAM request[] = {
282 OSSL_PARAM_UTF8_PTR("foo", foo, 0, foo_l),
283 OSSL_PARAM_UTF8_STRING("bar", bar, sizeof(bar), bar_l),
287 A I<responder> that receives this array (as C<params> in this example)
288 could fill in the parameters like this:
290 /* const OSSL_PARAM *params */
292 OSSL_PARAM_set_utf8_ptr(OSSL_PARAM_locate(params, "foo"), "foo value");
293 OSSL_PARAM_set_utf8_string(OSSL_PARAM_locate(params, "bar"), "bar value");
297 L<openssl-core.h(7)>, L<OSSL_PARAM(3)>
301 These APIs were introduced in OpenSSL 3.0.0.
305 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
307 Licensed under the Apache License 2.0 (the "License"). You may not use
308 this file except in compliance with the License. You can obtain a copy
309 in the file LICENSE in the source distribution or at
310 L<https://www.openssl.org/source/license.html>.