]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/OSSL_PARAM_BLD_new.pod
NEWS: note OSSL_PARAM_BLD API as public.
[thirdparty/openssl.git] / doc / man3 / OSSL_PARAM_BLD_new.pod
CommitLineData
3c93fbac
P
1=pod
2
3=head1 NAME
4
be19d3ca 5OSSL_PARAM_BLD_new, OSSL_PARAM_BLD_to_param, OSSL_PARAM_BLD_free_params,
110bff61
P
6OSSL_PARAM_BLD_free, OSSL_PARAM_BLD_push_int, OSSL_PARAM_BLD_push_uint,
7OSSL_PARAM_BLD_push_long, OSSL_PARAM_BLD_push_ulong,
8OSSL_PARAM_BLD_push_int32, OSSL_PARAM_BLD_push_uint32,
9OSSL_PARAM_BLD_push_int64, OSSL_PARAM_BLD_push_uint64,
10OSSL_PARAM_BLD_push_size_t, OSSL_PARAM_BLD_push_double,
11OSSL_PARAM_BLD_push_BN, OSSL_PARAM_BLD_push_BN_pad,
12OSSL_PARAM_BLD_push_utf8_string, OSSL_PARAM_BLD_push_utf8_ptr,
13OSSL_PARAM_BLD_push_octet_string, OSSL_PARAM_BLD_push_octet_ptr
3c93fbac
P
14- functions to assist in the creation of OSSL_PARAM arrays
15
16=head1 SYNOPSIS
17
bb82531f 18=for openssl generic
3c93fbac 19
110bff61 20 #include "openssl/param_build.h"
3c93fbac
P
21
22 #define OSSL_PARAM_BLD_MAX 10
23 typedef struct { ... } OSSL_PARAM_BLD;
24
110bff61
P
25 void OSSL_PARAM_BLD_init(OSSL_PARAM_BLD *bld);
26 OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld);
be19d3ca
P
27 void OSSL_PARAM_BLD_free_params(OSSL_PARAM *params);
28 void OSSL_PARAM_BLD_free(OSSL_PARAM_BLD *bld);
3c93fbac 29
110bff61 30 int OSSL_PARAM_BLD_push_TYPE(OSSL_PARAM_BLD *bld, const char *key, TYPE val);
3c93fbac 31
110bff61 32 int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
3c93fbac 33 const BIGNUM *bn);
110bff61 34 int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
ac23078b 35 const BIGNUM *bn, size_t sz);
3c93fbac 36
110bff61 37 int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
5fa7789f 38 const char *buf, size_t bsize);
110bff61 39 int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
3c93fbac 40 char *buf, size_t bsize);
110bff61 41 int OSSL_PARAM_BLD_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
5fa7789f 42 const void *buf, size_t bsize);
110bff61 43 int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
3c93fbac
P
44 void *buf, size_t bsize);
45
46
47=head1 DESCRIPTION
48
49A collection of utility functions that simplify the creation of OSSL_PARAM
bbecf04e 50arrays. The B<I<TYPE>> names are as per L<OSSL_PARAM_int(3)>.
3c93fbac 51
110bff61 52OSSL_PARAM_BLD_init() initialises the OSSL_PARAM_BLD structure so that values
3c93fbac
P
53can be added.
54Any existing values are cleared.
55
be19d3ca
P
56OSSL_PARAM_BLD_free() deallocates the memory allocates by OSSL_PARAM_BLD_new().
57
110bff61 58OSSL_PARAM_BLD_to_param() converts a built up OSSL_PARAM_BLD structure
dfabee82 59I<bld> into an allocated OSSL_PARAM array.
7312ef3f 60The OSSL_PARAM array and all associated storage must be freed by calling
be19d3ca
P
61OSSL_PARAM_BLD_free_params() with the functions return value.
62OSSL_PARAM_BLD_free() can safely be called any time after this function is.
7312ef3f 63
be19d3ca 64OSSL_PARAM_BLD_free_params() deallocates the memory allocated by
110bff61 65OSSL_PARAM_BLD_to_param().
3c93fbac 66
c18d2d94
RL
67=begin comment
68
69POD is pretty good at recognising function names and making them appropriately
70bold... however, when part of the function name is variable, we have to help
71the processor along
72
73=end comment
74
110bff61 75B<OSSL_PARAM_BLD_push_I<TYPE>>() are a series of functions which will create
dfabee82 76OSSL_PARAM objects of the specified size and correct type for the I<val>
3c93fbac 77argument.
dfabee82 78I<val> is stored by value and an expression or auto variable can be used.
3c93fbac 79
110bff61 80OSSL_PARAM_BLD_push_BN() is a function that will create an OSSL_PARAM object
dfabee82 81that holds the specified BIGNUM I<bn>.
af61cbca 82If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
7312ef3f 83will also be securely allocated.
dfabee82 84The I<bn> argument is stored by reference and the underlying BIGNUM object
110bff61 85must exist until after OSSL_PARAM_BLD_to_param() has been called.
3c93fbac 86
110bff61 87OSSL_PARAM_BLD_push_BN_pad() is a function that will create an OSSL_PARAM object
ac23078b
P
88that holds the specified BIGNUM I<bn>.
89The object will be padded to occupy exactly I<sz> bytes, if insufficient space
90is specified an error results.
af61cbca 91If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
ac23078b
P
92will also be securely allocated.
93The I<bn> argument is stored by reference and the underlying BIGNUM object
110bff61 94must exist until after OSSL_PARAM_BLD_to_param() has been called.
ac23078b 95
110bff61 96OSSL_PARAM_BLD_push_utf8_string() is a function that will create an OSSL_PARAM
dfabee82
RL
97object that references the UTF8 string specified by I<buf>.
98If the length of the string, I<bsize>, is zero then it will be calculated.
99The string that I<buf> points to is stored by reference and must remain in
110bff61 100scope until after OSSL_PARAM_BLD_to_param() has been called.
3c93fbac 101
110bff61 102OSSL_PARAM_BLD_push_octet_string() is a function that will create an OSSL_PARAM
dfabee82
RL
103object that references the octet string specified by I<buf> and <bsize>.
104The memory that I<buf> points to is stored by reference and must remain in
110bff61 105scope until after OSSL_PARAM_BLD_to_param() has been called.
3c93fbac 106
110bff61 107OSSL_PARAM_BLD_push_utf8_ptr() is a function that will create an OSSL_PARAM
dfabee82
RL
108object that references the UTF8 string specified by I<buf>.
109If the length of the string, I<bsize>, is zero then it will be calculated.
110The string I<buf> points to is stored by reference and must remain in
3c93fbac
P
111scope until the OSSL_PARAM array is freed.
112
110bff61 113OSSL_PARAM_BLD_push_octet_ptr() is a function that will create an OSSL_PARAM
dfabee82
RL
114object that references the octet string specified by I<buf>.
115The memory I<buf> points to is stored by reference and must remain in
3c93fbac
P
116scope until the OSSL_PARAM array is freed.
117
118=head1 RETURN VALUES
119
110bff61 120OSSL_PARAM_BLD_to_param() returns the allocated OSSL_PARAM array, or NULL
903f5820 121on error.
3c93fbac 122
110bff61 123All of the OSSL_PARAM_BLD_push_TYPE functions return 1 on success and 0
3c93fbac
P
124on error.
125
126=head1 NOTES
127
128The constant B<OSSL_PARAM_BLD_MAX> specifies the maximum number of parameters
129that can be added.
130Exceeding this will result in the push functions returning errors.
110bff61
P
131The define used for this will always be at least 10 but otherwise no assumption
132should be made about it's specific value.
3c93fbac
P
133
134The structure B<OSSL_PARAM_BLD> should be considered opaque and subject to
135change between versions.
136
137=head1 EXAMPLES
138
139Both examples creating an OSSL_PARAM array that contains an RSA key.
140For both, the predefined key variables are:
141
142 BIGNUM *p, *q; /* both prime */
143 BIGNUM *n; /* = p * q */
144 unsigned int e; /* exponent, usually 65537 */
145 BIGNUM *d; /* e^-1 */
146
147=head2 Example 1
148
149This example shows how to create an OSSL_PARAM array that contains an RSA
150private key.
151
152 OSSL_PARAM_BLD bld;
153 OSSL_PARAM *params;
3c93fbac 154
110bff61
P
155 OSSL_PARAM_BLD_init(&bld, &secure);
156 if (!OSSL_PARAM_BLD_push_BN(&bld, "p", p)
157 || !OSSL_PARAM_BLD_push_BN(&bld, "q", q)
158 || !OSSL_PARAM_BLD_push_uint(&bld, "e", e)
159 || !OSSL_PARAM_BLD_push_BN(&bld, "n", n)
160 || !OSSL_PARAM_BLD_push_BN(&bld, "d", d)
161 || (params = OSSL_PARAM_BLD_to_param(&bld)) == NULL)
3c93fbac 162 goto err;
be19d3ca 163 OSSL_PARAM_BLD_free(bld);
3c93fbac
P
164 /* Use params */
165 ...
be19d3ca 166 OSSL_PARAM_BLD_free_params(params);
3c93fbac
P
167
168=head2 Example 2
169
170This example shows how to create an OSSL_PARAM array that contains an RSA
171public key.
172
173 OSSL_PARAM_BLD bld;
174 OSSL_PARAM *params;
3c93fbac 175
110bff61
P
176 OSSL_PARAM_BLD_init(&bld, &secure);
177 if (!OSSL_PARAM_BLD_push_BN(&bld, "n", n)
178 || !OSSL_PARAM_BLD_push_BN(&bld, "d", d)
179 || (params = OSSL_PARAM_BLD_to_param(&bld)) == NULL)
3c93fbac 180 goto err;
be19d3ca 181 OSSL_PARAM_BLD_free(bld);
3c93fbac
P
182 /* Use params */
183 ...
be19d3ca 184 OSSL_PARAM_BLD_free_params(params);
3c93fbac
P
185
186=head1 SEE ALSO
187
6e4618a0 188L<OSSL_PARAM_int(3)>, L<OSSL_PARAM(3)>
3c93fbac
P
189
190=head1 HISTORY
191
192The functions described here were all added in OpenSSL 3.0.
193
194=head1 COPYRIGHT
195
196Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
197
198Licensed under the Apache License 2.0 (the "License"). You may not use
199this file except in compliance with the License. You can obtain a copy
200in the file LICENSE in the source distribution or at
201L<https://www.openssl.org/source/license.html>.
202
203=cut