| Recommend this page to a friend! |
| Packages of Mohamed Abdulalim | Crypto | src/Reversible/docs/ADR-001-Reversible-Crypto-Design.md | Download |
|
|||||||||||||||||||||
ADR-001: Reversible Cryptography ArchitectureStatusAccepted / Locked Date2026-01-08 ContextThe system requires a cryptographic mechanism that allows:
Primary use cases include: - Email queues - Webhook payloads - Deferred job processing - Secure storage of recoverable data This explicitly excludes: - Password hashing - One-way secrets - Authentication tokens - Integrity-only cryptography DecisionWe implemented a Reversible Cryptography Module with the following principles: 1. Reversible ? HashingReversible cryptography is treated as a distinct concern from hashing.
All naming, interfaces, and structure explicitly reflect reversibility. 2. Algorithm Execution Is IsolatedEach cryptographic algorithm is implemented as a self-contained class:
Example:
- This prevents: - Implicit mappings - Configuration-driven crypto behavior - Hidden execution logic 3. Enums Define Policy, Not Execution
Enums MUST NOT: - Contain cryptographic logic - Provide OpenSSL cipher names - Influence execution details 4. Registry Enforces Security BoundariesA dedicated registry: - Explicitly binds enums to implementations - Prevents unsupported algorithms - Prevents accidental or dynamic algorithm usage No algorithm can be used unless: - It is defined in the enum - It is registered in the registry 5. Service Is Pure Orchestration
It only: - Selects the algorithm - Selects the key - Passes data and metadata - Returns structured results 6. Key Management Is ExternalThe module explicitly does NOT handle: - Key generation - Key storage - Key rotation - Environment loading Key rotation is considered a policy concern, not a cryptographic primitive. The module only requires: - A key map - An active key identifier 7. Fail-Closed Security ModelAll cryptographic operations are fail-closed:
Any failure results in a hard exception: - Unsupported algorithm - Missing key - Invalid authentication tag - Corrupted ciphertext - Decryption failure 8. AEAD-First StrategyAuthenticated Encryption with Associated Data (AEAD) is the default.
ECB mode is explicitly forbidden. ConsequencesPositive
Trade-offs
These trade-offs are intentional and accepted. Alternatives Considered? Single Service with OpenSSL CallsRejected due to: - Tight coupling - Hard-to-test code - Unsafe extensibility ? Enum-Driven Cipher ExecutionRejected due to: - Hidden execution behavior - Configuration-driven crypto risks - Poor separation of concerns ? Automatic Key Rotation Inside ModuleRejected due to: - Mixing crypto primitives with policy - Increased complexity - Reduced auditability Final NotesThis design is intentionally strict. Cryptography must be: - Explicit - Predictable - Auditable - Difficult to misuse Any deviation from this architecture requires a new ADR. End of Record |