Skip to content

Commit

Permalink
Merge pull request #387 from nasa/373-run-linter-before-release
Browse files Browse the repository at this point in the history
[#373] Formatted Code
  • Loading branch information
Donnie-Ice authored Jan 14, 2025
2 parents e1f8cea + bd6edc7 commit 4c50ad3
Show file tree
Hide file tree
Showing 19 changed files with 586 additions and 581 deletions.
2 changes: 1 addition & 1 deletion include/crypto_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

// Generic Defines
#define NUM_SA 64
#define SPI_LEN 2 /* bytes */
#define SPI_LEN 2 /* bytes */
#define SPI_MIN 0
#define SPI_MAX NUM_SA - 1
#define KEY_SIZE 512 /* bytes */
Expand Down
1 change: 0 additions & 1 deletion include/crypto_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@

#define CRYPTO_CORE_ERROR_CODES_MAX -69


// Define codes for returning MDB Strings, and determining error based on strings
#define CAM_ERROR_CODES 600
#define CAM_ERROR_CODES_MAX 610
Expand Down
70 changes: 36 additions & 34 deletions src/core/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ int32_t Crypto_Get_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uin
return status;
}


/**
* @brief Function: Crypto_Process_Extended_Procedure_Pdu
* @param tc_sdls_processed_frame: TC_t*
Expand All @@ -776,7 +775,7 @@ int32_t Crypto_Get_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uin
int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uint8_t *ingest)
{
int32_t status = CRYPTO_LIB_SUCCESS;
ingest = ingest; // Suppress unused variable error depending on build
ingest = ingest; // Suppress unused variable error depending on build

// Check for null pointers
if (tc_sdls_processed_frame == NULL)
Expand All @@ -786,7 +785,8 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin

// Validate correct SA for EPs
uint8_t valid_ep_sa = CRYPTO_FALSE;
if ((tc_sdls_processed_frame->tc_sec_header.spi == SPI_MIN) || (tc_sdls_processed_frame->tc_sec_header.spi == SPI_MAX))
if ((tc_sdls_processed_frame->tc_sec_header.spi == SPI_MIN) ||
(tc_sdls_processed_frame->tc_sec_header.spi == SPI_MAX))
{
valid_ep_sa = CRYPTO_TRUE;
}
Expand All @@ -798,7 +798,7 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
{
#ifdef CRYPTO_EPROC
// Check validity of SAs used for EP
if(valid_ep_sa == CRYPTO_TRUE)
if (valid_ep_sa == CRYPTO_TRUE)
{
#ifdef DEBUG
printf(KGRN "Received SDLS command w/ packet header:\n\t " RESET);
Expand All @@ -817,8 +817,8 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin

// Using PUS Header
if (crypto_config.has_pus_hdr == TC_HAS_PUS_HDR)
{
// If ECSS PUS Header is being used
{
// If ECSS PUS Header is being used
sdls_frame.pus.shf = (tc_sdls_processed_frame->tc_pdu[6] & 0x80) >> 7;
sdls_frame.pus.pusv = (tc_sdls_processed_frame->tc_pdu[6] & 0x70) >> 4;
sdls_frame.pus.ack = (tc_sdls_processed_frame->tc_pdu[6] & 0x0F);
Expand All @@ -827,7 +827,7 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
sdls_frame.pus.sid = (tc_sdls_processed_frame->tc_pdu[9] & 0xF0) >> 4;
sdls_frame.pus.spare = (tc_sdls_processed_frame->tc_pdu[9] & 0x0F);

// SDLS TLV PDU
// SDLS TLV PDU
sdls_frame.pdu.hdr.type = (tc_sdls_processed_frame->tc_pdu[10] & 0x80) >> 7;
sdls_frame.pdu.hdr.uf = (tc_sdls_processed_frame->tc_pdu[10] & 0x40) >> 6;
sdls_frame.pdu.hdr.sg = (tc_sdls_processed_frame->tc_pdu[10] & 0x30) >> 4;
Expand All @@ -836,7 +836,8 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
(tc_sdls_processed_frame->tc_pdu[11] << 8) | tc_sdls_processed_frame->tc_pdu[12];

// Subtract headers from total frame length
// uint16_t max_tlv = tc_sdls_processed_frame->tc_header.fl - CCSDS_HDR_SIZE - CCSDS_PUS_SIZE - SDLS_TLV_HDR_SIZE;
// uint16_t max_tlv = tc_sdls_processed_frame->tc_header.fl - CCSDS_HDR_SIZE - CCSDS_PUS_SIZE -
// SDLS_TLV_HDR_SIZE;
if (sdls_frame.hdr.pkt_length < TLV_DATA_SIZE) // && (sdls_frame.hdr.pkt_length < max_tlv))
{
for (int x = 13; x < (13 + sdls_frame.hdr.pkt_length); x++)
Expand All @@ -853,14 +854,14 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
// Not using PUS Header
else
{
// SDLS TLV PDU
// SDLS TLV PDU
sdls_frame.pdu.hdr.type = (tc_sdls_processed_frame->tc_pdu[6] & 0x80) >> 7;
sdls_frame.pdu.hdr.uf = (tc_sdls_processed_frame->tc_pdu[6] & 0x40) >> 6;
sdls_frame.pdu.hdr.sg = (tc_sdls_processed_frame->tc_pdu[6] & 0x30) >> 4;
sdls_frame.pdu.hdr.pid = (tc_sdls_processed_frame->tc_pdu[6] & 0x0F);
sdls_frame.pdu.hdr.pdu_len =
(tc_sdls_processed_frame->tc_pdu[7] << 8) | tc_sdls_processed_frame->tc_pdu[8];

// Make sure TLV isn't larger than we have allocated, and it is sane given total frame length
uint16_t max_tlv = tc_sdls_processed_frame->tc_header.fl - CCSDS_HDR_SIZE - SDLS_TLV_HDR_SIZE;
if ((sdls_frame.hdr.pkt_length < TLV_DATA_SIZE) && (sdls_frame.hdr.pkt_length < max_tlv))
Expand All @@ -877,51 +878,51 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
}
}



#ifdef CCSDS_DEBUG
Crypto_ccsdsPrint(&sdls_frame);
#endif
// Determine type of PDU
status = Crypto_PDU(ingest, tc_sdls_processed_frame);

// Determine type of PDU
status = Crypto_PDU(ingest, tc_sdls_processed_frame);
}
// Received EP PDU on invalid SA
else
{
#ifdef CCSDS_DEBUG
printf(KRED "Received EP PDU on invalid SA! SPI %d\n" RESET, tc_sdls_processed_frame->tc_sec_header.spi);
printf(KRED "Received EP PDU on invalid SA! SPI %d\n" RESET,
tc_sdls_processed_frame->tc_sec_header.spi);
#endif
status = CRYPTO_LIB_ERR_SDLS_EP_WRONG_SPI;
}

#else // Received an EP command without EPs being built
#else // Received an EP command without EPs being built
valid_ep_sa = valid_ep_sa; // Suppress build error
status = CRYPTO_LIB_ERR_SDLS_EP_NOT_BUILT;
#endif //CRYPTO_EPROC
status = CRYPTO_LIB_ERR_SDLS_EP_NOT_BUILT;
#endif // CRYPTO_EPROC
}

// If not a specific APID, check if using VCIDs for SDLS PDUs with no packet layer
else if (tc_sdls_processed_frame->tc_header.vcid == TC_SDLS_EP_VCID)
else if (tc_sdls_processed_frame->tc_header.vcid == TC_SDLS_EP_VCID)
{
#ifdef CRYPTO_EPROC
#ifdef CRYPTO_EPROC
// Check validity of SAs used for EP
if(valid_ep_sa == CRYPTO_TRUE)
{
if (valid_ep_sa == CRYPTO_TRUE)
{
#ifdef CCSDS_DEBUG
printf(KGRN "Received SDLS command (No Packet Header or PUS): " RESET);
#endif
// No Packet HDR or PUS in these frames
// SDLS TLV PDU
sdls_frame.hdr.type = (tc_sdls_processed_frame->tc_pdu[0] & 0x80) >> 7;
sdls_frame.pdu.hdr.uf = (tc_sdls_processed_frame->tc_pdu[0] & 0x40) >> 6;
sdls_frame.pdu.hdr.sg = (tc_sdls_processed_frame->tc_pdu[0] & 0x30) >> 4;
sdls_frame.pdu.hdr.pid = (tc_sdls_processed_frame->tc_pdu[0] & 0x0F);
sdls_frame.pdu.hdr.pdu_len = (tc_sdls_processed_frame->tc_pdu[1] << 8) | tc_sdls_processed_frame->tc_pdu[2];
sdls_frame.hdr.type = (tc_sdls_processed_frame->tc_pdu[0] & 0x80) >> 7;
sdls_frame.pdu.hdr.uf = (tc_sdls_processed_frame->tc_pdu[0] & 0x40) >> 6;
sdls_frame.pdu.hdr.sg = (tc_sdls_processed_frame->tc_pdu[0] & 0x30) >> 4;
sdls_frame.pdu.hdr.pid = (tc_sdls_processed_frame->tc_pdu[0] & 0x0F);
sdls_frame.pdu.hdr.pdu_len =
(tc_sdls_processed_frame->tc_pdu[1] << 8) | tc_sdls_processed_frame->tc_pdu[2];
for (int x = 3; x < (3 + tc_sdls_processed_frame->tc_header.fl); x++)
{
// Todo - Consider how this behaves with large OTAR PDUs that are larger than 1 TC in size. Most likely
// fails. Must consider Uplink Sessions (sequence numbers).
// Todo - Consider how this behaves with large OTAR PDUs that are larger than 1 TC in size. Most
// likely fails. Must consider Uplink Sessions (sequence numbers).
sdls_frame.pdu.data[x - 3] = tc_sdls_processed_frame->tc_pdu[x];
}

Expand All @@ -932,13 +933,13 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
// Determine type of PDU
status = Crypto_PDU(ingest, tc_sdls_processed_frame);
}
#else // Received an EP command without EPs being built
#else // Received an EP command without EPs being built
#ifdef CCSDS_DEBUG
printf(KRED "PDU DEBUG %s %d\n" RESET, __FILE__, __LINE__);
#endif
valid_ep_sa = valid_ep_sa; // Suppress build error
status = CRYPTO_LIB_ERR_SDLS_EP_NOT_BUILT;
#endif //CRYPTO_EPROC
status = CRYPTO_LIB_ERR_SDLS_EP_NOT_BUILT;
#endif // CRYPTO_EPROC
}
}
return status;
Expand Down Expand Up @@ -1255,7 +1256,8 @@ int32_t Crypto_Get_Security_Trailer_Length(SecurityAssociation_t *sa_ptr)

void Crypto_Set_FSR(uint8_t *p_ingest, uint16_t byte_idx, uint16_t pdu_len, SecurityAssociation_t *sa_ptr)
{
if (current_managed_parameters_struct.has_ocf == TM_HAS_OCF || current_managed_parameters_struct.has_ocf == AOS_HAS_OCF)
if (current_managed_parameters_struct.has_ocf == TM_HAS_OCF ||
current_managed_parameters_struct.has_ocf == AOS_HAS_OCF)
{
Telemetry_Frame_Ocf_Fsr_t temp_report;
byte_idx += (pdu_len + sa_ptr->stmacf_len);
Expand Down
1 change: 0 additions & 1 deletion src/core/crypto_aos.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,6 @@ int32_t Crypto_AOS_ProcessSecurity(uint8_t *p_ingest, uint16_t len_ingest, uint8
crypto_key_t *ekp = NULL;
crypto_key_t *akp = NULL;


if (sa_ptr->est == 1)
{
ekp = key_if->get_key(sa_ptr->ekid);
Expand Down
Loading

0 comments on commit 4c50ad3

Please sign in to comment.