hashsigs-py README

The project's README from github.com/QuipNetwork/hashsigs-py. As one markdown file: README.md.

hashsigs (Python)

Python package for WOTS+ with optional Rust acceleration from hashsigs-rs.

Installation

pip install hashsigs

For best performance, ensure you have Rust installed (the package will automatically build the Rust extension if available):

# Install Rust toolchain (optional, for better performance)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Then install hashsigs
pip install hashsigs

Quick Usage

import hashsigs

# Create a WOTS+ instance
wots = hashsigs.WOTSPlus()

# Generate a key pair
private_key, public_key = wots.generate_key_pair()

# Sign a message
message = b"Hello, world!"
signature = wots.sign(private_key, message)

# Verify the signature
is_valid = wots.verify(public_key, message, signature)
print(f"Signature valid: {is_valid}")  # True

# Check if Rust acceleration is available
try:
    import hashsigs._rust
    print("Using Rust acceleration")
except ImportError:
    print("Using pure Python implementation")

Development Setup

For contributors and advanced users who want to build from source:

# from the repo root
python3 -m venv .hashsigs
source .hashsigs/bin/activate
python -m pip install -U pip pytest pytest-cov

# Ensure Rust toolchain (required to build the optional extension)
# macOS: also ensure Xcode CLT: xcode-select --install
rustup --version || brew install rust
cargo --version

# Install dev deps and try to build rust extension (quote extras in zsh)
pip install -v -e '.[rust,dev]'
# Install keccak provider (required for vectors when falling back to Python)
pip install pycryptodome
# or: pip install pysha3

# Quick check the extension is present (optional)
python -c "import hashsigs._rust as m; print('rust ext ok:', m)"

# Lint + type + tests with coverage; this is the full suite
pytest -q --cov=hashsigs --cov-report=term-missing

If the Rust toolchain is not available, the above will fail on the rust-backed vector tests. See the “Test options” section for alternatives.

Test options

You can choose between three categories:

Troubleshooting

Usage example

from hashsigs import WOTSPlus

# Prefer the Rust backend if available; falls back to Python keccak provider if not
wots = WOTSPlus.keccak256(prefer_rust=True)

# Derive a keypair from a 32-byte seed
seed = bytes([1]) * 32
pk, sk = wots.generate_key_pair(seed)

# Sign and verify a 32-byte message
msg = bytes([2]) * 32
sig = wots.sign(sk, msg)
assert wots.verify(pk, msg, sig)
print("Signature verifies!")

Quick self-check (from shell)

Run a one-liner to confirm the package imports, the Rust extension is available (optional), and basic operations work:

python - <<'PY'
from hashsigs import WOTSPlus
try:
    import hashsigs._rust as _
    print('Rust extension: available')
except Exception:
    print('Rust extension: not available (falling back to Python)')

wots = WOTSPlus.keccak256(prefer_rust=True)
seed = bytes([1]) * 32
pk, sk = wots.generate_key_pair(seed)
msg = bytes([2]) * 32
sig = wots.sign(sk, msg)
print('verify:', wots.verify(pk, msg, sig))
PY

Rust backend

We now depend on the public crate and repository:

The Python bindings (PyO3) will attempt to build against the published crate during installation. If the build fails, the package still installs and falls back to pure Python.

License

AGPL-3.0-or-later; see COPYING

hashsigs-py (QuipNetwork/hashsigs-py)

Searching Database…

What is this?It is a Python package implementing WOTS+ (Winternitz One-Time Signature Plus), a hash-based post-quantum digital signature scheme, with optional Rust acceleration via hashsigs-rs.
Is this a standalone app or a library I import into my code?It is a Python library you install into a project and call from your own code; it has an optional Rust-backed extension for performance but falls back to pure Python if that is unavailable.
How do I install and try it?Install it as an editable package with pip and run the quick self-check one-liner from the shell to confirm it imports and basic operations work; the full dev setup uses pip install -e with the rust and dev extras plus pycryptodome.
Do I need Rust installed to use it?No, Rust is optional for best performance; the package automatically builds the Rust extension if Rust is available, otherwise it runs in pure Python mode.
Any install pitfalls I should know about?On Python 3.13/macOS, the pysha3 dependency can fail to build with a missing pystrhex.h error; the fix is to install pycryptodome instead, or use Python 3.11/3.12.
What is WOTS+?WOTS+ (Winternitz One-Time Signature Plus) is a hash-based digital signature scheme considered resistant to attacks from quantum computers, often used as a building block in post-quantum signature schemes.
How do I run the tests?There are three test tiers: full tests (vectors plus Rust-backed plus lint/type/coverage) needing keccak and the Rust extension, a basic tier needing only a keccak provider without Rust (HASHSIGSBUILDRUST=0 pytest -q -m \'not requiresrust\'), and a minimal tier with no keccak dependency using hashlib.sha3_256 (pytest -q -m \'not vectors\').
What happens if the Rust extension fails to build?Installation still succeeds, and the package transparently falls back to a pure Python implementation.
What does the Rust backend depend on?It depends on the published hashsigs-rs crate (version 0.0.2), which the PyO3 Python bindings try to build against during installation.
Size
0.1 MB
Stars
11.2K
Updated
CommitAug 27
Age
1y
Commits · 90 Days