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.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 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: 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, 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.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.95

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.95
File Size Uploaded Provenance Actions
hpqc-0.0.95.tar.gz 154.7 kB With provenance Details for hpqc-0.0.95.tar.gz

Built distribution (wheel)

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

Total release size: 216.6 kB

Release files / hpqc-0.0.95.tar.gz

Download URL hpqc-0.0.95.tar.gz
Size 154.7 kB
Tags Source
SHA-256 checksum
How to use checksums
28c7a50ae9ce6c67a7b8fb313adad95bb2956456231236eedaadb5d065d73678
BLAKE2b-256 checksum
How to use checksums
28cd877d93c11ef7f52b28d913c72b8f0f7ea08a84821f1f4c8fe6b9dbf505a5
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 1, 2026.

Transparency log

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

Download URL hpqc-0.0.95-py3-none-any.whl
Size 61.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
086c9300ac02700cef788130f2f3587bdeeb86d948e13f34cd8e4196c93e3ddc
BLAKE2b-256 checksum
How to use checksums
cc6cd05e6535d1d35ad576e65c6cdcab0cef68c5109614c46f33501d77ff2780
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 1, 2026.

Transparency log

Security for hpqc 0.0.95

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hpqc-0.0.95.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 1, 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