Skip to main content

Quantum-resistant cryptographic hash functions for blockchain applications

Project description

Quantum-Resistant Hash Functions

A lightweight, pure Python implementation of quantum-resistant hash functions for blockchain applications.

Installation

Install from PyPI:

pip install dirac-hashes

For platform-specific optimized packages:

# For Linux, Windows, and macOS, pip will auto-select the appropriate wheel
pip install dirac-hashes

For developers or advanced users who want to build from source:

# Pure Python fallback if wheels aren't available
DIRAC_PURE_PYTHON=1 pip install dirac-hashes

See MANYLINUX.md for information on building manylinux-compatible wheels.

Features

  • DiracHash: Multiple pure Python hash algorithms with quantum resistance properties
  • QuantumEnhancedHash: High-performance hash implementation with strong security properties
  • No complex dependencies: Works with just Python standard library
  • Simple API: Easy to use with a consistent interface

Quick Start

from src.quantum_hash import DiracHash, QuantumEnhancedHash

# Basic usage
data = b"Hello, quantum world!"

# Using DiracHash
hash1 = DiracHash.hash(data)
print(f"DiracHash: {hash1.hex()}")

# Using QuantumEnhancedHash
hash2 = QuantumEnhancedHash.hash(data)
print(f"QuantumEnhancedHash: {hash2.hex()}")

# Different algorithms
hash3 = DiracHash.hash(data, algorithm="grover")
hash4 = DiracHash.hash(data, algorithm="shor")
print(f"Grover-resistant: {hash3.hex()}")
print(f"Shor-resistant: {hash4.hex()}")

# Custom digest size
hash5 = DiracHash.hash(data, digest_size=64)
print(f"Larger digest: {hash5.hex()}")

Testing

The framework includes comprehensive test suites to verify functionality, correctness, and performance.

Running Tests

To run all tests:

python test/run_tests.py

This will run the following test suites:

  1. Core hash function tests
  2. KEM (Key Encapsulation Mechanism) tests
  3. Signature scheme tests
  4. Performance benchmarks
  5. NIST statistical tests

Individual Test Suites

You can run specific test suites individually:

# Core hash functions
python test/test_suite.py

# KEM tests
python test/test_kem.py

# Signature tests
python test/test_signatures.py

# Performance benchmarks
python test/performance_benchmark.py

# NIST statistical tests
python test/nist_sts_tester.py

Documentation

For full documentation and usage examples, see the following:

  1. Tutorial - Comprehensive usage examples and integration guides
  2. Improvements - Planned improvements and feature roadmap

Benchmarking

For comprehensive benchmarks:

python advanced_benchmark.py

Add the --quick flag for faster benchmarks with fewer iterations:

python advanced_benchmark.py --quick

Performance

While pure Python implementations are not as fast as native C implementations of traditional hash functions, they offer quantum resistance with reasonable performance:

  • DiracHash: ~3-4 MB/s
  • QuantumEnhancedHash: ~3 MB/s

Algorithms

DiracHash Variants

  • standard: Basic DiracHash algorithm
  • improved: Enhanced version with better diffusion properties
  • grover: Resistant to Grover's quantum algorithm attacks
  • shor: Resistant to Shor's quantum algorithm attacks

QuantumEnhancedHash

Combines techniques from fast hash algorithms with quantum resistance properties for a balance of security and performance.

Post-Quantum Cryptography

This library also includes implementations of post-quantum cryptographic primitives:

Signature Schemes

  • Lamport: Simple hash-based one-time signatures
  • SPHINCS: Stateless hash-based signatures suitable for longer-term use
  • Dilithium: Lattice-based signatures with compact size

Key Encapsulation Mechanisms (KEM)

  • Kyber: Lattice-based KEM for secure key exchange

Security Considerations

This implementation is focused on being a functioning demonstration. For production applications, please:

  1. Review and audit the code thoroughly
  2. Conduct independent security analysis
  3. Consider using established cryptographic libraries when available

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

  1. Clone the repository
  2. Install development dependencies: pip install -e ".[dev]"
  3. Run tests: python test/run_tests.py

Building Wheels

This project uses GitHub Actions to automatically build manylinux-compatible wheels for Linux, Windows, and macOS.

For local development:

# Build wheels using cibuildwheel
./build_manylinux_wheels.sh

For more information, see MANYLINUX.md.

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

dirac_hashes-0.1.4.tar.gz (76.4 kB view details)

Uploaded Source

File details

Details for the file dirac_hashes-0.1.4.tar.gz.

File metadata

  • Download URL: dirac_hashes-0.1.4.tar.gz
  • Upload date:
  • Size: 76.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for dirac_hashes-0.1.4.tar.gz
Algorithm Hash digest
SHA256 54df40156bf422d3cf69a8e8fbeab4f575c7c4a9706e846cdd4a63294bae7d02
MD5 b90f7131b6b8c37ca6832e80b3134f1f
BLAKE2b-256 616a2a38deb001725075a0a949088160b1c5d027b84f5b3bb8e712184aaa534c

See more details on using hashes here.

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