]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/CRYPTO_get_ex_new_index.pod
Fix many doc L<> errors
[thirdparty/openssl.git] / doc / man3 / CRYPTO_get_ex_new_index.pod
CommitLineData
e6390aca
RS
1=pod
2
3=head1 NAME
4
c952780c 5CRYPTO_EX_new, CRYPTO_EX_free, CRYPTO_EX_dup,
e6390aca 6CRYPTO_free_ex_index, CRYPTO_get_ex_new_index, CRYPTO_set_ex_data,
c952780c 7CRYPTO_get_ex_data, CRYPTO_free_ex_data, CRYPTO_new_ex_data
e6390aca
RS
8- functions supporting application-specific data
9
10=head1 SYNOPSIS
11
12 #include <openssl/crypto.h>
13
14 int CRYPTO_get_ex_new_index(int class_index,
15 long argl, void *argp,
1bc74519
RS
16 CRYPTO_EX_new *new_func,
17 CRYPTO_EX_dup *dup_func,
18 CRYPTO_EX_free *free_func);
e6390aca
RS
19
20 typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp);
22 typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
23 int idx, long argl, void *argp);
3c853776 24 typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from,
e6390aca
RS
25 void *from_d, int idx, long argl, void *argp);
26
c952780c
RS
27 int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
28
e6390aca
RS
29 int CRYPTO_set_ex_data(CRYPTO_EX_DATA *r, int idx, void *arg);
30
31 void *CRYPTO_get_ex_data(CRYPTO_EX_DATA *r, int idx);
32
33 void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *r);
34
35 int CRYPTO_free_ex_index(int class_index, int idx);
36
37=head1 DESCRIPTION
38
39Several OpenSSL structures can have application-specific data attached to them,
40known as "exdata."
41The specific structures are:
42
43 SSL
44 SSL_CTX
45 SSL_SESSION
46 X509
47 X509_STORE
48 X509_STORE_CTX
49 DH
50 DSA
3aef36ff 51 EC_KEY
e6390aca
RS
52 RSA
53 ENGINE
54 UI
18cfc668 55 UI_METHOD
e6390aca
RS
56 BIO
57
58Each is identified by an B<CRYPTO_EX_INDEX_xxx> define in the B<crypto.h>
59header file. In addition, B<CRYPTO_EX_INDEX_APP> is reserved for
60applications to use this facility for their own structures.
61
62The API described here is used by OpenSSL to manipulate exdata for specific
63structures. Since the application data can be anything at all it is passed
64and retrieved as a B<void *> type.
65
c952780c
RS
66The B<CRYPTO_EX_DATA> type is opaque. To initialize the exdata part of
67a structure, call CRYPTO_new_ex_data(). This is only necessary for
68B<CRYPTO_EX_INDEX_APP> objects.
69
e6390aca
RS
70Exdata types are identified by an B<index>, an integer guaranteed to be
71unique within structures for the lifetime of the program. Applications
72using exdata typically call B<CRYPTO_get_ex_new_index> at startup, and
73store the result in a global variable, or write a wrapper function to
74provide lazy evaluation. The B<class_index> should be one of the
75B<CRYPTO_EX_INDEX_xxx> values. The B<argl> and B<argp> parameters are saved
76to be passed to the callbacks but are otherwise not used. In order to
77transparently manipulate exdata, three callbacks must be provided. The
78semantics of those callbacks are described below.
79
80When copying or releasing objects with exdata, the callback functions
81are called in increasing order of their B<index> value.
82
83If a dynamic library can be unloaded, it should call CRYPTO_free_ex_index()
84when this is done.
85This will replace the callbacks with no-ops
86so that applications don't crash. Any existing exdata will be leaked.
87
88To set or get the exdata on an object, the appropriate type-specific
89routine must be used. This is because the containing structure is opaque
90and the B<CRYPTO_EX_DATA> field is not accessible. In both API's, the
91B<idx> parameter should be an already-created index value.
92
93When setting exdata, the pointer specified with a particular index is saved,
94and returned on a subsequent "get" call. If the application is going to
95release the data, it must make sure to set a B<NULL> value at the index,
d3054fb6 96to avoid likely double-free crashes.
e6390aca
RS
97
98The function B<CRYPTO_free_ex_data> is used to free all exdata attached
99to a structure. The appropriate type-specific routine must be used.
100The B<class_index> identifies the structure type, the B<obj> is
101be the pointer to the actual structure, and B<r> is a pointer to the
102structure's exdata field.
103
104=head2 Callback Functions
105
106This section describes how the callback functions are used. Applications
107that are defining their own exdata using B<CYPRTO_EX_INDEX_APP> must
108call them as described here.
109
110When a structure is initially allocated (such as RSA_new()) then the
111new_func() is called for every defined index. There is no requirement
112that the entire parent, or containing, structure has been set up.
113The new_func() is typically used only to allocate memory to store the
114exdata, and perhaps an "initialized" flag within that memory.
115The exdata value should be set by calling CRYPTO_set_ex_data().
116
117When a structure is free'd (such as SSL_CTX_free()) then the
118free_func() is called for every defined index. Again, the state of the
119parent structure is not guaranteed. The free_func() may be called with a
120NULL pointer.
121
122Both new_func() and free_func() take the same parameters.
123The B<parent> is the pointer to the structure that contains the exdata.
124The B<ptr> is the current exdata item; for new_func() this will typically
125be NULL. The B<r> parameter is a pointer to the exdata field of the object.
126The B<idx> is the index and is the value returned when the callbacks were
127initially registered via CRYPTO_get_ex_new_index() and can be used if
128the same callback handles different types of exdata.
129
130dup_func() is called when a structure is being copied. This is only done
131for B<SSL> and B<SSL_SESSION> objects. The B<to> and B<from> parameters
132are pointers to the destination and source B<CRYPTO_EX_DATA> structures,
133respectively. The B<srcp> parameter is a pointer to the source exdata.
134When the dup_func() returns, the value in B<srcp> is copied to the
d3054fb6
BK
135destination ex_data. If the pointer contained in B<srcp> is not modified
136by the dup_func(), then both B<to> and B<from> will point to the same data.
137The B<idx>, B<argl> and B<argp> parameters are as described for the other
138two callbacks.
e6390aca
RS
139
140=head1 RETURN VALUES
141
142CRYPTO_get_ex_new_index() returns a new index or -1 on failure; the
143value B<0> is reserved for the legacy "app_data" API's.
144
145CRYPTO_free_ex_index() and
146CRYPTO_set_ex_data() return 1 on success or 0 on failure.
147
148CRYPTO_get_ex_data() returns the application data or NULL on failure;
149note that NULL may be a valid value.
150
151dup_func() should return 0 for failure and 1 for success.
152
e2f92610
RS
153=head1 COPYRIGHT
154
9e183d22 155Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved.
e2f92610
RS
156
157Licensed under the OpenSSL license (the "License"). You may not use
158this file except in compliance with the License. You can obtain a copy
159in the file LICENSE in the source distribution or at
160L<https://www.openssl.org/source/license.html>.
161
162=cut