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

[nasa/cryptolib#373] Formatted Code #387

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 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
@@ -1,4 +1,4 @@
/** Copyright (C) 2009 - 2022 National Aeronautics and Space Administration.

Check notice on line 1 in src/core/crypto_aos.c

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on src/core/crypto_aos.c

File src/core/crypto_aos.c does not conform to Custom style guidelines. (lines 912)
All Foreign Rights are Reserved to the U.S. Government.

This software is provided "as is" without any warranty of any kind, either expressed, implied, or statutory,
Expand Down Expand Up @@ -1214,7 +1214,6 @@
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
Loading