1CRYPTO_GET_EX_NEW_INDEX(3ossl)      OpenSSL     CRYPTO_GET_EX_NEW_INDEX(3ossl)
2
3
4

NAME

6       CRYPTO_EX_new, CRYPTO_EX_free, CRYPTO_EX_dup, CRYPTO_free_ex_index,
7       CRYPTO_get_ex_new_index, CRYPTO_alloc_ex_data, CRYPTO_set_ex_data,
8       CRYPTO_get_ex_data, CRYPTO_free_ex_data, CRYPTO_new_ex_data - functions
9       supporting application-specific data
10

SYNOPSIS

12        #include <openssl/crypto.h>
13
14        int CRYPTO_get_ex_new_index(int class_index,
15                                    long argl, void *argp,
16                                    CRYPTO_EX_new *new_func,
17                                    CRYPTO_EX_dup *dup_func,
18                                    CRYPTO_EX_free *free_func);
19
20        typedef void 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);
24        typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from,
25                                  void **from_d, int idx, long argl, void *argp);
26
27        int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
28
29        int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad,
30                                 int idx);
31
32        int CRYPTO_set_ex_data(CRYPTO_EX_DATA *r, int idx, void *arg);
33
34        void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *r, int idx);
35
36        void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *r);
37
38        int CRYPTO_free_ex_index(int class_index, int idx);
39

DESCRIPTION

41       Several OpenSSL structures can have application-specific data attached
42       to them, known as "exdata."  The specific structures are:
43
44           BIO
45           DH
46           DSA
47           EC_KEY
48           ENGINE
49           EVP_PKEY
50           RSA
51           SSL
52           SSL_CTX
53           SSL_SESSION
54           UI
55           UI_METHOD
56           X509
57           X509_STORE
58           X509_STORE_CTX
59
60       In addition, the APP name is reserved for use by application code.
61
62       Each is identified by an CRYPTO_EX_INDEX_xxx define in the header file
63       <openssl/crypto.h>.  In addition, CRYPTO_EX_INDEX_APP is reserved for
64       applications to use this facility for their own structures.
65
66       The API described here is used by OpenSSL to manipulate exdata for
67       specific structures.  Since the application data can be anything at all
68       it is passed and retrieved as a void * type.
69
70       The CRYPTO_EX_DATA type is opaque.  To initialize the exdata part of a
71       structure, call CRYPTO_new_ex_data(). This is only necessary for
72       CRYPTO_EX_INDEX_APP objects.
73
74       Exdata types are identified by an index, an integer guaranteed to be
75       unique within structures for the lifetime of the program.  Applications
76       using exdata typically call CRYPTO_get_ex_new_index at startup, and
77       store the result in a global variable, or write a wrapper function to
78       provide lazy evaluation.  The class_index should be one of the
79       CRYPTO_EX_INDEX_xxx values. The argl and argp parameters are saved to
80       be passed to the callbacks but are otherwise not used.  In order to
81       transparently manipulate exdata, three callbacks must be provided. The
82       semantics of those callbacks are described below.
83
84       When copying or releasing objects with exdata, the callback functions
85       are called in increasing order of their index value.
86
87       If a dynamic library can be unloaded, it should call
88       CRYPTO_free_ex_index() when this is done.  This will replace the
89       callbacks with no-ops so that applications don't crash.  Any existing
90       exdata will be leaked.
91
92       To set or get the exdata on an object, the appropriate type-specific
93       routine must be used.  This is because the containing structure is
94       opaque and the CRYPTO_EX_DATA field is not accessible.  In both API's,
95       the idx parameter should be an already-created index value.
96
97       When setting exdata, the pointer specified with a particular index is
98       saved, and returned on a subsequent "get" call.  If the application is
99       going to release the data, it must make sure to set a NULL value at the
100       index, to avoid likely double-free crashes.
101
102       The function CRYPTO_free_ex_data is used to free all exdata attached to
103       a structure. The appropriate type-specific routine must be used.  The
104       class_index identifies the structure type, the obj is a pointer to the
105       actual structure, and r is a pointer to the structure's exdata field.
106
107   Callback Functions
108       This section describes how the callback functions are used.
109       Applications that are defining their own exdata using
110       CYPRTO_EX_INDEX_APP must call them as described here.
111
112       When a structure is initially allocated (such as RSA_new()) then the
113       new_func() is called for every defined index. There is no requirement
114       that the entire parent, or containing, structure has been set up.  The
115       new_func() is typically used only to allocate memory to store the
116       exdata, and perhaps an "initialized" flag within that memory.  The
117       exdata value may be allocated later on with CRYPTO_alloc_ex_data(), or
118       may be set by calling CRYPTO_set_ex_data().
119
120       When a structure is free'd (such as SSL_CTX_free()) then the
121       free_func() is called for every defined index.  Again, the state of the
122       parent structure is not guaranteed.  The free_func() may be called with
123       a NULL pointer.
124
125       Both new_func() and free_func() take the same parameters.  The parent
126       is the pointer to the structure that contains the exdata.  The ptr is
127       the current exdata item; for new_func() this will typically be NULL.
128       The r parameter is a pointer to the exdata field of the object.  The
129       idx is the index and is the value returned when the callbacks were
130       initially registered via CRYPTO_get_ex_new_index() and can be used if
131       the same callback handles different types of exdata.
132
133       dup_func() is called when a structure is being copied.  This is only
134       done for SSL, SSL_SESSION, EC_KEY objects and BIO chains via
135       BIO_dup_chain().  The to and from parameters are pointers to the
136       destination and source CRYPTO_EX_DATA structures, respectively.  The
137       *from_d parameter is a pointer to the source exdata.  When the
138       dup_func() returns, the value in *from_d is copied to the destination
139       ex_data.  If the pointer contained in *pptr is not modified by the
140       dup_func(), then both to and from will point to the same data.  The
141       idx, argl and argp parameters are as described for the other two
142       callbacks.  If the dup_func() returns 0 the whole CRYPTO_dup_ex_data()
143       will fail.
144

RETURN VALUES

146       CRYPTO_get_ex_new_index() returns a new index or -1 on failure.
147
148       CRYPTO_free_ex_index(), CRYPTO_alloc_ex_data() and CRYPTO_set_ex_data()
149       return 1 on success or 0 on failure.
150
151       CRYPTO_get_ex_data() returns the application data or NULL on failure;
152       note that NULL may be a valid value.
153
154       dup_func() should return 0 for failure and 1 for success.
155

HISTORY

157       CRYPTO_alloc_ex_data() was added in OpenSSL 3.0.
158
159       The signature of the dup_func() callback was changed in OpenSSL 3.0 to
160       use the type void ** for from_d.  Previously this parameter was of type
161       void *.
162
163       Support for ENGINE "exdata" was deprecated in OpenSSL 3.0.
164
166       Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
167
168       Licensed under the Apache License 2.0 (the "License").  You may not use
169       this file except in compliance with the License.  You can obtain a copy
170       in the file LICENSE in the source distribution or at
171       <https://www.openssl.org/source/license.html>.
172
173
174
1753.1.1                             2023-08-31    CRYPTO_GET_EX_NEW_INDEX(3ossl)
Impressum