Skip to content

Commit

Permalink
[#246] Fix GCC 13.x Compilation Issues with Null SA/IV
Browse files Browse the repository at this point in the history
  • Loading branch information
Donnie-Ice committed Jun 3, 2024
1 parent 277a3fd commit a6eb0ce
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/core/crypto_aos.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ int32_t Crypto_AOS_ApplySecurity(uint8_t* pTfBuffer)

// Set initialization vector if specified
#ifdef SA_DEBUG
if (sa_ptr->shivf_len > 0 && sa_ptr->iv != NULL)
if (sa_ptr->shivf_len > 0)
{
printf(KYEL "Using IV value:\n\t");
for (i = 0; i < sa_ptr->iv_len; i++)
Expand Down
4 changes: 0 additions & 4 deletions src/core/crypto_mc.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ int32_t Crypto_SA_readARSN(uint8_t* ingest)
{ // Set IV - authenticated encryption
for (x = 0; x < sa_ptr->shivf_len - 1; x++)
{
if(sa_ptr->iv == NULL)
{
return CRYPTO_LIB_ERROR;
}
ingest[count++] = *(sa_ptr->iv + x);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/crypto_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ int32_t Crypto_TC_Set_IV(SecurityAssociation_t* sa_ptr, uint8_t* p_new_enc_frame
{
uint32_t status = CRYPTO_LIB_SUCCESS;
#ifdef SA_DEBUG
if (sa_ptr->shivf_len > 0 && sa_ptr->iv != NULL)
if (sa_ptr->shivf_len > 0)
{
int i = 0;
printf(KYEL "Using IV value:\n\t");
Expand Down
2 changes: 1 addition & 1 deletion src/core/crypto_tm.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int32_t Crypto_TM_IV_Sanity_Check(uint8_t* sa_service_type, SecurityAssociation_
{
int32_t status = CRYPTO_LIB_SUCCESS;
#ifdef SA_DEBUG
if (sa_ptr->shivf_len > 0 && sa_ptr->iv != NULL)
if (sa_ptr->shivf_len > 0)
{
printf(KYEL "Using IV value:\n\t");
for (int i = 0; i < sa_ptr->iv_len; i++)
Expand Down
24 changes: 10 additions & 14 deletions src/sa/internal/sa_interface_inmemory.template.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,10 @@ static int32_t sa_get_from_spi(uint16_t spi, SecurityAssociation_t** security_as
{
int32_t status = CRYPTO_LIB_SUCCESS;
*security_association = &sa[spi];
if ((sa[spi].iv == NULL) && (sa[spi].shivf_len > 0) && crypto_config.cryptography_type != CRYPTOGRAPHY_TYPE_KMCCRYPTO)
{
return CRYPTO_LIB_ERR_NULL_IV;
} // Must have IV if doing encryption or authentication
// if (sa[spi].shivf_len > 0 && crypto_config.cryptography_type != CRYPTOGRAPHY_TYPE_KMCCRYPTO)
// {
// return CRYPTO_LIB_ERR_NULL_IV;
// } // Must have IV if doing encryption or authentication

if ((sa[spi].abm_len == 0) && sa[spi].ast)
{
Expand Down Expand Up @@ -688,13 +688,13 @@ int32_t sa_get_operational_sa_from_gvcid_find_iv(uint8_t tfvn, uint16_t scid, ui
*security_association = &sa[i];

// Must have IV if using libgcrypt and auth/enc
if (sa[i].iv == NULL && (sa[i].ast == 1 || sa[i].est == 1) && crypto_config.cryptography_type != CRYPTOGRAPHY_TYPE_KMCCRYPTO)
{
status = CRYPTO_LIB_ERR_NULL_IV;
return status;
}
// if (sa[i].iv == NULL && (sa[i].ast == 1 || sa[i].est == 1) && crypto_config.cryptography_type != CRYPTOGRAPHY_TYPE_KMCCRYPTO)
// {
// //status = CRYPTO_LIB_ERR_NULL_IV;
// //return status;
// }
// Must have ABM if doing authentication
if (sa[i].abm == NULL && sa[i].ast)
if (sa[i].ast && sa[i].abm_len <= 0)
{
status = CRYPTO_LIB_ERR_NULL_ABM;
return status;
Expand Down Expand Up @@ -875,10 +875,6 @@ static int32_t sa_get_operational_sa_from_gvcid(uint8_t tfvn, uint16_t scid, uin
SecurityAssociation_t** security_association)
{
int32_t status = CRYPTO_LIB_ERR_NO_OPERATIONAL_SA;
if (sa == NULL)
{
return CRYPTO_LIB_ERR_NO_INIT;
}

status = sa_get_operational_sa_from_gvcid_find_iv(tfvn, scid, vcid, mapid, security_association);

Expand Down

0 comments on commit a6eb0ce

Please sign in to comment.