Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

169 aos support #207

Merged
merged 33 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1ae1b57
Initial AOS commit - copied TM structure
dccutrig Sep 18, 2023
c2b8ba8
Replace TM refs with AOS
dccutrig Sep 18, 2023
271d204
Update enums for AOS
dccutrig Sep 18, 2023
cb18ae6
Modify functions and structs for AOS
dccutrig Sep 18, 2023
b83e5a7
Add AOS Frame Security Report Struct
dccutrig Sep 20, 2023
3a8fe1d
Telemetry status word re-organization and cleanup
dccutrig Sep 20, 2023
c7c9aa8
Adjust AOD ApplySec print statements
dccutrig Sep 20, 2023
a1c5c12
Bit math update and cleanup
dccutrig Sep 20, 2023
49da99a
Remove secondary header artifacts from TM
dccutrig Sep 20, 2023
01314ee
Initial AOS Apply UTs
dccutrig Sep 20, 2023
65485ee
Add AOS Happy Path UT, and AOS Clear Mode SA (#14)
dccutrig Oct 1, 2023
c1c7919
Fix TM UT - not enforcing blank FECF
dccutrig Oct 1, 2023
e8e7cca
Add AOS UT with Clear FECF, update other AOS UT to ensure byte-by-byt…
dccutrig Oct 1, 2023
94dd85e
UPDATE API for aos fhec field, update all references to add_gvcid_man…
dccutrig Oct 1, 2023
9ab9f30
API MOD: Add AOS Insert Zone Managed Param Configs in gvcid_add_manag…
dccutrig Oct 1, 2023
5282415
Add Insert Zone UT
dccutrig Oct 1, 2023
06f04cb
Add AOS Authenticated UTs w/ varying bitmasks
dccutrig Oct 1, 2023
a0d4082
WIP on AOS Encryption UTs
dccutrig Oct 2, 2023
6f57a56
Add AOS ApplySec UT Encryption Only, no MAC
dccutrig Oct 2, 2023
07b744e
Add AOS AEAD Apply UT & SA 17
dccutrig Oct 22, 2023
0bd223c
First pass, AOS specific headers
dccutrig Oct 23, 2023
c07bd59
Normalize headers / file names
dccutrig Oct 23, 2023
3ccbacb
Update CMake for AOS_Process, find/replace for aos_process
dccutrig Oct 23, 2023
5191b09
Add AOS Process Insert Zone logic and UT
dccutrig Nov 5, 2023
f334fc8
Fix typos, add UT AOS Process AES bitmask of zeros
dccutrig Nov 5, 2023
41e440e
AOS ProcessSec UT CMAC Bitmask 1s
dccutrig Nov 5, 2023
c9d36e0
Add AOS Process UT HMAC 256 Bitmask 1s
dccutrig Nov 5, 2023
7665bab
Add AOS Process UT SHA256 Bitmask 0s
dccutrig Nov 5, 2023
101fe2b
UTs AOS Process HMAC 512, Bitmasks of 0s and 1s
dccutrig Nov 5, 2023
d2b4827
Add AOS Process AES-GCM Decryption ONLY UT
dccutrig Nov 5, 2023
0d7bb94
Update UTs to correct AOS TFVN - 01b, which is not to standard
dccutrig Nov 5, 2023
f71c845
Working AOS Apply/Process UTs for base functionality!
dccutrig Dec 11, 2023
4ab40cd
Merge branch 'dev' into 169-aos-support
dccutrig Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if(CODECOV)
endif()

if(DEBUG)
add_definitions(-DDEBUG -DOCF_DEBUG -DFECF_DEBUG -DSA_DEBUG -DPDU_DEBUG -DCCSDS_DEBUG -DTC_DEBUG -DMAC_DEBUG -DTM_DEBUG)
add_definitions(-DDEBUG -DOCF_DEBUG -DFECF_DEBUG -DSA_DEBUG -DPDU_DEBUG -DCCSDS_DEBUG -DTC_DEBUG -DMAC_DEBUG -DTM_DEBUG -DAOS_DEBUG)
add_compile_options(-ggdb)
endif()

Expand Down
19 changes: 13 additions & 6 deletions include/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ extern int32_t Crypto_Config_Kmc_Crypto_Service(char* protocol, char* kmc_crypto
char* mtls_client_key_pass, char* mtls_issuer_cert);
extern int32_t Crypto_Config_Cam(uint8_t cam_enabled, char* cookie_file_path, char* keytab_file_path, uint8_t login_method, char* access_manager_uri, char* username, char* cam_home);
extern int32_t Crypto_Config_Add_Gvcid_Managed_Parameter(uint8_t tfvn, uint16_t scid, uint8_t vcid, uint8_t has_fecf,
uint8_t has_segmentation_hdr, uint16_t max_frame_size);
uint8_t has_segmentation_hdr, uint16_t max_frame_size, uint8_t aos_has_fhec,
uint8_t aos_has_iz, uint16_t aos_iz_len);

