
Installing OpenSSL library is a straightforward process that can be completed in a few steps. You can install OpenSSL using a package manager like apt-get on Ubuntu or yum on Red Hat.
First, you'll need to update your package list to ensure you have the latest package information. This can be done by running the command `sudo apt-get update` on Ubuntu or `sudo yum update` on Red Hat.
Once your package list is updated, you can install OpenSSL by running the command `sudo apt-get install openssl` on Ubuntu or `sudo yum install openssl` on Red Hat.
Suggestion: How to Upgrade Openssl in Ubuntu 22.04
Getting Started
To use the OpenSSL library, you first need to initialize it, typically by calling the initialization function. This is a crucial step, as it sets up the library for use.
Initializing the library is usually a straightforward process, but it's essential to get it right to avoid any issues down the line.
Compilation
To compile the OpenSSL library, you should run make after configuring it. This is the standard process for building the library from a clean download.
If prompted, you can usually skip making depend, as it's not necessary in this case.
Retrieve Source Code
To retrieve the OpenSSL source code, you can download it from OpenSSL Source Tarballs or any suitable ftp mirror. There are various versions available, including stable and unstable ones.
The source code is managed via Git, specifically the Master repository. This repository is the central hub for all OpenSSL source code updates.
You can access the OpenSSL source code via Git by following the instructions provided. The repository is updated every 15 minutes to ensure you get the latest version.
To access the OpenSSL source code via Git, you can use the following method: Accessing OpenSSL source code via Git
Alternatively, you can also access the OpenSSL source code via a GitHub mirror, which is updated every 15 minutes. This provides a convenient way to get the latest version of the source code.
Compilation
After configuring the library, you should run make. If you're prompted to make depend, you can usually skip it since you're building from a clean download.
You can check if a specific configuration option is available by looking for the corresponding OPENSSL_NO_* define. For example, if you want to know if SSLv3 is available, you can perform a check in your code.
Explore further: Openssl Check Connection
Dependencies [edit]
If you're prompted to run make depend, you must do so. This is especially important for OpenSSL 1.0.2 and below, where it's required to update the standard distribution once configuration options change.
The good news is that OpenSSL 1.1.0 and above performs the dependency step for you automatically, so you shouldn't see this message.
However, even if you're using OpenSSL 1.1.0 or above, it's still a good idea to perform a make clean to ensure the list of object files is accurate after a reconfiguration.
The Command-Line Utility
The command-line utility is a powerful tool for compiling and managing cryptographic tasks. It's called openssl, and it's a must-know for anyone working with encryption.
To see what openssl can do, simply type openssl -help at a command prompt. This will give you a list of available commands.
You can also use openssl to view the version of OpenSSL installed on your system. Just type openssl version -a, and you'll get the version details as well as the directories where certificates, private keys, and other files are stored.
The OpenSSL Project is responsible for developing and maintaining openssl, and it's distributed under the Apache v2 license. This license applies to OpenSSL 3.0 or later, while earlier versions are licensed under a dual OpenSSL and SSLeay license.
Worth a look: Openssl Latest Version
Configuration
Configuration is a crucial aspect of working with OpenSSL. You should avoid custom build systems because they often miss important details, such as the unique opensslconf.h and bn.h files generated by Configure for each architecture and platform.
To configure OpenSSL, you can use the Configure and config commands. By default, OpenSSL will load a configuration file when it's first used, setting up various configuration settings within the default library context. This configuration file can be used to automatically load providers and set up default property query strings.
To ensure a smooth installation, it's recommended to specify both --prefix and --openssldir when configuring OpenSSL. This is especially true for OpenSSL 1.1.0 and above, where specifying both is necessary for make install to work as expected. If you don't specify both, you may end up with broken builds or other issues.
Here's a quick reference for configuring OpenSSL:
- Specify both --prefix and --openssldir to ensure a smooth installation.
- Set --prefix and --openssldir to the same location for consistency.
- Avoid specifying --prefix=/usr when OpenSSL versions are not binary compatible, as it may break your package management system.
Configuration
Configuration is a crucial step in setting up OpenSSL. You should avoid custom build systems because they often miss important details.

