Debian Codegraph @

upstream/debian-unstable/man3/OPENSSL_init_crypto.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "OPENSSL_INIT_CRYPTO 3SSL"
58 .TH OPENSSL_INIT_CRYPTO 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 OPENSSL_INIT_new, OPENSSL_INIT_set_config_filename,
65 OPENSSL_INIT_set_config_appname, OPENSSL_INIT_set_config_file_flags,
66 OPENSSL_INIT_free, OPENSSL_init_crypto, OPENSSL_cleanup, OPENSSL_atexit,
67 OPENSSL_thread_stop_ex, OPENSSL_thread_stop \- OpenSSL initialisation
68 and deinitialisation functions
69 .SH SYNOPSIS
70 .IX Header "SYNOPSIS"
71 .Vb 1
72 \& #include <openssl/crypto.h>
73 \&
74 \& void OPENSSL_cleanup(void);
75 \& int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);
76 \& int OPENSSL_atexit(void (*handler)(void));
77 \& void OPENSSL_thread_stop_ex(OSSL_LIB_CTX *ctx);
78 \& void OPENSSL_thread_stop(void);
79 \&
80 \& OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void);
81 \& int OPENSSL_INIT_set_config_filename(OPENSSL_INIT_SETTINGS *init,
82 \& const char* filename);
83 \& int OPENSSL_INIT_set_config_file_flags(OPENSSL_INIT_SETTINGS *init,
84 \& unsigned long flags);
85 \& int OPENSSL_INIT_set_config_appname(OPENSSL_INIT_SETTINGS *init,
86 \& const char* name);
87 \& void OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *init);
88 .Ve
89 .SH DESCRIPTION
90 .IX Header "DESCRIPTION"
91 During normal operation OpenSSL (libcrypto) will allocate various resources at
92 start up that must, subsequently, be freed on close down of the library.
93 Additionally some resources are allocated on a per thread basis (if the
94 application is multi-threaded), and these resources must be freed prior to the
95 thread closing.
96 .PP
97 As of version 1.1.0 OpenSSL will automatically allocate all resources that it
98 needs so no explicit initialisation is required. Similarly it will also
99 automatically deinitialise as required.
100 .PP
101 However, there may be situations when explicit initialisation is desirable or
102 needed, for example when some nondefault initialisation is required. The
103 function \fBOPENSSL_init_crypto()\fR can be used for this purpose for
104 libcrypto (see also \fBOPENSSL_init_ssl\fR\|(3) for the libssl
105 equivalent).
106 .PP
107 Numerous internal OpenSSL functions call \fBOPENSSL_init_crypto()\fR.
108 Therefore, in order to perform nondefault initialisation,
109 \&\fBOPENSSL_init_crypto()\fR MUST be called by application code prior to
110 any other OpenSSL function calls.
111 .PP
112 The \fBopts\fR parameter specifies which aspects of libcrypto should be
113 initialised. Valid options are:
114 .IP OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 4
115 .IX Item "OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS"
116 Suppress automatic loading of the libcrypto error strings. This option is
117 not a default option. Once selected subsequent calls to
118 \&\fBOPENSSL_init_crypto()\fR with the option
119 \&\fBOPENSSL_INIT_LOAD_CRYPTO_STRINGS\fR will be ignored.
120 .IP OPENSSL_INIT_LOAD_CRYPTO_STRINGS 4
121 .IX Item "OPENSSL_INIT_LOAD_CRYPTO_STRINGS"
122 Automatic loading of the libcrypto error strings. With this option the
123 library will automatically load the libcrypto error strings.
124 This option is a default option. Once selected subsequent calls to
125 \&\fBOPENSSL_init_crypto()\fR with the option
126 \&\fBOPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS\fR will be ignored.
127 .IP OPENSSL_INIT_ADD_ALL_CIPHERS 4
128 .IX Item "OPENSSL_INIT_ADD_ALL_CIPHERS"
129 With this option the library will automatically load and make available all
130 libcrypto ciphers. This option is a default option. Once selected subsequent
131 calls to \fBOPENSSL_init_crypto()\fR with the option
132 \&\fBOPENSSL_INIT_NO_ADD_ALL_CIPHERS\fR will be ignored.
133 .IP OPENSSL_INIT_ADD_ALL_DIGESTS 4
134 .IX Item "OPENSSL_INIT_ADD_ALL_DIGESTS"
135 With this option the library will automatically load and make available all
136 libcrypto digests. This option is a default option. Once selected subsequent
137 calls to \fBOPENSSL_init_crypto()\fR with the option
138 \&\fBOPENSSL_INIT_NO_ADD_ALL_DIGESTS\fR will be ignored.
139 .IP OPENSSL_INIT_NO_ADD_ALL_CIPHERS 4
140 .IX Item "OPENSSL_INIT_NO_ADD_ALL_CIPHERS"
141 With this option the library will suppress automatic loading of libcrypto
142 ciphers. This option is not a default option. Once selected subsequent
143 calls to \fBOPENSSL_init_crypto()\fR with the option
144 \&\fBOPENSSL_INIT_ADD_ALL_CIPHERS\fR will be ignored.
145 .IP OPENSSL_INIT_NO_ADD_ALL_DIGESTS 4
146 .IX Item "OPENSSL_INIT_NO_ADD_ALL_DIGESTS"
147 With this option the library will suppress automatic loading of libcrypto
148 digests. This option is not a default option. Once selected subsequent
149 calls to \fBOPENSSL_init_crypto()\fR with the option
150 \&\fBOPENSSL_INIT_ADD_ALL_DIGESTS\fR will be ignored.
151 .IP OPENSSL_INIT_LOAD_CONFIG 4
152 .IX Item "OPENSSL_INIT_LOAD_CONFIG"
153 With this option an OpenSSL configuration file will be automatically loaded and
154 used by calling \fBOPENSSL_config()\fR. This is a default option.
155 Note that in OpenSSL 1.1.1 this was the default for libssl but not for
156 libcrypto (see \fBOPENSSL_init_ssl\fR\|(3) for further details about libssl
157 initialisation).
158 In OpenSSL 1.1.0 this was a nondefault option for both libssl and libcrypto.
159 See the description of \fBOPENSSL_INIT_new()\fR, below.
160 .IP OPENSSL_INIT_NO_LOAD_CONFIG 4
161 .IX Item "OPENSSL_INIT_NO_LOAD_CONFIG"
162 With this option the loading of OpenSSL configuration files will be suppressed.
163 It is the equivalent of calling \fBOPENSSL_no_config()\fR. This is not a default
164 option.
165 .IP OPENSSL_INIT_ASYNC 4
166 .IX Item "OPENSSL_INIT_ASYNC"
167 With this option the library with automatically initialise the libcrypto async
168 sub-library (see \fBASYNC_start_job\fR\|(3)). This is a default option.
169 .IP OPENSSL_INIT_ENGINE_RDRAND 4
170 .IX Item "OPENSSL_INIT_ENGINE_RDRAND"
171 With this option the library will automatically load and initialise the
172 RDRAND engine (if available). This not a default option and is deprecated
173 in OpenSSL 3.0.
174 .IP OPENSSL_INIT_ENGINE_DYNAMIC 4
175 .IX Item "OPENSSL_INIT_ENGINE_DYNAMIC"
176 With this option the library will automatically load and initialise the
177 dynamic engine. This not a default option and is deprecated
178 in OpenSSL 3.0.
179 .IP OPENSSL_INIT_ENGINE_OPENSSL 4
180 .IX Item "OPENSSL_INIT_ENGINE_OPENSSL"
181 With this option the library will automatically load and initialise the
182 openssl engine. This not a default option and is deprecated
183 in OpenSSL 3.0.
184 .IP OPENSSL_INIT_ENGINE_CRYPTODEV 4
185 .IX Item "OPENSSL_INIT_ENGINE_CRYPTODEV"
186 With this option the library will automatically load and initialise the
187 cryptodev engine (if available). This not a default option and is deprecated
188 in OpenSSL 3.0.
189 .IP OPENSSL_INIT_ENGINE_CAPI 4
190 .IX Item "OPENSSL_INIT_ENGINE_CAPI"
191 With this option the library will automatically load and initialise the
192 CAPI engine (if available). This not a default option and is deprecated
193 in OpenSSL 3.0.
194 .IP OPENSSL_INIT_ENGINE_PADLOCK 4
195 .IX Item "OPENSSL_INIT_ENGINE_PADLOCK"
196 With this option the library will automatically load and initialise the
197 padlock engine (if available). This not a default option and is deprecated
198 in OpenSSL 3.0.
199 .IP OPENSSL_INIT_ENGINE_AFALG 4
200 .IX Item "OPENSSL_INIT_ENGINE_AFALG"
201 With this option the library will automatically load and initialise the
202 AFALG engine. This not a default option and is deprecated
203 in OpenSSL 3.0.
204 .IP OPENSSL_INIT_ENGINE_ALL_BUILTIN 4
205 .IX Item "OPENSSL_INIT_ENGINE_ALL_BUILTIN"
206 With this option the library will automatically load and initialise all the
207 built in engines listed above with the exception of the openssl and afalg
208 engines. This not a default option and is deprecated
209 in OpenSSL 3.0.
210 .IP OPENSSL_INIT_ATFORK 4
211 .IX Item "OPENSSL_INIT_ATFORK"
212 With this option the library will register its fork handlers.
213 See \fBOPENSSL_fork_prepare\fR\|(3) for details.
214 .IP OPENSSL_INIT_NO_ATEXIT 4
215 .IX Item "OPENSSL_INIT_NO_ATEXIT"
216 By default OpenSSL will attempt to clean itself up when the process exits via an
217 "atexit" handler. Using this option suppresses that behaviour. This means that
218 the application will have to clean up OpenSSL explicitly using
219 \&\fBOPENSSL_cleanup()\fR.
220 .PP
221 Multiple options may be combined together in a single call to
222 \&\fBOPENSSL_init_crypto()\fR. For example:
223 .PP
224 .Vb 2
225 \& OPENSSL_init_crypto(OPENSSL_INIT_NO_ADD_ALL_CIPHERS
226 \& | OPENSSL_INIT_NO_ADD_ALL_DIGESTS, NULL);
227 .Ve
228 .PP
229 The \fBOPENSSL_cleanup()\fR function deinitialises OpenSSL (both libcrypto
230 and libssl). All resources allocated by OpenSSL are freed. Typically there
231 should be no need to call this function directly as it is initiated
232 automatically on application exit. This is done via the standard C library
233 \&\fBatexit()\fR function. In the event that the application will close in a manner
234 that will not call the registered \fBatexit()\fR handlers then the application should
235 call \fBOPENSSL_cleanup()\fR directly. Developers of libraries using OpenSSL
236 are discouraged from calling this function and should instead, typically, rely
237 on auto-deinitialisation. This is to avoid error conditions where both an
238 application and a library it depends on both use OpenSSL, and the library
239 deinitialises it before the application has finished using it.
240 .PP
241 Once \fBOPENSSL_cleanup()\fR has been called the library cannot be reinitialised.
242 Attempts to call \fBOPENSSL_init_crypto()\fR will fail and an ERR_R_INIT_FAIL error
243 will be added to the error stack. Note that because initialisation has failed
244 OpenSSL error strings will not be available, only an error code. This code can
245 be put through the openssl errstr command line application to produce a human
246 readable error (see \fBopenssl\-errstr\fR\|(1)).
247 .PP
248 The \fBOPENSSL_atexit()\fR function enables the registration of a
249 function to be called during \fBOPENSSL_cleanup()\fR. Stop handlers are
250 called after deinitialisation of resources local to a thread, but before other
251 process wide resources are freed. In the event that multiple stop handlers are
252 registered, no guarantees are made about the order of execution.
253 .PP
254 The \fBOPENSSL_thread_stop_ex()\fR function deallocates resources associated
255 with the current thread for the given OSSL_LIB_CTX \fBctx\fR. The \fBctx\fR parameter
256 can be NULL in which case the default OSSL_LIB_CTX is used.
257 .PP
258 Typically, this function will be called automatically by the library when
259 the thread exits as long as the OSSL_LIB_CTX has not been freed before the thread
260 exits. If \fBOSSL_LIB_CTX_free()\fR is called OPENSSL_thread_stop_ex will be called
261 automatically for the current thread (but not any other threads that may have
262 used this OSSL_LIB_CTX).
263 .PP
264 OPENSSL_thread_stop_ex should be called on all threads that will exit after the
265 OSSL_LIB_CTX is freed.
266 Typically this is not necessary for the default OSSL_LIB_CTX (because all
267 resources are cleaned up on library exit) except if thread local resources
268 should be freed before library exit, or under the circumstances described in
269 the NOTES section below.
270 .PP
271 \&\fBOPENSSL_thread_stop()\fR is the same as \fBOPENSSL_thread_stop_ex()\fR except that the
272 default OSSL_LIB_CTX is always used.
273 .PP
274 The \fBOPENSSL_INIT_LOAD_CONFIG\fR flag will load a configuration file, as with
275 \&\fBCONF_modules_load_file\fR\|(3) with NULL filename and application name and the
276 \&\fBCONF_MFLAGS_IGNORE_MISSING_FILE\fR, \fBCONF_MFLAGS_IGNORE_RETURN_CODES\fR and
277 \&\fBCONF_MFLAGS_DEFAULT_SECTION\fR flags.
278 The filename, application name, and flags can be customized by providing a
279 non-null \fBOPENSSL_INIT_SETTINGS\fR object.
280 The object can be allocated via \fBOPENSSL_INIT_new()\fR.
281 The \fBOPENSSL_INIT_set_config_filename()\fR function can be used to specify a
282 nondefault filename, which is copied and need not refer to persistent storage.
283 Similarly, \fBOPENSSL_INIT_set_config_appname()\fR can be used to specify a
284 nondefault application name.
285 Finally, OPENSSL_INIT_set_file_flags can be used to specify nondefault flags.
286 If the \fBCONF_MFLAGS_IGNORE_RETURN_CODES\fR flag is not included, any errors in
287 the configuration file will cause an error return from \fBOPENSSL_init_crypto\fR
288 or indirectly \fBOPENSSL_init_ssl\fR\|(3).
289 The object can be released with \fBOPENSSL_INIT_free()\fR when done.
290 If the argument to \fBOPENSSL_INIT_free()\fR is NULL, nothing is done.
291 .SH NOTES
292 .IX Header "NOTES"
293 Resources local to a thread are deallocated automatically when the thread exits
294 (e.g. in a pthreads environment, when \fBpthread_exit()\fR is called). On Windows
295 platforms this is done in response to a DLL_THREAD_DETACH message being sent to
296 the libcrypto32.dll entry point. Some windows functions may cause threads to exit
297 without sending this message (for example \fBExitProcess()\fR). If the application
298 uses such functions, then the application must free up OpenSSL resources
299 directly via a call to \fBOPENSSL_thread_stop()\fR on each thread. Similarly this
300 message will also not be sent if OpenSSL is linked statically, and therefore
301 applications using static linking should also call \fBOPENSSL_thread_stop()\fR on each
302 thread. Additionally if OpenSSL is loaded dynamically via \fBLoadLibrary()\fR and the
303 threads are not destroyed until after \fBFreeLibrary()\fR is called then each thread
304 should call \fBOPENSSL_thread_stop()\fR prior to the \fBFreeLibrary()\fR call.
305 .PP
306 On Linux/Unix where OpenSSL has been loaded via \fBdlopen()\fR and the application is
307 multi-threaded and if \fBdlclose()\fR is subsequently called prior to the threads
308 being destroyed then OpenSSL will not be able to deallocate resources associated
309 with those threads. The application should either call \fBOPENSSL_thread_stop()\fR on
310 each thread prior to the \fBdlclose()\fR call, or alternatively the original \fBdlopen()\fR
311 call should use the RTLD_NODELETE flag (where available on the platform).
312 .SH "RETURN VALUES"
313 .IX Header "RETURN VALUES"
314 The functions OPENSSL_init_crypto, \fBOPENSSL_atexit()\fR and
315 \&\fBOPENSSL_INIT_set_config_appname()\fR return 1 on success or 0 on error.
316 .SH "SEE ALSO"
317 .IX Header "SEE ALSO"
318 \&\fBOPENSSL_init_ssl\fR\|(3)
319 .SH HISTORY
320 .IX Header "HISTORY"
321 The \fBOPENSSL_init_crypto()\fR, \fBOPENSSL_cleanup()\fR, \fBOPENSSL_atexit()\fR,
322 \&\fBOPENSSL_thread_stop()\fR, \fBOPENSSL_INIT_new()\fR, \fBOPENSSL_INIT_set_config_appname()\fR
323 and \fBOPENSSL_INIT_free()\fR functions were added in OpenSSL 1.1.0.
324 .SH COPYRIGHT
325 .IX Header "COPYRIGHT"
326 Copyright 2016\-2024 The OpenSSL Project Authors. All Rights Reserved.
327 .PP
328 Licensed under the Apache License 2.0 (the "License"). You may not use
329 this file except in compliance with the License. You can obtain a copy
330 in the file LICENSE in the source distribution or at
331 <https://www.openssl.org/source/license.html>.