RTE RBC 2oo2 Reference Application 0.1.0 build 0006685
SIL 4 2oo2 Dual-Site Fault-Tolerant ERTMS Radio Block Centre Reference Architecture
Loading...
Searching...
No Matches
ab_gp_takeover_key.c File Reference

See ab_gp_takeover_key.h. More...

#include "ab_gp_takeover_key.h"
#include <stdio.h>
#include <string.h>
#include "safecomm/mac/mac.h"
Include dependency graph for ab_gp_takeover_key.c:

Go to the source code of this file.

Functions

static int hex_nibble (char c)
static bool decode_hex (const char *hex, uint8_t *out, size_t len)
static char * trim_line (char *line)
bool ab_gp_takeover_key_load_file (const char *path)
 Loads the key file (one key, 48 hex characters) into this process's key slot.
bool ab_gp_takeover_key_loaded (void)
bool ab_gp_takeover_verify_mac (void *user, const uint8_t *msg, size_t msg_len, const uint8_t mac[RTE_SITE_ROLE_TOKEN_MAC_LEN])
 rte_site_role verify_mac callback: true only when a key is loaded and the Subset-037 MAC over msg matches.
bool ab_gp_takeover_token_from_payload (const char *payload, uint8_t out[RTE_SITE_ROLE_TOKEN_LEN])
 Decodes a util payload token=<48 hex> into a token.
bool ab_gp_takeover_token_build (uint8_t site_id, uint8_t channel_id, uint32_t challenge, uint32_t seq, uint8_t out[RTE_SITE_ROLE_TOKEN_LEN])
 Builds a token for one channel: the message (version, site id, channel id, challenge, issuer sequence) and its Subset-037 MAC with the loaded key.
bool ab_gp_takeover_token_to_payload (const uint8_t token[RTE_SITE_ROLE_TOKEN_LEN], char *out, size_t out_size)
 Encodes a token as the util payload token=<48 hex> (NUL-terminated).

Variables

static uint8_t s_key [SAFECOMM_MAC_KEY_LEN]
static bool s_key_loaded = false

Detailed Description

See ab_gp_takeover_key.h.

Definition in file ab_gp_takeover_key.c.

Function Documentation

◆ hex_nibble()

int hex_nibble ( char c)
static

Definition at line 15 of file ab_gp_takeover_key.c.

◆ decode_hex()

bool decode_hex ( const char * hex,
uint8_t * out,
size_t len )
static

Definition at line 33 of file ab_gp_takeover_key.c.

◆ trim_line()

char * trim_line ( char * line)
static

Definition at line 52 of file ab_gp_takeover_key.c.

◆ ab_gp_takeover_key_load_file()

bool ab_gp_takeover_key_load_file ( const char * path)

Loads the key file (one key, 48 hex characters) into this process's key slot.

Returns
true on success; false (slot left empty) when the file cannot be read, holds no key, more than one key or a malformed one.

Definition at line 75 of file ab_gp_takeover_key.c.

◆ ab_gp_takeover_key_loaded()

bool ab_gp_takeover_key_loaded ( void )
Returns
true once a key has been loaded.

Definition at line 116 of file ab_gp_takeover_key.c.

◆ ab_gp_takeover_verify_mac()

bool ab_gp_takeover_verify_mac ( void * user,
const uint8_t * msg,
size_t msg_len,
const uint8_t mac[RTE_SITE_ROLE_TOKEN_MAC_LEN] )

rte_site_role verify_mac callback: true only when a key is loaded and the Subset-037 MAC over msg matches.

Definition at line 121 of file ab_gp_takeover_key.c.

◆ ab_gp_takeover_token_from_payload()

bool ab_gp_takeover_token_from_payload ( const char * payload,
uint8_t out[RTE_SITE_ROLE_TOKEN_LEN] )

Decodes a util payload token=<48 hex> into a token.

Returns
true for exactly that form (case-insensitive hex, nothing after it); false otherwise.

Definition at line 139 of file ab_gp_takeover_key.c.

◆ ab_gp_takeover_token_build()

bool ab_gp_takeover_token_build ( uint8_t site_id,
uint8_t channel_id,
uint32_t challenge,
uint32_t seq,
uint8_t out[RTE_SITE_ROLE_TOKEN_LEN] )

Builds a token for one channel: the message (version, site id, channel id, challenge, issuer sequence) and its Subset-037 MAC with the loaded key.

Returns
false when no key is loaded or out is NULL.

Definition at line 151 of file ab_gp_takeover_key.c.

◆ ab_gp_takeover_token_to_payload()

bool ab_gp_takeover_token_to_payload ( const uint8_t token[RTE_SITE_ROLE_TOKEN_LEN],
char * out,
size_t out_size )

Encodes a token as the util payload token=<48 hex> (NUL-terminated).

Returns
false when out_size is too small (needs 6 + 48 + 1 bytes) or an argument is NULL.

Definition at line 181 of file ab_gp_takeover_key.c.

Variable Documentation

◆ s_key

uint8_t s_key[SAFECOMM_MAC_KEY_LEN]
static

Definition at line 12 of file ab_gp_takeover_key.c.

◆ s_key_loaded

bool s_key_loaded = false
static

Definition at line 13 of file ab_gp_takeover_key.c.