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