Skip to content

Commit

Permalink
[#256] Updates to GVCID_Managed_Paramaters. Conversion from malloc an…
Browse files Browse the repository at this point in the history
…d recurison to array insertion. Updated unit tests
  • Loading branch information
rjbrown6 committed Jul 29, 2024
1 parent 3c2a3d4 commit e5019ff
Show file tree
Hide file tree
Showing 25 changed files with 988 additions and 534 deletions.
26 changes: 15 additions & 11 deletions include/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "key_interface.h"
#include "mc_interface.h"
#include "sa_interface.h"
#include "crypto.h"

/*
** Crypto Version
Expand Down Expand Up @@ -82,10 +83,10 @@ extern int32_t Crypto_Config_Kmc_Crypto_Service(char* protocol, char* kmc_crypto
char* mtls_client_cert_type, char* mtls_client_key_path,
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, uint8_t has_ocf, uint16_t max_frame_size, uint8_t aos_has_fhec,
uint8_t aos_has_iz, uint16_t aos_iz_len);

// 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, uint8_t has_ocf, uint16_t max_frame_size, uint8_t aos_has_fhec,
// uint8_t aos_has_iz, uint16_t aos_iz_len);
extern int32_t Crypto_Config_Add_Gvcid_Managed_Parameters(GvcidManagedParameters_t mp_struct);
// Initialization
extern int32_t Crypto_Init(void); // Initialize CryptoLib After Configuration Calls
extern int32_t Crypto_Init_With_Configs(
Expand Down Expand Up @@ -253,13 +254,13 @@ int32_t Crypto_Get_Security_Trailer_Length(SecurityAssociation_t* sa_ptr);
// Managed Parameter Functions
int32_t Crypto_Get_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uint8_t vcid,
GvcidManagedParameters_t* managed_parameters_in,
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, uint8_t has_ocf,
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);
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, uint8_t has_ocf,
// 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);

// Project-wide support functions
extern char* crypto_deep_copy_string(char* src_string);
Expand All @@ -284,6 +285,9 @@ extern CryptographyKmcCryptoServiceConfig_t* cryptography_kmc_crypto_config;
extern CamConfig_t* cam_config;
extern GvcidManagedParameters_t* gvcid_managed_parameters;
extern GvcidManagedParameters_t* current_managed_parameters;
extern GvcidManagedParameters_t gvcid_managed_parameters_array[250];
extern GvcidManagedParameters_t current_managed_parameters_struct;
extern int gvcid_counter;
extern KeyInterface key_if;
extern McInterface mc_if;
extern SaInterface sa_if;
Expand Down
2 changes: 1 addition & 1 deletion include/crypto_config_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ struct _GvcidManagedParameters_t
TcSegmentHdrsPresent has_segmentation_hdr;
uint16_t max_frame_size; // Maximum TC/TM Frame Length with headers
OcfPresent has_ocf;
GvcidManagedParameters_t* next; // Will be a list of managed parameters!
int set_flag; // Will be a list of managed parameters!
};
#define GVCID_MANAGED_PARAMETERS_SIZE (sizeof(GvcidManagedParameters_t))

Expand Down
1 change: 1 addition & 0 deletions include/crypto_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
#define CRYPTO_LIB_ERR_INVALID_SA_SERVICE_TYPE (-51)
#define CRYPTO_LIB_ERR_FAIL_SA_SAVE (-52)
#define CRYPTO_LIB_ERR_FAIL_SA_LOAD (-53)
#define CRYPTO_LIB_ERR_EXCEEDS_MANAGED_PARAMETER_MAX_LIMIT (-54)

extern char *crypto_enum_errlist_core[];
extern char *crypto_enum_errlist_config[];
Expand Down
97 changes: 62 additions & 35 deletions src/core/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,61 +684,88 @@ int32_t Crypto_PDU(uint8_t* ingest, TC_t* tc_frame)
return status;
}

/**
* @brief Function: Crypto_Get_Managed_Parameters_For_Gvcid
* @param tfvn: uint8
* @param scid: uint16
* @param vcid: uint8
* @param managed_parameters_in: GvcidManagedParameters_t*
* @param managed_parameters_out: GvcidManagedParameters_t**
* @return int32: Success/Failure
**/

int32_t Crypto_Get_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uint8_t vcid,
GvcidManagedParameters_t* managed_parameters_in,
GvcidManagedParameters_t** managed_parameters_out)
GvcidManagedParameters_t* managed_parameters_out)
{
int32_t status = MANAGED_PARAMETERS_FOR_GVCID_NOT_FOUND;

if (managed_parameters_in != NULL)
for(int i = 0; i < gvcid_counter; i++)
{
if (managed_parameters_in->tfvn == tfvn && managed_parameters_in->scid == scid &&
managed_parameters_in->vcid == vcid)
if (managed_parameters_in[i].tfvn == tfvn && managed_parameters_in[i].scid == scid &&
managed_parameters_in[i].vcid == vcid)
{
*managed_parameters_out = managed_parameters_in;
*managed_parameters_out = managed_parameters_in[i];
status = CRYPTO_LIB_SUCCESS;
return status;
}
else
{
return Crypto_Get_Managed_Parameters_For_Gvcid(tfvn, scid, vcid, managed_parameters_in->next,
managed_parameters_out);
break;
}
}
else

if(status != CRYPTO_LIB_SUCCESS)
{
printf(KRED "Error: Managed Parameters for GVCID(TFVN: %d, SCID: %d, VCID: %d) not found. \n" RESET, tfvn, scid,
vcid);
return status;
}

return status;
}


