|
RBC_Test_Sim_Core 0.1.0 build 51fd23e
Shared transport-layer plumbing for the ADR-029 Train/IL/CTC RBC simulators
|
Classes | |
| class | SafError |
| class | SafSession |
Functions | |
| _permute (value, table, width) | |
| _des_subkeys (key8) | |
| _feistel (r, subkey) | |
| _des_block (block8, subkeys) | |
| des_encrypt_block (key8, block8) | |
| des_decrypt_block (key8, block8) | |
| _algo3 (key24, block8) | |
| _algo3_reversed (key24, block8) | |
| derive_ksmac (kmac, ra, rb) | |
| compute_mac (ksmac, msg) | |
| _equal_ct (a, b) | |
| mac_over_da_body (ksmac, da_id, body) | |
| _pack_id24 (id_) | |
| _unpack_id24 (buf) | |
| _pack_header (ety, mti, df) | |
| _header_mti (header_byte) | |
| _header_df (header_byte) | |
| _monotonic_ms () | |
Variables | |
| tuple | _IP |
| tuple | _FP |
| tuple | _E |
| tuple | _P |
| tuple | _PC1 |
| tuple | _PC2 |
| tuple | _SHIFTS = (1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1) |
| tuple | _SBOX |
| int | MAC_LEN = 8 |
| int | RAND_LEN = 8 |
| int | KEY_LEN = 24 |
| MTI_AU1 | |
| MTI_AU2 | |
| MTI_AU3 | |
| MTI_DT | |
| MTI_DI | |
| MTI_AR | |
| int | SEQ_WINDOW = 8 |
| int | MAX_PDU = 1024 |
SaF - Python mirror of the safe-communication Safety Functional layer.
Byte-identical to ``Platform_Protocol_SafeComm`` (``src/mac/mac.c``, ``src/saf/saf.c``), the same way
``simcore.rbc_wire`` mirrors the C wire codec. The construction follows Subset-037-2 v4.0.0
("EuroRadio FIS - Safety Layer") directly:
* DES, pure Python so a sim needs no crypto package.
* CBC-MAC (Subset-037-2 SS6.2.2, "single DES with modified MAC algorithm 3"): every block but the last is
single-DES under K1; the last block alone gets E(K3, D(K2, E(K1, .))). ISO/IEC 9797-1 Padding Method 1
(zero bits, no extra block when the message is already a multiple of 64 bits). Verified against the
official worked example in Subset-037-2 Annex B.
* KSMAC derivation (SS6.2.3.2.3.13-16): RA and RB are each split into 32-bit left/right halves; KS1/KS2 use
the normal key order over the left/right halves, KS3 reuses the left half with the key order reversed.
* Frames AU1 (13) / AU2 (21) / AU3 (9) / AR (9) / DT (1+n+8) / DI (3, unauthenticated) per Subset-037-2
SS6.2.5's tables: a packed ETY|MTI|DF header octet and 24-bit ETCS IDs. The MAC input for AU2/AU3/DT/AR
follows SS6.2.3.2.1 (message origin authentication: length|DA|body) and SS6.2.3.2.2/Figure 6 (peer entity
authentication) - DA is always the *receiver's own* identity.
* Sa-DISCONNECT carries no MAC or identity field at all (Table 6/13): SS6.2.3.3.3.2 says release-phase
authentication is not required, since a forged one can only end the connection early, never inject or
alter safety data. Any well-formed DI is honoured.
One deliberate, non-conformant addition: the official DT SaPDU carries no sequence number (Table 12) - that
defence is the Subset-098 SAI sub-layer's job (sequence numbering / Triple Time Stamping / EC counter,
SS5.4), which this module does not implement. In its place a 4-byte sequence number is carried inside the
MAC-covered user-data area, matching what ``saf.c`` does. This is a project extension, not itself
conformant to any subset - see ``docs/safety/SUBSET_MAPPING.md`` in the SafeComm library.
The session is transport-agnostic: the caller supplies ``send(bytes)`` and ``recv() -> bytes`` (one
frame per call). ``recv`` raises ``TimeoutError`` when nothing arrived in time.
This is a test tool. The MAC is cryptographically dated (see the C library's SUBSET_MAPPING.md).
|
protected |
|
protected |
|
protected |
| compute_mac | ( | ksmac, | |
| msg ) |
| derive_ksmac | ( | kmac, | |
| ra, | |||
| rb ) |
| des_decrypt_block | ( | key8, | |
| block8 ) |
| des_encrypt_block | ( | key8, | |
| block8 ) |
| mac_over_da_body | ( | ksmac, | |
| da_id, | |||
| body ) |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |