| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title SdlsAuthMask.hpp | ||
| 3 | // \brief SDLS additional authenticated data (AAD) construction | ||
| 4 | // ====================================================================== | ||
| 5 | |||
| 6 | #ifndef Svc_Ccsds_Utils_SdlsAuthMask_HPP | ||
| 7 | #define Svc_Ccsds_Utils_SdlsAuthMask_HPP | ||
| 8 | |||
| 9 | #include <cstring> | ||
| 10 | #include "Fw/FPrimeBasicTypes.hpp" | ||
| 11 | |||
| 12 | namespace Svc { | ||
| 13 | namespace Ccsds { | ||
| 14 | namespace Utils { | ||
| 15 | |||
| 16 | // AES-GCM authenticates, but does not encrypt, a block of frame fields supplied as AAD. SDLS | ||
| 17 | // uses this to bind a frame to its virtual channel and security association. The block is a | ||
| 18 | // masked copy of the frame header: fields that differ between the two ends are zeroed. | ||
| 19 | |||
| 20 | //! AAD for an SDLS-protected TC (uplink) transfer frame: 19 bytes, laid out as the masked | ||
| 21 | //! 5-byte primary header, the SPI verbatim, then a zeroed 12-byte IV field. | ||
| 22 | //! | ||
| 23 | //! Assumes no TC segment header; a link using one inserts an extra 0xFF mask byte. | ||
| 24 | struct SdlsTcAuthMask final { | ||
| 25 | static constexpr FwSizeType TC_PRIMARY_HEADER_SIZE = 5; | ||
| 26 | static constexpr FwSizeType SPI_SIZE = 2; | ||
| 27 | static constexpr FwSizeType IV_SIZE = 12; | ||
| 28 | static constexpr FwSizeType SIZE = TC_PRIMARY_HEADER_SIZE + SPI_SIZE + IV_SIZE; | ||
| 29 | |||
| 30 | //! Byte 2 holds the 6-bit VCID in bits 7..2, with the top of the frame length below it | ||
| 31 | static constexpr U8 VCID_MASK = 0xFC; | ||
| 32 | static constexpr FwSizeType VCID_BYTE_INDEX = 2; | ||
| 33 | static constexpr U8 VCID_SHIFT = 2; | ||
| 34 | |||
| 35 | U8 bytes[SIZE]; | ||
| 36 | |||
| 37 | 32 | SdlsTcAuthMask(U8 vcId, U16 securityAssociationIndex) { | |
| 38 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
|
32 | (void)::memset(this->bytes, 0, SIZE); |
| 39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | this->bytes[VCID_BYTE_INDEX] = static_cast<U8>((vcId << VCID_SHIFT) & VCID_MASK); |
| 40 | 32 | this->bytes[TC_PRIMARY_HEADER_SIZE] = static_cast<U8>(securityAssociationIndex >> 8); | |
| 41 | 32 | this->bytes[TC_PRIMARY_HEADER_SIZE + 1] = static_cast<U8>(securityAssociationIndex & 0xFF); | |
| 42 | 32 | } | |
| 43 | }; | ||
| 44 | |||
| 45 | //! AAD for an SDLS-protected TM (downlink) transfer frame: 20 bytes, laid out as the masked | ||
| 46 | //! 6-byte primary header, the SPI verbatim, then a zeroed 12-byte IV field. | ||
| 47 | //! | ||
| 48 | //! Assumes no transfer frame secondary header; a link using one inserts that many additional | ||
| 49 | //! zero bytes before the SPI. | ||
| 50 | struct SdlsTmAuthMask final { | ||
| 51 | static constexpr FwSizeType TM_PRIMARY_HEADER_SIZE = 6; | ||
| 52 | static constexpr FwSizeType SPI_SIZE = 2; | ||
| 53 | static constexpr FwSizeType IV_SIZE = 12; | ||
| 54 | static constexpr FwSizeType SIZE = TM_PRIMARY_HEADER_SIZE + SPI_SIZE + IV_SIZE; | ||
| 55 | |||
| 56 | //! Byte 1 holds the 3-bit VCID in bits 3..1, between the low spacecraft ID bits and the OCF flag | ||
| 57 | static constexpr U8 VCID_MASK = 0x0E; | ||
| 58 | static constexpr FwSizeType VCID_BYTE_INDEX = 1; | ||
| 59 | static constexpr U8 VCID_SHIFT = 1; | ||
| 60 | |||
| 61 | U8 bytes[SIZE]; | ||
| 62 | |||
| 63 | 27 | SdlsTmAuthMask(U8 vcId, U16 securityAssociationIndex) { | |
| 64 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
|
27 | (void)::memset(this->bytes, 0, SIZE); |
| 65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | this->bytes[VCID_BYTE_INDEX] = static_cast<U8>((vcId << VCID_SHIFT) & VCID_MASK); |
| 66 | 27 | this->bytes[TM_PRIMARY_HEADER_SIZE] = static_cast<U8>(securityAssociationIndex >> 8); | |
| 67 | 27 | this->bytes[TM_PRIMARY_HEADER_SIZE + 1] = static_cast<U8>(securityAssociationIndex & 0xFF); | |
| 68 | 27 | } | |
| 69 | }; | ||
| 70 | |||
| 71 | } // namespace Utils | ||
| 72 | } // namespace Ccsds | ||
| 73 | } // namespace Svc | ||
| 74 | |||
| 75 | #endif | ||
| 76 |