|
Safe Communication Framework 0.1.0 build feea4f9
ERTMS/ETCS safe communication (Subset-037 EuroRadio, Subset-098 RBC/RBC), CENELEC EN 50128 SIL 4 oriented
|
Message Authentication Code and session-key derivation (ERTMS/ETCS Subset-037-2 §6.2.2 / §6.2.3.2.3). More...
Go to the source code of this file.
Data Structures | |
| struct | safecomm_mac_ctx_t |
| Immutable session-key material for one SaF connection. More... | |
Macros | |
| #define | SAFECOMM_MAC_KEY_LEN 24U |
| #define | SAFECOMM_MAC_LEN 8U |
| #define | SAFECOMM_MAC_RAND_LEN 8U |
Enumerations | |
| enum | safecomm_mac_alg_t { SAFECOMM_MAC_ALG_3DES_SS037 = 0 } |
| MAC algorithm selector (only 3DES today; reserved for growth). More... | |
Functions | |
| safecomm_status_t | safecomm_mac_derive_ksmac (const uint8_t kmac[SAFECOMM_MAC_KEY_LEN], const uint8_t ra[SAFECOMM_MAC_RAND_LEN], const uint8_t rb[SAFECOMM_MAC_RAND_LEN], safecomm_mac_ctx_t *out_ctx) |
| Derive the session key KSMAC from KMAC and the AU random values. | |
| safecomm_status_t | safecomm_mac_compute (const safecomm_mac_ctx_t *ctx, const uint8_t *msg, size_t msg_len, uint8_t out_mac[SAFECOMM_MAC_LEN]) |
Compute the 8-byte EuroRadio MAC over msg. | |
| safecomm_status_t | safecomm_mac_verify (const safecomm_mac_ctx_t *ctx, const uint8_t *msg, size_t msg_len, const uint8_t rx_mac[SAFECOMM_MAC_LEN]) |
| Constant-time verify of a received MAC against a freshly computed one. | |
Message Authentication Code and session-key derivation (ERTMS/ETCS Subset-037-2 §6.2.2 / §6.2.3.2.3).
The EuroRadio MAC is a CBC-MAC ("single DES with modified MAC algorithm 3": every block but the last is single-DES under K1, the last is E(K3,D(K2,E(K1,.)))) computed with the session key KSMAC, which is itself derived during the AU1/AU2/AU3 handshake from the pre-shared KMAC and the two exchanged random values (RA split left/right, RB split left/right; the third block reverses the key order). Verified against the official worked example in Subset-037-2 Annex B; see tests/test_mac_kat.c.
SAFETY / SECURITY NOTE: DES/3DES are cryptographically dated. This module implements the algorithm the currently deployed trackside requires; a future AES-based EuroRadio MAC (Subset-037-3) would be an additional safecomm_mac_alg_t, not a replacement. See docs/safety/SUBSET_MAPPING.md.
REQ-SC-MAC-001..010 — see docs/requirements/SRS.md.
Definition in file mac.h.
| #define SAFECOMM_MAC_KEY_LEN 24U |
| #define SAFECOMM_MAC_LEN 8U |
| #define SAFECOMM_MAC_RAND_LEN 8U |
| enum safecomm_mac_alg_t |
| safecomm_status_t safecomm_mac_derive_ksmac | ( | const uint8_t | kmac[SAFECOMM_MAC_KEY_LEN], |
| const uint8_t | ra[SAFECOMM_MAC_RAND_LEN], | ||
| const uint8_t | rb[SAFECOMM_MAC_RAND_LEN], | ||
| safecomm_mac_ctx_t * | out_ctx ) |
Derive the session key KSMAC from KMAC and the AU random values.
Implements the Subset-037 §7.3 key-derivation: the two 64-bit random numbers exchanged in AU1 (RA, sent by the caller / initiator) and AU2 (RB, sent by the responder) are combined with KMAC to produce KSMAC.
| kmac | pre-shared 24-byte KMAC for this peer pair. Non-NULL. |
| ra | 8-byte random value from AU1. Non-NULL. |
| rb | 8-byte random value from AU2. Non-NULL. |
| out_ctx | receives the derived session context. Non-NULL. |
| safecomm_status_t safecomm_mac_compute | ( | const safecomm_mac_ctx_t * | ctx, |
| const uint8_t * | msg, | ||
| size_t | msg_len, | ||
| uint8_t | out_mac[SAFECOMM_MAC_LEN] ) |
Compute the 8-byte EuroRadio MAC over msg.
| ctx | session context from safecomm_mac_derive_ksmac(). Non-NULL. |
| msg | the safe PDU bytes the MAC covers. Non-NULL if msg_len > 0. |
| msg_len | number of bytes in msg. |
| out_mac | receives the 8-byte MAC. Non-NULL. |
| safecomm_status_t safecomm_mac_verify | ( | const safecomm_mac_ctx_t * | ctx, |
| const uint8_t * | msg, | ||
| size_t | msg_len, | ||
| const uint8_t | rx_mac[SAFECOMM_MAC_LEN] ) |
Constant-time verify of a received MAC against a freshly computed one.
| ctx | session context. Non-NULL. |
| msg | PDU bytes the MAC covers. Non-NULL if msg_len > 0. |
| msg_len | number of bytes in msg. |
| rx_mac | the 8-byte MAC received on the wire. Non-NULL. |