IBM Developer

Tutorial

Developing with quantum-safe OpenSSL

Discover why quantum-safe so important to OpenSSL

By Alex Bozarth

OpenSSL is an open-source library that implements the Transport Layer Security (TLS) protocol, a method of secure communication across a computer network. This communication is secured using various algorithms, such as RSA, to encrypt the data while in transit. These encryption methods are considered secure due to the astronomical amount of time (for example, centuries) it would take the fastest classical computers to break them.

With the recent leaps forward in creating viable quantum computers, this security is now at risk, where previous encryption algorithms can be broken by quantum computers in a relatively short amount of time. The solution to this is the creation of new algorithms that difficult to be broken by quantum computers. A fast move to using these new "quantum-safe" algorithms is imperative, as the encrypted information that is being sent today can potentially be saved and decrypted later.

Open Quantum Safe is an open-source project that is developing quantum-safe algorithms and integrating them into applications that deal with encryption such as OpenSSL. As the most used implementation of TLS, updating OpenSSL to use quantum-safe algorithms is a important step towards a quantum-safe future. Once OpenSSL is configured to be quantum-safe, other applications that use OpenSSL, such as cURL and HAProxy, can be made quantum-safe as well.

In this tutorial, we will walk you through setting up OpenSSL and how to configure it to use quantum-safe encryption algorithms. By the end of the tutorial you will be able to make cURL calls using quantum-safe encryption, and know the next steps to using quantum-safe encryption in other applications like HAProxy. You can learn more about the algorithms we’ll be installing and their limitations at the Open Quantum Safe website

Setting up your development environment

The following steps assume you're running Ubuntu 22.04 LTS. If you want to use a different Linux distribution, some steps may need to be modified.

You will also need GitHub.com access to pull git repositories. Each git clone step will also include an optional git commit to checkout. If you're having issues building with the latest code you can use the suggested commits instead. The following build steps can also be found in this gist, including up to date git commits.

Steps

  • Step 1. Install the dependencies
  • Step 2. Install OpenSSL
  • Step 3. Install liboqs
  • Step 4. Install Open Quantum Safe provider for OpenSSL 3
  • Step 5. Install and run cURL with quantum-safe algorithms

Step 1. Install the dependencies

The four projects we will be building have various dependencies that need to be installed before starting. These install steps might require you to run them as root or use sudo.

Some steps will also require an existing directory structure, so we will also create those directories in our WORKSPACE directory.

You can set the WORKSPACE directory to any directory you have write access to. All the cloned git repositories and artifacts generated by the build will exist in the WORKSPACE directory.

# If you are not running as root you might need to use "sudo apt" instead
sudo apt update
sudo apt -y install git build-essential perl cmake autoconf libtool zlib1g-dev

export WORKSPACE=~/quantumsafe # set this to a working dir of your choice
export BUILD_DIR=$WORKSPACE/build # this will contain all the build artifacts
mkdir -p $BUILD_DIR/lib64
ln -s $BUILD_DIR/lib64 $BUILD_DIR/lib

Step 2. Install OpenSSL

Now that we've set up our workspace and installed the required dependencies, we will build and install OpenSSL 3.

Given OpenSSL 1.1 will reach end of life on September 2023], the current work on supporting quantum-safe is using OpenSSL 3. OpenSSL 3 introduced providers, a set of algorithm implementations, that can be installed in addition to the default algorithms included with OpenSSL. We will explain providers further when we get to the Open Quantum Safe provider installation step.

We include options to not install or disable TLS protocols that don't support quantum-safe algorithms. This is necessary since quantum-safe encryption was not supported prior to TLS 1.2 and all current algorithms are written for TLS 1.3.

cd $WORKSPACE

git clone https://github.com/openssl/openssl.git
cd openssl

#OPTIONAL# git checkout c8ca810da9

./Configure \
  --prefix=$BUILD_DIR \
  no-ssl no-tls1 no-tls1_1 no-afalgeng \
  no-shared threads -lm

make -j $(nproc)
make -j $(nproc) install_sw install_ssldirs

Step 3. Install liboqs

liboqs is a C library created by the Open Quantum Safe project that provides implementations of quantum-safe algorithms and an API for accessing them. In our case we need to build liboqs since it provides the algorithms for the Open Quantum Safe provider we will be installing next.

We set the BUILD_SHARED_LIBS=ON and OQS_USE_OPENSSL=OFF configuration options so liboqs will use our local build of OpenSSL instead of downloading the release version. To minimize the build, we also set OQS_BUILD_ONLY_LIB=ON since we only need the liboqs library as a dependency for the OQS provider and do not need to build the other components.

cd $WORKSPACE

git clone https://github.com/open-quantum-safe/liboqs.git
cd liboqs

#OPTIONAL# git checkout 78e65bf1

mkdir build && cd build

cmake \
  -DCMAKE_INSTALL_PREFIX=$BUILD_DIR \
  -DBUILD_SHARED_LIBS=ON \
  -DOQS_USE_OPENSSL=OFF \
  -DCMAKE_BUILD_TYPE=Release \
  -DOQS_BUILD_ONLY_LIB=ON \
  -DOQS_DIST_BUILD=ON \
  ..

make -j $(nproc)
make -j $(nproc) install

Step 4. Install Open Quantum Safe provider for OpenSSL 3

Now it is time to install the Open Quantum Safe provider for OpenSSL 3 that we mentioned before. As detailed above, an OpenSSL provider is a unit of code that implements a set of encryption algorithms in a format expected by OpenSSL. OpenSSL can be configured to use multiple providers, which enables the use of algorithms implemented by any provider that was configured. The Open Quantum Safe provider wraps the algorithms implemented in liboqs to enable their usage in OpenSSL.

