Skip to main content

Module agreement

Module agreement 

Source
Expand description

Elliptic-curve key agreement for security suites 1 and 2 (IEC 62056-5-3, 5.3.4 / DLMS Green Book Annex C).

Two parties derive a shared symmetric key from a static/ephemeral EC key pair each. The raw shared secret Z is the x-coordinate of the ECDH point (FE2OS(x)); it is then run through the NIST SP 800-56A single-step (concat) KDF to obtain the DLMS session key:

K = Hash( counter(0x00000001) ‖ Z ‖ AlgorithmID ‖ PartyUInfo ‖ PartyVInfo )

where the hash is SHA-256 for suite 1 and SHA-384 for suite 2, PartyUInfo / PartyVInfo are the two system-titles, and the encryption key is the leftmost 16 (suite 1) or 32 (suite 2) octets of K. Validated against the One-Pass Diffie-Hellman test vector of DLMS Green Book Table C.2.

Enums§

AgreementError
Errors from key agreement.

Functions§

agree_key
Performs the full DLMS key agreement: ECDH followed by the KDF, returning the derived AES encryption key (16 octets for suite 1, 32 for suite 2).
coord_len 🔒
Coordinate length (octets) of the suite’s curve.
ecdh
Computes the raw ECDH shared secret Z = FE2OS(x) between our private_key (raw scalar) and the peer’s public_key (raw x ‖ y or SEC1) on the suite’s curve.
kdf
The NIST SP 800-56A single-step KDF over the suite’s hash, producing output_len octets from the shared secret z and the other-info fields algorithm_id ‖ party_u_info ‖ party_v_info.
originator_agree
The originator side of a One-Pass Diffie-Hellman agreed-key exchange (C(1e, 1s), IEC 62056-5-3 Annex C.2).
public_key
Derives the ephemeral public key (FE2OS(x) ‖ FE2OS(y)) from an ephemeral private key on the suite’s curve, for embedding as key-ciphered-data.
recipient_agree
The recipient side of a One-Pass Diffie-Hellman agreed-key exchange.
to_sec1 🔒
Normalizes a public key to SEC1 uncompressed form (0x04 ‖ x ‖ y).