Configure OpenSSL
You want your app to load a specific OpenSSL installation at startup and turn on post-quantum mode, or to stop with a clear message if that doesn't work.
Solution overview
| Element | Purpose |
|---|---|
PostQuantumConfig.OpenSslPath | the folder that the library loads libcrypto from |
CryptoProviderFactory.RegisterProvider | registers a provider explicitly; without this call, the library registers the OpenSSL provider itself |
PostQuantumConfig.EnablePostQuantum | loads OpenSSL, checks that it provides ML-DSA-65 and ML-KEM-768, and sets DefaultMode |
PostQuantumConfig.InitializationError | the message from the last failed load attempt |
Implementation
Run this code once when your app starts, before the first cryptographic operation:
using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using WKL.System.Security.Cryptography; using WKL.System.Security.Cryptography.X509Certificates; PostQuantumConfig.OpenSslPath = @"C:\OpenSSL\bin"; try { PostQuantumConfig.EnablePostQuantum(CryptoMode.Hybrid); } catch (CryptographicException ex) { Console.Error.WriteLine($"Post-quantum mode isn't available: {ex.Message}"); throw; }
The library picks the file based on the operating system and the process architecture:
| Platform | File |
|---|---|
| Windows, 64-bit | libcrypto-3-x64.dll |
| Windows, 32-bit | libcrypto-3.dll |
| Windows on Arm | libcrypto-3-arm64.dll |
| Linux | libcrypto.so.3 |
| macOS | libcrypto.3.dylib |
Without OpenSslPath, the operating system's library search applies. That's enough if the first file the
search finds belongs to OpenSSL 3.5 or later. On Windows, always set OpenSslPath.
Remarks
- Provider. The library registers the provider that computes the PQ algorithms through OpenSSL on first use, as long as the
WKL.System.Security.Cryptography.Extensionsassembly is part of your app. You only needCryptoProviderFactory.RegisterProviderfor a different provider, such as the WebAssembly provider in Blazor WebAssembly. - Linux: the OpenSSL that .NET loads.
OpenSslPathonly applies to this library's calls. On Linux,X509Chainand the .NET PFX import load the system'slibcryptothemselves. If that version lacks ML-DSA, as OpenSSL 3.0 on Ubuntu 24.04 does, building a chain with a pure ML-DSA issuer fails. In that case, have .NET load your OpenSSL 3.5 or later installation as well, by settingLD_LIBRARY_PATHto its library folder before the process starts. Hybrid certificates with an RSA or ECDSA key aren't affected. - Multiple OpenSSL copies on Windows. Git, VPN clients, and other programs ship their own, often older, OpenSSL files. The Windows search takes the first one it finds.
OpenSslPathpins the installation. - Once per process. The library loads OpenSSL on first use and keeps that choice until the process ends. If you set
OpenSslPathto a different value afterward, the next operation throws aCryptographicExceptioninstead of silently ignoring the new value. - Error messages name the path and the version. If the folder or the file is missing,
EnablePostQuantumthrows aCryptographicExceptionthat names the path. If the loaded installation doesn't provide ML-DSA-65 or ML-KEM-768, the message names the algorithm, the version, and the path. In both cases,DefaultModestays unchanged. To fix these errors, see OpenSSL doesn't load and OpenSSL doesn't provide ML-DSA or ML-KEM. - Path from configuration. In apps with a configuration file, read the path from configuration, so that each environment can specify its own installation without a rebuild.
Related topics
en/wiki/pqcrypt/lib/how-to/configure-openssl.txt · Zadnja sprememba: uporabnika Wolfgang van der Stille