For the Open Quantum Safe provider to use our local builds of OpenSSL and liboqs, we must set the liboqs_DIR and OPENSSL_ROOT_DIR environment variables; the former must be set prior to running the configuration.

Since the Open Quantum Safe provider does not have an easy way to configure where to put its build artifacts, we will instead copy those artifacts into the directories we created earlier. We also need to update the openssl.cnf to use the provider, we do this by calling sed to insert the nessesary lines into the file.

cd $WORKSPACE

git clone https://github.com/open-quantum-safe/oqs-provider.git
cd oqs-provider

#OPTIONAL# git checkout d540c28

liboqs_DIR=$BUILD_DIR cmake \
  -DCMAKE_INSTALL_PREFIX=$WORKSPACE/oqs-provider \
  -DOPENSSL_ROOT_DIR=$BUILD_DIR \
  -DCMAKE_BUILD_TYPE=Release \
  -S . \
  -B _build
cmake --build _build

# Manually copy the lib files into the build dir
cp _build/lib/* $BUILD_DIR/lib/

# We need to edit the openssl config to use the oqsprovider
sed -i "s/default = default_sect/default = default_sect\noqsprovider = oqsprovider_sect/g" $BUILD_DIR/ssl/openssl.cnf &&
sed -i "s/\[default_sect\]/\[default_sect\]\nactivate = 1\n\[oqsprovider_sect\]\nactivate = 1\n/g" $BUILD_DIR/ssl/openssl.cnf

For OpenSSL to use the provider we just built, we will need to set two environment variables. If you plan to use this build long-term you will want to set these environment variables in your bashrc; otherwise, you will need to set them every time you start a new shell.

After setting the environment variables, we can test that the provider is properly configured by running openssl list. You should expect to see both the default provider and the oqsprovider listed.

# These env vars need to be set for the oqsprovider to be used when using OpenSSL
export OPENSSL_CONF=$BUILD_DIR/ssl/openssl.cnf
export OPENSSL_MODULES=$BUILD_DIR/lib
$BUILD_DIR/bin/openssl list -providers -verbose -provider oqsprovider

Step 5. Install and run cURL with quantum-safe algorithms

Now that we have a quantum-safe instance of OpenSSL installed, it’s time to use it. For this tutorial, we will be using cURL to demo quantum-safe OpenSSL.

When using OpenSSL, cURL can be called with a --curves parameter that specifies which OpenSSL algorithm to use for encryption. This allows us to test our OpenSSL installation quickly.

As of version 8.4.0, cURL has no way to easily find out if a quantum-safe algorithm was successfully used when the curve is specified. This has been addressed in an unreleased commit which has added the encryption algorithms used in the verbose output.

cd $WORKSPACE

git clone https://github.com/curl/curl.git
cd curl

#OPTIONAL# git checkout 0eda1f6c9

autoreconf -fi
./configure \
  LIBS="-lssl -lcrypto -lz" \
  LDFLAGS="-Wl,-rpath,$BUILD_DIR/lib64 -L$BUILD_DIR/lib64 -Wl,-rpath,$BUILD_DIR/lib -L$BUILD_DIR/lib -Wl,-rpath,/lib64 -L/lib64 -Wl,-rpath,/lib -L/lib" \
  CFLAGS="-O3 -fPIC" \
  --prefix=$BUILD_DIR \
  --with-ssl=$BUILD_DIR \
  --with-zlib=/ \
  --enable-optimize --enable-libcurl-option --enable-libgcc --enable-shared \
  --enable-ldap=no --enable-ipv6 --enable-versioned-symbols \
  --disable-manual \
  --without-default-ssl-backend \
  --without-librtmp --without-libidn2 \
  --without-gnutls --without-mbedtls \
  --without-wolfssl --without-libpsl

make -j $(nproc)
make -j $(nproc) install

Now that cURL is installed, we can try using it. The Open Quantum Safe project provides a test server for demos such as this. To make calls to the test server, we first download the CA cert, and then we can make a call using one of the algorithms provided by liboqs.

$BUILD_DIR/bin/curl -vk https://test.openquantumsafe.org/CA.crt --output $BUILD_DIR/ca.cert
$BUILD_DIR/bin/curl -v --curves p521_kyber1024 --cacert $BUILD_DIR/ca.cert https://test.openquantumsafe.org:6162/

In the verbose output, you should see the following line if you’re successful:

* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / p521_kyber1024 / dilithium5

The port for a signature and key exchange algorithm combination provided by the test server is subject to change. In this example we are using dilithium5 and p521_kyber1024, which uses port 6162 at the time of writing. Please refer to the documentation on the test server and verify the current port for dilithium5 and p521_kyber1024 in the table.

Summary and next steps

Now that you have a working environment with a quantum-safe OpenSSL, you can take the next steps in development. Lots of software will need to be updated to use quantum-safe algorithms, like those available in liboqs, and OpenSSL is just the first step. By running other software using quantum-safe OpenSSL you can start testing to see where your applications need to be updated to be quantum-safe. To prepare for the future of quantum security, we must start updating our security now.

You can find more work around liboqs and various prototypes of open source applications leveraging it at the Open Quantum Safe website. IBM has also announced IBM Quantum Safe, a set of tools and guides for finding and addressing quantum security in your software.

Acknowledgements

Thanks to Nigel Jones, Michael Maximilien, Martin Schmatz, Paul Schweigert, and Mariam John for thier review and feedback.