// Initialization
extern int32_t Crypto_Init(void); // Initialize CryptoLib After Configuration Calls
Expand All @@ -89,6 +90,7 @@ extern int32_t Crypto_Init_With_Configs(
extern int32_t Crypto_TC_Init(void);
extern int32_t Crypto_Init_TC_Unit_Test(void); // Initialize CryptoLib with unit test default Configurations
extern int32_t Crypto_Init_TM_Unit_Test(void); // Initialize CryptoLib with unit test default Configurations
extern int32_t Crypto_Init_AOS_Unit_Test(void); // Initialize CryptoLib with unit test default Configurations

// Cleanup
extern int32_t Crypto_Shutdown(void); // Free all allocated memory
Expand All @@ -104,8 +106,8 @@ extern int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int *len_ingest, T
extern int32_t Crypto_TM_ApplySecurity(uint8_t* pTfBuffer);
extern int32_t Crypto_TM_ProcessSecurity(uint8_t* p_ingest, uint16_t len_ingest, uint8_t** pp_processed_frame, uint16_t *p_decrypted_length);
// Advanced Orbiting Systems (AOS)
extern int32_t Crypto_AOS_ApplySecurity(uint8_t* ingest, int *len_ingest);
extern int32_t Crypto_AOS_ProcessSecurity(uint8_t* ingest, int *len_ingest);
extern int32_t Crypto_AOS_ApplySecurity(uint8_t* pTfBuffer);
extern int32_t Crypto_AOS_ProcessSecurity(uint8_t* p_ingest, uint16_t len_ingest, uint8_t** pp_processed_frame, uint16_t* p_decrypted_length);

// Crypo Error Support Functions
extern char* Crypto_Get_Error_Code_Enum_String(int32_t crypto_error_code);
Expand All @@ -118,10 +120,11 @@ extern int32_t Crypto_increment(uint8_t* num, int length);
// int32_t Crypto_Get_tcPayloadLength(TC_t* tc_frame, SecurityAssociation_t* sa_ptr);
int32_t Crypto_Get_tmLength(int len);
uint8_t Crypto_Is_AEAD_Algorithm(uint32_t cipher_suite_id);
uint8_t* Crypto_Prepare_TC_AAD(uint8_t* buffer, uint16_t len_aad, uint8_t* abm_buffer);
void Crypto_TM_updatePDU(uint8_t* ingest, int len_ingest);
void Crypto_TM_updateOCF(void);
uint8_t* Crypto_Prepare_TC_AAD(uint8_t* buffer, uint16_t len_aad, uint8_t* abm_buffer);
uint32_t Crypto_Prepare_TM_AAD(const uint8_t* buffer, uint16_t len_aad, const uint8_t* abm_buffer, uint8_t* aad);
uint32_t Crypto_Prepare_AOS_AAD(const uint8_t* buffer, uint16_t len_aad, const uint8_t* abm_buffer, uint8_t* aad);
void Crypto_Local_Config(void);
void Crypto_Local_Init(void);
// int32_t Crypto_gcm_err(int gcm_err);
Expand Down Expand Up @@ -174,7 +177,8 @@ int32_t Crypto_Get_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uin
GvcidManagedParameters_t** managed_parameters_out);
int32_t crypto_config_add_gvcid_managed_parameter_recursion(uint8_t tfvn, uint16_t scid, uint8_t vcid,
uint8_t has_fecf, uint8_t has_segmentation_hdr,
uint16_t max_frame_size,
uint16_t max_frame_size, uint8_t aos_has_fhec,
uint8_t aos_has_iz, uint16_t aos_iz_len,
GvcidManagedParameters_t* managed_parameter);
void Crypto_Free_Managed_Parameters(GvcidManagedParameters_t* managed_parameters);

