<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openssl.org/index.php?action=history&amp;feed=atom&amp;title=API_Design_Considerations%3A_Initialization_Functions_Hurt</id>
	<title>API Design Considerations: Initialization Functions Hurt - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openssl.org/index.php?action=history&amp;feed=atom&amp;title=API_Design_Considerations%3A_Initialization_Functions_Hurt"/>
	<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=API_Design_Considerations:_Initialization_Functions_Hurt&amp;action=history"/>
	<updated>2026-04-10T10:15:32Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.13</generator>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=API_Design_Considerations:_Initialization_Functions_Hurt&amp;diff=2346&amp;oldid=prev</id>
		<title>NWilliams: Created page with &quot;== Layered Software and OpenSSL ==  OpenSSL isn't just used by &quot;applications&quot;, but also by libraries.  A sufficiently complex application can have many libraries loaded that c...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=API_Design_Considerations:_Initialization_Functions_Hurt&amp;diff=2346&amp;oldid=prev"/>
		<updated>2016-01-26T22:13:41Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Layered Software and OpenSSL ==  OpenSSL isn&amp;#039;t just used by &amp;quot;applications&amp;quot;, but also by libraries.  A sufficiently complex application can have many libraries loaded that c...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Layered Software and OpenSSL ==&lt;br /&gt;
&lt;br /&gt;
OpenSSL isn't just used by &amp;quot;applications&amp;quot;, but also&lt;br /&gt;
by libraries.  A sufficiently complex application can have many&lt;br /&gt;
libraries loaded that call OpenSSL, and the main program may not know it.&lt;br /&gt;
&lt;br /&gt;
For example, libldap, libcurl, Kerberos implementations, and many other&lt;br /&gt;
libraries might use OpenSSL.  Then there's things like PAM, SASL, and&lt;br /&gt;
GSS that are pluggable using dlopen() (or LoadLibrary(), ...) and whose&lt;br /&gt;
plugins might use one of those libraries or even OpenSSL directly.&lt;br /&gt;
&lt;br /&gt;
Now, with the lock callbacks: who's responsible for setting them?&lt;br /&gt;
&lt;br /&gt;
Today, each call to set the lock callbacks changes them.&lt;br /&gt;
&lt;br /&gt;
Surprise: set lock callbacks, use locks, have these callbacks changed&lt;br /&gt;
under your feet, explode.&lt;br /&gt;
&lt;br /&gt;
It's just not safe for libraries to set lock callbacks... unless all of&lt;br /&gt;
them set the same lock callbaks, which... they wouldn't because the lock&lt;br /&gt;
callback prototypes don't match, say, standard pthreads functions', thus&lt;br /&gt;
each library would have its own callback functions, and who knows how&lt;br /&gt;
they'll be coded.  So libraries can't set them.  Sure, libraries can&lt;br /&gt;
check if they've been set and set them otherwise, but this is racy&lt;br /&gt;
and fails in threaded applications (e.g., the JVM).&lt;br /&gt;
&lt;br /&gt;
If any threaded code uses OpenSSL prior to initializing callbacks -&amp;gt;&lt;br /&gt;
process explodes.&lt;br /&gt;
&lt;br /&gt;
Libraries can't initialize them.  That leaves the application.&lt;br /&gt;
&lt;br /&gt;
=== Automatic Self-Initialization is the Solution ===&lt;br /&gt;
&lt;br /&gt;
The solution to the above problems is simple: the OpenSSL libcrypto and&lt;br /&gt;
libssl libraries must self-initialize automatically.&lt;br /&gt;
&lt;br /&gt;
Note that relying on run-time linker-loader functionality for self-&lt;br /&gt;
initialization (e.g., .init/.fini sections, DllMain()) is generally&lt;br /&gt;
frowned upon.  The correct way to automatically self-initialize is to&lt;br /&gt;
use pthread_once() or InitOnceExecuteOnce(), or to construct a similar&lt;br /&gt;
once initializer.&lt;br /&gt;
&lt;br /&gt;
Explicit initialization functions are OK, as long as they are optional&lt;br /&gt;
(these may be useful for applications that will chroot, for example).&lt;br /&gt;
&lt;br /&gt;
Finalization should not be required and may not be possible.&lt;/div&gt;</summary>
		<author><name>NWilliams</name></author>
	</entry>
</feed>