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

Don't skip Handle_Increment if Do_Encrypt_NONPLAINTEXT succeeds #280

Merged
merged 2 commits into from
Aug 23, 2024
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
4 changes: 2 additions & 2 deletions src/core/crypto_tm.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ int32_t Crypto_TM_Do_Encrypt(uint8_t sa_service_type, SecurityAssociation_t* sa_
}


if (status != CRYPTO_LIB_SUCCESS)
if (status == CRYPTO_LIB_SUCCESS)
{
status = Crypto_TM_Do_Encrypt_Handle_Increment(sa_service_type, sa_ptr);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. This is correct.
However, the following code. Should it perhaps be in an if (status == CRYPTO_LIB_SUCCESS) block as well?
We need to make sure to check the return of status before moving on each time. There are two additional places where this seems to occur here.

Expand Down Expand Up @@ -2035,4 +2035,4 @@ uint32_t Crypto_Prepare_TM_AAD(const uint8_t* buffer, uint16_t len_aad, const ui
#endif

return status;
}
}
16 changes: 15 additions & 1 deletion test/unit/ut_tm_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,13 @@ UTEST(TM_APPLY_ENC_VAL, AEAD_AES_GCM_BITMASK_1)
hex_conversion(iv_h, &iv_b, &iv_len);
memcpy(sa_ptr->iv, iv_b, iv_len);

// Expected IV after increment
char* next_iv_h = "DEADBEEFDEADBEEFDEADBEEFDEADBEF0";
char* next_iv_b = NULL;
int next_iv_len = 0;
hex_conversion(next_iv_h, &next_iv_b, &next_iv_len);
ASSERT_EQ(next_iv_len, iv_len);

Crypto_TM_ApplySecurity((uint8_t*)framed_tm_b);

printf("Static frame contents:\n\t");
Expand Down Expand Up @@ -1142,10 +1149,17 @@ UTEST(TM_APPLY_ENC_VAL, AEAD_AES_GCM_BITMASK_1)
}
printf("\n");

// Ensure IV has been incremented
for (int i = 0; i < iv_len; i++)
{
ASSERT_EQ((uint8_t)next_iv_b[i], (uint8_t)sa_ptr->iv[i]);
}

Crypto_Shutdown();
free(truth_tm_b);
free(framed_tm_b);
free(iv_b);
free(next_iv_b);
}

UTEST_MAIN();
UTEST_MAIN();
Loading