-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Project Phoenix (v5.0): The Definitive Plan for a Fortress-Grade, Auditable, and Hybrid VSS Library
1. Executive Summary & Vision
The current feldman_vss.py is a feature-complete, research-grade cryptographic prototype. This project will transform it into a maintainable, testable, auditable, and provably secure library suitable for production use in high-stakes, adversarial environments. It will serve as a reference implementation for secure software engineering, architected from day one as a hybrid Python-native system.
This plan adopts a strategy of "Fortified Hybrid Architecture with Provable Security." We will not only refactor the Python monolith but also explicitly define the boundaries and interfaces for security-critical native extensions. The final deliverable will be a library that provides best-effort security in pure Python while offering a clear, planned upgrade path to hardware-level security guarantees via a native backend. It will be secure by design, secure by default, and transparent about its operational security guarantees.
2. Guiding Principles
- Honesty About Limitations: The library will be explicit and programmatic about the security guarantees it can and cannot provide in a pure Python environment. We will not create a false sense of security. Why: Trust in a cryptographic library is paramount. By being transparent about Python's inherent weaknesses (e.g., lack of true constant-time execution), we prevent users from making incorrect security assumptions and build a foundation of trust.
- Hybrid by Design: The architecture will be designed from the outset to seamlessly integrate a native (Rust) core for operations that are impossible to secure in Python (constant-time arithmetic, secure memory wiping). Why: This acknowledges reality. Instead of pretending Python can do everything, we design a system where Python handles the high-level logic and orchestration, while a small, auditable native core handles the security-critical primitives. This gives us the best of both worlds: development speed and ironclad security where it matters most.
- Layered Security & Ergonomics: The API will offer layers of security. A simple, default API will provide strong, practical security for common use cases. An advanced builder API will allow expert users to configure a fortress-grade security posture for high-threat environments. Why: A single, highly complex API leads to user error. By providing a safe, simple default, we protect most users from misconfiguration. The advanced API empowers experts without burdening novices.
- Cryptographic Agility & Provider Model: The library will use a provider model for all cryptographic and security primitives. Why: This future-proofs the library. If a vulnerability is found in a chosen algorithm (e.g., BLAKE3), a new, secure provider can be swapped in at the configuration level without requiring a full rewrite of the protocol logic. It also enables the transparent swapping of Python implementations for native ones.
- Formal Verification Hooks: The code will be structured with explicit pre- and post-conditions (
@requires/@ensuresstyle comments) to facilitate future formal verification. Why: While full formal verification is outside the scope of this refactor, structuring the code this way from the start dramatically lowers the cost of applying tools like Dafny or CrossHair later. It forces developers to think about and document the invariants their code must maintain. - Comprehensive Auditability: Every security-critical action will be logged to an immutable, cryptographically-chained audit trail. Why: In a security incident, a verifiable audit trail is indispensable for forensics. It allows operators to answer "what happened?" with cryptographic certainty. It's a key requirement for compliance in many regulated industries.
- Test-Driven Security: The testing strategy will include not just functional tests but also a dedicated adversarial framework for simulating sophisticated attacks. Why: This treats security as a testable property, not an abstract quality. By writing tests that embody specific attacks, we can prove the system is resistant to them, rather than just hoping it is.
3. Final Target Architecture
src/
└── pq_vss/
├── __init__.py # Public API entry point with critical dependency validation.
├── api.py # Defines the simple (create_standard) and advanced (builder) APIs.
├── vss.py # The core FeldmanVSS class, orchestrating calls to providers.
├── config.py # VSSConfig and SecurityLevel dataclasses.
├── group.py # CyclicGroup class, using cryptographic providers.
├── protocols.py # High-level protocol logic (refresh_shares, ZKPs).
├── exceptions.py # All custom exception and warning classes.
├── providers/ # Pluggable providers for core functionality.
│ ├── __init__.py
│ ├── base.py # Abstract base classes (CryptoProvider, TimingProvider, MemoryProvider).
│ ├── python.py # Default, best-effort pure Python implementations.
│ └── native.py # Thin, safe Python interface (FFI) to the compiled native library.
└── security/ # Core security mechanisms.
├── __init__.py
├── audit.py # SecurityAuditTrail class with configurable backends.
└── metrics.py # VSSMetrics class for operational security monitoring.
native/
└── rust/ # Rust source code for the native security core.
├── Cargo.toml
└── src/
├── lib.rs # FFI definitions using pyo3.
├── crypto.rs
└── timing.rs
tests/
├── __init__.py
├── conftest.py # Pytest fixtures (malicious actors, test harnesses).
├── adversarial/ # A dedicated framework for simulating advanced attacks.
│ ├── __init__.py
│ ├── test_malicious_dealer.py
│ ├── test_rushing_adversary.py
│ ├── test_byzantine_coalition.py
│ └── test_dos_attacks.py
├── fuzzing/ # Fuzzing targets and corpus for protocol messages.
├── chaos/ # Chaos engineering scripts for distributed scenarios.
├── formal/ # Property-based tests verifying mathematical invariants using Hypothesis.
├── regressions/ # Tests for previously fixed vulnerabilities.
├── test_group.py # Unit tests for CyclicGroup.
├── test_protocols.py # State machine tests for multi-party protocols.
├── test_security_mechanisms.py # Unit tests for audit trail, metrics, etc.
└── benchmarks/
└── test_performance.py # Performance and security regression tests.
docs/
├── ARCHITECTURE.md # High-level overview and Architectural Decision Records (ADRs).
├── THREAT_MODEL.md # Formal threat model, including DoS and side-channel attacks.
├── NATIVE_EXTENSION_STRATEGY.md # Detailed plan for the Rust FFI, focusing on safety and a minimal surface.
├── SECURITY.md # Detailed analysis of vulnerabilities, mitigations, and the security guarantee delta between Python and native modes.
└── COMPLIANCE/
├── FIPS_140-2.md # Analysis of compliance with FIPS 140-2 principles.
└── NIST_CSF.md # Mapping of library features to the NIST Cybersecurity Framework.
4. Detailed Phased Plan (Estimated Total: 35-45 Days)
Phase 1: Architecture & Provider Design (5-7 Days)
Goal: Design the core interfaces that will enable our hybrid architecture and configurable security. This design-first approach prevents costly architectural mistakes.
- Provider Interface Design (
providers/base.py):CryptoProvider: Defineshash,secure_random_bytes.TimingProvider: Definestiming_resistant_select,timing_resistant_equals. Why: We name itTimingResistantto be honest about the lack of true constant-time guarantees in Python. This provider will have aget_security_level()method that returns "BestEffort" for the Python implementation and "HardwareConstantTime" for the future native one.MemoryProvider: Definescreate_sensitive_buffer,wipe_buffer. This abstracts the memory-wiping logic.
- API Design (
api.py):- Design the simple
FeldmanVSS.create_standard()API, which will instantiate the system with a default, safeSecurityLevel. - Design the advanced
FeldmanVSS.builder()API, which allows injection of custom providers and security configurations.
- Design the simple
- Security Component Design:
SecurityAuditTrail(security/audit.py): Design the interface for the immutable, chained log, including support for different backend strategies (e.g., Null, Buffered, Direct).VSSMetrics(security/metrics.py): Design the interface for collecting operational security data (e.g., number of Byzantine detections, timing anomalies).
- Define Minimal FFI Surface (
docs/NATIVE_EXTENSION_STRATEGY.md): Draft the initial plan for the native extension. Mandate that the FFI boundary be as small as possible. The native library will expose simple, primitive functions (e.g.,secure_equals(a: bytes, b: bytes) -> bool). The Python provider will handle all complex logic and data conversion.
Phase 2: The Great Migration & Provider Implementation (6-8 Days)
Goal: Decompose the monolith and implement the default pure Python providers.
- Module Decomposition: Migrate all code to its new home as per the architecture.
- Implement Python Providers (
providers/python.py): Create the default, pure-Python implementations forCryptoProvider,TimingProvider, andMemoryProvider. TheTimingProviderwill use bitwise operations, and theMemoryProviderwill use the multi-pattern wipe, both with prominent docstrings explaining their limitations. - Implement Dependency Injection: Refactor
FeldmanVSSand other classes to accept the provider interfaces in their constructors. Theapi.pyfunctions will be responsible for creating and injecting the default Python providers. - Refactor & Verify: Fix all imports and type errors. All baseline functional tests must pass.
Phase 3: Security Mechanism Implementation (7-9 Days)
Goal: Build the security features designed in the previous phase.
- Implement
SecurityAuditTrailandVSSMetrics: Build the classes designed in Phase 1. Integrate calls to them at critical points in the code. - Implement Configurable Audit Backends: The
SecurityAuditTrailwill be implemented with a provider model to support different backends:NullAuditTrail(no-op for max performance),BufferedAuditTrail(in-memory with periodic flushes), andDirectAuditTrail(synchronous writes). - Implement Formal Verification Hooks: Add comments like
@requires(...)and@ensures(...)to key mathematical and protocol functions. Why: While not enforced by the Python runtime, these annotations make the code's intended invariants explicit for human auditors and can be used by static analysis tools likeCrossHair. - Implement Hardened Streaming Deserializer: Re-architect the deserialization logic to be a streaming process. It will enforce a strict memory budget on the
msgpack.Unpacker, never reading an entire untrusted payload into memory at once. It will reject any message that would exceed its budget before allocation, providing robust protection against memory exhaustion DoS attacks.
Phase 4: Comprehensive Testing & Assurance (10-14 Days)
Goal: Rigorously validate the library's security and correctness using a dedicated adversarial framework.
- Formal Property Testing (
formal/): UseHypothesisto write tests that verify the mathematical properties of the VSS scheme (e.g.,reconstruct(share(secret)) == secret). Why: This catches logical and mathematical bugs that example-based testing would miss. - Adversarial Testing Framework (
adversarial/): Build a dedicated testing framework to simulate specific, named attacks.MaliciousDealer: A test that verifies clients can always detect a dealer distributing inconsistent shares.RushingAdversary: An adversary that waits until all honest parties have sent their messages before sending its own, trying to influence the outcome.ByzantineCoalition: A test simulating a coordinated attack byt-1parties. Why: Testing against single Byzantine actors is insufficient. A coordinated coalition represents a much more powerful adversary.
- Denial-of-Service (DoS) Resistance Testing (
adversarial/test_dos_attacks.py):- Memory Exhaustion Fuzzing: Fuzzing targets will not just look for crashes, but for valid inputs that cause extreme memory allocation.
- Computational Complexity Attacks: Craft valid inputs that target worst-case algorithmic performance to ensure the system remains responsive.
- Protocol Resource Starvation: Test how protocols behave when a malicious party sends valid-but-late messages or floods other parties with verification requests.
- Protocol State Machine Testing (
test_protocols.py): Implement explicit state machine tests for multi-party protocols likerefresh_shares. Define all valid states (AwaitingZeroShares,Verifying) and transitions, and write tests to prove that any out-of-order or invalid messages are correctly rejected. - Security Regression Suite (
regressions/): For every fixed security vulnerability, a new test that specifically triggers the old vulnerability will be added to this suite. This test MUST fail on the pre-patch commit and pass on the post-patch commit.
Phase 5: Documentation & Release (4-6 Days)
Goal: Produce a complete, honest, and professional documentation suite and prepare for release.
- Finalize Documentation:
SECURITY.md: This is the most critical document. It will explicitly state: "The pure PythonTimingProviderdoes NOT provide constant-time guarantees. For environments where timing side-channels are a concern, a native implementation MUST be used." It will also include instructions for verifying release signatures.- Compliance Docs: Complete the initial drafts for
FIPS_140-2.mdandNIST_CSF.md. - Operational Runbooks: Create simple runbooks for "Responding to a Byzantine Detection Alert" and "Interpreting the Audit Trail."
- Implement Release Signing & Verification: Integrate
sigstoreinto the CI/CD release pipeline to cryptographically sign all release artifacts. - Final Review: Conduct a final, comprehensive self-review of all code and documentation.
- Release: Merge to
main, tag version1.0.0, and publish a detailedCHANGELOG.md.
6. New Entities & Concepts: Detailed Explanations
providers/(Provider Model):- Description: This directory contains the implementation of the "Strategy" design pattern for all core security functionality. The
base.pyfile defines the interfaces (the "what"), and other files likepython.pyandnative.pyprovide the concrete implementations (the "how"). - Why: This decouples the high-level protocol logic from the low-level cryptographic and security primitives. It allows us to swap out the entire security engine of the library by changing a single configuration parameter, enabling cryptographic agility and a seamless upgrade path from a pure Python backend to a high-performance, high-security native backend.
- Description: This directory contains the implementation of the "Strategy" design pattern for all core security functionality. The
security/(Security Mechanisms):- Description: This module contains cross-cutting security concerns that are not tied to a specific cryptographic primitive.
audit.py(SecurityAuditTrail): An append-only, cryptographically-chained log. Each new entry is hashed with the hash of the previous entry, creating a tamper-evident chain. This provides a high-integrity record of all security-sensitive operations.metrics.py(VSSMetrics): A mechanism to collect and expose operational security metrics (e.g., number of failed verifications, detected Byzantine parties) for monitoring systems like Prometheus or Datadog. This turns security events into observable data.
api.py(Layered API):- Description: This file provides the two main public entry points for creating a
FeldmanVSSinstance. create_standard(): A simple factory function for users who need a secure, well-configured instance without understanding the underlying details. It uses a safe, defaultSecurityLevel.builder(): A fluent builder pattern for expert users who need to customize the security posture, inject custom providers, or fine-tune performance parameters.- Why: This layered approach satisfies the needs of both novice and expert users, promoting ease of use without sacrificing power and configurability.
- Description: This file provides the two main public entry points for creating a
formal/(Formal Property Testing):- Description: This test directory will contain tests written with the
Hypothesislibrary. Instead of testing specific examples, these tests define abstract properties that must always hold true for the VSS scheme. For example: "For any valid polynomial of degreet-1, if we generatenshares (n >= t), anytof those shares can reconstruct the original secret." Hypothesis then generates hundreds or thousands of random inputs to try and find a counterexample that falsifies the property. - Why: This is a much more powerful testing technique than traditional example-based unit testing for finding subtle mathematical and logical errors in algorithms.
- Description: This test directory will contain tests written with the
7. Risk Assessment & Mitigation
- Risk: Users develop a false sense of security from the Python-only mode.
- Mitigation: Aggressive and explicit documentation in
SECURITY.md. RuntimeSecurityWarnings will be issued when using the PythonTimingProvider. The API naming itself (TimingResistantvs.ConstantTime) reinforces this.
- Mitigation: Aggressive and explicit documentation in
- Risk: The complexity of the advanced API hinders adoption.
- Mitigation: The
FeldmanVSS.create_standard()simple API provides a safe, easy entry point for 80% of use cases, hiding the complexity of the builder.
- Mitigation: The
- Risk: The native extension FFI boundary introduces new vulnerabilities (e.g., memory safety bugs, type mismatches).
- Mitigation: The
NATIVE_EXTENSION_STRATEGY.mdwill mandate Rust withpyo3for a memory-safe FFI. The FFI surface will be minimal, exposing only simple, primitive functions. All complex data conversion and logic will remain in the Python provider, drastically reducing the attack surface of the native code.
- Mitigation: The
- Risk: The library is vulnerable to Denial-of-Service attacks (memory exhaustion, computational complexity).
- Mitigation: The hardened streaming deserializer prevents memory bombs. The adversarial testing framework will include dedicated tests for computational complexity attacks and protocol-level resource starvation, ensuring resilience.
- Risk: Testing for timing leaks is inherently flaky and platform-dependent.
- Mitigation: Timing tests will be statistical and run multiple times, reporting confidence intervals rather than pass/fail. They will be marked as optional and primarily used for analysis rather than as a strict CI gate.