Skip to content

Practical Cryptography Engineering

Each walkthrough pairs a Python program using PyCA cryptography with a C program using OpenSSL. The examples exchange ordinary files, so you can inspect the inputs, switch languages halfway through, and see what happens when a message changes.

What you want to do Walkthrough
Keep a message confidential and detect changes Authenticated encryption
Establish the same secret on two machines Key establishment
Let others check who signed a message Digital signatures
Derive a key from a password with a memory-hard function Password derivation

Algorithm choices, December 2026

The examples pair a classical primitive with a post-quantum primitive where quantum computers change the choice most directly. X25519 and Ed25519 illustrate widely deployed elliptic-curve operations. ML-KEM-768 and ML-DSA-65 illustrate NIST's category 3 parameter sets for two different jobs. OpenSSL 3.5 introduced both families, and PyCA exposes them directly. For symmetric encryption, the two examples show the same authenticated-encryption interface with 256-bit keys. NIST standards · OpenSSL 3.5 release notes

Set up

Start with Installing prerequisites for macOS, Windows, or Ubuntu/Debian. The guide takes you from a clean machine through the first build and test run. On macOS and Linux, make help lists the local commands.

The walkthroughs use a POSIX shell, a fresh lab/ directory, and paths relative to the repository root. Keep that directory private. The examples create new output files, including unencrypted private keys and raw shared secrets. Use disposable keys and small local files. Each program holds a complete message in memory.

Use a private working directory on Windows so new keys inherit an appropriate access-control list. On POSIX, private outputs are created with owner-only permissions.

For commands with two outputs, choose two distinct, unused filenames. Both implementations open both files before writing either one. If an open, write, or close fails, the command exits with an error. An empty or incomplete file can remain. Discard the results of that run and retry with fresh paths.

Files and trust

Both languages serialize public keys as PEM SubjectPublicKeyInfo and private keys as PEM PKCS#8. The C commands use the configured OpenSSL provider policy for key generation and use. The C key reader rejects passphrase-protected PEM files without prompting. To exchange ML-KEM and ML-DSA private keys with Python, the examples write the seed-only PKCS#8 form. The provider must allow exporting the seed for this operation. File extensions are for the reader's convenience. The algorithm argument specifies what key the reader expects.

A public key can travel openly, but each recipient needs a trusted way to associate it with its owner. Copying both a message and its alleged signer's public key from an untrusted source gives the sender control over both.

Development and publication

make build builds the C programs. make test builds them and runs pytest against both implementations. make docs serves a local preview. GitHub Actions tests pull requests and builds the documentation. The Pages workflow deploys the reviewed default branch. Select GitHub Actions under Settings → Pages → Build and deployment when enabling publication.