To configure OpenSSL, you can use the Configure and config commands. These commands help set up protocol and behavior options for a particular platform.
OpenSSL will load a configuration file by default when it's first used. This configuration file can be used to automatically load providers and set up default property query strings.
The configuration file format is described in the config(5) manual page. You can also use the OSSL_LIB_CTX_load_config(3) function to configure library contexts.
When specifying the prefix and OpenSSL directory, it's best to use both --prefix and --openssldir. Setting them to the same location will ensure a smooth installation.
Here's a summary of the prefix and OpenSSL directory configuration:
Avoid using --prefix=/usr when OpenSSL versions are not binary compatible, as it may break the package management system.
Using RPATHs
RPATHs are supported by default on BSD platforms, but not on Linux and compatibles, where you'll need to manually add one.
To add a RPATH on Linux, you can configure with it as shown in the example, where you need to add -Wl,-rpath,... to two places in the Configure file.

RPATHs are especially important when building OpenSSL and your program, as not adding one can lead to linking against random versions of a security library.
Using a RUNPATH instead of a RPATH is recommended for modern Linux, as it allows library path overrides at runtime.
You can also add an RPATH or RUNPATH by hard coding the RPATH into a configure line, as shown in the example where -Wl,-rpath,... is added to fields 2 and 6.
After making the changes, verify that the settings stuck by checking the output of ldd after make install.
Library Details
The OpenSSL libraries provide a comprehensive API for SSL and Crypto libraries.
The ssl manpage is a general overview of the SSL library.
The crypto manpage offers a general overview of the Crypto library.
The libcrypto library supports various types of general-purpose cryptographic functionality.
This library includes symmetric encryption, certificate handling, public key cryptography, pseudo-random number generation and cryptographic hash functions.
Additional reading: Verify Ssl Certificate Chain Openssl
Security and Compliance
To ensure the security and compliance of your OpenSSL library, you need to download and install the FIPS Capable Library. This library is built with the fips option.
You can download the FIPS Capable Library from a tarball file, specifically openssl-1.0.1e.tar.gz. The library is designed to be used with FIPS validated cryptography.
To configure the FIPS Capable Library, you must use the fips option. This ensures that the library is built with the necessary security features.
If you're using only prime curves, you'll also need to configure with no-ec2m. This is because the library is designed to work with specific curve types.
The FIPS Capable Library is built in conjunction with the FIPS Object Module, which you'll also need to download and install.
Error Handling and Safety
Error handling is crucial when working with OpenSSL. Most OpenSSL functions will provide a return value indicating success or failure, so it's essential to check the return value from these functions.
Some functions return NULL on failure, while others return a positive integer for success or 0 to indicate failure. However, not all functions follow these conventions, so it's vital to consult the documentation for each function to understand how to interpret the return value.
To avoid potential problems, always use the idiom to check for errors when calling an OpenSSL function: if (result == 1) or if (result > 0) for success, and if (result == 0) or if (result handle errors correctly and avoid unexpected behavior.
Error Handling
Most OpenSSL functions will return an integer to indicate success or failure, typically 1 on success or 0 on error, and all return codes should be checked and handled as appropriate.
Some functions may return 0 for success, while others may return 0 or a negative value for failure, making it essential to check the documentation for each function to understand how to interpret the return value.

You should always check the return value from OpenSSL functions, as many will return NULL in the event of a failure, and some may not conform to the standard conventions.
It's not uncommon to see errors handled in a way that checks for the return value, but be aware that not all functions behave the same way, and some may have unexpected return values.
To avoid potential problems, use the idiom to check for errors when calling an OpenSSL function: "if (function() == 1) { success } else { error }".
Checking the manual pages or source code is crucial to ensure you understand how a specific function behaves, especially when dealing with exceptions that can trip up the unwary.
By following these guidelines and being mindful of the potential pitfalls, you can write more robust and secure code that handles errors effectively.
Thread Safety
Thread Safety is a crucial aspect of using OpenSSL, and it's not enabled by default. This means you need to take extra steps to ensure your application is thread-safe.
OpenSSL requires you to provide callbacks for locking, atomic integer addition, and thread ID determination to make it thread-safe. This can be a challenge, especially when working with multiple objects in a multi-threaded process.
To make OpenSSL thread-safe, you need to check if the locking callback has been set and set it if not. You also need to use the CRYPTO_w_lock and CRYPTO_w_unlock functions to ensure thread safety.
Here are the steps you can take to make OpenSSL thread-safe:
- Check if the locking callback has been set, then set it if not;
- CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK), set the remaining callbacks (threadid, dynlock, and add_lock) if not already set, then CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
In the future, OpenSSL may self-initialize thread-safely to use native threading where available.
Providers and Conventions
Providers in OpenSSL are essentially containers that hold multiple algorithm implementations. They can be thought of as a collection of algorithms that can be used together. A provider is loaded automatically when first attempting to access one of its algorithms, if no other provider has been loaded.
The OpenSSL distribution includes five core providers: Default, Legacy, Base, FIPS, and Null. The Default provider includes all the standard built-in algorithm implementations in OpenSSL, including SHA-3, MD-5, and AES.
Loading and unloading providers is an expensive operation, so it's normally done once early on in the application lifecycle and those providers are kept loaded for the duration of the application execution.
Here are the five core providers included in the OpenSSL distribution:
- Default: includes all standard built-in algorithm implementations
- Legacy: contains algorithms that are no longer commonly used or are discouraged from being used due to security issues
- Base: contains a small subset of non-cryptographic algorithms
- FIPS: includes algorithm implementations that conform to the Federal Information Processing Standard
- Null: includes no algorithms and is used to prevent the default provider from being automatically loaded
If you don't load a provider explicitly, the OpenSSL built-in "default" provider will be automatically loaded.
Providers
Providers are an essential part of OpenSSL, and understanding how they work is crucial for any serious developer.
A provider is a container that holds multiple algorithm implementations, and OpenSSL comes with five core providers: Default, Legacy, Base, FIPS, and Null.
The Default provider is built-in as part of the libcrypto library and contains all of the most commonly used algorithm implementations.
If you don't load any providers at all, the Default provider will be automatically loaded.
The Base provider is also built-in and contains algorithm implementations for encoding and decoding of OpenSSL keys.

