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_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
24 #include <openssl/params.h>
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
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);
52 OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *array, const char *key);
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);
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);
60 int OSSL_PARAM_get_utf8_string(const OSSL_PARAM *p, char **val,
62 int OSSL_PARAM_set_utf8_string(const OSSL_PARAM *p, const char *val);
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,
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);
72 int OSSL_PARAM_get_octet_ptr(const OSSL_PARAM *p, void **val,
74 int OSSL_PARAM_set_octet_ptr(const OSSL_PARAM *p, void *val, size_t used_len);
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:
121 unsigned long int (ulong)
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>.
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.
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.
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>.
151 OSSL_PARAM_END provides an end of parameter list marker.
152 This should terminate all OSSL_PARAM arrays.
154 OSSL_PARAM_construct_TYPE() are a series of functions that create OSSL_PARAM
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>.
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.
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.
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.
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.
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.
184 OSSL_PARAM_construct_end() is a function that constructs the terminating
185 OSSL_PARAM structure.
187 OSSL_PARAM_locate() is a function that searches an B<array> of parameters for
188 the one matching the B<key> name.
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.
194 OSSL_PARAM_set_TYPE() stores a value B<val> of type B<TYPE> into the paramter
196 Type coercion takes place as discussed in the NOTES section.
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
202 OSSL_PARAM_set_BN() stores the BIGNUM B<val> into the paramater B<p>.
204 OSSL_PARAM_get_utf8_string() retrieves a UTF8 string from the parameter
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.
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>.
214 OSSL_PARAM_get_octet_string() retrieves an OCTET string from the parameter
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.
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>.
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>.
227 OSSL_PARAM_set_utf8_ptr() sets the UTF8 string pointer in the parameter
228 referenced by B<p> to the values B<val>.
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>.
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>.
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.
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
249 All other functions return B<1> on success and B<0> on failure.
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.
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
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
272 This example is for setting parameters on some object:
274 #include <openssl/core.h>
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)),
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:
291 const char *foo = NULL;
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),
301 A I<responder> that receives this array (as C<params> in this example)
302 could fill in the parameters like this:
304 /* const OSSL_PARAM *params */
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");
317 L<openssl-core.h(7)>, L<OSSL_PARAM(3)>
321 These APIs were introduced in OpenSSL 3.0.0.
325 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
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>.