NEW UNIT (TLS 1.3).
This unit implements the TLS 1.3 key schedule of RFC 8446 section 7
(Key Schedule) and section 7.3 (Traffic Key Calculation).
It REUSES the existing HKDF primitives already present in stKDF.pas:
tHKDFExtract -> HKDF-Extract (RFC 5869)
tHKDFExpand -> HKDF-Expand (RFC 5869)
and the hash primitives in stSecUtils (MustFindHashClass / THash). No new
cryptography is implemented here - only the TLS-1.3-specific label framing
(HKDF-Expand-Label / Derive-Secret) and the Extract/Expand chaining that
produces the early, handshake and application traffic secrets.
The unit is deliberately independent of the StreamSec.Mobile.* handshake
units (it speaks only tBytes / THashClass), so it can be consumed by the
record layer (StreamSec.Mobile.TlsLayer) without introducing a circular
dependency.Feature notes: TLS implementation notes (RFC map)
TTls13KeySchedule walks the RFC 8446 sec.7.1 secret ladder:
0
| PSK ->HKDF-Extract = Early Secret
| +--> Derive-Secret(.,"c e traffic", CH) (0-RTT)
| Derive-Secret(.,"derived","")
| (EC)DHE->HKDF-Extract = Handshake Secret
| +--> Derive-Secret(.,"c hs traffic", CH..SH)
| +--> Derive-Secret(.,"s hs traffic", CH..SH)
| Derive-Secret(.,"derived","")
| 0 ->HKDF-Extract = Master Secret
+--> Derive-Secret(.,"c ap traffic", CH..SF)
+--> Derive-Secret(.,"s ap traffic", CH..SF)
+--> Derive-Secret(.,"res master", CH..CF)
The caller supplies the running Transcript-Hash at each stage; the schedule never stores handshake messages itself.
constructor Create(aHashClass: THashClass);
destructor Destroy; override;
procedure InitEarlySecret(const aPSK: tBytes);
procedure DeriveHandshakeSecret(const aSharedSecret: tBytes);
procedure DeriveMasterSecret;
function ClientEarlyTrafficSecret(const aTHash_CH: tBytes): tBytes;
function ClientHandshakeTrafficSecret(const aTHash_SH: tBytes): tBytes;
function ServerHandshakeTrafficSecret(const aTHash_SH: tBytes): tBytes;
function ClientApplicationTrafficSecret(const aTHash_SF: tBytes): tBytes;
function ServerApplicationTrafficSecret(const aTHash_SF: tBytes): tBytes;
function ResumptionMasterSecret(const aTHash_CF: tBytes): tBytes;
function ExporterMasterSecret(const aTHash_SF: tBytes): tBytes;
function ResumptionBinderKey: tBytes;
class function ResumptionPSK(aHashClass: THashClass; const aResMaster, aNonce: tBytes): tBytes;
property HashClass: THashClass read fHashClass;
class function HkdfExpandLabel(aHashClass: THashClass; const aSecret: tBytes; const aLabel: AnsiString; const aContext: tBytes; aLen: Integer): tBytes;
class function DeriveSecret(aHashClass: THashClass; const aSecret: tBytes; const aLabel: AnsiString; const aTranscriptHash: tBytes): tBytes;
class function Extract(aHashClass: THashClass; const aSalt, aIKM: tBytes): tBytes;
class function TranscriptHash(aHashClass: THashClass; const aMessages: tBytes): tBytes;
class procedure TrafficKeyIV(aHashClass: THashClass; const aTrafficSecret: tBytes; aKeyLen, aIVLen: Integer; out aKey, aIV: tBytes);
class procedure QUICInitialSecrets(aVersion: Cardinal; const aDCID: TBytes; out aClientSecret, aServerSecret: TBytes);
class procedure QUICPacketKeys(aHash: THashClass; const aTrafficSecret: TBytes; aKeyLen: Integer; aVersion: Cardinal; out aKey, aIV, aHeaderKey: TBytes);
class function FinishedKey(aHashClass: THashClass; const aBaseKey: tBytes): tBytes;
class function UpdateTrafficSecret(aHashClass: THashClass; const aSecret: tBytes): tBytes;