Rust bindings to OpenSSL using idiomatic Rust.
  • Rust 90.1%
  • Shell 5.1%
  • Python 3.8%
  • Makefile 1%
Find a file
Alexander Bokovoy 745620b062 docs: add rustls-native-ossl README
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
2026-07-25 10:28:24 +03:00
.github/workflows ci: build canary CI with --features rustls-0-24 2026-07-02 09:00:40 +03:00
contrib ci: build canary CI with --features rustls-0-24 2026-07-02 09:00:40 +03:00
docs docs: add pkey_builder key import guide and examples 2026-07-25 10:13:47 +03:00
examples/encrypt-demo chore(release): bump workspace versions to 0.2.0 2026-07-25 10:27:18 +03:00
native-ossl docs: update native-ossl README for pkey/ module split 2026-07-25 10:28:13 +03:00
native-ossl-sys docs: fix ossl400 -> ossl_v400 in native-ossl-sys README 2026-07-25 10:28:17 +03:00
ring-native-ossl docs: add ring-native-ossl README 2026-07-25 10:28:21 +03:00
rustls-native-ossl docs: add rustls-native-ossl README 2026-07-25 10:28:24 +03:00
wiki docs(wiki): record PRs #20–#27 merged — all gaps resolved 2026-04-18 14:34:00 +03:00
.gitignore chore: ignore generated packaging artifacts and Python cache 2026-06-12 17:38:03 +03:00
Cargo.lock chore(release): bump workspace versions to 0.2.0 2026-07-25 10:27:18 +03:00
Cargo.toml chore(release): bump workspace versions to 0.2.0 2026-07-25 10:27:18 +03:00
CHANGELOG.md docs(release): rewrite changelogs for 0.2.0 2026-07-25 10:27:26 +03:00
LICENSE license: add Apache-2.0 (matches OpenSSL 3.x) 2026-04-15 15:14:33 +03:00
README.md docs: update root README for 0.2.0 2026-07-25 10:28:09 +03:00

native-ossl

Safe, idiomatic Rust wrappers for modern OpenSSL (3.0.7+, 4.x).

native-ossl gives Rust code direct access to the OpenSSL cryptographic library already installed on the system — no reimplementation, no vendored C code by default, no protocol logic added on top. The API covers the full public OpenSSL stack: EVP algorithms, asymmetric keys, TLS, X.509, OCSP, PKCS#12, BIO, and provider/library-context management.

What is provided

Module Types
error ErrorStack — full OpenSSL error queue on failure
lib_ctx LibCtx, Provider — isolated library contexts
params ParamBuilder, Params — typed OSSL_PARAM arrays with set() method for compile-time type safety
typed_params Algorithm-scoped typed parameter constants (rsa::N, ec::GROUP, sig::PAD_MODE, etc.)
pkey_builder Per-algorithm key import builders (RsaPrivKeyBuilder, EcPrivKeyBuilder, RawKeyBuilder, DhPrivKeyBuilder)
pkey_params OpenSSL parameter name constants and key-type identifiers
digest DigestAlg, DigestCtx — including mid-stream context fork and checkpoint serialization
cipher CipherAlg, CipherCtx<Dir>, AeadEncryptCtx, AeadDecryptCtx
mac MacAlg, MacCtx, HmacCtx, CmacCtx
rand Rand, RandAlg, RandCtx
pkey Pkey<T>, KeygenCtx, Signer, Verifier, RawSigner, RawVerifier, MessageSigner, MessageVerifier, DeriveCtx, PkeyEncryptCtx, PkeyDecryptCtx, EncapCtx, DecapCtx
kdf HkdfBuilder, Pbkdf2Builder, ScryptBuilder, SshkdfBuilder, KbkdfBuilder
x509 X509, X509Builder, X509Store, X509StoreCtx, X509Crl, SignatureInfo
pkcs12 Pkcs12
ocsp OcspCertId, OcspRequest, OcspResponse, OcspBasicResp
ssl SslCtx, SslCtxBuilder<R>, Ssl, SslSession, BorrowedSslSession, HostnameFlags
fips fips::is_running
util SecretBuf — OPENSSL_cleanse-on-drop buffer

Requirements

  • OpenSSL 3.0.7 or later (system install; 3.2+ for KEM/message-sign APIs, 3.5+ for SSH-KDF/KBKDF)
  • Rust 1.77 or later (required for c"..." C-string literal syntax)
  • pkg-config
