Skip to main content

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 (immutable MessageBoxIndex, 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, 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.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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hpqc-0.0.2.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hpqc-0.0.2-py3-none-any.whl (42.7 kB view details)

Uploaded Python 3

File details

Details for the file hpqc-0.0.2.tar.gz.

File metadata

  • Download URL: hpqc-0.0.2.tar.gz
  • Upload date:
  • Size: 41.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hpqc-0.0.2.tar.gz
Algorithm Hash digest
SHA256 65df1d76dd9f742fa4603c1d64e0b23e25bea7daaf191284151b6daa4c6d00f4
MD5 d18d2fdeaa867f7ad9445e66a87e4414
BLAKE2b-256 4e86ef1d332e08e2bf3f652941dd766e41db39f467312d25733f819620f8176d

See more details on using hashes here.

Provenance

The following attestation bundles were made for hpqc-0.0.2.tar.gz:

Publisher: publish-py.yml on katzenpost/hpqc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hpqc-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: hpqc-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 42.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hpqc-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8855707c653d495713ec84597de949ec6e437166c0e621f05125f3ed52563a5e
MD5 a28dab84c7c2c6dafabe981932652737
BLAKE2b-256 ff99a3044fab904031bc2bb64f70725eea2b7d1c19fff063a98302445b84de32

See more details on using hashes here.

Provenance

The following attestation bundles were made for hpqc-0.0.2-py3-none-any.whl:

Publisher: publish-py.yml on katzenpost/hpqc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page