Loading and unloading providers is quite an expensive operation, so it's best to do it once early on in the application lifecycle.
The FIPS provider is a dynamically loadable module that contains algorithm implementations that have been validated according to FIPS standards.
If you need to use the FIPS provider, you'll need to load it explicitly, either in code or through OpenSSL configuration.
The Legacy provider is another dynamically loadable module that contains algorithm implementations that are considered insecure or no longer in common use.
The Null provider is built-in and contains no algorithms at all, making it useful for preventing the default provider from being automatically loaded.
Here's a quick rundown of the five core providers:
By understanding how providers work and how to use them, you'll be able to take full advantage of OpenSSL's capabilities and write more secure and efficient code.
Multi-Threaded Applications
When building multi-threaded applications with OpenSSL, it's essential to understand which functions are thread-safe. Most OpenSSL functions are thread-safe, but data structures are not.
OpenSSL functions like BIO_write(3) and BIO_read(3) are thread-safe, but using them with the same BIO object in multiple threads can lead to issues. This is because both functions may attempt to make changes to the same BIO object.
Some data structures, like OSSL_LIB_CTX, are always safe to use in multiple threads. This makes them a good choice for multi-threaded applications.
There are exceptions to these rules, and some functions are not thread-safe at all. If you're unsure about a specific function, check its documentation for any restrictions.
Library Conventions
Library Conventions are an essential part of the OpenSSL ecosystem. Many OpenSSL functions follow a naming convention using the numbers 0 and 1, i.e. "get0", "get1", "set0" and "set1".
This convention helps developers understand the behavior of functions that "get" or "set" a value. For example, the X509_CRL_add0_revoked() function passes ownership of the object to the parent object.
In the 0 version, ownership of the object is passed to or retained by the parent object. After calling X509_CRL_add0_revoked(), the rev object's ownership is passed to the crl object, so it should not be freed directly.

The 1 version, on the other hand, does not pass or retain ownership, instead performing a copy or "up ref" of the object. After calling X509_add1_trust_object(), the application is still responsible for freeing the obj value.
OpenSSL functions also follow a naming convention of the form CLASSNAME_func_name(). This convention indicates the primary data structure the function operates on, given in capital letters, and the purpose of the function in lowercase letters.
Platforms
OpenSSL 1.1.0 supports 64-bit iOS cross-compiles using the ios64-cross target, and --prefix=/usr/local/openssl-ios64.
This is a notable improvement over earlier versions, where 64-bit iOS support was not built-in.
For OpenSSL 1.0.2 and below, there is no 64-bit iOS support.
Curious to learn more? Check out: Phpinfo Openssl Support Disabled
Linux
Linux is an open-source operating system that's free to download and use. It was created by Linus Torvalds in 1991 as a hobby project.
Linux is widely used in servers, which can host websites, handle email, and provide other services. It's also used in many supercomputers, including the world's fastest supercomputer, Summit.

