|
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
|
Subset-037 §7.3 3DES CBC-MAC + KSMAC derivation. More...
Go to the source code of this file.
Data Structures | |
| struct | des_key_schedule_t |
Functions | |
| static uint64_t | des_permute (uint64_t in, const uint8_t *table, uint8_t n, uint8_t in_bits) |
| static void | des_schedule (const uint8_t key[8], des_key_schedule_t *ks) |
| static uint64_t | des_cipher_core (uint64_t in_block, const des_key_schedule_t *ks, int decrypt) |
| static uint64_t | des_bytes_to_u64 (const uint8_t b[8]) |
| static void | des_u64_to_bytes (uint64_t v, uint8_t b[8]) |
| static void | des_ecb (const uint8_t key[8], const uint8_t in[8], int decrypt, uint8_t out[8]) |
| Single DES encrypt/decrypt of one 8-byte block under one 8-byte key. | |
| static void | des3_algo3 (const uint8_t key24[24], const uint8_t in[8], uint8_t out[8]) |
| Subset-037-2 §6.2.2.1 "single DES with modified MAC algorithm 3": E(K3, D(K2, E(K1, block))). Used for the last block of a CBC-MAC and for KS1/KS2 of the KSMAC derivation (§6.2.3.2.3.15). | |
| static void | des3_algo3_reversed (const uint8_t key24[24], const uint8_t in[8], uint8_t out[8]) |
| The same construction with K1 and K3 swapped: E(K1, D(K2, E(K3, block))). Used only for KS3 of the KSMAC derivation (§6.2.3.2.3.15, "K'AB"). | |
| 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. | |
Variables | |
| static const uint8_t | IP_TABLE [64] |
| static const uint8_t | FP_TABLE [64] |
| static const uint8_t | E_TABLE [48] |
| static const uint8_t | P_TABLE [32] |
| static const uint8_t | SBOX [8][4][16] |
| static const uint8_t | PC1_TABLE [56] |
| static const uint8_t | PC2_TABLE [48] |
| static const uint8_t | ROTATE_TABLE [16] |
Subset-037 §7.3 3DES CBC-MAC + KSMAC derivation.
Compliant with CENELEC EN 50128 SIL 4 and MISRA C:2012. Pure C99, fixed static buffers, constant-time verification.
Definition in file mac.c.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| 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. |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |