5 ossl_param_bld_init, ossl_param_bld_to_param,
6 ossl_param_bld_free, ossl_param_bld_push_int, ossl_param_bld_push_uint,
7 ossl_param_bld_push_long, ossl_param_bld_push_ulong,
8 ossl_param_bld_push_int32, ossl_param_bld_push_uint32,
9 ossl_param_bld_push_int64, ossl_param_bld_push_uint64,
10 ossl_param_bld_push_size_t, ossl_param_bld_push_double,
11 ossl_param_bld_push_BN, ossl_param_bld_push_BN_pad,
12 ossl_param_bld_push_utf8_string, ossl_param_bld_push_utf8_ptr,
13 ossl_param_bld_push_octet_string, ossl_param_bld_push_octet_ptr
14 - functions to assist in the creation of OSSL_PARAM arrays
20 #include "internal/params_build.h"
22 #define OSSL_PARAM_BLD_MAX 10
23 typedef struct { ... } OSSL_PARAM_BLD;
25 void ossl_param_bld_init(OSSL_PARAM_BLD *bld);
26 OSSL_PARAM *ossl_param_bld_to_param(OSSL_PARAM_BLD *bld);
27 void ossl_param_bld_free(OSSL_PARAM *params);
29 int ossl_param_bld_push_TYPE(OSSL_PARAM_BLD *bld, const char *key, TYPE val);
31 int ossl_param_bld_push_BN(OSSL_PARAM_BLD *bld, const char *key,
33 int ossl_param_bld_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
34 const BIGNUM *bn, size_t sz);
36 int ossl_param_bld_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
37 const char *buf, size_t bsize);
38 int ossl_param_bld_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
39 char *buf, size_t bsize);
40 int ossl_param_bld_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
41 const void *buf, size_t bsize);
42 int ossl_param_bld_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
43 void *buf, size_t bsize);
48 A collection of utility functions that simplify the creation of OSSL_PARAM
49 arrays. The B<I<TYPE>> names are as per L<OSSL_PARAM_int(3)>.
51 ossl_param_bld_init() initialises the OSSL_PARAM_BLD structure so that values
53 Any existing values are cleared.
55 ossl_param_bld_to_param() converts a built up OSSL_PARAM_BLD structure
56 I<bld> into an allocated OSSL_PARAM array.
57 The OSSL_PARAM array and all associated storage must be freed by calling
58 ossl_param_bld_free() with the functions return value.
60 ossl_param_bld_free() deallocates the memory allocated by
61 ossl_param_bld_to_param().
65 POD is pretty good at recognising function names and making them appropriately
66 bold... however, when part of the function name is variable, we have to help
71 B<ossl_param_bld_push_I<TYPE>>() are a series of functions which will create
72 OSSL_PARAM objects of the specified size and correct type for the I<val>
74 I<val> is stored by value and an expression or auto variable can be used.
76 ossl_param_bld_push_BN() is a function that will create an OSSL_PARAM object
77 that holds the specified BIGNUM I<bn>.
78 If I<bn> is marked as being securely allocated, it's OSSL_PARAM representation
79 will also be securely allocated.
80 The I<bn> argument is stored by reference and the underlying BIGNUM object
81 must exist until after ossl_param_bld_to_param() has been called.
83 ossl_param_bld_push_BN_pad() is a function that will create an OSSL_PARAM object
84 that holds the specified BIGNUM I<bn>.
85 The object will be padded to occupy exactly I<sz> bytes, if insufficient space
86 is specified an error results.
87 If I<bn> is marked as being securely allocated, it's OSSL_PARAM representation
88 will also be securely allocated.
89 The I<bn> argument is stored by reference and the underlying BIGNUM object
90 must exist until after ossl_param_bld_to_param() has been called.
92 ossl_param_bld_push_utf8_string() is a function that will create an OSSL_PARAM
93 object that references the UTF8 string specified by I<buf>.
94 If the length of the string, I<bsize>, is zero then it will be calculated.
95 The string that I<buf> points to is stored by reference and must remain in
96 scope until after ossl_param_bld_to_param() has been called.
98 ossl_param_bld_push_octet_string() is a function that will create an OSSL_PARAM
99 object that references the octet string specified by I<buf> and <bsize>.
100 The memory that I<buf> points to is stored by reference and must remain in
101 scope until after ossl_param_bld_to_param() has been called.
103 ossl_param_bld_push_utf8_ptr() is a function that will create an OSSL_PARAM
104 object that references the UTF8 string specified by I<buf>.
105 If the length of the string, I<bsize>, is zero then it will be calculated.
106 The string I<buf> points to is stored by reference and must remain in
107 scope until the OSSL_PARAM array is freed.
109 ossl_param_bld_push_octet_ptr() is a function that will create an OSSL_PARAM
110 object that references the octet string specified by I<buf>.
111 The memory I<buf> points to is stored by reference and must remain in
112 scope until the OSSL_PARAM array is freed.
116 ossl_param_bld_to_param() returns the allocated OSSL_PARAM array, or NULL
119 All of the ossl_param_bld_push_TYPE functions return 1 on success and 0
124 The constant B<OSSL_PARAM_BLD_MAX> specifies the maximum number of parameters
126 Exceeding this will result in the push functions returning errors.
128 The structure B<OSSL_PARAM_BLD> should be considered opaque and subject to
129 change between versions.
133 Both examples creating an OSSL_PARAM array that contains an RSA key.
134 For both, the predefined key variables are:
136 BIGNUM *p, *q; /* both prime */
137 BIGNUM *n; /* = p * q */
138 unsigned int e; /* exponent, usually 65537 */
139 BIGNUM *d; /* e^-1 */
143 This example shows how to create an OSSL_PARAM array that contains an RSA
149 ossl_param_bld_init(&bld, &secure);
150 if (!ossl_param_bld_push_BN(&bld, "p", p)
151 || !ossl_param_bld_push_BN(&bld, "q", q)
152 || !ossl_param_bld_push_uint(&bld, "e", e)
153 || !ossl_param_bld_push_BN(&bld, "n", n)
154 || !ossl_param_bld_push_BN(&bld, "d", d)
155 || (params = ossl_param_bld_to_param(&bld)) == NULL)
159 ossl_param_bld_free(params);
163 This example shows how to create an OSSL_PARAM array that contains an RSA
169 ossl_param_bld_init(&bld, &secure);
170 if (!ossl_param_bld_push_BN(&bld, "n", n)
171 || !ossl_param_bld_push_BN(&bld, "d", d)
172 || (params = ossl_param_bld_to_param(&bld)) == NULL)
176 ossl_param_bld_free(params);
180 L<OSSL_PARAM_int(3)>, L<OSSL_PARAM(3)>
184 The functions described here were all added in OpenSSL 3.0.
188 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
190 Licensed under the Apache License 2.0 (the "License"). You may not use
191 this file except in compliance with the License. You can obtain a copy
192 in the file LICENSE in the source distribution or at
193 L<https://www.openssl.org/source/license.html>.