Linux has a massive community of developers who contribute to its code and create new software for it. This community is responsible for creating many popular Linux distributions, or versions, such as Ubuntu and Debian.
Linux is highly customizable, which is one reason why it's popular among programmers and developers. They can modify the code to suit their needs, and even create their own custom versions.
Linux has a wide range of applications, from simple games to complex software like video editing and 3D modeling. It's also used in many embedded systems, such as routers and set-top boxes.
If this caught your attention, see: Create Pfx from Crt and Key Openssl
64-Bit [Edit]
For 64-bit iOS cross-compiles with OpenSSL 1.1.0, you'll want to use the ios64-cross target and specify the prefix as /usr/local/openssl-ios64.
This is different from older versions of OpenSSL, where there's no built-in 64-bit iOS support for OpenSSL 1.0.2 or below.
To build a 64-bit iOS version of OpenSSL 1.1.0, you'll need to use the ios64-cross target specifically.
It's worth noting that if you're working with an older version of OpenSSL, you won't have the option to use a 64-bit iOS cross-compile.
HP-UX
HP-UX is a Unix-based operating system developed by Hewlett-Packard.
HP-UX can run on Itanium processors, which are known for their high performance and reliability.
Versions
OpenSSL lib has a long history of development, with the first version released in 1998. The library has undergone significant changes over the years to improve its functionality and security.
The OpenSSL lib has had several major releases, including OpenSSL 0.9.8, OpenSSL 1.0.0, and OpenSSL 1.1.0. Each of these releases brought new features and improvements to the library.
OpenSSL 1.1.0, for example, introduced support for TLS 1.3, which provides improved security and performance compared to earlier versions of the protocol.
1.1.0
For OpenSSL 1.1.0 and above, you'll need to have perl and NASM installed on your machine, and available on your %PATH%.
Ensure perl is installed on your machine, and available on your %PATH%. You can use ActiveState or Strawberry.
Extract the source files to your folder, here cd c:\myPath\openssl.
Suggestion: Windows Openssl Path

To configure the build, launch Visual Studio tool x64 Cross Tools Command prompt and goto your defined folder cd c:\myPath\openssl.
You can configure for the target OS with perl Configure VC-WIN64A or other configurations to be found in the INSTALL file.
If you compiled before on 32 or 64-bits, make sure you run nmake clean to prevent trouble across 32 and 64-bits which share output folder.
To build the OpenSSL, use the command nmake.
The output can be found in the root of your folder as libcrypto-1_1x64.dll and libssl-1_1-x64.dll.
1.0.2
For OpenSSL 1.0.2, you'll need to have perl and NASM installed on your machine, and available on your PATH.
Ensure you have perl installed on your machine, and available on your PATH. This can be ActiveState or Strawberry, for example.
You'll also need to launch a Visual Studio tool x64 Cross Tools Command prompt to get started.
Change to the directory where you have copied openssl sources, for example, c:\myPath\openssl.
Curious to learn more? Check out: Openssl Example

To configure for the target OS, use the command perl Configure VC-WIN64A. You may also want to set more configuration options as documented in the general INSTALL note.
The next step is to prepare the target environment with the command: ms\do_win64a.
Make sure to start afresh and clean any previous 32bit compile products from the directory. Use the command: nmake -f ms
tdll.mak clean for the DLL target.
For static libraries, use the command: nmake -f ms
t.mak clean.
To build the code, use the command: nmake -f ms
tdll.mak (respectively nmake -f ms
t.mak ).
The artefacts will be found in sub directories out32dll and out32dll.dbg (respectively out32 and out32.dbg for static libraries).
The libcrypto and ssl libraries are still named libeay32.lib and ssleay32.lib, and associated includes in inc32. You can check this is true 64bit code using the Visual Studio tool 'dumpbin'.
Here are the steps to build OpenSSL 1.0.2 in a concise list:
- Ensure perl and NASM are installed and available on your PATH.
- Launch a Visual Studio tool x64 Cross Tools Command prompt.
- Change to the directory where you have copied openssl sources.
- Configure for the target OS with the command perl Configure VC-WIN64A.
- Prepare the target environment with the command: ms\do_win64a.
- Clean any previous 32bit compile products from the directory.
- Build the code with the command: nmake
tdll.mak (respectively nmake -f ms
t.mak).Check the artefacts in sub directories out32dll and out32dll.dbg (respectively out32 and out32.dbg for static libraries).
Frequently Asked Questions
What is libssl used for?
libssl" is a library that enables secure communication between network peers, supporting standards like SSL/TLS and QUIC. It relies on "libcrypto" for its functionality, making it a crucial tool for secure networking.
Featured Images: pexels.com


