Skip to content

Commit

Permalink
[#196] Refactor for single return - Check Anti Replay
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbrown6 committed Mar 26, 2024
1 parent d8bbe63 commit 8e163bb
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions src/core/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,28 +916,43 @@ int32_t Crypto_Check_Anti_Replay(SecurityAssociation_t* sa_ptr, uint8_t* arsn, u

// Check for NULL pointers
status = Crypto_Check_Anti_Replay_Verify_Pointers(sa_ptr, arsn, iv);
if(status != CRYPTO_LIB_SUCCESS)
{
mc_if->mc_log(status);
return status;
}


// If sequence number field is greater than zero, check for replay
status = Crypto_Check_Anti_Replay_ARSNW(sa_ptr, arsn, &arsn_valid);
if(status != CRYPTO_LIB_SUCCESS)
if(status == CRYPTO_LIB_SUCCESS)
{
mc_if->mc_log(status);
return status;
status = Crypto_Check_Anti_Replay_ARSNW(sa_ptr, arsn, &arsn_valid);
}

// If IV is greater than zero and using GCM, check for replay
status = Crypto_Check_Anti_Replay_GCM(sa_ptr, iv, &iv_valid);
if(status != CRYPTO_LIB_SUCCESS)
if(status == CRYPTO_LIB_SUCCESS)
{
mc_if->mc_log(status);
return status;
status = Crypto_Check_Anti_Replay_GCM(sa_ptr, iv, &iv_valid);
}

// Check for NULL pointers
// status = Crypto_Check_Anti_Replay_Verify_Pointers(sa_ptr, arsn, iv);
// if(status != CRYPTO_LIB_SUCCESS)
// {
// mc_if->mc_log(status);
// return status;
// }

// // If sequence number field is greater than zero, check for replay
// status = Crypto_Check_Anti_Replay_ARSNW(sa_ptr, arsn, &arsn_valid);
// if(status != CRYPTO_LIB_SUCCESS)
// {
// mc_if->mc_log(status);
// return status;
// }

// // If IV is greater than zero and using GCM, check for replay
// status = Crypto_Check_Anti_Replay_GCM(sa_ptr, iv, &iv_valid);
// if(status != CRYPTO_LIB_SUCCESS)
// {
// mc_if->mc_log(status);
// return status;
// }

// For GCM specifically, if have a valid IV...
if ((sa_ptr->ecs == CRYPTO_CIPHER_AES256_GCM) && (iv_valid == CRYPTO_TRUE))
{
Expand All @@ -960,6 +975,12 @@ int32_t Crypto_Check_Anti_Replay(SecurityAssociation_t* sa_ptr, uint8_t* arsn, u
memcpy(sa_ptr->arsn, arsn, sa_ptr->arsn_len);
}

if(status != CRYPTO_LIB_SUCCESS)
{
// Log error if it happened
mc_if->mc_log(status);
}

return status;
}

Expand Down

0 comments on commit 8e163bb

Please sign in to comment.