-
Notifications
You must be signed in to change notification settings - Fork 67
Inline check_pair functions #580
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
base: development
Are you sure you want to change the base?
Conversation
1e12dba to
22b0400
Compare
22b0400 to
f231ae8
Compare
f231ae8 to
851cfba
Compare
davidhorstmann-arm
left a comment
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.
A few small things and questions, but looks good otherwise!
tests/suites/test_suite_pk.function
Outdated
| TEST_EQUAL(mbedtls_pk_check_pair(&pub, &prv), ret); | ||
| } else { | ||
| TEST_EQUAL(mbedtls_pk_check_pair(&pub, &prv), MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE); | ||
| TEST_EQUAL(mbedtls_pk_check_pair(&pub, &prv), MBEDTLS_ERR_ASN1_BUF_TOO_SMALL); |
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.
Why did this need changing? Was this code path not exercised before this change?
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.
So, this was because the previous implementation was able to check the function pointer to check_pair in the structure to see if it was supported. With the new architecture this isn't available, so it progresses further before failing with a different error. You make a good point though, so I've added additional logic to return the same error as before.
drivers/builtin/src/pk.c
Outdated
|
|
||
| return prv->pk_info->check_pair_func((mbedtls_pk_context *) pub, | ||
| (mbedtls_pk_context *) prv); | ||
| if ((prv->pk_info->type == MBEDTLS_PK_RSA) || (prv->pk_info->type == MBEDTLS_PK_RSASSA_PSS)) { |
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.
Since #532 has now been merged, could you change this to use mbedtls_pk_get_key_type()?
| if ((prv->pk_info->type == MBEDTLS_PK_RSA) || (prv->pk_info->type == MBEDTLS_PK_RSASSA_PSS)) { | |
| if (PSA_KEY_TYPE_IS_RSA(mbedtls_pk_get_key_type(prv))) { |
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.
I've replaced these calls with the new mbedtls_pk_get_key_type function.
drivers/builtin/src/pk.c
Outdated
| if ((prv->pk_info->type != MBEDTLS_PK_OPAQUE) && | ||
| (pub->pk_info != prv->pk_info)) { | ||
| (pub->pk_info != prv->pk_info) && | ||
| (pub->pk_info->type != prv->pk_info->type)) { |
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.
What was this check for originally and why does it need a new explicit check for the type?
Are there cases where the pk_info pointers are different but the types are the same? My understanding was that this could not happen as all of the possible pk_info structs are initialized statically (I think it's in pk_wrap.c).
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.
Yes, this is a good point. I've removed the type check.
52B code size reduction, thanks! |
d7dc92f to
fcec227
Compare
Add additional tests for the check_pair functionality, as some test cases are currently not covered. This is done first to validate that the refactoring and inline in future commits is correct. Signed-off-by: Ben Taylor <[email protected]>
Add the new check pair functionality, this is a refactored and inlined version of all of the original check pair functions. It therefore provides the same functionality with a smaller code size. Signed-off-by: Ben Taylor <[email protected]>
Remove the legacy functions and pointers as these are now replaced by the new inlined check_pair functionality. Thisis functionaly equivelent to the original code with the exception of some error codes. Signed-off-by: Ben Taylor <[email protected]>
Signed-off-by: Ben Taylor <[email protected]>
Signed-off-by: Ben Taylor <[email protected]>
Signed-off-by: Ben Taylor <[email protected]>
Signed-off-by: Ben Taylor <[email protected]>
Signed-off-by: Ben Taylor <[email protected]>
fb547b3 to
aceaf43
Compare
…lready checked Signed-off-by: Ben Taylor <[email protected]>
aceaf43 to
753d5dd
Compare
Signed-off-by: Ben Taylor <[email protected]>
Signed-off-by: Ben Taylor <[email protected]>
Description
Inline check_pair functions resolves #521
PR checklist