| Recommend this page to a friend! |
| Packages of Mohamed Abdulalim | Crypto | src/HKDF/HOW_TO_USE.md | Download |
|
|||||||||||||||||||||
HKDF Module ? How To UseThis document explains the correct and approved usage of the HKDF module within the Admin Control Panel architecture. This is a consumer-facing guide.
Architectural intent and design rationale are documented in PrerequisitesBefore using HKDF, the following MUST already be in place:
HKDF MUST NOT be used in isolation. Basic Usage FlowThe approved usage flow is:
HKDF is responsible only for key derivation. Step 1 ? Obtain the Root KeyHKDF NEVER generates or stores root keys. A root key MUST come from the Key Rotation module:
The root key is treated as binary secret material. Step 2 ? Define a ContextEvery cryptographic use-case MUST define its own context. Contexts MUST be:
Example
Contexts SHOULD be defined as constants in the consuming module, not inline strings scattered across the codebase. Step 3 ? Derive a KeyUse
The returned key is a binary string suitable for direct use with cryptographic primitives. Step 4 ? Use the Derived KeyThe derived key can now be used with cryptographic primitives:
HKDF does NOT perform encryption or hashing itself. Context Versioning StrategyContexts MUST be versioned to preserve backward compatibility. Example
When a context version changes:
Versioning is the ONLY approved mechanism for context evolution. Approved Usage Examples| Use Case | Context |
| ----------------------------- | -------------------------- |
| Email notification encryption | Each context MUST map to exactly one cryptographic responsibility. Common Mistakes (DO NOT DO THIS)? Using user input as context
Contexts must never be dynamic. ? Reusing the same context across multiple purposes
Too generic. This defeats domain separation. ? Using HKDF as a replacement for key rotationHKDF does not manage key lifecycle. Rotation MUST be handled by the Key Rotation module. ? Storing derived keysDerived keys MUST be treated as ephemeral runtime material. They MUST NOT be persisted. Error HandlingHKDF follows a fail-closed design. Any invariant violation results in an exception:
Consumers MUST NOT attempt to recover silently. Security Notes
Misuse of HKDF is considered a security defect, not a feature bug. Final ReminderHKDF is an organizational cryptographic layer. Use it to:
Do NOT use it to:
Follow the rules. |