Expand All @@ -190,6 +194,9 @@ extern CCSDS_t sdls_frame;
extern uint8_t tm_frame[1786];
extern TM_FramePrimaryHeader_t tm_frame_pri_hdr;
extern TM_FrameSecurityHeader_t tm_frame_sec_hdr; // Used to reduce bit math duplication
// exterm AOS_t aos_frame
extern AOS_FramePrimaryHeader_t aos_frame_pri_hdr;
extern AOS_FrameSecurityHeader_t aos_frame_sec_hdr; // Used to reduce bit math duplication

// Global configuration structs
extern CryptoConfig_t crypto_config;
Expand All @@ -211,7 +218,7 @@ extern GvcidManagedParameters_t* current_managed_parameters;
// OCF
extern uint8_t ocf;
extern SDLS_FSR_t report;
extern TM_FrameCLCW_t clcw;
extern Telemetry_Frame_Clcw_t clcw;
// Flags
extern SDLS_MC_LOG_RPLY_t log_summary;
extern SDLS_MC_DUMP_BLK_RPLY_t mc_log;
Expand Down
6 changes: 5 additions & 1 deletion include/crypto_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
#define OCF_SIZE 4
#define MAC_SIZE 16 /* bytes */
#define FECF_SIZE 2
#define SEGMENT_HDR_SIZE 1
#define TC_SEGMENT_HDR_SIZE 1
#define ECS_SIZE 4 /* bytes */
#define ABM_SIZE 1786 /* bytes */
#define ARSN_SIZE 20 /* total messages */
Expand Down Expand Up @@ -179,6 +179,10 @@
#define TM_FILL_SIZE 1145 /* bytes */
#define TM_PAD_SIZE 2 /* bytes */

// AOS Defines
#define AOS_FRAME_DATA_SIZE 1786 /* bytes */
#define AOS_FILL_SIZE 1145 /* bytes */

