summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/CRYPTO_set_ex_data.3
diff options
context:
space:
mode:
authorschwarze <>2023-09-18 14:49:43 +0000
committerschwarze <>2023-09-18 14:49:43 +0000
commit00e4137864cefcf6444cf38e75c42732dcda1684 (patch)
tree3323615e721a5d3b9e6fbe62dba7bfe09394ce09 /src/lib/libcrypto/man/CRYPTO_set_ex_data.3
parent647158289863bfec53e7444708536f0e5c277cc5 (diff)
downloadopenbsd-00e4137864cefcf6444cf38e75c42732dcda1684.tar.gz
openbsd-00e4137864cefcf6444cf38e75c42732dcda1684.tar.bz2
openbsd-00e4137864cefcf6444cf38e75c42732dcda1684.zip
Rewrite RSA_get_ex_new_index(3) and CRYPTO_set_ex_data(3) from scratch.
The defects of the old pages were too numerous to list in full but included vagueness, gaps, misleading statements, bad ordering, and duplication. Use my Copyright since none of the text we inherited from OpenSSL remains. Without doing a thorough review, tb@ thinks he likes the new pages after quickly reading through both of them.
Diffstat (limited to 'src/lib/libcrypto/man/CRYPTO_set_ex_data.3')
-rw-r--r--src/lib/libcrypto/man/CRYPTO_set_ex_data.3678
1 files changed, 438 insertions, 240 deletions
diff --git a/src/lib/libcrypto/man/CRYPTO_set_ex_data.3 b/src/lib/libcrypto/man/CRYPTO_set_ex_data.3
index abdef79d87..c22fb22352 100644
--- a/src/lib/libcrypto/man/CRYPTO_set_ex_data.3
+++ b/src/lib/libcrypto/man/CRYPTO_set_ex_data.3
@@ -1,70 +1,32 @@
1.\" $OpenBSD: CRYPTO_set_ex_data.3,v 1.14 2023/07/28 14:34:54 tb Exp $ 1.\" $OpenBSD: CRYPTO_set_ex_data.3,v 1.15 2023/09/18 14:49:43 schwarze Exp $
2.\" full merge up to:
3.\" OpenSSL CRYPTO_get_ex_new_index 9e183d22 Mar 11 08:56:44 2017 -0500
4.\" selective merge up to: 72a7a702 Feb 26 14:05:09 2019 +0000
5.\" 2.\"
6.\" This file was written by Dr. Stephen Henson <steve@openssl.org> 3.\" Copyright (c) 2023 Ingo Schwarze <schwarze@openbsd.org>
7.\" and by Rich Salz <rsalz@akamai.com>.
8.\" Copyright (c) 2000, 2006, 2015, 2016 The OpenSSL Project.
9.\" All rights reserved.
10.\" 4.\"
11.\" Redistribution and use in source and binary forms, with or without 5.\" Permission to use, copy, modify, and distribute this software for any
12.\" modification, are permitted provided that the following conditions 6.\" purpose with or without fee is hereby granted, provided that the above
13.\" are met: 7.\" copyright notice and this permission notice appear in all copies.
14.\" 8.\"
15.\" 1. Redistributions of source code must retain the above copyright 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16.\" notice, this list of conditions and the following disclaimer. 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17.\" 16.\"
18.\" 2. Redistributions in binary form must reproduce the above copyright 17.Dd $Mdocdate: September 18 2023 $
19.\" notice, this list of conditions and the following disclaimer in
20.\" the documentation and/or other materials provided with the
21.\" distribution.
22.\"
23.\" 3. All advertising materials mentioning features or use of this
24.\" software must display the following acknowledgment:
25.\" "This product includes software developed by the OpenSSL Project
26.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
27.\"
28.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
29.\" endorse or promote products derived from this software without
30.\" prior written permission. For written permission, please contact
31.\" openssl-core@openssl.org.
32.\"
33.\" 5. Products derived from this software may not be called "OpenSSL"
34.\" nor may "OpenSSL" appear in their names without prior written
35.\" permission of the OpenSSL Project.
36.\"
37.\" 6. Redistributions of any form whatsoever must retain the following
38.\" acknowledgment:
39.\" "This product includes software developed by the OpenSSL Project
40.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
41.\"
42.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
43.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
46.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53.\" OF THE POSSIBILITY OF SUCH DAMAGE.
54.\"
55.Dd $Mdocdate: July 28 2023 $
56.Dt CRYPTO_SET_EX_DATA 3 18.Dt CRYPTO_SET_EX_DATA 3
57.Os 19.Os
58.Sh NAME 20.Sh NAME
21.Nm CRYPTO_get_ex_new_index ,
59.Nm CRYPTO_EX_new , 22.Nm CRYPTO_EX_new ,
60.Nm CRYPTO_EX_free , 23.Nm CRYPTO_EX_free ,
61.Nm CRYPTO_EX_dup , 24.Nm CRYPTO_EX_dup ,
62.Nm CRYPTO_get_ex_new_index , 25.Nm CRYPTO_new_ex_data ,
63.Nm CRYPTO_set_ex_data , 26.Nm CRYPTO_set_ex_data ,
64.Nm CRYPTO_get_ex_data , 27.Nm CRYPTO_get_ex_data ,
65.Nm CRYPTO_free_ex_data , 28.Nm CRYPTO_free_ex_data
66.Nm CRYPTO_new_ex_data 29.Nd low-level functions for application specific data
67.Nd functions supporting application-specific data
68.Sh SYNOPSIS 30.Sh SYNOPSIS
69.In openssl/crypto.h 31.In openssl/crypto.h
70.Ft int 32.Ft int
@@ -79,7 +41,7 @@
79.Ft typedef int 41.Ft typedef int
80.Fo CRYPTO_EX_new 42.Fo CRYPTO_EX_new
81.Fa "void *parent" 43.Fa "void *parent"
82.Fa "void *ptr" 44.Fa "void *data"
83.Fa "CRYPTO_EX_DATA *ad" 45.Fa "CRYPTO_EX_DATA *ad"
84.Fa "int idx" 46.Fa "int idx"
85.Fa "long argl" 47.Fa "long argl"
@@ -88,7 +50,7 @@
88.Ft typedef void 50.Ft typedef void
89.Fo CRYPTO_EX_free 51.Fo CRYPTO_EX_free
90.Fa "void *parent" 52.Fa "void *parent"
91.Fa "void *ptr" 53.Fa "void *data"
92.Fa "CRYPTO_EX_DATA *ad" 54.Fa "CRYPTO_EX_DATA *ad"
93.Fa "int idx" 55.Fa "int idx"
94.Fa "long argl" 56.Fa "long argl"
@@ -98,7 +60,7 @@
98.Fo CRYPTO_EX_dup 60.Fo CRYPTO_EX_dup
99.Fa "CRYPTO_EX_DATA *to" 61.Fa "CRYPTO_EX_DATA *to"
100.Fa "const CRYPTO_EX_DATA *from" 62.Fa "const CRYPTO_EX_DATA *from"
101.Fa "void *from_d" 63.Fa "void *datap"
102.Fa "int idx" 64.Fa "int idx"
103.Fa "long argl" 65.Fa "long argl"
104.Fa "void *argp" 66.Fa "void *argp"
@@ -106,238 +68,336 @@
106.Ft int 68.Ft int
107.Fo CRYPTO_new_ex_data 69.Fo CRYPTO_new_ex_data
108.Fa "int class_index" 70.Fa "int class_index"
109.Fa "void *obj" 71.Fa "void *parent"
110.Fa "CRYPTO_EX_DATA *ad" 72.Fa "CRYPTO_EX_DATA *ad"
111.Fc 73.Fc
112.Ft int 74.Ft int
113.Fo CRYPTO_set_ex_data 75.Fo CRYPTO_set_ex_data
114.Fa "CRYPTO_EX_DATA *r" 76.Fa "CRYPTO_EX_DATA *ad"
115.Fa "int idx" 77.Fa "int idx"
116.Fa "void *arg" 78.Fa "void *data"
117.Fc 79.Fc
118.Ft void * 80.Ft void *
119.Fo CRYPTO_get_ex_data 81.Fo CRYPTO_get_ex_data
120.Fa "CRYPTO_EX_DATA *r" 82.Fa "CRYPTO_EX_DATA *ad"
121.Fa "int idx" 83.Fa "int idx"
122.Fc 84.Fc
123.Ft void 85.Ft void
124.Fo CRYPTO_free_ex_data 86.Fo CRYPTO_free_ex_data
125.Fa "int class_index" 87.Fa "int class_index"
126.Fa "void *obj" 88.Fa "void *parent"
127.Fa "CRYPTO_EX_DATA *r" 89.Fa "CRYPTO_EX_DATA *ad"
128.Fc 90.Fc
129.Sh DESCRIPTION 91.Sh DESCRIPTION
130Several OpenSSL structures can have application specific data attached 92The library implements the functions documented in the
131to them, known as "exdata". 93.Xr RSA_get_ex_new_index 3
132The specific structures are: 94manual page and similar functions for other parent object types
133.Bd -literal 95using the functions documented in the present manual page.
134 BIO 96Application programs almost never need
135 DH 97to call the functions documented here directly.
136 DSA
137 EC_KEY
138 ECDH
139 ECDSA
140 ENGINE
141 RSA
142 SSL
143 SSL_CTX
144 SSL_SESSION
145 UI
146 X509
147 X509_STORE
148 X509_STORE_CTX
149.Ed
150.Pp
151Each is identified by a
152.Dv CRYPTO_EX_INDEX_*
153constant defined in the
154.In openssl/crypto.h
155header file.
156.Pp
157The API described here is used by OpenSSL to manipulate exdata for
158specific structures.
159Since the application data can be anything at all, it is passed and
160retrieved as a
161.Vt void *
162type.
163.Pp 98.Pp
164To initialize the exdata part of a structure, call
165.Fn CRYPTO_new_ex_data .
166.Pp
167Exdata types are identified by an index, an integer guaranteed to
168be unique within structures for the lifetime of the program.
169Applications using exdata typically call
170.Fn CRYPTO_get_ex_new_index 99.Fn CRYPTO_get_ex_new_index
171at startup and store the result in a global variable, or write a 100behaves in the same way as
172wrapper function to provide lazy evaluation. 101.Xr RSA_get_ex_new_index 3
173The 102except that the parent object type that the new
103.Fa idx
104is reserved for is not part of the function name
105but instead specified by the additional
174.Fa class_index 106.Fa class_index
175should be one of the 107argument receiving one of the
176.Dv CRYPTO_EX_INDEX_* 108.Dv CRYPTO_EX_INDEX_*
177values. 109constants defined in
178The 110.In openssl/crypto.h .
111The recommendation given in
112.Xr RSA_get_ex_new_index 3
113to set the
114.Fa argl
115argument to 0 and the last four arguments all to
116.Dv NULL
117applies.
118The library passes the
179.Fa argl 119.Fa argl
180and 120and
181.Fa argp 121.Fa argp
182parameters are saved to be passed to the callbacks but are otherwise not 122arguments through to the callback functions for the respective
183used. 123.Fa idx ,
184In order to transparently manipulate exdata, three callbacks must be 124but ignores them otherwise.
185provided.
186The semantics of those callbacks are described below.
187.Pp
188When copying or releasing objects with exdata, the callback functions
189are called in increasing order of their index value.
190.Pp
191To set or get the exdata on an object, the appropriate type-specific
192routine must be used.
193This is because the containing structure is opaque and the
194.Vt CRYPTO_EX_DATA
195field is not accessible.
196In both APIs, the
197.Fa idx
198parameter should be an already-created index value.
199.Pp
200When setting exdata, the pointer specified with a particular index is
201saved, and returned on a subsequent "get" call.
202If the application is going to release the data, it must make sure to
203set a
204.Dv NULL
205value at the index, to avoid likely double-free crashes.
206.Pp
207The function
208.Fn CRYPTO_free_ex_data
209is used to free all exdata attached to a structure.
210The appropriate type-specific routine must be used.
211The
212.Fa class_index
213identifies the structure type, the
214.Fa obj
215is a pointer to the actual structure, and
216.Fa r
217is a pointer to the structure's exdata field.
218.Pp
219The callback functions are used as follows.
220.Pp 125.Pp
221When a structure is initially allocated (such as by 126If a function pointer is passed for the
222.Xr RSA_new 3 ) ,
223then
224.Fa new_func 127.Fa new_func
225is called for every defined index. 128argument, that function is called for the returned
226There is no requirement that the entire parent, or containing, structure 129.Fa idx
227has been set up. 130whenever a new parent object is allocated with
228The 131.Xr RSA_new 3
229.Fa new_func 132or a similar function.
230is typically used only to allocate memory to store the 133.Pp
231exdata, and perhaps an "initialized" flag within that memory. 134If a function pointer is passed for the
232The exdata value should be set by calling
233.Fn CRYPTO_set_ex_data .
234.Pp
235When a structure is free'd (such as by
236.Xr SSL_CTX_free 3 ) ,
237then the
238.Fa free_func
239is called for every defined index.
240Again, the state of the parent structure is not guaranteed.
241The
242.Fa free_func 135.Fa free_func
243may be called with a 136argument, that function is called for the returned
244.Dv NULL 137.Fa idx
245pointer. 138when a parent object is freed with
139.Xr RSA_free 3
140or a similar function.
246.Pp 141.Pp
247Both 142The arguments of
248.Fa new_func 143.Fa new_func
249and 144and
250.Fa free_func 145.Fa free_func
251take the same parameters. 146are as follows:
252The 147.Pp
148.Bl -tag -width Ds -compact
149.It Fa parent
150the parent object that contains the
151.Fa data
152.It Fa data
153the
154.Fa data
155previously set by
156.Fn CRYPTO_set_ex_data
157at
158.Fa idx
159in
253.Fa parent 160.Fa parent
254is the pointer to the structure that contains the exdata. 161.It Fa ad
255The 162the
256.Fa ptr 163.Vt CRYPTO_EX_DATA
257is the current exdata item; for 164subobject of the
258.Fa new_func 165.Fa parent
259this will typically be 166object
260.Dv NULL . 167.It Fa idx
261The 168return value of
262.Fa r 169.Fn CRYPTO_get_ex_new_index
263parameter is a pointer to the exdata field of the object. 170that set this callback
264The 171.It Fa argl
172the
173.Fa argl
174passed to
175.Fn CRYPTO_get_ex_new_index
176for this
265.Fa idx 177.Fa idx
266is the index and is the value returned when the callbacks were initially 178.It Fa argp
267registered via 179the
180.Fa argp
181passed to
268.Fn CRYPTO_get_ex_new_index 182.Fn CRYPTO_get_ex_new_index
269and can be used if the same callback handles different types of exdata. 183for this
184.Fa idx
185.El
270.Pp 186.Pp
271.Fa dup_func 187If a function pointer is passed for the
272is called when a structure is being copied. 188.Fa dup_func ,
273This is only done for 189that function is supposed to be called for the returned
274.Vt SSL 190.Fa idx
191whenever a parent object of the respective type is copied.
192Actually, the only functions doing that are
193.Xr BIO_dup_chain 3 ,
194.Xr EC_KEY_copy 3 ,
275and 195and
196.Xr SSL_dup 3 ,
197and the TLS 1.3 network stack does it internally when duplicating a
276.Vt SSL_SESSION 198.Vt SSL_SESSION
277objects. 199object after receiving a new session ticket message.
278The 200Most other object types supporting ex_data do not support
279.Fa to 201copying in the first place, whereas
202.Xr DSA_dup_DH 3
280and 203and
281.Fa from 204.Xr X509_dup 3
282parameters are pointers to the destination and source 205simply ignore
283.Vt CRYPTO_EX_DATA 206.Fa dup_func .
284structures, respectively. 207.Pp
285The 208The arguments of
286.Fa from_d
287parameter is a pointer to the source exdata.
288When
289.Fa dup_func 209.Fa dup_func
290returns, the value in 210are as follows:
291.Fa from_d 211.Pp
292is copied to the destination ex_data. 212.Bl -tag -width Ds -compact
293If the pointer contained in 213.It Fa to
294.Fa from_d 214the
295is not modified by the 215.Vt CRYPTO_EX_DATA
296.Fa dup_func , 216subobject of the new parent object
297then both 217.It Fa from
298.Fa to 218the
299and 219.Vt CRYPTO_EX_DATA
300.Fa from 220subobject of the original parent object
301will point to the same data. 221.It Fa datap
302The 222a pointer to a copy of the pointer to the original ex_data
303.Fa idx , 223.It Fa idx
224return value of
225.Fn CRYPTO_get_ex_new_index
226that set this callback
227.It Fa argl
228the
304.Fa argl 229.Fa argl
305and 230passed to
231.Fn CRYPTO_get_ex_new_index
232for this
233.Fa idx
234.It Fa argp
235the
306.Fa argp 236.Fa argp
307parameters are as described for the other two callbacks. 237passed to
238.Fn CRYPTO_get_ex_new_index
239for this
240.Fa idx
241.El
308.Pp 242.Pp
309.Fn CRYPTO_set_ex_data 243Inside
310is used to set application specific data. 244.Fa dup_func ,
311The data is supplied in the 245the
312.Fa arg 246.Fa data
313parameter and its precise meaning is up to the application. 247pointer contained in the original parent object being copied
248can be accessed by casting and dereferencing
249.Fa datap ,
250for example:
251.Pp
252.Dl char *orig_data = *(char **)datap;
253.Pp
254If the original data is copied, for example in a manner similar to
255.Bd -literal -offset indent
256char *new_data;
257if ((new_data = strdup(orig_data)) == NULL)
258 return 0;
259.Ed
260.Pp
261then the pointer to the newly allocated memory needs to be passed
262back to the caller in the
263.Fa datap
264argument, for example:
265.Bd -literal -offset indent
266*(char **)datap = new_data;
267return 1;
268.Ed
269.Pp
270Calling
271.Fn CRYPTO_set_ex_data to idx new_data
272from inside
273.Fa dup_func
274has no effect because the code calling
275.Fa dup_func
276unconditionally calls
277.Fn CRYPTO_set_ex_data to idx *datap
278after
279.Fa dup_func
280returns successfully.
281Consequently, if
282.Fa dup_func
283does not change
284.Pf * Fa datap ,
285the new parent object ends up containing a pointer to the same memory
286as the original parent object and any memory allocated in
287.Fa dup_func
288is leaked.
289.Pp
290When multiple callback functions are called,
291they are called in increasing order of their
292.Fa idx
293value.
294.Pp
295.Fn CRYPTO_new_ex_data
296is an internal function that initializes the
297.Fa ad
298subobject of the
299.Fa parent
300object, with the type of the parent object specified by the
301.Fa class_index
302argument.
303Initialization includes calling the respective
304.Fa new_func
305callbacks for all reserved
306.Fa idx
307values that have such callbacks configured.
308Despite its name,
309.Fn CRYPTO_new_ex_data
310does not create a new object but requires that
311.Fa ad
312points to an already allocated but still uninitialized object.
314.Pp 313.Pp
315.Fn CRYPTO_get_ex_data
316is used to retrieve application specific data.
317The data is returned to the application; this will be the same value as
318supplied to a previous
319.Fn CRYPTO_set_ex_data 314.Fn CRYPTO_set_ex_data
320call. 315and
316.Fn CRYPTO_get_ex_data
317behave in the same way as
318.Xr RSA_set_ex_data 3
319and
320.Xr RSA_get_ex_data 3 ,
321respectively, except that they do not accept a pointer
322to the parent object but instead require a pointer to the
323.Vt CRYPTO_EX_DATA
324subobject of that parent object.
325.Pp
326.Fn CRYPTO_free_ex_data
327is an internal function that frees any memory used inside the
328.Fa ad
329subobject of the
330.Fa parent
331object, with the type of the parent object specified by the
332.Fa class_index
333argument.
334This includes calling the respective
335.Fa free_func
336callbacks for all reserved
337.Fa idx
338values that have such callbacks configured.
339Despite its name,
340.Fn CRYPTO_free_ex_data
341does not free
342.Fa ad
343itself.
321.Sh RETURN VALUES 344.Sh RETURN VALUES
322.Fn CRYPTO_get_ex_new_index 345.Fn CRYPTO_get_ex_new_index
323returns a new index or -1 on failure; the value 0 is reserved for 346returns a new index equal to or greater than 1
324the legacy "app_data" APIs. 347or \-1 if memory allocation fails.
348.Pp
349.Fn CRYPTO_EX_new
350and
351.Fn CRYPTO_EX_dup
352functions are supposed to return 1 on success or 0 on failure.
325.Pp 353.Pp
354.Fn CRYPTO_new_ex_data
355and
326.Fn CRYPTO_set_ex_data 356.Fn CRYPTO_set_ex_data
327returns 1 on success or 0 on failure. 357return 1 on success or 0 if memory allocation fails.
328.Pp 358.Pp
329.Fn CRYPTO_get_ex_data 359.Fn CRYPTO_get_ex_data
330returns the application data or 360returns the application specific data or
331.Dv NULL
332on failure; note that
333.Dv NULL 361.Dv NULL
334may be a valid value. 362if the parent object that contains
363.Fa ad
364does not contain application specific data at the given
365.Fa idx .
366.Sh ERRORS
367After failure of
368.Fn CRYPTO_get_ex_new_index ,
369.Fn CRYPTO_new_ex_data ,
370or
371.Fn CRYPTO_set_ex_data ,
372the following diagnostic can be retrieved with
373.Xr ERR_get_error 3 ,
374.Xr ERR_GET_REASON 3 ,
375and
376.Xr ERR_reason_error_string 3 :
377.Bl -tag -width Ds
378.It Dv ERR_R_MALLOC_FAILURE Qq "malloc failure"
379Memory allocation failed.
380.El
335.Pp 381.Pp
336.Fa dup_func 382In a few unusual failure cases,
337should return 0 for failure and 1 for success. 383.Xr ERR_get_error 3
384may report different errors caused by
385.Xr OPENSSL_init_crypto 3
386or even none at all.
338.Pp 387.Pp
339On failure an error code can be obtained from 388Even though it cannot indicate failure,
389.Fn CRYPTO_free_ex_data
390may occasionally also set an error code that can be retrieved with
340.Xr ERR_get_error 3 . 391.Xr ERR_get_error 3 .
392.Pp
393.Fn CRYPTO_get_ex_data
394does not distinguish success from failure.
395Consequently, after
396.Fn CRYPTO_get_ex_data
397returns
398.Dv NULL ,
399.Xr ERR_get_error 3
400returns 0 unless there is still an earlier error in the queue.
341.Sh SEE ALSO 401.Sh SEE ALSO
342.Xr BIO_get_ex_new_index 3 , 402.Xr BIO_get_ex_new_index 3 ,
343.Xr DH_get_ex_new_index 3 , 403.Xr DH_get_ex_new_index 3 ,
@@ -350,11 +410,11 @@ On failure an error code can be obtained from
350.Xr X509_STORE_get_ex_new_index 3 410.Xr X509_STORE_get_ex_new_index 3
351.Sh HISTORY 411.Sh HISTORY
352.Fn CRYPTO_get_ex_new_index , 412.Fn CRYPTO_get_ex_new_index ,
413.Fn CRYPTO_new_ex_data ,
353.Fn CRYPTO_set_ex_data , 414.Fn CRYPTO_set_ex_data ,
354.Fn CRYPTO_get_ex_data , 415.Fn CRYPTO_get_ex_data ,
355.Fn CRYPTO_free_ex_data ,
356and 416and
357.Fn CRYPTO_new_ex_data 417.Fn CRYPTO_free_ex_data
358first appeared in SSLeay 0.9.0 and have been available since 418first appeared in SSLeay 0.9.0 and have been available since
359.Ox 2.4 . 419.Ox 2.4 .
360.Pp 420.Pp
@@ -364,3 +424,141 @@ and
364.Fn CRYPTO_EX_dup 424.Fn CRYPTO_EX_dup
365first appeared in OpenSSL 0.9.5 and have been available since 425first appeared in OpenSSL 0.9.5 and have been available since
366.Ox 2.7 . 426.Ox 2.7 .
427.Sh CAVEATS
428If an program installs callback functions, the last call to
429.Fn CRYPTO_get_ex_new_index
430installing a function of a certain type for a certain
431.Fa class_index
432needs to be complete before the first object of that
433.Fa class_index
434can be created, freed, or copied, respectively.
435Otherwise, incomplete initialization or cleanup will result.
436.Pp
437At the time
438.Fa new_func
439is called, the
440.Fa parent
441object is only partially initialized,
442so trying to access any data in it is strongly discouraged.
443The
444.Fa data
445argument is typically
446.Dv NULL
447in
448.Fa new_func .
449.Pp
450At the time
451.Fa free_func
452is called, the
453.Fa parent
454object is already mostly deconstructed
455and part of its content may have been cleared and freed.
456Consequently, trying to access any data in
457.Fa parent
458is strongly discouraged.
459According to the OpenSSL API documentation, the library code calling
460.Fa free_func
461would even be permitted to pass a
462.Dv NULL
463pointer for the
464.Fa parent
465argument.
466.Pp
467.Fn CRYPTO_set_ex_data
468and
469.Fn CRYPTO_get_ex_data
470cannot reasonably be used outside the callback functions
471because no API function provides access to any pointers of the type
472.Vt CRYPTO_EX_DATA * .
473.Pp
474Inside
475.Fa new_func ,
476calling
477.Fn CRYPTO_get_ex_data
478makes no sense because it always returns
479.Dv NULL ,
480and calling
481.Fn CRYPTO_set_ex_data
482makes no sense because
483.Fa new_func
484does not have access to any meaningful
485.Fa data
486it could store, and the absence of application specific data at any given
487.Fa idx
488is already sufficiently indicated by the default return value
489.Dv NULL
490of
491.Fn CRYPTO_get_ex_data ,
492.Xr RSA_get_ex_data 3 ,
493and similar functions.
494.Pp
495Inside
496.Fa free_func ,
497calling
498.Fn CRYPTO_get_ex_data
499makes no sense because the return value is already available in
500.Fa data ,
501and calling
502.Fn CRYPTO_set_ex_data
503makes no sense because the parent object, including any ex_data
504contained in it, is already being deconstructed and will no longer
505exist by the time application code regains control.
506.Pp
507Inside
508.Fa dup_func ,
509calling
510.Fn CRYPTO_get_ex_data
511makes no sense because the return value for
512.Fa from
513is already available as
514.Pf * Fa datap ,
515and the return value for
516.Fa to
517is
518.Dv NULL .
519Calling
520.Fn CRYPTO_set_ex_data
521makes no sense because changing
522.Fa from
523would cause an undesirable side effect in this context
524and trying to change
525.Fa to
526is ineffective as explained above.
527.Pp
528Consequently, application code can never use
529.Fn CRYPTO_set_ex_data
530or
531.Fn CRYPTO_get_ex_data
532in a meaningful way.
533.Pp
534The fact that the functions documented in the present manual page
535are part of the public API might create the impression
536that application programs could add ex_data support
537to additional object types not offering it by default.
538However, for built-in object types not offering ex_support, this
539is not possible because such objects do not contain the required
540.Vt CRYPTO_EX_DATA
541subobject.
542.Pp
543It is theoretically possible to add ex_data support to an
544application-defined object type by adding a
545.Vt CRYPTO_EX_DATA
546field to the struct declaration, a call to
547.Fn CRYPTO_new_ex_data
548to the object constructor, and a call to
549.Fn CRYPTO_free_ex_data
550to the object destructor.
551The OpenSSL documentation mentions that the constant
552.Dv CRYPTO_EX_INDEX_APP
553is reserved for this very purpose.
554However, doing this would hardly be useful.
555It is much more straightforward to just add
556all the required data fields to the struct declaration itself.
557.Sh BUGS
558If
559.Fa new_func
560or
561.Fa dup_func
562fails, the failure is silently ignored by the library, potentially
563resulting in an incompletely initialized object.
564The application program cannot detect this kind of failure.