core.kdf
TLS Key Derivation Function implementations for validation.
Provides pure-stdlib (hmac + hashlib) implementations of: - TLS 1.2 PRF (RFC 5246, Section 5) based on P_SHA256 - TLS 1.3 HKDF functions (RFC 8446, Section 7) based on HKDF-Extract/Expand
These are used by the constraint validator algorithm to verify that candidate key bytes found in memory dumps satisfy the expected KDF relationships (e.g. a candidate master secret actually derives from a candidate pre-master secret via the TLS 1.2 PRF).
- class TLS12PRF[source]
Bases:
objectTLS 1.2 Pseudo-Random Function (RFC 5246).
TLS 1.2 uses a single PRF based on P_SHA256:
PRF(secret, label, seed) = P_SHA256(secret, label + seed)
where P_hash is the iterative HMAC expansion defined in Section 5.
- static p_hash(secret, seed, length, hash_algo='sha256')[source]
P_hash expansion (RFC 5246 Section 5).
Iteratively applies HMAC: A(i) = HMAC(secret, A(i-1)), output = HMAC(secret, A(1)+seed) || HMAC(secret, A(2)+seed) || …
- static prf(secret, label, seed, length, hash_algo='sha256')[source]
PRF(secret, label, seed) = P_SHA256(secret, label + seed).
- static derive_master_secret(pre_master_secret, client_random, server_random, hash_algo='sha256')[source]
Derive the 48-byte master secret (RFC 5246 Section 8.1).
- class TLS13HKDF[source]
Bases:
objectTLS 1.3 HKDF functions (RFC 8446, Section 7).
Implements HKDF-Extract and HKDF-Expand (RFC 5869) plus the TLS 1.3 specific
HKDF-Expand-LabelandDerive-Secrethelpers.- static hkdf_extract(salt, ikm, hash_algo='sha256')[source]
HKDF-Extract: PRK = HMAC(salt, IKM) (RFC 5869 Section 2.2).
- static hkdf_expand(prk, info, length, hash_algo='sha256')[source]
HKDF-Expand: iterative HMAC expansion (RFC 5869 Section 2.3).
Base class and types for KDF (Key Derivation Function) plugins.
KDF plugins are auto-discovered from core/kdf_*.py modules that contain subclasses of BaseKDF. This mirrors the algorithm plugin pattern in algorithms/base.py but lives in core/ because KDF implementations are stdlib-only cryptographic primitives.
- class BaseKDF[source]
Bases:
ABCAbstract base for all KDF plugins.
Subclasses must set name, protocol, and versions as class attributes and implement the four abstract methods.
- abstract expand_traffic_secret(secret, key_lengths=None, hash_algo='sha256')[source]
Expand a traffic/session secret into derived keys and IVs.
- Parameters:
secret (CryptoSecret)
hash_algo (str)
- Return type:
Auto-discovery registry for KDF (Key Derivation Function) plugins.
Mirrors the algorithm plugin pattern in algorithms/registry.py. Discovers
BaseKDF subclasses from all core/kdf_*.py modules via importlib.
- class KDFRegistry[source]
Bases:
objectDiscover and manage KDF plugins from
core/kdf_*.pymodules.