core.kdf
Implement TLS 1.2 and TLS 1.3 key derivation for validation.
Use HMAC and hashlib from the Python standard library.
- class TLS12PRF[source]
Bases:
objectImplement the TLS 1.2 pseudorandom function from RFC 5246.
The default HMAC hash is SHA-256. Callers can supply the hash specified by the cipher suite.
- static p_hash(secret, seed, length, hash_algo='sha256')[source]
Expand the seed with the selected HMAC hash as specified by RFC 5246.
- static prf(secret, label, seed, length, hash_algo='sha256')[source]
Apply P_hash to the label followed by the 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]
Extract a pseudorandom key as specified by RFC 5869 Section 2.2.
An empty salt uses an all-zero string of the hash output length.
- static hkdf_expand(prk, info, length, hash_algo='sha256')[source]
Expand a pseudorandom key as specified by RFC 5869 Section 2.3.
Raise
ValueErrorif the request exceeds 255 hash output blocks.
Define the interface and parameters for key derivation plugins.
- class BaseKDF[source]
Bases:
ABCDefine the operations that a key derivation plugin supports.
Set the plugin name, protocol, and supported versions. Implement derivation, expansion, and pair validation. Override
supported_secret_types()to advertise expansion support.- abstractmethod expand_traffic_secret(secret, key_lengths=None, hash_algo='sha256')[source]
Expand a traffic/session secret into derived keys and IVs.
- abstractmethod validate_pair(candidate_a, candidate_b, dump_data, hash_algo='sha256', hash_candidates=None)[source]
Test whether candidate_a and candidate_b are KDF-related.
hash_candidates is an optional list of byte-strings discovered in the dump that may serve as protocol-specific KDF inputs (e.g. the SSH-2 exchange hash H and session_id). Plugins that do not need such inputs (TLS 1.2 / 1.3) ignore it; SSH-2 requires it to validate honestly.
Returns a confidence score between 0.0 (unrelated) and 1.0 (confirmed relationship).
Discover built-in and installed key derivation plugins.
Installed packages can register subclasses in the
memdiver.kdfs entry-point group.
- KDF_ENTRY_POINT_GROUP = 'memdiver.kdfs'
Entry-point group under which out-of-tree packages advertise KDFs.
- class KDFRegistry[source]
Bases:
objectDiscover and manage KDF plugins from
core/kdf_*.pymodules.- discover()[source]
Walk
core/kdf_*.pymodules and register BaseKDF subclasses.Per-plugin instantiation failures are isolated (a broken KDF no longer aborts discovery of the rest). Also loads any KDFs advertised by installed packages under the
memdiver.kdfsentry-point group.- Return type:
None
- get(name)[source]
Return KDF plugin by name, or None.
- Parameters:
name (str)
- Return type:
BaseKDF | None