TLV codec for CASE Sigma protocol messages.
Each message type has an encode and decode function. Encoding produces a TLV binary; decoding returns a plain map.
Summary
Functions
Build TBS (to-be-signed) data as a TLV structure.
Compute CASE destination identifier.
Decode a NOC. Accepts both X.509 DER certificates (as sent by chip-tool) and the simplified TLV format used in internal tests.
Decrypt TBE data with AES-128-CCM.
Default secure-channel session parameters.
Derive S2K key for Sigma2 TBE encryption.
Derive S3K key for Sigma3 TBE encryption.
Encode a simplified NOC containing node_id, fabric_id, and public_key.
Encrypt TBE data with AES-128-CCM. Returns ciphertext <> tag.
Extract the public key from an X.509 DER certificate.
Functions
Build TBS (to-be-signed) data as a TLV structure.
Matter CASE TBS contains:
- Tag 1: Sender NOC certificate
- Tag 2: Sender ICAC certificate (optional)
- Tag 3: Sender ephemeral public key (65 bytes)
- Tag 4: Receiver ephemeral public key (65 bytes)
@spec compute_destination_id( binary(), binary(), binary(), non_neg_integer(), non_neg_integer() ) :: binary()
Compute CASE destination identifier.
dest_id = HMAC-SHA256(IPK, initiator_random || root_public_key || fabric_id_le64 || node_id_le64)
The root_public_key is the full 65-byte uncompressed EC point (including 0x04 prefix).
Decode a NOC. Accepts both X.509 DER certificates (as sent by chip-tool) and the simplified TLV format used in internal tests.
Decrypt TBE data with AES-128-CCM.
@spec default_session_parameters() :: map()
Default secure-channel session parameters.
These mirror the fields emitted by connectedhomeip's PairingSession
EncodeSessionParameters: MRP timings plus protocol revision hints.
Derive S2K key for Sigma2 TBE encryption.
Salt = IPK(16) || responder_random(32) || responder_eph_pub(65) || transcript_hash(32) = 145 bytes. The transcript_hash is SHA256 of sigma1 payload only.
Derive S3K key for Sigma3 TBE encryption.
Salt = IPK(16) || transcript_hash(32) = 48 bytes. The transcript_hash is SHA256 of sigma1 || sigma2 payloads.
@spec encode_noc(non_neg_integer(), non_neg_integer(), binary()) :: binary()
Encode a simplified NOC containing node_id, fabric_id, and public_key.
@spec encode_sigma1(binary(), non_neg_integer(), binary(), binary()) :: binary()
@spec encode_sigma2(binary(), non_neg_integer(), binary(), binary()) :: binary()
Encrypt TBE data with AES-128-CCM. Returns ciphertext <> tag.
Extract the public key from an X.509 DER certificate.
Returns the raw EC point (65 bytes for P-256 uncompressed) or nil. Works with any X.509 cert (root CA, ICAC, or NOC).