otp_crypto/decryptor library
Decryptor – Verifies & decrypts a SecureMessage (Encrypt-then-MAC)
Processing order (DO NOT change):
- Validate protocol version and time-window skew.
- Derive {encKey, macKey} via HKDF-SHA256 from config.
- Recompute tag = HMAC(macKey, "tag" || u64be(w) || nonce || ciphertext).
- Constant-time compare with body tag; if mismatch → AuthenticationFailed.
- Derive IV = HMAC(macKey, "iv" || u64be(w) || nonce)
:16
. - Decrypt AES-256-CBC + PKCS#7 using encKey+IV → plaintext.
NOTES:
- This class does not handle HTTP. It only consumes a
SecureMessage
reconstructed from wire headers/body. - Time skew tolerance is enforced before any crypto to fail fast.
- We always verify MAC before decrypting (Encrypt-then-MAC).
HINTS:
- Keep a single
Decryptor
around; it caches HKDF-derived keys. - Configure
verificationSkewWindows
inOtpCryptoConfig
to accept ±N adjacent windows relative to current window.