Doc nits cleanup, round 2
[openssl.git] / doc / crypto / OPENSSL_init_crypto.pod
1 =pod
2
3 =head1 NAME
4
5 OPENSSL_init_crypto, OPENSSL_cleanup,
6 OPENSSL_atexit, OPENSSL_thread_stop - OpenSSL
7 initialisation and deinitialisation functions
8
9 =head1 SYNOPSIS
10
11  #include <openssl/crypto.h>
12
13  void OPENSSL_cleanup(void);
14  int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);
15  int OPENSSL_atexit(void (*handler)(void));
16  void OPENSSL_thread_stop(void);
17
18  OPENSSL_INIT_SETTINGS *OPENSSL_init_new(void);
19  OPENSSL_INIT_set_config_filename(OPENSSL_INIT_SETTINGS *init, const char* name);
20  OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *init);
21
22 =head1 DESCRIPTION
23
24 During normal operation OpenSSL (libcrypto) will allocate various resources at
25 start up that must, subsequently, be freed on close down of the library.
26 Additionally some resources are allocated on a per thread basis (if the
27 application is multi-threaded), and these resources must be freed prior to the
28 thread closing.
29
30 As of version 1.1.0 OpenSSL will automatically allocate all resources that it
31 needs so no explicit initialisation is required. Similarly it will also
32 automatically deinitialise as required.
33
34 However, there way be situations when explicit initialisation is desirable or
35 needed, for example when some non-default initialisation is required. The
36 function OPENSSL_init_crypto() can be used for this purpose for
37 libcrypto (see also L<OPENSSL_init_ssl(3)> for the libssl
38 equivalent).
39
40 Numerous internal OpenSSL functions call OPENSSL_init_crypto().
41 Therefore, in order to perform non-default initialisation,
42 OPENSSL_init_crypto() MUST be called by application code prior to
43 any other OpenSSL function calls.
44
45 The B<opts> parameter specifies which aspects of libcrypto should be
46 initialised. Valid options are:
47
48 =over 4
49
50 =item OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS
51
52 Suppress automatic loading of the libcrypto error strings. This option is
53 not a default option. Once selected subsequent calls to
54 OPENSSL_init_crypto() with the option
55 B<OPENSSL_INIT_LOAD_CRYPTO_STRINGS> will be ignored.
56
57 =item OPENSSL_INIT_LOAD_CRYPTO_STRINGS
58
59 Automatic loading of the libcrypto error strings. With this option the
60 library will automatically load the libcrypto error strings.
61 This option is a default option. Once selected subsequent calls to
62 OPENSSL_init_crypto() with the option
63 B<OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS> will be ignored.
64
65 =item OPENSSL_INIT_ADD_ALL_CIPHERS
66
67 With this option the library will automatically load and make available all
68 libcrypto ciphers. This option is a default option. Once selected subsequent
69 calls to OPENSSL_init_crypto() with the option
70 B<OPENSSL_INIT_NO_ADD_ALL_CIPHERS> will be ignored.
71
72 =item OPENSSL_INIT_ADD_ALL_DIGESTS
73
74 With this option the library will automatically load and make available all
75 libcrypto digests. This option is a default option. Once selected subsequent
76 calls to OPENSSL_init_crypto() with the option
77 B<OPENSSL_INIT_NO_ADD_ALL_CIPHERS> will be ignored.
78
79 =item OPENSSL_INIT_NO_ADD_ALL_CIPHERS
80
81 With this option the library will suppress automatic loading of libcrypto
82 ciphers. This option is not a default option. Once selected subsequent
83 calls to OPENSSL_init_crypto() with the option
84 B<OPENSSL_INIT_ADD_ALL_CIPHERS> will be ignored.
85
86 =item OPENSSL_INIT_NO_ADD_ALL_DIGESTS
87
88 With this option the library will suppress automatic loading of libcrypto
89 digests. This option is not a default option. Once selected subsequent
90 calls to OPENSSL_init_crypto() with the option
91 B<OPENSSL_INIT_ADD_ALL_DIGESTS> will be ignored.
92
93 =item OPENSSL_INIT_LOAD_CONFIG
94
95 With this option an OpenSSL configuration file will be automatically loaded and
96 used by calling OPENSSL_config(). This is not a default option.
97 See the description of OPENSSL_init_new(), below.
98
99 =item OPENSSL_INIT_NO_LOAD_CONFIG
100
101 With this option the loading of OpenSSL configuration files will be suppressed.
102 It is the equivalent of calling OPENSSL_no_config(). This is not a default
103 option.
104
105 =item OPENSSL_INIT_ASYNC
106
107 With this option the library with automatically initialise the libcrypto async
108 sub-library (see L<ASYNC_start_job(3)>). This is a default option.
109
110 =item OPENSSL_INIT_ENGINE_RDRAND
111
112 With this option the library will automatically load and initialise the
113 RDRAND engine (if available). This not a default option.
114
115 =item OPENSSL_INIT_ENGINE_DYNAMIC
116
117 With this option the library will automatically load and initialise the
118 dynamic engine. This not a default option.
119
120 =item OPENSSL_INIT_ENGINE_OPENSSL
121
122 With this option the library will automatically load and initialise the
123 openssl engine. This not a default option.
124
125 =item OPENSSL_INIT_ENGINE_CRYPTODEV
126
127 With this option the library will automatically load and initialise the
128 cryptodev engine (if available). This not a default option.
129
130 =item OPENSSL_INIT_ENGINE_CAPI
131
132 With this option the library will automatically load and initialise the
133 CAPI engine (if available). This not a default option.
134
135 =item OPENSSL_INIT_ENGINE_PADLOCK
136
137 With this option the library will automatically load and initialise the
138 padlock engine (if available). This not a default option.
139
140 =item OPENSSL_INIT_ENGINE_DASYNC
141
142 With this option the library will automatically load and initialise the
143 DASYNC engine. This not a default option.
144
145 =item OPENSSL_INIT_ENGINE_ALL_BUILTIN
146
147 With this option the library will automatically load and initialise all the
148 built in engines listed above with the exception of the openssl and dasync
149 engines. This not a default option.
150
151 =back
152
153 Multiple options may be combined together in a single call to
154 OPENSSL_init_crypto(). For example:
155
156  OPENSSL_init_crypto(OPENSSL_INIT_NO_ADD_ALL_CIPHERS
157                      | OPENSSL_INIT_NO_ADD_ALL_DIGESTS, NULL);
158
159 The OPENSSL_cleanup() function deinitialises OpenSSL (both libcrypto
160 and libssl). All resources allocated by OpenSSL are freed. Typically there
161 should be no need to call this function directly as it is initiated
162 automatically on application exit. This is done via the standard C library
163 L<atexit(3)> function. In the event that the application will close in a manner
164 that will not call the registered atexit() handlers then the application should
165 call OPENSSL_cleanup() directly. Developers of libraries using OpenSSL
166 are discouraged from calling this function and should instead, typically, rely
167 on auto-deinitialisation. This is to avoid error conditions where both an
168 application and a library it depends on both use OpenSSL, and the library
169 deinitialises it before the application has finished using it.
170
171 Once OPENSSL_cleanup() has been called the library cannot be reinitialised.
172 Attempts to call OPENSSL_init_crypto() will fail and an ERR_R_INIT_FAIL error
173 will be added to the error stack. Note that because initialisation has failed
174 OpenSSL error strings will not be available, only an error code. This code can
175 be put through the openssl errstr command line application to produce a human
176 readable error (see L<errstr(1)>).
177
178 The OPENSSL_atexit() function enables the registration of a
179 function to be called during OPENSSL_cleanup(). Stop handlers are
180 called after deinitialisation of resources local to a thread, but before other
181 process wide resources are freed. In the event that multiple stop handlers are
182 registered, no guarantees are made about the order of execution.
183
184 The OPENSSL_thread_stop() function deallocates resources associated
185 with the current thread. Typically this function will be called automatically by
186 the library when the thread exits. This should only be called directly if
187 resources should be freed at an earlier time, or under the circumstances
188 described in the NOTES section below.
189
190 The B<OPENSSL_INIT_LOAD_CONFIG> flag will load a default configuration
191 file.  To specify a different file, an B<OPENSSL_INIT_SETTINGS> must
192 be created and used. The routines
193 OPENSSL_init_new() and OPENSSL_INIT_set_config_filename() can be used to
194 allocate the object and set the configuration filename, and then the
195 object can be released with OPENSSL_INIT_free() when done.
196
197 =head1 NOTES
198
199 Resources local to a thread are deallocated automatically when the thread exits
200 (e.g. in a pthreads environment, when pthread_exit() is called). On Windows
201 platforms this is done in response to a DLL_THREAD_DETACH message being sent to
202 the libcrypto32.dll entry point. Some windows functions may cause threads to exit
203 without sending this message (for example ExitProcess()). If the application
204 uses such functions, then the application must free up OpenSSL resources
205 directly via a call to OPENSSL_thread_stop(). Similarly this message will
206 also not be sent if OpenSSL is linked statically, and therefore applications
207 using static linking should also call OPENSSL_thread_stop().
208
209 =head1 RETURN VALUES
210
211 The functions OPENSSL_init_crypto and  OPENSSL_atexit() returns 1 on success or
212 0 on error.
213
214 =head1 SEE ALSO
215
216 L<OPENSSL_init_ssl(3)>
217
218 =head1 HISTORY
219
220 The OPENSSL_init_crypto(), OPENSSL_cleanup(), OPENSSL_atexit(),
221 and OPENSSL_thread_stop() functions were added in OpenSSL 1.1.0.
222
223 =head1 COPYRIGHT
224
225 Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
226
227 Licensed under the OpenSSL license (the "License").  You may not use
228 this file except in compliance with the License.  You can obtain a copy
229 in the file LICENSE in the source distribution or at
230 L<https://www.openssl.org/source/license.html>.
231
232 =cut