// TC Behavior Defines
#define TC_SDLS_EP_VCID \
4 // VCID which has SDLS PDUs (JPL uses VCIDs to determine TC type, there is no space packet layer with APIDs). Set
Expand Down
58 changes: 43 additions & 15 deletions include/crypto_config_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ typedef enum
CRYPTOGRAPHY_TYPE_KMCCRYPTO,
CRYPTOGRAPHY_TYPE_WOLFSSL
} CryptographyType;
// gvcid managed parameter enums
/***************************************
** GVCID Managed Parameter enums
****************************************/
typedef enum
{
IV_INTERNAL,
Expand All @@ -70,28 +72,57 @@ typedef enum
TC_NO_FECF,
TC_HAS_FECF,
TM_NO_FECF,
TM_HAS_FECF
TM_HAS_FECF,
AOS_NO_FECF,
AOS_HAS_FECF
} FecfPresent;
typedef enum
{
CRYPTO_TC_CREATE_FECF_FALSE,
CRYPTO_TC_CREATE_FECF_TRUE,
CRYPTO_TM_CREATE_FECF_FALSE,
CRYPTO_TM_CREATE_FECF_TRUE
CRYPTO_TM_CREATE_FECF_TRUE,
CRYPTO_AOS_CREATE_FECF_FALSE,
CRYPTO_AOS_CREATE_FECF_TRUE
} CreateFecfBool;
typedef enum
{
AOS_FHEC_NA,
AOS_NO_FHEC,
AOS_HAS_FHEC
} AosFhecPresent;
typedef enum
{
AOS_IZ_NA,
AOS_NO_IZ,
AOS_HAS_IZ
} AosInsertZonePresent;
typedef enum
{
TC_CHECK_FECF_FALSE,
TC_CHECK_FECF_TRUE,
TM_CHECK_FECF_FALSE,
TM_CHECK_FECF_TRUE
TM_CHECK_FECF_TRUE,
AOS_CHECK_FECF_FALSE,
AOS_CHECK_FECF_TRUE
} CheckFecfBool;
// TC specific enums
typedef enum
{
AOS_NO_OCF,
AOS_HAS_OCF,
TC_OCF_NA,
TM_NO_OCF,
TM_HAS_OCF
} OcfPresent;
/***************************************
** TC specific enums
****************************************/
typedef enum
{
TC_NO_SEGMENT_HDRS,
TC_HAS_SEGMENT_HDRS,
TM_SEGMENT_HDRS_NA
TM_SEGMENT_HDRS_NA, // Invalid for TM
AOS_SEGMENT_HDRS_NA // Invalid for AOS
} TcSegmentHdrsPresent;
typedef enum
{
Expand Down Expand Up @@ -123,15 +154,9 @@ typedef enum
SA_INCREMENT_NONTRANSMITTED_IV_FALSE,
SA_INCREMENT_NONTRANSMITTED_IV_TRUE
} SaIncrementNonTransmittedIvPortion;
// TM specific enums
typedef enum
{
AOS_NO_OCF,
AOS_HAS_OCF,
TC_OCF_NA,
TM_NO_OCF,
TM_HAS_OCF
} OcfPresent;
/***************************************
** Telemetry specific enums
****************************************/
typedef enum
{
TM_NO_SECONDARY_HDR,
Expand Down Expand Up @@ -199,6 +224,9 @@ struct _GvcidManagedParameters_t
uint16_t scid : 10; // SpacecraftID
uint8_t vcid : 6; // Virtual Channel ID
FecfPresent has_fecf;
AosFhecPresent aos_has_fhec;
AosInsertZonePresent aos_has_iz;
uint16_t aos_iz_len;
TcSegmentHdrsPresent has_segmentation_hdr;
uint16_t max_frame_size; // Maximum TC/TM Frame Length with headers
OcfPresent has_ocf;
Expand Down
2 changes: 2 additions & 0 deletions include/crypto_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
#define CRYPTO_LIB_ERR_TC_ENUM_USED_FOR_TM_CONFIG (-46)
#define CRYPTO_LIB_ERR_KEY_ID_ERROR (-47)
#define CRYPTO_LIB_ERR_MC_INIT (-48)
#define CRYPTO_LIB_ERR_INPUT_FRAME_TOO_SHORT_FOR_AOS_STANDARD (-49)
#define CRYPTO_LIB_ERR_TC_ENUM_USED_FOR_AOS_CONFIG (-50)

extern char *crypto_enum_errlist_core[];
extern char *crypto_enum_errlist_config[];
Expand Down
2 changes: 1 addition & 1 deletion include/crypto_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
void Crypto_tcPrint(TC_t* tc_frame);
void Crypto_tmPrint(TM_t* tm_frame);
void Crypto_clcwPrint(TM_FrameCLCW_t* clcw);
void Crypto_clcwPrint(Telemetry_Frame_Clcw_t* clcw);
void Crypto_fsrPrint(SDLS_FSR_t* report);
void Crypto_ccsdsPrint(CCSDS_t* sdls_frame);
void Crypto_saPrint(SecurityAssociation_t* sa);
Expand Down
121 changes: 101 additions & 20 deletions include/crypto_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,49 @@ typedef struct
} CCSDS_t;
#define CCSDS_SIZE (sizeof(CCSDS_t))

