Python port of katzenpost/hpqc: hybrid post-quantum cryptography and BACAP.
Project description
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. Stateless API (immutableMessageBoxIndex,WriteCap,ReadCap) plus stateful reader/writer wrappers. 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,PrivateKeybase 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 upstreamhighctidhpackage), and a genericHybridNIKEcombiner (hpqc.nike.hybrid). - Ed25519 signing (
hpqc.sign.ed25519), including the blinded Ed25519 variant on which BACAP relies.
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
The package is not yet published to PyPI. Until it is, install from a checkout:
pip install -e /path/to/hpqc/py
Once published:
pip install hpqc
Runtime dependencies (pynacl, cryptography, cbor2,
highctidh) are pulled in automatically.
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.first_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
- Main repository README — full Go reference, design notes, and tables of every NIKE, KEM, and signature scheme that hpqc implements.
- Echomix paper — the design of BACAP (§4) and Pigeonhole (§5).
- Katzenpost mix network — the system this library serves.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hpqc-0.0.1.tar.gz.
File metadata
- Download URL: hpqc-0.0.1.tar.gz
- Upload date:
- Size: 38.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17853bceddb96d2c9941de6cfcdd3221a8076c074d33d60ad94ece70923e92bf
|
|
| MD5 |
501271b757bec91d8db528073904534b
|
|
| BLAKE2b-256 |
c71aee39cad94c598fd9d9307eebc1c7dee49c742123de6d5841596b45e53126
|
File details
Details for the file hpqc-0.0.1-py3-none-any.whl.
File metadata
- Download URL: hpqc-0.0.1-py3-none-any.whl
- Upload date:
- Size: 38.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e294e2ffa674822e9aaeb990fe4f940a3c21f354aa45c9f583d0af3d06d66bcd
|
|
| MD5 |
f64562d7b061d9147fe97ea8ca3be4fd
|
|
| BLAKE2b-256 |
f1cb91f1f3e59192c2eed88a408df258d080c502ab90c936774f86829001f236
|