GCC Code Coverage Report


Directory: ./
File: Svc/Ccsds/Utils/SdlsAuthMask.hpp
Date: 2026-09-23 22:11:34
Exec Total Coverage
Lines: 0 12 0.0%
Functions: 0 2 0.0%
Branches: 0 0 -%

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 ✗ SdlsTcAuthMask(U8 vcId, U16 securityAssociationIndex) {
38 ✗ (void)::memset(this->bytes, 0, SIZE);
39 ✗ this->bytes[VCID_BYTE_INDEX] = static_cast<U8>((vcId << VCID_SHIFT) & VCID_MASK);
40 ✗ this->bytes[TC_PRIMARY_HEADER_SIZE] = static_cast<U8>(securityAssociationIndex >> 8);
41 ✗ this->bytes[TC_PRIMARY_HEADER_SIZE + 1] = static_cast<U8>(securityAssociationIndex & 0xFF);
42 ✗ }
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 ✗ SdlsTmAuthMask(U8 vcId, U16 securityAssociationIndex) {
64 ✗ (void)::memset(this->bytes, 0, SIZE);
65 ✗ this->bytes[VCID_BYTE_INDEX] = static_cast<U8>((vcId << VCID_SHIFT) & VCID_MASK);
66 ✗ this->bytes[TM_PRIMARY_HEADER_SIZE] = static_cast<U8>(securityAssociationIndex >> 8);
67 ✗ this->bytes[TM_PRIMARY_HEADER_SIZE + 1] = static_cast<U8>(securityAssociationIndex & 0xFF);
68 ✗ }
69 };
70
71 } // namespace Utils
72 } // namespace Ccsds
73 } // namespace Svc
74
75 #endif
76