/*
** Operational Control Field definition
** Telemetry frames can reply with either of these in their OCF field:
** 1) A Communications Control Link Word -or-
** 2) A Frame Security Report
*/

// INFO: This is the Communications Link Control Word register format
typedef struct
{
uint8_t cwt : 1; // Control Word Type "0"
uint8_t cvn : 2; // CLCW Version Number "00"
uint8_t sf : 3; // Status Field
uint8_t cie : 2; // COP In Effect
uint8_t vci : 6; // Virtual Channel Identification
uint8_t spare0 : 2; // Reserved Spare
uint8_t nrfa : 1; // No RF Avaliable Flag
uint8_t nbl : 1; // No Bit Lock Flag
uint8_t lo : 1; // Lock-Out Flag
uint8_t wait : 1; // Wait Flag
uint8_t rt : 1; // Retransmit Flag
uint8_t fbc : 2; // FARM-B Counter
uint8_t spare1 : 1; // Reserved Spare
uint8_t rv : 8; // Report Value
} Telemetry_Frame_Clcw_t;

#define TM_FRAME_CLCW_SIZE (sizeof(Telemetry_Frame_Clcw_t))

// INFO: This is the Frame Security Report register format
typedef struct
{
uint8_t cwt : 1; // Control Word Type "1"
uint8_t fvn : 3; // FSR Version Number "100"
uint8_t af : 1; // Alarm Flag
uint8_t bsnf : 1; // Bad Sequence Number Flag
uint8_t bmf : 1; // Bad Mac Flag
uint8_t bsaf : 1; // Bad Security Association Flag
uint16_t lspi : 16; // Last SPI Used
uint8_t snv : 8; // Sequence Number Value (LSB)
} Telemetry_Frame_Fsr_t;

#define TELEMETRY_FRAME_OCF_SIZE (sizeof(Telemetry_Frame_Fsr_t))

/*
** Telemetry (TM) Definitions
*/
Expand All @@ -334,7 +377,7 @@ typedef struct
uint8_t tfvn : 2; // Transfer Frame Version Number
uint16_t scid : 10; // Spacecraft ID
uint8_t vcid : 3; // Virtual Channel ID
uint8_t ocff : 1; // Describes wether OCF is present or not
uint8_t ocff : 1; // Describes whether OCF is present or not
uint8_t mcfc : 8; // Master Channel Frame Count (modulo-256)
uint8_t vcfc : 8; // Virtual Channel Frame Count (modulo-256)
uint8_t tfsh : 1; // Transfer Frame Secondary Header
Expand Down Expand Up @@ -372,25 +415,6 @@ typedef struct
} TM_FrameSecurityTrailer_t;
#define TM_FRAME_SECTRAILER_SIZE (sizeof(TM_FrameSecurityTrailer_t))

typedef struct
{
uint8_t cwt : 1; // Control Word Type "0"
uint8_t cvn : 2; // CLCW Version Number "00"
uint8_t sf : 3; // Status Field
uint8_t cie : 2; // COP In Effect
uint8_t vci : 6; // Virtual Channel Identification
uint8_t spare0 : 2; // Reserved Spare
uint8_t nrfa : 1; // No RF Avaliable Flag
uint8_t nbl : 1; // No Bit Lock Flag
uint8_t lo : 1; // Lock-Out Flag
uint8_t wait : 1; // Wait Flag
uint8_t rt : 1; // Retransmit Flag
uint8_t fbc : 2; // FARM-B Counter
uint8_t spare1 : 1; // Reserved Spare
uint8_t rv : 8; // Report Value
} TM_FrameCLCW_t;
#define TM_FRAME_CLCW_SIZE (sizeof(TM_FrameCLCW_t))

