Skip to main content

hpqc (Python)

A Python port of selected primitives from katzenpost/hpqc, the hybrid post-quantum cryptography library used by the Katzenpost mix network. The Go implementation is the reference; this Python package covers BACAP, MKEM, and the NIKE primitives those depend on, so Python applications and tooling can perform these operations directly. The shared JSON test vectors under testvectors/ keep the Python and Go ports byte-identical.

For the rationale behind BACAP and a short overview of the construction, see the BACAP section of the main README. For a fuller treatment, see §4 of the Echomix paper. For the full catalogue of NIKE, KEM, and signature schemes that hpqc implements in Go, see the main repository README.

What is ported

  • BACAP (hpqc.bacap): blinding-and-capability scheme. Positions (ReadPosition, WritePosition) and the stateless API (immutable MessageBoxIndex, WriteCap, ReadCap). Encrypt, decrypt, sign, verify, and tombstones are all covered.
  • MKEM (hpqc.kem.mkem): multi-recipient KEM construction over any NIKE.
  • NIKE abstractions (hpqc.nike.scheme): Scheme, PublicKey, PrivateKey base classes mirroring the Go interfaces.
  • NIKE primitives: X25519 (hpqc.nike.x25519), CTIDH at field sizes 511, 512, 1024, and 2048 (hpqc.nike.ctidh{511,512,1024,2048}, via the upstream highctidh package), and a generic HybridNIKE combiner (hpqc.nike.hybrid).
  • Ed25519 signature verification (hpqc.sign.ed25519): the blinded Ed25519 variant on which BACAP relies, plus an Ed25519Scheme verify-only wrapper for plain Ed25519.
  • Falcon-padded-512 signature verification (hpqc.sign.falcon.FalconPadded512Scheme), backed by the pqcrypto runtime dependency, which vendors the same PQClean reference C used by the Go side.
  • Hybrid signature verification (hpqc.sign.hybrid): generic two-component combiner plus a pre-registered FalconPadded512Ed25519 instance.

The Python and Go test suites read the same JSON vector files via per-file symlinks under tests/.../vectors/, so any byte-level divergence between the two ports trips a failing assertion on whichever side runs first.

Installation

pip install hpqc

Runtime dependencies (pynacl, cryptography, cbor2, highctidh, pqcrypto) are pulled in automatically.

To install from a source checkout instead (for example to test an unreleased change):

pip install -e /path/to/hpqc/py

Quick start

A BACAP round-trip:

from hpqc.bacap import WriteCap

writer = WriteCap.generate()
reader = writer.read_cap()
ctx = b"my-application/v1"

mbi = writer.message_box_index
box_id, ciphertext, signature = mbi.encrypt_for_context(
    writer, ctx, b"hello, pigeonhole"
)

# Anyone holding the read cap can verify and decrypt:
plaintext = mbi.decrypt_for_context(box_id, ctx, ciphertext, signature)
assert plaintext == b"hello, pigeonhole"

Encapsulating a payload to multiple recipients with MKEM:

from hpqc.kem.mkem import MKEMScheme
from hpqc.nike.x25519 import X25519

mkem = MKEMScheme(X25519())
alice_pk, alice_sk = mkem.generate_keypair()
bob_pk,   bob_sk   = mkem.generate_keypair()

eph_priv, ct = mkem.encapsulate([alice_pk, bob_pk], b"secret payload")
assert mkem.decapsulate(alice_sk, ct) == b"secret payload"
assert mkem.decapsulate(bob_sk,   ct) == b"secret payload"

Running the tests

cd hpqc/py
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[test]"
pytest

Cross-language vector tests live under tests/bacap/, tests/kem/, and tests/sign/. They symlink into the canonical JSON vectors under ../testvectors/, which the Go test suite also consumes.

License

AGPL-3.0-only. See LICENSE.

See also

Metadata

Release files for hpqc 0.0.93

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hpqc 0.0.93
File Size Uploaded
hpqc-0.0.93.tar.gz 63.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hpqc 0.0.93
File Interpreter ABI Platform
hpqc-0.0.93-py3-none-any.whl Python 3 none any Details

Total release size: 123.0 kB

Release files / hpqc-0.0.93.tar.gz

Download URL hpqc-0.0.93.tar.gz
Size 63.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8e10c74ae20d46823ce43c51ddeddf669cf3f24111e739b483c0f1ce6a690659
BLAKE2b-256 checksum
How to use checksums
e6230cd81a186092c0ce0da599d09ff8a95352edb20118a84cc057d2117b70d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / hpqc-0.0.93-py3-none-any.whl

Download URL hpqc-0.0.93-py3-none-any.whl
Size 59.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05b52b9d0e48fa6a5c5e3663343dda538096bb0ca846d7835355751fc16a2061
BLAKE2b-256 checksum
How to use checksums
976e94102bad0fd54ff0fd8e0fb0e8e7dc53e7266345c56a79bd0153d294c1a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.93 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page