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