typedef struct
{
TM_FramePrimaryHeader_t tm_header;
Expand All @@ -403,4 +427,61 @@ typedef struct
#define TM_MIN_SIZE \
(TM_FRAME_PRIMARYHEADER_SIZE + TM_FRAME_SECHEADER_SIZE + TM_FRAME_SECTRAILER_SIZE + TM_FRAME_CLCW_SIZE)

/*
** Advanced Orbiting Systems (AOS) Definitions
*/
typedef struct
{
uint8_t tfvn : 2; // Transfer Frame Version Number
// Shall be set to '01' (732.0b4 Section 4.1.2.2.2)
uint16_t scid : 8; // Spacecraft ID
uint8_t vcid : 6; // Virtual Channel ID
// To be all zeros if only one VC used (732.0b4 Section 4.1.2.3)
long vcfc : 24; // Virtual Channel Frame Count (modulo-16,777,216)
/* Begin TF Signalling Field */
uint8_t rf : 1; // Replay Flag
uint8_t sf : 1; // VC Frame Count Usgae Flag
// 0 = Payload is either idle data or octet synchronized forward-ordered packets
// 1 = Data is a virtual channel access data unit
uint8_t spare : 2; // Reserved Spare
// 0 = Shall be set to 0
// Sync Flag 1 = Undefined
uint8_t vfcc : 2; // VC Frame Count cycle
// Sync Flag 0 = Shall be 11
// Sync Flag 1 = Undefined
uint16_t fhp : 11; // First Header Pointer
// Sync Flag 0 = Contains position of the first byte of the first packet in the data field
// Sync Flag 1 = undefined
} AOS_FramePrimaryHeader_t;
#define AOS_FRAME_PRIMARYHEADER_SIZE (sizeof(AOS_FramePrimaryHeader_t))

typedef struct
{
uint16_t spi; // Security Parameter Index
uint8_t iv[IV_SIZE]; // Initialization Vector for encryption
// uint8_t sn[TM_SN_SIZE]; // Sequence Number for anti-replay
// uint8_t pad[TM_PAD_SIZE]; // Count of the used fill Bytes
} AOS_FrameSecurityHeader_t;
#define AOS_FRAME_SECHEADER_SIZE (sizeof(AOS_FrameSecurityHeader_t))

typedef struct
{
uint8_t mac[MAC_SIZE]; // Message Authentication Code
uint8_t ocf[OCF_SIZE]; // Operational Control Field
uint16_t fecf; // Frame Error Control Field
} AOS_FrameSecurityTrailer_t;
#define AOS_FRAME_SECTRAILER_SIZE (sizeof(AOS_FrameSecurityTrailer_t))

typedef struct
{
AOS_FramePrimaryHeader_t tm_header;
AOS_FrameSecurityHeader_t tm_sec_header;
uint8_t aos_pdu[AOS_FRAME_DATA_SIZE];
AOS_FrameSecurityTrailer_t aos_sec_trailer;
} AOS_t;
#define AOS_SIZE (sizeof(AOS_t))

#define AOS_MIN_SIZE \
(AOS_FRAME_PRIMARYHEADER_SIZE + AOS_FRAME_SECHEADER_SIZE + AOS_FRAME_SECTRAILER_SIZE + AOS_FRAME_OCF_SIZE)

#endif //CRYPTO_STRUCTS_H
6 changes: 5 additions & 1 deletion src/core/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ CCSDS_t sdls_frame;
uint8_t tm_frame[1786]; // Testing
TM_FramePrimaryHeader_t tm_frame_pri_hdr; // Used to reduce bit math duplication
TM_FrameSecurityHeader_t tm_frame_sec_hdr; // Used to reduce bit math duplication
// AOS_t aos_frame
uint8_t aos_frame[1786]; // Testing
AOS_FramePrimaryHeader_t aos_frame_pri_hdr; // Used to reduce bit math duplication
AOS_FrameSecurityHeader_t aos_frame_sec_hdr; // Used to reduce bit math duplication
// OCF
uint8_t ocf = 0;
SDLS_FSR_t report;
TM_FrameCLCW_t clcw;
Telemetry_Frame_Clcw_t clcw;
// Flags
SDLS_MC_LOG_RPLY_t log_summary;
SDLS_MC_DUMP_BLK_RPLY_t mc_log;
Expand Down
Loading
Loading