/**
* @brief Function: Crypto_Get_Managed_Parameters_For_Gvcid
* @param tfvn: uint8
* @param scid: uint16
* @param vcid: uint8
* @param managed_parameters_in: GvcidManagedParameters_t*
* @param managed_parameters_out: GvcidManagedParameters_t**
* @return int32: Success/Failure
**/
// int32_t Crypto_Get_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uint8_t vcid,
// GvcidManagedParameters_t* managed_parameters_in,
// GvcidManagedParameters_t** managed_parameters_out)
// {
// int32_t status = MANAGED_PARAMETERS_FOR_GVCID_NOT_FOUND;

// if (managed_parameters_in != NULL)
// {
// if (managed_parameters_in->tfvn == tfvn && managed_parameters_in->scid == scid &&
// managed_parameters_in->vcid == vcid)
// {
// *managed_parameters_out = managed_parameters_in;
// status = CRYPTO_LIB_SUCCESS;
// return status;
// }
// else
// {
// return Crypto_Get_Managed_Parameters_For_Gvcid(tfvn, scid, vcid, managed_parameters_in->next,
// managed_parameters_out);
// }
// }
// else
// {
// printf(KRED "Error: Managed Parameters for GVCID(TFVN: %d, SCID: %d, VCID: %d) not found. \n" RESET, tfvn, scid,
// vcid);
// return status;
// }
// }

/**
* @brief Function: Crypto_Free_Managed_Parameters
* Managed parameters are expected to live the duration of the program, this may not be necessary.
* @param managed_parameters: GvcidManagedParameters_t*
**/
void Crypto_Free_Managed_Parameters(GvcidManagedParameters_t* managed_parameters)
{
if (managed_parameters == NULL)
{
return; // Nothing to free, just return!
}
if (managed_parameters->next != NULL)
{
Crypto_Free_Managed_Parameters(managed_parameters->next);
}
free(managed_parameters);
}
// void Crypto_Free_Managed_Parameters(GvcidManagedParameters_t* managed_parameters)
// {
// if (managed_parameters == NULL)
// {
// return; // Nothing to free, just return!
// }
// if (managed_parameters->next != NULL)
// {
// Crypto_Free_Managed_Parameters(managed_parameters->next);
// }
// free(managed_parameters);
// }

/**
* @brief Function: Crypto_Process_Extended_Procedure_Pdu
Expand Down
Loading

0 comments on commit e5019ff

Please sign in to comment.