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 page. 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 scheme tables.

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.protocols.mkem): multi-recipient KEM construction over any NIKE.
  • Sealed box (hpqc.protocols.sealedbox): anonymous public-key encryption to one recipient 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 package (the falcon extra), 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: the Python side reads copies under tests/.../vectors/, which tests/test_vector_copies.py keeps identical to the canonical files, 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) are pulled in automatically. Falcon verification needs the falcon extra, which adds pqcrypto:

pip install 'hpqc[falcon]'

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.protocols.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"

Sealing a payload to one recipient:

from hpqc.protocols.sealedbox import SealedBoxScheme
from hpqc.nike.x25519 import X25519

nike = X25519()
box = SealedBoxScheme(nike)
pk, sk = nike.generate_keypair()

ct = box.seal(pk, b"secret payload")
assert box.open(sk, pk, 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/protocols/, and tests/sign/. They read copies of the canonical JSON vectors under ../testvectors/, which the Go test suite also consumes. The copies are real files so that the sdist carries them; after regenerating the vectors, refresh them with the cp command that tests/test_vector_copies.py prints for each stale copy.

License

AGPL-3.0-only. See LICENSE.

See also

Metadata

Release files for hpqc 0.0.96

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.96
File Size Uploaded Provenance Actions
hpqc-0.0.96.tar.gz 159.7 kB With provenance Details for hpqc-0.0.96.tar.gz

Built distribution (wheel)

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

Total release size: 225.4 kB

Release files / hpqc-0.0.96.tar.gz

Download URL hpqc-0.0.96.tar.gz
Size 159.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f4fe7920012d8619697354a6e8f9fc156b389b239d1ab3815f24aed9b9b7fd32
BLAKE2b-256 checksum
How to use checksums
8365614231dd6faba8d218b2dc25ef36a7b51138d0f937d57e9c9e291e5d18ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 15, 2026.

Transparency log

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

Download URL hpqc-0.0.96-py3-none-any.whl
Size 65.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d451d4ac8e082adf530e399d28d94e7976100c0e2fdea040f2c4f1d02eb7317
BLAKE2b-256 checksum
How to use checksums
4720914c1d69102936981b89b1aa53a902733a9d9e735327b6adc6bbdc34813c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 15, 2026.

Transparency log

Security for hpqc 0.0.96

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hpqc-0.0.96.tar.gz

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 Nov 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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