# Fedora / RHEL
sudo dnf install openssl-devel

# Ubuntu / Debian
sudo apt install libssl-dev pkg-config

# macOS (Homebrew)
brew install openssl@3
export PKG_CONFIG_PATH="$(brew --prefix openssl@3)/lib/pkgconfig"

Usage

[dependencies]
native-ossl = { version = "0.2" }

SHA-256

use native_ossl::digest::DigestAlg;

let sha256 = DigestAlg::fetch(c"SHA2-256", None)?;
let mut ctx = sha256.new_context()?;
ctx.update(b"hello world")?;
let mut out = [0u8; 32];
ctx.finish(&mut out)?;

AES-256-GCM

use native_ossl::{cipher::{CipherAlg, AeadEncryptCtx, AeadDecryptCtx}, rand::Rand};

let alg = CipherAlg::fetch(c"AES-256-GCM", None)?;
let mut key = [0u8; 32];
let mut nonce = [0u8; 12];
Rand::fill(&mut key)?;
Rand::fill(&mut nonce)?;

let mut enc = AeadEncryptCtx::new(&alg, &key, &nonce, None)?;
let mut ct = vec![0u8; plaintext.len()];
enc.update(plaintext, &mut ct)?;
enc.finalize(&mut ct[n..])?;
let mut tag = [0u8; 16];
enc.tag(&mut tag)?;

HKDF

use native_ossl::{digest::DigestAlg, kdf::HkdfBuilder};

let sha256 = DigestAlg::fetch(c"SHA2-256", None)?;
let mut okm = [0u8; 32];
HkdfBuilder::new(&sha256)
    .key(ikm)
    .salt(salt)
    .info(info)
    .derive(&mut okm)?;

Ed25519 sign / verify

use native_ossl::pkey::KeygenCtx;

let key = KeygenCtx::new(c"ED25519")?.generate()?;
let sig = key.sign_oneshot(message)?;
key.verify_oneshot(&sig, message)?;

TLS client (fluent builder)

use native_ossl::ssl::{SslCtxBuilder, Client, TlsVersion, HostnameFlags};

let ctx = SslCtxBuilder::<Client>::new()?
    .min_proto_version(TlsVersion::Tls12)?
    .default_ca_paths()?
    .verify_peer()
    .verify_hostname("example.com")?
    .verify_hostname_flags(HostnameFlags::NO_PARTIAL_WILDCARDS)?
    .build()?;

let mut ssl = ctx.new_ssl()?;
ssl.set_connect_state();
ssl.connect()?;

Inspect certificate signature algorithm

use native_ossl::x509::X509;

let cert = X509::from_pem(&std::fs::read("cert.pem")?)?;
let info = cert.signature_info()?;
// info.md_nid, info.pk_nid, info.security_bits
println!("pk_nid={} md_nid={} bits={}", info.pk_nid, info.md_nid, info.security_bits);

Cargo features

Feature Default Effect
dynamic yes Link against the system OpenSSL via pkg-config
vendored no Build a specific OpenSSL source tree (set NATIVE_OSSL_OPENSSL_SOURCES)
fips no Link libfips.a instead of libcrypto.a
fips-provider no Enable non-public provider-internal bindings (OPENSSL_SOURCE_DIR required)

Version-gated APIs

The build system detects the installed OpenSSL version automatically and activates the appropriate #[cfg(...)] gates. No manual flags are needed.

cfg flag Minimum APIs
ossl320 3.2.0 MessageSigner, MessageVerifier, EncapCtx, DecapCtx, GlobalRandCtx
ossl350 3.5.0 SshkdfBuilder, KbkdfBuilder
ossl_v400 4.0.0 DigestCtx::serialize / deserialize
ossl_slhdsa — SLH-DSA key operations
ossl_mldsa — ML-DSA key operations
ossl_mlkem — ML-KEM encapsulate / decapsulate

Algorithm flags (ossl_slhdsa, ossl_mldsa, ossl_mlkem) are detected from header macros rather than the version number, so they track distribution backports correctly.

Building and testing

cargo build
cargo test --all
cargo clippy --all-targets -- -D warnings

See docs/src/dev/building.md for FIPS mode, fips-provider, vendored builds, and the full CI checklist.

Documentation

cargo install mdbook
cd docs && mdbook build --open

Or browse the source under docs/src/.

License

Apache-2.0. See LICENSE.