-
Notifications
You must be signed in to change notification settings - Fork 29
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
Fix psa_key_derivation_input_integer() not detecting bad state #186
base: development
Are you sure you want to change the base?
Fix psa_key_derivation_input_integer() not detecting bad state #186
Conversation
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
64f48d6
to
6b7da82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for providing a fix and a test!
I'd just like to avoid making the key derivation testing function even more complicated.
@@ -8954,6 +8954,25 @@ void derive_input(int alg_arg, | |||
} | |||
TEST_EQUAL(actual_output_status, expected_output_status); | |||
|
|||
/* Test calling input functions after operation has been aborted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding a test! But please don't add extra code to this function, which is already more complex than I'd like.
Proposal 1: keep this function, but skip the call to psa_key_derivation_setup()
when alg == 0
. Add test cases that expect that each input attempt returns BAD_STATE
.
Proposal 2: make a new function that tries input_xxx
without setup
.
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the tests. LGTM.
@@ -8900,7 +8900,9 @@ void derive_input(int alg_arg, | |||
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE); | |||
psa_set_key_algorithm(&attributes, alg); | |||
|
|||
PSA_ASSERT(psa_key_derivation_setup(&operation, alg)); | |||
if (alg != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: the code has 0
and the test data has PSA_ALG_NONE
. The value of PSA_ALG_NONE
won't ever change, but it's a bit confusing for readers who aren't very familiar with the API.
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, one minor suggestion for maintainability purposes only.
core/psa_crypto.c
Outdated
@@ -7612,6 +7612,12 @@ static psa_status_t psa_key_derivation_input_internal( | |||
psa_status_t status; | |||
psa_algorithm_t kdf_alg = psa_key_derivation_get_kdf_alg(operation); | |||
|
|||
if (kdf_alg == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (kdf_alg == 0) { | |
if (kdf_alg == PSA_ALG_NONE) { |
3 occurences.
I think the intent of @gilles-peskine-arm's comment was to keep it consistent between codebase and tests?
It woudl be good for users revewing the code to understand that this exit's purpose is.
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
fixes #185
Fix psa_key_derivation_input_integer() not detecting bad state after an operation has been aborted.
changed some existing tests my justification is after they have returned PSA_ERROR_BAD_STATE they
were expected to return PSA_ERROR_INVALID_ARGUMENT but this shouldn't happen as the user is
expected to call abort() after a function has returned an error and we call abort() internally in case of an error
and without calling setup() first we should return PSA_ERROR_BAD_STATE and not any other error.
PR checklist
Please remove the segment/s on either side of the | symbol as appropriate, and add any relevant link/s to the end of the line.
If the provided content is part of the present PR remove the # symbol.